LCOV - code coverage report
Current view: top level - gcc/cp - class.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 3883 4036 96.2 %
Date: 2020-03-28 11:57:23 Functions: 187 192 97.4 %
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 classes and their related objects.
       2                 :            :    Copyright (C) 1987-2020 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 void remove_zero_width_bit_fields (tree);
     140                 :            : static bool accessible_nvdtor_p (tree);
     141                 :            : 
     142                 :            : /* Used by find_flexarrays and related functions.  */
     143                 :            : struct flexmems_t;
     144                 :            : static void diagnose_flexarrays (tree, const flexmems_t *);
     145                 :            : static void find_flexarrays (tree, flexmems_t *, bool = false,
     146                 :            :                              tree = NULL_TREE, tree = NULL_TREE);
     147                 :            : static void check_flexarrays (tree, flexmems_t * = NULL, bool = false);
     148                 :            : static void check_bases (tree, int *, int *);
     149                 :            : static void check_bases_and_members (tree);
     150                 :            : static tree create_vtable_ptr (tree, tree *);
     151                 :            : static void include_empty_classes (record_layout_info);
     152                 :            : static void layout_class_type (tree, tree *);
     153                 :            : static void propagate_binfo_offsets (tree, tree);
     154                 :            : static void layout_virtual_bases (record_layout_info, splay_tree);
     155                 :            : static void build_vbase_offset_vtbl_entries (tree, vtbl_init_data *);
     156                 :            : static void add_vcall_offset_vtbl_entries_r (tree, vtbl_init_data *);
     157                 :            : static void add_vcall_offset_vtbl_entries_1 (tree, vtbl_init_data *);
     158                 :            : static void build_vcall_offset_vtbl_entries (tree, vtbl_init_data *);
     159                 :            : static void add_vcall_offset (tree, tree, vtbl_init_data *);
     160                 :            : static void layout_vtable_decl (tree, int);
     161                 :            : static tree dfs_find_final_overrider_pre (tree, void *);
     162                 :            : static tree dfs_find_final_overrider_post (tree, void *);
     163                 :            : static tree find_final_overrider (tree, tree, tree);
     164                 :            : static int make_new_vtable (tree, tree);
     165                 :            : static tree get_primary_binfo (tree);
     166                 :            : static int maybe_indent_hierarchy (FILE *, int, int);
     167                 :            : static tree dump_class_hierarchy_r (FILE *, dump_flags_t, tree, tree, int);
     168                 :            : static void dump_class_hierarchy (tree);
     169                 :            : static void dump_class_hierarchy_1 (FILE *, dump_flags_t, tree);
     170                 :            : static void dump_array (FILE *, tree);
     171                 :            : static void dump_vtable (tree, tree, tree);
     172                 :            : static void dump_vtt (tree, tree);
     173                 :            : static void dump_thunk (FILE *, int, tree);
     174                 :            : static tree build_vtable (tree, tree, tree);
     175                 :            : static void initialize_vtable (tree, vec<constructor_elt, va_gc> *);
     176                 :            : static void layout_nonempty_base_or_field (record_layout_info,
     177                 :            :                                            tree, tree, splay_tree);
     178                 :            : static void accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     179                 :            :                                    vec<constructor_elt, va_gc> **);
     180                 :            : static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree,
     181                 :            :                                        vec<constructor_elt, va_gc> **);
     182                 :            : static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
     183                 :            : static void build_vcall_and_vbase_vtbl_entries (tree, vtbl_init_data *);
     184                 :            : static void clone_constructors_and_destructors (tree);
     185                 :            : static tree build_clone (tree, tree);
     186                 :            : static void update_vtable_entry_for_fn (tree, tree, tree, tree *, unsigned);
     187                 :            : static void build_ctor_vtbl_group (tree, tree);
     188                 :            : static void build_vtt (tree);
     189                 :            : static tree binfo_ctor_vtable (tree);
     190                 :            : static void build_vtt_inits (tree, tree, vec<constructor_elt, va_gc> **,
     191                 :            :                              tree *);
     192                 :            : static tree dfs_build_secondary_vptr_vtt_inits (tree, void *);
     193                 :            : static tree dfs_fixup_binfo_vtbls (tree, void *);
     194                 :            : static int record_subobject_offset (tree, tree, splay_tree);
     195                 :            : static int check_subobject_offset (tree, tree, splay_tree);
     196                 :            : static int walk_subobject_offsets (tree, subobject_offset_fn,
     197                 :            :                                    tree, splay_tree, tree, int);
     198                 :            : static int layout_conflict_p (tree, tree, splay_tree, int);
     199                 :            : static int splay_tree_compare_integer_csts (splay_tree_key k1,
     200                 :            :                                             splay_tree_key k2);
     201                 :            : static void maybe_warn_about_inaccessible_bases (tree);
     202                 :            : static bool type_requires_array_cookie (tree);
     203                 :            : static bool base_derived_from (tree, tree);
     204                 :            : static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
     205                 :            : static tree end_of_base (tree);
     206                 :            : static tree get_vcall_index (tree, tree);
     207                 :            : static bool type_maybe_constexpr_default_constructor (tree);
     208                 :            : static bool type_maybe_constexpr_destructor (tree);
     209                 :            : static bool field_poverlapping_p (tree);
     210                 :            : 
     211                 :            : /* Return a COND_EXPR that executes TRUE_STMT if this execution of the
     212                 :            :    'structor is in charge of 'structing virtual bases, or FALSE_STMT
     213                 :            :    otherwise.  */
     214                 :            : 
     215                 :            : tree
     216                 :     136562 : build_if_in_charge (tree true_stmt, tree false_stmt)
     217                 :            : {
     218                 :     273124 :   gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (current_function_decl));
     219                 :     273124 :   tree cmp = build2 (NE_EXPR, boolean_type_node,
     220                 :     136562 :                      current_in_charge_parm, integer_zero_node);
     221                 :     136562 :   tree type = unlowered_expr_type (true_stmt);
     222                 :     136562 :   if (VOID_TYPE_P (type))
     223                 :       9598 :     type = unlowered_expr_type (false_stmt);
     224                 :     136562 :   tree cond = build3 (COND_EXPR, type,
     225                 :            :                       cmp, true_stmt, false_stmt);
     226                 :     136562 :   return cond;
     227                 :            : }
     228                 :            : 
     229                 :            : /* Convert to or from a base subobject.  EXPR is an expression of type
     230                 :            :    `A' or `A*', an expression of type `B' or `B*' is returned.  To
     231                 :            :    convert A to a base B, CODE is PLUS_EXPR and BINFO is the binfo for
     232                 :            :    the B base instance within A.  To convert base A to derived B, CODE
     233                 :            :    is MINUS_EXPR and BINFO is the binfo for the A instance within B.
     234                 :            :    In this latter case, A must not be a morally virtual base of B.
     235                 :            :    NONNULL is true if EXPR is known to be non-NULL (this is only
     236                 :            :    needed when EXPR is of pointer type).  CV qualifiers are preserved
     237                 :            :    from EXPR.  */
     238                 :            : 
     239                 :            : tree
     240                 :   18570800 : build_base_path (enum tree_code code,
     241                 :            :                  tree expr,
     242                 :            :                  tree binfo,
     243                 :            :                  int nonnull,
     244                 :            :                  tsubst_flags_t complain)
     245                 :            : {
     246                 :   18570800 :   tree v_binfo = NULL_TREE;
     247                 :   18570800 :   tree d_binfo = NULL_TREE;
     248                 :   18570800 :   tree probe;
     249                 :   18570800 :   tree offset;
     250                 :   18570800 :   tree target_type;
     251                 :   18570800 :   tree null_test = NULL;
     252                 :   18570800 :   tree ptr_target_type;
     253                 :   18570800 :   int fixed_type_p;
     254                 :   18570800 :   int want_pointer = TYPE_PTR_P (TREE_TYPE (expr));
     255                 :   18570800 :   bool has_empty = false;
     256                 :   18570800 :   bool virtual_access;
     257                 :   18570800 :   bool rvalue = false;
     258                 :            : 
     259                 :   18570800 :   if (expr == error_mark_node || binfo == error_mark_node || !binfo)
     260                 :            :     return error_mark_node;
     261                 :            : 
     262                 :   39918000 :   for (probe = binfo; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
     263                 :            :     {
     264                 :   21347200 :       d_binfo = probe;
     265                 :   21347200 :       if (is_empty_class (BINFO_TYPE (probe)))
     266                 :    5527770 :         has_empty = true;
     267                 :   42629200 :       if (!v_binfo && BINFO_VIRTUAL_P (probe))
     268                 :            :         v_binfo = probe;
     269                 :            :     }
     270                 :            : 
     271                 :   18570800 :   probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
     272                 :   18570800 :   if (want_pointer)
     273                 :   17446600 :     probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
     274                 :   18570800 :   if (dependent_type_p (probe))
     275                 :      16935 :     if (tree open = currently_open_class (probe))
     276                 :      16935 :       probe = open;
     277                 :            : 
     278                 :   18570800 :   if (code == PLUS_EXPR
     279                 :   36244500 :       && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
     280                 :            :     {
     281                 :            :       /* This can happen when adjust_result_of_qualified_name_lookup can't
     282                 :            :          find a unique base binfo in a call to a member function.  We
     283                 :            :          couldn't give the diagnostic then since we might have been calling
     284                 :            :          a static member function, so we do it now.  In other cases, eg.
     285                 :            :          during error recovery (c++/71979), we may not have a base at all.  */
     286                 :          7 :       if (complain & tf_error)
     287                 :            :         {
     288                 :          7 :           tree base = lookup_base (probe, BINFO_TYPE (d_binfo),
     289                 :            :                                    ba_unique, NULL, complain);
     290                 :          7 :           gcc_assert (base == error_mark_node || !base);
     291                 :            :         }
     292                 :          7 :       return error_mark_node;
     293                 :            :     }
     294                 :            : 
     295                 :   19467900 :   gcc_assert ((code == MINUS_EXPR
     296                 :            :                && SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), probe))
     297                 :            :               || code == PLUS_EXPR);
     298                 :            : 
     299                 :   18570800 :   if (binfo == d_binfo)
     300                 :            :     /* Nothing to do.  */
     301                 :            :     return expr;
     302                 :            : 
     303                 :    2575040 :   if (code == MINUS_EXPR && v_binfo)
     304                 :            :     {
     305                 :         15 :       if (complain & tf_error)
     306                 :            :         {
     307                 :         11 :           if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
     308                 :            :             {
     309                 :         11 :               if (want_pointer)
     310                 :         11 :                 error ("cannot convert from pointer to base class %qT to "
     311                 :            :                        "pointer to derived class %qT because the base is "
     312                 :         11 :                        "virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     313                 :            :               else
     314                 :          0 :                 error ("cannot convert from base class %qT to derived "
     315                 :            :                        "class %qT because the base is virtual",
     316                 :          0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
     317                 :            :             }         
     318                 :            :           else
     319                 :            :             {
     320                 :          0 :               if (want_pointer)
     321                 :          0 :                 error ("cannot convert from pointer to base class %qT to "
     322                 :            :                        "pointer to derived class %qT via virtual base %qT",
     323                 :          0 :                        BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
     324                 :          0 :                        BINFO_TYPE (v_binfo));
     325                 :            :               else
     326                 :          0 :                 error ("cannot convert from base class %qT to derived "
     327                 :          0 :                        "class %qT via virtual base %qT", BINFO_TYPE (binfo),
     328                 :          0 :                        BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
     329                 :            :             }
     330                 :            :         }
     331                 :         15 :       return error_mark_node;
     332                 :            :     }
     333                 :            : 
     334                 :    2575020 :   if (!want_pointer)
     335                 :            :     {
     336                 :    1122920 :       rvalue = !lvalue_p (expr);
     337                 :            :       /* This must happen before the call to save_expr.  */
     338                 :    1122920 :       expr = cp_build_addr_expr (expr, complain);
     339                 :            :     }
     340                 :            :   else
     341                 :    1452100 :     expr = mark_rvalue_use (expr);
     342                 :            : 
     343                 :    2575020 :   offset = BINFO_OFFSET (binfo);
     344                 :    2575020 :   fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
     345                 :    5150050 :   target_type = code == PLUS_EXPR ? BINFO_TYPE (binfo) : BINFO_TYPE (d_binfo);
     346                 :            :   /* TARGET_TYPE has been extracted from BINFO, and, is therefore always
     347                 :            :      cv-unqualified.  Extract the cv-qualifiers from EXPR so that the
     348                 :            :      expression returned matches the input.  */
     349                 :    2575020 :   target_type = cp_build_qualified_type
     350                 :            :     (target_type, cp_type_quals (TREE_TYPE (TREE_TYPE (expr))));
     351                 :    2575020 :   ptr_target_type = build_pointer_type (target_type);
     352                 :            : 
     353                 :            :   /* Do we need to look in the vtable for the real offset?  */
     354                 :    2575020 :   virtual_access = (v_binfo && fixed_type_p <= 0);
     355                 :            : 
     356                 :            :   /* Don't bother with the calculations inside sizeof; they'll ICE if the
     357                 :            :      source type is incomplete and the pointer value doesn't matter.  In a
     358                 :            :      template (even in instantiate_non_dependent_expr), we don't have vtables
     359                 :            :      set up properly yet, and the value doesn't matter there either; we're
     360                 :            :      just interested in the result of overload resolution.  */
     361                 :    2575020 :   if (cp_unevaluated_operand != 0
     362                 :    2491080 :       || processing_template_decl
     363                 :    5041890 :       || in_template_function ())
     364                 :            :     {
     365                 :     108372 :       expr = build_nop (ptr_target_type, expr);
     366                 :     108372 :       goto indout;
     367                 :            :     }
     368                 :            : 
     369                 :    2466650 :   if (!COMPLETE_TYPE_P (probe))
     370                 :            :     {
     371                 :          6 :       if (complain & tf_error)
     372                 :          6 :         error ("cannot convert from %qT to base class %qT because %qT is "
     373                 :          6 :                "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
     374                 :          6 :                BINFO_TYPE (d_binfo));
     375                 :          6 :       return error_mark_node;
     376                 :            :     }
     377                 :            : 
     378                 :            :   /* If we're in an NSDMI, we don't have the full constructor context yet
     379                 :            :      that we need for converting to a virtual base, so just build a stub
     380                 :            :      CONVERT_EXPR and expand it later in bot_replace.  */
     381                 :    2466640 :   if (virtual_access && fixed_type_p < 0
     382                 :    2466640 :       && current_scope () != current_function_decl)
     383                 :            :     {
     384                 :         18 :       expr = build1 (CONVERT_EXPR, ptr_target_type, expr);
     385                 :         18 :       CONVERT_EXPR_VBASE_PATH (expr) = true;
     386                 :         18 :       goto indout;
     387                 :            :     }
     388                 :            : 
     389                 :            :   /* Do we need to check for a null pointer?  */
     390                 :    2466630 :   if (want_pointer && !nonnull)
     391                 :            :     {
     392                 :            :       /* If we know the conversion will not actually change the value
     393                 :            :          of EXPR, then we can avoid testing the expression for NULL.
     394                 :            :          We have to avoid generating a COMPONENT_REF for a base class
     395                 :            :          field, because other parts of the compiler know that such
     396                 :            :          expressions are always non-NULL.  */
     397                 :      60022 :       if (!virtual_access && integer_zerop (offset))
     398                 :      57777 :         return build_nop (ptr_target_type, expr);
     399                 :       2245 :       null_test = error_mark_node;
     400                 :            :     }
     401                 :            : 
     402                 :            :   /* Protect against multiple evaluation if necessary.  */
     403                 :    2408850 :   if (TREE_SIDE_EFFECTS (expr) && (null_test || virtual_access))
     404                 :        313 :     expr = save_expr (expr);
     405                 :            : 
     406                 :            :   /* Now that we've saved expr, build the real null test.  */
     407                 :    2408850 :   if (null_test)
     408                 :            :     {
     409                 :       2245 :       tree zero = cp_convert (TREE_TYPE (expr), nullptr_node, complain);
     410                 :       2245 :       null_test = build2_loc (input_location, NE_EXPR, boolean_type_node,
     411                 :            :                               expr, zero);
     412                 :            :       /* This is a compiler generated comparison, don't emit
     413                 :            :          e.g. -Wnonnull-compare warning for it.  */
     414                 :       2245 :       TREE_NO_WARNING (null_test) = 1;
     415                 :            :     }
     416                 :            : 
     417                 :            :   /* If this is a simple base reference, express it as a COMPONENT_REF.  */
     418                 :    2408850 :   if (code == PLUS_EXPR && !virtual_access
     419                 :            :       /* We don't build base fields for empty bases, and they aren't very
     420                 :            :          interesting to the optimizers anyway.  */
     421                 :    2341880 :       && !has_empty)
     422                 :            :     {
     423                 :    1231090 :       expr = cp_build_fold_indirect_ref (expr);
     424                 :    1231090 :       expr = build_simple_base_path (expr, binfo);
     425                 :    1231090 :       if (rvalue && lvalue_p (expr))
     426                 :      14720 :         expr = move (expr);
     427                 :    1231090 :       if (want_pointer)
     428                 :     600559 :         expr = build_address (expr);
     429                 :    1231090 :       target_type = TREE_TYPE (expr);
     430                 :    1231090 :       goto out;
     431                 :            :     }
     432                 :            : 
     433                 :    1177760 :   if (virtual_access)
     434                 :            :     {
     435                 :            :       /* Going via virtual base V_BINFO.  We need the static offset
     436                 :            :          from V_BINFO to BINFO, and the dynamic offset from D_BINFO to
     437                 :            :          V_BINFO.  That offset is an entry in D_BINFO's vtable.  */
     438                 :      46082 :       tree v_offset;
     439                 :            : 
     440                 :      46082 :       if (fixed_type_p < 0 && in_base_initializer)
     441                 :            :         {
     442                 :            :           /* In a base member initializer, we cannot rely on the
     443                 :            :              vtable being set up.  We have to indirect via the
     444                 :            :              vtt_parm.  */
     445                 :         13 :           tree t;
     446                 :            : 
     447                 :         13 :           t = TREE_TYPE (TYPE_VFIELD (current_class_type));
     448                 :         13 :           t = build_pointer_type (t);
     449                 :         13 :           v_offset = fold_convert (t, current_vtt_parm);
     450                 :         13 :           v_offset = cp_build_fold_indirect_ref (v_offset);
     451                 :            :         }
     452                 :            :       else
     453                 :            :         {
     454                 :      46069 :           tree t = expr;
     455                 :      46069 :           if (sanitize_flags_p (SANITIZE_VPTR)
     456                 :      46069 :               && fixed_type_p == 0)
     457                 :            :             {
     458                 :         64 :               t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location,
     459                 :            :                                                            probe, expr);
     460                 :         64 :               if (t == NULL_TREE)
     461                 :          0 :                 t = expr;
     462                 :            :             }
     463                 :      92138 :           v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
     464                 :      46069 :           TREE_TYPE (TREE_TYPE (expr)));
     465                 :            :         }
     466                 :            : 
     467                 :      46082 :       if (v_offset == error_mark_node)
     468                 :            :         return error_mark_node;
     469                 :            : 
     470                 :      46082 :       v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
     471                 :      46082 :       v_offset = build1 (NOP_EXPR,
     472                 :            :                          build_pointer_type (ptrdiff_type_node),
     473                 :            :                          v_offset);
     474                 :      46082 :       v_offset = cp_build_fold_indirect_ref (v_offset);
     475                 :      46082 :       TREE_CONSTANT (v_offset) = 1;
     476                 :            : 
     477                 :      92164 :       offset = convert_to_integer (ptrdiff_type_node,
     478                 :            :                                    size_diffop_loc (input_location, offset,
     479                 :      46082 :                                                 BINFO_OFFSET (v_binfo)));
     480                 :            : 
     481                 :      46082 :       if (!integer_zerop (offset))
     482                 :        657 :         v_offset = build2 (code, ptrdiff_type_node, v_offset, offset);
     483                 :            : 
     484                 :      46082 :       if (fixed_type_p < 0)
     485                 :            :         /* Negative fixed_type_p means this is a constructor or destructor;
     486                 :            :            virtual base layout is fixed in in-charge [cd]tors, but not in
     487                 :            :            base [cd]tors.  */
     488                 :      37164 :         offset = build_if_in_charge
     489                 :      37164 :           (convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo)),
     490                 :            :            v_offset);
     491                 :            :       else
     492                 :            :         offset = v_offset;
     493                 :            :     }
     494                 :            : 
     495                 :    1177760 :   if (want_pointer)
     496                 :     749608 :     target_type = ptr_target_type;
     497                 :            : 
     498                 :    1177760 :   expr = build1 (NOP_EXPR, ptr_target_type, expr);
     499                 :            : 
     500                 :    1177760 :   if (!integer_zerop (offset))
     501                 :            :     {
     502                 :      46813 :       offset = fold_convert (sizetype, offset);
     503                 :      46813 :       if (code == MINUS_EXPR)
     504                 :        298 :         offset = fold_build1_loc (input_location, NEGATE_EXPR, sizetype, offset);
     505                 :      46813 :       expr = fold_build_pointer_plus (expr, offset);
     506                 :            :     }
     507                 :            :   else
     508                 :            :     null_test = NULL;
     509                 :            : 
     510                 :    1286150 :  indout:
     511                 :    1286150 :   if (!want_pointer)
     512                 :            :     {
     513                 :     492396 :       expr = cp_build_fold_indirect_ref (expr);
     514                 :     492396 :       if (rvalue)
     515                 :     191296 :         expr = move (expr);
     516                 :            :     }
     517                 :            : 
     518                 :     793757 :  out:
     519                 :    2517240 :   if (null_test)
     520                 :       2245 :     expr = fold_build3_loc (input_location, COND_EXPR, target_type, null_test, expr,
     521                 :            :                             build_zero_cst (target_type));
     522                 :            : 
     523                 :            :   return expr;
     524                 :            : }
     525                 :            : 
     526                 :            : /* Subroutine of build_base_path; EXPR and BINFO are as in that function.
     527                 :            :    Perform a derived-to-base conversion by recursively building up a
     528                 :            :    sequence of COMPONENT_REFs to the appropriate base fields.  */
     529                 :            : 
     530                 :            : static tree
     531                 :    3717860 : build_simple_base_path (tree expr, tree binfo)
     532                 :            : {
     533                 :    3717860 :   tree type = BINFO_TYPE (binfo);
     534                 :    3717860 :   tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
     535                 :    3717860 :   tree field;
     536                 :            : 
     537                 :    3717860 :   if (d_binfo == NULL_TREE)
     538                 :            :     {
     539                 :    1832520 :       tree temp;
     540                 :            : 
     541                 :    1832520 :       gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type);
     542                 :            : 
     543                 :            :       /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x'
     544                 :            :          into `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only
     545                 :            :          an lvalue in the front end; only _DECLs and _REFs are lvalues
     546                 :            :          in the back end.  */
     547                 :    1832520 :       temp = unary_complex_lvalue (ADDR_EXPR, expr);
     548                 :    1832520 :       if (temp)
     549                 :          0 :         expr = cp_build_fold_indirect_ref (temp);
     550                 :            : 
     551                 :    1832520 :       return expr;
     552                 :            :     }
     553                 :            : 
     554                 :            :   /* Recurse.  */
     555                 :    1885350 :   expr = build_simple_base_path (expr, d_binfo);
     556                 :            : 
     557                 :   10687400 :   for (field = TYPE_FIELDS (BINFO_TYPE (d_binfo));
     558                 :   10687400 :        field; field = DECL_CHAIN (field))
     559                 :            :     /* Is this the base field created by build_base_field?  */
     560                 :   10687400 :     if (TREE_CODE (field) == FIELD_DECL
     561                 :    2409490 :         && DECL_FIELD_IS_BASE (field)
     562                 :    2385600 :         && TREE_TYPE (field) == type
     563                 :            :         /* If we're looking for a field in the most-derived class,
     564                 :            :            also check the field offset; we can have two base fields
     565                 :            :            of the same type if one is an indirect virtual base and one
     566                 :            :            is a direct non-virtual base.  */
     567                 :   12572900 :         && (BINFO_INHERITANCE_CHAIN (d_binfo)
     568                 :    1832670 :             || tree_int_cst_equal (byte_position (field),
     569                 :    1832670 :                                    BINFO_OFFSET (binfo))))
     570                 :            :       {
     571                 :            :         /* We don't use build_class_member_access_expr here, as that
     572                 :            :            has unnecessary checks, and more importantly results in
     573                 :            :            recursive calls to dfs_walk_once.  */
     574                 :    1885350 :         int type_quals = cp_type_quals (TREE_TYPE (expr));
     575                 :            : 
     576                 :    1885350 :         expr = build3 (COMPONENT_REF,
     577                 :            :                        cp_build_qualified_type (type, type_quals),
     578                 :            :                        expr, field, NULL_TREE);
     579                 :            :         /* Mark the expression const or volatile, as appropriate.
     580                 :            :            Even though we've dealt with the type above, we still have
     581                 :            :            to mark the expression itself.  */
     582                 :    1885350 :         if (type_quals & TYPE_QUAL_CONST)
     583                 :     217357 :           TREE_READONLY (expr) = 1;
     584                 :    1885350 :         if (type_quals & TYPE_QUAL_VOLATILE)
     585                 :       1204 :           TREE_THIS_VOLATILE (expr) = 1;
     586                 :            : 
     587                 :    1885350 :         return expr;
     588                 :            :       }
     589                 :            : 
     590                 :            :   /* Didn't find the base field?!?  */
     591                 :          0 :   gcc_unreachable ();
     592                 :            : }
     593                 :            : 
     594                 :            : /* Convert OBJECT to the base TYPE.  OBJECT is an expression whose
     595                 :            :    type is a class type or a pointer to a class type.  In the former
     596                 :            :    case, TYPE is also a class type; in the latter it is another
     597                 :            :    pointer type.  If CHECK_ACCESS is true, an error message is emitted
     598                 :            :    if TYPE is inaccessible.  If OBJECT has pointer type, the value is
     599                 :            :    assumed to be non-NULL.  */
     600                 :            : 
     601                 :            : tree
     602                 :     671574 : convert_to_base (tree object, tree type, bool check_access, bool nonnull,
     603                 :            :                  tsubst_flags_t complain)
     604                 :            : {
     605                 :     671574 :   tree binfo;
     606                 :     671574 :   tree object_type;
     607                 :            : 
     608                 :     671574 :   if (TYPE_PTR_P (TREE_TYPE (object)))
     609                 :            :     {
     610                 :      72246 :       object_type = TREE_TYPE (TREE_TYPE (object));
     611                 :      72246 :       type = TREE_TYPE (type);
     612                 :            :     }
     613                 :            :   else
     614                 :     671574 :     object_type = TREE_TYPE (object);
     615                 :            : 
     616                 :     673885 :   binfo = lookup_base (object_type, type, check_access ? ba_check : ba_unique,
     617                 :            :                        NULL, complain);
     618                 :     671574 :   if (!binfo || binfo == error_mark_node)
     619                 :        111 :     return error_mark_node;
     620                 :            : 
     621                 :     671463 :   return build_base_path (PLUS_EXPR, object, binfo, nonnull, complain);
     622                 :            : }
     623                 :            : 
     624                 :            : /* EXPR is an expression with unqualified class type.  BASE is a base
     625                 :            :    binfo of that class type.  Returns EXPR, converted to the BASE
     626                 :            :    type.  This function assumes that EXPR is the most derived class;
     627                 :            :    therefore virtual bases can be found at their static offsets.  */
     628                 :            : 
     629                 :            : tree
     630                 :     691123 : convert_to_base_statically (tree expr, tree base)
     631                 :            : {
     632                 :     691123 :   tree expr_type;
     633                 :            : 
     634                 :     691123 :   expr_type = TREE_TYPE (expr);
     635                 :     691123 :   if (!SAME_BINFO_TYPE_P (BINFO_TYPE (base), expr_type))
     636                 :            :     {
     637                 :            :       /* If this is a non-empty base, use a COMPONENT_REF.  */
     638                 :     691123 :       if (!is_empty_class (BINFO_TYPE (base)))
     639                 :     308413 :         return build_simple_base_path (expr, base);
     640                 :            : 
     641                 :            :       /* We use fold_build2 and fold_convert below to simplify the trees
     642                 :            :          provided to the optimizers.  It is not safe to call these functions
     643                 :            :          when processing a template because they do not handle C++-specific
     644                 :            :          trees.  */
     645                 :     382710 :       gcc_assert (!processing_template_decl);
     646                 :     382710 :       expr = cp_build_addr_expr (expr, tf_warning_or_error);
     647                 :     382710 :       if (!integer_zerop (BINFO_OFFSET (base)))
     648                 :        252 :         expr = fold_build_pointer_plus_loc (input_location,
     649                 :        252 :                                             expr, BINFO_OFFSET (base));
     650                 :     382710 :       expr = fold_convert (build_pointer_type (BINFO_TYPE (base)), expr);
     651                 :     382710 :       expr = build_fold_indirect_ref_loc (input_location, expr);
     652                 :            :     }
     653                 :            : 
     654                 :            :   return expr;
     655                 :            : }
     656                 :            : 
     657                 :            : 
     658                 :            : tree
     659                 :     391815 : build_vfield_ref (tree datum, tree type)
     660                 :            : {
     661                 :     391815 :   tree vfield, vcontext;
     662                 :            : 
     663                 :     391815 :   if (datum == error_mark_node
     664                 :            :       /* Can happen in case of duplicate base types (c++/59082).  */
     665                 :     783630 :       || !TYPE_VFIELD (type))
     666                 :            :     return error_mark_node;
     667                 :            : 
     668                 :            :   /* First, convert to the requested type.  */
     669                 :     391815 :   if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (datum), type))
     670                 :          0 :     datum = convert_to_base (datum, type, /*check_access=*/false,
     671                 :            :                              /*nonnull=*/true, tf_warning_or_error);
     672                 :            : 
     673                 :            :   /* Second, the requested type may not be the owner of its own vptr.
     674                 :            :      If not, convert to the base class that owns it.  We cannot use
     675                 :            :      convert_to_base here, because VCONTEXT may appear more than once
     676                 :            :      in the inheritance hierarchy of TYPE, and thus direct conversion
     677                 :            :      between the types may be ambiguous.  Following the path back up
     678                 :            :      one step at a time via primary bases avoids the problem.  */
     679                 :     391815 :   vfield = TYPE_VFIELD (type);
     680                 :     391815 :   vcontext = DECL_CONTEXT (vfield);
     681                 :     684833 :   while (!same_type_ignoring_top_level_qualifiers_p (vcontext, type))
     682                 :            :     {
     683                 :     293018 :       datum = build_simple_base_path (datum, CLASSTYPE_PRIMARY_BINFO (type));
     684                 :     293018 :       type = TREE_TYPE (datum);
     685                 :            :     }
     686                 :            : 
     687                 :     391815 :   return build3 (COMPONENT_REF, TREE_TYPE (vfield), datum, vfield, NULL_TREE);
     688                 :            : }
     689                 :            : 
     690                 :            : /* Given an object INSTANCE, return an expression which yields the
     691                 :            :    vtable element corresponding to INDEX.  There are many special
     692                 :            :    cases for INSTANCE which we take care of here, mainly to avoid
     693                 :            :    creating extra tree nodes when we don't have to.  */
     694                 :            : 
     695                 :            : tree
     696                 :      96748 : build_vtbl_ref (tree instance, tree idx)
     697                 :            : {
     698                 :      96748 :   tree aref;
     699                 :      96748 :   tree vtbl = NULL_TREE;
     700                 :            : 
     701                 :            :   /* Try to figure out what a reference refers to, and
     702                 :            :      access its virtual function table directly.  */
     703                 :            : 
     704                 :      96748 :   int cdtorp = 0;
     705                 :      96748 :   tree fixed_type = fixed_type_or_null (instance, NULL, &cdtorp);
     706                 :            : 
     707                 :      96748 :   tree basetype = non_reference (TREE_TYPE (instance));
     708                 :            : 
     709                 :      96748 :   if (fixed_type && !cdtorp)
     710                 :            :     {
     711                 :        140 :       tree binfo = lookup_base (fixed_type, basetype,
     712                 :            :                                 ba_unique, NULL, tf_none);
     713                 :        140 :       if (binfo && binfo != error_mark_node)
     714                 :        120 :         vtbl = unshare_expr (BINFO_VTABLE (binfo));
     715                 :            :     }
     716                 :            : 
     717                 :        120 :   if (!vtbl)
     718                 :      96720 :     vtbl = build_vfield_ref (instance, basetype);
     719                 :            : 
     720                 :      96748 :   aref = build_array_ref (input_location, vtbl, idx);
     721                 :      96776 :   TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
     722                 :            : 
     723                 :      96748 :   return aref;
     724                 :            : }
     725                 :            : 
     726                 :            : /* Given a stable object pointer INSTANCE_PTR, return an expression which
     727                 :            :    yields a function pointer corresponding to vtable element INDEX.  */
     728                 :            : 
     729                 :            : tree
     730                 :      95908 : build_vfn_ref (tree instance_ptr, tree idx)
     731                 :            : {
     732                 :      95908 :   tree aref;
     733                 :            : 
     734                 :      95908 :   aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
     735                 :            : 
     736                 :            :   /* When using function descriptors, the address of the
     737                 :            :      vtable entry is treated as a function pointer.  */
     738                 :      95908 :   if (TARGET_VTABLE_USES_DESCRIPTORS)
     739                 :            :     aref = build1 (NOP_EXPR, TREE_TYPE (aref),
     740                 :            :                    cp_build_addr_expr (aref, tf_warning_or_error));
     741                 :            : 
     742                 :            :   /* Remember this as a method reference, for later devirtualization.  */
     743                 :      95908 :   aref = build3 (OBJ_TYPE_REF, TREE_TYPE (aref), aref, instance_ptr, idx);
     744                 :            : 
     745                 :      95908 :   return aref;
     746                 :            : }
     747                 :            : 
     748                 :            : /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
     749                 :            :    for the given TYPE.  */
     750                 :            : 
     751                 :            : static tree
     752                 :     197149 : get_vtable_name (tree type)
     753                 :            : {
     754                 :          0 :   return mangle_vtbl_for_type (type);
     755                 :            : }
     756                 :            : 
     757                 :            : /* DECL is an entity associated with TYPE, like a virtual table or an
     758                 :            :    implicitly generated constructor.  Determine whether or not DECL
     759                 :            :    should have external or internal linkage at the object file
     760                 :            :    level.  This routine does not deal with COMDAT linkage and other
     761                 :            :    similar complexities; it simply sets TREE_PUBLIC if it possible for
     762                 :            :    entities in other translation units to contain copies of DECL, in
     763                 :            :    the abstract.  */
     764                 :            : 
     765                 :            : void
     766                 :    4303840 : set_linkage_according_to_type (tree /*type*/, tree decl)
     767                 :            : {
     768                 :    4303840 :   TREE_PUBLIC (decl) = 1;
     769                 :    4303840 :   determine_visibility (decl);
     770                 :    4303840 : }
     771                 :            : 
     772                 :            : /* Create a VAR_DECL for a primary or secondary vtable for CLASS_TYPE.
     773                 :            :    (For a secondary vtable for B-in-D, CLASS_TYPE should be D, not B.)
     774                 :            :    Use NAME for the name of the vtable, and VTABLE_TYPE for its type.  */
     775                 :            : 
     776                 :            : static tree
     777                 :     241846 : build_vtable (tree class_type, tree name, tree vtable_type)
     778                 :            : {
     779                 :     241846 :   tree decl;
     780                 :            : 
     781                 :     241846 :   decl = build_lang_decl (VAR_DECL, name, vtable_type);
     782                 :            :   /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME
     783                 :            :      now to avoid confusion in mangle_decl.  */
     784                 :     241846 :   SET_DECL_ASSEMBLER_NAME (decl, name);
     785                 :     241846 :   DECL_CONTEXT (decl) = class_type;
     786                 :     241846 :   DECL_ARTIFICIAL (decl) = 1;
     787                 :     241846 :   TREE_STATIC (decl) = 1;
     788                 :     241846 :   TREE_READONLY (decl) = 1;
     789                 :     241846 :   DECL_VIRTUAL_P (decl) = 1;
     790                 :     251330 :   SET_DECL_ALIGN (decl, TARGET_VTABLE_ENTRY_ALIGN);
     791                 :     241846 :   DECL_USER_ALIGN (decl) = true;
     792                 :     241846 :   DECL_VTABLE_OR_VTT_P (decl) = 1;
     793                 :     241846 :   set_linkage_according_to_type (class_type, decl);
     794                 :            :   /* The vtable has not been defined -- yet.  */
     795                 :     241846 :   DECL_EXTERNAL (decl) = 1;
     796                 :     241846 :   DECL_NOT_REALLY_EXTERN (decl) = 1;
     797                 :            : 
     798                 :            :   /* Mark the VAR_DECL node representing the vtable itself as a
     799                 :            :      "gratuitous" one, thereby forcing dwarfout.c to ignore it.  It
     800                 :            :      is rather important that such things be ignored because any
     801                 :            :      effort to actually generate DWARF for them will run into
     802                 :            :      trouble when/if we encounter code like:
     803                 :            : 
     804                 :            :      #pragma interface
     805                 :            :      struct S { virtual void member (); };
     806                 :            : 
     807                 :            :      because the artificial declaration of the vtable itself (as
     808                 :            :      manufactured by the g++ front end) will say that the vtable is
     809                 :            :      a static member of `S' but only *after* the debug output for
     810                 :            :      the definition of `S' has already been output.  This causes
     811                 :            :      grief because the DWARF entry for the definition of the vtable
     812                 :            :      will try to refer back to an earlier *declaration* of the
     813                 :            :      vtable as a static member of `S' and there won't be one.  We
     814                 :            :      might be able to arrange to have the "vtable static member"
     815                 :            :      attached to the member list for `S' before the debug info for
     816                 :            :      `S' get written (which would solve the problem) but that would
     817                 :            :      require more intrusive changes to the g++ front end.  */
     818                 :     241846 :   DECL_IGNORED_P (decl) = 1;
     819                 :            : 
     820                 :     241846 :   return decl;
     821                 :            : }
     822                 :            : 
     823                 :            : /* Get the VAR_DECL of the vtable for TYPE. TYPE need not be polymorphic,
     824                 :            :    or even complete.  If this does not exist, create it.  If COMPLETE is
     825                 :            :    nonzero, then complete the definition of it -- that will render it
     826                 :            :    impossible to actually build the vtable, but is useful to get at those
     827                 :            :    which are known to exist in the runtime.  */
     828                 :            : 
     829                 :            : tree
     830                 :     751501 : get_vtable_decl (tree type, int complete)
     831                 :            : {
     832                 :     751501 :   tree decl;
     833                 :            : 
     834                 :     751501 :   if (CLASSTYPE_VTABLES (type))
     835                 :     751501 :     return CLASSTYPE_VTABLES (type);
     836                 :            : 
     837                 :     197149 :   decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
     838                 :     197149 :   CLASSTYPE_VTABLES (type) = decl;
     839                 :            : 
     840                 :     197149 :   if (complete)
     841                 :            :     {
     842                 :      30221 :       DECL_EXTERNAL (decl) = 1;
     843                 :      30221 :       cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
     844                 :            :     }
     845                 :            : 
     846                 :            :   return decl;
     847                 :            : }
     848                 :            : 
     849                 :            : /* Build the primary virtual function table for TYPE.  If BINFO is
     850                 :            :    non-NULL, build the vtable starting with the initial approximation
     851                 :            :    that it is the same as the one which is the head of the association
     852                 :            :    list.  Returns a nonzero value if a new vtable is actually
     853                 :            :    created.  */
     854                 :            : 
     855                 :            : static int
     856                 :     553186 : build_primary_vtable (tree binfo, tree type)
     857                 :            : {
     858                 :     553186 :   tree decl;
     859                 :     553186 :   tree virtuals;
     860                 :            : 
     861                 :     553186 :   decl = get_vtable_decl (type, /*complete=*/0);
     862                 :            : 
     863                 :     553186 :   if (binfo)
     864                 :            :     {
     865                 :     513856 :       if (BINFO_NEW_VTABLE_MARKED (binfo))
     866                 :            :         /* We have already created a vtable for this base, so there's
     867                 :            :            no need to do it again.  */
     868                 :            :         return 0;
     869                 :            : 
     870                 :     127598 :       virtuals = copy_list (BINFO_VIRTUALS (binfo));
     871                 :     127598 :       TREE_TYPE (decl) = TREE_TYPE (get_vtbl_decl_for_binfo (binfo));
     872                 :     127598 :       DECL_SIZE (decl) = TYPE_SIZE (TREE_TYPE (decl));
     873                 :     127598 :       DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (TREE_TYPE (decl));
     874                 :            :     }
     875                 :            :   else
     876                 :            :     {
     877                 :      39330 :       gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
     878                 :            :       virtuals = NULL_TREE;
     879                 :            :     }
     880                 :            : 
     881                 :            :   /* Initialize the association list for this type, based
     882                 :            :      on our first approximation.  */
     883                 :     166928 :   BINFO_VTABLE (TYPE_BINFO (type)) = decl;
     884                 :     166928 :   BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
     885                 :     333856 :   SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
     886                 :            :   return 1;
     887                 :            : }
     888                 :            : 
     889                 :            : /* Give BINFO a new virtual function table which is initialized
     890                 :            :    with a skeleton-copy of its original initialization.  The only
     891                 :            :    entry that changes is the `delta' entry, so we can really
     892                 :            :    share a lot of structure.
     893                 :            : 
     894                 :            :    FOR_TYPE is the most derived type which caused this table to
     895                 :            :    be needed.
     896                 :            : 
     897                 :            :    Returns nonzero if we haven't met BINFO before.
     898                 :            : 
     899                 :            :    The order in which vtables are built (by calling this function) for
     900                 :            :    an object must remain the same, otherwise a binary incompatibility
     901                 :            :    can result.  */
     902                 :            : 
     903                 :            : static int
     904                 :      66006 : build_secondary_vtable (tree binfo)
     905                 :            : {
     906                 :      66006 :   if (BINFO_NEW_VTABLE_MARKED (binfo))
     907                 :            :     /* We already created a vtable for this base.  There's no need to
     908                 :            :        do it again.  */
     909                 :            :     return 0;
     910                 :            : 
     911                 :            :   /* Remember that we've created a vtable for this BINFO, so that we
     912                 :            :      don't try to do so again.  */
     913                 :      32364 :   SET_BINFO_NEW_VTABLE_MARKED (binfo);
     914                 :            : 
     915                 :            :   /* Make fresh virtual list, so we can smash it later.  */
     916                 :      32364 :   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
     917                 :            : 
     918                 :            :   /* Secondary vtables are laid out as part of the same structure as
     919                 :            :      the primary vtable.  */
     920                 :      32364 :   BINFO_VTABLE (binfo) = NULL_TREE;
     921                 :      32364 :   return 1;
     922                 :            : }
     923                 :            : 
     924                 :            : /* Create a new vtable for BINFO which is the hierarchy dominated by
     925                 :            :    T. Return nonzero if we actually created a new vtable.  */
     926                 :            : 
     927                 :            : static int
     928                 :     579862 : make_new_vtable (tree t, tree binfo)
     929                 :            : {
     930                 :     579862 :   if (binfo == TYPE_BINFO (t))
     931                 :            :     /* In this case, it is *type*'s vtable we are modifying.  We start
     932                 :            :        with the approximation that its vtable is that of the
     933                 :            :        immediate base class.  */
     934                 :     513856 :     return build_primary_vtable (binfo, t);
     935                 :            :   else
     936                 :            :     /* This is our very own copy of `basetype' to play with.  Later,
     937                 :            :        we will fill in all the virtual functions that override the
     938                 :            :        virtual functions in these base classes which are not defined
     939                 :            :        by the current type.  */
     940                 :      66006 :     return build_secondary_vtable (binfo);
     941                 :            : }
     942                 :            : 
     943                 :            : /* Make *VIRTUALS, an entry on the BINFO_VIRTUALS list for BINFO
     944                 :            :    (which is in the hierarchy dominated by T) list FNDECL as its
     945                 :            :    BV_FN.  DELTA is the required constant adjustment from the `this'
     946                 :            :    pointer where the vtable entry appears to the `this' required when
     947                 :            :    the function is actually called.  */
     948                 :            : 
     949                 :            : static void
     950                 :     555965 : modify_vtable_entry (tree t,
     951                 :            :                      tree binfo,
     952                 :            :                      tree fndecl,
     953                 :            :                      tree delta,
     954                 :            :                      tree *virtuals)
     955                 :            : {
     956                 :     555965 :   tree v;
     957                 :            : 
     958                 :     555965 :   v = *virtuals;
     959                 :            : 
     960                 :     555965 :   if (fndecl != BV_FN (v)
     961                 :     555965 :       || !tree_int_cst_equal (delta, BV_DELTA (v)))
     962                 :            :     {
     963                 :            :       /* We need a new vtable for BINFO.  */
     964                 :     419900 :       if (make_new_vtable (t, binfo))
     965                 :            :         {
     966                 :            :           /* If we really did make a new vtable, we also made a copy
     967                 :            :              of the BINFO_VIRTUALS list.  Now, we have to find the
     968                 :            :              corresponding entry in that list.  */
     969                 :          0 :           *virtuals = BINFO_VIRTUALS (binfo);
     970                 :          0 :           while (BV_FN (*virtuals) != BV_FN (v))
     971                 :          0 :             *virtuals = TREE_CHAIN (*virtuals);
     972                 :            :           v = *virtuals;
     973                 :            :         }
     974                 :            : 
     975                 :     419900 :       BV_DELTA (v) = delta;
     976                 :     419900 :       BV_VCALL_INDEX (v) = NULL_TREE;
     977                 :     419900 :       BV_FN (v) = fndecl;
     978                 :            :     }
     979                 :     555965 : }
     980                 :            : 
     981                 :            : 
     982                 :            : /* Add method METHOD to class TYPE.  If VIA_USING indicates whether
     983                 :            :    METHOD is being injected via a using_decl.  Returns true if the
     984                 :            :    method could be added to the method vec.  */
     985                 :            : 
     986                 :            : bool
     987                 :   30516800 : add_method (tree type, tree method, bool via_using)
     988                 :            : {
     989                 :   30516800 :   if (method == error_mark_node)
     990                 :            :     return false;
     991                 :            : 
     992                 :   30516800 :   gcc_assert (!DECL_EXTERN_C_P (method));
     993                 :            : 
     994                 :   30516800 :   tree *slot = find_member_slot (type, DECL_NAME (method));
     995                 :   30516800 :   tree current_fns = slot ? *slot : NULL_TREE;
     996                 :            : 
     997                 :            :   /* See below.  */
     998                 :   30516800 :   int losem = -1;
     999                 :            : 
    1000                 :            :   /* Check to see if we've already got this method.  */
    1001                 :  110940000 :   for (ovl_iterator iter (current_fns); iter; ++iter)
    1002                 :            :     {
    1003                 :   40212500 :       tree fn = *iter;
    1004                 :   40212500 :       tree fn_type;
    1005                 :   40212500 :       tree method_type;
    1006                 :   40212500 :       tree parms1;
    1007                 :   40212500 :       tree parms2;
    1008                 :            : 
    1009                 :   40212500 :       if (TREE_CODE (fn) != TREE_CODE (method))
    1010                 :    8387770 :         continue;
    1011                 :            : 
    1012                 :            :       /* Two using-declarations can coexist, we'll complain about ambiguity in
    1013                 :            :          overload resolution.  */
    1014                 :   63777000 :       if (via_using && iter.using_p ()
    1015                 :            :           /* Except handle inherited constructors specially.  */
    1016                 :   32079700 :           && ! DECL_CONSTRUCTOR_P (fn))
    1017                 :      57191 :         continue;
    1018                 :            : 
    1019                 :            :       /* [over.load] Member function declarations with the
    1020                 :            :          same name and the same parameter types cannot be
    1021                 :            :          overloaded if any of them is a static member
    1022                 :            :          function declaration.
    1023                 :            : 
    1024                 :            :          [over.load] Member function declarations with the same name and
    1025                 :            :          the same parameter-type-list as well as member function template
    1026                 :            :          declarations with the same name, the same parameter-type-list, and
    1027                 :            :          the same template parameter lists cannot be overloaded if any of
    1028                 :            :          them, but not all, have a ref-qualifier.
    1029                 :            : 
    1030                 :            :          [namespace.udecl] When a using-declaration brings names
    1031                 :            :          from a base class into a derived class scope, member
    1032                 :            :          functions in the derived class override and/or hide member
    1033                 :            :          functions with the same name and parameter types in a base
    1034                 :            :          class (rather than conflicting).  */
    1035                 :   31767600 :       fn_type = TREE_TYPE (fn);
    1036                 :   31767600 :       method_type = TREE_TYPE (method);
    1037                 :   31767600 :       parms1 = TYPE_ARG_TYPES (fn_type);
    1038                 :   31767600 :       parms2 = TYPE_ARG_TYPES (method_type);
    1039                 :            : 
    1040                 :            :       /* Compare the quals on the 'this' parm.  Don't compare
    1041                 :            :          the whole types, as used functions are treated as
    1042                 :            :          coming from the using class in overload resolution.  */
    1043                 :   63535100 :       if (! DECL_STATIC_FUNCTION_P (fn)
    1044                 :   61993900 :           && ! DECL_STATIC_FUNCTION_P (method)
    1045                 :            :           /* Either both or neither need to be ref-qualified for
    1046                 :            :              differing quals to allow overloading.  */
    1047                 :   30995700 :           && (FUNCTION_REF_QUALIFIED (fn_type)
    1048                 :   92987000 :               == FUNCTION_REF_QUALIFIED (method_type))
    1049                 :   62763200 :           && (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
    1050                 :   30262000 :               || type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
    1051                 :     740548 :           continue;
    1052                 :            : 
    1053                 :            :       /* For templates, the return type and template parameters
    1054                 :            :          must be identical.  */
    1055                 :   38511000 :       if (TREE_CODE (fn) == TEMPLATE_DECL
    1056                 :   39641600 :           && (!same_type_p (TREE_TYPE (fn_type),
    1057                 :            :                             TREE_TYPE (method_type))
    1058                 :    8149950 :               || !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
    1059                 :    8149950 :                                        DECL_TEMPLATE_PARMS (method))))
    1060                 :    7483980 :         continue;
    1061                 :            : 
    1062                 :   47086100 :       if (! DECL_STATIC_FUNCTION_P (fn))
    1063                 :   23102000 :         parms1 = TREE_CHAIN (parms1);
    1064                 :   47086100 :       if (! DECL_STATIC_FUNCTION_P (method))
    1065                 :   23104800 :         parms2 = TREE_CHAIN (parms2);
    1066                 :            : 
    1067                 :            :       /* Bring back parameters omitted from an inherited ctor.  */
    1068                 :   23543000 :       if (ctor_omit_inherited_parms (fn))
    1069                 :       2124 :         parms1 = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn));
    1070                 :   23543000 :       if (ctor_omit_inherited_parms (method))
    1071                 :        981 :         parms2 = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (method));
    1072                 :            : 
    1073                 :   23543000 :       if (compparms (parms1, parms2)
    1074                 :   23598500 :           && (!DECL_CONV_FN_P (fn)
    1075                 :      45879 :               || same_type_p (TREE_TYPE (fn_type),
    1076                 :            :                               TREE_TYPE (method_type))))
    1077                 :            :         {
    1078                 :       9574 :           if (!equivalently_constrained (fn, method))
    1079                 :            :             {
    1080                 :       4816 :               special_function_kind sfk = special_memfn_p (method);
    1081                 :            : 
    1082                 :       4945 :               if (sfk == sfk_none || DECL_INHERITED_CTOR (fn))
    1083                 :            :                 /* Non-special member functions coexist if they are not
    1084                 :            :                    equivalently constrained.  A member function is not hidden
    1085                 :            :                    by an inherited constructor.  */
    1086                 :       4787 :                 continue;
    1087                 :            : 
    1088                 :            :               /* P0848: For special member functions, deleted, unsatisfied, or
    1089                 :            :                  less constrained overloads are ineligible.  We implement this
    1090                 :            :                  by removing them from CLASSTYPE_MEMBER_VEC.  Destructors don't
    1091                 :            :                  use the notion of eligibility, and the selected destructor can
    1092                 :            :                  be deleted, but removing unsatisfied or less constrained
    1093                 :            :                  overloads has the same effect as overload resolution.  */
    1094                 :         29 :               bool dtor = (sfk == sfk_destructor);
    1095                 :         29 :               if (losem == -1)
    1096                 :         49 :                 losem = ((!dtor && DECL_DELETED_FN (method))
    1097                 :         39 :                          || !constraints_satisfied_p (method));
    1098                 :         20 :               bool losef = ((!dtor && DECL_DELETED_FN (fn))
    1099                 :         39 :                             || !constraints_satisfied_p (fn));
    1100                 :         29 :               int win;
    1101                 :         29 :               if (losem || losef)
    1102                 :         11 :                 win = losem - losef;
    1103                 :            :               else
    1104                 :         18 :                 win = more_constrained (fn, method);
    1105                 :         29 :               if (win > 0)
    1106                 :            :                 /* Leave FN in the method vec, discard METHOD.  */
    1107                 :        805 :                 return false;
    1108                 :         19 :               else if (win < 0)
    1109                 :            :                 {
    1110                 :            :                   /* Remove FN, add METHOD.  */
    1111                 :         13 :                   current_fns = iter.remove_node (current_fns);
    1112                 :         13 :                   continue;
    1113                 :            :                 }
    1114                 :            :               else
    1115                 :            :                 /* Let them coexist for now.  */
    1116                 :          6 :                 continue;
    1117                 :            :             }
    1118                 :            : 
    1119                 :            :           /* If these are versions of the same function, process and
    1120                 :            :              move on.  */
    1121                 :       4794 :           if (TREE_CODE (fn) == FUNCTION_DECL
    1122                 :       4758 :               && maybe_version_functions (method, fn, true))
    1123                 :         36 :             continue;
    1124                 :            : 
    1125                 :       9444 :           if (DECL_INHERITED_CTOR (method))
    1126                 :            :             {
    1127                 :       1176 :               if (DECL_INHERITED_CTOR (fn))
    1128                 :            :                 {
    1129                 :        138 :                   tree basem = DECL_INHERITED_CTOR_BASE (method);
    1130                 :        207 :                   tree basef = DECL_INHERITED_CTOR_BASE (fn);
    1131                 :         69 :                   if (flag_new_inheriting_ctors)
    1132                 :            :                     {
    1133                 :         66 :                       if (basem == basef)
    1134                 :            :                         {
    1135                 :            :                           /* Inheriting the same constructor along different
    1136                 :            :                              paths, combine them.  */
    1137                 :        120 :                           SET_DECL_INHERITED_CTOR
    1138                 :            :                             (fn, ovl_make (DECL_INHERITED_CTOR (method),
    1139                 :            :                                            DECL_INHERITED_CTOR (fn)));
    1140                 :            :                           /* And discard the new one.  */
    1141                 :         30 :                           return false;
    1142                 :            :                         }
    1143                 :            :                       else
    1144                 :            :                         /* Inherited ctors can coexist until overload
    1145                 :            :                            resolution.  */
    1146                 :         36 :                         continue;
    1147                 :            :                     }
    1148                 :          3 :                   error_at (DECL_SOURCE_LOCATION (method),
    1149                 :            :                             "%q#D conflicts with version inherited from %qT",
    1150                 :            :                             method, basef);
    1151                 :          3 :                   inform (DECL_SOURCE_LOCATION (fn),
    1152                 :            :                           "version inherited from %qT declared here",
    1153                 :            :                           basef);
    1154                 :            :                 }
    1155                 :            :               /* Otherwise defer to the other function.  */
    1156                 :        522 :               return false;
    1157                 :            :             }
    1158                 :            : 
    1159                 :       4134 :           if (via_using)
    1160                 :            :             /* Defer to the local function.  */
    1161                 :            :             return false;
    1162                 :       7893 :           else if (flag_new_inheriting_ctors
    1163                 :       8004 :                    && DECL_INHERITED_CTOR (fn))
    1164                 :            :             {
    1165                 :            :               /* Remove the inherited constructor.  */
    1166                 :       3891 :               current_fns = iter.remove_node (current_fns);
    1167                 :       3891 :               continue;
    1168                 :            :             }
    1169                 :            :           else
    1170                 :            :             {
    1171                 :        111 :               error_at (DECL_SOURCE_LOCATION (method),
    1172                 :            :                         "%q#D cannot be overloaded with %q#D", method, fn);
    1173                 :        111 :               inform (DECL_SOURCE_LOCATION (fn),
    1174                 :            :                       "previous declaration %q#D", fn);
    1175                 :        111 :               return false;
    1176                 :            :             }
    1177                 :            :         }
    1178                 :            :     }
    1179                 :            : 
    1180                 :   30516000 :   current_fns = ovl_insert (method, current_fns, via_using);
    1181                 :            : 
    1182                 :   52016800 :   if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
    1183                 :   51895100 :       && !push_class_level_binding (DECL_NAME (method), current_fns))
    1184                 :            :     return false;
    1185                 :            : 
    1186                 :   30516000 :   if (!slot)
    1187                 :   12856200 :     slot = add_member_slot (type, DECL_NAME (method));
    1188                 :            : 
    1189                 :            :   /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc.  */
    1190                 :   30516000 :   grok_special_member_properties (method);
    1191                 :            : 
    1192                 :   30516000 :   *slot = current_fns;
    1193                 :            : 
    1194                 :   30516000 :   return true;
    1195                 :            : }
    1196                 :            : 
    1197                 :            : /* Subroutines of finish_struct.  */
    1198                 :            : 
    1199                 :            : /* Change the access of FDECL to ACCESS in T.  Return 1 if change was
    1200                 :            :    legit, otherwise return 0.  */
    1201                 :            : 
    1202                 :            : static int
    1203                 :     148331 : alter_access (tree t, tree fdecl, tree access)
    1204                 :            : {
    1205                 :     148331 :   tree elem;
    1206                 :            : 
    1207                 :     148331 :   retrofit_lang_decl (fdecl);
    1208                 :            : 
    1209                 :     148659 :   gcc_assert (!DECL_DISCRIMINATOR_P (fdecl));
    1210                 :            : 
    1211                 :     148331 :   elem = purpose_member (t, DECL_ACCESS (fdecl));
    1212                 :     148331 :   if (elem)
    1213                 :            :     {
    1214                 :          0 :       if (TREE_VALUE (elem) != access)
    1215                 :            :         {
    1216                 :          0 :           if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
    1217                 :          0 :             error ("conflicting access specifications for method"
    1218                 :          0 :                    " %q+D, ignored", TREE_TYPE (fdecl));
    1219                 :            :           else
    1220                 :          0 :             error ("conflicting access specifications for field %qE, ignored",
    1221                 :          0 :                    DECL_NAME (fdecl));
    1222                 :            :         }
    1223                 :            :       else
    1224                 :            :         {
    1225                 :            :           /* They're changing the access to the same thing they changed
    1226                 :            :              it to before.  That's OK.  */
    1227                 :            :           ;
    1228                 :            :         }
    1229                 :            :     }
    1230                 :            :   else
    1231                 :            :     {
    1232                 :     148331 :       perform_or_defer_access_check (TYPE_BINFO (t), fdecl, fdecl,
    1233                 :            :                                      tf_warning_or_error);
    1234                 :     148331 :       DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
    1235                 :     148331 :       return 1;
    1236                 :            :     }
    1237                 :            :   return 0;
    1238                 :            : }
    1239                 :            : 
    1240                 :            : /* Return the access node for DECL's access in its enclosing class.  */
    1241                 :            : 
    1242                 :            : tree
    1243                 :     105115 : declared_access (tree decl)
    1244                 :            : {
    1245                 :       3552 :   return (TREE_PRIVATE (decl) ? access_private_node
    1246                 :     101563 :           : TREE_PROTECTED (decl) ? access_protected_node
    1247                 :     105115 :           : access_public_node);
    1248                 :            : }
    1249                 :            : 
    1250                 :            : /* Process the USING_DECL, which is a member of T.  */
    1251                 :            : 
    1252                 :            : static void
    1253                 :     105115 : handle_using_decl (tree using_decl, tree t)
    1254                 :            : {
    1255                 :     105115 :   tree decl = USING_DECL_DECLS (using_decl);
    1256                 :     105115 :   tree name = DECL_NAME (using_decl);
    1257                 :     105115 :   tree access = declared_access (using_decl);
    1258                 :     105115 :   tree flist = NULL_TREE;
    1259                 :     105115 :   tree old_value;
    1260                 :            : 
    1261                 :     105115 :   gcc_assert (!processing_template_decl && decl);
    1262                 :            : 
    1263                 :     105115 :   old_value = lookup_member (t, name, /*protect=*/0, /*want_type=*/false,
    1264                 :            :                              tf_warning_or_error);
    1265                 :     105115 :   if (old_value)
    1266                 :            :     {
    1267                 :     104967 :       old_value = OVL_FIRST (old_value);
    1268                 :            : 
    1269                 :     108658 :       if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t)
    1270                 :            :         /* OK */;
    1271                 :            :       else
    1272                 :            :         old_value = NULL_TREE;
    1273                 :            :     }
    1274                 :            : 
    1275                 :     105115 :   cp_emit_debug_info_for_using (decl, t);
    1276                 :            : 
    1277                 :     105115 :   if (is_overloaded_fn (decl))
    1278                 :     101436 :     flist = decl;
    1279                 :            : 
    1280                 :     105115 :   if (! old_value)
    1281                 :            :     ;
    1282                 :         12 :   else if (is_overloaded_fn (old_value))
    1283                 :            :     {
    1284                 :          0 :       if (flist)
    1285                 :            :         /* It's OK to use functions from a base when there are functions with
    1286                 :            :            the same name already present in the current class.  */;
    1287                 :            :       else
    1288                 :            :         {
    1289                 :          0 :           error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1290                 :            :                     "because of local method %q#D with same name",
    1291                 :            :                     using_decl, t, old_value);
    1292                 :          0 :           inform (DECL_SOURCE_LOCATION (old_value),
    1293                 :            :                   "local method %q#D declared here", old_value);
    1294                 :          0 :           return;
    1295                 :            :         }
    1296                 :            :     }
    1297                 :         12 :   else if (!DECL_ARTIFICIAL (old_value))
    1298                 :            :     {
    1299                 :          0 :       error_at (DECL_SOURCE_LOCATION (using_decl), "%qD invalid in %q#T "
    1300                 :            :                 "because of local member %q#D with same name",
    1301                 :            :                 using_decl, t, old_value);
    1302                 :          0 :       inform (DECL_SOURCE_LOCATION (old_value),
    1303                 :            :               "local member %q#D declared here", old_value);
    1304                 :          0 :       return;
    1305                 :            :     }
    1306                 :            : 
    1307                 :            :   /* Make type T see field decl FDECL with access ACCESS.  */
    1308                 :     105115 :   if (flist)
    1309                 :     390740 :     for (ovl_iterator iter (flist); iter; ++iter)
    1310                 :            :       {
    1311                 :     144652 :         add_method (t, *iter, true);
    1312                 :     144652 :         alter_access (t, *iter, access);
    1313                 :            :       }
    1314                 :            :   else
    1315                 :       3679 :     alter_access (t, decl, access);
    1316                 :            : }
    1317                 :            : 
    1318                 :            : /* Data structure for find_abi_tags_r, below.  */
    1319                 :            : 
    1320                 :            : struct abi_tag_data
    1321                 :            : {
    1322                 :            :   tree t;               // The type that we're checking for missing tags.
    1323                 :            :   tree subob;           // The subobject of T that we're getting tags from.
    1324                 :            :   tree tags; // error_mark_node for diagnostics, or a list of missing tags.
    1325                 :            : };
    1326                 :            : 
    1327                 :            : /* Subroutine of find_abi_tags_r. Handle a single TAG found on the class TP
    1328                 :            :    in the context of P.  TAG can be either an identifier (the DECL_NAME of
    1329                 :            :    a tag NAMESPACE_DECL) or a STRING_CST (a tag attribute).  */
    1330                 :            : 
    1331                 :            : static void
    1332                 :    3961190 : check_tag (tree tag, tree id, tree *tp, abi_tag_data *p)
    1333                 :            : {
    1334                 :    3961190 :   if (!IDENTIFIER_MARKED (id))
    1335                 :            :     {
    1336                 :     813299 :       if (p->tags != error_mark_node)
    1337                 :            :         {
    1338                 :            :           /* We're collecting tags from template arguments or from
    1339                 :            :              the type of a variable or function return type.  */
    1340                 :     813275 :           p->tags = tree_cons (NULL_TREE, tag, p->tags);
    1341                 :            : 
    1342                 :            :           /* Don't inherit this tag multiple times.  */
    1343                 :     813275 :           IDENTIFIER_MARKED (id) = true;
    1344                 :            : 
    1345                 :     813275 :           if (TYPE_P (p->t))
    1346                 :            :             {
    1347                 :            :               /* Tags inherited from type template arguments are only used
    1348                 :            :                  to avoid warnings.  */
    1349                 :     810902 :               ABI_TAG_IMPLICIT (p->tags) = true;
    1350                 :     810902 :               return;
    1351                 :            :             }
    1352                 :            :           /* For functions and variables we want to warn, too.  */
    1353                 :            :         }
    1354                 :            : 
    1355                 :            :       /* Otherwise we're diagnosing missing tags.  */
    1356                 :       2397 :       if (TREE_CODE (p->t) == FUNCTION_DECL)
    1357                 :            :         {
    1358                 :       4238 :           auto_diagnostic_group d;
    1359                 :       2119 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1360                 :            :                        "that %qT (used in its return type) has",
    1361                 :            :                        p->t, tag, *tp))
    1362                 :          4 :             inform (location_of (*tp), "%qT declared here", *tp);
    1363                 :            :         }
    1364                 :        278 :       else if (VAR_P (p->t))
    1365                 :            :         {
    1366                 :        508 :           auto_diagnostic_group d;
    1367                 :        254 :           if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
    1368                 :            :                        "that %qT (used in its type) has", p->t, tag, *tp))
    1369                 :          4 :             inform (location_of (*tp), "%qT declared here", *tp);
    1370                 :            :         }
    1371                 :         24 :       else if (TYPE_P (p->subob))
    1372                 :            :         {
    1373                 :         16 :           auto_diagnostic_group d;
    1374                 :          8 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1375                 :            :                        "that base %qT has", p->t, tag, p->subob))
    1376                 :          8 :             inform (location_of (p->subob), "%qT declared here",
    1377                 :            :                     p->subob);
    1378                 :            :         }
    1379                 :            :       else
    1380                 :            :         {
    1381                 :         32 :           auto_diagnostic_group d;
    1382                 :         16 :           if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
    1383                 :            :                        "that %qT (used in the type of %qD) has",
    1384                 :            :                        p->t, tag, *tp, p->subob))
    1385                 :            :             {
    1386                 :         16 :               inform (location_of (p->subob), "%qD declared here",
    1387                 :            :                       p->subob);
    1388                 :         16 :               inform (location_of (*tp), "%qT declared here", *tp);
    1389                 :            :             }
    1390                 :            :         }
    1391                 :            :     }
    1392                 :            : }
    1393                 :            : 
    1394                 :            : /* Find all the ABI tags in the attribute list ATTR and either call
    1395                 :            :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1396                 :            : 
    1397                 :            : static void
    1398                 :  575533000 : mark_or_check_attr_tags (tree attr, tree *tp, abi_tag_data *p, bool val)
    1399                 :            : {
    1400                 :  575533000 :   if (!attr)
    1401                 :            :     return;
    1402                 :   82915100 :   for (; (attr = lookup_attribute ("abi_tag", attr));
    1403                 :   25449500 :        attr = TREE_CHAIN (attr))
    1404                 :   76348400 :     for (tree list = TREE_VALUE (attr); list;
    1405                 :   25449500 :          list = TREE_CHAIN (list))
    1406                 :            :       {
    1407                 :   25449500 :         tree tag = TREE_VALUE (list);
    1408                 :   25449500 :         tree id = get_identifier (TREE_STRING_POINTER (tag));
    1409                 :   25449500 :         if (tp)
    1410                 :    3961190 :           check_tag (tag, id, tp, p);
    1411                 :            :         else
    1412                 :   21488300 :           IDENTIFIER_MARKED (id) = val;
    1413                 :            :       }
    1414                 :            : }
    1415                 :            : 
    1416                 :            : /* Find all the ABI tags on T and its enclosing scopes and either call
    1417                 :            :    check_tag (if TP is non-null) or set IDENTIFIER_MARKED to val.  */
    1418                 :            : 
    1419                 :            : static void
    1420                 :  226614000 : mark_or_check_tags (tree t, tree *tp, abi_tag_data *p, bool val)
    1421                 :            : {
    1422                 :  802148000 :   while (t != global_namespace)
    1423                 :            :     {
    1424                 :  575533000 :       tree attr;
    1425                 :  575533000 :       if (TYPE_P (t))
    1426                 :            :         {
    1427                 :  232281000 :           attr = TYPE_ATTRIBUTES (t);
    1428                 :  232281000 :           t = CP_TYPE_CONTEXT (t);
    1429                 :            :         }
    1430                 :            :       else
    1431                 :            :         {
    1432                 :  343252000 :           attr = DECL_ATTRIBUTES (t);
    1433                 :  343252000 :           t = CP_DECL_CONTEXT (t);
    1434                 :            :         }
    1435                 :  575533000 :       mark_or_check_attr_tags (attr, tp, p, val);
    1436                 :            :     }
    1437                 :  226614000 : }
    1438                 :            : 
    1439                 :            : /* walk_tree callback for check_abi_tags: if the type at *TP involves any
    1440                 :            :    types with ABI tags, add the corresponding identifiers to the VEC in
    1441                 :            :    *DATA and set IDENTIFIER_MARKED.  */
    1442                 :            : 
    1443                 :            : static tree
    1444                 :  133322000 : find_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1445                 :            : {
    1446                 :  133322000 :   if (!OVERLOAD_TYPE_P (*tp))
    1447                 :            :     return NULL_TREE;
    1448                 :            : 
    1449                 :            :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1450                 :            :      anyway, but let's make sure of it.  */
    1451                 :   33995000 :   *walk_subtrees = false;
    1452                 :            : 
    1453                 :   33995000 :   abi_tag_data *p = static_cast<struct abi_tag_data*>(data);
    1454                 :            : 
    1455                 :   33995000 :   mark_or_check_tags (*tp, tp, p, false);
    1456                 :            : 
    1457                 :   33995000 :   return NULL_TREE;
    1458                 :            : }
    1459                 :            : 
    1460                 :            : /* walk_tree callback for mark_abi_tags: if *TP is a class, set
    1461                 :            :    IDENTIFIER_MARKED on its ABI tags.  */
    1462                 :            : 
    1463                 :            : static tree
    1464                 :  286901000 : mark_abi_tags_r (tree *tp, int *walk_subtrees, void *data)
    1465                 :            : {
    1466                 :  286901000 :   if (!OVERLOAD_TYPE_P (*tp))
    1467                 :            :     return NULL_TREE;
    1468                 :            : 
    1469                 :            :   /* walk_tree shouldn't be walking into any subtrees of a RECORD_TYPE
    1470                 :            :      anyway, but let's make sure of it.  */
    1471                 :   67019700 :   *walk_subtrees = false;
    1472                 :            : 
    1473                 :   67019700 :   bool *valp = static_cast<bool*>(data);
    1474                 :            : 
    1475                 :   67019700 :   mark_or_check_tags (*tp, NULL, NULL, *valp);
    1476                 :            : 
    1477                 :   67019700 :   return NULL_TREE;
    1478                 :            : }
    1479                 :            : 
    1480                 :            : /* Set IDENTIFIER_MARKED on all the ABI tags on T and its enclosing
    1481                 :            :    scopes.  */
    1482                 :            : 
    1483                 :            : static void
    1484                 :  125600000 : mark_abi_tags (tree t, bool val)
    1485                 :            : {
    1486                 :  125600000 :   mark_or_check_tags (t, NULL, NULL, val);
    1487                 :  125600000 :   if (DECL_P (t))
    1488                 :            :     {
    1489                 :  178938000 :       if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
    1490                 :  156575000 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)))
    1491                 :            :         {
    1492                 :            :           /* Template arguments are part of the signature.  */
    1493                 :    2166060 :           tree level = INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t));
    1494                 :    6232310 :           for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1495                 :            :             {
    1496                 :    4066250 :               tree arg = TREE_VEC_ELT (level, j);
    1497                 :    4066250 :               cp_walk_tree_without_duplicates (&arg, mark_abi_tags_r, &val);
    1498                 :            :             }
    1499                 :            :         }
    1500                 :   90605500 :       if (TREE_CODE (t) == FUNCTION_DECL)
    1501                 :            :         /* A function's parameter types are part of the signature, so
    1502                 :            :            we don't need to inherit any tags that are also in them.  */
    1503                 :  455283000 :         for (tree arg = FUNCTION_FIRST_USER_PARMTYPE (t); arg;
    1504                 :  156690000 :              arg = TREE_CHAIN (arg))
    1505                 :  156690000 :           cp_walk_tree_without_duplicates (&TREE_VALUE (arg),
    1506                 :            :                                            mark_abi_tags_r, &val);
    1507                 :            :     }
    1508                 :  125600000 : }
    1509                 :            : 
    1510                 :            : /* Check that T has all the ABI tags that subobject SUBOB has, or
    1511                 :            :    warn if not.  If T is a (variable or function) declaration, also
    1512                 :            :    return any missing tags, and add them to T if JUST_CHECKING is false.  */
    1513                 :            : 
    1514                 :            : static tree
    1515                 :   54478600 : check_abi_tags (tree t, tree subob, bool just_checking = false)
    1516                 :            : {
    1517                 :   54478600 :   bool inherit = DECL_P (t);
    1518                 :            : 
    1519                 :   54478600 :   if (!inherit && !warn_abi_tag)
    1520                 :            :     return NULL_TREE;
    1521                 :            : 
    1522                 :   45670600 :   tree decl = TYPE_P (t) ? TYPE_NAME (t) : t;
    1523                 :   45670600 :   if (!TREE_PUBLIC (decl))
    1524                 :            :     /* No need to worry about things local to this TU.  */
    1525                 :            :     return NULL_TREE;
    1526                 :            : 
    1527                 :   45302800 :   mark_abi_tags (t, true);
    1528                 :            : 
    1529                 :   45303100 :   tree subtype = TYPE_P (subob) ? subob : TREE_TYPE (subob);
    1530                 :   45302800 :   struct abi_tag_data data = { t, subob, error_mark_node };
    1531                 :   45302800 :   if (inherit)
    1532                 :   45302800 :     data.tags = NULL_TREE;
    1533                 :            : 
    1534                 :   45302800 :   cp_walk_tree_without_duplicates (&subtype, find_abi_tags_r, &data);
    1535                 :            : 
    1536                 :   45302800 :   if (!(inherit && data.tags))
    1537                 :            :     /* We don't need to do anything with data.tags.  */;
    1538                 :       2361 :   else if (just_checking)
    1539                 :         84 :     for (tree t = data.tags; t; t = TREE_CHAIN (t))
    1540                 :            :       {
    1541                 :         48 :         tree id = get_identifier (TREE_STRING_POINTER (TREE_VALUE (t)));
    1542                 :         48 :         IDENTIFIER_MARKED (id) = false;
    1543                 :            :       }
    1544                 :            :   else
    1545                 :            :     {
    1546                 :       2325 :       tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
    1547                 :       2325 :       if (attr)
    1548                 :          0 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1549                 :            :       else
    1550                 :       2325 :         DECL_ATTRIBUTES (t)
    1551                 :       2325 :           = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
    1552                 :            :     }
    1553                 :            : 
    1554                 :   45302800 :   mark_abi_tags (t, false);
    1555                 :            : 
    1556                 :   45302800 :   return data.tags;
    1557                 :            : }
    1558                 :            : 
    1559                 :            : /* Check that DECL has all the ABI tags that are used in parts of its type
    1560                 :            :    that are not reflected in its mangled name.  */
    1561                 :            : 
    1562                 :            : void
    1563                 :   47638200 : check_abi_tags (tree decl)
    1564                 :            : {
    1565                 :   47638200 :   if (VAR_P (decl))
    1566                 :    6953040 :     check_abi_tags (decl, TREE_TYPE (decl));
    1567                 :   40685200 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1568                 :   40685100 :            && !DECL_CONV_FN_P (decl)
    1569                 :   80968900 :            && !mangle_return_type_p (decl))
    1570                 :   38153200 :     check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)));
    1571                 :   47638200 : }
    1572                 :            : 
    1573                 :            : /* Return any ABI tags that are used in parts of the type of DECL
    1574                 :            :    that are not reflected in its mangled name.  This function is only
    1575                 :            :    used in backward-compatible mangling for ABI <11.  */
    1576                 :            : 
    1577                 :            : tree
    1578                 :     622217 : missing_abi_tags (tree decl)
    1579                 :            : {
    1580                 :     622217 :   if (VAR_P (decl))
    1581                 :      26878 :     return check_abi_tags (decl, TREE_TYPE (decl), true);
    1582                 :     595339 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    1583                 :            :            /* Don't check DECL_CONV_FN_P here like we do in check_abi_tags, so
    1584                 :            :               that we can use this function for setting need_abi_warning
    1585                 :            :               regardless of the current flag_abi_version.  */
    1586                 :     595339 :            && !mangle_return_type_p (decl))
    1587                 :     537434 :     return check_abi_tags (decl, TREE_TYPE (TREE_TYPE (decl)), true);
    1588                 :            :   else
    1589                 :      57905 :     return NULL_TREE;
    1590                 :            : }
    1591                 :            : 
    1592                 :            : void
    1593                 :   18091500 : inherit_targ_abi_tags (tree t)
    1594                 :            : {
    1595                 :   17497100 :   if (!CLASS_TYPE_P (t)
    1596                 :   35588600 :       || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE)
    1597                 :     594506 :     return;
    1598                 :            : 
    1599                 :   17497000 :   mark_abi_tags (t, true);
    1600                 :            : 
    1601                 :   17524400 :   tree args = CLASSTYPE_TI_ARGS (t);
    1602                 :   17497000 :   struct abi_tag_data data = { t, NULL_TREE, NULL_TREE };
    1603                 :  104982000 :   for (int i = 0; i < TMPL_ARGS_DEPTH (args); ++i)
    1604                 :            :     {
    1605                 :   35548300 :       tree level = TMPL_ARGS_LEVEL (args, i+1);
    1606                 :   48986800 :       for (int j = 0; j < TREE_VEC_LENGTH (level); ++j)
    1607                 :            :         {
    1608                 :   31212700 :           tree arg = TREE_VEC_ELT (level, j);
    1609                 :   31212700 :           data.subob = arg;
    1610                 :   31212700 :           cp_walk_tree_without_duplicates (&arg, find_abi_tags_r, &data);
    1611                 :            :         }
    1612                 :            :     }
    1613                 :            : 
    1614                 :            :   // If we found some tags on our template arguments, add them to our
    1615                 :            :   // abi_tag attribute.
    1616                 :   17497000 :   if (data.tags)
    1617                 :            :     {
    1618                 :     810902 :       tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
    1619                 :     810902 :       if (attr)
    1620                 :          4 :         TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
    1621                 :            :       else
    1622                 :     810898 :         TYPE_ATTRIBUTES (t)
    1623                 :     810898 :           = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
    1624                 :            :     }
    1625                 :            : 
    1626                 :   17497000 :   mark_abi_tags (t, false);
    1627                 :            : }
    1628                 :            : 
    1629                 :            : /* Return true, iff class T has a non-virtual destructor that is
    1630                 :            :    accessible from outside the class heirarchy (i.e. is public, or
    1631                 :            :    there's a suitable friend.  */
    1632                 :            : 
    1633                 :            : static bool
    1634                 :        129 : accessible_nvdtor_p (tree t)
    1635                 :            : {
    1636                 :        129 :   tree dtor = CLASSTYPE_DESTRUCTOR (t);
    1637                 :            : 
    1638                 :            :   /* An implicitly declared destructor is always public.  And,
    1639                 :            :      if it were virtual, we would have created it by now.  */
    1640                 :        129 :   if (!dtor)
    1641                 :            :     return true;
    1642                 :            : 
    1643                 :        102 :   if (DECL_VINDEX (dtor))
    1644                 :            :     return false; /* Virtual */
    1645                 :            :   
    1646                 :         54 :   if (!TREE_PRIVATE (dtor) && !TREE_PROTECTED (dtor))
    1647                 :            :     return true;  /* Public */
    1648                 :            : 
    1649                 :         38 :   if (CLASSTYPE_FRIEND_CLASSES (t)
    1650                 :         38 :       || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    1651                 :         16 :     return true;   /* Has friends */
    1652                 :            : 
    1653                 :            :   return false;
    1654                 :            : }
    1655                 :            : 
    1656                 :            : /* Run through the base classes of T, updating CANT_HAVE_CONST_CTOR_P,
    1657                 :            :    and NO_CONST_ASN_REF_P.  Also set flag bits in T based on
    1658                 :            :    properties of the bases.  */
    1659                 :            : 
    1660                 :            : static void
    1661                 :   11678000 : check_bases (tree t,
    1662                 :            :              int* cant_have_const_ctor_p,
    1663                 :            :              int* no_const_asn_ref_p)
    1664                 :            : {
    1665                 :   11678000 :   int i;
    1666                 :   11678000 :   bool seen_non_virtual_nearly_empty_base_p = 0;
    1667                 :   11678000 :   int seen_tm_mask = 0;
    1668                 :   11678000 :   tree base_binfo;
    1669                 :   11678000 :   tree binfo;
    1670                 :   11678000 :   tree field = NULL_TREE;
    1671                 :            : 
    1672                 :   11678000 :   if (!CLASSTYPE_NON_STD_LAYOUT (t))
    1673                 :   38044500 :     for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    1674                 :   27115500 :       if (TREE_CODE (field) == FIELD_DECL)
    1675                 :            :         break;
    1676                 :            : 
    1677                 :   18233100 :   for (binfo = TYPE_BINFO (t), i = 0;
    1678                 :   18133300 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    1679                 :            :     {
    1680                 :    6455320 :       tree basetype = TREE_TYPE (base_binfo);
    1681                 :            : 
    1682                 :    6455320 :       gcc_assert (COMPLETE_TYPE_P (basetype));
    1683                 :            : 
    1684                 :    6455320 :       if (CLASSTYPE_FINAL (basetype))
    1685                 :         11 :         error ("cannot derive from %<final%> base %qT in derived type %qT",
    1686                 :            :                basetype, t);
    1687                 :            : 
    1688                 :            :       /* If any base class is non-literal, so is the derived class.  */
    1689                 :    6455320 :       if (!CLASSTYPE_LITERAL_P (basetype))
    1690                 :     248180 :         CLASSTYPE_LITERAL_P (t) = false;
    1691                 :            : 
    1692                 :            :       /* If the base class doesn't have copy constructors or
    1693                 :            :          assignment operators that take const references, then the
    1694                 :            :          derived class cannot have such a member automatically
    1695                 :            :          generated.  */
    1696                 :    6455320 :       if (TYPE_HAS_COPY_CTOR (basetype)
    1697                 :    6455320 :           && ! TYPE_HAS_CONST_COPY_CTOR (basetype))
    1698                 :         46 :         *cant_have_const_ctor_p = 1;
    1699                 :    6455320 :       if (TYPE_HAS_COPY_ASSIGN (basetype)
    1700                 :    6455320 :           && !TYPE_HAS_CONST_COPY_ASSIGN (basetype))
    1701                 :         11 :         *no_const_asn_ref_p = 1;
    1702                 :            : 
    1703                 :    6455320 :       if (BINFO_VIRTUAL_P (base_binfo))
    1704                 :            :         /* A virtual base does not effect nearly emptiness.  */
    1705                 :            :         ;
    1706                 :    6446100 :       else if (CLASSTYPE_NEARLY_EMPTY_P (basetype))
    1707                 :            :         {
    1708                 :      37590 :           if (seen_non_virtual_nearly_empty_base_p)
    1709                 :            :             /* And if there is more than one nearly empty base, then the
    1710                 :            :                derived class is not nearly empty either.  */
    1711                 :       1210 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    1712                 :            :           else
    1713                 :            :             /* Remember we've seen one.  */
    1714                 :            :             seen_non_virtual_nearly_empty_base_p = 1;
    1715                 :            :         }
    1716                 :    6408520 :       else if (!is_empty_class (basetype))
    1717                 :            :         /* If the base class is not empty or nearly empty, then this
    1718                 :            :            class cannot be nearly empty.  */
    1719                 :     144870 :         CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    1720                 :            : 
    1721                 :            :       /* A lot of properties from the bases also apply to the derived
    1722                 :            :          class.  */
    1723                 :    6455320 :       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
    1724                 :    6455320 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1725                 :    6455320 :         |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (basetype);
    1726                 :    6455320 :       TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    1727                 :   12910600 :         |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (basetype)
    1728                 :    6455320 :             || !TYPE_HAS_COPY_ASSIGN (basetype));
    1729                 :    6455320 :       TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (basetype)
    1730                 :    6455320 :                                          || !TYPE_HAS_COPY_CTOR (basetype));
    1731                 :    6455320 :       TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    1732                 :    6455320 :         |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (basetype);
    1733                 :    6455320 :       TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (basetype);
    1734                 :   12910600 :       TYPE_POLYMORPHIC_P (t) |= TYPE_POLYMORPHIC_P (basetype);
    1735                 :    6455320 :       CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t)
    1736                 :    6455320 :         |= CLASSTYPE_CONTAINS_EMPTY_CLASS_P (basetype);
    1737                 :    6455320 :       TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
    1738                 :    6455320 :                                     || TYPE_HAS_COMPLEX_DFLT (basetype));
    1739                 :   12910600 :       SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT
    1740                 :            :         (t, CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    1741                 :            :          | CLASSTYPE_READONLY_FIELDS_NEED_INIT (basetype));
    1742                 :   12910600 :       SET_CLASSTYPE_REF_FIELDS_NEED_INIT
    1743                 :            :         (t, CLASSTYPE_REF_FIELDS_NEED_INIT (t)
    1744                 :            :          | CLASSTYPE_REF_FIELDS_NEED_INIT (basetype));
    1745                 :    6455320 :       if (TYPE_HAS_MUTABLE_P (basetype))
    1746                 :      59718 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    1747                 :            : 
    1748                 :            :       /*  A standard-layout class is a class that:
    1749                 :            :           ...
    1750                 :            :           * has no non-standard-layout base classes,  */
    1751                 :    6455320 :       CLASSTYPE_NON_STD_LAYOUT (t) |= CLASSTYPE_NON_STD_LAYOUT (basetype);
    1752                 :    6455320 :       if (!CLASSTYPE_NON_STD_LAYOUT (t))
    1753                 :            :         {
    1754                 :    6300980 :           tree basefield;
    1755                 :            :           /* ...has no base classes of the same type as the first non-static
    1756                 :            :              data member...  */
    1757                 :      78676 :           if (field && DECL_CONTEXT (field) == t
    1758                 :    6376760 :               && (same_type_ignoring_top_level_qualifiers_p
    1759                 :      75772 :                   (TREE_TYPE (field), basetype)))
    1760                 :        127 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1761                 :            :           /* DR 1813:
    1762                 :            :              ...has at most one base class subobject of any given type...  */
    1763                 :    6300860 :           else if (CLASSTYPE_REPEATED_BASE_P (t))
    1764                 :        406 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1765                 :            :           else
    1766                 :            :             /* ...either has no non-static data members in the most-derived
    1767                 :            :                class and at most one base class with non-static data
    1768                 :            :                members, or has no base classes with non-static data
    1769                 :            :                members.  FIXME This was reworded in DR 1813.  */
    1770                 :  118806000 :             for (basefield = TYPE_FIELDS (basetype); basefield;
    1771                 :   56252800 :                  basefield = DECL_CHAIN (basefield))
    1772                 :   56300400 :               if (TREE_CODE (basefield) == FIELD_DECL
    1773                 :   56999600 :                   && !(DECL_FIELD_IS_BASE (basefield)
    1774                 :     741532 :                        && integer_zerop (DECL_SIZE (basefield))))
    1775                 :            :                 {
    1776                 :      47595 :                   if (field)
    1777                 :       9827 :                     CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    1778                 :            :                   else
    1779                 :            :                     field = basefield;
    1780                 :            :                   break;
    1781                 :            :                 }
    1782                 :            :         }
    1783                 :            : 
    1784                 :            :       /* Don't bother collecting tm attributes if transactional memory
    1785                 :            :          support is not enabled.  */
    1786                 :    6455320 :       if (flag_tm)
    1787                 :            :         {
    1788                 :       1431 :           tree tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (basetype));
    1789                 :       1431 :           if (tm_attr)
    1790                 :         20 :             seen_tm_mask |= tm_attr_to_mask (tm_attr);
    1791                 :            :         }
    1792                 :            : 
    1793                 :    6455320 :       check_abi_tags (t, basetype);
    1794                 :            :     }
    1795                 :            : 
    1796                 :            :   /* If one of the base classes had TM attributes, and the current class
    1797                 :            :      doesn't define its own, then the current class inherits one.  */
    1798                 :   11678000 :   if (seen_tm_mask && !find_tm_attribute (TYPE_ATTRIBUTES (t)))
    1799                 :            :     {
    1800                 :         16 :       tree tm_attr = tm_mask_to_attr (least_bit_hwi (seen_tm_mask));
    1801                 :         16 :       TYPE_ATTRIBUTES (t) = tree_cons (tm_attr, NULL, TYPE_ATTRIBUTES (t));
    1802                 :            :     }
    1803                 :   11678000 : }
    1804                 :            : 
    1805                 :            : /* Determine all the primary bases within T.  Sets BINFO_PRIMARY_BASE_P for
    1806                 :            :    those that are primaries.  Sets BINFO_LOST_PRIMARY_P for those
    1807                 :            :    that have had a nearly-empty virtual primary base stolen by some
    1808                 :            :    other base in the hierarchy.  Determines CLASSTYPE_PRIMARY_BASE for
    1809                 :            :    T.  */
    1810                 :            : 
    1811                 :            : static void
    1812                 :   11678000 : determine_primary_bases (tree t)
    1813                 :            : {
    1814                 :   11678000 :   unsigned i;
    1815                 :   11678000 :   tree primary = NULL_TREE;
    1816                 :   11678000 :   tree type_binfo = TYPE_BINFO (t);
    1817                 :   11678000 :   tree base_binfo;
    1818                 :            : 
    1819                 :            :   /* Determine the primary bases of our bases.  */
    1820                 :   22709600 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    1821                 :   11031600 :        base_binfo = TREE_CHAIN (base_binfo))
    1822                 :            :     {
    1823                 :   11031600 :       tree primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (base_binfo));
    1824                 :            : 
    1825                 :            :       /* See if we're the non-virtual primary of our inheritance
    1826                 :            :          chain.  */
    1827                 :   11031600 :       if (!BINFO_VIRTUAL_P (base_binfo))
    1828                 :            :         {
    1829                 :   11002300 :           tree parent = BINFO_INHERITANCE_CHAIN (base_binfo);
    1830                 :   11002300 :           tree parent_primary = CLASSTYPE_PRIMARY_BINFO (BINFO_TYPE (parent));
    1831                 :            : 
    1832                 :   11002300 :           if (parent_primary
    1833                 :   11002300 :               && SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
    1834                 :            :                                     BINFO_TYPE (parent_primary)))
    1835                 :            :             /* We are the primary binfo.  */
    1836                 :      69686 :             BINFO_PRIMARY_P (base_binfo) = 1;
    1837                 :            :         }
    1838                 :            :       /* Determine if we have a virtual primary base, and mark it so.
    1839                 :            :        */
    1840                 :   11108700 :       if (primary && BINFO_VIRTUAL_P (primary))
    1841                 :            :         {
    1842                 :       7481 :           tree this_primary = copied_binfo (primary, base_binfo);
    1843                 :            : 
    1844                 :       7481 :           if (BINFO_PRIMARY_P (this_primary))
    1845                 :            :             /* Someone already claimed this base.  */
    1846                 :        759 :             BINFO_LOST_PRIMARY_P (base_binfo) = 1;
    1847                 :            :           else
    1848                 :            :             {
    1849                 :       6722 :               tree delta;
    1850                 :            : 
    1851                 :       6722 :               BINFO_PRIMARY_P (this_primary) = 1;
    1852                 :       6722 :               BINFO_INHERITANCE_CHAIN (this_primary) = base_binfo;
    1853                 :            : 
    1854                 :            :               /* A virtual binfo might have been copied from within
    1855                 :            :                  another hierarchy. As we're about to use it as a
    1856                 :            :                  primary base, make sure the offsets match.  */
    1857                 :       6722 :               delta = size_diffop_loc (input_location,
    1858                 :       6722 :                                    fold_convert (ssizetype,
    1859                 :            :                                             BINFO_OFFSET (base_binfo)),
    1860                 :       6722 :                                    fold_convert (ssizetype,
    1861                 :            :                                             BINFO_OFFSET (this_primary)));
    1862                 :            : 
    1863                 :       6722 :               propagate_binfo_offsets (this_primary, delta);
    1864                 :            :             }
    1865                 :            :         }
    1866                 :            :     }
    1867                 :            : 
    1868                 :            :   /* First look for a dynamic direct non-virtual base.  */
    1869                 :   17994000 :   for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, base_binfo); i++)
    1870                 :            :     {
    1871                 :    6441780 :       tree basetype = BINFO_TYPE (base_binfo);
    1872                 :            : 
    1873                 :   19194200 :       if (TYPE_CONTAINS_VPTR_P (basetype) && !BINFO_VIRTUAL_P (base_binfo))
    1874                 :            :         {
    1875                 :     125754 :           primary = base_binfo;
    1876                 :     125754 :           goto found;
    1877                 :            :         }
    1878                 :            :     }
    1879                 :            : 
    1880                 :            :   /* A "nearly-empty" virtual base class can be the primary base
    1881                 :            :      class, if no non-virtual polymorphic base can be found.  Look for
    1882                 :            :      a nearly-empty virtual dynamic base that is not already a primary
    1883                 :            :      base of something in the hierarchy.  If there is no such base,
    1884                 :            :      just pick the first nearly-empty virtual base.  */
    1885                 :            : 
    1886                 :   22317900 :   for (base_binfo = TREE_CHAIN (type_binfo); base_binfo;
    1887                 :   10765700 :        base_binfo = TREE_CHAIN (base_binfo))
    1888                 :   10767400 :     if (BINFO_VIRTUAL_P (base_binfo)
    1889                 :   10767400 :         && CLASSTYPE_NEARLY_EMPTY_P (BINFO_TYPE (base_binfo)))
    1890                 :            :       {
    1891                 :       1908 :         if (!BINFO_PRIMARY_P (base_binfo))
    1892                 :            :           {
    1893                 :            :             /* Found one that is not primary.  */
    1894                 :       1765 :             primary = base_binfo;
    1895                 :       1765 :             goto found;
    1896                 :            :           }
    1897                 :        143 :         else if (!primary)
    1898                 :            :           /* Remember the first candidate.  */
    1899                 :        123 :           primary = base_binfo;
    1900                 :            :       }
    1901                 :            : 
    1902                 :   11550500 :  found:
    1903                 :            :   /* If we've got a primary base, use it.  */
    1904                 :   11678000 :   if (primary)
    1905                 :            :     {
    1906                 :     127598 :       tree basetype = BINFO_TYPE (primary);
    1907                 :            : 
    1908                 :     127598 :       CLASSTYPE_PRIMARY_BINFO (t) = primary;
    1909                 :     127598 :       if (BINFO_PRIMARY_P (primary))
    1910                 :            :         /* We are stealing a primary base.  */
    1911                 :         79 :         BINFO_LOST_PRIMARY_P (BINFO_INHERITANCE_CHAIN (primary)) = 1;
    1912                 :     127598 :       BINFO_PRIMARY_P (primary) = 1;
    1913                 :     127598 :       if (BINFO_VIRTUAL_P (primary))
    1914                 :            :         {
    1915                 :       1844 :           tree delta;
    1916                 :            : 
    1917                 :       1844 :           BINFO_INHERITANCE_CHAIN (primary) = type_binfo;
    1918                 :            :           /* A virtual binfo might have been copied from within
    1919                 :            :              another hierarchy. As we're about to use it as a primary
    1920                 :            :              base, make sure the offsets match.  */
    1921                 :       1844 :           delta = size_diffop_loc (input_location, ssize_int (0),
    1922                 :       1844 :                                fold_convert (ssizetype, BINFO_OFFSET (primary)));
    1923                 :            : 
    1924                 :       1844 :           propagate_binfo_offsets (primary, delta);
    1925                 :            :         }
    1926                 :            : 
    1927                 :     127598 :       primary = TYPE_BINFO (basetype);
    1928                 :            : 
    1929                 :     127598 :       TYPE_VFIELD (t) = TYPE_VFIELD (basetype);
    1930                 :     127598 :       BINFO_VTABLE (type_binfo) = BINFO_VTABLE (primary);
    1931                 :     127598 :       BINFO_VIRTUALS (type_binfo) = BINFO_VIRTUALS (primary);
    1932                 :            :     }
    1933                 :   11678000 : }
    1934                 :            : 
    1935                 :            : /* Update the variant types of T.  */
    1936                 :            : 
    1937                 :            : void
    1938                 :   29135500 : fixup_type_variants (tree t)
    1939                 :            : {
    1940                 :   29135500 :   tree variants;
    1941                 :            : 
    1942                 :   29135500 :   if (!t)
    1943                 :            :     return;
    1944                 :            : 
    1945                 :   29135500 :   for (variants = TYPE_NEXT_VARIANT (t);
    1946                 :   59062200 :        variants;
    1947                 :   29926700 :        variants = TYPE_NEXT_VARIANT (variants))
    1948                 :            :     {
    1949                 :            :       /* These fields are in the _TYPE part of the node, not in
    1950                 :            :          the TYPE_LANG_SPECIFIC component, so they are not shared.  */
    1951                 :   29926700 :       TYPE_HAS_USER_CONSTRUCTOR (variants) = TYPE_HAS_USER_CONSTRUCTOR (t);
    1952                 :   29926700 :       TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
    1953                 :   29926700 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (variants)
    1954                 :   29926700 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
    1955                 :            : 
    1956                 :   59853400 :       TYPE_POLYMORPHIC_P (variants) = TYPE_POLYMORPHIC_P (t);
    1957                 :   30203400 :       CLASSTYPE_FINAL (variants) = CLASSTYPE_FINAL (t);
    1958                 :            : 
    1959                 :   30203400 :       TYPE_BINFO (variants) = TYPE_BINFO (t);
    1960                 :            : 
    1961                 :            :       /* Copy whatever these are holding today.  */
    1962                 :   30203400 :       TYPE_VFIELD (variants) = TYPE_VFIELD (t);
    1963                 :   30480100 :       TYPE_FIELDS (variants) = TYPE_FIELDS (t);
    1964                 :            :     }
    1965                 :            : }
    1966                 :            : 
    1967                 :            : /* KLASS is a class that we're applying may_alias to after the body is
    1968                 :            :    parsed.  Fixup any POINTER_TO and REFERENCE_TO types.  The
    1969                 :            :    canonical type(s) will be implicitly updated.  */
    1970                 :            : 
    1971                 :            : static void
    1972                 :       2568 : fixup_may_alias (tree klass)
    1973                 :            : {
    1974                 :       2568 :   tree t, v;
    1975                 :            : 
    1976                 :       3788 :   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
    1977                 :       3640 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    1978                 :       2420 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    1979                 :       2595 :   for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
    1980                 :         54 :     for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    1981                 :         54 :       TYPE_REF_CAN_ALIAS_ALL (v) = true;
    1982                 :       2568 : }
    1983                 :            : 
    1984                 :            : /* Early variant fixups: we apply attributes at the beginning of the class
    1985                 :            :    definition, and we need to fix up any variants that have already been
    1986                 :            :    made via elaborated-type-specifier so that check_qualified_type works.  */
    1987                 :            : 
    1988                 :            : void
    1989                 :   18177800 : fixup_attribute_variants (tree t)
    1990                 :            : {
    1991                 :   18177800 :   tree variants;
    1992                 :            : 
    1993                 :   18177800 :   if (!t)
    1994                 :            :     return;
    1995                 :            : 
    1996                 :   18177800 :   tree attrs = TYPE_ATTRIBUTES (t);
    1997                 :   18177800 :   unsigned align = TYPE_ALIGN (t);
    1998                 :   18177800 :   bool user_align = TYPE_USER_ALIGN (t);
    1999                 :   18177800 :   bool may_alias = lookup_attribute ("may_alias", attrs);
    2000                 :   18177800 :   bool packed = TYPE_PACKED (t);
    2001                 :            : 
    2002                 :   18177800 :   if (may_alias)
    2003                 :       1295 :     fixup_may_alias (t);
    2004                 :            : 
    2005                 :   24818500 :   for (variants = TYPE_NEXT_VARIANT (t);
    2006                 :   24818500 :        variants;
    2007                 :    6640750 :        variants = TYPE_NEXT_VARIANT (variants))
    2008                 :            :     {
    2009                 :            :       /* These are the two fields that check_qualified_type looks at and
    2010                 :            :          are affected by attributes.  */
    2011                 :    6640750 :       TYPE_ATTRIBUTES (variants) = attrs;
    2012                 :    6640750 :       unsigned valign = align;
    2013                 :    6640750 :       if (TYPE_USER_ALIGN (variants))
    2014                 :        435 :         valign = MAX (valign, TYPE_ALIGN (variants));
    2015                 :            :       else
    2016                 :    6640320 :         TYPE_USER_ALIGN (variants) = user_align;
    2017                 :    6640750 :       SET_TYPE_ALIGN (variants, valign);
    2018                 :    6640750 :       TYPE_PACKED (variants) = packed;
    2019                 :    6640750 :       if (may_alias)
    2020                 :       1273 :         fixup_may_alias (variants);
    2021                 :            :     }
    2022                 :            : }
    2023                 :            : 
    2024                 :            : /* Set memoizing fields and bits of T (and its variants) for later
    2025                 :            :    use.  */
    2026                 :            : 
    2027                 :            : static void
    2028                 :   11678000 : finish_struct_bits (tree t)
    2029                 :            : {
    2030                 :            :   /* Fix up variants (if any).  */
    2031                 :   11678000 :   fixup_type_variants (t);
    2032                 :            : 
    2033                 :   18193800 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) && TYPE_POLYMORPHIC_P (t))
    2034                 :            :     /* For a class w/o baseclasses, 'finish_struct' has set
    2035                 :            :        CLASSTYPE_PURE_VIRTUALS correctly (by definition).
    2036                 :            :        Similarly for a class whose base classes do not have vtables.
    2037                 :            :        When neither of these is true, we might have removed abstract
    2038                 :            :        virtuals (by providing a definition), added some (by declaring
    2039                 :            :        new ones), or redeclared ones from a base class.  We need to
    2040                 :            :        recalculate what's really an abstract virtual at this point (by
    2041                 :            :        looking in the vtables).  */
    2042                 :     133082 :     get_pure_virtuals (t);
    2043                 :            : 
    2044                 :            :   /* If this type has a copy constructor or a destructor, force its
    2045                 :            :      mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be
    2046                 :            :      nonzero.  This will cause it to be passed by invisible reference
    2047                 :            :      and prevent it from being returned in a register.  */
    2048                 :   11678000 :   if (type_has_nontrivial_copy_init (t)
    2049                 :   22930000 :       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    2050                 :            :     {
    2051                 :     581985 :       tree variants;
    2052                 :     581985 :       SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode);
    2053                 :    2290550 :       for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
    2054                 :            :         {
    2055                 :    1708560 :           SET_TYPE_MODE (variants, BLKmode);
    2056                 :    1708560 :           TREE_ADDRESSABLE (variants) = 1;
    2057                 :            :         }
    2058                 :            :     }
    2059                 :   11678000 : }
    2060                 :            : 
    2061                 :            : /* Issue warnings about T having private constructors, but no friends,
    2062                 :            :    and so forth.
    2063                 :            : 
    2064                 :            :    HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
    2065                 :            :    static members.  HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
    2066                 :            :    non-private static member functions.  */
    2067                 :            : 
    2068                 :            : static void
    2069                 :    3976430 : maybe_warn_about_overly_private_class (tree t)
    2070                 :            : {
    2071                 :    3976430 :   int has_member_fn = 0;
    2072                 :    3976430 :   int has_nonprivate_method = 0;
    2073                 :    3976430 :   bool nonprivate_ctor = false;
    2074                 :            : 
    2075                 :    3976430 :   if (!warn_ctor_dtor_privacy
    2076                 :            :       /* If the class has friends, those entities might create and
    2077                 :            :          access instances, so we should not warn.  */
    2078                 :         59 :       || (CLASSTYPE_FRIEND_CLASSES (t)
    2079                 :         59 :           || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
    2080                 :            :       /* We will have warned when the template was declared; there's
    2081                 :            :          no need to warn on every instantiation.  */
    2082                 :    3976480 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
    2083                 :            :     /* There's no reason to even consider warning about this
    2084                 :            :        class.  */
    2085                 :            :     return;
    2086                 :            : 
    2087                 :            :   /* We only issue one warning, if more than one applies, because
    2088                 :            :      otherwise, on code like:
    2089                 :            : 
    2090                 :            :      class A {
    2091                 :            :        // Oops - forgot `public:'
    2092                 :            :        A();
    2093                 :            :        A(const A&);
    2094                 :            :        ~A();
    2095                 :            :      };
    2096                 :            : 
    2097                 :            :      we warn several times about essentially the same problem.  */
    2098                 :            : 
    2099                 :            :   /* Check to see if all (non-constructor, non-destructor) member
    2100                 :            :      functions are private.  (Since there are no friends or
    2101                 :            :      non-private statics, we can't ever call any of the private member
    2102                 :            :      functions.)  */
    2103                 :        265 :   for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    2104                 :        206 :     if (TREE_CODE (fn) == USING_DECL
    2105                 :         21 :         && DECL_NAME (fn) == ctor_identifier
    2106                 :        209 :         && !TREE_PRIVATE (fn))
    2107                 :            :       nonprivate_ctor = true;
    2108                 :        203 :     else if (!DECL_DECLARES_FUNCTION_P (fn))
    2109                 :            :       /* Not a function.  */;
    2110                 :        118 :     else if (DECL_ARTIFICIAL (fn))
    2111                 :            :       /* We're not interested in compiler-generated methods; they don't
    2112                 :            :          provide any way to call private members.  */;
    2113                 :        118 :     else if (!TREE_PRIVATE (fn))
    2114                 :            :       {
    2115                 :        108 :         if (DECL_STATIC_FUNCTION_P (fn))
    2116                 :            :           /* A non-private static member function is just like a
    2117                 :            :              friend; it can create and invoke private member
    2118                 :            :              functions, and be accessed without a class
    2119                 :            :              instance.  */
    2120                 :            :           return;
    2121                 :            : 
    2122                 :            :         has_nonprivate_method = 1;
    2123                 :            :         /* Keep searching for a static member function.  */
    2124                 :            :       }
    2125                 :        128 :     else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
    2126                 :            :       has_member_fn = 1;
    2127                 :            : 
    2128                 :         59 :   if (!has_nonprivate_method && has_member_fn)
    2129                 :            :     {
    2130                 :            :       /* There are no non-private methods, and there's at least one
    2131                 :            :          private member function that isn't a constructor or
    2132                 :            :          destructor.  (If all the private members are
    2133                 :            :          constructors/destructors we want to use the code below that
    2134                 :            :          issues error messages specifically referring to
    2135                 :            :          constructors/destructors.)  */
    2136                 :         16 :       unsigned i;
    2137                 :         16 :       tree binfo = TYPE_BINFO (t);
    2138                 :            : 
    2139                 :         16 :       for (i = 0; i != BINFO_N_BASE_BINFOS (binfo); i++)
    2140                 :          0 :         if (BINFO_BASE_ACCESS (binfo, i) != access_private_node)
    2141                 :            :           {
    2142                 :            :             has_nonprivate_method = 1;
    2143                 :            :             break;
    2144                 :            :           }
    2145                 :         16 :       if (!has_nonprivate_method)
    2146                 :            :         {
    2147                 :         16 :           warning (OPT_Wctor_dtor_privacy,
    2148                 :            :                    "all member functions in class %qT are private", t);
    2149                 :         16 :           return;
    2150                 :            :         }
    2151                 :            :     }
    2152                 :            : 
    2153                 :            :   /* Even if some of the member functions are non-private, the class
    2154                 :            :      won't be useful for much if all the constructors or destructors
    2155                 :            :      are private: such an object can never be created or destroyed.  */
    2156                 :         43 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    2157                 :          8 :     if (TREE_PRIVATE (dtor))
    2158                 :            :       {
    2159                 :          8 :         warning (OPT_Wctor_dtor_privacy,
    2160                 :            :                  "%q#T only defines a private destructor and has no friends",
    2161                 :            :                  t);
    2162                 :          8 :         return;
    2163                 :            :       }
    2164                 :            : 
    2165                 :            :   /* Warn about classes that have private constructors and no friends.  */
    2166                 :         35 :   if (TYPE_HAS_USER_CONSTRUCTOR (t)
    2167                 :            :       /* Implicitly generated constructors are always public.  */
    2168                 :         35 :       && !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    2169                 :            :     {
    2170                 :         24 :       tree copy_or_move = NULL_TREE;
    2171                 :            : 
    2172                 :            :       /* If a non-template class does not define a copy
    2173                 :            :          constructor, one is defined for it, enabling it to avoid
    2174                 :            :          this warning.  For a template class, this does not
    2175                 :            :          happen, and so we would normally get a warning on:
    2176                 :            : 
    2177                 :            :            template <class T> class C { private: C(); };
    2178                 :            : 
    2179                 :            :          To avoid this asymmetry, we check TYPE_HAS_COPY_CTOR.  All
    2180                 :            :          complete non-template or fully instantiated classes have this
    2181                 :            :          flag set.  */
    2182                 :         24 :       if (!TYPE_HAS_COPY_CTOR (t))
    2183                 :            :         nonprivate_ctor = true;
    2184                 :            :       else
    2185                 :         53 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t));
    2186                 :         53 :              !nonprivate_ctor && iter; ++iter)
    2187                 :         29 :           if (TREE_PRIVATE (*iter))
    2188                 :         16 :             continue;
    2189                 :         13 :           else if (copy_fn_p (*iter) || move_fn_p (*iter))
    2190                 :            :             /* Ideally, we wouldn't count any constructor that takes
    2191                 :            :                an argument of the class type as a parameter, because
    2192                 :            :                such things cannot be used to construct an instance of
    2193                 :            :                the class unless you already have one.  */
    2194                 :         10 :             copy_or_move = *iter;
    2195                 :            :           else
    2196                 :            :             nonprivate_ctor = true;
    2197                 :            : 
    2198                 :         24 :       if (!nonprivate_ctor)
    2199                 :            :         {
    2200                 :         18 :           bool w = warning (OPT_Wctor_dtor_privacy,
    2201                 :            :                             "%q#T only defines private constructors and has "
    2202                 :            :                             "no friends", t);
    2203                 :         18 :           if (w && copy_or_move)
    2204                 :          6 :             inform (DECL_SOURCE_LOCATION (copy_or_move),
    2205                 :            :                     "%q#D is public, but requires an existing %q#T object",
    2206                 :            :                     copy_or_move, t);
    2207                 :         18 :           return;
    2208                 :            :         }
    2209                 :            :     }
    2210                 :            : }
    2211                 :            : 
    2212                 :            : /* Make BINFO's vtable have N entries, including RTTI entries,
    2213                 :            :    vbase and vcall offsets, etc.  Set its type and call the back end
    2214                 :            :    to lay it out.  */
    2215                 :            : 
    2216                 :            : static void
    2217                 :     166928 : layout_vtable_decl (tree binfo, int n)
    2218                 :            : {
    2219                 :     166928 :   tree atype;
    2220                 :     166928 :   tree vtable;
    2221                 :            : 
    2222                 :     166928 :   atype = build_array_of_n_type (vtable_entry_type, n);
    2223                 :     166928 :   layout_type (atype);
    2224                 :            : 
    2225                 :            :   /* We may have to grow the vtable.  */
    2226                 :     166928 :   vtable = get_vtbl_decl_for_binfo (binfo);
    2227                 :     166928 :   if (!same_type_p (TREE_TYPE (vtable), atype))
    2228                 :            :     {
    2229                 :      67586 :       TREE_TYPE (vtable) = atype;
    2230                 :      67586 :       DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
    2231                 :      67586 :       layout_decl (vtable, 0);
    2232                 :            :     }
    2233                 :     166928 : }
    2234                 :            : 
    2235                 :            : /* True iff FNDECL and BASE_FNDECL (both non-static member functions)
    2236                 :            :    have the same signature.  */
    2237                 :            : 
    2238                 :            : int
    2239                 :    7497280 : same_signature_p (const_tree fndecl, const_tree base_fndecl)
    2240                 :            : {
    2241                 :            :   /* One destructor overrides another if they are the same kind of
    2242                 :            :      destructor.  */
    2243                 :   10933300 :   if (DECL_DESTRUCTOR_P (base_fndecl) && DECL_DESTRUCTOR_P (fndecl)
    2244                 :    9185250 :       && special_function_p (base_fndecl) == special_function_p (fndecl))
    2245                 :            :     return 1;
    2246                 :            :   /* But a non-destructor never overrides a destructor, nor vice
    2247                 :            :      versa, nor do different kinds of destructors override
    2248                 :            :      one-another.  For example, a complete object destructor does not
    2249                 :            :      override a deleting destructor.  */
    2250                 :   18926500 :   if (DECL_DESTRUCTOR_P (base_fndecl) || DECL_DESTRUCTOR_P (fndecl))
    2251                 :            :     return 0;
    2252                 :            : 
    2253                 :    5078960 :   if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)
    2254                 :    5078960 :       || (DECL_CONV_FN_P (fndecl)
    2255                 :         40 :           && DECL_CONV_FN_P (base_fndecl)
    2256                 :         16 :           && same_type_p (DECL_CONV_FN_TYPE (fndecl),
    2257                 :            :                           DECL_CONV_FN_TYPE (base_fndecl))))
    2258                 :            :     {
    2259                 :    1243190 :       tree fntype = TREE_TYPE (fndecl);
    2260                 :    1243190 :       tree base_fntype = TREE_TYPE (base_fndecl);
    2261                 :    1243190 :       if (type_memfn_quals (fntype) == type_memfn_quals (base_fntype)
    2262                 :    1242270 :           && type_memfn_rqual (fntype) == type_memfn_rqual (base_fntype)
    2263                 :    3727720 :           && compparms (FUNCTION_FIRST_USER_PARMTYPE (fndecl),
    2264                 :    2484530 :                         FUNCTION_FIRST_USER_PARMTYPE (base_fndecl)))
    2265                 :     961210 :         return 1;
    2266                 :            :     }
    2267                 :            :   return 0;
    2268                 :            : }
    2269                 :            : 
    2270                 :            : /* Returns TRUE if DERIVED is a binfo containing the binfo BASE as a
    2271                 :            :    subobject.  */
    2272                 :            : 
    2273                 :            : static bool
    2274                 :      30357 : base_derived_from (tree derived, tree base)
    2275                 :            : {
    2276                 :      30357 :   tree probe;
    2277                 :            : 
    2278                 :      30693 :   for (probe = base; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
    2279                 :            :     {
    2280                 :      30569 :       if (probe == derived)
    2281                 :            :         return true;
    2282                 :       2020 :       else if (BINFO_VIRTUAL_P (probe))
    2283                 :            :         /* If we meet a virtual base, we can't follow the inheritance
    2284                 :            :            any more.  See if the complete type of DERIVED contains
    2285                 :            :            such a virtual base.  */
    2286                 :       1684 :         return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (derived))
    2287                 :       1684 :                 != NULL_TREE);
    2288                 :            :     }
    2289                 :            :   return false;
    2290                 :            : }
    2291                 :            : 
    2292                 :            : struct find_final_overrider_data {
    2293                 :            :   /* The function for which we are trying to find a final overrider.  */
    2294                 :            :   tree fn;
    2295                 :            :   /* The base class in which the function was declared.  */
    2296                 :            :   tree declaring_base;
    2297                 :            :   /* The candidate overriders.  */
    2298                 :            :   tree candidates;
    2299                 :            :   /* Path to most derived.  */
    2300                 :            :   vec<tree> path;
    2301                 :            : };
    2302                 :            : 
    2303                 :            : /* Add the overrider along the current path to FFOD->CANDIDATES.
    2304                 :            :    Returns true if an overrider was found; false otherwise.  */
    2305                 :            : 
    2306                 :            : static bool
    2307                 :    1012510 : dfs_find_final_overrider_1 (tree binfo,
    2308                 :            :                             find_final_overrider_data *ffod,
    2309                 :            :                             unsigned depth)
    2310                 :            : {
    2311                 :    1012510 :   tree method;
    2312                 :            : 
    2313                 :            :   /* If BINFO is not the most derived type, try a more derived class.
    2314                 :            :      A definition there will overrider a definition here.  */
    2315                 :    1012510 :   if (depth)
    2316                 :            :     {
    2317                 :     385810 :       depth--;
    2318                 :     385810 :       if (dfs_find_final_overrider_1
    2319                 :     385810 :           (ffod->path[depth], ffod, depth))
    2320                 :            :         return true;
    2321                 :            :     }
    2322                 :            : 
    2323                 :     827523 :   method = look_for_overrides_here (BINFO_TYPE (binfo), ffod->fn);
    2324                 :     827523 :   if (method)
    2325                 :            :     {
    2326                 :     626699 :       tree *candidate = &ffod->candidates;
    2327                 :            : 
    2328                 :            :       /* Remove any candidates overridden by this new function.  */
    2329                 :     627379 :       while (*candidate)
    2330                 :            :         {
    2331                 :            :           /* If *CANDIDATE overrides METHOD, then METHOD
    2332                 :            :              cannot override anything else on the list.  */
    2333                 :      29677 :           if (base_derived_from (TREE_VALUE (*candidate), binfo))
    2334                 :            :             return true;
    2335                 :            :           /* If METHOD overrides *CANDIDATE, remove *CANDIDATE.  */
    2336                 :        680 :           if (base_derived_from (binfo, TREE_VALUE (*candidate)))
    2337                 :        608 :             *candidate = TREE_CHAIN (*candidate);
    2338                 :            :           else
    2339                 :         72 :             candidate = &TREE_CHAIN (*candidate);
    2340                 :            :         }
    2341                 :            : 
    2342                 :            :       /* Add the new function.  */
    2343                 :     597702 :       ffod->candidates = tree_cons (method, binfo, ffod->candidates);
    2344                 :     597702 :       return true;
    2345                 :            :     }
    2346                 :            : 
    2347                 :            :   return false;
    2348                 :            : }
    2349                 :            : 
    2350                 :            : /* Called from find_final_overrider via dfs_walk.  */
    2351                 :            : 
    2352                 :            : static tree
    2353                 :    2115970 : dfs_find_final_overrider_pre (tree binfo, void *data)
    2354                 :            : {
    2355                 :    2115970 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2356                 :            : 
    2357                 :    2115970 :   if (binfo == ffod->declaring_base)
    2358                 :    1253400 :     dfs_find_final_overrider_1 (binfo, ffod, ffod->path.length ());
    2359                 :    2115970 :   ffod->path.safe_push (binfo);
    2360                 :            : 
    2361                 :    2115970 :   return NULL_TREE;
    2362                 :            : }
    2363                 :            : 
    2364                 :            : static tree
    2365                 :    2115970 : dfs_find_final_overrider_post (tree /*binfo*/, void *data)
    2366                 :            : {
    2367                 :    2115970 :   find_final_overrider_data *ffod = (find_final_overrider_data *) data;
    2368                 :    2115970 :   ffod->path.pop ();
    2369                 :            : 
    2370                 :    2115970 :   return NULL_TREE;
    2371                 :            : }
    2372                 :            : 
    2373                 :            : /* Returns a TREE_LIST whose TREE_PURPOSE is the final overrider for
    2374                 :            :    FN and whose TREE_VALUE is the binfo for the base where the
    2375                 :            :    overriding occurs.  BINFO (in the hierarchy dominated by the binfo
    2376                 :            :    DERIVED) is the base object in which FN is declared.  */
    2377                 :            : 
    2378                 :            : static tree
    2379                 :     597046 : find_final_overrider (tree derived, tree binfo, tree fn)
    2380                 :            : {
    2381                 :     597046 :   find_final_overrider_data ffod;
    2382                 :            : 
    2383                 :            :   /* Getting this right is a little tricky.  This is valid:
    2384                 :            : 
    2385                 :            :        struct S { virtual void f (); };
    2386                 :            :        struct T { virtual void f (); };
    2387                 :            :        struct U : public S, public T { };
    2388                 :            : 
    2389                 :            :      even though calling `f' in `U' is ambiguous.  But,
    2390                 :            : 
    2391                 :            :        struct R { virtual void f(); };
    2392                 :            :        struct S : virtual public R { virtual void f (); };
    2393                 :            :        struct T : virtual public R { virtual void f (); };
    2394                 :            :        struct U : public S, public T { };
    2395                 :            : 
    2396                 :            :      is not -- there's no way to decide whether to put `S::f' or
    2397                 :            :      `T::f' in the vtable for `R'.
    2398                 :            : 
    2399                 :            :      The solution is to look at all paths to BINFO.  If we find
    2400                 :            :      different overriders along any two, then there is a problem.  */
    2401                 :    1194090 :   if (DECL_THUNK_P (fn))
    2402                 :          0 :     fn = THUNK_TARGET (fn);
    2403                 :            : 
    2404                 :            :   /* Determine the depth of the hierarchy.  */
    2405                 :     597046 :   ffod.fn = fn;
    2406                 :     597046 :   ffod.declaring_base = binfo;
    2407                 :     597046 :   ffod.candidates = NULL_TREE;
    2408                 :     597046 :   ffod.path.create (30);
    2409                 :            : 
    2410                 :     597046 :   dfs_walk_all (derived, dfs_find_final_overrider_pre,
    2411                 :            :                 dfs_find_final_overrider_post, &ffod);
    2412                 :            : 
    2413                 :     597046 :   ffod.path.release ();
    2414                 :            : 
    2415                 :            :   /* If there was no winner, issue an error message.  */
    2416                 :     597046 :   if (!ffod.candidates || TREE_CHAIN (ffod.candidates))
    2417                 :         48 :     return error_mark_node;
    2418                 :            : 
    2419                 :            :   return ffod.candidates;
    2420                 :            : }
    2421                 :            : 
    2422                 :            : /* Return the index of the vcall offset for FN when TYPE is used as a
    2423                 :            :    virtual base.  */
    2424                 :            : 
    2425                 :            : static tree
    2426                 :      25690 : get_vcall_index (tree fn, tree type)
    2427                 :            : {
    2428                 :      25690 :   vec<tree_pair_s, va_gc> *indices = CLASSTYPE_VCALL_INDICES (type);
    2429                 :      25690 :   tree_pair_p p;
    2430                 :      25690 :   unsigned ix;
    2431                 :            : 
    2432                 :      33600 :   FOR_EACH_VEC_SAFE_ELT (indices, ix, p)
    2433                 :      96496 :     if ((DECL_DESTRUCTOR_P (fn) && DECL_DESTRUCTOR_P (p->purpose))
    2434                 :      41112 :         || same_signature_p (fn, p->purpose))
    2435                 :      25690 :       return p->value;
    2436                 :            : 
    2437                 :            :   /* There should always be an appropriate index.  */
    2438                 :          0 :   gcc_unreachable ();
    2439                 :            : }
    2440                 :            : 
    2441                 :            : /* Update an entry in the vtable for BINFO, which is in the hierarchy
    2442                 :            :    dominated by T.  FN is the old function; VIRTUALS points to the
    2443                 :            :    corresponding position in the new BINFO_VIRTUALS list.  IX is the index
    2444                 :            :    of that entry in the list.  */
    2445                 :            : 
    2446                 :            : static void
    2447                 :     555977 : update_vtable_entry_for_fn (tree t, tree binfo, tree fn, tree* virtuals,
    2448                 :            :                             unsigned ix)
    2449                 :            : {
    2450                 :     555977 :   tree b;
    2451                 :     555977 :   tree overrider;
    2452                 :     555977 :   tree delta;
    2453                 :     555977 :   tree virtual_base;
    2454                 :     555977 :   tree first_defn;
    2455                 :     555977 :   tree overrider_fn, overrider_target;
    2456                 :    1111950 :   tree target_fn = DECL_THUNK_P (fn) ? THUNK_TARGET (fn) : fn;
    2457                 :     555977 :   tree over_return, base_return;
    2458                 :     555977 :   bool lost = false;
    2459                 :            : 
    2460                 :            :   /* Find the nearest primary base (possibly binfo itself) which defines
    2461                 :            :      this function; this is the class the caller will convert to when
    2462                 :            :      calling FN through BINFO.  */
    2463                 :     690744 :   for (b = binfo; ; b = get_primary_binfo (b))
    2464                 :            :     {
    2465                 :     690744 :       gcc_assert (b);
    2466                 :     690744 :       if (look_for_overrides_here (BINFO_TYPE (b), target_fn))
    2467                 :            :         break;
    2468                 :            : 
    2469                 :            :       /* The nearest definition is from a lost primary.  */
    2470                 :     134767 :       if (BINFO_LOST_PRIMARY_P (b))
    2471                 :        484 :         lost = true;
    2472                 :            :     }
    2473                 :     555977 :   first_defn = b;
    2474                 :            : 
    2475                 :            :   /* Find the final overrider.  */
    2476                 :     555977 :   overrider = find_final_overrider (TYPE_BINFO (t), b, target_fn);
    2477                 :     555977 :   if (overrider == error_mark_node)
    2478                 :            :     {
    2479                 :         12 :       error ("no unique final overrider for %qD in %qT", target_fn, t);
    2480                 :         12 :       return;
    2481                 :            :     }
    2482                 :     555965 :   overrider_target = overrider_fn = TREE_PURPOSE (overrider);
    2483                 :            : 
    2484                 :            :   /* Check for adjusting covariant return types.  */
    2485                 :     555965 :   over_return = TREE_TYPE (TREE_TYPE (overrider_target));
    2486                 :     555965 :   base_return = TREE_TYPE (TREE_TYPE (target_fn));
    2487                 :            : 
    2488                 :     555965 :   if (INDIRECT_TYPE_P (over_return)
    2489                 :      84109 :       && TREE_CODE (over_return) == TREE_CODE (base_return)
    2490                 :      84097 :       && CLASS_TYPE_P (TREE_TYPE (over_return))
    2491                 :       4527 :       && CLASS_TYPE_P (TREE_TYPE (base_return))
    2492                 :            :       /* If the overrider is invalid, don't even try.  */
    2493                 :     560484 :       && !DECL_INVALID_OVERRIDER_P (overrider_target))
    2494                 :            :     {
    2495                 :            :       /* If FN is a covariant thunk, we must figure out the adjustment
    2496                 :            :          to the final base FN was converting to. As OVERRIDER_TARGET might
    2497                 :            :          also be converting to the return type of FN, we have to
    2498                 :            :          combine the two conversions here.  */
    2499                 :       4483 :       tree fixed_offset, virtual_offset;
    2500                 :            : 
    2501                 :       4483 :       over_return = TREE_TYPE (over_return);
    2502                 :       4483 :       base_return = TREE_TYPE (base_return);
    2503                 :            : 
    2504                 :       8966 :       if (DECL_THUNK_P (fn))
    2505                 :            :         {
    2506                 :         80 :           gcc_assert (DECL_RESULT_THUNK_P (fn));
    2507                 :         80 :           fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn));
    2508                 :         80 :           virtual_offset = THUNK_VIRTUAL_OFFSET (fn);
    2509                 :            :         }
    2510                 :            :       else
    2511                 :            :         fixed_offset = virtual_offset = NULL_TREE;
    2512                 :            : 
    2513                 :         80 :       if (virtual_offset)
    2514                 :            :         /* Find the equivalent binfo within the return type of the
    2515                 :            :            overriding function. We will want the vbase offset from
    2516                 :            :            there.  */
    2517                 :         72 :         virtual_offset = binfo_for_vbase (BINFO_TYPE (virtual_offset),
    2518                 :            :                                           over_return);
    2519                 :       4411 :       else if (!same_type_ignoring_top_level_qualifiers_p
    2520                 :       4411 :                (over_return, base_return))
    2521                 :            :         {
    2522                 :            :           /* There was no existing virtual thunk (which takes
    2523                 :            :              precedence).  So find the binfo of the base function's
    2524                 :            :              return type within the overriding function's return type.
    2525                 :            :              Fortunately we know the covariancy is valid (it
    2526                 :            :              has already been checked), so we can just iterate along
    2527                 :            :              the binfos, which have been chained in inheritance graph
    2528                 :            :              order.  Of course it is lame that we have to repeat the
    2529                 :            :              search here anyway -- we should really be caching pieces
    2530                 :            :              of the vtable and avoiding this repeated work.  */
    2531                 :        471 :           tree thunk_binfo = NULL_TREE;
    2532                 :        471 :           tree base_binfo = TYPE_BINFO (base_return);
    2533                 :            : 
    2534                 :            :           /* Find the base binfo within the overriding function's
    2535                 :            :              return type.  We will always find a thunk_binfo, except
    2536                 :            :              when the covariancy is invalid (which we will have
    2537                 :            :              already diagnosed).  */
    2538                 :        471 :           if (base_binfo)
    2539                 :       2003 :             for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo;
    2540                 :        768 :                  thunk_binfo = TREE_CHAIN (thunk_binfo))
    2541                 :       1235 :               if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
    2542                 :            :                                      BINFO_TYPE (base_binfo)))
    2543                 :            :                 break;
    2544                 :        471 :           gcc_assert (thunk_binfo || errorcount);
    2545                 :            : 
    2546                 :            :           /* See if virtual inheritance is involved.  */
    2547                 :        330 :           for (virtual_offset = thunk_binfo;
    2548                 :        801 :                virtual_offset;
    2549                 :        330 :                virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
    2550                 :        652 :             if (BINFO_VIRTUAL_P (virtual_offset))
    2551                 :            :               break;
    2552                 :            : 
    2553                 :        471 :           if (virtual_offset
    2554                 :        616 :               || (thunk_binfo && !BINFO_OFFSET_ZEROP (thunk_binfo)))
    2555                 :            :             {
    2556                 :        414 :               tree offset = fold_convert (ssizetype, BINFO_OFFSET (thunk_binfo));
    2557                 :            : 
    2558                 :        414 :               if (virtual_offset)
    2559                 :            :                 {
    2560                 :            :                   /* We convert via virtual base.  Adjust the fixed
    2561                 :            :                      offset to be from there.  */
    2562                 :        322 :                   offset = 
    2563                 :        322 :                     size_diffop (offset,
    2564                 :            :                                  fold_convert (ssizetype,
    2565                 :            :                                           BINFO_OFFSET (virtual_offset)));
    2566                 :            :                 }
    2567                 :        414 :               if (fixed_offset)
    2568                 :            :                 /* There was an existing fixed offset, this must be
    2569                 :            :                    from the base just converted to, and the base the
    2570                 :            :                    FN was thunking to.  */
    2571                 :          8 :                 fixed_offset = size_binop (PLUS_EXPR, fixed_offset, offset);
    2572                 :            :               else
    2573                 :            :                 fixed_offset = offset;
    2574                 :            :             }
    2575                 :            :         }
    2576                 :            : 
    2577                 :       4483 :       if (fixed_offset || virtual_offset)
    2578                 :            :         /* Replace the overriding function with a covariant thunk.  We
    2579                 :            :            will emit the overriding function in its own slot as
    2580                 :            :            well.  */
    2581                 :        486 :         overrider_fn = make_thunk (overrider_target, /*this_adjusting=*/0,
    2582                 :            :                                    fixed_offset, virtual_offset);
    2583                 :            :     }
    2584                 :            :   else
    2585                 :    1102810 :     gcc_assert (DECL_INVALID_OVERRIDER_P (overrider_target) ||
    2586                 :            :                 !DECL_THUNK_P (fn));
    2587                 :            : 
    2588                 :            :   /* If we need a covariant thunk, then we may need to adjust first_defn.
    2589                 :            :      The ABI specifies that the thunks emitted with a function are
    2590                 :            :      determined by which bases the function overrides, so we need to be
    2591                 :            :      sure that we're using a thunk for some overridden base; even if we
    2592                 :            :      know that the necessary this adjustment is zero, there may not be an
    2593                 :            :      appropriate zero-this-adjustment thunk for us to use since thunks for
    2594                 :            :      overriding virtual bases always use the vcall offset.
    2595                 :            : 
    2596                 :            :      Furthermore, just choosing any base that overrides this function isn't
    2597                 :            :      quite right, as this slot won't be used for calls through a type that
    2598                 :            :      puts a covariant thunk here.  Calling the function through such a type
    2599                 :            :      will use a different slot, and that slot is the one that determines
    2600                 :            :      the thunk emitted for that base.
    2601                 :            : 
    2602                 :            :      So, keep looking until we find the base that we're really overriding
    2603                 :            :      in this slot: the nearest primary base that doesn't use a covariant
    2604                 :            :      thunk in this slot.  */
    2605                 :     555965 :   if (overrider_target != overrider_fn)
    2606                 :            :     {
    2607                 :        486 :       if (BINFO_TYPE (b) == DECL_CONTEXT (overrider_target))
    2608                 :            :         /* We already know that the overrider needs a covariant thunk.  */
    2609                 :        172 :         b = get_primary_binfo (b);
    2610                 :         40 :       for (; ; b = get_primary_binfo (b))
    2611                 :            :         {
    2612                 :        526 :           tree main_binfo = TYPE_BINFO (BINFO_TYPE (b));
    2613                 :        526 :           tree bv = chain_index (ix, BINFO_VIRTUALS (main_binfo));
    2614                 :        526 :           if (!DECL_THUNK_P (TREE_VALUE (bv)))
    2615                 :            :             break;
    2616                 :         40 :           if (BINFO_LOST_PRIMARY_P (b))
    2617                 :          8 :             lost = true;
    2618                 :         40 :         }
    2619                 :            :       first_defn = b;
    2620                 :            :     }
    2621                 :            : 
    2622                 :            :   /* Assume that we will produce a thunk that convert all the way to
    2623                 :            :      the final overrider, and not to an intermediate virtual base.  */
    2624                 :     555965 :   virtual_base = NULL_TREE;
    2625                 :            : 
    2626                 :            :   /* See if we can convert to an intermediate virtual base first, and then
    2627                 :            :      use the vcall offset located there to finish the conversion.  */
    2628                 :     568582 :   for (; b; b = BINFO_INHERITANCE_CHAIN (b))
    2629                 :            :     {
    2630                 :            :       /* If we find the final overrider, then we can stop
    2631                 :            :          walking.  */
    2632                 :     568582 :       if (SAME_BINFO_TYPE_P (BINFO_TYPE (b),
    2633                 :            :                              BINFO_TYPE (TREE_VALUE (overrider))))
    2634                 :            :         break;
    2635                 :            : 
    2636                 :            :       /* If we find a virtual base, and we haven't yet found the
    2637                 :            :          overrider, then there is a virtual base between the
    2638                 :            :          declaring base (first_defn) and the final overrider.  */
    2639                 :      38307 :       if (BINFO_VIRTUAL_P (b))
    2640                 :            :         {
    2641                 :            :           virtual_base = b;
    2642                 :            :           break;
    2643                 :            :         }
    2644                 :            :     }
    2645                 :            : 
    2646                 :            :   /* Compute the constant adjustment to the `this' pointer.  The
    2647                 :            :      `this' pointer, when this function is called, will point at BINFO
    2648                 :            :      (or one of its primary bases, which are at the same offset).  */
    2649                 :     555965 :   if (virtual_base)
    2650                 :            :     /* The `this' pointer needs to be adjusted from the declaration to
    2651                 :            :        the nearest virtual base.  */
    2652                 :      77070 :     delta = size_diffop_loc (input_location,
    2653                 :      25690 :                          fold_convert (ssizetype, BINFO_OFFSET (virtual_base)),
    2654                 :      25690 :                          fold_convert (ssizetype, BINFO_OFFSET (first_defn)));
    2655                 :     530275 :   else if (lost)
    2656                 :            :     /* If the nearest definition is in a lost primary, we don't need an
    2657                 :            :        entry in our vtable.  Except possibly in a constructor vtable,
    2658                 :            :        if we happen to get our primary back.  In that case, the offset
    2659                 :            :        will be zero, as it will be a primary base.  */
    2660                 :        428 :     delta = size_zero_node;
    2661                 :            :   else
    2662                 :            :     /* The `this' pointer needs to be adjusted from pointing to
    2663                 :            :        BINFO to pointing at the base where the final overrider
    2664                 :            :        appears.  */
    2665                 :    1589540 :     delta = size_diffop_loc (input_location,
    2666                 :     529847 :                          fold_convert (ssizetype,
    2667                 :            :                                   BINFO_OFFSET (TREE_VALUE (overrider))),
    2668                 :     529847 :                          fold_convert (ssizetype, BINFO_OFFSET (binfo)));
    2669                 :            : 
    2670                 :     555965 :   modify_vtable_entry (t, binfo, overrider_fn, delta, virtuals);
    2671                 :            : 
    2672                 :     555965 :   if (virtual_base)
    2673                 :      25690 :     BV_VCALL_INDEX (*virtuals)
    2674                 :      25690 :       = get_vcall_index (overrider_target, BINFO_TYPE (virtual_base));
    2675                 :            :   else
    2676                 :     530275 :     BV_VCALL_INDEX (*virtuals) = NULL_TREE;
    2677                 :            : 
    2678                 :    1111930 :   BV_LOST_PRIMARY (*virtuals) = lost;
    2679                 :            : }
    2680                 :            : 
    2681                 :            : /* Called from modify_all_vtables via dfs_walk.  */
    2682                 :            : 
    2683                 :            : static tree
    2684                 :   11954300 : dfs_modify_vtables (tree binfo, void* data)
    2685                 :            : {
    2686                 :   11954300 :   tree t = (tree) data;
    2687                 :   11954300 :   tree virtuals;
    2688                 :   11954300 :   tree old_virtuals;
    2689                 :   11954300 :   unsigned ix;
    2690                 :            : 
    2691                 :   23908600 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    2692                 :            :     /* A base without a vtable needs no modification, and its bases
    2693                 :            :        are uninteresting.  */
    2694                 :            :     return dfs_skip_bases;
    2695                 :            : 
    2696                 :     394732 :   if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), t)
    2697                 :     561660 :       && !CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    2698                 :            :     /* Don't do the primary vtable, if it's new.  */
    2699                 :            :     return NULL_TREE;
    2700                 :            : 
    2701                 :     355402 :   if (BINFO_PRIMARY_P (binfo) && !BINFO_VIRTUAL_P (binfo))
    2702                 :            :     /* There's no need to modify the vtable for a non-virtual primary
    2703                 :            :        base; we're not going to use that vtable anyhow.  We do still
    2704                 :            :        need to do this for virtual primary bases, as they could become
    2705                 :            :        non-primary in a construction vtable.  */
    2706                 :            :     return NULL_TREE;
    2707                 :            : 
    2708                 :     159962 :   make_new_vtable (t, binfo);
    2709                 :            : 
    2710                 :            :   /* Now, go through each of the virtual functions in the virtual
    2711                 :            :      function table for BINFO.  Find the final overrider, and update
    2712                 :            :      the BINFO_VIRTUALS list appropriately.  */
    2713                 :     159962 :   for (ix = 0, virtuals = BINFO_VIRTUALS (binfo),
    2714                 :     159962 :          old_virtuals = BINFO_VIRTUALS (TYPE_BINFO (BINFO_TYPE (binfo)));
    2715                 :     715939 :        virtuals;
    2716                 :     555977 :        ix++, virtuals = TREE_CHAIN (virtuals),
    2717                 :     555977 :          old_virtuals = TREE_CHAIN (old_virtuals))
    2718                 :     555977 :     update_vtable_entry_for_fn (t,
    2719                 :            :                                 binfo,
    2720                 :     555977 :                                 BV_FN (old_virtuals),
    2721                 :            :                                 &virtuals, ix);
    2722                 :            : 
    2723                 :            :   return NULL_TREE;
    2724                 :            : }
    2725                 :            : 
    2726                 :            : /* Update all of the primary and secondary vtables for T.  Create new
    2727                 :            :    vtables as required, and initialize their RTTI information.  Each
    2728                 :            :    of the functions in VIRTUALS is declared in T and may override a
    2729                 :            :    virtual function from a base class; find and modify the appropriate
    2730                 :            :    entries to point to the overriding functions.  Returns a list, in
    2731                 :            :    declaration order, of the virtual functions that are declared in T,
    2732                 :            :    but do not appear in the primary base class vtable, and which
    2733                 :            :    should therefore be appended to the end of the vtable for T.  */
    2734                 :            : 
    2735                 :            : static tree
    2736                 :   11678000 : modify_all_vtables (tree t, tree virtuals)
    2737                 :            : {
    2738                 :   11678000 :   tree binfo = TYPE_BINFO (t);
    2739                 :   11678000 :   tree *fnsp;
    2740                 :            : 
    2741                 :            :   /* Mangle the vtable name before entering dfs_walk (c++/51884).  */
    2742                 :   34869700 :   if (TYPE_CONTAINS_VPTR_P (t))
    2743                 :     166928 :     get_vtable_decl (t, false);
    2744                 :            : 
    2745                 :            :   /* Update all of the vtables.  */
    2746                 :   11678000 :   dfs_walk_once (binfo, dfs_modify_vtables, NULL, t);
    2747                 :            : 
    2748                 :            :   /* Add virtual functions not already in our primary vtable. These
    2749                 :            :      will be both those introduced by this class, and those overridden
    2750                 :            :      from secondary bases.  It does not include virtuals merely
    2751                 :            :      inherited from secondary bases.  */
    2752                 :   12360000 :   for (fnsp = &virtuals; *fnsp; )
    2753                 :            :     {
    2754                 :     682018 :       tree fn = TREE_VALUE (*fnsp);
    2755                 :            : 
    2756                 :     682018 :       if (!value_member (fn, BINFO_VIRTUALS (binfo))
    2757                 :    1068050 :           || DECL_VINDEX (fn) == error_mark_node)
    2758                 :            :         {
    2759                 :            :           /* We don't need to adjust the `this' pointer when
    2760                 :            :              calling this function.  */
    2761                 :     295983 :           BV_DELTA (*fnsp) = integer_zero_node;
    2762                 :     295983 :           BV_VCALL_INDEX (*fnsp) = NULL_TREE;
    2763                 :            : 
    2764                 :            :           /* This is a function not already in our vtable.  Keep it.  */
    2765                 :     295983 :           fnsp = &TREE_CHAIN (*fnsp);
    2766                 :            :         }
    2767                 :            :       else
    2768                 :            :         /* We've already got an entry for this function.  Skip it.  */
    2769                 :     386035 :         *fnsp = TREE_CHAIN (*fnsp);
    2770                 :            :     }
    2771                 :            : 
    2772                 :   11678000 :   return virtuals;
    2773                 :            : }
    2774                 :            : 
    2775                 :            : /* Get the base virtual function declarations in T that have the
    2776                 :            :    indicated NAME.  */
    2777                 :            : 
    2778                 :            : static void
    2779                 :        156 : get_basefndecls (tree name, tree t, vec<tree> *base_fndecls)
    2780                 :            : {
    2781                 :        156 :   bool found_decls = false;
    2782                 :            : 
    2783                 :            :   /* Find virtual functions in T with the indicated NAME.  */
    2784                 :        316 :   for (ovl_iterator iter (get_class_binding (t, name)); iter; ++iter)
    2785                 :            :     {
    2786                 :         80 :       tree method = *iter;
    2787                 :            : 
    2788                 :         80 :       if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method))
    2789                 :            :         {
    2790                 :         68 :           base_fndecls->safe_push (method);
    2791                 :         68 :           found_decls = true;
    2792                 :            :         }
    2793                 :            :     }
    2794                 :            : 
    2795                 :        156 :   if (found_decls)
    2796                 :            :     return;
    2797                 :            : 
    2798                 :         96 :   int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t));
    2799                 :        120 :   for (int i = 0; i < n_baseclasses; i++)
    2800                 :            :     {
    2801                 :         24 :       tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i));
    2802                 :         24 :       get_basefndecls (name, basetype, base_fndecls);
    2803                 :            :     }
    2804                 :            : }
    2805                 :            : 
    2806                 :            : /* If this method overrides a virtual method from a base, then mark
    2807                 :            :    this member function as being virtual as well.  Do 'final' and
    2808                 :            :    'override' checks too.  */
    2809                 :            : 
    2810                 :            : void
    2811                 :   12601700 : check_for_override (tree decl, tree ctype)
    2812                 :            : {
    2813                 :   12601700 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    2814                 :            :     /* In [temp.mem] we have:
    2815                 :            : 
    2816                 :            :          A specialization of a member function template does not
    2817                 :            :          override a virtual function from a base class.  */
    2818                 :            :     return;
    2819                 :            : 
    2820                 :            :   /* IDENTIFIER_VIRTUAL_P indicates whether the name has ever been
    2821                 :            :      used for a vfunc.  That avoids the expensive look_for_overrides
    2822                 :            :      call that when we know there's nothing to find.  As conversion
    2823                 :            :      operators for the same type can have distinct identifiers, we
    2824                 :            :      cannot optimize those in that way.  */
    2825                 :   10404100 :   if ((IDENTIFIER_VIRTUAL_P (DECL_NAME (decl))
    2826                 :    9010170 :        || DECL_CONV_FN_P (decl))
    2827                 :    1457960 :       && look_for_overrides (ctype, decl)
    2828                 :            :       /* Check staticness after we've checked if we 'override'.  */
    2829                 :   10943600 :       && !DECL_STATIC_FUNCTION_P (decl))
    2830                 :            :     {
    2831                 :            :       /* Set DECL_VINDEX to a value that is neither an INTEGER_CST nor
    2832                 :            :          the error_mark_node so that we know it is an overriding
    2833                 :            :          function.  */
    2834                 :     269740 :       DECL_VINDEX (decl) = decl;
    2835                 :            : 
    2836                 :     269740 :       if (warn_override
    2837                 :          5 :           && !DECL_OVERRIDE_P (decl)
    2838                 :          4 :           && !DECL_FINAL_P (decl)
    2839                 :     269743 :           && !DECL_DESTRUCTOR_P (decl))
    2840                 :          2 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override,
    2841                 :            :                     "%qD can be marked override", decl);
    2842                 :            :     }
    2843                 :   20268700 :   else if (DECL_OVERRIDE_P (decl))
    2844                 :         12 :     error ("%q+#D marked %<override%>, but does not override", decl);
    2845                 :            : 
    2846                 :   10404100 :   if (DECL_VIRTUAL_P (decl))
    2847                 :            :     {
    2848                 :            :       /* Remember this identifier is virtual name.  */
    2849                 :     529956 :       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = true;
    2850                 :            : 
    2851                 :     529956 :       if (!DECL_VINDEX (decl))
    2852                 :            :         /* It's a new vfunc.  */
    2853                 :     260216 :         DECL_VINDEX (decl) = error_mark_node;
    2854                 :            : 
    2855                 :     529956 :       if (DECL_DESTRUCTOR_P (decl))
    2856                 :     152062 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
    2857                 :            :     }
    2858                 :    9874130 :   else if (DECL_FINAL_P (decl))
    2859                 :          3 :     error ("%q+#D marked %<final%>, but is not virtual", decl);
    2860                 :            : }
    2861                 :            : 
    2862                 :            : /* Warn about hidden virtual functions that are not overridden in t.
    2863                 :            :    We know that constructors and destructors don't apply.  */
    2864                 :            : 
    2865                 :            : static void
    2866                 :         84 : warn_hidden (tree t)
    2867                 :            : {
    2868                 :         84 :   if (vec<tree, va_gc> *member_vec = CLASSTYPE_MEMBER_VEC (t))
    2869                 :        364 :     for (unsigned ix = member_vec->length (); ix--;)
    2870                 :            :       {
    2871                 :        288 :         tree fns = (*member_vec)[ix];
    2872                 :            : 
    2873                 :        288 :         if (!OVL_P (fns))
    2874                 :        120 :           continue;
    2875                 :            : 
    2876                 :        168 :         tree name = OVL_NAME (fns);
    2877                 :        228 :         auto_vec<tree, 20> base_fndecls;
    2878                 :        168 :         tree base_binfo;
    2879                 :        168 :         tree binfo;
    2880                 :        168 :         unsigned j;
    2881                 :            : 
    2882                 :            :         /* Iterate through all of the base classes looking for possibly
    2883                 :            :            hidden functions.  */
    2884                 :        300 :         for (binfo = TYPE_BINFO (t), j = 0;
    2885                 :        300 :              BINFO_BASE_ITERATE (binfo, j, base_binfo); j++)
    2886                 :            :           {
    2887                 :        132 :             tree basetype = BINFO_TYPE (base_binfo);
    2888                 :        132 :             get_basefndecls (name, basetype, &base_fndecls);
    2889                 :            :           }
    2890                 :            : 
    2891                 :            :         /* If there are no functions to hide, continue.  */
    2892                 :        168 :         if (base_fndecls.is_empty ())
    2893                 :        336 :           continue;
    2894                 :            : 
    2895                 :            :         /* Remove any overridden functions.  */
    2896                 :        196 :         for (ovl_iterator iter (fns); iter; ++iter)
    2897                 :            :           {
    2898                 :         68 :             tree fndecl = *iter;
    2899                 :         68 :             if (TREE_CODE (fndecl) == FUNCTION_DECL
    2900                 :         68 :                 && DECL_VINDEX (fndecl))
    2901                 :            :               {
    2902                 :            :                 /* If the method from the base class has the same
    2903                 :            :                    signature as the method from the derived class, it
    2904                 :            :                    has been overridden.  */
    2905                 :        232 :                 for (size_t k = 0; k < base_fndecls.length (); k++)
    2906                 :         64 :                   if (base_fndecls[k]
    2907                 :         64 :                       && same_signature_p (fndecl, base_fndecls[k]))
    2908                 :         44 :                     base_fndecls[k] = NULL_TREE;
    2909                 :            :               }
    2910                 :            :           }
    2911                 :            : 
    2912                 :            :         /* Now give a warning for all base functions without overriders,
    2913                 :            :            as they are hidden.  */
    2914                 :         60 :         tree base_fndecl;
    2915                 :        188 :         FOR_EACH_VEC_ELT (base_fndecls, j, base_fndecl)
    2916                 :         68 :           if (base_fndecl)
    2917                 :            :             {
    2918                 :         48 :               auto_diagnostic_group d;
    2919                 :            :               /* Here we know it is a hider, and no overrider exists.  */
    2920                 :         24 :               if (warning_at (location_of (base_fndecl),
    2921                 :            :                               OPT_Woverloaded_virtual,
    2922                 :            :                               "%qD was hidden", base_fndecl))
    2923                 :         20 :                 inform (location_of (fns), "  by %qD", fns);
    2924                 :            :             }
    2925                 :            :       }
    2926                 :         84 : }
    2927                 :            : 
    2928                 :            : /* Recursive helper for finish_struct_anon.  */
    2929                 :            : 
    2930                 :            : static void
    2931                 :      24666 : finish_struct_anon_r (tree field, bool complain)
    2932                 :            : {
    2933                 :     133992 :   for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
    2934                 :            :     {
    2935                 :            :       /* We're generally only interested in entities the user
    2936                 :            :          declared, but we also find nested classes by noticing
    2937                 :            :          the TYPE_DECL that we create implicitly.  You're
    2938                 :            :          allowed to put one anonymous union inside another,
    2939                 :            :          though, so we explicitly tolerate that.  We use
    2940                 :            :          TYPE_UNNAMED_P rather than ANON_AGGR_TYPE_P so that
    2941                 :            :          we also allow unnamed types used for defining fields.  */
    2942                 :      85301 :       if (DECL_ARTIFICIAL (elt)
    2943                 :      35289 :           && (!DECL_IMPLICIT_TYPEDEF_P (elt)
    2944                 :      95924 :               || TYPE_UNNAMED_P (TREE_TYPE (elt))))
    2945                 :      35273 :         continue;
    2946                 :            : 
    2947                 :      50028 :       if (complain
    2948                 :      49218 :           && (TREE_CODE (elt) != FIELD_DECL
    2949                 :      49218 :               || (TREE_PRIVATE (elt) || TREE_PROTECTED (elt))))
    2950                 :            :         {
    2951                 :            :           /* We already complained about static data members in
    2952                 :            :              finish_static_data_member_decl.  */
    2953                 :         67 :           if (!VAR_P (elt))
    2954                 :            :             {
    2955                 :        102 :               auto_diagnostic_group d;
    2956                 :        102 :               if (permerror (DECL_SOURCE_LOCATION (elt),
    2957                 :         51 :                              TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
    2958                 :            :                              ? "%q#D invalid; an anonymous union may "
    2959                 :            :                              "only have public non-static data members"
    2960                 :            :                              : "%q#D invalid; an anonymous struct may "
    2961                 :            :                              "only have public non-static data members", elt))
    2962                 :            :                 {
    2963                 :         51 :                   static bool hint;
    2964                 :         51 :                   if (flag_permissive && !hint)
    2965                 :            :                     {
    2966                 :          8 :                       hint = true;
    2967                 :          8 :                       inform (DECL_SOURCE_LOCATION (elt),
    2968                 :            :                               "this flexibility is deprecated and will be "
    2969                 :            :                               "removed");
    2970                 :            :                     }
    2971                 :            :                 }
    2972                 :            :             }
    2973                 :            :         }
    2974                 :            : 
    2975                 :      50028 :       TREE_PRIVATE (elt) = TREE_PRIVATE (field);
    2976                 :      50028 :       TREE_PROTECTED (elt) = TREE_PROTECTED (field);
    2977                 :            : 
    2978                 :            :       /* Recurse into the anonymous aggregates to correctly handle
    2979                 :            :          access control (c++/24926):
    2980                 :            : 
    2981                 :            :          class A {
    2982                 :            :            union {
    2983                 :            :              union {
    2984                 :            :                int i;
    2985                 :            :              };
    2986                 :            :            };
    2987                 :            :          };
    2988                 :            : 
    2989                 :            :          int j=A().i;  */
    2990                 :      50028 :       if (DECL_NAME (elt) == NULL_TREE
    2991                 :      50319 :           && ANON_AGGR_TYPE_P (TREE_TYPE (elt)))
    2992                 :        291 :         finish_struct_anon_r (elt, /*complain=*/false);
    2993                 :            :     }
    2994                 :      24666 : }
    2995                 :            : 
    2996                 :            : /* Check for things that are invalid.  There are probably plenty of other
    2997                 :            :    things we should check for also.  */
    2998                 :            : 
    2999                 :            : static void
    3000                 :   11678000 : finish_struct_anon (tree t)
    3001                 :            : {
    3002                 :   47350000 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3003                 :            :     {
    3004                 :   35572200 :       if (TREE_STATIC (field))
    3005                 :    1211510 :         continue;
    3006                 :   34360700 :       if (TREE_CODE (field) != FIELD_DECL)
    3007                 :   32054500 :         continue;
    3008                 :            : 
    3009                 :    2306200 :       if (DECL_NAME (field) == NULL_TREE
    3010                 :    2362450 :           && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    3011                 :      24375 :         finish_struct_anon_r (field, /*complain=*/true);
    3012                 :            :     }
    3013                 :   11678000 : }
    3014                 :            : 
    3015                 :            : /* Add T to CLASSTYPE_DECL_LIST of current_class_type which
    3016                 :            :    will be used later during class template instantiation.
    3017                 :            :    When FRIEND_P is zero, T can be a static member data (VAR_DECL),
    3018                 :            :    a non-static member data (FIELD_DECL), a member function
    3019                 :            :    (FUNCTION_DECL), a nested type (RECORD_TYPE, ENUM_TYPE),
    3020                 :            :    a typedef (TYPE_DECL) or a member class template (TEMPLATE_DECL)
    3021                 :            :    When FRIEND_P is nonzero, T is either a friend class
    3022                 :            :    (RECORD_TYPE, TEMPLATE_DECL) or a friend function
    3023                 :            :    (FUNCTION_DECL, TEMPLATE_DECL).  */
    3024                 :            : 
    3025                 :            : void
    3026                 :   49744700 : maybe_add_class_template_decl_list (tree type, tree t, int friend_p)
    3027                 :            : {
    3028                 :            :   /* Save some memory by not creating TREE_LIST if TYPE is not template.  */
    3029                 :   50290600 :   if (CLASSTYPE_TEMPLATE_INFO (type))
    3030                 :   44124600 :     CLASSTYPE_DECL_LIST (type)
    3031                 :   44124600 :       = tree_cons (friend_p ? NULL_TREE : type,
    3032                 :   44124600 :                    t, CLASSTYPE_DECL_LIST (type));
    3033                 :   49744700 : }
    3034                 :            : 
    3035                 :            : /* This function is called from declare_virt_assop_and_dtor via
    3036                 :            :    dfs_walk_all.
    3037                 :            : 
    3038                 :            :    DATA is a type that direcly or indirectly inherits the base
    3039                 :            :    represented by BINFO.  If BINFO contains a virtual assignment [copy
    3040                 :            :    assignment or move assigment] operator or a virtual constructor,
    3041                 :            :    declare that function in DATA if it hasn't been already declared.  */
    3042                 :            : 
    3043                 :            : static tree
    3044                 :     304796 : dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
    3045                 :            : {
    3046                 :     304796 :   tree bv, fn, t = (tree)data;
    3047                 :     304796 :   tree opname = assign_op_identifier;
    3048                 :            : 
    3049                 :     609592 :   gcc_assert (t && CLASS_TYPE_P (t));
    3050                 :     304796 :   gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
    3051                 :            : 
    3052                 :     609592 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
    3053                 :            :     /* A base without a vtable needs no modification, and its bases
    3054                 :            :        are uninteresting.  */
    3055                 :            :     return dfs_skip_bases;
    3056                 :            : 
    3057                 :     262619 :   if (BINFO_PRIMARY_P (binfo))
    3058                 :            :     /* If this is a primary base, then we have already looked at the
    3059                 :            :        virtual functions of its vtable.  */
    3060                 :            :     return NULL_TREE;
    3061                 :            : 
    3062                 :     861485 :   for (bv = BINFO_VIRTUALS (binfo); bv; bv = TREE_CHAIN (bv))
    3063                 :            :     {
    3064                 :     598866 :       fn = BV_FN (bv);
    3065                 :            : 
    3066                 :     598866 :       if (DECL_NAME (fn) == opname)
    3067                 :            :         {
    3068                 :         28 :           if (CLASSTYPE_LAZY_COPY_ASSIGN (t))
    3069                 :         28 :             lazily_declare_fn (sfk_copy_assignment, t);
    3070                 :         28 :           if (CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    3071                 :         21 :             lazily_declare_fn (sfk_move_assignment, t);
    3072                 :            :         }
    3073                 :     598838 :       else if (DECL_DESTRUCTOR_P (fn)
    3074                 :     877740 :                && CLASSTYPE_LAZY_DESTRUCTOR (t))
    3075                 :      13180 :         lazily_declare_fn (sfk_destructor, t);
    3076                 :            :     }
    3077                 :            : 
    3078                 :            :   return NULL_TREE;
    3079                 :            : }
    3080                 :            : 
    3081                 :            : /* If the class type T has a direct or indirect base that contains a
    3082                 :            :    virtual assignment operator or a virtual destructor, declare that
    3083                 :            :    function in T if it hasn't been already declared.  */
    3084                 :            : 
    3085                 :            : static void
    3086                 :   11678000 : declare_virt_assop_and_dtor (tree t)
    3087                 :            : {
    3088                 :   11678000 :   if (!(TYPE_POLYMORPHIC_P (t)
    3089                 :     164356 :         && (CLASSTYPE_LAZY_COPY_ASSIGN (t)
    3090                 :     164356 :             || CLASSTYPE_LAZY_MOVE_ASSIGN (t)
    3091                 :   11733800 :             || CLASSTYPE_LAZY_DESTRUCTOR (t))))
    3092                 :            :     return;
    3093                 :            : 
    3094                 :     111955 :   dfs_walk_all (TYPE_BINFO (t),
    3095                 :            :                 dfs_declare_virt_assop_and_dtor,
    3096                 :            :                 NULL, t);
    3097                 :            : }
    3098                 :            : 
    3099                 :            : /* Declare the inheriting constructor for class T inherited from base
    3100                 :            :    constructor CTOR with the parameter array PARMS of size NPARMS.  */
    3101                 :            : 
    3102                 :            : static void
    3103                 :         90 : one_inheriting_sig (tree t, tree ctor, tree *parms, int nparms)
    3104                 :            : {
    3105                 :         90 :   gcc_assert (TYPE_MAIN_VARIANT (t) == t);
    3106                 :            : 
    3107                 :            :   /* We don't declare an inheriting ctor that would be a default,
    3108                 :            :      copy or move ctor for derived or base.  */
    3109                 :         90 :   if (nparms == 0)
    3110                 :            :     return;
    3111                 :         90 :   if (nparms == 1
    3112                 :         87 :       && TYPE_REF_P (parms[0]))
    3113                 :            :     {
    3114                 :         54 :       tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
    3115                 :        108 :       if (parm == t || parm == DECL_CONTEXT (ctor))
    3116                 :            :         return;
    3117                 :            :     }
    3118                 :            : 
    3119                 :         36 :   tree parmlist = void_list_node;
    3120                 :         75 :   for (int i = nparms - 1; i >= 0; i--)
    3121                 :         39 :     parmlist = tree_cons (NULL_TREE, parms[i], parmlist);
    3122                 :         36 :   tree fn = implicitly_declare_fn (sfk_inheriting_constructor,
    3123                 :            :                                    t, false, ctor, parmlist);
    3124                 :            : 
    3125                 :         36 :   if (add_method (t, fn, false))
    3126                 :            :     {
    3127                 :         27 :       DECL_CHAIN (fn) = TYPE_FIELDS (t);
    3128                 :         27 :       TYPE_FIELDS (t) = fn;
    3129                 :            :     }
    3130                 :            : }
    3131                 :            : 
    3132                 :            : /* Declare all the inheriting constructors for class T inherited from base
    3133                 :            :    constructor CTOR.  */
    3134                 :            : 
    3135                 :            : static void
    3136                 :      31027 : one_inherited_ctor (tree ctor, tree t, tree using_decl)
    3137                 :            : {
    3138                 :      62054 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (ctor);
    3139                 :            : 
    3140                 :      31027 :   if (flag_new_inheriting_ctors)
    3141                 :            :     {
    3142                 :      30937 :       ctor = implicitly_declare_fn (sfk_inheriting_constructor,
    3143                 :            :                                     t, /*const*/false, ctor, parms);
    3144                 :      30937 :       add_method (t, ctor, using_decl != NULL_TREE);
    3145                 :      30937 :       return;
    3146                 :            :     }
    3147                 :            : 
    3148                 :         90 :   tree *new_parms = XALLOCAVEC (tree, list_length (parms));
    3149                 :         90 :   int i = 0;
    3150                 :        183 :   for (; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
    3151                 :            :     {
    3152                 :         93 :       if (TREE_PURPOSE (parms))
    3153                 :          0 :         one_inheriting_sig (t, ctor, new_parms, i);
    3154                 :         93 :       new_parms[i++] = TREE_VALUE (parms);
    3155                 :            :     }
    3156                 :         90 :   one_inheriting_sig (t, ctor, new_parms, i);
    3157                 :         90 :   if (parms == NULL_TREE)
    3158                 :            :     {
    3159                 :          6 :       auto_diagnostic_group d;
    3160                 :          3 :       if (warning (OPT_Winherited_variadic_ctor,
    3161                 :            :                    "the ellipsis in %qD is not inherited", ctor))
    3162                 :          3 :         inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor);
    3163                 :            :     }
    3164                 :            : }
    3165                 :            : 
    3166                 :            : /* Create default constructors, assignment operators, and so forth for
    3167                 :            :    the type indicated by T, if they are needed.  CANT_HAVE_CONST_CTOR,
    3168                 :            :    and CANT_HAVE_CONST_ASSIGNMENT are nonzero if, for whatever reason,
    3169                 :            :    the class cannot have a default constructor, copy constructor
    3170                 :            :    taking a const reference argument, or an assignment operator taking
    3171                 :            :    a const reference, respectively.  */
    3172                 :            : 
    3173                 :            : static void
    3174                 :   11678000 : add_implicitly_declared_members (tree t, tree* access_decls,
    3175                 :            :                                  int cant_have_const_cctor,
    3176                 :            :                                  int cant_have_const_assignment)
    3177                 :            : {
    3178                 :            :   /* Destructor.  */
    3179                 :   11678000 :   if (!CLASSTYPE_DESTRUCTOR (t))
    3180                 :            :     /* In general, we create destructors lazily.  */
    3181                 :   11202000 :     CLASSTYPE_LAZY_DESTRUCTOR (t) = 1;
    3182                 :            : 
    3183                 :   11678000 :   bool move_ok = false;
    3184                 :   11592500 :   if (cxx_dialect >= cxx11 && CLASSTYPE_LAZY_DESTRUCTOR (t)
    3185                 :   11132100 :       && !TYPE_HAS_COPY_CTOR (t) && !TYPE_HAS_COPY_ASSIGN (t)
    3186                 :   22749300 :       && !classtype_has_move_assign_or_move_ctor_p (t, false))
    3187                 :            :     move_ok = true;
    3188                 :            : 
    3189                 :            :   /* [class.ctor]
    3190                 :            : 
    3191                 :            :      If there is no user-declared constructor for a class, a default
    3192                 :            :      constructor is implicitly declared.  */
    3193                 :   11678000 :   if (! TYPE_HAS_USER_CONSTRUCTOR (t))
    3194                 :            :     {
    3195                 :   10917900 :       TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
    3196                 :   10917900 :       CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1;
    3197                 :   10917900 :       if (cxx_dialect >= cxx11)
    3198                 :   10853700 :         TYPE_HAS_CONSTEXPR_CTOR (t)
    3199                 :            :           /* Don't force the declaration to get a hard answer; if the
    3200                 :            :              definition would have made the class non-literal, it will still be
    3201                 :            :              non-literal because of the base or member in question, and that
    3202                 :            :              gives a better diagnostic.  */
    3203                 :   10853700 :           = type_maybe_constexpr_default_constructor (t);
    3204                 :            :     }
    3205                 :            : 
    3206                 :            :   /* [class.ctor]
    3207                 :            : 
    3208                 :            :      If a class definition does not explicitly declare a copy
    3209                 :            :      constructor, one is declared implicitly.  */
    3210                 :   11678000 :   if (! TYPE_HAS_COPY_CTOR (t))
    3211                 :            :     {
    3212                 :   11398900 :       TYPE_HAS_COPY_CTOR (t) = 1;
    3213                 :   11398900 :       TYPE_HAS_CONST_COPY_CTOR (t) = !cant_have_const_cctor;
    3214                 :   11398900 :       CLASSTYPE_LAZY_COPY_CTOR (t) = 1;
    3215                 :   11398900 :       if (move_ok)
    3216                 :   11061000 :         CLASSTYPE_LAZY_MOVE_CTOR (t) = 1;
    3217                 :            :     }
    3218                 :            : 
    3219                 :            :   /* If there is no assignment operator, one will be created if and
    3220                 :            :      when it is needed.  For now, just record whether or not the type
    3221                 :            :      of the parameter to the assignment operator will be a const or
    3222                 :            :      non-const reference.  */
    3223                 :   11678000 :   if (!TYPE_HAS_COPY_ASSIGN (t))
    3224                 :            :     {
    3225                 :   11463400 :       TYPE_HAS_COPY_ASSIGN (t) = 1;
    3226                 :   11463400 :       TYPE_HAS_CONST_COPY_ASSIGN (t) = !cant_have_const_assignment;
    3227                 :   11463400 :       CLASSTYPE_LAZY_COPY_ASSIGN (t) = 1;
    3228                 :   22431300 :       if (move_ok && !LAMBDA_TYPE_P (t))
    3229                 :   11026200 :         CLASSTYPE_LAZY_MOVE_ASSIGN (t) = 1;
    3230                 :            :     }
    3231                 :            : 
    3232                 :            :   /* We can't be lazy about declaring functions that might override
    3233                 :            :      a virtual function from a base class.  */
    3234                 :   11678000 :   declare_virt_assop_and_dtor (t);
    3235                 :            : 
    3236                 :            :   /* If the class definition does not explicitly declare an == operator
    3237                 :            :      function, but declares a defaulted three-way comparison operator function,
    3238                 :            :      an == operator function is declared implicitly.  */
    3239                 :   11678000 :   if (!classtype_has_op (t, EQ_EXPR))
    3240                 :   11562100 :     if (tree space = classtype_has_defaulted_op (t, SPACESHIP_EXPR))
    3241                 :            :       {
    3242                 :          7 :         tree eq = implicitly_declare_fn (sfk_comparison, t, false, space,
    3243                 :            :                                          NULL_TREE);
    3244                 :         14 :         if (DECL_FRIEND_P (space))
    3245                 :          2 :           do_friend (NULL_TREE, DECL_NAME (eq), eq,
    3246                 :            :                      NULL_TREE, NO_SPECIAL, true);
    3247                 :            :         else
    3248                 :          5 :           add_method (t, eq, false);
    3249                 :            :       }
    3250                 :            : 
    3251                 :   11789600 :   while (*access_decls)
    3252                 :            :     {
    3253                 :     111633 :       tree using_decl = TREE_VALUE (*access_decls);
    3254                 :     111633 :       tree decl = USING_DECL_DECLS (using_decl);
    3255                 :     111633 :       if (DECL_NAME (using_decl) == ctor_identifier)
    3256                 :            :         {
    3257                 :            :           /* declare, then remove the decl */
    3258                 :       6518 :           tree ctor_list = decl;
    3259                 :       6518 :           location_t loc = input_location;
    3260                 :       6518 :           input_location = DECL_SOURCE_LOCATION (using_decl);
    3261                 :      68572 :           for (ovl_iterator iter (ctor_list); iter; ++iter)
    3262                 :      31027 :             one_inherited_ctor (*iter, t, using_decl);
    3263                 :       6518 :           *access_decls = TREE_CHAIN (*access_decls);
    3264                 :       6518 :           input_location = loc;
    3265                 :            :         }
    3266                 :            :       else
    3267                 :     105115 :         access_decls = &TREE_CHAIN (*access_decls);
    3268                 :            :     }
    3269                 :   11678000 : }
    3270                 :            : 
    3271                 :            : /* Cache of enum_min_precision values.  */
    3272                 :            : static GTY((deletable)) hash_map<tree, int> *enum_to_min_precision;
    3273                 :            : 
    3274                 :            : /* Return the minimum precision of a bit-field needed to store all
    3275                 :            :    enumerators of ENUMERAL_TYPE TYPE.  */
    3276                 :            : 
    3277                 :            : static int
    3278                 :       4900 : enum_min_precision (tree type)
    3279                 :            : {
    3280                 :       4900 :   type = TYPE_MAIN_VARIANT (type);
    3281                 :            :   /* For unscoped enums without fixed underlying type and without mode
    3282                 :            :      attribute we can just use precision of the underlying type.  */
    3283                 :       4900 :   if (UNSCOPED_ENUM_P (type)
    3284                 :       4880 :       && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
    3285                 :       9765 :       && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
    3286                 :       4853 :     return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
    3287                 :            : 
    3288                 :         47 :   if (enum_to_min_precision == NULL)
    3289                 :         11 :     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
    3290                 :            : 
    3291                 :         47 :   bool existed;
    3292                 :         47 :   int &prec = enum_to_min_precision->get_or_insert (type, &existed);
    3293                 :         47 :   if (existed)
    3294                 :         24 :     return prec;
    3295                 :            : 
    3296                 :         23 :   tree minnode, maxnode;
    3297                 :         23 :   if (TYPE_VALUES (type))
    3298                 :            :     {
    3299                 :            :       minnode = maxnode = NULL_TREE;
    3300                 :         39 :       for (tree values = TYPE_VALUES (type);
    3301                 :         60 :            values; values = TREE_CHAIN (values))
    3302                 :            :         {
    3303                 :         39 :           tree decl = TREE_VALUE (values);
    3304                 :         39 :           tree value = DECL_INITIAL (decl);
    3305                 :         39 :           if (value == error_mark_node)
    3306                 :          0 :             value = integer_zero_node;
    3307                 :         39 :           if (!minnode)
    3308                 :            :             minnode = maxnode = value;
    3309                 :         18 :           else if (tree_int_cst_lt (maxnode, value))
    3310                 :            :             maxnode = value;
    3311                 :          0 :           else if (tree_int_cst_lt (value, minnode))
    3312                 :          0 :             minnode = value;
    3313                 :            :         }
    3314                 :            :     }
    3315                 :            :   else
    3316                 :          2 :     minnode = maxnode = integer_zero_node;
    3317                 :            : 
    3318                 :         23 :   signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
    3319                 :         23 :   int lowprec = tree_int_cst_min_precision (minnode, sgn);
    3320                 :         23 :   int highprec = tree_int_cst_min_precision (maxnode, sgn);
    3321                 :         23 :   prec = MAX (lowprec, highprec);
    3322                 :         23 :   return prec;
    3323                 :            : }
    3324                 :            : 
    3325                 :            : /* FIELD is a bit-field.  We are finishing the processing for its
    3326                 :            :    enclosing type.  Issue any appropriate messages and set appropriate
    3327                 :            :    flags.  Returns false if an error has been diagnosed.  */
    3328                 :            : 
    3329                 :            : static bool
    3330                 :      45768 : check_bitfield_decl (tree field)
    3331                 :            : {
    3332                 :      45768 :   tree type = TREE_TYPE (field);
    3333                 :      45768 :   tree w;
    3334                 :            : 
    3335                 :            :   /* Extract the declared width of the bitfield, which has been
    3336                 :            :      temporarily stashed in DECL_BIT_FIELD_REPRESENTATIVE by grokbitfield.  */
    3337                 :      45768 :   w = DECL_BIT_FIELD_REPRESENTATIVE (field);
    3338                 :      45768 :   gcc_assert (w != NULL_TREE);
    3339                 :            :   /* Remove the bit-field width indicator so that the rest of the
    3340                 :            :      compiler does not treat that value as a qualifier.  */
    3341                 :      45768 :   DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
    3342                 :            : 
    3343                 :            :   /* Detect invalid bit-field type.  */
    3344                 :      45768 :   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    3345                 :            :     {
    3346                 :          4 :       error_at (DECL_SOURCE_LOCATION (field),
    3347                 :            :                 "bit-field %q#D with non-integral type %qT", field, type);
    3348                 :          4 :       w = error_mark_node;
    3349                 :            :     }
    3350                 :            :   else
    3351                 :            :     {
    3352                 :      45764 :       location_t loc = input_location;
    3353                 :            :       /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs.  */
    3354                 :      45764 :       STRIP_NOPS (w);
    3355                 :            : 
    3356                 :            :       /* detect invalid field size.  */
    3357                 :      45764 :       input_location = DECL_SOURCE_LOCATION (field);
    3358                 :      45764 :       w = cxx_constant_value (w);
    3359                 :      45764 :       input_location = loc;
    3360                 :            : 
    3361                 :      45764 :       if (TREE_CODE (w) != INTEGER_CST)
    3362                 :            :         {
    3363                 :         19 :           error ("bit-field %q+D width not an integer constant", field);
    3364                 :         19 :           w = error_mark_node;
    3365                 :            :         }
    3366                 :      45745 :       else if (tree_int_cst_sgn (w) < 0)
    3367                 :            :         {
    3368                 :          0 :           error ("negative width in bit-field %q+D", field);
    3369                 :          0 :           w = error_mark_node;
    3370                 :            :         }
    3371                 :      46349 :       else if (integer_zerop (w) && DECL_NAME (field) != 0)
    3372                 :            :         {
    3373                 :         18 :           error ("zero width for bit-field %q+D", field);
    3374                 :         18 :           w = error_mark_node;
    3375                 :            :         }
    3376                 :      45727 :       else if ((TREE_CODE (type) != ENUMERAL_TYPE
    3377                 :      45727 :                 && TREE_CODE (type) != BOOLEAN_TYPE
    3378                 :      39929 :                 && compare_tree_int (w, TYPE_PRECISION (type)) > 0)
    3379                 :      45727 :                || ((TREE_CODE (type) == ENUMERAL_TYPE
    3380                 :      45471 :                     || TREE_CODE (type) == BOOLEAN_TYPE)
    3381                 :       5798 :                    && tree_int_cst_lt (TYPE_SIZE (type), w)))
    3382                 :        458 :         warning_at (DECL_SOURCE_LOCATION (field), 0,
    3383                 :            :                     "width of %qD exceeds its type", field);
    3384                 :      45269 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    3385                 :            :         {
    3386                 :       4900 :           int prec = enum_min_precision (type);
    3387                 :       4900 :           if (compare_tree_int (w, prec) < 0)
    3388                 :         54 :             warning_at (DECL_SOURCE_LOCATION (field), 0,
    3389                 :            :                         "%qD is too small to hold all values of %q#T",
    3390                 :            :                         field, type);
    3391                 :            :         }
    3392                 :            :     }
    3393                 :            : 
    3394                 :      45768 :   if (w != error_mark_node)
    3395                 :            :     {
    3396                 :      45727 :       DECL_SIZE (field) = fold_convert (bitsizetype, w);
    3397                 :      45727 :       DECL_BIT_FIELD (field) = 1;
    3398                 :      45727 :       return true;
    3399                 :            :     }
    3400                 :            :   else
    3401                 :            :     {
    3402                 :            :       /* Non-bit-fields are aligned for their type.  */
    3403                 :         41 :       DECL_BIT_FIELD (field) = 0;
    3404                 :         41 :       CLEAR_DECL_C_BIT_FIELD (field);
    3405                 :         41 :       return false;
    3406                 :            :     }
    3407                 :            : }
    3408                 :            : 
    3409                 :            : /* FIELD is a non bit-field.  We are finishing the processing for its
    3410                 :            :    enclosing type T.  Issue any appropriate messages and set appropriate
    3411                 :            :    flags.  */
    3412                 :            : 
    3413                 :            : static bool
    3414                 :    2352770 : check_field_decl (tree field,
    3415                 :            :                   tree t,
    3416                 :            :                   int* cant_have_const_ctor,
    3417                 :            :                   int* no_const_asn_ref)
    3418                 :            : {
    3419                 :    2352770 :   tree type = strip_array_types (TREE_TYPE (field));
    3420                 :    2352770 :   bool any_default_members = false;
    3421                 :            : 
    3422                 :            :   /* In C++98 an anonymous union cannot contain any fields which would change
    3423                 :            :      the settings of CANT_HAVE_CONST_CTOR and friends.  */
    3424                 :    2405700 :   if (ANON_UNION_TYPE_P (type) && cxx_dialect < cxx11)
    3425                 :            :     ;
    3426                 :            :   /* And, we don't set TYPE_HAS_CONST_COPY_CTOR, etc., for anonymous
    3427                 :            :      structs.  So, we recurse through their fields here.  */
    3428                 :    2710140 :   else if (ANON_AGGR_TYPE_P (type))
    3429                 :            :     {
    3430                 :     182125 :       for (tree fields = TYPE_FIELDS (type); fields;
    3431                 :      79538 :            fields = DECL_CHAIN (fields))
    3432                 :      79538 :         if (TREE_CODE (fields) == FIELD_DECL)
    3433                 :      46769 :           any_default_members |= check_field_decl (fields, t,
    3434                 :            :                                                    cant_have_const_ctor,
    3435                 :            :                                                    no_const_asn_ref);
    3436                 :            :     }
    3437                 :            :   /* Check members with class type for constructors, destructors,
    3438                 :            :      etc.  */
    3439                 :    2664050 :   else if (CLASS_TYPE_P (type))
    3440                 :            :     {
    3441                 :            :       /* Never let anything with uninheritable virtuals
    3442                 :            :          make it through without complaint.  */
    3443                 :     334494 :       abstract_virtuals_error (field, type);
    3444                 :            : 
    3445                 :     334494 :       if (TREE_CODE (t) == UNION_TYPE && cxx_dialect < cxx11)
    3446                 :            :         {
    3447                 :       2680 :           static bool warned;
    3448                 :       2680 :           int oldcount = errorcount;
    3449                 :       2680 :           if (TYPE_NEEDS_CONSTRUCTING (type))
    3450                 :          2 :             error ("member %q+#D with constructor not allowed in union",
    3451                 :            :                    field);
    3452                 :       2680 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    3453                 :          0 :             error ("member %q+#D with destructor not allowed in union", field);
    3454                 :       2680 :           if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    3455                 :          3 :             error ("member %q+#D with copy assignment operator not allowed in union",
    3456                 :            :                    field);
    3457                 :       2680 :           if (!warned && errorcount > oldcount)
    3458                 :            :             {
    3459                 :          4 :               inform (DECL_SOURCE_LOCATION (field), "unrestricted unions "
    3460                 :            :                       "only available with %<-std=c++11%> or %<-std=gnu++11%>");
    3461                 :          4 :               warned = true;
    3462                 :            :             }
    3463                 :            :         }
    3464                 :            :       else
    3465                 :            :         {
    3466                 :     331814 :           TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
    3467                 :     331814 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3468                 :     331814 :             |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);
    3469                 :     331814 :           TYPE_HAS_COMPLEX_COPY_ASSIGN (t)
    3470                 :     663628 :             |= (TYPE_HAS_COMPLEX_COPY_ASSIGN (type)
    3471                 :     331814 :                 || !TYPE_HAS_COPY_ASSIGN (type));
    3472                 :     331814 :           TYPE_HAS_COMPLEX_COPY_CTOR (t) |= (TYPE_HAS_COMPLEX_COPY_CTOR (type)
    3473                 :     331814 :                                              || !TYPE_HAS_COPY_CTOR (type));
    3474                 :     331814 :           TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
    3475                 :     331814 :           TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
    3476                 :     663628 :           TYPE_HAS_COMPLEX_DFLT (t) |= (!TYPE_HAS_DEFAULT_CONSTRUCTOR (type)
    3477                 :     331814 :                                         || TYPE_HAS_COMPLEX_DFLT (type));
    3478                 :            :         }
    3479                 :            : 
    3480                 :     334494 :       if (TYPE_HAS_COPY_CTOR (type)
    3481                 :     334494 :           && !TYPE_HAS_CONST_COPY_CTOR (type))
    3482                 :         91 :         *cant_have_const_ctor = 1;
    3483                 :            : 
    3484                 :     334494 :       if (TYPE_HAS_COPY_ASSIGN (type)
    3485                 :     334494 :           && !TYPE_HAS_CONST_COPY_ASSIGN (type))
    3486                 :         47 :         *no_const_asn_ref = 1;
    3487                 :            :     }
    3488                 :            : 
    3489                 :    2352770 :   check_abi_tags (t, field);
    3490                 :            : 
    3491                 :    2352770 :   if (DECL_INITIAL (field) != NULL_TREE)
    3492                 :            :     /* `build_class_init_list' does not recognize
    3493                 :            :        non-FIELD_DECLs.  */
    3494                 :      20212 :     any_default_members = true;
    3495                 :            : 
    3496                 :    2352770 :   return any_default_members;
    3497                 :            : }
    3498                 :            : 
    3499                 :            : /* Check the data members (both static and non-static), class-scoped
    3500                 :            :    typedefs, etc., appearing in the declaration of T.  Issue
    3501                 :            :    appropriate diagnostics.  Sets ACCESS_DECLS to a list (in
    3502                 :            :    declaration order) of access declarations; each TREE_VALUE in this
    3503                 :            :    list is a USING_DECL.
    3504                 :            : 
    3505                 :            :    In addition, set the following flags:
    3506                 :            : 
    3507                 :            :      EMPTY_P
    3508                 :            :        The class is empty, i.e., contains no non-static data members.
    3509                 :            : 
    3510                 :            :      CANT_HAVE_CONST_CTOR_P
    3511                 :            :        This class cannot have an implicitly generated copy constructor
    3512                 :            :        taking a const reference.
    3513                 :            : 
    3514                 :            :      CANT_HAVE_CONST_ASN_REF
    3515                 :            :        This class cannot have an implicitly generated assignment
    3516                 :            :        operator taking a const reference.
    3517                 :            : 
    3518                 :            :    All of these flags should be initialized before calling this
    3519                 :            :    function.   */
    3520                 :            : 
    3521                 :            : static void
    3522                 :   11678000 : check_field_decls (tree t, tree *access_decls,
    3523                 :            :                    int *cant_have_const_ctor_p,
    3524                 :            :                    int *no_const_asn_ref_p)
    3525                 :            : {
    3526                 :   11678000 :   int cant_pack = 0;
    3527                 :            : 
    3528                 :            :   /* Assume there are no access declarations.  */
    3529                 :   11678000 :   *access_decls = NULL_TREE;
    3530                 :            :   /* Effective C has things to say about classes with pointer members.  */
    3531                 :   11678000 :   tree pointer_member = NULL_TREE;
    3532                 :            :   /* Default initialized members affect the whole class.  */
    3533                 :   11678000 :   tree default_init_member = NULL_TREE;
    3534                 :            :   /* Lack of any non-static data member of non-volatile literal
    3535                 :            :      type affects a union.  */
    3536                 :   11678000 :   bool found_nv_literal_p = false;
    3537                 :            :   /* Standard layout requires all FIELDS have same access.  */
    3538                 :   11678000 :   int field_access = -1;
    3539                 :            : 
    3540                 :   47350000 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    3541                 :            :     {
    3542                 :   35572200 :       tree type = TREE_TYPE (field);
    3543                 :            : 
    3544                 :   35572200 :       switch (TREE_CODE (field))
    3545                 :            :         {
    3546                 :          0 :         default:
    3547                 :          0 :           gcc_unreachable ();
    3548                 :            : 
    3549                 :     111633 :         case USING_DECL:
    3550                 :            :           /* Save the access declarations for our caller.  */
    3551                 :     111633 :           *access_decls = tree_cons (NULL_TREE, field, *access_decls);
    3552                 :     111633 :           break;
    3553                 :            : 
    3554                 :            :         case TYPE_DECL:
    3555                 :            :         case TEMPLATE_DECL:
    3556                 :            :           break;
    3557                 :            : 
    3558                 :            :         case FUNCTION_DECL:
    3559                 :            :           /* FIXME: We should fold in the checking from check_methods.  */
    3560                 :            :           break;
    3561                 :            : 
    3562                 :     239802 :         case CONST_DECL:
    3563                 :     239802 :           DECL_NONLOCAL (field) = 1;
    3564                 :     239802 :           break;
    3565                 :            :           
    3566                 :    1181310 :         case VAR_DECL:
    3567                 :    1181310 :           if (TREE_CODE (t) == UNION_TYPE
    3568                 :         28 :               && cxx_dialect < cxx11)
    3569                 :            :             {
    3570                 :            :               /* [class.union]
    3571                 :            : 
    3572                 :            :                  (C++98) If a union contains a static data member,
    3573                 :            :                  ... the program is ill-formed.  */
    3574                 :          1 :               if (cxx_dialect < cxx11)
    3575                 :          1 :                 error ("in C++98 %q+D may not be static because it is "
    3576                 :            :                        "a member of a union", field);
    3577                 :            :             }
    3578                 :    1181310 :           goto data_member;
    3579                 :            :           
    3580                 :    2306200 :         case FIELD_DECL:
    3581                 :    2306200 :           if (TREE_CODE (t) == UNION_TYPE)
    3582                 :            :             {
    3583                 :            :               /* [class.union]
    3584                 :            : 
    3585                 :            :                  If a union contains ... or a [non-static data] member
    3586                 :            :                  of reference type, the program is ill-formed.  */
    3587                 :     219223 :               if (TYPE_REF_P (type))
    3588                 :         30 :                 error ("non-static data member %q+D in a union may not "
    3589                 :            :                        "have reference type %qT", field, type);
    3590                 :            :             }
    3591                 :            : 
    3592                 :    2086970 :         data_member:
    3593                 :            :           /* Common VAR_DECL & FIELD_DECL processing.  */
    3594                 :    3487510 :           DECL_CONTEXT (field) = t;
    3595                 :    3487510 :           DECL_NONLOCAL (field) = 1;
    3596                 :            : 
    3597                 :            :           /* Template instantiation can cause this.  Perhaps this
    3598                 :            :              should be a specific instantiation check?  */
    3599                 :    3487510 :           if (TREE_CODE (type) == FUNCTION_TYPE)
    3600                 :            :             {
    3601                 :          4 :               error ("data member %q+D invalidly declared function type", field);
    3602                 :          4 :               type = build_pointer_type (type);
    3603                 :          4 :               TREE_TYPE (field) = type;
    3604                 :            :             }
    3605                 :    3487510 :           else if (TREE_CODE (type) == METHOD_TYPE)
    3606                 :            :             {
    3607                 :          0 :               error ("data member %q+D invalidly declared method type", field);
    3608                 :          0 :               type = build_pointer_type (type);
    3609                 :          0 :               TREE_TYPE (field) = type;
    3610                 :            :             }
    3611                 :            : 
    3612                 :            :           break;
    3613                 :            :         }
    3614                 :            : 
    3615                 :   35572200 :       if (TREE_CODE (field) != FIELD_DECL)
    3616                 :   33266000 :         continue;
    3617                 :            : 
    3618                 :    2306200 :       if (type == error_mark_node)
    3619                 :        195 :         continue;
    3620                 :            : 
    3621                 :            :       /* If it is not a union and at least one non-static data member is
    3622                 :            :          non-literal, the whole class becomes non-literal.  Per Core/1453,
    3623                 :            :          volatile non-static data members and base classes are also not allowed.
    3624                 :            :          If it is a union, we might set CLASSTYPE_LITERAL_P after we've seen all
    3625                 :            :          members.
    3626                 :            :          Note: if the type is incomplete we will complain later on.  */
    3627                 :    2306000 :       if (COMPLETE_TYPE_P (type))
    3628                 :            :         {
    3629                 :    2304810 :           if (!literal_type_p (type) || CP_TYPE_VOLATILE_P (type))
    3630                 :     124876 :             CLASSTYPE_LITERAL_P (t) = false;
    3631                 :            :           else
    3632                 :            :             found_nv_literal_p = true;
    3633                 :            :         }
    3634                 :            : 
    3635                 :    6753910 :       int this_field_access = (TREE_PROTECTED (field) ? 1
    3636                 :    2306000 :                                : TREE_PRIVATE (field) ? 2 : 0);
    3637                 :    2306000 :       if (field_access != this_field_access)
    3638                 :            :         {
    3639                 :            :           /* A standard-layout class is a class that:
    3640                 :            : 
    3641                 :            :              ... has the same access control (Clause 11) for all
    3642                 :            :              non-static data members, */
    3643                 :     850064 :           if (field_access < 0)
    3644                 :            :             field_access = this_field_access;
    3645                 :            :           else
    3646                 :       1456 :             CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3647                 :            : 
    3648                 :            :           /* Aggregates must be public.  */
    3649                 :     850064 :           if (this_field_access)
    3650                 :     260178 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    3651                 :            :         }
    3652                 :            : 
    3653                 :            :       /* If this is of reference type, check if it needs an init.  */
    3654                 :    2306000 :       if (TYPE_REF_P (type))
    3655                 :            :         {
    3656                 :      61636 :           CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3657                 :      61636 :           CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3658                 :      61636 :           if (DECL_INITIAL (field) == NULL_TREE)
    3659                 :      61590 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    3660                 :      61636 :           if (cxx_dialect < cxx11)
    3661                 :            :             {
    3662                 :            :               /* ARM $12.6.2: [A member initializer list] (or, for an
    3663                 :            :                  aggregate, initialization by a brace-enclosed list) is the
    3664                 :            :                  only way to initialize nonstatic const and reference
    3665                 :            :                  members.  */
    3666                 :        499 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    3667                 :        499 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    3668                 :            :             }
    3669                 :            :         }
    3670                 :            : 
    3671                 :    2306000 :       type = strip_array_types (type);
    3672                 :            : 
    3673                 :    2306000 :       if (TYPE_PACKED (t))
    3674                 :            :         {
    3675                 :       1197 :           if (!layout_pod_type_p (type) && !TYPE_PACKED (type))
    3676                 :            :             {
    3677                 :         24 :               warning_at (DECL_SOURCE_LOCATION (field), 0,
    3678                 :            :                           "ignoring packed attribute because of"
    3679                 :            :                           " unpacked non-POD field %q#D", field);
    3680                 :         24 :               cant_pack = 1;
    3681                 :            :             }
    3682                 :       1137 :           else if (DECL_C_BIT_FIELD (field)
    3683                 :       2204 :                    || TYPE_ALIGN (TREE_TYPE (field)) > BITS_PER_UNIT)
    3684                 :        902 :             DECL_PACKED (field) = 1;
    3685                 :            :         }
    3686                 :            : 
    3687                 :    2306000 :       if (DECL_C_BIT_FIELD (field)
    3688                 :    2306000 :           && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (field)))
    3689                 :            :         /* We don't treat zero-width bitfields as making a class
    3690                 :            :            non-empty.  */
    3691                 :            :         ;
    3692                 :    2305420 :       else if (field_poverlapping_p (field) && is_empty_class (type))
    3693                 :            :         /* Empty data members also don't make a class non-empty.  */
    3694                 :       3936 :         CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    3695                 :            :       else
    3696                 :            :         {
    3697                 :            :           /* The class is non-empty.  */
    3698                 :    2301480 :           CLASSTYPE_EMPTY_P (t) = 0;
    3699                 :            :           /* The class is not even nearly empty.  */
    3700                 :    2301480 :           CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    3701                 :            :           /* If one of the data members contains an empty class, so
    3702                 :            :              does T.  */
    3703                 :     345658 :           if (CLASS_TYPE_P (type)
    3704                 :    2645720 :               && CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    3705                 :     127009 :             CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    3706                 :            :         }
    3707                 :            : 
    3708                 :            :       /* This is used by -Weffc++ (see below). Warn only for pointers
    3709                 :            :          to members which might hold dynamic memory. So do not warn
    3710                 :            :          for pointers to functions or pointers to members.  */
    3711                 :    2306000 :       if (TYPE_PTR_P (type)
    3712                 :    2832370 :           && !TYPE_PTRFN_P (type))
    3713                 :            :         pointer_member = field;
    3714                 :            : 
    3715                 :    2655600 :       if (CLASS_TYPE_P (type))
    3716                 :            :         {
    3717                 :     348178 :           if (CLASSTYPE_REF_FIELDS_NEED_INIT (type))
    3718                 :       2141 :             SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
    3719                 :     348178 :           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
    3720                 :       1373 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    3721                 :            :         }
    3722                 :            : 
    3723                 :    2306000 :       if (DECL_MUTABLE_P (field) || TYPE_HAS_MUTABLE_P (type))
    3724                 :      18413 :         CLASSTYPE_HAS_MUTABLE (t) = 1;
    3725                 :            : 
    3726                 :    2306000 :       if (DECL_MUTABLE_P (field))
    3727                 :            :         {
    3728                 :      13827 :           if (TYPE_REF_P (type))
    3729                 :          4 :             error ("member %q+D cannot be declared as a %<mutable%> "
    3730                 :            :                    "reference", field);
    3731                 :      13823 :           else if (CP_TYPE_CONST_P (type))
    3732                 :          4 :             error ("member %q+D cannot be declared both %<const%> "
    3733                 :            :                    "and %<mutable%>", field);
    3734                 :            :         }
    3735                 :            : 
    3736                 :    2306000 :       if (! layout_pod_type_p (type))
    3737                 :            :         /* DR 148 now allows pointers to members (which are POD themselves),
    3738                 :            :            to be allowed in POD structs.  */
    3739                 :     211687 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3740                 :            : 
    3741                 :    2306000 :       if (field_poverlapping_p (field))
    3742                 :            :         /* A potentially-overlapping non-static data member makes the class
    3743                 :            :            non-layout-POD.  */
    3744                 :       4510 :         CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
    3745                 :            : 
    3746                 :    2306000 :       if (!std_layout_type_p (type))
    3747                 :      73670 :         CLASSTYPE_NON_STD_LAYOUT (t) = 1;
    3748                 :            : 
    3749                 :    2306000 :       if (! zero_init_p (type))
    3750                 :        113 :         CLASSTYPE_NON_ZERO_INIT_P (t) = 1;
    3751                 :            : 
    3752                 :            :       /* We set DECL_C_BIT_FIELD in grokbitfield.
    3753                 :            :          If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
    3754                 :    2306000 :       if (DECL_C_BIT_FIELD (field))
    3755                 :      45768 :         check_bitfield_decl (field);
    3756                 :            : 
    3757                 :    2306000 :       if (check_field_decl (field, t,
    3758                 :            :                             cant_have_const_ctor_p, no_const_asn_ref_p))
    3759                 :            :         {
    3760                 :      20191 :           if (default_init_member
    3761                 :       9072 :               && TREE_CODE (t) == UNION_TYPE)
    3762                 :            :             {
    3763                 :         12 :               error ("multiple fields in union %qT initialized", t);
    3764                 :         12 :               inform (DECL_SOURCE_LOCATION (default_init_member),
    3765                 :            :                       "initialized member %q+D declared here",
    3766                 :            :                       default_init_member);
    3767                 :            :             }
    3768                 :            :           default_init_member = field;
    3769                 :            :         }
    3770                 :            : 
    3771                 :            :       /* Now that we've removed bit-field widths from DECL_INITIAL,
    3772                 :            :          anything left in DECL_INITIAL is an NSDMI that makes the class
    3773                 :            :          non-aggregate in C++11.  */
    3774                 :    2306000 :       if (DECL_INITIAL (field) && cxx_dialect < cxx14)
    3775                 :       1953 :         CLASSTYPE_NON_AGGREGATE (t) = true;
    3776                 :            : 
    3777                 :    2306000 :       if (CP_TYPE_CONST_P (type))
    3778                 :            :         {
    3779                 :            :           /* If any field is const, the structure type is pseudo-const.  */
    3780                 :      12107 :           C_TYPE_FIELDS_READONLY (t) = 1;
    3781                 :      12107 :           if (DECL_INITIAL (field) == NULL_TREE)
    3782                 :      11770 :             SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t, 1);
    3783                 :      12107 :           if (cxx_dialect < cxx11)
    3784                 :            :             {
    3785                 :            :               /* ARM $12.6.2: [A member initializer list] (or, for an
    3786                 :            :                  aggregate, initialization by a brace-enclosed list) is the
    3787                 :            :                  only way to initialize nonstatic const and reference
    3788                 :            :                  members.  */
    3789                 :        216 :               TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = 1;
    3790                 :        216 :               TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = 1;
    3791                 :            :             }
    3792                 :            :         }
    3793                 :            :       /* A field that is pseudo-const makes the structure likewise.  */
    3794                 :    2642380 :       else if (CLASS_TYPE_P (type))
    3795                 :            :         {
    3796                 :     347072 :           C_TYPE_FIELDS_READONLY (t) |= C_TYPE_FIELDS_READONLY (type);
    3797                 :     694144 :           SET_CLASSTYPE_READONLY_FIELDS_NEED_INIT (t,
    3798                 :            :             CLASSTYPE_READONLY_FIELDS_NEED_INIT (t)
    3799                 :            :             | CLASSTYPE_READONLY_FIELDS_NEED_INIT (type));
    3800                 :            :         }
    3801                 :            : 
    3802                 :            :       /* Core issue 80: A nonstatic data member is required to have a
    3803                 :            :          different name from the class iff the class has a
    3804                 :            :          user-declared constructor.  */
    3805                 :    2306000 :       if (constructor_name_p (DECL_NAME (field), t)
    3806                 :    2306060 :           && TYPE_HAS_USER_CONSTRUCTOR (t))
    3807                 :         16 :         permerror (DECL_SOURCE_LOCATION (field),
    3808                 :            :                    "field %q#D with same name as class", field);
    3809                 :            :     }
    3810                 :            : 
    3811                 :            :   /* Per CWG 2096, a type is a literal type if it is a union, and at least
    3812                 :            :      one of its non-static data members is of non-volatile literal type.  */
    3813                 :   11678000 :   if (TREE_CODE (t) == UNION_TYPE && found_nv_literal_p)
    3814                 :      98385 :     CLASSTYPE_LITERAL_P (t) = true;
    3815                 :            : 
    3816                 :            :   /* Effective C++ rule 11: if a class has dynamic memory held by pointers,
    3817                 :            :      it should also define a copy constructor and an assignment operator to
    3818                 :            :      implement the correct copy semantic (deep vs shallow, etc.). As it is
    3819                 :            :      not feasible to check whether the constructors do allocate dynamic memory
    3820                 :            :      and store it within members, we approximate the warning like this:
    3821                 :            : 
    3822                 :            :      -- Warn only if there are members which are pointers
    3823                 :            :      -- Warn only if there is a non-trivial constructor (otherwise,
    3824                 :            :         there cannot be memory allocated).
    3825                 :            :      -- Warn only if there is a non-trivial destructor. We assume that the
    3826                 :            :         user at least implemented the cleanup correctly, and a destructor
    3827                 :            :         is needed to free dynamic memory.
    3828                 :            : 
    3829                 :            :      This seems enough for practical purposes.  */
    3830                 :   11678000 :   if (warn_ecpp
    3831                 :        180 :       && pointer_member
    3832                 :         20 :       && TYPE_HAS_USER_CONSTRUCTOR (t)
    3833                 :         20 :       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    3834                 :   11678000 :       && !(TYPE_HAS_COPY_CTOR (t) && TYPE_HAS_COPY_ASSIGN (t)))
    3835                 :            :     {
    3836                 :         12 :       if (warning (OPT_Weffc__, "%q#T has pointer data members", t))
    3837                 :            :         {
    3838                 :         12 :           if (! TYPE_HAS_COPY_CTOR (t))
    3839                 :            :             {
    3840                 :          8 :               warning (OPT_Weffc__,
    3841                 :            :                        "  but does not override %<%T(const %T&)%>", t, t);
    3842                 :          8 :               if (!TYPE_HAS_COPY_ASSIGN (t))
    3843                 :          4 :                 warning (OPT_Weffc__, "  or %<operator=(const %T&)%>", t);
    3844                 :            :             }
    3845                 :          4 :           else if (! TYPE_HAS_COPY_ASSIGN (t))
    3846                 :          4 :             warning (OPT_Weffc__,
    3847                 :            :                      "  but does not override %<operator=(const %T&)%>", t);
    3848                 :         12 :           inform (DECL_SOURCE_LOCATION (pointer_member),
    3849                 :            :                   "pointer member %q+D declared here", pointer_member);
    3850                 :            :         }
    3851                 :            :     }
    3852                 :            : 
    3853                 :            :   /* Non-static data member initializers make the default constructor
    3854                 :            :      non-trivial.  */
    3855                 :   11678000 :   if (default_init_member)
    3856                 :            :     {
    3857                 :      11119 :       TYPE_NEEDS_CONSTRUCTING (t) = true;
    3858                 :      11119 :       TYPE_HAS_COMPLEX_DFLT (t) = true;
    3859                 :            :     }
    3860                 :            : 
    3861                 :            :   /* If any of the fields couldn't be packed, unset TYPE_PACKED.  */
    3862                 :   11678000 :   if (cant_pack)
    3863                 :         16 :     TYPE_PACKED (t) = 0;
    3864                 :            : 
    3865                 :            :   /* Check anonymous struct/anonymous union fields.  */
    3866                 :   11678000 :   finish_struct_anon (t);
    3867                 :            : 
    3868                 :            :   /* We've built up the list of access declarations in reverse order.
    3869                 :            :      Fix that now.  */
    3870                 :   11678000 :   *access_decls = nreverse (*access_decls);
    3871                 :   11678000 : }
    3872                 :            : 
    3873                 :            : /* If TYPE is an empty class type, records its OFFSET in the table of
    3874                 :            :    OFFSETS.  */
    3875                 :            : 
    3876                 :            : static int
    3877                 :   11394200 : record_subobject_offset (tree type, tree offset, splay_tree offsets)
    3878                 :            : {
    3879                 :   11394200 :   splay_tree_node n;
    3880                 :            : 
    3881                 :   11394200 :   if (!is_empty_class (type))
    3882                 :            :     return 0;
    3883                 :            : 
    3884                 :            :   /* Record the location of this empty object in OFFSETS.  */
    3885                 :   11021800 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    3886                 :   11021800 :   if (!n)
    3887                 :    6351390 :     n = splay_tree_insert (offsets,
    3888                 :            :                            (splay_tree_key) offset,
    3889                 :            :                            (splay_tree_value) NULL_TREE);
    3890                 :   22043500 :   n->value = ((splay_tree_value)
    3891                 :   11021800 :               tree_cons (NULL_TREE,
    3892                 :            :                          type,
    3893                 :   11021800 :                          (tree) n->value));
    3894                 :            : 
    3895                 :   11021800 :   return 0;
    3896                 :            : }
    3897                 :            : 
    3898                 :            : /* Returns nonzero if TYPE is an empty class type and there is
    3899                 :            :    already an entry in OFFSETS for the same TYPE as the same OFFSET.  */
    3900                 :            : 
    3901                 :            : static int
    3902                 :     129978 : check_subobject_offset (tree type, tree offset, splay_tree offsets)
    3903                 :            : {
    3904                 :     129978 :   splay_tree_node n;
    3905                 :     129978 :   tree t;
    3906                 :            : 
    3907                 :     129978 :   if (!is_empty_class (type))
    3908                 :            :     return 0;
    3909                 :            : 
    3910                 :            :   /* Record the location of this empty object in OFFSETS.  */
    3911                 :      81513 :   n = splay_tree_lookup (offsets, (splay_tree_key) offset);
    3912                 :      81513 :   if (!n)
    3913                 :            :     return 0;
    3914                 :            : 
    3915                 :     491661 :   for (t = (tree) n->value; t; t = TREE_CHAIN (t))
    3916                 :     411823 :     if (same_type_p (TREE_VALUE (t), type))
    3917                 :            :       return 1;
    3918                 :            : 
    3919                 :            :   return 0;
    3920                 :            : }
    3921                 :            : 
    3922                 :            : /* Walk through all the subobjects of TYPE (located at OFFSET).  Call
    3923                 :            :    F for every subobject, passing it the type, offset, and table of
    3924                 :            :    OFFSETS.  If VBASES_P is one, then virtual non-primary bases should
    3925                 :            :    be traversed.
    3926                 :            : 
    3927                 :            :    If MAX_OFFSET is non-NULL, then subobjects with an offset greater
    3928                 :            :    than MAX_OFFSET will not be walked.
    3929                 :            : 
    3930                 :            :    If F returns a nonzero value, the traversal ceases, and that value
    3931                 :            :    is returned.  Otherwise, returns zero.  */
    3932                 :            : 
    3933                 :            : static int
    3934                 :   14261200 : walk_subobject_offsets (tree type,
    3935                 :            :                         subobject_offset_fn f,
    3936                 :            :                         tree offset,
    3937                 :            :                         splay_tree offsets,
    3938                 :            :                         tree max_offset,
    3939                 :            :                         int vbases_p)
    3940                 :            : {
    3941                 :   14261200 :   int r = 0;
    3942                 :   14261200 :   tree type_binfo = NULL_TREE;
    3943                 :            : 
    3944                 :            :   /* If this OFFSET is bigger than the MAX_OFFSET, then we should
    3945                 :            :      stop.  */
    3946                 :   14261200 :   if (max_offset && tree_int_cst_lt (max_offset, offset))
    3947                 :            :     return 0;
    3948                 :            : 
    3949                 :   12653400 :   if (type == error_mark_node)
    3950                 :            :     return 0;
    3951                 :            : 
    3952                 :   12653400 :   if (!TYPE_P (type))
    3953                 :            :     {
    3954                 :    4682950 :       type_binfo = type;
    3955                 :    4682950 :       type = BINFO_TYPE (type);
    3956                 :            :     }
    3957                 :            : 
    3958                 :   24416400 :   if (CLASS_TYPE_P (type))
    3959                 :            :     {
    3960                 :   11761700 :       tree field;
    3961                 :   11761700 :       tree binfo;
    3962                 :   11761700 :       int i;
    3963                 :            : 
    3964                 :            :       /* Avoid recursing into objects that are not interesting.  */
    3965                 :   11761700 :       if (!CLASSTYPE_CONTAINS_EMPTY_CLASS_P (type))
    3966                 :            :         return 0;
    3967                 :            : 
    3968                 :            :       /* Record the location of TYPE.  */
    3969                 :   11524700 :       r = (*f) (type, offset, offsets);
    3970                 :   11524700 :       if (r)
    3971                 :            :         return r;
    3972                 :            : 
    3973                 :            :       /* Iterate through the direct base classes of TYPE.  */
    3974                 :   11523100 :       if (!type_binfo)
    3975                 :    7039620 :         type_binfo = TYPE_BINFO (type);
    3976                 :   16203700 :       for (i = 0; BINFO_BASE_ITERATE (type_binfo, i, binfo); i++)
    3977                 :            :         {
    3978                 :    4681930 :           tree binfo_offset;
    3979                 :            : 
    3980                 :    4681930 :           if (BINFO_VIRTUAL_P (binfo))
    3981                 :       1834 :             continue;
    3982                 :            : 
    3983                 :    4680090 :           tree orig_binfo;
    3984                 :            :           /* We cannot rely on BINFO_OFFSET being set for the base
    3985                 :            :              class yet, but the offsets for direct non-virtual
    3986                 :            :              bases can be calculated by going back to the TYPE.  */
    3987                 :    4680090 :           orig_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    3988                 :    4680090 :           binfo_offset = size_binop (PLUS_EXPR,
    3989                 :            :                                      offset,
    3990                 :            :                                      BINFO_OFFSET (orig_binfo));
    3991                 :            : 
    3992                 :    4680090 :           r = walk_subobject_offsets (binfo,
    3993                 :            :                                       f,
    3994                 :            :                                       binfo_offset,
    3995                 :            :                                       offsets,
    3996                 :            :                                       max_offset,
    3997                 :            :                                       /*vbases_p=*/0);
    3998                 :    4680090 :           if (r)
    3999                 :       1275 :             return r;
    4000                 :            :         }
    4001                 :            : 
    4002                 :   11521800 :       if (CLASSTYPE_VBASECLASSES (type))
    4003                 :            :         {
    4004                 :       1459 :           unsigned ix;
    4005                 :       1459 :           vec<tree, va_gc> *vbases;
    4006                 :            : 
    4007                 :            :           /* Iterate through the virtual base classes of TYPE.  In G++
    4008                 :            :              3.2, we included virtual bases in the direct base class
    4009                 :            :              loop above, which results in incorrect results; the
    4010                 :            :              correct offsets for virtual bases are only known when
    4011                 :            :              working with the most derived type.  */
    4012                 :       1459 :           if (vbases_p)
    4013                 :         11 :             for (vbases = CLASSTYPE_VBASECLASSES (type), ix = 0;
    4014                 :         22 :                  vec_safe_iterate (vbases, ix, &binfo); ix++)
    4015                 :            :               {
    4016                 :         11 :                 r = walk_subobject_offsets (binfo,
    4017                 :            :                                             f,
    4018                 :         11 :                                             size_binop (PLUS_EXPR,
    4019                 :            :                                                         offset,
    4020                 :            :                                                         BINFO_OFFSET (binfo)),
    4021                 :            :                                             offsets,
    4022                 :            :                                             max_offset,
    4023                 :            :                                             /*vbases_p=*/0);
    4024                 :         11 :                 if (r)
    4025                 :          0 :                   return r;
    4026                 :            :               }
    4027                 :            :           else
    4028                 :            :             {
    4029                 :            :               /* We still have to walk the primary base, if it is
    4030                 :            :                  virtual.  (If it is non-virtual, then it was walked
    4031                 :            :                  above.)  */
    4032                 :       1448 :               tree vbase = get_primary_binfo (type_binfo);
    4033                 :            : 
    4034                 :        482 :               if (vbase && BINFO_VIRTUAL_P (vbase)
    4035                 :        273 :                   && BINFO_PRIMARY_P (vbase)
    4036                 :       1721 :                   && BINFO_INHERITANCE_CHAIN (vbase) == type_binfo)
    4037                 :            :                 {
    4038                 :        241 :                   r = (walk_subobject_offsets
    4039                 :        241 :                        (vbase, f, offset,
    4040                 :            :                         offsets, max_offset, /*vbases_p=*/0));
    4041                 :        241 :                   if (r)
    4042                 :            :                     return r;
    4043                 :            :                 }
    4044                 :            :             }
    4045                 :            :         }
    4046                 :            : 
    4047                 :            :       /* Iterate through the fields of TYPE.  */
    4048                 :  120012000 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    4049                 :  108326000 :         if (TREE_CODE (field) == FIELD_DECL
    4050                 :    2040510 :             && TREE_TYPE (field) != error_mark_node
    4051                 :  110366000 :             && !DECL_ARTIFICIAL (field))
    4052                 :            :           {
    4053                 :     604753 :             tree field_offset;
    4054                 :            : 
    4055                 :     604753 :             field_offset = byte_position (field);
    4056                 :            : 
    4057                 :     604753 :             r = walk_subobject_offsets (TREE_TYPE (field),
    4058                 :            :                                         f,
    4059                 :            :                                         size_binop (PLUS_EXPR,
    4060                 :            :                                                     offset,
    4061                 :            :                                                     field_offset),
    4062                 :            :                                         offsets,
    4063                 :            :                                         max_offset,
    4064                 :            :                                         /*vbases_p=*/1);
    4065                 :     604753 :             if (r)
    4066                 :         26 :               return r;
    4067                 :            :           }
    4068                 :            :     }
    4069                 :     891666 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    4070                 :            :     {
    4071                 :     180816 :       tree element_type = strip_array_types (type);
    4072                 :     180816 :       tree domain = TYPE_DOMAIN (type);
    4073                 :     180816 :       tree index;
    4074                 :            : 
    4075                 :            :       /* Avoid recursing into objects that are not interesting.  */
    4076                 :       5334 :       if (!CLASS_TYPE_P (element_type)
    4077                 :       5322 :           || !CLASSTYPE_CONTAINS_EMPTY_CLASS_P (element_type)
    4078                 :       1081 :           || !domain
    4079                 :     181877 :           || integer_minus_onep (TYPE_MAX_VALUE (domain)))
    4080                 :     179887 :         return 0;
    4081                 :            : 
    4082                 :            :       /* Step through each of the elements in the array.  */
    4083                 :        929 :       for (index = size_zero_node;
    4084                 :       2760 :            !tree_int_cst_lt (TYPE_MAX_VALUE (domain), index);
    4085                 :       1831 :            index = size_binop (PLUS_EXPR, index, size_one_node))
    4086                 :            :         {
    4087                 :       2447 :           r = walk_subobject_offsets (TREE_TYPE (type),
    4088                 :            :                                       f,
    4089                 :            :                                       offset,
    4090                 :            :                                       offsets,
    4091                 :            :                                       max_offset,
    4092                 :            :                                       /*vbases_p=*/1);
    4093                 :       2447 :           if (r)
    4094                 :          0 :             return r;
    4095                 :       2447 :           offset = size_binop (PLUS_EXPR, offset,
    4096                 :            :                                TYPE_SIZE_UNIT (TREE_TYPE (type)));
    4097                 :            :           /* If this new OFFSET is bigger than the MAX_OFFSET, then
    4098                 :            :              there's no point in iterating through the remaining
    4099                 :            :              elements of the array.  */
    4100                 :       2447 :           if (max_offset && tree_int_cst_lt (max_offset, offset))
    4101                 :            :             break;
    4102                 :            :         }
    4103                 :            :     }
    4104                 :            : 
    4105                 :            :   return 0;
    4106                 :            : }
    4107                 :            : 
    4108                 :            : /* Return true iff FIELD_DECL DECL is potentially overlapping.  */
    4109                 :            : 
    4110                 :            : static bool
    4111                 :   12451800 : field_poverlapping_p (tree decl)
    4112                 :            : {
    4113                 :            :   /* Base fields are actually potentially overlapping, but C++ bases go through
    4114                 :            :      a different code path based on binfos, and ObjC++ base fields are laid out
    4115                 :            :      in objc-act, so we don't want layout_class_type to mess with them.  */
    4116                 :   12451800 :   if (DECL_FIELD_IS_BASE (decl))
    4117                 :            :     {
    4118                 :          0 :       gcc_checking_assert (c_dialect_objc ());
    4119                 :            :       return false;
    4120                 :            :     }
    4121                 :            : 
    4122                 :   12451800 :   return lookup_attribute ("no_unique_address",
    4123                 :   12451800 :                            DECL_ATTRIBUTES (decl));
    4124                 :            : }
    4125                 :            : 
    4126                 :            : /* Record all of the empty subobjects of DECL_OR_BINFO.  */
    4127                 :            : 
    4128                 :            : static void
    4129                 :    8774770 : record_subobject_offsets (tree decl_or_binfo,
    4130                 :            :                           splay_tree offsets)
    4131                 :            : {
    4132                 :    8774770 :   tree type, offset;
    4133                 :    8774770 :   bool overlapping, vbases_p;
    4134                 :            : 
    4135                 :    8774770 :   if (DECL_P (decl_or_binfo))
    4136                 :            :     {
    4137                 :    2306000 :       tree decl = decl_or_binfo;
    4138                 :    2306000 :       type = TREE_TYPE (decl);
    4139                 :    2306000 :       offset = byte_position (decl);
    4140                 :    2306000 :       overlapping = field_poverlapping_p (decl);
    4141                 :    2306000 :       vbases_p = true;
    4142                 :            :     }
    4143                 :            :   else
    4144                 :            :     {
    4145                 :    6468770 :       type = BINFO_TYPE (decl_or_binfo);
    4146                 :    6468770 :       offset = BINFO_OFFSET (decl_or_binfo);
    4147                 :    6468770 :       overlapping = true;
    4148                 :    6468770 :       vbases_p = false;
    4149                 :            :     }
    4150                 :            : 
    4151                 :    8774770 :   tree max_offset;
    4152                 :            :   /* If recording subobjects for a non-static data member or a
    4153                 :            :      non-empty base class, we do not need to record offsets beyond
    4154                 :            :      the size of the biggest empty class.  Additional data members
    4155                 :            :      will go at the end of the class.  Additional base classes will go
    4156                 :            :      either at offset zero (if empty, in which case they cannot
    4157                 :            :      overlap with offsets past the size of the biggest empty class) or
    4158                 :            :      at the end of the class.
    4159                 :            : 
    4160                 :            :      However, if we are placing an empty base class, then we must record
    4161                 :            :      all offsets, as either the empty class is at offset zero (where
    4162                 :            :      other empty classes might later be placed) or at the end of the
    4163                 :            :      class (where other objects might then be placed, so other empty
    4164                 :            :      subobjects might later overlap).  */
    4165                 :    8774770 :   if (!overlapping
    4166                 :    8774770 :       || !is_empty_class (type))
    4167                 :    2504790 :     max_offset = sizeof_biggest_empty_class;
    4168                 :            :   else
    4169                 :            :     max_offset = NULL_TREE;
    4170                 :    8774770 :   walk_subobject_offsets (type, record_subobject_offset, offset,
    4171                 :            :                           offsets, max_offset, vbases_p);
    4172                 :    8774770 : }
    4173                 :            : 
    4174                 :            : /* Returns nonzero if any of the empty subobjects of TYPE (located at
    4175                 :            :    OFFSET) conflict with entries in OFFSETS.  If VBASES_P is nonzero,
    4176                 :            :    virtual bases of TYPE are examined.  */
    4177                 :            : 
    4178                 :            : static int
    4179                 :    8557590 : layout_conflict_p (tree type,
    4180                 :            :                    tree offset,
    4181                 :            :                    splay_tree offsets,
    4182                 :            :                    int vbases_p)
    4183                 :            : {
    4184                 :    8557590 :   splay_tree_node max_node;
    4185                 :            : 
    4186                 :            :   /* Get the node in OFFSETS that indicates the maximum offset where
    4187                 :            :      an empty subobject is located.  */
    4188                 :    8557590 :   max_node = splay_tree_max (offsets);
    4189                 :            :   /* If there aren't any empty subobjects, then there's no point in
    4190                 :            :      performing this check.  */
    4191                 :    8557590 :   if (!max_node)
    4192                 :            :     return 0;
    4193                 :            : 
    4194                 :     198511 :   return walk_subobject_offsets (type, check_subobject_offset, offset,
    4195                 :     198511 :                                  offsets, (tree) (max_node->key),
    4196                 :     198511 :                                  vbases_p);
    4197                 :            : }
    4198                 :            : 
    4199                 :            : /* DECL is a FIELD_DECL corresponding either to a base subobject of a
    4200                 :            :    non-static data member of the type indicated by RLI.  BINFO is the
    4201                 :            :    binfo corresponding to the base subobject, OFFSETS maps offsets to
    4202                 :            :    types already located at those offsets.  This function determines
    4203                 :            :    the position of the DECL.  */
    4204                 :            : 
    4205                 :            : static void
    4206                 :    2505240 : layout_nonempty_base_or_field (record_layout_info rli,
    4207                 :            :                                tree decl,
    4208                 :            :                                tree binfo,
    4209                 :            :                                splay_tree offsets)
    4210                 :            : {
    4211                 :    2505240 :   tree offset = NULL_TREE;
    4212                 :    2505240 :   bool field_p;
    4213                 :    2505240 :   tree type;
    4214                 :            : 
    4215                 :    2505240 :   if (binfo)
    4216                 :            :     {
    4217                 :            :       /* For the purposes of determining layout conflicts, we want to
    4218                 :            :          use the class type of BINFO; TREE_TYPE (DECL) will be the
    4219                 :            :          CLASSTYPE_AS_BASE version, which does not contain entries for
    4220                 :            :          zero-sized bases.  */
    4221                 :     202724 :       type = TREE_TYPE (binfo);
    4222                 :     202724 :       field_p = false;
    4223                 :            :     }
    4224                 :            :   else
    4225                 :            :     {
    4226                 :    2302520 :       type = TREE_TYPE (decl);
    4227                 :    2302520 :       field_p = true;
    4228                 :            :     }
    4229                 :            : 
    4230                 :            :   /* Try to place the field.  It may take more than one try if we have
    4231                 :            :      a hard time placing the field without putting two objects of the
    4232                 :            :      same type at the same address.  */
    4233                 :    2505570 :   while (1)
    4234                 :            :     {
    4235                 :    2505570 :       struct record_layout_info_s old_rli = *rli;
    4236                 :            : 
    4237                 :            :       /* Place this field.  */
    4238                 :    2505570 :       place_field (rli, decl);
    4239                 :    2505570 :       offset = byte_position (decl);
    4240                 :            : 
    4241                 :            :       /* We have to check to see whether or not there is already
    4242                 :            :          something of the same type at the offset we're about to use.
    4243                 :            :          For example, consider:
    4244                 :            : 
    4245                 :            :            struct S {};
    4246                 :            :            struct T : public S { int i; };
    4247                 :            :            struct U : public S, public T {};
    4248                 :            : 
    4249                 :            :          Here, we put S at offset zero in U.  Then, we can't put T at
    4250                 :            :          offset zero -- its S component would be at the same address
    4251                 :            :          as the S we already allocated.  So, we have to skip ahead.
    4252                 :            :          Since all data members, including those whose type is an
    4253                 :            :          empty class, have nonzero size, any overlap can happen only
    4254                 :            :          with a direct or indirect base-class -- it can't happen with
    4255                 :            :          a data member.  */
    4256                 :            :       /* In a union, overlap is permitted; all members are placed at
    4257                 :            :          offset zero.  */
    4258                 :    2505570 :       if (TREE_CODE (rli->t) == UNION_TYPE)
    4259                 :            :         break;
    4260                 :    2489140 :       if (layout_conflict_p (field_p ? type : binfo, offset,
    4261                 :            :                              offsets, field_p))
    4262                 :            :         {
    4263                 :            :           /* Strip off the size allocated to this field.  That puts us
    4264                 :            :              at the first place we could have put the field with
    4265                 :            :              proper alignment.  */
    4266                 :        330 :           *rli = old_rli;
    4267                 :            : 
    4268                 :            :           /* Bump up by the alignment required for the type.  */
    4269                 :        330 :           rli->bitpos
    4270                 :        660 :             = size_binop (PLUS_EXPR, rli->bitpos,
    4271                 :            :                           bitsize_int (binfo
    4272                 :            :                                        ? CLASSTYPE_ALIGN (type)
    4273                 :            :                                        : TYPE_ALIGN (type)));
    4274                 :        330 :           normalize_rli (rli);
    4275                 :            :         }
    4276                 :    2286010 :       else if (TREE_CODE (type) == NULLPTR_TYPE
    4277                 :       1953 :                && warn_abi && abi_version_crosses (9))
    4278                 :            :         {
    4279                 :            :           /* Before ABI v9, we were giving nullptr_t alignment of 1; if
    4280                 :            :              the offset wasn't aligned like a pointer when we started to
    4281                 :            :              layout this field, that affects its position.  */
    4282                 :        138 :           tree pos = rli_size_unit_so_far (&old_rli);
    4283                 :        138 :           if (int_cst_value (pos) % TYPE_ALIGN_UNIT (ptr_type_node) != 0)
    4284                 :            :             {
    4285                 :          3 :               if (abi_version_at_least (9))
    4286                 :          3 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi,
    4287                 :            :                             "alignment of %qD increased in %<-fabi-version=9%> "
    4288                 :            :                             "(GCC 5.2)", decl);
    4289                 :            :               else
    4290                 :          0 :                 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wabi, "alignment "
    4291                 :            :                             "of %qD will increase in %<-fabi-version=9%>",
    4292                 :            :                             decl);
    4293                 :            :             }
    4294                 :            :           break;
    4295                 :            :         }
    4296                 :            :       else
    4297                 :            :         /* There was no conflict.  We're done laying out this field.  */
    4298                 :            :         break;
    4299                 :            :     }
    4300                 :            : 
    4301                 :            :   /* Now that we know where it will be placed, update its
    4302                 :            :      BINFO_OFFSET.  */
    4303                 :    2707960 :   if (binfo && CLASS_TYPE_P (BINFO_TYPE (binfo)))
    4304                 :            :     /* Indirect virtual bases may have a nonzero BINFO_OFFSET at
    4305                 :            :        this point because their BINFO_OFFSET is copied from another
    4306                 :            :        hierarchy.  Therefore, we may not need to add the entire
    4307                 :            :        OFFSET.  */
    4308                 :     202724 :     propagate_binfo_offsets (binfo,
    4309                 :            :                              size_diffop_loc (input_location,
    4310                 :            :                                           fold_convert (ssizetype, offset),
    4311                 :     202724 :                                           fold_convert (ssizetype,
    4312                 :            :                                                    BINFO_OFFSET (binfo))));
    4313                 :    2505240 : }
    4314                 :            : 
    4315                 :            : /* Returns true if TYPE is empty and OFFSET is nonzero.  */
    4316                 :            : 
    4317                 :            : static int
    4318                 :        492 : empty_base_at_nonzero_offset_p (tree type,
    4319                 :            :                                 tree offset,
    4320                 :            :                                 splay_tree /*offsets*/)
    4321                 :            : {
    4322                 :        492 :   return is_empty_class (type) && !integer_zerop (offset);
    4323                 :            : }
    4324                 :            : 
    4325                 :            : /* Layout the empty base BINFO.  EOC indicates the byte currently just
    4326                 :            :    past the end of the class, and should be correctly aligned for a
    4327                 :            :    class of the type indicated by BINFO; OFFSETS gives the offsets of
    4328                 :            :    the empty bases allocated so far. T is the most derived
    4329                 :            :    type.  Return nonzero iff we added it at the end.  */
    4330                 :            : 
    4331                 :            : static bool
    4332                 :    6269980 : layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
    4333                 :            :                             splay_tree offsets)
    4334                 :            : {
    4335                 :    6269980 :   tree alignment;
    4336                 :    6269980 :   bool atend = false;
    4337                 :    6269980 :   tree binfo = NULL_TREE;
    4338                 :    6269980 :   tree decl = NULL_TREE;
    4339                 :    6269980 :   tree type;
    4340                 :    6269980 :   if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
    4341                 :            :     {
    4342                 :    6266050 :       binfo = binfo_or_decl;
    4343                 :    6266050 :       type = BINFO_TYPE (binfo);
    4344                 :            :     }
    4345                 :            :   else
    4346                 :            :     {
    4347                 :       3936 :       decl = binfo_or_decl;
    4348                 :       3936 :       type = TREE_TYPE (decl);
    4349                 :            :     }
    4350                 :            : 
    4351                 :            :   /* On some platforms (ARM), even empty classes will not be
    4352                 :            :      byte-aligned.  */
    4353                 :   12540000 :   tree eoc = round_up_loc (input_location,
    4354                 :            :                            rli_size_unit_so_far (rli),
    4355                 :    6269980 :                            CLASSTYPE_ALIGN_UNIT (type));
    4356                 :            : 
    4357                 :            :   /* This routine should only be used for empty classes.  */
    4358                 :    6269980 :   gcc_assert (is_empty_class (type));
    4359                 :    6269980 :   alignment = size_int (CLASSTYPE_ALIGN_UNIT (type));
    4360                 :            : 
    4361                 :            :   /* This is an empty base class.  We first try to put it at offset
    4362                 :            :      zero.  */
    4363                 :    6269980 :   tree offset = size_zero_node;
    4364                 :    6269980 :   if (layout_conflict_p (type,
    4365                 :            :                          offset,
    4366                 :            :                          offsets,
    4367                 :            :                          /*vbases_p=*/0))
    4368                 :            :     {
    4369                 :            :       /* That didn't work.  Now, we move forward from the next
    4370                 :            :          available spot in the class.  */
    4371                 :       1267 :       atend = true;
    4372                 :            :       offset = eoc;
    4373                 :       1833 :       while (1)
    4374                 :            :         {
    4375                 :       1267 :           if (!layout_conflict_p (type,
    4376                 :            :                                   offset,
    4377                 :            :                                   offsets,
    4378                 :            :                                   /*vbases_p=*/0))
    4379                 :            :             /* We finally found a spot where there's no overlap.  */
    4380                 :            :             break;
    4381                 :            : 
    4382                 :            :           /* There's overlap here, too.  Bump along to the next spot.  */
    4383                 :        566 :           offset = size_binop (PLUS_EXPR, offset, alignment);
    4384                 :            :         }
    4385                 :            :     }
    4386                 :            : 
    4387                 :    6269980 :   if (CLASSTYPE_USER_ALIGN (type))
    4388                 :            :     {
    4389                 :         16 :       rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type));
    4390                 :         16 :       if (warn_packed)
    4391                 :          0 :         rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type));
    4392                 :         16 :       TYPE_USER_ALIGN (rli->t) = 1;
    4393                 :            :     }
    4394                 :            : 
    4395                 :    6269980 :   if (binfo)
    4396                 :            :     /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET.  */
    4397                 :   12532100 :     propagate_binfo_offsets (binfo,
    4398                 :    6266050 :                              size_diffop (offset, BINFO_OFFSET (binfo)));
    4399                 :            :   else
    4400                 :            :     {
    4401                 :       3936 :       DECL_FIELD_OFFSET (decl) = offset;
    4402                 :       3936 :       DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4403                 :       3936 :       SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4404                 :            :     }
    4405                 :            : 
    4406                 :    6269980 :   return atend;
    4407                 :            : }
    4408                 :            : 
    4409                 :            : /* Build the FIELD_DECL for BASETYPE as a base of T, add it to the chain of
    4410                 :            :    fields at NEXT_FIELD, and return it.  */
    4411                 :            : 
    4412                 :            : static tree
    4413                 :    2286530 : build_base_field_1 (tree t, tree binfo, tree access, tree *&next_field)
    4414                 :            : {
    4415                 :            :   /* Create the FIELD_DECL.  */
    4416                 :    2286530 :   tree basetype = BINFO_TYPE (binfo);
    4417                 :    2286530 :   gcc_assert (CLASSTYPE_AS_BASE (basetype));
    4418                 :    2286530 :   tree decl = build_decl (input_location,
    4419                 :    2286530 :                           FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
    4420                 :    2286530 :   DECL_ARTIFICIAL (decl) = 1;
    4421                 :    2286530 :   DECL_IGNORED_P (decl) = 1;
    4422                 :    2286530 :   DECL_FIELD_CONTEXT (decl) = t;
    4423                 :    2286530 :   if (is_empty_class (basetype))
    4424                 :            :     /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero.  */
    4425                 :    2083810 :     DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
    4426                 :            :   else
    4427                 :            :     {
    4428                 :     202724 :       DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
    4429                 :     202724 :       DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
    4430                 :            :     }
    4431                 :    2286530 :   SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
    4432                 :    2286530 :   DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
    4433                 :    2286530 :   SET_DECL_MODE (decl, TYPE_MODE (basetype));
    4434                 :    2286530 :   DECL_FIELD_IS_BASE (decl) = 1;
    4435                 :            : 
    4436                 :    2286530 :   if (access == access_private_node)
    4437                 :      51730 :     TREE_PRIVATE (decl) = true;
    4438                 :    2234800 :   else if (access == access_protected_node)
    4439                 :       2979 :     TREE_PROTECTED (decl) = true;
    4440                 :            : 
    4441                 :            :   /* Add the new FIELD_DECL to the list of fields for T.  */
    4442                 :    2286530 :   DECL_CHAIN (decl) = *next_field;
    4443                 :    2286530 :   *next_field = decl;
    4444                 :    2286530 :   next_field = &DECL_CHAIN (decl);
    4445                 :            : 
    4446                 :    2286530 :   return decl;
    4447                 :            : }
    4448                 :            : 
    4449                 :            : /* Layout the base given by BINFO in the class indicated by RLI.
    4450                 :            :    *BASE_ALIGN is a running maximum of the alignments of
    4451                 :            :    any base class.  OFFSETS gives the location of empty base
    4452                 :            :    subobjects.  T is the most derived type.  Return nonzero if the new
    4453                 :            :    object cannot be nearly-empty.  A new FIELD_DECL is inserted at
    4454                 :            :    *NEXT_FIELD, unless BINFO is for an empty base class.
    4455                 :            : 
    4456                 :            :    Returns the location at which the next field should be inserted.  */
    4457                 :            : 
    4458                 :            : static tree *
    4459                 :    6468770 : build_base_field (record_layout_info rli, tree binfo, tree access,
    4460                 :            :                   splay_tree offsets, tree *next_field)
    4461                 :            : {
    4462                 :    6468770 :   tree t = rli->t;
    4463                 :    6468770 :   tree basetype = BINFO_TYPE (binfo);
    4464                 :            : 
    4465                 :    6468770 :   if (!COMPLETE_TYPE_P (basetype))
    4466                 :            :     /* This error is now reported in xref_tag, thus giving better
    4467                 :            :        location information.  */
    4468                 :          0 :     return next_field;
    4469                 :            : 
    4470                 :            :   /* Place the base class.  */
    4471                 :    6468770 :   if (!is_empty_class (basetype))
    4472                 :            :     {
    4473                 :     202724 :       tree decl;
    4474                 :            : 
    4475                 :            :       /* The containing class is non-empty because it has a non-empty
    4476                 :            :          base class.  */
    4477                 :     202724 :       CLASSTYPE_EMPTY_P (t) = 0;
    4478                 :            : 
    4479                 :            :       /* Create the FIELD_DECL.  */
    4480                 :     202724 :       decl = build_base_field_1 (t, binfo, access, next_field);
    4481                 :            : 
    4482                 :            :       /* Try to place the field.  It may take more than one try if we
    4483                 :            :          have a hard time placing the field without putting two
    4484                 :            :          objects of the same type at the same address.  */
    4485                 :     202724 :       layout_nonempty_base_or_field (rli, decl, binfo, offsets);
    4486                 :            :     }
    4487                 :            :   else
    4488                 :            :     {
    4489                 :    6266050 :       bool atend = layout_empty_base_or_field (rli, binfo, offsets);
    4490                 :            :       /* A nearly-empty class "has no proper base class that is empty,
    4491                 :            :          not morally virtual, and at an offset other than zero."  */
    4492                 :   12529700 :       if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
    4493                 :            :         {
    4494                 :        456 :           if (atend)
    4495                 :         83 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4496                 :            :           /* The check above (used in G++ 3.2) is insufficient because
    4497                 :            :              an empty class placed at offset zero might itself have an
    4498                 :            :              empty base at a nonzero offset.  */
    4499                 :        373 :           else if (walk_subobject_offsets (basetype,
    4500                 :            :                                            empty_base_at_nonzero_offset_p,
    4501                 :            :                                            size_zero_node,
    4502                 :            :                                            /*offsets=*/NULL,
    4503                 :            :                                            /*max_offset=*/NULL_TREE,
    4504                 :            :                                            /*vbases_p=*/true))
    4505                 :          8 :             CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    4506                 :            :         }
    4507                 :            : 
    4508                 :            :       /* We used to not create a FIELD_DECL for empty base classes because of
    4509                 :            :          back end issues with overlapping FIELD_DECLs, but that doesn't seem to
    4510                 :            :          be a problem anymore.  We need them to handle initialization of C++17
    4511                 :            :          aggregate bases.  */
    4512                 :    8350660 :       if (cxx_dialect >= cxx17 && !BINFO_VIRTUAL_P (binfo))
    4513                 :            :         {
    4514                 :    2083810 :           tree decl = build_base_field_1 (t, binfo, access, next_field);
    4515                 :    2083810 :           DECL_FIELD_OFFSET (decl) = BINFO_OFFSET (binfo);
    4516                 :    2083810 :           DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
    4517                 :    2083810 :           SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
    4518                 :            :         }
    4519                 :            : 
    4520                 :            :       /* An empty virtual base causes a class to be non-empty
    4521                 :            :          -- but in that case we do not need to clear CLASSTYPE_EMPTY_P
    4522                 :            :          here because that was already done when the virtual table
    4523                 :            :          pointer was created.  */
    4524                 :            :     }
    4525                 :            : 
    4526                 :            :   /* Record the offsets of BINFO and its base subobjects.  */
    4527                 :    6468770 :   record_subobject_offsets (binfo, offsets);
    4528                 :            : 
    4529                 :    6468770 :   return next_field;
    4530                 :            : }
    4531                 :            : 
    4532                 :            : /* Layout all of the non-virtual base classes.  Record empty
    4533                 :            :    subobjects in OFFSETS.  T is the most derived type.  Return nonzero
    4534                 :            :    if the type cannot be nearly empty.  The fields created
    4535                 :            :    corresponding to the base classes will be inserted at
    4536                 :            :    *NEXT_FIELD.  */
    4537                 :            : 
    4538                 :            : static void
    4539                 :   11678000 : build_base_fields (record_layout_info rli,
    4540                 :            :                    splay_tree offsets, tree *next_field)
    4541                 :            : {
    4542                 :            :   /* Chain to hold all the new FIELD_DECLs which stand in for base class
    4543                 :            :      subobjects.  */
    4544                 :   11678000 :   tree t = rli->t;
    4545                 :   11678000 :   tree binfo = TYPE_BINFO (t);
    4546                 :   11678000 :   int n_baseclasses = BINFO_N_BASE_BINFOS (binfo);
    4547                 :            : 
    4548                 :            :   /* The primary base class is always allocated first.  */
    4549                 :   11678000 :   const tree primary_binfo = CLASSTYPE_PRIMARY_BINFO (t);
    4550                 :   11678000 :   if (primary_binfo)
    4551                 :            :     {
    4552                 :            :       /* We need to walk BINFO_BASE_BINFO to find the access of the primary
    4553                 :            :          base, if it is direct.  Indirect base fields are private.  */
    4554                 :     127598 :       tree primary_access = access_private_node;
    4555                 :     128711 :       for (int i = 0; i < n_baseclasses; ++i)
    4556                 :            :         {
    4557                 :     128648 :           tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    4558                 :     128648 :           if (base_binfo == primary_binfo)
    4559                 :            :             {
    4560                 :     127535 :               primary_access = BINFO_BASE_ACCESS (binfo, i);
    4561                 :     127535 :               break;
    4562                 :            :             }
    4563                 :            :         }
    4564                 :     127598 :       next_field = build_base_field (rli, primary_binfo,
    4565                 :            :                                      primary_access,
    4566                 :            :                                      offsets, next_field);
    4567                 :            :     }
    4568                 :            : 
    4569                 :            :   /* Now allocate the rest of the bases.  */
    4570                 :   18133300 :   for (int i = 0; i < n_baseclasses; ++i)
    4571                 :            :     {
    4572                 :    6455320 :       tree base_binfo = BINFO_BASE_BINFO (binfo, i);
    4573                 :            : 
    4574                 :            :       /* The primary base was already allocated above, so we don't
    4575                 :            :          need to allocate it again here.  */
    4576                 :    6455320 :       if (base_binfo == primary_binfo)
    4577                 :     127535 :        continue;
    4578                 :            : 
    4579                 :            :       /* Virtual bases are added at the end (a primary virtual base
    4580                 :            :          will have already been added).  */
    4581                 :    6327790 :       if (BINFO_VIRTUAL_P (base_binfo))
    4582                 :       7439 :         continue;
    4583                 :            : 
    4584                 :   12640700 :       next_field = build_base_field (rli, base_binfo,
    4585                 :    6320350 :                                      BINFO_BASE_ACCESS (binfo, i),
    4586                 :            :                                      offsets, next_field);
    4587                 :            :     }
    4588                 :   11678000 : }
    4589                 :            : 
    4590                 :            : /* Go through the TYPE_FIELDS of T issuing any appropriate
    4591                 :            :    diagnostics, figuring out which methods override which other
    4592                 :            :    methods, and so forth.  */
    4593                 :            : 
    4594                 :            : static void
    4595                 :   11678000 : check_methods (tree t)
    4596                 :            : {
    4597                 :   47350000 :   for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    4598                 :   35572200 :     if (DECL_DECLARES_FUNCTION_P (x))
    4599                 :            :       {
    4600                 :   11643000 :         check_for_override (x, t);
    4601                 :            : 
    4602                 :   23286000 :         if (DECL_PURE_VIRTUAL_P (x)
    4603                 :   11643000 :             && (TREE_CODE (x) != FUNCTION_DECL || ! DECL_VINDEX (x)))
    4604                 :          4 :           error ("initializer specified for non-virtual method %q+D", x);
    4605                 :            :         /* The name of the field is the original field name
    4606                 :            :            Save this in auxiliary field for later overloading.  */
    4607                 :   11643000 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_VINDEX (x))
    4608                 :            :           {
    4609                 :     516772 :             TYPE_POLYMORPHIC_P (t) = 1;
    4610                 :    1033540 :             if (DECL_PURE_VIRTUAL_P (x))
    4611                 :      53914 :               vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    4612                 :            :           }
    4613                 :            : 
    4614                 :   11643000 :         if (!DECL_VIRTUAL_P (x)
    4615                 :   11643000 :             && lookup_attribute ("transaction_safe_dynamic",
    4616                 :   11126200 :                                  DECL_ATTRIBUTES (x)))
    4617                 :          2 :           error_at (DECL_SOURCE_LOCATION (x),
    4618                 :            :                     "%<transaction_safe_dynamic%> may only be specified for "
    4619                 :            :                     "a virtual function");
    4620                 :            :       }
    4621                 :            : 
    4622                 :            :   /* Check whether the eligible special member functions (P0848) are
    4623                 :            :      user-provided.  add_method arranged that the CLASSTYPE_MEMBER_VEC only
    4624                 :            :      has the eligible ones; TYPE_FIELDS also contains ineligible overloads,
    4625                 :            :      which is why this needs to be separate from the loop above.  */
    4626                 :            : 
    4627                 :   11678000 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    4628                 :            :     {
    4629                 :     476047 :       if (TREE_CODE (dtor) == OVERLOAD)
    4630                 :            :         {
    4631                 :            :           /* P0848: At the end of the definition of a class, overload
    4632                 :            :              resolution is performed among the prospective destructors declared
    4633                 :            :              in that class with an empty argument list to select the destructor
    4634                 :            :              for the class, also known as the selected destructor. The program
    4635                 :            :              is ill-formed if overload resolution fails. */
    4636                 :          0 :           auto_diagnostic_group d;
    4637                 :          0 :           error_at (location_of (t), "destructor for %qT is ambiguous", t);
    4638                 :          0 :           print_candidates (dtor);
    4639                 :            :         }
    4640                 :     476047 :       else if (user_provided_p (dtor))
    4641                 :     439111 :         TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = true;
    4642                 :            :     }
    4643                 :            : 
    4644                 :   15967800 :   for (ovl_iterator i (CLASSTYPE_CONSTRUCTORS (t)); i; ++i)
    4645                 :            :     {
    4646                 :    2144890 :       tree fn = *i;
    4647                 :    2144890 :       if (!user_provided_p (fn))
    4648                 :            :         /* Might be trivial.  */;
    4649                 :    1886670 :       else if (copy_fn_p (fn))
    4650                 :     161014 :         TYPE_HAS_COMPLEX_COPY_CTOR (t) = true;
    4651                 :    1725660 :       else if (move_fn_p (fn))
    4652                 :      64458 :         TYPE_HAS_COMPLEX_MOVE_CTOR (t) = true;
    4653                 :            :     }
    4654                 :            : 
    4655                 :   12099700 :   for (ovl_iterator i (get_class_binding_direct (t, assign_op_identifier));
    4656                 :   12099700 :        i; ++i)
    4657                 :            :     {
    4658                 :     421671 :       tree fn = *i;
    4659                 :     421671 :       if (!user_provided_p (fn))
    4660                 :            :         /* Might be trivial.  */;
    4661                 :     237807 :       else if (copy_fn_p (fn))
    4662                 :      67822 :         TYPE_HAS_COMPLEX_COPY_ASSIGN (t) = true;
    4663                 :     169985 :       else if (move_fn_p (fn))
    4664                 :      49103 :         TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) = true;
    4665                 :            :     }
    4666                 :   11678000 : }
    4667                 :            : 
    4668                 :            : /* FN is a constructor or destructor.  Clone the declaration to create
    4669                 :            :    a specialized in-charge or not-in-charge version, as indicated by
    4670                 :            :    NAME.  */
    4671                 :            : 
    4672                 :            : static tree
    4673                 :   14252300 : build_clone (tree fn, tree name)
    4674                 :            : {
    4675                 :            :   /* Copy the function.  */
    4676                 :   14252300 :   tree clone = copy_decl (fn);
    4677                 :            :   /* Reset the function name.  */
    4678                 :   14252300 :   DECL_NAME (clone) = name;
    4679                 :            :   /* Remember where this function came from.  */
    4680                 :   14252300 :   DECL_ABSTRACT_ORIGIN (clone) = fn;
    4681                 :            : 
    4682                 :            :   /* Make it easy to find the CLONE given the FN.  Note the
    4683                 :            :      template_result of a template will be chained this way too.  */
    4684                 :   14252300 :   DECL_CHAIN (clone) = DECL_CHAIN (fn);
    4685                 :   14252300 :   DECL_CHAIN (fn) = clone;
    4686                 :            : 
    4687                 :            :   /* If this is a template, do the rest on the DECL_TEMPLATE_RESULT.  */
    4688                 :   14252300 :   if (TREE_CODE (clone) == TEMPLATE_DECL)
    4689                 :            :     {
    4690                 :    1083930 :       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name);
    4691                 :    1083930 :       DECL_TEMPLATE_RESULT (clone) = result;
    4692                 :            : 
    4693                 :    1083930 :       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
    4694                 :    1083930 :       DECL_TI_TEMPLATE (result) = clone;
    4695                 :            : 
    4696                 :    1083930 :       TREE_TYPE (clone) = TREE_TYPE (result);
    4697                 :    1083930 :       return clone;
    4698                 :            :     }
    4699                 :            : 
    4700                 :   13168400 :   if (flag_concepts)
    4701                 :            :     /* Clone constraints.  */
    4702                 :    1803810 :     if (tree ci = get_constraints (fn))
    4703                 :      44160 :       set_constraints (clone, copy_node (ci));
    4704                 :            : 
    4705                 :   13168400 :   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
    4706                 :   13168400 :   DECL_CLONED_FUNCTION (clone) = fn;
    4707                 :            :   /* There's no pending inline data for this function.  */
    4708                 :   26336800 :   DECL_PENDING_INLINE_INFO (clone) = NULL;
    4709                 :   26336800 :   DECL_PENDING_INLINE_P (clone) = 0;
    4710                 :            : 
    4711                 :            :   /* The base-class destructor is not virtual.  */
    4712                 :   13168400 :   if (name == base_dtor_identifier)
    4713                 :            :     {
    4714                 :    1204820 :       DECL_VIRTUAL_P (clone) = 0;
    4715                 :    1204820 :       DECL_VINDEX (clone) = NULL_TREE;
    4716                 :            :     }
    4717                 :            : 
    4718                 :   13168400 :   bool ctor_omit_inherited_parms_p = ctor_omit_inherited_parms (clone);
    4719                 :   13168400 :   if (ctor_omit_inherited_parms_p)
    4720                 :        228 :     gcc_assert (DECL_HAS_IN_CHARGE_PARM_P (clone));
    4721                 :            : 
    4722                 :            :   /* If there was an in-charge parameter, drop it from the function
    4723                 :            :      type.  */
    4724                 :   26336800 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    4725                 :            :     {
    4726                 :    2668230 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    4727                 :    2668230 :       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
    4728                 :            :       /* Skip the `this' parameter.  */
    4729                 :    2668230 :       parmtypes = TREE_CHAIN (parmtypes);
    4730                 :            :       /* Skip the in-charge parameter.  */
    4731                 :    2668230 :       parmtypes = TREE_CHAIN (parmtypes);
    4732                 :            :       /* And the VTT parm, in a complete [cd]tor.  */
    4733                 :    5336450 :       if (DECL_HAS_VTT_PARM_P (fn)
    4734                 :    2813350 :           && ! DECL_NEEDS_VTT_PARM_P (clone))
    4735                 :      78172 :         parmtypes = TREE_CHAIN (parmtypes);
    4736                 :    2668230 :       if (ctor_omit_inherited_parms_p)
    4737                 :            :         {
    4738                 :            :           /* If we're omitting inherited parms, that just leaves the VTT.  */
    4739                 :        114 :           gcc_assert (DECL_NEEDS_VTT_PARM_P (clone));
    4740                 :        114 :           parmtypes = tree_cons (NULL_TREE, vtt_parm_type, void_list_node);
    4741                 :            :         }
    4742                 :    5336450 :       TREE_TYPE (clone)
    4743                 :    5336450 :         = build_method_type_directly (basetype,
    4744                 :    2668230 :                                       TREE_TYPE (TREE_TYPE (clone)),
    4745                 :            :                                       parmtypes);
    4746                 :    5336450 :       TREE_TYPE (clone)
    4747                 :    2668230 :         = cp_build_type_attribute_variant (TREE_TYPE (clone),
    4748                 :    2668230 :                                            TYPE_ATTRIBUTES (TREE_TYPE (fn)));
    4749                 :    5336450 :       TREE_TYPE (clone)
    4750                 :    2668230 :         = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
    4751                 :            :     }
    4752                 :            : 
    4753                 :            :   /* Copy the function parameters.  */
    4754                 :   13168400 :   DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
    4755                 :            :   /* Remove the in-charge parameter.  */
    4756                 :   26336800 :   if (DECL_HAS_IN_CHARGE_PARM_P (clone))
    4757                 :            :     {
    4758                 :    5336450 :       DECL_CHAIN (DECL_ARGUMENTS (clone))
    4759                 :    2668230 :         = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    4760                 :    5336450 :       DECL_HAS_IN_CHARGE_PARM_P (clone) = 0;
    4761                 :            :     }
    4762                 :            :   /* And the VTT parm, in a complete [cd]tor.  */
    4763                 :   26336800 :   if (DECL_HAS_VTT_PARM_P (fn))
    4764                 :            :     {
    4765                 :     145126 :       if (DECL_NEEDS_VTT_PARM_P (clone))
    4766                 :     133908 :         DECL_HAS_VTT_PARM_P (clone) = 1;
    4767                 :            :       else
    4768                 :            :         {
    4769                 :     156344 :           DECL_CHAIN (DECL_ARGUMENTS (clone))
    4770                 :      78172 :             = DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone)));
    4771                 :     156344 :           DECL_HAS_VTT_PARM_P (clone) = 0;
    4772                 :            :         }
    4773                 :            :     }
    4774                 :            : 
    4775                 :            :   /* A base constructor inheriting from a virtual base doesn't get the
    4776                 :            :      arguments.  */
    4777                 :   13168400 :   if (ctor_omit_inherited_parms_p)
    4778                 :        114 :     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
    4779                 :            : 
    4780                 :   37745400 :   for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
    4781                 :            :     {
    4782                 :   24576900 :       DECL_CONTEXT (parms) = clone;
    4783                 :   24576900 :       cxx_dup_lang_specific_decl (parms);
    4784                 :            :     }
    4785                 :            : 
    4786                 :            :   /* Create the RTL for this function.  */
    4787                 :   13168400 :   SET_DECL_RTL (clone, NULL);
    4788                 :   13168400 :   rest_of_decl_compilation (clone, /*top_level=*/1, at_eof);
    4789                 :            : 
    4790                 :   13168400 :   return clone;
    4791                 :            : }
    4792                 :            : 
    4793                 :            : /* Build the clones of FN, return the number of clones built.  These
    4794                 :            :    will be inserted onto DECL_CHAIN of FN.  */
    4795                 :            : 
    4796                 :            : unsigned
    4797                 :    6508170 : build_clones (tree fn)
    4798                 :            : {
    4799                 :    6508170 :   unsigned count = 0;
    4800                 :            : 
    4801                 :    6508170 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn))
    4802                 :            :     {
    4803                 :            :       /* For each constructor, we need two variants: an in-charge version
    4804                 :            :          and a not-in-charge version.  */
    4805                 :    5303360 :       build_clone (fn, complete_ctor_identifier);
    4806                 :    5303360 :       build_clone (fn, base_ctor_identifier);
    4807                 :    5303360 :       count += 2;
    4808                 :            :     }
    4809                 :            :   else
    4810                 :            :     {
    4811                 :    1204820 :       gcc_assert (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn));
    4812                 :            : 
    4813                 :            :       /* For each destructor, we need three variants: an in-charge
    4814                 :            :          version, a not-in-charge version, and an in-charge deleting
    4815                 :            :          version.  We clone the deleting version first because that
    4816                 :            :          means it will go second on the TYPE_FIELDS list -- and that
    4817                 :            :          corresponds to the correct layout order in the virtual
    4818                 :            :          function table.
    4819                 :            : 
    4820                 :            :          For a non-virtual destructor, we do not build a deleting
    4821                 :            :          destructor.  */
    4822                 :    1204820 :       if (DECL_VIRTUAL_P (fn))
    4823                 :            :         {
    4824                 :     152062 :           build_clone (fn, deleting_dtor_identifier);
    4825                 :     152062 :           count++;
    4826                 :            :         }
    4827                 :    1204820 :       build_clone (fn, complete_dtor_identifier);
    4828                 :    1204820 :       build_clone (fn, base_dtor_identifier);
    4829                 :    1204820 :       count += 2;
    4830                 :            :     }
    4831                 :            : 
    4832                 :    6508170 :   return count;
    4833                 :            : }
    4834                 :            : 
    4835                 :            : /* Produce declarations for all appropriate clones of FN.  If
    4836                 :            :    UPDATE_METHODS is true, the clones are added to the
    4837                 :            :    CLASSTYPE_MEMBER_VEC.  */
    4838                 :            : 
    4839                 :            : void
    4840                 :    6533510 : clone_function_decl (tree fn, bool update_methods)
    4841                 :            : {
    4842                 :            :   /* Avoid inappropriate cloning.  */
    4843                 :    6533510 :   if (DECL_CHAIN (fn)
    4844                 :    6533510 :       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
    4845                 :            :     return;
    4846                 :            : 
    4847                 :    6508170 :   unsigned count = build_clones (fn);
    4848                 :            : 
    4849                 :            :   /* Note that this is an abstract function that is never emitted.  */
    4850                 :    6508170 :   DECL_ABSTRACT_P (fn) = true;
    4851                 :            : 
    4852                 :    6508170 :   if (update_methods)
    4853                 :   16931100 :     for (tree clone = fn; count--;)
    4854                 :            :       {
    4855                 :   11338100 :         clone = DECL_CHAIN (clone);
    4856                 :   11338100 :         add_method (DECL_CONTEXT (clone), clone, false);
    4857                 :            :       }
    4858                 :            : }
    4859                 :            : 
    4860                 :            : /* DECL is an in charge constructor, which is being defined. This will
    4861                 :            :    have had an in class declaration, from whence clones were
    4862                 :            :    declared. An out-of-class definition can specify additional default
    4863                 :            :    arguments. As it is the clones that are involved in overload
    4864                 :            :    resolution, we must propagate the information from the DECL to its
    4865                 :            :    clones.  */
    4866                 :            : 
    4867                 :            : void
    4868                 :    2362970 : adjust_clone_args (tree decl)
    4869                 :            : {
    4870                 :    2362970 :   tree clone;
    4871                 :            : 
    4872                 :   13466400 :   for (clone = DECL_CHAIN (decl); clone && DECL_CLONED_FUNCTION_P (clone);
    4873                 :    3118330 :        clone = DECL_CHAIN (clone))
    4874                 :            :     {
    4875                 :    3118330 :       tree orig_clone_parms = TYPE_ARG_TYPES (TREE_TYPE (clone));
    4876                 :    3118330 :       tree orig_decl_parms = TYPE_ARG_TYPES (TREE_TYPE (decl));
    4877                 :    3118330 :       tree decl_parms, clone_parms;
    4878                 :            : 
    4879                 :            :       /* Skip the 'this' parameter.  */
    4880                 :    3118330 :       orig_clone_parms = TREE_CHAIN (orig_clone_parms);
    4881                 :    3118330 :       orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    4882                 :            : 
    4883                 :    6236660 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl))
    4884                 :      14166 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    4885                 :    3118330 :       if (DECL_HAS_VTT_PARM_P (decl))
    4886                 :      14166 :         orig_decl_parms = TREE_CHAIN (orig_decl_parms);
    4887                 :            : 
    4888                 :    3118330 :       clone_parms = orig_clone_parms;
    4889                 :    6236660 :       if (DECL_HAS_VTT_PARM_P (clone))
    4890                 :       7083 :         clone_parms = TREE_CHAIN (clone_parms);
    4891                 :            : 
    4892                 :    8495750 :       for (decl_parms = orig_decl_parms; decl_parms;
    4893                 :    2688710 :            decl_parms = TREE_CHAIN (decl_parms),
    4894                 :    2688710 :              clone_parms = TREE_CHAIN (clone_parms))
    4895                 :            :         {
    4896                 :    5805510 :           if (clone_parms == void_list_node)
    4897                 :            :             {
    4898                 :    3116770 :               gcc_assert (decl_parms == clone_parms
    4899                 :            :                           || ctor_omit_inherited_parms (clone));
    4900                 :            :               break;
    4901                 :            :             }
    4902                 :            : 
    4903                 :    2688740 :           gcc_checking_assert (same_type_p (TREE_VALUE (decl_parms),
    4904                 :            :                                             TREE_VALUE (clone_parms)));
    4905                 :            : 
    4906                 :    2978140 :           if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
    4907                 :            :             {
    4908                 :            :               /* A default parameter has been added. Adjust the
    4909                 :            :                  clone's parameters.  */
    4910                 :         32 :               clone_parms = orig_decl_parms;
    4911                 :            : 
    4912                 :         64 :               if (DECL_HAS_VTT_PARM_P (clone))
    4913                 :            :                 {
    4914                 :          4 :                   clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
    4915                 :          4 :                                            TREE_VALUE (orig_clone_parms),
    4916                 :            :                                            clone_parms);
    4917                 :          4 :                   TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
    4918                 :            :                 }
    4919                 :            : 
    4920                 :         32 :               tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
    4921                 :         32 :               tree type
    4922                 :         64 :                 = build_method_type_directly (basetype,
    4923                 :         32 :                                               TREE_TYPE (TREE_TYPE (clone)),
    4924                 :            :                                               clone_parms);
    4925                 :         32 :               if (tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone)))
    4926                 :          0 :                 type = cp_build_type_attribute_variant (type, attrs);
    4927                 :         32 :               type = cxx_copy_lang_qualifiers (type, TREE_TYPE (clone));
    4928                 :         32 :               TREE_TYPE (clone) = type;
    4929                 :            : 
    4930                 :         32 :               clone_parms = NULL_TREE;
    4931                 :         32 :               break;
    4932                 :            :             }
    4933                 :            :         }
    4934                 :    3118330 :       gcc_assert (!clone_parms || clone_parms == void_list_node);
    4935                 :            :     }
    4936                 :    2362970 : }
    4937                 :            : 
    4938                 :            : /* For each of the constructors and destructors in T, create an
    4939                 :            :    in-charge and not-in-charge variant.  */
    4940                 :            : 
    4941                 :            : static void
    4942                 :   11678000 : clone_constructors_and_destructors (tree t)
    4943                 :            : {
    4944                 :            :   /* While constructors can be via a using declaration, at this point
    4945                 :            :      we no longer need to know that.  */
    4946                 :   16028600 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    4947                 :    2175310 :     clone_function_decl (*iter, /*update_methods=*/true);
    4948                 :            : 
    4949                 :   11678000 :   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    4950                 :     489227 :     clone_function_decl (dtor, /*update_methods=*/true);
    4951                 :   11678000 : }
    4952                 :            : 
    4953                 :            : /* Deduce noexcept for a destructor DTOR.  */
    4954                 :            : 
    4955                 :            : void
    4956                 :     465311 : deduce_noexcept_on_destructor (tree dtor)
    4957                 :            : {
    4958                 :     930622 :   if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (dtor)))
    4959                 :     295521 :     TREE_TYPE (dtor) = build_exception_variant (TREE_TYPE (dtor),
    4960                 :            :                                                 noexcept_deferred_spec);
    4961                 :     465311 : }
    4962                 :            : 
    4963                 :            : /* Subroutine of set_one_vmethod_tm_attributes.  Search base classes
    4964                 :            :    of TYPE for virtual functions which FNDECL overrides.  Return a
    4965                 :            :    mask of the tm attributes found therein.  */
    4966                 :            : 
    4967                 :            : static int
    4968                 :        960 : look_for_tm_attr_overrides (tree type, tree fndecl)
    4969                 :            : {
    4970                 :        960 :   tree binfo = TYPE_BINFO (type);
    4971                 :        960 :   tree base_binfo;
    4972                 :        960 :   int ix, found = 0;
    4973                 :            : 
    4974                 :       1610 :   for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ++ix)
    4975                 :            :     {
    4976                 :        650 :       tree o, basetype = BINFO_TYPE (base_binfo);
    4977                 :            : 
    4978                 :       1300 :       if (!TYPE_POLYMORPHIC_P (basetype))
    4979                 :         48 :         continue;
    4980                 :            : 
    4981                 :        602 :       o = look_for_overrides_here (basetype, fndecl);
    4982                 :        602 :       if (o)
    4983                 :            :         {
    4984                 :        896 :           if (lookup_attribute ("transaction_safe_dynamic",
    4985                 :        448 :                                 DECL_ATTRIBUTES (o)))
    4986                 :            :             /* transaction_safe_dynamic is not inherited.  */;
    4987                 :            :           else
    4988                 :        642 :             found |= tm_attr_to_mask (find_tm_attribute
    4989                 :        321 :                                       (TYPE_ATTRIBUTES (TREE_TYPE (o))));
    4990                 :            :         }
    4991                 :            :       else
    4992                 :        154 :         found |= look_for_tm_attr_overrides (basetype, fndecl);
    4993                 :            :     }
    4994                 :            : 
    4995                 :        960 :   return found;
    4996                 :            : }
    4997                 :            : 
    4998                 :            : /* Subroutine of set_method_tm_attributes.  Handle the checks and
    4999                 :            :    inheritance for one virtual method FNDECL.  */
    5000                 :            : 
    5001                 :            : static void
    5002                 :        806 : set_one_vmethod_tm_attributes (tree type, tree fndecl)
    5003                 :            : {
    5004                 :        806 :   tree tm_attr;
    5005                 :        806 :   int found, have;
    5006                 :            : 
    5007                 :        806 :   found = look_for_tm_attr_overrides (type, fndecl);
    5008                 :            : 
    5009                 :            :   /* If FNDECL doesn't actually override anything (i.e. T is the
    5010                 :            :      class that first declares FNDECL virtual), then we're done.  */
    5011                 :        806 :   if (found == 0)
    5012                 :            :     return;
    5013                 :            : 
    5014                 :         59 :   tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl)));
    5015                 :         59 :   have = tm_attr_to_mask (tm_attr);
    5016                 :            : 
    5017                 :            :   /* Intel STM Language Extension 3.0, Section 4.2 table 4:
    5018                 :            :      tm_pure must match exactly, otherwise no weakening of
    5019                 :            :      tm_safe > tm_callable > nothing.  */
    5020                 :            :   /* ??? The tm_pure attribute didn't make the transition to the
    5021                 :            :      multivendor language spec.  */
    5022                 :         59 :   if (have == TM_ATTR_PURE)
    5023                 :            :     {
    5024                 :          0 :       if (found != TM_ATTR_PURE)
    5025                 :            :         {
    5026                 :          0 :           found &= -found;
    5027                 :          0 :           goto err_override;
    5028                 :            :         }
    5029                 :            :     }
    5030                 :            :   /* If the overridden function is tm_pure, then FNDECL must be.  */
    5031                 :         59 :   else if (found == TM_ATTR_PURE && tm_attr)
    5032                 :          8 :     goto err_override;
    5033                 :            :   /* Look for base class combinations that cannot be satisfied.  */
    5034                 :         51 :   else if (found != TM_ATTR_PURE && (found & TM_ATTR_PURE))
    5035                 :            :     {
    5036                 :          0 :       found &= ~TM_ATTR_PURE;
    5037                 :          0 :       found &= -found;
    5038                 :          0 :       error_at (DECL_SOURCE_LOCATION (fndecl),
    5039                 :            :                 "method overrides both %<transaction_pure%> and %qE methods",
    5040                 :            :                 tm_mask_to_attr (found));
    5041                 :            :     }
    5042                 :            :   /* If FNDECL did not declare an attribute, then inherit the most
    5043                 :            :      restrictive one.  */
    5044                 :         51 :   else if (tm_attr == NULL)
    5045                 :            :     {
    5046                 :         18 :       apply_tm_attr (fndecl, tm_mask_to_attr (least_bit_hwi (found)));
    5047                 :            :     }
    5048                 :            :   /* Otherwise validate that we're not weaker than a function
    5049                 :            :      that is being overridden.  */
    5050                 :            :   else
    5051                 :            :     {
    5052                 :         33 :       found &= -found;
    5053                 :         33 :       if (found <= TM_ATTR_CALLABLE && have > found)
    5054                 :         12 :         goto err_override;
    5055                 :            :     }
    5056                 :            :   return;
    5057                 :            : 
    5058                 :         20 :  err_override:
    5059                 :         20 :   error_at (DECL_SOURCE_LOCATION (fndecl),
    5060                 :            :             "method declared %qE overriding %qE method",
    5061                 :            :             tm_attr, tm_mask_to_attr (found));
    5062                 :            : }
    5063                 :            : 
    5064                 :            : /* For each of the methods in T, propagate a class-level tm attribute.  */
    5065                 :            : 
    5066                 :            : static void
    5067                 :   11678000 : set_method_tm_attributes (tree t)
    5068                 :            : {
    5069                 :   11678000 :   tree class_tm_attr, fndecl;
    5070                 :            : 
    5071                 :            :   /* Don't bother collecting tm attributes if transactional memory
    5072                 :            :      support is not enabled.  */
    5073                 :   11678000 :   if (!flag_tm)
    5074                 :            :     return;
    5075                 :            : 
    5076                 :            :   /* Process virtual methods first, as they inherit directly from the
    5077                 :            :      base virtual function and also require validation of new attributes.  */
    5078                 :      11219 :   if (TYPE_CONTAINS_VPTR_P (t))
    5079                 :            :     {
    5080                 :        220 :       tree vchain;
    5081                 :       1832 :       for (vchain = BINFO_VIRTUALS (TYPE_BINFO (t)); vchain;
    5082                 :        806 :            vchain = TREE_CHAIN (vchain))
    5083                 :            :         {
    5084                 :        806 :           fndecl = BV_FN (vchain);
    5085                 :       1612 :           if (DECL_THUNK_P (fndecl))
    5086                 :          4 :             fndecl = THUNK_TARGET (fndecl);
    5087                 :        806 :           set_one_vmethod_tm_attributes (t, fndecl);
    5088                 :            :         }
    5089                 :            :     }
    5090                 :            : 
    5091                 :            :   /* If the class doesn't have an attribute, nothing more to do.  */
    5092                 :       3813 :   class_tm_attr = find_tm_attribute (TYPE_ATTRIBUTES (t));
    5093                 :       3813 :   if (class_tm_attr == NULL)
    5094                 :            :     return;
    5095                 :            : 
    5096                 :            :   /* Any method that does not yet have a tm attribute inherits
    5097                 :            :      the one from the class.  */
    5098                 :        142 :   for (fndecl = TYPE_FIELDS (t); fndecl; fndecl = DECL_CHAIN (fndecl))
    5099                 :         58 :     if (DECL_DECLARES_FUNCTION_P (fndecl)
    5100                 :        154 :         && !find_tm_attribute (TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
    5101                 :         28 :       apply_tm_attr (fndecl, class_tm_attr);
    5102                 :            : }
    5103                 :            : 
    5104                 :            : /* Returns true if FN is a default constructor.  */
    5105                 :            : 
    5106                 :            : bool
    5107                 :    1719000 : default_ctor_p (const_tree fn)
    5108                 :            : {
    5109                 :    1719000 :   return (DECL_CONSTRUCTOR_P (fn)
    5110                 :    5157010 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
    5111                 :            : }
    5112                 :            : 
    5113                 :            : /* Returns true iff class T has a user-provided constructor that can be called
    5114                 :            :    with more than zero arguments.  */
    5115                 :            : 
    5116                 :            : bool
    5117                 :         63 : type_has_user_nondefault_constructor (tree t)
    5118                 :            : {
    5119                 :         63 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5120                 :            :     return false;
    5121                 :            : 
    5122                 :        107 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5123                 :            :     {
    5124                 :         44 :       tree fn = *iter;
    5125                 :         44 :       if (user_provided_p (fn)
    5126                 :         44 :           && (TREE_CODE (fn) == TEMPLATE_DECL
    5127                 :         23 :               || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
    5128                 :            :                   != NULL_TREE)))
    5129                 :          4 :         return true;
    5130                 :            :     }
    5131                 :            : 
    5132                 :         23 :   return false;
    5133                 :            : }
    5134                 :            : 
    5135                 :            : /* Returns the defaulted constructor if T has one. Otherwise, returns
    5136                 :            :    NULL_TREE.  */
    5137                 :            : 
    5138                 :            : tree
    5139                 :         59 : in_class_defaulted_default_constructor (tree t)
    5140                 :            : {
    5141                 :         59 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5142                 :            :     return NULL_TREE;
    5143                 :            : 
    5144                 :         81 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5145                 :            :     {
    5146                 :         52 :       tree fn = *iter;
    5147                 :            : 
    5148                 :        156 :       if (DECL_DEFAULTED_IN_CLASS_P (fn)
    5149                 :         78 :           && default_ctor_p (fn))
    5150                 :         23 :         return fn;
    5151                 :            :     }
    5152                 :            : 
    5153                 :          0 :   return NULL_TREE;
    5154                 :            : }
    5155                 :            : 
    5156                 :            : /* Returns true iff FN is a user-provided function, i.e. user-declared
    5157                 :            :    and not defaulted at its first declaration.  */
    5158                 :            : 
    5159                 :            : bool
    5160                 :   10708400 : user_provided_p (tree fn)
    5161                 :            : {
    5162                 :   10708400 :   fn = STRIP_TEMPLATE (fn);
    5163                 :   10708400 :   return (!DECL_ARTIFICIAL (fn)
    5164                 :   20198400 :           && !(DECL_INITIALIZED_IN_CLASS_P (fn)
    5165                 :   18038400 :                && (DECL_DEFAULTED_FN (fn) || DECL_DELETED_FN (fn))));
    5166                 :            : }
    5167                 :            : 
    5168                 :            : /* Returns true iff class T has a user-provided constructor.  */
    5169                 :            : 
    5170                 :            : bool
    5171                 :   11810400 : type_has_user_provided_constructor (tree t)
    5172                 :            : {
    5173                 :   23620800 :   if (!CLASS_TYPE_P (t))
    5174                 :            :     return false;
    5175                 :            : 
    5176                 :   11810400 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5177                 :            :     return false;
    5178                 :            : 
    5179                 :    1147510 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5180                 :     986730 :     if (user_provided_p (*iter))
    5181                 :     855750 :       return true;
    5182                 :            : 
    5183                 :      29802 :   return false;
    5184                 :            : }
    5185                 :            : 
    5186                 :            : /* Returns true iff class T has a user-provided or explicit constructor.  */
    5187                 :            : 
    5188                 :            : bool
    5189                 :   10242100 : type_has_user_provided_or_explicit_constructor (tree t)
    5190                 :            : {
    5191                 :   20484100 :   if (!CLASS_TYPE_P (t))
    5192                 :            :     return false;
    5193                 :            : 
    5194                 :   10242100 :   if (!TYPE_HAS_USER_CONSTRUCTOR (t))
    5195                 :            :     return false;
    5196                 :            : 
    5197                 :     926758 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5198                 :            :     {
    5199                 :     807598 :       tree fn = *iter;
    5200                 :     910905 :       if (user_provided_p (fn) || DECL_NONCONVERTING_P (fn))
    5201                 :     712581 :         return true;
    5202                 :            :     }
    5203                 :            : 
    5204                 :      24143 :   return false;
    5205                 :            : }
    5206                 :            : 
    5207                 :            : /* Returns true iff class T has a non-user-provided (i.e. implicitly
    5208                 :            :    declared or explicitly defaulted in the class body) default
    5209                 :            :    constructor.  */
    5210                 :            : 
    5211                 :            : bool
    5212                 :     685660 : type_has_non_user_provided_default_constructor (tree t)
    5213                 :            : {
    5214                 :     685660 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    5215                 :            :     return false;
    5216                 :     685642 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5217                 :            :     return true;
    5218                 :            : 
    5219                 :    3648730 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5220                 :            :     {
    5221                 :    1685440 :       tree fn = *iter;
    5222                 :    1685440 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5223                 :    1457790 :           && default_ctor_p (fn)
    5224                 :    2366140 :           && !user_provided_p (fn))
    5225                 :     203780 :         return true;
    5226                 :            :     }
    5227                 :            : 
    5228                 :     481634 :   return false;
    5229                 :            : }
    5230                 :            : 
    5231                 :            : /* TYPE is being used as a virtual base, and has a non-trivial move
    5232                 :            :    assignment.  Return true if this is due to there being a user-provided
    5233                 :            :    move assignment in TYPE or one of its subobjects; if there isn't, then
    5234                 :            :    multiple move assignment can't cause any harm.  */
    5235                 :            : 
    5236                 :            : bool
    5237                 :         21 : vbase_has_user_provided_move_assign (tree type)
    5238                 :            : {
    5239                 :            :   /* Does the type itself have a user-provided move assignment operator?  */
    5240                 :         21 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type))
    5241                 :         30 :     for (ovl_iterator iter (get_class_binding_direct
    5242                 :         21 :                             (type, assign_op_identifier));
    5243                 :         51 :          iter; ++iter)
    5244                 :         42 :       if (user_provided_p (*iter) && move_fn_p (*iter))
    5245                 :         12 :         return true;
    5246                 :            : 
    5247                 :            :   /* Do any of its bases?  */
    5248                 :          9 :   tree binfo = TYPE_BINFO (type);
    5249                 :          9 :   tree base_binfo;
    5250                 :         12 :   for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    5251                 :          6 :     if (vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
    5252                 :            :       return true;
    5253                 :            : 
    5254                 :            :   /* Or non-static data members?  */
    5255                 :         27 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    5256                 :            :     {
    5257                 :         21 :       if (TREE_CODE (field) == FIELD_DECL
    5258                 :          3 :           && CLASS_TYPE_P (TREE_TYPE (field))
    5259                 :         21 :           && vbase_has_user_provided_move_assign (TREE_TYPE (field)))
    5260                 :            :         return true;
    5261                 :            :     }
    5262                 :            : 
    5263                 :            :   /* Seems not.  */
    5264                 :            :   return false;
    5265                 :            : }
    5266                 :            : 
    5267                 :            : /* If default-initialization leaves part of TYPE uninitialized, returns
    5268                 :            :    a DECL for the field or TYPE itself (DR 253).  */
    5269                 :            : 
    5270                 :            : tree
    5271                 :     134997 : default_init_uninitialized_part (tree type)
    5272                 :            : {
    5273                 :     134997 :   tree t, r, binfo;
    5274                 :     134997 :   int i;
    5275                 :            : 
    5276                 :     134997 :   type = strip_array_types (type);
    5277                 :     269181 :   if (!CLASS_TYPE_P (type))
    5278                 :            :     return type;
    5279                 :     134181 :   if (!type_has_non_user_provided_default_constructor (type))
    5280                 :            :     return NULL_TREE;
    5281                 :       2986 :   for (binfo = TYPE_BINFO (type), i = 0;
    5282                 :       2977 :        BINFO_BASE_ITERATE (binfo, i, t); ++i)
    5283                 :            :     {
    5284                 :       1146 :       r = default_init_uninitialized_part (BINFO_TYPE (t));
    5285                 :       1146 :       if (r)
    5286                 :          2 :         return r;
    5287                 :            :     }
    5288                 :      32905 :   for (t = TYPE_FIELDS (type); t; t = DECL_CHAIN (t))
    5289                 :      31167 :     if (TREE_CODE (t) == FIELD_DECL
    5290                 :       1510 :         && !DECL_ARTIFICIAL (t)
    5291                 :      31451 :         && !DECL_INITIAL (t))
    5292                 :            :       {
    5293                 :        180 :         r = default_init_uninitialized_part (TREE_TYPE (t));
    5294                 :        180 :         if (r)
    5295                 :        199 :           return DECL_P (r) ? r : t;
    5296                 :            :       }
    5297                 :            : 
    5298                 :            :   return NULL_TREE;
    5299                 :            : }
    5300                 :            : 
    5301                 :            : /* Returns true iff for class T, a trivial synthesized default constructor
    5302                 :            :    would be constexpr.  */
    5303                 :            : 
    5304                 :            : bool
    5305                 :   11358900 : trivial_default_constructor_is_constexpr (tree t)
    5306                 :            : {
    5307                 :            :   /* A defaulted trivial default constructor is constexpr
    5308                 :            :      if there is nothing to initialize.  */
    5309                 :   11358900 :   gcc_assert (!TYPE_HAS_COMPLEX_DFLT (t));
    5310                 :            :   /* A class with a vptr doesn't have a trivial default ctor.
    5311                 :            :      In C++20, a class can have transient uninitialized members, e.g.:
    5312                 :            : 
    5313                 :            :        struct S { int i; constexpr S() = default; };
    5314                 :            : 
    5315                 :            :      should work.  */
    5316                 :   11358900 :   return (cxx_dialect >= cxx2a
    5317                 :   11358900 :           || is_really_empty_class (t, /*ignore_vptr*/true));
    5318                 :            : }
    5319                 :            : 
    5320                 :            : /* Returns true iff class T has a constexpr default constructor.  */
    5321                 :            : 
    5322                 :            : bool
    5323                 :   10816100 : type_has_constexpr_default_constructor (tree t)
    5324                 :            : {
    5325                 :   10816100 :   tree fns;
    5326                 :            : 
    5327                 :   21632000 :   if (!CLASS_TYPE_P (t))
    5328                 :            :     {
    5329                 :            :       /* The caller should have stripped an enclosing array.  */
    5330                 :        151 :       gcc_assert (TREE_CODE (t) != ARRAY_TYPE);
    5331                 :            :       return false;
    5332                 :            :     }
    5333                 :   10815900 :   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
    5334                 :            :     {
    5335                 :   10814100 :       if (!TYPE_HAS_COMPLEX_DFLT (t))
    5336                 :   10814000 :         return trivial_default_constructor_is_constexpr (t);
    5337                 :            :       /* Non-trivial, we need to check subobject constructors.  */
    5338                 :         56 :       lazily_declare_fn (sfk_constructor, t);
    5339                 :            :     }
    5340                 :       1891 :   fns = locate_ctor (t);
    5341                 :       3776 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5342                 :            : }
    5343                 :            : 
    5344                 :            : /* Returns true iff class T has a constexpr default constructor or has an
    5345                 :            :    implicitly declared default constructor that we can't tell if it's constexpr
    5346                 :            :    without forcing a lazy declaration (which might cause undesired
    5347                 :            :    instantiations).  */
    5348                 :            : 
    5349                 :            : static bool
    5350                 :   10853700 : type_maybe_constexpr_default_constructor (tree t)
    5351                 :            : {
    5352                 :   10853700 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DEFAULT_CTOR (t)
    5353                 :   21707400 :       && TYPE_HAS_COMPLEX_DFLT (t))
    5354                 :            :     /* Assume it's constexpr.  */
    5355                 :            :     return true;
    5356                 :   10814000 :   return type_has_constexpr_default_constructor (t);
    5357                 :            : }
    5358                 :            : 
    5359                 :            : /* Returns true iff class T has a constexpr destructor.  */
    5360                 :            : 
    5361                 :            : bool
    5362                 :      21139 : type_has_constexpr_destructor (tree t)
    5363                 :            : {
    5364                 :      21139 :   tree fns;
    5365                 :            : 
    5366                 :      21139 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    5367                 :            :     /* Non-trivial, we need to check subobject destructors.  */
    5368                 :          2 :     lazily_declare_fn (sfk_destructor, t);
    5369                 :      21139 :   fns = CLASSTYPE_DESTRUCTOR (t);
    5370                 :      42278 :   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
    5371                 :            : }
    5372                 :            : 
    5373                 :            : /* Returns true iff class T has a constexpr destructor or has an
    5374                 :            :    implicitly declared destructor that we can't tell if it's constexpr
    5375                 :            :    without forcing a lazy declaration (which might cause undesired
    5376                 :            :    instantiations).  */
    5377                 :            : 
    5378                 :            : static bool
    5379                 :      24183 : type_maybe_constexpr_destructor (tree t)
    5380                 :            : {
    5381                 :      48366 :   if (CLASS_TYPE_P (t) && CLASSTYPE_LAZY_DESTRUCTOR (t))
    5382                 :            :     /* Assume it's constexpr.  */
    5383                 :            :     return true;
    5384                 :      21078 :   return type_has_constexpr_destructor (t);
    5385                 :            : }
    5386                 :            : 
    5387                 :            : /* Returns true iff class TYPE has a virtual destructor.  */
    5388                 :            : 
    5389                 :            : bool
    5390                 :     411084 : type_has_virtual_destructor (tree type)
    5391                 :            : {
    5392                 :     411084 :   tree dtor;
    5393                 :            : 
    5394                 :     822065 :   if (!CLASS_TYPE_P (type))
    5395                 :            :     return false;
    5396                 :            : 
    5397                 :     410981 :   gcc_assert (COMPLETE_TYPE_P (type));
    5398                 :     410981 :   dtor = CLASSTYPE_DESTRUCTOR (type);
    5399                 :     821882 :   return (dtor && DECL_VIRTUAL_P (dtor));
    5400                 :            : }
    5401                 :            : 
    5402                 :            : /* Returns true iff T, a class, has a move-assignment or
    5403                 :            :    move-constructor.  Does not lazily declare either.
    5404                 :            :    If USER_P is false, any move function will do.  If it is true, the
    5405                 :            :    move function must be user-declared.
    5406                 :            : 
    5407                 :            :    Note that user-declared here is different from "user-provided",
    5408                 :            :    which doesn't include functions that are defaulted in the
    5409                 :            :    class.  */
    5410                 :            : 
    5411                 :            : bool
    5412                 :   12314300 : classtype_has_move_assign_or_move_ctor_p (tree t, bool user_p)
    5413                 :            : {
    5414                 :   23385600 :   gcc_assert (user_p
    5415                 :            :               || (!CLASSTYPE_LAZY_MOVE_CTOR (t)
    5416                 :            :                   && !CLASSTYPE_LAZY_MOVE_ASSIGN (t)));
    5417                 :            : 
    5418                 :   12314300 :   if (!CLASSTYPE_LAZY_MOVE_CTOR (t))
    5419                 :   13801000 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5420                 :    1200290 :       if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
    5421                 :      63669 :         return true;
    5422                 :            : 
    5423                 :   12250600 :   if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
    5424                 :      96420 :     for (ovl_iterator iter (get_class_binding_direct
    5425                 :   11479900 :                             (t, assign_op_identifier));
    5426                 :   11576300 :          iter; ++iter)
    5427                 :      85809 :       if ((!user_p || !DECL_ARTIFICIAL (*iter))
    5428                 :      18711 :           && DECL_CONTEXT (*iter) == t
    5429                 :     115661 :           && move_fn_p (*iter))
    5430                 :       1346 :         return true;
    5431                 :            :   
    5432                 :            :   return false;
    5433                 :            : }
    5434                 :            : 
    5435                 :            : /* True iff T has a move constructor that is not deleted.  */
    5436                 :            : 
    5437                 :            : bool
    5438                 :         41 : classtype_has_non_deleted_move_ctor (tree t)
    5439                 :            : {
    5440                 :         41 :   if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    5441                 :          8 :     lazily_declare_fn (sfk_move_constructor, t);
    5442                 :        149 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5443                 :        136 :     if (move_fn_p (*iter) && !DECL_DELETED_FN (*iter))
    5444                 :         41 :       return true;
    5445                 :          0 :   return false;
    5446                 :            : }
    5447                 :            : 
    5448                 :            : /* True iff T has a copy constructor that is not deleted.  */
    5449                 :            : 
    5450                 :            : bool
    5451                 :         35 : classtype_has_non_deleted_copy_ctor (tree t)
    5452                 :            : {
    5453                 :         35 :   if (CLASSTYPE_LAZY_COPY_CTOR (t))
    5454                 :          8 :     lazily_declare_fn (sfk_copy_constructor, t);
    5455                 :        197 :   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5456                 :        151 :     if (copy_fn_p (*iter) && !DECL_DELETED_FN (*iter))
    5457                 :         35 :       return true;
    5458                 :          0 :   return false;
    5459                 :            : }
    5460                 :            : 
    5461                 :            : /* If T, a class, has a user-provided copy constructor, copy assignment
    5462                 :            :    operator, or destructor, returns that function.  Otherwise, null.  */
    5463                 :            : 
    5464                 :            : tree
    5465                 :    1034270 : classtype_has_depr_implicit_copy (tree t)
    5466                 :            : {
    5467                 :    1034270 :   if (!CLASSTYPE_LAZY_COPY_CTOR (t))
    5468                 :    3775910 :     for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5469                 :            :       {
    5470                 :    1433200 :         tree fn = *iter;
    5471                 :    1433200 :         if (user_provided_p (fn) && copy_fn_p (fn))
    5472                 :      43001 :           return fn;
    5473                 :            :       }
    5474                 :            : 
    5475                 :     991270 :   if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
    5476                 :      85800 :     for (ovl_iterator iter (get_class_binding_direct
    5477                 :     122569 :                             (t, assign_op_identifier));
    5478                 :     208369 :          iter; ++iter)
    5479                 :            :       {
    5480                 :      86221 :         tree fn = *iter;
    5481                 :      86221 :         if (user_provided_p (fn) && copy_fn_p (fn))
    5482                 :        421 :           return fn;
    5483                 :            :       }
    5484                 :            : 
    5485                 :     990849 :   if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
    5486                 :            :     {
    5487                 :     428831 :       tree fn = CLASSTYPE_DESTRUCTOR (t);
    5488                 :     428831 :       if (user_provided_p (fn))
    5489                 :     163093 :         return fn;
    5490                 :            :     }
    5491                 :            : 
    5492                 :            :   return NULL_TREE;
    5493                 :            : }
    5494                 :            : 
    5495                 :            : /* True iff T has a member or friend declaration of operator OP.  */
    5496                 :            : 
    5497                 :            : bool
    5498                 :   11678000 : classtype_has_op (tree t, tree_code op)
    5499                 :            : {
    5500                 :   11678000 :   tree name = ovl_op_identifier (op);
    5501                 :   11678000 :   if (get_class_binding (t, name))
    5502                 :            :     return true;
    5503                 :   11829400 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    5504                 :     267317 :     if (FRIEND_NAME (f) == name)
    5505                 :            :       return true;
    5506                 :            :   return false;
    5507                 :            : }
    5508                 :            : 
    5509                 :            : 
    5510                 :            : /* If T has a defaulted member or friend declaration of OP, return it.  */
    5511                 :            : 
    5512                 :            : tree
    5513                 :   11562100 : classtype_has_defaulted_op (tree t, tree_code op)
    5514                 :            : {
    5515                 :   11562100 :   tree name = ovl_op_identifier (op);
    5516                 :   11562100 :   for (ovl_iterator oi (get_class_binding (t, name)); oi; ++oi)
    5517                 :            :     {
    5518                 :          9 :       tree fn = *oi;
    5519                 :         18 :       if (DECL_DEFAULTED_FN (fn))
    5520                 :          5 :         return fn;
    5521                 :            :     }
    5522                 :   11602800 :   for (tree f = DECL_FRIENDLIST (TYPE_MAIN_DECL (t)); f; f = TREE_CHAIN (f))
    5523                 :      40687 :     if (FRIEND_NAME (f) == name)
    5524                 :          4 :       for (tree l = FRIEND_DECLS (f); l; l = TREE_CHAIN (l))
    5525                 :            :         {
    5526                 :          3 :           tree fn = TREE_VALUE (l);
    5527                 :          6 :           if (DECL_DEFAULTED_FN (fn))
    5528                 :          2 :             return fn;
    5529                 :            :         }
    5530                 :            :   return NULL_TREE;
    5531                 :            : }
    5532                 :            : 
    5533                 :            : /* Nonzero if we need to build up a constructor call when initializing an
    5534                 :            :    object of this class, either because it has a user-declared constructor
    5535                 :            :    or because it doesn't have a default constructor (so we need to give an
    5536                 :            :    error if no initializer is provided).  Use TYPE_NEEDS_CONSTRUCTING when
    5537                 :            :    what you care about is whether or not an object can be produced by a
    5538                 :            :    constructor (e.g. so we don't set TREE_READONLY on const variables of
    5539                 :            :    such type); use this function when what you care about is whether or not
    5540                 :            :    to try to call a constructor to create an object.  The latter case is
    5541                 :            :    the former plus some cases of constructors that cannot be called.  */
    5542                 :            : 
    5543                 :            : bool
    5544                 :    6868300 : type_build_ctor_call (tree t)
    5545                 :            : {
    5546                 :    6868300 :   tree inner;
    5547                 :    6868300 :   if (TYPE_NEEDS_CONSTRUCTING (t))
    5548                 :            :     return true;
    5549                 :    5441710 :   inner = strip_array_types (t);
    5550                 :    6332290 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner))
    5551                 :            :     return false;
    5552                 :     864650 :   if (!TYPE_HAS_DEFAULT_CONSTRUCTOR (inner))
    5553                 :            :     return true;
    5554                 :     705620 :   if (cxx_dialect < cxx11)
    5555                 :            :     return false;
    5556                 :            :   /* A user-declared constructor might be private, and a constructor might
    5557                 :            :      be trivial but deleted.  */
    5558                 :    2753190 :   for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
    5559                 :    2753190 :        iter; ++iter)
    5560                 :            :     {
    5561                 :    2088950 :       tree fn = *iter;
    5562                 :    2088950 :       if (!DECL_ARTIFICIAL (fn)
    5563                 :    2074160 :           || TREE_DEPRECATED (fn)
    5564                 :    6232940 :           || DECL_DELETED_FN (fn))
    5565                 :      33860 :         return true;
    5566                 :            :     }
    5567                 :     664240 :   return false;
    5568                 :            : }
    5569                 :            : 
    5570                 :            : /* Like type_build_ctor_call, but for destructors.  */
    5571                 :            : 
    5572                 :            : bool
    5573                 :   15580700 : type_build_dtor_call (tree t)
    5574                 :            : {
    5575                 :   15580700 :   tree inner;
    5576                 :   15580700 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    5577                 :            :     return true;
    5578                 :    9365870 :   inner = strip_array_types (t);
    5579                 :    4380330 :   if (!CLASS_TYPE_P (inner) || ANON_AGGR_TYPE_P (inner)
    5580                 :   13719800 :       || !COMPLETE_TYPE_P (inner))
    5581                 :            :     return false;
    5582                 :    4353890 :   if (cxx_dialect < cxx11)
    5583                 :            :     return false;
    5584                 :            :   /* A user-declared destructor might be private, and a destructor might
    5585                 :            :      be trivial but deleted.  */
    5586                 :    8058240 :   for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
    5587                 :    8058240 :        iter; ++iter)
    5588                 :            :     {
    5589                 :    4169710 :       tree fn = *iter;
    5590                 :    4169710 :       if (!DECL_ARTIFICIAL (fn)
    5591                 :    3732500 :           || TREE_DEPRECATED (fn)
    5592                 :   11634700 :           || DECL_DELETED_FN (fn))
    5593                 :     437205 :         return true;
    5594                 :            :     }
    5595                 :    3888530 :   return false;
    5596                 :            : }
    5597                 :            : 
    5598                 :            : /* Remove all zero-width bit-fields from T.  */
    5599                 :            : 
    5600                 :            : static void
    5601                 :   11678000 : remove_zero_width_bit_fields (tree t)
    5602                 :            : {
    5603                 :   11678000 :   tree *fieldsp;
    5604                 :            : 
    5605                 :   11777800 :   fieldsp = &TYPE_FIELDS (t);
    5606                 :   54991200 :   while (*fieldsp)
    5607                 :            :     {
    5608                 :   43313200 :       if (TREE_CODE (*fieldsp) == FIELD_DECL
    5609                 :    4613640 :           && DECL_C_BIT_FIELD (*fieldsp)
    5610                 :            :           /* We should not be confused by the fact that grokbitfield
    5611                 :            :              temporarily sets the width of the bit field into
    5612                 :            :              DECL_BIT_FIELD_REPRESENTATIVE (*fieldsp).
    5613                 :            :              check_bitfield_decl eventually sets DECL_SIZE (*fieldsp)
    5614                 :            :              to that width.  */
    5615                 :   43359000 :           && (DECL_SIZE (*fieldsp) == NULL_TREE
    5616                 :      45727 :               || integer_zerop (DECL_SIZE (*fieldsp))))
    5617                 :        586 :         *fieldsp = DECL_CHAIN (*fieldsp);
    5618                 :            :       else
    5619                 :   43312600 :         fieldsp = &DECL_CHAIN (*fieldsp);
    5620                 :            :     }
    5621                 :   11678000 : }
    5622                 :            : 
    5623                 :            : /* Returns TRUE iff we need a cookie when dynamically allocating an
    5624                 :            :    array whose elements have the indicated class TYPE.  */
    5625                 :            : 
    5626                 :            : static bool
    5627                 :   11678000 : type_requires_array_cookie (tree type)
    5628                 :            : {
    5629                 :   11678000 :   tree fns;
    5630                 :   11678000 :   bool has_two_argument_delete_p = false;
    5631                 :            : 
    5632                 :   23356000 :   gcc_assert (CLASS_TYPE_P (type));
    5633                 :            : 
    5634                 :            :   /* If there's a non-trivial destructor, we need a cookie.  In order
    5635                 :            :      to iterate through the array calling the destructor for each
    5636                 :            :      element, we'll have to know how many elements there are.  */
    5637                 :   11678000 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5638                 :            :     return true;
    5639                 :            : 
    5640                 :            :   /* If the usual deallocation function is a two-argument whose second
    5641                 :            :      argument is of type `size_t', then we have to pass the size of
    5642                 :            :      the array to the deallocation function, so we will need to store
    5643                 :            :      a cookie.  */
    5644                 :   11161200 :   fns = lookup_fnfields (TYPE_BINFO (type),
    5645                 :            :                          ovl_op_identifier (false, VEC_DELETE_EXPR),
    5646                 :            :                          /*protect=*/0);
    5647                 :            :   /* If there are no `operator []' members, or the lookup is
    5648                 :            :      ambiguous, then we don't need a cookie.  */
    5649                 :   11161200 :   if (!fns || fns == error_mark_node)
    5650                 :            :     return false;
    5651                 :            :   /* Loop through all of the functions.  */
    5652                 :         86 :   for (lkp_iterator iter (BASELINK_FUNCTIONS (fns)); iter; ++iter)
    5653                 :            :     {
    5654                 :         37 :       tree fn = *iter;
    5655                 :            : 
    5656                 :            :       /* See if this function is a one-argument delete function.  If
    5657                 :            :          it is, then it will be the usual deallocation function.  */
    5658                 :         37 :       tree second_parm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
    5659                 :         37 :       if (second_parm == void_list_node)
    5660                 :         17 :         return false;
    5661                 :            :       /* Do not consider this function if its second argument is an
    5662                 :            :          ellipsis.  */
    5663                 :         20 :       if (!second_parm)
    5664                 :          4 :         continue;
    5665                 :            :       /* Otherwise, if we have a two-argument function and the second
    5666                 :            :          argument is `size_t', it will be the usual deallocation
    5667                 :            :          function -- unless there is one-argument function, too.  */
    5668                 :         16 :       if (TREE_CHAIN (second_parm) == void_list_node
    5669                 :         16 :           && same_type_p (TREE_VALUE (second_parm), size_type_node))
    5670                 :            :         has_two_argument_delete_p = true;
    5671                 :            :     }
    5672                 :            : 
    5673                 :         16 :   return has_two_argument_delete_p;
    5674                 :            : }
    5675                 :            : 
    5676                 :            : /* Finish computing the `literal type' property of class type T.
    5677                 :            : 
    5678                 :            :    At this point, we have already processed base classes and
    5679                 :            :    non-static data members.  We need to check whether the copy
    5680                 :            :    constructor is trivial, the destructor is trivial, and there
    5681                 :            :    is a trivial default constructor or at least one constexpr
    5682                 :            :    constructor other than the copy constructor.  */
    5683                 :            : 
    5684                 :            : static void
    5685                 :   11678000 : finalize_literal_type_property (tree t)
    5686                 :            : {
    5687                 :   11678000 :   tree fn;
    5688                 :            : 
    5689                 :   11678000 :   if (cxx_dialect < cxx11)
    5690                 :      85561 :     CLASSTYPE_LITERAL_P (t) = false;
    5691                 :   11592500 :   else if (CLASSTYPE_LITERAL_P (t)
    5692                 :   11319800 :            && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    5693                 :   11848300 :            && (cxx_dialect < cxx2a || !type_maybe_constexpr_destructor (t)))
    5694                 :     249047 :     CLASSTYPE_LITERAL_P (t) = false;
    5695                 :   11343400 :   else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
    5696                 :      34650 :     CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx17);
    5697                 :   11308800 :   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
    5698                 :     199323 :            && CLASSTYPE_NON_AGGREGATE (t)
    5699                 :   11503600 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    5700                 :      70890 :     CLASSTYPE_LITERAL_P (t) = false;
    5701                 :            : 
    5702                 :            :   /* C++14 DR 1684 removed this restriction.  */
    5703                 :   11678000 :   if (cxx_dialect < cxx14
    5704                 :   11989000 :       && !CLASSTYPE_LITERAL_P (t) && !LAMBDA_TYPE_P (t))
    5705                 :    1359450 :     for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    5706                 :    1233090 :       if (TREE_CODE (fn) == FUNCTION_DECL
    5707                 :     640992 :           && DECL_DECLARED_CONSTEXPR_P (fn)
    5708                 :       2287 :           && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
    5709                 :    1235130 :           && !DECL_CONSTRUCTOR_P (fn))
    5710                 :            :         {
    5711                 :        817 :           DECL_DECLARED_CONSTEXPR_P (fn) = false;
    5712                 :        817 :           if (!DECL_GENERATED_P (fn))
    5713                 :            :             {
    5714                 :          0 :               auto_diagnostic_group d;
    5715                 :          0 :               if (pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic,
    5716                 :            :                              "enclosing class of %<constexpr%> non-static "
    5717                 :            :                              "member function %q+#D is not a literal type", fn))
    5718                 :          0 :                 explain_non_literal_class (t);
    5719                 :            :             }
    5720                 :            :         }
    5721                 :   11678000 : }
    5722                 :            : 
    5723                 :            : /* T is a non-literal type used in a context which requires a constant
    5724                 :            :    expression.  Explain why it isn't literal.  */
    5725                 :            : 
    5726                 :            : void
    5727                 :        102 : explain_non_literal_class (tree t)
    5728                 :            : {
    5729                 :        102 :   static hash_set<tree> *diagnosed;
    5730                 :            : 
    5731                 :        102 :   if (!CLASS_TYPE_P (t))
    5732                 :         39 :     return;
    5733                 :        102 :   t = TYPE_MAIN_VARIANT (t);
    5734                 :            : 
    5735                 :        102 :   if (diagnosed == NULL)
    5736                 :         51 :     diagnosed = new hash_set<tree>;
    5737                 :        102 :   if (diagnosed->add (t))
    5738                 :            :     /* Already explained.  */
    5739                 :            :     return;
    5740                 :            : 
    5741                 :        141 :   auto_diagnostic_group d;
    5742                 :         78 :   inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
    5743                 :         78 :   if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t))
    5744                 :          1 :     inform (UNKNOWN_LOCATION,
    5745                 :            :             "  %qT is a closure type, which is only literal in "
    5746                 :            :             "C++17 and later", t);
    5747                 :         77 :   else if (cxx_dialect < cxx2a && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    5748                 :          6 :     inform (UNKNOWN_LOCATION, "  %q+T has a non-trivial destructor", t);
    5749                 :         71 :   else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    5750                 :         71 :            && !type_maybe_constexpr_destructor (t))
    5751                 :          6 :     inform (UNKNOWN_LOCATION, "  %q+T does not have %<constexpr%> destructor",
    5752                 :            :             t);
    5753                 :         65 :   else if (CLASSTYPE_NON_AGGREGATE (t)
    5754                 :         55 :            && !TYPE_HAS_TRIVIAL_DFLT (t)
    5755                 :         55 :            && !LAMBDA_TYPE_P (t)
    5756                 :        120 :            && !TYPE_HAS_CONSTEXPR_CTOR (t))
    5757                 :            :     {
    5758                 :         32 :       inform (UNKNOWN_LOCATION,
    5759                 :            :               "  %q+T is not an aggregate, does not have a trivial "
    5760                 :            :               "default constructor, and has no %<constexpr%> constructor that "
    5761                 :            :               "is not a copy or move constructor", t);
    5762                 :         32 :       if (type_has_non_user_provided_default_constructor (t))
    5763                 :            :         /* Note that we can't simply call locate_ctor because when the
    5764                 :            :            constructor is deleted it just returns NULL_TREE.  */
    5765                 :          0 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    5766                 :            :           {
    5767                 :          0 :             tree fn = *iter;
    5768                 :          0 :             tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    5769                 :            : 
    5770                 :          0 :             parms = skip_artificial_parms_for (fn, parms);
    5771                 :            : 
    5772                 :          0 :             if (sufficient_parms_p (parms))
    5773                 :            :               {
    5774                 :          0 :                 if (DECL_DELETED_FN (fn))
    5775                 :          0 :                   maybe_explain_implicit_delete (fn);
    5776                 :            :                 else
    5777                 :          0 :                   explain_invalid_constexpr_fn (fn);
    5778                 :            :                 break;
    5779                 :            :               }
    5780                 :            :         }
    5781                 :            :     }
    5782                 :            :   else
    5783                 :            :     {
    5784                 :         33 :       tree binfo, base_binfo, field; int i;
    5785                 :         36 :       for (binfo = TYPE_BINFO (t), i = 0;
    5786                 :         33 :            BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    5787                 :            :         {
    5788                 :         15 :           tree basetype = TREE_TYPE (base_binfo);
    5789                 :         15 :           if (!CLASSTYPE_LITERAL_P (basetype))
    5790                 :            :             {
    5791                 :         15 :               inform (UNKNOWN_LOCATION,
    5792                 :            :                       "  base class %qT of %q+T is non-literal",
    5793                 :            :                       basetype, t);
    5794                 :         15 :               explain_non_literal_class (basetype);
    5795                 :         15 :               return;
    5796                 :            :             }
    5797                 :            :         }
    5798                 :        141 :       for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
    5799                 :            :         {
    5800                 :        120 :           tree ftype;
    5801                 :        120 :           if (TREE_CODE (field) != FIELD_DECL)
    5802                 :        102 :             continue;
    5803                 :         18 :           ftype = TREE_TYPE (field);
    5804                 :         18 :           if (!literal_type_p (ftype))
    5805                 :            :             {
    5806                 :          6 :               inform (DECL_SOURCE_LOCATION (field),
    5807                 :            :                       "  non-static data member %qD has non-literal type",
    5808                 :            :                       field);
    5809                 :         12 :               if (CLASS_TYPE_P (ftype))
    5810                 :          6 :                 explain_non_literal_class (ftype);
    5811                 :            :             }
    5812                 :         18 :           if (CP_TYPE_VOLATILE_P (ftype))
    5813                 :         12 :             inform (DECL_SOURCE_LOCATION (field),
    5814                 :            :                     "  non-static data member %qD has volatile type", field);
    5815                 :            :         }
    5816                 :            :     }
    5817                 :            : }
    5818                 :            : 
    5819                 :            : /* Check the validity of the bases and members declared in T.  Add any
    5820                 :            :    implicitly-generated functions (like copy-constructors and
    5821                 :            :    assignment operators).  Compute various flag bits (like
    5822                 :            :    CLASSTYPE_NON_LAYOUT_POD_T) for T.  This routine works purely at the C++
    5823                 :            :    level: i.e., independently of the ABI in use.  */
    5824                 :            : 
    5825                 :            : static void
    5826                 :   11678000 : check_bases_and_members (tree t)
    5827                 :            : {
    5828                 :            :   /* Nonzero if the implicitly generated copy constructor should take
    5829                 :            :      a non-const reference argument.  */
    5830                 :   11678000 :   int cant_have_const_ctor;
    5831                 :            :   /* Nonzero if the implicitly generated assignment operator
    5832                 :            :      should take a non-const reference argument.  */
    5833                 :   11678000 :   int no_const_asn_ref;
    5834                 :   11678000 :   tree access_decls;
    5835                 :   11678000 :   bool saved_complex_asn_ref;
    5836                 :   11678000 :   bool saved_nontrivial_dtor;
    5837                 :   11678000 :   tree fn;
    5838                 :            : 
    5839                 :            :   /* By default, we use const reference arguments and generate default
    5840                 :            :      constructors.  */
    5841                 :   11678000 :   cant_have_const_ctor = 0;
    5842                 :   11678000 :   no_const_asn_ref = 0;
    5843                 :            : 
    5844                 :            :   /* Check all the base-classes and set FMEM members to point to arrays
    5845                 :            :      of potential interest.  */
    5846                 :   11678000 :   check_bases (t, &cant_have_const_ctor, &no_const_asn_ref);
    5847                 :            : 
    5848                 :            :   /* Deduce noexcept on destructor.  This needs to happen after we've set
    5849                 :            :      triviality flags appropriately for our bases.  */
    5850                 :   11678000 :   if (cxx_dialect >= cxx11)
    5851                 :   11592500 :     if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
    5852                 :     460380 :       deduce_noexcept_on_destructor (dtor);
    5853                 :            : 
    5854                 :            :   /* Check all the method declarations.  */
    5855                 :   11678000 :   check_methods (t);
    5856                 :            : 
    5857                 :            :   /* Save the initial values of these flags which only indicate whether
    5858                 :            :      or not the class has user-provided functions.  As we analyze the
    5859                 :            :      bases and members we can set these flags for other reasons.  */
    5860                 :   11678000 :   saved_complex_asn_ref = TYPE_HAS_COMPLEX_COPY_ASSIGN (t);
    5861                 :   11678000 :   saved_nontrivial_dtor = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t);
    5862                 :            : 
    5863                 :            :   /* Check all the data member declarations.  We cannot call
    5864                 :            :      check_field_decls until we have called check_bases check_methods,
    5865                 :            :      as check_field_decls depends on TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    5866                 :            :      being set appropriately.  */
    5867                 :   11678000 :   check_field_decls (t, &access_decls,
    5868                 :            :                      &cant_have_const_ctor,
    5869                 :            :                      &no_const_asn_ref);
    5870                 :            : 
    5871                 :            :   /* A nearly-empty class has to be vptr-containing; a nearly empty
    5872                 :            :      class contains just a vptr.  */
    5873                 :   34869700 :   if (!TYPE_CONTAINS_VPTR_P (t))
    5874                 :   11511100 :     CLASSTYPE_NEARLY_EMPTY_P (t) = 0;
    5875                 :            : 
    5876                 :            :   /* Do some bookkeeping that will guide the generation of implicitly
    5877                 :            :      declared member functions.  */
    5878                 :   34872300 :   TYPE_HAS_COMPLEX_COPY_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    5879                 :   34872300 :   TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_CONTAINS_VPTR_P (t);
    5880                 :            :   /* We need to call a constructor for this class if it has a
    5881                 :            :      user-provided constructor, or if the default constructor is going
    5882                 :            :      to initialize the vptr.  (This is not an if-and-only-if;
    5883                 :            :      TYPE_NEEDS_CONSTRUCTING is set elsewhere if bases or members
    5884                 :            :      themselves need constructing.)  */
    5885                 :   23356000 :   TYPE_NEEDS_CONSTRUCTING (t)
    5886                 :   33548400 :     |= (type_has_user_provided_constructor (t) || TYPE_CONTAINS_VPTR_P (t));
    5887                 :            :   /* [dcl.init.aggr]
    5888                 :            : 
    5889                 :            :      An aggregate is an array or a class with no user-provided
    5890                 :            :      constructors ... and no virtual functions.  
    5891                 :            : 
    5892                 :            :      Again, other conditions for being an aggregate are checked
    5893                 :            :      elsewhere.  */
    5894                 :   23356000 :   CLASSTYPE_NON_AGGREGATE (t)
    5895                 :   23356000 :     |= ((cxx_dialect < cxx2a
    5896                 :   11678000 :          ? type_has_user_provided_or_explicit_constructor (t)
    5897                 :    2659120 :          : TYPE_HAS_USER_CONSTRUCTOR (t))
    5898                 :   22638600 :         || TYPE_POLYMORPHIC_P (t));
    5899                 :            :   /* This is the C++98/03 definition of POD; it changed in C++0x, but we
    5900                 :            :      retain the old definition internally for ABI reasons.  */
    5901                 :   11678000 :   CLASSTYPE_NON_LAYOUT_POD_P (t)
    5902                 :   23356000 :     |= (CLASSTYPE_NON_AGGREGATE (t)
    5903                 :   18480300 :         || saved_nontrivial_dtor || saved_complex_asn_ref);
    5904                 :   34872300 :   CLASSTYPE_NON_STD_LAYOUT (t) |= TYPE_CONTAINS_VPTR_P (t);
    5905                 :   34872300 :   TYPE_HAS_COMPLEX_COPY_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    5906                 :   34872300 :   TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) |= TYPE_CONTAINS_VPTR_P (t);
    5907                 :   34872300 :   TYPE_HAS_COMPLEX_DFLT (t) |= TYPE_CONTAINS_VPTR_P (t);
    5908                 :            : 
    5909                 :            :   /* If the only explicitly declared default constructor is user-provided,
    5910                 :            :      set TYPE_HAS_COMPLEX_DFLT.  */
    5911                 :   11678000 :   if (!TYPE_HAS_COMPLEX_DFLT (t)
    5912                 :   11326600 :       && TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
    5913                 :   12073300 :       && !type_has_non_user_provided_default_constructor (t))
    5914                 :     329382 :     TYPE_HAS_COMPLEX_DFLT (t) = true;
    5915                 :            : 
    5916                 :            :   /* Warn if a public base of a polymorphic type has an accessible
    5917                 :            :      non-virtual destructor.  It is only now that we know the class is
    5918                 :            :      polymorphic.  Although a polymorphic base will have a already
    5919                 :            :      been diagnosed during its definition, we warn on use too.  */
    5920                 :   23356000 :   if (TYPE_POLYMORPHIC_P (t) && warn_nonvdtor)
    5921                 :            :     {
    5922                 :        110 :       tree binfo = TYPE_BINFO (t);
    5923                 :        110 :       vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo);
    5924                 :        110 :       tree base_binfo;
    5925                 :        110 :       unsigned i;
    5926                 :            :       
    5927                 :        149 :       for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    5928                 :            :         {
    5929                 :         39 :           tree basetype = TREE_TYPE (base_binfo);
    5930                 :            : 
    5931                 :         39 :           if ((*accesses)[i] == access_public_node
    5932                 :         23 :               && (TYPE_POLYMORPHIC_P (basetype) || warn_ecpp)
    5933                 :         58 :               && accessible_nvdtor_p (basetype))
    5934                 :         12 :             warning (OPT_Wnon_virtual_dtor,
    5935                 :            :                      "base class %q#T has accessible non-virtual destructor",
    5936                 :            :                      basetype);
    5937                 :            :         }
    5938                 :            :     }
    5939                 :            :   
    5940                 :            :   /* If the class has no user-declared constructor, but does have
    5941                 :            :      non-static const or reference data members that can never be
    5942                 :            :      initialized, issue a warning.  */
    5943                 :   11678000 :   if (warn_uninitialized
    5944                 :            :       /* Classes with user-declared constructors are presumed to
    5945                 :            :          initialize these members.  */
    5946                 :     316424 :       && !TYPE_HAS_USER_CONSTRUCTOR (t)
    5947                 :            :       /* Aggregates can be initialized with brace-enclosed
    5948                 :            :          initializers.  */
    5949                 :   11946200 :       && CLASSTYPE_NON_AGGREGATE (t))
    5950                 :            :     {
    5951                 :      56965 :       tree field;
    5952                 :            : 
    5953                 :     247585 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5954                 :            :         {
    5955                 :     190620 :           tree type;
    5956                 :            : 
    5957                 :     363141 :           if (TREE_CODE (field) != FIELD_DECL
    5958                 :     209843 :               || DECL_INITIAL (field) != NULL_TREE)
    5959                 :     172521 :             continue;
    5960                 :            : 
    5961                 :      18099 :           type = TREE_TYPE (field);
    5962                 :      18099 :           if (TYPE_REF_P (type))
    5963                 :          7 :             warning_at (DECL_SOURCE_LOCATION (field),
    5964                 :            :                         OPT_Wuninitialized, "non-static reference %q#D "
    5965                 :            :                         "in class without a constructor", field);
    5966                 :      18092 :           else if (CP_TYPE_CONST_P (type)
    5967                 :      18096 :                    && (!CLASS_TYPE_P (type)
    5968                 :          4 :                        || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type)))
    5969                 :         11 :             warning_at (DECL_SOURCE_LOCATION (field),
    5970                 :            :                         OPT_Wuninitialized, "non-static const member %q#D "
    5971                 :            :                         "in class without a constructor", field);
    5972                 :            :         }
    5973                 :            :     }
    5974                 :            : 
    5975                 :            :   /* Synthesize any needed methods.  */
    5976                 :   11678000 :   add_implicitly_declared_members (t, &access_decls,
    5977                 :            :                                    cant_have_const_ctor,
    5978                 :            :                                    no_const_asn_ref);
    5979                 :            : 
    5980                 :            :   /* Check defaulted declarations here so we have cant_have_const_ctor
    5981                 :            :      and don't need to worry about clones.  */
    5982                 :   47402800 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    5983                 :   26126800 :     if (DECL_DECLARES_FUNCTION_P (fn)
    5984                 :   11695800 :         && !DECL_ARTIFICIAL (fn)
    5985                 :   59213600 :         && DECL_DEFAULTED_IN_CLASS_P (fn))
    5986                 :            :       {
    5987                 :     357494 :         int copy = copy_fn_p (fn);
    5988                 :     357494 :         if (copy > 0)
    5989                 :            :           {
    5990                 :     167038 :             bool imp_const_p
    5991                 :     240989 :               = (DECL_CONSTRUCTOR_P (fn) ? !cant_have_const_ctor
    5992                 :     167038 :                  : !no_const_asn_ref);
    5993                 :     167038 :             bool fn_const_p = (copy == 2);
    5994                 :            : 
    5995                 :     167038 :             if (fn_const_p && !imp_const_p)
    5996                 :            :               /* If the function is defaulted outside the class, we just
    5997                 :            :                  give the synthesis error.  Core Issue #1331 says this is
    5998                 :            :                  no longer ill-formed, it is defined as deleted instead.  */
    5999                 :         18 :               DECL_DELETED_FN (fn) = true;
    6000                 :            :           }
    6001                 :     357494 :         defaulted_late_check (fn);
    6002                 :            :       }
    6003                 :            : 
    6004                 :   23256200 :   if (LAMBDA_TYPE_P (t))
    6005                 :            :     {
    6006                 :            :       /* "This class type is not an aggregate."  */
    6007                 :      34798 :       CLASSTYPE_NON_AGGREGATE (t) = 1;
    6008                 :            :     }
    6009                 :            : 
    6010                 :            :   /* Compute the 'literal type' property before we
    6011                 :            :      do anything with non-static member functions.  */
    6012                 :   11678000 :   finalize_literal_type_property (t);
    6013                 :            : 
    6014                 :            :   /* Create the in-charge and not-in-charge variants of constructors
    6015                 :            :      and destructors.  */
    6016                 :   11678000 :   clone_constructors_and_destructors (t);
    6017                 :            : 
    6018                 :            :   /* Process the using-declarations.  */
    6019                 :   11783100 :   for (; access_decls; access_decls = TREE_CHAIN (access_decls))
    6020                 :     105115 :     handle_using_decl (TREE_VALUE (access_decls), t);
    6021                 :            : 
    6022                 :            :   /* Figure out whether or not we will need a cookie when dynamically
    6023                 :            :      allocating an array of this type.  */
    6024                 :   11678000 :   LANG_TYPE_CLASS_CHECK (t)->vec_new_uses_cookie
    6025                 :   11678000 :     = type_requires_array_cookie (t);
    6026                 :   11678000 : }
    6027                 :            : 
    6028                 :            : /* If T needs a pointer to its virtual function table, set TYPE_VFIELD
    6029                 :            :    accordingly.  If a new vfield was created (because T doesn't have a
    6030                 :            :    primary base class), then the newly created field is returned.  It
    6031                 :            :    is not added to the TYPE_FIELDS list; it is the caller's
    6032                 :            :    responsibility to do that.  Accumulate declared virtual functions
    6033                 :            :    on VIRTUALS_P.  */
    6034                 :            : 
    6035                 :            : static tree
    6036                 :   11678000 : create_vtable_ptr (tree t, tree* virtuals_p)
    6037                 :            : {
    6038                 :   11678000 :   tree fn;
    6039                 :            : 
    6040                 :            :   /* Collect the virtual functions declared in T.  */
    6041                 :   52783600 :   for (fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
    6042                 :   41005800 :     if (TREE_CODE (fn) == FUNCTION_DECL
    6043                 :   14635500 :         && DECL_VINDEX (fn) && !DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn)
    6044                 :   41687800 :         && TREE_CODE (DECL_VINDEX (fn)) != INTEGER_CST)
    6045                 :            :       {
    6046                 :     682018 :         tree new_virtual = make_node (TREE_LIST);
    6047                 :            : 
    6048                 :     682018 :         BV_FN (new_virtual) = fn;
    6049                 :     682018 :         BV_DELTA (new_virtual) = integer_zero_node;
    6050                 :     682018 :         BV_VCALL_INDEX (new_virtual) = NULL_TREE;
    6051                 :            : 
    6052                 :     682018 :         TREE_CHAIN (new_virtual) = *virtuals_p;
    6053                 :     682018 :         *virtuals_p = new_virtual;
    6054                 :            :       }
    6055                 :            : 
    6056                 :            :   /* If we couldn't find an appropriate base class, create a new field
    6057                 :            :      here.  Even if there weren't any new virtual functions, we might need a
    6058                 :            :      new virtual function table if we're supposed to include vptrs in
    6059                 :            :      all classes that need them.  */
    6060                 :   34803200 :   if (!TYPE_VFIELD (t) && (*virtuals_p || TYPE_CONTAINS_VPTR_P (t)))
    6061                 :            :     {
    6062                 :            :       /* We build this decl with vtbl_ptr_type_node, which is a
    6063                 :            :          `vtable_entry_type*'.  It might seem more precise to use
    6064                 :            :          `vtable_entry_type (*)[N]' where N is the number of virtual
    6065                 :            :          functions.  However, that would require the vtable pointer in
    6066                 :            :          base classes to have a different type than the vtable pointer
    6067                 :            :          in derived classes.  We could make that happen, but that
    6068                 :            :          still wouldn't solve all the problems.  In particular, the
    6069                 :            :          type-based alias analysis code would decide that assignments
    6070                 :            :          to the base class vtable pointer can't alias assignments to
    6071                 :            :          the derived class vtable pointer, since they have different
    6072                 :            :          types.  Thus, in a derived class destructor, where the base
    6073                 :            :          class constructor was inlined, we could generate bad code for
    6074                 :            :          setting up the vtable pointer.
    6075                 :            : 
    6076                 :            :          Therefore, we use one type for all vtable pointers.  We still
    6077                 :            :          use a type-correct type; it's just doesn't indicate the array
    6078                 :            :          bounds.  That's better than using `void*' or some such; it's
    6079                 :            :          cleaner, and it let's the alias analysis code know that these
    6080                 :            :          stores cannot alias stores to void*!  */
    6081                 :      39330 :       tree field;
    6082                 :            : 
    6083                 :      39330 :       field = build_decl (input_location, 
    6084                 :            :                           FIELD_DECL, get_vfield_name (t), vtbl_ptr_type_node);
    6085                 :      39330 :       DECL_VIRTUAL_P (field) = 1;
    6086                 :      39330 :       DECL_ARTIFICIAL (field) = 1;
    6087                 :      39330 :       DECL_FIELD_CONTEXT (field) = t;
    6088                 :      39330 :       DECL_FCONTEXT (field) = t;
    6089                 :      39330 :       if (TYPE_PACKED (t))
    6090                 :          4 :         DECL_PACKED (field) = 1;
    6091                 :            : 
    6092                 :      39330 :       TYPE_VFIELD (t) = field;
    6093                 :            : 
    6094                 :            :       /* This class is non-empty.  */
    6095                 :      39330 :       CLASSTYPE_EMPTY_P (t) = 0;
    6096                 :            : 
    6097                 :      39330 :       return field;
    6098                 :            :     }
    6099                 :            : 
    6100                 :            :   return NULL_TREE;
    6101                 :            : }
    6102                 :            : 
    6103                 :            : /* Add OFFSET to all base types of BINFO which is a base in the
    6104                 :            :    hierarchy dominated by T.
    6105                 :            : 
    6106                 :            :    OFFSET, which is a type offset, is number of bytes.  */
    6107                 :            : 
    6108                 :            : static void
    6109                 :   11041100 : propagate_binfo_offsets (tree binfo, tree offset)
    6110                 :            : {
    6111                 :   11041100 :   int i;
    6112                 :   11041100 :   tree primary_binfo;
    6113                 :   11041100 :   tree base_binfo;
    6114                 :            : 
    6115                 :            :   /* Update BINFO's offset.  */
    6116                 :   11041100 :   BINFO_OFFSET (binfo)
    6117                 :   11041100 :     = fold_convert (sizetype,
    6118                 :            :                size_binop (PLUS_EXPR,
    6119                 :            :                            fold_convert (ssizetype, BINFO_OFFSET (binfo)),
    6120                 :            :                            offset));
    6121                 :            : 
    6122                 :            :   /* Find the primary base class.  */
    6123                 :   11041100 :   primary_binfo = get_primary_binfo (binfo);
    6124                 :            : 
    6125                 :   11119500 :   if (primary_binfo && BINFO_INHERITANCE_CHAIN (primary_binfo) == binfo)
    6126                 :      77162 :     propagate_binfo_offsets (primary_binfo, offset);
    6127                 :            : 
    6128                 :            :   /* Scan all of the bases, pushing the BINFO_OFFSET adjust
    6129                 :            :      downwards.  */
    6130                 :   15638900 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6131                 :            :     {
    6132                 :            :       /* Don't do the primary base twice.  */
    6133                 :    4597740 :       if (base_binfo == primary_binfo)
    6134                 :      78260 :         continue;
    6135                 :            : 
    6136                 :    4519480 :       if (BINFO_VIRTUAL_P (base_binfo))
    6137                 :      32860 :         continue;
    6138                 :            : 
    6139                 :    4486620 :       propagate_binfo_offsets (base_binfo, offset);
    6140                 :            :     }
    6141                 :   11041100 : }
    6142                 :            : 
    6143                 :            : /* Set BINFO_OFFSET for all of the virtual bases for RLI->T.  Update
    6144                 :            :    TYPE_ALIGN and TYPE_SIZE for T.  OFFSETS gives the location of
    6145                 :            :    empty subobjects of T.  */
    6146                 :            : 
    6147                 :            : static void
    6148                 :   11678000 : layout_virtual_bases (record_layout_info rli, splay_tree offsets)
    6149                 :            : {
    6150                 :   11678000 :   tree vbase;
    6151                 :   11678000 :   tree t = rli->t;
    6152                 :   11678000 :   tree *next_field;
    6153                 :            : 
    6154                 :   11777800 :   if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) == 0)
    6155                 :            :     return;
    6156                 :            : 
    6157                 :            :   /* Find the last field.  The artificial fields created for virtual
    6158                 :            :      bases will go after the last extant field to date.  */
    6159                 :    6416010 :   next_field = &TYPE_FIELDS (t);
    6160                 :   22742000 :   while (*next_field)
    6161                 :   16326000 :     next_field = &DECL_CHAIN (*next_field);
    6162                 :            : 
    6163                 :            :   /* Go through the virtual bases, allocating space for each virtual
    6164                 :            :      base that is not already a primary base class.  These are
    6165                 :            :      allocated in inheritance graph order.  */
    6166                 :   30279600 :   for (vbase = TYPE_BINFO (t); vbase; vbase = TREE_CHAIN (vbase))
    6167                 :            :     {
    6168                 :   17447600 :       if (!BINFO_VIRTUAL_P (vbase))
    6169                 :   17418300 :         continue;
    6170                 :            : 
    6171                 :      29308 :       if (!BINFO_PRIMARY_P (vbase))
    6172                 :            :         {
    6173                 :            :           /* This virtual base is not a primary base of any class in the
    6174                 :            :              hierarchy, so we have to add space for it.  */
    6175                 :      20821 :           next_field = build_base_field (rli, vbase,
    6176                 :            :                                          access_private_node,
    6177                 :            :                                          offsets, next_field);
    6178                 :            :         }
    6179                 :            :     }
    6180                 :            : }
    6181                 :            : 
    6182                 :            : /* Returns the offset of the byte just past the end of the base class
    6183                 :            :    BINFO.  */
    6184                 :            : 
    6185                 :            : static tree
    6186                 :   12932700 : end_of_base (tree binfo)
    6187                 :            : {
    6188                 :   12932700 :   tree size;
    6189                 :            : 
    6190                 :   12932700 :   if (!CLASSTYPE_AS_BASE (BINFO_TYPE (binfo)))
    6191                 :          0 :     size = TYPE_SIZE_UNIT (char_type_node);
    6192                 :   12932700 :   else if (is_empty_class (BINFO_TYPE (binfo)))
    6193                 :            :     /* An empty class has zero CLASSTYPE_SIZE_UNIT, but we need to
    6194                 :            :        allocate some space for it. It cannot have virtual bases, so
    6195                 :            :        TYPE_SIZE_UNIT is fine.  */
    6196                 :   12531200 :     size = TYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6197                 :            :   else
    6198                 :     401470 :     size = CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo));
    6199                 :            : 
    6200                 :   12932700 :   return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
    6201                 :            : }
    6202                 :            : 
    6203                 :            : /* Returns the offset of the byte just past the end of the base class or empty
    6204                 :            :    data member with the highest offset in T.  If INCLUDE_VIRTUALS_P is zero,
    6205                 :            :    then only non-virtual bases are included.  */
    6206                 :            : 
    6207                 :            : static tree
    6208                 :   23041700 : end_of_class (tree t, bool include_virtuals_p)
    6209                 :            : {
    6210                 :   23041700 :   tree result = size_zero_node;
    6211                 :   23041700 :   vec<tree, va_gc> *vbases;
    6212                 :   23041700 :   tree binfo;
    6213                 :   23041700 :   tree base_binfo;
    6214                 :   23041700 :   tree offset;
    6215                 :   23041700 :   int i;
    6216                 :            : 
    6217                 :   36056300 :   for (binfo = TYPE_BINFO (t), i = 0;
    6218                 :   35952600 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6219                 :            :     {
    6220                 :   12918300 :       if (!include_virtuals_p
    6221                 :    6455320 :           && BINFO_VIRTUAL_P (base_binfo)
    6222                 :   12920000 :           && (!BINFO_PRIMARY_P (base_binfo)
    6223                 :       1938 :               || BINFO_INHERITANCE_CHAIN (base_binfo) != TYPE_BINFO (t)))
    6224                 :       7439 :         continue;
    6225                 :            : 
    6226                 :   12903400 :       offset = end_of_base (base_binfo);
    6227                 :   12903400 :       if (tree_int_cst_lt (result, offset))
    6228                 :   12850500 :         result = offset;
    6229                 :            :     }
    6230                 :            : 
    6231                 :            :   /* Also consider empty data members.  */
    6232                 :  108031000 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6233                 :   84885600 :     if (TREE_CODE (field) == FIELD_DECL
    6234                 :    7861820 :         && !DECL_ARTIFICIAL (field)
    6235                 :    3228330 :         && field_poverlapping_p (field)
    6236                 :   84894600 :         && is_empty_class (TREE_TYPE (field)))
    6237                 :            :       {
    6238                 :            :         /* Update sizeof(C) to max (sizeof(C), offset(D)+sizeof(D)) */
    6239                 :       7876 :         offset = size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (field),
    6240                 :            :                              TYPE_SIZE_UNIT (TREE_TYPE (field)));
    6241                 :       7876 :         if (tree_int_cst_lt (result, offset))
    6242                 :       7706 :           result = offset;
    6243                 :            :       }
    6244                 :            : 
    6245                 :   23041700 :   if (include_virtuals_p)
    6246                 :   11711700 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6247                 :   11711700 :          vec_safe_iterate (vbases, i, &base_binfo); i++)
    6248                 :            :       {
    6249                 :      29311 :         offset = end_of_base (base_binfo);
    6250                 :      29311 :         if (tree_int_cst_lt (result, offset))
    6251                 :      12366 :           result = offset;
    6252                 :            :       }
    6253                 :            : 
    6254                 :   23041700 :   return result;
    6255                 :            : }
    6256                 :            : 
    6257                 :            : /* Warn about bases of T that are inaccessible because they are
    6258                 :            :    ambiguous.  For example:
    6259                 :            : 
    6260                 :            :      struct S {};
    6261                 :            :      struct T : public S {};
    6262                 :            :      struct U : public S, public T {};
    6263                 :            : 
    6264                 :            :    Here, `(S*) new U' is not allowed because there are two `S'
    6265                 :            :    subobjects of U.  */
    6266                 :            : 
    6267                 :            : static void
    6268                 :   11678000 : maybe_warn_about_inaccessible_bases (tree t)
    6269                 :            : {
    6270                 :   11678000 :   int i;
    6271                 :   11678000 :   vec<tree, va_gc> *vbases;
    6272                 :   11678000 :   tree basetype;
    6273                 :   11678000 :   tree binfo;
    6274                 :   11678000 :   tree base_binfo;
    6275                 :            : 
    6276                 :            :   /* If not checking for warning then return early.  */
    6277                 :   11678000 :   if (!warn_inaccessible_base)
    6278                 :   11678000 :     return;
    6279                 :            : 
    6280                 :            :   /* If there are no repeated bases, nothing can be ambiguous.  */
    6281                 :   11678000 :   if (!CLASSTYPE_REPEATED_BASE_P (t))
    6282                 :            :     return;
    6283                 :            : 
    6284                 :            :   /* Check direct bases.  */
    6285                 :       4598 :   for (binfo = TYPE_BINFO (t), i = 0;
    6286                 :       4598 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    6287                 :            :     {
    6288                 :       3317 :       basetype = BINFO_TYPE (base_binfo);
    6289                 :            : 
    6290                 :       3317 :       if (!uniquely_derived_from_p (basetype, t))
    6291                 :        969 :         warning (OPT_Winaccessible_base, "direct base %qT inaccessible "
    6292                 :            :                  "in %qT due to ambiguity", basetype, t);
    6293                 :            :     }
    6294                 :            : 
    6295                 :            :   /* Check for ambiguous virtual bases.  */
    6296                 :       1281 :   if (extra_warnings)
    6297                 :          8 :     for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    6298                 :          8 :          vec_safe_iterate (vbases, i, &binfo); i++)
    6299                 :            :       {
    6300                 :          4 :         basetype = BINFO_TYPE (binfo);
    6301                 :            : 
    6302                 :          4 :         if (!uniquely_derived_from_p (basetype, t))
    6303                 :          4 :           warning (OPT_Winaccessible_base, "virtual base %qT inaccessible in "
    6304                 :            :                    "%qT due to ambiguity", basetype, t);
    6305                 :            :       }
    6306                 :            : }
    6307                 :            : 
    6308                 :            : /* Compare two INTEGER_CSTs K1 and K2.  */
    6309                 :            : 
    6310                 :            : static int
    6311                 :    9523420 : splay_tree_compare_integer_csts (splay_tree_key k1, splay_tree_key k2)
    6312                 :            : {
    6313                 :    9523420 :   return tree_int_cst_compare ((tree) k1, (tree) k2);
    6314                 :            : }
    6315                 :            : 
    6316                 :            : /* Increase the size indicated in RLI to account for empty classes
    6317                 :            :    that are "off the end" of the class.  */
    6318                 :            : 
    6319                 :            : static void
    6320                 :   11678000 : include_empty_classes (record_layout_info rli)
    6321                 :            : {
    6322                 :   11678000 :   tree eoc;
    6323                 :   11678000 :   tree rli_size;
    6324                 :            : 
    6325                 :            :   /* It might be the case that we grew the class to allocate a
    6326                 :            :      zero-sized base class.  That won't be reflected in RLI, yet,
    6327                 :            :      because we are willing to overlay multiple bases at the same
    6328                 :            :      offset.  However, now we need to make sure that RLI is big enough
    6329                 :            :      to reflect the entire class.  */
    6330                 :   11678000 :   eoc = end_of_class (rli->t, CLASSTYPE_AS_BASE (rli->t) != NULL_TREE);
    6331                 :   11678000 :   rli_size = rli_size_unit_so_far (rli);
    6332                 :   11678000 :   if (TREE_CODE (rli_size) == INTEGER_CST
    6333                 :   11678000 :       && tree_int_cst_lt (rli_size, eoc))
    6334                 :            :     {
    6335                 :            :       /* The size should have been rounded to a whole byte.  */
    6336                 :    6179120 :       gcc_assert (tree_int_cst_equal
    6337                 :            :                   (rli->bitpos, round_down (rli->bitpos, BITS_PER_UNIT)));
    6338                 :    6179120 :       rli->bitpos
    6339                 :    6179120 :         = size_binop (PLUS_EXPR,
    6340                 :            :                       rli->bitpos,
    6341                 :            :                       size_binop (MULT_EXPR,
    6342                 :            :                                   fold_convert (bitsizetype,
    6343                 :            :                                            size_binop (MINUS_EXPR,
    6344                 :            :                                                        eoc, rli_size)),
    6345                 :            :                                   bitsize_int (BITS_PER_UNIT)));
    6346                 :    6179120 :       normalize_rli (rli);
    6347                 :            :     }
    6348                 :   11678000 : }
    6349                 :            : 
    6350                 :            : /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T.  Calculate
    6351                 :            :    BINFO_OFFSETs for all of the base-classes.  Position the vtable
    6352                 :            :    pointer.  Accumulate declared virtual functions on VIRTUALS_P.  */
    6353                 :            : 
    6354                 :            : static void
    6355                 :   11678000 : layout_class_type (tree t, tree *virtuals_p)
    6356                 :            : {
    6357                 :   11678000 :   tree non_static_data_members;
    6358                 :   11678000 :   tree field;
    6359                 :   11678000 :   tree vptr;
    6360                 :   11678000 :   record_layout_info rli;
    6361                 :            :   /* Maps offsets (represented as INTEGER_CSTs) to a TREE_LIST of
    6362                 :            :      types that appear at that offset.  */
    6363                 :   11678000 :   splay_tree empty_base_offsets;
    6364                 :            :   /* True if the last field laid out was a bit-field.  */
    6365                 :   11678000 :   bool last_field_was_bitfield = false;
    6366                 :            :   /* The location at which the next field should be inserted.  */
    6367                 :   11678000 :   tree *next_field;
    6368                 :            : 
    6369                 :            :   /* Keep track of the first non-static data member.  */
    6370                 :   11678000 :   non_static_data_members = TYPE_FIELDS (t);
    6371                 :            : 
    6372                 :            :   /* Start laying out the record.  */
    6373                 :   11678000 :   rli = start_record_layout (t);
    6374                 :            : 
    6375                 :            :   /* Mark all the primary bases in the hierarchy.  */
    6376                 :   11678000 :   determine_primary_bases (t);
    6377                 :            : 
    6378                 :            :   /* Create a pointer to our virtual function table.  */
    6379                 :   11678000 :   vptr = create_vtable_ptr (t, virtuals_p);
    6380                 :            : 
    6381                 :            :   /* The vptr is always the first thing in the class.  */
    6382                 :   11678000 :   if (vptr)
    6383                 :            :     {
    6384                 :      39330 :       DECL_CHAIN (vptr) = TYPE_FIELDS (t);
    6385                 :      39330 :       TYPE_FIELDS (t) = vptr;
    6386                 :      39330 :       next_field = &DECL_CHAIN (vptr);
    6387                 :      39330 :       place_field (rli, vptr);
    6388                 :            :     }
    6389                 :            :   else
    6390                 :   11738500 :     next_field = &TYPE_FIELDS (t);
    6391                 :            : 
    6392                 :            :   /* Build FIELD_DECLs for all of the non-virtual base-types.  */
    6393                 :   11678000 :   empty_base_offsets = splay_tree_new (splay_tree_compare_integer_csts,
    6394                 :            :                                        NULL, NULL);
    6395                 :   11678000 :   build_base_fields (rli, empty_base_offsets, next_field);
    6396                 :            : 
    6397                 :            :   /* Layout the non-static data members.  */
    6398                 :   52683800 :   for (field = non_static_data_members; field; field = DECL_CHAIN (field))
    6399                 :            :     {
    6400                 :   41005800 :       tree type;
    6401                 :   41005800 :       tree padding;
    6402                 :            : 
    6403                 :            :       /* We still pass things that aren't non-static data members to
    6404                 :            :          the back end, in case it wants to do something with them.  */
    6405                 :   41005800 :       if (TREE_CODE (field) != FIELD_DECL)
    6406                 :            :         {
    6407                 :   38699600 :           place_field (rli, field);
    6408                 :            :           /* If the static data member has incomplete type, keep track
    6409                 :            :              of it so that it can be completed later.  (The handling
    6410                 :            :              of pending statics in finish_record_layout is
    6411                 :            :              insufficient; consider:
    6412                 :            : 
    6413                 :            :                struct S1;
    6414                 :            :                struct S2 { static S1 s1; };
    6415                 :            : 
    6416                 :            :              At this point, finish_record_layout will be called, but
    6417                 :            :              S1 is still incomplete.)  */
    6418                 :   38699600 :           if (VAR_P (field))
    6419                 :            :             {
    6420                 :    1181310 :               maybe_register_incomplete_var (field);
    6421                 :            :               /* The visibility of static data members is determined
    6422                 :            :                  at their point of declaration, not their point of
    6423                 :            :                  definition.  */
    6424                 :    1181310 :               determine_visibility (field);
    6425                 :            :             }
    6426                 :   38699600 :           continue;
    6427                 :            :         }
    6428                 :            : 
    6429                 :    2306200 :       type = TREE_TYPE (field);
    6430                 :    2306200 :       if (type == error_mark_node)
    6431                 :        195 :         continue;
    6432                 :            : 
    6433                 :    2306000 :       padding = NULL_TREE;
    6434                 :            : 
    6435                 :    2306000 :       bool might_overlap = field_poverlapping_p (field);
    6436                 :            : 
    6437                 :       8872 :       if (might_overlap && CLASS_TYPE_P (type)
    6438                 :    2310360 :           && (CLASSTYPE_NON_LAYOUT_POD_P (type) || CLASSTYPE_EMPTY_P (type)))
    6439                 :            :         {
    6440                 :            :           /* if D is a potentially-overlapping data member, update sizeof(C) to
    6441                 :            :              max (sizeof(C), offset(D)+max (nvsize(D), dsize(D))).  */
    6442                 :       4327 :           tree nvsize = CLASSTYPE_SIZE_UNIT (type);
    6443                 :            :           /* end_of_class doesn't always give dsize, but it does in the case of
    6444                 :            :              a class with virtual bases, which is when dsize > nvsize.  */
    6445                 :       4327 :           tree dsize = end_of_class (type, /*vbases*/true);
    6446                 :       4327 :           if (tree_int_cst_le (dsize, nvsize))
    6447                 :            :             {
    6448                 :       4324 :               DECL_SIZE_UNIT (field) = nvsize;
    6449                 :       4324 :               DECL_SIZE (field) = CLASSTYPE_SIZE (type);
    6450                 :            :             }
    6451                 :            :           else
    6452                 :            :             {
    6453                 :          3 :               DECL_SIZE_UNIT (field) = dsize;
    6454                 :          3 :               DECL_SIZE (field) = bit_from_pos (dsize, bitsize_zero_node);
    6455                 :            :             }
    6456                 :            :         }
    6457                 :            : 
    6458                 :            :       /* If this field is a bit-field whose width is greater than its
    6459                 :            :          type, then there are some special rules for allocating
    6460                 :            :          it.  */
    6461                 :    2306000 :       if (DECL_C_BIT_FIELD (field)
    6462                 :    2306000 :           && tree_int_cst_lt (TYPE_SIZE (type), DECL_SIZE (field)))
    6463                 :            :         {
    6464                 :        458 :           bool was_unnamed_p = false;
    6465                 :            :           /* We must allocate the bits as if suitably aligned for the
    6466                 :            :              longest integer type that fits in this many bits.  Then,
    6467                 :            :              we are supposed to use the left over bits as additional
    6468                 :            :              padding.  */
    6469                 :            : 
    6470                 :            :           /* Do not pick a type bigger than MAX_FIXED_MODE_SIZE.  */
    6471                 :        916 :           tree limit = size_int (MAX_FIXED_MODE_SIZE);
    6472                 :        458 :           if (tree_int_cst_lt (DECL_SIZE (field), limit))
    6473                 :        439 :             limit = DECL_SIZE (field);
    6474                 :            : 
    6475                 :        458 :           tree integer_type = integer_types[itk_char];
    6476                 :       3874 :           for (unsigned itk = itk_char; itk != itk_none; itk++)
    6477                 :       3855 :             if (tree next = integer_types[itk])
    6478                 :            :               {
    6479                 :       3741 :                 if (tree_int_cst_lt (limit, TYPE_SIZE (next)))
    6480                 :            :                   /* Too big, so our current guess is what we want.  */
    6481                 :            :                   break;
    6482                 :            :                 /* Not bigger than limit, ok  */
    6483                 :            :                 integer_type = next;
    6484                 :            :               }
    6485                 :            : 
    6486                 :            :           /* Figure out how much additional padding is required.  */
    6487                 :        458 :           if (TREE_CODE (t) == UNION_TYPE)
    6488                 :            :             /* In a union, the padding field must have the full width
    6489                 :            :                of the bit-field; all fields start at offset zero.  */
    6490                 :         55 :             padding = DECL_SIZE (field);
    6491                 :            :           else
    6492                 :        403 :             padding = size_binop (MINUS_EXPR, DECL_SIZE (field),
    6493                 :            :                                   TYPE_SIZE (integer_type));
    6494                 :            : 
    6495                 :        458 :           if (integer_zerop (padding))
    6496                 :          7 :             padding = NULL_TREE;
    6497                 :            : 
    6498                 :            :           /* An unnamed bitfield does not normally affect the
    6499                 :            :              alignment of the containing class on a target where
    6500                 :            :              PCC_BITFIELD_TYPE_MATTERS.  But, the C++ ABI does not
    6501                 :            :              make any exceptions for unnamed bitfields when the
    6502                 :            :              bitfields are longer than their types.  Therefore, we
    6503                 :            :              temporarily give the field a name.  */
    6504                 :        458 :           if (PCC_BITFIELD_TYPE_MATTERS && !DECL_NAME (field))
    6505                 :            :             {
    6506                 :          0 :               was_unnamed_p = true;
    6507                 :          0 :               DECL_NAME (field) = make_anon_name ();
    6508                 :            :             }
    6509                 :            : 
    6510                 :        458 :           DECL_SIZE (field) = TYPE_SIZE (integer_type);
    6511                 :        458 :           SET_DECL_ALIGN (field, TYPE_ALIGN (integer_type));
    6512                 :        458 :           DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
    6513                 :        458 :           layout_nonempty_base_or_field (rli, field, NULL_TREE,
    6514                 :            :                                          empty_base_offsets);
    6515                 :        458 :           if (was_unnamed_p)
    6516                 :          0 :             DECL_NAME (field) = NULL_TREE;
    6517                 :            :           /* Now that layout has been performed, set the size of the
    6518                 :            :              field to the size of its declared type; the rest of the
    6519                 :            :              field is effectively invisible.  */
    6520                 :        458 :           DECL_SIZE (field) = TYPE_SIZE (type);
    6521                 :            :           /* We must also reset the DECL_MODE of the field.  */
    6522                 :        916 :           SET_DECL_MODE (field, TYPE_MODE (type));
    6523                 :            :         }
    6524                 :    2305540 :       else if (might_overlap && is_empty_class (type))
    6525                 :       3936 :         layout_empty_base_or_field (rli, field, empty_base_offsets);
    6526                 :            :       else
    6527                 :    2301610 :         layout_nonempty_base_or_field (rli, field, NULL_TREE,
    6528                 :            :                                        empty_base_offsets);
    6529                 :            : 
    6530                 :            :       /* Remember the location of any empty classes in FIELD.  */
    6531                 :    2306000 :       record_subobject_offsets (field, empty_base_offsets);
    6532                 :            : 
    6533                 :            :       /* If a bit-field does not immediately follow another bit-field,
    6534                 :            :          and yet it starts in the middle of a byte, we have failed to
    6535                 :            :          comply with the ABI.  */
    6536                 :    2306000 :       if (warn_abi
    6537                 :      92704 :           && DECL_C_BIT_FIELD (field)
    6538                 :            :           /* The TREE_NO_WARNING flag gets set by Objective-C when
    6539                 :            :              laying out an Objective-C class.  The ObjC ABI differs
    6540                 :            :              from the C++ ABI, and so we do not want a warning
    6541                 :            :              here.  */
    6542                 :       2592 :           && !TREE_NO_WARNING (field)
    6543                 :         22 :           && !last_field_was_bitfield
    6544                 :    2306010 :           && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
    6545                 :            :                                          DECL_FIELD_BIT_OFFSET (field),
    6546                 :            :                                          bitsize_unit_node)))
    6547                 :          0 :         warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi,
    6548                 :            :                     "offset of %qD is not ABI-compliant and may "
    6549                 :            :                     "change in a future version of GCC", field);
    6550                 :            : 
    6551                 :            :       /* The middle end uses the type of expressions to determine the
    6552                 :            :          possible range of expression values.  In order to optimize
    6553                 :            :          "x.i > 7" to "false" for a 2-bit bitfield "i", the middle end
    6554                 :            :          must be made aware of the width of "i", via its type.
    6555                 :            : 
    6556                 :            :          Because C++ does not have integer types of arbitrary width,
    6557                 :            :          we must (for the purposes of the front end) convert from the
    6558                 :            :          type assigned here to the declared type of the bitfield
    6559                 :            :          whenever a bitfield expression is used as an rvalue.
    6560                 :            :          Similarly, when assigning a value to a bitfield, the value
    6561                 :            :          must be converted to the type given the bitfield here.  */
    6562                 :    2306000 :       if (DECL_C_BIT_FIELD (field))
    6563                 :            :         {
    6564                 :      45727 :           unsigned HOST_WIDE_INT width;
    6565                 :      45727 :           tree ftype = TREE_TYPE (field);
    6566                 :      45727 :           width = tree_to_uhwi (DECL_SIZE (field));
    6567                 :      45727 :           if (width != TYPE_PRECISION (ftype))
    6568                 :            :             {
    6569                 :      11414 :               TREE_TYPE (field)
    6570                 :      22828 :                 = c_build_bitfield_integer_type (width,
    6571                 :      11414 :                                                  TYPE_UNSIGNED (ftype));
    6572                 :      11414 :               TREE_TYPE (field)
    6573                 :      11414 :                 = cp_build_qualified_type (TREE_TYPE (field),
    6574                 :            :                                            cp_type_quals (ftype));
    6575                 :            :             }
    6576                 :            :         }
    6577                 :            : 
    6578                 :            :       /* If we needed additional padding after this field, add it
    6579                 :            :          now.  */
    6580                 :    2306000 :       if (padding)
    6581                 :            :         {
    6582                 :        451 :           tree padding_field;
    6583                 :            : 
    6584                 :        451 :           padding_field = build_decl (input_location,
    6585                 :            :                                       FIELD_DECL,
    6586                 :            :                                       NULL_TREE,
    6587                 :            :                                       char_type_node);
    6588                 :        451 :           DECL_BIT_FIELD (padding_field) = 1;
    6589                 :        451 :           DECL_SIZE (padding_field) = padding;
    6590                 :        451 :           DECL_CONTEXT (padding_field) = t;
    6591                 :        451 :           DECL_ARTIFICIAL (padding_field) = 1;
    6592                 :        451 :           DECL_IGNORED_P (padding_field) = 1;
    6593                 :        451 :           DECL_PADDING_P (padding_field) = 1;
    6594                 :        451 :           layout_nonempty_base_or_field (rli, padding_field,
    6595                 :            :                                          NULL_TREE,
    6596                 :            :                                          empty_base_offsets);
    6597                 :            :         }
    6598                 :            : 
    6599                 :    2306000 :       last_field_was_bitfield = DECL_C_BIT_FIELD (field);
    6600                 :            :     }
    6601                 :            : 
    6602                 :   11678000 :   if (!integer_zerop (rli->bitpos))
    6603                 :            :     {
    6604                 :            :       /* Make sure that we are on a byte boundary so that the size of
    6605                 :            :          the class without virtual bases will always be a round number
    6606                 :            :          of bytes.  */
    6607                 :     604434 :       rli->bitpos = round_up_loc (input_location, rli->bitpos, BITS_PER_UNIT);
    6608                 :     604434 :       normalize_rli (rli);
    6609                 :            :     }
    6610                 :            : 
    6611                 :            :   /* Delete all zero-width bit-fields from the list of fields.  Now
    6612                 :            :      that the type is laid out they are no longer important.  */
    6613                 :   11678000 :   remove_zero_width_bit_fields (t);
    6614                 :            : 
    6615                 :   11678000 :   if (CLASSTYPE_NON_LAYOUT_POD_P (t) || CLASSTYPE_EMPTY_P (t))
    6616                 :            :     {
    6617                 :            :       /* T needs a different layout as a base (eliding virtual bases
    6618                 :            :          or whatever).  Create that version.  */
    6619                 :   11359400 :       tree base_t = make_node (TREE_CODE (t));
    6620                 :            : 
    6621                 :            :       /* If the ABI version is not at least two, and the last
    6622                 :            :          field was a bit-field, RLI may not be on a byte
    6623                 :            :          boundary.  In particular, rli_size_unit_so_far might
    6624                 :            :          indicate the last complete byte, while rli_size_so_far
    6625                 :            :          indicates the total number of bits used.  Therefore,
    6626                 :            :          rli_size_so_far, rather than rli_size_unit_so_far, is
    6627                 :            :          used to compute TYPE_SIZE_UNIT.  */
    6628                 :   11359400 :       tree eoc = end_of_class (t, /*include_virtuals_p=*/0);
    6629                 :   22718800 :       TYPE_SIZE_UNIT (base_t)
    6630                 :   11359400 :         = size_binop (MAX_EXPR,
    6631                 :            :                       fold_convert (sizetype,
    6632                 :            :                                size_binop (CEIL_DIV_EXPR,
    6633                 :            :                                            rli_size_so_far (rli),
    6634                 :            :                                            bitsize_int (BITS_PER_UNIT))),
    6635                 :            :                       eoc);
    6636                 :   22718800 :       TYPE_SIZE (base_t)
    6637                 :   11359400 :         = size_binop (MAX_EXPR,
    6638                 :            :                       rli_size_so_far (rli),
    6639                 :            :                       size_binop (MULT_EXPR,
    6640                 :            :                                   fold_convert (bitsizetype, eoc),
    6641                 :            :                                   bitsize_int (BITS_PER_UNIT)));
    6642                 :   11359400 :       SET_TYPE_ALIGN (base_t, rli->record_align);
    6643                 :   11359400 :       TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
    6644                 :   11359400 :       TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
    6645                 :   11363400 :       TYPE_CXX_ODR_P (base_t) = TYPE_CXX_ODR_P (t);
    6646                 :            : 
    6647                 :            :       /* Copy the non-static data members of T. This will include its
    6648                 :            :          direct non-virtual bases & vtable.  */
    6649                 :   11359400 :       next_field = &TYPE_FIELDS (base_t);
    6650                 :   52861900 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6651                 :   41498500 :         if (TREE_CODE (field) == FIELD_DECL)
    6652                 :            :           {
    6653                 :    3229900 :             *next_field = copy_node (field);
    6654                 :    3229900 :             DECL_CONTEXT (*next_field) = base_t;
    6655                 :    3229900 :             next_field = &DECL_CHAIN (*next_field);
    6656                 :            :           }
    6657                 :   11359400 :       *next_field = NULL_TREE;
    6658                 :            : 
    6659                 :            :       /* We use the base type for trivial assignments, and hence it
    6660                 :            :          needs a mode.  */
    6661                 :   11359400 :       compute_record_mode (base_t);
    6662                 :            : 
    6663                 :   11359400 :       TYPE_CONTEXT (base_t) = t;
    6664                 :            : 
    6665                 :            :       /* Record the base version of the type.  */
    6666                 :   11359400 :       CLASSTYPE_AS_BASE (t) = base_t;
    6667                 :            :     }
    6668                 :            :   else
    6669                 :     318624 :     CLASSTYPE_AS_BASE (t) = t;
    6670                 :            : 
    6671                 :            :   /* Every empty class contains an empty class.  */
    6672                 :   11678000 :   if (CLASSTYPE_EMPTY_P (t))
    6673                 :   10693600 :     CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 1;
    6674                 :            : 
    6675                 :            :   /* Set the TYPE_DECL for this type to contain the right
    6676                 :            :      value for DECL_OFFSET, so that we can use it as part
    6677                 :            :      of a COMPONENT_REF for multiple inheritance.  */
    6678                 :   11678000 :   layout_decl (TYPE_MAIN_DECL (t), 0);
    6679                 :            : 
    6680                 :            :   /* Now fix up any virtual base class types that we left lying
    6681                 :            :      around.  We must get these done before we try to lay out the
    6682                 :            :      virtual function table.  As a side-effect, this will remove the
    6683                 :            :      base subobject fields.  */
    6684                 :   11678000 :   layout_virtual_bases (rli, empty_base_offsets);
    6685                 :            : 
    6686                 :            :   /* Make sure that empty classes are reflected in RLI at this
    6687                 :            :      point.  */
    6688                 :   11678000 :   include_empty_classes (rli);
    6689                 :            : 
    6690                 :            :   /* Make sure not to create any structures with zero size.  */
    6691                 :   16193300 :   if (integer_zerop (rli_size_unit_so_far (rli)) && CLASSTYPE_EMPTY_P (t))
    6692                 :    4514680 :     place_field (rli,
    6693                 :            :                  build_decl (input_location,
    6694                 :            :                              FIELD_DECL, NULL_TREE, char_type_node));
    6695                 :            : 
    6696                 :            :   /* If this is a non-POD, declaring it packed makes a difference to how it
    6697                 :            :      can be used as a field; don't let finalize_record_size undo it.  */
    6698                 :   11678000 :   if (TYPE_PACKED (t) && !layout_pod_type_p (t))
    6699                 :        169 :     rli->packed_maybe_necessary = true;
    6700                 :            : 
    6701                 :            :   /* Let the back end lay out the type.  */
    6702                 :   11678000 :   finish_record_layout (rli, /*free_p=*/true);
    6703                 :            : 
    6704                 :            :   /* If we didn't end up needing an as-base type, don't use it.  */
    6705                 :   11678000 :   if (CLASSTYPE_AS_BASE (t) != t
    6706                 :            :       /* If T's CLASSTYPE_AS_BASE is TYPE_USER_ALIGN, but T is not,
    6707                 :            :          replacing the as-base type would change CLASSTYPE_USER_ALIGN,
    6708                 :            :          causing us to lose the user-specified alignment as in PR94050.  */
    6709                 :   11359400 :       && TYPE_USER_ALIGN (t) == TYPE_USER_ALIGN (CLASSTYPE_AS_BASE (t))
    6710                 :   23037400 :       && tree_int_cst_equal (TYPE_SIZE (t),
    6711                 :   11359400 :                              TYPE_SIZE (CLASSTYPE_AS_BASE (t))))
    6712                 :    6783500 :     CLASSTYPE_AS_BASE (t) = t;
    6713                 :            : 
    6714                 :   11678000 :   if (TYPE_SIZE_UNIT (t)
    6715                 :   11678000 :       && TREE_CODE (TYPE_SIZE_UNIT (t)) == INTEGER_CST
    6716                 :   11678000 :       && !TREE_OVERFLOW (TYPE_SIZE_UNIT (t))
    6717                 :   23356000 :       && !valid_constant_size_p (TYPE_SIZE_UNIT (t)))
    6718                 :          0 :     error ("size of type %qT is too large (%qE bytes)", t, TYPE_SIZE_UNIT (t));
    6719                 :            : 
    6720                 :            :   /* Warn about bases that can't be talked about due to ambiguity.  */
    6721                 :   11678000 :   maybe_warn_about_inaccessible_bases (t);
    6722                 :            : 
    6723                 :            :   /* Now that we're done with layout, give the base fields the real types.  */
    6724                 :   55108900 :   for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6725                 :   57776200 :     if (DECL_ARTIFICIAL (field) && IS_FAKE_BASE_TYPE (TREE_TYPE (field)))
    6726                 :    1449990 :       TREE_TYPE (field) = TYPE_CONTEXT (TREE_TYPE (field));
    6727                 :            : 
    6728                 :            :   /* Clean up.  */
    6729                 :   11678000 :   splay_tree_delete (empty_base_offsets);
    6730                 :            : 
    6731                 :   11678000 :   if (CLASSTYPE_EMPTY_P (t)
    6732                 :   10693600 :       && tree_int_cst_lt (sizeof_biggest_empty_class,
    6733                 :   11678000 :                           TYPE_SIZE_UNIT (t)))
    6734                 :      39388 :     sizeof_biggest_empty_class = TYPE_SIZE_UNIT (t);
    6735                 :   11678000 : }
    6736                 :            : 
    6737                 :            : /* Determine the "key method" for the class type indicated by TYPE,
    6738                 :            :    and set CLASSTYPE_KEY_METHOD accordingly.  */
    6739                 :            : 
    6740                 :            : void
    6741                 :     166928 : determine_key_method (tree type)
    6742                 :            : {
    6743                 :     166928 :   tree method;
    6744                 :            : 
    6745                 :     166928 :   if (processing_template_decl
    6746                 :     166928 :       || CLASSTYPE_TEMPLATE_INSTANTIATION (type)
    6747                 :     261305 :       || CLASSTYPE_INTERFACE_KNOWN (type))
    6748                 :            :     return;
    6749                 :            : 
    6750                 :            :   /* The key method is the first non-pure virtual function that is not
    6751                 :            :      inline at the point of class definition.  On some targets the
    6752                 :            :      key function may not be inline; those targets should not call
    6753                 :            :      this function until the end of the translation unit.  */
    6754                 :     834950 :   for (method = TYPE_FIELDS (type); method; method = DECL_CHAIN (method))
    6755                 :     811905 :     if (TREE_CODE (method) == FUNCTION_DECL
    6756                 :     666478 :         && DECL_VINDEX (method) != NULL_TREE
    6757                 :     140812 :         && ! DECL_DECLARED_INLINE_P (method)
    6758                 :     895558 :         && ! DECL_PURE_VIRTUAL_P (method))
    6759                 :            :       {
    6760                 :      71297 :         CLASSTYPE_KEY_METHOD (type) = method;
    6761                 :      71297 :         break;
    6762                 :            :       }
    6763                 :            : 
    6764                 :            :   return;
    6765                 :            : }
    6766                 :            : 
    6767                 :            : /* Helper of find_flexarrays.  Return true when FLD refers to a non-static
    6768                 :            :    class data member of non-zero size, otherwise false.  */
    6769                 :            : 
    6770                 :            : static inline bool
    6771                 :    4098620 : field_nonempty_p (const_tree fld)
    6772                 :            : {
    6773                 :    4098620 :   if (TREE_CODE (fld) == ERROR_MARK)
    6774                 :            :     return false;
    6775                 :            : 
    6776                 :    4098620 :   tree type = TREE_TYPE (fld);
    6777                 :    4098620 :   if (TREE_CODE (fld) == FIELD_DECL
    6778                 :    4098620 :       && TREE_CODE (type) != ERROR_MARK
    6779                 :    8197250 :       && (DECL_NAME (fld) || RECORD_OR_UNION_TYPE_P (type)))
    6780                 :            :     {
    6781                 :    4067330 :       return TYPE_SIZE (type)
    6782                 :    4067330 :         && (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
    6783                 :    4065890 :             || !tree_int_cst_equal (size_zero_node, TYPE_SIZE (type)));
    6784                 :            :     }
    6785                 :            : 
    6786                 :            :   return false;
    6787                 :            : }
    6788                 :            : 
    6789                 :            : /* Used by find_flexarrays and related functions.  */
    6790                 :            : 
    6791                 :            : struct flexmems_t
    6792                 :            : {
    6793                 :            :   /* The first flexible array member or non-zero array member found
    6794                 :            :      in the order of layout.  */
    6795                 :            :   tree array;
    6796                 :            :   /* First non-static non-empty data member in the class or its bases.  */
    6797                 :            :   tree first;
    6798                 :            :   /* The first non-static non-empty data member following either
    6799                 :            :      the flexible array member, if found, or the zero-length array member
    6800                 :            :      otherwise.  AFTER[1] refers to the first such data member of a union
    6801                 :            :      of which the struct containing the flexible array member or zero-length
    6802                 :            :      array is a member, or NULL when no such union exists.  This element is
    6803                 :            :      only used during searching, not for diagnosing problems.  AFTER[0]
    6804                 :            :      refers to the first such data member that is not a member of such
    6805                 :            :      a union.  */
    6806                 :            :   tree after[2];
    6807                 :            : 
    6808                 :            :   /* Refers to a struct (not union) in which the struct of which the flexible
    6809                 :            :      array is member is defined.  Used to diagnose strictly (according to C)
    6810                 :            :      invalid uses of the latter structs.  */
    6811                 :            :   tree enclosing;
    6812                 :            : };
    6813                 :            : 
    6814                 :            : /* Find either the first flexible array member or the first zero-length
    6815                 :            :    array, in that order of preference, among members of class T (but not
    6816                 :            :    its base classes), and set members of FMEM accordingly.
    6817                 :            :    BASE_P is true if T is a base class of another class.
    6818                 :            :    PUN is set to the outermost union in which the flexible array member
    6819                 :            :    (or zero-length array) is defined if one such union exists, otherwise
    6820                 :            :    to NULL.
    6821                 :            :    Similarly, PSTR is set to a data member of the outermost struct of
    6822                 :            :    which the flexible array is a member if one such struct exists,
    6823                 :            :    otherwise to NULL.  */
    6824                 :            : 
    6825                 :            : static void
    6826                 :   23657800 : find_flexarrays (tree t, flexmems_t *fmem, bool base_p,
    6827                 :            :                  tree pun /* = NULL_TREE */,
    6828                 :            :                  tree pstr /* = NULL_TREE */)
    6829                 :            : {
    6830                 :            :   /* Set the "pointer" to the outermost enclosing union if not set
    6831                 :            :      yet and maintain it for the remainder of the recursion.   */
    6832                 :   23657800 :   if (!pun && TREE_CODE (t) == UNION_TYPE)
    6833                 :     195785 :     pun = t;
    6834                 :            : 
    6835                 :  185290000 :   for (tree fld = TYPE_FIELDS (t); fld; fld = DECL_CHAIN (fld))
    6836                 :            :     {
    6837                 :  161315000 :       if (fld == error_mark_node)
    6838                 :            :         return;
    6839                 :            : 
    6840                 :            :       /* Is FLD a typedef for an anonymous struct?  */
    6841                 :            : 
    6842                 :            :       /* FIXME: Note that typedefs (as well as arrays) need to be fully
    6843                 :            :          handled elsewhere so that errors like the following are detected
    6844                 :            :          as well:
    6845                 :            :            typedef struct { int i, a[], j; } S;   // bug c++/72753
    6846                 :            :            S s [2];                               // bug c++/68489
    6847                 :            :       */
    6848                 :  161490000 :       if (TREE_CODE (fld) == TYPE_DECL
    6849                 :   46428600 :           && DECL_IMPLICIT_TYPEDEF_P (fld)
    6850                 :     815295 :           && CLASS_TYPE_P (TREE_TYPE (fld))
    6851                 :  161819000 :           && IDENTIFIER_ANON_P (DECL_NAME (fld)))
    6852                 :            :         {
    6853                 :            :           /* Check the nested unnamed type referenced via a typedef
    6854                 :            :              independently of FMEM (since it's not a data member of
    6855                 :            :              the enclosing class).  */
    6856                 :     174197 :           check_flexarrays (TREE_TYPE (fld));
    6857                 :     174197 :           continue;
    6858                 :            :         }
    6859                 :            : 
    6860                 :            :       /* Skip anything that's GCC-generated or not a (non-static) data
    6861                 :            :          member.  */
    6862                 :  161141000 :       if (DECL_ARTIFICIAL (fld) || TREE_CODE (fld) != FIELD_DECL)
    6863                 :  156968000 :         continue;
    6864                 :            : 
    6865                 :            :       /* Type of the member.  */
    6866                 :    4173320 :       tree fldtype = TREE_TYPE (fld);
    6867                 :    4173320 :       if (fldtype == error_mark_node)
    6868                 :            :         return;
    6869                 :            : 
    6870                 :            :       /* Determine the type of the array element or object referenced
    6871                 :            :          by the member so that it can be checked for flexible array
    6872                 :            :          members if it hasn't been yet.  */
    6873                 :            :       tree eltype = fldtype;
    6874                 :    5523210 :       while (TREE_CODE (eltype) == ARRAY_TYPE
    6875                 :    5523210 :              || INDIRECT_TYPE_P (eltype))
    6876                 :    1350090 :         eltype = TREE_TYPE (eltype);
    6877                 :            : 
    6878                 :    4173120 :       if (RECORD_OR_UNION_TYPE_P (eltype))
    6879                 :            :         {
    6880                 :    1434620 :           if (fmem->array && !fmem->after[bool (pun)])
    6881                 :            :             {
    6882                 :            :               /* Once the member after the flexible array has been found
    6883                 :            :                  we're done.  */
    6884                 :        357 :               fmem->after[bool (pun)] = fld;
    6885                 :        357 :               break;
    6886                 :            :             }
    6887                 :            : 
    6888                 :    1872850 :           if (eltype == fldtype || TYPE_UNNAMED_P (eltype))
    6889                 :            :             {
    6890                 :            :               /* Descend into the non-static member struct or union and try
    6891                 :            :                  to find a flexible array member or zero-length array among
    6892                 :            :                  its members.  This is only necessary for anonymous types
    6893                 :            :                  and types in whose context the current type T has not been
    6894                 :            :                  defined (the latter must not be checked again because they
    6895                 :            :                  are already in the process of being checked by one of the
    6896                 :            :                  recursive calls).  */
    6897                 :            : 
    6898                 :    1000000 :               tree first = fmem->first;
    6899                 :    1000000 :               tree array = fmem->array;
    6900                 :            : 
    6901                 :            :               /* If this member isn't anonymous and a prior non-flexible array
    6902                 :            :                  member has been seen in one of the enclosing structs, clear
    6903                 :            :                  the FIRST member since it doesn't contribute to the flexible
    6904                 :            :                  array struct's members.  */
    6905                 :    1484880 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    6906                 :     454986 :                 fmem->first = NULL_TREE;
    6907                 :            : 
    6908                 :    1709780 :               find_flexarrays (eltype, fmem, false, pun,
    6909                 :     709782 :                                !pstr && TREE_CODE (t) == RECORD_TYPE ? fld : pstr);
    6910                 :            : 
    6911                 :    1000000 :               if (fmem->array != array)
    6912                 :        963 :                 continue;
    6913                 :            : 
    6914                 :    1483570 :               if (first && !array && !ANON_AGGR_TYPE_P (eltype))
    6915                 :            :                 {
    6916                 :            :                   /* Restore the FIRST member reset above if no flexible
    6917                 :            :                      array member has been found in this member's struct.  */
    6918                 :     454747 :                   fmem->first = first;
    6919                 :            :                 }
    6920                 :            : 
    6921                 :            :               /* If the member struct contains the first flexible array
    6922                 :            :                  member, or if this member is a base class, continue to
    6923                 :            :                  the next member and avoid setting the FMEM->NEXT pointer
    6924                 :            :                  to point to it.  */
    6925                 :     999040 :               if (base_p)
    6926                 :      73181 :                 continue;
    6927                 :            :             }
    6928                 :            :         }
    6929                 :            : 
    6930                 :    4098620 :       if (field_nonempty_p (fld))
    6931                 :            :         {
    6932                 :            :           /* Remember the first non-static data member.  */
    6933                 :    4064190 :           if (!fmem->first)
    6934                 :    1258820 :             fmem->first = fld;
    6935                 :            : 
    6936                 :            :           /* Remember the first non-static data member after the flexible
    6937                 :            :              array member, if one has been found, or the zero-length array
    6938                 :            :              if it has been found.  */
    6939                 :    4064190 :           if (fmem->array && !fmem->after[bool (pun)])
    6940                 :        864 :             fmem->after[bool (pun)] = fld;
    6941                 :            :         }
    6942                 :            : 
    6943                 :            :       /* Skip non-arrays.  */
    6944                 :    4098620 :       if (TREE_CODE (fldtype) != ARRAY_TYPE)
    6945                 :    3709090 :         continue;
    6946                 :            : 
    6947                 :            :       /* Determine the upper bound of the array if it has one.  */
    6948                 :     389531 :       if (TYPE_DOMAIN (fldtype))
    6949                 :            :         {
    6950                 :     388095 :           if (fmem->array)
    6951                 :            :             {
    6952                 :            :               /* Make a record of the zero-length array if either one
    6953                 :            :                  such field or a flexible array member has been seen to
    6954                 :            :                  handle the pathological and unlikely case of multiple
    6955                 :            :                  such members.  */
    6956                 :        541 :               if (!fmem->after[bool (pun)])
    6957                 :         49 :                 fmem->after[bool (pun)] = fld;
    6958                 :            :             }
    6959                 :     387554 :           else if (integer_all_onesp (TYPE_MAX_VALUE (TYPE_DOMAIN (fldtype))))
    6960                 :            :             {
    6961                 :            :               /* Remember the first zero-length array unless a flexible array
    6962                 :            :                  member has already been seen.  */
    6963                 :       1544 :               fmem->array = fld;
    6964                 :       1544 :               fmem->enclosing = pstr;
    6965                 :            :             }
    6966                 :            :         }
    6967                 :            :       else
    6968                 :            :         {
    6969                 :            :           /* Flexible array members have no upper bound.  */
    6970                 :       1436 :           if (fmem->array)
    6971                 :            :             {
    6972                 :        116 :               if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    6973                 :            :                 {
    6974                 :            :                   /* Replace the zero-length array if it's been stored and
    6975                 :            :                      reset the after pointer.  */
    6976                 :         30 :                   fmem->after[bool (pun)] = NULL_TREE;
    6977                 :         30 :                   fmem->array = fld;
    6978                 :         30 :                   fmem->enclosing = pstr;
    6979                 :            :                 }
    6980                 :         86 :               else if (!fmem->after[bool (pun)])
    6981                 :            :                 /* Make a record of another flexible array member.  */
    6982                 :         20 :                 fmem->after[bool (pun)] = fld;
    6983                 :            :             }
    6984                 :            :           else
    6985                 :            :             {
    6986                 :       1320 :               fmem->array = fld;
    6987                 :       1320 :               fmem->enclosing = pstr;
    6988                 :            :             }
    6989                 :            :         }
    6990                 :            :     }
    6991                 :            : }
    6992                 :            : 
    6993                 :            : /* Diagnose a strictly (by the C standard) invalid use of a struct with
    6994                 :            :    a flexible array member (or the zero-length array extension).  */
    6995                 :            : 
    6996                 :            : static void
    6997                 :       1583 : diagnose_invalid_flexarray (const flexmems_t *fmem)
    6998                 :            : {
    6999                 :       1583 :   if (fmem->array && fmem->enclosing)
    7000                 :            :     {
    7001                 :        786 :       auto_diagnostic_group d;
    7002                 :        393 :       if (pedwarn (location_of (fmem->enclosing), OPT_Wpedantic,
    7003                 :        393 :                      TYPE_DOMAIN (TREE_TYPE (fmem->array))
    7004                 :            :                      ? G_("invalid use of %q#T with a zero-size array "
    7005                 :            :                           "in %q#D")
    7006                 :            :                      : G_("invalid use of %q#T with a flexible array member "
    7007                 :            :                           "in %q#T"),
    7008                 :        393 :                      DECL_CONTEXT (fmem->array),
    7009                 :        393 :                      DECL_CONTEXT (fmem->enclosing)))
    7010                 :         88 :         inform (DECL_SOURCE_LOCATION (fmem->array),
    7011                 :         88 :                   "array member %q#D declared here", fmem->array);
    7012                 :            :     }
    7013                 :       1583 : }
    7014                 :            : 
    7015                 :            : /* Issue diagnostics for invalid flexible array members or zero-length
    7016                 :            :    arrays that are not the last elements of the containing class or its
    7017                 :            :    base classes or that are its sole members.  */
    7018                 :            : 
    7019                 :            : static void
    7020                 :   11614700 : diagnose_flexarrays (tree t, const flexmems_t *fmem)
    7021                 :            : {
    7022                 :   11614700 :   if (!fmem->array)
    7023                 :            :     return;
    7024                 :            : 
    7025                 :       2864 :   if (fmem->first && !fmem->after[0])
    7026                 :            :     {
    7027                 :       1438 :       diagnose_invalid_flexarray (fmem);
    7028                 :       1438 :       return;
    7029                 :            :     }
    7030                 :            : 
    7031                 :            :   /* Has a diagnostic been issued?  */
    7032                 :       1426 :   bool diagd = false;
    7033                 :            : 
    7034                 :       1426 :   const char *msg = 0;
    7035                 :            : 
    7036                 :       1426 :   if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
    7037                 :            :     {
    7038                 :        916 :       if (fmem->after[0])
    7039                 :            :         msg = G_("zero-size array member %qD not at end of %q#T");
    7040                 :        249 :       else if (!fmem->first)
    7041                 :            :         msg = G_("zero-size array member %qD in an otherwise empty %q#T");
    7042                 :            : 
    7043                 :        916 :       if (msg)
    7044                 :            :         {
    7045                 :        916 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7046                 :            : 
    7047                 :       1832 :           auto_diagnostic_group d;
    7048                 :        916 :           if (pedwarn (loc, OPT_Wpedantic, msg, fmem->array, t))
    7049                 :            :             {
    7050                 :        192 :               inform (location_of (t), "in the definition of %q#T", t);
    7051                 :        192 :               diagd = true;
    7052                 :            :             }
    7053                 :            :         }
    7054                 :            :     }
    7055                 :            :   else
    7056                 :            :     {
    7057                 :        510 :       if (fmem->after[0])
    7058                 :            :         msg = G_("flexible array member %qD not at end of %q#T");
    7059                 :        238 :       else if (!fmem->first)
    7060                 :            :         msg = G_("flexible array member %qD in an otherwise empty %q#T");
    7061                 :            : 
    7062                 :        510 :       if (msg)
    7063                 :            :         {
    7064                 :        510 :           location_t loc = DECL_SOURCE_LOCATION (fmem->array);
    7065                 :        510 :           diagd = true;
    7066                 :            : 
    7067                 :       1020 :           auto_diagnostic_group d;
    7068                 :        510 :           error_at (loc, msg, fmem->array, t);
    7069                 :            : 
    7070                 :            :           /* In the unlikely event that the member following the flexible
    7071                 :            :              array member is declared in a different class, or the member
    7072                 :            :              overlaps another member of a common union, point to it.
    7073                 :            :              Otherwise it should be obvious.  */
    7074                 :        510 :           if (fmem->after[0]
    7075                 :        510 :               && ((DECL_CONTEXT (fmem->after[0])
    7076                 :        272 :                    != DECL_CONTEXT (fmem->array))))
    7077                 :            :             {
    7078                 :        128 :               inform (DECL_SOURCE_LOCATION (fmem->after[0]),
    7079                 :            :                       "next member %q#D declared here",
    7080                 :            :                       fmem->after[0]);
    7081                 :        128 :               inform (location_of (t), "in the definition of %q#T", t);
    7082                 :            :             }
    7083                 :            :         }
    7084                 :            :     }
    7085                 :            : 
    7086                 :       1426 :   if (!diagd && fmem->array && fmem->enclosing)
    7087                 :        145 :     diagnose_invalid_flexarray (fmem);
    7088                 :            : }
    7089                 :            : 
    7090                 :            : 
    7091                 :            : /* Recursively check to make sure that any flexible array or zero-length
    7092                 :            :    array members of class T or its bases are valid (i.e., not the sole
    7093                 :            :    non-static data member of T and, if one exists, that it is the last
    7094                 :            :    non-static data member of T and its base classes.  FMEM is expected
    7095                 :            :    to be initially null and is used internally by recursive calls to
    7096                 :            :    the function.  Issue the appropriate diagnostics for the array member
    7097                 :            :    that fails the checks.  */
    7098                 :            : 
    7099                 :            : static void
    7100                 :   22895300 : check_flexarrays (tree t, flexmems_t *fmem /* = NULL */,
    7101                 :            :                   bool base_p /* = false */)
    7102                 :            : {
    7103                 :            :   /* Initialize the result of a search for flexible array and zero-length
    7104                 :            :      array members.  Avoid doing any work if the most interesting FMEM data
    7105                 :            :      have already been populated.  */
    7106                 :   45790700 :   flexmems_t flexmems = flexmems_t ();
    7107                 :   22895300 :   if (!fmem)
    7108                 :            :     fmem = &flexmems;
    7109                 :   11043100 :   else if (fmem->array && fmem->first && fmem->after[0])
    7110                 :          0 :     return;
    7111                 :            : 
    7112                 :   22895300 :   tree fam = fmem->array;
    7113                 :            : 
    7114                 :            :   /* Recursively check the primary base class first.  */
    7115                 :   22895300 :   if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7116                 :            :     {
    7117                 :     206362 :       tree basetype = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (t));
    7118                 :     206362 :       check_flexarrays (basetype, fmem, true);
    7119                 :            :     }
    7120                 :            : 
    7121                 :            :   /* Recursively check the base classes.  */
    7122                 :   45975000 :   int nbases = TYPE_BINFO (t) ? BINFO_N_BASE_BINFOS (TYPE_BINFO (t)) : 0;
    7123                 :   33949600 :   for (int i = 0; i < nbases; ++i)
    7124                 :            :     {
    7125                 :   11054300 :       tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (t), i);
    7126                 :            : 
    7127                 :            :       /* The primary base class was already checked above.  */
    7128                 :   11054300 :       if (base_binfo == CLASSTYPE_PRIMARY_BINFO (t))
    7129                 :     206227 :         continue;
    7130                 :            : 
    7131                 :            :       /* Virtual base classes are at the end.  */
    7132                 :   10848100 :       if (BINFO_VIRTUAL_P (base_binfo))
    7133                 :      40635 :         continue;
    7134                 :            : 
    7135                 :            :       /* Check the base class.  */
    7136                 :   10807500 :       check_flexarrays (BINFO_TYPE (base_binfo), fmem, /*base_p=*/true);
    7137                 :            :     }
    7138                 :            : 
    7139                 :   22895300 :   if (fmem == &flexmems)
    7140                 :            :     {
    7141                 :            :       /* Check virtual base classes only once per derived class.
    7142                 :            :          I.e., this check is not performed recursively for base
    7143                 :            :          classes.  */
    7144                 :   11852200 :       int i;
    7145                 :   11852200 :       tree base_binfo;
    7146                 :   11852200 :       vec<tree, va_gc> *vbases;
    7147                 :   11881500 :       for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    7148                 :   11881500 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    7149                 :            :         {
    7150                 :            :           /* Check the virtual base class.  */
    7151                 :      29308 :           tree basetype = TREE_TYPE (base_binfo);
    7152                 :            : 
    7153                 :      29308 :           check_flexarrays (basetype, fmem, /*base_p=*/true);
    7154                 :            :         }
    7155                 :            :     }
    7156                 :            : 
    7157                 :            :   /* Is the type unnamed (and therefore a member of it potentially
    7158                 :            :      an anonymous struct or union)?  */
    7159                 :   22895300 :   bool maybe_anon_p = TYPE_UNNAMED_P (t);
    7160                 :     321224 :   if (tree ctx = maybe_anon_p ? TYPE_CONTEXT (t) : NULL_TREE)
    7161                 :     321224 :     maybe_anon_p = RECORD_OR_UNION_TYPE_P (ctx);
    7162                 :            : 
    7163                 :            :   /* Search the members of the current (possibly derived) class, skipping
    7164                 :            :      unnamed structs and unions since those could be anonymous.  */
    7165                 :   22895300 :   if (fmem != &flexmems || !maybe_anon_p)
    7166                 :   34272300 :     find_flexarrays (t, fmem, base_p || fam != fmem->array);
    7167                 :            : 
    7168                 :   22895300 :   if (fmem == &flexmems && !maybe_anon_p)
    7169                 :            :     {
    7170                 :            :       /* Issue diagnostics for invalid flexible and zero-length array
    7171                 :            :          members found in base classes or among the members of the current
    7172                 :            :          class.  Ignore anonymous structs and unions whose members are
    7173                 :            :          considered to be members of the enclosing class and thus will
    7174                 :            :          be diagnosed when checking it.  */
    7175                 :   11614700 :       diagnose_flexarrays (t, fmem);
    7176                 :            :     }
    7177                 :            : }
    7178                 :            : 
    7179                 :            : /* Perform processing required when the definition of T (a class type)
    7180                 :            :    is complete.  Diagnose invalid definitions of flexible array members
    7181                 :            :    and zero-size arrays.  */
    7182                 :            : 
    7183                 :            : void
    7184                 :   11678000 : finish_struct_1 (tree t)
    7185                 :            : {
    7186                 :   11678000 :   tree x;
    7187                 :            :   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
    7188                 :   11678000 :   tree virtuals = NULL_TREE;
    7189                 :            : 
    7190                 :   11678000 :   if (COMPLETE_TYPE_P (t))
    7191                 :            :     {
    7192                 :          0 :       gcc_assert (MAYBE_CLASS_TYPE_P (t));
    7193                 :          0 :       error ("redefinition of %q#T", t);
    7194                 :          0 :       popclass ();
    7195                 :          0 :       return;
    7196                 :            :     }
    7197                 :            : 
    7198                 :            :   /* If this type was previously laid out as a forward reference,
    7199                 :            :      make sure we lay it out again.  */
    7200                 :   11678000 :   TYPE_SIZE (t) = NULL_TREE;
    7201                 :   11678000 :   CLASSTYPE_PRIMARY_BINFO (t) = NULL_TREE;
    7202                 :            : 
    7203                 :            :   /* Make assumptions about the class; we'll reset the flags if
    7204                 :            :      necessary.  */
    7205                 :   11678000 :   CLASSTYPE_EMPTY_P (t) = 1;
    7206                 :   11678000 :   CLASSTYPE_NEARLY_EMPTY_P (t) = 1;
    7207                 :   11678000 :   CLASSTYPE_CONTAINS_EMPTY_CLASS_P (t) = 0;
    7208                 :   11678000 :   CLASSTYPE_LITERAL_P (t) = true;
    7209                 :            : 
    7210                 :            :   /* Do end-of-class semantic processing: checking the validity of the
    7211                 :            :      bases and members and add implicitly generated methods.  */
    7212                 :   11678000 :   check_bases_and_members (t);
    7213                 :            : 
    7214                 :            :   /* Find the key method.  */
    7215                 :   23356000 :   if (TYPE_CONTAINS_VPTR_P (t))
    7216                 :            :     {
    7217                 :            :       /* The Itanium C++ ABI permits the key method to be chosen when
    7218                 :            :          the class is defined -- even though the key method so
    7219                 :            :          selected may later turn out to be an inline function.  On
    7220                 :            :          some systems (such as ARM Symbian OS) the key method cannot
    7221                 :            :          be determined until the end of the translation unit.  On such
    7222                 :            :          systems, we leave CLASSTYPE_KEY_METHOD set to NULL, which
    7223                 :            :          will cause the class to be added to KEYED_CLASSES.  Then, in
    7224                 :            :          finish_file we will determine the key method.  */
    7225                 :     166928 :       if (targetm.cxx.key_method_may_be_inline ())
    7226                 :     166928 :         determine_key_method (t);
    7227                 :            : 
    7228                 :            :       /* If a polymorphic class has no key method, we may emit the vtable
    7229                 :            :          in every translation unit where the class definition appears.  If
    7230                 :            :          we're devirtualizing, we can look into the vtable even if we
    7231                 :            :          aren't emitting it.  */
    7232                 :     166928 :       if (!CLASSTYPE_KEY_METHOD (t))
    7233                 :      95631 :         vec_safe_push (keyed_classes, t);
    7234                 :            :     }
    7235                 :            : 
    7236                 :            :   /* Layout the class itself.  */
    7237                 :   11678000 :   layout_class_type (t, &virtuals);
    7238                 :            :   /* COMPLETE_TYPE_P is now true.  */
    7239                 :            : 
    7240                 :   11678000 :   set_class_bindings (t);
    7241                 :            : 
    7242                 :            :   /* With the layout complete, check for flexible array members and
    7243                 :            :      zero-length arrays that might overlap other members in the final
    7244                 :            :      layout.  */
    7245                 :   11678000 :   check_flexarrays (t);
    7246                 :            : 
    7247                 :   11678000 :   virtuals = modify_all_vtables (t, nreverse (virtuals));
    7248                 :            : 
    7249                 :            :   /* If necessary, create the primary vtable for this class.  */
    7250                 :   23294800 :   if (virtuals || TYPE_CONTAINS_VPTR_P (t))
    7251                 :            :     {
    7252                 :            :       /* We must enter these virtuals into the table.  */
    7253                 :     166928 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7254                 :      39330 :         build_primary_vtable (NULL_TREE, t);
    7255                 :     127598 :       else if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
    7256                 :            :         /* Here we know enough to change the type of our virtual
    7257                 :            :            function table, but we will wait until later this function.  */
    7258                 :          0 :         build_primary_vtable (CLASSTYPE_PRIMARY_BINFO (t), t);
    7259                 :            : 
    7260                 :            :       /* If we're warning about ABI tags, check the types of the new
    7261                 :            :          virtual functions.  */
    7262                 :     166928 :       if (warn_abi_tag)
    7263                 :          8 :         for (tree v = virtuals; v; v = TREE_CHAIN (v))
    7264                 :          4 :           check_abi_tags (t, TREE_VALUE (v));
    7265                 :            :     }
    7266                 :            : 
    7267                 :   23356000 :   if (TYPE_CONTAINS_VPTR_P (t))
    7268                 :            :     {
    7269                 :     166928 :       int vindex;
    7270                 :     166928 :       tree fn;
    7271                 :            : 
    7272                 :     166928 :       if (BINFO_VTABLE (TYPE_BINFO (t)))
    7273                 :     166928 :         gcc_assert (DECL_VIRTUAL_P (BINFO_VTABLE (TYPE_BINFO (t))));
    7274                 :     166928 :       if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
    7275                 :      39330 :         gcc_assert (BINFO_VIRTUALS (TYPE_BINFO (t)) == NULL_TREE);
    7276                 :            : 
    7277                 :            :       /* Add entries for virtual functions introduced by this class.  */
    7278                 :     166928 :       BINFO_VIRTUALS (TYPE_BINFO (t))
    7279                 :     166928 :         = chainon (BINFO_VIRTUALS (TYPE_BINFO (t)), virtuals);
    7280                 :            : 
    7281                 :            :       /* Set DECL_VINDEX for all functions declared in this class.  */
    7282                 :     978269 :       for (vindex = 0, fn = BINFO_VIRTUALS (TYPE_BINFO (t));
    7283                 :     978269 :            fn;
    7284                 :     811341 :            fn = TREE_CHAIN (fn),
    7285                 :     811341 :              vindex += (TARGET_VTABLE_USES_DESCRIPTORS
    7286                 :            :                         ? TARGET_VTABLE_USES_DESCRIPTORS : 1))
    7287                 :            :         {
    7288                 :     811341 :           tree fndecl = BV_FN (fn);
    7289                 :            : 
    7290                 :    1622680 :           if (DECL_THUNK_P (fndecl))
    7291                 :            :             /* A thunk. We should never be calling this entry directly
    7292                 :            :                from this vtable -- we'd use the entry for the non
    7293                 :            :                thunk base function.  */
    7294                 :        164 :             DECL_VINDEX (fndecl) = NULL_TREE;
    7295                 :     811177 :           else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
    7296                 :     682018 :             DECL_VINDEX (fndecl) = build_int_cst (NULL_TREE, vindex);
    7297                 :            :         }
    7298                 :            :     }
    7299                 :            : 
    7300                 :   11678000 :   finish_struct_bits (t);
    7301                 :            : 
    7302                 :   11678000 :   set_method_tm_attributes (t);
    7303                 :   11678000 :   if (flag_openmp || flag_openmp_simd)
    7304                 :      22790 :     finish_omp_declare_simd_methods (t);
    7305                 :            : 
    7306                 :            :   /* Clear DECL_IN_AGGR_P for all member functions.  Complete the rtl
    7307                 :            :      for any static member objects of the type we're working on.  */
    7308                 :   55108900 :   for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7309                 :   43331100 :     if (DECL_DECLARES_FUNCTION_P (x))
    7310                 :   17076600 :       DECL_IN_AGGR_P (x) = false;
    7311                 :   26254500 :     else if (VAR_P (x) && TREE_STATIC (x)
    7312                 :    1181310 :              && TREE_TYPE (x) != error_mark_node
    7313                 :   27435800 :              && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (x)), t))
    7314                 :      16030 :       SET_DECL_MODE (x, TYPE_MODE (t));
    7315                 :            : 
    7316                 :            :   /* Complain if one of the field types requires lower visibility.  */
    7317                 :   11678000 :   constrain_class_visibility (t);
    7318                 :            : 
    7319                 :            :   /* Make the rtl for any new vtables we have created, and unmark
    7320                 :            :      the base types we marked.  */
    7321                 :   11678000 :   finish_vtbls (t);
    7322                 :            : 
    7323                 :            :   /* Build the VTT for T.  */
    7324                 :   11678000 :   build_vtt (t);
    7325                 :            : 
    7326                 :   11678000 :   if (warn_nonvdtor
    7327                 :        380 :       && TYPE_POLYMORPHIC_P (t) && accessible_nvdtor_p (t)
    7328                 :   11678100 :       && !CLASSTYPE_FINAL (t))
    7329                 :         44 :     warning (OPT_Wnon_virtual_dtor,
    7330                 :            :              "%q#T has virtual functions and accessible"
    7331                 :            :              " non-virtual destructor", t);
    7332                 :            : 
    7333                 :   11678000 :   complete_vars (t);
    7334                 :            : 
    7335                 :   11678000 :   if (warn_overloaded_virtual)
    7336                 :         84 :     warn_hidden (t);
    7337                 :            : 
    7338                 :            :   /* Class layout, assignment of virtual table slots, etc., is now
    7339                 :            :      complete.  Give the back end a chance to tweak the visibility of
    7340                 :            :      the class or perform any other required target modifications.  */
    7341                 :   11678000 :   targetm.cxx.adjust_class_at_definition (t);
    7342                 :            : 
    7343                 :   11678000 :   maybe_suppress_debug_info (t);
    7344                 :            : 
    7345                 :   11678000 :   if (flag_vtable_verify)
    7346                 :         10 :     vtv_save_class_info (t);
    7347                 :            : 
    7348                 :   11678000 :   dump_class_hierarchy (t);
    7349                 :            : 
    7350                 :            :   /* Finish debugging output for this type.  */
    7351                 :   11678000 :   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
    7352                 :            : 
    7353                 :            :   /* Recalculate satisfaction that might depend on completeness.  */
    7354                 :   11678000 :   clear_satisfaction_cache ();
    7355                 :            : 
    7356                 :   11777800 :   if (TYPE_TRANSPARENT_AGGR (t))
    7357                 :            :     {
    7358                 :        164 :       tree field = first_field (t);
    7359                 :        316 :       if (field == NULL_TREE || error_operand_p (field))
    7360                 :            :         {
    7361                 :         12 :           error ("type transparent %q#T does not have any fields", t);
    7362                 :         12 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7363                 :            :         }
    7364                 :        152 :       else if (DECL_ARTIFICIAL (field))
    7365                 :            :         {
    7366                 :          4 :           if (DECL_FIELD_IS_BASE (field))
    7367                 :          4 :             error ("type transparent class %qT has base classes", t);
    7368                 :            :           else
    7369                 :            :             {
    7370                 :          0 :               gcc_checking_assert (DECL_VIRTUAL_P (field));
    7371                 :          0 :               error ("type transparent class %qT has virtual functions", t);
    7372                 :            :             }
    7373                 :          4 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7374                 :            :         }
    7375                 :        296 :       else if (TYPE_MODE (t) != DECL_MODE (field))
    7376                 :            :         {
    7377                 :          4 :           error ("type transparent %q#T cannot be made transparent because "
    7378                 :            :                  "the type of the first field has a different ABI from the "
    7379                 :            :                  "class overall", t);
    7380                 :          8 :           TYPE_TRANSPARENT_AGGR (t) = 0;
    7381                 :            :         }
    7382                 :            :     }
    7383                 :            : }
    7384                 :            : 
    7385                 :            : /* When T was built up, the member declarations were added in reverse
    7386                 :            :    order.  Rearrange them to declaration order.  */
    7387                 :            : 
    7388                 :            : void
    7389                 :   14242200 : unreverse_member_declarations (tree t)
    7390                 :            : {
    7391                 :   14242200 :   tree next;
    7392                 :   14242200 :   tree prev;
    7393                 :   14242200 :   tree x;
    7394                 :            : 
    7395                 :            :   /* The following lists are all in reverse order.  Put them in
    7396                 :            :      declaration order now.  */
    7397                 :   14242200 :   CLASSTYPE_DECL_LIST (t) = nreverse (CLASSTYPE_DECL_LIST (t));
    7398                 :            : 
    7399                 :            :   /* For the TYPE_FIELDS, only the non TYPE_DECLs are in reverse
    7400                 :            :      order, so we can't just use nreverse.  Due to stat_hack
    7401                 :            :      chicanery in finish_member_declaration.  */
    7402                 :   14242200 :   prev = NULL_TREE;
    7403                 :   14356100 :   for (x = TYPE_FIELDS (t);
    7404                 :   35197600 :        x && TREE_CODE (x) != TYPE_DECL;
    7405                 :   20955400 :        x = next)
    7406                 :            :     {
    7407                 :   20955400 :       next = DECL_CHAIN (x);
    7408                 :   20955400 :       DECL_CHAIN (x) = prev;
    7409                 :   20955400 :       prev = x;
    7410                 :            :     }
    7411                 :            : 
    7412                 :   14242200 :   if (prev)
    7413                 :            :     {
    7414                 :    3233640 :       DECL_CHAIN (TYPE_FIELDS (t)) = x;
    7415                 :    3233640 :       TYPE_FIELDS (t) = prev;
    7416                 :            :     }
    7417                 :   14242200 : }
    7418                 :            : 
    7419                 :            : tree
    7420                 :    3976430 : finish_struct (tree t, tree attributes)
    7421                 :            : {
    7422                 :    3976430 :   location_t saved_loc = input_location;
    7423                 :            : 
    7424                 :            :   /* Now that we've got all the field declarations, reverse everything
    7425                 :            :      as necessary.  */
    7426                 :    3976430 :   unreverse_member_declarations (t);
    7427                 :            : 
    7428                 :    3976430 :   cplus_decl_attributes (&t, attributes, (int) ATTR_FLAG_TYPE_IN_PLACE);
    7429                 :    3976430 :   fixup_attribute_variants (t);
    7430                 :            : 
    7431                 :            :   /* Nadger the current location so that diagnostics point to the start of
    7432                 :            :      the struct, not the end.  */
    7433                 :    3976430 :   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (t));
    7434                 :            : 
    7435                 :    3976430 :   if (processing_template_decl)
    7436                 :            :     {
    7437                 :    2564150 :       tree x;
    7438                 :            : 
    7439                 :            :       /* We need to add the target functions of USING_DECLS, so that
    7440                 :            :          they can be found when the using declaration is not
    7441                 :            :          instantiated yet.  */
    7442                 :   12120200 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7443                 :    9541940 :         if (TREE_CODE (x) == USING_DECL)
    7444                 :            :           {
    7445                 :      41621 :             tree fn = strip_using_decl (x);
    7446                 :      41621 :             if (OVL_P (fn))
    7447                 :      11781 :               for (lkp_iterator iter (fn); iter; ++iter)
    7448                 :       8631 :                 add_method (t, *iter, true);
    7449                 :            :           }
    7450                 :    9500310 :         else if (DECL_DECLARES_FUNCTION_P (x))
    7451                 :            :           {
    7452                 :    4143420 :             DECL_IN_AGGR_P (x) = false;
    7453                 :    4143420 :             if (DECL_VIRTUAL_P (x))
    7454                 :     141983 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    7455                 :            :           }
    7456                 :    5356900 :         else if (TREE_CODE (x) == FIELD_DECL)
    7457                 :            :           {
    7458                 :     497701 :             if (TREE_PROTECTED (x) || TREE_PRIVATE (x))
    7459                 :     277087 :               CLASSTYPE_NON_AGGREGATE (t) = true;
    7460                 :            :           }
    7461                 :            : 
    7462                 :            :       /* Also add a USING_DECL for operator=.  We know there'll be (at
    7463                 :            :          least) one, but we don't know the signature(s).  We want name
    7464                 :            :          lookup not to fail or recurse into bases.  This isn't added
    7465                 :            :          to the template decl list so we drop this at instantiation
    7466                 :            :          time.  */
    7467                 :    2564150 :       tree ass_op = build_lang_decl (USING_DECL, assign_op_identifier,
    7468                 :            :                                      NULL_TREE);
    7469                 :    2564150 :       DECL_CONTEXT (ass_op) = t;
    7470                 :    2564150 :       USING_DECL_SCOPE (ass_op) = t;
    7471                 :    2564150 :       DECL_DEPENDENT_P (ass_op) = true;
    7472                 :    2564150 :       DECL_ARTIFICIAL (ass_op) = true;
    7473                 :    2578290 :       DECL_CHAIN (ass_op) = TYPE_FIELDS (t);
    7474                 :    2564150 :       TYPE_FIELDS (t) = ass_op;
    7475                 :            : 
    7476                 :    2564150 :       TYPE_SIZE (t) = bitsize_zero_node;
    7477                 :    2564150 :       TYPE_SIZE_UNIT (t) = size_zero_node;
    7478                 :            :       /* COMPLETE_TYPE_P is now true.  */
    7479                 :            : 
    7480                 :    2564150 :       set_class_bindings (t);
    7481                 :            : 
    7482                 :            :       /* We need to emit an error message if this type was used as a parameter
    7483                 :            :          and it is an abstract type, even if it is a template. We construct
    7484                 :            :          a simple CLASSTYPE_PURE_VIRTUALS list without taking bases into
    7485                 :            :          account and we call complete_vars with this type, which will check
    7486                 :            :          the PARM_DECLS. Note that while the type is being defined,
    7487                 :            :          CLASSTYPE_PURE_VIRTUALS contains the list of the inline friends
    7488                 :            :          (see CLASSTYPE_INLINE_FRIENDS) so we need to clear it.  */
    7489                 :    2564150 :       CLASSTYPE_PURE_VIRTUALS (t) = NULL;
    7490                 :   14684400 :       for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
    7491                 :   12106100 :         if (TREE_CODE (x) == FUNCTION_DECL && DECL_PURE_VIRTUAL_P (x))
    7492                 :      21201 :           vec_safe_push (CLASSTYPE_PURE_VIRTUALS (t), x);
    7493                 :    2564150 :       complete_vars (t);
    7494                 :            : 
    7495                 :            :       /* Remember current #pragma pack value.  */
    7496                 :    2564150 :       TYPE_PRECISION (t) = maximum_field_alignment;
    7497                 :            : 
    7498                 :    2564150 :       if (cxx_dialect < cxx2a)
    7499                 :            :         {
    7500                 :    1963430 :           if (!CLASSTYPE_NON_AGGREGATE (t)
    7501                 :    1963430 :               && type_has_user_provided_or_explicit_constructor (t))
    7502                 :      66838 :             CLASSTYPE_NON_AGGREGATE (t) = 1;
    7503                 :            :         }
    7504                 :     600720 :       else if (TYPE_HAS_USER_CONSTRUCTOR (t))
    7505                 :      82451 :         CLASSTYPE_NON_AGGREGATE (t) = 1;
    7506                 :            : 
    7507                 :            :       /* Fix up any variants we've already built.  */
    7508                 :    5516380 :       for (x = TYPE_NEXT_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
    7509                 :            :         {
    7510                 :    2952230 :           TYPE_SIZE (x) = TYPE_SIZE (t);
    7511                 :    2952230 :           TYPE_SIZE_UNIT (x) = TYPE_SIZE_UNIT (t);
    7512                 :    2980520 :           TYPE_FIELDS (x) = TYPE_FIELDS (t);
    7513                 :            :         }
    7514                 :            :     }
    7515                 :            :   else
    7516                 :    1412280 :     finish_struct_1 (t);
    7517                 :            :   /* COMPLETE_TYPE_P is now true.  */
    7518                 :            : 
    7519                 :    3976430 :   maybe_warn_about_overly_private_class (t);
    7520                 :            :   
    7521                 :    3976430 :   if (is_std_init_list (t))
    7522                 :            :     {
    7523                 :            :       /* People keep complaining that the compiler crashes on an invalid
    7524                 :            :          definition of initializer_list, so I guess we should explicitly
    7525                 :            :          reject it.  What the compiler internals care about is that it's a
    7526                 :            :          template and has a pointer field followed by size_type field.  */
    7527                 :       3009 :       bool ok = false;
    7528                 :       3009 :       if (processing_template_decl)
    7529                 :            :         {
    7530                 :       3009 :           tree f = next_initializable_field (TYPE_FIELDS (t));
    7531                 :       6015 :           if (f && TYPE_PTR_P (TREE_TYPE (f)))
    7532                 :            :             {
    7533                 :       3006 :               f = next_initializable_field (DECL_CHAIN (f));
    7534                 :       3006 :               if (f && same_type_p (TREE_TYPE (f), size_type_node))
    7535                 :            :                 ok = true;
    7536                 :            :             }
    7537                 :            :         }
    7538                 :            :       if (!ok)
    7539                 :         12 :         fatal_error (input_location, "definition of %qD does not match "
    7540                 :          6 :                      "%<#include <initializer_list>%>", TYPE_NAME (t));
    7541                 :            :     }
    7542                 :            : 
    7543                 :    3976420 :   input_location = saved_loc;
    7544                 :            : 
    7545                 :    3976420 :   TYPE_BEING_DEFINED (t) = 0;
    7546                 :            : 
    7547                 :    3976420 :   if (current_class_type)
    7548                 :    3976420 :     popclass ();
    7549                 :            :   else
    7550                 :          0 :     error ("trying to finish struct, but kicked out due to previous parse errors");
    7551                 :            : 
    7552                 :    3976420 :   if (flag_openmp)
    7553                 :      90576 :     for (tree decl = TYPE_FIELDS (t); decl; decl = DECL_CHAIN (decl))
    7554                 :      74572 :       if (TREE_CODE (decl) == FUNCTION_DECL
    7555                 :      96743 :           && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
    7556                 :      38844 :         if (tree attr = lookup_attribute ("omp declare variant base",
    7557                 :      19422 :                                           DECL_ATTRIBUTES (decl)))
    7558                 :        118 :           omp_declare_variant_finalize (decl, attr);
    7559                 :            : 
    7560                 :    2564140 :   if (processing_template_decl && at_function_scope_p ()
    7561                 :            :       /* Lambdas are defined by the LAMBDA_EXPR.  */
    7562                 :    3993980 :       && !LAMBDA_TYPE_P (t))
    7563                 :       9110 :     add_stmt (build_min (TAG_DEFN, t));
    7564                 :            : 
    7565                 :    3976420 :   return t;
    7566                 :            : }
    7567                 :            : 
    7568                 :            : /* Hash table to avoid endless recursion when handling references.  */
    7569                 :            : static hash_table<nofree_ptr_hash<tree_node> > *fixed_type_or_null_ref_ht;
    7570                 :            : 
    7571                 :            : /* Return the dynamic type of INSTANCE, if known.
    7572                 :            :    Used to determine whether the virtual function table is needed
    7573                 :            :    or not.
    7574                 :            : 
    7575                 :            :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    7576                 :            :    of our knowledge of its type.  *NONNULL should be initialized
    7577                 :            :    before this function is called.  */
    7578                 :            : 
    7579                 :            : static tree
    7580                 :   22402100 : fixed_type_or_null (tree instance, int *nonnull, int *cdtorp)
    7581                 :            : {
    7582                 :            : #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
    7583                 :            : 
    7584                 :   22402100 :   switch (TREE_CODE (instance))
    7585                 :            :     {
    7586                 :     411469 :     case INDIRECT_REF:
    7587                 :     411469 :       if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
    7588                 :            :         return NULL_TREE;
    7589                 :            :       else
    7590                 :     389640 :         return RECUR (TREE_OPERAND (instance, 0));
    7591                 :            : 
    7592                 :     316596 :     case CALL_EXPR:
    7593                 :            :       /* This is a call to a constructor, hence it's never zero.  */
    7594                 :     316596 :       if (CALL_EXPR_FN (instance)
    7595                 :     316596 :           && TREE_HAS_CONSTRUCTOR (instance))
    7596                 :            :         {
    7597                 :          0 :           if (nonnull)
    7598                 :          0 :             *nonnull = 1;
    7599                 :          0 :           return TREE_TYPE (instance);
    7600                 :            :         }
    7601                 :            :       return NULL_TREE;
    7602                 :            : 
    7603                 :      26210 :     case SAVE_EXPR:
    7604                 :            :       /* This is a call to a constructor, hence it's never zero.  */
    7605                 :      52420 :       if (TREE_HAS_CONSTRUCTOR (instance))
    7606                 :            :         {
    7607                 :          0 :           if (nonnull)
    7608                 :          0 :             *nonnull = 1;
    7609                 :          0 :           return TREE_TYPE (instance);
    7610                 :            :         }
    7611                 :      26210 :       return RECUR (TREE_OPERAND (instance, 0));
    7612                 :            : 
    7613                 :        688 :     case POINTER_PLUS_EXPR:
    7614                 :        688 :     case PLUS_EXPR:
    7615                 :        688 :     case MINUS_EXPR:
    7616                 :        688 :       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
    7617                 :          0 :         return RECUR (TREE_OPERAND (instance, 0));
    7618                 :        688 :       if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
    7619                 :            :         /* Propagate nonnull.  */
    7620                 :         86 :         return RECUR (TREE_OPERAND (instance, 0));
    7621                 :            : 
    7622                 :            :       return NULL_TREE;
    7623                 :            : 
    7624                 :    6586470 :     CASE_CONVERT:
    7625                 :    6586470 :       return RECUR (TREE_OPERAND (instance, 0));
    7626                 :            : 
    7627                 :    3729000 :     case ADDR_EXPR:
    7628                 :    3729000 :       instance = TREE_OPERAND (instance, 0);
    7629                 :    3729000 :       if (nonnull)
    7630                 :            :         {
    7631                 :            :           /* Just because we see an ADDR_EXPR doesn't mean we're dealing
    7632                 :            :              with a real object -- given &p->f, p can still be null.  */
    7633                 :     708959 :           tree t = get_base_address (instance);
    7634                 :            :           /* ??? Probably should check DECL_WEAK here.  */
    7635                 :     708959 :           if (t && DECL_P (t))
    7636                 :      73606 :             *nonnull = 1;
    7637                 :            :         }
    7638                 :    3729000 :       return RECUR (instance);
    7639                 :            : 
    7640                 :    1519150 :     case COMPONENT_REF:
    7641                 :            :       /* If this component is really a base class reference, then the field
    7642                 :            :          itself isn't definitive.  */
    7643                 :    1519150 :       if (DECL_FIELD_IS_BASE (TREE_OPERAND (instance, 1)))
    7644                 :     305673 :         return RECUR (TREE_OPERAND (instance, 0));
    7645                 :    1213480 :       return RECUR (TREE_OPERAND (instance, 1));
    7646                 :            : 
    7647                 :    2642750 :     case VAR_DECL:
    7648                 :    2642750 :     case FIELD_DECL:
    7649                 :    2642750 :       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
    7650                 :    2642750 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (instance))))
    7651                 :            :         {
    7652                 :         23 :           if (nonnull)
    7653                 :          0 :             *nonnull = 1;
    7654                 :         23 :           return TREE_TYPE (TREE_TYPE (instance));
    7655                 :            :         }
    7656                 :            :       /* fall through.  */
    7657                 :    9500000 :     case TARGET_EXPR:
    7658                 :    9500000 :     case PARM_DECL:
    7659                 :    9500000 :     case RESULT_DECL:
    7660                 :    9500000 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (instance)))
    7661                 :            :         {
    7662                 :    3446860 :           if (nonnull)
    7663                 :     714896 :             *nonnull = 1;
    7664                 :    3446860 :           return TREE_TYPE (instance);
    7665                 :            :         }
    7666                 :    6053140 :       else if (instance == current_class_ptr)
    7667                 :            :         {
    7668                 :    4130720 :           if (nonnull)
    7669                 :    1192250 :             *nonnull = 1;
    7670                 :            : 
    7671                 :            :           /* if we're in a ctor or dtor, we know our type.  If
    7672                 :            :              current_class_ptr is set but we aren't in a function, we're in
    7673                 :            :              an NSDMI (and therefore a constructor).  */
    7674                 :    4130720 :           if (current_scope () != current_function_decl
    7675                 :    4130720 :               || (DECL_LANG_SPECIFIC (current_function_decl)
    7676                 :    4130450 :                   && (DECL_CONSTRUCTOR_P (current_function_decl)
    7677                 :    4130450 :                       || DECL_DESTRUCTOR_P (current_function_decl))))
    7678                 :            :             {
    7679                 :    2021200 :               if (cdtorp)
    7680                 :    2021200 :                 *cdtorp = 1;
    7681                 :    2021200 :               return TREE_TYPE (TREE_TYPE (instance));
    7682                 :            :             }
    7683                 :            :         }
    7684                 :    1922420 :       else if (TYPE_REF_P (TREE_TYPE (instance)))
    7685                 :            :         {
    7686                 :            :           /* We only need one hash table because it is always left empty.  */
    7687                 :    1829680 :           if (!fixed_type_or_null_ref_ht)
    7688                 :      12298 :             fixed_type_or_null_ref_ht
    7689                 :      12298 :               = new hash_table<nofree_ptr_hash<tree_node> > (37);
    7690                 :            : 
    7691                 :            :           /* Reference variables should be references to objects.  */
    7692                 :    1829680 :           if (nonnull)
    7693                 :     510665 :             *nonnull = 1;
    7694                 :            : 
    7695                 :            :           /* Enter the INSTANCE in a table to prevent recursion; a
    7696                 :            :              variable's initializer may refer to the variable
    7697                 :            :              itself.  */
    7698                 :    1829680 :           if (VAR_P (instance)
    7699                 :      40877 :               && DECL_INITIAL (instance)
    7700                 :      10022 :               && !type_dependent_expression_p_push (DECL_INITIAL (instance))
    7701                 :    1839700 :               && !fixed_type_or_null_ref_ht->find (instance))
    7702                 :            :             {
    7703                 :       9970 :               tree type;
    7704                 :       9970 :               tree_node **slot;
    7705                 :            : 
    7706                 :       9970 :               slot = fixed_type_or_null_ref_ht->find_slot (instance, INSERT);
    7707                 :       9970 :               *slot = instance;
    7708                 :       9970 :               type = RECUR (DECL_INITIAL (instance));
    7709                 :       9970 :               fixed_type_or_null_ref_ht->remove_elt (instance);
    7710                 :            : 
    7711                 :       9970 :               return type;
    7712                 :            :             }
    7713                 :            :         }
    7714                 :            :       return NULL_TREE;
    7715                 :            : 
    7716                 :      80522 :     case VIEW_CONVERT_EXPR:
    7717                 :      80522 :       if (location_wrapper_p (instance))
    7718                 :      80522 :         return RECUR (TREE_OPERAND (instance, 0));
    7719                 :            :       else
    7720                 :            :         /* TODO: Recursion may be correct for some non-location-wrapper
    7721                 :            :            uses of VIEW_CONVERT_EXPR.  */
    7722                 :            :         return NULL_TREE;
    7723                 :            : 
    7724                 :            :     default:
    7725                 :            :       return NULL_TREE;
    7726                 :            :     }
    7727                 :            : #undef RECUR
    7728                 :            : }
    7729                 :            : 
    7730                 :            : /* Return nonzero if the dynamic type of INSTANCE is known, and
    7731                 :            :    equivalent to the static type.  We also handle the case where
    7732                 :            :    INSTANCE is really a pointer. Return negative if this is a
    7733                 :            :    ctor/dtor. There the dynamic type is known, but this might not be
    7734                 :            :    the most derived base of the original object, and hence virtual
    7735                 :            :    bases may not be laid out according to this type.
    7736                 :            : 
    7737                 :            :    Used to determine whether the virtual function table is needed
    7738                 :            :    or not.
    7739                 :            : 
    7740                 :            :    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
    7741                 :            :    of our knowledge of its type.  *NONNULL should be initialized
    7742                 :            :    before this function is called.  */
    7743                 :            : 
    7744                 :            : int
    7745                 :   10031500 : resolves_to_fixed_type_p (tree instance, int* nonnull)
    7746                 :            : {
    7747