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-16 15:32:57 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    203257305 : set_current_access_from_decl (tree decl)
     215              : {
     216    203257305 :   if (TREE_PRIVATE (decl))
     217     18933136 :     current_access_specifier = access_private_node;
     218    184324169 :   else if (TREE_PROTECTED (decl))
     219     11355874 :     current_access_specifier = access_protected_node;
     220              :   else
     221    172968295 :     current_access_specifier = access_public_node;
     222    203257305 : }
     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       153039 : build_if_in_charge (tree true_stmt, tree false_stmt)
     230              : {
     231       153039 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     232       306078 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     233       153039 :                      current_in_charge_parm, integer_zero_node);
     234       153039 :   tree type = unlowered_expr_type (true_stmt);
     235       153039 :   if (VOID_TYPE_P (type))
     236         7070 :     type = unlowered_expr_type (false_stmt);
     237       153039 :   tree cond = build3 (COND_EXPR, type,
     238              :                       cmp, true_stmt, false_stmt);
     239       153039 :   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     57114987 : build_base_path (enum tree_code code,
     254              :                  tree expr,
     255              :                  tree binfo,
     256              :                  int nonnull,
     257              :                  tsubst_flags_t complain)
     258              : {
     259     57114987 :   tree v_binfo = NULL_TREE;
     260     57114987 :   tree d_binfo = NULL_TREE;
     261     57114987 :   tree probe;
     262     57114987 :   tree offset;
     263     57114987 :   tree target_type;
     264     57114987 :   tree null_test = NULL;
     265     57114987 :   tree ptr_target_type;
     266     57114987 :   int fixed_type_p;
     267     57114987 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     268     57114987 :   bool has_empty = false;
     269     57114987 :   bool virtual_access;
     270     57114987 :   bool rvalue = false;
     271              : 
     272     57114987 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     273              :     return error_mark_node;
     274              : 
     275    122824234 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     276              :     {
     277     65709262 :       d_binfo = probe;
     278     65709262 :       if (is_empty_class (BINFO_TYPE (probe)))
     279      9029970 :         has_empty = true;
     280    131327831 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     281              :         v_binfo = probe;
     282              :     }
     283              : 
     284     57114972 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     285     57114972 :   if (want_pointer)
     286     53365737 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     287     57114972 :   if (dependent_type_p (probe))
     288       276326 :     if (tree open = currently_open_class (probe))
     289     57114972 :       probe = open;
     290              : 
     291     57114972 :   if (code == PLUS_EXPR
     292    110995791 :       && !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     60349117 :   gcc_assert ((code == MINUS_EXPR
     309              :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     310              :               || code == PLUS_EXPR);
     311              : 
     312     57114964 :   if (binfo == d_binfo)
     313              :     /* Nothing to do.  */
     314              :     return expr;
     315              : 
     316      7935769 :   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     22752108 :   bool uneval = (cp_unevaluated_operand != 0
     348      7215416 :                  || processing_template_decl
     349     14816511 :                  || in_template_context);
     350              : 
     351      6880594 :   if (!uneval)
     352      6880594 :     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      7935757 :   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      7935757 :   if (code == PLUS_EXPR
     362      7935757 :       && !want_pointer
     363              :       && !has_empty
     364      3748860 :       && !uneval
     365      2215379 :       && !virtual_access)
     366      2210182 :     return build_simple_base_path (expr, binfo);
     367              : 
     368      5725575 :   if (!want_pointer)
     369              :     {
     370      1538678 :       rvalue = !lvalue_p (expr);
     371              :       /* This must happen before the call to save_expr.  */
     372      1538678 :       expr = cp_build_addr_expr (expr, complain);
     373              :     }
     374              :   else
     375      4186897 :     expr = mark_rvalue_use (expr);
     376              : 
     377      5725575 :   offset = BINFO_OFFSET (binfo);
     378      5772810 :   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      5725575 :   target_type = cp_build_qualified_type
     383      5725575 :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     384      5725575 :   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      5725575 :   if (uneval)
     392              :     {
     393      1055163 :       expr = build_nop (ptr_target_type, expr);
     394      1055163 :       goto indout;
     395              :     }
     396              : 
     397      4670412 :   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      4670406 :   if (virtual_access && fixed_type_p < 0
     410      4670406 :       && 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      4670373 :   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        65337 :       if (!virtual_access && integer_zerop (offset))
     426        63430 :         return build_nop (ptr_target_type, expr);
     427         1907 :       null_test = error_mark_node;
     428              :     }
     429              : 
     430              :   /* Protect against multiple evaluation if necessary.  */
     431      4606943 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     432          844 :     expr = save_expr (expr);
     433              : 
     434              :   /* Store EXPR and build the real null test just before returning.  */
     435      4606943 :   if (null_test)
     436         1907 :     null_test = expr;
     437              : 
     438              :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     439      4606943 :   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      4500875 :       && !has_empty)
     443              :     {
     444      2649202 :       expr = cp_build_fold_indirect_ref (expr);
     445      2649202 :       expr = build_simple_base_path (expr, binfo);
     446      2649202 :       if (rvalue && lvalue_p (expr))
     447            0 :         expr = move (expr);
     448      2649202 :       if (want_pointer)
     449      2649202 :         expr = build_address (expr);
     450      2649202 :       target_type = TREE_TYPE (expr);
     451      2649202 :       goto out;
     452              :     }
     453              : 
     454      1957741 :   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        69777 :       tree v_offset;
     460              : 
     461        69777 :       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        69771 :           tree t = expr;
     476        69771 :           if (sanitize_flags_p (SANITIZE_VPTR)
     477        69771 :               && 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        69727 :                 t = expr;
     483              :             }
     484        69771 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     485        69771 :           TREE_TYPE (TREE_TYPE (expr)));
     486              :         }
     487              : 
     488        69777 :       if (v_offset == error_mark_node)
     489              :         return error_mark_node;
     490              : 
     491        69777 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     492        69777 :       v_offset = build1 (NOP_EXPR,
     493              :                          build_pointer_type (ptrdiff_type_node),
     494              :                          v_offset);
     495        69777 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     496        69777 :       TREE_CONSTANT (v_offset) = 1;
     497              : 
     498       139554 :       offset = convert_to_integer (ptrdiff_type_node,
     499              :                                    size_diffop_loc (input_location, offset,
     500        69777 :                                                 BINFO_OFFSET (v_binfo)));
     501              : 
     502        69777 :       if (!integer_zerop (offset))
     503          502 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     504              : 
     505        69777 :       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        43710 :         offset = build_if_in_charge
     510        43710 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     511              :            v_offset);
     512              :       else
     513              :         offset = v_offset;
     514              :     }
     515              : 
     516      1957741 :   if (want_pointer)
     517      1957741 :     target_type = ptr_target_type;
     518              : 
     519      1957741 :   if (!integer_zerop (offset))
     520              :     {
     521        70692 :       offset = fold_convert (sizetype, offset);
     522        70692 :       if (code == MINUS_EXPR)
     523          439 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     524        70692 :       expr = fold_build_pointer_plus (expr, offset);
     525              :     }
     526              :   else
     527              :     null_test = NULL;
     528              : 
     529      1957741 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     530              : 
     531      3012937 :  indout:
     532      3012937 :   if (!want_pointer)
     533              :     {
     534      1538678 :       expr = cp_build_fold_indirect_ref (expr);
     535      1538678 :       if (rvalue)
     536       233578 :         expr = move (expr);
     537              :     }
     538              : 
     539      1474259 :  out:
     540      5662139 :   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     16608594 : build_simple_base_path (tree expr, tree binfo)
     553              : {
     554     16608594 :   tree type = BINFO_TYPE (binfo);
     555     16608594 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     556     16608594 :   tree field;
     557              : 
     558     16608594 :   if (d_binfo == NULL_TREE)
     559              :     {
     560      8123487 :       tree temp;
     561              : 
     562      8123487 :       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      8123487 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     569      8123487 :       if (temp)
     570            0 :         expr = cp_build_fold_indirect_ref (temp);
     571              : 
     572      8123487 :       return expr;
     573              :     }
     574              : 
     575              :   /* Recurse.  */
     576      8485107 :   expr = build_simple_base_path (expr, d_binfo);
     577              : 
     578      8485107 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     579     42975969 :        field; field = DECL_CHAIN (field))
     580              :     /* Is this the base field created by build_base_field?  */
     581     42975969 :     if (TREE_CODE (field) == FIELD_DECL
     582      9667070 :         && DECL_FIELD_IS_BASE (field)
     583      9625354 :         && 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     51461199 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     589      8123469 :             || tree_int_cst_equal (byte_position (field),
     590      8123469 :                                    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      8485107 :         int type_quals = cp_type_quals (TREE_TYPE (expr));
     596              : 
     597      8485107 :         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      8485107 :         if (type_quals & TYPE_QUAL_CONST)
     604       750424 :           TREE_READONLY (expr) = 1;
     605      8485107 :         if (type_quals & TYPE_QUAL_VOLATILE)
     606        28085 :           TREE_THIS_VOLATILE (expr) = 1;
     607              : 
     608      8485107 :         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      1885806 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     624              :                  tsubst_flags_t complain)
     625              : {
     626      1885806 :   tree binfo;
     627      1885806 :   tree object_type;
     628              : 
     629      1885806 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     630              :     {
     631       204178 :       object_type = TREE_TYPE (TREE_TYPE (object));
     632       204178 :       type = TREE_TYPE (type);
     633              :     }
     634              :   else
     635      1681628 :     object_type = TREE_TYPE (object);
     636              : 
     637      1888458 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     638              :                        NULL, complain);
     639      1885806 :   if (!binfo || binfo == error_mark_node)
     640           87 :     return error_mark_node;
     641              : 
     642      1885719 :   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      1544209 : convert_to_base_statically (tree expr, tree base)
     652              : {
     653      1544209 :   tree expr_type;
     654              : 
     655      1544209 :   expr_type = TREE_TYPE (expr);
     656      1544209 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     657              :     {
     658              :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     659      1544209 :       if (!is_empty_class (BINFO_TYPE (base)))
     660      1325626 :         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       218583 :       gcc_assert (!processing_template_decl);
     667       218583 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     668       218583 :       if (!integer_zerop (BINFO_OFFSET (base)))
     669          189 :         expr = fold_build_pointer_plus_loc (input_location,
     670          189 :                                             expr, BINFO_OFFSET (base));
     671       218583 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     672       218583 :       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     38280422 : is_empty_base_ref (tree expr)
     685              : {
     686     38280422 :   if (INDIRECT_REF_P (expr))
     687     30765927 :     expr = TREE_OPERAND (expr, 0);
     688     38280422 :   if (TREE_CODE (expr) != NOP_EXPR)
     689              :     return false;
     690      1091158 :   tree type = TREE_TYPE (expr);
     691      1091158 :   if (!POINTER_TYPE_P (type))
     692              :     return false;
     693      1091158 :   type = TREE_TYPE (type);
     694      1091158 :   if (!is_empty_class (type))
     695              :     return false;
     696       454783 :   STRIP_NOPS (expr);
     697       454783 :   tree fromtype = TREE_TYPE (expr);
     698       454783 :   if (!POINTER_TYPE_P (fromtype))
     699              :     return false;
     700       454783 :   fromtype = TREE_TYPE (fromtype);
     701       446507 :   return (CLASS_TYPE_P (fromtype)
     702       446507 :           && !same_type_ignoring_top_level_qualifiers_p (fromtype, type)
     703       900656 :           && DERIVED_FROM_P (type, fromtype));
     704              : }
     705              : 
     706              : tree
     707      1636018 : build_vfield_ref (tree datum, tree type)
     708              : {
     709      1636018 :   tree vfield, vcontext;
     710              : 
     711      1636018 :   if (datum == error_mark_node
     712              :       /* Can happen in case of duplicate base types (c++/59082).  */
     713      1636018 :       || !TYPE_VFIELD (type))
     714              :     return error_mark_node;
     715              : 
     716              :   /* First, convert to the requested type.  */
     717      1636018 :   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      1636018 :   vfield = TYPE_VFIELD (type);
     728      1636018 :   vcontext = DECL_CONTEXT (vfield);
     729      3574495 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     730              :     {
     731      1938477 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     732      1938477 :       type = TREE_TYPE (datum);
     733              :     }
     734              : 
     735      1636018 :   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       467995 : build_vtbl_ref (tree instance, tree idx)
     745              : {
     746       467995 :   tree aref;
     747       467995 :   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       467995 :   int cdtorp = 0;
     753       467995 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     754              : 
     755       467995 :   tree basetype = non_reference (TREE_TYPE (instance));
     756              : 
     757       467995 :   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       467964 :     vtbl = build_vfield_ref (instance, basetype);
     767              : 
     768       467995 :   aref = build_array_ref (input_location, vtbl, idx);
     769       935959 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     770              : 
     771       467995 :   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       467084 : build_vfn_ref (tree instance_ptr, tree idx)
     779              : {
     780       467084 :   tree aref;
     781              : 
     782       467084 :   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       467084 :   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       467084 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
     792       467084 :                  fold_convert (TREE_TYPE (instance_ptr), idx));
     793              : 
     794       467084 :   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      1750710 : 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     35831633 : set_linkage_according_to_type (tree /*type*/, tree decl)
     816              : {
     817     35831633 :   TREE_PUBLIC (decl) = 1;
     818     35831633 :   determine_visibility (decl);
     819     35831633 : }
     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      2174020 : build_vtable (tree class_type, tree name, tree vtable_type)
     827              : {
     828      2174020 :   tree decl;
     829              : 
     830      2174020 :   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      2174020 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     834      2174020 :   DECL_CONTEXT (decl) = class_type;
     835      2174020 :   DECL_ARTIFICIAL (decl) = 1;
     836      2174020 :   TREE_STATIC (decl) = 1;
     837      2174020 :   TREE_READONLY (decl) = 1;
     838      2174020 :   DECL_VIRTUAL_P (decl) = 1;
     839      2185502 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     840      2174020 :   DECL_USER_ALIGN (decl) = true;
     841      2174020 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     842      2174020 :   set_linkage_according_to_type (class_type, decl);
     843              :   /* The vtable has not been defined -- yet.  */
     844      2174020 :   DECL_EXTERNAL (decl) = 1;
     845      2174020 :   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      2174020 :   DECL_IGNORED_P (decl) = 1;
     868              : 
     869      2174020 :   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      8268978 : get_vtable_decl (tree type, int complete)
     880              : {
     881      8268978 :   tree decl;
     882              : 
     883      8268978 :   if (CLASSTYPE_VTABLES (type))
     884      6518268 :     return CLASSTYPE_VTABLES (type);
     885              : 
     886      1750710 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     887      1750710 :   CLASSTYPE_VTABLES (type) = decl;
     888              : 
     889      1750710 :   if (complete)
     890              :     {
     891        39117 :       DECL_EXTERNAL (decl) = 1;
     892        39117 :       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      6507757 : build_primary_vtable (tree binfo, tree type)
     906              : {
     907      6507757 :   tree decl;
     908      6507757 :   tree virtuals;
     909              : 
     910      6507757 :   decl = get_vtable_decl (type, /*complete=*/0);
     911              : 
     912      6507757 :   if (binfo)
     913              :     {
     914      6262915 :       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      1466751 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     920      1466751 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     921      1466751 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     922      1466751 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     923              :     }
     924              :   else
     925              :     {
     926       244842 :       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      1711593 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     933      1711593 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     934      1711593 :   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       716879 : build_secondary_vtable (tree binfo)
     954              : {
     955       716879 :   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       249136 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     963              : 
     964              :   /* Make fresh virtual list, so we can smash it later.  */
     965       249136 :   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       249136 :   BINFO_VTABLE (binfo) = NULL_TREE;
     970       249136 :   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      6979794 : make_new_vtable (tree t, tree binfo)
     978              : {
     979      6979794 :   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      6262915 :     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       716879 :     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      7363264 : modify_vtable_entry (tree t,
    1000              :                      tree binfo,
    1001              :                      tree fndecl,
    1002              :                      tree delta,
    1003              :                      tree *virtuals)
    1004              : {
    1005      7363264 :   tree v;
    1006              : 
    1007      7363264 :   v = *virtuals;
    1008              : 
    1009      7363264 :   if (fndecl != BV_FN (v)
    1010      7363264 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
    1011              :     {
    1012              :       /* We need a new vtable for BINFO.  */
    1013      5263907 :       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      5263907 :       BV_DELTA (v) = delta;
    1025      5263907 :       BV_VCALL_INDEX (v) = NULL_TREE;
    1026      5263907 :       BV_FN (v) = fndecl;
    1027              :     }
    1028      7363264 : }
    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       282417 : iobj_parm_corresponds_to (tree iobj_fn, tree xobj_param, tree context)
    1037              : {
    1038       282417 :   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       282417 :   if (!same_type_ignoring_top_level_qualifiers_p
    1108       282417 :       (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       282408 :   cp_ref_qualifier const iobj_ref_qual = type_memfn_rqual (iobj_fn_type);
    1121              :   /* We only care about cv qualifiers when determining correspondence.  */
    1122       282408 :   static constexpr cp_cv_quals cv_bits = TYPE_QUAL_VOLATILE
    1123              :                                        | TYPE_QUAL_CONST;
    1124       282408 :   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       282408 :   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       563594 :       cp_ref_qualifier const xobj_ref_qual = [&](){
    1183       281797 :           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       281797 :         }(); /* 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       281797 :       cp_cv_quals const xobj_cv_quals
    1193       281797 :         = 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       281797 :       if (iobj_ref_qual != xobj_ref_qual
    1198       281413 :           || 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    413764378 : object_parms_correspond (tree fn, tree method, tree context)
    1215              : {
    1216    413764378 :   tree fn_type = TREE_TYPE (fn);
    1217    413764378 :   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    413764378 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    1223    413764378 :       && 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    411600731 :       if ((cxx_dialect >= cxx20
    1228      3485018 :            || (FUNCTION_REF_QUALIFIED (fn_type)
    1229      3485018 :                == FUNCTION_REF_QUALIFIED (method_type)))
    1230    415085741 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1231    393744382 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1232     18225491 :         return false;
    1233    393375240 :       return true;
    1234              :     }
    1235              :   /* Treat a static member function as corresponding to any object parm.  */
    1236      2163647 :   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         9170 :   else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    1242        17600 :            && DECL_XOBJ_MEMBER_FUNCTION_P (method))
    1243              :     {
    1244        23142 :       auto get_object_param = [] (tree fn)
    1245              :         {
    1246        15428 :           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         7714 :       tree fn_param = get_object_param (fn);
    1251         7714 :       tree method_param = get_object_param (method);
    1252         7714 :       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         5709 :   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    339802896 : add_method (tree type, tree method, bool via_using)
    1273              : {
    1274    339802896 :   if (method == error_mark_node)
    1275              :     return false;
    1276              : 
    1277    339802896 :   gcc_assert (!DECL_EXTERN_C_P (method));
    1278              : 
    1279    339802896 :   tree *slot = find_member_slot (type, DECL_NAME (method));
    1280    339802896 :   tree current_fns = slot ? *slot : NULL_TREE;
    1281              : 
    1282              :   /* See below.  */
    1283    339802896 :   int losem = -1;
    1284              : 
    1285              :   /* Check to see if we've already got this method.  */
    1286   1354517086 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1287              :     {
    1288    571122230 :       tree fn = *iter;
    1289              : 
    1290    571122230 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1291    155902852 :         continue;
    1292              : 
    1293              :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1294              :          overload resolution.  */
    1295      3755569 :       if (via_using && iter.using_p ()
    1296              :           /* Except handle inherited constructors specially.  */
    1297    419356226 :           && ! DECL_CONSTRUCTOR_P (fn))
    1298              :         {
    1299      1519863 :           if (fn == method)
    1300              :             /* Don't add the same one twice.  */
    1301        12429 :             return false;
    1302      1519854 :           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    413699515 :       if (!object_parms_correspond (fn, method, type))
    1322     18228569 :         continue;
    1323              : 
    1324    395470946 :       tree fn_type = TREE_TYPE (fn);
    1325    395470946 :       tree method_type = TREE_TYPE (method);
    1326              : 
    1327    395470946 :       tree real_fn = fn;
    1328    395470946 :       tree real_method = method;
    1329              : 
    1330              :       /* Templates and conversion ops must match return types.  */
    1331    790786014 :       if ((DECL_CONV_FN_P (fn) || TREE_CODE (fn) == TEMPLATE_DECL)
    1332    546773428 :           && !same_type_p (TREE_TYPE (fn_type), TREE_TYPE (method_type)))
    1333      4245320 :         continue;
    1334              : 
    1335              :       /* For templates, the template parameters must be identical.  */
    1336    391225626 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    1337              :         {
    1338    294425924 :           if (!comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1339    147212962 :                                     DECL_TEMPLATE_PARMS (method)))
    1340    102205832 :             continue;
    1341              : 
    1342     45007130 :           real_fn = DECL_TEMPLATE_RESULT (fn);
    1343     45007130 :           real_method = DECL_TEMPLATE_RESULT (method);
    1344              :         }
    1345              : 
    1346    289019794 :       tree parms1 = TYPE_ARG_TYPES (fn_type);
    1347    289019794 :       tree parms2 = TYPE_ARG_TYPES (method_type);
    1348    289019794 :       if (! DECL_STATIC_FUNCTION_P (real_fn))
    1349    287650397 :         parms1 = TREE_CHAIN (parms1);
    1350    289019794 :       if (! DECL_STATIC_FUNCTION_P (real_method))
    1351    287642357 :         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    289019794 :       if (ctor_omit_inherited_parms (real_fn))
    1356          729 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_CLONED_FUNCTION (real_fn));
    1357    289019794 :       if (ctor_omit_inherited_parms (real_method))
    1358          330 :         parms2 = (FUNCTION_FIRST_USER_PARMTYPE
    1359              :                   (DECL_CLONED_FUNCTION (real_method)));
    1360              : 
    1361    289019794 :       if (!compparms (parms1, parms2))
    1362    285515402 :         continue;
    1363              : 
    1364      3504392 :       tree fn_constraints = get_constraints (fn);
    1365      3504392 :       tree method_constraints = get_constraints (method);
    1366              : 
    1367      3504392 :       if (fn_constraints && method_constraints
    1368      2950926 :           && DECL_CONTEXT (fn) != type
    1369      3504404 :           && !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      3504392 :       if (!equivalent_constraints (fn_constraints, method_constraints))
    1388              :         {
    1389      3316236 :           if (processing_template_decl)
    1390              :             /* We can't check satisfaction in dependent context, wait until
    1391              :                the class is instantiated.  */
    1392       490781 :             continue;
    1393              : 
    1394      2825455 :           special_function_kind sfk = special_memfn_p (method);
    1395              : 
    1396      5510881 :           if (sfk == sfk_none
    1397       626226 :               || DECL_INHERITED_CTOR (fn)
    1398      3138491 :               || 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      2685426 :             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       140029 :           bool dtor = (sfk == sfk_destructor);
    1411       140029 :           if (losem == -1)
    1412       277215 :             losem = ((!dtor && DECL_DELETED_FN (method))
    1413       276938 :                      || !constraints_satisfied_p (method));
    1414       137742 :           bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1415       149833 :                         || !constraints_satisfied_p (fn));
    1416       140029 :           int win;
    1417       140029 :           if (losem || losef)
    1418       136332 :             win = losem - losef;
    1419              :           else
    1420         3697 :             win = more_constrained (fn, method);
    1421       140029 :           if (win > 0)
    1422              :             /* Leave FN in the method vec, discard METHOD.  */
    1423              :             return false;
    1424       131032 :           else if (win < 0)
    1425              :             {
    1426              :               /* Remove FN, add METHOD.  */
    1427       117978 :               current_fns = iter.remove_node (current_fns);
    1428       117978 :               continue;
    1429              :             }
    1430              :           else
    1431              :             /* Let them coexist for now.  */
    1432        13054 :             continue;
    1433              :         }
    1434              : 
    1435              :       /* If these are versions of the same function, process and
    1436              :          move on.  */
    1437       188183 :       if (TREE_CODE (fn) == FUNCTION_DECL
    1438       188156 :           && maybe_version_functions (method, fn))
    1439           27 :         continue;
    1440              : 
    1441       376258 :       if (DECL_INHERITED_CTOR (method))
    1442              :         {
    1443         6324 :           if (!DECL_INHERITED_CTOR (fn))
    1444              :             /* Defer to the other function.  */
    1445         3090 :             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       184967 :       if (via_using)
    1478              :         /* Defer to the local function.  */
    1479              :         return false;
    1480       184955 :       else if (iter.using_p ()
    1481       184955 :                ||  (flag_new_inheriting_ctors
    1482       233410 :                     && DECL_INHERITED_CTOR (fn)))
    1483              :         {
    1484              :           /* Remove the inherited function.  */
    1485       184634 :           current_fns = iter.remove_node (current_fns);
    1486       184634 :           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    339790467 :   current_fns = ovl_insert (method, current_fns, via_using);
    1500              : 
    1501    614652939 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1502    611996669 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1503              :     return false;
    1504              : 
    1505    339790449 :   if (!slot)
    1506    149748707 :     slot = add_member_slot (type, DECL_NAME (method));
    1507              : 
    1508              :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1509    339790449 :   grok_special_member_properties (method);
    1510              : 
    1511    339790449 :   *slot = current_fns;
    1512              : 
    1513    339790449 :   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      2920469 : alter_access (tree t, tree fdecl, tree access)
    1523              : {
    1524      2920469 :   tree elem;
    1525              : 
    1526      2920469 :   retrofit_lang_decl (fdecl);
    1527              : 
    1528      2920469 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1529              : 
    1530      2920469 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1531      2920469 :   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      2920469 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1552              :                                      tf_warning_or_error);
    1553      2920469 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1554      2920469 :       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       393554 : declared_access (tree decl)
    1563              : {
    1564       393554 :   return (TREE_PRIVATE (decl) ? access_private_node
    1565       383707 :           : TREE_PROTECTED (decl) ? access_protected_node
    1566       393554 :           : 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    187507151 : maybe_push_used_methods (tree decl)
    1575              : {
    1576    187507151 :   if (TREE_CODE (decl) != USING_DECL)
    1577              :     return false;
    1578      3089274 :   tree used = strip_using_decl (decl);
    1579      3089274 :   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      6000272 :   for (tree f : ovl_range (used))
    1585              :     {
    1586      5657922 :       if (DECL_CONSTRUCTOR_P (f))
    1587              :         /* Inheriting constructors are handled separately.  */
    1588       101698 :         return false;
    1589              : 
    1590      2727263 :       bool added = add_method (current_class_type, f, true);
    1591              : 
    1592      2727263 :       if (added)
    1593      2727242 :         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      1744403 :   return true;
    1608              : }
    1609              : 
    1610              : /* Process the USING_DECL, which is a member of T.  */
    1611              : 
    1612              : static void
    1613      2119439 : handle_using_decl (tree using_decl, tree t)
    1614              : {
    1615      2119439 :   tree decl = USING_DECL_DECLS (using_decl);
    1616              : 
    1617      2119439 :   gcc_assert (!processing_template_decl && decl);
    1618              : 
    1619      2119439 :   cp_emit_debug_info_for_using (decl, t);
    1620              : 
    1621      2119439 :   if (is_overloaded_fn (decl))
    1622              :     /* Handled in maybe_push_used_methods.  */
    1623      2119439 :     return;
    1624              : 
    1625       375202 :   tree name = DECL_NAME (using_decl);
    1626       375202 :   tree old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1627              :                                   tf_warning_or_error);
    1628       375202 :   if (old_value)
    1629              :     {
    1630       375202 :       old_value = OVL_FIRST (old_value);
    1631              : 
    1632       375202 :       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       375202 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (using_decl));
    1662       375202 :   tree access = declared_access (using_decl);
    1663              : 
    1664              :   /* Make type T see field decl FDECL with access ACCESS.  */
    1665       375202 :   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       193227 :     alter_access (t, decl, access);
    1685       375202 : }
    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     16758144 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1702              : {
    1703     16758144 :   if (!IDENTIFIER_MARKED (id))
    1704              :     {
    1705      5731655 :       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      5731637 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1710              : 
    1711              :           /* Don't inherit this tag multiple times.  */
    1712      5731637 :           IDENTIFIER_MARKED (id) = true;
    1713              : 
    1714      5731637 :           ABI_TAG_INHERITED (p->tags) = true;
    1715      5731637 :           if (TYPE_P (p->t))
    1716              :             {
    1717              :               /* Tags inherited from type template arguments are only used
    1718              :                  to avoid warnings.  */
    1719      5688441 :               ABI_TAG_NOT_MANGLED (p->tags) = true;
    1720      5688441 :               return;
    1721              :             }
    1722              :           /* For functions and variables we want to warn, too.  */
    1723              :         }
    1724              : 
    1725              :       /* Otherwise we're diagnosing missing tags.  */
    1726        43214 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1727              :         {
    1728        42801 :           auto_diagnostic_group d;
    1729        42801 :           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        42801 :         }
    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   2476948856 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1769              : {
    1770   2476948856 :   if (!attr)
    1771              :     return;
    1772    293648280 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1773    102694503 :        attr = TREE_CHAIN (attr))
    1774    205389036 :     for (tree list = TREE_VALUE (attr); list;
    1775    102694533 :          list = TREE_CHAIN (list))
    1776              :       {
    1777    102694533 :         tree tag = TREE_VALUE (list);
    1778    102694533 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1779    102694533 :         if (tp)
    1780     16758144 :           check_tag (tag, id, tp, p);
    1781              :         else
    1782     85936389 :           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    919724537 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1791              : {
    1792   3396673393 :   while (t != global_namespace)
    1793              :     {
    1794   2476948856 :       tree attr;
    1795   2476948856 :       if (TYPE_P (t))
    1796              :         {
    1797    915709191 :           attr = TYPE_ATTRIBUTES (t);
    1798    915709191 :           t = CP_TYPE_CONTEXT (t);
    1799              :         }
    1800              :       else
    1801              :         {
    1802   1561239665 :           attr = DECL_ATTRIBUTES (t);
    1803   1561239665 :           t = CP_DECL_CONTEXT (t);
    1804              :         }
    1805   2476948856 :       mark_or_check_attr_tags (attr, tp, p, val);
    1806              :     }
    1807    919724537 : }
    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    764538594 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1815              : {
    1816    764538594 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1817              :     /* Tell cp_walk_subtrees to look though typedefs. [PR98481] */
    1818    493769842 :     *walk_subtrees = 2;
    1819              : 
    1820    764538594 :   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    138840683 :   *walk_subtrees = false;
    1826              : 
    1827    138840683 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1828              : 
    1829    138840683 :   mark_or_check_tags (*tp, tp, p, false);
    1830              : 
    1831    138840683 :   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   1296528214 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1839              : {
    1840   1296528214 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1841              :     /* Tell cp_walk_subtrees to look though typedefs.  */
    1842    920919240 :     *walk_subtrees = 2;
    1843              : 
    1844   1296528214 :   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    175962504 :   *walk_subtrees = false;
    1850              : 
    1851    175962504 :   bool *valp = static_cast<bool*>(data);
    1852              : 
    1853    175962504 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1854              : 
    1855    175962504 :   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    604921350 : mark_abi_tags (tree t, bool val)
    1863              : {
    1864    604921350 :   mark_or_check_tags (t, NULL, NULL, val);
    1865    604921350 :   if (DECL_P (t))
    1866              :     {
    1867    782335858 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1868    674744270 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1869              :         {
    1870              :           /* Template arguments are part of the signature.  */
    1871     30696430 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1872     76564818 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1873              :             {
    1874     45868388 :               tree arg = TREE_VEC_ELT (level, j);
    1875     45868388 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1876              :             }
    1877              :         }
    1878    392411596 :       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   1007808412 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1882    677445672 :              arg = TREE_CHAIN (arg))
    1883    677445672 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1884              :                                            mark_abi_tags_r, &val);
    1885              :     }
    1886    604921350 : }
    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    237089944 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1894              : {
    1895    237089944 :   bool inherit = DECL_P (t);
    1896              : 
    1897    237089944 :   if (!inherit && !warn_abi_tag)
    1898              :     return NULL_TREE;
    1899              : 
    1900    196383999 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1901    196383999 :   if (!TREE_PUBLIC (decl))
    1902              :     /* No need to worry about things local to this TU.  */
    1903              :     return NULL_TREE;
    1904              : 
    1905    196205819 :   mark_abi_tags (t, true);
    1906              : 
    1907    196205819 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1908    196205819 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1909    196205819 :   if (inherit)
    1910    196205798 :     data.tags = NULL_TREE;
    1911              : 
    1912    196205819 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1913              : 
    1914    196205819 :   if (!(inherit && data.tags))
    1915              :     /* We don't need to do anything with data.tags.  */;
    1916        43181 :   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        43148 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1925        43148 :       if (attr)
    1926            0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1927              :       else
    1928        43148 :         DECL_ATTRIBUTES (t)
    1929        86296 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1930              :     }
    1931              : 
    1932    196205819 :   mark_abi_tags (t, false);
    1933              : 
    1934    196205819 :   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    208941439 : check_abi_tags (tree decl)
    1942              : {
    1943    208941439 :   if (VAR_P (decl))
    1944     31131588 :     check_abi_tags (decl, TREE_TYPE (decl));
    1945    177809851 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1946    177806531 :            && !DECL_CONV_FN_P (decl)
    1947    352993127 :            && !mangle_return_type_p (decl))
    1948    165168826 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1949    208941439 : }
    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    106613129 : inherit_targ_abi_tags (tree t)
    1972              : {
    1973    106254856 :   if (!CLASS_TYPE_P (t)
    1974    212867985 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1975       358273 :     return;
    1976              : 
    1977    106254856 :   mark_abi_tags (t, true);
    1978              : 
    1979    106254856 :   tree args = CLASSTYPE_TI_ARGS (t);
    1980    106254856 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1981    637529318 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1982              :     {
    1983    217651648 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1984    299390138 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1985              :         {
    1986    190564314 :           tree arg = TREE_VEC_ELT (level, j);
    1987    190564314 :           data.subob = arg;
    1988    190564314 :           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    106254856 :   if (data.tags)
    1995              :     {
    1996      5688441 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    1997      5688441 :       if (attr)
    1998            3 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1999              :       else
    2000      5688438 :         TYPE_ATTRIBUTES (t)
    2001     11376876 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    2002              :     }
    2003              : 
    2004    106254856 :   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     49090220 : check_bases (tree t,
    2040              :              int* cant_have_const_ctor_p,
    2041              :              int* no_const_asn_ref_p)
    2042              : {
    2043     49090220 :   int i;
    2044     49090220 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    2045     49090220 :   int seen_tm_mask = 0;
    2046     49090220 :   tree base_binfo;
    2047     49090220 :   tree binfo;
    2048     49090220 :   tree field = NULL_TREE;
    2049              : 
    2050     49090220 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2051    221798525 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    2052    179399261 :       if (TREE_CODE (field) == FIELD_DECL)
    2053              :         break;
    2054              : 
    2055     72438305 :   for (binfo = TYPE_BINFO (t), i = 0;
    2056     72438305 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2057              :     {
    2058     23348085 :       tree basetype = TREE_TYPE (base_binfo);
    2059              : 
    2060     23348085 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    2061              : 
    2062     23348085 :       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     23348085 :       if (!CLASSTYPE_LITERAL_P (basetype))
    2068      1658602 :         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     23348085 :       if (TYPE_HAS_COPY_CTOR (basetype)
    2075     23348085 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    2076           60 :         *cant_have_const_ctor_p = 1;
    2077     23348085 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    2078     23348085 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    2079           18 :         *no_const_asn_ref_p = 1;
    2080              : 
    2081     23348085 :       if (BINFO_VIRTUAL_P (base_binfo))
    2082              :         /* A virtual base does not effect nearly emptiness.  */
    2083              :         ;
    2084     23302080 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    2085              :         {
    2086       265371 :           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     23036709 :       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      2088100 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2098              : 
    2099              :       /* A lot of properties from the bases also apply to the derived
    2100              :          class.  */
    2101     23348085 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    2102     70044255 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2103     23348085 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    2104     23348085 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    2105     23348085 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    2106     23348085 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    2107     46696170 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    2108     23348085 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    2109     70044255 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    2110     23348085 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    2111     23348085 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    2112     23348085 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    2113     70044255 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    2114     23348085 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    2115     46696170 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    2116     23348085 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    2117     23348085 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    2118              :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    2119              :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    2120     23348085 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    2121              :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    2122              :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    2123     23348085 :       if (TYPE_HAS_MUTABLE_P (basetype))
    2124       955730 :         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     23348085 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    2130     23348085 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2131              :         {
    2132     21443141 :           tree basefield;
    2133              :           /* ...has no base classes of the same type as the first non-static
    2134              :              data member...  */
    2135       500984 :           if (field && DECL_CONTEXT (field) == t
    2136     21890908 :               && (same_type_ignoring_top_level_qualifiers_p
    2137       447767 :                   (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     21443012 :           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    308961038 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    2147    287518402 :                  basefield = DECL_CHAIN (basefield))
    2148    288447164 :               if (TREE_CODE (basefield) == FIELD_DECL
    2149    289743146 :                   && !(DECL_FIELD_IS_BASE (basefield)
    2150      1295982 :                        && is_empty_field (basefield)))
    2151              :                 {
    2152       928762 :                   if (field)
    2153       126410 :                     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     23348085 :       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     23348085 :       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     49090220 :   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     49090220 : }
    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     49090220 : determine_primary_bases (tree t)
    2189              : {
    2190     49090220 :   unsigned i;
    2191     49090220 :   tree primary = NULL_TREE;
    2192     49090220 :   tree type_binfo = TYPE_BINFO (t);
    2193     49090220 :   tree base_binfo;
    2194              : 
    2195              :   /* Determine the primary bases of our bases.  */
    2196     76138319 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2197     27048099 :        base_binfo = TREE_CHAIN (base_binfo))
    2198              :     {
    2199     27048099 :       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     27048099 :       if (!BINFO_VIRTUAL_P (base_binfo))
    2204              :         {
    2205     26856079 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    2206     26856079 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    2207              : 
    2208     26856079 :           if (parent_primary
    2209     26856079 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2210              :                                     BINFO_TYPE (parent_primary)))
    2211              :             /* We are the primary binfo.  */
    2212      1084235 :             BINFO_PRIMARY_P (base_binfo) = 1;
    2213              :         }
    2214              :       /* Determine if we have a virtual primary base, and mark it so.
    2215              :        */
    2216     28139469 :       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     70789921 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    2246              :     {
    2247     23164803 :       tree basetype = BINFO_TYPE (base_binfo);
    2248              : 
    2249     23164803 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    2250              :         {
    2251      1465102 :           primary = base_binfo;
    2252      1465102 :           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     71386765 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2263     23761647 :        base_binfo = TREE_CHAIN (base_binfo))
    2264     23763215 :     if (BINFO_VIRTUAL_P (base_binfo)
    2265     23763215 :         && 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     23761647 :           primary = base_binfo;
    2276              :       }
    2277              : 
    2278     47623550 :  found:
    2279              :   /* If we've got a primary base, use it.  */
    2280     49090220 :   if (primary)
    2281              :     {
    2282      1466751 :       tree basetype = BINFO_TYPE (primary);
    2283              : 
    2284      1466751 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    2285      1466751 :       if (BINFO_PRIMARY_P (primary))
    2286              :         /* We are stealing a primary base.  */
    2287           81 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    2288      1466751 :       BINFO_PRIMARY_P (primary) = 1;
    2289      1466751 :       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      1466751 :       primary = TYPE_BINFO (basetype);
    2304              : 
    2305      1466751 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    2306      1466751 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    2307      1466751 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    2308              :     }
    2309     49090220 : }
    2310              : 
    2311              : /* Update the variant types of T.  */
    2312              : 
    2313              : void
    2314    159301673 : fixup_type_variants (tree type)
    2315              : {
    2316    159301673 :   if (!type)
    2317              :     return;
    2318              : 
    2319    159301673 :   for (tree variant = TYPE_NEXT_VARIANT (type);
    2320    319964409 :        variant;
    2321    160662736 :        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    160662736 :       TYPE_HAS_USER_CONSTRUCTOR (variant) = TYPE_HAS_USER_CONSTRUCTOR (type);
    2326    160662736 :       TYPE_NEEDS_CONSTRUCTING (variant) = TYPE_NEEDS_CONSTRUCTING (type);
    2327    321325472 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variant)
    2328    160662736 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    2329              : 
    2330    160662736 :       TYPE_POLYMORPHIC_P (variant) = TYPE_POLYMORPHIC_P (type);
    2331    160662736 :       CLASSTYPE_FINAL (variant) = CLASSTYPE_FINAL (type);
    2332              : 
    2333    160662736 :       TYPE_BINFO (variant) = TYPE_BINFO (type);
    2334              : 
    2335              :       /* Copy whatever these are holding today.  */
    2336    160662736 :       TYPE_VFIELD (variant) = TYPE_VFIELD (type);
    2337    160662736 :       TYPE_FIELDS (variant) = TYPE_FIELDS (type);
    2338              : 
    2339    160662736 :       TYPE_SIZE (variant) = TYPE_SIZE (type);
    2340    160662736 :       TYPE_SIZE_UNIT (variant) = TYPE_SIZE_UNIT (type);
    2341              : 
    2342    160662736 :       if (!TYPE_USER_ALIGN (variant)
    2343      2708360 :           || TYPE_NAME (variant) == TYPE_NAME (type)
    2344    162038060 :           || TYPE_ALIGN_RAW (variant) < TYPE_ALIGN_RAW (type))
    2345              :         {
    2346    159287412 :           TYPE_ALIGN_RAW (variant) =  TYPE_ALIGN_RAW (type);
    2347    159287412 :           TYPE_USER_ALIGN (variant) = TYPE_USER_ALIGN (type);
    2348              :         }
    2349              : 
    2350    160662736 :       TYPE_PRECISION (variant) = TYPE_PRECISION (type);
    2351    160662736 :       TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type);
    2352    160662736 :       TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type);
    2353    160662736 :       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        37352 : fixup_may_alias (tree klass)
    2363              : {
    2364        37352 :   tree t, v;
    2365              : 
    2366        55665 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    2367        54924 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2368        36611 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2369        37373 :   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        37352 : }
    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     95690145 : fixup_attribute_variants (tree t)
    2380              : {
    2381     95690145 :   tree variants;
    2382              : 
    2383     95690145 :   if (!t)
    2384              :     return;
    2385              : 
    2386     95690145 :   tree attrs = TYPE_ATTRIBUTES (t);
    2387     95690145 :   unsigned align = TYPE_ALIGN (t);
    2388     95690145 :   bool user_align = TYPE_USER_ALIGN (t);
    2389     95690145 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2390     95690145 :   bool packed = TYPE_PACKED (t);
    2391              : 
    2392     95690145 :   if (may_alias)
    2393        18787 :     fixup_may_alias (t);
    2394              : 
    2395     95690145 :   for (variants = TYPE_NEXT_VARIANT (t);
    2396    144243319 :        variants;
    2397     48553174 :        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     48553174 :       TYPE_ATTRIBUTES (variants) = attrs;
    2402     48553174 :       unsigned valign = align;
    2403     48553174 :       if (TYPE_USER_ALIGN (variants))
    2404        24523 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2405              :       else
    2406     48528651 :         TYPE_USER_ALIGN (variants) = user_align;
    2407     48553174 :       SET_TYPE_ALIGN (variants, valign);
    2408     48553174 :       TYPE_PACKED (variants) = packed;
    2409     48553174 :       if (may_alias)
    2410        18565 :         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     49090220 : 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     49090220 :   if (!has_trivial_abi_attribute (t)
    2425     49090220 :       && (type_has_nontrivial_copy_init (t)
    2426     44590761 :           || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)))
    2427              :     {
    2428      4994120 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2429      4994120 :       SET_TYPE_MODE (t, BLKmode);
    2430      4994120 :       TREE_ADDRESSABLE (t) = 1;
    2431              :     }
    2432              : 
    2433     49090220 :   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      1535366 :     get_pure_virtuals (t);
    2443              : 
    2444              :   /* Fix up variants (if any).  */
    2445     49090220 :   fixup_type_variants (t);
    2446     49090220 : }
    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     29351013 : maybe_warn_about_overly_private_class (tree t)
    2457              : {
    2458     29351013 :   int has_member_fn = 0;
    2459     29351013 :   int has_nonprivate_method = 0;
    2460     29351013 :   bool nonprivate_ctor = false;
    2461              : 
    2462     29351013 :   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     29351061 :       || 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      1711593 : layout_vtable_decl (tree binfo, int n)
    2608              : {
    2609      1711593 :   tree atype;
    2610      1711593 :   tree vtable;
    2611              : 
    2612      1711593 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2613      1711593 :   layout_type (atype);
    2614              : 
    2615              :   /* We may have to grow the vtable.  */
    2616      1711593 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2617      1711593 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2618              :     {
    2619       576126 :       TREE_TYPE (vtable) = atype;
    2620       576126 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2621       576126 :       layout_decl (vtable, 0);
    2622              :     }
    2623      1711593 : }
    2624              : 
    2625              : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2626              :    have the same signature.  */
    2627              : 
    2628              : int
    2629     77891491 : 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    119366229 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2634     98525795 :       && 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    190497792 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2641              :     return 0;
    2642              : 
    2643     47354418 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2644     47354418 :       || (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     16710623 :       tree fntype = TREE_TYPE (fndecl);
    2650     16710623 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2651     16710623 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2652     16710250 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2653     33420870 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2654     16710247 :                         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       227903 : base_derived_from (tree derived, tree base)
    2665              : {
    2666       227903 :   tree probe;
    2667              : 
    2668       228179 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2669              :     {
    2670       228074 :       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      7780823 : 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     12832233 : dfs_find_final_overrider_1 (tree binfo,
    2698              :                             find_final_overrider_data *ffod,
    2699              :                             unsigned depth)
    2700              : {
    2701     12832233 :   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     12832233 :   if (depth)
    2706              :     {
    2707      4824047 :       depth--;
    2708      4824047 :       if (dfs_find_final_overrider_1
    2709      4824047 :           (ffod->path[depth], ffod, depth))
    2710              :         return true;
    2711              :     }
    2712              : 
    2713     10269492 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2714     10269492 :   if (method)
    2715              :     {
    2716      8008186 :       tree *candidate = &ffod->candidates;
    2717              : 
    2718              :       /* Remove any candidates overridden by this new function.  */
    2719      8008708 :       while (*candidate)
    2720              :         {
    2721              :           /* If *CANDIDATE overrides METHOD, then METHOD
    2722              :              cannot override anything else on the list.  */
    2723       227381 :           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      7781327 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2734      7781327 :       return true;
    2735              :     }
    2736              : 
    2737              :   return false;
    2738              : }
    2739              : 
    2740              : /* Called from find_final_overrider via dfs_walk.  */
    2741              : 
    2742              : static tree
    2743     29428772 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2744              : {
    2745     29428772 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2746              : 
    2747     29428772 :   if (binfo == ffod->declaring_base)
    2748     16016372 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2749     29428772 :   ffod->path.safe_push (binfo);
    2750              : 
    2751     29428772 :   return NULL_TREE;
    2752              : }
    2753              : 
    2754              : static tree
    2755     29428772 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2756              : {
    2757     29428772 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2758     29428772 :   ffod->path.pop ();
    2759              : 
    2760     29428772 :   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      7780823 : find_final_overrider (tree derived, tree binfo, tree fn)
    2770              : {
    2771      7780823 :   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      7780823 :   if (DECL_THUNK_P (fn))
    2792            0 :     fn = THUNK_TARGET (fn);
    2793              : 
    2794              :   /* Determine the depth of the hierarchy.  */
    2795      7780823 :   ffod.fn = fn;
    2796      7780823 :   ffod.declaring_base = binfo;
    2797      7780823 :   ffod.candidates = NULL_TREE;
    2798      7780823 :   ffod.path.create (30);
    2799              : 
    2800      7780823 :   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      7780823 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2805           36 :     return error_mark_node;
    2806              : 
    2807              :   return ffod.candidates;
    2808      7780823 : }
    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       351237 : get_vcall_index (tree fn, tree type)
    2815              : {
    2816       351237 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2817       351237 :   tree_pair_p p;
    2818       351237 :   unsigned ix;
    2819              : 
    2820       357190 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2821      1068174 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2822       362838 :         || same_signature_p (fn, p->purpose))
    2823       351237 :       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      7363273 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2854              :                             unsigned ix)
    2855              : {
    2856      7363273 :   tree b;
    2857      7363273 :   tree overrider;
    2858      7363273 :   tree delta;
    2859      7363273 :   tree virtual_base;
    2860      7363273 :   tree first_defn;
    2861      7363273 :   tree overrider_fn, overrider_target;
    2862      7363273 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2863      7363273 :   tree over_return, base_return;
    2864      7363273 :   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      9565277 :   for (b = binfo; ; b = get_primary_binfo (b))
    2870              :     {
    2871      9565277 :       gcc_assert (b);
    2872      9565277 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2873              :         break;
    2874              : 
    2875              :       /* The nearest definition is from a lost primary.  */
    2876      2202004 :       if (BINFO_LOST_PRIMARY_P (b))
    2877          412 :         lost = true;
    2878              :     }
    2879      7363273 :   first_defn = b;
    2880              : 
    2881              :   /* Find the final overrider.  */
    2882      7363273 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2883      7363273 :   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      7363264 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2889              : 
    2890              :   /* Check for adjusting covariant return types.  */
    2891      7363264 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2892      7363264 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2893              : 
    2894      7363264 :   if (INDIRECT_TYPE_P (over_return)
    2895       638584 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2896       638575 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2897        41027 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2898              :       /* If the overrider is invalid, don't even try.  */
    2899      7404285 :       && !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        40988 :       tree fixed_offset, virtual_offset;
    2906              : 
    2907        40988 :       over_return = TREE_TYPE (over_return);
    2908        40988 :       base_return = TREE_TYPE (base_return);
    2909              : 
    2910        40988 :       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        40934 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2926        40934 :                (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        40988 :       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      7322276 :     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      7363264 :   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      7363264 :   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      7555962 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    3035              :     {
    3036              :       /* If we find the final overrider, then we can stop
    3037              :          walking.  */
    3038      7555962 :       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       543935 :       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      7363264 :   if (virtual_base)
    3056              :     /* The `this' pointer needs to be adjusted from the declaration to
    3057              :        the nearest virtual base.  */
    3058      1053711 :     delta = size_diffop_loc (input_location,
    3059       351237 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    3060       351237 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    3061      7012027 :   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     21034980 :     delta = size_diffop_loc (input_location,
    3072      7011660 :                          fold_convert (ssizetype,
    3073              :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    3074      7011660 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    3075              : 
    3076      7363264 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    3077              : 
    3078      7363264 :   if (virtual_base)
    3079       702474 :     BV_VCALL_INDEX (*virtuals)
    3080       702474 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    3081              :   else
    3082      7012027 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    3083              : 
    3084      7363264 :   BV_LOST_PRIMARY (*virtuals) = lost;
    3085              : }
    3086              : 
    3087              : /* Called from modify_all_vtables via dfs_walk.  */
    3088              : 
    3089              : static tree
    3090     52478945 : dfs_modify_vtables (tree binfo, void* data)
    3091              : {
    3092     52478945 :   tree t = (tree) data;
    3093     52478945 :   tree virtuals;
    3094     52478945 :   tree old_virtuals;
    3095     52478945 :   unsigned ix;
    3096              : 
    3097     52478945 :   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      4510066 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    3103      4510066 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    3104              :     /* Don't do the primary vtable, if it's new.  */
    3105              :     return NULL_TREE;
    3106              : 
    3107      4265224 :   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      1715887 :   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      1715887 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    3120      1715887 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    3121      9079160 :        virtuals;
    3122      7363273 :        ix++, virtuals = TREE_CHAIN (virtuals),
    3123      7363273 :          old_virtuals = TREE_CHAIN (old_virtuals))
    3124      7363273 :     update_vtable_entry_for_fn (t,
    3125              :                                 binfo,
    3126      7363273 :                                 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     49090220 : modify_all_vtables (tree t, tree virtuals)
    3143              : {
    3144     49090220 :   tree binfo = TYPE_BINFO (t);
    3145     49090220 :   tree *fnsp;
    3146              : 
    3147              :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    3148     49090220 :   if (TYPE_CONTAINS_VPTR_P (t))
    3149      1711593 :     get_vtable_decl (t, false);
    3150              : 
    3151              :   /* Update all of the vtables.  */
    3152     49090220 :   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     56847565 :   for (fnsp = &virtuals; *fnsp; )
    3159              :     {
    3160      7757345 :       tree fn = TREE_VALUE (*fnsp);
    3161              : 
    3162      7757345 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    3163     12553334 :           || DECL_VINDEX (fn) == error_mark_node)
    3164              :         {
    3165              :           /* We don't need to adjust the `this' pointer when
    3166              :              calling this function.  */
    3167      2961356 :           BV_DELTA (*fnsp) = integer_zero_node;
    3168      2961356 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    3169              : 
    3170              :           /* This is a function not already in our vtable.  Keep it.  */
    3171      2961356 :           fnsp = &TREE_CHAIN (*fnsp);
    3172              :         }
    3173              :       else
    3174              :         /* We've already got an entry for this function.  Skip it.  */
    3175      4795989 :         *fnsp = TREE_CHAIN (*fnsp);
    3176              :     }
    3177              : 
    3178     49090220 :   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    143583853 : check_for_override (tree decl, tree ctype)
    3216              : {
    3217    143583853 :   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    117178740 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    3230    102999561 :        || DECL_CONV_FN_P (decl))
    3231     15744668 :       && look_for_overrides (ctype, decl)
    3232              :       /* Check staticness after we've checked if we 'override'.  */
    3233    120636907 :       && !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      3458161 :       DECL_VINDEX (decl) = decl;
    3239              : 
    3240      3458161 :       if (warn_override
    3241            6 :           && !DECL_OVERRIDE_P (decl)
    3242            5 :           && !DECL_FINAL_P (decl)
    3243      3458165 :           && !DECL_DESTRUCTOR_P (decl))
    3244            3 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    3245              :                     "%qD can be marked override", decl);
    3246              :     }
    3247    113720579 :   else if (DECL_OVERRIDE_P (decl))
    3248           20 :     error ("%q+#D marked %<override%>, but does not override", decl);
    3249              : 
    3250    117178740 :   if (DECL_VIRTUAL_P (decl))
    3251              :     {
    3252              :       /* Remember this identifier is virtual name.  */
    3253      6161932 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    3254              : 
    3255      6161932 :       if (!DECL_VINDEX (decl))
    3256              :         /* It's a new vfunc.  */
    3257      2703787 :         DECL_VINDEX (decl) = error_mark_node;
    3258              : 
    3259      6161932 :       if (DECL_DESTRUCTOR_P (decl))
    3260      1595385 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    3261              : 
    3262      6161932 :       if (DECL_HAS_CONTRACTS_P (decl))
    3263           12 :         error_at (DECL_SOURCE_LOCATION (decl),
    3264              :                   "contracts cannot be added to virtual functions");
    3265              :     }
    3266    111016808 :   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       423911 : warn_hidden (tree t)
    3275              : {
    3276       423911 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    3277      2113481 :     for (unsigned ix = member_vec->length (); ix--;)
    3278              :       {
    3279      1970413 :         tree fns = (*member_vec)[ix];
    3280              : 
    3281      1970413 :         if (!OVL_P (fns))
    3282      1970255 :           continue;
    3283              : 
    3284      1080372 :         tree name = OVL_NAME (fns);
    3285      1080372 :         size_t num_fns = 0; /* The number of fndecls in fns.  */
    3286      1080372 :         auto_vec<tree, 20> base_fndecls;
    3287      1080372 :         tree base_binfo;
    3288      1080372 :         tree binfo;
    3289      1080372 :         unsigned j;
    3290      1080372 :         size_t num_overriders = 0;
    3291      1080372 :         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      1080372 :         hash_map<tree, tree> hidden_base_fndecls;
    3295              : 
    3296      1080372 :         if (IDENTIFIER_CDTOR_P (name))
    3297       358919 :           continue;
    3298              : 
    3299              :         /* Iterate through all of the base classes looking for possibly
    3300              :            hidden functions.  */
    3301       929594 :         for (binfo = TYPE_BINFO (t), j = 0;
    3302       929594 :              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       721453 :         if (base_fndecls.is_empty ())
    3310       702017 :           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      1080372 :       }
    3372       423911 : }
    3373              : 
    3374              : /* Recursive helper for finish_struct_anon.  */
    3375              : 
    3376              : static void
    3377       216341 : finish_struct_anon_r (tree field)
    3378              : {
    3379       966634 :   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       750293 :       if (DECL_ARTIFICIAL (elt)
    3389       750293 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    3390       110838 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    3391       253286 :         continue;
    3392              : 
    3393       497007 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    3394       497007 :       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       497007 :       if (DECL_NAME (elt) == NULL_TREE
    3409       497007 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    3410        36151 :         finish_struct_anon_r (elt);
    3411              :     }
    3412       216341 : }
    3413              : 
    3414              : /* Fix up any anonymous union/struct members of T.  */
    3415              : 
    3416              : static void
    3417     49090220 : finish_struct_anon (tree t)
    3418              : {
    3419    317487398 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3420              :     {
    3421    268397178 :       if (TREE_STATIC (field))
    3422     13815523 :         continue;
    3423    254581655 :       if (TREE_CODE (field) != FIELD_DECL)
    3424    237718736 :         continue;
    3425              : 
    3426     16862919 :       if (DECL_NAME (field) == NULL_TREE
    3427     16862919 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3428       180190 :         finish_struct_anon_r (field);
    3429              :     }
    3430     49090220 : }
    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    439009905 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3444              : {
    3445    439009905 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    3446    439009905 :       && TREE_CODE (t) != CONST_DECL)
    3447              :     {
    3448    380663801 :       tree purpose = friend_p ? NULL_TREE : type;
    3449              : 
    3450    380663801 :       CLASSTYPE_DECL_LIST (type)
    3451    761327602 :         = tree_cons (purpose, t, CLASSTYPE_DECL_LIST (type));
    3452              :     }
    3453    439009905 : }
    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      3611781 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3465              : {
    3466      3611781 :   tree bv, fn, t = (tree)data;
    3467      3611781 :   tree opname = assign_op_identifier;
    3468              : 
    3469      3611781 :   gcc_assert (t && CLASS_TYPE_P (t));
    3470      3611781 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3471              : 
    3472      3611781 :   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      3053704 :   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     12085287 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3483              :     {
    3484      9031583 :       fn = BV_FN (bv);
    3485              : 
    3486      9031583 :       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      9031562 :       else if (DECL_DESTRUCTOR_P (fn)
    3494      9031562 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3495       181553 :         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     49090220 : declare_virt_assop_and_dtor (tree t)
    3507              : {
    3508     49090220 :   if (!(TYPE_POLYMORPHIC_P (t)
    3509      1709106 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3510       610409 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3511       610409 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3512              :     return;
    3513              : 
    3514      1164818 :   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       433116 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3557              : {
    3558       433116 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3559              : 
    3560       433116 :   if (flag_new_inheriting_ctors)
    3561              :     {
    3562       433026 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3563              :                                     t, /*const*/false, ctor, parms);
    3564       433026 :       add_method (t, ctor, using_decl != NULL_TREE);
    3565       433026 :       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     42385763 : add_implicit_default_ctor (tree t)
    3590              : {
    3591     42385763 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3592     42385763 :   CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3593     42385763 :   if (cxx_dialect >= cxx11)
    3594     42299478 :     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     84598956 :       = type_maybe_constexpr_default_constructor (t);
    3600     42385763 : }
    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     49090220 : 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     49090220 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3616              :     /* In general, we create destructors lazily.  */
    3617     45500980 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3618              : 
    3619     49090220 :   bool move_ok = false;
    3620     48975448 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3621     45407510 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3622     93160237 :       && !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     49090220 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3630     42329450 :     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     49090220 :   if (! TYPE_HAS_COPY_CTOR (t))
    3637              :     {
    3638     45704115 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3639     45704115 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3640     45704115 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3641     45704115 :       if (move_ok)
    3642     43760880 :         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     49090220 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3650              :     {
    3651     45830746 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3652     45830746 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3653     45830746 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3654     89195799 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3655     43422073 :         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     49090220 :   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     49090220 :   if (!classtype_has_op (t, EQ_EXPR))
    3666     47829719 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3667              :       {
    3668          672 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3669              :                                          NULL_TREE);
    3670          672 :         bool is_friend = DECL_CONTEXT (space) != t;
    3671          672 :         if (is_friend)
    3672           73 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3673              :                      NO_SPECIAL, true);
    3674              :         else
    3675              :           {
    3676          599 :             add_method (t, eq, false);
    3677          599 :             DECL_CHAIN (eq) = TYPE_FIELDS (t);
    3678          599 :             TYPE_FIELDS (t) = eq;
    3679              :           }
    3680          672 :         maybe_add_class_template_decl_list (t, eq, is_friend);
    3681              :       }
    3682              : 
    3683     51310135 :   while (*access_decls)
    3684              :     {
    3685      2219915 :       tree using_decl = TREE_VALUE (*access_decls);
    3686      2219915 :       tree decl = USING_DECL_DECLS (using_decl);
    3687      2219915 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3688              :         {
    3689              :           /* declare, then remove the decl */
    3690       100476 :           tree ctor_list = decl;
    3691       100476 :           location_t loc = input_location;
    3692       100476 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3693       867292 :           for (tree fn : ovl_range (ctor_list))
    3694              :             {
    3695       433116 :               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        56313 :                 add_implicit_default_ctor (t);
    3699       433116 :               one_inherited_ctor (fn, t, using_decl);
    3700              :             }
    3701       100476 :           *access_decls = TREE_CHAIN (*access_decls);
    3702       100476 :           input_location = loc;
    3703              :         }
    3704              :       else
    3705      2119439 :         access_decls = &TREE_CHAIN (*access_decls);
    3706              :     }
    3707     49090220 : }
    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       101078 : enum_min_precision (tree type)
    3717              : {
    3718       101078 :   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       101078 :   if (UNSCOPED_ENUM_P (type)
    3722        45585 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3723       109868 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3724         8778 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3725              : 
    3726        92300 :   if (enum_to_min_precision == NULL)
    3727         9277 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3728              : 
    3729        92300 :   bool existed;
    3730        92300 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3731        92300 :   if (existed)
    3732        55429 :     return prec;
    3733              : 
    3734        36871 :   tree minnode, maxnode;
    3735        36871 :   if (TYPE_VALUES (type))
    3736              :     {
    3737              :       minnode = maxnode = NULL_TREE;
    3738       285375 :       for (tree values = TYPE_VALUES (type);
    3739       322243 :            values; values = TREE_CHAIN (values))
    3740              :         {
    3741       285375 :           tree decl = TREE_VALUE (values);
    3742       285375 :           tree value = DECL_INITIAL (decl);
    3743       285375 :           if (value == error_mark_node)
    3744            0 :             value = integer_zero_node;
    3745       285375 :           if (!minnode)
    3746              :             minnode = maxnode = value;
    3747       248507 :           else if (tree_int_cst_lt (maxnode, value))
    3748              :             maxnode = value;
    3749        91930 :           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        36871 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3757        36871 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3758        36871 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3759        36871 :   prec = MAX (lowprec, highprec);
    3760        36871 :   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       634428 : check_bitfield_decl (tree field)
    3769              : {
    3770       634428 :   tree type = TREE_TYPE (field);
    3771       634428 :   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       634428 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3776       634428 :   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       634428 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3780              : 
    3781              :   /* Detect invalid bit-field type.  */
    3782       634428 :   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       634425 :       location_t loc = input_location;
    3791              :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3792       634425 :       STRIP_NOPS (w);
    3793              : 
    3794              :       /* detect invalid field size.  */
    3795       634425 :       input_location = DECL_SOURCE_LOCATION (field);
    3796       634425 :       w = cxx_constant_value (w);
    3797       634425 :       input_location = loc;
    3798              : 
    3799       634425 :       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       634410 :       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       634410 :       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       634395 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3815       634395 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3816       531832 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3817       634395 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3818       633961 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3819       102563 :                    && 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       633621 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3823              :         {
    3824       101078 :           int prec = enum_min_precision (type);
    3825       101078 :           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       634428 :   if (w != error_mark_node)
    3833              :     {
    3834       634395 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3835       634395 :       DECL_BIT_FIELD (field) = 1;
    3836       634395 :       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     17357881 : check_field_decl (tree field,
    3853              :                   tree t,
    3854              :                   int* cant_have_const_ctor,
    3855              :                   int* no_const_asn_ref)
    3856              : {
    3857     17357881 :   tree type = strip_array_types (TREE_TYPE (field));
    3858     17357881 :   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     17357881 :   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     17356958 :   else if (ANON_AGGR_TYPE_P (type))
    3867              :     {
    3868       962845 :       for (tree fields = TYPE_FIELDS (type); fields;
    3869       747444 :            fields = DECL_CHAIN (fields))
    3870       747444 :         if (TREE_CODE (fields) == FIELD_DECL)
    3871       495127 :           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     17141557 :   else if (CLASS_TYPE_P (type))
    3878              :     {
    3879              :       /* Never let anything with uninheritable virtuals
    3880              :          make it through without complaint.  */
    3881      3327478 :       abstract_virtuals_error (field, type);
    3882              : 
    3883      3327478 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3884              :         {
    3885         3069 :           static bool warned;
    3886         3069 :           auto_diagnostic_group d;
    3887         3069 :           int oldcount = errorcount;
    3888         3069 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3889            2 :             error ("member %q+#D with constructor not allowed in union",
    3890              :                    field);
    3891         3069 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3892            0 :             error ("member %q+#D with destructor not allowed in union", field);
    3893         3069 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3894            3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3895              :                    field);
    3896         3069 :           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         3069 :         }
    3903              :       else
    3904              :         {
    3905      3324409 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3906      9973227 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3907      3324409 :             |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3908      3324409 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3909      3324409 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3910      3324409 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3911      6648818 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3912      3324409 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3913      3324409 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3914      3324409 :           TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
    3915      6648818 :           TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3916      3324409 :                                         || TYPE_HAS_COMPLEX_DFLT (type));
    3917              :         }
    3918              : 
    3919      3327478 :       if (TYPE_HAS_COPY_CTOR (type)
    3920      3327478 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3921         9170 :         *cant_have_const_ctor = 1;
    3922              : 
    3923      3327478 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3924      3327478 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3925           55 :         *no_const_asn_ref = 1;
    3926              :     }
    3927              : 
    3928     17357881 :   check_abi_tags (t, field);
    3929              : 
    3930     17357881 :   if (DECL_INITIAL (field) != NULL_TREE)
    3931              :     /* `build_class_init_list' does not recognize
    3932              :        non-FIELD_DECLs.  */
    3933      1391657 :     any_default_members = true;
    3934              : 
    3935     17357881 :   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     49090220 : check_field_decls (tree t, tree *access_decls,
    3962              :                    int *cant_have_const_ctor_p,
    3963              :                    int *no_const_asn_ref_p)
    3964              : {
    3965     49090220 :   int cant_pack = 0;
    3966              : 
    3967              :   /* Assume there are no access declarations.  */
    3968     49090220 :   *access_decls = NULL_TREE;
    3969              :   /* Effective C has things to say about classes with pointer members.  */
    3970     49090220 :   tree pointer_member = NULL_TREE;
    3971              :   /* Default initialized members affect the whole class.  */
    3972     49090220 :   tree default_init_member = NULL_TREE;
    3973              :   /* Lack of any non-static data member of non-volatile literal
    3974              :      type affects a union.  */
    3975     49090220 :   bool found_nv_literal_p = false;
    3976              :   /* Standard layout requires all FIELDS have same access.  */
    3977     49090220 :   int field_access = -1;
    3978              : 
    3979    317487398 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3980              :     {
    3981    268397178 :       tree type = TREE_TYPE (field);
    3982              : 
    3983    268397178 :       switch (TREE_CODE (field))
    3984              :         {
    3985            0 :         default:
    3986            0 :           gcc_unreachable ();
    3987              : 
    3988      2219915 :         case USING_DECL:
    3989              :           /* Save the access declarations for our caller.  */
    3990      2219915 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    3991      2219915 :           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      1661548 :         case CONST_DECL:
    4002      1661548 :           DECL_NONLOCAL (field) = 1;
    4003      1661548 :           break;
    4004              : 
    4005     13472273 :         case VAR_DECL:
    4006     13472273 :           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     13472273 :           goto data_member;
    4018              : 
    4019     16862919 :         case FIELD_DECL:
    4020     16862919 :           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      1035392 :               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     15827527 :         data_member:
    4032              :           /* Common VAR_DECL & FIELD_DECL processing.  */
    4033     30335192 :           DECL_CONTEXT (field) = t;
    4034     30335192 :           DECL_NONLOCAL (field) = 1;
    4035              : 
    4036              :           /* Template instantiation can cause this.  Perhaps this
    4037              :              should be a specific instantiation check?  */
    4038     30335192 :           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     30335181 :           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    268397178 :       if (TREE_CODE (field) != FIELD_DECL)
    4055    251534259 :         continue;
    4056              : 
    4057     16862919 :       if (type == error_mark_node)
    4058          165 :         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     16862754 :       if (COMPLETE_TYPE_P (type))
    4067              :         {
    4068     16861365 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    4069       955410 :             CLASSTYPE_LITERAL_P (t) = false;
    4070              :           else
    4071              :             found_nv_literal_p = true;
    4072              :         }
    4073              : 
    4074     16862754 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    4075     15166370 :                                : TREE_PRIVATE (field) ? 2 : 0);
    4076     16862754 :       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      6729801 :           if (field_access < 0)
    4083              :             field_access = this_field_access;
    4084              :           else
    4085        38980 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4086              : 
    4087              :           /* Aggregates must be public.  */
    4088      6729801 :           if (this_field_access)
    4089      3292705 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    4090              :         }
    4091              : 
    4092              :       /* If this is of reference type, check if it needs an init.  */
    4093     16862754 :       if (TYPE_REF_P (type))
    4094              :         {
    4095       344191 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4096       344191 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4097       344191 :           if (DECL_INITIAL (field) == NULL_TREE)
    4098       344062 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4099       344191 :           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         1101 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4106         1101 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4107              :             }
    4108              :         }
    4109              : 
    4110     16862754 :       type = strip_array_types (type);
    4111              : 
    4112     16862754 :       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     16862754 :       if (DECL_C_BIT_FIELD (field)
    4127     16862754 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    4128              :         /* We don't treat zero-width bitfields as making a class
    4129              :            non-empty.  */
    4130              :         ;
    4131     16861585 :       else if (field_poverlapping_p (field)
    4132     16861585 :                && is_empty_class (TREE_TYPE (field)))
    4133              :         /* Empty data members also don't make a class non-empty.  */
    4134       222615 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4135              :       else
    4136              :         {
    4137              :           /* The class is non-empty.  */
    4138     16638970 :           CLASSTYPE_EMPTY_P (t) = 0;
    4139              :           /* The class is not even nearly empty.  */
    4140     16638970 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4141              :           /* If one of the data members contains an empty class, so
    4142              :              does T.  */
    4143      3258426 :           if (CLASS_TYPE_P (type)
    4144     19886806 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4145       909705 :             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     16862754 :       if (TYPE_PTR_P (type)
    4152     16862754 :           && !TYPE_PTRFN_P (type))
    4153              :         pointer_member = field;
    4154              : 
    4155     16862754 :       if (CLASS_TYPE_P (type))
    4156              :         {
    4157      3470451 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    4158         3002 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4159      3470451 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    4160        27986 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4161              :         }
    4162              : 
    4163     16862754 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    4164       205109 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    4165              : 
    4166     16862754 :       if (DECL_MUTABLE_P (field))
    4167              :         {
    4168       127497 :           if (TYPE_REF_P (type))
    4169            3 :             error ("member %q+D cannot be declared as a %<mutable%> "
    4170              :                    "reference", field);
    4171       127494 :           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     16862754 :       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      2835390 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4180              : 
    4181     16862754 :       if (field_poverlapping_p (field))
    4182              :         /* A potentially-overlapping non-static data member makes the class
    4183              :            non-layout-POD.  */
    4184       275964 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4185              : 
    4186     16862754 :       if (!std_layout_type_p (type))
    4187       565499 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4188              : 
    4189     16862754 :       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     16862754 :       if (DECL_C_BIT_FIELD (field))
    4195       634428 :         check_bitfield_decl (field);
    4196              : 
    4197     16862754 :       if (check_field_decl (field, t,
    4198              :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    4199              :         {
    4200      1391636 :           if (default_init_member
    4201       558572 :               && 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     16862754 :       if (DECL_INITIAL (field))
    4216              :         {
    4217      1373401 :           if (cxx_dialect < cxx14)
    4218         1002 :             CLASSTYPE_NON_AGGREGATE (t) = true;
    4219              :           else
    4220      1372399 :             CLASSTYPE_NON_POD_AGGREGATE (t) = true;
    4221              :         }
    4222              : 
    4223     16862754 :       if (CP_TYPE_CONST_P (type))
    4224              :         {
    4225              :           /* If any field is const, the structure type is pseudo-const.  */
    4226       268466 :           C_TYPE_FIELDS_READONLY (t) = 1;
    4227       268466 :           if (DECL_INITIAL (field) == NULL_TREE)
    4228       223018 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4229       268466 :           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          745 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4236          745 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4237              :             }
    4238              :         }
    4239              :       /* A field that is pseudo-const makes the structure likewise.  */
    4240     16594288 :       else if (CLASS_TYPE_P (type))
    4241              :         {
    4242      3424280 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    4243      3424280 :           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     16862754 :       if (constructor_name_p (DECL_NAME (field), t)
    4252     16862754 :           && 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     49090220 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    4260       414138 :     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     49090220 :   if (warn_ecpp
    4277          138 :       && pointer_member
    4278           15 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    4279           15 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    4280     49090232 :       && !(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     49090220 :   if (default_init_member)
    4303              :     {
    4304       833064 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    4305       833064 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    4306              :     }
    4307              : 
    4308              :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    4309     49090220 :   if (cant_pack)
    4310           12 :     TYPE_PACKED (t) = 0;
    4311              : 
    4312              :   /* Check anonymous struct/anonymous union fields.  */
    4313     49090220 :   finish_struct_anon (t);
    4314              : 
    4315              :   /* We've built up the list of access declarations in reverse order.
    4316              :      Fix that now.  */
    4317     49090220 :   *access_decls = nreverse (*access_decls);
    4318     49090220 : }
    4319              : 
    4320              : /* If TYPE is an empty class type, records its OFFSET in the table of
    4321              :    OFFSETS.  */
    4322              : 
    4323              : static int
    4324     29156392 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    4325              : {
    4326     29156392 :   splay_tree_node n;
    4327              : 
    4328     29156392 :   if (!is_empty_class (type))
    4329              :     return 0;
    4330              : 
    4331              :   /* Record the location of this empty object in OFFSETS.  */
    4332     26414995 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4333     26414995 :   if (!n)
    4334     22268373 :     n = splay_tree_insert (offsets,
    4335              :                            (splay_tree_key) offset,
    4336              :                            (splay_tree_value) NULL_TREE);
    4337     52829990 :   n->value = ((splay_tree_value)
    4338     26414995 :               tree_cons (NULL_TREE,
    4339              :                          type,
    4340     26414995 :                          (tree) n->value));
    4341              : 
    4342     26414995 :   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       627606 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    4350              : {
    4351       627606 :   splay_tree_node n;
    4352       627606 :   tree t;
    4353              : 
    4354       627606 :   if (!is_empty_class (type))
    4355              :     return 0;
    4356              : 
    4357              :   /* Record the location of this empty object in OFFSETS.  */
    4358       536845 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4359       536845 :   if (!n)
    4360              :     return 0;
    4361              : 
    4362       536747 :   enum { ignore, fast, slow, warn }
    4363       536747 :   cv_check = (abi_version_crosses (19) ? slow
    4364       536714 :               : abi_version_at_least (19) ? fast
    4365            0 :               : ignore);
    4366      3869521 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    4367              :     {
    4368      3335960 :       tree elt = TREE_VALUE (t);
    4369              : 
    4370      3335960 :       if (same_type_p (elt, type))
    4371              :         return 1;
    4372              : 
    4373      3332774 :       if (cv_check != ignore
    4374      3332774 :           && similar_type_p (elt, type))
    4375              :         {
    4376           12 :           if (cv_check == fast)
    4377              :             return 1;
    4378              :           cv_check = warn;
    4379              :         }
    4380              :     }
    4381              : 
    4382       533561 :   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     53138588 : 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     53138588 :   int r = 0;
    4413     53138588 :   tree type_binfo = NULL_TREE;
    4414              : 
    4415              :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    4416              :      stop.  */
    4417     53138588 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    4418              :     return 0;
    4419              : 
    4420     44779559 :   if (type == error_mark_node)
    4421              :     return 0;
    4422              : 
    4423     44779559 :   if (!TYPE_P (type))
    4424              :     {
    4425      5831130 :       type_binfo = type;
    4426      5831130 :       type = BINFO_TYPE (type);
    4427              :     }
    4428              : 
    4429     44779559 :   if (CLASS_TYPE_P (type))
    4430              :     {
    4431     34472759 :       tree field;
    4432     34472759 :       tree binfo;
    4433     34472759 :       int i;
    4434              : 
    4435              :       /* Avoid recursing into objects that are not interesting.  */
    4436     34472759 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4437              :         return 0;
    4438              : 
    4439              :       /* Record the location of TYPE.  */
    4440     29784433 :       r = (*f) (type, offset, offsets);
    4441     29784433 :       if (r)
    4442              :         return r;
    4443              : 
    4444              :       /* Iterate through the direct base classes of TYPE.  */
    4445     29781235 :       if (!type_binfo)
    4446     24946287 :         type_binfo = TYPE_BINFO (type);
    4447     35456156 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    4448              :         {
    4449      5676074 :           tree binfo_offset;
    4450              : 
    4451      5676074 :           if (BINFO_VIRTUAL_P (binfo))
    4452         1680 :             continue;
    4453              : 
    4454      5674394 :           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      5674394 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    4459      5674394 :           binfo_offset = size_binop (PLUS_EXPR,
    4460              :                                      offset,
    4461              :                                      BINFO_OFFSET (orig_binfo));
    4462              : 
    4463      5674394 :           r = walk_subobject_offsets (binfo,
    4464              :                                       f,
    4465              :                                       binfo_offset,
    4466              :                                       offsets,
    4467              :                                       max_offset,
    4468              :                                       /*vbases_p=*/0);
    4469      5674394 :           if (r)
    4470              :             return r;
    4471              :         }
    4472              : 
    4473     29780082 :       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    570714495 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4520    540936829 :         if (TREE_CODE (field) == FIELD_DECL
    4521     10472998 :             && TREE_TYPE (field) != error_mark_node
    4522    551409783 :             && !DECL_ARTIFICIAL (field))
    4523              :           {
    4524      4773284 :             tree field_offset;
    4525              : 
    4526      4773284 :             field_offset = byte_position (field);
    4527              : 
    4528      4773284 :             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      4773284 :             if (r)
    4537              :               return r;
    4538              :           }
    4539              :     }
    4540     10306800 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4541              :     {
    4542       664492 :       tree element_type = strip_array_types (type);
    4543       664492 :       tree domain = TYPE_DOMAIN (type);
    4544       664492 :       tree index;
    4545              : 
    4546              :       /* Avoid recursing into objects that are not interesting.  */
    4547        26127 :       if (!CLASS_TYPE_P (element_type)
    4548        26115 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4549        11934 :           || !domain
    4550       676407 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4551       652794 :         return 0;
    4552              : 
    4553              :       /* Step through each of the elements in the array.  */
    4554        11698 :       for (index = size_zero_node;
    4555        34100 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4556        22402 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4557              :         {
    4558        33132 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4559              :                                       f,
    4560              :                                       offset,
    4561              :                                       offsets,
    4562              :                                       max_offset,
    4563              :                                       /*vbases_p=*/1);
    4564        33132 :           if (r)
    4565              :             return r;
    4566        33132 :           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        33132 :           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     83571287 : 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     83571287 :   if (DECL_FIELD_IS_BASE (decl))
    4588              :     {
    4589            0 :       gcc_checking_assert (c_dialect_objc ());
    4590              :       return false;
    4591              :     }
    4592              : 
    4593     83571287 :   return lookup_attribute ("no_unique_address",
    4594    167142574 :                            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    484429408 : is_empty_field (tree decl)
    4602              : {
    4603    484429408 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4604              :     return false;
    4605              : 
    4606     97073972 :   bool r = (is_empty_class (TREE_TYPE (decl))
    4607     99687969 :             && (DECL_FIELD_IS_BASE (decl)
    4608       768585 :                 || field_poverlapping_p (decl)));
    4609              : 
    4610              :   /* Empty fields should have size zero.  */
    4611      2455642 :   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     40350436 : record_subobject_offsets (tree decl_or_binfo,
    4620              :                           splay_tree offsets)
    4621              : {
    4622     40350436 :   tree type, offset;
    4623     40350436 :   bool overlapping, vbases_p;
    4624              : 
    4625     40350436 :   if (DECL_P (decl_or_binfo))
    4626              :     {
    4627     16862754 :       tree decl = decl_or_binfo;
    4628     16862754 :       type = TREE_TYPE (decl);
    4629     16862754 :       offset = byte_position (decl);
    4630     16862754 :       overlapping = field_poverlapping_p (decl);
    4631     16862754 :       vbases_p = true;
    4632              :     }
    4633              :   else
    4634              :     {
    4635     23487682 :       type = BINFO_TYPE (decl_or_binfo);
    4636     23487682 :       offset = BINFO_OFFSET (decl_or_binfo);
    4637     23487682 :       overlapping = true;
    4638     23487682 :       vbases_p = false;
    4639              :     }
    4640              : 
    4641     40350436 :   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     23487682 :   if (!overlapping
    4656     40350436 :       || !is_empty_class (type))
    4657     19176988 :     max_offset = sizeof_biggest_empty_class;
    4658              :   else
    4659              :     max_offset = NULL_TREE;
    4660     40350436 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4661              :                           offsets, max_offset, vbases_p);
    4662     40350436 : }
    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     39318952 : layout_conflict_p (tree type,
    4670              :                    tree offset,
    4671              :                    splay_tree offsets,
    4672              :                    int vbases_p)
    4673              : {
    4674     39318952 :   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     39318952 :   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     39318952 :   if (!max_node)
    4682              :     return 0;
    4683              : 
    4684      2306767 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4685      2306767 :                                  offsets, (tree) (max_node->key),
    4686      2306767 :                                  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     19177756 : layout_nonempty_base_or_field (record_layout_info rli,
    4697              :                                tree decl,
    4698              :                                tree binfo,
    4699              :                                splay_tree offsets)
    4700              : {
    4701     19177756 :   tree offset = NULL_TREE;
    4702     19177756 :   bool field_p;
    4703     19177756 :   tree type;
    4704              : 
    4705     19177756 :   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      2536849 :       type = TREE_TYPE (binfo);
    4712      2536849 :       field_p = false;
    4713              :     }
    4714              :   else
    4715              :     {
    4716     16640907 :       type = TREE_TYPE (decl);
    4717     16640907 :       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     19177989 :       struct record_layout_info_s old_rli = *rli;
    4726              : 
    4727              :       /* Place this field.  */
    4728     19177989 :       place_field (rli, decl);
    4729     19177989 :       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     19177989 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4749              :         break;
    4750     20680630 :       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     18143489 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4767        83059 :                && 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     21714605 :   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      2536849 :     propagate_binfo_offsets (binfo,
    4799              :                              size_diffop_loc (input_location,
    4800              :                                           fold_convert (ssizetype, offset),
    4801      2536849 :                                           fold_convert (ssizetype,
    4802              :                                                    BINFO_OFFSET (binfo))));
    4803     19177756 : }
    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     21173448 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4823              :                             splay_tree offsets)
    4824              : {
    4825     21173448 :   tree alignment;
    4826     21173448 :   bool atend = false;
    4827     21173448 :   tree binfo = NULL_TREE;
    4828     21173448 :   tree decl = NULL_TREE;
    4829     21173448 :   tree type;
    4830     21173448 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4831              :     {
    4832     20950833 :       binfo = binfo_or_decl;
    4833     20950833 :       type = BINFO_TYPE (binfo);
    4834              :     }
    4835              :   else
    4836              :     {
    4837       222615 :       decl = binfo_or_decl;
    4838       222615 :       type = TREE_TYPE (decl);
    4839              :     }
    4840              : 
    4841              :   /* On some platforms (ARM), even empty classes will not be
    4842              :      byte-aligned.  */
    4843     21173448 :   tree eoc = round_up_loc (input_location,
    4844              :                            rli_size_unit_so_far (rli),
    4845     21173448 :                            CLASSTYPE_ALIGN_UNIT (type));
    4846              : 
    4847              :   /* This routine should only be used for empty classes.  */
    4848     21173448 :   gcc_assert (is_empty_class (type));
    4849              : 
    4850     21173448 :   if (decl && DECL_USER_ALIGN (decl))
    4851            3 :     alignment = size_int (DECL_ALIGN_UNIT (decl));
    4852              :   else
    4853     21173445 :     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     21173448 :   tree offset = size_zero_node;
    4858     21173448 :   if (TREE_CODE (rli->t) != UNION_TYPE
    4859     21173448 :       && 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     21173448 :   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     21173445 :   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     21173448 :   if (binfo)
    4898              :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4899     41901666 :     propagate_binfo_offsets (binfo,
    4900     20950833 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4901              :   else
    4902              :     {
    4903       222615 :       DECL_FIELD_OFFSET (decl) = offset;
    4904       222615 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4905       222615 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4906              :     }
    4907              : 
    4908     21173448 :   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     23409821 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4916              : {
    4917              :   /* Create the FIELD_DECL.  */
    4918     23409821 :   tree basetype = BINFO_TYPE (binfo);
    4919     23409821 :   tree as_base = CLASSTYPE_AS_BASE (basetype);
    4920     23409821 :   gcc_assert (as_base);
    4921     23409821 :   tree decl = build_decl (input_location, FIELD_DECL, NULL_TREE, as_base);
    4922              : 
    4923     23409821 :   DECL_ARTIFICIAL (decl) = 1;
    4924     23409821 :   DECL_IGNORED_P (decl) = 1;
    4925     23409821 :   DECL_FIELD_CONTEXT (decl) = t;
    4926     23409821 :   if (is_empty_class (basetype))
    4927              :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4928     20872972 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4929              :   else
    4930              :     {
    4931      2536849 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4932      2536849 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4933              :     }
    4934     23409821 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4935     23409821 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4936     23409821 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4937     23409821 :   DECL_FIELD_IS_BASE (decl) = 1;
    4938              : 
    4939     23409821 :   if (access == access_private_node)
    4940       436417 :     TREE_PRIVATE (decl) = true;
    4941     22973404 :   else if (access == access_protected_node)
    4942        86225 :     TREE_PROTECTED (decl) = true;
    4943              : 
    4944              :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4945     23409821 :   DECL_CHAIN (decl) = *next_field;
    4946     23409821 :   *next_field = decl;
    4947     23409821 :   next_field = &DECL_CHAIN (decl);
    4948              : 
    4949     23409821 :   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     23487682 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4963              :                   splay_tree offsets, tree *next_field)
    4964              : {
    4965     23487682 :   tree t = rli->t;
    4966     23487682 :   tree basetype = BINFO_TYPE (binfo);
    4967              : 
    4968     23487682 :   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     23487682 :   if (!is_empty_class (basetype))
    4975              :     {
    4976      2536849 :       tree decl;
    4977              : 
    4978              :       /* The containing class is non-empty because it has a non-empty
    4979              :          base class.  */
    4980      2536849 :       CLASSTYPE_EMPTY_P (t) = 0;
    4981              : 
    4982              :       /* Create the FIELD_DECL.  */
    4983      2536849 :       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      2536849 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    4989              :     }
    4990              :   else
    4991              :     {
    4992     20950833 :       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     20950833 :       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     41825506 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    5016              :         {
    5017     20872972 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    5018     20872972 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    5019     20872972 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    5020     20872972 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    5021     20872972 :           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     23487682 :   record_subobject_offsets (binfo, offsets);
    5032              : 
    5033     23487682 :   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     49090220 : 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     49090220 :   tree t = rli->t;
    5049     49090220 :   tree binfo = TYPE_BINFO (t);
    5050     49090220 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    5051              : 
    5052              :   /* The primary base class is always allocated first.  */
    5053     49090220 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    5054     49090220 :   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      1466751 :       tree primary_access = access_private_node;
    5059      1467632 :       for (int i = 0; i < n_baseclasses; ++i)
    5060              :         {
    5061      1467561 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    5062      1467561 :           if (base_binfo == primary_binfo)
    5063              :             {
    5064      1466680 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    5065      1466680 :               break;
    5066              :             }
    5067              :         }
    5068      1466751 :       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     72438305 :   for (int i = 0; i < n_baseclasses; ++i)
    5075              :     {
    5076     23348085 :       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     23348085 :       if (base_binfo == primary_binfo)
    5081      1466680 :        continue;
    5082              : 
    5083              :       /* Virtual bases are added at the end (a primary virtual base
    5084              :          will have already been added).  */
    5085     21881405 :       if (BINFO_VIRTUAL_P (base_binfo))
    5086        44427 :         continue;
    5087              : 
    5088     21836978 :       next_field = build_base_field (rli, base_binfo,
    5089     21836978 :                                      BINFO_BASE_ACCESS (binfo, i),
    5090              :                                      offsets, next_field);
    5091              :     }
    5092     49090220 : }
    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     49090220 : check_methods (tree t)
    5100              : {
    5101    317487398 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    5102    268397178 :     if (DECL_DECLARES_FUNCTION_P (x))
    5103              :       {
    5104    134054388 :         check_for_override (x, t);
    5105              : 
    5106    134054388 :         if (DECL_PURE_VIRTUAL_P (x)
    5107    134054388 :             && (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    134054388 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    5112              :           {
    5113      5980392 :             TYPE_POLYMORPHIC_P (t) = 1;
    5114      5980392 :             if (DECL_PURE_VIRTUAL_P (x))
    5115       723767 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    5116              :           }
    5117              : 
    5118    134054388 :         if (!DECL_VIRTUAL_P (x)
    5119    262128400 :             && lookup_attribute ("transaction_safe_dynamic",
    5120    128074012 :                                  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     49090220 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5133              :     {
    5134      3589240 :       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      3589234 :       else if (user_provided_p (dtor))
    5160      2781578 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    5161              :     }
    5162              : 
    5163     97879455 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5164              :     {
    5165     27698369 :       if (!user_provided_p (fn))
    5166              :         /* Might be trivial.  */;
    5167     21750387 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5168              :         /* Templates are never special members.  */;
    5169     14059428 :       else if (copy_fn_p (fn)
    5170     14059428 :                && constraints_satisfied_p (fn))
    5171      1011552 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    5172     13047876 :       else if (move_fn_p (fn)
    5173     13047876 :                && constraints_satisfied_p (fn))
    5174       904311 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    5175              :     }
    5176              : 
    5177     61423740 :   for (tree fn : ovl_range (get_class_binding_direct (t, assign_op_identifier)))
    5178              :     {
    5179      7908940 :       if (!user_provided_p (fn))
    5180              :         /* Might be trivial.  */;
    5181      4122978 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5182              :         /* Templates are never special members.  */;
    5183      3029489 :       else if (copy_fn_p (fn)
    5184      3029489 :                && constraints_satisfied_p (fn))
    5185       644231 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    5186      2385258 :       else if (move_fn_p (fn)
    5187      2385258 :                && constraints_satisfied_p (fn))
    5188       857126 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    5189              :     }
    5190     49090220 : }
    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    126345536 : 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    126345536 :   tree clone = copy_decl (fn);
    5202              :   /* Reset the function name.  */
    5203    126345536 :   DECL_NAME (clone) = name;
    5204              : 
    5205    126345536 :   if (flag_concepts)
    5206              :     /* Clone constraints.  */
    5207    125051278 :     if (tree ci = get_constraints (fn))
    5208     11734742 :       set_constraints (clone, copy_node (ci));
    5209              : 
    5210    126345536 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    5211    126345536 :   DECL_ABSTRACT_P (clone) = false;
    5212              :   /* There's no pending inline data for this function.  */
    5213    126345536 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    5214    126345536 :   DECL_PENDING_INLINE_P (clone) = 0;
    5215              : 
    5216    126345536 :   if (name == base_dtor_identifier)
    5217              :     {
    5218              :       /* The base-class destructor is not virtual.  */
    5219     10511248 :       DECL_VIRTUAL_P (clone) = 0;
    5220     10511248 :       DECL_VINDEX (clone) = NULL_TREE;
    5221              :     }
    5222    115834288 :   else if (code != ERROR_MARK)
    5223              :     {
    5224              :       /* Set the operator code.  */
    5225          672 :       const ovl_op_info_t *ovl_op = OVL_OP_INFO (false, code);
    5226          672 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (clone) = ovl_op->ovl_op_code;
    5227              : 
    5228              :       /* The operator could be virtual.  */
    5229          672 :       if (DECL_VIRTUAL_P (clone))
    5230           12 :         IDENTIFIER_VIRTUAL_P (name) = true;
    5231              :    }
    5232              : 
    5233    126345536 :   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    126345536 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5239              :     {
    5240      2414026 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5241      2414026 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5242              :       /* Skip the `this' parameter.  */
    5243      2414026 :       parmtypes = TREE_CHAIN (parmtypes);
    5244              :       /* Skip the in-charge parameter.  */
    5245      2414026 :       parmtypes = TREE_CHAIN (parmtypes);
    5246              :       /* And the VTT parm, in a complete [cd]tor.  */
    5247      2414026 :       if (DECL_HAS_VTT_PARM_P (fn) && !need_vtt_parm_p)
    5248      1294212 :         parmtypes = TREE_CHAIN (parmtypes);
    5249      2414026 :       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      2414026 :       TREE_TYPE (clone)
    5256      2414026 :         = build_method_type_directly (basetype,
    5257      2414026 :                                       TREE_TYPE (TREE_TYPE (clone)),
    5258              :                                       parmtypes);
    5259      2414026 :       TREE_TYPE (clone)
    5260      2414026 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    5261      2414026 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    5262      2414026 :       TREE_TYPE (clone)
    5263      4828052 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    5264              :     }
    5265              : 
    5266              :   /* Copy the function parameters.  */
    5267    126345536 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    5268              : 
    5269              :   /* Remove the in-charge parameter.  */
    5270    126345536 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5271              :     {
    5272      2414026 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    5273      2414026 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5274      2414026 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    5275              :     }
    5276              : 
    5277              :   /* And the VTT parm, in a complete [cd]tor.  */
    5278    126345536 :   if (DECL_HAS_VTT_PARM_P (fn))
    5279              :     {
    5280      2414026 :       if (need_vtt_parm_p)
    5281      1119814 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    5282              :       else
    5283              :         {
    5284      2588424 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    5285      1294212 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5286      1294212 :           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    126345536 :   if (omit_inherited_parms_p)
    5293          120 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    5294              : 
    5295    388801477 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    5296              :     {
    5297    262455941 :       DECL_CONTEXT (parms) = clone;
    5298    262455941 :       cxx_dup_lang_specific_decl (parms);
    5299              :     }
    5300              : 
    5301              :   /* Create the RTL for this function.  */
    5302    126345536 :   SET_DECL_RTL (clone, NULL);
    5303              : 
    5304              :   /* Regardless of the current scope, this is a member function, so
    5305              :      not at namespace scope.  */
    5306    126345536 :   rest_of_decl_compilation (clone, /*top_level=*/0, at_eof);
    5307              : 
    5308    126345536 :   return clone;
    5309              : }
    5310              : 
    5311              : /* FN is an operator function, create a variant for CODE.  */
    5312              : 
    5313              : tree
    5314          672 : copy_operator_fn (tree fn, tree_code code)
    5315              : {
    5316          672 :   return copy_fndecl_with_name (fn, ovl_op_identifier (code),
    5317          672 :                                 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    143701904 : build_clone (tree fn, tree name, bool need_vtt_parm_p,
    5326              :              bool omit_inherited_parms_p)
    5327              : {
    5328    143701904 :   tree clone;
    5329              : 
    5330              :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    5331    143701904 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
    5332              :     {
    5333     17357040 :       clone = copy_decl (fn);
    5334     17357040 :       DECL_NAME (clone) = name;
    5335              : 
    5336     17357040 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name,
    5337              :                                  need_vtt_parm_p, omit_inherited_parms_p);
    5338     17357040 :       DECL_TEMPLATE_RESULT (clone) = result;
    5339              : 
    5340     17357040 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    5341     17357040 :       DECL_TI_TEMPLATE (result) = clone;
    5342              : 
    5343     17357040 :       TREE_TYPE (clone) = TREE_TYPE (result);
    5344              :     }
    5345              :   else
    5346              :     {
    5347    126344864 :       clone = copy_fndecl_with_name (fn, name, ERROR_MARK,
    5348              :                                      need_vtt_parm_p, omit_inherited_parms_p);
    5349    126344864 :       DECL_CLONED_FUNCTION (clone) = fn;
    5350              : 
    5351    126344864 :       maybe_prepare_return_this (clone);
    5352              :     }
    5353              : 
    5354              :   /* Remember where this function came from.  */
    5355    143701904 :   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    143701904 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    5360    143701904 :   DECL_CHAIN (fn) = clone;
    5361              : 
    5362    143701904 :   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     62374043 : build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p,
    5370              :                     bool update_methods)
    5371              : {
    5372     62374043 :   unsigned count = 0;
    5373              : 
    5374     62374043 :   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     51862795 :       build_clone (fn, complete_ctor_identifier, false, false);
    5379     51862795 :       build_clone (fn, base_ctor_identifier, needs_vtt_p,
    5380              :                    base_omits_inherited_p);
    5381     51862795 :       count += 2;
    5382              :     }
    5383              :   else
    5384              :     {
    5385     10511248 :       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     10511248 :       if (DECL_VIRTUAL_P (fn))
    5397              :         {
    5398      1596778 :           build_clone (fn, deleting_dtor_identifier, false, false);
    5399      1596778 :           count++;
    5400              :         }
    5401     10511248 :       build_clone (fn, complete_dtor_identifier, false, false);
    5402     10511248 :       build_clone (fn, base_dtor_identifier, needs_vtt_p, false);
    5403     10511248 :       count += 2;
    5404              :     }
    5405              : 
    5406              :   /* The original is now an abstract function that is never
    5407              :      emitted.  */
    5408     62374043 :   DECL_ABSTRACT_P (fn) = true;
    5409              : 
    5410     62374043 :   if (update_methods)
    5411    159604566 :     for (tree clone = fn; count--;)
    5412              :       {
    5413    106934839 :         clone = DECL_CHAIN (clone);
    5414    106934839 :         add_method (DECL_CONTEXT (clone), clone, false);
    5415              :       }
    5416     62374043 : }
    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     62684881 : clone_cdtor (tree fn, bool update_methods)
    5424              : {
    5425              :   /* Avoid inappropriate cloning.  */
    5426     62684881 :   if (DECL_CHAIN (fn)
    5427     62684881 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    5428              :     return;
    5429              : 
    5430              :   /* Base cdtors need a vtt parm if there are virtual bases.  */
    5431     62329857 :   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     62329857 :   bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
    5436     62329857 :                                && base_ctor_omit_inherited_parms (fn));
    5437              : 
    5438     62329857 :   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     19642353 : adjust_clone_args (tree decl)
    5450              : {
    5451     19642353 :   tree clone;
    5452              : 
    5453     32314209 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    5454     12671856 :        clone = DECL_CHAIN (clone))
    5455              :     {
    5456     12671856 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5457     12671856 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    5458     12671856 :       tree decl_parms, clone_parms;
    5459              : 
    5460              :       /* Skip the 'this' parameter.  */
    5461     12671856 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    5462     12671856 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5463              : 
    5464     12671856 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    5465        18684 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5466     12671856 :       if (DECL_HAS_VTT_PARM_P (decl))
    5467        18684 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5468              : 
    5469     12671856 :       clone_parms = orig_clone_parms;
    5470     12671856 :       if (DECL_HAS_VTT_PARM_P (clone))
    5471         9342 :         clone_parms = TREE_CHAIN (clone_parms);
    5472              : 
    5473     25633414 :       for (decl_parms = orig_decl_parms; decl_parms;
    5474     12961558 :            decl_parms = TREE_CHAIN (decl_parms),
    5475     12961558 :              clone_parms = TREE_CHAIN (clone_parms))
    5476              :         {
    5477     25631770 :           if (clone_parms == void_list_node)
    5478              :             {
    5479     12670188 :               gcc_assert (decl_parms == clone_parms
    5480              :                           || ctor_omit_inherited_parms (clone));
    5481              :               break;
    5482              :             }
    5483              : 
    5484     12961582 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    5485              :                                             TREE_VALUE (clone_parms)));
    5486              : 
    5487     14080618 :           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     12671856 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    5516              :     }
    5517     19642353 : }
    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     49090220 : 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     98739390 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5528     28128341 :     clone_cdtor (fn, /*update_methods=*/true);
    5529              : 
    5530     49090220 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5531      3770793 :     clone_cdtor (dtor, /*update_methods=*/true);
    5532     49090220 : }
    5533              : 
    5534              : /* Deduce noexcept for a destructor DTOR.  */
    5535              : 
    5536              : void
    5537      3650302 : deduce_noexcept_on_destructor (tree dtor)
    5538              : {
    5539      3650302 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    5540      2455046 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    5541              :                                                 noexcept_deferred_spec);
    5542      3650302 : }
    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     49090220 : set_method_tm_attributes (tree t)
    5649              : {
    5650     49090220 :   tree class_tm_attr, fndecl;
    5651              : 
    5652              :   /* Don't bother collecting tm attributes if transactional memory
    5653              :      support is not enabled.  */
    5654     49090220 :   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     11864396 : default_ctor_p (const_tree fn)
    5689              : {
    5690     11864396 :   return (DECL_CONSTRUCTOR_P (fn)
    5691     11864396 :           && 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    110037458 : user_provided_p (tree fn)
    5741              : {
    5742    110037458 :   fn = STRIP_TEMPLATE (fn);
    5743    110037458 :   return (!DECL_ARTIFICIAL (fn)
    5744    101280401 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5745     91554254 :                && (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    193774849 :           && !(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     49090358 : type_has_user_provided_constructor (tree t)
    5757              : {
    5758     49090358 :   if (!CLASS_TYPE_P (t))
    5759              :     return false;
    5760              : 
    5761     49090302 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5762              :     return false;
    5763              : 
    5764      9465505 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5765      7906638 :     if (user_provided_p (*iter))
    5766      6348253 :       return true;
    5767              : 
    5768       412522 :   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      1527644 : type_has_converting_constructor (tree t)
    5780              : {
    5781      1527644 :   if (!CLASS_TYPE_P (t))
    5782              :     return false;
    5783              : 
    5784      1527644 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5785              :     return false;
    5786              : 
    5787      4967209 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5788              :     {
    5789      2925526 :       tree fn = *iter;
    5790      2925526 :       tree parm = FUNCTION_FIRST_USER_PARMTYPE (fn);
    5791      2925526 :       if (parm == NULL_TREE)
    5792              :         /* Varargs.  */
    5793       883843 :         return true;
    5794      3773437 :       if (parm == void_list_node
    5795      2925524 :           || !sufficient_parms_p (TREE_CHAIN (parm)))
    5796              :         /* Can't accept a single argument, so won't be considered for
    5797              :            conversion.  */
    5798       847913 :         continue;
    5799      2077611 :       if (TREE_CODE (fn) == TEMPLATE_DECL
    5800      2077611 :           || TREE_CHAIN (parm) != void_list_node)
    5801              :         /* Not a simple single parameter.  */
    5802              :         return true;
    5803      1583479 :       if (TYPE_MAIN_VARIANT (non_reference (TREE_VALUE (parm)))
    5804      1583479 :           != DECL_CONTEXT (fn))
    5805              :         /* The single parameter has the wrong type.  */
    5806              :         return true;
    5807      1193770 :       if (get_constraints (fn))
    5808              :         /* Constrained.  */
    5809              :         return true;
    5810              :     }
    5811              : 
    5812       316087 :   return false;
    5813              : }
    5814              : 
    5815              : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5816              : 
    5817              : bool
    5818     49522438 : type_has_user_provided_or_explicit_constructor (tree t)
    5819              : {
    5820     49522438 :   if (!CLASS_TYPE_P (t))
    5821              :     return false;
    5822              : 
    5823     49522438 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5824              :     return false;
    5825              : 
    5826      9348945 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5827              :     {
    5828      7931934 :       tree fn = *iter;
    5829      7931934 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5830      6515406 :         return true;
    5831              :     }
    5832              : 
    5833       267016 :   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      3158382 : type_has_non_user_provided_default_constructor (tree t)
    5842              : {
    5843      3158382 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5844              :     return false;
    5845      3158356 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5846              :     return true;
    5847              : 
    5848     22841724 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5849              :     {
    5850     12048120 :       tree fn = *iter;
    5851     12048120 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5852      8244187 :           && default_ctor_p (fn)
    5853     15204287 :           && !user_provided_p (fn))
    5854      1255702 :         return true;
    5855              :     }
    5856              : 
    5857      1901727 :   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       762775 : default_init_uninitialized_part (tree type)
    5901              : {
    5902       762775 :   tree t, r, binfo;
    5903       762775 :   int i;
    5904              : 
    5905       762775 :   type = strip_array_types (type);
    5906       762775 :   if (!CLASS_TYPE_P (type))
    5907              :     return type;
    5908       757226 :   if (!type_has_non_user_provided_default_constructor (type))
    5909              :     return NULL_TREE;
    5910       703558 :   for (binfo = TYPE_BINFO (type), i = 0;
    5911       703558 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5912              :     {
    5913       136159 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5914       136159 :       if (r)
    5915              :         return r;
    5916              :     }
    5917       704075 :   for (t = next_aggregate_field (TYPE_FIELDS (type)); t;
    5918       136676 :        t = next_aggregate_field (DECL_CHAIN (t)))
    5919       136907 :     if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
    5920              :       {
    5921          304 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    5922          304 :         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     45618197 : trivial_default_constructor_is_constexpr (tree t)
    5934              : {
    5935              :   /* A defaulted trivial default constructor is constexpr
    5936              :      if there is nothing to initialize.  */
    5937     45618197 :   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     45618197 :   return (cxx_dialect >= cxx20
    5945     45618197 :           || 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     41876106 : type_has_constexpr_default_constructor (tree t)
    5952              : {
    5953     41876106 :   tree fns;
    5954              : 
    5955     41876106 :   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     41875874 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5962              :     {
    5963     41874388 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5964     41874325 :         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     42299478 : type_maybe_constexpr_default_constructor (tree t)
    5979              : {
    5980     42299478 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    5981     84598956 :       && TYPE_HAS_COMPLEX_DFLT (t))
    5982              :     /* Assume it's constexpr.  */
    5983              :     return true;
    5984     41874325 :   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     46841108 : type_maybe_constexpr_destructor (tree t)
    6008              : {
    6009              :   /* Until C++20, only trivial destruction is constexpr.  */
    6010     46841108 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    6011              :     return true;
    6012      1604804 :   if (cxx_dialect < cxx20)
    6013              :     return false;
    6014      1581331 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    6015              :     /* Assume it's constexpr.  */
    6016              :     return true;
    6017      1339440 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    6018      1339440 :   return (fn && maybe_constexpr_fn (fn));
    6019              : }
    6020              : 
    6021              : /* Returns true iff class TYPE has a virtual destructor.  */
    6022              : 
    6023              : bool
    6024      3404140 : type_has_virtual_destructor (tree type)
    6025              : {
    6026      3404140 :   tree dtor;
    6027              : 
    6028      3404140 :   if (!NON_UNION_CLASS_TYPE_P (type))
    6029              :     return false;
    6030              : 
    6031      3404008 :   gcc_assert (COMPLETE_TYPE_P (type));
    6032      3404008 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    6033      3404008 :   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        19325 : type_has_non_deleted_trivial_default_ctor (tree type)
    6041              : {
    6042        19325 :   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     51896755 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    6056              : {
    6057     51896755 :   gcc_assert (user_p
    6058              :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    6059              :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    6060              : 
    6061     51896755 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    6062     61833324 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6063     10389780 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    6064      1219017 :         return true;
    6065              : 
    6066     50677738 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    6067      1058547 :     for (ovl_iterator iter (get_class_binding_direct
    6068     45478787 :                             (t, assign_op_identifier));
    6069     46537334 :          iter; ++iter)
    6070       903918 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    6071       343756 :           && DECL_CONTEXT (*iter) == t
    6072      1199239 :           && 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      6392756 : classtype_has_depr_implicit_copy (tree t)
    6114              : {
    6115      6392756 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    6116     17625311 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6117              :       {
    6118      8781189 :         tree fn = *iter;
    6119      8781189 :         if (user_provided_p (fn) && copy_fn_p (fn))
    6120          740 :           return fn;
    6121              :       }
    6122              : 
    6123      6392016 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    6124       748224 :     for (ovl_iterator iter (get_class_binding_direct
    6125      1425090 :                             (t, assign_op_identifier));
    6126      2173314 :          iter; ++iter)
    6127              :       {
    6128       748623 :         tree fn = *iter;
    6129       748623 :         if (DECL_CONTEXT (fn) == t
    6130       748623 :             && user_provided_p (fn) && copy_fn_p (fn))
    6131          399 :           return fn;
    6132              :       }
    6133              : 
    6134      6391617 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    6135              :     {
    6136      1946968 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    6137      1946968 :       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     49090220 : classtype_has_op (tree t, tree_code op)
    6148              : {
    6149     49090220 :   tree name = ovl_op_identifier (op);
    6150     49090220 :   if (get_class_binding (t, name))
    6151              :     return true;
    6152     51010763 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6153      3181044 :     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     47829719 : classtype_has_defaulted_op (tree t, tree_code op)
    6163              : {
    6164     47829719 :   tree name = ovl_op_identifier (op);
    6165     47829773 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    6166              :     {
    6167          642 :       tree fn = *oi;
    6168          642 :       if (DECL_DEFAULTED_FN (fn))
    6169          599 :         return fn;
    6170              :     }
    6171     48620283 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6172       791236 :     if (FRIEND_NAME (f) == name)
    6173         1838 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    6174              :         {
    6175         1024 :           tree fn = TREE_VALUE (l);
    6176         1024 :           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     66283806 : type_build_ctor_call (tree t)
    6194              : {
    6195     66283806 :   tree inner;
    6196     66283806 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    6197              :     return true;
    6198     59159200 :   inner = strip_array_types (t);
    6199     59159200 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    6200              :     return false;
    6201      5111299 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    6202              :     return true;
    6203      4688332 :   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     18034434 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    6208     18034434 :        iter; ++iter)
    6209              :     {
    6210     13810949 :       tree fn = *iter;
    6211     13810949 :       if (!DECL_ARTIFICIAL (fn)
    6212     13594896 :           || TREE_DEPRECATED (fn)
    6213     13481939 :           || TREE_UNAVAILABLE (fn)
    6214     27292888 :           || DECL_DELETED_FN (fn))
    6215       456139 :         return true;
    6216              :     }
    6217      4223485 :   return false;
    6218              : }
    6219              : 
    6220              : /* Like type_build_ctor_call, but for destructors.  */
    6221              : 
    6222              : bool
    6223    124310927 : type_build_dtor_call (tree t)
    6224              : {
    6225    124310927 :   tree inner;
    6226    124310927 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6227              :     return true;
    6228     98425624 :   inner = strip_array_types (t);
    6229     42534626 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    6230    140790651 :       || !COMPLETE_TYPE_P (inner))
    6231              :     return false;
    6232     42365004 :   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     72782069 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    6237     72782069 :        iter; ++iter)
    6238              :     {
    6239     41908650 :       tree fn = *iter;
    6240     41908650 :       if (!DECL_ARTIFICIAL (fn)
    6241     30453800 :           || TREE_DEPRECATED (fn)
    6242     30453800 :           || TREE_UNAVAILABLE (fn)
    6243     72362450 :           || DECL_DELETED_FN (fn))
    6244     11454853 :         return true;
    6245              :     }
    6246     30873419 :   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     49090220 : type_requires_array_cookie (tree type)
    6254              : {
    6255     49090220 :   tree fns;
    6256     49090220 :   bool has_two_argument_delete_p = false;
    6257              : 
    6258     49090220 :   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     49090220 :   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     45476370 :   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     45476370 :   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     49090220 : finalize_literal_type_property (tree t)
    6312              : {
    6313     49090220 :   tree fn;
    6314              : 
    6315     49090220 :   if (cxx_dialect < cxx11)
    6316       114772 :     CLASSTYPE_LITERAL_P (t) = false;
    6317     48975448 :   else if (CLASSTYPE_LITERAL_P (t)
    6318     48975448 :            && !type_maybe_constexpr_destructor (t))
    6319       703073 :     CLASSTYPE_LITERAL_P (t) = false;
    6320     94003952 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    6321       338626 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    6322     93733141 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    6323      3718469 :            && CLASSTYPE_NON_AGGREGATE (t)
    6324     51489123 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6325       536797 :     CLASSTYPE_LITERAL_P (t) = false;
    6326              : 
    6327              :   /* C++14 DR 1684 removed this restriction.  */
    6328     49090220 :   if (cxx_dialect < cxx14
    6329     49219354 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    6330      1382700 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6331      1246918 :       if (TREE_CODE (fn) == FUNCTION_DECL
    6332       596859 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    6333         2707 :           && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    6334      1249273 :           && !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     49090220 : }
    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     49090220 : check_bases_and_members (tree t)
    6452              : {
    6453              :   /* Nonzero if the implicitly generated copy constructor should take
    6454              :      a non-const reference argument.  */
    6455     49090220 :   int cant_have_const_ctor;
    6456              :   /* Nonzero if the implicitly generated assignment operator
    6457              :      should take a non-const reference argument.  */
    6458     49090220 :   int no_const_asn_ref;
    6459     49090220 :   tree access_decls;
    6460     49090220 :   bool saved_complex_asn_ref;
    6461     49090220 :   bool saved_nontrivial_dtor;
    6462     49090220 :   tree fn;
    6463              : 
    6464              :   /* By default, we use const reference arguments and generate default
    6465              :      constructors.  */
    6466     49090220 :   cant_have_const_ctor = 0;
    6467     49090220 :   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     49090220 :   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     49090220 :   if (cxx_dialect >= cxx11)
    6477     48975448 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    6478      7135888 :       for (tree fn : ovl_range (dtor))
    6479      3567944 :         deduce_noexcept_on_destructor (fn);
    6480              : 
    6481              :   /* Check all the method declarations.  */
    6482     49090220 :   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     49090220 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    6488     49090220 :   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     49090220 :   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     49090220 :   if (!TYPE_CONTAINS_VPTR_P (t))
    6501     47378627 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    6502              : 
    6503              :   /* Do some bookkeeping that will guide the generation of implicitly
    6504              :      declared member functions.  */
    6505     50801813 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6506     50801813 :   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     49090220 :   TYPE_NEEDS_CONSTRUCTING (t)
    6513     49090220 :     |= (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     49090220 :   CLASSTYPE_NON_AGGREGATE (t)
    6522     49090220 :     |= (type_has_user_provided_or_explicit_constructor (t)
    6523     49090220 :         || 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     49090220 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    6527     49090220 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    6528     49090220 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    6529     50801813 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6530     50801813 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6531     50801813 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6532     50801813 :   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     49090220 :   if (CLASSTYPE_NON_POD_AGGREGATE (t))
    6536              :     {
    6537       823224 :       if (CLASSTYPE_NON_LAYOUT_POD_P (t))
    6538              :         /* It's non-POD for another reason.  */
    6539       755232 :         CLASSTYPE_NON_POD_AGGREGATE (t) = false;
    6540        67992 :       else if (abi_version_at_least (17))
    6541        67990 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6542              :     }
    6543              : 
    6544              :   /* P1008: Prohibit aggregates with user-declared constructors.  */
    6545     49090220 :   if (cxx_dialect >= cxx20 && TYPE_HAS_USER_CONSTRUCTOR (t))
    6546              :     {
    6547      6657567 :       CLASSTYPE_NON_AGGREGATE (t) = true;
    6548      6657567 :       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     49090220 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    6561     44558922 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    6562     51089743 :       && !type_has_non_user_provided_default_constructor (t))
    6563      1442112 :     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     49090220 :   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     49090220 :   if (warn_uninitialized
    6593              :       /* Classes with user-declared constructors are presumed to
    6594              :          initialize these members.  */
    6595       433405 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    6596              :       /* Aggregates can be initialized with brace-enclosed
    6597              :          initializers.  */
    6598     49455509 :       && 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     49090220 :   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    318214271 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6632    160747912 :     if (DECL_DECLARES_FUNCTION_P (fn)
    6633    134781261 :         && !DECL_ARTIFICIAL (fn)
    6634    133754313 :         && DECL_DEFAULTED_IN_CLASS_P (fn)
    6635              :         /* ...except handle comparisons later, in finish_struct_1.  */
    6636    275331711 :         && special_function_p (fn) != sfk_comparison)
    6637              :       {
    6638      6171607 :         bool imp_const_p
    6639     12343214 :           = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    6640      6171607 :              : !no_const_asn_ref);
    6641      6171685 :         defaulted_late_check (fn, imp_const_p);
    6642              :       }
    6643              : 
    6644     97763454 :   if (LAMBDA_TYPE_P (t))
    6645              :     /* "This class type is not an aggregate."  */
    6646       338811 :     CLASSTYPE_NON_AGGREGATE (t) = 1;
    6647              : 
    6648              :   /* Compute the 'literal type' property before we
    6649              :      do anything with non-static member functions.  */
    6650     49090220 :   finalize_literal_type_property (t);
    6651              : 
    6652              :   /* Create the in-charge and not-in-charge variants of constructors
    6653              :      and destructors.  */
    6654     49090220 :   clone_constructors_and_destructors (t);
    6655              : 
    6656              :   /* Process the using-declarations.  */
    6657    100299879 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6658      2119439 :     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     49090220 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6663     49090220 :     = 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     49090220 :   propagate_class_warmth_attribute (t);
    6670     49090220 : }
    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     49090220 : create_vtable_ptr (tree t, tree* virtuals_p)
    6681              : {
    6682     49090220 :   tree fn;
    6683              : 
    6684              :   /* Collect the virtual functions declared in T.  */
    6685    382385350 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6686    333295130 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6687    155151089 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6688    341052475 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6689              :       {
    6690      7757345 :         tree new_virtual = make_node (TREE_LIST);
    6691              : 
    6692      7757345 :         BV_FN (new_virtual) = fn;
    6693      7757345 :         BV_DELTA (new_virtual) = integer_zero_node;
    6694      7757345 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6695              : 
    6696      7757345 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6697      7757345 :         *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     49090220 :   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       244842 :       tree field;
    6726              : 
    6727       244842 :       field = build_decl (input_location,
    6728              :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6729       244842 :       DECL_VIRTUAL_P (field) = 1;
    6730       244842 :       DECL_ARTIFICIAL (field) = 1;
    6731       244842 :       DECL_FIELD_CONTEXT (field) = t;
    6732       244842 :       DECL_FCONTEXT (field) = t;
    6733       244842 :       if (TYPE_PACKED (t))
    6734            3 :         DECL_PACKED (field) = 1;
    6735              : 
    6736       244842 :       TYPE_VFIELD (t) = field;
    6737              : 
    6738              :       /* This class is non-empty.  */
    6739       244842 :       CLASSTYPE_EMPTY_P (t) = 0;
    6740              : 
    6741       244842 :       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     27057139 : propagate_binfo_offsets (tree binfo, tree offset)
    6754              : {
    6755     27057139 :   int i;
    6756     27057139 :   tree primary_binfo;
    6757     27057139 :   tree base_binfo;
    6758              : 
    6759              :   /* Update BINFO's offset.  */
    6760     27057139 :   BINFO_OFFSET (binfo)
    6761     27057139 :     = 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     27057139 :   primary_binfo = get_primary_binfo (binfo);
    6768              : 
    6769     28149497 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6770      1091358 :     propagate_binfo_offsets (primary_binfo, offset);
    6771              : 
    6772              :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6773              :      downwards.  */
    6774     30832196 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6775              :     {
    6776              :       /* Don't do the primary base twice.  */
    6777      4867331 :       if (base_binfo == primary_binfo)
    6778      1092274 :         continue;
    6779              : 
    6780      2682783 :       if (BINFO_VIRTUAL_P (base_binfo))
    6781       212832 :         continue;
    6782              : 
    6783      2469951 :       propagate_binfo_offsets (base_binfo, offset);
    6784              :     }
    6785     27057139 : }
    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     49090220 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6793              : {
    6794     49090220 :   tree vbase;
    6795     49090220 :   tree t = rli->t;
    6796     49090220 :   tree *next_field;
    6797              : 
    6798     49090220 :   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     22794176 :   next_field = &TYPE_FIELDS (t);
    6804    174080980 :   while (*next_field)
    6805    151286804 :     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     72636451 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6811              :     {
    6812     49842275 :       if (!BINFO_VIRTUAL_P (vbase))
    6813     49650255 :         continue;
    6814              : 
    6815       192020 :       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       183953 :           tree access = access_private_node;
    6820       183953 :           if (publicly_virtually_derived_p (BINFO_TYPE (vbase), t))
    6821       183070 :             access = access_public_node;
    6822       183953 :           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     46801025 : end_of_base (tree binfo)
    6833              : {
    6834     46801025 :   tree size;
    6835              : 
    6836     46801025 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6837            0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6838     46801025 :   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     41900348 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6843              :   else
    6844      4900677 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6845              : 
    6846     46801025 :   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     96483485 : end_of_class (tree t, eoc_mode mode)
    6860              : {
    6861     96483485 :   tree result = size_zero_node;
    6862     96483485 :   vec<tree, va_gc> *vbases;
    6863     96483485 :   tree binfo;
    6864     96483485 :   tree base_binfo;
    6865     96483485 :   tree offset;
    6866     96483485 :   int i;
    6867              : 
    6868     96483485 :   for (binfo = TYPE_BINFO (t), i = 0;
    6869    143181353 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6870              :     {
    6871     46697868 :       if (BINFO_VIRTUAL_P (base_binfo)
    6872     46697868 :           && (!BINFO_PRIMARY_P (base_binfo)
    6873         3390 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6874        88863 :         continue;
    6875              : 
    6876     46609005 :       offset = end_of_base (base_binfo);
    6877     46609005 :       if (tree_int_cst_lt (result, offset))
    6878     46697868 :         result = offset;
    6879              :     }
    6880              : 
    6881    801294069 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6882    704810584 :     if (TREE_CODE (field) == FIELD_DECL
    6883    704810584 :         && !DECL_FIELD_IS_BASE (field))
    6884              :       {
    6885     27788985 :         tree size = DECL_SIZE_UNIT (field);
    6886     27788985 :         if (!size)
    6887              :           /* DECL_SIZE_UNIT can be null for a flexible array.  */
    6888         1994 :           continue;
    6889              : 
    6890     27786991 :         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       445777 :           size = TYPE_SIZE_UNIT (TREE_TYPE (field));
    6894              : 
    6895     27786991 :         if (DECL_BIT_FIELD_TYPE (field))
    6896              :           {
    6897       897757 :             offset = size_binop (PLUS_EXPR, bit_position (field),
    6898              :                                  DECL_SIZE (field));
    6899       897757 :             offset = size_binop (CEIL_DIV_EXPR, offset, bitsize_unit_node);
    6900       897757 :             offset = fold_convert (sizetype, offset);
    6901              :           }
    6902              :         else
    6903     26889234 :           offset = size_binop (PLUS_EXPR, byte_position (field), size);
    6904     27786991 :         if (tree_int_cst_lt (result, offset))
    6905    704810584 :           result = offset;
    6906              :       }
    6907              : 
    6908     96483485 :   if (mode != eoc_nvsize)
    6909     49312439 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6910     49312439 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6911              :       {
    6912       192029 :         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       192020 :           offset = end_of_base (base_binfo);
    6918       192029 :         if (tree_int_cst_lt (result, offset))
    6919       181608 :           result = offset;
    6920              :       }
    6921              : 
    6922     96483485 :   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    356768064 : check_non_pod_aggregate (tree field)
    6931              : {
    6932   1070135655 :   if ((!abi_version_crosses (17) || cxx_dialect < cxx14)
    6933    731727912 :       && (!abi_version_crosses (21) || cxx_dialect < cxx20))
    6934              :     return;
    6935    336499332 :   if (TREE_CODE (field) != FIELD_DECL
    6936    336499332 :       || (!DECL_FIELD_IS_BASE (field)
    6937     15352855 :           && !field_poverlapping_p (field)))
    6938    314163383 :     return;
    6939     22335949 :   tree next = DECL_CHAIN (field);
    6940    111713160 :   while (next && TREE_CODE (next) != FIELD_DECL) next = DECL_CHAIN (next);
    6941     22335949 :   if (!next)
    6942              :     return;
    6943      1660330 :   tree type = TREE_TYPE (field);
    6944      1660330 :   if (TYPE_IDENTIFIER (type) == as_base_identifier)
    6945       904224 :     type = TYPE_CONTEXT (type);
    6946      1639895 :   if (!CLASS_TYPE_P (type)
    6947      1639894 :       || is_empty_class (type)
    6948      2511368 :       || (!CLASSTYPE_NON_POD_AGGREGATE (type)
    6949       849504 :           && !CLASSTYPE_NON_AGGREGATE_POD (type)))
    6950      1658788 :     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     49090220 : maybe_warn_about_inaccessible_bases (tree t)
    6998              : {
    6999     49090220 :   int i;
    7000     49090220 :   vec<tree, va_gc> *vbases;
    7001     49090220 :   tree basetype;
    7002     49090220 :   tree binfo;
    7003     49090220 :   tree base_binfo;
    7004              : 
    7005              :   /* If not checking for warning then return early.  */
    7006     49090220 :   if (!warn_inaccessible_base)
    7007     49090220 :     return;
    7008              : 
    7009              :   /* If there are no repeated bases, nothing can be ambiguous.  */
    7010     49090064 :   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      9625490 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    7041              : {
    7042      9625490 :   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     49090220 : include_empty_classes (record_layout_info rli)
    7050              : {
    7051     49090220 :   tree eoc;
    7052     49090220 :   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     49090220 :   eoc = end_of_class (rli->t, eoc_vsize);
    7060     49090220 :   rli_size = rli_size_unit_so_far (rli);
    7061     49090220 :   if (TREE_CODE (rli_size) == INTEGER_CST
    7062     49090220 :       && tree_int_cst_lt (rli_size, eoc))
    7063              :     {
    7064              :       /* The size should have been rounded to a whole byte.  */
    7065     20221937 :       gcc_assert (tree_int_cst_equal
    7066              :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    7067     20221937 :       rli->bitpos
    7068     20221937 :         = 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     20221937 :       normalize_rli (rli);
    7076              :     }
    7077     49090220 : }
    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     49090220 : layout_class_type (tree t, tree *virtuals_p)
    7085              : {
    7086     49090220 :   tree non_static_data_members;
    7087     49090220 :   tree field;
    7088     49090220 :   tree vptr;
    7089     49090220 :   record_layout_info rli;
    7090              :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    7091              :      types that appear at that offset.  */
    7092     49090220 :   splay_tree empty_base_offsets;
    7093              :   /* True if the last field laid out was a bit-field.  */
    7094     49090220 :   bool last_field_was_bitfield = false;
    7095              :   /* The location at which the next field should be inserted.  */
    7096     49090220 :   tree *next_field;
    7097              : 
    7098              :   /* Keep track of the first non-static data member.  */
    7099     49090220 :   non_static_data_members = TYPE_FIELDS (t);
    7100              : 
    7101              :   /* Start laying out the record.  */
    7102     49090220 :   rli = start_record_layout (t);
    7103              : 
    7104              :   /* Mark all the primary bases in the hierarchy.  */
    7105     49090220 :   determine_primary_bases (t);
    7106              : 
    7107              :   /* Create a pointer to our virtual function table.  */
    7108     49090220 :   vptr = create_vtable_ptr (t, virtuals_p);
    7109              : 
    7110              :   /* The vptr is always the first thing in the class.  */
    7111     49090220 :   if (vptr)
    7112              :     {
    7113       244842 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    7114       244842 :       TYPE_FIELDS (t) = vptr;
    7115       244842 :       next_field = &DECL_CHAIN (vptr);
    7116       244842 :       place_field (rli, vptr);
    7117              :     }
    7118              :   else
    7119     48845378 :     next_field = &TYPE_FIELDS (t);
    7120              : 
    7121              :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    7122     49090220 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    7123              :                                        NULL, NULL);
    7124     49090220 :   build_base_fields (rli, empty_base_offsets, next_field);
    7125              : 
    7126              :   /* Layout the non-static data members.  */
    7127    382385350 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    7128              :     {
    7129    333295130 :       tree type;
    7130    333295130 :       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    333295130 :       if (TREE_CODE (field) != FIELD_DECL)
    7135              :         {
    7136    316432211 :           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    316432211 :           if (VAR_P (field))
    7148              :             {
    7149     13472273 :               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     13472273 :               determine_visibility (field);
    7154              :             }
    7155    316432211 :           continue;
    7156              :         }
    7157              : 
    7158     16862919 :       type = TREE_TYPE (field);
    7159     16862919 :       if (type == error_mark_node)
    7160          165 :         continue;
    7161              : 
    7162     16862754 :       padding = NULL_TREE;
    7163              : 
    7164     16862754 :       bool might_overlap = field_poverlapping_p (field);
    7165              : 
    7166       275964 :       if (might_overlap && CLASS_TYPE_P (type)
    7167     17115673 :           && (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       252789 :           if (CLASSTYPE_EMPTY_P (type))
    7172       222615 :             DECL_SIZE (field) = DECL_SIZE_UNIT (field) = size_zero_node;
    7173              :           else
    7174              :             {
    7175        30174 :               tree size = end_of_class (type, eoc_nv_or_dsize);
    7176        30174 :               DECL_SIZE_UNIT (field) = size;
    7177        30174 :               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     16862754 :       if (DECL_C_BIT_FIELD (field)
    7185     16862754 :           && 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     16861980 :       else if (might_overlap && is_empty_class (type))
    7248              :         {
    7249       222615 :           SET_DECL_FIELD_ABI_IGNORED (field, 1);
    7250       222615 :           layout_empty_base_or_field (rli, field, empty_base_offsets);
    7251              :         }
    7252              :       else
    7253     16639365 :         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     16862754 :       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     16862754 :       if (warn_abi
    7263     15281153 :           && 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       583904 :           && !warning_suppressed_p (field, OPT_Wabi)
    7269       583904 :           && !last_field_was_bitfield
    7270     16986502 :           && !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     16862754 :       if (DECL_C_BIT_FIELD (field))
    7289              :         {
    7290       634395 :           unsigned HOST_WIDE_INT width;
    7291       634395 :           tree ftype = TREE_TYPE (field);
    7292       634395 :           width = tree_to_uhwi (DECL_SIZE (field));
    7293       634395 :           if (width != TYPE_PRECISION (ftype))
    7294              :             {
    7295       500016 :               TREE_TYPE (field)
    7296      1000032 :                 = c_build_bitfield_integer_type (width,
    7297       500016 :                                                  TYPE_UNSIGNED (ftype));
    7298       500016 :               TREE_TYPE (field)
    7299      1000032 :                 = 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     16862754 :       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     16862754 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    7326              :     }
    7327              : 
    7328     49090220 :   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      5246250 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    7334      5246250 :       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    405858284 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7343              :     {
    7344    356768064 :       if (TREE_CODE (field) == FIELD_DECL
    7345     40335853 :           && 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       634395 :           && (DECL_SIZE (field) == NULL_TREE
    7352       634395 :               || integer_zerop (DECL_SIZE (field)))
    7353    356769233 :           && TREE_TYPE (field) != error_mark_node)
    7354         1169 :         SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
    7355    356768064 :       check_non_pod_aggregate (field);
    7356              :     }
    7357              : 
    7358     49090220 :   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     47361549 :       tree base_t = make_node (TREE_CODE (t));
    7363     47361549 :       tree base_d = create_implicit_typedef (as_base_identifier, base_t);
    7364              : 
    7365     47361549 :       TYPE_CONTEXT (base_t) = t;
    7366     47361549 :       DECL_CONTEXT (base_d) = t;
    7367              : 
    7368     47361549 :       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     47361549 :       tree eoc = end_of_class (t, eoc_nvsize);
    7380     47361549 :       TYPE_SIZE_UNIT (base_t)
    7381     47361549 :         = 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     47361549 :       TYPE_SIZE (base_t)
    7388     47361549 :         = 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     47361549 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    7394     47361549 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    7395     47361549 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    7396     47361549 :       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     47361549 :       next_field = &TYPE_FIELDS (base_t);
    7401    394514002 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7402    347152453 :         if (TREE_CODE (field) == FIELD_DECL)
    7403              :           {
    7404     33870843 :             *next_field = copy_node (field);
    7405              :             /* Zap any NSDMI, it's not needed and might be a deferred
    7406              :                parse.  */
    7407     33870843 :             DECL_INITIAL (*next_field) = NULL_TREE;
    7408     33870843 :             DECL_CONTEXT (*next_field) = base_t;
    7409     33870843 :             next_field = &DECL_CHAIN (*next_field);
    7410              :           }
    7411     47361549 :       *next_field = NULL_TREE;
    7412              : 
    7413              :       /* We use the base type for trivial assignments, and hence it
    7414              :          needs a mode.  */
    7415     47361549 :       compute_record_mode (base_t);
    7416              : 
    7417              :       /* Record the base version of the type.  */
    7418     47361549 :       CLASSTYPE_AS_BASE (t) = base_t;
    7419              :     }
    7420              :   else
    7421      1728671 :     CLASSTYPE_AS_BASE (t) = t;
    7422              : 
    7423              :   /* Every empty class contains an empty class.  */
    7424     49090220 :   if (CLASSTYPE_EMPTY_P (t))
    7425     40905752 :     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     49090220 :   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     49090220 :   layout_virtual_bases (rli, empty_base_offsets);
    7437              : 
    7438              :   /* Make sure that empty classes are reflected in RLI at this
    7439              :      point.  */
    7440     49090220 :   include_empty_classes (rli);
    7441              : 
    7442              :   /* Make sure not to create any structures with zero size.  */
    7443     49090220 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    7444     20684112 :     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     49090220 :   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     49090220 :   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     49090220 :   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     47361549 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    7462     96451755 :       && tree_int_cst_equal (TYPE_SIZE (t),
    7463     47361535 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    7464     25680596 :     CLASSTYPE_AS_BASE (t) = t;
    7465              : 
    7466     49090220 :   if (TYPE_SIZE_UNIT (t)
    7467     49090220 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    7468     49090220 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    7469     98180431 :       && !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     49090220 :   maybe_warn_about_inaccessible_bases (t);
    7474              : 
    7475              :   /* Now that we're done with layout, give the base fields the real types.  */
    7476    406040013 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7477    356949793 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    7478     20444310 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    7479              : 
    7480              :   /* Clean up.  */
    7481     49090220 :   splay_tree_delete (empty_base_offsets);
    7482              : 
    7483     49090220 :   if (CLASSTYPE_EMPTY_P (t)
    7484     89995972 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    7485     40905752 :                           TYPE_SIZE_UNIT (t)))
    7486        60673 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    7487     49090220 : }
    7488              : 
    7489              : /* Determine the "key method" for the class type indicated by TYPE,
    7490              :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    7491              : 
    7492              : void
    7493      1711593 : determine_key_method (tree type)
    7494              : {
    7495      1711593 :   tree method;
    7496              : 
    7497      1711593 :   if (processing_template_decl
    7498      1711593 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    7499      2464578 :       || 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      7643552 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    7507      7454971 :     if (TREE_CODE (method) == FUNCTION_DECL
    7508      6076417 :         && 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      1240761 :         && ! DECL_NONGNU_INLINE_P (method)
    7514      8040751 :         && ! DECL_PURE_VIRTUAL_P (method))
    7515              :       {
    7516       564375 :         SET_CLASSTYPE_KEY_METHOD (type, method);
    7517       564375 :         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     40689065 : field_nonempty_p (const_tree fld)
    7528              : {
    7529     40689065 :   if (TREE_CODE (fld) == ERROR_MARK)
    7530              :     return false;
    7531              : 
    7532     40689065 :   tree type = TREE_TYPE (fld);
    7533     40689065 :   if (TREE_CODE (fld) == FIELD_DECL
    7534     40689065 :       && TREE_CODE (type) != ERROR_MARK
    7535     81378130 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    7536     40559125 :     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     82245982 : 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     82245982 :   if (TREE_CODE (t) == UNION_TYPE)
    7585      1270879 :     pun = true;
    7586              : 
    7587     82245982 :   tree fld = TYPE_FIELDS (t);
    7588     82245982 :   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     56193226 :       for (; (fld = next_subobject_field (fld)); fld = DECL_CHAIN (fld))
    7606     23930247 :         if (DECL_ARTIFICIAL (fld))
    7607      7220123 :           continue;
    7608     16710124 :         else if (TREE_TYPE (fld) == error_mark_node)
    7609              :           return;
    7610     16710097 :         else if (TREE_CODE (TREE_TYPE (fld)) == ARRAY_TYPE
    7611     16710097 :                  || field_nonempty_p (fld))
    7612              :           last_fld = fld;
    7613              :       fld = last_fld;
    7614              :     }
    7615    625262899 :   for (; fld; fld = DECL_CHAIN (fld))
    7616              :     {
    7617    543017517 :       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    543874102 :       if (TREE_CODE (fld) == TYPE_DECL
    7629    126018871 :           && DECL_IMPLICIT_TYPEDEF_P (fld)
    7630      7602995 :           && CLASS_TYPE_P (TREE_TYPE (fld))
    7631    548713041 :           && (IDENTIFIER_ANON_P (DECL_NAME (fld))
    7632      4838950 :               || 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       856585 :           check_flexarrays (TREE_TYPE (fld));
    7638       856585 :           continue;
    7639              :         }
    7640              : 
    7641              :       /* Skip anything that's GCC-generated or not a (non-static) data
    7642              :          member.  */
    7643    542160932 :       if (DECL_ARTIFICIAL (fld) || TREE_CODE (fld) != FIELD_DECL)
    7644    516384563 :         continue;
    7645              : 
    7646              :       /* Type of the member.  */
    7647     25776369 :       tree fldtype = TREE_TYPE (fld);
    7648     25776369 :       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     35206317 :       while (TREE_CODE (eltype) == ARRAY_TYPE
    7656     35206317 :              || INDIRECT_TYPE_P (eltype))
    7657      9430093 :         eltype = TREE_TYPE (eltype);
    7658              : 
    7659     25776224 :       if (RECORD_OR_UNION_TYPE_P (eltype))
    7660              :         {
    7661      9767917 :           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     13122734 :           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      6428851 :               bool first = fmem->first;
    7680      6428851 :               tree array = fmem->array;
    7681     13659224 :               bool maybe_anon_p = TYPE_UNNAMED_P (eltype);
    7682       829050 :               if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (eltype) : NULL_TREE)
    7683       829050 :                 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      6428851 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    7690      1990350 :                 fmem->first = false;
    7691              : 
    7692     11089464 :               find_flexarrays (eltype, fmem, false, !maybe_anon_p, pun,
    7693      4660613 :                                !pstr && TREE_CODE (t) == RECORD_TYPE
    7694              :                                ? fld : pstr);
    7695              : 
    7696      6428851 :               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      6427812 :               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      1989968 :                 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      6427812 :               if (base_p)
    7718      1135199 :                 continue;
    7719              :             }
    7720              :         }
    7721              : 
    7722     24639558 :       if (field_nonempty_p (fld))
    7723              :         {
    7724              :           /* Remember the first non-static data member.  */
    7725     24505243 :           if (!fmem->first)
    7726      9513917 :             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     24505243 :           if (fmem->array && !fmem->after[pun])
    7732         1508 :             fmem->after[pun] = fld;
    7733              :         }
    7734              : 
    7735              :       /* Skip non-arrays.  */
    7736     24639558 :       if (TREE_CODE (fldtype) != ARRAY_TYPE)
    7737     22724509 :         continue;
    7738              : 
    7739              :       /* Determine the upper bound of the array if it has one.  */
    7740      1915049 :       if (TYPE_DOMAIN (fldtype))
    7741              :         {
    7742      1913427 :           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      1912387 :           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         2446 :               fmem->array = fld;
    7756         2446 :               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         2140 : diagnose_invalid_flexarray (const flexmems_t *fmem)
    7790              : {
    7791         2140 :   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         2140 : }
    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     48757063 : diagnose_flexarrays (tree t, const flexmems_t *fmem)
    7812              : {
    7813     48757063 :   if (!fmem->array)
    7814              :     return;
    7815              : 
    7816         3989 :   if (fmem->first && !fmem->after[0])
    7817              :     {
    7818         1858 :       diagnose_invalid_flexarray (fmem);
    7819         1858 :       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     77006873 : 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     77006873 :   flexmems_t flexmems = flexmems_t ();
    7903     77006873 :   if (!fmem)
    7904              :     fmem = &flexmems;
    7905     27060068 :   else if (fmem->array && fmem->first && fmem->after[0])
    7906            0 :     return;
    7907              : 
    7908     77006873 :   tree fam = fmem->array;
    7909              : 
    7910              :   /* Recursively check the primary base class first.  */
    7911     77006873 :   if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7912              :     {
    7913      2559489 :       tree basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
    7914      2559489 :       check_flexarrays (basetype, fmem, true);
    7915              :     }
    7916              : 
    7917              :   /* Recursively check the base classes.  */
    7918     77006873 :   int nbases = TYPE_BINFO (t) ? BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) : 0;
    7919    104132307 :   for (int i = 0; i < nbases; ++i)
    7920              :     {
    7921     27125434 :       tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
    7922              : 
    7923              :       /* The primary base class was already checked above.  */
    7924     27125434 :       if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
    7925      2559334 :         continue;
    7926              : 
    7927              :       /* Virtual base classes are at the end.  */
    7928     24566100 :       if (BINFO_VIRTUAL_P (base_binfo))
    7929       257544 :         continue;
    7930              : 
    7931              :       /* Check the base class.  */
    7932     24308556 :       check_flexarrays (BINFO_TYPE (base_binfo), fmem, /*base_p=*/true);
    7933              :     }
    7934              : 
    7935     77006873 :   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     49946805 :       int i;
    7941     49946805 :       tree base_binfo;
    7942     49946805 :       vec<tree, va_gc> *vbases;
    7943     50138828 :       for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    7944     50138828 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    7945              :         {
    7946              :           /* Check the virtual base class.  */
    7947       192023 :           tree basetype = TREE_TYPE (base_binfo);
    7948              : 
    7949       192023 :           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    155932612 :   bool maybe_anon_p = TYPE_UNNAMED_P (t);
    7956      1573113 :   if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE)
    7957      1573113 :     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     77006873 :   if (fmem != &flexmems || !maybe_anon_p)
    7962    102877377 :     find_flexarrays (t, fmem, base_p || fam != fmem->array);
    7963              : 
    7964     77006873 :   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     48757063 :     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     49090220 : finish_struct_1 (tree t)
    7979              : {
    7980     49090220 :   tree x;
    7981              :   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
    7982     49090220 :   tree virtuals = NULL_TREE;
    7983              : 
    7984     49090220 :   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     49090220 :   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     49090220 :   TYPE_SIZE (t) = NULL_TREE;
    8006     49090220 :   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
    8007              : 
    8008              :   /* Make assumptions about the class; we'll reset the flags if
    8009              :      necessary.  */
    8010     49090220 :   CLASSTYPE_EMPTY_P (t) = 1;
    8011     49090220 :   CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
    8012     49090220 :   CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
    8013     49090220 :   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     49090220 :   check_bases_and_members (t);
    8018              : 
    8019              :   /* Find the key method.  */
    8020     49090220 :   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      1711593 :       if (targetm.cxx.key_method_may_be_inline ())
    8031      1711593 :         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      1711593 :       if (!CLASSTYPE_KEY_METHOD (t) || module_attach_p ())
    8041      1147263 :         vec_safe_push (keyed_classes, t);
    8042              :     }
    8043              : 
    8044              :   /* Layout the class itself.  */
    8045     49090220 :   layout_class_type (t, &virtuals);
    8046              :   /* COMPLETE_TYPE_P is now true.  */
    8047              : 
    8048     49090220 :   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     49090220 :   check_flexarrays (t);
    8054              : 
    8055     49090220 :   virtuals = modify_all_vtables (t, nreverse (virtuals));
    8056              : 
    8057              :   /* If necessary, create the primary vtable for this class.  */
    8058     49090220 :   if (virtuals || TYPE_CONTAINS_VPTR_P (t))
    8059              :     {
    8060              :       /* We must enter these virtuals into the table.  */
    8061      1711593 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    8062       244842 :         build_primary_vtable (NULL_TREE, t);
    8063      1466751 :       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      1711593 :       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     49090220 :   if (TYPE_CONTAINS_VPTR_P (t))
    8076              :     {
    8077      1711593 :       int vindex;
    8078      1711593 :       tree fn;
    8079              : 
    8080      1711593 :       if (BINFO_VTABLE (TYPE_BINFO (t)))
    8081      1711593 :         gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
    8082      1711593 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    8083       244842 :         gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
    8084              : 
    8085              :       /* Add entries for virtual functions introduced by this class.  */
    8086      1711593 :       BINFO_VIRTUALS (TYPE_BINFO (t))
    8087      1711593 :         = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
    8088              : 
    8089              :       /* Set DECL_VINDEX for all functions declared in this class.  */
    8090      1711593 :       for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
    8091     11562654 :            fn;
    8092      9851061 :            fn = TREE_CHAIN (fn),
    8093      9851061 :              vindex += (TARGET_VTABLE_USES_DESCRIPTORS
    8094              :                         ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
    8095              :         {
    8096      9851061 :           tree fndecl = BV_FN (fn);
    8097              : 
    8098      9851061 :           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      9850935 :           else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
    8104      7757345 :             DECL_VINDEX (fndecl) = build_int_cst (NULL_TREE, vindex);
    8105              :         }
    8106              :     }
    8107              : 
    8108     49090220 :   validate_trivial_abi_attribute (t);
    8109              : 
    8110     49090220 :   finish_struct_bits (t);
    8111              : 
    8112     49090220 :   set_method_tm_attributes (t);
    8113     49090220 :   if (flag_openmp || flag_openmp_simd)
    8114       117787 :     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    406040337 :   for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8119    356950117 :     if (DECL_DECLARES_FUNCTION_P (x))
    8120              :       {
    8121              :         /* Synthesize constexpr defaulted comparisons.  */
    8122    198770689 :         if (!DECL_ARTIFICIAL (x)
    8123    197743363 :             && DECL_DEFAULTED_IN_CLASS_P (x)
    8124    214134031 :             && special_function_p (x) == sfk_comparison)
    8125        36053 :           defaulted_late_check (x);
    8126    198770689 :         DECL_IN_AGGR_P (x) = false;
    8127              :       }
    8128     13472273 :     else if (VAR_P (x) && TREE_STATIC (x)
    8129     13472273 :              && TREE_TYPE (x) != error_mark_node
    8130    171651636 :              && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
    8131       140904 :       SET_DECL_MODE (x, TYPE_MODE (t));
    8132              : 
    8133              :   /* Complain if one of the field types requires lower visibility.  */
    8134     49090220 :   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     49090220 :   finish_vtbls (t);
    8139              : 
    8140              :   /* Build the VTT for T.  */
    8141     49090220 :   build_vtt (t);
    8142              : 
    8143     49090220 :   if (warn_nonvdtor
    8144          147 :       && TYPE_POLYMORPHIC_P (t) && accessible_nvdtor_p (t)
    8145     49090256 :       && !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     49090220 :   complete_vars (t);
    8151              : 
    8152     49090220 :   if (warn_overloaded_virtual)
    8153       423911 :     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     49090220 :   targetm.cxx.adjust_class_at_definition (t);
    8159              : 
    8160     49090220 :   maybe_suppress_debug_info (t);
    8161              : 
    8162     49090220 :   if (flag_vtable_verify)
    8163           12 :     vtv_save_class_info (t);
    8164              : 
    8165     49090220 :   dump_class_hierarchy (t);
    8166              : 
    8167              :   /* Finish debugging output for this type.  */
    8168     49090220 :   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
    8169              : 
    8170     49090220 :   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     67782000 : unreverse_member_declarations (tree t)
    8204              : {
    8205     67782000 :   tree next;
    8206     67782000 :   tree prev;
    8207     67782000 :   tree x;
    8208              : 
    8209              :   /* The following lists are all in reverse order.  Put them in
    8210              :      declaration order now.  */
    8211     67782000 :   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     67782000 :   prev = NULL_TREE;
    8217     67782000 :   for (x = TYPE_FIELDS (t);
    8218    328028422 :        x && TREE_CODE (x) != TYPE_DECL;
    8219    260246422 :        x = next)
    8220              :     {
    8221    260246422 :       next = DECL_CHAIN (x);
    8222    260246422 :       DECL_CHAIN (x) = prev;
    8223    260246422 :       prev = x;
    8224              :     }
    8225              : 
    8226     67782000 :   if (prev)
    8227              :     {
    8228     27132333 :       DECL_CHAIN (TYPE_FIELDS (t)) = x;
    8229     27132333 :       TYPE_FIELDS (t) = prev;
    8230              :     }
    8231     67782000 : }
    8232              : 
    8233              : /* Classes, structs or unions T marked with hotness attributes propagate
    8234              :    the attribute to all methods.  */
    8235              : 
    8236              : void
    8237     49090220 : propagate_class_warmth_attribute (tree t)
    8238              : {
    8239     49090220 :   if (t == NULL_TREE
    8240     49090220 :       || !(TREE_CODE (t) == RECORD_TYPE
    8241              :            || TREE_CODE (t) == UNION_TYPE))
    8242              :     return;
    8243              : 
    8244     49090220 :   tree class_has_cold_attr
    8245     49090220 :     = lookup_attribute ("cold", TYPE_ATTRIBUTES (t));
    8246     49090220 :   tree class_has_hot_attr
    8247     49090220 :     = lookup_attribute ("hot", TYPE_ATTRIBUTES (t));
    8248              : 
    8249     49090220 :   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     29351013 : finish_struct (tree t, tree attributes)
    8257              : {
    8258     29351013 :   location_t saved_loc = input_location;
    8259              : 
    8260              :   /* Now that we've got all the field declarations, reverse everything
    8261              :      as necessary.  */
    8262     29351013 :   unreverse_member_declarations (t);
    8263              : 
    8264     29351013 :   cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    8265     29351013 :   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     29351013 :   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
    8270              : 
    8271     29351013 :   if (processing_template_decl)
    8272              :     {
    8273     18691780 :       tree x;
    8274              : 
    8275    146309454 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8276    127617674 :         if (DECL_DECLARES_FUNCTION_P (x))
    8277              :           {
    8278     71294775 :             DECL_IN_AGGR_P (x) = false;
    8279     71294775 :             if (DECL_VIRTUAL_P (x))
    8280      1810867 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    8281              :           }
    8282     56322899 :         else if (TREE_CODE (x) == FIELD_DECL)
    8283              :           {
    8284     11887759 :             if (TREE_PROTECTED (x) || TREE_PRIVATE (x))
    8285      6162669 :               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     18691780 :       tree ass_op = build_lang_decl (USING_DECL, assign_op_identifier,
    8294              :                                      NULL_TREE);
    8295     18691780 :       DECL_CONTEXT (ass_op) = t;
    8296     18691780 :       USING_DECL_SCOPE (ass_op) = t;
    8297     18691780 :       DECL_DEPENDENT_P (ass_op) = true;
    8298     18691780 :       DECL_ARTIFICIAL (ass_op) = true;
    8299     18691780 :       DECL_CHAIN (ass_op) = TYPE_FIELDS (t);
    8300     18691780 :       TYPE_FIELDS (t) = ass_op;
    8301              : 
    8302     18691780 :       TYPE_SIZE (t) = bitsize_zero_node;
    8303     18691780 :       TYPE_SIZE_UNIT (t) = size_zero_node;
    8304              :       /* COMPLETE_TYPE_P is now true.  */
    8305              : 
    8306     18691780 :       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     18691780 :       CLASSTYPE_PURE_VIRTUALS (t) = NULL;
    8316    165001234 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    8317    146309454 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P (x))
    8318       264260 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    8319     18691780 :       complete_vars (t);
    8320              : 
    8321              :       /* Remember current #pragma pack value.  */
    8322     18691780 :       TYPE_PRECISION (t) = maximum_field_alignment;
    8323              : 
    8324     18691780 :       if (cxx_dialect < cxx20)
    8325              :         {
    8326       583781 :           if (!CLASSTYPE_NON_AGGREGATE (t)
    8327       583781 :               && type_has_user_provided_or_explicit_constructor (t))
    8328        19115 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    8329              :         }
    8330     18107999 :       else if (TYPE_HAS_USER_CONSTRUCTOR (t))
    8331      5560653 :         CLASSTYPE_NON_AGGREGATE (t) = 1;
    8332              : 
    8333              :       /* Fix up any variants we've already built.  */
    8334     18691780 :       fixup_type_variants (t);
    8335              :     }
    8336              :   else
    8337     10659233 :     finish_struct_1 (t);
    8338              :   /* COMPLETE_TYPE_P is now true.  */
    8339              : 
    8340     29351013 :   maybe_warn_about_overly_private_class (t);
    8341              : 
    8342     29351013 :   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        13805 :       bool ok = false;
    8349        13805 :       if (processing_template_decl)
    8350              :         {
    8351        13805 :           tree f = next_aggregate_field (TYPE_FIELDS (t));
    8352        13805 :           if (f && TYPE_PTR_P (TREE_TYPE (f)))
    8353              :             {
    8354        13802 :               f = next_aggregate_field (DECL_CHAIN (f));
    8355        13802 :               if (f && same_type_p (TREE_TYPE (f), size_type_node))
    8356              :                 ok = true;
    8357              :             }
    8358              :         }
    8359              :       /* It also cannot be a union.  */
    8360        13805 :       ok &= NON_UNION_CLASS_TYPE_P (t);
    8361        13802 :       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     29351004 :   input_location = saved_loc;
    8367              : 
    8368     29351004 :   TYPE_BEING_DEFINED (t) = 0;
    8369              : 
    8370     29351004 :   if (current_class_type)
    8371     29351004 :     popclass ();
    8372              :   else
    8373            0 :     error ("trying to finish struct, but kicked out due to previous parse errors");
    8374              : 
    8375     29351004 :   if (flag_openmp)
    8376       716850 :     for (tree decl = TYPE_FIELDS (t); decl; decl = DECL_CHAIN (decl))
    8377       603794 :       if (TREE_CODE (decl) == FUNCTION_DECL
    8378       603794 :           && 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     18691771 :   if (processing_template_decl && at_function_scope_p ()
    8384              :       /* Lambdas are defined by the LAMBDA_EXPR.  */
    8385     31717781 :       && !LAMBDA_TYPE_P (t))
    8386       238093 :     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     30870749 :   if (at_function_scope_p () && !LAMBDA_TYPE_P (t))
    8391       245268 :     maybe_key_decl (current_scope (), TYPE_NAME (t));
    8392              : 
    8393     29351004 :   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     15180675 : fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
    8409              : {
    8410              : #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
    8411              : 
    8412     15180675 :   switch (TREE_CODE (instance))
    8413              :     {
    8414      2247264 :     case INDIRECT_REF:
    8415      2247264 :       if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
    8416              :         return NULL_TREE;
    8417              :       else
    8418      2234444 :         return RECUR (TREE_OPERAND (instance, 0));
    8419              : 
    8420       136042 :     case CALL_EXPR:
    8421              :       /* This is a call to a constructor, hence it's never zero.  */
    8422       136042 :       if (CALL_EXPR_FN (instance)
    8423       136042 :           && TREE_HAS_CONSTRUCTOR (instance))
    8424              :         {
    8425            0 :           if (nonnull)
    8426            0 :             *nonnull = 1;
    8427            0 :           return TREE_TYPE (instance);
    8428              :         }
    8429       136042 :       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        45333 :     case SAVE_EXPR:
    8441              :       /* This is a call to a constructor, hence it's never zero.  */
    8442        45333 :       if (TREE_HAS_CONSTRUCTOR (instance))
    8443              :         {
    8444            0 :           if (nonnull)
    8445            0 :             *nonnull = 1;
    8446            0 :           return TREE_TYPE (instance);
    8447              :         }
    8448        45333 :       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      2810584 :     CASE_CONVERT:
    8462      2810584 :       return RECUR (TREE_OPERAND (instance, 0));
    8463              : 
    8464       795453 :     case ADDR_EXPR:
    8465       795453 :       instance = TREE_OPERAND (instance, 0);
    8466       795453 :       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       793774 :           tree t = get_base_address (instance);
    8471              :           /* ??? Probably should check DECL_WEAK here.  */
    8472       793774 :           if (t && DECL_P (t))
    8473       116639 :             *nonnull = 1;
    8474              :         }
    8475       795453 :       return RECUR (instance);
    8476              : 
    8477      1092582 :     case COMPONENT_REF:
    8478              :       /* If this component is really a base class reference, then the field
    8479              :          itself isn't definitive.  */
    8480      1092582 :       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
    8481         1264 :         return RECUR (TREE_OPERAND (instance, 0));
    8482      1091318 :       return RECUR (TREE_OPERAND (instance, 1));
    8483              : 
    8484      1463886 :     case VAR_DECL:
    8485      1463886 :     case FIELD_DECL:
    8486      1463886 :       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
    8487      1463886 :           && 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      7470930 :     case TARGET_EXPR:
    8495      7470930 :     case PARM_DECL:
    8496      7470930 :     case RESULT_DECL:
    8497      7470930 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (instance)))
    8498              :         {
    8499      1838554 :           if (nonnull)
    8500      1837100 :             *nonnull = 1;
    8501      1838554 :           return TREE_TYPE (instance);
    8502              :         }
    8503      5632376 :       else if (instance == current_class_ptr)
    8504              :         {
    8505      4791731 :           if (nonnull)
    8506      4150609 :             *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      4791731 :           if (current_scope () != current_function_decl
    8512      4791731 :               || (DECL_LANG_SPECIFIC (current_function_decl)
    8513      9583214 :                   && (DECL_CONSTRUCTOR_P (current_function_decl)
    8514      2332136 :                       || DECL_DESTRUCTOR_P (current_function_decl))))
    8515              :             {
    8516      2547955 :               if (cdtorp)
    8517      2547955 :                 *cdtorp = 1;
    8518      2547955 :               return TREE_TYPE (TREE_TYPE (instance));
    8519              :             }
    8520              :         }
    8521       840645 :       else if (TYPE_REF_P (TREE_TYPE (instance)))
    8522              :         {
    8523              :           /* We only need one hash table because it is always left empty.  */
    8524       672169 :           if (!fixed_type_or_null_ref_ht)
    8525        13369 :             fixed_type_or_null_ref_ht
    8526        13369 :               = new hash_table<nofree_ptr_hash<tree_node> > (37);
    8527              : 
    8528              :           /* Reference variables should be references to objects.  */
    8529       672169 :           if (nonnull)
    8530       669709 :             *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       672169 :           if (VAR_P (instance)
    8536        22026 :               && DECL_INITIAL (instance)
    8537         2452 :               && !type_dependent_expression_p_push (DECL_INITIAL (instance))
    8538       674621 :               && !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       353472 :     case VIEW_CONVERT_EXPR:
    8554       353472 :       if (location_wrapper_p (instance))
    8555       353472 :         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      7378372 : resolves_to_fixed_type_p (tree instance, int* nonnull)
    8583              : {
    8584      7378372 :   tree t = TREE_TYPE (instance);
    8585      7378372 :   int cdtorp = 0;
    8586      7378372 :   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      7378372 :   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      7378359 :   fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
    8600      7378359 :   if (INDIRECT_TYPE_P (t))
    8601      4568257 :     t = TREE_TYPE (t);
    8602      7378359 :   if (CLASS_TYPE_P (t) && CLASSTYPE_FINAL (t))
    8603              :     return 1;
    8604      7316328 :   if (fixed == NULL_TREE)
    8605              :     return 0;
    8606      4351153 :   if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
    8607              :     return 0;
    8608      4350687 :   return cdtorp ? -1 : 1;
    8609              : }
    8610              : 
    8611              : 
    8612              : void
    8613        97879 : init_class_processing (void)
    8614              : {
    8615        97879 :   current_class_depth = 0;
    8616        97879 :   current_class_stack_size = 10;
    8617        97879 :   current_class_stack
    8618        97879 :     = XNEWVEC (struct class_stack_node, current_class_stack_size);
    8619        97879 :   sizeof_biggest_empty_class = size_zero_node;
    8620              : 
    8621        97879 :   ridpointers[(int) RID_PUBLIC] = access_public_node;
    8622        97879 :   ridpointers[(int) RID_PRIVATE] = access_private_node;
    8623        97879 :   ridpointers[(int) RID_PROTECTED] = access_protected_node;
    8624        97879 : }
    8625              : 
    8626              : /* Restore the cached PREVIOUS_CLASS_LEVEL.  */
    8627              : 
    8628              : static void
    8629    199942909 : restore_class_cache (void)
    8630              : {
    8631    199942909 :   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    199942909 :   push_binding_level (previous_class_level);
    8638    199942909 :   class_binding_level = previous_class_level;
    8639              :   /* Restore IDENTIFIER_TYPE_VALUE.  */
    8640    199942909 :   for (type = class_binding_level->type_shadowed;
    8641   1029748388 :        type;
    8642    829805479 :        type = TREE_CHAIN (type))
    8643    829805479 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (type), TREE_TYPE (type));
    8644    199942909 : }
    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    432542555 : pushclass (tree type)
    8657              : {
    8658    432542555 :   class_stack_node_t csn;
    8659              : 
    8660    432542555 :   type = TYPE_MAIN_VARIANT (type);
    8661              : 
    8662              :   /* Make sure there is enough room for the new entry on the stack.  */
    8663    432542555 :   if (current_class_depth + 1 >= current_class_stack_size)
    8664              :     {
    8665        11151 :       current_class_stack_size *= 2;
    8666        11151 :       current_class_stack
    8667        11151 :         = 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    432542555 :   csn = current_class_stack + current_class_depth;
    8673    432542555 :   csn->name = current_class_name;
    8674    432542555 :   csn->type = current_class_type;
    8675    432542555 :   csn->access = current_access_specifier;
    8676    432542555 :   csn->names_used = 0;
    8677    432542555 :   csn->hidden = 0;
    8678    432542555 :   current_class_depth++;
    8679              : 
    8680              :   /* Now set up the new type.  */
    8681    432542555 :   current_class_name = TYPE_NAME (type);
    8682    432542555 :   if (TREE_CODE (current_class_name) == TYPE_DECL)
    8683    432542555 :     current_class_name = DECL_NAME (current_class_name);
    8684    432542555 :   current_class_type = type;
    8685              : 
    8686              :   /* By default, things in classes are private, while things in
    8687              :      structures or unions are public.  */
    8688    432542555 :   current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
    8689    432542555 :                               ? access_private_node
    8690              :                               : access_public_node);
    8691              : 
    8692    432542555 :   if (previous_class_level
    8693    258980353 :       && type != previous_class_level->this_entity
    8694     54440783 :       && current_class_depth == 1)
    8695              :     {
    8696              :       /* Forcibly remove any old class remnants.  */
    8697     29114047 :       invalidate_class_lookup_cache ();
    8698              :     }
    8699              : 
    8700    432542555 :   if (!previous_class_level
    8701    229866306 :       || type != previous_class_level->this_entity
    8702    204539570 :       || current_class_depth > 1)
    8703    232599646 :     pushlevel_class ();
    8704              :   else
    8705    199942909 :     restore_class_cache ();
    8706    432542555 : }
    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    432526292 : popclass (void)
    8713              : {
    8714    432526292 :   poplevel_class ();
    8715              : 
    8716    432526289 :   current_class_depth--;
    8717    432526289 :   current_class_name = current_class_stack[current_class_depth].name;
    8718    432526289 :   current_class_type = current_class_stack[current_class_depth].type;
    8719    432526289 :   current_access_specifier = current_class_stack[current_class_depth].access;
    8720    432526289 :   if (current_class_stack[current_class_depth].names_used)
    8721     16393010 :     splay_tree_delete (current_class_stack[current_class_depth].names_used);
    8722    432526289 : }
    8723              : 
    8724              : /* Mark the top of the class stack as hidden.  */
    8725              : 
    8726              : void
    8727    488212063 : push_class_stack (void)
    8728              : {
    8729    488212063 :   if (current_class_depth)
    8730    331177746 :     ++current_class_stack[current_class_depth - 1].hidden;
    8731    488212063 : }
    8732              : 
    8733              : /* Mark the top of the class stack as un-hidden.  */
    8734              : 
    8735              : void
    8736    488087094 : pop_class_stack (void)
    8737              : {
    8738    488087094 :   if (current_class_depth)
    8739    331164210 :     --current_class_stack[current_class_depth - 1].hidden;
    8740    488087094 : }
    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   4936142574 : currently_open_class (tree t)
    8749              : {
    8750   4936142574 :   int i;
    8751              : 
    8752   4936142574 :   if (!CLASS_TYPE_P (t))
    8753              :     return NULL_TREE;
    8754              : 
    8755   4757428419 :   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   5907171048 :   for (i = current_class_depth; i > 0; --i)
    8760              :     {
    8761   4948909658 :       tree c;
    8762   4948909658 :       if (i == current_class_depth)
    8763   4363051906 :         c = current_class_type;
    8764              :       else
    8765              :         {
    8766    585857752 :           if (current_class_stack[i].hidden)
    8767              :             break;
    8768    438226449 :           c = current_class_stack[i].type;
    8769              :         }
    8770   4801278355 :       if (!c)
    8771    285845546 :         continue;
    8772   4515432809 :       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    159313299 : currently_open_derived_class (tree t)
    8784              : {
    8785    159313299 :   int i;
    8786              : 
    8787              :   /* The bases of a dependent type are unknown.  */
    8788    159313299 :   if (dependent_type_p (t))
    8789              :     return NULL_TREE;
    8790              : 
    8791    153287719 :   if (!current_class_type)
    8792              :     return NULL_TREE;
    8793              : 
    8794    151906178 :   if (DERIVED_FROM_P (t, current_class_type))
    8795    138614281 :     return current_class_type;
    8796              : 
    8797     17757705 :   for (i = current_class_depth - 1; i > 0; --i)
    8798              :     {
    8799      7590880 :       if (current_class_stack[i].hidden)
    8800              :         break;
    8801      7590880 :       if (DERIVED_FROM_P (t, current_class_stack[i].type))
    8802      3125072 :         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           21 : outermost_open_class (void)
    8813              : {
    8814           21 :   if (!current_class_type)
    8815              :     return NULL_TREE;
    8816           21 :   tree r = NULL_TREE;
    8817           21 :   if (TYPE_BEING_DEFINED (current_class_type))
    8818           21 :     r = current_class_type;
    8819           21 :   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   1300355457 : current_nonlambda_class_type (void)
    8835              : {
    8836   1300355457 :   tree type = current_class_type;
    8837   2319845454 :   while (type && LAMBDA_TYPE_P (type))
    8838      2715744 :     type = decl_type_context (TYPE_NAME (type));
    8839   1300355457 :   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    709448017 : push_nested_class (tree type)
    8850              : {
    8851              :   /* A namespace might be passed in error cases, like A::B:C.  */
    8852    709448017 :   if (type == NULL_TREE
    8853    709448017 :       || !CLASS_TYPE_P (type))
    8854              :     return;
    8855              : 
    8856    364576792 :   push_nested_class (DECL_CONTEXT (TYPE_MAIN_DECL (type)));
    8857              : 
    8858    364576792 :   pushclass (type);
    8859              : }
    8860              : 
    8861              : /* Undoes a push_nested_class call.  */
    8862              : 
    8863              : void
    8864    344857677 : pop_nested_class (void)
    8865              : {
    8866    364560544 :   tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
    8867              : 
    8868    364560544 :   popclass ();
    8869    364560544 :   if (context && CLASS_TYPE_P (context))
    8870              :     pop_nested_class ();
    8871    344857677 : }
    8872              : 
    8873              : /* Returns the number of extern "LANG" blocks we are nested within.  */
    8874              : 
    8875              : int
    8876         3427 : current_lang_depth (void)
    8877              : {
    8878         3427 :   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      1152146 : push_lang_context (tree name)
    8886              : {
    8887      1152146 :   vec_safe_push (current_lang_base, current_lang_name);
    8888              : 
    8889      1152146 :   if (name == lang_name_cplusplus)
    8890       608196 :     current_lang_name = name;
    8891       543950 :   else if (name == lang_name_c)
    8892       543950 :     current_lang_name = name;
    8893              :   else
    8894            0 :     error ("language string %<\"%E\"%> not recognized", name);
    8895      1152146 : }
    8896              : 
    8897              : /* Get out of the current language scope.  */
    8898              : 
    8899              : void
    8900      1152146 : pop_lang_context (void)
    8901              : {
    8902      1152146 :   current_lang_name = current_lang_base->pop ();
    8903      1152146 : }
    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       673393 : 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       673393 :   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       673393 :   tree matches = NULL_TREE;
    8959       673393 :   tree fn;
    8960       673393 :   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       673393 :   gcc_assert (!TYPE_PTR_P (target_type)
    8966              :               || TREE_CODE (TREE_TYPE (target_type)) != METHOD_TYPE);
    8967              : 
    8968       673393 :   gcc_assert (is_overloaded_fn (overload));
    8969              : 
    8970              :   /* Check that the TARGET_TYPE is reasonable.  */
    8971        47687 :   if (TYPE_PTRFN_P (target_type)
    8972       673397 :       || TYPE_REFFN_P (target_type))
    8973              :     /* This is OK.  */;
    8974       625708 :   else if (TYPE_PTRMEMFUNC_P (target_type))
    8975              :     /* This is OK, too.  */
    8976              :     is_ptrmem = 1;
    8977       624448 :   else if (TREE_CODE (target_type) == FUNCTION_TYPE)
    8978              :     /* This is OK, too.  This comes from a conversion to reference
    8979              :        type.  */
    8980       624405 :     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       673350 :   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       673350 :   if (!template_only)
    9004      5045468 :     for (lkp_iterator iter (overload); iter; ++iter)
    9005              :       {
    9006      4396038 :         tree fn = *iter;
    9007              : 
    9008      4396038 :         if (TREE_CODE (fn) == TEMPLATE_DECL)
    9009              :           /* We're not looking for templates just yet.  */
    9010        23872 :           continue;
    9011              : 
    9012      4372166 :         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      4371586 :         if (!constraints_satisfied_p (fn))
    9021           27 :           continue;
    9022              : 
    9023              :         /* For target_version semantics, never resolve a non-default
    9024              :            version.  */
    9025      4371559 :         if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    9026              :             && TREE_CODE (fn) == FUNCTION_DECL
    9027              :             && !is_function_default_version (fn))
    9028              :           continue;
    9029              : 
    9030      4371559 :         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      4371559 :         if (flag_noexcept_type
    9039      4371559 :             && !maybe_instantiate_noexcept (fn, complain))
    9040            0 :           continue;
    9041              : 
    9042              :         /* See if there's a match.  */
    9043      4371559 :         tree fntype = static_fn_type (fn);
    9044      4371559 :         if (same_type_p (target_fn_type, fntype)
    9045      4371559 :             || fnptr_conv_p (target_fn_type, fntype))
    9046       626165 :           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       649430 :   if (!matches)
    9053              :     {
    9054        47758 :       tree target_arg_types;
    9055        47758 :       tree target_ret_type;
    9056        47758 :       tree *args;
    9057        47758 :       unsigned int nargs, ia;
    9058        47758 :       tree arg;
    9059              : 
    9060        47758 :       target_arg_types = TYPE_ARG_TYPES (target_fn_type);
    9061        47758 :       target_ret_type = TREE_TYPE (target_fn_type);
    9062              : 
    9063        47758 :       nargs = list_length (target_arg_types);
    9064        47758 :       args = XALLOCAVEC (tree, nargs);
    9065        47758 :       for (arg = target_arg_types, ia = 0;
    9066       150235 :            arg != NULL_TREE;
    9067       102477 :            arg = TREE_CHAIN (arg), ++ia)
    9068       102477 :         args[ia] = TREE_VALUE (arg);
    9069        47758 :       nargs = ia;
    9070              : 
    9071        98822 :       for (lkp_iterator iter (overload); iter; ++iter)
    9072              :         {
    9073        51064 :           tree fn = *iter;
    9074        51064 :           tree instantiation;
    9075        51064 :           tree targs;
    9076              : 
    9077        51064 :           if (TREE_CODE (fn) != TEMPLATE_DECL)
    9078              :             /* We're only looking for templates.  */
    9079         3519 :             continue;
    9080              : 
    9081        47545 :           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        47533 :           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        47533 :           if (undeduced_auto_decl (fn))
    9092          230 :             ret = NULL_TREE;
    9093              : 
    9094              :           /* Try to do argument deduction.  */
    9095        47533 :           targs = make_tree_vec (DECL_NTPARMS (fn));
    9096        47533 :           instantiation = fn_type_unification (fn, explicit_targs, targs, args,
    9097              :                                                nargs, ret,
    9098              :                                               DEDUCE_EXACT, LOOKUP_NORMAL,
    9099              :                                                NULL, false, false);
    9100        47533 :           if (instantiation == error_mark_node)
    9101              :             /* Instantiation failed.  */
    9102        11285 :             continue;
    9103              : 
    9104              :           /* Constraints must be satisfied. This is done before
    9105              :              return type deduction since that instantiates the
    9106              :              function. */
    9107        36248 :           if (flag_concepts && !constraints_satisfied_p (instantiation))
    9108            0 :             continue;
    9109              : 
    9110              :           /* And now force instantiation to do return type deduction.  */
    9111        36248 :           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        36248 :           if (flag_noexcept_type)
    9122        35376 :             maybe_instantiate_noexcept (instantiation, complain);
    9123              : 
    9124              :           /* See if there's a match.  */
    9125        36248 :           tree fntype = static_fn_type (instantiation);
    9126        36248 :           if (same_type_p (target_fn_type, fntype)
    9127        36248 :               || fnptr_conv_p (target_fn_type, fntype))
    9128        36230 :             matches = tree_cons (instantiation, fn, matches);
    9129              :         }
    9130              : 
    9131              :       /* Now, remove all but the most specialized of the matches.  */
    9132        47758 :       if (matches)
    9133              :         {
    9134        36119 :           tree match = most_specialized_instantiation (matches);
    9135              : 
    9136        36119 :           if (match != error_mark_node)
    9137              :             {
    9138        36092 :               matches = match;
    9139        36092 :               TREE_CHAIN (match) = NULL_TREE;
    9140              :             }
    9141              :         }
    9142              :     }
    9143       625592 :   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       661711 :   if (matches == NULL_TREE)
    9152              :     {
    9153              :       /* There were *no* matches.  */
    9154        11639 :       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        11639 :       return error_mark_node;
    9163              :     }
    9164       661711 :   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       661684 :   fn = TREE_PURPOSE (matches);
    9201              : 
    9202      1322179 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fn)
    9203       661948 :       && !(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       661505 :   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       661424 :   if (!(complain & tf_conv))
    9272              :     {
    9273              :       /* Make =delete work with SFINAE.  */
    9274       641530 :       if (DECL_DELETED_FN (fn) && !(complain & tf_error))
    9275            0 :         return error_mark_node;
    9276       641530 :       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       661496 :   if (DECL_FUNCTION_MEMBER_P (fn))
    9284              :     {
    9285         6176 :       gcc_assert (access_path);
    9286         6176 :       perform_or_defer_access_check (access_path, fn, fn, complain);
    9287              :     }
    9288              : 
    9289       661496 :   if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
    9290        37760 :     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       623736 :       cxx_mark_addressable (fn);
    9297              : 
    9298       623736 :       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       675707 : instantiate_type (tree lhstype, tree rhs, tsubst_flags_t complain)
    9314              : {
    9315       684789 :   tsubst_flags_t complain_in = complain;
    9316       684789 :   tree access_path = NULL_TREE;
    9317              : 
    9318       684789 :   complain &= ~tf_ptrmem_ok;
    9319              : 
    9320       684789 :   STRIP_ANY_LOCATION_WRAPPER (rhs);
    9321              : 
    9322       684789 :   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       684789 :   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       683084 :   if (TREE_CODE (rhs) == SAVE_EXPR)
    9354            9 :     rhs = TREE_OPERAND (rhs, 0);
    9355              : 
    9356       683084 :   if (BASELINK_P (rhs))
    9357              :     {
    9358         6511 :       access_path = BASELINK_ACCESS_BINFO (rhs);
    9359         6511 :       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       683084 :   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       683084 :   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         2032 :     case OFFSET_REF:
    9390         2032 :       rhs = TREE_OPERAND (rhs, 1);
    9391         2032 :       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        23932 :     case TEMPLATE_ID_EXPR:
    9401        23932 :       {
    9402        23932 :         tree fns = TREE_OPERAND (rhs, 0);
    9403        23932 :         tree args = TREE_OPERAND (rhs, 1);
    9404              : 
    9405        23932 :         return
    9406        23932 :           resolve_address_of_overloaded_function (lhstype, fns, complain_in,
    9407              :                                                   /*template_only=*/true,
    9408        23932 :                                                   args, access_path);
    9409              :       }
    9410              : 
    9411       649461 :     case OVERLOAD:
    9412       649461 :     case FUNCTION_DECL:
    9413       649461 :       return
    9414       649461 :         resolve_address_of_overloaded_function (lhstype, rhs, complain_in,
    9415              :                                                 /*template_only=*/false,
    9416              :                                                 /*explicit_targs=*/NULL_TREE,
    9417       649461 :                                                 access_path);
    9418              : 
    9419         7050 :     case ADDR_EXPR:
    9420         7050 :     {
    9421         7050 :       if (PTRMEM_OK_P (rhs))
    9422         2032 :         complain |= tf_ptrmem_ok;
    9423              : 
    9424         7050 :       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       244842 : get_vfield_name (tree type)
    9444              : {
    9445       244842 :   tree binfo, base_binfo;
    9446              : 
    9447       244842 :   for (binfo = TYPE_BINFO (type);
    9448       244842 :        BINFO_N_BASE_BINFOS (binfo);
    9449              :        binfo = base_binfo)
    9450              :     {
    9451        71102 :       base_binfo = BINFO_BASE_BINFO (binfo, 0);
    9452              : 
    9453       142204 :       if (BINFO_VIRTUAL_P (base_binfo)
    9454        71102 :           || !TYPE_CONTAINS_VPTR_P (BINFO_TYPE (base_binfo)))
    9455              :         break;
    9456              :     }
    9457              : 
    9458       244842 :   type = BINFO_TYPE (binfo);
    9459       244842 :   tree ctor_name = constructor_name (type);
    9460       244842 :   char *buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
    9461              :                                + IDENTIFIER_LENGTH (ctor_name) + 2);
    9462       244842 :   sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name));
    9463       244842 :   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     29351022 : build_self_reference (void)
    9474              : {
    9475     29351022 :   tree name = DECL_NAME (TYPE_NAME (current_class_type));
    9476     29351022 :   tree decl = build_lang_decl (TYPE_DECL, name, current_class_type);
    9477              : 
    9478     29351022 :   DECL_NONLOCAL (decl) = 1;
    9479     29351022 :   DECL_CONTEXT (decl) = current_class_type;
    9480     29351022 :   DECL_ARTIFICIAL (decl) = 1;
    9481     29351022 :   SET_DECL_SELF_REFERENCE_P (decl);
    9482     29351022 :   set_underlying_type (decl);
    9483     29351022 :   set_instantiating_module (decl);
    9484              : 
    9485     29351022 :   if (processing_template_decl)
    9486     18691780 :     decl = push_template_decl (decl);
    9487              : 
    9488     29351022 :   tree saved_cas = current_access_specifier;
    9489     29351022 :   current_access_specifier = access_public_node;
    9490     29351022 :   finish_member_declaration (decl);
    9491     29351022 :   current_access_specifier = saved_cas;
    9492     29351022 : }
    9493              : 
    9494              : /* Returns 1 if TYPE contains only padding bytes.  */
    9495              : 
    9496              : int
    9497    587023819 : is_empty_class (tree type)
    9498              : {
    9499    587023819 :   if (type == error_mark_node)
    9500              :     return 0;
    9501              : 
    9502    587023816 :   if (! CLASS_TYPE_P (type))
    9503              :     return 0;
    9504              : 
    9505    355537413 :   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    372938701 : is_really_empty_class (tree type, bool ignore_vptr)
    9515              : {
    9516    372938701 :   if (CLASS_TYPE_P (type))
    9517              :     {
    9518     30453883 :       tree field;
    9519     30453883 :       tree binfo;
    9520     30453883 :       tree base_binfo;
    9521     30453883 :       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     30453883 :       if (COMPLETE_TYPE_P (type) && is_empty_class (type))
    9526              :         return true;
    9527              : 
    9528     23406568 :       if (!ignore_vptr && TYPE_CONTAINS_VPTR_P (type))
    9529              :         return false;
    9530              : 
    9531     25710884 :       for (binfo = TYPE_BINFO (type), i = 0;
    9532     25710884 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    9533      3721650 :         if (!is_really_empty_class (BINFO_TYPE (base_binfo), ignore_vptr))
    9534              :           return false;
    9535    408455526 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    9536    407988559 :         if (TREE_CODE (field) == FIELD_DECL
    9537     23764702 :             && !DECL_ARTIFICIAL (field)
    9538              :             /* An unnamed bit-field is not a data member.  */
    9539     21645854 :             && !DECL_UNNAMED_BIT_FIELD (field)
    9540    429632075 :             && !is_really_empty_class (TREE_TYPE (field), ignore_vptr))
    9541              :           return false;
    9542              :       return true;
    9543              :     }
    9544    342484818 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    9545      1345707 :     return (integer_zerop (array_type_nelts_top (type))
    9546      1345707 :             || 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   2111396328 : 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   2111396328 :   if (!(innermost_scope_kind() == sk_class
    9558    288072989 :         && TYPE_BEING_DEFINED (current_class_type)
    9559    512298141 :         && !LAMBDA_TYPE_P (current_class_type)))
    9560              :     return;
    9561              : 
    9562    257031845 :   const cp_binding_level *blev = nullptr;
    9563    257031845 :   if (const cxx_binding *binding = IDENTIFIER_BINDING (name))
    9564    212916414 :     blev = binding->scope;
    9565    257031845 :   const cp_binding_level *lev = current_binding_level;
    9566              : 
    9567              :   /* Record the binding in the names_used tables for classes inside blev.  */
    9568    383026980 :   for (int i = current_class_depth; i > 0; --i)
    9569              :     {
    9570    546149836 :       tree type = (i == current_class_depth
    9571    273074918 :                    ? current_class_type
    9572     16043073 :                    : current_class_stack[i].type);
    9573              : 
    9574    295362156 :       for (; lev; lev = lev->level_chain)
    9575              :         {
    9576    295362156 :           if (lev == blev)
    9577              :             /* We found the declaration.  */
    9578              :             return;
    9579    148282373 :           if (lev->kind == sk_class && lev->this_entity == type)
    9580              :             /* This class is inside the declaration scope.  */
    9581              :             break;
    9582              :         }
    9583              : 
    9584    125995135 :       auto &names_used = current_class_stack[i-1].names_used;
    9585    125995135 :       if (!names_used)
    9586     16393019 :         names_used = splay_tree_new (splay_tree_compare_pointers, 0, 0);
    9587              : 
    9588    125995135 :       tree use = build1_loc (input_location, VIEW_CONVERT_EXPR,
    9589    125995135 :                              TREE_TYPE (decl), decl);
    9590    125995135 :       EXPR_LOCATION_WRAPPER_P (use) = 1;
    9591    125995135 :       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    319412499 : note_name_declared_in_class (tree name, tree decl)
    9606              : {
    9607    319412499 :   splay_tree names_used;
    9608    319412499 :   splay_tree_node n;
    9609              : 
    9610              :   /* Look to see if we ever used this name.  */
    9611    319412499 :   names_used
    9612    319412499 :     = current_class_stack[current_class_depth - 1].names_used;
    9613    319412499 :   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     98725820 :   if ((!pedantic && current_lang_name == lang_name_c)
    9620     96667430 :       || flag_ms_extensions)
    9621              :     return;
    9622     96667424 :   n = splay_tree_lookup (names_used, (splay_tree_key) name);
    9623     96667424 :   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      5985636 : get_vtbl_decl_for_binfo (tree binfo)
    9661              : {
    9662      5985636 :   tree decl;
    9663              : 
    9664      5985636 :   decl = BINFO_VTABLE (binfo);
    9665      5985636 :   if (decl && TREE_CODE (decl) == POINTER_PLUS_EXPR)
    9666              :     {
    9667      5985633 :       gcc_assert (TREE_CODE (TREE_OPERAND (decl, 0)) == ADDR_EXPR);
    9668      5985633 :       decl = TREE_OPERAND (TREE_OPERAND (decl, 0), 0);
    9669              :     }
    9670      5985633 :   if (decl)
    9671      5985633 :     gcc_assert (VAR_P (decl));
    9672      5985636 :   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     44022123 : get_primary_binfo (tree binfo)
    9684              : {
    9685     44022123 :   tree primary_base;
    9686              : 
    9687     44022123 :   primary_base = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (binfo));
    9688     44022123 :   if (!primary_base)
    9689              :     return NULL_TREE;
    9690              : 
    9691     12631207 :   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      2545035 : most_primary_binfo (tree binfo)
    9699              : {
    9700      2545035 :   tree b = binfo;
    9701      7994514 :   while (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (b))
    9702     10898958 :          && !BINFO_LOST_PRIMARY_P (b))
    9703              :     {
    9704      2904444 :       tree primary_base = get_primary_binfo (b);
    9705      2904444 :       gcc_assert (BINFO_PRIMARY_P (primary_base)
    9706              :                   && BINFO_INHERITANCE_CHAIN (primary_base) == b);
    9707              :       b = primary_base;
    9708              :     }
    9709      2545035 :   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     49090220 : dump_class_hierarchy (tree t)
    9861              : {
    9862     49090220 :   dump_flags_t flags;
    9863     49090220 :   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     49090220 : }
    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      1956637 : dump_vtable (tree t, tree binfo, tree vtable)
    9894              : {
    9895      1956637 :   dump_flags_t flags;
    9896      1956637 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9897              : 
    9898      1956637 :   if (!stream)
    9899      1956598 :     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       178266 : dump_vtt (tree t, tree vtt)
    9925              : {
    9926       178266 :   dump_flags_t flags;
    9927       178266 :   FILE *stream = dump_begin (class_dump_id, &flags);
    9928              : 
    9929       178266 :   if (!stream)
    9930       178254 :     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     49090220 : finish_vtbls (tree t)
    9994              : {
    9995     49090220 :   tree vbase;
    9996     49090220 :   vec<constructor_elt, va_gc> *v = NULL;
    9997     49090220 :   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     49090220 :   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    125228539 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
   10007              :     {
   10008     76138319 :       if (!BINFO_VIRTUAL_P (vbase))
   10009     75946299 :         continue;
   10010       192020 :       accumulate_vtbl_inits (vbase, vbase, TYPE_BINFO (t), vtable, t, &v);
   10011              :     }
   10012              : 
   10013     49090220 :   if (BINFO_VTABLE (TYPE_BINFO (t)))
   10014      1711593 :     initialize_vtable (TYPE_BINFO (t), v);
   10015     49090220 : }
   10016              : 
   10017              : /* Initialize the vtable for BINFO with the INITS.  */
   10018              : 
   10019              : static void
   10020      1711593 : initialize_vtable (tree binfo, vec<constructor_elt, va_gc> *inits)
   10021              : {
   10022      1711593 :   tree decl;
   10023              : 
   10024      3423186 :   layout_vtable_decl (binfo, vec_safe_length (inits));
   10025      1711593 :   decl = get_vtbl_decl_for_binfo (binfo);
   10026      1711593 :   initialize_artificial_var (decl, inits);
   10027      1711593 :   dump_vtable (BINFO_TYPE (binfo), binfo, decl);
   10028      1711593 : }
   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     49090220 : build_vtt (tree t)
   10045              : {
   10046     49090220 :   tree type;
   10047     49090220 :   tree vtt;
   10048     49090220 :   tree index;
   10049     49090220 :   vec<constructor_elt, va_gc> *inits;
   10050              : 
   10051              :   /* Build up the initializers for the VTT.  */
   10052     49090220 :   inits = NULL;
   10053     49090220 :   index = size_zero_node;
   10054     49090220 :   build_vtt_inits (TYPE_BINFO (t), t, &inits, &index);
   10055              : 
   10056              :   /* If we didn't need a VTT, we're done.  */
   10057     49090220 :   if (!inits)
   10058     48911954 :     return;
   10059              : 
   10060              :   /* Figure out the type of the VTT.  */
   10061       356532 :   type = build_array_of_n_type (const_ptr_type_node,
   10062       178266 :                                 inits->length ());
   10063              : 
   10064              :   /* Now, build the VTT object itself.  */
   10065       178266 :   vtt = build_vtable (t, mangle_vtt_for_type (t), type);
   10066       178266 :   initialize_artificial_var (vtt, inits);
   10067              :   /* Add the VTT to the vtables list.  */
   10068       178266 :   DECL_CHAIN (vtt) = DECL_CHAIN (CLASSTYPE_VTABLES (t));
   10069       178266 :   DECL_CHAIN (CLASSTYPE_VTABLES (t)) = vtt;
   10070              : 
   10071       178266 :   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      1081799 : binfo_ctor_vtable (tree binfo)
   10081              : {
   10082      1153786 :   tree vt;
   10083              : 
   10084      1153786 :   while (1)
   10085              :     {
   10086      1153786 :       vt = BINFO_VTABLE (binfo);
   10087      1153786 :       if (TREE_CODE (vt) == TREE_LIST)
   10088       727581 :         vt = TREE_VALUE (vt);
   10089      1153786 :       if (TREE_CODE (vt) == TREE_BINFO)
   10090              :         binfo = vt;
   10091              :       else
   10092              :         break;
   10093              :     }
   10094              : 
   10095      1081799 :   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     49515806 : build_vtt_inits (tree binfo, tree t, vec<constructor_elt, va_gc> **inits,
   10124              :                  tree *index)
   10125              : {
   10126     49515806 :   int i;
   10127     49515806 :   tree b;
   10128     49515806 :   tree init;
   10129     49515806 :   secondary_vptr_vtt_init_data data;
   10130     49515806 :   int top_level_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10131              : 
   10132              :   /* We only need VTTs for subobjects with virtual bases.  */
   10133     49515806 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10134     49092496 :     return;
   10135              : 
   10136              :   /* We need to use a construction vtable if this is not the primary
   10137              :      VTT.  */
   10138       423310 :   if (!top_level_p)
   10139              :     {
   10140       245044 :       build_ctor_vtbl_group (binfo, t);
   10141              : 
   10142              :       /* Record the offset in the VTT where this sub-VTT can be found.  */
   10143       245044 :       BINFO_SUBVTT_INDEX (binfo) = *index;
   10144              :     }
   10145              : 
   10146              :   /* Add the address of the primary vtable for the complete object.  */
   10147       423310 :   init = binfo_ctor_vtable (binfo);
   10148       423310 :   CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
   10149       423310 :   if (top_level_p)
   10150              :     {
   10151       178266 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10152       178266 :       BINFO_VPTR_INDEX (binfo) = *index;
   10153              :     }
   10154       423310 :   *index = size_binop (PLUS_EXPR, *index, TYPE_SIZE_UNIT (ptr_type_node));
   10155              : 
   10156              :   /* Recursively add the secondary VTTs for non-virtual bases.  */
   10157       916555 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, b); ++i)
   10158       493245 :     if (!BINFO_VIRTUAL_P (b))
   10159       233566 :       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       423310 :   data.top_level_p = top_level_p;
   10165       423310 :   data.index = *index;
   10166       423310 :   data.inits = *inits;
   10167       423310 :   data.type_being_constructed = BINFO_TYPE (binfo);
   10168              : 
   10169       423310 :   dfs_walk_once (binfo, dfs_build_secondary_vptr_vtt_inits, NULL, &data);
   10170              : 
   10171       423310 :   *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       423310 :   *inits = data.inits;
   10176              : 
   10177       423310 :   if (top_level_p)
   10178              :     /* Add the secondary VTTs for virtual bases in inheritance graph
   10179              :        order.  */
   10180       957135 :     for (b = TYPE_BINFO (BINFO_TYPE (binfo)); b; b = TREE_CHAIN (b))
   10181              :       {
   10182       778869 :         if (!BINFO_VIRTUAL_P (b))
   10183       586849 :           continue;
   10184              : 
   10185       192020 :         build_vtt_inits (b, t, inits, index);
   10186              :       }
   10187              :   else
   10188              :     /* Remove the ctor vtables we created.  */
   10189       245044 :     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      1726479 : dfs_build_secondary_vptr_vtt_inits (tree binfo, void *data_)
   10197              : {
   10198      1726479 :   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      1726479 :   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      1702802 :   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      2087832 :   if (!(CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10212       808340 :         || 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      1278966 :   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       658489 :   if (data->top_level_p)
   10221              :     {
   10222       247939 :       gcc_assert (!BINFO_VPTR_INDEX (binfo));
   10223       247939 :       BINFO_VPTR_INDEX (binfo) = data->index;
   10224              : 
   10225       247939 :       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       198518 :           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       658489 :   CONSTRUCTOR_APPEND_ELT (data->inits, NULL_TREE, binfo_ctor_vtable (binfo));
   10238              : 
   10239              :   /* Advance the vtt index.  */
   10240       658489 :   data->index = size_binop (PLUS_EXPR, data->index,
   10241              :                             TYPE_SIZE_UNIT (ptr_type_node));
   10242              : 
   10243       658489 :   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      1104042 : dfs_fixup_binfo_vtbls (tree binfo, void* data)
   10253              : {
   10254      1104042 :   tree vtable = BINFO_VTABLE (binfo);
   10255              : 
   10256      1104042 :   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      1008722 :   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       694565 :   if (TREE_CODE (vtable) == TREE_LIST
   10268       694565 :       && (TREE_PURPOSE (vtable) == (tree) data))
   10269       655594 :     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       245044 : build_ctor_vtbl_group (tree binfo, tree t)
   10279              : {
   10280       245044 :   tree type;
   10281       245044 :   tree vtbl;
   10282       245044 :   tree id;
   10283       245044 :   tree vbase;
   10284       245044 :   vec<constructor_elt, va_gc> *v;
   10285              : 
   10286              :   /* See if we've already created this construction vtable group.  */
   10287       245044 :   id = mangle_ctor_vtbl_for_type (t, binfo);
   10288       245044 :   if (get_global_binding (id))
   10289            0 :     return;
   10290              : 
   10291       245044 :   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       245044 :   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       245044 :   DECL_VISIBILITY (vtbl) = VISIBILITY_HIDDEN;
   10302       245044 :   DECL_VISIBILITY_SPECIFIED (vtbl) = true;
   10303              : 
   10304       245044 :   v = NULL;
   10305       245044 :   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       245044 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10311      1196675 :        vbase;
   10312       951631 :        vbase = TREE_CHAIN (vbase))
   10313              :     {
   10314       951631 :       tree b;
   10315              : 
   10316       951631 :       if (!BINFO_VIRTUAL_P (vbase))
   10317       564181 :         continue;
   10318       387450 :       b = copied_binfo (vbase, binfo);
   10319              : 
   10320       387450 :       accumulate_vtbl_inits (b, vbase, binfo, vtbl, t, &v);
   10321              :     }
   10322              : 
   10323              :   /* Figure out the type of the construction vtable.  */
   10324       245044 :   type = build_array_of_n_type (vtable_entry_type, v->length ());
   10325       245044 :   layout_type (type);
   10326       245044 :   TREE_TYPE (vtbl) = type;
   10327       245044 :   DECL_SIZE (vtbl) = DECL_SIZE_UNIT (vtbl) = NULL_TREE;
   10328       245044 :   layout_decl (vtbl, 0);
   10329              : 
   10330              :   /* Initialize the construction vtable.  */
   10331       245044 :   CLASSTYPE_VTABLES (t) = chainon (CLASSTYPE_VTABLES (t), vtbl);
   10332       245044 :   initialize_artificial_var (vtbl, v);
   10333       245044 :   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     53427927 : 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     53427927 :   int i;
   10355     53427927 :   tree base_binfo;
   10356     53427927 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10357              : 
   10358     53427927 :   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     53427927 :   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      5440089 :   if (ctor_vtbl_p
   10367       930023 :       && !CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo))
   10368      5898960 :       && !binfo_via_virtual (orig_binfo, BINFO_TYPE (rtti_binfo)))
   10369              :     return;
   10370              : 
   10371              :   /* Build the initializers for the BINFO-in-T vtable.  */
   10372      5439888 :   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     15152437 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10380              :     {
   10381              :       /* Skip virtual bases.  */
   10382      4272661 :       if (BINFO_VIRTUAL_P (base_binfo))
   10383       759468 :         continue;
   10384      7026386 :       accumulate_vtbl_inits (base_binfo,
   10385      3513193 :                              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      5439888 : 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      5439888 :   tree vtbl = NULL_TREE;
   10403      5439888 :   int ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10404      5439888 :   int n_inits;
   10405              : 
   10406      5439888 :   if (ctor_vtbl_p
   10407      6369710 :       && 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      5367511 :   else if (!BINFO_NEW_VTABLE_MARKED (orig_binfo))
   10458              :     return;
   10459              : 
   10460      2616323 :   n_inits = vec_safe_length (*l);
   10461              : 
   10462      2616323 :   if (!vtbl)
   10463              :     {
   10464      2544870 :       tree index;
   10465      2544870 :       int non_fn_entries;
   10466              : 
   10467              :       /* Add the initializer for this vtable.  */
   10468      2544870 :       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      2544870 :       vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, orig_vtbl);
   10473      2544870 :       index = size_binop (MULT_EXPR,
   10474              :                           TYPE_SIZE_UNIT (vtable_entry_type),
   10475              :                           size_int (non_fn_entries + n_inits));
   10476      2544870 :       vtbl = fold_build_pointer_plus (vtbl, index);
   10477              :     }
   10478              : 
   10479      2616323 :   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       655594 :     BINFO_VTABLE (binfo) = tree_cons (rtti_binfo, vtbl, BINFO_VTABLE (binfo));
   10484      1960729 :   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      1952662 :     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      2544870 : 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      2544870 :   tree v;
   10527      2544870 :   vtbl_init_data vid;
   10528      2544870 :   unsigned ix, jx;
   10529      2544870 :   tree vbinfo;
   10530      2544870 :   vec<tree, va_gc> *vbases;
   10531      2544870 :   constructor_elt *e;
   10532              : 
   10533              :   /* Initialize VID.  */
   10534      2544870 :   memset (&vid, 0, sizeof (vid));
   10535      2544870 :   vid.binfo = binfo;
   10536      2544870 :   vid.derived = t;
   10537      2544870 :   vid.rtti_binfo = rtti_binfo;
   10538      2544870 :   vid.primary_vtbl_p = SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t);
   10539      2544870 :   vid.ctor_vtbl_p = !SAME_BINFO_TYPE_P (BINFO_TYPE (rtti_binfo), t);
   10540      2544870 :   vid.generate_vcall_entries = true;
   10541              :   /* The first vbase or vcall offset is at index -3 in the vtable.  */
   10542      2544870 :   vid.index = ssize_int(-3 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
   10543              : 
   10544              :   /* Add entries to the vtable for RTTI.  */
   10545      2544870 :   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      2544870 :   vec_alloc (vid.fns, 32);
   10551              :   /* Add the vcall and vbase offset entries.  */
   10552      2544870 :   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      2544870 :   for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
   10557      8903020 :        vec_safe_iterate (vbases, ix, &vbinfo); ix++)
   10558      6358150 :     BINFO_VTABLE_PATH_MARKED (vbinfo) = 0;
   10559              : 
   10560              :   /* If the target requires padding between data entries, add that now.  */
   10561      2544870 :   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      2544870 :   if (non_fn_entries_p)
   10592      5089740 :     *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      2544870 :   jx = vec_safe_length (*inits);
   10598      2544870 :   vec_safe_grow (*inits, jx + vid.inits->length (), true);
   10599              : 
   10600      2544870 :   for (ix = vid.inits->length () - 1;
   10601     10237074 :        vid.inits->iterate (ix, &e);
   10602      7692204 :        ix--, jx++)
   10603      7692204 :     (**inits)[jx] = *e;
   10604              : 
   10605              :   /* Go through all the ordinary virtual functions, building up
   10606              :      initializers.  */
   10607     13864549 :   for (v = BINFO_VIRTUALS (orig_binfo); v; v = TREE_CHAIN (v))
   10608              :     {
   10609     11319679 :       tree delta;
   10610     11319679 :       tree vcall_index;
   10611     11319679 :       tree fn, fn_original;
   10612     11319679 :       tree init = NULL_TREE;
   10613              : 
   10614     11319679 :       fn = BV_FN (v);
   10615     11319679 :       fn_original = fn;
   10616     11319679 :       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     11319679 :       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     11318934 :           delta = BV_DELTA (v);
   10646     11318934 :           vcall_index = BV_VCALL_INDEX (v);
   10647              : 
   10648     11318934 :           gcc_assert (TREE_CODE (delta) == INTEGER_CST);
   10649     11318934 :           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     11318934 :           if (DECL_PURE_VIRTUAL_P (fn_original))
   10654              :             {
   10655       744156 :               fn = abort_fndecl;
   10656       744156 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10657              :                 {
   10658       744156 :                   if (abort_fndecl_addr == NULL)
   10659        13460 :                     abort_fndecl_addr
   10660        13460 :                       = fold_convert (vfunc_ptr_type_node,
   10661              :                                       build_fold_addr_expr (fn));
   10662       744156 :                   init = abort_fndecl_addr;
   10663              :                 }
   10664              :             }
   10665              :           /* Likewise for deleted virtuals.  */
   10666     10574778 :           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     10574731 :               if (!integer_zerop (delta) || vcall_index)
   10686              :                 {
   10687      1000521 :                   fn = make_thunk (fn, /*this_adjusting=*/1,
   10688              :                                    delta, vcall_index);
   10689      1000521 :                   if (!DECL_NAME (fn))
   10690       466112 :                     finish_thunk (fn);
   10691              :                 }
   10692              :               /* Take the address of the function, considering it to be of an
   10693              :                  appropriate generic type.  */
   10694     10574731 :               if (!TARGET_VTABLE_USES_DESCRIPTORS)
   10695     10574731 :                 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     10574731 :               if (DECL_DESTRUCTOR_P (fn_original)
   10704     10574731 :                   && (CLASSTYPE_PURE_VIRTUALS (DECL_CONTEXT (fn_original))
   10705      4338990 :                       || orig_binfo != binfo))
   10706      1293516 :                 init = size_zero_node;
   10707              :             }
   10708              :         }
   10709              : 
   10710              :       /* And add it to the chain of initializers.  */
   10711     11319679 :       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     11319679 :         CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init);
   10729              :     }
   10730      2544870 : }
   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      5452323 : build_vcall_and_vbase_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10737              : {
   10738      5452323 :   tree b;
   10739              : 
   10740              :   /* If this is a derived class, we must first create entries
   10741              :      corresponding to the primary base class.  */
   10742      5452323 :   b = get_primary_binfo (binfo);
   10743      5452323 :   if (b)
   10744      2907453 :     build_vcall_and_vbase_vtbl_entries (b, vid);
   10745              : 
   10746              :   /* Add the vbase entries for this base.  */
   10747      5452323 :   build_vbase_offset_vtbl_entries (binfo, vid);
   10748              :   /* Add the vcall entries for this base.  */
   10749      5452323 :   build_vcall_offset_vtbl_entries (binfo, vid);
   10750      5452323 : }
   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      5452323 : build_vbase_offset_vtbl_entries (tree binfo, vtbl_init_data* vid)
   10759              : {
   10760      5452323 :   tree vbase;
   10761      5452323 :   tree t;
   10762      5452323 :   tree non_primary_binfo;
   10763              : 
   10764              :   /* If there are no virtual baseclasses, then there is nothing to
   10765              :      do.  */
   10766      5452323 :   if (!CLASSTYPE_VBASECLASSES (BINFO_TYPE (binfo)))
   10767              :     return;
   10768              : 
   10769       903023 :   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       903023 :   non_primary_binfo = binfo;
   10775      1408933 :   while (BINFO_INHERITANCE_CHAIN (non_primary_binfo))
   10776              :     {
   10777       849847 :       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       849847 :       if (BINFO_VIRTUAL_P (non_primary_binfo))
   10784              :         {
   10785       185278 :           non_primary_binfo = vid->binfo;
   10786       185278 :           break;
   10787              :         }
   10788              : 
   10789       664569 :       b = BINFO_INHERITANCE_CHAIN (non_primary_binfo);
   10790       664569 :       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       903023 :   for (vbase = TYPE_BINFO (BINFO_TYPE (binfo));
   10797      5496876 :        vbase;
   10798      4593853 :        vbase = TREE_CHAIN (vbase))
   10799              :     {
   10800      4593853 :       tree b;
   10801      4593853 :       tree delta;
   10802              : 
   10803      4593853 :       if (!BINFO_VIRTUAL_P (vbase))
   10804      2107663 :         continue;
   10805              : 
   10806              :       /* Find the instance of this virtual base in the complete
   10807              :          object.  */
   10808      2486190 :       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      2486190 :       if (BINFO_VTABLE_PATH_MARKED (b))
   10813       301276 :         continue;
   10814      2184914 :       BINFO_VTABLE_PATH_MARKED (b) = 1;
   10815              : 
   10816              :       /* Figure out where we can find this vbase offset.  */
   10817      2184914 :       delta = size_binop (MULT_EXPR,
   10818              :                           vid->index,
   10819              :                           fold_convert (ssizetype,
   10820              :                                    TYPE_SIZE_UNIT (vtable_entry_type)));
   10821      2184914 :       if (vid->primary_vtbl_p)
   10822       192020 :         BINFO_VPTR_FIELD (b) = delta;
   10823              : 
   10824      2184914 :       if (binfo != TYPE_BINFO (t))
   10825              :         /* The vbase offset had better be the same.  */
   10826      2128358 :         gcc_assert (tree_int_cst_equal (delta, BINFO_VPTR_FIELD (vbase)));
   10827              : 
   10828              :       /* The next vbase will come at a more negative offset.  */
   10829      2184914 :       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      2184914 :       delta = size_diffop_loc (input_location,
   10837      2184914 :                            BINFO_OFFSET (b), BINFO_OFFSET (non_primary_binfo));
   10838              : 
   10839      6778767 :       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      5452323 : 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      5452323 :   if (binfo == TYPE_BINFO (vid->derived)
   10856      9193053 :       || (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       586475 :           && 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      2284657 :       vid->vbase = binfo;
   10883              :       /* If we are just computing the vcall indices -- but do not need
   10884              :          the actual entries -- not that.  */
   10885      2284657 :       if (!BINFO_VIRTUAL_P (binfo))
   10886      1711593 :         vid->generate_vcall_entries = false;
   10887              :       /* Now, walk through the non-virtual bases, adding vcall offsets.  */
   10888      2284657 :       add_vcall_offset_vtbl_entries_r (binfo, vid);
   10889              :     }
   10890      5452323 : }
   10891              : 
   10892              : /* Build vcall offsets, starting with those for BINFO.  */
   10893              : 
   10894              : static void
   10895      6216678 : add_vcall_offset_vtbl_entries_r (tree binfo, vtbl_init_data* vid)
   10896              : {
   10897      6216678 :   int i;
   10898      6216678 :   tree primary_binfo;
   10899      6216678 :   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      6216678 :   if (BINFO_VIRTUAL_P (binfo) && vid->vbase != binfo)
   10906      6216678 :     return;
   10907              : 
   10908              :   /* If BINFO has a primary base, process it first.  */
   10909      5740128 :   primary_binfo = get_primary_binfo (binfo);
   10910      5740128 :   if (primary_binfo)
   10911      2859794 :     add_vcall_offset_vtbl_entries_r (primary_binfo, vid);
   10912              : 
   10913              :   /* Add BINFO itself to the list.  */
   10914      5740128 :   add_vcall_offset_vtbl_entries_1 (binfo, vid);
   10915              : 
   10916              :   /* Scan the non-primary bases of BINFO.  */
   10917     15412097 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
   10918      3931841 :     if (base_binfo != primary_binfo)
   10919      1072227 :       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      5740128 : add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid)
   10926              : {
   10927              :   /* Make entries for the rest of the virtuals.  */
   10928      5740128 :   tree orig_fn;
   10929              : 
   10930              :   /* The ABI requires that the methods be processed in declaration
   10931              :      order.  */
   10932      5740128 :   for (orig_fn = TYPE_FIELDS (BINFO_TYPE (binfo));
   10933    196069528 :        orig_fn;
   10934    190329400 :        orig_fn = DECL_CHAIN (orig_fn))
   10935    190329400 :     if (TREE_CODE (orig_fn) == FUNCTION_DECL && DECL_VINDEX (orig_fn))
   10936     24573986 :       add_vcall_offset (orig_fn, binfo, vid);
   10937      5740128 : }
   10938              : 
   10939              : /* Add a vcall offset entry for ORIG_FN to the vtable.  */
   10940              : 
   10941              : static void
   10942     24573986 : add_vcall_offset (tree orig_fn, tree binfo, vtbl_init_data *vid)
   10943              : {
   10944     24573986 :   size_t i;
   10945     24573986 :   tree vcall_offset;
   10946     24573986 :   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     67315552 :   FOR_EACH_VEC_SAFE_ELT (vid->fns, i, derived_entry)
   10953              :     {
   10954     58644244 :       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    110800458 :           || (DECL_DESTRUCTOR_P (derived_entry)
   10958     38417408 :               && DECL_DESTRUCTOR_P (orig_fn)))
   10959     24573986 :         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      8671308 :   if (vid->binfo == TYPE_BINFO (vid->derived))
   10966              :     {
   10967      8255856 :       tree_pair_s elt = {orig_fn, vid->index};
   10968      8255856 :       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      8671308 :   vid->index = size_binop (MINUS_EXPR, vid->index,
   10974              :                            ssize_int (TARGET_VTABLE_DATA_ENTRY_DISTANCE));
   10975              : 
   10976              :   /* Keep track of this function.  */
   10977      8671308 :   vec_safe_push (vid->fns, orig_fn);
   10978              : 
   10979      8671308 :   if (vid->generate_vcall_entries)
   10980              :     {
   10981       417550 :       tree base;
   10982       417550 :       tree fn;
   10983              : 
   10984              :       /* Find the overriding function.  */
   10985       417550 :       fn = find_final_overrider (vid->rtti_binfo, binfo, orig_fn);
   10986       417550 :       if (fn == error_mark_node)
   10987           27 :         vcall_offset = build_zero_cst (vtable_entry_type);
   10988              :       else
   10989              :         {
   10990       417523 :           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      1670092 :           vcall_offset = size_diffop_loc (input_location,
   10997       417523 :                                       BINFO_OFFSET (base),
   10998       417523 :                                       BINFO_OFFSET (vid->binfo));
   10999       417523 :           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       417550 :       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      2544870 : build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   11014              : {
   11015      2544870 :   tree b;
   11016      2544870 :   tree t;
   11017      2544870 :   tree offset;
   11018      2544870 :   tree decl;
   11019      2544870 :   tree init;
   11020              : 
   11021      2544870 :   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      2544870 :   b = most_primary_binfo (binfo);
   11026      2544870 :   offset = size_diffop_loc (input_location,
   11027      2544870 :                         BINFO_OFFSET (vid->rtti_binfo), BINFO_OFFSET (b));
   11028              : 
   11029              :   /* The second entry is the address of the typeinfo object.  */
   11030      2544870 :   if (flag_rtti)
   11031      2541761 :     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      2544870 :   init = build_nop (vfunc_ptr_type_node, decl);
   11038      2544870 :   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      2544870 :   init = build_nop (vfunc_ptr_type_node, offset);
   11044      2544870 :   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
   11045      2544870 : }
   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       183953 : publicly_virtually_derived_p (tree parent, tree type)
   11071              : {
   11072       183953 :   tree base = lookup_base (type, parent,
   11073              :                            ba_ignore_scope | ba_check | ba_require_virtual,
   11074              :                            NULL, tf_none);
   11075       183953 :   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         9328 : common_enclosing_class (tree ctx1, tree ctx2)
   11083              : {
   11084         9328 :   if (!TYPE_P (ctx1) || !TYPE_P (ctx2))
   11085              :     return NULL_TREE;
   11086         9328 :   gcc_assert (ctx1 == TYPE_MAIN_VARIANT (ctx1)
   11087              :               && ctx2 == TYPE_MAIN_VARIANT (ctx2));
   11088         9328 :   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.