LCOV - code coverage report
Current view: top level - gcc/cp - class.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.5 % 4314 4164
Test Date: 2024-09-07 14:08:43 Functions: 97.6 % 205 200
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Functions related to building -*- C++ -*- classes and their related objects.
       2                 :             :    Copyright (C) 1987-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* High-level class interface.  */
      23                 :             : 
      24                 :             : #include "config.h"
      25                 :             : #include "system.h"
      26                 :             : #include "coretypes.h"
      27                 :             : #include "target.h"
      28                 :             : #include "cp-tree.h"
      29                 :             : #include "stringpool.h"
      30                 :             : #include "cgraph.h"
      31                 :             : #include "stor-layout.h"
      32                 :             : #include "attribs.h"
      33                 :             : #include "flags.h"
      34                 :             : #include "toplev.h"
      35                 :             : #include "convert.h"
      36                 :             : #include "dumpfile.h"
      37                 :             : #include "gimplify.h"
      38                 :             : #include "intl.h"
      39                 :             : #include "asan.h"
      40                 :             : 
      41                 :             : /* Id for dumping the class hierarchy.  */
      42                 :             : int class_dump_id;
      43                 :             :  
      44                 :             : /* The number of nested classes being processed.  If we are not in the
      45                 :             :    scope of any class, this is zero.  */
      46                 :             : 
      47                 :             : int current_class_depth;
      48                 :             : 
      49                 :             : /* In order to deal with nested classes, we keep a stack of classes.
      50                 :             :    The topmost entry is the innermost class, and is the entry at index
      51                 :             :    CURRENT_CLASS_DEPTH  */
      52                 :             : 
      53                 :             : typedef struct class_stack_node {
      54                 :             :   /* The name of the class.  */
      55                 :             :   tree name;
      56                 :             : 
      57                 :             :   /* The _TYPE node for the class.  */
      58                 :             :   tree type;
      59                 :             : 
      60                 :             :   /* The access specifier pending for new declarations in the scope of
      61                 :             :      this class.  */
      62                 :             :   tree access;
      63                 :             : 
      64                 :             :   /* If were defining TYPE, the names used in this class.  */
      65                 :             :   splay_tree names_used;
      66                 :             : 
      67                 :             :   /* Nonzero if this class is no longer open, because of a call to
      68                 :             :      push_to_top_level.  */
      69                 :             :   size_t hidden;
      70                 :             : }* class_stack_node_t;
      71                 :             : 
      72                 :             : struct vtbl_init_data
      73                 :             : {
      74                 :             :   /* The base for which we're building initializers.  */
      75                 :             :   tree binfo;
      76                 :             :   /* The type of the most-derived type.  */
      77                 :             :   tree derived;
      78                 :             :   /* The binfo for the dynamic type. This will be TYPE_BINFO (derived),
      79                 :             :      unless ctor_vtbl_p is true.  */
      80                 :             :   tree rtti_binfo;
      81                 :             :   /* The negative-index vtable initializers built up so far.  These
      82                 :             :      are in order from least negative index to most negative index.  */
      83                 :             :   vec<constructor_elt, va_gc> *inits;
      84                 :             :   /* The binfo for the virtual base for which we're building
      85                 :             :      vcall offset initializers.  */
      86                 :             :   tree vbase;
      87                 :             :   /* The functions in vbase for which we have already provided vcall
      88                 :             :      offsets.  */
      89                 :             :   vec<tree, va_gc> *fns;
      90                 :             :   /* The vtable index of the next vcall or vbase offset.  */
      91                 :             :   tree index;
      92                 :             :   /* Nonzero if we are building the initializer for the primary
      93                 :             :      vtable.  */
      94                 :             :   int primary_vtbl_p;
      95                 :             :   /* Nonzero if we are building the initializer for a construction
      96                 :             :      vtable.  */
      97                 :             :   int ctor_vtbl_p;
      98                 :             :   /* True when adding vcall offset entries to the vtable.  False when
      99                 :             :      merely computing the indices.  */
     100                 :             :   bool generate_vcall_entries;
     101                 :             : };
     102                 :             : 
     103                 :             : /* The type of a function passed to walk_subobject_offsets.  */
     104                 :             : typedef int (*subobject_offset_fn) (tree, tree, splay_tree);
     105                 :             : 
     106                 :             : /* The stack itself.  This is a dynamically resized array.  The
     107                 :             :    number of elements allocated is CURRENT_CLASS_STACK_SIZE.  */
     108                 :             : static int current_class_stack_size;
     109                 :             : static class_stack_node_t current_class_stack;
     110                 :             : 
     111                 :             : /* The size of the largest empty class seen in this translation unit.  */
     112                 :             : static GTY (()) tree sizeof_biggest_empty_class;
     113                 :             : 
     114                 :             : static tree get_vfield_name (tree);
     115                 :             : static void finish_struct_anon (tree);
     116                 :             : static tree get_vtable_name (tree);
     117                 :             : static void get_basefndecls (tree, tree, vec<tree> *);
     118                 :             : static int build_primary_vtable (tree, tree);
     119                 :             : static int build_secondary_vtable (tree);
     120                 :             : static void finish_vtbls (tree);
     121                 :             : static void modify_vtable_entry (tree, tree, tree, tree, tree *);
     122                 :             : static void finish_struct_bits (tree);
     123                 :             : static int alter_access (tree, tree, tree);
     124                 :             : static void handle_using_decl (tree, tree);
     125                 :             : static tree dfs_modify_vtables (tree, void *);
     126                 :             : static tree modify_all_vtables (tree, tree);
     127                 :             : static void determine_primary_bases (tree);
     128                 :             : static void maybe_warn_about_overly_private_class (tree);
     129                 :             : static void add_implicitly_declared_members (tree, tree*, int, int);
     130                 :             : static tree fixed_type_or_null (tree, int *, int *);
     131                 :             : static tree build_simple_base_path (tree expr, tree binfo);
     132                 :             : static void build_vtbl_initializer (tree, tree, tree, tree, int *,
     133                 :             :                                     vec<constructor_elt, va_gc> **);
     134                 :             : static bool check_bitfield_decl (tree);
     135                 :             : static bool check_field_decl (tree, tree, int *, int *);
     136                 :             : static void check_field_decls (tree, tree *, int *, int *);
     137                 :             : static void build_base_fields (record_layout_info, splay_tree, tree *);
     138                 :             : static void check_methods (tree);
     139                 :             : static bool accessible_nvdtor_p (tree);
     140                 :             : 
     141                 :             : /* Used by find_flexarrays and related functions.  */
     142                 :             : struct flexmems_t;
     143                 :             : static void diagnose_flexarrays (tree, const flexmems_t *);
     144                 :             : static void find_flexarrays (tree, flexmems_t *, bool = false,
     145                 :             :                              tree = NULL_TREE, tree = NULL_TREE);
     146                 :             : static void check_flexarrays (tree, flexmems_t * = NULL, bool = false);
     147                 :             : static void check_bases (tree, int *, int *);
     148                 :             : static void check_bases_and_members (tree);
     149                 :             : static tree create_vtable_ptr (tree, tree *);
     150                 :             : static void include_empty_classes (record_layout_info);
     151                 :             : static void layout_class_type (tree, tree *);
     152                 :             : static void propagate_binfo_offsets (tree, tree);
     153                 :             : static void layout_virtual_bases (record_layout_info, splay_tree);
     154                 :             : static void build_vbase_offset_vtbl_entries (tree, vtbl_init_data *);
     155                 :             : static void add_vcall_offset_vtbl_entries_r (tree, vtbl_init_data *);
     156                 :             : static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
     157                 :             : static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
     158                 :             : static void add_vcall_offset (tree, tree, vtbl_init_data *);
     159                 :             : static void layout_vtable_decl (tree, int);
     160                 :             : static tree dfs_find_final_overrider_pre (tree, void *);
     161                 :             : static tree dfs_find_final_overrider_post (tree, void *);
     162                 :             : static tree find_final_overrider (tree, tree, tree);
     163                 :             : static int make_new_vtable (tree, tree);
     164                 :             : static tree get_primary_binfo (tree);
     165                 :             : static int maybe_indent_hierarchy (FILE *, int, int);
     166                 :             : static tree dump_class_hierarchy_r (FILE *, dump_flags_t, tree, tree, int);
     167                 :             : static void dump_class_hierarchy (tree);
     168                 :             : static void dump_class_hierarchy_1 (FILE *, dump_flags_t, tree);
     169                 :             : static void dump_array (FILE *, tree);
     170                 :             : static void dump_vtable (tree, tree, tree);
     171                 :             : static void dump_vtt (tree, tree);
     172                 :             : static void dump_thunk (FILE *, int, tree);
     173                 :             : static tree build_vtable (tree, tree, tree);
     174                 :             : static void initialize_vtable (tree, vec<constructor_elt, va_gc> *);
     175                 :             : static void layout_nonempty_base_or_field (record_layout_info,
     176                 :             :                                            tree, tree, splay_tree);
     177                 :             : static void accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     178                 :             :                                    vec<constructor_elt, va_gc> **);
     179                 :             : static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     180                 :             :                                        vec<constructor_elt, va_gc> **);
     181                 :             : static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
     182                 :             : static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
     183                 :             : static void clone_constructors_and_destructors (tree);
     184                 :             : static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
     185                 :             : static void build_ctor_vtbl_group (tree, tree);
     186                 :             : static void build_vtt (tree);
     187                 :             : static tree binfo_ctor_vtable (tree);
     188                 :             : static void build_vtt_inits (tree, tree, vec<constructor_elt, va_gc> **,
     189                 :             :                              tree *);
     190                 :             : static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
     191                 :             : static tree dfs_fixup_binfo_vtbls (tree, void *);
     192                 :             : static int record_subobject_offset (tree, tree, splay_tree);
     193                 :             : static int check_subobject_offset (tree, tree, splay_tree);
     194                 :             : static int walk_subobject_offsets (tree, subobject_offset_fn,
     195                 :             :                                    tree, splay_tree, tree, int);
     196                 :             : static int layout_conflict_p (tree, tree, splay_tree, int);
     197                 :             : static int splay_tree_compare_integer_csts (splay_tree_key k1,
     198                 :             :                                             splay_tree_key k2);
     199                 :             : static void maybe_warn_about_inaccessible_bases (tree);
     200                 :             : static bool type_requires_array_cookie (tree);
     201                 :             : static bool base_derived_from (tree, tree);
     202                 :             : static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
     203                 :             : static tree end_of_base (tree);
     204                 :             : static tree get_vcall_index (tree, tree);
     205                 :             : static bool type_maybe_constexpr_default_constructor (tree);
     206                 :             : static bool type_maybe_constexpr_destructor (tree);
     207                 :             : static bool field_poverlapping_p (tree);
     208                 :             : static void propagate_class_warmth_attribute (tree);
     209                 :             : 
     210                 :             : /* Set CURRENT_ACCESS_SPECIFIER based on the protection of DECL.  */
     211                 :             : 
     212                 :             : void
     213                 :   164767553 : set_current_access_from_decl (tree decl)
     214                 :             : {
     215                 :   164767553 :   if (TREE_PRIVATE (decl))
     216                 :    15473217 :     current_access_specifier = access_private_node;
     217                 :   149294336 :   else if (TREE_PROTECTED (decl))
     218                 :    10978923 :     current_access_specifier = access_protected_node;
     219                 :             :   else
     220                 :   138315413 :     current_access_specifier = access_public_node;
     221                 :   164767553 : }
     222                 :             : 
     223                 :             : /* Return a COND_EXPR that executes TRUE_STMT if this execution of the
     224                 :             :    'structor is in charge of 'structing virtual bases, or FALSE_STMT
     225                 :             :    otherwise.  */
     226                 :             : 
     227                 :             : tree
     228                 :      174418 : build_if_in_charge (tree true_stmt, tree false_stmt)
     229                 :             : {
     230                 :      174418 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     231                 :      348836 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     232                 :      174418 :                      current_in_charge_parm, integer_zero_node);
     233                 :      174418 :   tree type = unlowered_expr_type (true_stmt);
     234                 :      174418 :   if (VOID_TYPE_P (type))
     235                 :       17045 :     type = unlowered_expr_type (false_stmt);
     236                 :      174418 :   tree cond = build3 (COND_EXPR, type,
     237                 :             :                       cmp, true_stmt, false_stmt);
     238                 :      174418 :   return cond;
     239                 :             : }
     240                 :             : 
     241                 :             : /* Convert to or from a base subobject.  EXPR is an expression of type
     242                 :             :    `A' or `A*', an expression of type `B' or `B*' is returned.  To
     243                 :             :    convert A to a base B, CODE is PLUS_EXPR and BINFO is the binfo for
     244                 :             :    the B base instance within A.  To convert base A to derived B, CODE
     245                 :             :    is MINUS_EXPR and BINFO is the binfo for the A instance within B.
     246                 :             :    In this latter case, A must not be a morally virtual base of B.
     247                 :             :    NONNULL is true if EXPR is known to be non-NULL (this is only
     248                 :             :    needed when EXPR is of pointer type).  CV qualifiers are preserved
     249                 :             :    from EXPR.  */
     250                 :             : 
     251                 :             : tree
     252                 :    43244510 : build_base_path (enum tree_code code,
     253                 :             :                  tree expr,
     254                 :             :                  tree binfo,
     255                 :             :                  int nonnull,
     256                 :             :                  tsubst_flags_t complain)
     257                 :             : {
     258                 :    43244510 :   tree v_binfo = NULL_TREE;
     259                 :    43244510 :   tree d_binfo = NULL_TREE;
     260                 :    43244510 :   tree probe;
     261                 :    43244510 :   tree offset;
     262                 :    43244510 :   tree target_type;
     263                 :    43244510 :   tree null_test = NULL;
     264                 :    43244510 :   tree ptr_target_type;
     265                 :    43244510 :   int fixed_type_p;
     266                 :    43244510 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     267                 :    43244510 :   bool has_empty = false;
     268                 :    43244510 :   bool virtual_access;
     269                 :    43244510 :   bool rvalue = false;
     270                 :             : 
     271                 :    43244510 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     272                 :             :     return error_mark_node;
     273                 :             : 
     274                 :    93504657 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     275                 :             :     {
     276                 :    50260162 :       d_binfo = probe;
     277                 :    50260162 :       if (is_empty_class (BINFO_TYPE (probe)))
     278                 :     7535409 :         has_empty = true;
     279                 :   100424785 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     280                 :             :         v_binfo = probe;
     281                 :             :     }
     282                 :             : 
     283                 :    43244495 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     284                 :    43244495 :   if (want_pointer)
     285                 :    40298257 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     286                 :    43244495 :   if (dependent_type_p (probe))
     287                 :      278621 :     if (tree open = currently_open_class (probe))
     288                 :    43244495 :       probe = open;
     289                 :             : 
     290                 :    43244495 :   if (code == PLUS_EXPR
     291                 :    84400763 :       && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
     292                 :             :     {
     293                 :             :       /* This can happen when adjust_result_of_qualified_name_lookup can't
     294                 :             :          find a unique base binfo in a call to a member function.  We
     295                 :             :          couldn't give the diagnostic then since we might have been calling
     296                 :             :          a static member function, so we do it now.  In other cases, eg.
     297                 :             :          during error recovery (c++/71979), we may not have a base at all.  */
     298                 :           6 :       if (complain & tf_error)
     299                 :             :         {
     300                 :           6 :           tree base = lookup_base (probe, BINFO_TYPE (d_binfo),
     301                 :             :                                    ba_unique, NULL, complain);
     302                 :           6 :           gcc_assert (base == error_mark_node || !base);
     303                 :             :         }
     304                 :           6 :       return error_mark_node;
     305                 :             :     }
     306                 :             : 
     307                 :    45332716 :   gcc_assert ((code == MINUS_EXPR
     308                 :             :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     309                 :             :               || code == PLUS_EXPR);
     310                 :             : 
     311                 :    43244489 :   if (binfo == d_binfo)
     312                 :             :     /* Nothing to do.  */
     313                 :             :     return expr;
     314                 :             : 
     315                 :     6643510 :   if (code == MINUS_EXPR && v_binfo)
     316                 :             :     {
     317                 :          12 :       if (complain & tf_error)
     318                 :             :         {
     319                 :           9 :           if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
     320                 :             :             {
     321                 :           9 :               if (want_pointer)
     322                 :          18 :                 error ("cannot convert from pointer to base class %qT to "
     323                 :             :                        "pointer to derived class %qT because the base is "
     324                 :           9 :                        "virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     325                 :             :               else
     326                 :           0 :                 error ("cannot convert from base class %qT to derived "
     327                 :             :                        "class %qT because the base is virtual",
     328                 :           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     329                 :             :             }         
     330                 :             :           else
     331                 :             :             {
     332                 :           0 :               if (want_pointer)
     333                 :           0 :                 error ("cannot convert from pointer to base class %qT to "
     334                 :             :                        "pointer to derived class %qT via virtual base %qT",
     335                 :           0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
     336                 :           0 :                        BINFO_TYPE (v_binfo));
     337                 :             :               else
     338                 :           0 :                 error ("cannot convert from base class %qT to derived "
     339                 :           0 :                        "class %qT via virtual base %qT", BINFO_TYPE (binfo),
     340                 :           0 :                        BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
     341                 :             :             }
     342                 :             :         }
     343                 :          12 :       return error_mark_node;
     344                 :             :     }
     345                 :             : 
     346                 :    13286996 :   bool uneval = (cp_unevaluated_operand != 0
     347                 :     6373921 :                  || processing_template_decl
     348                 :    12690594 :                  || in_template_context);
     349                 :             : 
     350                 :             :   /* For a non-pointer simple base reference, express it as a COMPONENT_REF
     351                 :             :      without taking its address (and so causing lambda capture, 91933).  */
     352                 :     6643498 :   if (code == PLUS_EXPR && !v_binfo && !want_pointer && !has_empty && !uneval)
     353                 :     1908066 :     return build_simple_base_path (expr, binfo);
     354                 :             : 
     355                 :     4735432 :   if (!want_pointer)
     356                 :             :     {
     357                 :     1037887 :       rvalue = !lvalue_p (expr);
     358                 :             :       /* This must happen before the call to save_expr.  */
     359                 :     1037887 :       expr = cp_build_addr_expr (expr, complain);
     360                 :             :     }
     361                 :             :   else
     362                 :     3697545 :     expr = mark_rvalue_use (expr);
     363                 :             : 
     364                 :     4735432 :   offset = BINFO_OFFSET (binfo);
     365                 :     4735432 :   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
     366                 :     9470864 :   target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
     367                 :             :   /* TARGET_TYPE has been extracted from BINFO, and, is therefore always
     368                 :             :      cv-unqualified.  Extract the cv-qualifiers from EXPR so that the
     369                 :             :      expression returned matches the input.  */
     370                 :     4735432 :   target_type = cp_build_qualified_type
     371                 :     4735432 :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     372                 :     4735432 :   ptr_target_type = build_pointer_type (target_type);
     373                 :             : 
     374                 :             :   /* Do we need to look in the vtable for the real offset?  */
     375                 :     4735432 :   virtual_access = (v_binfo && fixed_type_p <= 0);
     376                 :             : 
     377                 :             :   /* Don't bother with the calculations inside sizeof; they'll ICE if the
     378                 :             :      source type is incomplete and the pointer value doesn't matter.  In a
     379                 :             :      template (even in instantiate_non_dependent_expr), we don't have vtables
     380                 :             :      set up properly yet, and the value doesn't matter there either; we're
     381                 :             :      just interested in the result of overload resolution.  */
     382                 :     4735432 :   if (uneval)
     383                 :             :     {
     384                 :      596404 :       expr = build_nop (ptr_target_type, expr);
     385                 :      596404 :       goto indout;
     386                 :             :     }
     387                 :             : 
     388                 :     4139028 :   if (!COMPLETE_TYPE_P (probe))
     389                 :             :     {
     390                 :           6 :       if (complain & tf_error)
     391                 :          18 :         error ("cannot convert from %qT to base class %qT because %qT is "
     392                 :           6 :                "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
     393                 :           6 :                BINFO_TYPE (d_binfo));
     394                 :           6 :       return error_mark_node;
     395                 :             :     }
     396                 :             : 
     397                 :             :   /* If we're in an NSDMI, we don't have the full constructor context yet
     398                 :             :      that we need for converting to a virtual base, so just build a stub
     399                 :             :      CONVERT_EXPR and expand it later in bot_replace.  */
     400                 :     4139022 :   if (virtual_access && fixed_type_p < 0
     401                 :     4139022 :       && current_scope () != current_function_decl)
     402                 :             :     {
     403                 :          33 :       expr = build1 (CONVERT_EXPR, ptr_target_type, expr);
     404                 :          33 :       CONVERT_EXPR_VBASE_PATH (expr) = true;
     405                 :          33 :       goto indout;
     406                 :             :     }
     407                 :             : 
     408                 :             :   /* Do we need to check for a null pointer?  */
     409                 :     4138989 :   if (want_pointer && !nonnull)
     410                 :             :     {
     411                 :             :       /* If we know the conversion will not actually change the value
     412                 :             :          of EXPR, then we can avoid testing the expression for NULL.
     413                 :             :          We have to avoid generating a COMPONENT_REF for a base class
     414                 :             :          field, because other parts of the compiler know that such
     415                 :             :          expressions are always non-NULL.  */
     416                 :       82828 :       if (!virtual_access && integer_zerop (offset))
     417                 :       81053 :         return build_nop (ptr_target_type, expr);
     418                 :        1775 :       null_test = error_mark_node;
     419                 :             :     }
     420                 :             : 
     421                 :             :   /* Protect against multiple evaluation if necessary.  */
     422                 :     4057936 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     423                 :         780 :     expr = save_expr (expr);
     424                 :             : 
     425                 :             :   /* Store EXPR and build the real null test just before returning.  */
     426                 :     4057936 :   if (null_test)
     427                 :        1775 :     null_test = expr;
     428                 :             : 
     429                 :             :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     430                 :     4057936 :   if (code == PLUS_EXPR && !virtual_access
     431                 :             :       /* We don't build base fields for empty bases, and they aren't very
     432                 :             :          interesting to the optimizers anyway.  */
     433                 :     3938748 :       && !has_empty)
     434                 :             :     {
     435                 :     2251348 :       expr = cp_build_fold_indirect_ref (expr);
     436                 :     2251348 :       expr = build_simple_base_path (expr, binfo);
     437                 :     2251348 :       if (rvalue && lvalue_p (expr))
     438                 :           0 :         expr = move (expr);
     439                 :     2251348 :       if (want_pointer)
     440                 :     2249487 :         expr = build_address (expr);
     441                 :     2251348 :       target_type = TREE_TYPE (expr);
     442                 :     2251348 :       goto out;
     443                 :             :     }
     444                 :             : 
     445                 :     1806588 :   if (virtual_access)
     446                 :             :     {
     447                 :             :       /* Going via virtual base V_BINFO.  We need the static offset
     448                 :             :          from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
     449                 :             :          V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
     450                 :       75364 :       tree v_offset;
     451                 :             : 
     452                 :       75364 :       if (fixed_type_p < 0 && in_base_initializer)
     453                 :             :         {
     454                 :             :           /* In a base member initializer, we cannot rely on the
     455                 :             :              vtable being set up.  We have to indirect via the
     456                 :             :              vtt_parm.  */
     457                 :           6 :           tree t;
     458                 :             : 
     459                 :           6 :           t = TREE_TYPE (TYPE_VFIELD (current_class_type));
     460                 :           6 :           t = build_pointer_type (t);
     461                 :           6 :           v_offset = fold_convert (t, current_vtt_parm);
     462                 :           6 :           v_offset = cp_build_fold_indirect_ref (v_offset);
     463                 :           6 :         }
     464                 :             :       else
     465                 :             :         {
     466                 :       75358 :           tree t = expr;
     467                 :       75358 :           if (sanitize_flags_p (SANITIZE_VPTR)
     468                 :       75358 :               && fixed_type_p == 0)
     469                 :             :             {
     470                 :          39 :               t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location,
     471                 :             :                                                            probe, expr);
     472                 :          39 :               if (t == NULL_TREE)
     473                 :       75319 :                 t = expr;
     474                 :             :             }
     475                 :       75358 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     476                 :       75358 :           TREE_TYPE (TREE_TYPE (expr)));
     477                 :             :         }
     478                 :             : 
     479                 :       75364 :       if (v_offset == error_mark_node)
     480                 :             :         return error_mark_node;
     481                 :             : 
     482                 :       75364 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     483                 :       75364 :       v_offset = build1 (NOP_EXPR,
     484                 :             :                          build_pointer_type (ptrdiff_type_node),
     485                 :             :                          v_offset);
     486                 :       75364 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     487                 :       75364 :       TREE_CONSTANT (v_offset) = 1;
     488                 :             : 
     489                 :      150728 :       offset = convert_to_integer (ptrdiff_type_node,
     490                 :             :                                    size_diffop_loc (input_location, offset,
     491                 :       75364 :                                                 BINFO_OFFSET (v_binfo)));
     492                 :             : 
     493                 :       75364 :       if (!integer_zerop (offset))
     494                 :         502 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     495                 :             : 
     496                 :       75364 :       if (fixed_type_p < 0)
     497                 :             :         /* Negative fixed_type_p means this is a constructor or destructor;
     498                 :             :            virtual base layout is fixed in in-charge [cd]tors, but not in
     499                 :             :            base [cd]tors.  */
     500                 :       47701 :         offset = build_if_in_charge
     501                 :       47701 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     502                 :             :            v_offset);
     503                 :             :       else
     504                 :             :         offset = v_offset;
     505                 :             :     }
     506                 :             : 
     507                 :     1806588 :   if (want_pointer)
     508                 :     1806588 :     target_type = ptr_target_type;
     509                 :             : 
     510                 :     1806588 :   if (!integer_zerop (offset))
     511                 :             :     {
     512                 :       77049 :       offset = fold_convert (sizetype, offset);
     513                 :       77049 :       if (code == MINUS_EXPR)
     514                 :         345 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     515                 :       77049 :       expr = fold_build_pointer_plus (expr, offset);
     516                 :             :     }
     517                 :             :   else
     518                 :             :     null_test = NULL;
     519                 :             : 
     520                 :     1806588 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     521                 :             : 
     522                 :     2403025 :  indout:
     523                 :     2403025 :   if (!want_pointer)
     524                 :             :     {
     525                 :     1036026 :       expr = cp_build_fold_indirect_ref (expr);
     526                 :     1036026 :       if (rvalue)
     527                 :      224654 :         expr = move (expr);
     528                 :             :     }
     529                 :             : 
     530                 :     1366999 :  out:
     531                 :     4654373 :   if (null_test)
     532                 :             :     /* Wrap EXPR in a null test.  */
     533                 :        1775 :     expr = build_if_nonnull (null_test, expr, complain);
     534                 :             : 
     535                 :             :   return expr;
     536                 :             : }
     537                 :             : 
     538                 :             : /* Subroutine of build_base_path; EXPR and BINFO are as in that function.
     539                 :             :    Perform a derived-to-base conversion by recursively building up a
     540                 :             :    sequence of COMPONENT_REFs to the appropriate base fields.  */
     541                 :             : 
     542                 :             : static tree
     543                 :    14231850 : build_simple_base_path (tree expr, tree binfo)
     544                 :             : {
     545                 :    14231850 :   tree type = BINFO_TYPE (binfo);
     546                 :    14231850 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     547                 :    14231850 :   tree field;
     548                 :             : 
     549                 :    14231850 :   if (d_binfo == NULL_TREE)
     550                 :             :     {
     551                 :     7033333 :       tree temp;
     552                 :             : 
     553                 :     7033333 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
     554                 :             : 
     555                 :             :       /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x'
     556                 :             :          into `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only
     557                 :             :          an lvalue in the front end; only _DECLs and _REFs are lvalues
     558                 :             :          in the back end.  */
     559                 :     7033333 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     560                 :     7033333 :       if (temp)
     561                 :           0 :         expr = cp_build_fold_indirect_ref (temp);
     562                 :             : 
     563                 :     7033333 :       return expr;
     564                 :             :     }
     565                 :             : 
     566                 :             :   /* Recurse.  */
     567                 :     7198517 :   expr = build_simple_base_path (expr, d_binfo);
     568                 :             : 
     569                 :     7198517 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     570                 :    36308870 :        field; field = DECL_CHAIN (field))
     571                 :             :     /* Is this the base field created by build_base_field?  */
     572                 :    36308870 :     if (TREE_CODE (field) == FIELD_DECL
     573                 :     8298734 :         && DECL_FIELD_IS_BASE (field)
     574                 :     8253925 :         && TREE_TYPE (field) == type
     575                 :             :         /* If we're looking for a field in the most-derived class,
     576                 :             :            also check the field offset; we can have two base fields
     577                 :             :            of the same type if one is an indirect virtual base and one
     578                 :             :            is a direct non-virtual base.  */
     579                 :    43507510 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     580                 :     7033456 :             || tree_int_cst_equal (byte_position (field),
     581                 :     7033456 :                                    BINFO_OFFSET (binfo))))
     582                 :             :       {
     583                 :             :         /* We don't use build_class_member_access_expr here, as that
     584                 :             :            has unnecessary checks, and more importantly results in
     585                 :             :            recursive calls to dfs_walk_once.  */
     586                 :     7198517 :         int type_quals = cp_type_quals (TREE_TYPE (expr));
     587                 :             : 
     588                 :     7198517 :         expr = build3 (COMPONENT_REF,
     589                 :             :                        cp_build_qualified_type (type, type_quals),
     590                 :             :                        expr, field, NULL_TREE);
     591                 :             :         /* Mark the expression const or volatile, as appropriate.
     592                 :             :            Even though we've dealt with the type above, we still have
     593                 :             :            to mark the expression itself.  */
     594                 :     7198517 :         if (type_quals & TYPE_QUAL_CONST)
     595                 :      765280 :           TREE_READONLY (expr) = 1;
     596                 :     7198517 :         if (type_quals & TYPE_QUAL_VOLATILE)
     597                 :       21698 :           TREE_THIS_VOLATILE (expr) = 1;
     598                 :             : 
     599                 :     7198517 :         return expr;
     600                 :             :       }
     601                 :             : 
     602                 :             :   /* Didn't find the base field?!?  */
     603                 :           0 :   gcc_unreachable ();
     604                 :             : }
     605                 :             : 
     606                 :             : /* Convert OBJECT to the base TYPE.  OBJECT is an expression whose
     607                 :             :    type is a class type or a pointer to a class type.  In the former
     608                 :             :    case, TYPE is also a class type; in the latter it is another
     609                 :             :    pointer type.  If CHECK_ACCESS is true, an error message is emitted
     610                 :             :    if TYPE is inaccessible.  If OBJECT has pointer type, the value is
     611                 :             :    assumed to be non-NULL.  */
     612                 :             : 
     613                 :             : tree
     614                 :     1272802 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     615                 :             :                  tsubst_flags_t complain)
     616                 :             : {
     617                 :     1272802 :   tree binfo;
     618                 :     1272802 :   tree object_type;
     619                 :             : 
     620                 :     1272802 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     621                 :             :     {
     622                 :      163181 :       object_type = TREE_TYPE (TREE_TYPE (object));
     623                 :      163181 :       type = TREE_TYPE (type);
     624                 :             :     }
     625                 :             :   else
     626                 :     1109621 :     object_type = TREE_TYPE (object);
     627                 :             : 
     628                 :     1274761 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     629                 :             :                        NULL, complain);
     630                 :     1272802 :   if (!binfo || binfo == error_mark_node)
     631                 :         105 :     return error_mark_node;
     632                 :             : 
     633                 :     1272697 :   return build_base_path (PLUS_EXPR, object, binfo, nonnull, complain);
     634                 :             : }
     635                 :             : 
     636                 :             : /* EXPR is an expression with unqualified class type.  BASE is a base
     637                 :             :    binfo of that class type.  Returns EXPR, converted to the BASE
     638                 :             :    type.  This function assumes that EXPR is the most derived class;
     639                 :             :    therefore virtual bases can be found at their static offsets.  */
     640                 :             : 
     641                 :             : tree
     642                 :     1608912 : convert_to_base_statically (tree expr, tree base)
     643                 :             : {
     644                 :     1608912 :   tree expr_type;
     645                 :             : 
     646                 :     1608912 :   expr_type = TREE_TYPE (expr);
     647                 :     1608912 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     648                 :             :     {
     649                 :             :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     650                 :     1608912 :       if (!is_empty_class (BINFO_TYPE (base)))
     651                 :     1200144 :         return build_simple_base_path (expr, base);
     652                 :             : 
     653                 :             :       /* We use fold_build2 and fold_convert below to simplify the trees
     654                 :             :          provided to the optimizers.  It is not safe to call these functions
     655                 :             :          when processing a template because they do not handle C++-specific
     656                 :             :          trees.  */
     657                 :      408768 :       gcc_assert (!processing_template_decl);
     658                 :      408768 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     659                 :      408768 :       if (!integer_zerop (BINFO_OFFSET (base)))
     660                 :         189 :         expr = fold_build_pointer_plus_loc (input_location,
     661                 :         189 :                                             expr, BINFO_OFFSET (base));
     662                 :      408768 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     663                 :      408768 :       expr = build_fold_indirect_ref_loc (input_location, expr);
     664                 :             :     }
     665                 :             : 
     666                 :             :   return expr;
     667                 :             : }
     668                 :             : 
     669                 :             : /* True IFF EXPR is a reference to an empty base class "subobject", as built in
     670                 :             :    convert_to_base_statically.  We look for the result of the fold_convert
     671                 :             :    call, a NOP_EXPR from one pointer type to another, where the target is an
     672                 :             :    empty base of the original type.  */
     673                 :             : 
     674                 :             : bool
     675                 :    25352395 : is_empty_base_ref (tree expr)
     676                 :             : {
     677                 :    25352395 :   if (INDIRECT_REF_P (expr))
     678                 :    20485837 :     expr = TREE_OPERAND (expr, 0);
     679                 :    25352395 :   if (TREE_CODE (expr) != NOP_EXPR)
     680                 :             :     return false;
     681                 :      821438 :   tree type = TREE_TYPE (expr);
     682                 :      821438 :   if (!POINTER_TYPE_P (type))
     683                 :             :     return false;
     684                 :      821438 :   type = TREE_TYPE (type);
     685                 :      821438 :   if (!is_empty_class (type))
     686                 :             :     return false;
     687                 :      453714 :   STRIP_NOPS (expr);
     688                 :      453714 :   tree fromtype = TREE_TYPE (expr);
     689                 :      453714 :   if (!POINTER_TYPE_P (fromtype))
     690                 :             :     return false;
     691                 :      453714 :   fromtype = TREE_TYPE (fromtype);
     692                 :      447638 :   return (CLASS_TYPE_P (fromtype)
     693                 :      447638 :           && !same_type_ignoring_top_level_qualifiers_p (fromtype, type)
     694                 :      900755 :           && DERIVED_FROM_P (type, fromtype));
     695                 :             : }
     696                 :             : 
     697                 :             : tree
     698                 :     1534523 : build_vfield_ref (tree datum, tree type)
     699                 :             : {
     700                 :     1534523 :   tree vfield, vcontext;
     701                 :             : 
     702                 :     1534523 :   if (datum == error_mark_node
     703                 :             :       /* Can happen in case of duplicate base types (c++/59082).  */
     704                 :     1534523 :       || !TYPE_VFIELD (type))
     705                 :             :     return error_mark_node;
     706                 :             : 
     707                 :             :   /* First, convert to the requested type.  */
     708                 :     1534523 :   if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
     709                 :           0 :     datum = convert_to_base (datum, type, /*check_access=*/false,
     710                 :             :                              /*nonnull=*/true, tf_warning_or_error);
     711                 :             : 
     712                 :             :   /* Second, the requested type may not be the owner of its own vptr.
     713                 :             :      If not, convert to the base class that owns it.  We cannot use
     714                 :             :      convert_to_base here, because VCONTEXT may appear more than once
     715                 :             :      in the inheritance hierarchy of TYPE, and thus direct conversion
     716                 :             :      between the types may be ambiguous.  Following the path back up
     717                 :             :      one step at a time via primary bases avoids the problem.  */
     718                 :     1534523 :   vfield = TYPE_VFIELD (type);
     719                 :     1534523 :   vcontext = DECL_CONTEXT (vfield);
     720                 :     3208298 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     721                 :             :     {
     722                 :     1673775 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     723                 :     1673775 :       type = TREE_TYPE (datum);
     724                 :             :     }
     725                 :             : 
     726                 :     1534523 :   return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
     727                 :             : }
     728                 :             : 
     729                 :             : /* Given an object INSTANCE, return an expression which yields the
     730                 :             :    vtable element corresponding to INDEX.  There are many special
     731                 :             :    cases for INSTANCE which we take care of here, mainly to avoid
     732                 :             :    creating extra tree nodes when we don't have to.  */
     733                 :             : 
     734                 :             : tree
     735                 :      523376 : build_vtbl_ref (tree instance, tree idx)
     736                 :             : {
     737                 :      523376 :   tree aref;
     738                 :      523376 :   tree vtbl = NULL_TREE;
     739                 :             : 
     740                 :             :   /* Try to figure out what a reference refers to, and
     741                 :             :      access its virtual function table directly.  */
     742                 :             : 
     743                 :      523376 :   int cdtorp = 0;
     744                 :      523376 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     745                 :             : 
     746                 :      523376 :   tree basetype = non_reference (TREE_TYPE (instance));
     747                 :             : 
     748                 :      523376 :   if (fixed_type && !cdtorp)
     749                 :             :     {
     750                 :         116 :       tree binfo = lookup_base (fixed_type, basetype,
     751                 :             :                                 ba_unique, NULL, tf_none);
     752                 :         116 :       if (binfo && binfo != error_mark_node)
     753                 :         101 :         vtbl = unshare_expr (BINFO_VTABLE (binfo));
     754                 :             :     }
     755                 :             : 
     756                 :         101 :   if (!vtbl)
     757                 :      523345 :     vtbl = build_vfield_ref (instance, basetype);
     758                 :             : 
     759                 :      523376 :   aref = build_array_ref (input_location, vtbl, idx);
     760                 :     1046721 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     761                 :             : 
     762                 :      523376 :   return aref;
     763                 :             : }
     764                 :             : 
     765                 :             : /* Given a stable object pointer INSTANCE_PTR, return an expression which
     766                 :             :    yields a function pointer corresponding to vtable element INDEX.  */
     767                 :             : 
     768                 :             : tree
     769                 :      522726 : build_vfn_ref (tree instance_ptr, tree idx)
     770                 :             : {
     771                 :      522726 :   tree aref;
     772                 :             : 
     773                 :      522726 :   aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
     774                 :             : 
     775                 :             :   /* When using function descriptors, the address of the
     776                 :             :      vtable entry is treated as a function pointer.  */
     777                 :      522726 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
     778                 :             :     aref = build1 (NOP_EXPR, TREE_TYPE (aref),
     779                 :             :                    cp_build_addr_expr (aref, tf_warning_or_error));
     780                 :             : 
     781                 :             :   /* Remember this as a method reference, for later devirtualization.  */
     782                 :      522726 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr,
     783                 :      522726 :                  fold_convert (TREE_TYPE (instance_ptr), idx));
     784                 :             : 
     785                 :      522726 :   return aref;
     786                 :             : }
     787                 :             : 
     788                 :             : /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
     789                 :             :    for the given TYPE.  */
     790                 :             : 
     791                 :             : static tree
     792                 :     1667777 : get_vtable_name (tree type)
     793                 :             : {
     794                 :           0 :   return mangle_vtbl_for_type (type);
     795                 :             : }
     796                 :             : 
     797                 :             : /* DECL is an entity associated with TYPE, like a virtual table or an
     798                 :             :    implicitly generated constructor.  Determine whether or not DECL
     799                 :             :    should have external or internal linkage at the object file
     800                 :             :    level.  This routine does not deal with COMDAT linkage and other
     801                 :             :    similar complexities; it simply sets TREE_PUBLIC if it possible for
     802                 :             :    entities in other translation units to contain copies of DECL, in
     803                 :             :    the abstract.  */
     804                 :             : 
     805                 :             : void
     806                 :    26343502 : set_linkage_according_to_type (tree /*type*/, tree decl)
     807                 :             : {
     808                 :    26343502 :   TREE_PUBLIC (decl) = 1;
     809                 :    26343502 :   determine_visibility (decl);
     810                 :    26343502 : }
     811                 :             : 
     812                 :             : /* Create a VAR_DECL for a primary or secondary vtable for CLASS_TYPE.
     813                 :             :    (For a secondary vtable for B-in-D, CLASS_TYPE should be D, not B.)
     814                 :             :    Use NAME for the name of the vtable, and VTABLE_TYPE for its type.  */
     815                 :             : 
     816                 :             : static tree
     817                 :     2107961 : build_vtable (tree class_type, tree name, tree vtable_type)
     818                 :             : {
     819                 :     2107961 :   tree decl;
     820                 :             : 
     821                 :     2107961 :   decl = build_lang_decl (VAR_DECL, name, vtable_type);
     822                 :             :   /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME
     823                 :             :      now to avoid confusion in mangle_decl.  */
     824                 :     2107961 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     825                 :     2107961 :   DECL_CONTEXT (decl) = class_type;
     826                 :     2107961 :   DECL_ARTIFICIAL (decl) = 1;
     827                 :     2107961 :   TREE_STATIC (decl) = 1;
     828                 :     2107961 :   TREE_READONLY (decl) = 1;
     829                 :     2107961 :   DECL_VIRTUAL_P (decl) = 1;
     830                 :     2118466 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     831                 :     2107961 :   DECL_USER_ALIGN (decl) = true;
     832                 :     2107961 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     833                 :     2107961 :   set_linkage_according_to_type (class_type, decl);
     834                 :             :   /* The vtable has not been defined -- yet.  */
     835                 :     2107961 :   DECL_EXTERNAL (decl) = 1;
     836                 :     2107961 :   DECL_NOT_REALLY_EXTERN (decl) = 1;
     837                 :             : 
     838                 :             :   /* Mark the VAR_DECL node representing the vtable itself as a
     839                 :             :      "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
     840                 :             :      is rather important that such things be ignored because any
     841                 :             :      effort to actually generate DWARF for them will run into
     842                 :             :      trouble when/if we encounter code like:
     843                 :             : 
     844                 :             :      #pragma interface
     845                 :             :      struct S { virtual void member (); };
     846                 :             : 
     847                 :             :      because the artificial declaration of the vtable itself (as
     848                 :             :      manufactured by the g++ front end) will say that the vtable is
     849                 :             :      a static member of `S' but only *after* the debug output for
     850                 :             :      the definition of `S' has already been output.  This causes
     851                 :             :      grief because the DWARF entry for the definition of the vtable
     852                 :             :      will try to refer back to an earlier *declaration* of the
     853                 :             :      vtable as a static member of `S' and there won't be one.  We
     854                 :             :      might be able to arrange to have the "vtable static member"
     855                 :             :      attached to the member list for `S' before the debug info for
     856                 :             :      `S' get written (which would solve the problem) but that would
     857                 :             :      require more intrusive changes to the g++ front end.  */
     858                 :     2107961 :   DECL_IGNORED_P (decl) = 1;
     859                 :             : 
     860                 :     2107961 :   return decl;
     861                 :             : }
     862                 :             : 
     863                 :             : /* Get the VAR_DECL of the vtable for TYPE. TYPE need not be polymorphic,
     864                 :             :    or even complete.  If this does not exist, create it.  If COMPLETE is
     865                 :             :    nonzero, then complete the definition of it -- that will render it
     866                 :             :    impossible to actually build the vtable, but is useful to get at those
     867                 :             :    which are known to exist in the runtime.  */
     868                 :             : 
     869                 :             : tree
     870                 :     7930258 : get_vtable_decl (tree type, int complete)
     871                 :             : {
     872                 :     7930258 :   tree decl;
     873                 :             : 
     874                 :     7930258 :   if (CLASSTYPE_VTABLES (type))
     875                 :     6262481 :     return CLASSTYPE_VTABLES (type);
     876                 :             : 
     877                 :     1667777 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     878                 :     1667777 :   CLASSTYPE_VTABLES (type) = decl;
     879                 :             : 
     880                 :     1667777 :   if (complete)
     881                 :             :     {
     882                 :       39346 :       DECL_EXTERNAL (decl) = 1;
     883                 :       39346 :       cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
     884                 :             :     }
     885                 :             : 
     886                 :             :   return decl;
     887                 :             : }
     888                 :             : 
     889                 :             : /* Build the primary virtual function table for TYPE.  If BINFO is
     890                 :             :    non-NULL, build the vtable starting with the initial approximation
     891                 :             :    that it is the same as the one which is the head of the association
     892                 :             :    list.  Returns a nonzero value if a new vtable is actually
     893                 :             :    created.  */
     894                 :             : 
     895                 :             : static int
     896                 :     6251380 : build_primary_vtable (tree binfo, tree type)
     897                 :             : {
     898                 :     6251380 :   tree decl;
     899                 :     6251380 :   tree virtuals;
     900                 :             : 
     901                 :     6251380 :   decl = get_vtable_decl (type, /*complete=*/0);
     902                 :             : 
     903                 :     6251380 :   if (binfo)
     904                 :             :     {
     905                 :     6013938 :       if (BINFO_NEW_VTABLE_MARKED (binfo))
     906                 :             :         /* We have already created a vtable for this base, so there's
     907                 :             :            no need to do it again.  */
     908                 :             :         return 0;
     909                 :             : 
     910                 :     1390989 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     911                 :     1390989 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     912                 :     1390989 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     913                 :     1390989 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     914                 :             :     }
     915                 :             :   else
     916                 :             :     {
     917                 :      237442 :       gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
     918                 :             :       virtuals = NULL_TREE;
     919                 :             :     }
     920                 :             : 
     921                 :             :   /* Initialize the association list for this type, based
     922                 :             :      on our first approximation.  */
     923                 :     1628431 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     924                 :     1628431 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     925                 :     1628431 :   SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
     926                 :             :   return 1;
     927                 :             : }
     928                 :             : 
     929                 :             : /* Give BINFO a new virtual function table which is initialized
     930                 :             :    with a skeleton-copy of its original initialization.  The only
     931                 :             :    entry that changes is the `delta' entry, so we can really
     932                 :             :    share a lot of structure.
     933                 :             : 
     934                 :             :    FOR_TYPE is the most derived type which caused this table to
     935                 :             :    be needed.
     936                 :             : 
     937                 :             :    Returns nonzero if we haven't met BINFO before.
     938                 :             : 
     939                 :             :    The order in which vtables are built (by calling this function) for
     940                 :             :    an object must remain the same, otherwise a binary incompatibility
     941                 :             :    can result.  */
     942                 :             : 
     943                 :             : static int
     944                 :      746907 : build_secondary_vtable (tree binfo)
     945                 :             : {
     946                 :      746907 :   if (BINFO_NEW_VTABLE_MARKED (binfo))
     947                 :             :     /* We already created a vtable for this base.  There's no need to
     948                 :             :        do it again.  */
     949                 :             :     return 0;
     950                 :             : 
     951                 :             :   /* Remember that we've created a vtable for this BINFO, so that we
     952                 :             :      don't try to do so again.  */
     953                 :      258825 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     954                 :             : 
     955                 :             :   /* Make fresh virtual list, so we can smash it later.  */
     956                 :      258825 :   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
     957                 :             : 
     958                 :             :   /* Secondary vtables are laid out as part of the same structure as
     959                 :             :      the primary vtable.  */
     960                 :      258825 :   BINFO_VTABLE (binfo) = NULL_TREE;
     961                 :      258825 :   return 1;
     962                 :             : }
     963                 :             : 
     964                 :             : /* Create a new vtable for BINFO which is the hierarchy dominated by
     965                 :             :    T. Return nonzero if we actually created a new vtable.  */
     966                 :             : 
     967                 :             : static int
     968                 :     6760845 : make_new_vtable (tree t, tree binfo)
     969                 :             : {
     970                 :     6760845 :   if (binfo == TYPE_BINFO (t))
     971                 :             :     /* In this case, it is *type*'s vtable we are modifying.  We start
     972                 :             :        with the approximation that its vtable is that of the
     973                 :             :        immediate base class.  */
     974                 :     6013938 :     return build_primary_vtable (binfo, t);
     975                 :             :   else
     976                 :             :     /* This is our very own copy of `basetype' to play with.  Later,
     977                 :             :        we will fill in all the virtual functions that override the
     978                 :             :        virtual functions in these base classes which are not defined
     979                 :             :        by the current type.  */
     980                 :      746907 :     return build_secondary_vtable (binfo);
     981                 :             : }
     982                 :             : 
     983                 :             : /* Make *VIRTUALS, an entry on the BINFO_VIRTUALS list for BINFO
     984                 :             :    (which is in the hierarchy dominated by T) list FNDECL as its
     985                 :             :    BV_FN.  DELTA is the required constant adjustment from the `this'
     986                 :             :    pointer where the vtable entry appears to the `this' required when
     987                 :             :    the function is actually called.  */
     988                 :             : 
     989                 :             : static void
     990                 :     6997949 : modify_vtable_entry (tree t,
     991                 :             :                      tree binfo,
     992                 :             :                      tree fndecl,
     993                 :             :                      tree delta,
     994                 :             :                      tree *virtuals)
     995                 :             : {
     996                 :     6997949 :   tree v;
     997                 :             : 
     998                 :     6997949 :   v = *virtuals;
     999                 :             : 
    1000                 :     6997949 :   if (fndecl != BV_FN (v)
    1001                 :     6997949 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
    1002                 :             :     {
    1003                 :             :       /* We need a new vtable for BINFO.  */
    1004                 :     5111031 :       if (make_new_vtable (t, binfo))
    1005                 :             :         {
    1006                 :             :           /* If we really did make a new vtable, we also made a copy
    1007                 :             :              of the BINFO_VIRTUALS list.  Now, we have to find the
    1008                 :             :              corresponding entry in that list.  */
    1009                 :           0 :           *virtuals = BINFO_VIRTUALS (binfo);
    1010                 :           0 :           while (BV_FN (*virtuals) != BV_FN (v))
    1011                 :           0 :             *virtuals = TREE_CHAIN (*virtuals);
    1012                 :             :           v = *virtuals;
    1013                 :             :         }
    1014                 :             : 
    1015                 :     5111031 :       BV_DELTA (v) = delta;
    1016                 :     5111031 :       BV_VCALL_INDEX (v) = NULL_TREE;
    1017                 :     5111031 :       BV_FN (v) = fndecl;
    1018                 :             :     }
    1019                 :     6997949 : }
    1020                 :             : 
    1021                 :             : 
    1022                 :             : /* Check if the object parameter of an iobj member function corresponds to
    1023                 :             :    another parameter type.  CONTEXT is the class that the implicit object
    1024                 :             :    parameter is considered to refer to.  */
    1025                 :             : 
    1026                 :             : bool
    1027                 :       71523 : iobj_parm_corresponds_to (tree iobj_fn, tree xobj_param, tree context)
    1028                 :             : {
    1029                 :       71523 :   tree iobj_fn_type = TREE_TYPE (iobj_fn);
    1030                 :             : 
    1031                 :             :   /* If the iobj member function was introduced with a using declaration, the
    1032                 :             :      type of its object parameter is considered to be that of the class it was
    1033                 :             :      introduced into.
    1034                 :             : 
    1035                 :             :      [over.match.funcs.general.4]
    1036                 :             :      For non-conversion functions that are implicit object member
    1037                 :             :      functions nominated by a using-declaration in a derived class, the
    1038                 :             :      function is considered to be a member of the derived class for the purpose
    1039                 :             :      of defining the type of the implicit object parameter.
    1040                 :             : 
    1041                 :             :      Unfortunately, because of this rule, we can't just compare the xobj member
    1042                 :             :      function's DECL_CONTEXT to its object parameter.
    1043                 :             : 
    1044                 :             :      struct S;
    1045                 :             : 
    1046                 :             :      struct B {
    1047                 :             :        int f(this S&) { return 5; }
    1048                 :             :      };
    1049                 :             : 
    1050                 :             :      struct S : B {
    1051                 :             :        using B::f;
    1052                 :             :        int f() { return 10; }
    1053                 :             :      };
    1054                 :             : 
    1055                 :             :      The using declaration does not change the object parameter of B::f as it
    1056                 :             :      is an xobj member function.  However, its object parameter still
    1057                 :             :      corresponds to S::f as it was declared with an object parameter of type
    1058                 :             :      S const&.  The DECL_CONTEXT of B::f is B, so if we compare the type of the
    1059                 :             :      object parameter to that, it will not match.  If we naively assume a
    1060                 :             :      different type from the DECL_CONTEXT for an xobj parameter means that the
    1061                 :             :      object parameters do not correspond, then the object parameters in the
    1062                 :             :      above example will be considered non-corresponding.
    1063                 :             : 
    1064                 :             :      As a result of this, B::f would incorrectly not be discarded, causing an
    1065                 :             :      ambiguity when f is called on an object of type S.
    1066                 :             : 
    1067                 :             :      This also impacts member functions with constraints as in the following
    1068                 :             :      example.
    1069                 :             : 
    1070                 :             :      template<typename = void>
    1071                 :             :      struct S;
    1072                 :             : 
    1073                 :             :      template<typename = void>
    1074                 :             :      struct B {
    1075                 :             :        int f(this S<>&) requires true { return 5; }
    1076                 :             :      };
    1077                 :             : 
    1078                 :             :      template<typename>
    1079                 :             :      struct S : B<> {
    1080                 :             :        using B<>::f;
    1081                 :             :        int f() { return 10; }
    1082                 :             :      };
    1083                 :             : 
    1084                 :             :      Once again, if we compare the DECL_CONTEXT of B<>::f to it's xobj
    1085                 :             :      parameter, it would not match.  If the object parameters do not
    1086                 :             :      correspond, constraints are not taken into account, so in this example we
    1087                 :             :      would (probably) get an ambiguous lookup instead of correctly picking
    1088                 :             :      B<>::f.
    1089                 :             : 
    1090                 :             :      Because of this caveat, we must actually compare the type of the iobj
    1091                 :             :      parameter to the type of the xobj parameter, shortcuts will have these
    1092                 :             :      edge cases.
    1093                 :             : 
    1094                 :             :      Aside from the more complex reasons above, this logic also implicitly
    1095                 :             :      handles xobj parameters of pointer type, we don't have to explicitly
    1096                 :             :      check for that case.  */
    1097                 :             : 
    1098                 :       71523 :   if (!same_type_ignoring_top_level_qualifiers_p
    1099                 :       71523 :       (context, non_reference (xobj_param)))
    1100                 :             :     return false;
    1101                 :             : 
    1102                 :             :   /* We don't get to bail yet even if we have a by-value xobj parameter,
    1103                 :             :      a by-value xobj parameter can correspond to an iobj parameter provided the
    1104                 :             :      iobj member function is not declared with a reference qualifier.
    1105                 :             : 
    1106                 :             :      From this point on, we know we are dealing with an xobj parameter that has
    1107                 :             :      an object parameter of the same type as the class it was declared in.
    1108                 :             :      We still don't know if we have a reference or by-value parameter yet
    1109                 :             :      though.  */
    1110                 :             : 
    1111                 :       71521 :   cp_ref_qualifier const iobj_ref_qual = type_memfn_rqual (iobj_fn_type);
    1112                 :             :   /* We only care about cv qualifiers when determining correspondence.  */
    1113                 :       71521 :   static constexpr cp_cv_quals cv_bits = TYPE_QUAL_VOLATILE
    1114                 :             :                                        | TYPE_QUAL_CONST;
    1115                 :       71521 :   cp_cv_quals const iobj_cv_quals = type_memfn_quals (iobj_fn_type) & cv_bits;
    1116                 :             :   /* We need to ignore the ref qualifier of the xobj parameter if the iobj
    1117                 :             :      member function lacks a ref qualifier.
    1118                 :             : 
    1119                 :             :      [basic.scope.scope.3]
    1120                 :             :      Two non-static member functions have corresponding object parameters if:
    1121                 :             :      -- exactly one is an implicit object member function with no ref-qualifier
    1122                 :             :         and the types of their object parameters ([dcl.fct]), after removing
    1123                 :             :         top-level references, are the same, or
    1124                 :             :      -- their object parameters have the same type.
    1125                 :             : 
    1126                 :             :      The cv qualifiers of a by-value parameter are supposed to be discarded, so
    1127                 :             :      we ignore them.
    1128                 :             : 
    1129                 :             :      [dcl.fct.5]
    1130                 :             :      After producing the list of parameter types, any top-level cv-qualifiers
    1131                 :             :      modifying a parameter type are deleted when forming the function type.
    1132                 :             : 
    1133                 :             :      However, they still need to be taken into account when our xobj parameter
    1134                 :             :      is a reference that is being ignored (according to [basic.scope.scope.3]
    1135                 :             :      quoted above), but when we are actually dealing with a by-value xobj
    1136                 :             :      parameter we can proceed following this table.
    1137                 :             :      | iobj | xobj | equal |
    1138                 :             :      | none | none |   X   |
    1139                 :             :      | none |    c |   X   |
    1140                 :             :      | none |    v |   X   |
    1141                 :             :      | none |   cv |   X   |
    1142                 :             :      |    c | none |   O   |
    1143                 :             :      |    c |    c |   O   |
    1144                 :             :      |    c |    v |   O   |
    1145                 :             :      |    c |   cv |   O   |
    1146                 :             :      |    v | none |   O   |
    1147                 :             :      |    v |    c |   O   |
    1148                 :             :      |    v |    v |   O   |
    1149                 :             :      |    v |   cv |   O   |
    1150                 :             :      |   cv | none |   O   |
    1151                 :             :      |   cv |    c |   O   |
    1152                 :             :      |   cv |    v |   O   |
    1153                 :             :      |   cv |   cv |   O   |
    1154                 :             : 
    1155                 :             :      Additionally, if the iobj member function is ref qualified, we aren't
    1156                 :             :      ignoring the ref qualifier of the iobj parameter, so we can't be dealing
    1157                 :             :      with correspondence in that case either.
    1158                 :             : 
    1159                 :             :      So to recap, if we have a by-value xobj parameter, we know for sure that
    1160                 :             :      we aren't dealing with corresponding object parameters if the iobj member
    1161                 :             :      function has any cv-ref qualifiers.  The only case where we might still be
    1162                 :             :      dealing with corresponding object parameters is when the iobj member
    1163                 :             :      function lacks any cv-ref qualification.  */
    1164                 :       71521 :   if (!TYPE_REF_P (xobj_param))
    1165                 :             :     {
    1166                 :         981 :       if (iobj_ref_qual || iobj_cv_quals)
    1167                 :             :         return false;
    1168                 :             :     }
    1169                 :             :   else
    1170                 :             :     {
    1171                 :             :       /* We are dealing with an xobj parameter that is a reference now, but due
    1172                 :             :          to [basic.scope.scope.3] we need to ignore its ref qual.  */
    1173                 :      141080 :       cp_ref_qualifier const xobj_ref_qual = [&](){
    1174                 :       70540 :           if (!TYPE_REF_P (xobj_param) || !iobj_ref_qual)
    1175                 :             :             return REF_QUAL_NONE;
    1176                 :         816 :           return TYPE_REF_IS_RVALUE (xobj_param) ? REF_QUAL_RVALUE
    1177                 :             :                                                  : REF_QUAL_LVALUE;
    1178                 :       70540 :         }(); /* IILE.  */
    1179                 :             : 
    1180                 :             :       /* Even if we are ignoring the reference qualifier, the xobj parameter
    1181                 :             :          was still a reference so we still take the cv qualifiers into
    1182                 :             :          account.  */
    1183                 :       70540 :       cp_cv_quals const xobj_cv_quals
    1184                 :       70540 :         = cp_type_quals (TREE_TYPE (xobj_param)) & cv_bits;
    1185                 :             : 
    1186                 :             :       /* Finally, if the qualifications don't match exactly, the object
    1187                 :             :          parameters don't correspond.  */
    1188                 :       70540 :       if (iobj_ref_qual != xobj_ref_qual
    1189                 :       70156 :           || iobj_cv_quals != xobj_cv_quals)
    1190                 :             :         return false;
    1191                 :             :     }
    1192                 :             :   /* If we got past everything else, the object parameters of fn1 and fn2
    1193                 :             :      definitely correspond.  */
    1194                 :             :   return true;
    1195                 :             : }
    1196                 :             : 
    1197                 :             : /* True if FN and METHOD have corresponding object parms per
    1198                 :             :    [basic.scope.scope], or if one of them is a static member function (which
    1199                 :             :    are considered to have an object parm that corresponds to any other).
    1200                 :             :    CONTEXT is the class that an implicit object member function is considered
    1201                 :             :    to be a member of for the purpose of this comparison, per
    1202                 :             :    [over.match.funcs].  */
    1203                 :             : 
    1204                 :             : bool
    1205                 :   366174922 : object_parms_correspond (tree fn, tree method, tree context)
    1206                 :             : {
    1207                 :   366174922 :   tree fn_type = TREE_TYPE (fn);
    1208                 :   366174922 :   tree method_type = TREE_TYPE (method);
    1209                 :             : 
    1210                 :             :   /* Compare the quals on the 'this' parm.  Don't compare
    1211                 :             :      the whole types, as used functions are treated as
    1212                 :             :      coming from the using class in overload resolution.  */
    1213                 :   366174922 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    1214                 :   366174922 :       && DECL_IOBJ_MEMBER_FUNCTION_P (method))
    1215                 :             :     {
    1216                 :             :       /* Either both or neither need to be ref-qualified for
    1217                 :             :          differing quals to allow overloading.  */
    1218                 :   363545400 :       if ((FUNCTION_REF_QUALIFIED (fn_type)
    1219                 :   363545400 :            == FUNCTION_REF_QUALIFIED (method_type))
    1220                 :   363545400 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1221                 :   347842458 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1222                 :    15812042 :         return false;
    1223                 :   347733358 :       return true;
    1224                 :             :     }
    1225                 :             :   /* Treat a static member function as corresponding to any object parm.  */
    1226                 :     2629522 :   else if (DECL_STATIC_FUNCTION_P (fn) || DECL_STATIC_FUNCTION_P (method))
    1227                 :             :     return true;
    1228                 :             :   /* Handle special correspondence rules for xobj vs xobj and xobj vs iobj
    1229                 :             :      member function declarations.
    1230                 :             :      We don't worry about static member functions here.  */
    1231                 :        8625 :   else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn)
    1232                 :       16516 :            && DECL_XOBJ_MEMBER_FUNCTION_P (method))
    1233                 :             :     {
    1234                 :       21531 :       auto get_object_param = [] (tree fn)
    1235                 :             :         {
    1236                 :       14354 :           return TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    1237                 :             :         };
    1238                 :             :       /* We skip the object parameter below, check it here instead of
    1239                 :             :          making changes to that code.  */
    1240                 :        7177 :       tree fn_param = get_object_param (fn);
    1241                 :        7177 :       tree method_param = get_object_param (method);
    1242                 :        7177 :       if (!same_type_p (fn_param, method_param))
    1243                 :        2004 :         return false;
    1244                 :             :     }
    1245                 :             :   else
    1246                 :             :     {
    1247                 :        1448 :       tree xobj_fn = DECL_XOBJ_MEMBER_FUNCTION_P (fn) ? fn : method;
    1248                 :        1448 :       tree iobj_fn = xobj_fn != fn ? fn : method;
    1249                 :        1448 :       tree xobj_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (xobj_fn)));
    1250                 :             : 
    1251                 :        1448 :       return iobj_parm_corresponds_to (iobj_fn, xobj_param, context);
    1252                 :             :     }
    1253                 :             : 
    1254                 :        5173 :   return true;
    1255                 :             : }
    1256                 :             : 
    1257                 :             : /* Add method METHOD to class TYPE.  If VIA_USING indicates whether
    1258                 :             :    METHOD is being injected via a using_decl.  Returns true if the
    1259                 :             :    method could be added to the method vec.  */
    1260                 :             : 
    1261                 :             : bool
    1262                 :   275205310 : add_method (tree type, tree method, bool via_using)
    1263                 :             : {
    1264                 :   275205310 :   if (method == error_mark_node)
    1265                 :             :     return false;
    1266                 :             : 
    1267                 :   275205310 :   gcc_assert (!DECL_EXTERN_C_P (method));
    1268                 :             : 
    1269                 :   275205310 :   tree *slot = find_member_slot (type, DECL_NAME (method));
    1270                 :   275205310 :   tree current_fns = slot ? *slot : NULL_TREE;
    1271                 :             : 
    1272                 :             :   /* See below.  */
    1273                 :   275205310 :   int losem = -1;
    1274                 :             : 
    1275                 :             :   /* Check to see if we've already got this method.  */
    1276                 :  1149247010 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1277                 :             :     {
    1278                 :   488364939 :       tree fn = *iter;
    1279                 :             : 
    1280                 :   488364939 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1281                 :   120847780 :         continue;
    1282                 :             : 
    1283                 :             :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1284                 :             :          overload resolution.  */
    1285                 :     3025985 :       if (via_using && iter.using_p ()
    1286                 :             :           /* Except handle inherited constructors specially.  */
    1287                 :   370826659 :           && ! DECL_CONSTRUCTOR_P (fn))
    1288                 :             :         {
    1289                 :     1353931 :           if (fn == method)
    1290                 :             :             /* Don't add the same one twice.  */
    1291                 :        5788 :             return false;
    1292                 :     1353922 :           continue;
    1293                 :             :         }
    1294                 :             : 
    1295                 :             :       /* [over.load] Member function declarations with the
    1296                 :             :          same name and the same parameter types cannot be
    1297                 :             :          overloaded if any of them is a static member
    1298                 :             :          function declaration.
    1299                 :             : 
    1300                 :             :          [over.load] Member function declarations with the same name and
    1301                 :             :          the same parameter-type-list as well as member function template
    1302                 :             :          declarations with the same name, the same parameter-type-list, and
    1303                 :             :          the same template parameter lists cannot be overloaded if any of
    1304                 :             :          them, but not all, have a ref-qualifier.
    1305                 :             : 
    1306                 :             :          [namespace.udecl] When a using-declaration brings names
    1307                 :             :          from a base class into a derived class scope, member
    1308                 :             :          functions in the derived class override and/or hide member
    1309                 :             :          functions with the same name and parameter types in a base
    1310                 :             :          class (rather than conflicting).  */
    1311                 :   366163228 :       if (!object_parms_correspond (fn, method, type))
    1312                 :    15815104 :         continue;
    1313                 :             : 
    1314                 :   350348124 :       tree fn_type = TREE_TYPE (fn);
    1315                 :   350348124 :       tree method_type = TREE_TYPE (method);
    1316                 :             : 
    1317                 :   350348124 :       tree real_fn = fn;
    1318                 :   350348124 :       tree real_method = method;
    1319                 :             : 
    1320                 :             :       /* Templates and conversion ops must match return types.  */
    1321                 :   700631172 :       if ((DECL_CONV_FN_P (fn) || TREE_CODE (fn) == TEMPLATE_DECL)
    1322                 :   499841827 :           && !same_type_p (TREE_TYPE (fn_type), TREE_TYPE (method_type)))
    1323                 :     3938402 :         continue;
    1324                 :             :       
    1325                 :             :       /* For templates, the template parameters must be identical.  */
    1326                 :   346409722 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    1327                 :             :         {
    1328                 :   291240718 :           if (!comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1329                 :   145620359 :                                     DECL_TEMPLATE_PARMS (method)))
    1330                 :   116466710 :             continue;
    1331                 :             : 
    1332                 :    29153649 :           real_fn = DECL_TEMPLATE_RESULT (fn);
    1333                 :    29153649 :           real_method = DECL_TEMPLATE_RESULT (method);
    1334                 :             :         }
    1335                 :             : 
    1336                 :   229943012 :       tree parms1 = TYPE_ARG_TYPES (fn_type);
    1337                 :   229943012 :       tree parms2 = TYPE_ARG_TYPES (method_type);
    1338                 :   229943012 :       if (! DECL_STATIC_FUNCTION_P (real_fn))
    1339                 :   228142008 :         parms1 = TREE_CHAIN (parms1);
    1340                 :   229943012 :       if (! DECL_STATIC_FUNCTION_P (real_method))
    1341                 :   228134065 :         parms2 = TREE_CHAIN (parms2);
    1342                 :             : 
    1343                 :             :       /* Bring back parameters omitted from an inherited ctor.  The
    1344                 :             :          method and the function can have different omittedness.  */
    1345                 :   229943012 :       if (ctor_omit_inherited_parms (real_fn))
    1346                 :         729 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_CLONED_FUNCTION (real_fn));
    1347                 :   229943012 :       if (ctor_omit_inherited_parms (real_method))
    1348                 :         330 :         parms2 = (FUNCTION_FIRST_USER_PARMTYPE
    1349                 :             :                   (DECL_CLONED_FUNCTION (real_method)));
    1350                 :             : 
    1351                 :   229943012 :       if (!compparms (parms1, parms2))
    1352                 :   228841303 :         continue;
    1353                 :             : 
    1354                 :     1101709 :       if (!equivalently_constrained (fn, method))
    1355                 :             :         {
    1356                 :      971569 :           if (processing_template_decl)
    1357                 :             :             /* We can't check satisfaction in dependent context, wait until
    1358                 :             :                the class is instantiated.  */
    1359                 :      139277 :             continue;
    1360                 :             : 
    1361                 :      832292 :           special_function_kind sfk = special_memfn_p (method);
    1362                 :             : 
    1363                 :     1631207 :           if (sfk == sfk_none
    1364                 :      133112 :               || DECL_INHERITED_CTOR (fn)
    1365                 :      898813 :               || TREE_CODE (fn) == TEMPLATE_DECL)
    1366                 :             :             /* Member function templates and non-special member functions
    1367                 :             :                coexist if they are not equivalently constrained.  A member
    1368                 :             :                function is not hidden by an inherited constructor.  */
    1369                 :      798915 :             continue;
    1370                 :             : 
    1371                 :             :           /* P0848: For special member functions, deleted, unsatisfied, or
    1372                 :             :              less constrained overloads are ineligible.  We implement this
    1373                 :             :              by removing them from CLASSTYPE_MEMBER_VEC.  Destructors don't
    1374                 :             :              use the notion of eligibility, and the selected destructor can
    1375                 :             :              be deleted, but removing unsatisfied or less constrained
    1376                 :             :              overloads has the same effect as overload resolution.  */
    1377                 :       33377 :           bool dtor = (sfk == sfk_destructor);
    1378                 :       33377 :           if (losem == -1)
    1379                 :       65835 :             losem = ((!dtor && DECL_DELETED_FN (method))
    1380                 :       65793 :                      || !constraints_satisfied_p (method));
    1381                 :       32510 :           bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1382                 :       37850 :                         || !constraints_satisfied_p (fn));
    1383                 :       33377 :           int win;
    1384                 :       33377 :           if (losem || losef)
    1385                 :       32648 :             win = losem - losef;
    1386                 :             :           else
    1387                 :         729 :             win = more_constrained (fn, method);
    1388                 :       33377 :           if (win > 0)
    1389                 :             :             /* Leave FN in the method vec, discard METHOD.  */
    1390                 :             :             return false;
    1391                 :       28861 :           else if (win < 0)
    1392                 :             :             {
    1393                 :             :               /* Remove FN, add METHOD.  */
    1394                 :       26205 :               current_fns = iter.remove_node (current_fns);
    1395                 :       26205 :               continue;
    1396                 :             :             }
    1397                 :             :           else
    1398                 :             :             /* Let them coexist for now.  */
    1399                 :        2656 :             continue;
    1400                 :             :         }
    1401                 :             : 
    1402                 :             :       /* If these are versions of the same function, process and
    1403                 :             :          move on.  */
    1404                 :      130167 :       if (TREE_CODE (fn) == FUNCTION_DECL
    1405                 :      130140 :           && maybe_version_functions (method, fn, true))
    1406                 :          27 :         continue;
    1407                 :             : 
    1408                 :      260226 :       if (DECL_INHERITED_CTOR (method))
    1409                 :             :         {
    1410                 :        2002 :           if (!DECL_INHERITED_CTOR (fn))
    1411                 :             :             /* Defer to the other function.  */
    1412                 :         929 :             return false;
    1413                 :             :             
    1414                 :         105 :           tree basem = DECL_INHERITED_CTOR_BASE (method);
    1415                 :         210 :           tree basef = DECL_INHERITED_CTOR_BASE (fn);
    1416                 :         105 :           if (flag_new_inheriting_ctors)
    1417                 :             :             {
    1418                 :         102 :               if (basem == basef)
    1419                 :             :                 {
    1420                 :             :                   /* Inheriting the same constructor along different
    1421                 :             :                      paths, combine them.  */
    1422                 :          90 :                   SET_DECL_INHERITED_CTOR
    1423                 :             :                     (fn, ovl_make (DECL_INHERITED_CTOR (method),
    1424                 :             :                                    DECL_INHERITED_CTOR (fn)));
    1425                 :             :                   /* And discard the new one.  */
    1426                 :          30 :                   return false;
    1427                 :             :                 }
    1428                 :             :               else
    1429                 :             :                 /* Inherited ctors can coexist until overload
    1430                 :             :                    resolution.  */
    1431                 :          72 :                 continue;
    1432                 :             :             }
    1433                 :             : 
    1434                 :           3 :           auto_diagnostic_group d;
    1435                 :           3 :           error_at (DECL_SOURCE_LOCATION (method),
    1436                 :             :                     "%q#D conflicts with version inherited from %qT",
    1437                 :             :                     method, basef);
    1438                 :           3 :           inform (DECL_SOURCE_LOCATION (fn),
    1439                 :             :                   "version inherited from %qT declared here",
    1440                 :             :                   basef);
    1441                 :           3 :           return false;
    1442                 :           3 :         }
    1443                 :             : 
    1444                 :      129112 :       if (via_using)
    1445                 :             :         /* Defer to the local function.  */
    1446                 :             :         return false;
    1447                 :      129100 :       else if (iter.using_p ()
    1448                 :      129100 :                ||  (flag_new_inheriting_ctors
    1449                 :      171508 :                     && DECL_INHERITED_CTOR (fn)))
    1450                 :             :         {
    1451                 :             :           /* Remove the inherited function.  */
    1452                 :      128778 :           current_fns = iter.remove_node (current_fns);
    1453                 :      128778 :           continue;
    1454                 :             :         }
    1455                 :             :       else
    1456                 :             :         {
    1457                 :         322 :           auto_diagnostic_group d;
    1458                 :         322 :           error_at (DECL_SOURCE_LOCATION (method),
    1459                 :             :                     "%q#D cannot be overloaded with %q#D", method, fn);
    1460                 :         322 :           inform (DECL_SOURCE_LOCATION (fn),
    1461                 :             :                   "previous declaration %q#D", fn);
    1462                 :         322 :           return false;
    1463                 :         322 :         }
    1464                 :             :     }
    1465                 :             : 
    1466                 :   275199522 :   current_fns = ovl_insert (method, current_fns, via_using);
    1467                 :             : 
    1468                 :   507220797 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1469                 :   505513084 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1470                 :             :     return false;
    1471                 :             : 
    1472                 :   275199507 :   if (!slot)
    1473                 :   124643361 :     slot = add_member_slot (type, DECL_NAME (method));
    1474                 :             : 
    1475                 :             :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1476                 :   275199507 :   grok_special_member_properties (method);
    1477                 :             : 
    1478                 :   275199507 :   *slot = current_fns;
    1479                 :             : 
    1480                 :   275199507 :   return true;
    1481                 :             : }
    1482                 :             : 
    1483                 :             : /* Subroutines of finish_struct.  */
    1484                 :             : 
    1485                 :             : /* Change the access of FDECL to ACCESS in T.  Return 1 if change was
    1486                 :             :    legit, otherwise return 0.  */
    1487                 :             : 
    1488                 :             : static int
    1489                 :     2461684 : alter_access (tree t, tree fdecl, tree access)
    1490                 :             : {
    1491                 :     2461684 :   tree elem;
    1492                 :             : 
    1493                 :     2461684 :   retrofit_lang_decl (fdecl);
    1494                 :             : 
    1495                 :     2461684 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1496                 :             : 
    1497                 :     2461684 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1498                 :     2461684 :   if (elem)
    1499                 :             :     {
    1500                 :           0 :       if (TREE_VALUE (elem) != access)
    1501                 :             :         {
    1502                 :           0 :           if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
    1503                 :           0 :             error ("conflicting access specifications for method"
    1504                 :           0 :                    " %q+D, ignored", TREE_TYPE (fdecl));
    1505                 :             :           else
    1506                 :           0 :             error ("conflicting access specifications for field %qE, ignored",
    1507                 :           0 :                    DECL_NAME (fdecl));
    1508                 :             :         }
    1509                 :             :       else
    1510                 :             :         {
    1511                 :             :           /* They're changing the access to the same thing they changed
    1512                 :             :              it to before.  That's OK.  */
    1513                 :             :           ;
    1514                 :             :         }
    1515                 :             :     }
    1516                 :             :   else
    1517                 :             :     {
    1518                 :     2461684 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1519                 :             :                                      tf_warning_or_error);
    1520                 :     2461684 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1521                 :     2461684 :       return 1;
    1522                 :             :     }
    1523                 :             :   return 0;
    1524                 :             : }
    1525                 :             : 
    1526                 :             : /* Return the access node for DECL's access in its enclosing class.  */
    1527                 :             : 
    1528                 :             : tree
    1529                 :      486923 : declared_access (tree decl)
    1530                 :             : {
    1531                 :      486923 :   return (TREE_PRIVATE (decl) ? access_private_node
    1532                 :      476826 :           : TREE_PROTECTED (decl) ? access_protected_node
    1533                 :      486923 :           : access_public_node);
    1534                 :             : }
    1535                 :             : 
    1536                 :             : /* If DECL is a non-dependent using of non-ctor function members, push them
    1537                 :             :    and return true, otherwise return false.  Called from
    1538                 :             :    finish_member_declaration.  */
    1539                 :             : 
    1540                 :             : bool
    1541                 :   151684461 : maybe_push_used_methods (tree decl)
    1542                 :             : {
    1543                 :   151684461 :   if (TREE_CODE (decl) != USING_DECL)
    1544                 :             :     return false;
    1545                 :     2486717 :   tree used = strip_using_decl (decl);
    1546                 :     2486717 :   if (!used || !is_overloaded_fn (used))
    1547                 :             :     return false;
    1548                 :             : 
    1549                 :             :   /* Add the functions to CLASSTYPE_MEMBER_VEC so that overload resolution
    1550                 :             :      works within the class body.  */
    1551                 :     4959945 :   for (tree f : ovl_range (used))
    1552                 :             :     {
    1553                 :     4695174 :       if (DECL_CONSTRUCTOR_P (f))
    1554                 :             :         /* Inheriting constructors are handled separately.  */
    1555                 :       50023 :         return false;
    1556                 :             : 
    1557                 :     2297564 :       bool added = add_method (current_class_type, f, true);
    1558                 :             : 
    1559                 :     2297564 :       if (added)
    1560                 :     2297543 :         alter_access (current_class_type, f, current_access_specifier);
    1561                 :             : 
    1562                 :             :       /* If add_method returns false because f was already declared, look
    1563                 :             :          for a duplicate using-declaration.  */
    1564                 :             :       else
    1565                 :          72 :         for (tree d = TYPE_FIELDS (current_class_type); d; d = DECL_CHAIN (d))
    1566                 :          57 :           if (TREE_CODE (d) == USING_DECL
    1567                 :          24 :               && DECL_NAME (d) == DECL_NAME (decl)
    1568                 :          66 :               && same_type_p (USING_DECL_SCOPE (d), USING_DECL_SCOPE (decl)))
    1569                 :             :             {
    1570                 :           6 :               diagnose_name_conflict (decl, d);
    1571                 :           6 :               break;
    1572                 :             :             }
    1573                 :             :     }
    1574                 :     1388469 :   return true;
    1575                 :             : }
    1576                 :             : 
    1577                 :             : /* Process the USING_DECL, which is a member of T.  */
    1578                 :             : 
    1579                 :             : static void
    1580                 :     1853872 : handle_using_decl (tree using_decl, tree t)
    1581                 :             : {
    1582                 :     1853872 :   tree decl = USING_DECL_DECLS (using_decl);
    1583                 :             : 
    1584                 :     1853872 :   gcc_assert (!processing_template_decl && decl);
    1585                 :             : 
    1586                 :     1853872 :   cp_emit_debug_info_for_using (decl, t);
    1587                 :             : 
    1588                 :     1853872 :   if (is_overloaded_fn (decl))
    1589                 :             :     /* Handled in maybe_push_used_methods.  */
    1590                 :     1853872 :     return;
    1591                 :             : 
    1592                 :      465561 :   tree name = DECL_NAME (using_decl);
    1593                 :      465561 :   tree old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1594                 :             :                                   tf_warning_or_error);
    1595                 :      465561 :   if (old_value)
    1596                 :             :     {
    1597                 :      465561 :       old_value = OVL_FIRST (old_value);
    1598                 :             : 
    1599                 :      465561 :       if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
    1600                 :             :         /* OK */;
    1601                 :             :       else
    1602                 :             :         old_value = NULL_TREE;
    1603                 :             :     }
    1604                 :             : 
    1605                 :           0 :   if (! old_value)
    1606                 :             :     ;
    1607                 :           0 :   else if (is_overloaded_fn (old_value))
    1608                 :             :     {
    1609                 :           0 :       auto_diagnostic_group d;
    1610                 :           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1611                 :             :                 "because of local method %q#D with same name",
    1612                 :             :                 using_decl, t, old_value);
    1613                 :           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1614                 :             :               "local method %q#D declared here", old_value);
    1615                 :           0 :       return;
    1616                 :           0 :     }
    1617                 :           0 :   else if (!DECL_ARTIFICIAL (old_value))
    1618                 :             :     {
    1619                 :           0 :       auto_diagnostic_group d;
    1620                 :           0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1621                 :             :                 "because of local member %q#D with same name",
    1622                 :             :                 using_decl, t, old_value);
    1623                 :           0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1624                 :             :               "local member %q#D declared here", old_value);
    1625                 :           0 :       return;
    1626                 :           0 :     }
    1627                 :             : 
    1628                 :      465561 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (using_decl));
    1629                 :      465561 :   tree access = declared_access (using_decl);
    1630                 :             : 
    1631                 :             :   /* Make type T see field decl FDECL with access ACCESS.  */
    1632                 :      465561 :   if (USING_DECL_UNRELATED_P (using_decl))
    1633                 :             :     {
    1634                 :             :       /* C++20 using enum can import non-inherited enumerators into class
    1635                 :             :          scope.  We implement that by making a copy of the CONST_DECL for which
    1636                 :             :          CONST_DECL_USING_P is true.  */
    1637                 :      301420 :       gcc_assert (TREE_CODE (decl) == CONST_DECL);
    1638                 :             : 
    1639                 :      301420 :       auto cas = make_temp_override (current_access_specifier, access);
    1640                 :      301420 :       tree copy = copy_decl (decl);
    1641                 :      301420 :       DECL_CONTEXT (copy) = t;
    1642                 :      301420 :       DECL_ARTIFICIAL (copy) = true;
    1643                 :             :       /* We emitted debug info for the USING_DECL above; make sure we don't
    1644                 :             :          also emit anything for this clone.  */
    1645                 :      301420 :       DECL_IGNORED_P (copy) = true;
    1646                 :      301420 :       DECL_SOURCE_LOCATION (copy) = DECL_SOURCE_LOCATION (using_decl);
    1647                 :      301420 :       finish_member_declaration (copy);
    1648                 :      301420 :       DECL_ABSTRACT_ORIGIN (copy) = decl;
    1649                 :      301420 :     }
    1650                 :             :   else
    1651                 :      164141 :     alter_access (t, decl, access);
    1652                 :      465561 : }
    1653                 :             : 
    1654                 :             : /* Data structure for find_abi_tags_r, below.  */
    1655                 :             : 
    1656                 :             : struct abi_tag_data
    1657                 :             : {
    1658                 :             :   tree t;               // The type that we're checking for missing tags.
    1659                 :             :   tree subob;           // The subobject of T that we're getting tags from.
    1660                 :             :   tree tags; // error_mark_node for diagnostics, or a list of missing tags.
    1661                 :             : };
    1662                 :             : 
    1663                 :             : /* Subroutine of find_abi_tags_r. Handle a single TAG found on the class TP
    1664                 :             :    in the context of P.  TAG can be either an identifier (the DECL_NAME of
    1665                 :             :    a tag NAMESPACE_DECL) or a STRING_CST (a tag attribute).  */
    1666                 :             : 
    1667                 :             : static void
    1668                 :    11961456 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1669                 :             : {
    1670                 :    11961456 :   if (!IDENTIFIER_MARKED (id))
    1671                 :             :     {
    1672                 :     4969790 :       if (p->tags != error_mark_node)
    1673                 :             :         {
    1674                 :             :           /* We're collecting tags from template arguments or from
    1675                 :             :              the type of a variable or function return type.  */
    1676                 :     4969772 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1677                 :             : 
    1678                 :             :           /* Don't inherit this tag multiple times.  */
    1679                 :     4969772 :           IDENTIFIER_MARKED (id) = true;
    1680                 :             : 
    1681                 :     4969772 :           if (TYPE_P (p->t))
    1682                 :             :             {
    1683                 :             :               /* Tags inherited from type template arguments are only used
    1684                 :             :                  to avoid warnings.  */
    1685                 :     4950686 :               ABI_TAG_IMPLICIT (p->tags) = true;
    1686                 :     4950686 :               return;
    1687                 :             :             }
    1688                 :             :           /* For functions and variables we want to warn, too.  */
    1689                 :             :         }
    1690                 :             : 
    1691                 :             :       /* Otherwise we're diagnosing missing tags.  */
    1692                 :       19104 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1693                 :             :         {
    1694                 :       18697 :           auto_diagnostic_group d;
    1695                 :       18697 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1696                 :             :                        "that %qT (used in its return type) has",
    1697                 :             :                        p->t, tag, *tp))
    1698                 :           3 :             inform (location_of (*tp), "%qT declared here", *tp);
    1699                 :       18697 :         }
    1700                 :         407 :       else if (VAR_P (p->t))
    1701                 :             :         {
    1702                 :         389 :           auto_diagnostic_group d;
    1703                 :         389 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1704                 :             :                        "that %qT (used in its type) has", p->t, tag, *tp))
    1705                 :           3 :             inform (location_of (*tp), "%qT declared here", *tp);
    1706                 :         389 :         }
    1707                 :          18 :       else if (TYPE_P (p->subob))
    1708                 :             :         {
    1709                 :           6 :           auto_diagnostic_group d;
    1710                 :           6 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1711                 :             :                        "that base %qT has", p->t, tag, p->subob))
    1712                 :           6 :             inform (location_of (p->subob), "%qT declared here",
    1713                 :             :                     p->subob);
    1714                 :           6 :         }
    1715                 :             :       else
    1716                 :             :         {
    1717                 :          12 :           auto_diagnostic_group d;
    1718                 :          12 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1719                 :             :                        "that %qT (used in the type of %qD) has",
    1720                 :             :                        p->t, tag, *tp, p->subob))
    1721                 :             :             {
    1722                 :          12 :               inform (location_of (p->subob), "%qD declared here",
    1723                 :             :                       p->subob);
    1724                 :          12 :               inform (location_of (*tp), "%qT declared here", *tp);
    1725                 :             :             }
    1726                 :          12 :         }
    1727                 :             :     }
    1728                 :             : }
    1729                 :             : 
    1730                 :             : /* Find all the ABI tags in the attribute list ATTR and either call
    1731                 :             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1732                 :             : 
    1733                 :             : static void
    1734                 :  1583243358 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1735                 :             : {
    1736                 :  1583243358 :   if (!attr)
    1737                 :             :     return;
    1738                 :   175688050 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1739                 :    68682818 :        attr = TREE_CHAIN (attr))
    1740                 :   137365666 :     for (tree list = TREE_VALUE (attr); list;
    1741                 :    68682848 :          list = TREE_CHAIN (list))
    1742                 :             :       {
    1743                 :    68682848 :         tree tag = TREE_VALUE (list);
    1744                 :    68682848 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1745                 :    68682848 :         if (tp)
    1746                 :    11961456 :           check_tag (tag, id, tp, p);
    1747                 :             :         else
    1748                 :    56721392 :           IDENTIFIER_MARKED (id) = val;
    1749                 :             :       }
    1750                 :             : }
    1751                 :             : 
    1752                 :             : /* Find all the ABI tags on T and its enclosing scopes and either call
    1753                 :             :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1754                 :             : 
    1755                 :             : static void
    1756                 :   604295320 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1757                 :             : {
    1758                 :  2187538678 :   while (t != global_namespace)
    1759                 :             :     {
    1760                 :  1583243358 :       tree attr;
    1761                 :  1583243358 :       if (TYPE_P (t))
    1762                 :             :         {
    1763                 :   614644387 :           attr = TYPE_ATTRIBUTES (t);
    1764                 :   614644387 :           t = CP_TYPE_CONTEXT (t);
    1765                 :             :         }
    1766                 :             :       else
    1767                 :             :         {
    1768                 :   968598971 :           attr = DECL_ATTRIBUTES (t);
    1769                 :   968598971 :           t = CP_DECL_CONTEXT (t);
    1770                 :             :         }
    1771                 :  1583243358 :       mark_or_check_attr_tags (attr, tp, p, val);
    1772                 :             :     }
    1773                 :   604295320 : }
    1774                 :             : 
    1775                 :             : /* walk_tree callback for check_abi_tags: if the type at *TP involves any
    1776                 :             :    types with ABI tags, add the corresponding identifiers to the VEC in
    1777                 :             :    *DATA and set IDENTIFIER_MARKED.  */
    1778                 :             : 
    1779                 :             : static tree
    1780                 :   459879312 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1781                 :             : {
    1782                 :   459879312 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1783                 :             :     /* Tell cp_walk_subtrees to look though typedefs. [PR98481] */
    1784                 :   357637963 :     *walk_subtrees = 2;
    1785                 :             : 
    1786                 :   459879312 :   if (!OVERLOAD_TYPE_P (*tp))
    1787                 :             :     return NULL_TREE;
    1788                 :             : 
    1789                 :             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1790                 :             :      anyway, but let's make sure of it.  */
    1791                 :   104259020 :   *walk_subtrees = false;
    1792                 :             : 
    1793                 :   104259020 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1794                 :             : 
    1795                 :   104259020 :   mark_or_check_tags (*tp, tp, p, false);
    1796                 :             : 
    1797                 :   104259020 :   return NULL_TREE;
    1798                 :             : }
    1799                 :             : 
    1800                 :             : /* walk_tree callback for mark_abi_tags: if *TP is a class, set
    1801                 :             :    IDENTIFIER_MARKED on its ABI tags.  */
    1802                 :             : 
    1803                 :             : static tree
    1804                 :   516582674 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1805                 :             : {
    1806                 :   516582674 :   if (TYPE_P (*tp) && *walk_subtrees == 1 && flag_abi_version != 14)
    1807                 :             :     /* Tell cp_walk_subtrees to look though typedefs.  */
    1808                 :   515638612 :     *walk_subtrees = 2;
    1809                 :             : 
    1810                 :   516582674 :   if (!OVERLOAD_TYPE_P (*tp))
    1811                 :             :     return NULL_TREE;
    1812                 :             : 
    1813                 :             :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1814                 :             :      anyway, but let's make sure of it.  */
    1815                 :    98918186 :   *walk_subtrees = false;
    1816                 :             : 
    1817                 :    98918186 :   bool *valp = static_cast<bool*>(data);
    1818                 :             : 
    1819                 :    98918186 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1820                 :             : 
    1821                 :    98918186 :   return NULL_TREE;
    1822                 :             : }
    1823                 :             : 
    1824                 :             : /* Set IDENTIFIER_MARKED on all the ABI tags on T and its enclosing
    1825                 :             :    scopes.  */
    1826                 :             : 
    1827                 :             : static void
    1828                 :   401118114 : mark_abi_tags (tree t, bool val)
    1829                 :             : {
    1830                 :   401118114 :   mark_or_check_tags (t, NULL, NULL, val);
    1831                 :   401118114 :   if (DECL_P (t))
    1832                 :             :     {
    1833                 :   443067316 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1834                 :   361296558 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1835                 :             :         {
    1836                 :             :           /* Template arguments are part of the signature.  */
    1837                 :    10647352 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1838                 :    27700824 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1839                 :             :             {
    1840                 :    17053472 :               tree arg = TREE_VEC_ELT (level, j);
    1841                 :    17053472 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1842                 :             :             }
    1843                 :             :         }
    1844                 :   222648864 :       if (TREE_CODE (t) == FUNCTION_DECL)
    1845                 :             :         /* A function's parameter types are part of the signature, so
    1846                 :             :            we don't need to inherit any tags that are also in them.  */
    1847                 :   584884226 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1848                 :   391262972 :              arg = TREE_CHAIN (arg))
    1849                 :   391262972 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1850                 :             :                                            mark_abi_tags_r, &val);
    1851                 :             :     }
    1852                 :   401118114 : }
    1853                 :             : 
    1854                 :             : /* Check that T has all the ABI tags that subobject SUBOB has, or
    1855                 :             :    warn if not.  If T is a (variable or function) declaration, also
    1856                 :             :    return any missing tags, and add them to T if JUST_CHECKING is false.  */
    1857                 :             : 
    1858                 :             : static tree
    1859                 :   145950864 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1860                 :             : {
    1861                 :   145950864 :   bool inherit = DECL_P (t);
    1862                 :             : 
    1863                 :   145950864 :   if (!inherit && !warn_abi_tag)
    1864                 :             :     return NULL_TREE;
    1865                 :             : 
    1866                 :   111533184 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1867                 :   111533184 :   if (!TREE_PUBLIC (decl))
    1868                 :             :     /* No need to worry about things local to this TU.  */
    1869                 :             :     return NULL_TREE;
    1870                 :             : 
    1871                 :   111324453 :   mark_abi_tags (t, true);
    1872                 :             : 
    1873                 :   111324453 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1874                 :   111324453 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1875                 :   111324453 :   if (inherit)
    1876                 :   111324432 :     data.tags = NULL_TREE;
    1877                 :             : 
    1878                 :   111324453 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1879                 :             : 
    1880                 :   111324453 :   if (!(inherit && data.tags))
    1881                 :             :     /* We don't need to do anything with data.tags.  */;
    1882                 :       19071 :   else if (just_checking)
    1883                 :         667 :     for (tree t = data.tags; t; t = TREE_CHAIN (t))
    1884                 :             :       {
    1885                 :         338 :         tree id = get_identifier (TREE_STRING_POINTER (TREE_VALUE (t)));
    1886                 :         338 :         IDENTIFIER_MARKED (id) = false;
    1887                 :             :       }
    1888                 :             :   else
    1889                 :             :     {
    1890                 :       18742 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1891                 :       18742 :       if (attr)
    1892                 :           0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1893                 :             :       else
    1894                 :       18742 :         DECL_ATTRIBUTES (t)
    1895                 :       37484 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1896                 :             :     }
    1897                 :             : 
    1898                 :   111324453 :   mark_abi_tags (t, false);
    1899                 :             : 
    1900                 :   111324453 :   return data.tags;
    1901                 :             : }
    1902                 :             : 
    1903                 :             : /* Check that DECL has all the ABI tags that are used in parts of its type
    1904                 :             :    that are not reflected in its mangled name.  */
    1905                 :             : 
    1906                 :             : void
    1907                 :   119428007 : check_abi_tags (tree decl)
    1908                 :             : {
    1909                 :   119428007 :   if (VAR_P (decl))
    1910                 :    14573448 :     check_abi_tags (decl, TREE_TYPE (decl));
    1911                 :   104854559 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1912                 :   104851451 :            && !DECL_CONV_FN_P (decl)
    1913                 :   208783504 :            && !mangle_return_type_p (decl))
    1914                 :    96397334 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1915                 :   119428007 : }
    1916                 :             : 
    1917                 :             : /* Return any ABI tags that are used in parts of the type of DECL
    1918                 :             :    that are not reflected in its mangled name.  This function is only
    1919                 :             :    used in backward-compatible mangling for ABI <11.  */
    1920                 :             : 
    1921                 :             : tree
    1922                 :      635846 : missing_abi_tags (tree decl)
    1923                 :             : {
    1924                 :      635846 :   if (VAR_P (decl))
    1925                 :       38347 :     return check_abi_tags (decl, TREE_TYPE (decl), true);
    1926                 :      597499 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1927                 :             :            /* Don't check DECL_CONV_FN_P here like we do in check_abi_tags, so
    1928                 :             :               that we can use this function for setting need_abi_warning
    1929                 :             :               regardless of the current flag_abi_version.  */
    1930                 :      597499 :            && !mangle_return_type_p (decl))
    1931                 :      524031 :     return check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)), true);
    1932                 :             :   else
    1933                 :       73468 :     return NULL_TREE;
    1934                 :             : }
    1935                 :             : 
    1936                 :             : void
    1937                 :    89551667 : inherit_targ_abi_tags (tree t)
    1938                 :             : {
    1939                 :    89234604 :   if (!CLASS_TYPE_P (t)
    1940                 :   178786271 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1941                 :      317063 :     return;
    1942                 :             : 
    1943                 :    89234604 :   mark_abi_tags (t, true);
    1944                 :             : 
    1945                 :    89234604 :   tree args = CLASSTYPE_TI_ARGS (t);
    1946                 :    89234604 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1947                 :   535407806 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1948                 :             :     {
    1949                 :   182817786 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1950                 :   257667870 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1951                 :             :         {
    1952                 :   166258977 :           tree arg = TREE_VEC_ELT (level, j);
    1953                 :   166258977 :           data.subob = arg;
    1954                 :   166258977 :           cp_walk_tree_without_duplicates (&arg, find_abi_tags_r, &data);
    1955                 :             :         }
    1956                 :             :     }
    1957                 :             : 
    1958                 :             :   // If we found some tags on our template arguments, add them to our
    1959                 :             :   // abi_tag attribute.
    1960                 :    89234604 :   if (data.tags)
    1961                 :             :     {
    1962                 :     4950686 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    1963                 :     4950686 :       if (attr)
    1964                 :           3 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1965                 :             :       else
    1966                 :     4950683 :         TYPE_ATTRIBUTES (t)
    1967                 :     9901366 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    1968                 :             :     }
    1969                 :             : 
    1970                 :    89234604 :   mark_abi_tags (t, false);
    1971                 :             : }
    1972                 :             : 
    1973                 :             : /* Return true, iff class T has a non-virtual destructor that is
    1974                 :             :    accessible from outside the class heirarchy (i.e. is public, or
    1975                 :             :    there's a suitable friend.  */
    1976                 :             : 
    1977                 :             : static bool
    1978                 :          99 : accessible_nvdtor_p (tree t)
    1979                 :             : {
    1980                 :          99 :   tree dtor = CLASSTYPE_DESTRUCTOR (t);
    1981                 :             : 
    1982                 :             :   /* An implicitly declared destructor is always public.  And,
    1983                 :             :      if it were virtual, we would have created it by now.  */
    1984                 :          99 :   if (!dtor)
    1985                 :             :     return true;
    1986                 :             : 
    1987                 :          78 :   if (DECL_VINDEX (dtor))
    1988                 :             :     return false; /* Virtual */
    1989                 :             :   
    1990                 :          42 :   if (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
    1991                 :             :     return true;  /* Public */
    1992                 :             : 
    1993                 :          30 :   if (CLASSTYPE_FRIEND_CLASSES (t)
    1994                 :          30 :       || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    1995                 :          12 :     return true;   /* Has friends */
    1996                 :             : 
    1997                 :             :   return false;
    1998                 :             : }
    1999                 :             : 
    2000                 :             : /* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P,
    2001                 :             :    and NO_CONST_ASN_REF_P.  Also set flag bits in T based on
    2002                 :             :    properties of the bases.  */
    2003                 :             : 
    2004                 :             : static void
    2005                 :    36027736 : check_bases (tree t,
    2006                 :             :              int* cant_have_const_ctor_p,
    2007                 :             :              int* no_const_asn_ref_p)
    2008                 :             : {
    2009                 :    36027736 :   int i;
    2010                 :    36027736 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    2011                 :    36027736 :   int seen_tm_mask = 0;
    2012                 :    36027736 :   tree base_binfo;
    2013                 :    36027736 :   tree binfo;
    2014                 :    36027736 :   tree field = NULL_TREE;
    2015                 :             : 
    2016                 :    36027736 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2017                 :   171290327 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    2018                 :   140822519 :       if (TREE_CODE (field) == FIELD_DECL)
    2019                 :             :         break;
    2020                 :             : 
    2021                 :    55389009 :   for (binfo = TYPE_BINFO (t), i = 0;
    2022                 :    55389009 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    2023                 :             :     {
    2024                 :    19361273 :       tree basetype = TREE_TYPE (base_binfo);
    2025                 :             : 
    2026                 :    19361273 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    2027                 :             : 
    2028                 :    19361273 :       if (CLASSTYPE_FINAL (basetype))
    2029                 :          11 :         error ("cannot derive from %<final%> base %qT in derived type %qT",
    2030                 :             :                basetype, t);
    2031                 :             : 
    2032                 :             :       /* If any base class is non-literal, so is the derived class.  */
    2033                 :    19361273 :       if (!CLASSTYPE_LITERAL_P (basetype))
    2034                 :     2176590 :         CLASSTYPE_LITERAL_P (t) = false;
    2035                 :             : 
    2036                 :             :       /* If the base class doesn't have copy constructors or
    2037                 :             :          assignment operators that take const references, then the
    2038                 :             :          derived class cannot have such a member automatically
    2039                 :             :          generated.  */
    2040                 :    19361273 :       if (TYPE_HAS_COPY_CTOR (basetype)
    2041                 :    19361273 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    2042                 :          50 :         *cant_have_const_ctor_p = 1;
    2043                 :    19361273 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    2044                 :    19361273 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    2045                 :          15 :         *no_const_asn_ref_p = 1;
    2046                 :             : 
    2047                 :    19361273 :       if (BINFO_VIRTUAL_P (base_binfo))
    2048                 :             :         /* A virtual base does not effect nearly emptiness.  */
    2049                 :             :         ;
    2050                 :    19313865 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    2051                 :             :         {
    2052                 :      269933 :           if (seen_non_virtual_nearly_empty_base_p)
    2053                 :             :             /* And if there is more than one nearly empty base, then the
    2054                 :             :                derived class is not nearly empty either.  */
    2055                 :        1056 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2056                 :             :           else
    2057                 :             :             /* Remember we've seen one.  */
    2058                 :             :             seen_non_virtual_nearly_empty_base_p = 1;
    2059                 :             :         }
    2060                 :    19043932 :       else if (!is_empty_class (basetype))
    2061                 :             :         /* If the base class is not empty or nearly empty, then this
    2062                 :             :            class cannot be nearly empty.  */
    2063                 :     1840998 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    2064                 :             : 
    2065                 :             :       /* A lot of properties from the bases also apply to the derived
    2066                 :             :          class.  */
    2067                 :    19361273 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    2068                 :    58083819 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    2069                 :    19361273 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    2070                 :    19361273 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    2071                 :    19361273 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    2072                 :    19361273 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    2073                 :    38722546 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    2074                 :    19361273 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    2075                 :    58083819 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    2076                 :    19361273 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    2077                 :    19361273 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    2078                 :    19361273 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    2079                 :    58083819 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    2080                 :    19361273 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    2081                 :    38722546 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    2082                 :    19361273 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    2083                 :    19361273 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    2084                 :             :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    2085                 :             :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    2086                 :    19361273 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    2087                 :             :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    2088                 :             :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    2089                 :    19361273 :       if (TYPE_HAS_MUTABLE_P (basetype))
    2090                 :      949368 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    2091                 :             : 
    2092                 :             :       /*  A standard-layout class is a class that:
    2093                 :             :           ...
    2094                 :             :           * has no non-standard-layout base classes,  */
    2095                 :    19361273 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    2096                 :    19361273 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    2097                 :             :         {
    2098                 :    17722287 :           tree basefield;
    2099                 :             :           /* ...has no base classes of the same type as the first non-static
    2100                 :             :              data member...  */
    2101                 :      706876 :           if (field && DECL_CONTEXT (field) == t
    2102                 :    18385581 :               && (same_type_ignoring_top_level_qualifiers_p
    2103                 :      663294 :                   (TREE_TYPE (field), basetype)))
    2104                 :         128 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2105                 :             :           /* DR 1813:
    2106                 :             :              ...has at most one base class subobject of any given type...  */
    2107                 :    17722159 :           else if (CLASSTYPE_REPEATED_BASE_P (t))
    2108                 :         340 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2109                 :             :           else
    2110                 :             :             /* ...has all non-static data members and bit-fields in the class
    2111                 :             :                and its base classes first declared in the same class.  */
    2112                 :   242238899 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    2113                 :   224517080 :                  basefield = DECL_CHAIN (basefield))
    2114                 :   225218520 :               if (TREE_CODE (basefield) == FIELD_DECL
    2115                 :   226446688 :                   && !(DECL_FIELD_IS_BASE (basefield)
    2116                 :     1228168 :                        && is_empty_field (basefield)))
    2117                 :             :                 {
    2118                 :      701440 :                   if (field)
    2119                 :       93036 :                     CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    2120                 :             :                   else
    2121                 :             :                     field = basefield;
    2122                 :             :                   break;
    2123                 :             :                 }
    2124                 :             :         }
    2125                 :             : 
    2126                 :             :       /* Don't bother collecting tm attributes if transactional memory
    2127                 :             :          support is not enabled.  */
    2128                 :    19361273 :       if (flag_tm)
    2129                 :             :         {
    2130                 :        1183 :           tree tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (basetype));
    2131                 :        1183 :           if (tm_attr)
    2132                 :          15 :             seen_tm_mask |= tm_attr_to_mask (tm_attr);
    2133                 :             :         }
    2134                 :             : 
    2135                 :    19361273 :       check_abi_tags (t, basetype);
    2136                 :             :     }
    2137                 :             : 
    2138                 :             :   /* If one of the base classes had TM attributes, and the current class
    2139                 :             :      doesn't define its own, then the current class inherits one.  */
    2140                 :    36027736 :   if (seen_tm_mask && !find_tm_attribute (TYPE_ATTRIBUTES (t)))
    2141                 :             :     {
    2142                 :          12 :       tree tm_attr = tm_mask_to_attr (least_bit_hwi (seen_tm_mask));
    2143                 :          12 :       TYPE_ATTRIBUTES (t) = tree_cons (tm_attr, NULL, TYPE_ATTRIBUTES (t));
    2144                 :             :     }
    2145                 :    36027736 : }
    2146                 :             : 
    2147                 :             : /* Determine all the primary bases within T.  Sets BINFO_PRIMARY_BASE_P for
    2148                 :             :    those that are primaries.  Sets BINFO_LOST_PRIMARY_P for those
    2149                 :             :    that have had a nearly-empty virtual primary base stolen by some
    2150                 :             :    other base in the hierarchy.  Determines CLASSTYPE_PRIMARY_BASE for
    2151                 :             :    T.  */
    2152                 :             : 
    2153                 :             : static void
    2154                 :    36027736 : determine_primary_bases (tree t)
    2155                 :             : {
    2156                 :    36027736 :   unsigned i;
    2157                 :    36027736 :   tree primary = NULL_TREE;
    2158                 :    36027736 :   tree type_binfo = TYPE_BINFO (t);
    2159                 :    36027736 :   tree base_binfo;
    2160                 :             : 
    2161                 :             :   /* Determine the primary bases of our bases.  */
    2162                 :    59178897 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2163                 :    23151161 :        base_binfo = TREE_CHAIN (base_binfo))
    2164                 :             :     {
    2165                 :    23151161 :       tree primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (base_binfo));
    2166                 :             : 
    2167                 :             :       /* See if we're the non-virtual primary of our inheritance
    2168                 :             :          chain.  */
    2169                 :    23151161 :       if (!BINFO_VIRTUAL_P (base_binfo))
    2170                 :             :         {
    2171                 :    22952083 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    2172                 :    22952083 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    2173                 :             : 
    2174                 :    22952083 :           if (parent_primary
    2175                 :    22952083 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    2176                 :             :                                     BINFO_TYPE (parent_primary)))
    2177                 :             :             /* We are the primary binfo.  */
    2178                 :     1023291 :             BINFO_PRIMARY_P (base_binfo) = 1;
    2179                 :             :         }
    2180                 :             :       /* Determine if we have a virtual primary base, and mark it so.
    2181                 :             :        */
    2182                 :    24181554 :       if (primary && BINFO_VIRTUAL_P (primary))
    2183                 :             :         {
    2184                 :        7102 :           tree this_primary = copied_binfo (primary, base_binfo);
    2185                 :             : 
    2186                 :        7102 :           if (BINFO_PRIMARY_P (this_primary))
    2187                 :             :             /* Someone already claimed this base.  */
    2188                 :         634 :             BINFO_LOST_PRIMARY_P (base_binfo) = 1;
    2189                 :             :           else
    2190                 :             :             {
    2191                 :        6468 :               tree delta;
    2192                 :             : 
    2193                 :        6468 :               BINFO_PRIMARY_P (this_primary) = 1;
    2194                 :        6468 :               BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
    2195                 :             : 
    2196                 :             :               /* A virtual binfo might have been copied from within
    2197                 :             :                  another hierarchy. As we're about to use it as a
    2198                 :             :                  primary base, make sure the offsets match.  */
    2199                 :        6468 :               delta = size_diffop_loc (input_location,
    2200                 :        6468 :                                    fold_convert (ssizetype,
    2201                 :             :                                             BINFO_OFFSET (base_binfo)),
    2202                 :        6468 :                                    fold_convert (ssizetype,
    2203                 :             :                                             BINFO_OFFSET (this_primary)));
    2204                 :             : 
    2205                 :        6468 :               propagate_binfo_offsets (this_primary, delta);
    2206                 :             :             }
    2207                 :             :         }
    2208                 :             :     }
    2209                 :             : 
    2210                 :             :   /* First look for a dynamic direct non-virtual base.  */
    2211                 :    53824725 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    2212                 :             :     {
    2213                 :    19186359 :       tree basetype = BINFO_TYPE (base_binfo);
    2214                 :             : 
    2215                 :    19186359 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    2216                 :             :         {
    2217                 :     1389370 :           primary = base_binfo;
    2218                 :     1389370 :           goto found;
    2219                 :             :         }
    2220                 :             :     }
    2221                 :             : 
    2222                 :             :   /* A "nearly-empty" virtual base class can be the primary base
    2223                 :             :      class, if no non-virtual polymorphic base can be found.  Look for
    2224                 :             :      a nearly-empty virtual dynamic base that is not already a primary
    2225                 :             :      base of something in the hierarchy.  If there is no such base,
    2226                 :             :      just pick the first nearly-empty virtual base.  */
    2227                 :             : 
    2228                 :    54658964 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    2229                 :    20020598 :        base_binfo = TREE_CHAIN (base_binfo))
    2230                 :    20022136 :     if (BINFO_VIRTUAL_P (base_binfo)
    2231                 :    20022136 :         && CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (base_binfo)))
    2232                 :             :       {
    2233                 :        1667 :         if (!BINFO_PRIMARY_P (base_binfo))
    2234                 :             :           {
    2235                 :             :             /* Found one that is not primary.  */
    2236                 :        1538 :             primary = base_binfo;
    2237                 :        1538 :             goto found;
    2238                 :             :           }
    2239                 :         129 :         else if (!primary)
    2240                 :             :           /* Remember the first candidate.  */
    2241                 :    20020598 :           primary = base_binfo;
    2242                 :             :       }
    2243                 :             : 
    2244                 :    34636828 :  found:
    2245                 :             :   /* If we've got a primary base, use it.  */
    2246                 :    36027736 :   if (primary)
    2247                 :             :     {
    2248                 :     1390989 :       tree basetype = BINFO_TYPE (primary);
    2249                 :             : 
    2250                 :     1390989 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    2251                 :     1390989 :       if (BINFO_PRIMARY_P (primary))
    2252                 :             :         /* We are stealing a primary base.  */
    2253                 :          81 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    2254                 :     1390989 :       BINFO_PRIMARY_P (primary) = 1;
    2255                 :     1390989 :       if (BINFO_VIRTUAL_P (primary))
    2256                 :             :         {
    2257                 :        1619 :           tree delta;
    2258                 :             : 
    2259                 :        1619 :           BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
    2260                 :             :           /* A virtual binfo might have been copied from within
    2261                 :             :              another hierarchy. As we're about to use it as a primary
    2262                 :             :              base, make sure the offsets match.  */
    2263                 :        1619 :           delta = size_diffop_loc (input_location, ssize_int (0),
    2264                 :        1619 :                                fold_convert (ssizetype, BINFO_OFFSET (primary)));
    2265                 :             : 
    2266                 :        1619 :           propagate_binfo_offsets (primary, delta);
    2267                 :             :         }
    2268                 :             : 
    2269                 :     1390989 :       primary = TYPE_BINFO (basetype);
    2270                 :             : 
    2271                 :     1390989 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    2272                 :     1390989 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    2273                 :     1390989 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    2274                 :             :     }
    2275                 :    36027736 : }
    2276                 :             : 
    2277                 :             : /* Update the variant types of T.  */
    2278                 :             : 
    2279                 :             : void
    2280                 :   120409588 : fixup_type_variants (tree type)
    2281                 :             : {
    2282                 :   120409588 :   if (!type)
    2283                 :             :     return;
    2284                 :             : 
    2285                 :   120409588 :   for (tree variant = TYPE_NEXT_VARIANT (type);
    2286                 :   242881814 :        variant;
    2287                 :   122472226 :        variant = TYPE_NEXT_VARIANT (variant))
    2288                 :             :     {
    2289                 :             :       /* These fields are in the _TYPE part of the node, not in
    2290                 :             :          the TYPE_LANG_SPECIFIC component, so they are not shared.  */
    2291                 :   122472226 :       TYPE_HAS_USER_CONSTRUCTOR (variant) = TYPE_HAS_USER_CONSTRUCTOR (type);
    2292                 :   122472226 :       TYPE_NEEDS_CONSTRUCTING (variant) = TYPE_NEEDS_CONSTRUCTING (type);
    2293                 :   244944452 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variant)
    2294                 :   122472226 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    2295                 :             : 
    2296                 :   122472226 :       TYPE_POLYMORPHIC_P (variant) = TYPE_POLYMORPHIC_P (type);
    2297                 :   122472226 :       CLASSTYPE_FINAL (variant) = CLASSTYPE_FINAL (type);
    2298                 :             : 
    2299                 :   122472226 :       TYPE_BINFO (variant) = TYPE_BINFO (type);
    2300                 :             : 
    2301                 :             :       /* Copy whatever these are holding today.  */
    2302                 :   122472226 :       TYPE_VFIELD (variant) = TYPE_VFIELD (type);
    2303                 :   122472226 :       TYPE_FIELDS (variant) = TYPE_FIELDS (type);
    2304                 :             : 
    2305                 :   122472226 :       TYPE_SIZE (variant) = TYPE_SIZE (type);
    2306                 :   122472226 :       TYPE_SIZE_UNIT (variant) = TYPE_SIZE_UNIT (type);
    2307                 :             : 
    2308                 :   122472226 :       if (!TYPE_USER_ALIGN (variant)
    2309                 :     2177114 :           || TYPE_NAME (variant) == TYPE_NAME (type)
    2310                 :   123491296 :           || TYPE_ALIGN_RAW (variant) < TYPE_ALIGN_RAW (type))
    2311                 :             :         {
    2312                 :   121453156 :           TYPE_ALIGN_RAW (variant) =  TYPE_ALIGN_RAW (type);
    2313                 :   121453156 :           TYPE_USER_ALIGN (variant) = TYPE_USER_ALIGN (type);
    2314                 :             :         }
    2315                 :             : 
    2316                 :   122472226 :       TYPE_PRECISION (variant) = TYPE_PRECISION (type);
    2317                 :   122472226 :       TYPE_MODE_RAW (variant) = TYPE_MODE_RAW (type);
    2318                 :   122472226 :       TYPE_EMPTY_P (variant) = TYPE_EMPTY_P (type);
    2319                 :   122472226 :       TREE_ADDRESSABLE (variant) = TREE_ADDRESSABLE (type);
    2320                 :             :     }
    2321                 :             : }
    2322                 :             : 
    2323                 :             : /* KLASS is a class that we're applying may_alias to after the body is
    2324                 :             :    parsed.  Fixup any POINTER_TO and REFERENCE_TO types.  The
    2325                 :             :    canonical type(s) will be implicitly updated.  */
    2326                 :             : 
    2327                 :             : static void
    2328                 :       38643 : fixup_may_alias (tree klass)
    2329                 :             : {
    2330                 :       38643 :   tree t, v;
    2331                 :             : 
    2332                 :       57606 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    2333                 :       56874 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2334                 :       37911 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2335                 :       38664 :   for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
    2336                 :          42 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    2337                 :          21 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    2338                 :       38643 : }
    2339                 :             : 
    2340                 :             : /* Early variant fixups: we apply attributes at the beginning of the class
    2341                 :             :    definition, and we need to fix up any variants that have already been
    2342                 :             :    made via elaborated-type-specifier so that check_qualified_type works.  */
    2343                 :             : 
    2344                 :             : void
    2345                 :    76044298 : fixup_attribute_variants (tree t)
    2346                 :             : {
    2347                 :    76044298 :   tree variants;
    2348                 :             : 
    2349                 :    76044298 :   if (!t)
    2350                 :             :     return;
    2351                 :             : 
    2352                 :    76044298 :   tree attrs = TYPE_ATTRIBUTES (t);
    2353                 :    76044298 :   unsigned align = TYPE_ALIGN (t);
    2354                 :    76044298 :   bool user_align = TYPE_USER_ALIGN (t);
    2355                 :    76044298 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2356                 :    76044298 :   bool packed = TYPE_PACKED (t);
    2357                 :             : 
    2358                 :    76044298 :   if (may_alias)
    2359                 :       19431 :     fixup_may_alias (t);
    2360                 :             : 
    2361                 :    76044298 :   for (variants = TYPE_NEXT_VARIANT (t);
    2362                 :   114667919 :        variants;
    2363                 :    38623621 :        variants = TYPE_NEXT_VARIANT (variants))
    2364                 :             :     {
    2365                 :             :       /* These are the two fields that check_qualified_type looks at and
    2366                 :             :          are affected by attributes.  */
    2367                 :    38623621 :       TYPE_ATTRIBUTES (variants) = attrs;
    2368                 :    38623621 :       unsigned valign = align;
    2369                 :    38623621 :       if (TYPE_USER_ALIGN (variants))
    2370                 :         791 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2371                 :             :       else
    2372                 :    38622830 :         TYPE_USER_ALIGN (variants) = user_align;
    2373                 :    38623621 :       SET_TYPE_ALIGN (variants, valign);
    2374                 :    38623621 :       TYPE_PACKED (variants) = packed;
    2375                 :    38623621 :       if (may_alias)
    2376                 :       19212 :         fixup_may_alias (variants);
    2377                 :             :     }
    2378                 :             : }
    2379                 :             : 
    2380                 :             : /* Set memoizing fields and bits of T (and its variants) for later
    2381                 :             :    use.  */
    2382                 :             : 
    2383                 :             : static void
    2384                 :    36027736 : finish_struct_bits (tree t)
    2385                 :             : {
    2386                 :             :   /* If this type has a copy constructor or a destructor, force its
    2387                 :             :      mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be
    2388                 :             :      nonzero.  This will cause it to be passed by invisible reference
    2389                 :             :      and prevent it from being returned in a register.  */
    2390                 :    36027736 :   if (type_has_nontrivial_copy_init (t)
    2391                 :    36027736 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    2392                 :             :     {
    2393                 :     4408595 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2394                 :     4408595 :       SET_TYPE_MODE (t, BLKmode);
    2395                 :     4408595 :       TREE_ADDRESSABLE (t) = 1;
    2396                 :             :     }
    2397                 :             : 
    2398                 :    36027736 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
    2399                 :             :     /* For a class w/o baseclasses, 'finish_struct' has set
    2400                 :             :        CLASSTYPE_PURE_VIRTUALS correctly (by definition).
    2401                 :             :        Similarly for a class whose base classes do not have vtables.
    2402                 :             :        When neither of these is true, we might have removed abstract
    2403                 :             :        virtuals (by providing a definition), added some (by declaring
    2404                 :             :        new ones), or redeclared ones from a base class.  We need to
    2405                 :             :        recalculate what's really an abstract virtual at this point (by
    2406                 :             :        looking in the vtables).  */
    2407                 :     1462319 :     get_pure_virtuals (t);
    2408                 :             : 
    2409                 :             :   /* Fix up variants (if any).  */
    2410                 :    36027736 :   fixup_type_variants (t);
    2411                 :    36027736 : }
    2412                 :             : 
    2413                 :             : /* Issue warnings about T having private constructors, but no friends,
    2414                 :             :    and so forth.
    2415                 :             : 
    2416                 :             :    HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
    2417                 :             :    static members.  HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
    2418                 :             :    non-private static member functions.  */
    2419                 :             : 
    2420                 :             : static void
    2421                 :    24631843 : maybe_warn_about_overly_private_class (tree t)
    2422                 :             : {
    2423                 :    24631843 :   int has_member_fn = 0;
    2424                 :    24631843 :   int has_nonprivate_method = 0;
    2425                 :    24631843 :   bool nonprivate_ctor = false;
    2426                 :             : 
    2427                 :    24631843 :   if (!warn_ctor_dtor_privacy
    2428                 :             :       /* If the class has friends, those entities might create and
    2429                 :             :          access instances, so we should not warn.  */
    2430                 :          48 :       || (CLASSTYPE_FRIEND_CLASSES (t)
    2431                 :          48 :           || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    2432                 :             :       /* We will have warned when the template was declared; there's
    2433                 :             :          no need to warn on every instantiation.  */
    2434                 :    24631891 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
    2435                 :             :     /* There's no reason to even consider warning about this
    2436                 :             :        class.  */
    2437                 :             :     return;
    2438                 :             : 
    2439                 :             :   /* We only issue one warning, if more than one applies, because
    2440                 :             :      otherwise, on code like:
    2441                 :             : 
    2442                 :             :      class A {
    2443                 :             :        // Oops - forgot `public:'
    2444                 :             :        A();
    2445                 :             :        A(const A&);
    2446                 :             :        ~A();
    2447                 :             :      };
    2448                 :             : 
    2449                 :             :      we warn several times about essentially the same problem.  */
    2450                 :             : 
    2451                 :             :   /* Check to see if all (non-constructor, non-destructor) member
    2452                 :             :      functions are private.  (Since there are no friends or
    2453                 :             :      non-private statics, we can't ever call any of the private member
    2454                 :             :      functions.)  */
    2455                 :         216 :   for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    2456                 :         168 :     if (TREE_CODE (fn) == USING_DECL
    2457                 :          18 :         && DECL_NAME (fn) == ctor_identifier
    2458                 :         171 :         && !TREE_PRIVATE (fn))
    2459                 :             :       nonprivate_ctor = true;
    2460                 :         165 :     else if (!DECL_DECLARES_FUNCTION_P (fn))
    2461                 :             :       /* Not a function.  */;
    2462                 :          96 :     else if (DECL_ARTIFICIAL (fn))
    2463                 :             :       /* We're not interested in compiler-generated methods; they don't
    2464                 :             :          provide any way to call private members.  */;
    2465                 :          96 :     else if (!TREE_PRIVATE (fn))
    2466                 :             :       {
    2467                 :          48 :         if (DECL_STATIC_FUNCTION_P (fn))
    2468                 :             :           /* A non-private static member function is just like a
    2469                 :             :              friend; it can create and invoke private member
    2470                 :             :              functions, and be accessed without a class
    2471                 :             :              instance.  */
    2472                 :             :           return;
    2473                 :             : 
    2474                 :             :         has_nonprivate_method = 1;
    2475                 :             :         /* Keep searching for a static member function.  */
    2476                 :             :       }
    2477                 :          96 :     else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
    2478                 :             :       has_member_fn = 1;
    2479                 :             : 
    2480                 :          48 :   if (!has_nonprivate_method && has_member_fn)
    2481                 :             :     {
    2482                 :             :       /* There are no non-private methods, and there's at least one
    2483                 :             :          private member function that isn't a constructor or
    2484                 :             :          destructor.  (If all the private members are
    2485                 :             :          constructors/destructors we want to use the code below that
    2486                 :             :          issues error messages specifically referring to
    2487                 :             :          constructors/destructors.)  */
    2488                 :          12 :       unsigned i;
    2489                 :          12 :       tree binfo = TYPE_BINFO (t);
    2490                 :             : 
    2491                 :          12 :       for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
    2492                 :           0 :         if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
    2493                 :             :           {
    2494                 :             :             has_nonprivate_method = 1;
    2495                 :             :             break;
    2496                 :             :           }
    2497                 :          12 :       if (!has_nonprivate_method)
    2498                 :             :         {
    2499                 :          12 :           warning (OPT_Wctor_dtor_privacy,
    2500                 :             :                    "all member functions in class %qT are private", t);
    2501                 :          12 :           return;
    2502                 :             :         }
    2503                 :             :     }
    2504                 :             : 
    2505                 :             :   /* Even if some of the member functions are non-private, the class
    2506                 :             :      won't be useful for much if all the constructors or destructors
    2507                 :             :      are private: such an object can never be created or destroyed.  */
    2508                 :          36 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    2509                 :           6 :     if (TREE_PRIVATE (dtor))
    2510                 :             :       {
    2511                 :           6 :         warning (OPT_Wctor_dtor_privacy,
    2512                 :             :                  "%q#T only defines a private destructor and has no friends",
    2513                 :             :                  t);
    2514                 :           6 :         return;
    2515                 :             :       }
    2516                 :             : 
    2517                 :             :   /* Warn about classes that have private constructors and no friends.  */
    2518                 :          30 :   if (TYPE_HAS_USER_CONSTRUCTOR (t)
    2519                 :             :       /* Implicitly generated constructors are always public.  */
    2520                 :          30 :       && !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    2521                 :             :     {
    2522                 :          21 :       tree copy_or_move = NULL_TREE;
    2523                 :             : 
    2524                 :             :       /* If a non-template class does not define a copy
    2525                 :             :          constructor, one is defined for it, enabling it to avoid
    2526                 :             :          this warning.  For a template class, this does not
    2527                 :             :          happen, and so we would normally get a warning on:
    2528                 :             : 
    2529                 :             :            template <class T> class C { private: C(); };
    2530                 :             : 
    2531                 :             :          To avoid this asymmetry, we check TYPE_HAS_COPY_CTOR.  All
    2532                 :             :          complete non-template or fully instantiated classes have this
    2533                 :             :          flag set.  */
    2534                 :          21 :       if (!TYPE_HAS_COPY_CTOR (t))
    2535                 :             :         nonprivate_ctor = true;
    2536                 :             :       else
    2537                 :          51 :         for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    2538                 :          27 :           if (TREE_PRIVATE (fn))
    2539                 :          12 :             continue;
    2540                 :          15 :           else if (copy_fn_p (fn) || move_fn_p (fn))
    2541                 :             :             /* Ideally, we wouldn't count any constructor that takes
    2542                 :             :                an argument of the class type as a parameter, because
    2543                 :             :                such things cannot be used to construct an instance of
    2544                 :             :                the class unless you already have one.  */
    2545                 :             :             copy_or_move = fn;
    2546                 :             :           else
    2547                 :             :             {
    2548                 :             :               nonprivate_ctor = true;
    2549                 :             :               break;
    2550                 :             :             }
    2551                 :             : 
    2552                 :          21 :       if (!nonprivate_ctor)
    2553                 :             :         {
    2554                 :          15 :           auto_diagnostic_group d;
    2555                 :          15 :           bool w = warning (OPT_Wctor_dtor_privacy,
    2556                 :             :                             "%q#T only defines private constructors and has "
    2557                 :             :                             "no friends", t);
    2558                 :          15 :           if (w && copy_or_move)
    2559                 :           6 :             inform (DECL_SOURCE_LOCATION (copy_or_move),
    2560                 :             :                     "%q#D is public, but requires an existing %q#T object",
    2561                 :             :                     copy_or_move, t);
    2562                 :          15 :           return;
    2563                 :          15 :         }
    2564                 :             :     }
    2565                 :             : }
    2566                 :             : 
    2567                 :             : /* Make BINFO's vtable have N entries, including RTTI entries,
    2568                 :             :    vbase and vcall offsets, etc.  Set its type and call the back end
    2569                 :             :    to lay it out.  */
    2570                 :             : 
    2571                 :             : static void
    2572                 :     1628431 : layout_vtable_decl (tree binfo, int n)
    2573                 :             : {
    2574                 :     1628431 :   tree atype;
    2575                 :     1628431 :   tree vtable;
    2576                 :             : 
    2577                 :     1628431 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2578                 :     1628431 :   layout_type (atype);
    2579                 :             : 
    2580                 :             :   /* We may have to grow the vtable.  */
    2581                 :     1628431 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2582                 :     1628431 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2583                 :             :     {
    2584                 :      566299 :       TREE_TYPE (vtable) = atype;
    2585                 :      566299 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2586                 :      566299 :       layout_decl (vtable, 0);
    2587                 :             :     }
    2588                 :     1628431 : }
    2589                 :             : 
    2590                 :             : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2591                 :             :    have the same signature.  */
    2592                 :             : 
    2593                 :             : int
    2594                 :    75279559 : same_signature_p (const_tree fndecl, const_tree base_fndecl)
    2595                 :             : {
    2596                 :             :   /* One destructor overrides another if they are the same kind of
    2597                 :             :      destructor.  */
    2598                 :   116440221 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2599                 :    95754197 :       && special_function_p (base_fndecl) == special_function_p (fndecl))
    2600                 :             :     return 1;
    2601                 :             :   /* But a non-destructor never overrides a destructor, nor vice
    2602                 :             :      versa, nor do different kinds of destructors override
    2603                 :             :      one-another.  For example, a complete object destructor does not
    2604                 :             :      override a deleting destructor.  */
    2605                 :   182975106 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2606                 :             :     return 0;
    2607                 :             : 
    2608                 :    45135803 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2609                 :    45135803 :       || (DECL_CONV_FN_P (fndecl)
    2610                 :          33 :           && DECL_CONV_FN_P (base_fndecl)
    2611                 :          12 :           && same_type_p (DECL_CONV_FN_TYPE (fndecl),
    2612                 :             :                           DECL_CONV_FN_TYPE (base_fndecl))))
    2613                 :             :     {
    2614                 :    15724131 :       tree fntype = TREE_TYPE (fndecl);
    2615                 :    15724131 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2616                 :    15724131 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2617                 :    15723841 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2618                 :    31447969 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2619                 :    15723838 :                         FUNCTION_FIRST_USER_PARMTYPE (base_fndecl)))
    2620                 :             :         return 1;
    2621                 :             :     }
    2622                 :             :   return 0;
    2623                 :             : }
    2624                 :             : 
    2625                 :             : /* Returns TRUE if DERIVED is a binfo containing the binfo BASE as a
    2626                 :             :    subobject.  */
    2627                 :             : 
    2628                 :             : static bool
    2629                 :      236473 : base_derived_from (tree derived, tree base)
    2630                 :             : {
    2631                 :      236473 :   tree probe;
    2632                 :             : 
    2633                 :      236749 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2634                 :             :     {
    2635                 :      236644 :       if (probe == derived)
    2636                 :             :         return true;
    2637                 :        1551 :       else if (BINFO_VIRTUAL_P (probe))
    2638                 :             :         /* If we meet a virtual base, we can't follow the inheritance
    2639                 :             :            any more.  See if the complete type of DERIVED contains
    2640                 :             :            such a virtual base.  */
    2641                 :        1275 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (derived))
    2642                 :        1275 :                 != NULL_TREE);
    2643                 :             :     }
    2644                 :             :   return false;
    2645                 :             : }
    2646                 :             : 
    2647                 :     7432596 : struct find_final_overrider_data {
    2648                 :             :   /* The function for which we are trying to find a final overrider.  */
    2649                 :             :   tree fn;
    2650                 :             :   /* The base class in which the function was declared.  */
    2651                 :             :   tree declaring_base;
    2652                 :             :   /* The candidate overriders.  */
    2653                 :             :   tree candidates;
    2654                 :             :   /* Path to most derived.  */
    2655                 :             :   auto_vec<tree> path;
    2656                 :             : };
    2657                 :             : 
    2658                 :             : /* Add the overrider along the current path to FFOD->CANDIDATES.
    2659                 :             :    Returns true if an overrider was found; false otherwise.  */
    2660                 :             : 
    2661                 :             : static bool
    2662                 :    12365195 : dfs_find_final_overrider_1 (tree binfo,
    2663                 :             :                             find_final_overrider_data *ffod,
    2664                 :             :                             unsigned depth)
    2665                 :             : {
    2666                 :    12365195 :   tree method;
    2667                 :             : 
    2668                 :             :   /* If BINFO is not the most derived type, try a more derived class.
    2669                 :             :      A definition there will overrider a definition here.  */
    2670                 :    12365195 :   if (depth)
    2671                 :             :     {
    2672                 :     4696666 :       depth--;
    2673                 :     4696666 :       if (dfs_find_final_overrider_1
    2674                 :     4696666 :           (ffod->path[depth], ffod, depth))
    2675                 :             :         return true;
    2676                 :             :     }
    2677                 :             : 
    2678                 :     9693124 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2679                 :     9693124 :   if (method)
    2680                 :             :     {
    2681                 :     7668529 :       tree *candidate = &ffod->candidates;
    2682                 :             : 
    2683                 :             :       /* Remove any candidates overridden by this new function.  */
    2684                 :     7669051 :       while (*candidate)
    2685                 :             :         {
    2686                 :             :           /* If *CANDIDATE overrides METHOD, then METHOD
    2687                 :             :              cannot override anything else on the list.  */
    2688                 :      235951 :           if (base_derived_from (TREE_VALUE (*candidate), binfo))
    2689                 :             :             return true;
    2690                 :             :           /* If METHOD overrides *CANDIDATE, remove *CANDIDATE.  */
    2691                 :         522 :           if (base_derived_from (binfo, TREE_VALUE (*candidate)))
    2692                 :         468 :             *candidate = TREE_CHAIN (*candidate);
    2693                 :             :           else
    2694                 :          54 :             candidate = &TREE_CHAIN (*candidate);
    2695                 :             :         }
    2696                 :             : 
    2697                 :             :       /* Add the new function.  */
    2698                 :     7433100 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2699                 :     7433100 :       return true;
    2700                 :             :     }
    2701                 :             : 
    2702                 :             :   return false;
    2703                 :             : }
    2704                 :             : 
    2705                 :             : /* Called from find_final_overrider via dfs_walk.  */
    2706                 :             : 
    2707                 :             : static tree
    2708                 :    28326598 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2709                 :             : {
    2710                 :    28326598 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2711                 :             : 
    2712                 :    28326598 :   if (binfo == ffod->declaring_base)
    2713                 :    15337058 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2714                 :    28326598 :   ffod->path.safe_push (binfo);
    2715                 :             : 
    2716                 :    28326598 :   return NULL_TREE;
    2717                 :             : }
    2718                 :             : 
    2719                 :             : static tree
    2720                 :    28326598 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2721                 :             : {
    2722                 :    28326598 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2723                 :    28326598 :   ffod->path.pop ();
    2724                 :             : 
    2725                 :    28326598 :   return NULL_TREE;
    2726                 :             : }
    2727                 :             : 
    2728                 :             : /* Returns a TREE_LIST whose TREE_PURPOSE is the final overrider for
    2729                 :             :    FN and whose TREE_VALUE is the binfo for the base where the
    2730                 :             :    overriding occurs.  BINFO (in the hierarchy dominated by the binfo
    2731                 :             :    DERIVED) is the base object in which FN is declared.  */
    2732                 :             : 
    2733                 :             : static tree
    2734                 :     7432596 : find_final_overrider (tree derived, tree binfo, tree fn)
    2735                 :             : {
    2736                 :     7432596 :   find_final_overrider_data ffod;
    2737                 :             : 
    2738                 :             :   /* Getting this right is a little tricky.  This is valid:
    2739                 :             : 
    2740                 :             :        struct S { virtual void f (); };
    2741                 :             :        struct T { virtual void f (); };
    2742                 :             :        struct U : public S, public T { };
    2743                 :             : 
    2744                 :             :      even though calling `f' in `U' is ambiguous.  But,
    2745                 :             : 
    2746                 :             :        struct R { virtual void f(); };
    2747                 :             :        struct S : virtual public R { virtual void f (); };
    2748                 :             :        struct T : virtual public R { virtual void f (); };
    2749                 :             :        struct U : public S, public T { };
    2750                 :             : 
    2751                 :             :      is not -- there's no way to decide whether to put `S::f' or
    2752                 :             :      `T::f' in the vtable for `R'.
    2753                 :             : 
    2754                 :             :      The solution is to look at all paths to BINFO.  If we find
    2755                 :             :      different overriders along any two, then there is a problem.  */
    2756                 :     7432596 :   if (DECL_THUNK_P (fn))
    2757                 :           0 :     fn = THUNK_TARGET (fn);
    2758                 :             : 
    2759                 :             :   /* Determine the depth of the hierarchy.  */
    2760                 :     7432596 :   ffod.fn = fn;
    2761                 :     7432596 :   ffod.declaring_base = binfo;
    2762                 :     7432596 :   ffod.candidates = NULL_TREE;
    2763                 :     7432596 :   ffod.path.create (30);
    2764                 :             : 
    2765                 :     7432596 :   dfs_walk_all (derived, dfs_find_final_overrider_pre,
    2766                 :             :                 dfs_find_final_overrider_post, &ffod);
    2767                 :             : 
    2768                 :             :   /* If there was no winner, issue an error message.  */
    2769                 :     7432596 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2770                 :          36 :     return error_mark_node;
    2771                 :             : 
    2772                 :             :   return ffod.candidates;
    2773                 :     7432596 : }
    2774                 :             : 
    2775                 :             : /* Return the index of the vcall offset for FN when TYPE is used as a
    2776                 :             :    virtual base.  */
    2777                 :             : 
    2778                 :             : static tree
    2779                 :      366559 : get_vcall_index (tree fn, tree type)
    2780                 :             : {
    2781                 :      366559 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2782                 :      366559 :   tree_pair_p p;
    2783                 :      366559 :   unsigned ix;
    2784                 :             : 
    2785                 :      372506 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2786                 :     1114146 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2787                 :      378148 :         || same_signature_p (fn, p->purpose))
    2788                 :      366559 :       return p->value;
    2789                 :             : 
    2790                 :             :   /* There should always be an appropriate index.  */
    2791                 :           0 :   gcc_unreachable ();
    2792                 :             : }
    2793                 :             : 
    2794                 :             : /* Given a DECL_VINDEX of a virtual function found in BINFO, return the final
    2795                 :             :    overrider at that index in the vtable.  This should only be used when we
    2796                 :             :    know that BINFO is correct for the dynamic type of the object.  */
    2797                 :             : 
    2798                 :             : tree
    2799                 :         801 : lookup_vfn_in_binfo (tree idx, tree binfo)
    2800                 :             : {
    2801                 :         801 :   int ix = tree_to_shwi (idx);
    2802                 :         801 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
    2803                 :             :     ix /= MAX (TARGET_VTABLE_USES_DESCRIPTORS, 1);
    2804                 :         978 :   while (BINFO_PRIMARY_P (binfo))
    2805                 :             :     /* BINFO_VIRTUALS in a primary base isn't accurate, find the derived
    2806                 :             :        class that actually owns the vtable.  */
    2807                 :         177 :     binfo = BINFO_INHERITANCE_CHAIN (binfo);
    2808                 :         801 :   tree virtuals = BINFO_VIRTUALS (binfo);
    2809                 :         801 :   return TREE_VALUE (chain_index (ix, virtuals));
    2810                 :             : }
    2811                 :             : 
    2812                 :             : /* Update an entry in the vtable for BINFO, which is in the hierarchy
    2813                 :             :    dominated by T.  FN is the old function; VIRTUALS points to the
    2814                 :             :    corresponding position in the new BINFO_VIRTUALS list.  IX is the index
    2815                 :             :    of that entry in the list.  */
    2816                 :             : 
    2817                 :             : static void
    2818                 :     6997958 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2819                 :             :                             unsigned ix)
    2820                 :             : {
    2821                 :     6997958 :   tree b;
    2822                 :     6997958 :   tree overrider;
    2823                 :     6997958 :   tree delta;
    2824                 :     6997958 :   tree virtual_base;
    2825                 :     6997958 :   tree first_defn;
    2826                 :     6997958 :   tree overrider_fn, overrider_target;
    2827                 :     6997958 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2828                 :     6997958 :   tree over_return, base_return;
    2829                 :     6997958 :   bool lost = false;
    2830                 :             : 
    2831                 :             :   /* Find the nearest primary base (possibly binfo itself) which defines
    2832                 :             :      this function; this is the class the caller will convert to when
    2833                 :             :      calling FN through BINFO.  */
    2834                 :     8965139 :   for (b = binfo; ; b = get_primary_binfo (b))
    2835                 :             :     {
    2836                 :     8965139 :       gcc_assert (b);
    2837                 :     8965139 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2838                 :             :         break;
    2839                 :             : 
    2840                 :             :       /* The nearest definition is from a lost primary.  */
    2841                 :     1967181 :       if (BINFO_LOST_PRIMARY_P (b))
    2842                 :         412 :         lost = true;
    2843                 :             :     }
    2844                 :     6997958 :   first_defn = b;
    2845                 :             : 
    2846                 :             :   /* Find the final overrider.  */
    2847                 :     6997958 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2848                 :     6997958 :   if (overrider == error_mark_node)
    2849                 :             :     {
    2850                 :           9 :       error ("no unique final overrider for %qD in %qT", target_fn, t);
    2851                 :           9 :       return;
    2852                 :             :     }
    2853                 :     6997949 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2854                 :             : 
    2855                 :             :   /* Check for adjusting covariant return types.  */
    2856                 :     6997949 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2857                 :     6997949 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2858                 :             : 
    2859                 :     6997949 :   if (INDIRECT_TYPE_P (over_return)
    2860                 :      632318 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2861                 :      632309 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2862                 :       43105 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2863                 :             :       /* If the overrider is invalid, don't even try.  */
    2864                 :     7041048 :       && !DECL_INVALID_OVERRIDER_P (overrider_target))
    2865                 :             :     {
    2866                 :             :       /* If FN is a covariant thunk, we must figure out the adjustment
    2867                 :             :          to the final base FN was converting to. As OVERRIDER_TARGET might
    2868                 :             :          also be converting to the return type of FN, we have to
    2869                 :             :          combine the two conversions here.  */
    2870                 :       43066 :       tree fixed_offset, virtual_offset;
    2871                 :             : 
    2872                 :       43066 :       over_return = TREE_TYPE (over_return);
    2873                 :       43066 :       base_return = TREE_TYPE (base_return);
    2874                 :             : 
    2875                 :       43066 :       if (DECL_THUNK_P (fn))
    2876                 :             :         {
    2877                 :          60 :           gcc_assert (DECL_RESULT_THUNK_P (fn));
    2878                 :          60 :           fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn));
    2879                 :          60 :           virtual_offset = THUNK_VIRTUAL_OFFSET (fn);
    2880                 :             :         }
    2881                 :             :       else
    2882                 :             :         fixed_offset = virtual_offset = NULL_TREE;
    2883                 :             : 
    2884                 :          60 :       if (virtual_offset)
    2885                 :             :         /* Find the equivalent binfo within the return type of the
    2886                 :             :            overriding function. We will want the vbase offset from
    2887                 :             :            there.  */
    2888                 :          54 :         virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
    2889                 :             :                                           over_return);
    2890                 :       43012 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2891                 :       43012 :                (over_return, base_return))
    2892                 :             :         {
    2893                 :             :           /* There was no existing virtual thunk (which takes
    2894                 :             :              precedence).  So find the binfo of the base function's
    2895                 :             :              return type within the overriding function's return type.
    2896                 :             :              Fortunately we know the covariancy is valid (it
    2897                 :             :              has already been checked), so we can just iterate along
    2898                 :             :              the binfos, which have been chained in inheritance graph
    2899                 :             :              order.  Of course it is lame that we have to repeat the
    2900                 :             :              search here anyway -- we should really be caching pieces
    2901                 :             :              of the vtable and avoiding this repeated work.  */
    2902                 :         373 :           tree thunk_binfo = NULL_TREE;
    2903                 :         373 :           tree base_binfo = TYPE_BINFO (base_return);
    2904                 :             : 
    2905                 :             :           /* Find the base binfo within the overriding function's
    2906                 :             :              return type.  We will always find a thunk_binfo, except
    2907                 :             :              when the covariancy is invalid (which we will have
    2908                 :             :              already diagnosed).  */
    2909                 :         373 :           if (base_binfo)
    2910                 :         972 :             for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo;
    2911                 :         602 :                  thunk_binfo = TREE_CHAIN (thunk_binfo))
    2912                 :         972 :               if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
    2913                 :             :                                      BINFO_TYPE (base_binfo)))
    2914                 :             :                 break;
    2915                 :         373 :           gcc_assert (thunk_binfo || errorcount);
    2916                 :             : 
    2917                 :             :           /* See if virtual inheritance is involved.  */
    2918                 :         373 :           for (virtual_offset = thunk_binfo;
    2919                 :         653 :                virtual_offset;
    2920                 :         280 :                virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
    2921                 :         525 :             if (BINFO_VIRTUAL_P (virtual_offset))
    2922                 :             :               break;
    2923                 :             : 
    2924                 :         373 :           if (virtual_offset
    2925                 :         498 :               || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
    2926                 :             :             {
    2927                 :         320 :               tree offset = fold_convert (ssizetype, BINFO_OFFSET (thunk_binfo));
    2928                 :             : 
    2929                 :         320 :               if (virtual_offset)
    2930                 :             :                 {
    2931                 :             :                   /* We convert via virtual base.  Adjust the fixed
    2932                 :             :                      offset to be from there.  */
    2933                 :         245 :                   offset = 
    2934                 :         245 :                     size_diffop (offset,
    2935                 :             :                                  fold_convert (ssizetype,
    2936                 :             :                                           BINFO_OFFSET (virtual_offset)));
    2937                 :             :                 }
    2938                 :         320 :               if (fixed_offset)
    2939                 :             :                 /* There was an existing fixed offset, this must be
    2940                 :             :                    from the base just converted to, and the base the
    2941                 :             :                    FN was thunking to.  */
    2942                 :           6 :                 fixed_offset = size_binop (PLUS_EXPR, fixed_offset, offset);
    2943                 :             :               else
    2944                 :             :                 fixed_offset = offset;
    2945                 :             :             }
    2946                 :             :         }
    2947                 :             : 
    2948                 :       43066 :       if (fixed_offset || virtual_offset)
    2949                 :             :         /* Replace the overriding function with a covariant thunk.  We
    2950                 :             :            will emit the overriding function in its own slot as
    2951                 :             :            well.  */
    2952                 :         374 :         overrider_fn = make_thunk (overrider_target, /*this_adjusting=*/0,
    2953                 :             :                                    fixed_offset, virtual_offset);
    2954                 :             :     }
    2955                 :             :   else
    2956                 :     6954883 :     gcc_assert (DECL_INVALID_OVERRIDER_P (overrider_target) ||
    2957                 :             :                 !DECL_THUNK_P (fn));
    2958                 :             : 
    2959                 :             :   /* If we need a covariant thunk, then we may need to adjust first_defn.
    2960                 :             :      The ABI specifies that the thunks emitted with a function are
    2961                 :             :      determined by which bases the function overrides, so we need to be
    2962                 :             :      sure that we're using a thunk for some overridden base; even if we
    2963                 :             :      know that the necessary this adjustment is zero, there may not be an
    2964                 :             :      appropriate zero-this-adjustment thunk for us to use since thunks for
    2965                 :             :      overriding virtual bases always use the vcall offset.
    2966                 :             : 
    2967                 :             :      Furthermore, just choosing any base that overrides this function isn't
    2968                 :             :      quite right, as this slot won't be used for calls through a type that
    2969                 :             :      puts a covariant thunk here.  Calling the function through such a type
    2970                 :             :      will use a different slot, and that slot is the one that determines
    2971                 :             :      the thunk emitted for that base.
    2972                 :             : 
    2973                 :             :      So, keep looking until we find the base that we're really overriding
    2974                 :             :      in this slot: the nearest primary base that doesn't use a covariant
    2975                 :             :      thunk in this slot.  */
    2976                 :     6997949 :   if (overrider_target != overrider_fn)
    2977                 :             :     {
    2978                 :         374 :       if (BINFO_TYPE (b) == DECL_CONTEXT (overrider_target))
    2979                 :             :         /* We already know that the overrider needs a covariant thunk.  */
    2980                 :         132 :         b = get_primary_binfo (b);
    2981                 :          30 :       for (; ; b = get_primary_binfo (b))
    2982                 :             :         {
    2983                 :         404 :           tree main_binfo = TYPE_BINFO (BINFO_TYPE (b));
    2984                 :         404 :           tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo));
    2985                 :         404 :           if (!DECL_THUNK_P (TREE_VALUE (bv)))
    2986                 :             :             break;
    2987                 :          30 :           if (BINFO_LOST_PRIMARY_P (b))
    2988                 :           6 :             lost = true;
    2989                 :          30 :         }
    2990                 :             :       first_defn = b;
    2991                 :             :     }
    2992                 :             : 
    2993                 :             :   /* Assume that we will produce a thunk that convert all the way to
    2994                 :             :      the final overrider, and not to an intermediate virtual base.  */
    2995                 :     6997949 :   virtual_base = NULL_TREE;
    2996                 :             : 
    2997                 :             :   /* See if we can convert to an intermediate virtual base first, and then
    2998                 :             :      use the vcall offset located there to finish the conversion.  */
    2999                 :     7198853 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    3000                 :             :     {
    3001                 :             :       /* If we find the final overrider, then we can stop
    3002                 :             :          walking.  */
    3003                 :     7198853 :       if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
    3004                 :             :                              BINFO_TYPE (TREE_VALUE (overrider))))
    3005                 :             :         break;
    3006                 :             : 
    3007                 :             :       /* If we find a virtual base, and we haven't yet found the
    3008                 :             :          overrider, then there is a virtual base between the
    3009                 :             :          declaring base (first_defn) and the final overrider.  */
    3010                 :      567463 :       if (BINFO_VIRTUAL_P (b))
    3011                 :             :         {
    3012                 :             :           virtual_base = b;
    3013                 :             :           break;
    3014                 :             :         }
    3015                 :             :     }
    3016                 :             : 
    3017                 :             :   /* Compute the constant adjustment to the `this' pointer.  The
    3018                 :             :      `this' pointer, when this function is called, will point at BINFO
    3019                 :             :      (or one of its primary bases, which are at the same offset).  */
    3020                 :     6997949 :   if (virtual_base)
    3021                 :             :     /* The `this' pointer needs to be adjusted from the declaration to
    3022                 :             :        the nearest virtual base.  */
    3023                 :     1099677 :     delta = size_diffop_loc (input_location,
    3024                 :      366559 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    3025                 :      366559 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    3026                 :     6631390 :   else if (lost)
    3027                 :             :     /* If the nearest definition is in a lost primary, we don't need an
    3028                 :             :        entry in our vtable.  Except possibly in a constructor vtable,
    3029                 :             :        if we happen to get our primary back.  In that case, the offset
    3030                 :             :        will be zero, as it will be a primary base.  */
    3031                 :         367 :     delta = size_zero_node;
    3032                 :             :   else
    3033                 :             :     /* The `this' pointer needs to be adjusted from pointing to
    3034                 :             :        BINFO to pointing at the base where the final overrider
    3035                 :             :        appears.  */
    3036                 :    19893069 :     delta = size_diffop_loc (input_location,
    3037                 :     6631023 :                          fold_convert (ssizetype,
    3038                 :             :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    3039                 :     6631023 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    3040                 :             : 
    3041                 :     6997949 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    3042                 :             : 
    3043                 :     6997949 :   if (virtual_base)
    3044                 :      733118 :     BV_VCALL_INDEX (*virtuals)
    3045                 :      733118 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    3046                 :             :   else
    3047                 :     6631390 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    3048                 :             : 
    3049                 :     6997949 :   BV_LOST_PRIMARY (*virtuals) = lost;
    3050                 :             : }
    3051                 :             : 
    3052                 :             : /* Called from modify_all_vtables via dfs_walk.  */
    3053                 :             : 
    3054                 :             : static tree
    3055                 :    39264603 : dfs_modify_vtables (tree binfo, void* data)
    3056                 :             : {
    3057                 :    39264603 :   tree t = (tree) data;
    3058                 :    39264603 :   tree virtuals;
    3059                 :    39264603 :   tree old_virtuals;
    3060                 :    39264603 :   unsigned ix;
    3061                 :             : 
    3062                 :    39264603 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3063                 :             :     /* A base without a vtable needs no modification, and its bases
    3064                 :             :        are uninteresting.  */
    3065                 :             :     return dfs_skip_bases;
    3066                 :             : 
    3067                 :     4299917 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    3068                 :     4299917 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    3069                 :             :     /* Don't do the primary vtable, if it's new.  */
    3070                 :             :     return NULL_TREE;
    3071                 :             : 
    3072                 :     4062475 :   if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
    3073                 :             :     /* There's no need to modify the vtable for a non-virtual primary
    3074                 :             :        base; we're not going to use that vtable anyhow.  We do still
    3075                 :             :        need to do this for virtual primary bases, as they could become
    3076                 :             :        non-primary in a construction vtable.  */
    3077                 :             :     return NULL_TREE;
    3078                 :             : 
    3079                 :     1649814 :   make_new_vtable (t, binfo);
    3080                 :             : 
    3081                 :             :   /* Now, go through each of the virtual functions in the virtual
    3082                 :             :      function table for BINFO.  Find the final overrider, and update
    3083                 :             :      the BINFO_VIRTUALS list appropriately.  */
    3084                 :     1649814 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    3085                 :     1649814 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    3086                 :     8647772 :        virtuals;
    3087                 :     6997958 :        ix++, virtuals = TREE_CHAIN (virtuals),
    3088                 :     6997958 :          old_virtuals = TREE_CHAIN (old_virtuals))
    3089                 :     6997958 :     update_vtable_entry_for_fn (t,
    3090                 :             :                                 binfo,
    3091                 :     6997958 :                                 BV_FN (old_virtuals),
    3092                 :             :                                 &virtuals, ix);
    3093                 :             : 
    3094                 :             :   return NULL_TREE;
    3095                 :             : }
    3096                 :             : 
    3097                 :             : /* Update all of the primary and secondary vtables for T.  Create new
    3098                 :             :    vtables as required, and initialize their RTTI information.  Each
    3099                 :             :    of the functions in VIRTUALS is declared in T and may override a
    3100                 :             :    virtual function from a base class; find and modify the appropriate
    3101                 :             :    entries to point to the overriding functions.  Returns a list, in
    3102                 :             :    declaration order, of the virtual functions that are declared in T,
    3103                 :             :    but do not appear in the primary base class vtable, and which
    3104                 :             :    should therefore be appended to the end of the vtable for T.  */
    3105                 :             : 
    3106                 :             : static tree
    3107                 :    36027736 : modify_all_vtables (tree t, tree virtuals)
    3108                 :             : {
    3109                 :    36027736 :   tree binfo = TYPE_BINFO (t);
    3110                 :    36027736 :   tree *fnsp;
    3111                 :             : 
    3112                 :             :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    3113                 :    36027736 :   if (TYPE_CONTAINS_VPTR_P (t))
    3114                 :     1628431 :     get_vtable_decl (t, false);
    3115                 :             : 
    3116                 :             :   /* Update all of the vtables.  */
    3117                 :    36027736 :   dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
    3118                 :             : 
    3119                 :             :   /* Add virtual functions not already in our primary vtable. These
    3120                 :             :      will be both those introduced by this class, and those overridden
    3121                 :             :      from secondary bases.  It does not include virtuals merely
    3122                 :             :      inherited from secondary bases.  */
    3123                 :    43544401 :   for (fnsp = &virtuals; *fnsp; )
    3124                 :             :     {
    3125                 :     7516665 :       tree fn = TREE_VALUE (*fnsp);
    3126                 :             : 
    3127                 :     7516665 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    3128                 :    12139439 :           || DECL_VINDEX (fn) == error_mark_node)
    3129                 :             :         {
    3130                 :             :           /* We don't need to adjust the `this' pointer when
    3131                 :             :              calling this function.  */
    3132                 :     2893891 :           BV_DELTA (*fnsp) = integer_zero_node;
    3133                 :     2893891 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    3134                 :             : 
    3135                 :             :           /* This is a function not already in our vtable.  Keep it.  */
    3136                 :     2893891 :           fnsp = &TREE_CHAIN (*fnsp);
    3137                 :             :         }
    3138                 :             :       else
    3139                 :             :         /* We've already got an entry for this function.  Skip it.  */
    3140                 :     4622774 :         *fnsp = TREE_CHAIN (*fnsp);
    3141                 :             :     }
    3142                 :             : 
    3143                 :    36027736 :   return virtuals;
    3144                 :             : }
    3145                 :             : 
    3146                 :             : /* Get the base virtual function declarations in T that have the
    3147                 :             :    indicated NAME.  */
    3148                 :             : 
    3149                 :             : static void
    3150                 :      221093 : get_basefndecls (tree name, tree t, vec<tree> *base_fndecls)
    3151                 :             : {
    3152                 :      221093 :   bool found_decls = false;
    3153                 :             : 
    3154                 :             :   /* Find virtual functions in T with the indicated NAME.  */
    3155                 :      301951 :   for (tree method : ovl_range (get_class_binding (t, name)))
    3156                 :             :     {
    3157                 :       59486 :       if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method))
    3158                 :             :         {
    3159                 :        6706 :           base_fndecls->safe_push (method);
    3160                 :        6706 :           found_decls = true;
    3161                 :             :         }
    3162                 :             :     }
    3163                 :             : 
    3164                 :      221093 :   if (found_decls)
    3165                 :             :     return;
    3166                 :             : 
    3167                 :      214660 :   int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
    3168                 :      258000 :   for (int i = 0; i < n_baseclasses; i++)
    3169                 :             :     {
    3170                 :       43340 :       tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
    3171                 :       43340 :       get_basefndecls (name, basetype, base_fndecls);
    3172                 :             :     }
    3173                 :             : }
    3174                 :             : 
    3175                 :             : /* If this method overrides a virtual method from a base, then mark
    3176                 :             :    this member function as being virtual as well.  Do 'final' and
    3177                 :             :    'override' checks too.  */
    3178                 :             : 
    3179                 :             : void
    3180                 :   118493091 : check_for_override (tree decl, tree ctype)
    3181                 :             : {
    3182                 :   118493091 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    3183                 :             :     /* In [temp.mem] we have:
    3184                 :             : 
    3185                 :             :          A specialization of a member function template does not
    3186                 :             :          override a virtual function from a base class.  */
    3187                 :             :     return;
    3188                 :             : 
    3189                 :             :   /* IDENTIFIER_VIRTUAL_P indicates whether the name has ever been
    3190                 :             :      used for a vfunc.  That avoids the expensive look_for_overrides
    3191                 :             :      call that when we know there's nothing to find.  As conversion
    3192                 :             :      operators for the same type can have distinct identifiers, we
    3193                 :             :      cannot optimize those in that way.  */
    3194                 :    97853386 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    3195                 :    86147894 :        || DECL_CONV_FN_P (decl))
    3196                 :    12680385 :       && look_for_overrides (ctype, decl)
    3197                 :             :       /* Check staticness after we've checked if we 'override'.  */
    3198                 :   101161563 :       && !DECL_STATIC_FUNCTION_P (decl))
    3199                 :             :     {
    3200                 :             :       /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
    3201                 :             :          the error_mark_node so that we know it is an overriding
    3202                 :             :          function.  */
    3203                 :     3308171 :       DECL_VINDEX (decl) = decl;
    3204                 :             : 
    3205                 :     3308171 :       if (warn_override
    3206                 :           6 :           && !DECL_OVERRIDE_P (decl)
    3207                 :           5 :           && !DECL_FINAL_P (decl)
    3208                 :     3308175 :           && !DECL_DESTRUCTOR_P (decl))
    3209                 :           3 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    3210                 :             :                     "%qD can be marked override", decl);
    3211                 :             :     }
    3212                 :    94545215 :   else if (DECL_OVERRIDE_P (decl))
    3213                 :          20 :     error ("%q+#D marked %<override%>, but does not override", decl);
    3214                 :             : 
    3215                 :    97853386 :   if (DECL_VIRTUAL_P (decl))
    3216                 :             :     {
    3217                 :             :       /* Remember this identifier is virtual name.  */
    3218                 :     5937785 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    3219                 :             : 
    3220                 :     5937785 :       if (!DECL_VINDEX (decl))
    3221                 :             :         /* It's a new vfunc.  */
    3222                 :     2629630 :         DECL_VINDEX (decl) = error_mark_node;
    3223                 :             : 
    3224                 :     5937785 :       if (DECL_DESTRUCTOR_P (decl))
    3225                 :     1578852 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    3226                 :             :     }
    3227                 :    91915601 :   else if (DECL_FINAL_P (decl))
    3228                 :          19 :     error ("%q+#D marked %<final%>, but is not virtual", decl);
    3229                 :             : }
    3230                 :             : 
    3231                 :             : /* Warn about hidden virtual functions that are not overridden in t.
    3232                 :             :    We know that constructors and destructors don't apply.  */
    3233                 :             : 
    3234                 :             : static void
    3235                 :      346297 : warn_hidden (tree t)
    3236                 :             : {
    3237                 :      346297 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    3238                 :     1850792 :     for (unsigned ix = member_vec->length (); ix--;)
    3239                 :             :       {
    3240                 :     1727703 :         tree fns = (*member_vec)[ix];
    3241                 :             : 
    3242                 :     1727703 :         if (!OVL_P (fns))
    3243                 :     1721273 :           continue;
    3244                 :             : 
    3245                 :      954412 :         tree name = OVL_NAME (fns);
    3246                 :      954412 :         auto_vec<tree, 20> base_fndecls;
    3247                 :      954412 :         tree base_binfo;
    3248                 :      954412 :         tree binfo;
    3249                 :      954412 :         unsigned j;
    3250                 :             : 
    3251                 :      954412 :         if (IDENTIFIER_CDTOR_P (name))
    3252                 :      322657 :           continue;
    3253                 :             : 
    3254                 :             :         /* Iterate through all of the base classes looking for possibly
    3255                 :             :            hidden functions.  */
    3256                 :      809508 :         for (binfo = TYPE_BINFO (t), j = 0;
    3257                 :      809508 :              BINFO_BASE_ITERATE (binfo, j, base_binfo); j++)
    3258                 :             :           {
    3259                 :      177753 :             tree basetype = BINFO_TYPE (base_binfo);
    3260                 :      177753 :             get_basefndecls (name, basetype, &base_fndecls);
    3261                 :             :           }
    3262                 :             : 
    3263                 :             :         /* If there are no functions to hide, continue.  */
    3264                 :      631755 :         if (base_fndecls.is_empty ())
    3265                 :      625325 :           continue;
    3266                 :             : 
    3267                 :             :         /* Remove any overridden functions.  */
    3268                 :        6430 :         bool seen_non_override = false;
    3269                 :       13447 :         for (tree fndecl : ovl_range (fns))
    3270                 :             :           {
    3271                 :        6722 :             bool any_override = false;
    3272                 :        6722 :             if (TREE_CODE (fndecl) == FUNCTION_DECL
    3273                 :        6722 :                 && DECL_VINDEX (fndecl))
    3274                 :             :               {
    3275                 :             :                 /* If the method from the base class has the same
    3276                 :             :                    signature as the method from the derived class, it
    3277                 :             :                    has been overridden.  Note that we can't move on
    3278                 :             :                    after finding one match: fndecl might override
    3279                 :             :                    multiple base fns.  */
    3280                 :       27818 :                 for (size_t k = 0; k < base_fndecls.length (); k++)
    3281                 :        7199 :                   if (base_fndecls[k]
    3282                 :        7199 :                       && same_signature_p (fndecl, base_fndecls[k]))
    3283                 :             :                     {
    3284                 :        6626 :                       base_fndecls[k] = NULL_TREE;
    3285                 :        6626 :                       any_override = true;
    3286                 :             :                     }
    3287                 :             :               }
    3288                 :        6710 :             if (!any_override)
    3289                 :             :               seen_non_override = true;
    3290                 :             :           }
    3291                 :             : 
    3292                 :        6430 :         if (!seen_non_override && warn_overloaded_virtual == 1)
    3293                 :             :           /* All the derived fns override base virtuals.  */
    3294                 :        6319 :           return;
    3295                 :             : 
    3296                 :             :         /* Now give a warning for all base functions without overriders,
    3297                 :             :            as they are hidden.  */
    3298                 :         453 :         for (tree base_fndecl : base_fndecls)
    3299                 :         120 :           if (base_fndecl)
    3300                 :             :             {
    3301                 :          23 :               auto_diagnostic_group d;
    3302                 :             :               /* Here we know it is a hider, and no overrider exists.  */
    3303                 :          23 :               if (warning_at (location_of (base_fndecl),
    3304                 :             :                               OPT_Woverloaded_virtual_,
    3305                 :             :                               "%qD was hidden", base_fndecl))
    3306                 :          18 :                 inform (location_of (fns), "  by %qD", fns);
    3307                 :          23 :             }
    3308                 :      954412 :       }
    3309                 :             : }
    3310                 :             : 
    3311                 :             : /* Recursive helper for finish_struct_anon.  */
    3312                 :             : 
    3313                 :             : static void
    3314                 :      144382 : finish_struct_anon_r (tree field)
    3315                 :             : {
    3316                 :      700462 :   for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
    3317                 :             :     {
    3318                 :             :       /* We're generally only interested in entities the user
    3319                 :             :          declared, but we also find nested classes by noticing
    3320                 :             :          the TYPE_DECL that we create implicitly.  You're
    3321                 :             :          allowed to put one anonymous union inside another,
    3322                 :             :          though, so we explicitly tolerate that.  We use
    3323                 :             :          TYPE_UNNAMED_P rather than ANON_AGGR_TYPE_P so that
    3324                 :             :          we also allow unnamed types used for defining fields.  */
    3325                 :      556080 :       if (DECL_ARTIFICIAL (elt)
    3326                 :      556080 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    3327                 :       58767 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    3328                 :      163970 :         continue;
    3329                 :             : 
    3330                 :      392110 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    3331                 :      392110 :       TREE_PROTECTED (elt) = TREE_PROTECTED (field);
    3332                 :             : 
    3333                 :             :       /* Recurse into the anonymous aggregates to correctly handle
    3334                 :             :          access control (c++/24926):
    3335                 :             : 
    3336                 :             :          class A {
    3337                 :             :            union {
    3338                 :             :              union {
    3339                 :             :                int i;
    3340                 :             :              };
    3341                 :             :            };
    3342                 :             :          };
    3343                 :             : 
    3344                 :             :          int j=A().i;  */
    3345                 :      392110 :       if (DECL_NAME (elt) == NULL_TREE
    3346                 :      392110 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    3347                 :       18896 :         finish_struct_anon_r (elt);
    3348                 :             :     }
    3349                 :      144382 : }
    3350                 :             : 
    3351                 :             : /* Fix up any anonymous union/struct members of T.  */
    3352                 :             : 
    3353                 :             : static void
    3354                 :    36027736 : finish_struct_anon (tree t)
    3355                 :             : {
    3356                 :   254117928 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3357                 :             :     {
    3358                 :   218090192 :       if (TREE_STATIC (field))
    3359                 :    10041851 :         continue;
    3360                 :   208048341 :       if (TREE_CODE (field) != FIELD_DECL)
    3361                 :   193381459 :         continue;
    3362                 :             : 
    3363                 :    14666882 :       if (DECL_NAME (field) == NULL_TREE
    3364                 :    14666882 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3365                 :      125486 :         finish_struct_anon_r (field);
    3366                 :             :     }
    3367                 :    36027736 : }
    3368                 :             : 
    3369                 :             : /* Add T to CLASSTYPE_DECL_LIST of current_class_type which
    3370                 :             :    will be used later during class template instantiation.
    3371                 :             :    When FRIEND_P is zero, T can be a static member data (VAR_DECL),
    3372                 :             :    a non-static member data (FIELD_DECL), a member function
    3373                 :             :    (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE),
    3374                 :             :    a typedef (TYPE_DECL) or a member class template (TEMPLATE_DECL)
    3375                 :             :    When FRIEND_P is nonzero, T is either a friend class
    3376                 :             :    (RECORD_TYPE, TEMPLATE_DECL) or a friend function
    3377                 :             :    (FUNCTION_DECL, TEMPLATE_DECL).  */
    3378                 :             : 
    3379                 :             : void
    3380                 :   356221170 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3381                 :             : {
    3382                 :   356221170 :   if (CLASSTYPE_TEMPLATE_INFO (type)
    3383                 :   356221170 :       && TREE_CODE (t) != CONST_DECL)
    3384                 :             :     {
    3385                 :   314404070 :       tree purpose = friend_p ? NULL_TREE : type;
    3386                 :             : 
    3387                 :   314404070 :       CLASSTYPE_DECL_LIST (type)
    3388                 :   628808140 :         = tree_cons (purpose, t, CLASSTYPE_DECL_LIST (type));
    3389                 :             :     }
    3390                 :   356221170 : }
    3391                 :             : 
    3392                 :             : /* This function is called from declare_virt_assop_and_dtor via
    3393                 :             :    dfs_walk_all.
    3394                 :             : 
    3395                 :             :    DATA is a type that direcly or indirectly inherits the base
    3396                 :             :    represented by BINFO.  If BINFO contains a virtual assignment [copy
    3397                 :             :    assignment or move assigment] operator or a virtual constructor,
    3398                 :             :    declare that function in DATA if it hasn't been already declared.  */
    3399                 :             : 
    3400                 :             : static tree
    3401                 :     3331102 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3402                 :             : {
    3403                 :     3331102 :   tree bv, fn, t = (tree)data;
    3404                 :     3331102 :   tree opname = assign_op_identifier;
    3405                 :             : 
    3406                 :     3331102 :   gcc_assert (t && CLASS_TYPE_P (t));
    3407                 :     3331102 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3408                 :             : 
    3409                 :     3331102 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3410                 :             :     /* A base without a vtable needs no modification, and its bases
    3411                 :             :        are uninteresting.  */
    3412                 :             :     return dfs_skip_bases;
    3413                 :             : 
    3414                 :     2798697 :   if (BINFO_PRIMARY_P (binfo))
    3415                 :             :     /* If this is a primary base, then we have already looked at the
    3416                 :             :        virtual functions of its vtable.  */
    3417                 :             :     return NULL_TREE;
    3418                 :             : 
    3419                 :    11131439 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3420                 :             :     {
    3421                 :     8332742 :       fn = BV_FN (bv);
    3422                 :             : 
    3423                 :     8332742 :       if (DECL_NAME (fn) == opname)
    3424                 :             :         {
    3425                 :          21 :           if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
    3426                 :          21 :             lazily_declare_fn (sfk_copy_assignment, t);
    3427                 :          21 :           if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    3428                 :          14 :             lazily_declare_fn (sfk_move_assignment, t);
    3429                 :             :         }
    3430                 :     8332721 :       else if (DECL_DESTRUCTOR_P (fn)
    3431                 :     8332721 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3432                 :      165677 :         lazily_declare_fn (sfk_destructor, t);
    3433                 :             :     }
    3434                 :             : 
    3435                 :             :   return NULL_TREE;
    3436                 :             : }
    3437                 :             : 
    3438                 :             : /* If the class type T has a direct or indirect base that contains a
    3439                 :             :    virtual assignment operator or a virtual destructor, declare that
    3440                 :             :    function in T if it hasn't been already declared.  */
    3441                 :             : 
    3442                 :             : static void
    3443                 :    36027736 : declare_virt_assop_and_dtor (tree t)
    3444                 :             : {
    3445                 :    36027736 :   if (!(TYPE_POLYMORPHIC_P (t)
    3446                 :     1626071 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3447                 :      613042 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3448                 :      613042 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3449                 :             :     return;
    3450                 :             : 
    3451                 :     1066384 :   dfs_walk_all (TYPE_BINFO (t),
    3452                 :             :                 dfs_declare_virt_assop_and_dtor,
    3453                 :             :                 NULL, t);
    3454                 :             : }
    3455                 :             : 
    3456                 :             : /* Declare the inheriting constructor for class T inherited from base
    3457                 :             :    constructor CTOR with the parameter array PARMS of size NPARMS.  */
    3458                 :             : 
    3459                 :             : static void
    3460                 :          90 : one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms)
    3461                 :             : {
    3462                 :          90 :   gcc_assert (TYPE_MAIN_VARIANT (t) == t);
    3463                 :             : 
    3464                 :             :   /* We don't declare an inheriting ctor that would be a default,
    3465                 :             :      copy or move ctor for derived or base.  */
    3466                 :          90 :   if (nparms == 0)
    3467                 :             :     return;
    3468                 :          90 :   if (nparms == 1
    3469                 :          87 :       && TYPE_REF_P (parms[0]))
    3470                 :             :     {
    3471                 :          54 :       tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
    3472                 :          54 :       if (parm == t || parm == DECL_CONTEXT (ctor))
    3473                 :             :         return;
    3474                 :             :     }
    3475                 :             : 
    3476                 :          36 :   tree parmlist = void_list_node;
    3477                 :          75 :   for (int i = nparms - 1; i >= 0; i--)
    3478                 :          39 :     parmlist = tree_cons (NULL_TREE, parms[i], parmlist);
    3479                 :          36 :   tree fn = implicitly_declare_fn (sfk_inheriting_constructor,
    3480                 :             :                                    t, false, ctor, parmlist);
    3481                 :             : 
    3482                 :          36 :   if (add_method (t, fn, false))
    3483                 :             :     {
    3484                 :          27 :       DECL_CHAIN (fn) = TYPE_FIELDS (t);
    3485                 :          27 :       TYPE_FIELDS (t) = fn;
    3486                 :             :     }
    3487                 :             : }
    3488                 :             : 
    3489                 :             : /* Declare all the inheriting constructors for class T inherited from base
    3490                 :             :    constructor CTOR.  */
    3491                 :             : 
    3492                 :             : static void
    3493                 :      237353 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3494                 :             : {
    3495                 :      237353 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3496                 :             : 
    3497                 :      237353 :   if (flag_new_inheriting_ctors)
    3498                 :             :     {
    3499                 :      237263 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3500                 :             :                                     t, /*const*/false, ctor, parms);
    3501                 :      237263 :       add_method (t, ctor, using_decl != NULL_TREE);
    3502                 :      237263 :       return;
    3503                 :             :     }
    3504                 :             : 
    3505                 :          90 :   tree *new_parms = XALLOCAVEC (tree, list_length (parms));
    3506                 :          90 :   int i = 0;
    3507                 :         183 :   for (; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
    3508                 :             :     {
    3509                 :          93 :       if (TREE_PURPOSE (parms))
    3510                 :           0 :         one_inheriting_sig (t, ctor, new_parms, i);
    3511                 :          93 :       new_parms[i++] = TREE_VALUE (parms);
    3512                 :             :     }
    3513                 :          90 :   one_inheriting_sig (t, ctor, new_parms, i);
    3514                 :          90 :   if (parms == NULL_TREE)
    3515                 :             :     {
    3516                 :           3 :       auto_diagnostic_group d;
    3517                 :           3 :       if (warning (OPT_Winherited_variadic_ctor,
    3518                 :             :                    "the ellipsis in %qD is not inherited", ctor))
    3519                 :           3 :         inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor);
    3520                 :           3 :     }
    3521                 :             : }
    3522                 :             : 
    3523                 :             : /* Implicitly declare T().  */
    3524                 :             : 
    3525                 :             : static void
    3526                 :    30279971 : add_implicit_default_ctor (tree t)
    3527                 :             : {
    3528                 :    30279971 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3529                 :    30279971 :   CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3530                 :    30279971 :   if (cxx_dialect >= cxx11)
    3531                 :    30188166 :     TYPE_HAS_CONSTEXPR_CTOR (t)
    3532                 :             :       /* Don't force the declaration to get a hard answer; if the
    3533                 :             :          definition would have made the class non-literal, it will still be
    3534                 :             :          non-literal because of the base or member in question, and that
    3535                 :             :          gives a better diagnostic.  */
    3536                 :    60376332 :       = type_maybe_constexpr_default_constructor (t);
    3537                 :    30279971 : }
    3538                 :             : 
    3539                 :             : /* Create default constructors, assignment operators, and so forth for
    3540                 :             :    the type indicated by T, if they are needed.  CANT_HAVE_CONST_CTOR,
    3541                 :             :    and CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason,
    3542                 :             :    the class cannot have a default constructor, copy constructor
    3543                 :             :    taking a const reference argument, or an assignment operator taking
    3544                 :             :    a const reference, respectively.  */
    3545                 :             : 
    3546                 :             : static void
    3547                 :    36027736 : add_implicitly_declared_members (tree t, tree* access_decls,
    3548                 :             :                                  int cant_have_const_cctor,
    3549                 :             :                                  int cant_have_const_assignment)
    3550                 :             : {
    3551                 :             :   /* Destructor.  */
    3552                 :    36027736 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3553                 :             :     /* In general, we create destructors lazily.  */
    3554                 :    32521753 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3555                 :             : 
    3556                 :    36027736 :   bool move_ok = false;
    3557                 :    35902245 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3558                 :    32420506 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3559                 :    67571694 :       && !classtype_has_move_assign_or_move_ctor_p (t, false))
    3560                 :             :     move_ok = true;
    3561                 :             : 
    3562                 :             :   /* [class.ctor]
    3563                 :             : 
    3564                 :             :      If there is no user-declared constructor for a class, a default
    3565                 :             :      constructor is implicitly declared.  */
    3566                 :    36027736 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3567                 :    30238479 :     add_implicit_default_ctor (t);
    3568                 :             : 
    3569                 :             :   /* [class.ctor]
    3570                 :             : 
    3571                 :             :      If a class definition does not explicitly declare a copy
    3572                 :             :      constructor, one is declared implicitly.  */
    3573                 :    36027736 :   if (! TYPE_HAS_COPY_CTOR (t))
    3574                 :             :     {
    3575                 :    33087088 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3576                 :    33087088 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3577                 :    33087088 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3578                 :    33087088 :       if (move_ok)
    3579                 :    31317164 :         CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
    3580                 :             :     }
    3581                 :             : 
    3582                 :             :   /* If there is no assignment operator, one will be created if and
    3583                 :             :      when it is needed.  For now, just record whether or not the type
    3584                 :             :      of the parameter to the assignment operator will be a const or
    3585                 :             :      non-const reference.  */
    3586                 :    36027736 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3587                 :             :     {
    3588                 :    33211325 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3589                 :    33211325 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3590                 :    33211325 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3591                 :    64167645 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3592                 :    31064867 :         CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
    3593                 :             :     }
    3594                 :             : 
    3595                 :             :   /* We can't be lazy about declaring functions that might override
    3596                 :             :      a virtual function from a base class.  */
    3597                 :    36027736 :   declare_virt_assop_and_dtor (t);
    3598                 :             : 
    3599                 :             :   /* If the class definition does not explicitly declare an == operator
    3600                 :             :      function, but declares a defaulted three-way comparison operator function,
    3601                 :             :      an == operator function is declared implicitly.  */
    3602                 :    36027736 :   if (!classtype_has_op (t, EQ_EXPR))
    3603                 :    35208433 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3604                 :             :       {
    3605                 :         185 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3606                 :             :                                          NULL_TREE);
    3607                 :         185 :         bool is_friend = DECL_CONTEXT (space) != t;
    3608                 :         185 :         if (is_friend)
    3609                 :          23 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3610                 :             :                      NO_SPECIAL, true);
    3611                 :             :         else
    3612                 :             :           {
    3613                 :         162 :             add_method (t, eq, false);
    3614                 :         162 :             DECL_CHAIN (eq) = TYPE_FIELDS (t);
    3615                 :         162 :             TYPE_FIELDS (t) = eq;
    3616                 :             :           }
    3617                 :         185 :         maybe_add_class_template_decl_list (t, eq, is_friend);
    3618                 :             :       }
    3619                 :             : 
    3620                 :    37930545 :   while (*access_decls)
    3621                 :             :     {
    3622                 :     1902809 :       tree using_decl = TREE_VALUE (*access_decls);
    3623                 :     1902809 :       tree decl = USING_DECL_DECLS (using_decl);
    3624                 :     1902809 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3625                 :             :         {
    3626                 :             :           /* declare, then remove the decl */
    3627                 :       48937 :           tree ctor_list = decl;
    3628                 :       48937 :           location_t loc = input_location;
    3629                 :       48937 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3630                 :      475594 :           for (tree fn : ovl_range (ctor_list))
    3631                 :             :             {
    3632                 :      237353 :               if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t) && default_ctor_p (fn))
    3633                 :             :                 /* CWG2799: Inheriting a default constructor gives us a default
    3634                 :             :                    constructor, not just an inherited constructor.  */
    3635                 :       41492 :                 add_implicit_default_ctor (t);
    3636                 :      237353 :               one_inherited_ctor (fn, t, using_decl);
    3637                 :             :             }
    3638                 :       48937 :           *access_decls = TREE_CHAIN (*access_decls);
    3639                 :       48937 :           input_location = loc;
    3640                 :             :         }
    3641                 :             :       else
    3642                 :     1853872 :         access_decls = &TREE_CHAIN (*access_decls);
    3643                 :             :     }
    3644                 :    36027736 : }
    3645                 :             : 
    3646                 :             : /* Cache of enum_min_precision values.  */
    3647                 :             : static GTY((deletable)) hash_map<tree, int> *enum_to_min_precision;
    3648                 :             : 
    3649                 :             : /* Return the minimum precision of a bit-field needed to store all
    3650                 :             :    enumerators of ENUMERAL_TYPE TYPE.  */
    3651                 :             : 
    3652                 :             : static int
    3653                 :       30805 : enum_min_precision (tree type)
    3654                 :             : {
    3655                 :       30805 :   type = TYPE_MAIN_VARIANT (type);
    3656                 :             :   /* For unscoped enums without fixed underlying type and without mode
    3657                 :             :      attribute we can just use precision of the underlying type.  */
    3658                 :       30805 :   if (UNSCOPED_ENUM_P (type)
    3659                 :       30457 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3660                 :       61227 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3661                 :       30410 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3662                 :             : 
    3663                 :         395 :   if (enum_to_min_precision == NULL)
    3664                 :          81 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3665                 :             : 
    3666                 :         395 :   bool existed;
    3667                 :         395 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3668                 :         395 :   if (existed)
    3669                 :         299 :     return prec;
    3670                 :             : 
    3671                 :          96 :   tree minnode, maxnode;
    3672                 :          96 :   if (TYPE_VALUES (type))
    3673                 :             :     {
    3674                 :             :       minnode = maxnode = NULL_TREE;
    3675                 :         383 :       for (tree values = TYPE_VALUES (type);
    3676                 :         476 :            values; values = TREE_CHAIN (values))
    3677                 :             :         {
    3678                 :         383 :           tree decl = TREE_VALUE (values);
    3679                 :         383 :           tree value = DECL_INITIAL (decl);
    3680                 :         383 :           if (value == error_mark_node)
    3681                 :           0 :             value = integer_zero_node;
    3682                 :         383 :           if (!minnode)
    3683                 :             :             minnode = maxnode = value;
    3684                 :         290 :           else if (tree_int_cst_lt (maxnode, value))
    3685                 :             :             maxnode = value;
    3686                 :           0 :           else if (tree_int_cst_lt (value, minnode))
    3687                 :           0 :             minnode = value;
    3688                 :             :         }
    3689                 :             :     }
    3690                 :             :   else
    3691                 :           3 :     minnode = maxnode = integer_zero_node;
    3692                 :             : 
    3693                 :          96 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3694                 :          96 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3695                 :          96 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3696                 :          96 :   prec = MAX (lowprec, highprec);
    3697                 :          96 :   return prec;
    3698                 :             : }
    3699                 :             : 
    3700                 :             : /* FIELD is a bit-field.  We are finishing the processing for its
    3701                 :             :    enclosing type.  Issue any appropriate messages and set appropriate
    3702                 :             :    flags.  Returns false if an error has been diagnosed.  */
    3703                 :             : 
    3704                 :             : static bool
    3705                 :      382452 : check_bitfield_decl (tree field)
    3706                 :             : {
    3707                 :      382452 :   tree type = TREE_TYPE (field);
    3708                 :      382452 :   tree w;
    3709                 :             : 
    3710                 :             :   /* Extract the declared width of the bitfield, which has been
    3711                 :             :      temporarily stashed in DECL_BIT_FIELD_REPRESENTATIVE by grokbitfield.  */
    3712                 :      382452 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3713                 :      382452 :   gcc_assert (w != NULL_TREE);
    3714                 :             :   /* Remove the bit-field width indicator so that the rest of the
    3715                 :             :      compiler does not treat that value as a qualifier.  */
    3716                 :      382452 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3717                 :             : 
    3718                 :             :   /* Detect invalid bit-field type.  */
    3719                 :      382452 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    3720                 :             :     {
    3721                 :           3 :       error_at (DECL_SOURCE_LOCATION (field),
    3722                 :             :                 "bit-field %q#D with non-integral type %qT", field, type);
    3723                 :           3 :       w = error_mark_node;
    3724                 :             :     }
    3725                 :             :   else
    3726                 :             :     {
    3727                 :      382449 :       location_t loc = input_location;
    3728                 :             :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3729                 :      382449 :       STRIP_NOPS (w);
    3730                 :             : 
    3731                 :             :       /* detect invalid field size.  */
    3732                 :      382449 :       input_location = DECL_SOURCE_LOCATION (field);
    3733                 :      382449 :       w = cxx_constant_value (w);
    3734                 :      382449 :       input_location = loc;
    3735                 :             : 
    3736                 :      382449 :       if (TREE_CODE (w) != INTEGER_CST)
    3737                 :             :         {
    3738                 :          15 :           error ("bit-field %q+D width not an integer constant", field);
    3739                 :          15 :           w = error_mark_node;
    3740                 :             :         }
    3741                 :      382434 :       else if (tree_int_cst_sgn (w) < 0)
    3742                 :             :         {
    3743                 :           0 :           error ("negative width in bit-field %q+D", field);
    3744                 :           0 :           w = error_mark_node;
    3745                 :             :         }
    3746                 :      382434 :       else if (integer_zerop (w) && DECL_NAME (field) != 0)
    3747                 :             :         {
    3748                 :          15 :           error ("zero width for bit-field %q+D", field);
    3749                 :          15 :           w = error_mark_node;
    3750                 :             :         }
    3751                 :      382419 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3752                 :      382419 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3753                 :      350161 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3754                 :      382419 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3755                 :      381985 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3756                 :       32258 :                    && tree_int_cst_lt (TYPE_SIZE (type), w)))
    3757                 :         774 :         warning_at (DECL_SOURCE_LOCATION (field), 0,
    3758                 :             :                     "width of %qD exceeds its type", field);
    3759                 :      381645 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3760                 :             :         {
    3761                 :       30805 :           int prec = enum_min_precision (type);
    3762                 :       30805 :           if (compare_tree_int (w, prec) < 0)
    3763                 :          48 :             warning_at (DECL_SOURCE_LOCATION (field), 0,
    3764                 :             :                         "%qD is too small to hold all values of %q#T",
    3765                 :             :                         field, type);
    3766                 :             :         }
    3767                 :             :     }
    3768                 :             : 
    3769                 :      382452 :   if (w != error_mark_node)
    3770                 :             :     {
    3771                 :      382419 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3772                 :      382419 :       DECL_BIT_FIELD (field) = 1;
    3773                 :      382419 :       return true;
    3774                 :             :     }
    3775                 :             :   else
    3776                 :             :     {
    3777                 :             :       /* Non-bit-fields are aligned for their type.  */
    3778                 :          33 :       DECL_BIT_FIELD (field) = 0;
    3779                 :          33 :       CLEAR_DECL_C_BIT_FIELD (field);
    3780                 :          33 :       return false;
    3781                 :             :     }
    3782                 :             : }
    3783                 :             : 
    3784                 :             : /* FIELD is a non bit-field.  We are finishing the processing for its
    3785                 :             :    enclosing type T.  Issue any appropriate messages and set appropriate
    3786                 :             :    flags.  */
    3787                 :             : 
    3788                 :             : static bool
    3789                 :    15056428 : check_field_decl (tree field,
    3790                 :             :                   tree t,
    3791                 :             :                   int* cant_have_const_ctor,
    3792                 :             :                   int* no_const_asn_ref)
    3793                 :             : {
    3794                 :    15056428 :   tree type = strip_array_types (TREE_TYPE (field));
    3795                 :    15056428 :   bool any_default_members = false;
    3796                 :             : 
    3797                 :             :   /* In C++98 an anonymous union cannot contain any fields which would change
    3798                 :             :      the settings of CANT_HAVE_CONST_CTOR and friends.  */
    3799                 :    15056428 :   if (ANON_UNION_TYPE_P (type) && cxx_dialect < cxx11)
    3800                 :             :     ;
    3801                 :             :   /* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
    3802                 :             :      structs.  So, we recurse through their fields here.  */
    3803                 :    15055244 :   else if (ANON_AGGR_TYPE_P (type))
    3804                 :             :     {
    3805                 :      695628 :       for (tree fields = TYPE_FIELDS (type); fields;
    3806                 :      552447 :            fields = DECL_CHAIN (fields))
    3807                 :      552447 :         if (TREE_CODE (fields) == FIELD_DECL)
    3808                 :      389707 :           any_default_members |= check_field_decl (fields, t,
    3809                 :             :                                                    cant_have_const_ctor,
    3810                 :             :                                                    no_const_asn_ref);
    3811                 :             :     }
    3812                 :             :   /* Check members with class type for constructors, destructors,
    3813                 :             :      etc.  */
    3814                 :    14912063 :   else if (CLASS_TYPE_P (type))
    3815                 :             :     {
    3816                 :             :       /* Never let anything with uninheritable virtuals
    3817                 :             :          make it through without complaint.  */
    3818                 :     2509380 :       abstract_virtuals_error (field, type);
    3819                 :             : 
    3820                 :     2509380 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3821                 :             :         {
    3822                 :        3168 :           static bool warned;
    3823                 :        3168 :           auto_diagnostic_group d;
    3824                 :        3168 :           int oldcount = errorcount;
    3825                 :        3168 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3826                 :           2 :             error ("member %q+#D with constructor not allowed in union",
    3827                 :             :                    field);
    3828                 :        3168 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3829                 :           0 :             error ("member %q+#D with destructor not allowed in union", field);
    3830                 :        3168 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3831                 :           3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3832                 :             :                    field);
    3833                 :        3168 :           if (!warned && errorcount > oldcount)
    3834                 :             :             {
    3835                 :           4 :               inform (DECL_SOURCE_LOCATION (field), "unrestricted unions "
    3836                 :             :                       "only available with %<-std=c++11%> or %<-std=gnu++11%>");
    3837                 :           4 :               warned = true;
    3838                 :             :             }
    3839                 :        3168 :         }
    3840                 :             :       else
    3841                 :             :         {
    3842                 :     2506212 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3843                 :     7518636 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3844                 :     2506212 :             |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3845                 :     2506212 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3846                 :     2506212 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3847                 :     2506212 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3848                 :     5012424 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3849                 :     2506212 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3850                 :     2506212 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3851                 :     2506212 :           TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
    3852                 :     5012424 :           TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3853                 :     2506212 :                                         || TYPE_HAS_COMPLEX_DFLT (type));
    3854                 :             :         }
    3855                 :             : 
    3856                 :     2509380 :       if (TYPE_HAS_COPY_CTOR (type)
    3857                 :     2509380 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3858                 :         122 :         *cant_have_const_ctor = 1;
    3859                 :             : 
    3860                 :     2509380 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3861                 :     2509380 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3862                 :          45 :         *no_const_asn_ref = 1;
    3863                 :             :     }
    3864                 :             : 
    3865                 :    15056428 :   check_abi_tags (t, field);
    3866                 :             : 
    3867                 :    15056428 :   if (DECL_INITIAL (field) != NULL_TREE)
    3868                 :             :     /* `build_class_init_list' does not recognize
    3869                 :             :        non-FIELD_DECLs.  */
    3870                 :      701020 :     any_default_members = true;
    3871                 :             : 
    3872                 :    15056428 :   return any_default_members;
    3873                 :             : }
    3874                 :             : 
    3875                 :             : /* Check the data members (both static and non-static), class-scoped
    3876                 :             :    typedefs, etc., appearing in the declaration of T.  Issue
    3877                 :             :    appropriate diagnostics.  Sets ACCESS_DECLS to a list (in
    3878                 :             :    declaration order) of access declarations; each TREE_VALUE in this
    3879                 :             :    list is a USING_DECL.
    3880                 :             : 
    3881                 :             :    In addition, set the following flags:
    3882                 :             : 
    3883                 :             :      EMPTY_P
    3884                 :             :        The class is empty, i.e., contains no non-static data members.
    3885                 :             : 
    3886                 :             :      CANT_HAVE_CONST_CTOR_P
    3887                 :             :        This class cannot have an implicitly generated copy constructor
    3888                 :             :        taking a const reference.
    3889                 :             : 
    3890                 :             :      CANT_HAVE_CONST_ASN_REF
    3891                 :             :        This class cannot have an implicitly generated assignment
    3892                 :             :        operator taking a const reference.
    3893                 :             : 
    3894                 :             :    All of these flags should be initialized before calling this
    3895                 :             :    function.   */
    3896                 :             : 
    3897                 :             : static void
    3898                 :    36027736 : check_field_decls (tree t, tree *access_decls,
    3899                 :             :                    int *cant_have_const_ctor_p,
    3900                 :             :                    int *no_const_asn_ref_p)
    3901                 :             : {
    3902                 :    36027736 :   int cant_pack = 0;
    3903                 :             : 
    3904                 :             :   /* Assume there are no access declarations.  */
    3905                 :    36027736 :   *access_decls = NULL_TREE;
    3906                 :             :   /* Effective C has things to say about classes with pointer members.  */
    3907                 :    36027736 :   tree pointer_member = NULL_TREE;
    3908                 :             :   /* Default initialized members affect the whole class.  */
    3909                 :    36027736 :   tree default_init_member = NULL_TREE;
    3910                 :             :   /* Lack of any non-static data member of non-volatile literal
    3911                 :             :      type affects a union.  */
    3912                 :    36027736 :   bool found_nv_literal_p = false;
    3913                 :             :   /* Standard layout requires all FIELDS have same access.  */
    3914                 :    36027736 :   int field_access = -1;
    3915                 :             : 
    3916                 :   254117928 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3917                 :             :     {
    3918                 :   218090192 :       tree type = TREE_TYPE (field);
    3919                 :             : 
    3920                 :   218090192 :       switch (TREE_CODE (field))
    3921                 :             :         {
    3922                 :           0 :         default:
    3923                 :           0 :           gcc_unreachable ();
    3924                 :             : 
    3925                 :     1902809 :         case USING_DECL:
    3926                 :             :           /* Save the access declarations for our caller.  */
    3927                 :     1902809 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    3928                 :     1902809 :           break;
    3929                 :             : 
    3930                 :             :         case TYPE_DECL:
    3931                 :             :         case TEMPLATE_DECL:
    3932                 :             :           break;
    3933                 :             : 
    3934                 :             :         case FUNCTION_DECL:
    3935                 :             :           /* FIXME: We should fold in the checking from check_methods.  */
    3936                 :             :           break;
    3937                 :             : 
    3938                 :     1573547 :         case CONST_DECL:
    3939                 :     1573547 :           DECL_NONLOCAL (field) = 1;
    3940                 :     1573547 :           break;
    3941                 :             :           
    3942                 :     9803719 :         case VAR_DECL:
    3943                 :     9803719 :           if (TREE_CODE (t) == UNION_TYPE
    3944                 :          36 :               && cxx_dialect < cxx11)
    3945                 :             :             {
    3946                 :             :               /* [class.union]
    3947                 :             : 
    3948                 :             :                  (C++98) If a union contains a static data member,
    3949                 :             :                  ... the program is ill-formed.  */
    3950                 :           1 :               if (cxx_dialect < cxx11)
    3951                 :           1 :                 error ("in C++98 %q+D may not be static because it is "
    3952                 :             :                        "a member of a union", field);
    3953                 :             :             }
    3954                 :     9803719 :           goto data_member;
    3955                 :             :           
    3956                 :    14666882 :         case FIELD_DECL:
    3957                 :    14666882 :           if (TREE_CODE (t) == UNION_TYPE)
    3958                 :             :             {
    3959                 :             :               /* [class.union]
    3960                 :             : 
    3961                 :             :                  If a union contains ... or a [non-static data] member
    3962                 :             :                  of reference type, the program is ill-formed.  */
    3963                 :      987388 :               if (TYPE_REF_P (type))
    3964                 :          33 :                 error ("non-static data member %q+D in a union may not "
    3965                 :             :                        "have reference type %qT", field, type);
    3966                 :             :             }
    3967                 :             : 
    3968                 :    13679494 :         data_member:
    3969                 :             :           /* Common VAR_DECL & FIELD_DECL processing.  */
    3970                 :    24470601 :           DECL_CONTEXT (field) = t;
    3971                 :    24470601 :           DECL_NONLOCAL (field) = 1;
    3972                 :             : 
    3973                 :             :           /* Template instantiation can cause this.  Perhaps this
    3974                 :             :              should be a specific instantiation check?  */
    3975                 :    24470601 :           if (TREE_CODE (type) == FUNCTION_TYPE)
    3976                 :             :             {
    3977                 :          10 :               error ("data member %q+D invalidly declared function type", field);
    3978                 :          10 :               type = build_pointer_type (type);
    3979                 :          10 :               TREE_TYPE (field) = type;
    3980                 :             :             }
    3981                 :    24470591 :           else if (TREE_CODE (type) == METHOD_TYPE)
    3982                 :             :             {
    3983                 :           0 :               error ("data member %q+D invalidly declared method type", field);
    3984                 :           0 :               type = build_pointer_type (type);
    3985                 :           0 :               TREE_TYPE (field) = type;
    3986                 :             :             }
    3987                 :             : 
    3988                 :             :           break;
    3989                 :             :         }
    3990                 :             : 
    3991                 :   218090192 :       if (TREE_CODE (field) != FIELD_DECL)
    3992                 :   203423310 :         continue;
    3993                 :             : 
    3994                 :    14666882 :       if (type == error_mark_node)
    3995                 :         161 :         continue;
    3996                 :             : 
    3997                 :             :       /* If it is not a union and at least one non-static data member is
    3998                 :             :          non-literal, the whole class becomes non-literal.  Per Core/1453,
    3999                 :             :          volatile non-static data members and base classes are also not allowed.
    4000                 :             :          If it is a union, we might set CLASSTYPE_LITERAL_P after we've seen all
    4001                 :             :          members.
    4002                 :             :          Note: if the type is incomplete we will complain later on.  */
    4003                 :    14666721 :       if (COMPLETE_TYPE_P (type))
    4004                 :             :         {
    4005                 :    14665379 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    4006                 :     1028605 :             CLASSTYPE_LITERAL_P (t) = false;
    4007                 :             :           else
    4008                 :             :             found_nv_literal_p = true;
    4009                 :             :         }
    4010                 :             : 
    4011                 :    14666721 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    4012                 :    13061119 :                                : TREE_PRIVATE (field) ? 2 : 0);
    4013                 :    14666721 :       if (field_access != this_field_access)
    4014                 :             :         {
    4015                 :             :           /* A standard-layout class is a class that:
    4016                 :             : 
    4017                 :             :              ... has the same access control (Clause 11) for all
    4018                 :             :              non-static data members, */
    4019                 :     5589561 :           if (field_access < 0)
    4020                 :             :             field_access = this_field_access;
    4021                 :             :           else
    4022                 :       29765 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4023                 :             : 
    4024                 :             :           /* Aggregates must be public.  */
    4025                 :     5589561 :           if (this_field_access)
    4026                 :     2653666 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    4027                 :             :         }
    4028                 :             : 
    4029                 :             :       /* If this is of reference type, check if it needs an init.  */
    4030                 :    14666721 :       if (TYPE_REF_P (type))
    4031                 :             :         {
    4032                 :      371001 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4033                 :      371001 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4034                 :      371001 :           if (DECL_INITIAL (field) == NULL_TREE)
    4035                 :      370922 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4036                 :      371001 :           if (cxx_dialect < cxx11)
    4037                 :             :             {
    4038                 :             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    4039                 :             :                  aggregate, initialization by a brace-enclosed list) is the
    4040                 :             :                  only way to initialize non-static const and reference
    4041                 :             :                  members.  */
    4042                 :         761 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4043                 :         761 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4044                 :             :             }
    4045                 :             :         }
    4046                 :             : 
    4047                 :    14666721 :       type = strip_array_types (type);
    4048                 :             : 
    4049                 :    14666721 :       if (TYPE_PACKED (t))
    4050                 :             :         {
    4051                 :        1044 :           if (!layout_pod_type_p (type) && !TYPE_PACKED (type))
    4052                 :             :             {
    4053                 :          18 :               warning_at (DECL_SOURCE_LOCATION (field), 0,
    4054                 :             :                           "ignoring packed attribute because of"
    4055                 :             :                           " unpacked non-POD field %q#D", field);
    4056                 :          18 :               cant_pack = 1;
    4057                 :             :             }
    4058                 :        1026 :           else if (DECL_C_BIT_FIELD (field)
    4059                 :        1026 :                    || TYPE_ALIGN (TREE_TYPE (field)) > BITS_PER_UNIT)
    4060                 :         791 :             DECL_PACKED (field) = 1;
    4061                 :             :         }
    4062                 :             : 
    4063                 :    14666721 :       if (DECL_C_BIT_FIELD (field)
    4064                 :    14666721 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    4065                 :             :         /* We don't treat zero-width bitfields as making a class
    4066                 :             :            non-empty.  */
    4067                 :             :         ;
    4068                 :    14665626 :       else if (field_poverlapping_p (field)
    4069                 :    14665626 :                && is_empty_class (TREE_TYPE (field)))
    4070                 :             :         /* Empty data members also don't make a class non-empty.  */
    4071                 :       40098 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4072                 :             :       else
    4073                 :             :         {
    4074                 :             :           /* The class is non-empty.  */
    4075                 :    14625528 :           CLASSTYPE_EMPTY_P (t) = 0;
    4076                 :             :           /* The class is not even nearly empty.  */
    4077                 :    14625528 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4078                 :             :           /* If one of the data members contains an empty class, so
    4079                 :             :              does T.  */
    4080                 :     2569750 :           if (CLASS_TYPE_P (type)
    4081                 :    17183998 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4082                 :      670737 :             CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    4083                 :             :         }
    4084                 :             : 
    4085                 :             :       /* This is used by -Weffc++ (see below). Warn only for pointers
    4086                 :             :          to members which might hold dynamic memory. So do not warn
    4087                 :             :          for pointers to functions or pointers to members.  */
    4088                 :    14666721 :       if (TYPE_PTR_P (type)
    4089                 :    14666721 :           && !TYPE_PTRFN_P (type))
    4090                 :             :         pointer_member = field;
    4091                 :             : 
    4092                 :    14666721 :       if (CLASS_TYPE_P (type))
    4093                 :             :         {
    4094                 :     2598568 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    4095                 :        3077 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    4096                 :     2598568 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    4097                 :       29124 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4098                 :             :         }
    4099                 :             : 
    4100                 :    14666721 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    4101                 :      212647 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    4102                 :             : 
    4103                 :    14666721 :       if (DECL_MUTABLE_P (field))
    4104                 :             :         {
    4105                 :      132367 :           if (TYPE_REF_P (type))
    4106                 :           3 :             error ("member %q+D cannot be declared as a %<mutable%> "
    4107                 :             :                    "reference", field);
    4108                 :      132364 :           else if (CP_TYPE_CONST_P (type))
    4109                 :           3 :             error ("member %q+D cannot be declared both %<const%> "
    4110                 :             :                    "and %<mutable%>", field);
    4111                 :             :         }
    4112                 :             : 
    4113                 :    14666721 :       if (! layout_pod_type_p (type))
    4114                 :             :         /* DR 148 now allows pointers to members (which are POD themselves),
    4115                 :             :            to be allowed in POD structs.  */
    4116                 :     2062810 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4117                 :             : 
    4118                 :    14666721 :       if (field_poverlapping_p (field))
    4119                 :             :         /* A potentially-overlapping non-static data member makes the class
    4120                 :             :            non-layout-POD.  */
    4121                 :       71087 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    4122                 :             : 
    4123                 :    14666721 :       if (!std_layout_type_p (type))
    4124                 :      562548 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    4125                 :             : 
    4126                 :    14666721 :       if (! zero_init_p (type))
    4127                 :         147 :         CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
    4128                 :             : 
    4129                 :             :       /* We set DECL_C_BIT_FIELD in grokbitfield.
    4130                 :             :          If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
    4131                 :    14666721 :       if (DECL_C_BIT_FIELD (field))
    4132                 :      382452 :         check_bitfield_decl (field);
    4133                 :             : 
    4134                 :    14666721 :       if (check_field_decl (field, t,
    4135                 :             :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    4136                 :             :         {
    4137                 :      700999 :           if (default_init_member
    4138                 :      313732 :               && TREE_CODE (t) == UNION_TYPE)
    4139                 :             :             {
    4140                 :          12 :               auto_diagnostic_group d;
    4141                 :          12 :               error ("multiple fields in union %qT initialized", t);
    4142                 :          12 :               inform (DECL_SOURCE_LOCATION (default_init_member),
    4143                 :             :                       "initialized member %q+D declared here",
    4144                 :             :                       default_init_member);
    4145                 :          12 :             }
    4146                 :             :           default_init_member = field;
    4147                 :             :         }
    4148                 :             : 
    4149                 :             :       /* Now that we've removed bit-field widths from DECL_INITIAL,
    4150                 :             :          anything left in DECL_INITIAL is an NSDMI that makes the class
    4151                 :             :          non-aggregate in C++11, and non-layout-POD always.  */
    4152                 :    14666721 :       if (DECL_INITIAL (field))
    4153                 :             :         {
    4154                 :      698768 :           if (cxx_dialect < cxx14)
    4155                 :         899 :             CLASSTYPE_NON_AGGREGATE (t) = true;
    4156                 :             :           else
    4157                 :      697869 :             CLASSTYPE_NON_POD_AGGREGATE (t) = true;
    4158                 :             :         }
    4159                 :             : 
    4160                 :    14666721 :       if (CP_TYPE_CONST_P (type))
    4161                 :             :         {
    4162                 :             :           /* If any field is const, the structure type is pseudo-const.  */
    4163                 :      253077 :           C_TYPE_FIELDS_READONLY (t) = 1;
    4164                 :      253077 :           if (DECL_INITIAL (field) == NULL_TREE)
    4165                 :      206114 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    4166                 :      253077 :           if (cxx_dialect < cxx11)
    4167                 :             :             {
    4168                 :             :               /* ARM $12.6.2: [A member initializer list] (or, for an
    4169                 :             :                  aggregate, initialization by a brace-enclosed list) is the
    4170                 :             :                  only way to initialize non-static const and reference
    4171                 :             :                  members.  */
    4172                 :         323 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    4173                 :         323 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    4174                 :             :             }
    4175                 :             :         }
    4176                 :             :       /* A field that is pseudo-const makes the structure likewise.  */
    4177                 :    14413644 :       else if (CLASS_TYPE_P (type))
    4178                 :             :         {
    4179                 :     2550847 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    4180                 :     2550847 :           SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
    4181                 :             :             CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    4182                 :             :             | CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
    4183                 :             :         }
    4184                 :             : 
    4185                 :             :       /* Core issue 80: A non-static data member is required to have a
    4186                 :             :          different name from the class iff the class has a
    4187                 :             :          user-declared constructor.  */
    4188                 :    14666721 :       if (constructor_name_p (DECL_NAME (field), t)
    4189                 :    14666721 :           && TYPE_HAS_USER_CONSTRUCTOR (t))
    4190                 :          12 :         permerror (DECL_SOURCE_LOCATION (field),
    4191                 :             :                    "field %q#D with same name as class", field);
    4192                 :             :     }
    4193                 :             : 
    4194                 :             :   /* Per CWG 2096, a type is a literal type if it is a union, and at least
    4195                 :             :      one of its non-static data members is of non-volatile literal type.  */
    4196                 :    36027736 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    4197                 :      377998 :     CLASSTYPE_LITERAL_P (t) = true;
    4198                 :             : 
    4199                 :             :   /* Effective C++ rule 11: if a class has dynamic memory held by pointers,
    4200                 :             :      it should also define a copy constructor and an assignment operator to
    4201                 :             :      implement the correct copy semantic (deep vs shallow, etc.). As it is
    4202                 :             :      not feasible to check whether the constructors do allocate dynamic memory
    4203                 :             :      and store it within members, we approximate the warning like this:
    4204                 :             : 
    4205                 :             :      -- Warn only if there are members which are pointers
    4206                 :             :      -- Warn only if there is a non-trivial constructor (otherwise,
    4207                 :             :         there cannot be memory allocated).
    4208                 :             :      -- Warn only if there is a non-trivial destructor. We assume that the
    4209                 :             :         user at least implemented the cleanup correctly, and a destructor
    4210                 :             :         is needed to free dynamic memory.
    4211                 :             : 
    4212                 :             :      This seems enough for practical purposes.  */
    4213                 :    36027736 :   if (warn_ecpp
    4214                 :         138 :       && pointer_member
    4215                 :          15 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    4216                 :          15 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    4217                 :    36027748 :       && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)))
    4218                 :             :     {
    4219                 :           9 :       auto_diagnostic_group d;
    4220                 :           9 :       if (warning (OPT_Weffc__, "%q#T has pointer data members", t))
    4221                 :             :         {
    4222                 :           9 :           if (! TYPE_HAS_COPY_CTOR (t))
    4223                 :             :             {
    4224                 :           6 :               warning (OPT_Weffc__,
    4225                 :             :                        "  but does not declare %<%T(const %T&)%>", t, t);
    4226                 :           6 :               if (!TYPE_HAS_COPY_ASSIGN (t))
    4227                 :           3 :                 warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
    4228                 :             :             }
    4229                 :           3 :           else if (! TYPE_HAS_COPY_ASSIGN (t))
    4230                 :           3 :             warning (OPT_Weffc__,
    4231                 :             :                      "  but does not declare %<operator=(const %T&)%>", t);
    4232                 :           9 :           inform (DECL_SOURCE_LOCATION (pointer_member),
    4233                 :             :                   "pointer member %q+D declared here", pointer_member);
    4234                 :             :         }
    4235                 :           9 :     }
    4236                 :             : 
    4237                 :             :   /* Non-static data member initializers make the default constructor
    4238                 :             :      non-trivial.  */
    4239                 :    36027736 :   if (default_init_member)
    4240                 :             :     {
    4241                 :      387267 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    4242                 :      387267 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    4243                 :             :     }
    4244                 :             : 
    4245                 :             :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    4246                 :    36027736 :   if (cant_pack)
    4247                 :          12 :     TYPE_PACKED (t) = 0;
    4248                 :             : 
    4249                 :             :   /* Check anonymous struct/anonymous union fields.  */
    4250                 :    36027736 :   finish_struct_anon (t);
    4251                 :             : 
    4252                 :             :   /* We've built up the list of access declarations in reverse order.
    4253                 :             :      Fix that now.  */
    4254                 :    36027736 :   *access_decls = nreverse (*access_decls);
    4255                 :    36027736 : }
    4256                 :             : 
    4257                 :             : /* If TYPE is an empty class type, records its OFFSET in the table of
    4258                 :             :    OFFSETS.  */
    4259                 :             : 
    4260                 :             : static int
    4261                 :    23601108 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    4262                 :             : {
    4263                 :    23601108 :   splay_tree_node n;
    4264                 :             : 
    4265                 :    23601108 :   if (!is_empty_class (type))
    4266                 :             :     return 0;
    4267                 :             : 
    4268                 :             :   /* Record the location of this empty object in OFFSETS.  */
    4269                 :    21554128 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4270                 :    21554128 :   if (!n)
    4271                 :    17945671 :     n = splay_tree_insert (offsets,
    4272                 :             :                            (splay_tree_key) offset,
    4273                 :             :                            (splay_tree_value) NULL_TREE);
    4274                 :    43108256 :   n->value = ((splay_tree_value)
    4275                 :    21554128 :               tree_cons (NULL_TREE,
    4276                 :             :                          type,
    4277                 :    21554128 :                          (tree) n->value));
    4278                 :             : 
    4279                 :    21554128 :   return 0;
    4280                 :             : }
    4281                 :             : 
    4282                 :             : /* Returns nonzero if TYPE is an empty class type and there is
    4283                 :             :    already an entry in OFFSETS for the same TYPE as the same OFFSET.  */
    4284                 :             : 
    4285                 :             : static int
    4286                 :      676922 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    4287                 :             : {
    4288                 :      676922 :   splay_tree_node n;
    4289                 :      676922 :   tree t;
    4290                 :             : 
    4291                 :      676922 :   if (!is_empty_class (type))
    4292                 :             :     return 0;
    4293                 :             : 
    4294                 :             :   /* Record the location of this empty object in OFFSETS.  */
    4295                 :      598545 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    4296                 :      598545 :   if (!n)
    4297                 :             :     return 0;
    4298                 :             : 
    4299                 :      598497 :   enum { ignore, fast, slow, warn }
    4300                 :      598497 :   cv_check = (abi_version_crosses (19) ? slow
    4301                 :      598026 :               : abi_version_at_least (19) ? fast
    4302                 :      598497 :               : ignore);
    4303                 :     5812150 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    4304                 :             :     {
    4305                 :     5215178 :       tree elt = TREE_VALUE (t);
    4306                 :             : 
    4307                 :     5215178 :       if (same_type_p (elt, type))
    4308                 :             :         return 1;
    4309                 :             : 
    4310                 :     5213653 :       if (cv_check != ignore
    4311                 :     5213653 :           && similar_type_p (elt, type))
    4312                 :             :         {
    4313                 :          12 :           if (cv_check == fast)
    4314                 :             :             return 1;
    4315                 :             :           cv_check = warn;
    4316                 :             :         }
    4317                 :             :     }
    4318                 :             : 
    4319                 :      596972 :   if (cv_check == warn)
    4320                 :             :     {
    4321                 :          12 :       warning (OPT_Wabi, "layout of %qs member of type %qT changes in %qs",
    4322                 :             :                "[[no_unique_address]]", type, "-fabi-version=19");
    4323                 :          12 :       if (abi_version_at_least (19))
    4324                 :             :         return 1;
    4325                 :             :     }
    4326                 :             : 
    4327                 :             :   return 0;
    4328                 :             : }
    4329                 :             : 
    4330                 :             : /* Walk through all the subobjects of TYPE (located at OFFSET).  Call
    4331                 :             :    F for every subobject, passing it the type, offset, and table of
    4332                 :             :    OFFSETS.  If VBASES_P is one, then virtual non-primary bases should
    4333                 :             :    be traversed.
    4334                 :             : 
    4335                 :             :    If MAX_OFFSET is non-NULL, then subobjects with an offset greater
    4336                 :             :    than MAX_OFFSET will not be walked.
    4337                 :             : 
    4338                 :             :    If F returns a nonzero value, the traversal ceases, and that value
    4339                 :             :    is returned.  Otherwise, returns zero.  */
    4340                 :             : 
    4341                 :             : static int
    4342                 :    43894472 : walk_subobject_offsets (tree type,
    4343                 :             :                         subobject_offset_fn f,
    4344                 :             :                         tree offset,
    4345                 :             :                         splay_tree offsets,
    4346                 :             :                         tree max_offset,
    4347                 :             :                         int vbases_p)
    4348                 :             : {
    4349                 :    43894472 :   int r = 0;
    4350                 :    43894472 :   tree type_binfo = NULL_TREE;
    4351                 :             : 
    4352                 :             :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    4353                 :             :      stop.  */
    4354                 :    43894472 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    4355                 :             :     return 0;
    4356                 :             : 
    4357                 :    32257574 :   if (type == error_mark_node)
    4358                 :             :     return 0;
    4359                 :             : 
    4360                 :    32257574 :   if (!TYPE_P (type))
    4361                 :             :     {
    4362                 :     5459735 :       type_binfo = type;
    4363                 :     5459735 :       type = BINFO_TYPE (type);
    4364                 :             :     }
    4365                 :             : 
    4366                 :    32257574 :   if (CLASS_TYPE_P (type))
    4367                 :             :     {
    4368                 :    27327447 :       tree field;
    4369                 :    27327447 :       tree binfo;
    4370                 :    27327447 :       int i;
    4371                 :             : 
    4372                 :             :       /* Avoid recursing into objects that are not interesting.  */
    4373                 :    27327447 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    4374                 :             :         return 0;
    4375                 :             : 
    4376                 :             :       /* Record the location of TYPE.  */
    4377                 :    24278463 :       r = (*f) (type, offset, offsets);
    4378                 :    24278463 :       if (r)
    4379                 :             :         return r;
    4380                 :             : 
    4381                 :             :       /* Iterate through the direct base classes of TYPE.  */
    4382                 :    24276926 :       if (!type_binfo)
    4383                 :    19574817 :         type_binfo = TYPE_BINFO (type);
    4384                 :    29634836 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    4385                 :             :         {
    4386                 :     5358764 :           tree binfo_offset;
    4387                 :             : 
    4388                 :     5358764 :           if (BINFO_VIRTUAL_P (binfo))
    4389                 :        1577 :             continue;
    4390                 :             : 
    4391                 :     5357187 :           tree orig_binfo;
    4392                 :             :           /* We cannot rely on BINFO_OFFSET being set for the base
    4393                 :             :              class yet, but the offsets for direct non-virtual
    4394                 :             :              bases can be calculated by going back to the TYPE.  */
    4395                 :     5357187 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    4396                 :     5357187 :           binfo_offset = size_binop (PLUS_EXPR,
    4397                 :             :                                      offset,
    4398                 :             :                                      BINFO_OFFSET (orig_binfo));
    4399                 :             : 
    4400                 :     5357187 :           r = walk_subobject_offsets (binfo,
    4401                 :             :                                       f,
    4402                 :             :                                       binfo_offset,
    4403                 :             :                                       offsets,
    4404                 :             :                                       max_offset,
    4405                 :             :                                       /*vbases_p=*/0);
    4406                 :     5357187 :           if (r)
    4407                 :         854 :             return r;
    4408                 :             :         }
    4409                 :             : 
    4410                 :    24276072 :       if (CLASSTYPE_VBASECLASSES (type))
    4411                 :             :         {
    4412                 :        1288 :           unsigned ix;
    4413                 :        1288 :           vec<tree, va_gc> *vbases;
    4414                 :             : 
    4415                 :             :           /* Iterate through the virtual base classes of TYPE.  In G++
    4416                 :             :              3.2, we included virtual bases in the direct base class
    4417                 :             :              loop above, which results in incorrect results; the
    4418                 :             :              correct offsets for virtual bases are only known when
    4419                 :             :              working with the most derived type.  */
    4420                 :        1288 :           if (vbases_p)
    4421                 :          30 :             for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
    4422                 :          30 :                  vec_safe_iterate (vbases, ix, &binfo); ix++)
    4423                 :             :               {
    4424                 :          15 :                 r = walk_subobject_offsets (binfo,
    4425                 :             :                                             f,
    4426                 :          15 :                                             size_binop (PLUS_EXPR,
    4427                 :             :                                                         offset,
    4428                 :             :                                                         BINFO_OFFSET (binfo)),
    4429                 :             :                                             offsets,
    4430                 :             :                                             max_offset,
    4431                 :             :                                             /*vbases_p=*/0);
    4432                 :          15 :                 if (r)
    4433                 :           0 :                   return r;
    4434                 :             :               }
    4435                 :             :           else
    4436                 :             :             {
    4437                 :             :               /* We still have to walk the primary base, if it is
    4438                 :             :                  virtual.  (If it is non-virtual, then it was walked
    4439                 :             :                  above.)  */
    4440                 :        1273 :               tree vbase = get_primary_binfo (type_binfo);
    4441                 :             : 
    4442                 :         395 :               if (vbase && BINFO_VIRTUAL_P (vbase)
    4443                 :         234 :                   && BINFO_PRIMARY_P (vbase)
    4444                 :        1507 :                   && BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
    4445                 :             :                 {
    4446                 :         200 :                   r = (walk_subobject_offsets
    4447                 :         200 :                        (vbase, f, offset,
    4448                 :             :                         offsets, max_offset, /*vbases_p=*/0));
    4449                 :         200 :                   if (r)
    4450                 :             :                     return r;
    4451                 :             :                 }
    4452                 :             :             }
    4453                 :             :         }
    4454                 :             : 
    4455                 :             :       /* Iterate through the fields of TYPE.  */
    4456                 :   456397670 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4457                 :   432121805 :         if (TREE_CODE (field) == FIELD_DECL
    4458                 :     7774675 :             && TREE_TYPE (field) != error_mark_node
    4459                 :   439896454 :             && !DECL_ARTIFICIAL (field))
    4460                 :             :           {
    4461                 :     2390078 :             tree field_offset;
    4462                 :             : 
    4463                 :     2390078 :             field_offset = byte_position (field);
    4464                 :             : 
    4465                 :     2390078 :             r = walk_subobject_offsets (TREE_TYPE (field),
    4466                 :             :                                         f,
    4467                 :             :                                         size_binop (PLUS_EXPR,
    4468                 :             :                                                     offset,
    4469                 :             :                                                     field_offset),
    4470                 :             :                                         offsets,
    4471                 :             :                                         max_offset,
    4472                 :             :                                         /*vbases_p=*/1);
    4473                 :     2390078 :             if (r)
    4474                 :         207 :               return r;
    4475                 :             :           }
    4476                 :             :     }
    4477                 :     4930127 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4478                 :             :     {
    4479                 :      553957 :       tree element_type = strip_array_types (type);
    4480                 :      553957 :       tree domain = TYPE_DOMAIN (type);
    4481                 :      553957 :       tree index;
    4482                 :             : 
    4483                 :             :       /* Avoid recursing into objects that are not interesting.  */
    4484                 :       26026 :       if (!CLASS_TYPE_P (element_type)
    4485                 :       26015 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4486                 :       11778 :           || !domain
    4487                 :      565716 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4488                 :      542415 :         return 0;
    4489                 :             : 
    4490                 :             :       /* Step through each of the elements in the array.  */
    4491                 :       11542 :       for (index = size_zero_node;
    4492                 :       14454 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4493                 :        2912 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4494                 :             :         {
    4495                 :       13943 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4496                 :             :                                       f,
    4497                 :             :                                       offset,
    4498                 :             :                                       offsets,
    4499                 :             :                                       max_offset,
    4500                 :             :                                       /*vbases_p=*/1);
    4501                 :       13943 :           if (r)
    4502                 :           0 :             return r;
    4503                 :       13943 :           offset = size_binop (PLUS_EXPR, offset,
    4504                 :             :                                TYPE_SIZE_UNIT (TREE_TYPE (type)));
    4505                 :             :           /* If this new OFFSET is bigger than the MAX_OFFSET, then
    4506                 :             :              there's no point in iterating through the remaining
    4507                 :             :              elements of the array.  */
    4508                 :       13943 :           if (max_offset && tree_int_cst_lt (max_offset, offset))
    4509                 :             :             break;
    4510                 :             :         }
    4511                 :             :     }
    4512                 :             : 
    4513                 :             :   return 0;
    4514                 :             : }
    4515                 :             : 
    4516                 :             : /* Return true iff FIELD_DECL DECL is potentially overlapping.  */
    4517                 :             : 
    4518                 :             : static bool
    4519                 :    58908046 : field_poverlapping_p (tree decl)
    4520                 :             : {
    4521                 :             :   /* Base fields are actually potentially overlapping, but C++ bases go through
    4522                 :             :      a different code path based on binfos, and ObjC++ base fields are laid out
    4523                 :             :      in objc-act, so we don't want layout_class_type to mess with them.  */
    4524                 :    58908046 :   if (DECL_FIELD_IS_BASE (decl))
    4525                 :             :     {
    4526                 :           0 :       gcc_checking_assert (c_dialect_objc ());
    4527                 :             :       return false;
    4528                 :             :     }
    4529                 :             : 
    4530                 :    58908046 :   return lookup_attribute ("no_unique_address",
    4531                 :   117816092 :                            DECL_ATTRIBUTES (decl));
    4532                 :             : }
    4533                 :             : 
    4534                 :             : /* Return true iff DECL is an empty field, either for an empty base or a
    4535                 :             :    [[no_unique_address]] data member.  */
    4536                 :             : 
    4537                 :             : bool
    4538                 :   140274563 : is_empty_field (tree decl)
    4539                 :             : {
    4540                 :   140274563 :   if (!decl || TREE_CODE (decl) != FIELD_DECL)
    4541                 :             :     return false;
    4542                 :             : 
    4543                 :    74845799 :   bool r = (is_empty_class (TREE_TYPE (decl))
    4544                 :    76734682 :             && (DECL_FIELD_IS_BASE (decl)
    4545                 :      200623 :                 || field_poverlapping_p (decl)));
    4546                 :             : 
    4547                 :             :   /* Empty fields should have size zero.  */
    4548                 :     1773115 :   gcc_checking_assert (!r || integer_zerop (DECL_SIZE (decl)));
    4549                 :             : 
    4550                 :             :   return r;
    4551                 :             : }
    4552                 :             : 
    4553                 :             : /* Record all of the empty subobjects of DECL_OR_BINFO.  */
    4554                 :             : 
    4555                 :             : static void
    4556                 :    34173277 : record_subobject_offsets (tree decl_or_binfo,
    4557                 :             :                           splay_tree offsets)
    4558                 :             : {
    4559                 :    34173277 :   tree type, offset;
    4560                 :    34173277 :   bool overlapping, vbases_p;
    4561                 :             : 
    4562                 :    34173277 :   if (DECL_P (decl_or_binfo))
    4563                 :             :     {
    4564                 :    14666721 :       tree decl = decl_or_binfo;
    4565                 :    14666721 :       type = TREE_TYPE (decl);
    4566                 :    14666721 :       offset = byte_position (decl);
    4567                 :    14666721 :       overlapping = field_poverlapping_p (decl);
    4568                 :    14666721 :       vbases_p = true;
    4569                 :             :     }
    4570                 :             :   else
    4571                 :             :     {
    4572                 :    19506556 :       type = BINFO_TYPE (decl_or_binfo);
    4573                 :    19506556 :       offset = BINFO_OFFSET (decl_or_binfo);
    4574                 :    19506556 :       overlapping = true;
    4575                 :    19506556 :       vbases_p = false;
    4576                 :             :     }
    4577                 :             : 
    4578                 :    34173277 :   tree max_offset;
    4579                 :             :   /* If recording subobjects for a non-static data member or a
    4580                 :             :      non-empty base class, we do not need to record offsets beyond
    4581                 :             :      the size of the biggest empty class.  Additional data members
    4582                 :             :      will go at the end of the class.  Additional base classes will go
    4583                 :             :      either at offset zero (if empty, in which case they cannot
    4584                 :             :      overlap with offsets past the size of the biggest empty class) or
    4585                 :             :      at the end of the class.
    4586                 :             : 
    4587                 :             :      However, if we are placing an empty base class, then we must record
    4588                 :             :      all offsets, as either the empty class is at offset zero (where
    4589                 :             :      other empty classes might later be placed) or at the end of the
    4590                 :             :      class (where other objects might then be placed, so other empty
    4591                 :             :      subobjects might later overlap).  */
    4592                 :    34173277 :   if (!overlapping
    4593                 :    34173277 :       || !is_empty_class (type))
    4594                 :    16928103 :     max_offset = sizeof_biggest_empty_class;
    4595                 :             :   else
    4596                 :             :     max_offset = NULL_TREE;
    4597                 :    34173277 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4598                 :             :                           offsets, max_offset, vbases_p);
    4599                 :    34173277 : }
    4600                 :             : 
    4601                 :             : /* Returns nonzero if any of the empty subobjects of TYPE (located at
    4602                 :             :    OFFSET) conflict with entries in OFFSETS.  If VBASES_P is nonzero,
    4603                 :             :    virtual bases of TYPE are examined.  */
    4604                 :             : 
    4605                 :             : static int
    4606                 :    33188136 : layout_conflict_p (tree type,
    4607                 :             :                    tree offset,
    4608                 :             :                    splay_tree offsets,
    4609                 :             :                    int vbases_p)
    4610                 :             : {
    4611                 :    33188136 :   splay_tree_node max_node;
    4612                 :             : 
    4613                 :             :   /* Get the node in OFFSETS that indicates the maximum offset where
    4614                 :             :      an empty subobject is located.  */
    4615                 :    33188136 :   max_node = splay_tree_max (offsets);
    4616                 :             :   /* If there aren't any empty subobjects, then there's no point in
    4617                 :             :      performing this check.  */
    4618                 :    33188136 :   if (!max_node)
    4619                 :             :     return 0;
    4620                 :             : 
    4621                 :     1959442 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4622                 :     1959442 :                                  offsets, (tree) (max_node->key),
    4623                 :     1959442 :                                  vbases_p);
    4624                 :             : }
    4625                 :             : 
    4626                 :             : /* DECL is a FIELD_DECL corresponding either to a base subobject of a
    4627                 :             :    non-static data member of the type indicated by RLI.  BINFO is the
    4628                 :             :    binfo corresponding to the base subobject, OFFSETS maps offsets to
    4629                 :             :    types already located at those offsets.  This function determines
    4630                 :             :    the position of the DECL.  */
    4631                 :             : 
    4632                 :             : static void
    4633                 :    16928871 : layout_nonempty_base_or_field (record_layout_info rli,
    4634                 :             :                                tree decl,
    4635                 :             :                                tree binfo,
    4636                 :             :                                splay_tree offsets)
    4637                 :             : {
    4638                 :    16928871 :   tree offset = NULL_TREE;
    4639                 :    16928871 :   bool field_p;
    4640                 :    16928871 :   tree type;
    4641                 :             : 
    4642                 :    16928871 :   if (binfo)
    4643                 :             :     {
    4644                 :             :       /* For the purposes of determining layout conflicts, we want to
    4645                 :             :          use the class type of BINFO; TREE_TYPE (DECL) will be the
    4646                 :             :          CLASSTYPE_AS_BASE version, which does not contain entries for
    4647                 :             :          zero-sized bases.  */
    4648                 :     2301480 :       type = TREE_TYPE (binfo);
    4649                 :     2301480 :       field_p = false;
    4650                 :             :     }
    4651                 :             :   else
    4652                 :             :     {
    4653                 :    14627391 :       type = TREE_TYPE (decl);
    4654                 :    14627391 :       field_p = true;
    4655                 :             :     }
    4656                 :             : 
    4657                 :             :   /* Try to place the field.  It may take more than one try if we have
    4658                 :             :      a hard time placing the field without putting two objects of the
    4659                 :             :      same type at the same address.  */
    4660                 :         229 :   while (1)
    4661                 :             :     {
    4662                 :    16929100 :       struct record_layout_info_s old_rli = *rli;
    4663                 :             : 
    4664                 :             :       /* Place this field.  */
    4665                 :    16929100 :       place_field (rli, decl);
    4666                 :    16929100 :       offset = byte_position (decl);
    4667                 :             : 
    4668                 :             :       /* We have to check to see whether or not there is already
    4669                 :             :          something of the same type at the offset we're about to use.
    4670                 :             :          For example, consider:
    4671                 :             : 
    4672                 :             :            struct S {};
    4673                 :             :            struct T : public S { int i; };
    4674                 :             :            struct U : public S, public T {};
    4675                 :             : 
    4676                 :             :          Here, we put S at offset zero in U.  Then, we can't put T at
    4677                 :             :          offset zero -- its S component would be at the same address
    4678                 :             :          as the S we already allocated.  So, we have to skip ahead.
    4679                 :             :          Since all data members, including those whose type is an
    4680                 :             :          empty class, have nonzero size, any overlap can happen only
    4681                 :             :          with a direct or indirect base-class -- it can't happen with
    4682                 :             :          a data member.  */
    4683                 :             :       /* In a union, overlap is permitted; all members are placed at
    4684                 :             :          offset zero.  */
    4685                 :    16929100 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4686                 :             :         break;
    4687                 :    18244167 :       if (layout_conflict_p (field_p ? type : binfo, offset,
    4688                 :             :                              offsets, field_p))
    4689                 :             :         {
    4690                 :             :           /* Strip off the size allocated to this field.  That puts us
    4691                 :             :              at the first place we could have put the field with
    4692                 :             :              proper alignment.  */
    4693                 :         229 :           *rli = old_rli;
    4694                 :             : 
    4695                 :             :           /* Bump up by the alignment required for the type.  */
    4696                 :         229 :           rli->bitpos
    4697                 :         229 :             = size_binop (PLUS_EXPR, rli->bitpos,
    4698                 :             :                           bitsize_int (binfo
    4699                 :             :                                        ? CLASSTYPE_ALIGN (type)
    4700                 :             :                                        : TYPE_ALIGN (type)));
    4701                 :         229 :           normalize_rli (rli);
    4702                 :             :         }
    4703                 :    15942399 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4704                 :       29012 :                && warn_abi && abi_version_crosses (9))
    4705                 :             :         {
    4706                 :             :           /* Before ABI v9, we were giving nullptr_t alignment of 1; if
    4707                 :             :              the offset wasn't aligned like a pointer when we started to
    4708                 :             :              layout this field, that affects its position.  */
    4709                 :         144 :           tree pos = rli_size_unit_so_far (&old_rli);
    4710                 :         144 :           if (int_cst_value (pos) % TYPE_ALIGN_UNIT (ptr_type_node) != 0)
    4711                 :             :             {
    4712                 :           3 :               if (abi_version_at_least (9))
    4713                 :           3 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi,
    4714                 :             :                             "alignment of %qD increased in %<-fabi-version=9%> "
    4715                 :             :                             "(GCC 5.2)", decl);
    4716                 :             :               else
    4717                 :           0 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi, "alignment "
    4718                 :             :                             "of %qD will increase in %<-fabi-version=9%>",
    4719                 :             :                             decl);
    4720                 :             :             }
    4721                 :             :           break;
    4722                 :             :         }
    4723                 :             :       else
    4724                 :             :         /* There was no conflict.  We're done laying out this field.  */
    4725                 :             :         break;
    4726                 :             :     }
    4727                 :             : 
    4728                 :             :   /* Now that we know where it will be placed, update its
    4729                 :             :      BINFO_OFFSET.  */
    4730                 :    19230351 :   if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
    4731                 :             :     /* Indirect virtual bases may have a nonzero BINFO_OFFSET at
    4732                 :             :        this point because their BINFO_OFFSET is copied from another
    4733                 :             :        hierarchy.  Therefore, we may not need to add the entire
    4734                 :             :        OFFSET.  */
    4735                 :     2301480 :     propagate_binfo_offsets (binfo,
    4736                 :             :                              size_diffop_loc (input_location,
    4737                 :             :                                           fold_convert (ssizetype, offset),
    4738                 :     2301480 :                                           fold_convert (ssizetype,
    4739                 :             :                                                    BINFO_OFFSET (binfo))));
    4740                 :    16928871 : }
    4741                 :             : 
    4742                 :             : /* Returns true if TYPE is empty and OFFSET is nonzero.  */
    4743                 :             : 
    4744                 :             : static int
    4745                 :         433 : empty_base_at_nonzero_offset_p (tree type,
    4746                 :             :                                 tree offset,
    4747                 :             :                                 splay_tree /*offsets*/)
    4748                 :             : {
    4749                 :         433 :   return is_empty_class (type) && !integer_zerop (offset);
    4750                 :             : }
    4751                 :             : 
    4752                 :             : /* Layout the empty base BINFO.  EOC indicates the byte currently just
    4753                 :             :    past the end of the class, and should be correctly aligned for a
    4754                 :             :    class of the type indicated by BINFO; OFFSETS gives the offsets of
    4755                 :             :    the empty bases allocated so far. T is the most derived
    4756                 :             :    type.  Return nonzero iff we added it at the end.  */
    4757                 :             : 
    4758                 :             : static bool
    4759                 :    17245174 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4760                 :             :                             splay_tree offsets)
    4761                 :             : {
    4762                 :    17245174 :   tree alignment;
    4763                 :    17245174 :   bool atend = false;
    4764                 :    17245174 :   tree binfo = NULL_TREE;
    4765                 :    17245174 :   tree decl = NULL_TREE;
    4766                 :    17245174 :   tree type;
    4767                 :    17245174 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4768                 :             :     {
    4769                 :    17205076 :       binfo = binfo_or_decl;
    4770                 :    17205076 :       type = BINFO_TYPE (binfo);
    4771                 :             :     }
    4772                 :             :   else
    4773                 :             :     {
    4774                 :       40098 :       decl = binfo_or_decl;
    4775                 :       40098 :       type = TREE_TYPE (decl);
    4776                 :             :     }
    4777                 :             : 
    4778                 :             :   /* On some platforms (ARM), even empty classes will not be
    4779                 :             :      byte-aligned.  */
    4780                 :    17245174 :   tree eoc = round_up_loc (input_location,
    4781                 :             :                            rli_size_unit_so_far (rli),
    4782                 :    17245174 :                            CLASSTYPE_ALIGN_UNIT (type));
    4783                 :             : 
    4784                 :             :   /* This routine should only be used for empty classes.  */
    4785                 :    17245174 :   gcc_assert (is_empty_class (type));
    4786                 :             : 
    4787                 :    17245174 :   if (decl && DECL_USER_ALIGN (decl))
    4788                 :           3 :     alignment = size_int (DECL_ALIGN_UNIT (decl));
    4789                 :             :   else
    4790                 :    17245171 :     alignment = size_int (CLASSTYPE_ALIGN_UNIT (type));
    4791                 :             : 
    4792                 :             :   /* This is an empty base class.  We first try to put it at offset
    4793                 :             :      zero.  */
    4794                 :    17245174 :   tree offset = size_zero_node;
    4795                 :    17245174 :   if (TREE_CODE (rli->t) != UNION_TYPE
    4796                 :    17245174 :       && layout_conflict_p (type,
    4797                 :             :                             offset,
    4798                 :             :                             offsets,
    4799                 :             :                             /*vbases_p=*/0))
    4800                 :             :     {
    4801                 :             :       /* That didn't work.  Now, we move forward from the next
    4802                 :             :          available spot in the class.  */
    4803                 :        1302 :       atend = true;
    4804                 :             :       offset = eoc;
    4805                 :        1867 :       while (1)
    4806                 :             :         {
    4807                 :        1302 :           if (!layout_conflict_p (type,
    4808                 :             :                                   offset,
    4809                 :             :                                   offsets,
    4810                 :             :                                   /*vbases_p=*/0))
    4811                 :             :             /* We finally found a spot where there's no overlap.  */
    4812                 :             :             break;
    4813                 :             : 
    4814                 :             :           /* There's overlap here, too.  Bump along to the next spot.  */
    4815                 :         565 :           offset = size_binop (PLUS_EXPR, offset, alignment);
    4816                 :             :         }
    4817                 :             :     }
    4818                 :             : 
    4819                 :    17245174 :   if (decl && DECL_USER_ALIGN (decl))
    4820                 :             :     {
    4821                 :           3 :       rli->record_align = MAX (rli->record_align, DECL_ALIGN (decl));
    4822                 :           3 :       if (warn_packed)
    4823                 :           0 :         rli->unpacked_align = MAX (rli->unpacked_align, DECL_ALIGN (decl));
    4824                 :           3 :       TYPE_USER_ALIGN (rli->t) = 1;
    4825                 :             :     }
    4826                 :    17245171 :   else if (CLASSTYPE_USER_ALIGN (type))
    4827                 :             :     {
    4828                 :          18 :       rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type));
    4829                 :          18 :       if (warn_packed)
    4830                 :           0 :         rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type));
    4831                 :          18 :       TYPE_USER_ALIGN (rli->t) = 1;
    4832                 :             :     }
    4833                 :             : 
    4834                 :    17245174 :   if (binfo)
    4835                 :             :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4836                 :    34410152 :     propagate_binfo_offsets (binfo,
    4837                 :    17205076 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4838                 :             :   else
    4839                 :             :     {
    4840                 :       40098 :       DECL_FIELD_OFFSET (decl) = offset;
    4841                 :       40098 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4842                 :       40098 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4843                 :             :     }
    4844                 :             : 
    4845                 :    17245174 :   return atend;
    4846                 :             : }
    4847                 :             : 
    4848                 :             : /* Build the FIELD_DECL for BASETYPE as a base of T, add it to the chain of
    4849                 :             :    fields at NEXT_FIELD, and return it.  */
    4850                 :             : 
    4851                 :             : static tree
    4852                 :    19432392 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4853                 :             : {
    4854                 :             :   /* Create the FIELD_DECL.  */
    4855                 :    19432392 :   tree basetype = BINFO_TYPE (binfo);
    4856                 :    19432392 :   tree as_base = CLASSTYPE_AS_BASE (basetype);
    4857                 :    19432392 :   gcc_assert (as_base);
    4858                 :    19432392 :   tree decl = build_decl (input_location, FIELD_DECL, NULL_TREE, as_base);
    4859                 :             : 
    4860                 :    19432392 :   DECL_ARTIFICIAL (decl) = 1;
    4861                 :    19432392 :   DECL_IGNORED_P (decl) = 1;
    4862                 :    19432392 :   DECL_FIELD_CONTEXT (decl) = t;
    4863                 :    19432392 :   if (is_empty_class (basetype))
    4864                 :             :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4865                 :    17130912 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4866                 :             :   else
    4867                 :             :     {
    4868                 :     2301480 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4869                 :     2301480 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4870                 :             :     }
    4871                 :    19432392 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4872                 :    19432392 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4873                 :    19432392 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4874                 :    19432392 :   DECL_FIELD_IS_BASE (decl) = 1;
    4875                 :             : 
    4876                 :    19432392 :   if (access == access_private_node)
    4877                 :      757643 :     TREE_PRIVATE (decl) = true;
    4878                 :    18674749 :   else if (access == access_protected_node)
    4879                 :       66609 :     TREE_PROTECTED (decl) = true;
    4880                 :             : 
    4881                 :             :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4882                 :    19432392 :   DECL_CHAIN (decl) = *next_field;
    4883                 :    19432392 :   *next_field = decl;
    4884                 :    19432392 :   next_field = &DECL_CHAIN (decl);
    4885                 :             : 
    4886                 :    19432392 :   return decl;
    4887                 :             : }
    4888                 :             : 
    4889                 :             : /* Layout the base given by BINFO in the class indicated by RLI.
    4890                 :             :    *BASE_ALIGN is a running maximum of the alignments of
    4891                 :             :    any base class.  OFFSETS gives the location of empty base
    4892                 :             :    subobjects.  T is the most derived type.  Return nonzero if the new
    4893                 :             :    object cannot be nearly-empty.  A new FIELD_DECL is inserted at
    4894                 :             :    *NEXT_FIELD, unless BINFO is for an empty base class.
    4895                 :             : 
    4896                 :             :    Returns the location at which the next field should be inserted.  */
    4897                 :             : 
    4898                 :             : static tree *
    4899                 :    19506556 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4900                 :             :                   splay_tree offsets, tree *next_field)
    4901                 :             : {
    4902                 :    19506556 :   tree t = rli->t;
    4903                 :    19506556 :   tree basetype = BINFO_TYPE (binfo);
    4904                 :             : 
    4905                 :    19506556 :   if (!COMPLETE_TYPE_P (basetype))
    4906                 :             :     /* This error is now reported in xref_tag, thus giving better
    4907                 :             :        location information.  */
    4908                 :           0 :     return next_field;
    4909                 :             : 
    4910                 :             :   /* Place the base class.  */
    4911                 :    19506556 :   if (!is_empty_class (basetype))
    4912                 :             :     {
    4913                 :     2301480 :       tree decl;
    4914                 :             : 
    4915                 :             :       /* The containing class is non-empty because it has a non-empty
    4916                 :             :          base class.  */
    4917                 :     2301480 :       CLASSTYPE_EMPTY_P (t) = 0;
    4918                 :             : 
    4919                 :             :       /* Create the FIELD_DECL.  */
    4920                 :     2301480 :       decl = build_base_field_1 (t, binfo, access, next_field);
    4921                 :             : 
    4922                 :             :       /* Try to place the field.  It may take more than one try if we
    4923                 :             :          have a hard time placing the field without putting two
    4924                 :             :          objects of the same type at the same address.  */
    4925                 :     2301480 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    4926                 :             :     }
    4927                 :             :   else
    4928                 :             :     {
    4929                 :    17205076 :       bool atend = layout_empty_base_or_field (rli, binfo, offsets);
    4930                 :             :       /* A nearly-empty class "has no proper base class that is empty,
    4931                 :             :          not morally virtual, and at an offset other than zero."  */
    4932                 :    17205076 :       if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
    4933                 :             :         {
    4934                 :         424 :           if (atend)
    4935                 :          94 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4936                 :             :           /* The check above (used in G++ 3.2) is insufficient because
    4937                 :             :              an empty class placed at offset zero might itself have an
    4938                 :             :              empty base at a nonzero offset.  */
    4939                 :         330 :           else if (walk_subobject_offsets (basetype,
    4940                 :             :                                            empty_base_at_nonzero_offset_p,
    4941                 :             :                                            size_zero_node,
    4942                 :             :                                            /*offsets=*/NULL,
    4943                 :             :                                            /*max_offset=*/NULL_TREE,
    4944                 :             :                                            /*vbases_p=*/true))
    4945                 :           6 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4946                 :             :         }
    4947                 :             : 
    4948                 :             :       /* We used to not create a FIELD_DECL for empty base classes because of
    4949                 :             :          back end issues with overlapping FIELD_DECLs, but that doesn't seem to
    4950                 :             :          be a problem anymore.  We need them to handle initialization of C++17
    4951                 :             :          aggregate bases.  */
    4952                 :    34337613 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    4953                 :             :         {
    4954                 :    17130912 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    4955                 :    17130912 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    4956                 :    17130912 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4957                 :    17130912 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4958                 :    17130912 :           SET_DECL_FIELD_ABI_IGNORED (decl, 1);
    4959                 :             :         }
    4960                 :             : 
    4961                 :             :       /* An empty virtual base causes a class to be non-empty
    4962                 :             :          -- but in that case we do not need to clear CLASSTYPE_EMPTY_P
    4963                 :             :          here because that was already done when the virtual table
    4964                 :             :          pointer was created.  */
    4965                 :             :     }
    4966                 :             : 
    4967                 :             :   /* Record the offsets of BINFO and its base subobjects.  */
    4968                 :    19506556 :   record_subobject_offsets (binfo, offsets);
    4969                 :             : 
    4970                 :    19506556 :   return next_field;
    4971                 :             : }
    4972                 :             : 
    4973                 :             : /* Layout all of the non-virtual base classes.  Record empty
    4974                 :             :    subobjects in OFFSETS.  T is the most derived type.  Return nonzero
    4975                 :             :    if the type cannot be nearly empty.  The fields created
    4976                 :             :    corresponding to the base classes will be inserted at
    4977                 :             :    *NEXT_FIELD.  */
    4978                 :             : 
    4979                 :             : static void
    4980                 :    36027736 : build_base_fields (record_layout_info rli,
    4981                 :             :                    splay_tree offsets, tree *next_field)
    4982                 :             : {
    4983                 :             :   /* Chain to hold all the new FIELD_DECLs which stand in for base class
    4984                 :             :      subobjects.  */
    4985                 :    36027736 :   tree t = rli->t;
    4986                 :    36027736 :   tree binfo = TYPE_BINFO (t);
    4987                 :    36027736 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    4988                 :             : 
    4989                 :             :   /* The primary base class is always allocated first.  */
    4990                 :    36027736 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    4991                 :    36027736 :   if (primary_binfo)
    4992                 :             :     {
    4993                 :             :       /* We need to walk BINFO_BASE_BINFO to find the access of the primary
    4994                 :             :          base, if it is direct.  Indirect base fields are private.  */
    4995                 :     1390989 :       tree primary_access = access_private_node;
    4996                 :     1391856 :       for (int i = 0; i < n_baseclasses; ++i)
    4997                 :             :         {
    4998                 :     1391787 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    4999                 :     1391787 :           if (base_binfo == primary_binfo)
    5000                 :             :             {
    5001                 :     1390920 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    5002                 :     1390920 :               break;
    5003                 :             :             }
    5004                 :             :         }
    5005                 :     1390989 :       next_field = build_base_field (rli, primary_binfo,
    5006                 :             :                                      primary_access,
    5007                 :             :                                      offsets, next_field);
    5008                 :             :     }
    5009                 :             : 
    5010                 :             :   /* Now allocate the rest of the bases.  */
    5011                 :    55389009 :   for (int i = 0; i < n_baseclasses; ++i)
    5012                 :             :     {
    5013                 :    19361273 :       tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    5014                 :             : 
    5015                 :             :       /* The primary base was already allocated above, so we don't
    5016                 :             :          need to allocate it again here.  */
    5017                 :    19361273 :       if (base_binfo == primary_binfo)
    5018                 :     1390920 :        continue;
    5019                 :             : 
    5020                 :             :       /* Virtual bases are added at the end (a primary virtual base
    5021                 :             :          will have already been added).  */
    5022                 :    17970353 :       if (BINFO_VIRTUAL_P (base_binfo))
    5023                 :       45858 :         continue;
    5024                 :             : 
    5025                 :    17924495 :       next_field = build_base_field (rli, base_binfo,
    5026                 :    17924495 :                                      BINFO_BASE_ACCESS (binfo, i),
    5027                 :             :                                      offsets, next_field);
    5028                 :             :     }
    5029                 :    36027736 : }
    5030                 :             : 
    5031                 :             : /* Go through the TYPE_FIELDS of T issuing any appropriate
    5032                 :             :    diagnostics, figuring out which methods override which other
    5033                 :             :    methods, and so forth.  */
    5034                 :             : 
    5035                 :             : static void
    5036                 :    36027736 : check_methods (tree t)
    5037                 :             : {
    5038                 :   254117928 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    5039                 :   218090192 :     if (DECL_DECLARES_FUNCTION_P (x))
    5040                 :             :       {
    5041                 :   111722573 :         check_for_override (x, t);
    5042                 :             : 
    5043                 :   111722573 :         if (DECL_PURE_VIRTUAL_P (x)
    5044                 :   111722573 :             && (TREE_CODE (x) != FUNCTION_DECL || ! DECL_VINDEX (x)))
    5045                 :           3 :           error ("initializer specified for non-virtual method %q+D", x);
    5046                 :             :         /* The name of the field is the original field name
    5047                 :             :            Save this in auxiliary field for later overloading.  */
    5048                 :   111722573 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    5049                 :             :           {
    5050                 :     5772121 :             TYPE_POLYMORPHIC_P (t) = 1;
    5051                 :     5772121 :             if (DECL_PURE_VIRTUAL_P (x))
    5052                 :      626567 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    5053                 :             :           }
    5054                 :             : 
    5055                 :   111722573 :         if (!DECL_VIRTUAL_P (x)
    5056                 :   217673041 :             && lookup_attribute ("transaction_safe_dynamic",
    5057                 :   105950468 :                                  DECL_ATTRIBUTES (x)))
    5058                 :           2 :           error_at (DECL_SOURCE_LOCATION (x),
    5059                 :             :                     "%<transaction_safe_dynamic%> may only be specified for "
    5060                 :             :                     "a virtual function");
    5061                 :             :       }
    5062                 :             : 
    5063                 :             :   /* Check whether the eligible special member functions (P0848) are
    5064                 :             :      user-provided.  add_method arranged that the CLASSTYPE_MEMBER_VEC only
    5065                 :             :      has the eligible ones, unless none are eligible; TYPE_FIELDS also contains
    5066                 :             :      ineligible overloads, which is why this needs to be separate from the loop
    5067                 :             :      above.  */
    5068                 :             : 
    5069                 :    36027736 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5070                 :             :     {
    5071                 :     3505983 :       if (TREE_CODE (dtor) == OVERLOAD)
    5072                 :             :         {
    5073                 :             :           /* P0848: At the end of the definition of a class, overload
    5074                 :             :              resolution is performed among the prospective destructors declared
    5075                 :             :              in that class with an empty argument list to select the destructor
    5076                 :             :              for the class, also known as the selected destructor. The program
    5077                 :             :              is ill-formed if overload resolution fails. */
    5078                 :           6 :           int viable = 0;
    5079                 :          24 :           for (tree fn : ovl_range (dtor))
    5080                 :          12 :             if (constraints_satisfied_p (fn))
    5081                 :           6 :               ++viable;
    5082                 :           6 :           gcc_checking_assert (viable != 1);
    5083                 :             : 
    5084                 :           6 :           auto_diagnostic_group d;
    5085                 :           6 :           if (viable == 0)
    5086                 :           3 :             error_at (location_of (t), "no viable destructor for %qT", t);
    5087                 :             :           else
    5088                 :           3 :             error_at (location_of (t), "destructor for %qT is ambiguous", t);
    5089                 :           6 :           print_candidates (dtor);
    5090                 :             : 
    5091                 :             :           /* Arbitrarily prune the overload set to a single function for
    5092                 :             :              sake of error recovery.  */
    5093                 :           6 :           tree *slot = find_member_slot (t, dtor_identifier);
    5094                 :           6 :           *slot = get_first_fn (dtor);
    5095                 :           6 :         }
    5096                 :     3505977 :       else if (user_provided_p (dtor))
    5097                 :     2751260 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    5098                 :             :     }
    5099                 :             : 
    5100                 :    77006155 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5101                 :             :     {
    5102                 :    23310117 :       if (!user_provided_p (fn))
    5103                 :             :         /* Might be trivial.  */;
    5104                 :    18855582 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5105                 :             :         /* Templates are never special members.  */;
    5106                 :    12041950 :       else if (copy_fn_p (fn)
    5107                 :    12041950 :                && constraints_satisfied_p (fn))
    5108                 :      906901 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    5109                 :    11135049 :       else if (move_fn_p (fn)
    5110                 :    11135049 :                && constraints_satisfied_p (fn))
    5111                 :      825504 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    5112                 :             :     }
    5113                 :             : 
    5114                 :    46643406 :   for (tree fn : ovl_range (get_class_binding_direct (t, assign_op_identifier)))
    5115                 :             :     {
    5116                 :     6785328 :       if (!user_provided_p (fn))
    5117                 :             :         /* Might be trivial.  */;
    5118                 :     3623689 :       else if (TREE_CODE (fn) == TEMPLATE_DECL)
    5119                 :             :         /* Templates are never special members.  */;
    5120                 :     2662077 :       else if (copy_fn_p (fn)
    5121                 :     2662077 :                && constraints_satisfied_p (fn))
    5122                 :      590357 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    5123                 :     2071720 :       else if (move_fn_p (fn)
    5124                 :     2071720 :                && constraints_satisfied_p (fn))
    5125                 :      785820 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    5126                 :             :     }
    5127                 :    36027736 : }
    5128                 :             : 
    5129                 :             : /* FN is constructor, destructor or operator function.  Clone the
    5130                 :             :    declaration to create a NAME'd variant.  NEED_VTT_PARM_P and
    5131                 :             :    OMIT_INHERITED_PARMS_P are relevant if it's a cdtor.  */
    5132                 :             : 
    5133                 :             : static tree
    5134                 :    99210939 : copy_fndecl_with_name (tree fn, tree name, tree_code code,
    5135                 :             :                        bool need_vtt_parm_p, bool omit_inherited_parms_p)
    5136                 :             : {
    5137                 :             :   /* Copy the function.  */
    5138                 :    99210939 :   tree clone = copy_decl (fn);
    5139                 :             :   /* Reset the function name.  */
    5140                 :    99210939 :   DECL_NAME (clone) = name;
    5141                 :             : 
    5142                 :    99210939 :   if (flag_concepts)
    5143                 :             :     /* Clone constraints.  */
    5144                 :    30334228 :     if (tree ci = get_constraints (fn))
    5145                 :     2912044 :       set_constraints (clone, copy_node (ci));
    5146                 :             : 
    5147                 :    99210939 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    5148                 :             :   /* There's no pending inline data for this function.  */
    5149                 :    99210939 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    5150                 :    99210939 :   DECL_PENDING_INLINE_P (clone) = 0;
    5151                 :             : 
    5152                 :    99210939 :   if (name == base_dtor_identifier)
    5153                 :             :     {
    5154                 :             :       /* The base-class destructor is not virtual.  */
    5155                 :     8188623 :       DECL_VIRTUAL_P (clone) = 0;
    5156                 :     8188623 :       DECL_VINDEX (clone) = NULL_TREE;
    5157                 :             :     }
    5158                 :    91022316 :   else if (code != ERROR_MARK)
    5159                 :             :     {
    5160                 :             :       /* Set the operator code.  */
    5161                 :         185 :       const ovl_op_info_t *ovl_op = OVL_OP_INFO (false, code);
    5162                 :         185 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (clone) = ovl_op->ovl_op_code;
    5163                 :             : 
    5164                 :             :       /* The operator could be virtual.  */
    5165                 :         185 :       if (DECL_VIRTUAL_P (clone))
    5166                 :          12 :         IDENTIFIER_VIRTUAL_P (name) = true;
    5167                 :             :    }
    5168                 :             : 
    5169                 :    99210939 :   if (omit_inherited_parms_p)
    5170                 :         120 :     gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (clone));
    5171                 :             : 
    5172                 :             :   /* If there was an in-charge parameter, drop it from the function
    5173                 :             :      type.  */
    5174                 :    99210939 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5175                 :             :     {
    5176                 :     2331531 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5177                 :     2331531 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5178                 :             :       /* Skip the `this' parameter.  */
    5179                 :     2331531 :       parmtypes = TREE_CHAIN (parmtypes);
    5180                 :             :       /* Skip the in-charge parameter.  */
    5181                 :     2331531 :       parmtypes = TREE_CHAIN (parmtypes);
    5182                 :             :       /* And the VTT parm, in a complete [cd]tor.  */
    5183                 :     2331531 :       if (DECL_HAS_VTT_PARM_P (fn) && !need_vtt_parm_p)
    5184                 :     1256817 :         parmtypes = TREE_CHAIN (parmtypes);
    5185                 :     2331531 :       if (omit_inherited_parms_p)
    5186                 :             :         {
    5187                 :             :           /* If we're omitting inherited parms, that just leaves the VTT.  */
    5188                 :         120 :           gcc_assert (need_vtt_parm_p);
    5189                 :         120 :           parmtypes = tree_cons (NULL_TREE, vtt_parm_type, void_list_node);
    5190                 :             :         }
    5191                 :     2331531 :       TREE_TYPE (clone)
    5192                 :     2331531 :         = build_method_type_directly (basetype,
    5193                 :     2331531 :                                       TREE_TYPE (TREE_TYPE (clone)),
    5194                 :             :                                       parmtypes);
    5195                 :     2331531 :       TREE_TYPE (clone)
    5196                 :     2331531 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    5197                 :     2331531 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    5198                 :     2331531 :       TREE_TYPE (clone)
    5199                 :     4663062 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    5200                 :             :     }
    5201                 :             : 
    5202                 :             :   /* Copy the function parameters.  */
    5203                 :    99210939 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    5204                 :             : 
    5205                 :             :   /* Remove the in-charge parameter.  */
    5206                 :    99210939 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    5207                 :             :     {
    5208                 :     2331531 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    5209                 :     2331531 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5210                 :     2331531 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    5211                 :             :     }
    5212                 :             : 
    5213                 :             :   /* And the VTT parm, in a complete [cd]tor.  */
    5214                 :    99210939 :   if (DECL_HAS_VTT_PARM_P (fn))
    5215                 :             :     {
    5216                 :     2331531 :       if (need_vtt_parm_p)
    5217                 :     1074714 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    5218                 :             :       else
    5219                 :             :         {
    5220                 :     2513634 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    5221                 :     1256817 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    5222                 :     1256817 :           DECL_HAS_VTT_PARM_P (clone) = 0;
    5223                 :             :         }
    5224                 :             :     }
    5225                 :             : 
    5226                 :             :   /* A base constructor inheriting from a virtual base doesn't get the
    5227                 :             :      arguments.  */
    5228                 :    99210939 :   if (omit_inherited_parms_p)
    5229                 :         120 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    5230                 :             : 
    5231                 :   307718630 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    5232                 :             :     {
    5233                 :   208507691 :       DECL_CONTEXT (parms) = clone;
    5234                 :   208507691 :       cxx_dup_lang_specific_decl (parms);
    5235                 :             :     }
    5236                 :             : 
    5237                 :             :   /* Create the RTL for this function.  */
    5238                 :    99210939 :   SET_DECL_RTL (clone, NULL);
    5239                 :             : 
    5240                 :             :   /* Regardless of the current scope, this is a member function, so
    5241                 :             :      not at namespace scope.  */
    5242                 :    99210939 :   rest_of_decl_compilation (clone, /*top_level=*/0, at_eof);
    5243                 :             : 
    5244                 :    99210939 :   return clone;
    5245                 :             : }
    5246                 :             : 
    5247                 :             : /* FN is an operator function, create a variant for CODE.  */
    5248                 :             : 
    5249                 :             : tree
    5250                 :         185 : copy_operator_fn (tree fn, tree_code code)
    5251                 :             : {
    5252                 :         185 :   return copy_fndecl_with_name (fn, ovl_op_identifier (code),
    5253                 :         185 :                                 code, false, false);
    5254                 :             : }
    5255                 :             : 
    5256                 :             : /* FN is a constructor or destructor.  Clone the declaration to create
    5257                 :             :    a specialized in-charge or not-in-charge version, as indicated by
    5258                 :             :    NAME.  */
    5259                 :             : 
    5260                 :             : static tree
    5261                 :   113518844 : build_clone (tree fn, tree name, bool need_vtt_parm_p,
    5262                 :             :              bool omit_inherited_parms_p)
    5263                 :             : {
    5264                 :   113518844 :   tree clone;
    5265                 :             : 
    5266                 :             :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    5267                 :   113518844 :   if (TREE_CODE (fn) == TEMPLATE_DECL)
    5268                 :             :     {
    5269                 :    14308090 :       clone = copy_decl (fn);
    5270                 :    14308090 :       DECL_NAME (clone) = name;
    5271                 :             : 
    5272                 :    14308090 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name,
    5273                 :             :                                  need_vtt_parm_p, omit_inherited_parms_p);
    5274                 :    14308090 :       DECL_TEMPLATE_RESULT (clone) = result;
    5275                 :             : 
    5276                 :    14308090 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    5277                 :    14308090 :       DECL_TI_TEMPLATE (result) = clone;
    5278                 :             : 
    5279                 :    14308090 :       TREE_TYPE (clone) = TREE_TYPE (result);
    5280                 :             :     }
    5281                 :             :   else
    5282                 :             :     {
    5283                 :    99210754 :       clone = copy_fndecl_with_name (fn, name, ERROR_MARK,
    5284                 :             :                                      need_vtt_parm_p, omit_inherited_parms_p);
    5285                 :    99210754 :       DECL_CLONED_FUNCTION (clone) = fn;
    5286                 :             : 
    5287                 :    99210754 :       maybe_prepare_return_this (clone);
    5288                 :             :     }
    5289                 :             : 
    5290                 :             :   /* Remember where this function came from.  */
    5291                 :   113518844 :   DECL_ABSTRACT_ORIGIN (clone) = fn;
    5292                 :             : 
    5293                 :             :   /* Make it easy to find the CLONE given the FN.  Note the
    5294                 :             :      template_result of a template will be chained this way too.  */
    5295                 :   113518844 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    5296                 :   113518844 :   DECL_CHAIN (fn) = clone;
    5297                 :             : 
    5298                 :   113518844 :   return clone;
    5299                 :             : }
    5300                 :             : 
    5301                 :             : /* Build the clones of FN, return the number of clones built.  These
    5302                 :             :    will be inserted onto DECL_CHAIN of FN.  */
    5303                 :             : 
    5304                 :             : void
    5305                 :    48815098 : build_cdtor_clones (tree fn, bool needs_vtt_p, bool base_omits_inherited_p,
    5306                 :             :                     bool update_methods)
    5307                 :             : {
    5308                 :    48815098 :   unsigned count = 0;
    5309                 :             : 
    5310                 :    48815098 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
    5311                 :             :     {
    5312                 :             :       /* For each constructor, we need two variants: an in-charge version
    5313                 :             :          and a not-in-charge version.  */
    5314                 :    40626475 :       build_clone (fn, complete_ctor_identifier, false, false);
    5315                 :    40626475 :       build_clone (fn, base_ctor_identifier, needs_vtt_p,
    5316                 :             :                    base_omits_inherited_p);
    5317                 :    40626475 :       count += 2;
    5318                 :             :     }
    5319                 :             :   else
    5320                 :             :     {
    5321                 :     8188623 :       gcc_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn));
    5322                 :             : 
    5323                 :             :       /* For each destructor, we need three variants: an in-charge
    5324                 :             :          version, a not-in-charge version, and an in-charge deleting
    5325                 :             :          version.  We clone the deleting version first because that
    5326                 :             :          means it will go second on the TYPE_FIELDS list -- and that
    5327                 :             :          corresponds to the correct layout order in the virtual
    5328                 :             :          function table.
    5329                 :             : 
    5330                 :             :          For a non-virtual destructor, we do not build a deleting
    5331                 :             :          destructor.  */
    5332                 :     8188623 :       if (DECL_VIRTUAL_P (fn))
    5333                 :             :         {
    5334                 :     1580558 :           build_clone (fn, deleting_dtor_identifier, false, false);
    5335                 :     1580558 :           count++;
    5336                 :             :         }
    5337                 :     8188623 :       build_clone (fn, complete_dtor_identifier, false, false);
    5338                 :     8188623 :       build_clone (fn, base_dtor_identifier, needs_vtt_p, false);
    5339                 :     8188623 :       count += 2;
    5340                 :             :     }
    5341                 :             : 
    5342                 :             :   /* The original is now an abstract function that is never
    5343                 :             :      emitted.  */
    5344                 :    48815098 :   DECL_ABSTRACT_P (fn) = true;
    5345                 :             : 
    5346                 :    48815098 :   if (update_methods)
    5347                 :   124315530 :     for (tree clone = fn; count--;)
    5348                 :             :       {
    5349                 :    83403304 :         clone = DECL_CHAIN (clone);
    5350                 :    83403304 :         add_method (DECL_CONTEXT (clone), clone, false);
    5351                 :             :       }
    5352                 :    48815098 : }
    5353                 :             : 
    5354                 :             : /* Produce declarations for all appropriate clones of FN.  If
    5355                 :             :    UPDATE_METHODS is true, the clones are added to the
    5356                 :             :    CLASSTYPE_MEMBER_VEC.  */
    5357                 :             : 
    5358                 :             : void
    5359                 :    49027351 : clone_cdtor (tree fn, bool update_methods)
    5360                 :             : {
    5361                 :             :   /* Avoid inappropriate cloning.  */
    5362                 :    49027351 :   if (DECL_CHAIN (fn)
    5363                 :    49027351 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    5364                 :             :     return;
    5365                 :             : 
    5366                 :             :   /* Base cdtors need a vtt parm if there are virtual bases.  */
    5367                 :    48772875 :   bool vtt = CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn));
    5368                 :             : 
    5369                 :             :   /* Base ctor omits inherited parms it needs a vttparm and inherited
    5370                 :             :      from a virtual nase ctor.  */
    5371                 :    48772875 :   bool base_omits_inherited = (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
    5372                 :    48772875 :                                && base_ctor_omit_inherited_parms (fn));
    5373                 :             : 
    5374                 :    48772875 :   build_cdtor_clones (fn, vtt, base_omits_inherited, update_methods);
    5375                 :             : }
    5376                 :             : 
    5377                 :             : /* DECL is an in charge constructor, which is being defined. This will
    5378                 :             :    have had an in class declaration, from whence clones were
    5379                 :             :    declared. An out-of-class definition can specify additional default
    5380                 :             :    arguments. As it is the clones that are involved in overload
    5381                 :             :    resolution, we must propagate the information from the DECL to its
    5382                 :             :    clones.  */
    5383                 :             : 
    5384                 :             : void
    5385                 :    17189344 : adjust_clone_args (tree decl)
    5386                 :             : {
    5387                 :    17189344 :   tree clone;
    5388                 :             : 
    5389                 :    27518854 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    5390                 :    10329510 :        clone = DECL_CHAIN (clone))
    5391                 :             :     {
    5392                 :    10329510 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    5393                 :    10329510 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    5394                 :    10329510 :       tree decl_parms, clone_parms;
    5395                 :             : 
    5396                 :             :       /* Skip the 'this' parameter.  */
    5397                 :    10329510 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    5398                 :    10329510 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5399                 :             : 
    5400                 :    10329510 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    5401                 :       21108 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5402                 :    10329510 :       if (DECL_HAS_VTT_PARM_P (decl))
    5403                 :       21108 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    5404                 :             : 
    5405                 :    10329510 :       clone_parms = orig_clone_parms;
    5406                 :    10329510 :       if (DECL_HAS_VTT_PARM_P (clone))
    5407                 :       10554 :         clone_parms = TREE_CHAIN (clone_parms);
    5408                 :             : 
    5409                 :    20440488 :       for (decl_parms = orig_decl_parms; decl_parms;
    5410                 :    10110978 :            decl_parms = TREE_CHAIN (decl_parms),
    5411                 :    10110978 :              clone_parms = TREE_CHAIN (clone_parms))
    5412                 :             :         {
    5413                 :    20438854 :           if (clone_parms == void_list_node)
    5414                 :             :             {
    5415                 :    10327852 :               gcc_assert (decl_parms == clone_parms
    5416                 :             :                           || ctor_omit_inherited_parms (clone));
    5417                 :             :               break;
    5418                 :             :             }
    5419                 :             : 
    5420                 :    10111002 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    5421                 :             :                                             TREE_VALUE (clone_parms)));
    5422                 :             : 
    5423                 :    11002204 :           if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
    5424                 :             :             {
    5425                 :             :               /* A default parameter has been added. Adjust the
    5426                 :             :                  clone's parameters.  */
    5427                 :          24 :               clone_parms = orig_decl_parms;
    5428                 :             : 
    5429                 :          24 :               if (DECL_HAS_VTT_PARM_P (clone))
    5430                 :             :                 {
    5431                 :           3 :                   clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
    5432                 :           3 :                                            TREE_VALUE (orig_clone_parms),
    5433                 :             :                                            clone_parms);
    5434                 :           3 :                   TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
    5435                 :             :                 }
    5436                 :             : 
    5437                 :          24 :               tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    5438                 :          24 :               tree type
    5439                 :          24 :                 = build_method_type_directly (basetype,
    5440                 :          24 :                                               TREE_TYPE (TREE_TYPE (clone)),
    5441                 :             :                                               clone_parms);
    5442                 :          24 :               if (tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone)))
    5443                 :           0 :                 type = cp_build_type_attribute_variant (type, attrs);
    5444                 :          24 :               type = cxx_copy_lang_qualifiers (type, TREE_TYPE (clone));
    5445                 :          24 :               TREE_TYPE (clone) = type;
    5446                 :             : 
    5447                 :          24 :               clone_parms = NULL_TREE;
    5448                 :          24 :               break;
    5449                 :             :             }
    5450                 :             :         }
    5451                 :    10329510 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    5452                 :             :     }
    5453                 :    17189344 : }
    5454                 :             : 
    5455                 :             : /* For each of the constructors and destructors in T, create an
    5456                 :             :    in-charge and not-in-charge variant.  */
    5457                 :             : 
    5458                 :             : static void
    5459                 :    36027736 : clone_constructors_and_destructors (tree t)
    5460                 :             : {
    5461                 :             :   /* We do not need to propagate the usingness to the clone, at this
    5462                 :             :      point that is not needed.  */
    5463                 :    77478886 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5464                 :    23546487 :     clone_cdtor (fn, /*update_methods=*/true);
    5465                 :             : 
    5466                 :    36027736 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5467                 :     3671660 :     clone_cdtor (dtor, /*update_methods=*/true);
    5468                 :    36027736 : }
    5469                 :             : 
    5470                 :             : /* Deduce noexcept for a destructor DTOR.  */
    5471                 :             : 
    5472                 :             : void
    5473                 :     3566788 : deduce_noexcept_on_destructor (tree dtor)
    5474                 :             : {
    5475                 :     3566788 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    5476                 :     2313668 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    5477                 :             :                                                 noexcept_deferred_spec);
    5478                 :     3566788 : }
    5479                 :             : 
    5480                 :             : /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
    5481                 :             :    of TYPE for virtual functions which FNDECL overrides.  Return a
    5482                 :             :    mask of the tm attributes found therein.  */
    5483                 :             : 
    5484                 :             : static int
    5485                 :         925 : look_for_tm_attr_overrides (tree type, tree fndecl)
    5486                 :             : {
    5487                 :         925 :   tree binfo = TYPE_BINFO (type);
    5488                 :         925 :   tree base_binfo;
    5489                 :         925 :   int ix, found = 0;
    5490                 :             : 
    5491                 :        1549 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ++ix)
    5492                 :             :     {
    5493                 :         624 :       tree o, basetype = BINFO_TYPE (base_binfo);
    5494                 :             : 
    5495                 :         624 :       if (!TYPE_POLYMORPHIC_P (basetype))
    5496                 :          48 :         continue;
    5497                 :             : 
    5498                 :         576 :       o = look_for_overrides_here (basetype, fndecl);
    5499                 :         576 :       if (o)
    5500                 :             :         {
    5501                 :         411 :           if (lookup_attribute ("transaction_safe_dynamic",
    5502                 :         411 :                                 DECL_ATTRIBUTES (o)))
    5503                 :             :             /* transaction_safe_dynamic is not inherited.  */;
    5504                 :             :           else
    5505                 :         311 :             found |= tm_attr_to_mask (find_tm_attribute
    5506                 :         311 :                                       (TYPE_ATTRIBUTES (TREE_TYPE (o))));
    5507                 :             :         }
    5508                 :             :       else
    5509                 :         165 :         found |= look_for_tm_attr_overrides (basetype, fndecl);
    5510                 :             :     }
    5511                 :             : 
    5512                 :         925 :   return found;
    5513                 :             : }
    5514                 :             : 
    5515                 :             : /* Subroutine of set_method_tm_attributes.  Handle the checks and
    5516                 :             :    inheritance for one virtual method FNDECL.  */
    5517                 :             : 
    5518                 :             : static void
    5519                 :         760 : set_one_vmethod_tm_attributes (tree type, tree fndecl)
    5520                 :             : {
    5521                 :         760 :   tree tm_attr;
    5522                 :         760 :   int found, have;
    5523                 :             : 
    5524                 :         760 :   found = look_for_tm_attr_overrides (type, fndecl);
    5525                 :             : 
    5526                 :             :   /* If FNDECL doesn't actually override anything (i.e. T is the
    5527                 :             :      class that first declares FNDECL virtual), then we're done.  */
    5528                 :         760 :   if (found == 0)
    5529                 :             :     return;
    5530                 :             : 
    5531                 :          45 :   tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl)));
    5532                 :          45 :   have = tm_attr_to_mask (tm_attr);
    5533                 :             : 
    5534                 :             :   /* Intel STM Language Extension 3.0, Section 4.2 table 4:
    5535                 :             :      tm_pure must match exactly, otherwise no weakening of
    5536                 :             :      tm_safe > tm_callable > nothing.  */
    5537                 :             :   /* ??? The tm_pure attribute didn't make the transition to the
    5538                 :             :      multivendor language spec.  */
    5539                 :          45 :   if (have == TM_ATTR_PURE)
    5540                 :             :     {
    5541                 :           0 :       if (found != TM_ATTR_PURE)
    5542                 :             :         {
    5543                 :           0 :           found &= -found;
    5544                 :           0 :           goto err_override;
    5545                 :             :         }
    5546                 :             :     }
    5547                 :             :   /* If the overridden function is tm_pure, then FNDECL must be.  */
    5548                 :          45 :   else if (found == TM_ATTR_PURE && tm_attr)
    5549                 :           6 :     goto err_override;
    5550                 :             :   /* Look for base class combinations that cannot be satisfied.  */
    5551                 :          39 :   else if (found != TM_ATTR_PURE && (found & TM_ATTR_PURE))
    5552                 :             :     {
    5553                 :           0 :       found &= ~TM_ATTR_PURE;
    5554                 :           0 :       found &= -found;
    5555                 :           0 :       error_at (DECL_SOURCE_LOCATION (fndecl),
    5556                 :             :                 "method overrides both %<transaction_pure%> and %qE methods",
    5557                 :             :                 tm_mask_to_attr (found));
    5558                 :             :     }
    5559                 :             :   /* If FNDECL did not declare an attribute, then inherit the most
    5560                 :             :      restrictive one.  */
    5561                 :          39 :   else if (tm_attr == NULL)
    5562                 :             :     {
    5563                 :          14 :       apply_tm_attr (fndecl, tm_mask_to_attr (least_bit_hwi (found)));
    5564                 :             :     }
    5565                 :             :   /* Otherwise validate that we're not weaker than a function
    5566                 :             :      that is being overridden.  */
    5567                 :             :   else
    5568                 :             :     {
    5569                 :          25 :       found &= -found;
    5570                 :          25 :       if (found <= TM_ATTR_CALLABLE && have > found)
    5571                 :           9 :         goto err_override;
    5572                 :             :     }
    5573                 :             :   return;
    5574                 :             : 
    5575                 :          15 :  err_override:
    5576                 :          15 :   error_at (DECL_SOURCE_LOCATION (fndecl),
    5577                 :             :             "method declared %qE overriding %qE method",
    5578                 :             :             tm_attr, tm_mask_to_attr (found));
    5579                 :             : }
    5580                 :             : 
    5581                 :             : /* For each of the methods in T, propagate a class-level tm attribute.  */
    5582                 :             : 
    5583                 :             : static void
    5584                 :    36027736 : set_method_tm_attributes (tree t)
    5585                 :             : {
    5586                 :    36027736 :   tree class_tm_attr, fndecl;
    5587                 :             : 
    5588                 :             :   /* Don't bother collecting tm attributes if transactional memory
    5589                 :             :      support is not enabled.  */
    5590                 :    36027736 :   if (!flag_tm)
    5591                 :             :     return;
    5592                 :             : 
    5593                 :             :   /* Process virtual methods first, as they inherit directly from the
    5594                 :             :      base virtual function and also require validation of new attributes.  */
    5595                 :        3590 :   if (TYPE_CONTAINS_VPTR_P (t))
    5596                 :             :     {
    5597                 :         200 :       tree vchain;
    5598                 :         960 :       for (vchain = BINFO_VIRTUALS (TYPE_BINFO (t)); vchain;
    5599                 :         760 :            vchain = TREE_CHAIN (vchain))
    5600                 :             :         {
    5601                 :         760 :           fndecl = BV_FN (vchain);
    5602                 :         760 :           if (DECL_THUNK_P (fndecl))
    5603                 :           3 :             fndecl = THUNK_TARGET (fndecl);
    5604                 :         760 :           set_one_vmethod_tm_attributes (t, fndecl);
    5605                 :             :         }
    5606                 :             :     }
    5607                 :             : 
    5608                 :             :   /* If the class doesn't have an attribute, nothing more to do.  */
    5609                 :        3590 :   class_tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (t));
    5610                 :        3590 :   if (class_tm_attr == NULL)
    5611                 :             :     return;
    5612                 :             : 
    5613                 :             :   /* Any method that does not yet have a tm attribute inherits
    5614                 :             :      the one from the class.  */
    5615                 :         108 :   for (fndecl = TYPE_FIELDS (t); fndecl; fndecl = DECL_CHAIN (fndecl))
    5616                 :          45 :     if (DECL_DECLARES_FUNCTION_P (fndecl)
    5617                 :          81 :         && !find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
    5618                 :          21 :       apply_tm_attr (fndecl, class_tm_attr);
    5619                 :             : }
    5620                 :             : 
    5621                 :             : /* Returns true if FN is a default constructor.  */
    5622                 :             : 
    5623                 :             : bool
    5624                 :    14248761 : default_ctor_p (const_tree fn)
    5625                 :             : {
    5626                 :    14248761 :   return (DECL_CONSTRUCTOR_P (fn)
    5627                 :    14248761 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
    5628                 :             : }
    5629                 :             : 
    5630                 :             : /* Returns true iff class T has a user-provided constructor that can be called
    5631                 :             :    with more than zero arguments.  */
    5632                 :             : 
    5633                 :             : bool
    5634                 :          55 : type_has_user_nondefault_constructor (tree t)
    5635                 :             : {
    5636                 :          55 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5637                 :             :     return false;
    5638                 :             : 
    5639                 :          65 :   for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (t)))
    5640                 :             :     {
    5641                 :          34 :       if (user_provided_p (fn)
    5642                 :          34 :           && (TREE_CODE (fn) == TEMPLATE_DECL
    5643                 :          18 :               || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
    5644                 :             :                   != NULL_TREE)))
    5645                 :           3 :         return true;
    5646                 :             :     }
    5647                 :             : 
    5648                 :          18 :   return false;
    5649                 :             : }
    5650                 :             : 
    5651                 :             : /* Returns the defaulted constructor if T has one. Otherwise, returns
    5652                 :             :    NULL_TREE.  */
    5653                 :             : 
    5654                 :             : tree
    5655                 :          62 : in_class_defaulted_default_constructor (tree t)
    5656                 :             : {
    5657                 :          62 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5658                 :             :     return NULL_TREE;
    5659                 :             : 
    5660                 :         123 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5661                 :             :     {
    5662                 :          78 :       tree fn = *iter;
    5663                 :             : 
    5664                 :         156 :       if (DECL_DEFAULTED_IN_CLASS_P (fn)
    5665                 :         114 :           && default_ctor_p (fn))
    5666                 :          33 :         return fn;
    5667                 :             :     }
    5668                 :             : 
    5669                 :           0 :   return NULL_TREE;
    5670                 :             : }
    5671                 :             : 
    5672                 :             : /* Returns true iff FN is a user-provided function, i.e. user-declared
    5673                 :             :    and not defaulted at its first declaration.  */
    5674                 :             : 
    5675                 :             : bool
    5676                 :    85403905 : user_provided_p (tree fn)
    5677                 :             : {
    5678                 :    85403905 :   fn = STRIP_TEMPLATE (fn);
    5679                 :    85403905 :   return (!DECL_ARTIFICIAL (fn)
    5680                 :    85403905 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5681                 :    70342064 :                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
    5682                 :             : }
    5683                 :             : 
    5684                 :             : /* Returns true iff class T has a user-provided constructor.  */
    5685                 :             : 
    5686                 :             : bool
    5687                 :    36027874 : type_has_user_provided_constructor (tree t)
    5688                 :             : {
    5689                 :    36027874 :   if (!CLASS_TYPE_P (t))
    5690                 :             :     return false;
    5691                 :             : 
    5692                 :    36027818 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5693                 :             :     return false;
    5694                 :             : 
    5695                 :     8019729 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5696                 :     6689480 :     if (user_provided_p (*iter))
    5697                 :     5359707 :       return true;
    5698                 :             : 
    5699                 :      429555 :   return false;
    5700                 :             : }
    5701                 :             : 
    5702                 :             : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5703                 :             : 
    5704                 :             : bool
    5705                 :    33333897 : type_has_user_provided_or_explicit_constructor (tree t)
    5706                 :             : {
    5707                 :    33333897 :   if (!CLASS_TYPE_P (t))
    5708                 :             :     return false;
    5709                 :             : 
    5710                 :    33333897 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5711                 :             :     return false;
    5712                 :             : 
    5713                 :     8080940 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5714                 :             :     {
    5715                 :     6690237 :       tree fn = *iter;
    5716                 :     6690237 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5717                 :     5299981 :         return true;
    5718                 :             :     }
    5719                 :             : 
    5720                 :      343985 :   return false;
    5721                 :             : }
    5722                 :             : 
    5723                 :             : /* Returns true iff class T has a non-user-provided (i.e. implicitly
    5724                 :             :    declared or explicitly defaulted in the class body) default
    5725                 :             :    constructor.  */
    5726                 :             : 
    5727                 :             : bool
    5728                 :     2981370 : type_has_non_user_provided_default_constructor (tree t)
    5729                 :             : {
    5730                 :     2981370 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5731                 :             :     return false;
    5732                 :     2981334 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5733                 :             :     return true;
    5734                 :             : 
    5735                 :    20729929 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5736                 :             :     {
    5737                 :    10977490 :       tree fn = *iter;
    5738                 :    10977490 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5739                 :     7580017 :           && default_ctor_p (fn)
    5740                 :    13910097 :           && !user_provided_p (fn))
    5741                 :     1226285 :         return true;
    5742                 :             :     }
    5743                 :             : 
    5744                 :     1754157 :   return false;
    5745                 :             : }
    5746                 :             : 
    5747                 :             : /* TYPE is being used as a virtual base, and has a non-trivial move
    5748                 :             :    assignment.  Return true if this is due to there being a user-provided
    5749                 :             :    move assignment in TYPE or one of its subobjects; if there isn't, then
    5750                 :             :    multiple move assignment can't cause any harm.  */
    5751                 :             : 
    5752                 :             : bool
    5753                 :          21 : vbase_has_user_provided_move_assign (tree type)
    5754                 :             : {
    5755                 :             :   /* Does the type itself have a user-provided move assignment operator?  */
    5756                 :          21 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type))
    5757                 :          30 :     for (ovl_iterator iter (get_class_binding_direct
    5758                 :          21 :                             (type, assign_op_identifier));
    5759                 :          51 :          iter; ++iter)
    5760                 :          42 :       if (user_provided_p (*iter) && move_fn_p (*iter))
    5761                 :          12 :         return true;
    5762                 :             : 
    5763                 :             :   /* Do any of its bases?  */
    5764                 :           9 :   tree binfo = TYPE_BINFO (type);
    5765                 :           9 :   tree base_binfo;
    5766                 :          12 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    5767                 :           6 :     if (vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    5768                 :             :       return true;
    5769                 :             : 
    5770                 :             :   /* Or non-static data members?  */
    5771                 :          27 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5772                 :             :     {
    5773                 :          21 :       if (TREE_CODE (field) == FIELD_DECL
    5774                 :           3 :           && CLASS_TYPE_P (TREE_TYPE (field))
    5775                 :          21 :           && vbase_has_user_provided_move_assign (TREE_TYPE (field)))
    5776                 :             :         return true;
    5777                 :             :     }
    5778                 :             : 
    5779                 :             :   /* Seems not.  */
    5780                 :             :   return false;
    5781                 :             : }
    5782                 :             : 
    5783                 :             : /* If default-initialization leaves part of TYPE uninitialized, returns
    5784                 :             :    a DECL for the field or TYPE itself (DR 253).  */
    5785                 :             : 
    5786                 :             : tree
    5787                 :      778312 : default_init_uninitialized_part (tree type)
    5788                 :             : {
    5789                 :      778312 :   tree t, r, binfo;
    5790                 :      778312 :   int i;
    5791                 :             : 
    5792                 :      778312 :   type = strip_array_types (type);
    5793                 :      778312 :   if (!CLASS_TYPE_P (type))
    5794                 :             :     return type;
    5795                 :      664187 :   if (!type_has_non_user_provided_default_constructor (type))
    5796                 :             :     return NULL_TREE;
    5797                 :      516268 :   for (binfo = TYPE_BINFO (type), i = 0;
    5798                 :      516268 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5799                 :             :     {
    5800                 :       39805 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5801                 :       39805 :       if (r)
    5802                 :           5 :         return r;
    5803                 :             :     }
    5804                 :      520861 :   for (t = next_aggregate_field (TYPE_FIELDS (type)); t;
    5805                 :       44398 :        t = next_aggregate_field (DECL_CHAIN (t)))
    5806                 :      154488 :     if (!DECL_INITIAL (t) && !DECL_ARTIFICIAL (t))
    5807                 :             :       {
    5808                 :      110162 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    5809                 :      110162 :         if (r)
    5810                 :      220166 :           return DECL_P (r) ? r : t;
    5811                 :             :       }
    5812                 :             : 
    5813                 :             :   return NULL_TREE;
    5814                 :             : }
    5815                 :             : 
    5816                 :             : /* Returns true iff for class T, a trivial synthesized default constructor
    5817                 :             :    would be constexpr.  */
    5818                 :             : 
    5819                 :             : bool
    5820                 :    32419486 : trivial_default_constructor_is_constexpr (tree t)
    5821                 :             : {
    5822                 :             :   /* A defaulted trivial default constructor is constexpr
    5823                 :             :      if there is nothing to initialize.  */
    5824                 :    32419486 :   gcc_assert (!TYPE_HAS_COMPLEX_DFLT (t));
    5825                 :             :   /* A class with a vptr doesn't have a trivial default ctor.
    5826                 :             :      In C++20, a class can have transient uninitialized members, e.g.:
    5827                 :             : 
    5828                 :             :        struct S { int i; constexpr S() = default; };
    5829                 :             : 
    5830                 :             :      should work.  */
    5831                 :    32419486 :   return (cxx_dialect >= cxx20
    5832                 :    32419486 :           || is_really_empty_class (t, /*ignore_vptr*/true));
    5833                 :             : }
    5834                 :             : 
    5835                 :             : /* Returns true iff class T has a constexpr default constructor.  */
    5836                 :             : 
    5837                 :             : bool
    5838                 :    29886200 : type_has_constexpr_default_constructor (tree t)
    5839                 :             : {
    5840                 :    29886200 :   tree fns;
    5841                 :             : 
    5842                 :    29886200 :   if (!CLASS_TYPE_P (t))
    5843                 :             :     {
    5844                 :             :       /* The caller should have stripped an enclosing array.  */
    5845                 :         217 :       gcc_assert (TREE_CODE (t) != ARRAY_TYPE);
    5846                 :             :       return false;
    5847                 :             :     }
    5848                 :    29885983 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5849                 :             :     {
    5850                 :    29882508 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5851                 :    29882450 :         return trivial_default_constructor_is_constexpr (t);
    5852                 :             :       /* Non-trivial, we need to check subobject constructors.  */
    5853                 :          58 :       lazily_declare_fn (sfk_constructor, t);
    5854                 :             :     }
    5855                 :        3533 :   fns = locate_ctor (t);
    5856                 :        3533 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5857                 :             : }
    5858                 :             : 
    5859                 :             : /* Returns true iff class T has a constexpr default constructor or has an
    5860                 :             :    implicitly declared default constructor that we can't tell if it's constexpr
    5861                 :             :    without forcing a lazy declaration (which might cause undesired
    5862                 :             :    instantiations).  */
    5863                 :             : 
    5864                 :             : static bool
    5865                 :    30188166 : type_maybe_constexpr_default_constructor (tree t)
    5866                 :             : {
    5867                 :    30188166 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    5868                 :    60376332 :       && TYPE_HAS_COMPLEX_DFLT (t))
    5869                 :             :     /* Assume it's constexpr.  */
    5870                 :             :     return true;
    5871                 :    29882450 :   return type_has_constexpr_default_constructor (t);
    5872                 :             : }
    5873                 :             : 
    5874                 :             : /* Returns true iff class T has a constexpr destructor.  */
    5875                 :             : 
    5876                 :             : bool
    5877                 :         288 : type_has_constexpr_destructor (tree t)
    5878                 :             : {
    5879                 :         288 :   tree fns;
    5880                 :             : 
    5881                 :         288 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    5882                 :             :     /* Non-trivial, we need to check subobject destructors.  */
    5883                 :          10 :     lazily_declare_fn (sfk_destructor, t);
    5884                 :         288 :   fns = CLASSTYPE_DESTRUCTOR (t);
    5885                 :         288 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5886                 :             : }
    5887                 :             : 
    5888                 :             : /* Returns true iff class T has a constexpr destructor or has an
    5889                 :             :    implicitly declared destructor that we can't tell if it's constexpr
    5890                 :             :    without forcing a lazy declaration (which might cause undesired
    5891                 :             :    instantiations).  */
    5892                 :             : 
    5893                 :             : static bool
    5894                 :    33382837 : type_maybe_constexpr_destructor (tree t)
    5895                 :             : {
    5896                 :             :   /* Until C++20, only trivial destruction is constexpr.  */
    5897                 :    33382837 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (t))
    5898                 :             :     return true;
    5899                 :     1116159 :   if (cxx_dialect < cxx20)
    5900                 :             :     return false;
    5901                 :      349850 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    5902                 :             :     /* Assume it's constexpr.  */
    5903                 :             :     return true;
    5904                 :      303049 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    5905                 :      303049 :   return (fn && maybe_constexpr_fn (fn));
    5906                 :             : }
    5907                 :             : 
    5908                 :             : /* Returns true iff class TYPE has a virtual destructor.  */
    5909                 :             : 
    5910                 :             : bool
    5911                 :     3103820 : type_has_virtual_destructor (tree type)
    5912                 :             : {
    5913                 :     3103820 :   tree dtor;
    5914                 :             : 
    5915                 :     3103820 :   if (!NON_UNION_CLASS_TYPE_P (type))
    5916                 :             :     return false;
    5917                 :             : 
    5918                 :     3103701 :   gcc_assert (COMPLETE_TYPE_P (type));
    5919                 :     3103701 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    5920                 :     3103701 :   return (dtor && DECL_VIRTUAL_P (dtor));
    5921                 :             : }
    5922                 :             : 
    5923                 :             : /* True iff class TYPE has a non-deleted trivial default
    5924                 :             :    constructor.  */
    5925                 :             : 
    5926                 :             : bool
    5927                 :       26283 : type_has_non_deleted_trivial_default_ctor (tree type)
    5928                 :             : {
    5929                 :       26283 :   return TYPE_HAS_TRIVIAL_DFLT (type) && locate_ctor (type);
    5930                 :             : }
    5931                 :             : 
    5932                 :             : /* Returns true iff T, a class, has a move-assignment or
    5933                 :             :    move-constructor.  Does not lazily declare either.
    5934                 :             :    If USER_P is false, any move function will do.  If it is true, the
    5935                 :             :    move function must be user-declared.
    5936                 :             : 
    5937                 :             :    Note that user-declared here is different from "user-provided",
    5938                 :             :    which doesn't include functions that are defaulted in the
    5939                 :             :    class.  */
    5940                 :             : 
    5941                 :             : bool
    5942                 :    37186606 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    5943                 :             : {
    5944                 :    37186606 :   gcc_assert (user_p
    5945                 :             :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    5946                 :             :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    5947                 :             : 
    5948                 :    37186606 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    5949                 :    44365940 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5950                 :     7558091 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    5951                 :      913288 :         return true;
    5952                 :             : 
    5953                 :    36273318 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    5954                 :      940577 :     for (ovl_iterator iter (get_class_binding_direct
    5955                 :    32916552 :                             (t, assign_op_identifier));
    5956                 :    33857129 :          iter; ++iter)
    5957                 :      907149 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    5958                 :      108121 :           && DECL_CONTEXT (*iter) == t
    5959                 :     1003104 :           && move_fn_p (*iter))
    5960                 :        1489 :         return true;
    5961                 :             :   
    5962                 :             :   return false;
    5963                 :             : }
    5964                 :             : 
    5965                 :             : /* True iff T has a move constructor that is not deleted.  */
    5966                 :             : 
    5967                 :             : bool
    5968                 :           6 : classtype_has_non_deleted_move_ctor (tree t)
    5969                 :             : {
    5970                 :           6 :   if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    5971                 :           0 :     lazily_declare_fn (sfk_move_constructor, t);
    5972                 :           6 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5973                 :           6 :     if (move_fn_p (*iter) && !DECL_DELETED_FN (*iter))
    5974                 :           6 :       return true;
    5975                 :           0 :   return false;
    5976                 :             : }
    5977                 :             : 
    5978                 :             : /* If T, a class, has a user-provided copy constructor, copy assignment
    5979                 :             :    operator, or destructor, returns that function.  Otherwise, null.  */
    5980                 :             : 
    5981                 :             : tree
    5982                 :     4477347 : classtype_has_depr_implicit_copy (tree t)
    5983                 :             : {
    5984                 :     4477347 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    5985                 :    11526762 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5986                 :             :       {
    5987                 :     5740441 :         tree fn = *iter;
    5988                 :     5740441 :         if (user_provided_p (fn) && copy_fn_p (fn))
    5989                 :         768 :           return fn;
    5990                 :             :       }
    5991                 :             : 
    5992                 :     4476579 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    5993                 :      837980 :     for (ovl_iterator iter (get_class_binding_direct
    5994                 :     1283328 :                             (t, assign_op_identifier));
    5995                 :     2121308 :          iter; ++iter)
    5996                 :             :       {
    5997                 :      838359 :         tree fn = *iter;
    5998                 :      838359 :         if (DECL_CONTEXT (fn) == t
    5999                 :      838359 :             && user_provided_p (fn) && copy_fn_p (fn))
    6000                 :         379 :           return fn;
    6001                 :             :       }
    6002                 :             : 
    6003                 :     4476200 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    6004                 :             :     {
    6005                 :     1458046 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    6006                 :     1458046 :       if (user_provided_p (fn))
    6007                 :             :         return fn;
    6008                 :             :     }
    6009                 :             : 
    6010                 :             :   return NULL_TREE;
    6011                 :             : }
    6012                 :             : 
    6013                 :             : /* True iff T has a member or friend declaration of operator OP.  */
    6014                 :             : 
    6015                 :             : bool
    6016                 :    36027736 : classtype_has_op (tree t, tree_code op)
    6017                 :             : {
    6018                 :    36027736 :   tree name = ovl_op_identifier (op);
    6019                 :    36027736 :   if (get_class_binding (t, name))
    6020                 :             :     return true;
    6021                 :    37339333 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6022                 :     2130900 :     if (FRIEND_NAME (f) == name)
    6023                 :             :       return true;
    6024                 :             :   return false;
    6025                 :             : }
    6026                 :             : 
    6027                 :             : 
    6028                 :             : /* If T has a defaulted member or friend declaration of OP, return it.  */
    6029                 :             : 
    6030                 :             : tree
    6031                 :    35208433 : classtype_has_defaulted_op (tree t, tree_code op)
    6032                 :             : {
    6033                 :    35208433 :   tree name = ovl_op_identifier (op);
    6034                 :    35208468 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    6035                 :             :     {
    6036                 :         192 :       tree fn = *oi;
    6037                 :         192 :       if (DECL_DEFAULTED_FN (fn))
    6038                 :         162 :         return fn;
    6039                 :             :     }
    6040                 :    35750064 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    6041                 :      541816 :     if (FRIEND_NAME (f) == name)
    6042                 :         187 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    6043                 :             :         {
    6044                 :         110 :           tree fn = TREE_VALUE (l);
    6045                 :         110 :           if (DECL_DEFAULTED_FN (fn))
    6046                 :          23 :             return fn;
    6047                 :             :         }
    6048                 :             :   return NULL_TREE;
    6049                 :             : }
    6050                 :             : 
    6051                 :             : /* Nonzero if we need to build up a constructor call when initializing an
    6052                 :             :    object of this class, either because it has a user-declared constructor
    6053                 :             :    or because it doesn't have a default constructor (so we need to give an
    6054                 :             :    error if no initializer is provided).  Use TYPE_NEEDS_CONSTRUCTING when
    6055                 :             :    what you care about is whether or not an object can be produced by a
    6056                 :             :    constructor (e.g. so we don't set TREE_READONLY on const variables of
    6057                 :             :    such type); use this function when what you care about is whether or not
    6058                 :             :    to try to call a constructor to create an object.  The latter case is
    6059                 :             :    the former plus some cases of constructors that cannot be called.  */
    6060                 :             : 
    6061                 :             : bool
    6062                 :    46989307 : type_build_ctor_call (tree t)
    6063                 :             : {
    6064                 :    46989307 :   tree inner;
    6065                 :    46989307 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    6066                 :             :     return true;
    6067                 :    41789090 :   inner = strip_array_types (t);
    6068                 :    41789090 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    6069                 :             :     return false;
    6070                 :     3423392 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    6071                 :             :     return true;
    6072                 :     3067237 :   if (cxx_dialect < cxx11)
    6073                 :             :     return false;
    6074                 :             :   /* A user-declared constructor might be private, and a constructor might
    6075                 :             :      be trivial but deleted.  */
    6076                 :    11637699 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    6077                 :    11637699 :        iter; ++iter)
    6078                 :             :     {
    6079                 :     8960129 :       tree fn = *iter;
    6080                 :     8960129 :       if (!DECL_ARTIFICIAL (fn)
    6081                 :             :           || TREE_DEPRECATED (fn)
    6082                 :     8802956 :           || TREE_UNAVAILABLE (fn)
    6083                 :    17658278 :           || DECL_DELETED_FN (fn))
    6084                 :      379524 :         return true;
    6085                 :             :     }
    6086                 :     2677570 :   return false;
    6087                 :             : }
    6088                 :             : 
    6089                 :             : /* Like type_build_ctor_call, but for destructors.  */
    6090                 :             : 
    6091                 :             : bool
    6092                 :    88340836 : type_build_dtor_call (tree t)
    6093                 :             : {
    6094                 :    88340836 :   tree inner;
    6095                 :    88340836 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6096                 :             :     return true;
    6097                 :    64830662 :   inner = strip_array_types (t);
    6098                 :    26072852 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    6099                 :    90815002 :       || !COMPLETE_TYPE_P (inner))
    6100                 :             :     return false;
    6101                 :    25984312 :   if (cxx_dialect < cxx11)
    6102                 :             :     return false;
    6103                 :             :   /* A user-declared destructor might be private, and a destructor might
    6104                 :             :      be trivial but deleted.  */
    6105                 :    45058682 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    6106                 :    45058682 :        iter; ++iter)
    6107                 :             :     {
    6108                 :    25587933 :       tree fn = *iter;
    6109                 :    25587933 :       if (!DECL_ARTIFICIAL (fn)
    6110                 :             :           || TREE_DEPRECATED (fn)
    6111                 :    19117242 :           || TREE_UNAVAILABLE (fn)
    6112                 :    44705175 :           || DECL_DELETED_FN (fn))
    6113                 :     6470691 :         return true;
    6114                 :             :     }
    6115                 :    19470749 :   return false;
    6116                 :             : }
    6117                 :             : 
    6118                 :             : /* Returns TRUE iff we need a cookie when dynamically allocating an
    6119                 :             :    array whose elements have the indicated class TYPE.  */
    6120                 :             : 
    6121                 :             : static bool
    6122                 :    36027736 : type_requires_array_cookie (tree type)
    6123                 :             : {
    6124                 :    36027736 :   tree fns;
    6125                 :    36027736 :   bool has_two_argument_delete_p = false;
    6126                 :             : 
    6127                 :    36027736 :   gcc_assert (CLASS_TYPE_P (type));
    6128                 :             : 
    6129                 :             :   /* If there's a non-trivial destructor, we need a cookie.  In order
    6130                 :             :      to iterate through the array calling the destructor for each
    6131                 :             :      element, we'll have to know how many elements there are.  */
    6132                 :    36027736 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6133                 :             :     return true;
    6134                 :             : 
    6135                 :             :   /* If the usual deallocation function is a two-argument whose second
    6136                 :             :      argument is of type `size_t', then we have to pass the size of
    6137                 :             :      the array to the deallocation function, so we will need to store
    6138                 :             :      a cookie.  */
    6139                 :    32585285 :   fns = lookup_fnfields (TYPE_BINFO (type),
    6140                 :             :                          ovl_op_identifier (false, VEC_DELETE_EXPR),
    6141                 :             :                          /*protect=*/0, tf_warning_or_error);
    6142                 :             :   /* If there are no `operator []' members, or the lookup is
    6143                 :             :      ambiguous, then we don't need a cookie.  */
    6144                 :    32585285 :   if (!fns || fns == error_mark_node)
    6145                 :             :     return false;
    6146                 :             :   /* Loop through all of the functions.  */
    6147                 :         230 :   for (lkp_iterator iter (BASELINK_FUNCTIONS (fns)); iter; ++iter)
    6148                 :             :     {
    6149                 :         218 :       tree fn = *iter;
    6150                 :             : 
    6151                 :             :       /* See if this function is a one-argument delete function.  If
    6152                 :             :          it is, then it will be the usual deallocation function.  */
    6153                 :         218 :       tree second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    6154                 :         218 :       if (second_parm == void_list_node)
    6155                 :          98 :         return false;
    6156                 :             :       /* Do not consider this function if its second argument is an
    6157                 :             :          ellipsis.  */
    6158                 :         120 :       if (!second_parm)
    6159                 :           3 :         continue;
    6160                 :             :       /* Otherwise, if we have a two-argument function and the second
    6161                 :             :          argument is `size_t', it will be the usual deallocation
    6162                 :             :          function -- unless there is one-argument function, too.  */
    6163                 :         117 :       if (TREE_CHAIN (second_parm) == void_list_node
    6164                 :         117 :           && same_type_p (TREE_VALUE (second_parm), size_type_node))
    6165                 :             :         has_two_argument_delete_p = true;
    6166                 :             :     }
    6167                 :             : 
    6168                 :          12 :   return has_two_argument_delete_p;
    6169                 :             : }
    6170                 :             : 
    6171                 :             : /* Finish computing the `literal type' property of class type T.
    6172                 :             : 
    6173                 :             :    At this point, we have already processed base classes and
    6174                 :             :    non-static data members.  We need to check whether the copy
    6175                 :             :    constructor is trivial, the destructor is trivial, and there
    6176                 :             :    is a trivial default constructor or at least one constexpr
    6177                 :             :    constructor other than the copy constructor.  */
    6178                 :             : 
    6179                 :             : static void
    6180                 :    36027736 : finalize_literal_type_property (tree t)
    6181                 :             : {
    6182                 :    36027736 :   tree fn;
    6183                 :             : 
    6184                 :    36027736 :   if (cxx_dialect < cxx11)
    6185                 :      125491 :     CLASSTYPE_LITERAL_P (t) = false;
    6186                 :    35902245 :   else if (CLASSTYPE_LITERAL_P (t)
    6187                 :    35902245 :            && !type_maybe_constexpr_destructor (t))
    6188                 :      902589 :     CLASSTYPE_LITERAL_P (t) = false;
    6189                 :    67110117 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    6190                 :      252133 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    6191                 :    66975625 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    6192                 :     2005724 :            && CLASSTYPE_NON_AGGREGATE (t)
    6193                 :    36681081 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6194                 :      582389 :     CLASSTYPE_LITERAL_P (t) = false;
    6195                 :             : 
    6196                 :             :   /* C++14 DR 1684 removed this restriction.  */
    6197                 :    36027736 :   if (cxx_dialect < cxx14
    6198                 :    36165946 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    6199                 :     1532325 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6200                 :     1386701 :       if (TREE_CODE (fn) == FUNCTION_DECL
    6201                 :      680484 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    6202                 :        2463 :           && DECL_IOBJ_MEMBER_FUNCTION_P (fn)
    6203                 :     1388875 :           && !DECL_CONSTRUCTOR_P (fn))
    6204                 :             :         {
    6205                 :         533 :           DECL_DECLARED_CONSTEXPR_P (fn) = false;
    6206                 :         533 :           if (!DECL_GENERATED_P (fn))
    6207                 :             :             {
    6208                 :           5 :               auto_diagnostic_group d;
    6209                 :           5 :               if (pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic,
    6210                 :             :                              "enclosing class of %<constexpr%> non-static "
    6211                 :             :                              "member function %q+#D is not a literal type", fn))
    6212                 :           5 :                 explain_non_literal_class (t);
    6213                 :           5 :             }
    6214                 :             :         }
    6215                 :    36027736 : }
    6216                 :             : 
    6217                 :             : /* T is a non-literal type used in a context which requires a constant
    6218                 :             :    expression.  Explain why it isn't literal.  */
    6219                 :             : 
    6220                 :             : void
    6221                 :         132 : explain_non_literal_class (tree t)
    6222                 :             : {
    6223                 :         132 :   static hash_set<tree> *diagnosed;
    6224                 :             : 
    6225                 :         132 :   if (!CLASS_TYPE_P (t))
    6226                 :          51 :     return;
    6227                 :         129 :   t = TYPE_MAIN_VARIANT (t);
    6228                 :             : 
    6229                 :         129 :   if (diagnosed == NULL)
    6230                 :          69 :     diagnosed = new hash_set<tree>;
    6231                 :         129 :   if (diagnosed->add (t))
    6232                 :             :     /* Already explained.  */
    6233                 :             :     return;
    6234                 :             : 
    6235                 :          96 :   auto_diagnostic_group d;
    6236                 :          96 :   inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
    6237                 :         125 :   if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t))
    6238                 :           1 :     inform (UNKNOWN_LOCATION,
    6239                 :             :             "  %qT is a closure type, which is only literal in "
    6240                 :             :             "C++17 and later", t);
    6241                 :          95 :   else if (cxx_dialect < cxx20 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    6242                 :           8 :     inform (UNKNOWN_LOCATION, "  %q+T has a non-trivial destructor", t);
    6243                 :          87 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    6244                 :          87 :            && !type_maybe_constexpr_destructor (t))
    6245                 :          13 :     inform (UNKNOWN_LOCATION, "  %q+T does not have %<constexpr%> destructor",
    6246                 :             :             t);
    6247                 :          74 :   else if (CLASSTYPE_NON_AGGREGATE (t)
    6248                 :          64 :            && !TYPE_HAS_TRIVIAL_DFLT (t)
    6249                 :         125 :            && !LAMBDA_TYPE_P (t)
    6250                 :         138 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    6251                 :             :     {
    6252                 :          41 :       inform (UNKNOWN_LOCATION,
    6253                 :             :               "  %q+T is not an aggregate, does not have a trivial "
    6254                 :             :               "default constructor, and has no %<constexpr%> constructor that "
    6255                 :             :               "is not a copy or move constructor", t);
    6256                 :          41 :       if (type_has_non_user_provided_default_constructor (t))
    6257                 :             :         /* Note that we can't simply call locate_ctor because when the
    6258                 :             :            constructor is deleted it just returns NULL_TREE.  */
    6259                 :           0 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    6260                 :             :           {
    6261                 :           0 :             tree fn = *iter;
    6262                 :           0 :             tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    6263                 :             : 
    6264                 :           0 :             parms = skip_artificial_parms_for (fn, parms);
    6265                 :             : 
    6266                 :           0 :             if (sufficient_parms_p (parms))
    6267                 :             :               {
    6268                 :           0 :                 if (DECL_DELETED_FN (fn))
    6269                 :           0 :                   maybe_explain_implicit_delete (fn);
    6270                 :             :                 else
    6271                 :           0 :                   explain_invalid_constexpr_fn (fn);
    6272                 :             :                 break;
    6273                 :             :               }
    6274                 :             :         }
    6275                 :             :     }
    6276                 :             :   else
    6277                 :             :     {
    6278                 :          33 :       tree binfo, base_binfo, field; int i;
    6279                 :          33 :       for (binfo = TYPE_BINFO (t), i = 0;
    6280                 :          33 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6281                 :             :         {
    6282                 :          15 :           tree basetype = TREE_TYPE (base_binfo);
    6283                 :          15 :           if (!CLASSTYPE_LITERAL_P (basetype))
    6284                 :             :             {
    6285                 :          15 :               inform (UNKNOWN_LOCATION,
    6286                 :             :                       "  base class %qT of %q+T is non-literal",
    6287                 :             :                       basetype, t);
    6288                 :          15 :               explain_non_literal_class (basetype);
    6289                 :          15 :               return;
    6290                 :             :             }
    6291                 :             :         }
    6292                 :         138 :       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
    6293                 :             :         {
    6294                 :         120 :           tree ftype;
    6295                 :         120 :           if (TREE_CODE (field) != FIELD_DECL)
    6296                 :         102 :             continue;
    6297                 :          18 :           ftype = TREE_TYPE (field);
    6298                 :          18 :           if (!literal_type_p (ftype))
    6299                 :             :             {
    6300                 :           6 :               inform (DECL_SOURCE_LOCATION (field),
    6301                 :             :                       "  non-static data member %qD has non-literal type",
    6302                 :             :                       field);
    6303                 :           6 :               if (CLASS_TYPE_P (ftype))
    6304                 :           6 :                 explain_non_literal_class (ftype);
    6305                 :             :             }
    6306                 :          18 :           if (CP_TYPE_VOLATILE_P (ftype))
    6307                 :          12 :             inform (DECL_SOURCE_LOCATION (field),
    6308                 :             :                     "  non-static data member %qD has volatile type", field);
    6309                 :             :         }
    6310                 :             :     }
    6311                 :          96 : }
    6312                 :             : 
    6313                 :             : /* Check the validity of the bases and members declared in T.  Add any
    6314                 :             :    implicitly-generated functions (like copy-constructors and
    6315                 :             :    assignment operators).  Compute various flag bits (like
    6316                 :             :    CLASSTYPE_NON_LAYOUT_POD_T) for T.  This routine works purely at the C++
    6317                 :             :    level: i.e., independently of the ABI in use.  */
    6318                 :             : 
    6319                 :             : static void
    6320                 :    36027736 : check_bases_and_members (tree t)
    6321                 :             : {
    6322                 :             :   /* Nonzero if the implicitly generated copy constructor should take
    6323                 :             :      a non-const reference argument.  */
    6324                 :    36027736 :   int cant_have_const_ctor;
    6325                 :             :   /* Nonzero if the implicitly generated assignment operator
    6326                 :             :      should take a non-const reference argument.  */
    6327                 :    36027736 :   int no_const_asn_ref;
    6328                 :    36027736 :   tree access_decls;
    6329                 :    36027736 :   bool saved_complex_asn_ref;
    6330                 :    36027736 :   bool saved_nontrivial_dtor;
    6331                 :    36027736 :   tree fn;
    6332                 :             : 
    6333                 :             :   /* By default, we use const reference arguments and generate default
    6334                 :             :      constructors.  */
    6335                 :    36027736 :   cant_have_const_ctor = 0;
    6336                 :    36027736 :   no_const_asn_ref = 0;
    6337                 :             : 
    6338                 :             :   /* Check all the base-classes and set FMEM members to point to arrays
    6339                 :             :      of potential interest.  */
    6340                 :    36027736 :   check_bases (t, &cant_have_const_ctor, &no_const_asn_ref);
    6341                 :             : 
    6342                 :             :   /* Deduce noexcept on destructor.  This needs to happen after we've set
    6343                 :             :      triviality flags appropriately for our bases, and before checking
    6344                 :             :      overriden virtual functions via check_methods.  */
    6345                 :    36027736 :   if (cxx_dialect >= cxx11)
    6346                 :    35902245 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    6347                 :     6963490 :       for (tree fn : ovl_range (dtor))
    6348                 :     3481745 :         deduce_noexcept_on_destructor (fn);
    6349                 :             : 
    6350                 :             :   /* Check all the method declarations.  */
    6351                 :    36027736 :   check_methods (t);
    6352                 :             : 
    6353                 :             :   /* Save the initial values of these flags which only indicate whether
    6354                 :             :      or not the class has user-provided functions.  As we analyze the
    6355                 :             :      bases and members we can set these flags for other reasons.  */
    6356                 :    36027736 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    6357                 :    36027736 :   saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
    6358                 :             : 
    6359                 :             :   /* Check all the data member declarations.  We cannot call
    6360                 :             :      check_field_decls until we have called check_bases check_methods,
    6361                 :             :      as check_field_decls depends on TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6362                 :             :      being set appropriately.  */
    6363                 :    36027736 :   check_field_decls (t, &access_decls,
    6364                 :             :                      &cant_have_const_ctor,
    6365                 :             :                      &no_const_asn_ref);
    6366                 :             : 
    6367                 :             :   /* A nearly-empty class has to be vptr-containing; a nearly empty
    6368                 :             :      class contains just a vptr.  */
    6369                 :    36027736 :   if (!TYPE_CONTAINS_VPTR_P (t))
    6370                 :    34399305 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    6371                 :             : 
    6372                 :             :   /* Do some bookkeeping that will guide the generation of implicitly
    6373                 :             :      declared member functions.  */
    6374                 :    37656167 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6375                 :    37656167 :   TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    6376                 :             :   /* We need to call a constructor for this class if it has a
    6377                 :             :      user-provided constructor, or if the default constructor is going
    6378                 :             :      to initialize the vptr.  (This is not an if-and-only-if;
    6379                 :             :      TYPE_NEEDS_CONSTRUCTING is set elsewhere if bases or members
    6380                 :             :      themselves need constructing.)  */
    6381                 :    36027736 :   TYPE_NEEDS_CONSTRUCTING (t)
    6382                 :    36027736 :     |= (type_has_user_provided_constructor (t) || TYPE_CONTAINS_VPTR_P (t));
    6383                 :             :   /* [dcl.init.aggr]
    6384                 :             : 
    6385                 :             :      An aggregate is an array or a class with no user-provided
    6386                 :             :      constructors ... and no virtual functions.  
    6387                 :             : 
    6388                 :             :      Again, other conditions for being an aggregate are checked
    6389                 :             :      elsewhere.  */
    6390                 :    36027736 :   CLASSTYPE_NON_AGGREGATE (t)
    6391                 :    72055472 :     |= ((cxx_dialect < cxx20
    6392                 :    36027736 :          ? type_has_user_provided_or_explicit_constructor (t)
    6393                 :    12264974 :          : TYPE_HAS_USER_CONSTRUCTOR (t))
    6394                 :    36027736 :         || TYPE_POLYMORPHIC_P (t));
    6395                 :             :   /* This is the C++98/03 definition of POD; it changed in C++0x, but we
    6396                 :             :      retain the old definition internally for ABI reasons.  */
    6397                 :    36027736 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    6398                 :    36027736 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    6399                 :    36027736 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    6400                 :    37656167 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6401                 :    37656167 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6402                 :    37656167 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    6403                 :    37656167 :   TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
    6404                 :             : 
    6405                 :             :   /* Is this class non-layout-POD because it wasn't an aggregate in C++98?  */
    6406                 :    36027736 :   if (CLASSTYPE_NON_POD_AGGREGATE (t))
    6407                 :             :     {
    6408                 :      386482 :       if (CLASSTYPE_NON_LAYOUT_POD_P (t))
    6409                 :             :         /* It's non-POD for another reason.  */
    6410                 :      361358 :         CLASSTYPE_NON_POD_AGGREGATE (t) = false;
    6411                 :       25124 :       else if (abi_version_at_least (17))
    6412                 :       25122 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = true;
    6413                 :             :     }
    6414                 :             : 
    6415                 :             :   /* If the only explicitly declared default constructor is user-provided,
    6416                 :             :      set TYPE_HAS_COMPLEX_DFLT.  */
    6417                 :    36027736 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    6418                 :    32413928 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    6419                 :    38054363 :       && !type_has_non_user_provided_default_constructor (t))
    6420                 :     1373891 :     TYPE_HAS_COMPLEX_DFLT (t) = true;
    6421                 :             : 
    6422                 :             :   /* Warn if a public base of a polymorphic type has an accessible
    6423                 :             :      non-virtual destructor.  It is only now that we know the class is
    6424                 :             :      polymorphic.  Although a polymorphic base will have a already
    6425                 :             :      been diagnosed during its definition, we warn on use too.  */
    6426                 :    36027736 :   if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor)
    6427                 :             :     {
    6428                 :          84 :       tree binfo = TYPE_BINFO (t);
    6429                 :          84 :       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
    6430                 :          84 :       tree base_binfo;
    6431                 :          84 :       unsigned i;
    6432                 :             :       
    6433                 :         114 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    6434                 :             :         {
    6435                 :          30 :           tree basetype = TREE_TYPE (base_binfo);
    6436                 :             : 
    6437                 :          30 :           if ((*accesses)[i] == access_public_node
    6438                 :          18 :               && (TYPE_POLYMORPHIC_P (basetype) || warn_ecpp)
    6439                 :          45 :               && accessible_nvdtor_p (basetype))
    6440                 :           9 :             warning (OPT_Wnon_virtual_dtor,
    6441                 :             :                      "base class %q#T has accessible non-virtual destructor",
    6442                 :             :                      basetype);
    6443                 :             :         }
    6444                 :             :     }
    6445                 :             :   
    6446                 :             :   /* If the class has no user-declared constructor, but does have
    6447                 :             :      non-static const or reference data members that can never be
    6448                 :             :      initialized, issue a warning.  */
    6449                 :    36027736 :   if (warn_uninitialized
    6450                 :             :       /* Classes with user-declared constructors are presumed to
    6451                 :             :          initialize these members.  */
    6452                 :      355995 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    6453                 :             :       /* Aggregates can be initialized with brace-enclosed
    6454                 :             :          initializers.  */
    6455                 :    36320546 :       && CLASSTYPE_NON_AGGREGATE (t))
    6456                 :             :     {
    6457                 :       36337 :       tree field;
    6458                 :             : 
    6459                 :      232669 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6460                 :             :         {
    6461                 :      196332 :           tree type;
    6462                 :             : 
    6463                 :      370561 :           if (TREE_CODE (field) != FIELD_DECL
    6464                 :      196332 :               || DECL_INITIAL (field) != NULL_TREE)
    6465                 :      174229 :             continue;
    6466                 :             : 
    6467                 :       22103 :           type = TREE_TYPE (field);
    6468                 :       22103 :           if (TYPE_REF_P (type))
    6469                 :           6 :             warning_at (DECL_SOURCE_LOCATION (field),
    6470                 :             :                         OPT_Wuninitialized, "non-static reference %q#D "
    6471                 :             :                         "in class without a constructor", field);
    6472                 :       22097 :           else if (CP_TYPE_CONST_P (type)
    6473                 :       22097 :                    && (!CLASS_TYPE_P (type)
    6474                 :           3 :                        || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
    6475                 :           9 :             warning_at (DECL_SOURCE_LOCATION (field),
    6476                 :             :                         OPT_Wuninitialized, "non-static const member %q#D "
    6477                 :             :                         "in class without a constructor", field);
    6478                 :             :         }
    6479                 :             :     }
    6480                 :             : 
    6481                 :             :   /* Synthesize any needed methods.  */
    6482                 :    36027736 :   add_implicitly_declared_members (t, &access_decls,
    6483                 :             :                                    cant_have_const_ctor,
    6484                 :             :                                    no_const_asn_ref);
    6485                 :             : 
    6486                 :             :   /* Check defaulted declarations here so we have cant_have_const_ctor
    6487                 :             :      and don't need to worry about clones.  */
    6488                 :   254780860 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6489                 :   127007333 :     if (DECL_DECLARES_FUNCTION_P (fn)
    6490                 :   112385505 :         && !DECL_ARTIFICIAL (fn)
    6491                 :   330241861 :         && DECL_DEFAULTED_IN_CLASS_P (fn))
    6492                 :             :       {
    6493                 :             :         /* ...except handle comparisons later, in finish_struct_1.  */
    6494                 :     5156795 :         if (special_function_p (fn) == sfk_comparison)
    6495                 :        9576 :           continue;
    6496                 :             : 
    6497                 :     5147219 :         int copy = copy_fn_p (fn);
    6498                 :     5147219 :         if (copy > 0)
    6499                 :             :           {
    6500                 :     2015258 :             bool imp_const_p
    6501                 :     4030516 :               = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    6502                 :     1024159 :                  : !no_const_asn_ref);
    6503                 :     2015258 :             bool fn_const_p = (copy == 2);
    6504                 :             : 
    6505                 :     2015258 :             if (fn_const_p && !imp_const_p)
    6506                 :             :               /* If the function is defaulted outside the class, we just
    6507                 :             :                  give the synthesis error.  Core Issue #1331 says this is
    6508                 :             :                  no longer ill-formed, it is defined as deleted instead.  */
    6509                 :          18 :               DECL_DELETED_FN (fn) = true;
    6510                 :             :           }
    6511                 :     5147219 :         defaulted_late_check (fn);
    6512                 :             :       }
    6513                 :             : 
    6514                 :    71674369 :   if (LAMBDA_TYPE_P (t))
    6515                 :             :     /* "This class type is not an aggregate."  */
    6516                 :      252301 :     CLASSTYPE_NON_AGGREGATE (t) = 1;
    6517                 :             : 
    6518                 :             :   /* Compute the 'literal type' property before we
    6519                 :             :      do anything with non-static member functions.  */
    6520                 :    36027736 :   finalize_literal_type_property (t);
    6521                 :             : 
    6522                 :             :   /* Create the in-charge and not-in-charge variants of constructors
    6523                 :             :      and destructors.  */
    6524                 :    36027736 :   clone_constructors_and_destructors (t);
    6525                 :             : 
    6526                 :             :   /* Process the using-declarations.  */
    6527                 :    73909344 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6528                 :     1853872 :     handle_using_decl (TREE_VALUE (access_decls), t);
    6529                 :             : 
    6530                 :             :   /* Figure out whether or not we will need a cookie when dynamically
    6531                 :             :      allocating an array of this type.  */
    6532                 :    36027736 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6533                 :    36027736 :     = type_requires_array_cookie (t);
    6534                 :             : 
    6535                 :             :   /* Classes marked hot or cold propagate the attribute to all members.  We
    6536                 :             :      may do this now that methods are declared.  This does miss some lazily
    6537                 :             :      declared special member functions (CLASSTYPE_LAZY_*), which are handled
    6538                 :             :      in lazily_declare_fn later on.  */
    6539                 :    36027736 :   propagate_class_warmth_attribute (t);
    6540                 :    36027736 : }
    6541                 :             : 
    6542                 :             : /* If T needs a pointer to its virtual function table, set TYPE_VFIELD
    6543                 :             :    accordingly.  If a new vfield was created (because T doesn't have a
    6544                 :             :    primary base class), then the newly created field is returned.  It
    6545                 :             :    is not added to the TYPE_FIELDS list; it is the caller's
    6546                 :             :    responsibility to do that.  Accumulate declared virtual functions
    6547                 :             :    on VIRTUALS_P.  */
    6548                 :             : 
    6549                 :             : static tree
    6550                 :    36027736 : create_vtable_ptr (tree t, tree* virtuals_p)
    6551                 :             : {
    6552                 :    36027736 :   tree fn;
    6553                 :             : 
    6554                 :             :   /* Collect the virtual functions declared in T.  */
    6555                 :   310127709 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6556                 :   274099973 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6557                 :   132578004 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6558                 :   281616638 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6559                 :             :       {
    6560                 :     7516665 :         tree new_virtual = make_node (TREE_LIST);
    6561                 :             : 
    6562                 :     7516665 :         BV_FN (new_virtual) = fn;
    6563                 :     7516665 :         BV_DELTA (new_virtual) = integer_zero_node;
    6564                 :     7516665 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6565                 :             : 
    6566                 :     7516665 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6567                 :     7516665 :         *virtuals_p = new_virtual;
    6568                 :             :       }
    6569                 :             : 
    6570                 :             :   /* If we couldn't find an appropriate base class, create a new field
    6571                 :             :      here.  Even if there weren't any new virtual functions, we might need a
    6572                 :             :      new virtual function table if we're supposed to include vptrs in
    6573                 :             :      all classes that need them.  */
    6574                 :    36027736 :   if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
    6575                 :             :     {
    6576                 :             :       /* We build this decl with vtbl_ptr_type_node, which is a
    6577                 :             :          `vtable_entry_type*'.  It might seem more precise to use
    6578                 :             :          `vtable_entry_type (*)[N]' where N is the number of virtual
    6579                 :             :          functions.  However, that would require the vtable pointer in
    6580                 :             :          base classes to have a different type than the vtable pointer
    6581                 :             :          in derived classes.  We could make that happen, but that
    6582                 :             :          still wouldn't solve all the problems.  In particular, the
    6583                 :             :          type-based alias analysis code would decide that assignments
    6584                 :             :          to the base class vtable pointer can't alias assignments to
    6585                 :             :          the derived class vtable pointer, since they have different
    6586                 :             :          types.  Thus, in a derived class destructor, where the base
    6587                 :             :          class constructor was inlined, we could generate bad code for
    6588                 :             :          setting up the vtable pointer.
    6589                 :             : 
    6590                 :             :          Therefore, we use one type for all vtable pointers.  We still
    6591                 :             :          use a type-correct type; it's just doesn't indicate the array
    6592                 :             :          bounds.  That's better than using `void*' or some such; it's
    6593                 :             :          cleaner, and it let's the alias analysis code know that these
    6594                 :             :          stores cannot alias stores to void*!  */
    6595                 :      237442 :       tree field;
    6596                 :             : 
    6597                 :      237442 :       field = build_decl (input_location, 
    6598                 :             :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6599                 :      237442 :       DECL_VIRTUAL_P (field) = 1;
    6600                 :      237442 :       DECL_ARTIFICIAL (field) = 1;
    6601                 :      237442 :       DECL_FIELD_CONTEXT (field) = t;
    6602                 :      237442 :       DECL_FCONTEXT (field) = t;
    6603                 :      237442 :       if (TYPE_PACKED (t))
    6604                 :           3 :         DECL_PACKED (field) = 1;
    6605                 :             : 
    6606                 :      237442 :       TYPE_VFIELD (t) = field;
    6607                 :             : 
    6608                 :             :       /* This class is non-empty.  */
    6609                 :      237442 :       CLASSTYPE_EMPTY_P (t) = 0;
    6610                 :             : 
    6611                 :      237442 :       return field;
    6612                 :             :     }
    6613                 :             : 
    6614                 :             :   return NULL_TREE;
    6615                 :             : }
    6616                 :             : 
    6617                 :             : /* Add OFFSET to all base types of BINFO which is a base in the
    6618                 :             :    hierarchy dominated by T.
    6619                 :             : 
    6620                 :             :    OFFSET, which is a type offset, is number of bytes.  */
    6621                 :             : 
    6622                 :             : static void
    6623                 :    23160116 : propagate_binfo_offsets (tree binfo, tree offset)
    6624                 :             : {
    6625                 :    23160116 :   int i;
    6626                 :    23160116 :   tree primary_binfo;
    6627                 :    23160116 :   tree base_binfo;
    6628                 :             : 
    6629                 :             :   /* Update BINFO's offset.  */
    6630                 :    23160116 :   BINFO_OFFSET (binfo)
    6631                 :    23160116 :     = fold_convert (sizetype,
    6632                 :             :                size_binop (PLUS_EXPR,
    6633                 :             :                            fold_convert (ssizetype, BINFO_OFFSET (binfo)),
    6634                 :             :                            offset));
    6635                 :             : 
    6636                 :             :   /* Find the primary base class.  */
    6637                 :    23160116 :   primary_binfo = get_primary_binfo (binfo);
    6638                 :             : 
    6639                 :    24191467 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6640                 :     1030359 :     propagate_binfo_offsets (primary_binfo, offset);
    6641                 :             : 
    6642                 :             :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6643                 :             :      downwards.  */
    6644                 :    27027174 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6645                 :             :     {
    6646                 :             :       /* Don't do the primary base twice.  */
    6647                 :     4898335 :       if (base_binfo == primary_binfo)
    6648                 :     1031277 :         continue;
    6649                 :             : 
    6650                 :     2835781 :       if (BINFO_VIRTUAL_P (base_binfo))
    6651                 :      220667 :         continue;
    6652                 :             : 
    6653                 :     2615114 :       propagate_binfo_offsets (base_binfo, offset);
    6654                 :             :     }
    6655                 :    23160116 : }
    6656                 :             : 
    6657                 :             : /* Set BINFO_OFFSET for all of the virtual bases for RLI->T.  Update
    6658                 :             :    TYPE_ALIGN and TYPE_SIZE for T.  OFFSETS gives the location of
    6659                 :             :    empty subobjects of T.  */
    6660                 :             : 
    6661                 :             : static void
    6662                 :    36027736 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6663                 :             : {
    6664                 :    36027736 :   tree vbase;
    6665                 :    36027736 :   tree t = rli->t;
    6666                 :    36027736 :   tree *next_field;
    6667                 :             : 
    6668                 :    36027736 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) == 0)
    6669                 :             :     return;
    6670                 :             : 
    6671                 :             :   /* Find the last field.  The artificial fields created for virtual
    6672                 :             :      bases will go after the last extant field to date.  */
    6673                 :    18736723 :   next_field = &TYPE_FIELDS (t);
    6674                 :   151807383 :   while (*next_field)
    6675                 :   133070660 :     next_field = &DECL_CHAIN (*next_field);
    6676                 :             : 
    6677                 :             :   /* Go through the virtual bases, allocating space for each virtual
    6678                 :             :      base that is not already a primary base class.  These are
    6679                 :             :      allocated in inheritance graph order.  */
    6680                 :    60624607 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6681                 :             :     {
    6682                 :    41887884 :       if (!BINFO_VIRTUAL_P (vbase))
    6683                 :    41688806 :         continue;
    6684                 :             : 
    6685                 :      199078 :       if (!BINFO_PRIMARY_P (vbase))
    6686                 :             :         {
    6687                 :             :           /* This virtual base is not a primary base of any class in the
    6688                 :             :              hierarchy, so we have to add space for it.  */
    6689                 :      191072 :           next_field = build_base_field (rli, vbase,
    6690                 :             :                                          access_private_node,
    6691                 :             :                                          offsets, next_field);
    6692                 :             :         }
    6693                 :             :     }
    6694                 :             : }
    6695                 :             : 
    6696                 :             : /* Returns the offset of the byte just past the end of the base class
    6697                 :             :    BINFO.  */
    6698                 :             : 
    6699                 :             : static tree
    6700                 :    38830953 : end_of_base (tree binfo)
    6701                 :             : {
    6702                 :    38830953 :   tree size;
    6703                 :             : 
    6704                 :    38830953 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6705                 :           0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6706                 :    38830953 :   else if (is_empty_class (BINFO_TYPE (binfo)))
    6707                 :             :     /* An empty class has zero CLASSTYPE_SIZE_UNIT, but we need to
    6708                 :             :        allocate some space for it. It cannot have virtual bases, so
    6709                 :             :        TYPE_SIZE_UNIT is fine.  */
    6710                 :    34408430 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6711                 :             :   else
    6712                 :     4422523 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6713                 :             : 
    6714                 :    38830953 :   return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
    6715                 :             : }
    6716                 :             : 
    6717                 :             : /* Returns one of three variations of the ending offset of T.  If MODE is
    6718                 :             :    eoc_nvsize, the result is the ABI "nvsize" (i.e. sizeof before allocating
    6719                 :             :    vbases).  If MODE is eoc_vsize, the result is the sizeof after allocating
    6720                 :             :    vbases but before rounding, which is not named in the ABI.  If MODE is
    6721                 :             :    eoc_nv_or_dsize, the result is the greater of "nvsize" and "dsize" (the size
    6722                 :             :    of the actual data in the class, kinda), as used for allocation of
    6723                 :             :    potentially-overlapping fields.  */
    6724                 :             : 
    6725                 :             : enum eoc_mode { eoc_nvsize, eoc_vsize, eoc_nv_or_dsize };
    6726                 :             : static tree
    6727                 :    70538346 : end_of_class (tree t, eoc_mode mode)
    6728                 :             : {
    6729                 :    70538346 :   tree result = size_zero_node;
    6730                 :    70538346 :   vec<tree, va_gc> *vbases;
    6731                 :    70538346 :   tree binfo;
    6732                 :    70538346 :   tree base_binfo;
    6733                 :    70538346 :   tree offset;
    6734                 :    70538346 :   int i;
    6735                 :             : 
    6736                 :    70538346 :   for (binfo = TYPE_BINFO (t), i = 0;
    6737                 :   109261946 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6738                 :             :     {
    6739                 :    38723600 :       if (BINFO_VIRTUAL_P (base_binfo)
    6740                 :    38723600 :           && (!BINFO_PRIMARY_P (base_binfo)
    6741                 :        3330 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6742                 :       91725 :         continue;
    6743                 :             : 
    6744                 :    38631875 :       offset = end_of_base (base_binfo);
    6745                 :    38631875 :       if (tree_int_cst_lt (result, offset))
    6746                 :    38723600 :         result = offset;
    6747                 :             :     }
    6748                 :             : 
    6749                 :   650074641 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6750                 :   579536295 :     if (TREE_CODE (field) == FIELD_DECL
    6751                 :   579536295 :         && !DECL_FIELD_IS_BASE (field))
    6752                 :             :       {
    6753                 :    23787493 :         tree size = DECL_SIZE_UNIT (field);
    6754                 :    23787493 :         if (!size)
    6755                 :             :           /* DECL_SIZE_UNIT can be null for a flexible array.  */
    6756                 :        1930 :           continue;
    6757                 :             : 
    6758                 :    23785563 :         if (is_empty_field (field))
    6759                 :             :           /* For empty fields DECL_SIZE_UNIT is 0, but we want the
    6760                 :             :              size of the type (usually 1) for computing nvsize.  */
    6761                 :       80226 :           size = TYPE_SIZE_UNIT (TREE_TYPE (field));
    6762                 :             : 
    6763                 :    23785563 :         if (DECL_BIT_FIELD_TYPE (field))
    6764                 :             :           {
    6765                 :      449901 :             offset = size_binop (PLUS_EXPR, bit_position (field),
    6766                 :             :                                  DECL_SIZE (field));
    6767                 :      449901 :             offset = size_binop (CEIL_DIV_EXPR, offset, bitsize_unit_node);
    6768                 :      449901 :             offset = fold_convert (sizetype, offset);
    6769                 :             :           }
    6770                 :             :         else
    6771                 :    23335662 :           offset = size_binop (PLUS_EXPR, byte_position (field), size);
    6772                 :    23785563 :         if (tree_int_cst_lt (result, offset))
    6773                 :   579536295 :           result = offset;
    6774                 :             :       }
    6775                 :             : 
    6776                 :    70538346 :   if (mode != eoc_nvsize)
    6777                 :    36246061 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6778                 :    36246061 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6779                 :             :       {
    6780                 :      199087 :         if (mode == eoc_nv_or_dsize)
    6781                 :             :           /* For dsize, don't count trailing empty bases.  */
    6782                 :           9 :           offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo),
    6783                 :             :                                CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
    6784                 :             :         else
    6785                 :      199078 :           offset = end_of_base (base_binfo);
    6786                 :      199087 :         if (tree_int_cst_lt (result, offset))
    6787                 :      188806 :           result = offset;
    6788                 :             :       }
    6789                 :             : 
    6790                 :    70538346 :   return result;
    6791                 :             : }
    6792                 :             : 
    6793                 :             : /* Warn as appropriate about the change in whether we pack into the tail
    6794                 :             :    padding of FIELD, a base field which has a C++14 aggregate type with default
    6795                 :             :    member initializers.  */
    6796                 :             : 
    6797                 :             : static void
    6798                 :   293580877 : check_non_pod_aggregate (tree field)
    6799                 :             : {
    6800                 :   879205724 :   if (!abi_version_crosses (17) || cxx_dialect < cxx14)
    6801                 :             :     return;
    6802                 :      673538 :   if (TREE_CODE (field) != FIELD_DECL
    6803                 :      673538 :       || (!DECL_FIELD_IS_BASE (field)
    6804                 :       41634 :           && !field_poverlapping_p (field)))
    6805                 :      626686 :     return;
    6806                 :       46852 :   tree next = DECL_CHAIN (field);
    6807                 :      197342 :   while (next && TREE_CODE (next) != FIELD_DECL) next = DECL_CHAIN (next);
    6808                 :       46852 :   if (!next)
    6809                 :             :     return;
    6810                 :        3578 :   tree type = TREE_TYPE (field);
    6811                 :        3578 :   if (TYPE_IDENTIFIER (type) == as_base_identifier)
    6812                 :        1627 :     type = TYPE_CONTEXT (type);
    6813                 :        3578 :   if (!CLASS_TYPE_P (type) || !CLASSTYPE_NON_POD_AGGREGATE (type))
    6814                 :             :     return;
    6815                 :          22 :   tree size = end_of_class (type, (DECL_FIELD_IS_BASE (field)
    6816                 :             :                                    ? eoc_nvsize : eoc_nv_or_dsize));
    6817                 :          20 :   tree rounded = round_up_loc (input_location, size, DECL_ALIGN_UNIT (next));
    6818                 :          20 :   if (tree_int_cst_lt (rounded, TYPE_SIZE_UNIT (type)))
    6819                 :             :     {
    6820                 :          12 :       location_t loc = DECL_SOURCE_LOCATION (next);
    6821                 :          12 :       if (DECL_FIELD_IS_BASE (next))
    6822                 :           6 :         warning_at (loc, OPT_Wabi,"offset of %qT base class for "
    6823                 :             :                     "%<-std=c++14%> and up changes in "
    6824                 :           6 :                     "%<-fabi-version=17%> (GCC 12)", TREE_TYPE (next));
    6825                 :             :       else
    6826                 :           6 :         warning_at (loc, OPT_Wabi, "offset of %qD for "
    6827                 :             :                     "%<-std=c++14%> and up changes in "
    6828                 :             :                     "%<-fabi-version=17%> (GCC 12)", next);
    6829                 :             :     }
    6830                 :             : }
    6831                 :             : 
    6832                 :             : /* Warn about bases of T that are inaccessible because they are
    6833                 :             :    ambiguous.  For example:
    6834                 :             : 
    6835                 :             :      struct S {};
    6836                 :             :      struct T : public S {};
    6837                 :             :      struct U : public S, public T {};
    6838                 :             : 
    6839                 :             :    Here, `(S*) new U' is not allowed because there are two `S'
    6840                 :             :    subobjects of U.  */
    6841                 :             : 
    6842                 :             : static void
    6843                 :    36027736 : maybe_warn_about_inaccessible_bases (tree t)
    6844                 :             : {
    6845                 :    36027736 :   int i;
    6846                 :    36027736 :   vec<tree, va_gc> *vbases;
    6847                 :    36027736 :   tree basetype;
    6848                 :    36027736 :   tree binfo;
    6849                 :    36027736 :   tree base_binfo;
    6850                 :             : 
    6851                 :             :   /* If not checking for warning then return early.  */
    6852                 :    36027736 :   if (!warn_inaccessible_base)
    6853                 :    36027736 :     return;
    6854                 :             : 
    6855                 :             :   /* If there are no repeated bases, nothing can be ambiguous.  */
    6856                 :    36027604 :   if (!CLASSTYPE_REPEATED_BASE_P (t))
    6857                 :             :     return;
    6858                 :             : 
    6859                 :             :   /* Check direct bases.  */
    6860                 :        3684 :   for (binfo = TYPE_BINFO (t), i = 0;
    6861                 :        3684 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6862                 :             :     {
    6863                 :        2670 :       basetype = BINFO_TYPE (base_binfo);
    6864                 :             : 
    6865                 :        2670 :       if (!uniquely_derived_from_p (basetype, t))
    6866                 :         781 :         warning (OPT_Winaccessible_base, "direct base %qT inaccessible "
    6867                 :             :                  "in %qT due to ambiguity", basetype, t);
    6868                 :             :     }
    6869                 :             : 
    6870                 :             :   /* Check for ambiguous virtual bases.  */
    6871                 :        1014 :   if (extra_warnings)
    6872                 :           6 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6873                 :           6 :          vec_safe_iterate (vbases, i, &binfo); i++)
    6874                 :             :       {
    6875                 :           3 :         basetype = BINFO_TYPE (binfo);
    6876                 :             : 
    6877                 :           3 :         if (!uniquely_derived_from_p (basetype, t))
    6878                 :           3 :           warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
    6879                 :             :                    "%qT due to ambiguity", basetype, t);
    6880                 :             :       }
    6881                 :             : }
    6882                 :             : 
    6883                 :             : /* Compare two INTEGER_CSTs K1 and K2.  */
    6884                 :             : 
    6885                 :             : static int
    6886                 :     8434207 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    6887                 :             : {
    6888                 :     8434207 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    6889                 :             : }
    6890                 :             : 
    6891                 :             : /* Increase the size indicated in RLI to account for empty classes
    6892                 :             :    that are "off the end" of the class.  */
    6893                 :             : 
    6894                 :             : static void
    6895                 :    36027736 : include_empty_classes (record_layout_info rli)
    6896                 :             : {
    6897                 :    36027736 :   tree eoc;
    6898                 :    36027736 :   tree rli_size;
    6899                 :             : 
    6900                 :             :   /* It might be the case that we grew the class to allocate a
    6901                 :             :      zero-sized base class.  That won't be reflected in RLI, yet,
    6902                 :             :      because we are willing to overlay multiple bases at the same
    6903                 :             :      offset.  However, now we need to make sure that RLI is big enough
    6904                 :             :      to reflect the entire class.  */
    6905                 :    36027736 :   eoc = end_of_class (rli->t, eoc_vsize);
    6906                 :    36027736 :   rli_size = rli_size_unit_so_far (rli);
    6907                 :    36027736 :   if (TREE_CODE (rli_size) == INTEGER_CST
    6908                 :    36027736 :       && tree_int_cst_lt (rli_size, eoc))
    6909                 :             :     {
    6910                 :             :       /* The size should have been rounded to a whole byte.  */
    6911                 :    16324621 :       gcc_assert (tree_int_cst_equal
    6912                 :             :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    6913                 :    16324621 :       rli->bitpos
    6914                 :    16324621 :         = size_binop (PLUS_EXPR,
    6915                 :             :                       rli->bitpos,
    6916                 :             :                       size_binop (MULT_EXPR,
    6917                 :             :                                   fold_convert (bitsizetype,
    6918                 :             :                                            size_binop (MINUS_EXPR,
    6919                 :             :                                                        eoc, rli_size)),
    6920                 :             :                                   bitsize_int (BITS_PER_UNIT)));
    6921                 :    16324621 :       normalize_rli (rli);
    6922                 :             :     }
    6923                 :    36027736 : }
    6924                 :             : 
    6925                 :             : /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T.  Calculate
    6926                 :             :    BINFO_OFFSETs for all of the base-classes.  Position the vtable
    6927                 :             :    pointer.  Accumulate declared virtual functions on VIRTUALS_P.  */
    6928                 :             : 
    6929                 :             : static void
    6930                 :    36027736 : layout_class_type (tree t, tree *virtuals_p)
    6931                 :             : {
    6932                 :    36027736 :   tree non_static_data_members;
    6933                 :    36027736 :   tree field;
    6934                 :    36027736 :   tree vptr;
    6935                 :    36027736 :   record_layout_info rli;
    6936                 :             :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    6937                 :             :      types that appear at that offset.  */
    6938                 :    36027736 :   splay_tree empty_base_offsets;
    6939                 :             :   /* True if the last field laid out was a bit-field.  */
    6940                 :    36027736 :   bool last_field_was_bitfield = false;
    6941                 :             :   /* The location at which the next field should be inserted.  */
    6942                 :    36027736 :   tree *next_field;
    6943                 :             : 
    6944                 :             :   /* Keep track of the first non-static data member.  */
    6945                 :    36027736 :   non_static_data_members = TYPE_FIELDS (t);
    6946                 :             : 
    6947                 :             :   /* Start laying out the record.  */
    6948                 :    36027736 :   rli = start_record_layout (t);
    6949                 :             : 
    6950                 :             :   /* Mark all the primary bases in the hierarchy.  */
    6951                 :    36027736 :   determine_primary_bases (t);
    6952                 :             : 
    6953                 :             :   /* Create a pointer to our virtual function table.  */
    6954                 :    36027736 :   vptr = create_vtable_ptr (t, virtuals_p);
    6955                 :             : 
    6956                 :             :   /* The vptr is always the first thing in the class.  */
    6957                 :    36027736 :   if (vptr)
    6958                 :             :     {
    6959                 :      237442 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    6960                 :      237442 :       TYPE_FIELDS (t) = vptr;
    6961                 :      237442 :       next_field = &DECL_CHAIN (vptr);
    6962                 :      237442 :       place_field (rli, vptr);
    6963                 :             :     }
    6964                 :             :   else
    6965                 :    35790294 :     next_field = &TYPE_FIELDS (t);
    6966                 :             : 
    6967                 :             :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    6968                 :    36027736 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    6969                 :             :                                        NULL, NULL);
    6970                 :    36027736 :   build_base_fields (rli, empty_base_offsets, next_field);
    6971                 :             : 
    6972                 :             :   /* Layout the non-static data members.  */
    6973                 :   310127709 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    6974                 :             :     {
    6975                 :   274099973 :       tree type;
    6976                 :   274099973 :       tree padding;
    6977                 :             : 
    6978                 :             :       /* We still pass things that aren't non-static data members to
    6979                 :             :          the back end, in case it wants to do something with them.  */
    6980                 :   274099973 :       if (TREE_CODE (field) != FIELD_DECL)
    6981                 :             :         {
    6982                 :   259433091 :           place_field (rli, field);
    6983                 :             :           /* If the static data member has incomplete type, keep track
    6984                 :             :              of it so that it can be completed later.  (The handling
    6985                 :             :              of pending statics in finish_record_layout is
    6986                 :             :              insufficient; consider:
    6987                 :             : 
    6988                 :             :                struct S1;
    6989                 :             :                struct S2 { static S1 s1; };
    6990                 :             : 
    6991                 :             :              At this point, finish_record_layout will be called, but
    6992                 :             :              S1 is still incomplete.)  */
    6993                 :   259433091 :           if (VAR_P (field))
    6994                 :             :             {
    6995                 :     9803719 :               maybe_register_incomplete_var (field);
    6996                 :             :               /* The visibility of static data members is determined
    6997                 :             :                  at their point of declaration, not their point of
    6998                 :             :                  definition.  */
    6999                 :     9803719 :               determine_visibility (field);
    7000                 :             :             }
    7001                 :   259433091 :           continue;
    7002                 :             :         }
    7003                 :             : 
    7004                 :    14666882 :       type = TREE_TYPE (field);
    7005                 :    14666882 :       if (type == error_mark_node)
    7006                 :         161 :         continue;
    7007                 :             : 
    7008                 :    14666721 :       padding = NULL_TREE;
    7009                 :             : 
    7010                 :    14666721 :       bool might_overlap = field_poverlapping_p (field);
    7011                 :             : 
    7012                 :       71087 :       if (might_overlap && CLASS_TYPE_P (type)
    7013                 :    14726119 :           && (CLASSTYPE_NON_LAYOUT_POD_P (type) || CLASSTYPE_EMPTY_P (type)))
    7014                 :             :         {
    7015                 :             :           /* if D is a potentially-overlapping data member, update sizeof(C) to
    7016                 :             :              max (sizeof(C), offset(D)+max (nvsize(D), dsize(D))).  */
    7017                 :       59334 :           if (CLASSTYPE_EMPTY_P (type))
    7018                 :       40098 :             DECL_SIZE (field) = DECL_SIZE_UNIT (field) = size_zero_node;
    7019                 :             :           else
    7020                 :             :             {
    7021                 :       19236 :               tree size = end_of_class (type, eoc_nv_or_dsize);
    7022                 :       19236 :               DECL_SIZE_UNIT (field) = size;
    7023                 :       19236 :               DECL_SIZE (field) = bit_from_pos (size, bitsize_zero_node);
    7024                 :             :             }
    7025                 :             :         }
    7026                 :             : 
    7027                 :             :       /* If this field is a bit-field whose width is greater than its
    7028                 :             :          type, then there are some special rules for allocating
    7029                 :             :          it.  */
    7030                 :    14666721 :       if (DECL_C_BIT_FIELD (field)
    7031                 :    14666721 :           && tree_int_cst_lt (TYPE_SIZE (type), DECL_SIZE (field)))
    7032                 :             :         {
    7033                 :         774 :           bool was_unnamed_p = false;
    7034                 :             :           /* We must allocate the bits as if suitably aligned for the
    7035                 :             :              longest integer type that fits in this many bits.  Then,
    7036                 :             :              we are supposed to use the left over bits as additional
    7037                 :             :              padding.  */
    7038                 :             : 
    7039                 :             :           /* Do not pick a type bigger than MAX_FIXED_MODE_SIZE.  */
    7040                 :        1548 :           tree limit = size_int (MAX_FIXED_MODE_SIZE);
    7041                 :         774 :           if (tree_int_cst_lt (DECL_SIZE (field), limit))
    7042                 :         753 :             limit = DECL_SIZE (field);
    7043                 :             : 
    7044                 :         774 :           tree integer_type = integer_types[itk_char];
    7045                 :        6620 :           for (unsigned itk = itk_char; itk != itk_none; itk++)
    7046                 :        6599 :             if (tree next = integer_types[itk])
    7047                 :             :               {
    7048                 :        6473 :                 if (tree_int_cst_lt (limit, TYPE_SIZE (next)))
    7049                 :             :                   /* Too big, so our current guess is what we want.  */
    7050                 :             :                   break;
    7051                 :             :                 /* Not bigger than limit, ok  */
    7052                 :             :                 integer_type = next;
    7053                 :             :               }
    7054                 :             : 
    7055                 :             :           /* Figure out how much additional padding is required.  */
    7056                 :         774 :           if (TREE_CODE (t) == UNION_TYPE)
    7057                 :             :             /* In a union, the padding field must have the full width
    7058                 :             :                of the bit-field; all fields start at offset zero.  */
    7059                 :          77 :             padding = DECL_SIZE (field);
    7060                 :             :           else
    7061                 :         697 :             padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
    7062                 :             :                                   TYPE_SIZE (integer_type));
    7063                 :             : 
    7064                 :         774 :           if (integer_zerop (padding))
    7065                 :           6 :             padding = NULL_TREE;
    7066                 :             : 
    7067                 :             :           /* An unnamed bitfield does not normally affect the
    7068                 :             :              alignment of the containing class on a target where
    7069                 :             :              PCC_BITFIELD_TYPE_MATTERS.  But, the C++ ABI does not
    7070                 :             :              make any exceptions for unnamed bitfields when the
    7071                 :             :              bitfields are longer than their types.  Therefore, we
    7072                 :             :              temporarily give the field a name.  */
    7073                 :         774 :           if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
    7074                 :             :             {
    7075                 :           0 :               was_unnamed_p = true;
    7076                 :           0 :               DECL_NAME (field) = make_anon_name ();
    7077                 :             :             }
    7078                 :             : 
    7079                 :         774 :           DECL_SIZE (field) = TYPE_SIZE (integer_type);
    7080                 :         774 :           SET_DECL_ALIGN (field, TYPE_ALIGN (integer_type));
    7081                 :         774 :           DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
    7082                 :         774 :           layout_nonempty_base_or_field (rli, field, NULL_TREE,
    7083                 :             :                                          empty_base_offsets);
    7084                 :         774 :           if (was_unnamed_p)
    7085                 :           0 :             DECL_NAME (field) = NULL_TREE;
    7086                 :             :           /* Now that layout has been performed, set the size of the
    7087                 :             :              field to the size of its declared type; the rest of the
    7088                 :             :              field is effectively invisible.  */
    7089                 :         774 :           DECL_SIZE (field) = TYPE_SIZE (type);
    7090                 :             :           /* We must also reset the DECL_MODE of the field.  */
    7091                 :         774 :           SET_DECL_MODE (field, TYPE_MODE (type));
    7092                 :             :         }
    7093                 :    14665947 :       else if (might_overlap && is_empty_class (type))
    7094                 :             :         {
    7095                 :       40098 :           SET_DECL_FIELD_ABI_IGNORED (field, 1);
    7096                 :       40098 :           layout_empty_base_or_field (rli, field, empty_base_offsets);
    7097                 :             :         }
    7098                 :             :       else
    7099                 :    14625849 :         layout_nonempty_base_or_field (rli, field, NULL_TREE,
    7100                 :             :                                        empty_base_offsets);
    7101                 :             : 
    7102                 :             :       /* Remember the location of any empty classes in FIELD.  */
    7103                 :    14666721 :       record_subobject_offsets (field, empty_base_offsets);
    7104                 :             : 
    7105                 :             :       /* If a bit-field does not immediately follow another bit-field,
    7106                 :             :          and yet it starts in the middle of a byte, we have failed to
    7107                 :             :          comply with the ABI.  */
    7108                 :    14666721 :       if (warn_abi
    7109                 :      106923 :           && DECL_C_BIT_FIELD (field)
    7110                 :             :           /* The TREE_NO_WARNING flag gets set by Objective-C when
    7111                 :             :              laying out an Objective-C class.  The ObjC ABI differs
    7112                 :             :              from the C++ ABI, and so we do not want a warning
    7113                 :             :              here.  */
    7114                 :        4082 :           && !warning_suppressed_p (field, OPT_Wabi)
    7115                 :        4082 :           && !last_field_was_bitfield
    7116                 :    14667135 :           && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
    7117                 :             :                                          DECL_FIELD_BIT_OFFSET (field),
    7118                 :             :                                          bitsize_unit_node)))
    7119                 :           0 :         warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi,
    7120                 :             :                     "offset of %qD is not ABI-compliant and may "
    7121                 :             :                     "change in a future version of GCC", field);
    7122                 :             : 
    7123                 :             :       /* The middle end uses the type of expressions to determine the
    7124                 :             :          possible range of expression values.  In order to optimize
    7125                 :             :          "x.i > 7" to "false" for a 2-bit bitfield "i", the middle end
    7126                 :             :          must be made aware of the width of "i", via its type.
    7127                 :             : 
    7128                 :             :          Because C++ does not have integer types of arbitrary width,
    7129                 :             :          we must (for the purposes of the front end) convert from the
    7130                 :             :          type assigned here to the declared type of the bitfield
    7131                 :             :          whenever a bitfield expression is used as an rvalue.
    7132                 :             :          Similarly, when assigning a value to a bitfield, the value
    7133                 :             :          must be converted to the type given the bitfield here.  */
    7134                 :    14666721 :       if (DECL_C_BIT_FIELD (field))
    7135                 :             :         {
    7136                 :      382419 :           unsigned HOST_WIDE_INT width;
    7137                 :      382419 :           tree ftype = TREE_TYPE (field);
    7138                 :      382419 :           width = tree_to_uhwi (DECL_SIZE (field));
    7139                 :      382419 :           if (width != TYPE_PRECISION (ftype))
    7140                 :             :             {
    7141                 :      243034 :               TREE_TYPE (field)
    7142                 :      486068 :                 = c_build_bitfield_integer_type (width,
    7143                 :      243034 :                                                  TYPE_UNSIGNED (ftype));
    7144                 :      243034 :               TREE_TYPE (field)
    7145                 :      486068 :                 = cp_build_qualified_type (TREE_TYPE (field),
    7146                 :             :                                            cp_type_quals (ftype));
    7147                 :             :             }
    7148                 :             :         }
    7149                 :             : 
    7150                 :             :       /* If we needed additional padding after this field, add it
    7151                 :             :          now.  */
    7152                 :    14666721 :       if (padding)
    7153                 :             :         {
    7154                 :         768 :           tree padding_field;
    7155                 :             : 
    7156                 :         768 :           padding_field = build_decl (input_location,
    7157                 :             :                                       FIELD_DECL,
    7158                 :             :                                       NULL_TREE,
    7159                 :             :                                       char_type_node);
    7160                 :         768 :           DECL_BIT_FIELD (padding_field) = 1;
    7161                 :         768 :           DECL_SIZE (padding_field) = padding;
    7162                 :         768 :           DECL_CONTEXT (padding_field) = t;
    7163                 :         768 :           DECL_ARTIFICIAL (padding_field) = 1;
    7164                 :         768 :           DECL_IGNORED_P (padding_field) = 1;
    7165                 :         768 :           DECL_PADDING_P (padding_field) = 1;
    7166                 :         768 :           layout_nonempty_base_or_field (rli, padding_field,
    7167                 :             :                                          NULL_TREE,
    7168                 :             :                                          empty_base_offsets);
    7169                 :             :         }
    7170                 :             : 
    7171                 :    14666721 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    7172                 :             :     }
    7173                 :             : 
    7174                 :    36027736 :   if (!integer_zerop (rli->bitpos))
    7175                 :             :     {
    7176                 :             :       /* Make sure that we are on a byte boundary so that the size of
    7177                 :             :          the class without virtual bases will always be a round number
    7178                 :             :          of bytes.  */
    7179                 :     4291288 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    7180                 :     4291288 :       normalize_rli (rli);
    7181                 :             :     }
    7182                 :             : 
    7183                 :             :   /* We used to remove zero width bitfields at this point since PR42217,
    7184                 :             :      while the C FE never did that.  That caused ABI differences on various
    7185                 :             :      targets.  Set the DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD flag on them
    7186                 :             :      instead, so that the backends can emit -Wpsabi warnings in the cases
    7187                 :             :      where the ABI changed.  */
    7188                 :   329608613 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7189                 :             :     {
    7190                 :   293580877 :       if (TREE_CODE (field) == FIELD_DECL
    7191                 :    34147786 :           && DECL_C_BIT_FIELD (field)
    7192                 :             :           /* We should not be confused by the fact that grokbitfield
    7193                 :             :              temporarily sets the width of the bit field into
    7194                 :             :              DECL_BIT_FIELD_REPRESENTATIVE (field).
    7195                 :             :              check_bitfield_decl eventually sets DECL_SIZE (field)
    7196                 :             :              to that width.  */
    7197                 :      382422 :           && (DECL_SIZE (field) == NULL_TREE
    7198                 :      382419 :               || integer_zerop (DECL_SIZE (field)))
    7199                 :   293581975 :           && TREE_TYPE (field) != error_mark_node)
    7200                 :        1095 :         SET_DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD (field, 1);
    7201                 :   293580877 :       check_non_pod_aggregate (field);
    7202                 :             :     }
    7203                 :             : 
    7204                 :    36027736 :   if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t))
    7205                 :             :     {
    7206                 :             :       /* T needs a different layout as a base (eliding virtual bases
    7207                 :             :          or whatever).  Create that version.  */
    7208                 :    34491354 :       tree base_t = make_node (TREE_CODE (t));
    7209                 :    34491354 :       tree base_d = create_implicit_typedef (as_base_identifier, base_t);
    7210                 :             : 
    7211                 :    34491354 :       TYPE_CONTEXT (base_t) = t;
    7212                 :    34491354 :       DECL_CONTEXT (base_d) = t;
    7213                 :             : 
    7214                 :    34491354 :       set_instantiating_module (base_d);
    7215                 :             : 
    7216                 :             :       /* If the ABI version is not at least two, and the last
    7217                 :             :          field was a bit-field, RLI may not be on a byte
    7218                 :             :          boundary.  In particular, rli_size_unit_so_far might
    7219                 :             :          indicate the last complete byte, while rli_size_so_far
    7220                 :             :          indicates the total number of bits used.  Therefore,
    7221                 :             :          rli_size_so_far, rather than rli_size_unit_so_far, is
    7222                 :             :          used to compute TYPE_SIZE_UNIT.  */
    7223                 :             : 
    7224                 :             :       /* Set the size and alignment for the new type.  */
    7225                 :    34491354 :       tree eoc = end_of_class (t, eoc_nvsize);
    7226                 :    34491354 :       TYPE_SIZE_UNIT (base_t)
    7227                 :    34491354 :         = size_binop (MAX_EXPR,
    7228                 :             :                       fold_convert (sizetype,
    7229                 :             :                                size_binop (CEIL_DIV_EXPR,
    7230                 :             :                                            rli_size_so_far (rli),
    7231                 :             :                                            bitsize_int (BITS_PER_UNIT))),
    7232                 :             :                       eoc);
    7233                 :    34491354 :       TYPE_SIZE (base_t)
    7234                 :    34491354 :         = size_binop (MAX_EXPR,
    7235                 :             :                       rli_size_so_far (rli),
    7236                 :             :                       size_binop (MULT_EXPR,
    7237                 :             :                                   fold_convert (bitsizetype, eoc),
    7238                 :             :                                   bitsize_int (BITS_PER_UNIT)));
    7239                 :    34491354 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    7240                 :    34491354 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    7241                 :    34491354 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    7242                 :    34491354 :       TYPE_CXX_ODR_P (base_t) = TYPE_CXX_ODR_P (t);
    7243                 :             : 
    7244                 :             :       /* Copy the non-static data members of T. This will include its
    7245                 :             :          direct non-virtual bases & vtable.  */
    7246                 :    34491354 :       next_field = &TYPE_FIELDS (base_t);
    7247                 :   319708192 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7248                 :   285216838 :         if (TREE_CODE (field) == FIELD_DECL)
    7249                 :             :           {
    7250                 :    28107703 :             *next_field = copy_node (field);
    7251                 :             :             /* Zap any NSDMI, it's not needed and might be a deferred
    7252                 :             :                parse.  */
    7253                 :    28107703 :             DECL_INITIAL (*next_field) = NULL_TREE;
    7254                 :    28107703 :             DECL_CONTEXT (*next_field) = base_t;
    7255                 :    28107703 :             next_field = &DECL_CHAIN (*next_field);
    7256                 :             :           }
    7257                 :    34491354 :       *next_field = NULL_TREE;
    7258                 :             : 
    7259                 :             :       /* We use the base type for trivial assignments, and hence it
    7260                 :             :          needs a mode.  */
    7261                 :    34491354 :       compute_record_mode (base_t);
    7262                 :             : 
    7263                 :             :       /* Record the base version of the type.  */
    7264                 :    34491354 :       CLASSTYPE_AS_BASE (t) = base_t;
    7265                 :             :     }
    7266                 :             :   else
    7267                 :     1536382 :     CLASSTYPE_AS_BASE (t) = t;
    7268                 :             : 
    7269                 :             :   /* Every empty class contains an empty class.  */
    7270                 :    36027736 :   if (CLASSTYPE_EMPTY_P (t))
    7271                 :    29063863 :     CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    7272                 :             : 
    7273                 :             :   /* Set the TYPE_DECL for this type to contain the right
    7274                 :             :      value for DECL_OFFSET, so that we can use it as part
    7275                 :             :      of a COMPONENT_REF for multiple inheritance.  */
    7276                 :    36027736 :   layout_decl (TYPE_MAIN_DECL (t), 0);
    7277                 :             : 
    7278                 :             :   /* Now fix up any virtual base class types that we left lying
    7279                 :             :      around.  We must get these done before we try to lay out the
    7280                 :             :      virtual function table.  As a side-effect, this will remove the
    7281                 :             :      base subobject fields.  */
    7282                 :    36027736 :   layout_virtual_bases (rli, empty_base_offsets);
    7283                 :             : 
    7284                 :             :   /* Make sure that empty classes are reflected in RLI at this
    7285                 :             :      point.  */
    7286                 :    36027736 :   include_empty_classes (rli);
    7287                 :             : 
    7288                 :             :   /* Make sure not to create any structures with zero size.  */
    7289                 :    36027736 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    7290                 :    12739453 :     place_field (rli,
    7291                 :             :                  build_decl (input_location,
    7292                 :             :                              FIELD_DECL, NULL_TREE, char_type_node));
    7293                 :             : 
    7294                 :             :   /* If this is a non-POD, declaring it packed makes a difference to how it
    7295                 :             :      can be used as a field; don't let finalize_record_size undo it.  */
    7296                 :    36027736 :   if (TYPE_PACKED (t) && !layout_pod_type_p (t))
    7297                 :          72 :     rli->packed_maybe_necessary = true;
    7298                 :             : 
    7299                 :             :   /* Let the back end lay out the type.  */
    7300                 :    36027736 :   finish_record_layout (rli, /*free_p=*/true);
    7301                 :             : 
    7302                 :             :   /* If we didn't end up needing an as-base type, don't use it.  */
    7303                 :    36027736 :   if (CLASSTYPE_AS_BASE (t) != t
    7304                 :             :       /* If T's CLASSTYPE_AS_BASE is TYPE_USER_ALIGN, but T is not,
    7305                 :             :          replacing the as-base type would change CLASSTYPE_USER_ALIGN,
    7306                 :             :          causing us to lose the user-specified alignment as in PR94050.  */
    7307                 :    34491354 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    7308                 :    70519076 :       && tree_int_cst_equal (TYPE_SIZE (t),
    7309                 :    34491340 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    7310                 :    20911289 :     CLASSTYPE_AS_BASE (t) = t;
    7311                 :             : 
    7312                 :    36027736 :   if (TYPE_SIZE_UNIT (t)
    7313                 :    36027736 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    7314                 :    36027736 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    7315                 :    72055463 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    7316                 :           0 :     error ("size of type %qT is too large (%qE bytes)", t, TYPE_SIZE_UNIT (t));
    7317                 :             : 
    7318                 :             :   /* Warn about bases that can't be talked about due to ambiguity.  */
    7319                 :    36027736 :   maybe_warn_about_inaccessible_bases (t);
    7320                 :             : 
    7321                 :             :   /* Now that we're done with layout, give the base fields the real types.  */
    7322                 :   329797543 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    7323                 :   293769807 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    7324                 :    16854931 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    7325                 :             : 
    7326                 :             :   /* Clean up.  */
    7327                 :    36027736 :   splay_tree_delete (empty_base_offsets);
    7328                 :             : 
    7329                 :    36027736 :   if (CLASSTYPE_EMPTY_P (t)
    7330                 :    65091599 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    7331                 :    29063863 :                           TYPE_SIZE_UNIT (t)))
    7332                 :       43591 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    7333                 :    36027736 : }
    7334                 :             : 
    7335                 :             : /* Determine the "key method" for the class type indicated by TYPE,
    7336                 :             :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    7337                 :             : 
    7338                 :             : void
    7339                 :     1628431 : determine_key_method (tree type)
    7340                 :             : {
    7341                 :     1628431 :   tree method;
    7342                 :             : 
    7343                 :     1628431 :   if (processing_template_decl
    7344                 :     1628431 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    7345                 :     2342253 :       || CLASSTYPE_INTERFACE_KNOWN (type))
    7346                 :             :     return;
    7347                 :             : 
    7348                 :             :   /* The key method is the first non-pure virtual function that is not
    7349                 :             :      inline at the point of class definition.  On some targets the
    7350                 :             :      key function may not be inline; those targets should not call
    7351                 :             :      this function until the end of the translation unit.  */
    7352                 :     7289403 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    7353                 :     7134850 :     if (TREE_CODE (method) == FUNCTION_DECL
    7354                 :     5830018 :         && DECL_VINDEX (method) != NULL_TREE
    7355                 :     1141050 :         && ! DECL_DECLARED_INLINE_P (method)
    7356                 :     7715855 :         && ! DECL_PURE_VIRTUAL_P (method))
    7357                 :             :       {
    7358                 :      559240 :         CLASSTYPE_KEY_METHOD (type) = method;
    7359                 :      559240 :         break;
    7360                 :             :       }
    7361                 :             : 
    7362                 :             :   return;
    7363                 :             : }
    7364                 :             : 
    7365                 :             : /* Helper of find_flexarrays.  Return true when FLD refers to a non-static
    7366                 :             :    class data member of non-zero size, otherwise false.  */
    7367                 :             : 
    7368                 :             : static inline bool
    7369                 :    33964263 : field_nonempty_p (const_tree fld)
    7370                 :             : {
    7371                 :    33964263 :   if (TREE_CODE (fld) == ERROR_MARK)
    7372                 :             :     return false;
    7373                 :             : 
    7374                 :    33964263 :   tree type = TREE_TYPE (fld);
    7375                 :    33964263 :   if (TREE_CODE (fld) == FIELD_DECL
    7376                 :    33964263 :       && TREE_CODE (type) != ERROR_MARK
    7377                 :    67928526 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    7378                 :             :     {
    7379                 :    33829395 :       return TYPE_SIZE (type)
    7380                 :    33829395 :         && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
    7381                 :    33827742 :             || !tree_int_cst_equal (size_zero_node, TYPE_SIZE (type)));
    7382                 :             :     }
    7383                 :             : 
    7384                 :             :   return false;
    7385                 :             : }
    7386                 :             : 
    7387                 :             : /* Used by find_flexarrays and related functions.  */
    7388                 :             : 
    7389                 :             : struct flexmems_t
    7390                 :             : {
    7391                 :             :   /* The first flexible array member or non-zero array member found
    7392                 :             :      in the order of layout.  */
    7393                 :             :   tree array;
    7394                 :             :   /* First non-static non-empty data member in the class or its bases.  */
    7395                 :             :   tree first;
    7396                 :             :   /* The first non-static non-empty data member following either
    7397                 :             :      the flexible array member, if found, or the zero-length array member
    7398                 :             :      otherwise.  AFTER[1] refers to the first such data member of a union
    7399                 :             :      of which the struct containing the flexible array member or zero-length
    7400                 :             :      array is a member, or NULL when no such union exists.  This element is
    7401                 :             :      only used during searching, not for diagnosing problems.  AFTER[0]
    7402                 :             :      refers to the first such data member that is not a member of such
    7403                 :             :      a union.  */
    7404                 :             :   tree after[2];
    7405                 :             : 
    7406                 :             :   /* Refers to a struct (not union) in which the struct of which the flexible
    7407                 :             :      array is member is defined.  Used to diagnose strictly (according to C)
    7408                 :             :      invalid uses of the latter structs.  */
    7409                 :             :   tree enclosing;
    7410                 :             : };
    7411                 :             : 
    7412                 :             : /* Find either the first flexible array member or the first zero-length
    7413                 :             :    array, in that order of preference, among members of class T (but not
    7414                 :             :    its base classes), and set members of FMEM accordingly.
    7415                 :             :    BASE_P is true if T is a base class of another class.
    7416                 :             :    PUN is set to the outermost union in which the flexible array member
    7417                 :             :    (or zero-length array) is defined if one such union exists, otherwise
    7418                 :             :    to NULL.
    7419                 :             :    Similarly, PSTR is set to a data member of the outermost struct of
    7420                 :             :    which the flexible array is a member if one such struct exists,
    7421                 :             :    otherwise to NULL.  */
    7422                 :             : 
    7423                 :             : static void
    7424                 :    65390703 : find_flexarrays (tree t, flexmems_t *fmem, bool base_p,
    7425                 :             :                  tree pun /* = NULL_TREE */,
    7426                 :             :                  tree pstr /* = NULL_TREE */)
    7427                 :             : {
    7428                 :             :   /* Set the "pointer" to the outermost enclosing union if not set
    7429                 :             :      yet and maintain it for the remainder of the recursion.   */
    7430                 :    65390703 :   if (!pun && TREE_CODE (t) == UNION_TYPE)
    7431                 :     1284793 :     pun = t;
    7432                 :             : 
    7433                 :   946792427 :   for (tree fld = TYPE_FIELDS (t); fld; fld = DECL_CHAIN (fld))
    7434                 :             :     {
    7435                 :   881402349 :       if (fld == error_mark_node)
    7