LCOV - code coverage report
Current view: top level - gcc/cp - init.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 2042 2144 95.2 %
Date: 2020-03-28 11:57:23 Functions: 59 59 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Handle initialization things in C++.
       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                 :            : /* High-level class interface.  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : #include "system.h"
      25                 :            : #include "coretypes.h"
      26                 :            : #include "target.h"
      27                 :            : #include "cp-tree.h"
      28                 :            : #include "stringpool.h"
      29                 :            : #include "varasm.h"
      30                 :            : #include "gimplify.h"
      31                 :            : #include "c-family/c-ubsan.h"
      32                 :            : #include "intl.h"
      33                 :            : #include "stringpool.h"
      34                 :            : #include "attribs.h"
      35                 :            : #include "asan.h"
      36                 :            : #include "stor-layout.h"
      37                 :            : 
      38                 :            : static bool begin_init_stmts (tree *, tree *);
      39                 :            : static tree finish_init_stmts (bool, tree, tree);
      40                 :            : static void construct_virtual_base (tree, tree);
      41                 :            : static void expand_aggr_init_1 (tree, tree, tree, tree, int, tsubst_flags_t);
      42                 :            : static void expand_default_init (tree, tree, tree, tree, int, tsubst_flags_t);
      43                 :            : static void perform_member_init (tree, tree);
      44                 :            : static int member_init_ok_or_else (tree, tree, tree);
      45                 :            : static void expand_virtual_init (tree, tree);
      46                 :            : static tree sort_mem_initializers (tree, tree);
      47                 :            : static tree initializing_context (tree);
      48                 :            : static void expand_cleanup_for_base (tree, tree);
      49                 :            : static tree dfs_initialize_vtbl_ptrs (tree, void *);
      50                 :            : static tree build_field_list (tree, tree, int *);
      51                 :            : static int diagnose_uninitialized_cst_or_ref_member_1 (tree, tree, bool, bool);
      52                 :            : 
      53                 :            : static GTY(()) tree fn;
      54                 :            : 
      55                 :            : /* We are about to generate some complex initialization code.
      56                 :            :    Conceptually, it is all a single expression.  However, we may want
      57                 :            :    to include conditionals, loops, and other such statement-level
      58                 :            :    constructs.  Therefore, we build the initialization code inside a
      59                 :            :    statement-expression.  This function starts such an expression.
      60                 :            :    STMT_EXPR_P and COMPOUND_STMT_P are filled in by this function;
      61                 :            :    pass them back to finish_init_stmts when the expression is
      62                 :            :    complete.  */
      63                 :            : 
      64                 :            : static bool
      65                 :     752765 : begin_init_stmts (tree *stmt_expr_p, tree *compound_stmt_p)
      66                 :            : {
      67                 :     752765 :   bool is_global = !building_stmt_list_p ();
      68                 :            : 
      69                 :     752765 :   *stmt_expr_p = begin_stmt_expr ();
      70                 :     752765 :   *compound_stmt_p = begin_compound_stmt (BCS_NO_SCOPE);
      71                 :            : 
      72                 :     752765 :   return is_global;
      73                 :            : }
      74                 :            : 
      75                 :            : /* Finish out the statement-expression begun by the previous call to
      76                 :            :    begin_init_stmts.  Returns the statement-expression itself.  */
      77                 :            : 
      78                 :            : static tree
      79                 :     752765 : finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt)
      80                 :            : {
      81                 :     752765 :   finish_compound_stmt (compound_stmt);
      82                 :            : 
      83                 :     752765 :   stmt_expr = finish_stmt_expr (stmt_expr, true);
      84                 :            : 
      85                 :     783098 :   gcc_assert (!building_stmt_list_p () == is_global);
      86                 :            : 
      87                 :     752765 :   return stmt_expr;
      88                 :            : }
      89                 :            : 
      90                 :            : /* Constructors */
      91                 :            : 
      92                 :            : /* Called from initialize_vtbl_ptrs via dfs_walk.  BINFO is the base
      93                 :            :    which we want to initialize the vtable pointer for, DATA is
      94                 :            :    TREE_LIST whose TREE_VALUE is the this ptr expression.  */
      95                 :            : 
      96                 :            : static tree
      97                 :    2498390 : dfs_initialize_vtbl_ptrs (tree binfo, void *data)
      98                 :            : {
      99                 :    4996780 :   if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
     100                 :            :     return dfs_skip_bases;
     101                 :            : 
     102                 :     453754 :   if (!BINFO_PRIMARY_P (binfo) || BINFO_VIRTUAL_P (binfo))
     103                 :            :     {
     104                 :     248122 :       tree base_ptr = TREE_VALUE ((tree) data);
     105                 :            : 
     106                 :     248122 :       base_ptr = build_base_path (PLUS_EXPR, base_ptr, binfo, /*nonnull=*/1,
     107                 :            :                                   tf_warning_or_error);
     108                 :            : 
     109                 :     248122 :       expand_virtual_init (binfo, base_ptr);
     110                 :            :     }
     111                 :            : 
     112                 :            :   return NULL_TREE;
     113                 :            : }
     114                 :            : 
     115                 :            : /* Initialize all the vtable pointers in the object pointed to by
     116                 :            :    ADDR.  */
     117                 :            : 
     118                 :            : void
     119                 :    2164610 : initialize_vtbl_ptrs (tree addr)
     120                 :            : {
     121                 :    2164610 :   tree list;
     122                 :    2164610 :   tree type;
     123                 :            : 
     124                 :    2164610 :   type = TREE_TYPE (TREE_TYPE (addr));
     125                 :    2164610 :   list = build_tree_list (type, addr);
     126                 :            : 
     127                 :            :   /* Walk through the hierarchy, initializing the vptr in each base
     128                 :            :      class.  We do these in pre-order because we can't find the virtual
     129                 :            :      bases for a class until we've initialized the vtbl for that
     130                 :            :      class.  */
     131                 :    2165390 :   dfs_walk_once (TYPE_BINFO (type), dfs_initialize_vtbl_ptrs, NULL, list);
     132                 :    2164610 : }
     133                 :            : 
     134                 :            : /* Return an expression for the zero-initialization of an object with
     135                 :            :    type T.  This expression will either be a constant (in the case
     136                 :            :    that T is a scalar), or a CONSTRUCTOR (in the case that T is an
     137                 :            :    aggregate), or NULL (in the case that T does not require
     138                 :            :    initialization).  In either case, the value can be used as
     139                 :            :    DECL_INITIAL for a decl of the indicated TYPE; it is a valid static
     140                 :            :    initializer. If NELTS is non-NULL, and TYPE is an ARRAY_TYPE, NELTS
     141                 :            :    is the number of elements in the array.  If STATIC_STORAGE_P is
     142                 :            :    TRUE, initializers are only generated for entities for which
     143                 :            :    zero-initialization does not simply mean filling the storage with
     144                 :            :    zero bytes.  FIELD_SIZE, if non-NULL, is the bit size of the field,
     145                 :            :    subfields with bit positions at or above that bit size shouldn't
     146                 :            :    be added.  Note that this only works when the result is assigned
     147                 :            :    to a base COMPONENT_REF; if we only have a pointer to the base subobject,
     148                 :            :    expand_assignment will end up clearing the full size of TYPE.  */
     149                 :            : 
     150                 :            : static tree
     151                 :     498995 : build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
     152                 :            :                    tree field_size)
     153                 :            : {
     154                 :     498995 :   tree init = NULL_TREE;
     155                 :            : 
     156                 :            :   /* [dcl.init]
     157                 :            : 
     158                 :            :      To zero-initialize an object of type T means:
     159                 :            : 
     160                 :            :      -- if T is a scalar type, the storage is set to the value of zero
     161                 :            :         converted to T.
     162                 :            : 
     163                 :            :      -- if T is a non-union class type, the storage for each nonstatic
     164                 :            :         data member and each base-class subobject is zero-initialized.
     165                 :            : 
     166                 :            :      -- if T is a union type, the storage for its first data member is
     167                 :            :         zero-initialized.
     168                 :            : 
     169                 :            :      -- if T is an array type, the storage for each element is
     170                 :            :         zero-initialized.
     171                 :            : 
     172                 :            :      -- if T is a reference type, no initialization is performed.  */
     173                 :            : 
     174                 :     498995 :   gcc_assert (nelts == NULL_TREE || TREE_CODE (nelts) == INTEGER_CST);
     175                 :            : 
     176                 :     498995 :   if (type == error_mark_node)
     177                 :            :     ;
     178                 :     498950 :   else if (static_storage_p && zero_init_p (type))
     179                 :            :     /* In order to save space, we do not explicitly build initializers
     180                 :            :        for items that do not need them.  GCC's semantics are that
     181                 :            :        items with static storage duration that are not otherwise
     182                 :            :        initialized are initialized to zero.  */
     183                 :            :     ;
     184                 :     439009 :   else if (TYPE_PTR_OR_PTRMEM_P (type))
     185                 :     233584 :     init = fold (convert (type, nullptr_node));
     186                 :     205425 :   else if (NULLPTR_TYPE_P (type))
     187                 :         21 :     init = build_int_cst (type, 0);
     188                 :     205404 :   else if (SCALAR_TYPE_P (type))
     189                 :     193715 :     init = fold (convert (type, integer_zero_node));
     190                 :      11689 :   else if (RECORD_OR_UNION_CODE_P (TREE_CODE (type)))
     191                 :            :     {
     192                 :      11471 :       tree field;
     193                 :      11471 :       vec<constructor_elt, va_gc> *v = NULL;
     194                 :            : 
     195                 :            :       /* Iterate over the fields, building initializations.  */
     196                 :     349462 :       for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     197                 :            :         {
     198                 :     339411 :           if (TREE_CODE (field) != FIELD_DECL)
     199                 :     319373 :             continue;
     200                 :            : 
     201                 :      20038 :           if (TREE_TYPE (field) == error_mark_node)
     202                 :          4 :             continue;
     203                 :            : 
     204                 :            :           /* Don't add virtual bases for base classes if they are beyond
     205                 :            :              the size of the current field, that means it is present
     206                 :            :              somewhere else in the object.  */
     207                 :      20034 :           if (field_size)
     208                 :            :             {
     209                 :       7906 :               tree bitpos = bit_position (field);
     210                 :       8184 :               if (TREE_CODE (bitpos) == INTEGER_CST
     211                 :       7906 :                   && !tree_int_cst_lt (bitpos, field_size))
     212                 :        278 :                 continue;
     213                 :            :             }
     214                 :            : 
     215                 :            :           /* Note that for class types there will be FIELD_DECLs
     216                 :            :              corresponding to base classes as well.  Thus, iterating
     217                 :            :              over TYPE_FIELDs will result in correct initialization of
     218                 :            :              all of the subobjects.  */
     219                 :      19780 :           if (!static_storage_p || !zero_init_p (TREE_TYPE (field)))
     220                 :            :             {
     221                 :      19752 :               tree new_field_size
     222                 :      19752 :                 = (DECL_FIELD_IS_BASE (field)
     223                 :       4737 :                    && DECL_SIZE (field)
     224                 :       4737 :                    && TREE_CODE (DECL_SIZE (field)) == INTEGER_CST)
     225                 :      19752 :                   ? DECL_SIZE (field) : NULL_TREE;
     226                 :      19752 :               tree value = build_zero_init_1 (TREE_TYPE (field),
     227                 :            :                                               /*nelts=*/NULL_TREE,
     228                 :            :                                               static_storage_p,
     229                 :            :                                               new_field_size);
     230                 :      19752 :               if (value)
     231                 :      19752 :                 CONSTRUCTOR_APPEND_ELT(v, field, value);
     232                 :            :             }
     233                 :            : 
     234                 :            :           /* For unions, only the first field is initialized.  */
     235                 :      19756 :           if (TREE_CODE (type) == UNION_TYPE)
     236                 :            :             break;
     237                 :            :         }
     238                 :            : 
     239                 :            :       /* Build a constructor to contain the initializations.  */
     240                 :      11471 :       init = build_constructor (type, v);
     241                 :            :     }
     242                 :        218 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     243                 :            :     {
     244                 :        204 :       tree max_index;
     245                 :        204 :       vec<constructor_elt, va_gc> *v = NULL;
     246                 :            : 
     247                 :            :       /* Iterate over the array elements, building initializations.  */
     248                 :        204 :       if (nelts)
     249                 :          0 :         max_index = fold_build2_loc (input_location,
     250                 :          0 :                                  MINUS_EXPR, TREE_TYPE (nelts),
     251                 :            :                                  nelts, integer_one_node);
     252                 :            :       else
     253                 :        204 :         max_index = array_type_nelts (type);
     254                 :            : 
     255                 :            :       /* If we have an error_mark here, we should just return error mark
     256                 :            :          as we don't know the size of the array yet.  */
     257                 :        204 :       if (max_index == error_mark_node)
     258                 :          4 :         return error_mark_node;
     259                 :        200 :       gcc_assert (TREE_CODE (max_index) == INTEGER_CST);
     260                 :            : 
     261                 :            :       /* A zero-sized array, which is accepted as an extension, will
     262                 :            :          have an upper bound of -1.  */
     263                 :        200 :       if (!tree_int_cst_equal (max_index, integer_minus_one_node))
     264                 :            :         {
     265                 :        200 :           constructor_elt ce;
     266                 :            : 
     267                 :            :           /* If this is a one element array, we just use a regular init.  */
     268                 :        200 :           if (tree_int_cst_equal (size_zero_node, max_index))
     269                 :         18 :             ce.index = size_zero_node;
     270                 :            :           else
     271                 :        182 :             ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node,
     272                 :            :                                 max_index);
     273                 :            : 
     274                 :        200 :           ce.value = build_zero_init_1 (TREE_TYPE (type),
     275                 :            :                                          /*nelts=*/NULL_TREE,
     276                 :            :                                          static_storage_p, NULL_TREE);
     277                 :        200 :           if (ce.value)
     278                 :            :             {
     279                 :        200 :               vec_alloc (v, 1);
     280                 :        200 :               v->quick_push (ce);
     281                 :            :             }
     282                 :            :         }
     283                 :            : 
     284                 :            :       /* Build a constructor to contain the initializations.  */
     285                 :        200 :       init = build_constructor (type, v);
     286                 :            :     }
     287                 :         14 :   else if (VECTOR_TYPE_P (type))
     288                 :          6 :     init = build_zero_cst (type);
     289                 :            :   else
     290                 :            :     {
     291                 :          8 :       gcc_assert (TYPE_REF_P (type));
     292                 :          8 :       init = build_zero_cst (type);
     293                 :            :     }
     294                 :            : 
     295                 :            :   /* In all cases, the initializer is a constant.  */
     296                 :     498946 :   if (init)
     297                 :     439005 :     TREE_CONSTANT (init) = 1;
     298                 :            : 
     299                 :            :   return init;
     300                 :            : }
     301                 :            : 
     302                 :            : /* Return an expression for the zero-initialization of an object with
     303                 :            :    type T.  This expression will either be a constant (in the case
     304                 :            :    that T is a scalar), or a CONSTRUCTOR (in the case that T is an
     305                 :            :    aggregate), or NULL (in the case that T does not require
     306                 :            :    initialization).  In either case, the value can be used as
     307                 :            :    DECL_INITIAL for a decl of the indicated TYPE; it is a valid static
     308                 :            :    initializer. If NELTS is non-NULL, and TYPE is an ARRAY_TYPE, NELTS
     309                 :            :    is the number of elements in the array.  If STATIC_STORAGE_P is
     310                 :            :    TRUE, initializers are only generated for entities for which
     311                 :            :    zero-initialization does not simply mean filling the storage with
     312                 :            :    zero bytes.  */
     313                 :            : 
     314                 :            : tree
     315                 :     478881 : build_zero_init (tree type, tree nelts, bool static_storage_p)
     316                 :            : {
     317                 :     478881 :   return build_zero_init_1 (type, nelts, static_storage_p, NULL_TREE);
     318                 :            : }
     319                 :            : 
     320                 :            : /* Return a suitable initializer for value-initializing an object of type
     321                 :            :    TYPE, as described in [dcl.init].  */
     322                 :            : 
     323                 :            : tree
     324                 :    1073440 : build_value_init (tree type, tsubst_flags_t complain)
     325                 :            : {
     326                 :            :   /* [dcl.init]
     327                 :            : 
     328                 :            :      To value-initialize an object of type T means:
     329                 :            : 
     330                 :            :      - if T is a class type (clause 9) with either no default constructor
     331                 :            :        (12.1) or a default constructor that is user-provided or deleted,
     332                 :            :        then the object is default-initialized;
     333                 :            : 
     334                 :            :      - if T is a (possibly cv-qualified) class type without a user-provided
     335                 :            :        or deleted default constructor, then the object is zero-initialized
     336                 :            :        and the semantic constraints for default-initialization are checked,
     337                 :            :        and if T has a non-trivial default constructor, the object is
     338                 :            :        default-initialized;
     339                 :            : 
     340                 :            :      - if T is an array type, then each element is value-initialized;
     341                 :            : 
     342                 :            :      - otherwise, the object is zero-initialized.
     343                 :            : 
     344                 :            :      A program that calls for default-initialization or
     345                 :            :      value-initialization of an entity of reference type is ill-formed.  */
     346                 :            : 
     347                 :            :   /* The AGGR_INIT_EXPR tweaking below breaks in templates.  */
     348                 :    1073440 :   gcc_assert (!processing_template_decl
     349                 :            :               || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE));
     350                 :            : 
     351                 :    1713790 :   if (CLASS_TYPE_P (type) && type_build_ctor_call (type))
     352                 :            :     {
     353                 :     213258 :       tree ctor
     354                 :     213258 :         = build_special_member_call (NULL_TREE, complete_ctor_identifier,
     355                 :            :                                      NULL, type, LOOKUP_NORMAL, complain);
     356                 :     426397 :       if (ctor == error_mark_node || TREE_CONSTANT (ctor))
     357                 :            :         return ctor;
     358                 :     213131 :       tree fn = NULL_TREE;
     359                 :     213131 :       if (TREE_CODE (ctor) == CALL_EXPR)
     360                 :     173690 :         fn = get_callee_fndecl (ctor);
     361                 :     213131 :       ctor = build_aggr_init_expr (type, ctor);
     362                 :     213131 :       if (fn && user_provided_p (fn))
     363                 :            :         return ctor;
     364                 :      84196 :       else if (TYPE_HAS_COMPLEX_DFLT (type))
     365                 :            :         {
     366                 :            :           /* This is a class that needs constructing, but doesn't have
     367                 :            :              a user-provided constructor.  So we need to zero-initialize
     368                 :            :              the object and then call the implicitly defined ctor.
     369                 :            :              This will be handled in simplify_aggr_init_expr.  */
     370                 :      44752 :           AGGR_INIT_ZERO_FIRST (ctor) = 1;
     371                 :      44752 :           return ctor;
     372                 :            :         }
     373                 :            :     }
     374                 :            : 
     375                 :            :   /* Discard any access checking during subobject initialization;
     376                 :            :      the checks are implied by the call to the ctor which we have
     377                 :            :      verified is OK (cpp0x/defaulted46.C).  */
     378                 :     899623 :   push_deferring_access_checks (dk_deferred);
     379                 :     899623 :   tree r = build_value_init_noctor (type, complain);
     380                 :     899623 :   pop_deferring_access_checks ();
     381                 :     899623 :   return r;
     382                 :            : }
     383                 :            : 
     384                 :            : /* Like build_value_init, but don't call the constructor for TYPE.  Used
     385                 :            :    for base initializers.  */
     386                 :            : 
     387                 :            : tree
     388                 :     899623 : build_value_init_noctor (tree type, tsubst_flags_t complain)
     389                 :            : {
     390                 :     899623 :   if (!COMPLETE_TYPE_P (type))
     391                 :            :     {
     392                 :          3 :       if (complain & tf_error)
     393                 :          3 :         error ("value-initialization of incomplete type %qT", type);
     394                 :          3 :       return error_mark_node;
     395                 :            :     }
     396                 :            :   /* FIXME the class and array cases should just use digest_init once it is
     397                 :            :      SFINAE-enabled.  */
     398                 :     899620 :   if (CLASS_TYPE_P (type))
     399                 :            :     {
     400                 :     466398 :       gcc_assert (!TYPE_HAS_COMPLEX_DFLT (type)
     401                 :            :                   || errorcount != 0);
     402                 :            :         
     403                 :     466398 :       if (TREE_CODE (type) != UNION_TYPE)
     404                 :            :         {
     405                 :     465141 :           tree field;
     406                 :     465141 :           vec<constructor_elt, va_gc> *v = NULL;
     407                 :            : 
     408                 :            :           /* Iterate over the fields, building initializations.  */
     409                 :    6996980 :           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     410                 :            :             {
     411                 :    6531850 :               tree ftype, value;
     412                 :            : 
     413                 :    6531850 :               if (TREE_CODE (field) != FIELD_DECL)
     414                 :    6463970 :                 continue;
     415                 :            : 
     416                 :      67874 :               ftype = TREE_TYPE (field);
     417                 :            : 
     418                 :      67874 :               if (ftype == error_mark_node)
     419                 :         10 :                 continue;
     420                 :            : 
     421                 :            :               /* Ignore flexible array members for value initialization.  */
     422                 :      67872 :               if (TREE_CODE (ftype) == ARRAY_TYPE
     423                 :       9481 :                   && !COMPLETE_TYPE_P (ftype)
     424                 :          8 :                   && !TYPE_DOMAIN (ftype)
     425                 :          8 :                   && COMPLETE_TYPE_P (TREE_TYPE (ftype))
     426                 :      67872 :                   && (next_initializable_field (DECL_CHAIN (field))
     427                 :            :                       == NULL_TREE))
     428                 :          8 :                 continue;
     429                 :            : 
     430                 :            :               /* We could skip vfields and fields of types with
     431                 :            :                  user-defined constructors, but I think that won't improve
     432                 :            :                  performance at all; it should be simpler in general just
     433                 :            :                  to zero out the entire object than try to only zero the
     434                 :            :                  bits that actually need it.  */
     435                 :            : 
     436                 :            :               /* Note that for class types there will be FIELD_DECLs
     437                 :            :                  corresponding to base classes as well.  Thus, iterating
     438                 :            :                  over TYPE_FIELDs will result in correct initialization of
     439                 :            :                  all of the subobjects.  */
     440                 :      67856 :               value = build_value_init (ftype, complain);
     441                 :      67856 :               value = maybe_constant_init (value);
     442                 :            : 
     443                 :      67856 :               if (value == error_mark_node)
     444                 :          5 :                 return error_mark_node;
     445                 :            : 
     446                 :      67851 :               CONSTRUCTOR_APPEND_ELT(v, field, value);
     447                 :            : 
     448                 :            :               /* We shouldn't have gotten here for anything that would need
     449                 :            :                  non-trivial initialization, and gimplify_init_ctor_preeval
     450                 :            :                  would need to be fixed to allow it.  */
     451                 :      67851 :               gcc_assert (TREE_CODE (value) != TARGET_EXPR
     452                 :            :                           && TREE_CODE (value) != AGGR_INIT_EXPR);
     453                 :            :             }
     454                 :            : 
     455                 :            :           /* Build a constructor to contain the zero- initializations.  */
     456                 :     465136 :           return build_constructor (type, v);
     457                 :            :         }
     458                 :            :     }
     459                 :     433222 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     460                 :            :     {
     461                 :      18399 :       vec<constructor_elt, va_gc> *v = NULL;
     462                 :            : 
     463                 :            :       /* Iterate over the array elements, building initializations.  */
     464                 :      18399 :       tree max_index = array_type_nelts (type);
     465                 :            : 
     466                 :            :       /* If we have an error_mark here, we should just return error mark
     467                 :            :          as we don't know the size of the array yet.  */
     468                 :      18399 :       if (max_index == error_mark_node)
     469                 :            :         {
     470                 :          0 :           if (complain & tf_error)
     471                 :          0 :             error ("cannot value-initialize array of unknown bound %qT",
     472                 :            :                    type);
     473                 :          0 :           return error_mark_node;
     474                 :            :         }
     475                 :      18399 :       gcc_assert (TREE_CODE (max_index) == INTEGER_CST);
     476                 :            : 
     477                 :            :       /* A zero-sized array, which is accepted as an extension, will
     478                 :            :          have an upper bound of -1.  */
     479                 :      18399 :       if (!tree_int_cst_equal (max_index, integer_minus_one_node))
     480                 :            :         {
     481                 :      18399 :           constructor_elt ce;
     482                 :            : 
     483                 :            :           /* If this is a one element array, we just use a regular init.  */
     484                 :      18399 :           if (tree_int_cst_equal (size_zero_node, max_index))
     485                 :         39 :             ce.index = size_zero_node;
     486                 :            :           else
     487                 :      18360 :             ce.index = build2 (RANGE_EXPR, sizetype, size_zero_node, max_index);
     488                 :            : 
     489                 :      18399 :           ce.value = build_value_init (TREE_TYPE (type), complain);
     490                 :      18399 :           ce.value = maybe_constant_init (ce.value);
     491                 :      18399 :           if (ce.value == error_mark_node)
     492                 :      18399 :             return error_mark_node;
     493                 :            : 
     494                 :      18399 :           vec_alloc (v, 1);
     495                 :      18399 :           v->quick_push (ce);
     496                 :            : 
     497                 :            :           /* We shouldn't have gotten here for anything that would need
     498                 :            :              non-trivial initialization, and gimplify_init_ctor_preeval
     499                 :            :              would need to be fixed to allow it.  */
     500                 :      18399 :           gcc_assert (TREE_CODE (ce.value) != TARGET_EXPR
     501                 :            :                       && TREE_CODE (ce.value) != AGGR_INIT_EXPR);
     502                 :            :         }
     503                 :            : 
     504                 :            :       /* Build a constructor to contain the initializations.  */
     505                 :      18399 :       return build_constructor (type, v);
     506                 :            :     }
     507                 :     414823 :   else if (TREE_CODE (type) == FUNCTION_TYPE)
     508                 :            :     {
     509                 :          5 :       if (complain & tf_error)
     510                 :          0 :         error ("value-initialization of function type %qT", type);
     511                 :          5 :       return error_mark_node;
     512                 :            :     }
     513                 :     414818 :   else if (TYPE_REF_P (type))
     514                 :            :     {
     515                 :        121 :       if (complain & tf_error)
     516                 :         19 :         error ("value-initialization of reference type %qT", type);
     517                 :        121 :       return error_mark_node;
     518                 :            :     }
     519                 :            : 
     520                 :     415954 :   return build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
     521                 :            : }
     522                 :            : 
     523                 :            : /* Initialize current class with INIT, a TREE_LIST of
     524                 :            :    arguments for a target constructor. If TREE_LIST is void_type_node,
     525                 :            :    an empty initializer list was given.  */
     526                 :            : 
     527                 :            : static void
     528                 :      11901 : perform_target_ctor (tree init)
     529                 :            : {
     530                 :      11901 :   tree decl = current_class_ref;
     531                 :      11901 :   tree type = current_class_type;
     532                 :            : 
     533                 :      11901 :   finish_expr_stmt (build_aggr_init (decl, init,
     534                 :            :                                      LOOKUP_NORMAL|LOOKUP_DELEGATING_CONS,
     535                 :            :                                      tf_warning_or_error));
     536                 :      11901 :   if (type_build_dtor_call (type))
     537                 :            :     {
     538                 :      10168 :       tree expr = build_delete (input_location,
     539                 :            :                                 type, decl, sfk_complete_destructor,
     540                 :            :                                 LOOKUP_NORMAL
     541                 :            :                                 |LOOKUP_NONVIRTUAL
     542                 :            :                                 |LOOKUP_DESTRUCTOR,
     543                 :            :                                 0, tf_warning_or_error);
     544                 :      10168 :       if (expr != error_mark_node
     545                 :      20336 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
     546                 :       9959 :         finish_eh_cleanup (expr);
     547                 :            :     }
     548                 :      11901 : }
     549                 :            : 
     550                 :            : /* Return the non-static data initializer for FIELD_DECL MEMBER.  */
     551                 :            : 
     552                 :            : static GTY((cache)) decl_tree_cache_map *nsdmi_inst;
     553                 :            : 
     554                 :            : tree
     555                 :     254446 : get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain)
     556                 :            : {
     557                 :     254446 :   tree init;
     558                 :     254446 :   tree save_ccp = current_class_ptr;
     559                 :     254446 :   tree save_ccr = current_class_ref;
     560                 :            :   
     561                 :     254446 :   if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
     562                 :            :     {
     563                 :       7970 :       init = DECL_INITIAL (DECL_TI_TEMPLATE (member));
     564                 :       7970 :       location_t expr_loc
     565                 :       7970 :         = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (member));
     566                 :       7970 :       if (TREE_CODE (init) == DEFERRED_PARSE)
     567                 :            :         /* Unparsed.  */;
     568                 :      14914 :       else if (tree *slot = hash_map_safe_get (nsdmi_inst, member))
     569                 :       3620 :         init = *slot;
     570                 :            :       /* Check recursive instantiation.  */
     571                 :       4350 :       else if (DECL_INSTANTIATING_NSDMI_P (member))
     572                 :            :         {
     573                 :          9 :           if (complain & tf_error)
     574                 :          9 :             error_at (expr_loc, "recursive instantiation of default member "
     575                 :            :                       "initializer for %qD", member);
     576                 :          9 :           init = error_mark_node;
     577                 :            :         }
     578                 :            :       else
     579                 :            :         {
     580                 :       8682 :           cp_evaluated ev;
     581                 :            : 
     582                 :       4341 :           location_t sloc = input_location;
     583                 :       4341 :           input_location = expr_loc;
     584                 :            : 
     585                 :       4341 :           DECL_INSTANTIATING_NSDMI_P (member) = 1;
     586                 :            : 
     587                 :       4341 :           bool pushed = false;
     588                 :       4341 :           if (!currently_open_class (DECL_CONTEXT (member)))
     589                 :            :             {
     590                 :        119 :               push_to_top_level ();
     591                 :        119 :               push_nested_class (DECL_CONTEXT (member));
     592                 :        119 :               pushed = true;
     593                 :            :             }
     594                 :            : 
     595                 :       4341 :           gcc_checking_assert (!processing_template_decl);
     596                 :            : 
     597                 :       4341 :           inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED);
     598                 :            : 
     599                 :       4341 :           start_lambda_scope (member);
     600                 :            : 
     601                 :            :           /* Do deferred instantiation of the NSDMI.  */
     602                 :       8682 :           init = (tsubst_copy_and_build
     603                 :       4341 :                   (init, DECL_TI_ARGS (member),
     604                 :            :                    complain, member, /*function_p=*/false,
     605                 :            :                    /*integral_constant_expression_p=*/false));
     606                 :       4341 :           init = digest_nsdmi_init (member, init, complain);
     607                 :            : 
     608                 :       4341 :           finish_lambda_scope ();
     609                 :            : 
     610                 :       4341 :           DECL_INSTANTIATING_NSDMI_P (member) = 0;
     611                 :            : 
     612                 :       4341 :           if (init != error_mark_node)
     613                 :       4306 :             hash_map_safe_put<hm_ggc> (nsdmi_inst, member, init);
     614                 :            : 
     615                 :       4341 :           if (pushed)
     616                 :            :             {
     617                 :        119 :               pop_nested_class ();
     618                 :        119 :               pop_from_top_level ();
     619                 :            :             }
     620                 :            : 
     621                 :       4341 :           input_location = sloc;
     622                 :            :         }
     623                 :            :     }
     624                 :            :   else
     625                 :     246476 :     init = DECL_INITIAL (member);
     626                 :            : 
     627                 :     254446 :   if (init && TREE_CODE (init) == DEFERRED_PARSE)
     628                 :            :     {
     629                 :         21 :       if (complain & tf_error)
     630                 :            :         {
     631                 :         15 :           error ("default member initializer for %qD required before the end "
     632                 :            :                  "of its enclosing class", member);
     633                 :         15 :           inform (location_of (init), "defined here");
     634                 :         15 :           DECL_INITIAL (member) = error_mark_node;
     635                 :            :         }
     636                 :         21 :       init = error_mark_node;
     637                 :            :     }
     638                 :            : 
     639                 :     254446 :   if (in_ctor)
     640                 :            :     {
     641                 :     247465 :       current_class_ptr = save_ccp;
     642                 :     247465 :       current_class_ref = save_ccr;
     643                 :            :     }
     644                 :            :   else
     645                 :            :     {
     646                 :            :       /* Use a PLACEHOLDER_EXPR when we don't have a 'this' parameter to
     647                 :            :          refer to; constexpr evaluation knows what to do with it.  */
     648                 :       6981 :       current_class_ref = build0 (PLACEHOLDER_EXPR, DECL_CONTEXT (member));
     649                 :       6981 :       current_class_ptr = build_address (current_class_ref);
     650                 :            :     }
     651                 :            : 
     652                 :            :   /* Strip redundant TARGET_EXPR so we don't need to remap it, and
     653                 :            :      so the aggregate init code below will see a CONSTRUCTOR.  */
     654                 :     254446 :   bool simple_target = (init && SIMPLE_TARGET_EXPR_P (init));
     655                 :        146 :   if (simple_target)
     656                 :        146 :     init = TARGET_EXPR_INITIAL (init);
     657                 :     254446 :   init = break_out_target_exprs (init, /*loc*/true);
     658                 :     254446 :   if (in_ctor && init && TREE_CODE (init) == TARGET_EXPR)
     659                 :            :     /* This expresses the full initialization, prevent perform_member_init from
     660                 :            :        calling another constructor (58162).  */
     661                 :        734 :     TARGET_EXPR_DIRECT_INIT_P (init) = true;
     662                 :     254446 :   if (simple_target && TREE_CODE (init) != CONSTRUCTOR)
     663                 :            :     /* Now put it back so C++17 copy elision works.  */
     664                 :         47 :     init = get_target_expr (init);
     665                 :            : 
     666                 :     254446 :   current_class_ptr = save_ccp;
     667                 :     254446 :   current_class_ref = save_ccr;
     668                 :     254446 :   return init;
     669                 :            : }
     670                 :            : 
     671                 :            : /* Diagnose the flexible array MEMBER if its INITializer is non-null
     672                 :            :    and return true if so.  Otherwise return false.  */
     673                 :            : 
     674                 :            : bool
     675                 :       9756 : maybe_reject_flexarray_init (tree member, tree init)
     676                 :            : {
     677                 :       9756 :   tree type = TREE_TYPE (member);
     678                 :            : 
     679                 :       9756 :   if (!init
     680                 :       9725 :       || TREE_CODE (type) != ARRAY_TYPE
     681                 :       9996 :       || TYPE_DOMAIN (type))
     682                 :            :     return false;
     683                 :            : 
     684                 :            :   /* Point at the flexible array member declaration if it's initialized
     685                 :            :      in-class, and at the ctor if it's initialized in a ctor member
     686                 :            :      initializer list.  */
     687                 :         50 :   location_t loc;
     688                 :         50 :   if (DECL_INITIAL (member) == init
     689                 :         50 :       || !current_function_decl
     690                 :         96 :       || DECL_DEFAULTED_FN (current_function_decl))
     691                 :         30 :     loc = DECL_SOURCE_LOCATION (member);
     692                 :            :   else
     693                 :         20 :     loc = DECL_SOURCE_LOCATION (current_function_decl);
     694                 :            : 
     695                 :         50 :   error_at (loc, "initializer for flexible array member %q#D", member);
     696                 :         50 :   return true;
     697                 :            : }
     698                 :            : 
     699                 :            : /* If INIT's value can come from a call to std::initializer_list<T>::begin,
     700                 :            :    return that function.  Otherwise, NULL_TREE.  */
     701                 :            : 
     702                 :            : static tree
     703                 :         11 : find_list_begin (tree init)
     704                 :            : {
     705                 :         14 :   STRIP_NOPS (init);
     706                 :         14 :   while (TREE_CODE (init) == COMPOUND_EXPR)
     707                 :          0 :     init = TREE_OPERAND (init, 1);
     708                 :         14 :   STRIP_NOPS (init);
     709                 :         14 :   if (TREE_CODE (init) == COND_EXPR)
     710                 :            :     {
     711                 :          3 :       tree left = TREE_OPERAND (init, 1);
     712                 :          3 :       if (!left)
     713                 :          0 :         left = TREE_OPERAND (init, 0);
     714                 :          3 :       left = find_list_begin (left);
     715                 :          3 :       if (left)
     716                 :            :         return left;
     717                 :          3 :       return find_list_begin (TREE_OPERAND (init, 2));
     718                 :            :     }
     719                 :         11 :   if (TREE_CODE (init) == CALL_EXPR)
     720                 :          8 :     if (tree fn = get_callee_fndecl (init))
     721                 :          8 :       if (id_equal (DECL_NAME (fn), "begin")
     722                 :          8 :           && is_std_init_list (DECL_CONTEXT (fn)))
     723                 :          3 :         return fn;
     724                 :            :   return NULL_TREE;
     725                 :            : }
     726                 :            : 
     727                 :            : /* If INIT initializing MEMBER is copying the address of the underlying array
     728                 :            :    of an initializer_list, warn.  */
     729                 :            : 
     730                 :            : static void
     731                 :     849455 : maybe_warn_list_ctor (tree member, tree init)
     732                 :            : {
     733                 :     849455 :   tree memtype = TREE_TYPE (member);
     734                 :     673163 :   if (!init || !TYPE_PTR_P (memtype)
     735                 :    1169330 :       || !is_list_ctor (current_function_decl))
     736                 :     849445 :     return;
     737                 :            : 
     738                 :         20 :   tree parms = FUNCTION_FIRST_USER_PARMTYPE (current_function_decl);
     739                 :         10 :   tree initlist = non_reference (TREE_VALUE (parms));
     740                 :         10 :   tree targs = CLASSTYPE_TI_ARGS (initlist);
     741                 :         10 :   tree elttype = TREE_VEC_ELT (targs, 0);
     742                 :            : 
     743                 :         20 :   if (!same_type_ignoring_top_level_qualifiers_p
     744                 :         10 :       (TREE_TYPE (memtype), elttype))
     745                 :            :     return;
     746                 :            : 
     747                 :          8 :   tree begin = find_list_begin (init);
     748                 :          8 :   if (!begin)
     749                 :            :     return;
     750                 :            : 
     751                 :          3 :   location_t loc = cp_expr_loc_or_input_loc (init);
     752                 :          3 :   warning_at (loc, OPT_Winit_list_lifetime,
     753                 :            :              "initializing %qD from %qE does not extend the lifetime "
     754                 :            :              "of the underlying array", member, begin);
     755                 :            : }
     756                 :            : 
     757                 :            : /* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of
     758                 :            :    arguments.  If TREE_LIST is void_type_node, an empty initializer
     759                 :            :    list was given; if NULL_TREE no initializer was given.  */
     760                 :            : 
     761                 :            : static void
     762                 :    1340440 : perform_member_init (tree member, tree init)
     763                 :            : {
     764                 :    1340440 :   tree decl;
     765                 :    1340440 :   tree type = TREE_TYPE (member);
     766                 :            : 
     767                 :            :   /* Use the non-static data member initializer if there was no
     768                 :            :      mem-initializer for this field.  */
     769                 :    1340440 :   if (init == NULL_TREE)
     770                 :     247465 :     init = get_nsdmi (member, /*ctor*/true, tf_warning_or_error);
     771                 :            : 
     772                 :    1340440 :   if (init == error_mark_node)
     773                 :            :     return;
     774                 :            : 
     775                 :            :   /* Effective C++ rule 12 requires that all data members be
     776                 :            :      initialized.  */
     777                 :    1340430 :   if (warn_ecpp && init == NULL_TREE && TREE_CODE (type) != ARRAY_TYPE)
     778                 :          0 :     warning_at (DECL_SOURCE_LOCATION (current_function_decl), OPT_Weffc__,
     779                 :            :                 "%qD should be initialized in the member initialization list",
     780                 :            :                 member);
     781                 :            : 
     782                 :            :   /* Get an lvalue for the data member.  */
     783                 :    1340430 :   decl = build_class_member_access_expr (current_class_ref, member,
     784                 :            :                                          /*access_path=*/NULL_TREE,
     785                 :            :                                          /*preserve_reference=*/true,
     786                 :            :                                          tf_warning_or_error);
     787                 :    1340430 :   if (decl == error_mark_node)
     788                 :            :     return;
     789                 :            : 
     790                 :      49230 :   if (warn_init_self && init && TREE_CODE (init) == TREE_LIST
     791                 :    1376010 :       && TREE_CHAIN (init) == NULL_TREE)
     792                 :            :     {
     793                 :      33629 :       tree val = TREE_VALUE (init);
     794                 :            :       /* Handle references.  */
     795                 :      33629 :       if (REFERENCE_REF_P (val))
     796                 :       1346 :         val = TREE_OPERAND (val, 0);
     797                 :       1091 :       if (TREE_CODE (val) == COMPONENT_REF && TREE_OPERAND (val, 1) == member
     798                 :      34644 :           && TREE_OPERAND (val, 0) == current_class_ref)
     799                 :         20 :         warning_at (DECL_SOURCE_LOCATION (current_function_decl),
     800                 :            :                     OPT_Winit_self, "%qD is initialized with itself",
     801                 :            :                     member);
     802                 :            :     }
     803                 :            : 
     804                 :    1340420 :   if (array_of_unknown_bound_p (type))
     805                 :            :     {
     806                 :         54 :       maybe_reject_flexarray_init (member, init);
     807                 :         54 :       return;
     808                 :            :     }
     809                 :            : 
     810                 :    1111880 :   if (init && TREE_CODE (init) == TREE_LIST
     811                 :    2306190 :       && (DIRECT_LIST_INIT_P (TREE_VALUE (init))
     812                 :            :           /* FIXME C++20 parenthesized aggregate init (PR 92812).  */
     813                 :    1234590 :           || !(/* cxx_dialect >= cxx2a ? CP_AGGREGATE_TYPE_P (type) */
     814                 :    1234590 :                /* :  */CLASS_TYPE_P (type))))
     815                 :     684113 :     init = build_x_compound_expr_from_list (init, ELK_MEM_INIT,
     816                 :            :                                             tf_warning_or_error);
     817                 :            : 
     818                 :    1340360 :   if (init == void_type_node)
     819                 :            :     {
     820                 :            :       /* mem() means value-initialization.  */
     821                 :     127129 :       if (TREE_CODE (type) == ARRAY_TYPE)
     822                 :            :         {
     823                 :        175 :           init = build_vec_init_expr (type, init, tf_warning_or_error);
     824                 :        175 :           init = build2 (INIT_EXPR, type, decl, init);
     825                 :        175 :           finish_expr_stmt (init);
     826                 :            :         }
     827                 :            :       else
     828                 :            :         {
     829                 :     126954 :           tree value = build_value_init (type, tf_warning_or_error);
     830                 :     126954 :           if (value == error_mark_node)
     831                 :            :             return;
     832                 :     126946 :           init = build2 (INIT_EXPR, type, decl, value);
     833                 :     126946 :           finish_expr_stmt (init);
     834                 :            :         }
     835                 :            :     }
     836                 :            :   /* Deal with this here, as we will get confused if we try to call the
     837                 :            :      assignment op for an anonymous union.  This can happen in a
     838                 :            :      synthesized copy constructor.  */
     839                 :    1565010 :   else if (ANON_AGGR_TYPE_P (type))
     840                 :            :     {
     841                 :         10 :       if (init)
     842                 :            :         {
     843                 :         10 :           init = build2 (INIT_EXPR, type, decl, TREE_VALUE (init));
     844                 :         10 :           finish_expr_stmt (init);
     845                 :            :         }
     846                 :            :     }
     847                 :    1213220 :   else if (init
     848                 :    1213220 :            && (TYPE_REF_P (type)
     849                 :     965490 :                || (TREE_CODE (init) == CONSTRUCTOR
     850                 :      31237 :                    && (CP_AGGREGATE_TYPE_P (type)
     851                 :      12480 :                        || is_std_init_list (type)))))
     852                 :            :     {
     853                 :            :       /* With references and list-initialization, we need to deal with
     854                 :            :          extending temporary lifetimes.  12.2p5: "A temporary bound to a
     855                 :            :          reference member in a constructor’s ctor-initializer (12.6.2)
     856                 :            :          persists until the constructor exits."  */
     857                 :      28956 :       unsigned i; tree t;
     858                 :      57837 :       releasing_vec cleanups;
     859                 :      28956 :       if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), type))
     860                 :            :         {
     861                 :        847 :           if (BRACE_ENCLOSED_INITIALIZER_P (init)
     862                 :      20235 :               && CP_AGGREGATE_TYPE_P (type))
     863                 :        823 :             init = reshape_init (type, init, tf_warning_or_error);
     864                 :      19151 :           init = digest_init (type, init, tf_warning_or_error);
     865                 :            :         }
     866                 :      28956 :       if (init == error_mark_node)
     867                 :         75 :         return;
     868                 :      57880 :       if (DECL_SIZE (member) && integer_zerop (DECL_SIZE (member))
     869                 :      28999 :           && !TREE_SIDE_EFFECTS (init))
     870                 :            :         /* Don't add trivial initialization of an empty base/field, as they
     871                 :            :            might not be ordered the way the back-end expects.  */
     872                 :            :         return;
     873                 :            :       /* A FIELD_DECL doesn't really have a suitable lifetime, but
     874                 :            :          make_temporary_var_for_ref_to_temp will treat it as automatic and
     875                 :            :          set_up_extended_ref_temp wants to use the decl in a warning.  */
     876                 :      28881 :       init = extend_ref_init_temps (member, init, &cleanups);
     877                 :      28881 :       if (TREE_CODE (type) == ARRAY_TYPE
     878                 :      29641 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (type)))
     879                 :          0 :         init = build_vec_init_expr (type, init, tf_warning_or_error);
     880                 :      28881 :       init = build2 (INIT_EXPR, type, decl, init);
     881                 :      28881 :       finish_expr_stmt (init);
     882                 :      28973 :       FOR_EACH_VEC_ELT (*cleanups, i, t)
     883                 :         92 :         push_cleanup (decl, t, false);
     884                 :            :     }
     885                 :    1184270 :   else if (type_build_ctor_call (type)
     886                 :    1184270 :            || (init && CLASS_TYPE_P (strip_array_types (type))))
     887                 :            :     {
     888                 :     334812 :       if (TREE_CODE (type) == ARRAY_TYPE)
     889                 :            :         {
     890                 :        485 :           if (init == NULL_TREE
     891                 :        532 :               || same_type_ignoring_top_level_qualifiers_p (type,
     892                 :         47 :                                                             TREE_TYPE (init)))
     893                 :            :             {
     894                 :        473 :               if (TYPE_DOMAIN (type) && TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
     895                 :            :                 {
     896                 :            :                   /* Initialize the array only if it's not a flexible
     897                 :            :                      array member (i.e., if it has an upper bound).  */
     898                 :        473 :                   init = build_vec_init_expr (type, init, tf_warning_or_error);
     899                 :        473 :                   init = build2 (INIT_EXPR, type, decl, init);
     900                 :        473 :                   finish_expr_stmt (init);
     901                 :            :                 }
     902                 :            :             }
     903                 :            :           else
     904                 :         12 :             error ("invalid initializer for array member %q#D", member);
     905                 :            :         }
     906                 :            :       else
     907                 :            :         {
     908                 :     334327 :           int flags = LOOKUP_NORMAL;
     909                 :     668654 :           if (DECL_DEFAULTED_FN (current_function_decl))
     910                 :      32313 :             flags |= LOOKUP_DEFAULTED;
     911                 :     334327 :           if (CP_TYPE_CONST_P (type)
     912                 :        768 :               && init == NULL_TREE
     913                 :     334374 :               && default_init_uninitialized_part (type))
     914                 :            :             {
     915                 :            :               /* TYPE_NEEDS_CONSTRUCTING can be set just because we have a
     916                 :            :                  vtable; still give this diagnostic.  */
     917                 :          6 :               auto_diagnostic_group d;
     918                 :          3 :               if (permerror (DECL_SOURCE_LOCATION (current_function_decl),
     919                 :            :                              "uninitialized const member in %q#T", type))
     920                 :          3 :                 inform (DECL_SOURCE_LOCATION (member),
     921                 :            :                         "%q#D should be initialized", member );
     922                 :            :             }
     923                 :     334327 :           finish_expr_stmt (build_aggr_init (decl, init, flags,
     924                 :            :                                              tf_warning_or_error));
     925                 :            :         }
     926                 :            :     }
     927                 :            :   else
     928                 :            :     {
     929                 :     849455 :       if (init == NULL_TREE)
     930                 :            :         {
     931                 :     176292 :           tree core_type;
     932                 :            :           /* member traversal: note it leaves init NULL */
     933                 :     176292 :           if (TYPE_REF_P (type))
     934                 :            :             {
     935                 :         18 :               auto_diagnostic_group d;
     936                 :          9 :               if (permerror (DECL_SOURCE_LOCATION (current_function_decl),
     937                 :            :                              "uninitialized reference member in %q#T", type))
     938                 :          9 :                 inform (DECL_SOURCE_LOCATION (member),
     939                 :            :                         "%q#D should be initialized", member);
     940                 :            :             }
     941                 :     176283 :           else if (CP_TYPE_CONST_P (type))
     942                 :            :             {
     943                 :         34 :               auto_diagnostic_group d;
     944                 :         17 :               if (permerror (DECL_SOURCE_LOCATION (current_function_decl),
     945                 :            :                              "uninitialized const member in %q#T", type))
     946                 :         17 :                   inform (DECL_SOURCE_LOCATION (member),
     947                 :            :                           "%q#D should be initialized", member );
     948                 :            :             }
     949                 :            : 
     950                 :     176292 :           core_type = strip_array_types (type);
     951                 :            : 
     952                 :       8426 :           if (CLASS_TYPE_P (core_type)
     953                 :     184706 :               && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
     954                 :       8412 :                   || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
     955                 :          3 :             diagnose_uninitialized_cst_or_ref_member (core_type,
     956                 :            :                                                       /*using_new=*/false,
     957                 :            :                                                       /*complain=*/true);
     958                 :            :         }
     959                 :            : 
     960                 :     849455 :       maybe_warn_list_ctor (member, init);
     961                 :            : 
     962                 :     849455 :       if (init)
     963                 :     673163 :         finish_expr_stmt (cp_build_modify_expr (input_location, decl,
     964                 :            :                                                 INIT_EXPR, init,
     965                 :            :                                                 tf_warning_or_error));
     966                 :            :     }
     967                 :            : 
     968                 :    1340280 :   if (type_build_dtor_call (type))
     969                 :            :     {
     970                 :     266155 :       tree expr;
     971                 :            : 
     972                 :     266155 :       expr = build_class_member_access_expr (current_class_ref, member,
     973                 :            :                                              /*access_path=*/NULL_TREE,
     974                 :            :                                              /*preserve_reference=*/false,
     975                 :            :                                              tf_warning_or_error);
     976                 :     266155 :       expr = build_delete (input_location,
     977                 :            :                            type, expr, sfk_complete_destructor,
     978                 :            :                            LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0,
     979                 :            :                            tf_warning_or_error);
     980                 :            : 
     981                 :     266155 :       if (expr != error_mark_node
     982                 :     532307 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
     983                 :     251191 :         finish_eh_cleanup (expr);
     984                 :            :     }
     985                 :            : }
     986                 :            : 
     987                 :            : /* Returns a TREE_LIST containing (as the TREE_PURPOSE of each node) all
     988                 :            :    the FIELD_DECLs on the TYPE_FIELDS list for T, in reverse order.  */
     989                 :            : 
     990                 :            : static tree
     991                 :    1641150 : build_field_list (tree t, tree list, int *uses_unions_or_anon_p)
     992                 :            : {
     993                 :    1641150 :   tree fields;
     994                 :            : 
     995                 :            :   /* Note whether or not T is a union.  */
     996                 :    1641150 :   if (TREE_CODE (t) == UNION_TYPE)
     997                 :     107494 :     *uses_unions_or_anon_p = 1;
     998                 :            : 
     999                 :   76926500 :   for (fields = TYPE_FIELDS (t); fields; fields = DECL_CHAIN (fields))
    1000                 :            :     {
    1001                 :   75177800 :       tree fieldtype;
    1002                 :            : 
    1003                 :            :       /* Skip CONST_DECLs for enumeration constants and so forth.  */
    1004                 :   77231300 :       if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
    1005                 :   73511600 :         continue;
    1006                 :            : 
    1007                 :    1666200 :       fieldtype = TREE_TYPE (fields);
    1008                 :            : 
    1009                 :            :       /* For an anonymous struct or union, we must recursively
    1010                 :            :          consider the fields of the anonymous type.  They can be
    1011                 :            :          directly initialized from the constructor.  */
    1012                 :    2176880 :       if (ANON_AGGR_TYPE_P (fieldtype))
    1013                 :            :         {
    1014                 :            :           /* Add this field itself.  Synthesized copy constructors
    1015                 :            :              initialize the entire aggregate.  */
    1016                 :     107024 :           list = tree_cons (fields, NULL_TREE, list);
    1017                 :            :           /* And now add the fields in the anonymous aggregate.  */
    1018                 :     107024 :           list = build_field_list (fieldtype, list, uses_unions_or_anon_p);
    1019                 :     107024 :           *uses_unions_or_anon_p = 1;
    1020                 :            :         }
    1021                 :            :       /* Add this field.  */
    1022                 :    1559180 :       else if (DECL_NAME (fields))
    1023                 :    1559140 :         list = tree_cons (fields, NULL_TREE, list);
    1024                 :            :     }
    1025                 :            : 
    1026                 :    1641150 :   return list;
    1027                 :            : }
    1028                 :            : 
    1029                 :            : /* Return the innermost aggregate scope for FIELD, whether that is
    1030                 :            :    the enclosing class or an anonymous aggregate within it.  */
    1031                 :            : 
    1032                 :            : static tree
    1033                 :     432176 : innermost_aggr_scope (tree field)
    1034                 :            : {
    1035                 :     432176 :   if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1036                 :     432176 :     return TREE_TYPE (field);
    1037                 :            :   else
    1038                 :     432160 :     return DECL_CONTEXT (field);
    1039                 :            : }
    1040                 :            : 
    1041                 :            : /* The MEM_INITS are a TREE_LIST.  The TREE_PURPOSE of each list gives
    1042                 :            :    a FIELD_DECL or BINFO in T that needs initialization.  The
    1043                 :            :    TREE_VALUE gives the initializer, or list of initializer arguments.
    1044                 :            : 
    1045                 :            :    Return a TREE_LIST containing all of the initializations required
    1046                 :            :    for T, in the order in which they should be performed.  The output
    1047                 :            :    list has the same format as the input.  */
    1048                 :            : 
    1049                 :            : static tree
    1050                 :    1534130 : sort_mem_initializers (tree t, tree mem_inits)
    1051                 :            : {
    1052                 :    1534130 :   tree init;
    1053                 :    1534130 :   tree base, binfo, base_binfo;
    1054                 :    1534130 :   tree sorted_inits;
    1055                 :    1534130 :   tree next_subobject;
    1056                 :    1534130 :   vec<tree, va_gc> *vbases;
    1057                 :    1534130 :   int i;
    1058                 :    1534130 :   int uses_unions_or_anon_p = 0;
    1059                 :            : 
    1060                 :            :   /* Build up a list of initializations.  The TREE_PURPOSE of entry
    1061                 :            :      will be the subobject (a FIELD_DECL or BINFO) to initialize.  The
    1062                 :            :      TREE_VALUE will be the constructor arguments, or NULL if no
    1063                 :            :      explicit initialization was provided.  */
    1064                 :    1534130 :   sorted_inits = NULL_TREE;
    1065                 :            : 
    1066                 :            :   /* Process the virtual bases.  */
    1067                 :    1534130 :   for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
    1068                 :    1553730 :        vec_safe_iterate (vbases, i, &base); i++)
    1069                 :      19606 :     sorted_inits = tree_cons (base, NULL_TREE, sorted_inits);
    1070                 :            : 
    1071                 :            :   /* Process the direct bases.  */
    1072                 :    2335520 :   for (binfo = TYPE_BINFO (t), i = 0;
    1073                 :    2334790 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
    1074                 :     800667 :     if (!BINFO_VIRTUAL_P (base_binfo))
    1075                 :     795217 :       sorted_inits = tree_cons (base_binfo, NULL_TREE, sorted_inits);
    1076                 :            : 
    1077                 :            :   /* Process the non-static data members.  */
    1078                 :    1534130 :   sorted_inits = build_field_list (t, sorted_inits, &uses_unions_or_anon_p);
    1079                 :            :   /* Reverse the entire list of initializations, so that they are in
    1080                 :            :      the order that they will actually be performed.  */
    1081                 :    1534130 :   sorted_inits = nreverse (sorted_inits);
    1082                 :            : 
    1083                 :            :   /* If the user presented the initializers in an order different from
    1084                 :            :      that in which they will actually occur, we issue a warning.  Keep
    1085                 :            :      track of the next subobject which can be explicitly initialized
    1086                 :            :      without issuing a warning.  */
    1087                 :    1534130 :   next_subobject = sorted_inits;
    1088                 :            : 
    1089                 :            :   /* Go through the explicit initializers, filling in TREE_PURPOSE in
    1090                 :            :      the SORTED_INITS.  */
    1091                 :    3114930 :   for (init = mem_inits; init; init = TREE_CHAIN (init))
    1092                 :            :     {
    1093                 :    1580810 :       tree subobject;
    1094                 :    1580810 :       tree subobject_init;
    1095                 :            : 
    1096                 :    1580810 :       subobject = TREE_PURPOSE (init);
    1097                 :            : 
    1098                 :            :       /* If the explicit initializers are in sorted order, then
    1099                 :            :          SUBOBJECT will be NEXT_SUBOBJECT, or something following
    1100                 :            :          it.  */
    1101                 :    2131860 :       for (subobject_init = next_subobject;
    1102                 :    2131860 :            subobject_init;
    1103                 :     551059 :            subobject_init = TREE_CHAIN (subobject_init))
    1104                 :    2131590 :         if (TREE_PURPOSE (subobject_init) == subobject)
    1105                 :            :           break;
    1106                 :            : 
    1107                 :            :       /* Issue a warning if the explicit initializer order does not
    1108                 :            :          match that which will actually occur.
    1109                 :            :          ??? Are all these on the correct lines?  */
    1110                 :    1580810 :       if (warn_reorder && !subobject_init)
    1111                 :            :         {
    1112                 :         16 :           if (TREE_CODE (TREE_PURPOSE (next_subobject)) == FIELD_DECL)
    1113                 :          8 :             warning_at (DECL_SOURCE_LOCATION (TREE_PURPOSE (next_subobject)),
    1114                 :            :                         OPT_Wreorder, "%qD will be initialized after",
    1115                 :          8 :                         TREE_PURPOSE (next_subobject));
    1116                 :            :           else
    1117                 :          8 :             warning (OPT_Wreorder, "base %qT will be initialized after",
    1118                 :          8 :                      TREE_PURPOSE (next_subobject));
    1119                 :         16 :           if (TREE_CODE (subobject) == FIELD_DECL)
    1120                 :          4 :             warning_at (DECL_SOURCE_LOCATION (subobject),
    1121                 :            :                         OPT_Wreorder, "  %q#D", subobject);
    1122                 :            :           else
    1123                 :         12 :             warning (OPT_Wreorder, "  base %qT", subobject);
    1124                 :         16 :           warning_at (DECL_SOURCE_LOCATION (current_function_decl),
    1125                 :            :                       OPT_Wreorder, "  when initialized here");
    1126                 :            :         }
    1127                 :            : 
    1128                 :            :       /* Look again, from the beginning of the list.  */
    1129                 :    1580810 :       if (!subobject_init)
    1130                 :            :         {
    1131                 :            :           subobject_init = sorted_inits;
    1132                 :        349 :           while (TREE_PURPOSE (subobject_init) != subobject)
    1133                 :         70 :             subobject_init = TREE_CHAIN (subobject_init);
    1134                 :            :         }
    1135                 :            : 
    1136                 :            :       /* It is invalid to initialize the same subobject more than
    1137                 :            :          once.  */
    1138                 :    1580810 :       if (TREE_VALUE (subobject_init))
    1139                 :            :         {
    1140                 :          0 :           if (TREE_CODE (subobject) == FIELD_DECL)
    1141                 :          0 :             error_at (DECL_SOURCE_LOCATION (current_function_decl),
    1142                 :            :                       "multiple initializations given for %qD",
    1143                 :            :                       subobject);
    1144                 :            :           else
    1145                 :          0 :             error_at (DECL_SOURCE_LOCATION (current_function_decl),
    1146                 :            :                       "multiple initializations given for base %qT",
    1147                 :            :                       subobject);
    1148                 :            :         }
    1149                 :            : 
    1150                 :            :       /* Record the initialization.  */
    1151                 :    1580810 :       TREE_VALUE (subobject_init) = TREE_VALUE (init);
    1152                 :    1580810 :       next_subobject = subobject_init;
    1153                 :            :     }
    1154                 :            : 
    1155                 :            :   /* [class.base.init]
    1156                 :            : 
    1157                 :            :      If a ctor-initializer specifies more than one mem-initializer for
    1158                 :            :      multiple members of the same union (including members of
    1159                 :            :      anonymous unions), the ctor-initializer is ill-formed.
    1160                 :            : 
    1161                 :            :      Here we also splice out uninitialized union members.  */
    1162                 :    1534130 :   if (uses_unions_or_anon_p)
    1163                 :            :     {
    1164                 :            :       tree *last_p = NULL;
    1165                 :            :       tree *p;
    1166                 :     647265 :       for (p = &sorted_inits; *p; )
    1167                 :            :         {
    1168                 :     539788 :           tree field;
    1169                 :     539788 :           tree ctx;
    1170                 :            : 
    1171                 :     539788 :           init = *p;
    1172                 :            : 
    1173                 :     539788 :           field = TREE_PURPOSE (init);
    1174                 :            : 
    1175                 :            :           /* Skip base classes.  */
    1176                 :     539788 :           if (TREE_CODE (field) != FIELD_DECL)
    1177                 :        677 :             goto next;
    1178                 :            : 
    1179                 :            :           /* If this is an anonymous aggregate with no explicit initializer,
    1180                 :            :              splice it out.  */
    1181                 :     970719 :           if (!TREE_VALUE (init) && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1182                 :     107014 :             goto splice;
    1183                 :            : 
    1184                 :            :           /* See if this field is a member of a union, or a member of a
    1185                 :            :              structure contained in a union, etc.  */
    1186                 :     432097 :           ctx = innermost_aggr_scope (field);
    1187                 :            : 
    1188                 :            :           /* If this field is not a member of a union, skip it.  */
    1189                 :     432097 :           if (TREE_CODE (ctx) != UNION_TYPE
    1190                 :     644855 :               && !ANON_AGGR_TYPE_P (ctx))
    1191                 :     212109 :             goto next;
    1192                 :            : 
    1193                 :            :           /* If this union member has no explicit initializer and no NSDMI,
    1194                 :            :              splice it out.  */
    1195                 :     438729 :           if (TREE_VALUE (init) || DECL_INITIAL (field))
    1196                 :            :             /* OK.  */;
    1197                 :            :           else
    1198                 :     218681 :             goto splice;
    1199                 :            : 
    1200                 :            :           /* It's only an error if we have two initializers for the same
    1201                 :            :              union type.  */
    1202                 :       1307 :           if (!last_p)
    1203                 :            :             {
    1204                 :       1228 :               last_p = p;
    1205                 :       1228 :               goto next;
    1206                 :            :             }
    1207                 :            : 
    1208                 :            :           /* See if LAST_FIELD and the field initialized by INIT are
    1209                 :            :              members of the same union (or the union itself). If so, there's
    1210                 :            :              a problem, unless they're actually members of the same structure
    1211                 :            :              which is itself a member of a union.  For example, given:
    1212                 :            : 
    1213                 :            :                union { struct { int i; int j; }; };
    1214                 :            : 
    1215                 :            :              initializing both `i' and `j' makes sense.  */
    1216                 :         79 :           ctx = common_enclosing_class
    1217                 :         79 :             (innermost_aggr_scope (field),
    1218                 :         79 :              innermost_aggr_scope (TREE_PURPOSE (*last_p)));
    1219                 :            : 
    1220                 :         79 :           if (ctx && (TREE_CODE (ctx) == UNION_TYPE
    1221                 :         53 :                       || ctx == TREE_TYPE (TREE_PURPOSE (*last_p))))
    1222                 :            :             {
    1223                 :            :               /* A mem-initializer hides an NSDMI.  */
    1224                 :         29 :               if (TREE_VALUE (init) && !TREE_VALUE (*last_p))
    1225                 :          3 :                 *last_p = TREE_CHAIN (*last_p);
    1226                 :         26 :               else if (TREE_VALUE (*last_p) && !TREE_VALUE (init))
    1227                 :          6 :                 goto splice;
    1228                 :            :               else
    1229                 :            :                 {
    1230                 :         20 :                   error_at (DECL_SOURCE_LOCATION (current_function_decl),
    1231                 :            :                             "initializations for multiple members of %qT",
    1232                 :            :                             ctx);
    1233                 :         20 :                   goto splice;
    1234                 :            :                 }
    1235                 :            :             }
    1236                 :            : 
    1237                 :            :           last_p = p;
    1238                 :            : 
    1239                 :     214067 :         next:
    1240                 :     214067 :           p = &TREE_CHAIN (*p);
    1241                 :     214067 :           continue;
    1242                 :     325721 :         splice:
    1243                 :     325721 :           *p = TREE_CHAIN (*p);
    1244                 :     325721 :           continue;
    1245                 :     539788 :         }
    1246                 :            :     }
    1247                 :            : 
    1248                 :    1534130 :   return sorted_inits;
    1249                 :            : }
    1250                 :            : 
    1251                 :            : /* Callback for cp_walk_tree to mark all PARM_DECLs in a tree as read.  */
    1252                 :            : 
    1253                 :            : static tree
    1254                 :        311 : mark_exp_read_r (tree *tp, int *, void *)
    1255                 :            : {
    1256                 :        311 :   tree t = *tp;
    1257                 :        311 :   if (TREE_CODE (t) == PARM_DECL)
    1258                 :         52 :     mark_exp_read (t);
    1259                 :        311 :   return NULL_TREE;
    1260                 :            : }
    1261                 :            : 
    1262                 :            : /* Initialize all bases and members of CURRENT_CLASS_TYPE.  MEM_INITS
    1263                 :            :    is a TREE_LIST giving the explicit mem-initializer-list for the
    1264                 :            :    constructor.  The TREE_PURPOSE of each entry is a subobject (a
    1265                 :            :    FIELD_DECL or a BINFO) of the CURRENT_CLASS_TYPE.  The TREE_VALUE
    1266                 :            :    is a TREE_LIST giving the arguments to the constructor or
    1267                 :            :    void_type_node for an empty list of arguments.  */
    1268                 :            : 
    1269                 :            : void
    1270                 :    1546030 : emit_mem_initializers (tree mem_inits)
    1271                 :            : {
    1272                 :    1546030 :   int flags = LOOKUP_NORMAL;
    1273                 :            : 
    1274                 :            :   /* We will already have issued an error message about the fact that
    1275                 :            :      the type is incomplete.  */
    1276                 :    1546030 :   if (!COMPLETE_TYPE_P (current_class_type))
    1277                 :            :     return;
    1278                 :            : 
    1279                 :    1546030 :   if (mem_inits
    1280                 :    1192730 :       && TYPE_P (TREE_PURPOSE (mem_inits))
    1281                 :    1557930 :       && same_type_p (TREE_PURPOSE (mem_inits), current_class_type))
    1282                 :            :     {
    1283                 :            :       /* Delegating constructor. */
    1284                 :      11901 :       gcc_assert (TREE_CHAIN (mem_inits) == NULL_TREE);
    1285                 :      11901 :       perform_target_ctor (TREE_VALUE (mem_inits));
    1286                 :      11901 :       return;
    1287                 :            :     }
    1288                 :            : 
    1289                 :    3068250 :   if (DECL_DEFAULTED_FN (current_function_decl)
    1290                 :    1649100 :       && ! DECL_INHERITED_CTOR (current_function_decl))
    1291                 :            :     flags |= LOOKUP_DEFAULTED;
    1292                 :            : 
    1293                 :            :   /* Sort the mem-initializers into the order in which the
    1294                 :            :      initializations should be performed.  */
    1295                 :    1534130 :   mem_inits = sort_mem_initializers (current_class_type, mem_inits);
    1296                 :            : 
    1297                 :    1534130 :   in_base_initializer = 1;
    1298                 :            : 
    1299                 :            :   /* Initialize base classes.  */
    1300                 :     814823 :   for (; (mem_inits
    1301                 :    4076860 :           && TREE_CODE (TREE_PURPOSE (mem_inits)) != FIELD_DECL);
    1302                 :     814823 :        mem_inits = TREE_CHAIN (mem_inits))
    1303                 :            :     {
    1304                 :     814823 :       tree subobject = TREE_PURPOSE (mem_inits);
    1305                 :     814823 :       tree arguments = TREE_VALUE (mem_inits);
    1306                 :            : 
    1307                 :            :       /* We already have issued an error message.  */
    1308                 :     814823 :       if (arguments == error_mark_node)
    1309                 :          3 :         continue;
    1310                 :            : 
    1311                 :            :       /* Suppress access control when calling the inherited ctor.  */
    1312                 :    1629640 :       bool inherited_base = (DECL_INHERITED_CTOR (current_function_decl)
    1313                 :      29432 :                              && flag_new_inheriting_ctors
    1314                 :     844243 :                              && arguments);
    1315                 :      23053 :       if (inherited_base)
    1316                 :      23053 :         push_deferring_access_checks (dk_deferred);
    1317                 :            : 
    1318                 :     814820 :       if (arguments == NULL_TREE)
    1319                 :            :         {
    1320                 :            :           /* If these initializations are taking place in a copy constructor,
    1321                 :            :              the base class should probably be explicitly initialized if there
    1322                 :            :              is a user-defined constructor in the base class (other than the
    1323                 :            :              default constructor, which will be called anyway).  */
    1324                 :     327012 :           if (extra_warnings
    1325                 :      10682 :               && DECL_COPY_CONSTRUCTOR_P (current_function_decl)
    1326                 :     327075 :               && type_has_user_nondefault_constructor (BINFO_TYPE (subobject)))
    1327                 :          8 :             warning_at (DECL_SOURCE_LOCATION (current_function_decl),
    1328                 :            :                         OPT_Wextra, "base class %q#T should be explicitly "
    1329                 :            :                         "initialized in the copy constructor",
    1330                 :          4 :                         BINFO_TYPE (subobject));
    1331                 :            :         }
    1332                 :            : 
    1333                 :            :       /* Initialize the base.  */
    1334                 :     814820 :       if (!BINFO_VIRTUAL_P (subobject))
    1335                 :            :         {
    1336                 :     795214 :           tree base_addr;
    1337                 :            : 
    1338                 :     795214 :           base_addr = build_base_path (PLUS_EXPR, current_class_ptr,
    1339                 :            :                                        subobject, 1, tf_warning_or_error);
    1340                 :     795214 :           expand_aggr_init_1 (subobject, NULL_TREE,
    1341                 :            :                               cp_build_fold_indirect_ref (base_addr),
    1342                 :            :                               arguments,
    1343                 :            :                               flags,
    1344                 :            :                               tf_warning_or_error);
    1345                 :     795214 :           expand_cleanup_for_base (subobject, NULL_TREE);
    1346                 :            :         }
    1347                 :      19606 :       else if (!ABSTRACT_CLASS_TYPE_P (current_class_type))
    1348                 :            :         /* C++14 DR1658 Means we do not have to construct vbases of
    1349                 :            :            abstract classes.  */
    1350                 :      19404 :         construct_virtual_base (subobject, arguments);
    1351                 :            :       else
    1352                 :            :         /* When not constructing vbases of abstract classes, at least mark
    1353                 :            :            the arguments expressions as read to avoid
    1354                 :            :            -Wunused-but-set-parameter false positives.  */
    1355                 :        202 :         cp_walk_tree (&arguments, mark_exp_read_r, NULL, NULL);
    1356                 :            : 
    1357                 :     814820 :       if (inherited_base)
    1358                 :      23053 :         pop_deferring_access_checks ();
    1359                 :            :     }
    1360                 :    1534130 :   in_base_initializer = 0;
    1361                 :            : 
    1362                 :            :   /* Initialize the vptrs.  */
    1363                 :    1534130 :   initialize_vtbl_ptrs (current_class_ptr);
    1364                 :            : 
    1365                 :            :   /* Initialize the data members.  */
    1366                 :    2874570 :   while (mem_inits)
    1367                 :            :     {
    1368                 :    1340440 :       perform_member_init (TREE_PURPOSE (mem_inits),
    1369                 :    1340440 :                            TREE_VALUE (mem_inits));
    1370                 :    1340440 :       mem_inits = TREE_CHAIN (mem_inits);
    1371                 :            :     }
    1372                 :            : }
    1373                 :            : 
    1374                 :            : /* Returns the address of the vtable (i.e., the value that should be
    1375                 :            :    assigned to the vptr) for BINFO.  */
    1376                 :            : 
    1377                 :            : tree
    1378                 :     248127 : build_vtbl_address (tree binfo)
    1379                 :            : {
    1380                 :     248127 :   tree binfo_for = binfo;
    1381                 :     248127 :   tree vtbl;
    1382                 :            : 
    1383                 :     248127 :   if (BINFO_VPTR_INDEX (binfo) && BINFO_VIRTUAL_P (binfo))
    1384                 :            :     /* If this is a virtual primary base, then the vtable we want to store
    1385                 :            :        is that for the base this is being used as the primary base of.  We
    1386                 :            :        can't simply skip the initialization, because we may be expanding the
    1387                 :            :        inits of a subobject constructor where the virtual base layout
    1388                 :            :        can be different.  */
    1389                 :      48375 :     while (BINFO_PRIMARY_P (binfo_for))
    1390                 :      15146 :       binfo_for = BINFO_INHERITANCE_CHAIN (binfo_for);
    1391                 :            : 
    1392                 :            :   /* Figure out what vtable BINFO's vtable is based on, and mark it as
    1393                 :            :      used.  */
    1394                 :     248127 :   vtbl = get_vtbl_decl_for_binfo (binfo_for);
    1395                 :     248127 :   TREE_USED (vtbl) = true;
    1396                 :            : 
    1397                 :            :   /* Now compute the address to use when initializing the vptr.  */
    1398                 :     248127 :   vtbl = unshare_expr (BINFO_VTABLE (binfo_for));
    1399                 :     248127 :   if (VAR_P (vtbl))
    1400                 :          0 :     vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl);
    1401                 :            : 
    1402                 :     248127 :   return vtbl;
    1403                 :            : }
    1404                 :            : 
    1405                 :            : /* This code sets up the virtual function tables appropriate for
    1406                 :            :    the pointer DECL.  It is a one-ply initialization.
    1407                 :            : 
    1408                 :            :    BINFO is the exact type that DECL is supposed to be.  In
    1409                 :            :    multiple inheritance, this might mean "C's A" if C : A, B.  */
    1410                 :            : 
    1411                 :            : static void
    1412                 :     248122 : expand_virtual_init (tree binfo, tree decl)
    1413                 :            : {
    1414                 :     248122 :   tree vtbl, vtbl_ptr;
    1415                 :     248122 :   tree vtt_index;
    1416                 :            : 
    1417                 :            :   /* Compute the initializer for vptr.  */
    1418                 :     248122 :   vtbl = build_vtbl_address (binfo);
    1419                 :            : 
    1420                 :            :   /* We may get this vptr from a VTT, if this is a subobject
    1421                 :            :      constructor or subobject destructor.  */
    1422                 :     248122 :   vtt_index = BINFO_VPTR_INDEX (binfo);
    1423                 :     248122 :   if (vtt_index)
    1424                 :            :     {
    1425                 :      47044 :       tree vtbl2;
    1426                 :      47044 :       tree vtt_parm;
    1427                 :            : 
    1428                 :            :       /* Compute the value to use, when there's a VTT.  */
    1429                 :      47044 :       vtt_parm = current_vtt_parm;
    1430                 :      47044 :       vtbl2 = fold_build_pointer_plus (vtt_parm, vtt_index);
    1431                 :      47044 :       vtbl2 = cp_build_fold_indirect_ref (vtbl2);
    1432                 :      47044 :       vtbl2 = convert (TREE_TYPE (vtbl), vtbl2);
    1433                 :            : 
    1434                 :            :       /* The actual initializer is the VTT value only in the subobject
    1435                 :            :          constructor.  In maybe_clone_body we'll substitute NULL for
    1436                 :            :          the vtt_parm in the case of the non-subobject constructor.  */
    1437                 :      47044 :       vtbl = build_if_in_charge (vtbl, vtbl2);
    1438                 :            :     }
    1439                 :            : 
    1440                 :            :   /* Compute the location of the vtpr.  */
    1441                 :     496244 :   vtbl_ptr = build_vfield_ref (cp_build_fold_indirect_ref (decl),
    1442                 :     248122 :                                TREE_TYPE (binfo));
    1443                 :     248122 :   gcc_assert (vtbl_ptr != error_mark_node);
    1444                 :            : 
    1445                 :            :   /* Assign the vtable to the vptr.  */
    1446                 :     248122 :   vtbl = convert_force (TREE_TYPE (vtbl_ptr), vtbl, 0, tf_warning_or_error);
    1447                 :     248122 :   finish_expr_stmt (cp_build_modify_expr (input_location, vtbl_ptr, NOP_EXPR,
    1448                 :            :                                           vtbl, tf_warning_or_error));
    1449                 :     248122 : }
    1450                 :            : 
    1451                 :            : /* If an exception is thrown in a constructor, those base classes already
    1452                 :            :    constructed must be destroyed.  This function creates the cleanup
    1453                 :            :    for BINFO, which has just been constructed.  If FLAG is non-NULL,
    1454                 :            :    it is a DECL which is nonzero when this base needs to be
    1455                 :            :    destroyed.  */
    1456                 :            : 
    1457                 :            : static void
    1458                 :     814618 : expand_cleanup_for_base (tree binfo, tree flag)
    1459                 :            : {
    1460                 :     814618 :   tree expr;
    1461                 :            : 
    1462                 :     814618 :   if (!type_build_dtor_call (BINFO_TYPE (binfo)))
    1463                 :            :     return;
    1464                 :            : 
    1465                 :            :   /* Call the destructor.  */
    1466                 :     435519 :   expr = build_special_member_call (current_class_ref,
    1467                 :            :                                     base_dtor_identifier,
    1468                 :            :                                     NULL,
    1469                 :            :                                     binfo,
    1470                 :            :                                     LOOKUP_NORMAL | LOOKUP_NONVIRTUAL,
    1471                 :            :                                     tf_warning_or_error);
    1472                 :            : 
    1473                 :     435519 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (BINFO_TYPE (binfo)))
    1474                 :            :     return;
    1475                 :            : 
    1476                 :     410587 :   if (flag)
    1477                 :      16259 :     expr = fold_build3_loc (input_location,
    1478                 :            :                         COND_EXPR, void_type_node,
    1479                 :            :                         c_common_truthvalue_conversion (input_location, flag),
    1480                 :            :                         expr, integer_zero_node);
    1481                 :            : 
    1482                 :     410587 :   finish_eh_cleanup (expr);
    1483                 :            : }
    1484                 :            : 
    1485                 :            : /* Construct the virtual base-class VBASE passing the ARGUMENTS to its
    1486                 :            :    constructor.  */
    1487                 :            : 
    1488                 :            : static void
    1489                 :      19404 : construct_virtual_base (tree vbase, tree arguments)
    1490                 :            : {
    1491                 :      19404 :   tree inner_if_stmt;
    1492                 :      19404 :   tree exp;
    1493                 :      19404 :   tree flag;
    1494                 :            : 
    1495                 :            :   /* If there are virtual base classes with destructors, we need to
    1496                 :            :      emit cleanups to destroy them if an exception is thrown during
    1497                 :            :      the construction process.  These exception regions (i.e., the
    1498                 :            :      period during which the cleanups must occur) begin from the time
    1499                 :            :      the construction is complete to the end of the function.  If we
    1500                 :            :      create a conditional block in which to initialize the
    1501                 :            :      base-classes, then the cleanup region for the virtual base begins
    1502                 :            :      inside a block, and ends outside of that block.  This situation
    1503                 :            :      confuses the sjlj exception-handling code.  Therefore, we do not
    1504                 :            :      create a single conditional block, but one for each
    1505                 :            :      initialization.  (That way the cleanup regions always begin
    1506                 :            :      in the outer block.)  We trust the back end to figure out
    1507                 :            :      that the FLAG will not change across initializations, and
    1508                 :            :      avoid doing multiple tests.  */
    1509                 :      19404 :   flag = DECL_CHAIN (DECL_ARGUMENTS (current_function_decl));
    1510                 :      19404 :   inner_if_stmt = begin_if_stmt ();
    1511                 :      19404 :   finish_if_stmt_cond (flag, inner_if_stmt);
    1512                 :            : 
    1513                 :            :   /* Compute the location of the virtual base.  If we're
    1514                 :            :      constructing virtual bases, then we must be the most derived
    1515                 :            :      class.  Therefore, we don't have to look up the virtual base;
    1516                 :            :      we already know where it is.  */
    1517                 :      19404 :   exp = convert_to_base_statically (current_class_ref, vbase);
    1518                 :            : 
    1519                 :      19404 :   expand_aggr_init_1 (vbase, current_class_ref, exp, arguments,
    1520                 :            :                       0, tf_warning_or_error);
    1521                 :      19404 :   finish_then_clause (inner_if_stmt);
    1522                 :      19404 :   finish_if_stmt (inner_if_stmt);
    1523                 :            : 
    1524                 :      19404 :   expand_cleanup_for_base (vbase, flag);
    1525                 :      19404 : }
    1526                 :            : 
    1527                 :            : /* Find the context in which this FIELD can be initialized.  */
    1528                 :            : 
    1529                 :            : static tree
    1530                 :    1802500 : initializing_context (tree field)
    1531                 :            : {
    1532                 :    1802500 :   tree t = DECL_CONTEXT (field);
    1533                 :            : 
    1534                 :            :   /* Anonymous union members can be initialized in the first enclosing
    1535                 :            :      non-anonymous union context.  */
    1536                 :    3613360 :   while (t && ANON_AGGR_TYPE_P (t))
    1537                 :       4179 :     t = TYPE_CONTEXT (t);
    1538                 :    1802500 :   return t;
    1539                 :            : }
    1540                 :            : 
    1541                 :            : /* Function to give error message if member initialization specification
    1542                 :            :    is erroneous.  FIELD is the member we decided to initialize.
    1543                 :            :    TYPE is the type for which the initialization is being performed.
    1544                 :            :    FIELD must be a member of TYPE.
    1545                 :            : 
    1546                 :            :    MEMBER_NAME is the name of the member.  */
    1547                 :            : 
    1548                 :            : static int
    1549                 :    1802520 : member_init_ok_or_else (tree field, tree type, tree member_name)
    1550                 :            : {
    1551                 :    1802520 :   if (field == error_mark_node)
    1552                 :            :     return 0;
    1553                 :    1802520 :   if (!field)
    1554                 :            :     {
    1555                 :         16 :       error ("class %qT does not have any field named %qD", type,
    1556                 :            :              member_name);
    1557                 :         16 :       return 0;
    1558                 :            :     }
    1559                 :    1802500 :   if (VAR_P (field))
    1560                 :            :     {
    1561                 :          0 :       error ("%q#D is a static data member; it can only be "
    1562                 :            :              "initialized at its definition",
    1563                 :            :              field);
    1564                 :          0 :       return 0;
    1565                 :            :     }
    1566                 :    1802500 :   if (TREE_CODE (field) != FIELD_DECL)
    1567                 :            :     {
    1568                 :          4 :       error ("%q#D is not a non-static data member of %qT",
    1569                 :            :              field, type);
    1570                 :          4 :       return 0;
    1571                 :            :     }
    1572                 :    1802500 :   if (initializing_context (field) != type)
    1573                 :            :     {
    1574                 :          4 :       error ("class %qT does not have any field named %qD", type,
    1575                 :            :                 member_name);
    1576                 :          4 :       return 0;
    1577                 :            :     }
    1578                 :            : 
    1579                 :            :   return 1;
    1580                 :            : }
    1581                 :            : 
    1582                 :            : /* NAME is a FIELD_DECL, an IDENTIFIER_NODE which names a field, or it
    1583                 :            :    is a _TYPE node or TYPE_DECL which names a base for that type.
    1584                 :            :    Check the validity of NAME, and return either the base _TYPE, base
    1585                 :            :    binfo, or the FIELD_DECL of the member.  If NAME is invalid, return
    1586                 :            :    NULL_TREE and issue a diagnostic.
    1587                 :            : 
    1588                 :            :    An old style unnamed direct single base construction is permitted,
    1589                 :            :    where NAME is NULL.  */
    1590                 :            : 
    1591                 :            : tree
    1592                 :    2603070 : expand_member_init (tree name)
    1593                 :            : {
    1594                 :    2603070 :   tree basetype;
    1595                 :    2603070 :   tree field;
    1596                 :            : 
    1597                 :    2603070 :   if (!current_class_ref)
    1598                 :            :     return NULL_TREE;
    1599                 :            : 
    1600                 :    2603070 :   if (!name)
    1601                 :            :     {
    1602                 :            :       /* This is an obsolete unnamed base class initializer.  The
    1603                 :            :          parser will already have warned about its use.  */
    1604                 :          8 :       switch (BINFO_N_BASE_BINFOS (TYPE_BINFO (current_class_type)))
    1605                 :            :         {
    1606                 :          0 :         case 0:
    1607                 :          0 :           error ("unnamed initializer for %qT, which has no base classes",
    1608                 :            :                  current_class_type);
    1609                 :          0 :           return NULL_TREE;
    1610                 :          8 :         case 1:
    1611                 :          8 :           basetype = BINFO_TYPE
    1612                 :            :             (BINFO_BASE_BINFO (TYPE_BINFO (current_class_type), 0));
    1613                 :          8 :           break;
    1614                 :          0 :         default:
    1615                 :          0 :           error ("unnamed initializer for %qT, which uses multiple inheritance",
    1616                 :            :                  current_class_type);
    1617                 :          0 :           return NULL_TREE;
    1618                 :            :       }
    1619                 :            :     }
    1620                 :    2603060 :   else if (TYPE_P (name))
    1621                 :            :     {
    1622                 :     404013 :       basetype = TYPE_MAIN_VARIANT (name);
    1623                 :     404013 :       name = TYPE_NAME (name);
    1624                 :            :     }
    1625                 :    2199050 :   else if (TREE_CODE (name) == TYPE_DECL)
    1626                 :     396528 :     basetype = TYPE_MAIN_VARIANT (TREE_TYPE (name));
    1627                 :            :   else
    1628                 :            :     basetype = NULL_TREE;
    1629                 :            : 
    1630                 :     800549 :   if (basetype)
    1631                 :            :     {
    1632                 :     800549 :       tree class_binfo;
    1633                 :     800549 :       tree direct_binfo;
    1634                 :     800549 :       tree virtual_binfo;
    1635                 :     800549 :       int i;
    1636                 :            : 
    1637                 :     800549 :       if (current_template_parms
    1638                 :     800549 :           || same_type_p (basetype, current_class_type))
    1639                 :     369787 :           return basetype;
    1640                 :            : 
    1641                 :     430762 :       class_binfo = TYPE_BINFO (current_class_type);
    1642                 :     430762 :       direct_binfo = NULL_TREE;
    1643                 :     430762 :       virtual_binfo = NULL_TREE;
    1644                 :            : 
    1645                 :            :       /* Look for a direct base.  */
    1646                 :     497622 :       for (i = 0; BINFO_BASE_ITERATE (class_binfo, i, direct_binfo); ++i)
    1647                 :     497565 :         if (SAME_BINFO_TYPE_P (BINFO_TYPE (direct_binfo), basetype))
    1648                 :            :           break;
    1649                 :            : 
    1650                 :            :       /* Look for a virtual base -- unless the direct base is itself
    1651                 :            :          virtual.  */
    1652                 :     430762 :       if (!direct_binfo || !BINFO_VIRTUAL_P (direct_binfo))
    1653                 :     430553 :         virtual_binfo = binfo_for_vbase (basetype, current_class_type);
    1654                 :            : 
    1655                 :            :       /* [class.base.init]
    1656                 :            : 
    1657                 :            :          If a mem-initializer-id is ambiguous because it designates
    1658                 :            :          both a direct non-virtual base class and an inherited virtual
    1659                 :            :          base class, the mem-initializer is ill-formed.  */
    1660                 :     430762 :       if (direct_binfo && virtual_binfo)
    1661                 :            :         {
    1662                 :          0 :           error ("%qD is both a direct base and an indirect virtual base",
    1663                 :            :                  basetype);
    1664                 :          0 :           return NULL_TREE;
    1665                 :            :         }
    1666                 :            : 
    1667                 :     430762 :       if (!direct_binfo && !virtual_binfo)
    1668                 :            :         {
    1669                 :         11 :           if (CLASSTYPE_VBASECLASSES (current_class_type))
    1670                 :          0 :             error ("type %qT is not a direct or virtual base of %qT",
    1671                 :            :                    basetype, current_class_type);
    1672                 :            :           else
    1673                 :         11 :             error ("type %qT is not a direct base of %qT",
    1674                 :            :                    basetype, current_class_type);
    1675                 :         11 :           return NULL_TREE;
    1676                 :            :         }
    1677                 :            : 
    1678                 :     430797 :       return direct_binfo ? direct_binfo : virtual_binfo;
    1679                 :            :     }
    1680                 :            :   else
    1681                 :            :     {
    1682                 :    1802520 :       if (identifier_p (name))
    1683                 :     891968 :         field = lookup_field (current_class_type, name, 1, false);
    1684                 :            :       else
    1685                 :            :         field = name;
    1686                 :            : 
    1687                 :    1802520 :       if (member_init_ok_or_else (field, current_class_type, name))
    1688                 :    1802500 :         return field;
    1689                 :            :     }
    1690                 :            : 
    1691                 :            :   return NULL_TREE;
    1692                 :            : }
    1693                 :            : 
    1694                 :            : /* This is like `expand_member_init', only it stores one aggregate
    1695                 :            :    value into another.
    1696                 :            : 
    1697                 :            :    INIT comes in two flavors: it is either a value which
    1698                 :            :    is to be stored in EXP, or it is a parameter list
    1699                 :            :    to go to a constructor, which will operate on EXP.
    1700                 :            :    If INIT is not a parameter list for a constructor, then set
    1701                 :            :    LOOKUP_ONLYCONVERTING.
    1702                 :            :    If FLAGS is LOOKUP_ONLYCONVERTING then it is the = init form of
    1703                 :            :    the initializer, if FLAGS is 0, then it is the (init) form.
    1704                 :            :    If `init' is a CONSTRUCTOR, then we emit a warning message,
    1705                 :            :    explaining that such initializations are invalid.
    1706                 :            : 
    1707                 :            :    If INIT resolves to a CALL_EXPR which happens to return
    1708                 :            :    something of the type we are looking for, then we know
    1709                 :            :    that we can safely use that call to perform the
    1710                 :            :    initialization.
    1711                 :            : 
    1712                 :            :    The virtual function table pointer cannot be set up here, because
    1713                 :            :    we do not really know its type.
    1714                 :            : 
    1715                 :            :    This never calls operator=().
    1716                 :            : 
    1717                 :            :    When initializing, nothing is CONST.
    1718                 :            : 
    1719                 :            :    A default copy constructor may have to be used to perform the
    1720                 :            :    initialization.
    1721                 :            : 
    1722                 :            :    A constructor or a conversion operator may have to be used to
    1723                 :            :    perform the initialization, but not both, as it would be ambiguous.  */
    1724                 :            : 
    1725                 :            : tree
    1726                 :     751538 : build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain)
    1727                 :            : {
    1728                 :     751538 :   tree stmt_expr;
    1729                 :     751538 :   tree compound_stmt;
    1730                 :     751538 :   int destroy_temps;
    1731                 :     751538 :   tree type = TREE_TYPE (exp);
    1732                 :     751538 :   int was_const = TREE_READONLY (exp);
    1733                 :     751538 :   int was_volatile = TREE_THIS_VOLATILE (exp);
    1734                 :     751538 :   int is_global;
    1735                 :            : 
    1736                 :     751538 :   if (init == error_mark_node)
    1737                 :            :     return error_mark_node;
    1738                 :            : 
    1739                 :     751389 :   location_t init_loc = (init
    1740                 :     751389 :                          ? cp_expr_loc_or_input_loc (init)
    1741                 :     227403 :                          : location_of (exp));
    1742                 :            : 
    1743                 :     751389 :   TREE_READONLY (exp) = 0;
    1744                 :     751389 :   TREE_THIS_VOLATILE (exp) = 0;
    1745                 :            : 
    1746                 :     751389 :   if (TREE_CODE (type) == ARRAY_TYPE)
    1747                 :            :     {
    1748                 :       2761 :       tree itype = init ? TREE_TYPE (init) : NULL_TREE;
    1749                 :       1683 :       int from_array = 0;
    1750                 :            : 
    1751                 :       3186 :       if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp))
    1752                 :            :         {
    1753                 :         58 :           from_array = 1;
    1754                 :         58 :           init = mark_rvalue_use (init);
    1755                 :         58 :           if (init
    1756                 :         58 :               && DECL_P (tree_strip_any_location_wrapper (init))
    1757                 :        104 :               && !(flags & LOOKUP_ONLYCONVERTING))
    1758                 :            :             {
    1759                 :            :               /* Wrap the initializer in a CONSTRUCTOR so that build_vec_init
    1760                 :            :                  recognizes it as direct-initialization.  */
    1761                 :         11 :               init = build_constructor_single (init_list_type_node,
    1762                 :            :                                                NULL_TREE, init);
    1763                 :         11 :               CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    1764                 :            :             }
    1765                 :            :         }
    1766                 :            :       else
    1767                 :            :         {
    1768                 :            :           /* Must arrange to initialize each element of EXP
    1769                 :            :              from elements of INIT.  */
    1770                 :       1625 :           if (cv_qualified_p (type))
    1771                 :        363 :             TREE_TYPE (exp) = cv_unqualified (type);
    1772                 :       1625 :           if (itype && cv_qualified_p (itype))
    1773                 :          0 :             TREE_TYPE (init) = cv_unqualified (itype);
    1774                 :       2645 :           from_array = (itype && same_type_p (TREE_TYPE (init),
    1775                 :            :                                               TREE_TYPE (exp)));
    1776                 :            : 
    1777                 :       2022 :           if (init && !BRACE_ENCLOSED_INITIALIZER_P (init)
    1778                 :       1649 :               && (!from_array
    1779                 :         21 :                   || (TREE_CODE (init) != CONSTRUCTOR
    1780                 :            :                       /* Can happen, eg, handling the compound-literals
    1781                 :            :                          extension (ext/complit12.C).  */
    1782                 :         15 :                       && TREE_CODE (init) != TARGET_EXPR)))
    1783                 :            :             {
    1784                 :          6 :               if (complain & tf_error)
    1785                 :          6 :                 error_at (init_loc, "array must be initialized "
    1786                 :            :                           "with a brace-enclosed initializer");
    1787                 :          6 :               return error_mark_node;
    1788                 :            :             }
    1789                 :            :         }
    1790                 :            : 
    1791                 :       1677 :       stmt_expr = build_vec_init (exp, NULL_TREE, init,
    1792                 :            :                                   /*explicit_value_init_p=*/false,
    1793                 :            :                                   from_array,
    1794                 :            :                                   complain);
    1795                 :       1677 :       TREE_READONLY (exp) = was_const;
    1796                 :       1677 :       TREE_THIS_VOLATILE (exp) = was_volatile;
    1797                 :       1677 :       TREE_TYPE (exp) = type;
    1798                 :            :       /* Restore the type of init unless it was used directly.  */
    1799                 :       1677 :       if (init && TREE_CODE (stmt_expr) != INIT_EXPR)
    1800                 :        783 :         TREE_TYPE (init) = itype;
    1801                 :       1677 :       return stmt_expr;
    1802                 :            :     }
    1803                 :            : 
    1804                 :     522908 :   if (init && init != void_type_node
    1805                 :     522468 :       && TREE_CODE (init) != TREE_LIST
    1806                 :     141138 :       && !(TREE_CODE (init) == TARGET_EXPR
    1807                 :      71032 :            && TARGET_EXPR_DIRECT_INIT_P (init))
    1808                 :     913381 :       && !DIRECT_LIST_INIT_P (init))
    1809                 :     120449 :     flags |= LOOKUP_ONLYCONVERTING;
    1810                 :            : 
    1811                 :     749706 :   is_global = begin_init_stmts (&stmt_expr, &compound_stmt);
    1812                 :     749706 :   destroy_temps = stmts_are_full_exprs_p ();
    1813                 :     749706 :   current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    1814                 :     756983 :   expand_aggr_init_1 (TYPE_BINFO (type), exp, exp,
    1815                 :            :                       init, LOOKUP_NORMAL|flags, complain);
    1816                 :     749706 :   stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
    1817                 :     749706 :   current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
    1818                 :     749706 :   TREE_READONLY (exp) = was_const;
    1819                 :     749706 :   TREE_THIS_VOLATILE (exp) = was_volatile;
    1820                 :            : 
    1821                 :     749706 :   if ((VAR_P (exp) || TREE_CODE (exp) == PARM_DECL)
    1822                 :     395945 :       && TREE_SIDE_EFFECTS (stmt_expr)
    1823                 :    1143960 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (type)))
    1824                 :            :     /* Just know that we've seen something for this node.  */
    1825                 :     394241 :     TREE_USED (exp) = 1;
    1826                 :            : 
    1827                 :     749706 :   return stmt_expr;
    1828                 :            : }
    1829                 :            : 
    1830                 :            : static void
    1831                 :    1557600 : expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags,
    1832                 :            :                      tsubst_flags_t complain)
    1833                 :            : {
    1834                 :    1557600 :   tree type = TREE_TYPE (exp);
    1835                 :            : 
    1836                 :            :   /* It fails because there may not be a constructor which takes
    1837                 :            :      its own type as the first (or only parameter), but which does
    1838                 :            :      take other types via a conversion.  So, if the thing initializing
    1839                 :            :      the expression is a unit element of type X, first try X(X&),
    1840                 :            :      followed by initialization by X.  If neither of these work
    1841                 :            :      out, then look hard.  */
    1842                 :    1557600 :   tree rval;
    1843                 :    1557600 :   vec<tree, va_gc> *parms;
    1844                 :            : 
    1845                 :            :   /* If we have direct-initialization from an initializer list, pull
    1846                 :            :      it out of the TREE_LIST so the code below can see it.  */
    1847                 :     878338 :   if (init && TREE_CODE (init) == TREE_LIST
    1848                 :    2294880 :       && DIRECT_LIST_INIT_P (TREE_VALUE (init)))
    1849                 :            :     {
    1850                 :       1368 :       gcc_checking_assert ((flags & LOOKUP_ONLYCONVERTING) == 0
    1851                 :            :                            && TREE_CHAIN (init) == NULL_TREE);
    1852                 :        684 :       init = TREE_VALUE (init);
    1853                 :            :       /* Only call reshape_init if it has not been called earlier
    1854                 :            :          by the callers.  */
    1855                 :       1368 :       if (BRACE_ENCLOSED_INITIALIZER_P (init) && CP_AGGREGATE_TYPE_P (type))
    1856                 :        635 :         init = reshape_init (type, init, complain);
    1857                 :            :     }
    1858                 :            : 
    1859                 :     902221 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init)
    1860                 :    1605180 :       && CP_AGGREGATE_TYPE_P (type))
    1861                 :            :     /* A brace-enclosed initializer for an aggregate.  In C++0x this can
    1862                 :            :        happen for direct-initialization, too.  */
    1863                 :        786 :     init = digest_init (type, init, complain);
    1864                 :            : 
    1865                 :            :   /* A CONSTRUCTOR of the target's type is a previously digested
    1866                 :            :      initializer, whether that happened just above or in
    1867                 :            :      cp_parser_late_parsing_nsdmi.
    1868                 :            : 
    1869                 :            :      A TARGET_EXPR with TARGET_EXPR_DIRECT_INIT_P or TARGET_EXPR_LIST_INIT_P
    1870                 :            :      set represents the whole initialization, so we shouldn't build up
    1871                 :            :      another ctor call.  */
    1872                 :    1557600 :   if (init
    1873                 :     878338 :       && (TREE_CODE (init) == CONSTRUCTOR
    1874                 :     854459 :           || (TREE_CODE (init) == TARGET_EXPR
    1875                 :      71032 :               && (TARGET_EXPR_DIRECT_INIT_P (init)
    1876                 :      71032 :                   || TARGET_EXPR_LIST_INIT_P (init))))
    1877                 :    1582240 :       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), type))
    1878                 :            :     {
    1879                 :            :       /* Early initialization via a TARGET_EXPR only works for
    1880                 :            :          complete objects.  */
    1881                 :       1628 :       gcc_assert (TREE_CODE (init) == CONSTRUCTOR || true_exp == exp);
    1882                 :            : 
    1883                 :       1628 :       init = build2 (INIT_EXPR, TREE_TYPE (exp), exp, init);
    1884                 :       1628 :       TREE_SIDE_EFFECTS (init) = 1;
    1885                 :       1628 :       finish_expr_stmt (init);
    1886                 :     123374 :       return;
    1887                 :            :     }
    1888                 :            : 
    1889                 :    1555980 :   if (init && TREE_CODE (init) != TREE_LIST
    1890                 :     140117 :       && (flags & LOOKUP_ONLYCONVERTING))
    1891                 :            :     {
    1892                 :            :       /* Base subobjects should only get direct-initialization.  */
    1893                 :     120118 :       gcc_assert (true_exp == exp);
    1894                 :            : 
    1895                 :     120118 :       if (flags & DIRECT_BIND)
    1896                 :            :         /* Do nothing.  We hit this in two cases:  Reference initialization,
    1897                 :            :            where we aren't initializing a real variable, so we don't want
    1898                 :            :            to run a new constructor; and catching an exception, where we
    1899                 :            :            have already built up the constructor call so we could wrap it
    1900                 :            :            in an exception region.  */;
    1901                 :            :       else
    1902                 :     119628 :         init = ocp_convert (type, init, CONV_IMPLICIT|CONV_FORCE_TEMP,
    1903                 :            :                             flags, complain);
    1904                 :            : 
    1905                 :     120118 :       if (TREE_CODE (init) == MUST_NOT_THROW_EXPR)
    1906                 :            :         /* We need to protect the initialization of a catch parm with a
    1907                 :            :            call to terminate(), which shows up as a MUST_NOT_THROW_EXPR
    1908                 :            :            around the TARGET_EXPR for the copy constructor.  See
    1909                 :            :            initialize_handler_parm.  */
    1910                 :            :         {
    1911                 :        340 :           TREE_OPERAND (init, 0) = build2 (INIT_EXPR, TREE_TYPE (exp), exp,
    1912                 :        340 :                                            TREE_OPERAND (init, 0));
    1913                 :        340 :           TREE_TYPE (init) = void_type_node;
    1914                 :            :         }
    1915                 :            :       else
    1916                 :     119778 :         init = build2 (INIT_EXPR, TREE_TYPE (exp), exp, init);
    1917                 :     120118 :       TREE_SIDE_EFFECTS (init) = 1;
    1918                 :     120118 :       finish_expr_stmt (init);
    1919                 :     120118 :       return;
    1920                 :            :     }
    1921                 :            : 
    1922                 :    1435860 :   if (init == NULL_TREE)
    1923                 :     679266 :     parms = NULL;
    1924                 :    1493180 :   else if (TREE_CODE (init) == TREE_LIST && !TREE_TYPE (init))
    1925                 :            :     {
    1926                 :     736593 :       parms = make_tree_vector ();
    1927                 :    1685630 :       for (; init != NULL_TREE; init = TREE_CHAIN (init))
    1928                 :     949033 :         vec_safe_push (parms, TREE_VALUE (init));
    1929                 :            :     }
    1930                 :            :   else
    1931                 :      19999 :     parms = make_tree_vector_single (init);
    1932                 :            : 
    1933                 :    1447760 :   if (exp == current_class_ref && current_function_decl
    1934                 :    1459660 :       && DECL_HAS_IN_CHARGE_PARM_P (current_function_decl))
    1935                 :            :     {
    1936                 :            :       /* Delegating constructor. */
    1937                 :         30 :       tree complete;
    1938                 :         30 :       tree base;
    1939                 :         30 :       tree elt; unsigned i;
    1940                 :            : 
    1941                 :            :       /* Unshare the arguments for the second call.  */
    1942                 :         60 :       releasing_vec parms2;
    1943                 :         77 :       FOR_EACH_VEC_SAFE_ELT (parms, i, elt)
    1944                 :            :         {
    1945                 :         27 :           elt = break_out_target_exprs (elt);
    1946                 :         27 :           vec_safe_push (parms2, elt);
    1947                 :            :         }
    1948                 :         30 :       complete = build_special_member_call (exp, complete_ctor_identifier,
    1949                 :            :                                             &parms2, binfo, flags,
    1950                 :            :                                             complain);
    1951                 :         30 :       complete = fold_build_cleanup_point_expr (void_type_node, complete);
    1952                 :            : 
    1953                 :         30 :       base = build_special_member_call (exp, base_ctor_identifier,
    1954                 :            :                                         &parms, binfo, flags,
    1955                 :            :                                         complain);
    1956                 :         30 :       base = fold_build_cleanup_point_expr (void_type_node, base);
    1957                 :         30 :       rval = build_if_in_charge (complete, base);
    1958                 :            :     }
    1959                 :            :    else
    1960                 :            :     {
    1961                 :    2871660 :       tree ctor_name = (true_exp == exp
    1962                 :    1435830 :                         ? complete_ctor_identifier : base_ctor_identifier);
    1963                 :            : 
    1964                 :    1435830 :       rval = build_special_member_call (exp, ctor_name, &parms, binfo, flags,
    1965                 :            :                                         complain);
    1966                 :            :     }
    1967                 :            : 
    1968                 :    1435860 :   if (parms != NULL)
    1969                 :     771818 :     release_tree_vector (parms);
    1970                 :            : 
    1971                 :    1435860 :   if (exp == true_exp && TREE_CODE (rval) == CALL_EXPR)
    1972                 :            :     {
    1973                 :     578845 :       tree fn = get_callee_fndecl (rval);
    1974                 :    1157680 :       if (fn && DECL_DECLARED_CONSTEXPR_P (fn))
    1975                 :            :         {
    1976                 :      55974 :           tree e = maybe_constant_init (rval, exp);
    1977                 :      55974 :           if (TREE_CONSTANT (e))
    1978                 :      16741 :             rval = build2 (INIT_EXPR, type, exp, e);
    1979                 :            :         }
    1980                 :            :     }
    1981                 :            : 
    1982                 :            :   /* FIXME put back convert_to_void?  */
    1983                 :    1435860 :   if (TREE_SIDE_EFFECTS (rval))
    1984                 :    1272420 :     finish_expr_stmt (rval);
    1985                 :            : }
    1986                 :            : 
    1987                 :            : /* This function is responsible for initializing EXP with INIT
    1988                 :            :    (if any).
    1989                 :            : 
    1990                 :            :    BINFO is the binfo of the type for who we are performing the
    1991                 :            :    initialization.  For example, if W is a virtual base class of A and B,
    1992                 :            :    and C : A, B.
    1993                 :            :    If we are initializing B, then W must contain B's W vtable, whereas
    1994                 :            :    were we initializing C, W must contain C's W vtable.
    1995                 :            : 
    1996                 :            :    TRUE_EXP is nonzero if it is the true expression being initialized.
    1997                 :            :    In this case, it may be EXP, or may just contain EXP.  The reason we
    1998                 :            :    need this is because if EXP is a base element of TRUE_EXP, we
    1999                 :            :    don't necessarily know by looking at EXP where its virtual
    2000                 :            :    baseclass fields should really be pointing.  But we do know
    2001                 :            :    from TRUE_EXP.  In constructors, we don't know anything about
    2002                 :            :    the value being initialized.
    2003                 :            : 
    2004                 :            :    FLAGS is just passed to `build_new_method_call'.  See that function
    2005                 :            :    for its description.  */
    2006                 :            : 
    2007                 :            : static void
    2008                 :    1564320 : expand_aggr_init_1 (tree binfo, tree true_exp, tree exp, tree init, int flags,
    2009                 :            :                     tsubst_flags_t complain)
    2010                 :            : {
    2011                 :    1564320 :   tree type = TREE_TYPE (exp);
    2012                 :            : 
    2013                 :    1564320 :   gcc_assert (init != error_mark_node && type != error_mark_node);
    2014                 :    1564320 :   gcc_assert (building_stmt_list_p ());
    2015                 :            : 
    2016                 :            :   /* Use a function returning the desired type to initialize EXP for us.
    2017                 :            :      If the function is a constructor, and its first argument is
    2018                 :            :      NULL_TREE, know that it was meant for us--just slide exp on
    2019                 :            :      in and expand the constructor.  Constructors now come
    2020                 :            :      as TARGET_EXPRs.  */
    2021                 :            : 
    2022                 :    1010680 :   if (init && VAR_P (exp)
    2023                 :    1786260 :       && COMPOUND_LITERAL_P (init))
    2024                 :            :     {
    2025                 :         77 :       vec<tree, va_gc> *cleanups = NULL;
    2026                 :            :       /* If store_init_value returns NULL_TREE, the INIT has been
    2027                 :            :          recorded as the DECL_INITIAL for EXP.  That means there's
    2028                 :            :          nothing more we have to do.  */
    2029                 :         77 :       init = store_init_value (exp, init, &cleanups, flags);
    2030                 :         77 :       if (init)
    2031                 :          0 :         finish_expr_stmt (init);
    2032                 :         77 :       gcc_assert (!cleanups);
    2033                 :         77 :       return;
    2034                 :            :     }
    2035                 :            : 
    2036                 :            :   /* List-initialization from {} becomes value-initialization for non-aggregate
    2037                 :            :      classes with default constructors.  Handle this here when we're
    2038                 :            :      initializing a base, so protected access works.  */
    2039                 :    1564250 :   if (exp != true_exp && init && TREE_CODE (init) == TREE_LIST)
    2040                 :            :     {
    2041                 :     355966 :       tree elt = TREE_VALUE (init);
    2042                 :        756 :       if (DIRECT_LIST_INIT_P (elt)
    2043                 :        672 :           && CONSTRUCTOR_ELTS (elt) == 0
    2044                 :         37 :           && CLASSTYPE_NON_AGGREGATE (type)
    2045                 :     355985 :           && TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
    2046                 :         19 :         init = void_type_node;
    2047                 :            :     }
    2048                 :            : 
    2049                 :            :   /* If an explicit -- but empty -- initializer list was present,
    2050                 :            :      that's value-initialization.  */
    2051                 :    1564250 :   if (init == void_type_node)
    2052                 :            :     {
    2053                 :            :       /* If the type has data but no user-provided ctor, we need to zero
    2054                 :            :          out the object.  */
    2055                 :     132270 :       if (!type_has_user_provided_constructor (type)
    2056                 :     132270 :           && !is_really_empty_class (type, /*ignore_vptr*/true))
    2057                 :            :         {
    2058                 :        162 :           tree field_size = NULL_TREE;
    2059                 :        324 :           if (exp != true_exp && CLASSTYPE_AS_BASE (type) != type)
    2060                 :            :             /* Don't clobber already initialized virtual bases.  */
    2061                 :         44 :             field_size = TYPE_SIZE (CLASSTYPE_AS_BASE (type));
    2062                 :        162 :           init = build_zero_init_1 (type, NULL_TREE, /*static_storage_p=*/false,
    2063                 :            :                                     field_size);
    2064                 :        162 :           init = build2 (INIT_EXPR, type, exp, init);
    2065                 :        162 :           finish_expr_stmt (init);
    2066                 :            :         }
    2067                 :            : 
    2068                 :            :       /* If we don't need to mess with the constructor at all,
    2069                 :            :          then we're done.  */
    2070                 :     132270 :       if (! type_build_ctor_call (type))
    2071                 :            :         return;
    2072                 :            : 
    2073                 :            :       /* Otherwise fall through and call the constructor.  */
    2074                 :            :       init = NULL_TREE;
    2075                 :            :     }
    2076                 :            : 
    2077                 :            :   /* We know that expand_default_init can handle everything we want
    2078                 :            :      at this point.  */
    2079                 :    1557600 :   expand_default_init (binfo, true_exp, exp, init, flags, complain);
    2080                 :            : }
    2081                 :            : 
    2082                 :            : /* Report an error if TYPE is not a user-defined, class type.  If
    2083                 :            :    OR_ELSE is nonzero, give an error message.  */
    2084                 :            : 
    2085                 :            : int
    2086                 :   10890100 : is_class_type (tree type, int or_else)
    2087                 :            : {
    2088                 :   10890100 :   if (type == error_mark_node)
    2089                 :            :     return 0;
    2090                 :            : 
    2091                 :   21705500 :   if (! CLASS_TYPE_P (type))
    2092                 :            :     {
    2093                 :         48 :       if (or_else)
    2094                 :          2 :         error ("%qT is not a class type", type);
    2095                 :         48 :       return 0;
    2096                 :            :     }
    2097                 :            :   return 1;
    2098                 :            : }
    2099                 :            : 
    2100                 :            : tree
    2101                 :         12 : get_type_value (tree name)
    2102                 :            : {
    2103                 :         12 :   if (name == error_mark_node)
    2104                 :            :     return NULL_TREE;
    2105                 :            : 
    2106                 :         12 :   if (IDENTIFIER_HAS_TYPE_VALUE (name))
    2107                 :          4 :     return IDENTIFIER_TYPE_VALUE (name);
    2108                 :            :   else
    2109                 :            :     return NULL_TREE;
    2110                 :            : }
    2111                 :            : 
    2112                 :            : /* Build a reference to a member of an aggregate.  This is not a C++
    2113                 :            :    `&', but really something which can have its address taken, and
    2114                 :            :    then act as a pointer to member, for example TYPE :: FIELD can have
    2115                 :            :    its address taken by saying & TYPE :: FIELD.  ADDRESS_P is true if
    2116                 :            :    this expression is the operand of "&".
    2117                 :            : 
    2118                 :            :    @@ Prints out lousy diagnostics for operator <typename>
    2119                 :            :    @@ fields.
    2120                 :            : 
    2121                 :            :    @@ This function should be rewritten and placed in search.c.  */
    2122                 :            : 
    2123                 :            : tree
    2124                 :      38217 : build_offset_ref (tree type, tree member, bool address_p,
    2125                 :            :                   tsubst_flags_t complain)
    2126                 :            : {
    2127                 :      38217 :   tree decl;
    2128                 :      38217 :   tree basebinfo = NULL_TREE;
    2129                 :            : 
    2130                 :            :   /* class templates can come in as TEMPLATE_DECLs here.  */
    2131                 :      38217 :   if (TREE_CODE (member) == TEMPLATE_DECL)
    2132                 :            :     return member;
    2133                 :            : 
    2134                 :      38217 :   if (dependent_scope_p (type) || type_dependent_expression_p (member))
    2135                 :        308 :     return build_qualified_name (NULL_TREE, type, member,
    2136                 :        308 :                                   /*template_p=*/false);
    2137                 :            : 
    2138                 :      37909 :   gcc_assert (TYPE_P (type));
    2139                 :      37909 :   if (! is_class_type (type, 1))
    2140                 :          0 :     return error_mark_node;
    2141                 :            : 
    2142                 :      37909 :   gcc_assert (DECL_P (member) || BASELINK_P (member));
    2143                 :            :   /* Callers should call mark_used before this point.  */
    2144                 :      37909 :   gcc_assert (!DECL_P (member) || TREE_USED (member));
    2145                 :            : 
    2146                 :      37909 :   type = TYPE_MAIN_VARIANT (type);
    2147                 :      37909 :   if (!COMPLETE_OR_OPEN_TYPE_P (complete_type (type)))
    2148                 :            :     {
    2149                 :          0 :       if (complain & tf_error)
    2150                 :          0 :         error ("incomplete type %qT does not have member %qD", type, member);
    2151                 :          0 :       return error_mark_node;
    2152                 :            :     }
    2153                 :            : 
    2154                 :            :   /* Entities other than non-static members need no further
    2155                 :            :      processing.  */
    2156                 :      37909 :   if (TREE_CODE (member) == TYPE_DECL)
    2157                 :            :     return member;
    2158                 :      37909 :   if (VAR_P (member) || TREE_CODE (member) == CONST_DECL)
    2159                 :        841 :     return convert_from_reference (member);
    2160                 :            : 
    2161                 :      37068 :   if (TREE_CODE (member) == FIELD_DECL && DECL_C_BIT_FIELD (member))
    2162                 :            :     {
    2163                 :          0 :       if (complain & tf_error)
    2164                 :          0 :         error ("invalid pointer to bit-field %qD", member);
    2165                 :          0 :       return error_mark_node;
    2166                 :            :     }
    2167                 :            : 
    2168                 :            :   /* Set up BASEBINFO for member lookup.  */
    2169                 :      37068 :   decl = maybe_dummy_object (type, &basebinfo);
    2170                 :            : 
    2171                 :            :   /* A lot of this logic is now handled in lookup_member.  */
    2172                 :      37068 :   if (BASELINK_P (member))
    2173                 :            :     {
    2174                 :            :       /* Go from the TREE_BASELINK to the member function info.  */
    2175                 :      35868 :       tree t = BASELINK_FUNCTIONS (member);
    2176                 :            : 
    2177                 :      35868 :       if (TREE_CODE (t) != TEMPLATE_ID_EXPR && !really_overloaded_fn (t))
    2178                 :            :         {
    2179                 :            :           /* Get rid of a potential OVERLOAD around it.  */
    2180                 :      35002 :           t = OVL_FIRST (t);
    2181                 :            : 
    2182                 :            :           /* Unique functions are handled easily.  */
    2183                 :            : 
    2184                 :            :           /* For non-static member of base class, we need a special rule
    2185                 :            :              for access checking [class.protected]:
    2186                 :            : 
    2187                 :            :                If the access is to form a pointer to member, the
    2188                 :            :                nested-name-specifier shall name the derived class
    2189                 :            :                (or any class derived from that class).  */
    2190                 :      35002 :           bool ok;
    2191                 :      34814 :           if (address_p && DECL_P (t)
    2192                 :      69816 :               && DECL_NONSTATIC_MEMBER_P (t))
    2193                 :       4680 :             ok = perform_or_defer_access_check (TYPE_BINFO (type), t, t,
    2194                 :            :                                                 complain);
    2195                 :            :           else
    2196                 :      30322 :             ok = perform_or_defer_access_check (basebinfo, t, t,
    2197                 :            :                                                 complain);
    2198                 :      35002 :           if (!ok)
    2199                 :          3 :             return error_mark_node;
    2200                 :      69998 :           if (DECL_STATIC_FUNCTION_P (t))
    2201                 :            :             return t;
    2202                 :            :           member = t;
    2203                 :            :         }
    2204                 :            :       else
    2205                 :        866 :         TREE_TYPE (member) = unknown_type_node;
    2206                 :            :     }
    2207                 :       1200 :   else if (address_p && TREE_CODE (member) == FIELD_DECL)
    2208                 :            :     {
    2209                 :            :       /* We need additional test besides the one in
    2210                 :            :          check_accessibility_of_qualified_id in case it is
    2211                 :            :          a pointer to non-static member.  */
    2212                 :       1164 :       if (!perform_or_defer_access_check (TYPE_BINFO (type), member, member,
    2213                 :            :                                           complain))
    2214                 :          0 :         return error_mark_node;
    2215                 :            :     }
    2216                 :            : 
    2217                 :       6793 :   if (!address_p)
    2218                 :            :     {
    2219                 :            :       /* If MEMBER is non-static, then the program has fallen afoul of
    2220                 :            :          [expr.prim]:
    2221                 :            : 
    2222                 :            :            An id-expression that denotes a nonstatic data member or
    2223                 :            :            nonstatic member function of a class can only be used:
    2224                 :            : 
    2225                 :            :            -- as part of a class member access (_expr.ref_) in which the
    2226                 :            :            object-expression refers to the member's class or a class
    2227                 :            :            derived from that class, or
    2228                 :            : 
    2229                 :            :            -- to form a pointer to member (_expr.unary.op_), or
    2230                 :            : 
    2231                 :            :            -- in the body of a nonstatic member function of that class or
    2232                 :            :            of a class derived from that class (_class.mfct.nonstatic_), or
    2233                 :            : 
    2234                 :            :            -- in a mem-initializer for a constructor for that class or for
    2235                 :            :            a class derived from that class (_class.base.init_).  */
    2236                 :        141 :       if (DECL_NONSTATIC_MEMBER_FUNCTION_P (member))
    2237                 :            :         {
    2238                 :            :           /* Build a representation of the qualified name suitable
    2239                 :            :              for use as the operand to "&" -- even though the "&" is
    2240                 :            :              not actually present.  */
    2241                 :         50 :           member = build2 (OFFSET_REF, TREE_TYPE (member), decl, member);
    2242                 :            :           /* In Microsoft mode, treat a non-static member function as if
    2243                 :            :              it were a pointer-to-member.  */
    2244                 :         50 :           if (flag_ms_extensions)
    2245                 :            :             {
    2246                 :         16 :               PTRMEM_OK_P (member) = 1;
    2247                 :          8 :               return cp_build_addr_expr (member, complain);
    2248                 :            :             }
    2249                 :         42 :           if (complain & tf_error)
    2250                 :         39 :             error ("invalid use of non-static member function %qD",
    2251                 :         39 :                    TREE_OPERAND (member, 1));
    2252                 :         42 :           return error_mark_node;
    2253                 :            :         }
    2254                 :         91 :       else if (TREE_CODE (member) == FIELD_DECL)
    2255                 :            :         {
    2256                 :          0 :           if (complain & tf_error)
    2257                 :          0 :             error ("invalid use of non-static data member %qD", member);
    2258                 :          0 :           return error_mark_node;
    2259                 :            :         }
    2260                 :            :       return member;
    2261                 :            :     }
    2262                 :            : 
    2263                 :       6652 :   member = build2 (OFFSET_REF, TREE_TYPE (member), decl, member);
    2264                 :      13304 :   PTRMEM_OK_P (member) = 1;
    2265                 :       6652 :   return member;
    2266                 :            : }
    2267                 :            : 
    2268                 :            : /* If DECL is a scalar enumeration constant or variable with a
    2269                 :            :    constant initializer, return the initializer (or, its initializers,
    2270                 :            :    recursively); otherwise, return DECL.  If STRICT_P, the
    2271                 :            :    initializer is only returned if DECL is a
    2272                 :            :    constant-expression.  If RETURN_AGGREGATE_CST_OK_P, it is ok to
    2273                 :            :    return an aggregate constant.  */
    2274                 :            : 
    2275                 :            : static tree
    2276                 :   97028800 : constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
    2277                 :            : {
    2278                 :  113503000 :   while (TREE_CODE (decl) == CONST_DECL
    2279                 :  111800000 :          || decl_constant_var_p (decl)
    2280                 :  210666000 :          || (!strict_p && VAR_P (decl)
    2281                 :    6601380 :              && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))))
    2282                 :            :     {
    2283                 :   17591300 :       tree init;
    2284                 :            :       /* If DECL is a static data member in a template
    2285                 :            :          specialization, we must instantiate it here.  The
    2286                 :            :          initializer for the static data member is not processed
    2287                 :            :          until needed; we need it now.  */
    2288                 :   17591300 :       mark_used (decl, tf_none);
    2289                 :   17591300 :       init = DECL_INITIAL (decl);
    2290                 :   17591300 :       if (init == error_mark_node)
    2291                 :            :         {
    2292                 :        387 :           if (TREE_CODE (decl) == CONST_DECL
    2293                 :       1161 :               || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    2294                 :            :             /* Treat the error as a constant to avoid cascading errors on
    2295                 :            :                excessively recursive template instantiation (c++/9335).  */
    2296                 :        387 :             return init;
    2297                 :            :           else
    2298                 :            :             return decl;
    2299                 :            :         }
    2300                 :            :       /* Initializers in templates are generally expanded during
    2301                 :            :          instantiation, so before that for const int i(2)
    2302                 :            :          INIT is a TREE_LIST with the actual initializer as
    2303                 :            :          TREE_VALUE.  */
    2304                 :   17590900 :       if (processing_template_decl
    2305                 :       3203 :           && init
    2306                 :       3194 :           && TREE_CODE (init) == TREE_LIST
    2307                 :   17590900 :           && TREE_CHAIN (init) == NULL_TREE)
    2308                 :          0 :         init = TREE_VALUE (init);
    2309                 :            :       /* Instantiate a non-dependent initializer for user variables.  We
    2310                 :            :          mustn't do this for the temporary for an array compound literal;
    2311                 :            :          trying to instatiate the initializer will keep creating new
    2312                 :            :          temporaries until we crash.  Probably it's not useful to do it for
    2313                 :            :          other artificial variables, either.  */
    2314                 :   17590900 :       if (!DECL_ARTIFICIAL (decl))
    2315                 :   17566100 :         init = instantiate_non_dependent_or_null (init);
    2316                 :   17590900 :       if (!init
    2317                 :   17001100 :           || !TREE_TYPE (init)
    2318                 :   17000800 :           || !TREE_CONSTANT (init)
    2319                 :   34065600 :           || (!return_aggregate_cst_ok_p
    2320                 :            :               /* Unless RETURN_AGGREGATE_CST_OK_P is true, do not
    2321                 :            :                  return an aggregate constant (of which string
    2322                 :            :                  literals are a special case), as we do not want
    2323                 :            :                  to make inadvertent copies of such entities, and
    2324                 :            :                  we must be sure that their addresses are the
    2325                 :            :                  same everywhere.  */
    2326                 :     482051 :               && (TREE_CODE (init) == CONSTRUCTOR
    2327                 :     482051 :                   || TREE_CODE (init) == STRING_CST)))
    2328                 :            :         break;
    2329                 :            :       /* Don't return a CONSTRUCTOR for a variable with partial run-time
    2330                 :            :          initialization, since it doesn't represent the entire value.
    2331                 :            :          Similarly for VECTOR_CSTs created by cp_folding those
    2332                 :            :          CONSTRUCTORs.  */
    2333                 :   16474700 :       if ((TREE_CODE (init) == CONSTRUCTOR
    2334                 :   16474700 :            || TREE_CODE (init) == VECTOR_CST)
    2335                 :   16508900 :           && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    2336                 :            :         break;
    2337                 :            :       /* If the variable has a dynamic initializer, don't use its
    2338                 :            :          DECL_INITIAL which doesn't reflect the real value.  */
    2339                 :   16474600 :       if (VAR_P (decl)
    2340                 :   16474600 :           && TREE_STATIC (decl)
    2341                 :   14490200 :           && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)
    2342                 :   16474600 :           && DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    2343                 :            :         break;
    2344                 :   16474600 :       decl = unshare_expr (init);
    2345                 :            :     }
    2346                 :            :   return decl;
    2347                 :            : }
    2348                 :            : 
    2349                 :            : /* If DECL is a CONST_DECL, or a constant VAR_DECL initialized by constant
    2350                 :            :    of integral or enumeration type, or a constexpr variable of scalar type,
    2351                 :            :    then return that value.  These are those variables permitted in constant
    2352                 :            :    expressions by [5.19/1].  */
    2353                 :            : 
    2354                 :            : tree
    2355                 :   48253500 : scalar_constant_value (tree decl)
    2356                 :            : {
    2357                 :   48253500 :   return constant_value_1 (decl, /*strict_p=*/true,
    2358                 :   48253500 :                            /*return_aggregate_cst_ok_p=*/false);
    2359                 :            : }
    2360                 :            : 
    2361                 :            : /* Like scalar_constant_value, but can also return aggregate initializers.  */
    2362                 :            : 
    2363                 :            : tree
    2364                 :   18686700 : decl_really_constant_value (tree decl)
    2365                 :            : {
    2366                 :   18686700 :   return constant_value_1 (decl, /*strict_p=*/true,
    2367                 :   18686700 :                            /*return_aggregate_cst_ok_p=*/true);
    2368                 :            : }
    2369                 :            : 
    2370                 :            : /* A more relaxed version of scalar_constant_value, used by the
    2371                 :            :    common C/C++ code.  */
    2372                 :            : 
    2373                 :            : tree
    2374                 :   30088700 : decl_constant_value (tree decl)
    2375                 :            : {
    2376                 :   30088700 :   return constant_value_1 (decl, /*strict_p=*/processing_template_decl,
    2377                 :   30088700 :                            /*return_aggregate_cst_ok_p=*/true);
    2378                 :            : }
    2379                 :            : 
    2380                 :            : /* Common subroutines of build_new and build_vec_delete.  */
    2381                 :            : 
    2382                 :            : /* Build and return a NEW_EXPR.  If NELTS is non-NULL, TYPE[NELTS] is
    2383                 :            :    the type of the object being allocated; otherwise, it's just TYPE.
    2384                 :            :    INIT is the initializer, if any.  USE_GLOBAL_NEW is true if the
    2385                 :            :    user explicitly wrote "::operator new".  PLACEMENT, if non-NULL, is
    2386                 :            :    a vector of arguments to be provided as arguments to a placement
    2387                 :            :    new operator.  This routine performs no semantic checks; it just
    2388                 :            :    creates and returns a NEW_EXPR.  */
    2389                 :            : 
    2390                 :            : static tree
    2391                 :      68777 : build_raw_new_expr (location_t loc, vec<tree, va_gc> *placement, tree type,
    2392                 :            :                     tree nelts, vec<tree, va_gc> *init, int use_global_new)
    2393                 :            : {
    2394                 :      68777 :   tree init_list;
    2395                 :      68777 :   tree new_expr;
    2396                 :            : 
    2397                 :            :   /* If INIT is NULL, the we want to store NULL_TREE in the NEW_EXPR.
    2398                 :            :      If INIT is not NULL, then we want to store VOID_ZERO_NODE.  This
    2399                 :            :      permits us to distinguish the case of a missing initializer "new
    2400                 :            :      int" from an empty initializer "new int()".  */
    2401                 :      68777 :   if (init == NULL)
    2402                 :            :     init_list = NULL_TREE;
    2403                 :      48748 :   else if (init->is_empty ())
    2404                 :       2488 :     init_list = void_node;
    2405                 :            :   else
    2406                 :      46260 :     init_list = build_tree_list_vec (init);
    2407                 :            : 
    2408                 :      68777 :   new_expr = build4_loc (loc, NEW_EXPR, build_pointer_type (type),
    2409                 :            :                          build_tree_list_vec (placement), type, nelts,
    2410                 :            :                          init_list);
    2411                 :      68777 :   NEW_EXPR_USE_GLOBAL (new_expr) = use_global_new;
    2412                 :      68777 :   TREE_SIDE_EFFECTS (new_expr) = 1;
    2413                 :            : 
    2414                 :      68777 :   return new_expr;
    2415                 :            : }
    2416                 :            : 
    2417                 :            : /* Diagnose uninitialized const members or reference members of type
    2418                 :            :    TYPE. USING_NEW is used to disambiguate the diagnostic between a
    2419                 :            :    new expression without a new-initializer and a declaration. Returns
    2420                 :            :    the error count. */
    2421                 :            : 
    2422                 :            : static int
    2423                 :         71 : diagnose_uninitialized_cst_or_ref_member_1 (tree type, tree origin,
    2424                 :            :                                             bool using_new, bool complain)
    2425                 :            : {
    2426                 :         71 :   tree field;
    2427                 :         71 :   int error_count = 0;
    2428                 :            : 
    2429                 :         71 :   if (type_has_user_provided_constructor (type))
    2430                 :            :     return 0;
    2431                 :            : 
    2432                 :        224 :   for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    2433                 :            :     {
    2434                 :        153 :       tree field_type;
    2435                 :            : 
    2436                 :        153 :       if (TREE_CODE (field) != FIELD_DECL)
    2437                 :         70 :         continue;
    2438                 :            : 
    2439                 :         83 :       field_type = strip_array_types (TREE_TYPE (field));
    2440                 :            : 
    2441                 :         83 :       if (type_has_user_provided_constructor (field_type))
    2442                 :          3 :         continue;
    2443                 :            : 
    2444                 :         80 :       if (TYPE_REF_P (field_type))
    2445                 :            :         {
    2446                 :         26 :           ++ error_count;
    2447                 :         26 :           if (complain)
    2448                 :            :             {
    2449                 :         24 :               if (DECL_CONTEXT (field) == origin)
    2450                 :            :                 {
    2451                 :         14 :                   if (using_new)
    2452                 :          6 :                     error ("uninitialized reference member in %q#T "
    2453                 :            :                            "using %<new%> without new-initializer", origin);
    2454                 :            :                   else
    2455                 :          8 :                     error ("uninitialized reference member in %q#T", origin);
    2456                 :            :                 }
    2457                 :            :               else
    2458                 :            :                 {
    2459                 :         10 :                   if (using_new)
    2460                 :          4 :                     error ("uninitialized reference member in base %q#T "
    2461                 :            :                            "of %q#T using %<new%> without new-initializer",
    2462                 :          4 :                            DECL_CONTEXT (field), origin);
    2463                 :            :                   else
    2464                 :          6 :                     error ("uninitialized reference member in base %q#T "
    2465                 :          6 :                            "of %q#T", DECL_CONTEXT (field), origin);
    2466                 :            :                 }
    2467                 :         24 :               inform (DECL_SOURCE_LOCATION (field),
    2468                 :            :                       "%q#D should be initialized", field);
    2469                 :            :             }
    2470                 :            :         }
    2471                 :            : 
    2472                 :         80 :       if (CP_TYPE_CONST_P (field_type))
    2473                 :            :         {
    2474                 :         32 :           ++ error_count;
    2475                 :         32 :           if (complain)
    2476                 :            :             {
    2477                 :         30 :               if (DECL_CONTEXT (field) == origin)
    2478                 :            :                 {
    2479                 :         21 :                   if (using_new)
    2480                 :          9 :                     error ("uninitialized const member in %q#T "
    2481                 :            :                            "using %<new%> without new-initializer", origin);
    2482                 :            :                   else
    2483                 :         12 :                     error ("uninitialized const member in %q#T", origin);
    2484                 :            :                 }
    2485                 :            :               else
    2486                 :            :                 {
    2487                 :          9 :                   if (using_new)
    2488                 :          4 :                     error ("uninitialized const member in base %q#T "
    2489                 :            :                            "of %q#T using %<new%> without new-initializer",
    2490                 :          4 :                            DECL_CONTEXT (field), origin);
    2491                 :            :                   else
    2492                 :          5 :                     error ("uninitialized const member in base %q#T "
    2493                 :          5 :                            "of %q#T", DECL_CONTEXT (field), origin);
    2494                 :            :                 }
    2495                 :         30 :               inform (DECL_SOURCE_LOCATION (field),
    2496                 :            :                       "%q#D should be initialized", field);
    2497                 :            :             }
    2498                 :            :         }
    2499                 :            : 
    2500                 :        100 :       if (CLASS_TYPE_P (field_type))
    2501                 :         20 :         error_count
    2502                 :         20 :           += diagnose_uninitialized_cst_or_ref_member_1 (field_type, origin,
    2503                 :            :                                                          using_new, complain);
    2504                 :            :     }
    2505                 :            :   return error_count;
    2506                 :            : }
    2507                 :            : 
    2508                 :            : int
    2509                 :         51 : diagnose_uninitialized_cst_or_ref_member (tree type, bool using_new, bool complain)
    2510                 :            : {
    2511                 :         51 :   return diagnose_uninitialized_cst_or_ref_member_1 (type, type, using_new, complain);
    2512                 :            : }
    2513                 :            : 
    2514                 :            : /* Call __cxa_bad_array_new_length to indicate that the size calculation
    2515                 :            :    overflowed.  Pretend it returns sizetype so that it plays nicely in the
    2516                 :            :    COND_EXPR.  */
    2517                 :            : 
    2518                 :            : tree
    2519                 :       1719 : throw_bad_array_new_length (void)
    2520                 :            : {
    2521                 :       1719 :   if (!fn)
    2522                 :            :     {
    2523                 :       1103 :       tree name = get_identifier ("__cxa_throw_bad_array_new_length");
    2524                 :            : 
    2525                 :       1103 :       fn = get_global_binding (name);
    2526                 :       1103 :       if (!fn)
    2527                 :       1103 :         fn = push_throw_library_fn
    2528                 :       1103 :           (name, build_function_type_list (sizetype, NULL_TREE));
    2529                 :            :     }
    2530                 :            : 
    2531                 :       1719 :   return build_cxx_call (fn, 0, NULL, tf_warning_or_error);
    2532                 :            : }
    2533                 :            : 
    2534                 :            : /* Attempt to find the initializer for flexible array field T in the
    2535                 :            :    initializer INIT, when non-null.  Returns the initializer when
    2536                 :            :    successful and NULL otherwise.  */
    2537                 :            : static tree
    2538                 :        224 : find_flexarray_init (tree t, tree init)
    2539                 :            : {
    2540                 :        224 :   if (!init || init == error_mark_node)
    2541                 :            :     return NULL_TREE;
    2542                 :            : 
    2543                 :            :   unsigned HOST_WIDE_INT idx;
    2544                 :            :   tree field, elt;
    2545                 :            : 
    2546                 :            :   /* Iterate over all top-level initializer elements.  */
    2547                 :        400 :   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), idx, field, elt)
    2548                 :            :     /* If the member T is found, return it.  */
    2549                 :        168 :     if (field == t)
    2550                 :         52 :       return elt;
    2551                 :            : 
    2552                 :            :   return NULL_TREE;
    2553                 :            : }
    2554                 :            : 
    2555                 :            : /* Attempt to verify that the argument, OPER, of a placement new expression
    2556                 :            :    refers to an object sufficiently large for an object of TYPE or an array
    2557                 :            :    of NELTS of such objects when NELTS is non-null, and issue a warning when
    2558                 :            :    it does not.  SIZE specifies the size needed to construct the object or
    2559                 :            :    array and captures the result of NELTS * sizeof (TYPE). (SIZE could be
    2560                 :            :    greater when the array under construction requires a cookie to store
    2561                 :            :    NELTS.  GCC's placement new expression stores the cookie when invoking
    2562                 :            :    a user-defined placement new operator function but not the default one.
    2563                 :            :    Placement new expressions with user-defined placement new operator are
    2564                 :            :    not diagnosed since we don't know how they use the buffer (this could
    2565                 :            :    be a future extension).  */
    2566                 :            : static void
    2567                 :     105380 : warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
    2568                 :            : {
    2569                 :     105380 :   location_t loc = cp_expr_loc_or_input_loc (oper);
    2570                 :            : 
    2571                 :            :   /* The number of bytes to add to or subtract from the size of the provided
    2572                 :            :      buffer based on an offset into an array or an array element reference.
    2573                 :            :      Although intermediate results may be negative (as in a[3] - 2) a valid
    2574                 :            :      final result cannot be.  */
    2575                 :     105380 :   offset_int adjust = 0;
    2576                 :            :   /* True when the size of the entire destination object should be used
    2577                 :            :      to compute the possibly optimistic estimate of the available space.  */
    2578                 :     105380 :   bool use_obj_size = false;
    2579                 :            :   /* True when the reference to the destination buffer is an ADDR_EXPR.  */
    2580                 :     105380 :   bool addr_expr = false;
    2581                 :            : 
    2582                 :     105380 :   STRIP_NOPS (oper);
    2583                 :            : 
    2584                 :            :   /* Using a function argument or a (non-array) variable as an argument
    2585                 :            :      to placement new is not checked since it's unknown what it might
    2586                 :            :      point to.  */
    2587                 :     105380 :   if (TREE_CODE (oper) == PARM_DECL
    2588                 :      53103 :       || VAR_P (oper)
    2589                 :      32694 :       || TREE_CODE (oper) == COMPONENT_REF)
    2590                 :      72771 :     return;
    2591                 :            : 
    2592                 :            :   /* Evaluate any constant expressions.  */
    2593                 :      32637 :   size = fold_non_dependent_expr (size);
    2594                 :            : 
    2595                 :            :   /* Handle the common case of array + offset expression when the offset
    2596                 :            :      is a constant.  */
    2597                 :      32637 :   if (TREE_CODE (oper) == POINTER_PLUS_EXPR)
    2598                 :            :     {
    2599                 :            :       /* If the offset is compile-time constant, use it to compute a more
    2600                 :            :          accurate estimate of the size of the buffer.  Since the operand
    2601                 :            :          of POINTER_PLUS_EXPR is represented as an unsigned type, convert
    2602                 :            :          it to signed first.
    2603                 :            :          Otherwise, use the size of the entire array as an optimistic
    2604                 :            :          estimate (this may lead to false negatives).  */
    2605                 :        317 :       tree adj = TREE_OPERAND (oper, 1);
    2606                 :        317 :       adj = fold_for_warn (adj);
    2607                 :        317 :       if (CONSTANT_CLASS_P (adj))
    2608                 :        212 :         adjust += wi::to_offset (convert (ssizetype, adj));
    2609                 :            :       else
    2610                 :            :         use_obj_size = true;
    2611                 :            : 
    2612                 :        317 :       oper = TREE_OPERAND (oper, 0);
    2613                 :            : 
    2614                 :        317 :       STRIP_NOPS (oper);
    2615                 :            :     }
    2616                 :            : 
    2617                 :      32637 :   if (TREE_CODE (oper) == TARGET_EXPR)
    2618                 :          0 :     oper = TREE_OPERAND (oper, 1);
    2619                 :      32637 :   else if (TREE_CODE (oper) == ADDR_EXPR)
    2620                 :            :     {
    2621                 :       2649 :       addr_expr = true;
    2622                 :       2649 :       oper = TREE_OPERAND (oper, 0);
    2623                 :            :     }
    2624                 :            : 
    2625                 :      32637 :   STRIP_NOPS (oper);
    2626                 :            : 
    2627                 :      32637 :   if (TREE_CODE (oper) == ARRAY_REF
    2628                 :      32653 :       && (addr_expr || TREE_CODE (TREE_TYPE (oper)) == ARRAY_TYPE))
    2629                 :            :     {
    2630                 :            :       /* Similar to the offset computed above, see if the array index
    2631                 :            :          is a compile-time constant.  If so, and unless the offset was
    2632                 :            :          not a compile-time constant, use the index to determine the
    2633                 :            :          size of the buffer.  Otherwise, use the entire array as
    2634                 :            :          an optimistic estimate of the size.  */
    2635                 :        665 :       const_tree adj = fold_non_dependent_expr (TREE_OPERAND (oper, 1));
    2636                 :        665 :       if (!use_obj_size && CONSTANT_CLASS_P (adj))
    2637                 :        593 :         adjust += wi::to_offset (adj);
    2638                 :            :       else
    2639                 :            :         {
    2640                 :         72 :           use_obj_size = true;
    2641                 :         72 :           adjust = 0;
    2642                 :            :         }
    2643                 :            : 
    2644                 :        665 :       oper = TREE_OPERAND (oper, 0);
    2645                 :            :     }
    2646                 :            : 
    2647                 :            :   /* Refers to the declared object that constains the subobject referenced
    2648                 :            :      by OPER.  When the object is initialized, makes it possible to determine
    2649                 :            :      the actual size of a flexible array member used as the buffer passed
    2650                 :            :      as OPER to placement new.  */
    2651                 :      32637 :   tree var_decl = NULL_TREE;
    2652                 :            :   /* True when operand is a COMPONENT_REF, to distinguish flexible array
    2653                 :            :      members from arrays of unspecified size.  */
    2654                 :      32637 :   bool compref = TREE_CODE (oper) == COMPONENT_REF;
    2655                 :            : 
    2656                 :            :   /* For COMPONENT_REF (i.e., a struct member) the size of the entire
    2657                 :            :      enclosing struct.  Used to validate the adjustment (offset) into
    2658                 :            :      an array at the end of a struct.  */
    2659                 :      32637 :   offset_int compsize = 0;
    2660                 :            : 
    2661                 :            :   /* Descend into a struct or union to find the member whose address
    2662                 :            :      is being used as the argument.  */
    2663                 :      32637 :   if (TREE_CODE (oper) == COMPONENT_REF)
    2664                 :            :     {
    2665                 :       1243 :       tree comptype = TREE_TYPE (TREE_OPERAND (oper, 0));
    2666                 :       1243 :       compsize = wi::to_offset (TYPE_SIZE_UNIT (comptype));
    2667                 :            : 
    2668                 :       1243 :       tree op0 = oper;
    2669                 :       1737 :       while (TREE_CODE (op0 = TREE_OPERAND (op0, 0)) == COMPONENT_REF);
    2670                 :       1243 :       STRIP_ANY_LOCATION_WRAPPER (op0);
    2671                 :       1243 :       if (VAR_P (op0))
    2672                 :        362 :         var_decl = op0;
    2673                 :       1243 :       oper = TREE_OPERAND (oper, 1);
    2674                 :            :     }
    2675                 :            : 
    2676                 :      32637 :   STRIP_ANY_LOCATION_WRAPPER (oper);
    2677                 :      32637 :   tree opertype = TREE_TYPE (oper);
    2678                 :      32637 :   if ((addr_expr || !INDIRECT_TYPE_P (opertype))
    2679                 :       2649 :       && (VAR_P (oper)
    2680                 :       2649 :           || TREE_CODE (oper) == FIELD_DECL
    2681                 :         15 :           || TREE_CODE (oper) == PARM_DECL))
    2682                 :            :     {
    2683                 :            :       /* A possibly optimistic estimate of the number of bytes available
    2684                 :            :          in the destination buffer.  */
    2685                 :       2649 :       offset_int bytes_avail = 0;
    2686                 :            :       /* True when the estimate above is in fact the exact size
    2687                 :            :          of the destination buffer rather than an estimate.  */
    2688                 :       2649 :       bool exact_size = true;
    2689                 :            : 
    2690                 :            :       /* Treat members of unions and members of structs uniformly, even
    2691                 :            :          though the size of a member of a union may be viewed as extending
    2692                 :            :          to the end of the union itself (it is by __builtin_object_size).  */
    2693                 :       1243 :       if ((VAR_P (oper) || use_obj_size)
    2694                 :       1438 :           && DECL_SIZE_UNIT (oper)
    2695                 :       4043 :           && tree_fits_uhwi_p (DECL_SIZE_UNIT (oper)))
    2696                 :            :         {
    2697                 :            :           /* Use the size of the entire array object when the expression
    2698                 :            :              refers to a variable or its size depends on an expression
    2699                 :            :              that's not a compile-time constant.  */
    2700                 :       1338 :           bytes_avail = wi::to_offset (DECL_SIZE_UNIT (oper));
    2701                 :       1338 :           exact_size = !use_obj_size;
    2702                 :            :         }
    2703                 :       1311 :       else if (tree opersize = TYPE_SIZE_UNIT (opertype))
    2704                 :            :         {
    2705                 :            :           /* Use the size of the type of the destination buffer object
    2706                 :            :              as the optimistic estimate of the available space in it.
    2707                 :            :              Use the maximum possible size for zero-size arrays and
    2708                 :            :              flexible array members (except of initialized objects
    2709                 :            :              thereof).  */
    2710                 :        835 :           if (TREE_CODE (opersize) == INTEGER_CST)
    2711                 :        779 :             bytes_avail = wi::to_offset (opersize);
    2712                 :            :         }
    2713                 :            : 
    2714                 :       2649 :       if (bytes_avail == 0)
    2715                 :            :         {
    2716                 :        768 :           if (var_decl)
    2717                 :            :             {
    2718                 :            :               /* Constructing into a buffer provided by the flexible array
    2719                 :            :                  member of a declared object (which is permitted as a G++
    2720                 :            :                  extension).  If the array member has been initialized,
    2721                 :            :                  determine its size from the initializer.  Otherwise,
    2722                 :            :                  the array size is zero.  */
    2723                 :        448 :               if (tree init = find_flexarray_init (oper,
    2724                 :        224 :                                                    DECL_INITIAL (var_decl)))
    2725                 :         52 :                 bytes_avail = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (init)));
    2726                 :            :             }
    2727                 :            :           else
    2728                 :        544 :             bytes_avail = (wi::to_offset (TYPE_MAX_VALUE (ptrdiff_type_node))
    2729                 :        544 :                            - compsize);
    2730                 :            :         }
    2731                 :            : 
    2732                 :       2649 :       tree_code oper_code = TREE_CODE (opertype);
    2733                 :            : 
    2734                 :       2649 :       if (compref && oper_code == ARRAY_TYPE)
    2735                 :            :         {
    2736                 :        937 :           tree nelts = array_type_nelts_top (opertype);
    2737                 :        937 :           tree nelts_cst = maybe_constant_value (nelts);
    2738                 :        937 :           if (TREE_CODE (nelts_cst) == INTEGER_CST
    2739                 :        477 :               && integer_onep (nelts_cst)
    2740                 :         84 :               && !var_decl
    2741                 :        993 :               && warn_placement_new < 2)
    2742                 :         28 :             return;
    2743                 :            :         }
    2744                 :            : 
    2745                 :            :       /* Reduce the size of the buffer by the adjustment computed above
    2746                 :            :          from the offset and/or the index into the array.  */
    2747                 :       2625 :       if (bytes_avail < adjust || adjust < 0)
    2748                 :        320 :         bytes_avail = 0;
    2749                 :            :       else
    2750                 :            :         {
    2751                 :       2305 :           tree elttype = (TREE_CODE (opertype) == ARRAY_TYPE
    2752                 :       3969 :                           ? TREE_TYPE (opertype) : opertype);
    2753                 :       2305 :           if (tree eltsize = TYPE_SIZE_UNIT (elttype))
    2754                 :            :             {
    2755                 :       2297 :               bytes_avail -= adjust * wi::to_offset (eltsize);
    2756                 :       2297 :               if (bytes_avail < 0)
    2757                 :         28 :                 bytes_avail = 0;
    2758                 :            :             }
    2759                 :            :         }
    2760                 :            : 
    2761                 :            :       /* The minimum amount of space needed for the allocation.  This
    2762                 :            :          is an optimistic estimate that makes it possible to detect
    2763                 :            :          placement new invocation for some undersize buffers but not
    2764                 :            :          others.  */
    2765                 :       2625 :       offset_int bytes_need;
    2766                 :            : 
    2767                 :       2625 :       if (nelts)
    2768                 :        797 :         nelts = fold_for_warn (nelts);
    2769                 :            : 
    2770                 :       2625 :       if (CONSTANT_CLASS_P (size))
    2771                 :       2593 :         bytes_need = wi::to_offset (size);
    2772                 :         32 :       else if (nelts && CONSTANT_CLASS_P (nelts))
    2773                 :          0 :         bytes_need = (wi::to_offset (nelts)
    2774                 :          0 :                       * wi::to_offset (TYPE_SIZE_UNIT (type)));
    2775                 :         32 :       else if (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
    2776                 :         28 :         bytes_need = wi::to_offset (TYPE_SIZE_UNIT (type));
    2777                 :            :       else
    2778                 :            :         {
    2779                 :            :           /* The type is a VLA.  */
    2780                 :            :           return;
    2781                 :            :         }
    2782                 :            : 
    2783                 :       2621 :       if (bytes_avail < bytes_need)
    2784                 :            :         {
    2785                 :       1192 :           if (nelts)
    2786                 :        536 :             if (CONSTANT_CLASS_P (nelts))
    2787                 :        532 :               warning_at (loc, OPT_Wplacement_new_,
    2788                 :            :                           exact_size ?
    2789                 :            :                           "placement new constructing an object of type "
    2790                 :            :                           "%<%T [%wu]%> and size %qwu in a region of type %qT "
    2791                 :            :                           "and size %qwi"
    2792                 :            :                           : "placement new constructing an object of type "
    2793                 :            :                           "%<%T [%wu]%> and size %qwu in a region of type %qT "
    2794                 :            :                           "and size at most %qwu",
    2795                 :            :                           type, tree_to_uhwi (nelts), bytes_need.to_uhwi (),
    2796                 :            :                           opertype, bytes_avail.to_uhwi ());
    2797                 :            :             else
    2798                 :         12 :               warning_at (loc, OPT_Wplacement_new_,
    2799                 :            :                           exact_size ?
    2800                 :            :                           "placement new constructing an array of objects "
    2801                 :            :                           "of type %qT and size %qwu in a region of type %qT "
    2802                 :            :                           "and size %qwi"
    2803                 :            :                           : "placement new constructing an array of objects "
    2804                 :            :                           "of type %qT and size %qwu in a region of type %qT "
    2805                 :            :                           "and size at most %qwu",
    2806                 :            :                           type, bytes_need.to_uhwi (), opertype,
    2807                 :            :                           bytes_avail.to_uhwi ());
    2808                 :            :           else
    2809                 :        672 :             warning_at (loc, OPT_Wplacement_new_,
    2810                 :            :                         exact_size ?
    2811                 :            :                         "placement new constructing an object of type %qT "
    2812                 :            :                         "and size %qwu in a region of type %qT and size %qwi"
    2813                 :            :                         : "placement new constructing an object of type %qT "
    2814                 :            :                         "and size %qwu in a region of type %qT and size "
    2815                 :            :                         "at most %qwu",
    2816                 :            :                         type, bytes_need.to_uhwi (), opertype,
    2817                 :            :                         bytes_avail.to_uhwi ());
    2818                 :            :         }
    2819                 :            :     }
    2820                 :            : }
    2821                 :            : 
    2822                 :            : /* True if alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__.  */
    2823                 :            : 
    2824                 :            : bool
    2825                 :     311539 : type_has_new_extended_alignment (tree t)
    2826                 :            : {
    2827                 :     311539 :   return (aligned_new_threshold
    2828                 :     509438 :           && TYPE_ALIGN_UNIT (t) > (unsigned)aligned_new_threshold);
    2829                 :            : }
    2830                 :            : 
    2831                 :            : /* Return the alignment we expect malloc to guarantee.  This should just be
    2832                 :            :    MALLOC_ABI_ALIGNMENT, but that macro defaults to only BITS_PER_WORD for some
    2833                 :            :    reason, so don't let the threshold be smaller than max_align_t_align.  */
    2834                 :            : 
    2835                 :            : unsigned
    2836                 :      34129 : malloc_alignment ()
    2837                 :            : {
    2838                 :      34874 :   return MAX (max_align_t_align(), MALLOC_ABI_ALIGNMENT);
    2839                 :            : }
    2840                 :            : 
    2841                 :            : /* Determine whether an allocation function is a namespace-scope
    2842                 :            :    non-replaceable placement new function. See DR 1748.  */
    2843                 :            : static bool
    2844                 :     102910 : std_placement_new_fn_p (tree alloc_fn)
    2845                 :            : {
    2846                 :     205820 :   if (DECL_NAMESPACE_SCOPE_P (alloc_fn))
    2847                 :            :     {
    2848                 :     102896 :       tree first_arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (alloc_fn)));
    2849                 :     102896 :       if ((TREE_VALUE (first_arg) == ptr_type_node)
    2850                 :     205772 :           && TREE_CHAIN (first_arg) == void_list_node)
    2851                 :     102876 :         return true;
    2852                 :            :     }
    2853                 :            :   return false;
    2854                 :            : }
    2855                 :            : 
    2856                 :            : /* For element type ELT_TYPE, return the appropriate type of the heap object
    2857                 :            :    containing such element(s).  COOKIE_SIZE is NULL or the size of cookie
    2858                 :            :    in bytes.  FULL_SIZE is NULL if it is unknown how big the heap allocation
    2859                 :            :    will be, otherwise size of the heap object.  If COOKIE_SIZE is NULL,
    2860                 :            :    return array type ELT_TYPE[FULL_SIZE / sizeof(ELT_TYPE)], otherwise return
    2861                 :            :    struct { size_t[COOKIE_SIZE/sizeof(size_t)]; ELT_TYPE[N]; }
    2862                 :            :    where N is nothing (flexible array member) if FULL_SIZE is NULL, otherwise
    2863                 :            :    it is computed such that the size of the struct fits into FULL_SIZE.  */
    2864                 :            : 
    2865                 :            : tree
    2866                 :        188 : build_new_constexpr_heap_type (tree elt_type, tree cookie_size, tree full_size)
    2867                 :            : {
    2868                 :        188 :   gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size));
    2869                 :        188 :   gcc_assert (full_size == NULL_TREE || tree_fits_uhwi_p (full_size));
    2870                 :        188 :   unsigned HOST_WIDE_INT csz = cookie_size ? tree_to_uhwi (cookie_size) : 0;
    2871                 :        188 :   tree itype2 = NULL_TREE;
    2872                 :        188 :   if (full_size)
    2873                 :            :     {
    2874                 :        187 :       unsigned HOST_WIDE_INT fsz = tree_to_uhwi (full_size);
    2875                 :        187 :       gcc_assert (fsz >= csz);
    2876                 :        187 :       fsz -= csz;
    2877                 :        187 :       fsz /= int_size_in_bytes (elt_type);
    2878                 :        187 :       itype2 = build_index_type (size_int (fsz - 1));
    2879                 :        187 :       if (!cookie_size)
    2880                 :        186 :         return build_cplus_array_type (elt_type, itype2);
    2881                 :            :     }
    2882                 :            :   else
    2883                 :          1 :     gcc_assert (cookie_size);
    2884                 :          2 :   csz /= int_size_in_bytes (sizetype);
    2885                 :          2 :   tree itype1 = build_index_type (size_int (csz - 1));
    2886                 :          2 :   tree atype1 = build_cplus_array_type (sizetype, itype1);
    2887                 :          2 :   tree atype2 = build_cplus_array_type (elt_type, itype2);
    2888                 :          2 :   tree rtype = cxx_make_type (RECORD_TYPE);
    2889                 :          2 :   TYPE_NAME (rtype) = heap_identifier;
    2890                 :          2 :   tree fld1 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype1);
    2891                 :          2 :   tree fld2 = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, atype2);
    2892                 :          2 :   DECL_FIELD_CONTEXT (fld1) = rtype;
    2893                 :          2 :   DECL_FIELD_CONTEXT (fld2) = rtype;
    2894                 :          2 :   DECL_ARTIFICIAL (fld1) = true;
    2895                 :          2 :   DECL_ARTIFICIAL (fld2) = true;
    2896                 :          2 :   TYPE_FIELDS (rtype) = fld1;
    2897                 :          2 :   DECL_CHAIN (fld1) = fld2;
    2898                 :          2 :   layout_type (rtype);
    2899                 :          2 :   return rtype;
    2900                 :            : }
    2901                 :            : 
    2902                 :            : /* Help the constexpr code to find the right type for the heap variable
    2903                 :            :    by adding a NOP_EXPR around ALLOC_CALL if needed for cookie_size.
    2904                 :            :    Return ALLOC_CALL or ALLOC_CALL cast to a pointer to
    2905                 :            :    struct { size_t[cookie_size/sizeof(size_t)]; elt_type[]; }.  */
    2906                 :            : 
    2907                 :            : static tree
    2908                 :        215 : maybe_wrap_new_for_constexpr (tree alloc_call, tree elt_type, tree cookie_size)
    2909                 :            : {
    2910                 :        215 :   if (cxx_dialect < cxx2a)
    2911                 :            :     return alloc_call;
    2912                 :            : 
    2913                 :         39 :   if (current_function_decl != NULL_TREE
    2914                 :         78 :       && !DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    2915                 :            :     return alloc_call;
    2916                 :            :   
    2917                 :          1 :   tree call_expr = extract_call_expr (alloc_call);
    2918                 :          1 :   if (call_expr == error_mark_node)
    2919                 :            :     return alloc_call;
    2920                 :            : 
    2921                 :          1 :   tree alloc_call_fndecl = cp_get_callee_fndecl_nofold (call_expr);
    2922                 :          1 :   if (alloc_call_fndecl == NULL_TREE
    2923                 :          1 :       || !IDENTIFIER_NEW_OP_P (DECL_NAME (alloc_call_fndecl))
    2924                 :          2 :       || CP_DECL_CONTEXT (alloc_call_fndecl) != global_namespace)
    2925                 :            :     return alloc_call;
    2926                 :            : 
    2927                 :          1 :   tree rtype = build_new_constexpr_heap_type (elt_type, cookie_size,
    2928                 :            :                                               NULL_TREE);
    2929                 :          1 :   return build_nop (build_pointer_type (rtype), alloc_call);
    2930                 :            : }
    2931                 :            : 
    2932                 :            : /* Generate code for a new-expression, including calling the "operator
    2933                 :            :    new" function, initializing the object, and, if an exception occurs
    2934                 :            :    during construction, cleaning up.  The arguments are as for
    2935                 :            :    build_raw_new_expr.  This may change PLACEMENT and INIT.
    2936                 :            :    TYPE is the type of the object being constructed, possibly an array
    2937                 :            :    of NELTS elements when NELTS is non-null (in "new T[NELTS]", T may
    2938                 :            :    be an array of the form U[inner], with the whole expression being
    2939                 :            :    "new U[NELTS][inner]").  */
    2940                 :            : 
    2941                 :            : static tree
    2942                 :     182843 : build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
    2943                 :            :              vec<tree, va_gc> **init, bool globally_qualified_p,
    2944                 :            :              tsubst_flags_t complain)
    2945                 :            : {
    2946                 :     182843 :   tree size, rval;
    2947                 :            :   /* True iff this is a call to "operator new[]" instead of just
    2948                 :            :      "operator new".  */
    2949                 :     182843 :   bool array_p = false;
    2950                 :            :   /* If ARRAY_P is true, the element type of the array.  This is never
    2951                 :            :      an ARRAY_TYPE; for something like "new int[3][4]", the
    2952                 :            :      ELT_TYPE is "int".  If ARRAY_P is false, this is the same type as
    2953                 :            :      TYPE.  */
    2954                 :     182843 :   tree elt_type;
    2955                 :            :   /* The type of the new-expression.  (This type is always a pointer
    2956                 :            :      type.)  */
    2957                 :     182843 :   tree pointer_type;
    2958                 :     182843 :   tree non_const_pointer_type;
    2959                 :            :   /* The most significant array bound in int[OUTER_NELTS][inner].  */
    2960                 :     182843 :   tree outer_nelts = NULL_TREE;
    2961                 :            :   /* For arrays with a non-constant number of elements, a bounds checks
    2962                 :            :      on the NELTS parameter to avoid integer overflow at runtime. */
    2963                 :     182843 :   tree outer_nelts_check = NULL_TREE;
    2964                 :     182843 :   bool outer_nelts_from_type = false;
    2965                 :            :   /* Number of the "inner" elements in "new T[OUTER_NELTS][inner]".  */
    2966                 :     182843 :   offset_int inner_nelts_count = 1;
    2967                 :     182843 :   tree alloc_call, alloc_expr;
    2968                 :            :   /* Size of the inner array elements (those with constant dimensions). */
    2969                 :     182843 :   offset_int inner_size;
    2970                 :            :   /* The address returned by the call to "operator new".  This node is
    2971                 :            :      a VAR_DECL and is therefore reusable.  */
    2972                 :     182843 :   tree alloc_node;
    2973                 :     182843 :   tree alloc_fn;
    2974                 :     182843 :   tree cookie_expr, init_expr;
    2975                 :     182843 :   int nothrow, check_new;
    2976                 :            :   /* If non-NULL, the number of extra bytes to allocate at the
    2977                 :            :      beginning of the storage allocated for an array-new expression in
    2978                 :            :      order to store the number of elements.  */
    2979                 :     182843 :   tree cookie_size = NULL_TREE;
    2980                 :     182843 :   tree placement_first;
    2981                 :     182843 :   tree placement_expr = NULL_TREE;
    2982                 :            :   /* True if the function we are calling is a placement allocation
    2983                 :            :      function.  */
    2984                 :     182843 :   bool placement_allocation_fn_p;
    2985                 :            :   /* True if the storage must be initialized, either by a constructor
    2986                 :            :      or due to an explicit new-initializer.  */
    2987                 :     182843 :   bool is_initialized;
    2988                 :            :   /* The address of the thing allocated, not including any cookie.  In
    2989                 :            :      particular, if an array cookie is in use, DATA_ADDR is the
    2990                 :            :      address of the first array element.  This node is a VAR_DECL, and
    2991                 :            :      is therefore reusable.  */
    2992                 :     182843 :   tree data_addr;
    2993                 :     182843 :   tree init_preeval_expr = NULL_TREE;
    2994                 :     182843 :   tree orig_type = type;
    2995                 :            : 
    2996                 :     182843 :   if (nelts)
    2997                 :            :     {
    2998                 :            :       outer_nelts = nelts;
    2999                 :            :       array_p = true;
    3000                 :            :     }
    3001                 :     174207 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    3002                 :            :     {
    3003                 :            :       /* Transforms new (T[N]) to new T[N].  The former is a GNU
    3004                 :            :          extension for variable N.  (This also covers new T where T is
    3005                 :            :          a VLA typedef.)  */
    3006                 :         71 :       array_p = true;
    3007                 :         71 :       nelts = array_type_nelts_top (type);
    3008                 :         71 :       outer_nelts = nelts;
    3009                 :         71 :       type = TREE_TYPE (type);
    3010                 :         71 :       outer_nelts_from_type = true;
    3011                 :            :     }
    3012                 :            : 
    3013                 :            :   /* Lots of logic below depends on whether we have a constant number of
    3014                 :            :      elements, so go ahead and fold it now.  */
    3015                 :     182843 :   const_tree cst_outer_nelts = fold_non_dependent_expr (outer_nelts, complain);
    3016                 :            : 
    3017                 :            :   /* If our base type is an array, then make sure we know how many elements
    3018                 :            :      it has.  */
    3019                 :     184644 :   for (elt_type = type;
    3020                 :     184644 :        TREE_CODE (elt_type) == ARRAY_TYPE;
    3021                 :       1801 :        elt_type = TREE_TYPE (elt_type))
    3022                 :            :     {
    3023                 :       1801 :       tree inner_nelts = array_type_nelts_top (elt_type);
    3024                 :       1801 :       tree inner_nelts_cst = maybe_constant_value (inner_nelts);
    3025                 :       1801 :       if (TREE_CODE (inner_nelts_cst) == INTEGER_CST)
    3026                 :            :         {
    3027                 :       1746 :           wi::overflow_type overflow;
    3028                 :       1746 :           offset_int result = wi::mul (wi::to_offset (inner_nelts_cst),
    3029                 :       1746 :                                        inner_nelts_count, SIGNED, &overflow);
    3030                 :       1746 :           if (overflow)
    3031                 :            :             {
    3032                 :          0 :               if (complain & tf_error)
    3033                 :          0 :                 error ("integer overflow in array size");
    3034                 :          0 :               nelts = error_mark_node;
    3035                 :            :             }
    3036                 :       1746 :           inner_nelts_count = result;
    3037                 :            :         }
    3038                 :            :       else
    3039                 :            :         {
    3040                 :         55 :           if (complain & tf_error)
    3041                 :            :             {
    3042                 :        110 :               error_at (cp_expr_loc_or_input_loc (inner_nelts),
    3043                 :            :                         "array size in new-expression must be constant");
    3044                 :         55 :               cxx_constant_value(inner_nelts);
    3045                 :            :             }
    3046                 :         55 :           nelts = error_mark_node;
    3047                 :            :         }
    3048                 :       1801 :       if (nelts != error_mark_node)
    3049                 :       1746 :         nelts = cp_build_binary_op (input_location,
    3050                 :            :                                     MULT_EXPR, nelts,
    3051                 :            :                                     inner_nelts_cst,
    3052                 :            :                                     complain);
    3053                 :            :     }
    3054                 :            : 
    3055                 :     182843 :   if (!verify_type_context (input_location, TCTX_ALLOCATION, elt_type,
    3056                 :     182843 :                             !(complain & tf_error)))
    3057                 :          0 :     return error_mark_node;
    3058                 :            : 
    3059                 :     182843 :   if (variably_modified_type_p (elt_type, NULL_TREE) && (complain & tf_error))
    3060                 :            :     {
    3061                 :          0 :       error ("variably modified type not allowed in new-expression");
    3062                 :          0 :       return error_mark_node;
    3063                 :            :     }
    3064                 :            : 
    3065                 :     182843 :   if (nelts == error_mark_node)
    3066                 :            :     return error_mark_node;
    3067                 :            : 
    3068                 :            :   /* Warn if we performed the (T[N]) to T[N] transformation and N is
    3069                 :            :      variable.  */
    3070                 :     182788 :   if (outer_nelts_from_type
    3071                 :     182847 :       && !TREE_CONSTANT (cst_outer_nelts))
    3072                 :            :     {
    3073                 :         16 :       if (complain & tf_warning_or_error)
    3074                 :            :         {
    3075                 :         32 :           pedwarn (cp_expr_loc_or_input_loc (outer_nelts), OPT_Wvla,
    3076                 :         16 :                    typedef_variant_p (orig_type)
    3077                 :            :                    ? G_("non-constant array new length must be specified "
    3078                 :            :                         "directly, not by %<typedef%>")
    3079                 :            :                    : G_("non-constant array new length must be specified "
    3080                 :            :                         "without parentheses around the type-id"));
    3081                 :            :         }
    3082                 :            :       else
    3083                 :            :         return error_mark_node;
    3084                 :            :     }
    3085                 :            : 
    3086                 :     182788 :   if (VOID_TYPE_P (elt_type))
    3087                 :            :     {
    3088                 :          0 :       if (complain & tf_error)
    3089                 :          0 :         error ("invalid type %<void%> for %<new%>");
    3090                 :          0 :       return error_mark_node;
    3091                 :            :     }
    3092                 :            : 
    3093                 :     182788 :   if (is_std_init_list (elt_type))
    3094                 :         11 :     warning (OPT_Winit_list_lifetime,
    3095                 :            :              "%<new%> of %<initializer_list%> does not "
    3096                 :            :              "extend the lifetime of the underlying array");
    3097                 :            : 
    3098                 :     182788 :   if (abstract_virtuals_error_sfinae (ACU_NEW, elt_type, complain))
    3099                 :          6 :     return error_mark_node;
    3100                 :            : 
    3101                 :     182782 :   is_initialized = (type_build_ctor_call (elt_type) || *init != NULL);
    3102                 :            : 
    3103                 :     182782 :   if (*init == NULL && cxx_dialect < cxx11)
    3104                 :            :     {
    3105                 :       1942 :       bool maybe_uninitialized_error = false;
    3106                 :            :       /* A program that calls for default-initialization [...] of an
    3107                 :            :          entity of reference type is ill-formed. */
    3108                 :       1942 :       if (CLASSTYPE_REF_FIELDS_NEED_INIT (elt_type))
    3109                 :         13 :         maybe_uninitialized_error = true;
    3110                 :            : 
    3111                 :            :       /* A new-expression that creates an object of type T initializes
    3112                 :            :          that object as follows:
    3113                 :            :       - If the new-initializer is omitted:
    3114                 :            :         -- If T is a (possibly cv-qualified) non-POD class type
    3115                 :            :            (or array thereof), the object is default-initialized (8.5).
    3116                 :            :            [...]
    3117                 :            :         -- Otherwise, the object created has indeterminate
    3118                 :            :            value. If T is a const-qualified type, or a (possibly
    3119                 :            :            cv-qualified) POD class type (or array thereof)
    3120                 :            :            containing (directly or indirectly) a member of
    3121                 :            :            const-qualified type, the program is ill-formed; */
    3122                 :            : 
    3123                 :       1942 :       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (elt_type))
    3124                 :            :         maybe_uninitialized_error = true;
    3125                 :            : 
    3126                 :       1923 :       if (maybe_uninitialized_error
    3127                 :       1942 :           && diagnose_uninitialized_cst_or_ref_member (elt_type,
    3128                 :            :                                                        /*using_new=*/true,
    3129                 :            :                                                        complain & tf_error))
    3130                 :         22 :         return error_mark_node;
    3131                 :            :     }
    3132                 :            : 
    3133                 :     182854 :   if (CP_TYPE_CONST_P (elt_type) && *init == NULL
    3134                 :     182820 :       && default_init_uninitialized_part (elt_type))
    3135                 :            :     {
    3136                 :         52 :       if (complain & tf_error)
    3137                 :         23 :         error ("uninitialized const in %<new%> of %q#T", elt_type);
    3138                 :         52 :       return error_mark_node;
    3139                 :            :     }
    3140                 :            : 
    3141                 :     182708 :   size = size_in_bytes (elt_type);
    3142                 :     182708 :   if (array_p)
    3143                 :            :     {
    3144                 :            :       /* Maximum available size in bytes.  Half of the address space
    3145                 :            :          minus the cookie size.  */
    3146                 :       8641 :       offset_int max_size
    3147                 :       8641 :         = wi::set_bit_in_zero <offset_int> (TYPE_PRECISION (sizetype) - 1);
    3148                 :            :       /* Maximum number of outer elements which can be allocated. */
    3149                 :       8641 :       offset_int max_outer_nelts;
    3150                 :       8641 :       tree max_outer_nelts_tree;
    3151                 :            : 
    3152                 :       8641 :       gcc_assert (TREE_CODE (size) == INTEGER_CST);
    3153                 :       8641 :       cookie_size = targetm.cxx.get_cookie_size (elt_type);
    3154                 :       8641 :       gcc_assert (TREE_CODE (cookie_size) == INTEGER_CST);
    3155                 :       8641 :       gcc_checking_assert (wi::ltu_p (wi::to_offset (cookie_size), max_size));
    3156                 :            :       /* Unconditionally subtract the cookie size.  This decreases the
    3157                 :            :          maximum object size and is safe even if we choose not to use
    3158                 :            :          a cookie after all.  */
    3159                 :       8641 :       max_size -= wi::to_offset (cookie_size);
    3160                 :       8641 :       wi::overflow_type overflow;
    3161                 :       8641 :       inner_size = wi::mul (wi::to_offset (size), inner_nelts_count, SIGNED,
    3162                 :       8641 :                             &overflow);
    3163                 :      17282 :       if (overflow || wi::gtu_p (inner_size, max_size))
    3164                 :            :         {
    3165                 :        184 :           if (complain & tf_error)
    3166                 :            :             {
    3167                 :        184 :               cst_size_error error;
    3168                 :        184 :               if (overflow)
    3169                 :            :                 error = cst_size_overflow;
    3170                 :            :               else
    3171                 :            :                 {
    3172                 :        184 :                   error = cst_size_too_big;
    3173                 :        184 :                   size = size_binop (MULT_EXPR, size,
    3174                 :            :                                      wide_int_to_tree (sizetype,
    3175                 :            :                                                        inner_nelts_count));
    3176                 :        184 :                   size = cp_fully_fold (size);
    3177                 :            :                 }
    3178                 :        184 :               invalid_array_size_error (input_location, error, size,
    3179                 :            :                                         /*name=*/NULL_TREE);
    3180                 :            :             }
    3181                 :        428 :           return error_mark_node;
    3182                 :            :         }
    3183                 :            : 
    3184                 :       8457 :       max_outer_nelts = wi::udiv_trunc (max_size, inner_size);
    3185                 :       8457 :       max_outer_nelts_tree = wide_int_to_tree (sizetype, max_outer_nelts);
    3186                 :            : 
    3187                 :       8457 :       size = size_binop (MULT_EXPR, size, fold_convert (sizetype, nelts));
    3188                 :            : 
    3189                 :       8457 :       if (TREE_CODE (cst_outer_nelts) == INTEGER_CST)
    3190                 :            :         {
    3191                 :       2447 :           if (tree_int_cst_lt (max_outer_nelts_tree, cst_outer_nelts))
    3192                 :            :             {
    3193                 :            :               /* When the array size is constant, check it at compile time
    3194                 :            :                  to make sure it doesn't exceed the implementation-defined
    3195                 :            :                  maximum, as required by C++ 14 (in C++ 11 this requirement
    3196                 :            :                  isn't explicitly stated but it's enforced anyway -- see
    3197                 :            :                  grokdeclarator in cp/decl.c).  */
    3198                 :        244 :               if (complain & tf_error)
    3199                 :            :                 {
    3200                 :        244 :                   size = cp_fully_fold (size);
    3201                 :        244 :                   invalid_array_size_error (input_location, cst_size_too_big,
    3202                 :            :                                             size, NULL_TREE);
    3203                 :            :                 }
    3204                 :        244 :               return error_mark_node;
    3205                 :            :             }
    3206                 :            :         }
    3207                 :            :       else
    3208                 :            :         {
    3209                 :            :           /* When a runtime check is necessary because the array size
    3210                 :            :              isn't constant, keep only the top-most seven bits (starting
    3211                 :            :              with the most significant non-zero bit) of the maximum size
    3212                 :            :              to compare the array size against, to simplify encoding the
    3213                 :            :              constant maximum size in the instruction stream.  */
    3214                 :            : 
    3215                 :       6010 :           unsigned shift = (max_outer_nelts.get_precision ()) - 7
    3216                 :       6010 :             - wi::clz (max_outer_nelts);
    3217                 :       6010 :           max_outer_nelts = (max_outer_nelts >> shift) << shift;
    3218                 :            : 
    3219                 :       6010 :           outer_nelts_check = fold_build2 (LE_EXPR, boolean_type_node,
    3220                 :            :                                            outer_nelts,
    3221                 :            :                                            max_outer_nelts_tree);
    3222                 :            :         }
    3223                 :            :     }
    3224                 :            : 
    3225                 :     182280 :   tree align_arg = NULL_TREE;
    3226                 :     182280 :   if (type_has_new_extended_alignment (elt_type))
    3227                 :         23 :     align_arg = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (elt_type));
    3228                 :            : 
    3229                 :     182280 :   alloc_fn = NULL_TREE;
    3230                 :            : 
    3231                 :            :   /* If PLACEMENT is a single simple pointer type not passed by
    3232                 :            :      reference, prepare to capture it in a temporary variable.  Do
    3233                 :            :      this now, since PLACEMENT will change in the calls below.  */
    3234                 :     182280 :   placement_first = NULL_TREE;
    3235                 :     182280 :   if (vec_safe_length (*placement) == 1
    3236                 :     105979 :       && (TYPE_PTR_P (TREE_TYPE ((**placement)[0]))))
    3237                 :     182280 :     placement_first = (**placement)[0];
    3238                 :            : 
    3239                 :     182280 :   bool member_new_p = false;
    3240                 :            : 
    3241                 :            :   /* Allocate the object.  */
    3242                 :     182280 :   tree fnname;
    3243                 :     182280 :   tree fns;
    3244                 :            : 
    3245                 :     182280 :   fnname = ovl_op_identifier (false, array_p ? VEC_NEW_EXPR : NEW_EXPR);
    3246                 :            : 
    3247                 :     364560 :   member_new_p = !globally_qualified_p
    3248                 :      34607 :                  && CLASS_TYPE_P (elt_type)
    3249                 :     195622 :                  && (array_p
    3250                 :      13342 :                      ? TYPE_HAS_ARRAY_NEW_OPERATOR (elt_type)
    3251                 :      11302 :                      : TYPE_HAS_NEW_OPERATOR (elt_type));
    3252                 :            : 
    3253                 :     182280 :   if (member_new_p)
    3254                 :            :     {
    3255                 :            :       /* Use a class-specific operator new.  */
    3256                 :            :       /* If a cookie is required, add some extra space.  */
    3257                 :        477 :       if (array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type))
    3258                 :         10 :         size = size_binop (PLUS_EXPR, size, cookie_size);
    3259                 :            :       else
    3260                 :            :         {
    3261                 :        467 :           cookie_size = NULL_TREE;
    3262                 :            :           /* No size arithmetic necessary, so the size check is
    3263                 :            :              not needed. */
    3264                 :        467 :           if (outer_nelts_check != NULL && inner_size == 1)
    3265                 :            :             outer_nelts_check = NULL_TREE;
    3266                 :            :         }
    3267                 :            :       /* Perform the overflow check.  */
    3268                 :        477 :       tree errval = TYPE_MAX_VALUE (sizetype);
    3269                 :        477 :       if (cxx_dialect >= cxx11 && flag_exceptions)
    3270                 :        355 :         errval = throw_bad_array_new_length ();
    3271                 :        477 :       if (outer_nelts_check != NULL_TREE)
    3272                 :          7 :         size = fold_build3 (COND_EXPR, sizetype, outer_nelts_check,
    3273                 :            :                             size, errval);
    3274                 :            :       /* Create the argument list.  */
    3275                 :        477 :       vec_safe_insert (*placement, 0, size);
    3276                 :            :       /* Do name-lookup to find the appropriate operator.  */
    3277                 :        477 :       fns = lookup_fnfields (elt_type, fnname, /*protect=*/2);
    3278                 :        477 :       if (fns == NULL_TREE)
    3279                 :            :         {
    3280                 :          0 :           if (complain & tf_error)
    3281                 :          0 :             error ("no suitable %qD found in class %qT", fnname, elt_type);
    3282                 :          0 :           return error_mark_node;
    3283                 :            :         }
    3284                 :        477 :       if (TREE_CODE (fns) == TREE_LIST)
    3285                 :            :         {
    3286                 :          4 :           if (complain & tf_error)
    3287                 :            :             {
    3288                 :          4 :               error ("request for member %qD is ambiguous", fnname);
    3289                 :          4 :               print_candidates (fns);
    3290                 :            :             }
    3291                 :          4 :           return error_mark_node;
    3292                 :            :         }
    3293                 :        473 :       tree dummy = build_dummy_object (elt_type);
    3294                 :        473 :       alloc_call = NULL_TREE;
    3295                 :        473 :       if (align_arg)
    3296                 :            :         {
    3297                 :          0 :           vec<tree, va_gc> *align_args
    3298                 :          0 :             = vec_copy_and_insert (*placement, align_arg, 1);
    3299                 :          0 :           alloc_call
    3300                 :          0 :             = build_new_method_call (dummy, fns, &align_args,
    3301                 :            :                                      /*conversion_path=*/NULL_TREE,
    3302                 :            :                                      LOOKUP_NORMAL, &alloc_fn, tf_none);
    3303                 :            :           /* If no matching function is found and the allocated object type
    3304                 :            :              has new-extended alignment, the alignment argument is removed
    3305                 :            :              from the argument list, and overload resolution is performed
    3306                 :            :              again.  */
    3307                 :          0 :           if (alloc_call == error_mark_node)
    3308                 :          0 :             alloc_call = NULL_TREE;
    3309                 :            :         }
    3310                 :          0 :       if (!alloc_call)
    3311                 :        473 :         alloc_call = build_new_method_call (dummy, fns, placement,
    3312                 :            :                                             /*conversion_path=*/NULL_TREE,
    3313                 :            :                                             LOOKUP_NORMAL,
    3314                 :            :                                             &alloc_fn, complain);
    3315                 :            :     }
    3316                 :            :   else
    3317                 :            :     {
    3318                 :            :       /* Use a global operator new.  */
    3319                 :            :       /* See if a cookie might be required.  */
    3320                 :     183607 :       if (!(array_p && TYPE_VEC_NEW_USES_COOKIE (elt_type)))
    3321                 :            :         {
    3322                 :     181586 :           cookie_size = NULL_TREE;
    3323                 :            :           /* No size arithmetic necessary, so the size check is
    3324                 :            :              not needed. */
    3325                 :     181586 :           if (outer_nelts_check != NULL && inner_size == 1)
    3326                 :            :             outer_nelts_check = NULL_TREE;
    3327                 :            :         }
    3328                 :            : 
    3329                 :     181803 :       alloc_call = build_operator_new_call (fnname, placement,
    3330                 :            :                                             &size, &cookie_size,
    3331                 :            :                                             align_arg, outer_nelts_check,
    3332                 :            :                                             &alloc_fn, complain);
    3333                 :            :     }
    3334                 :            : 
    3335                 :     182276 :   if (alloc_call == error_mark_node)
    3336                 :            :     return error_mark_node;
    3337                 :            : 
    3338                 :     182260 :   gcc_assert (alloc_fn != NULL_TREE);
    3339                 :            : 
    3340                 :            :   /* Now, check to see if this function is actually a placement
    3341                 :            :      allocation function.  This can happen even when PLACEMENT is NULL
    3342                 :            :      because we might have something like:
    3343                 :            : 
    3344                 :            :        struct S { void* operator new (size_t, int i = 0); };
    3345                 :            : 
    3346                 :            :      A call to `new S' will get this allocation function, even though
    3347                 :            :      there is no explicit placement argument.  If there is more than
    3348                 :            :      one argument, or there are variable arguments, then this is a
    3349                 :            :      placement allocation function.  */
    3350                 :     182260 :   placement_allocation_fn_p
    3351                 :     182260 :     = (type_num_arguments (TREE_TYPE (alloc_fn)) > 1
    3352                 :     182260 :        || varargs_function_p (alloc_fn));
    3353                 :            : 
    3354                 :     182260 :   if (warn_aligned_new
    3355                 :       3092 :       && !placement_allocation_fn_p
    3356                 :       2034 :       && TYPE_ALIGN (elt_type) > malloc_alignment ()
    3357                 :         18 :       && (warn_aligned_new > 1
    3358                 :         16 :           || CP_DECL_CONTEXT (alloc_fn) == global_namespace)
    3359                 :     182269 :       && !aligned_allocation_fn_p (alloc_fn))
    3360                 :            :     {
    3361                 :         18 :       auto_diagnostic_group d;
    3362                 :         18 :       if (warning (OPT_Waligned_new_, "%<new%> of type %qT with extended "
    3363                 :          9 :                    "alignment %d", elt_type, TYPE_ALIGN_UNIT (elt_type)))
    3364                 :            :         {
    3365                 :          3 :           inform (input_location, "uses %qD, which does not have an alignment "
    3366                 :            :                   "parameter", alloc_fn);
    3367                 :          3 :           if (!aligned_new_threshold)
    3368                 :          3 :             inform (input_location, "use %<-faligned-new%> to enable C++17 "
    3369                 :            :                                     "over-aligned new support");
    3370                 :            :         }
    3371                 :            :     }
    3372                 :            : 
    3373                 :            :   /* If we found a simple case of PLACEMENT_EXPR above, then copy it
    3374                 :            :      into a temporary variable.  */
    3375                 :     182260 :   if (!processing_template_decl
    3376                 :     174791 :       && TREE_CODE (alloc_call) == CALL_EXPR
    3377                 :     174791 :       && call_expr_nargs (alloc_call) == 2
    3378                 :     105952 :       && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (alloc_call, 0))) == INTEGER_TYPE
    3379                 :     288212 :       && TYPE_PTR_P (TREE_TYPE (CALL_EXPR_ARG (alloc_call, 1))))
    3380                 :            :     {
    3381                 :     105678 :       tree placement = CALL_EXPR_ARG (alloc_call, 1);
    3382                 :            : 
    3383                 :     105678 :       if (placement_first != NULL_TREE
    3384                 :     210344 :           && (INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (TREE_TYPE (placement)))
    3385                 :     104650 :               || VOID_TYPE_P (TREE_TYPE (TREE_TYPE (placement)))))
    3386                 :            :         {
    3387                 :     104634 :           placement_expr = get_target_expr (placement_first);
    3388                 :     209268 :           CALL_EXPR_ARG (alloc_call, 1)
    3389                 :     209268 :             = fold_convert (TREE_TYPE (placement), placement_expr);
    3390                 :            :         }
    3391                 :            : 
    3392                 :     105678 :       if (!member_new_p
    3393                 :     211094 :           && VOID_TYPE_P (TREE_TYPE (TREE_TYPE (CALL_EXPR_ARG (alloc_call, 1)))))
    3394                 :            :         {
    3395                 :            :           /* Attempt to make the warning point at the operator new argument.  */
    3396                 :     105380 :           if (placement_first)
    3397                 :     104382 :             placement = placement_first;
    3398                 :            : 
    3399                 :     105380 :           warn_placement_new_too_small (orig_type, nelts, size, placement);
    3400                 :            :         }
    3401                 :            :     }
    3402                 :            : 
    3403                 :     182260 :   tree alloc_call_expr = extract_call_expr (alloc_call);
    3404                 :     182260 :   if (TREE_CODE (alloc_call_expr) == CALL_EXPR)
    3405                 :     182260 :     CALL_FROM_NEW_OR_DELETE_P (alloc_call_expr) = 1;
    3406                 :            : 
    3407                 :     182260 :   if (cookie_size)
    3408                 :        215 :     alloc_call = maybe_wrap_new_for_constexpr (alloc_call, elt_type,
    3409                 :            :                                                cookie_size);
    3410                 :            : 
    3411                 :            :   /* In the simple case, we can stop now.  */
    3412                 :     182260 :   pointer_type = build_pointer_type (type);
    3413                 :     182260 :   if (!cookie_size && !is_initialized)
    3414                 :      36962 :     return build_nop (pointer_type, alloc_call);
    3415                 :            : 
    3416                 :            :   /* Store the result of the allocation call in a variable so that we can
    3417                 :            :      use it more than once.  */
    3418                 :     145298 :   alloc_expr = get_target_expr (alloc_call);
    3419                 :     145298 :   alloc_node = TARGET_EXPR_SLOT (alloc_expr);
    3420                 :            : 
    3421                 :            :   /* Strip any COMPOUND_EXPRs from ALLOC_CALL.  */
    3422                 :     145298 :   while (TREE_CODE (alloc_call) == COMPOUND_EXPR)
    3423                 :          0 :     alloc_call = TREE_OPERAND (alloc_call, 1);
    3424                 :            : 
    3425                 :            :   /* Preevaluate the placement args so that we don't reevaluate them for a
    3426                 :            :      placement delete.  */
    3427                 :     145298 :   if (placement_allocation_fn_p)
    3428                 :            :     {
    3429                 :     103552 :       tree inits;
    3430                 :     103552 :       stabilize_call (alloc_call, &inits);
    3431                 :     103552 :       if (inits)
    3432                 :     103011 :         alloc_expr = build2 (COMPOUND_EXPR, TREE_TYPE (alloc_expr), inits,
    3433                 :            :                              alloc_expr);
    3434                 :            :     }
    3435                 :            : 
    3436                 :            :   /*        unless an allocation function is declared with an empty  excep-
    3437                 :            :      tion-specification  (_except.spec_),  throw(), it indicates failure to
    3438                 :            :      allocate storage by throwing a bad_alloc exception  (clause  _except_,
    3439                 :            :      _lib.bad.alloc_); it returns a non-null pointer otherwise If the allo-
    3440                 :            :      cation function is declared  with  an  empty  exception-specification,
    3441                 :            :      throw(), it returns null to indicate failure to allocate storage and a
    3442                 :            :      non-null pointer otherwise.
    3443                 :            : 
    3444                 :            :      So check for a null exception spec on the op new we just called.  */
    3445                 :            : 
    3446                 :     145298 :   nothrow = TYPE_NOTHROW_P (TREE_TYPE (alloc_fn));
    3447                 :     145298 :   check_new
    3448                 :     145298 :     = flag_check_new || (nothrow && !std_placement_new_fn_p (alloc_fn));
    3449                 :            : 
    3450                 :     145298 :   if (cookie_size)
    3451                 :            :     {
    3452                 :        215 :       tree cookie;
    3453                 :        215 :       tree cookie_ptr;
    3454                 :        215 :       tree size_ptr_type;
    3455                 :            : 
    3456                 :            :       /* Adjust so we're pointing to the start of the object.  */
    3457                 :        215 :       data_addr = fold_build_pointer_plus (alloc_node, cookie_size);
    3458                 :            : 
    3459                 :            :       /* Store the number of bytes allocated so that we can know how
    3460                 :            :          many elements to destroy later.  We use the last sizeof
    3461                 :            :          (size_t) bytes to store the number of elements.  */
    3462                 :        215 :       cookie_ptr = size_binop (MINUS_EXPR, cookie_size, size_in_bytes (sizetype));
    3463                 :        215 :       cookie_ptr = fold_build_pointer_plus_loc (input_location,
    3464                 :            :                                                 alloc_node, cookie_ptr);
    3465                 :        215 :       size_ptr_type = build_pointer_type (sizetype);
    3466                 :        215 :       cookie_ptr = fold_convert (size_ptr_type, cookie_ptr);
    3467                 :        215 :       cookie = cp_build_fold_indirect_ref (cookie_ptr);
    3468                 :            : 
    3469                 :        215 :       cookie_expr = build2 (MODIFY_EXPR, sizetype, cookie, nelts);
    3470                 :            : 
    3471                 :        215 :       if (targetm.cxx.cookie_has_size ())
    3472                 :            :         {
    3473                 :            :           /* Also store the element size.  */
    3474                 :          0 :           cookie_ptr = fold_build_pointer_plus (cookie_ptr,
    3475                 :            :                                fold_build1_loc (input_location,
    3476                 :            :                                                 NEGATE_EXPR, sizetype,
    3477                 :            :                                                 size_in_bytes (sizetype)));
    3478                 :            : 
    3479                 :          0 :           cookie = cp_build_fold_indirect_ref (cookie_ptr);
    3480                 :          0 :           cookie = build2 (MODIFY_EXPR, sizetype, cookie,
    3481                 :            :                            size_in_bytes (elt_type));
    3482                 :          0 :           cookie_expr = build2 (COMPOUND_EXPR, TREE_TYPE (cookie_expr),
    3483                 :            :                                 cookie, cookie_expr);
    3484                 :            :         }
    3485                 :            :     }
    3486                 :            :   else
    3487                 :            :     {
    3488                 :            :       cookie_expr = NULL_TREE;
    3489                 :            :       data_addr = alloc_node;
    3490                 :            :     }
    3491                 :            : 
    3492                 :            :   /* Now use a pointer to the type we've actually allocated.  */
    3493                 :            : 
    3494                 :            :   /* But we want to operate on a non-const version to start with,
    3495                 :            :      since we'll be modifying the elements.  */
    3496                 :     145298 :   non_const_pointer_type = build_pointer_type
    3497                 :     145298 :     (cp_build_qualified_type (type, cp_type_quals (type) & ~TYPE_QUAL_CONST));
    3498                 :            : 
    3499                 :     145298 :   data_addr = fold_convert (non_const_pointer_type, data_addr);
    3500                 :            :   /* Any further uses of alloc_node will want this type, too.  */
    3501                 :     145298 :   alloc_node = fold_convert (non_const_pointer_type, alloc_node);
    3502                 :            : 
    3503                 :            :   /* Now initialize the allocated object.  Note that we preevaluate the
    3504                 :            :      initialization expression, apart from the actual constructor call or
    3505                 :            :      assignment--we do this because we want to delay the allocation as long
    3506                 :            :      as possible in order to minimize the size of the exception region for
    3507                 :            :      placement delete.  */
    3508                 :     145298 :   if (is_initialized)
    3509                 :            :     {
    3510                 :     145273 :       bool stable;
    3511                 :     145273 :       bool explicit_value_init_p = false;
    3512                 :            : 
    3513                 :     145273 :       if (*init != NULL && (*init)->is_empty ())
    3514                 :            :         {
    3515                 :      39551 :           *init = NULL;
    3516                 :      39551 :           explicit_value_init_p = true;
    3517                 :            :         }
    3518                 :            : 
    3519                 :     145273 :       if (processing_template_decl)
    3520                 :            :         {
    3521                 :            :           /* Avoid an ICE when converting to a base in build_simple_base_path.
    3522                 :            :              We'll throw this all away anyway, and build_new will create
    3523                 :            :              a NEW_EXPR.  */
    3524                 :       3998 :           tree t = fold_convert (build_pointer_type (elt_type), data_addr);
    3525                 :            :           /* build_value_init doesn't work in templates, and we don't need
    3526                 :            :              the initializer anyway since we're going to throw it away and
    3527                 :            :              rebuild it at instantiation time, so just build up a single
    3528                 :            :              constructor call to get any appropriate diagnostics.  */
    3529                 :       3998 :           init_expr = cp_build_fold_indirect_ref (t);
    3530                 :       3998 :           if (type_build_ctor_call (elt_type))
    3531                 :       3957 :             init_expr = build_special_member_call (init_expr,
    3532                 :            :                                                    complete_ctor_identifier,
    3533                 :            :                                                    init, elt_type,
    3534                 :            :                                                    LOOKUP_NORMAL,
    3535                 :            :                                                    complain);
    3536                 :       3998 :           stable = stabilize_init (init_expr, &init_preeval_expr);
    3537                 :            :         }
    3538                 :     141275 :       else if (array_p)
    3539                 :            :         {
    3540                 :        595 :           tree vecinit = NULL_TREE;
    3541                 :        595 :           if (vec_safe_length (*init) == 1
    3542                 :         56 :               && DIRECT_LIST_INIT_P ((**init)[0]))
    3543                 :            :             {
    3544                 :         40 :               vecinit = (**init)[0];
    3545                 :         40 :               if (CONSTRUCTOR_NELTS (vecinit) == 0)
    3546                 :            :                 /* List-value-initialization, leave it alone.  */;
    3547                 :            :               else
    3548                 :            :                 {
    3549                 :         31 :                   tree arraytype, domain;
    3550                 :         31 :                   if (TREE_CONSTANT (nelts))
    3551                 :         28 :                     domain = compute_array_index_type (NULL_TREE, nelts,
    3552                 :            :                                                        complain);
    3553                 :            :                   else
    3554                 :            :                     /* We'll check the length at runtime.  */
    3555                 :            :                     domain = NULL_TREE;
    3556                 :         31 :                   arraytype = build_cplus_array_type (type, domain);
    3557                 :         31 :                   vecinit = digest_init (arraytype, vecinit, complain);
    3558                 :            :                 }
    3559                 :            :             }
    3560                 :        555 :           else if (*init)
    3561                 :            :             {
    3562                 :         16 :               if (complain & tf_error)
    3563                 :         16 :                 error ("parenthesized initializer in array new");
    3564                 :         16 :               return error_mark_node;
    3565                 :            :             }
    3566                 :        579 :           init_expr
    3567                 :        579 :             = build_vec_init (data_addr,
    3568                 :            :                               cp_build_binary_op (input_location,
    3569                 :            :                                                   MINUS_EXPR, outer_nelts,
    3570                 :            :                                                   integer_one_node,
    3571                 :            :                                                   complain),
    3572                 :            :                               vecinit,
    3573                 :            :                               explicit_value_init_p,
    3574                 :            :                               /*from_array=*/0,
    3575                 :            :                               complain);
    3576                 :            : 
    3577                 :            :           /* An array initialization is stable because the initialization
    3578                 :            :              of each element is a full-expression, so the temporaries don't
    3579                 :            :              leak out.  */
    3580                 :        579 :           stable = true;
    3581                 :            :         }
    3582                 :            :       else
    3583                 :            :         {
    3584                 :     140680 :           init_expr = cp_build_fold_indirect_ref (data_addr);
    3585                 :            : 
    3586                 :     140680 :           if (type_build_ctor_call (type) && !explicit_value_init_p)
    3587                 :            :             {
    3588                 :      71498 :               init_expr = build_special_member_call (init_expr,
    3589                 :            :                                                      complete_ctor_identifier,
    3590                 :            :                                                      init, elt_type,
    3591                 :            :                                                      LOOKUP_NORMAL,
    3592                 :            :                                                      complain|tf_no_cleanup);
    3593                 :            :             }
    3594                 :      69182 :           else if (explicit_value_init_p)
    3595                 :            :             {
    3596                 :            :               /* Something like `new int()'.  NO_CLEANUP is needed so
    3597                 :            :                  we don't try and build a (possibly ill-formed)
    3598                 :            :                  destructor.  */
    3599                 :      39319 :               tree val = build_value_init (type, complain | tf_no_cleanup);
    3600                 :      39319 :               if (val == error_mark_node)
    3601                 :         24 :                 return error_mark_node;
    3602                 :      39295 :               init_expr = build2 (INIT_EXPR, type, init_expr, val);
    3603                 :            :             }
    3604                 :            :           else
    3605                 :            :             {
    3606                 :      29863 :               tree ie;
    3607                 :            : 
    3608                 :            :               /* We are processing something like `new int (10)', which
    3609                 :            :                  means allocate an int, and initialize it with 10.
    3610                 :            : 
    3611                 :            :                  In C++20, also handle `new A(1, 2)'.  */
    3612                 :      29863 :               if (cxx_dialect >= cxx2a
    3613                 :        287 :                   && AGGREGATE_TYPE_P (type)
    3614                 :      29934 :                   && (*init)->length () > 1)
    3615                 :            :                 {
    3616                 :          4 :                   ie = build_tree_list_vec (*init);
    3617                 :          4 :                   ie = build_constructor_from_list (init_list_type_node, ie);
    3618                 :          4 :                   CONSTRUCTOR_IS_DIRECT_INIT (ie) = true;
    3619                 :          4 :                   CONSTRUCTOR_IS_PAREN_INIT (ie) = true;
    3620                 :          4 :                   ie = digest_init (type, ie, complain);
    3621                 :            :                 }
    3622                 :            :               else
    3623                 :      29859 :                 ie = build_x_compound_expr_from_vec (*init, "new initializer",
    3624                 :            :                                                      complain);
    3625                 :      29863 :               init_expr = cp_build_modify_expr (input_location, init_expr,
    3626                 :            :                                                 INIT_EXPR, ie, complain);
    3627                 :            :             }
    3628                 :            :           /* If the initializer uses C++14 aggregate NSDMI that refer to the
    3629                 :            :              object being initialized, replace them now and don't try to
    3630                 :            :              preevaluate.  */
    3631                 :     140656 :           bool had_placeholder = false;
    3632                 :     140656 :           if (!processing_template_decl
    3633                 :     140656 :               && TREE_CODE (init_expr) == INIT_EXPR)
    3634                 :     147930 :             TREE_OPERAND (init_expr, 1)
    3635                 :      73965 :               = replace_placeholders (TREE_OPERAND (init_expr, 1),
    3636                 :      73965 :                                       TREE_OPERAND (init_expr, 0),
    3637                 :            :                                       &had_placeholder);
    3638                 :     140656 :           stable = (!had_placeholder
    3639                 :     140656 :                     && stabilize_init (init_expr, &init_preeval_expr));
    3640                 :            :         }
    3641                 :            : 
    3642                 :     145233 :       if (init_expr == error_mark_node)
    3643                 :            :         return error_mark_node;
    3644                 :            : 
    3645                 :            :       /* If any part of the object initialization terminates by throwing an
    3646                 :            :          exception and a suitable deallocation function can be found, the
    3647                 :            :          deallocation function is called to free the memory in which the
    3648                 :            :          object was being constructed, after which the exception continues
    3649                 :            :          to propagate in the context of the new-expression. If no
    3650                 :            :          unambiguous matching deallocation function can be found,
    3651                 :            :          propagating the exception does not cause the object's memory to be
    3652                 :            :          freed.  */
    3653                 :     145072 :       if (flag_exceptions)
    3654                 :            :         {
    3655                 :     144638 :           enum tree_code dcode = array_p ? VEC_DELETE_EXPR : DELETE_EXPR;
    3656                 :     144638 :           tree cleanup;
    3657                 :            : 
    3658                 :            :           /* The Standard is unclear here, but the right thing to do
    3659                 :            :              is to use the same method for finding deallocation
    3660                 :            :              functions that we use for finding allocation functions.  */
    3661                 :     144638 :           cleanup = (build_op_delete_call
    3662                 :     247849 :                      (dcode,
    3663                 :            :                       alloc_node,
    3664                 :            :                       size,
    3665                 :            :                       globally_qualified_p,
    3666                 :            :                       placement_allocation_fn_p ? alloc_call : NULL_TREE,
    3667                 :            :                       alloc_fn,
    3668                 :            :                       complain));
    3669                 :            : 
    3670                 :     144638 :           if (!cleanup)
    3671                 :            :             /* We're done.  */;
    3672                 :     144099 :           else if (stable)
    3673                 :            :             /* This is much simpler if we were able to preevaluate all of
    3674                 :            :                the arguments to the constructor call.  */
    3675                 :            :             {
    3676                 :            :               /* CLEANUP is compiler-generated, so no diagnostics.  */
    3677                 :     144087 :               TREE_NO_WARNING (cleanup) = true;
    3678                 :     144087 :               init_expr = build2 (TRY_CATCH_EXPR, void_type_node,
    3679                 :            :                                   init_expr, cleanup);
    3680                 :            :               /* Likewise, this try-catch is compiler-generated.  */
    3681                 :     144087 :               TREE_NO_WARNING (init_expr) = true;
    3682                 :            :             }
    3683                 :            :           else
    3684                 :            :             /* Ack!  First we allocate the memory.  Then we set our sentry
    3685                 :            :                variable to true, and expand a cleanup that deletes the
    3686                 :            :                memory if sentry is true.  Then we run the constructor, and
    3687                 :            :                finally clear the sentry.
    3688                 :            : 
    3689                 :            :                We need to do this because we allocate the space first, so
    3690                 :            :                if there are any temporaries with cleanups in the
    3691                 :            :                constructor args and we weren't able to preevaluate them, we
    3692                 :            :                need this EH region to extend until end of full-expression
    3693                 :            :                to preserve nesting.  */
    3694                 :            :             {
    3695                 :         12 :               tree end, sentry, begin;
    3696                 :            : 
    3697                 :         12 :               begin = get_target_expr (boolean_true_node);
    3698                 :         12 :               CLEANUP_EH_ONLY (begin) = 1;
    3699                 :            : 
    3700                 :         12 :               sentry = TARGET_EXPR_SLOT (begin);
    3701                 :            : 
    3702                 :            :               /* CLEANUP is compiler-generated, so no diagnostics.  */
    3703                 :         12 :               TREE_NO_WARNING (cleanup) = true;
    3704                 :            : 
    3705                 :         12 :               TARGET_EXPR_CLEANUP (begin)
    3706                 :         12 :                 = build3 (COND_EXPR, void_type_node, sentry,
    3707                 :            :                           cleanup, void_node);
    3708                 :            : 
    3709                 :         12 :               end = build2 (MODIFY_EXPR, TREE_TYPE (sentry),
    3710                 :            :                             sentry, boolean_false_node);
    3711                 :            : 
    3712                 :         12 :               init_expr
    3713                 :         12 :                 = build2 (COMPOUND_EXPR, void_type_node, begin,
    3714                 :            :                           build2 (COMPOUND_EXPR, void_type_node, init_expr,
    3715                 :            :                                   end));
    3716                 :            :               /* Likewise, this is compiler-generated.  */
    3717                 :         12 :               TREE_NO_WARNING (init_expr) = true;
    3718                 :            :             }
    3719                 :            :         }
    3720                 :            :     }
    3721                 :            :   else
    3722                 :            :     init_expr = NULL_TREE;
    3723                 :            : 
    3724                 :            :   /* Now build up the return value in reverse order.  */
    3725                 :            : 
    3726                 :     145072 :   rval = data_addr;
    3727                 :            : 
    3728                 :     145072 :   if (init_expr)
    3729                 :     145072 :     rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), init_expr, rval);
    3730                 :     145097 :   if (cookie_expr)
    3731                 :        215 :     rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval);
    3732                 :            : 
    3733                 :     145097 :   if (rval == data_addr)
    3734                 :            :     /* If we don't have an initializer or a cookie, strip the TARGET_EXPR
    3735                 :            :        and return the call (which doesn't need to be adjusted).  */
    3736                 :          0 :     rval = TARGET_EXPR_INITIAL (alloc_expr);
    3737                 :            :   else
    3738                 :            :     {
    3739                 :     145097 :       if (check_new)
    3740                 :            :         {
    3741                 :         80 :           tree ifexp = cp_build_binary_op (input_location,
    3742                 :            :                                            NE_EXPR, alloc_node,
    3743                 :            :                                            nullptr_node,
    3744                 :            :                                            complain);
    3745                 :         80 :           rval = build_conditional_expr (input_location, ifexp, rval,
    3746                 :            :                                          alloc_node, complain);
    3747                 :            :         }
    3748                 :            : 
    3749                 :            :       /* Perform the allocation before anything else, so that ALLOC_NODE
    3750                 :            :          has been initialized before we start using it.  */
    3751                 :     145097 :       rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
    3752                 :            :     }
    3753                 :            : 
    3754                 :     145097 :   if (init_preeval_expr)
    3755                 :      57569 :     rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), init_preeval_expr, rval);
    3756                 :            : 
    3757                 :            :   /* A new-expression is never an lvalue.  */
    3758                 :     145097 :   gcc_assert (!obvalue_p (rval));
    3759                 :            : 
    3760                 :     145097 :   return convert (pointer_type, rval);
    3761                 :            : }
    3762                 :            : 
    3763                 :            : /* Generate a representation for a C++ "new" expression.  *PLACEMENT
    3764                 :            :    is a vector of placement-new arguments (or NULL if none).  If NELTS
    3765                 :            :    is NULL, TYPE is the type of the storage to be allocated.  If NELTS
    3766                 :            :    is not NULL, then this is an array-new allocation; TYPE is the type
    3767                 :            :    of the elements in the array and NELTS is the number of elements in
    3768                 :            :    the array.  *INIT, if non-NULL, is the initializer for the new
    3769                 :            :    object, or an empty vector to indicate an initializer of "()".  If
    3770                 :            :    USE_GLOBAL_NEW is true, then the user explicitly wrote "::new"
    3771                 :            :    rather than just "new".  This may change PLACEMENT and INIT.  */
    3772                 :            : 
    3773                 :            : tree
    3774                 :     244962 : build_new (location_t loc, vec<tree, va_gc> **placement, tree type,
    3775                 :            :            tree nelts, vec<tree, va_gc> **init, int use_global_new,
    3776                 :            :            tsubst_flags_t complain)
    3777                 :            : {
    3778                 :     244962 :   tree rval;
    3779                 :     244962 :   vec<tree, va_gc> *orig_placement = NULL;
    3780                 :     244962 :   tree orig_nelts = NULL_TREE;
    3781                 :     244962 :   vec<tree, va_gc> *orig_init = NULL;
    3782                 :            : 
    3783                 :     244962 :   if (type == error_mark_node)
    3784                 :            :     return error_mark_node;
    3785                 :            : 
    3786                 :     244688 :   if (nelts == NULL_TREE
    3787                 :            :       /* Don't do auto deduction where it might affect mangling.  */
    3788                 :     244688 :       && (!processing_template_decl || at_function_scope_p ()))
    3789                 :            :     {
    3790                 :     215351 :       tree auto_node = type_uses_auto (type);
    3791                 :     215351 :       if (auto_node)
    3792                 :            :         {
    3793                 :         46 :           tree d_init = NULL_TREE;
    3794                 :         46 :           const size_t len = vec_safe_length (*init);
    3795                 :            :           /* E.g. new auto(x) must have exactly one element, or
    3796                 :            :              a {} initializer will have one element.  */
    3797                 :         46 :           if (len == 1)
    3798                 :            :             {
    3799                 :         37 :               d_init = (**init)[0];
    3800                 :         37 :               d_init = resolve_nondeduced_context (d_init, complain);
    3801                 :            :             }
    3802                 :            :           /* For the rest, e.g. new A(1, 2, 3), create a list.  */
    3803                 :          9 :           else if (len > 1)
    3804                 :            :             {
    3805                 :            :               unsigned int n;
    3806                 :            :               tree t;
    3807                 :            :               tree *pp = &d_init;
    3808                 :         14 :               FOR_EACH_VEC_ELT (**init, n, t)
    3809                 :            :                 {
    3810                 :         10 :                   t = resolve_nondeduced_context (t, complain);
    3811                 :         10 :                   *pp = build_tree_list (NULL_TREE, t);
    3812                 :         10 :                   pp = &TREE_CHAIN (*pp);
    3813                 :            :                 }
    3814                 :            :             }
    3815                 :         46 :           type = do_auto_deduction (type, d_init, auto_node, complain);
    3816                 :            :         }
    3817                 :            :     }
    3818                 :            : 
    3819                 :     244688 :   if (processing_template_decl)
    3820                 :            :     {
    3821                 :      68785 :       if (dependent_type_p (type)
    3822                 :       7930 :           || any_type_dependent_arguments_p (*placement)
    3823                 :       7930 :           || (nelts && type_dependent_expression_p (nelts))
    3824                 :       7588 :           || (nelts && *init)
    3825                 :      76315 :           || any_type_dependent_arguments_p (*init))
    3826                 :      61308 :         return build_raw_new_expr (loc, *placement, type, nelts, *init,
    3827                 :      61308 :                                    use_global_new);
    3828                 :            : 
    3829                 :       7477 :       orig_placement = make_tree_vector_copy (*placement);
    3830                 :       7477 :       orig_nelts = nelts;
    3831                 :       7477 :       if (*init)
    3832                 :            :         {
    3833                 :       3041 :           orig_init = make_tree_vector_copy (*init);
    3834                 :            :           /* Also copy any CONSTRUCTORs in *init, since reshape_init and
    3835                 :            :              digest_init clobber them in place.  */
    3836                 :       9003 :           for (unsigned i = 0; i < orig_init->length(); ++i)
    3837                 :            :             {
    3838                 :       5962 :               tree e = (**init)[i];
    3839                 :       5962 :               if (TREE_CODE (e) == CONSTRUCTOR)
    3840                 :         21 :                 (**init)[i] = copy_node (e);
    3841                 :            :             }
    3842                 :            :         }
    3843                 :            : 
    3844                 :       7477 :       make_args_non_dependent (*placement);
    3845                 :       7477 :       if (nelts)
    3846                 :       4389 :         nelts = build_non_dependent_expr (nelts);
    3847                 :       7477 :       make_args_non_dependent (*init);
    3848                 :            :     }
    3849                 :            : 
    3850                 :     183380 :   if (nelts)
    3851                 :            :     {
    3852                 :       9044 :       location_t nelts_loc = cp_expr_loc_or_loc (nelts, loc);
    3853                 :       9044 :       if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false))
    3854                 :            :         {
    3855                 :         12 :           if (complain & tf_error)
    3856                 :          8 :             permerror (nelts_loc,
    3857                 :            :                        "size in array new must have integral type");
    3858                 :            :           else
    3859                 :          4 :             return error_mark_node;
    3860                 :            :         }
    3861                 :            : 
    3862                 :            :       /* Try to determine the constant value only for the purposes
    3863                 :            :          of the diagnostic below but continue to use the original
    3864                 :            :          value and handle const folding later.  */
    3865                 :       9040 :       const_tree cst_nelts = fold_non_dependent_expr (nelts, complain);
    3866                 :            : 
    3867                 :            :       /* The expression in a noptr-new-declarator is erroneous if it's of
    3868                 :            :          non-class type and its value before converting to std::size_t is
    3869                 :            :          less than zero. ... If the expression is a constant expression,
    3870                 :            :          the program is ill-fomed.  */
    3871                 :       9040 :       if (TREE_CODE (cst_nelts) == INTEGER_CST
    3872                 :       9040 :           && !valid_array_size_p (nelts_loc, cst_nelts, NULL_TREE,
    3873                 :            :                                   complain & tf_error))
    3874                 :        404 :         return error_mark_node;
    3875                 :            : 
    3876                 :       8636 :       nelts = mark_rvalue_use (nelts);
    3877                 :       8636 :       nelts = cp_save_expr (cp_convert (sizetype, nelts, complain));
    3878                 :            :     }
    3879                 :            : 
    3880                 :            :   /* ``A reference cannot be created by the new operator.  A reference
    3881                 :            :      is not an object (8.2.2, 8.4.3), so a pointer to it could not be
    3882                 :            :      returned by new.'' ARM 5.3.3 */
    3883                 :     182972 :   if (TYPE_REF_P (type))
    3884                 :            :     {
    3885                 :         64 :       if (complain & tf_error)
    3886                 :         16 :         error_at (loc, "new cannot be applied to a reference type");
    3887                 :            :       else
    3888                 :         48 :         return error_mark_node;
    3889                 :         16 :       type = TREE_TYPE (type);
    3890                 :            :     }
    3891                 :            : 
    3892                 :     182924 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    3893                 :            :     {
    3894                 :         22 :       if (complain & tf_error)
    3895                 :          4 :         error_at (loc, "new cannot be applied to a function type");
    3896                 :         22 :       return error_mark_node;
    3897                 :            :     }
    3898                 :            : 
    3899                 :            :   /* The type allocated must be complete.  If the new-type-id was
    3900                 :            :      "T[N]" then we are just checking that "T" is complete here, but
    3901                 :            :      that is equivalent, since the value of "N" doesn't matter.  */
    3902                 :     182902 :   if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
    3903                 :         59 :     return error_mark_node;
    3904                 :            : 
    3905                 :     182843 :   rval = build_new_1 (placement, type, nelts, init, use_global_new, complain);
    3906                 :     182843 :   if (rval == error_mark_node)
    3907                 :            :     return error_mark_node;
    3908                 :            : 
    3909                 :     182059 :   if (processing_template_decl)
    3910                 :            :     {
    3911                 :       7469 :       tree ret = build_raw_new_expr (loc, orig_placement, type, orig_nelts,
    3912                 :            :                                      orig_init, use_global_new);
    3913                 :       7469 :       release_tree_vector (orig_placement);
    3914                 :       7469 :       release_tree_vector (orig_init);
    3915                 :       7469 :       return ret;
    3916                 :            :     }
    3917                 :            : 
    3918                 :            :   /* Wrap it in a NOP_EXPR so warn_if_unused_value doesn't complain.  */
    3919                 :     174590 :   rval = build1_loc (loc, NOP_EXPR, TREE_TYPE (rval), rval);
    3920                 :     174590 :   TREE_NO_WARNING (rval) = 1;
    3921                 :            : 
    3922                 :     174590 :   return rval;
    3923                 :            : }
    3924                 :            : 
    3925                 :            : static tree
    3926                 :       5419 : build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type,
    3927                 :            :                     special_function_kind auto_delete_vec,
    3928                 :            :                     int use_global_delete, tsubst_flags_t complain)
    3929                 :            : {
    3930                 :       5419 :   tree virtual_size;
    3931                 :       5419 :   tree ptype = build_pointer_type (type = complete_type (type));
    3932                 :       5419 :   tree size_exp;
    3933                 :            : 
    3934                 :            :   /* Temporary variables used by the loop.  */
    3935                 :       5419 :   tree tbase, tbase_init;
    3936                 :            : 
    3937                 :            :   /* This is the body of the loop that implements the deletion of a
    3938                 :            :      single element, and moves temp variables to next elements.  */
    3939                 :       5419 :   tree body;
    3940                 :            : 
    3941                 :            :   /* This is the LOOP_EXPR that governs the deletion of the elements.  */
    3942                 :       5419 :   tree loop = 0;
    3943                 :            : 
    3944                 :            :   /* This is the thing that governs what to do after the loop has run.  */
    3945                 :       5419 :   tree deallocate_expr = 0;
    3946                 :            : 
    3947                 :            :   /* This is the BIND_EXPR which holds the outermost iterator of the
    3948                 :            :      loop.  It is convenient to set this variable up and test it before
    3949                 :            :      executing any other code in the loop.
    3950                 :            :      This is also the containing expression returned by this function.  */
    3951                 :       5419 :   tree controller = NULL_TREE;
    3952                 :       5419 :   tree tmp;
    3953                 :            : 
    3954                 :            :   /* We should only have 1-D arrays here.  */
    3955                 :       5419 :   gcc_assert (TREE_CODE (type) != ARRAY_TYPE);
    3956                 :            : 
    3957                 :       5419 :   if (base == error_mark_node || maxindex == error_mark_node)
    3958                 :            :     return error_mark_node;
    3959                 :            : 
    3960                 :       5419 :   if (!verify_type_context (loc, TCTX_DEALLOCATION, type,
    3961                 :       5419 :                             !(complain & tf_error)))
    3962                 :          0 :     return error_mark_node;
    3963                 :            : 
    3964                 :       5419 :   if (!COMPLETE_TYPE_P (type))
    3965                 :            :     {
    3966                 :         12 :       if (complain & tf_warning)
    3967                 :            :         {
    3968                 :         24 :           auto_diagnostic_group d;
    3969                 :         12 :           if (warning_at (loc, OPT_Wdelete_incomplete,
    3970                 :            :                           "possible problem detected in invocation of "
    3971                 :            :                           "operator %<delete []%>"))
    3972                 :            :             {
    3973                 :          8 :               cxx_incomplete_type_diagnostic (base, type, DK_WARNING);
    3974                 :          8 :               inform (loc, "neither the destructor nor the "
    3975                 :            :                       "class-specific operator %<delete []%> will be called, "
    3976                 :            :                       "even if they are declared when the class is defined");
    3977                 :            :             }
    3978                 :            :         }
    3979                 :            :       /* This size won't actually be used.  */
    3980                 :         12 :       size_exp = size_one_node;
    3981                 :         12 :       goto no_destructor;
    3982                 :            :     } 
    3983                 :            : 
    3984                 :       5407 :   size_exp = size_in_bytes (type);
    3985                 :            : 
    3986                 :       8606 :   if (! MAYBE_CLASS_TYPE_P (type))
    3987                 :       2208 :     goto no_destructor;
    3988                 :       3199 :   else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
    3989                 :            :     {
    3990                 :            :       /* Make sure the destructor is callable.  */
    3991                 :        239 :       if (type_build_dtor_call (type))
    3992                 :            :         {
    3993                 :         29 :           tmp = build_delete (loc, ptype, base, sfk_complete_destructor,
    3994                 :            :                               LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1,
    3995                 :            :                               complain);
    3996                 :         29 :           if (tmp == error_mark_node)
    3997                 :            :             return error_mark_node;
    3998                 :            :         }
    3999                 :        233 :       goto no_destructor;
    4000                 :            :     }
    4001                 :            : 
    4002                 :            :   /* The below is short by the cookie size.  */
    4003                 :       2960 :   virtual_size = size_binop (MULT_EXPR, size_exp,
    4004                 :            :                              fold_convert (sizetype, maxindex));
    4005                 :            : 
    4006                 :       2960 :   tbase = create_temporary_var (ptype);
    4007                 :       5920 :   DECL_INITIAL (tbase)
    4008                 :       2960 :     = fold_build_pointer_plus_loc (loc, fold_convert (ptype, base),
    4009                 :            :                                    virtual_size);
    4010                 :       2960 :   tbase_init = build_stmt (loc, DECL_EXPR, tbase);
    4011                 :       2960 :   controller = build3 (BIND_EXPR, void_type_node, tbase, NULL_TREE, NULL_TREE);
    4012                 :       2960 :   TREE_SIDE_EFFECTS (controller) = 1;
    4013                 :            : 
    4014                 :       2960 :   body = build1 (EXIT_EXPR, void_type_node,
    4015                 :            :                  build2 (EQ_EXPR, boolean_type_node, tbase,
    4016                 :            :                          fold_convert (ptype, base)));
    4017                 :       2960 :   tmp = fold_build1_loc (loc, NEGATE_EXPR, sizetype, size_exp);
    4018                 :       2960 :   tmp = fold_build_pointer_plus (tbase, tmp);
    4019                 :       2960 :   tmp = cp_build_modify_expr (loc, tbase, NOP_EXPR, tmp, complain);
    4020                 :       2960 :   if (tmp == error_mark_node)
    4021                 :            :     return error_mark_node;
    4022                 :       2960 :   body = build_compound_expr (loc, body, tmp);
    4023                 :       2960 :   tmp = build_delete (loc, ptype, tbase, sfk_complete_destructor,
    4024                 :            :                       LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1,
    4025                 :            :                       complain);
    4026                 :       2960 :   if (tmp == error_mark_node)
    4027                 :            :     return error_mark_node;
    4028                 :       2960 :   body = build_compound_expr (loc, body, tmp);
    4029                 :            : 
    4030                 :       2960 :   loop = build1 (LOOP_EXPR, void_type_node, body);
    4031                 :       2960 :   loop = build_compound_expr (loc, tbase_init, loop);
    4032                 :            : 
    4033                 :       5413 :  no_destructor:
    4034                 :            :   /* Delete the storage if appropriate.  */
    4035                 :       5413 :   if (auto_delete_vec == sfk_deleting_destructor)
    4036                 :            :     {
    4037                 :       2566 :       tree base_tbd;
    4038                 :            : 
    4039                 :            :       /* The below is short by the cookie size.  */
    4040                 :       2566 :       virtual_size = size_binop (MULT_EXPR, size_exp,
    4041                 :            :                                  fold_convert (sizetype, maxindex));
    4042                 :            : 
    4043                 :       2924 :       if (! TYPE_VEC_NEW_USES_COOKIE (type))
    4044                 :            :         /* no header */
    4045                 :            :         base_tbd = base;
    4046                 :            :       else
    4047                 :            :         {
    4048                 :        140 :           tree cookie_size;
    4049                 :            : 
    4050                 :        140 :           cookie_size = targetm.cxx.get_cookie_size (type);
    4051                 :        140 :           base_tbd = cp_build_binary_op (loc,
    4052                 :            :                                          MINUS_EXPR,
    4053                 :            :                                          cp_convert (string_type_node,
    4054                 :            :                                                      base, complain),
    4055                 :            :                                          cookie_size,
    4056                 :            :                                          complain);
    4057                 :        140 :           if (base_tbd == error_mark_node)
    4058                 :            :             return error_mark_node;
    4059                 :        140 :           base_tbd = cp_convert (ptype, base_tbd, complain);
    4060                 :            :           /* True size with header.  */
    4061                 :        140 :           virtual_size = size_binop (PLUS_EXPR, virtual_size, cookie_size);
    4062                 :            :         }
    4063                 :            : 
    4064                 :       2566 :       deallocate_expr = build_op_delete_call (VEC_DELETE_EXPR,
    4065                 :            :                                               base_tbd, virtual_size,
    4066                 :            :                                               use_global_delete & 1,
    4067                 :            :                                               /*placement=*/NULL_TREE,
    4068                 :            :                                               /*alloc_fn=*/NULL_TREE,
    4069                 :            :                                               complain);
    4070                 :            : 
    4071                 :       2566 :       tree deallocate_call_expr = extract_call_expr (deallocate_expr);
    4072                 :       2566 :       if (TREE_CODE (deallocate_call_expr) == CALL_EXPR)
    4073                 :       2566 :         CALL_FROM_NEW_OR_DELETE_P (deallocate_call_expr) = 1;
    4074                 :            :     }
    4075                 :            : 
    4076                 :       2566 :   body = loop;
    4077                 :       2566 :   if (!deallocate_expr)
    4078                 :            :     ;
    4079                 :       2566 :   else if (!body)
    4080                 :            :     body = deallocate_expr;
    4081                 :            :   else
    4082                 :            :     /* The delete operator must be called, even if a destructor
    4083                 :            :        throws.  */
    4084                 :        136 :     body = build2 (TRY_FINALLY_EXPR, void_type_node, body, deallocate_expr);
    4085                 :            : 
    4086                 :       5413 :   if (!body)
    4087                 :         23 :     body = integer_zero_node;
    4088                 :            : 
    4089                 :            :   /* Outermost wrapper: If pointer is null, punt.  */
    4090                 :      10826 :   tree cond = build2_loc (loc, NE_EXPR, boolean_type_node, base,
    4091                 :       5413 :                           fold_convert (TREE_TYPE (base), nullptr_node));
    4092                 :            :   /* This is a compiler generated comparison, don't emit
    4093                 :            :      e.g. -Wnonnull-compare warning for it.  */
    4094                 :       5413 :   TREE_NO_WARNING (cond) = 1;
    4095                 :       5413 :   body = build3_loc (loc, COND_EXPR, void_type_node,
    4096                 :            :                      cond, body, integer_zero_node);
    4097                 :       5413 :   COND_EXPR_IS_VEC_DELETE (body) = true;
    4098                 :       5413 :   body = build1 (NOP_EXPR, void_type_node, body);
    4099                 :            : 
    4100                 :       5413 :   if (controller)
    4101                 :            :     {
    4102                 :       2960 :       TREE_OPERAND (controller, 1) = body;
    4103                 :       2960 :       body = controller;
    4104                 :            :     }
    4105                 :            : 
    4106                 :       5413 :   if (TREE_CODE (base) == SAVE_EXPR)
    4107                 :            :     /* Pre-evaluate the SAVE_EXPR outside of the BIND_EXPR.  */
    4108                 :          0 :     body = build2 (COMPOUND_EXPR, void_type_node, base, body);
    4109                 :            : 
    4110                 :       5413 :   return convert_to_void (body, ICV_CAST, complain);
    4111                 :            : }
    4112                 :            : 
    4113                 :            : /* Create an unnamed variable of the indicated TYPE.  */
    4114                 :            : 
    4115                 :            : tree
    4116                 :      23170 : create_temporary_var (tree type)
    4117                 :            : {
    4118                 :      23170 :   tree decl;
    4119                 :            : 
    4120                 :      23170 :   decl = build_decl (input_location,
    4121                 :            :                      VAR_DECL, NULL_TREE, type);
    4122                 :      23170 :   TREE_USED (decl) = 1;
    4123                 :      23170 :   DECL_ARTIFICIAL (decl) = 1;
    4124                 :      23170 :   DECL_IGNORED_P (decl) = 1;
    4125                 :      23170 :   DECL_CONTEXT (decl) = current_function_decl;
    4126                 :            : 
    4127                 :      23170 :   return decl;
    4128                 :            : }
    4129                 :            : 
    4130                 :            : /* Create a new temporary variable of the indicated TYPE, initialized
    4131                 :            :    to INIT.
    4132                 :            : 
    4133                 :            :    It is not entered into current_binding_level, because that breaks
    4134                 :            :    things when it comes time to do final cleanups (which take place
    4135                 :            :    "outside" the binding contour of the function).  */
    4136                 :            : 
    4137                 :            : tree
    4138                 :       9375 : get_temp_regvar (tree type, tree init)
    4139                 :            : {
    4140                 :       9375 :   tree decl;
    4141                 :            : 
    4142                 :       9375 :   decl = create_temporary_var (type);
    4143                 :       9375 :   add_decl_expr (decl);
    4144                 :            : 
    4145                 :       9375 :   finish_expr_stmt (cp_build_modify_expr (input_location, decl, INIT_EXPR,
    4146                 :            :                                           init, tf_warning_or_error));
    4147                 :            : 
    4148                 :       9375 :   return decl;
    4149                 :            : }
    4150                 :            : 
    4151                 :            : /* Subroutine of build_vec_init.  Returns true if assigning to an array of
    4152                 :            :    INNER_ELT_TYPE from INIT is trivial.  */
    4153                 :            : 
    4154                 :            : static bool
    4155                 :         36 : vec_copy_assign_is_trivial (tree inner_elt_type, tree init)
    4156                 :            : {
    4157                 :         36 :   tree fromtype = inner_elt_type;
    4158                 :         36 :   if (lvalue_p (init))
    4159                 :         33 :     fromtype = cp_build_reference_type (fromtype, /*rval*/false);
    4160                 :         36 :   return is_trivially_xible (MODIFY_EXPR, inner_elt_type, fromtype);
    4161                 :            : }
    4162                 :            : 
    4163                 :            : /* Subroutine of build_vec_init: Check that the array has at least N
    4164                 :            :    elements.  Other parameters are local variables in build_vec_init.  */
    4165                 :            : 
    4166                 :            : void
    4167                 :         76 : finish_length_check (tree atype, tree iterator, tree obase, unsigned n)
    4168                 :            : {
    4169                 :         76 :   tree nelts = build_int_cst (ptrdiff_type_node, n - 1);
    4170                 :         76 :   if (TREE_CODE (atype) != ARRAY_TYPE)
    4171                 :            :     {
    4172                 :          3 :       if (flag_exceptions)
    4173                 :            :         {
    4174                 :          3 :           tree c = fold_build2 (LT_EXPR, boolean_type_node, iterator,
    4175                 :            :                                 nelts);
    4176                 :          3 :           c = build3 (COND_EXPR, void_type_node, c,
    4177                 :            :                       throw_bad_array_new_length (), void_node);
    4178                 :          3 :           finish_expr_stmt (c);
    4179                 :            :         }
    4180                 :            :       /* Don't check an array new when -fno-exceptions.  */
    4181                 :            :     }
    4182                 :         73 :   else if (sanitize_flags_p (SANITIZE_BOUNDS)
    4183                 :         73 :            && current_function_decl != NULL_TREE)
    4184                 :            :     {
    4185                 :            :       /* Make sure the last element of the initializer is in bounds. */
    4186                 :          7 :       finish_expr_stmt
    4187                 :          7 :         (ubsan_instrument_bounds
    4188                 :            :          (input_location, obase, &nelts, /*ignore_off_by_one*/false));
    4189                 :            :     }
    4190                 :         76 : }
    4191                 :            : 
    4192                 :            : /* `build_vec_init' returns tree structure that performs
    4193                 :            :    initialization of a vector of aggregate types.
    4194                 :            : 
    4195                 :            :    BASE is a reference to the vector, of ARRAY_TYPE, or a pointer
    4196                 :            :      to the first element, of POINTER_TYPE.
    4197                 :            :    MAXINDEX is the maximum index of the array (one less than the
    4198                 :            :      number of elements).  It is only used if BASE is a pointer or
    4199                 :            :      TYPE_DOMAIN (TREE_TYPE (BASE)) == NULL_TREE.
    4200                 :            : 
    4201                 :            :    INIT is the (possibly NULL) initializer.
    4202                 :            : 
    4203                 :            :    If EXPLICIT_VALUE_INIT_P is true, then INIT must be NULL.  All
    4204                 :            :    elements in the array are value-initialized.
    4205                 :            : 
    4206                 :            :    FROM_ARRAY is 0 if we should init everything with INIT
    4207                 :            :    (i.e., every element initialized from INIT).
    4208                 :            :    FROM_ARRAY is 1 if we should index into INIT in parallel
    4209                 :            :    with initialization of DECL.
    4210                 :            :    FROM_ARRAY is 2 if we should index into INIT in parallel,
    4211                 :            :    but use assignment instead of initialization.  */
    4212                 :            : 
    4213                 :            : tree
    4214                 :       3189 : build_vec_init (tree base, tree maxindex, tree init,
    4215                 :            :                 bool explicit_value_init_p,
    4216                 :            :                 int from_array, tsubst_flags_t complain)
    4217                 :            : {
    4218                 :       3189 :   tree rval;
    4219                 :       3189 :   tree base2 = NULL_TREE;
    4220                 :       3189 :   tree itype = NULL_TREE;
    4221                 :       3189 :   tree iterator;
    4222                 :            :   /* The type of BASE.  */
    4223                 :       3189 :   tree atype = TREE_TYPE (base);
    4224                 :            :   /* The type of an element in the array.  */
    4225                 :       3189 :   tree type = TREE_TYPE (atype);
    4226                 :            :   /* The element type reached after removing all outer array
    4227                 :            :      types.  */
    4228                 :       3189 :   tree inner_elt_type;
    4229                 :            :   /* The type of a pointer to an element in the array.  */
    4230                 :       3189 :   tree ptype;
    4231                 :       3189 :   tree stmt_expr;
    4232                 :       3189 :   tree compound_stmt;
    4233                 :       3189 :   int destroy_temps;
    4234                 :       3189 :   tree try_block = NULL_TREE;
    4235                 :       3189 :   HOST_WIDE_INT num_initialized_elts = 0;
    4236                 :       3189 :   bool is_global;
    4237                 :       3189 :   tree obase = base;
    4238                 :       3189 :   bool xvalue = false;
    4239                 :       3189 :   bool errors = false;
    4240                 :       3189 :   location_t loc = (init ? cp_expr_loc_or_input_loc (init)
    4241                 :       1715 :                     : location_of (base));
    4242                 :            : 
    4243                 :       3189 :   if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
    4244                 :       2610 :     maxindex = array_type_nelts (atype);
    4245                 :            : 
    4246                 :       3189 :   if (maxindex == NULL_TREE || maxindex == error_mark_node)
    4247                 :          0 :     return error_mark_node;
    4248                 :            : 
    4249                 :       3189 :   maxindex = maybe_constant_value (maxindex);
    4250                 :       3189 :   if (explicit_value_init_p)
    4251                 :        373 :     gcc_assert (!init);
    4252                 :            : 
    4253                 :       3189 :   inner_elt_type = strip_array_types (type);
    4254                 :            : 
    4255                 :            :   /* Look through the TARGET_EXPR around a compound literal.  */
    4256                 :       1474 :   if (init && TREE_CODE (init) == TARGET_EXPR
    4257                 :         20 :       && TREE_CODE (TARGET_EXPR_INITIAL (init)) == CONSTRUCTOR
    4258                 :       3209 :       && from_array != 2)
    4259                 :         20 :     init = TARGET_EXPR_INITIAL (init);
    4260                 :            : 
    4261                 :       3189 :   bool direct_init = false;
    4262                 :        648 :   if (from_array && init && BRACE_ENCLOSED_INITIALIZER_P (init)
    4263                 :       3207 :       && CONSTRUCTOR_NELTS (init) == 1)
    4264                 :            :     {
    4265                 :         18 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    4266                 :         18 :       if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE)
    4267                 :            :         {
    4268                 :         18 :           direct_init = DIRECT_LIST_INIT_P (init);
    4269                 :            :           init = elt;
    4270                 :            :         }
    4271                 :            :     }
    4272                 :            : 
    4273                 :            :   /* If we have a braced-init-list or string constant, make sure that the array
    4274                 :            :      is big enough for all the initializers.  */
    4275                 :       3189 :   bool length_check = (init
    4276                 :       1474 :                        && (TREE_CODE (init) == STRING_CST
    4277                 :       1440 :                            || (TREE_CODE (init) == CONSTRUCTOR
    4278                 :       1255 :                                && CONSTRUCTOR_NELTS (init) > 0))
    4279                 :       4398 :                        && !TREE_CONSTANT (maxindex));
    4280                 :            : 
    4281                 :       3189 :   if (init
    4282                 :       1474 :       && TREE_CODE (atype) == ARRAY_TYPE
    4283                 :       1434 :       && TREE_CONSTANT (maxindex)
    4284                 :         36 :       && (from_array == 2
    4285                 :         36 :           ? vec_copy_assign_is_trivial (inner_elt_type, init)
    4286                 :       1304 :           : !TYPE_NEEDS_CONSTRUCTING (type))
    4287                 :       4659 :       && ((TREE_CODE (init) == CONSTRUCTOR
    4288                 :         26 :            && (BRACE_ENCLOSED_INITIALIZER_P (init)
    4289                 :         26 :                || (same_type_ignoring_top_level_qualifiers_p
    4290                 :         26 :                    (atype, TREE_TYPE (init))))
    4291                 :            :            /* Don't do this if the CONSTRUCTOR might contain something
    4292                 :            :               that might throw and require us to clean up.  */
    4293                 :         52 :            && (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))
    4294                 :         26 :                || ! TYPE_HAS_NONTRIVIAL_DESTRUCTOR (inner_elt_type)))
    4295                 :        104 :           || from_array))
    4296                 :            :     {
    4297                 :            :       /* Do non-default initialization of trivial arrays resulting from
    4298                 :            :          brace-enclosed initializers.  In this case, digest_init and
    4299                 :            :          store_constructor will handle the semantics for us.  */
    4300                 :            : 
    4301                 :        156 :       if (BRACE_ENCLOSED_INITIALIZER_P (init))
    4302                 :          0 :         init = digest_init (atype, init, complain);
    4303                 :        130 :       stmt_expr = build2 (INIT_EXPR, atype, base, init);
    4304                 :        130 :       return stmt_expr;
    4305                 :            :     }
    4306                 :            : 
    4307                 :       3059 :   maxindex = cp_convert (ptrdiff_type_node, maxindex, complain);
    4308                 :       3059 :   maxindex = fold_simple (maxindex);
    4309                 :            : 
    4310                 :       3059 :   if (TREE_CODE (atype) == ARRAY_TYPE)
    4311                 :            :     {
    4312                 :       2480 :       ptype = build_pointer_type (type);
    4313                 :       2480 :       base = decay_conversion (base, complain);
    4314                 :       2480 :       if (base == error_mark_node)
    4315                 :            :         return error_mark_node;
    4316                 :       2480 :       base = cp_convert (ptype, base, complain);
    4317                 :            :     }
    4318                 :            :   else
    4319                 :            :     ptype = atype;
    4320                 :            : 
    4321                 :            :   /* The code we are generating looks like:
    4322                 :            :      ({
    4323                 :            :        T* t1 = (T*) base;
    4324                 :            :        T* rval = t1;
    4325                 :            :        ptrdiff_t iterator = maxindex;
    4326                 :            :        try {
    4327                 :            :          for (; iterator != -1; --iterator) {
    4328                 :            :            ... initialize *t1 ...
    4329                 :            :            ++t1;
    4330                 :            :          }
    4331                 :            :        } catch (...) {
    4332                 :            :          ... destroy elements that were constructed ...
    4333                 :            :        }
    4334                 :            :        rval;
    4335                 :            :      })
    4336                 :            : 
    4337                 :            :      We can omit the try and catch blocks if we know that the
    4338                 :            :      initialization will never throw an exception, or if the array
    4339                 :            :      elements do not have destructors.  We can omit the loop completely if
    4340                 :            :      the elements of the array do not have constructors.
    4341                 :            : 
    4342                 :            :      We actually wrap the entire body of the above in a STMT_EXPR, for
    4343                 :            :      tidiness.
    4344                 :            : 
    4345                 :            :      When copying from array to another, when the array elements have
    4346                 :            :      only trivial copy constructors, we should use __builtin_memcpy
    4347                 :            :      rather than generating a loop.  That way, we could take advantage
    4348                 :            :      of whatever cleverness the back end has for dealing with copies
    4349                 :            :      of blocks of memory.  */
    4350                 :            : 
    4351                 :       3059 :   is_global = begin_init_stmts (&stmt_expr, &compound_stmt);
    4352                 :       3059 :   destroy_temps = stmts_are_full_exprs_p ();
    4353                 :       3059 :   current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    4354                 :       3059 :   rval = get_temp_regvar (ptype, base);
    4355                 :       3059 :   base = get_temp_regvar (ptype, rval);
    4356                 :       3059 :   iterator = get_temp_regvar (ptrdiff_type_node, maxindex);
    4357                 :            : 
    4358                 :            :   /* If initializing one array from another, initialize element by
    4359                 :            :      element.  We rely upon the below calls to do the argument
    4360                 :            :      checking.  Evaluate the initializer before entering the try block.  */
    4361                 :       3059 :   if (from_array && init && TREE_CODE (init) != CONSTRUCTOR)
    4362                 :            :     {
    4363                 :        112 :       if (lvalue_kind (init) & clk_rvalueref)
    4364                 :          6 :         xvalue = true;
    4365                 :        112 :       base2 = decay_conversion (init, complain);
    4366                 :        112 :       if (base2 == error_mark_node)
    4367                 :            :         return error_mark_node;
    4368                 :        112 :       itype = TREE_TYPE (base2);
    4369                 :        112 :       base2 = get_temp_regvar (itype, base2);
    4370                 :        112 :       itype = TREE_TYPE (itype);
    4371                 :            :     }
    4372                 :            : 
    4373                 :            :   /* Protect the entire array initialization so that we can destroy
    4374                 :            :      the partially constructed array if an exception is thrown.
    4375                 :            :      But don't do this if we're assigning.  */
    4376                 :       3039 :   if (flag_exceptions && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    4377                 :       4315 :       && from_array != 2)
    4378                 :            :     {
    4379                 :       1249 :       try_block = begin_try_block ();
    4380                 :            :     }
    4381                 :            : 
    4382                 :            :   /* Should we try to create a constant initializer?  */
    4383                 :       3059 :   bool try_const = (TREE_CODE (atype) == ARRAY_TYPE
    4384                 :       2480 :                     && TREE_CONSTANT (maxindex)
    4385                 :       2376 :                     && (init ? TREE_CODE (init) == CONSTRUCTOR
    4386                 :            :                         : (type_has_constexpr_default_constructor
    4387                 :       1166 :                            (inner_elt_type)))
    4388                 :       6754 :                     && (literal_type_p (inner_elt_type)
    4389                 :        864 :                         || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type)));
    4390                 :       3059 :   vec<constructor_elt, va_gc> *const_vec = NULL;
    4391                 :       3059 :   bool saw_non_const = false;
    4392                 :            :   /* If we're initializing a static array, we want to do static
    4393                 :            :      initialization of any elements with constant initializers even if
    4394                 :            :      some are non-constant.  */
    4395                 :       3059 :   bool do_static_init = (DECL_P (obase) && TREE_STATIC (obase));
    4396                 :            : 
    4397                 :       3059 :   bool empty_list = false;
    4398                 :       2573 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init)
    4399                 :       4079 :       && CONSTRUCTOR_NELTS (init) == 0)
    4400                 :            :     /* Skip over the handling of non-empty init lists.  */
    4401                 :            :     empty_list = true;
    4402                 :            : 
    4403                 :            :   /* Maybe pull out constant value when from_array? */
    4404                 :            : 
    4405                 :       2997 :   else if (init != NULL_TREE && TREE_CODE (init) == CONSTRUCTOR)
    4406                 :            :     {
    4407                 :            :       /* Do non-default initialization of non-trivial arrays resulting from
    4408                 :            :          brace-enclosed initializers.  */
    4409                 :       1167 :       unsigned HOST_WIDE_INT idx;
    4410                 :       1167 :       tree field, elt;
    4411                 :            :       /* If the constructor already has the array type, it's been through
    4412                 :            :          digest_init, so we shouldn't try to do anything more.  */
    4413                 :       1167 :       bool digested = same_type_p (atype, TREE_TYPE (init));
    4414                 :       1167 :       from_array = 0;
    4415                 :            : 
    4416                 :       1167 :       if (length_check)
    4417                 :         92 :         finish_length_check (atype, iterator, obase, CONSTRUCTOR_NELTS (init));
    4418                 :            : 
    4419                 :       1167 :       if (try_const)
    4420                 :        642 :         vec_alloc (const_vec, CONSTRUCTOR_NELTS (init));
    4421                 :            : 
    4422                 :      16372 :       FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), idx, field, elt)
    4423                 :            :         {
    4424                 :       7028 :           tree baseref = build1 (INDIRECT_REF, type, base);
    4425                 :       7028 :           tree one_init;
    4426                 :            : 
    4427                 :       7028 :           num_initialized_elts++;
    4428                 :            : 
    4429                 :       7028 :           current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    4430                 :       7028 :           if (digested)
    4431                 :        425 :             one_init = build2 (INIT_EXPR, type, baseref, elt);
    4432                 :      12982 :           else if (MAYBE_CLASS_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
    4433                 :       6559 :             one_init = build_aggr_init (baseref, elt, 0, complain);
    4434                 :            :           else
    4435                 :         44 :             one_init = cp_build_modify_expr (input_location, baseref,
    4436                 :            :                                              NOP_EXPR, elt, complain);
    4437                 :       7028 :           if (one_init == error_mark_node)
    4438                 :          0 :             errors = true;
    4439                 :       7028 :           if (try_const)
    4440                 :            :             {
    4441                 :       2397 :               tree e = maybe_constant_init (one_init);
    4442                 :       2397 :               if (reduced_constant_expression_p (e))
    4443                 :            :                 {
    4444                 :       2161 :                   CONSTRUCTOR_APPEND_ELT (const_vec, field, e);
    4445                 :       2161 :                   if (do_static_init)
    4446                 :            :                     one_init = NULL_TREE;
    4447                 :            :                   else
    4448                 :        311 :                     one_init = build2 (INIT_EXPR, type, baseref, e);
    4449                 :            :                 }
    4450                 :            :               else
    4451                 :            :                 {
    4452                 :        236 :                   if (do_static_init)
    4453                 :            :                     {
    4454                 :        111 :                       tree value = build_zero_init (TREE_TYPE (e), NULL_TREE,
    4455                 :            :                                                     true);
    4456                 :        111 :                       if (value)
    4457                 :          0 :                         CONSTRUCTOR_APPEND_ELT (const_vec, field, value);
    4458                 :            :                     }
    4459                 :            :                   saw_non_const = true;
    4460                 :            :                 }
    4461                 :            :             }
    4462                 :            : 
    4463                 :       5178 :           if (one_init)
    4464                 :       5178 :             finish_expr_stmt (one_init);
    4465                 :       7028 :           current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    4466                 :            : 
    4467                 :       7028 :           one_init = cp_build_unary_op (PREINCREMENT_EXPR, base, false,
    4468                 :            :                                         complain);
    4469                 :       7028 :           if (one_init == error_mark_node)
    4470                 :            :             errors = true;
    4471                 :            :           else
    4472                 :       7028 :             finish_expr_stmt (one_init);
    4473                 :            : 
    4474                 :       7028 :           one_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, false,
    4475                 :            :                                         complain);
    4476                 :       7028 :           if (one_init == error_mark_node)
    4477                 :            :             errors = true;
    4478                 :            :           else
    4479                 :       7028 :             finish_expr_stmt (one_init);
    4480                 :            :         }
    4481                 :            : 
    4482                 :            :       /* Any elements without explicit initializers get T{}.  */
    4483                 :            :       empty_list = true;
    4484                 :            :     }
    4485                 :       1830 :   else if (init && TREE_CODE (init) == STRING_CST)
    4486                 :            :     {
    4487                 :            :       /* Check that the array is at least as long as the string.  */
    4488                 :         30 :       if (length_check)
    4489                 :         30 :         finish_length_check (atype, iterator, obase,
    4490                 :         30 :                              TREE_STRING_LENGTH (init));
    4491                 :         30 :       tree length = build_int_cst (ptrdiff_type_node,
    4492                 :         30 :                                    TREE_STRING_LENGTH (init));
    4493                 :            : 
    4494                 :            :       /* Copy the string to the first part of the array.  */
    4495                 :         30 :       tree alias_set = build_int_cst (build_pointer_type (type), 0);
    4496                 :         30 :       tree lhs = build2 (MEM_REF, TREE_TYPE (init), base, alias_set);
    4497                 :         30 :       tree stmt = build2 (MODIFY_EXPR, void_type_node, lhs, init);
    4498                 :         30 :       finish_expr_stmt (stmt);
    4499                 :            : 
    4500                 :            :       /* Adjust the counter and pointer.  */
    4501                 :         30 :       stmt = cp_build_binary_op (loc, MINUS_EXPR, iterator, length, complain);
    4502                 :         30 :       stmt = build2 (MODIFY_EXPR, void_type_node, iterator, stmt);
    4503                 :         30 :       finish_expr_stmt (stmt);
    4504                 :            : 
    4505                 :         30 :       stmt = cp_build_binary_op (loc, PLUS_EXPR, base, length, complain);
    4506                 :         30 :       stmt = build2 (MODIFY_EXPR, void_type_node, base, stmt);
    4507                 :         30 :       finish_expr_stmt (stmt);
    4508                 :            : 
    4509                 :            :       /* And set the rest of the array to NUL.  */
    4510                 :         30 :       from_array = 0;
    4511                 :         30 :       explicit_value_init_p = true;
    4512                 :            :     }
    4513                 :       1800 :   else if (from_array)
    4514                 :            :     {
    4515                 :         82 :       if (init)
    4516                 :            :         /* OK, we set base2 above.  */;
    4517                 :          0 :       else if (CLASS_TYPE_P (type)
    4518                 :          0 :                && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
    4519                 :            :         {
    4520                 :          0 :           if (complain & tf_error)
    4521                 :          0 :             error ("initializer ends prematurely");
    4522                 :            :           errors = true;
    4523                 :            :         }
    4524                 :            :     }
    4525                 :            : 
    4526                 :            :   /* Now, default-initialize any remaining elements.  We don't need to
    4527                 :            :      do that if a) the type does not need constructing, or b) we've
    4528                 :            :      already initialized all the elements.
    4529                 :            : 
    4530                 :            :      We do need to keep going if we're copying an array.  */
    4531                 :            : 
    4532                 :       3059 :   if (try_const && !init)
    4533                 :            :     /* With a constexpr default constructor, which we checked for when
    4534                 :            :        setting try_const above, default-initialization is equivalent to
    4535                 :            :        value-initialization, and build_value_init gives us something more
    4536                 :            :        friendly to maybe_constant_init.  */
    4537                 :        191 :     explicit_value_init_p = true;
    4538                 :       3059 :   if (from_array
    4539                 :       3059 :       || ((type_build_ctor_call (type) || init || explicit_value_init_p)
    4540                 :       2977 :           && ! (tree_fits_shwi_p (maxindex)
    4541                 :            :                 && (num_initialized_elts
    4542                 :       2623 :                     == tree_to_shwi (maxindex) + 1))))
    4543                 :            :     {
    4544                 :            :       /* If the ITERATOR is lesser or equal to -1, then we don't have to loop;
    4545                 :            :          we've already initialized all the elements.  */
    4546                 :       1977 :       tree for_stmt;
    4547                 :       1977 :       tree elt_init;
    4548                 :       1977 :       tree to;
    4549                 :            : 
    4550                 :       1977 :       for_stmt = begin_for_stmt (NULL_TREE, NULL_TREE);
    4551                 :       1977 :       finish_init_stmt (for_stmt);
    4552                 :       1977 :       finish_for_cond (build2 (GT_EXPR, boolean_type_node, iterator,
    4553                 :       1977 :                                build_int_cst (TREE_TYPE (iterator), -1)),
    4554                 :            :                        for_stmt, false, 0);
    4555                 :       1977 :       elt_init = cp_build_unary_op (PREDECREMENT_EXPR, iterator, false,
    4556                 :            :                                     complain);
    4557                 :       1977 :       if (elt_init == error_mark_node)
    4558                 :          0 :         errors = true;
    4559                 :       1977 :       finish_for_expr (elt_init, for_stmt);
    4560                 :            : 
    4561                 :       1977 :       to = build1 (INDIRECT_REF, type, base);
    4562                 :            : 
    4563                 :            :       /* If the initializer is {}, then all elements are initialized from T{}.
    4564                 :            :          But for non-classes, that's the same as value-initialization.  */
    4565                 :       1977 :       if (empty_list)
    4566                 :            :         {
    4567                 :        166 :           if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type))
    4568                 :            :             {
    4569                 :         90 :               init = build_constructor (init_list_type_node, NULL);
    4570                 :            :             }
    4571                 :            :           else
    4572                 :            :             {
    4573                 :            :               init = NULL_TREE;
    4574                 :            :               explicit_value_init_p = true;
    4575                 :            :             }
    4576                 :            :         }
    4577                 :            : 
    4578                 :       1977 :       if (from_array)
    4579                 :            :         {
    4580                 :         82 :           tree from;
    4581                 :            : 
    4582                 :         82 :           if (base2)
    4583                 :            :             {
    4584                 :         82 :               from = build1 (INDIRECT_REF, itype, base2);
    4585                 :         82 :               if (xvalue)
    4586                 :          6 :                 from = move (from);
    4587                 :         82 :               if (direct_init)
    4588                 :          7 :                 from = build_tree_list (NULL_TREE, from);
    4589                 :            :             }
    4590                 :            :           else
    4591                 :            :             from = NULL_TREE;
    4592                 :            : 
    4593                 :         82 :           if (TREE_CODE (type) == ARRAY_TYPE)
    4594                 :         10 :             elt_init = build_vec_init (to, NULL_TREE, from, /*val_init*/false,
    4595                 :            :                                        from_array, complain);
    4596                 :         72 :           else if (from_array == 2)
    4597                 :         32 :             elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR,
    4598                 :            :                                              from, complain);
    4599                 :         40 :           else if (type_build_ctor_call (type))
    4600                 :         40 :             elt_init = build_aggr_init (to, from, 0, complain);
    4601                 :          0 :           else if (from)
    4602                 :          0 :             elt_init = cp_build_modify_expr (input_location, to, NOP_EXPR, from,
    4603                 :            :                                              complain);
    4604                 :            :           else
    4605                 :          0 :             gcc_unreachable ();
    4606                 :            :         }
    4607                 :       1895 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    4608                 :            :         {
    4609                 :        181 :           if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
    4610                 :            :             {
    4611                 :          0 :               if ((complain & tf_error))
    4612                 :          0 :                 error_at (loc, "array must be initialized "
    4613                 :            :                           "with a brace-enclosed initializer");
    4614                 :          0 :               elt_init = error_mark_node;
    4615                 :            :             }
    4616                 :            :           else
    4617                 :        166 :             elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
    4618                 :            :                                        0, init,
    4619                 :            :                                        explicit_value_init_p,
    4620                 :            :                                        0, complain);
    4621                 :            :         }
    4622                 :       1729 :       else if (explicit_value_init_p)
    4623                 :            :         {
    4624                 :        612 :           elt_init = build_value_init (type, complain);
    4625                 :        612 :           if (elt_init != error_mark_node)
    4626                 :        612 :             elt_init = build2 (INIT_EXPR, type, to, elt_init);
    4627                 :            :         }
    4628                 :            :       else
    4629                 :            :         {
    4630                 :       1117 :           gcc_assert (type_build_ctor_call (type) || init);
    4631                 :       2231 :           if (CLASS_TYPE_P (type))
    4632                 :       1114 :             elt_init = build_aggr_init (to, init, 0, complain);
    4633                 :            :           else
    4634                 :            :             {
    4635                 :          3 :               if (TREE_CODE (init) == TREE_LIST)
    4636                 :          0 :                 init = build_x_compound_expr_from_list (init, ELK_INIT,
    4637                 :            :                                                         complain);
    4638                 :          3 :               elt_init = (init == error_mark_node
    4639                 :          3 :                           ? error_mark_node
    4640                 :          0 :                           : build2 (INIT_EXPR, type, to, init));
    4641                 :            :             }
    4642                 :            :         }
    4643                 :            : 
    4644                 :       1977 :       if (elt_init == error_mark_node)
    4645                 :          3 :         errors = true;
    4646                 :            : 
    4647                 :       1977 :       if (try_const)
    4648                 :            :         {
    4649                 :            :           /* FIXME refs to earlier elts */
    4650                 :        232 :           tree e = maybe_constant_init (elt_init);
    4651                 :        232 :           if (reduced_constant_expression_p (e))
    4652                 :            :             {
    4653                 :        209 :               if (initializer_zerop (e))
    4654                 :            :                 /* Don't fill the CONSTRUCTOR with zeros.  */
    4655                 :         83 :                 e = NULL_TREE;
    4656                 :        209 :               if (do_static_init)
    4657                 :         32 :                 elt_init = NULL_TREE;
    4658                 :            :             }
    4659                 :            :           else
    4660                 :            :             {
    4661                 :         23 :               saw_non_const = true;
    4662                 :         23 :               if (do_static_init)
    4663                 :          0 :                 e = build_zero_init (TREE_TYPE (e), NULL_TREE, true);
    4664                 :            :               else
    4665                 :            :                 e = NULL_TREE;
    4666                 :            :             }
    4667                 :            : 
    4668                 :        232 :           if (e)
    4669                 :            :             {
    4670                 :        126 :               HOST_WIDE_INT last = tree_to_shwi (maxindex);
    4671                 :        126 :               if (num_initialized_elts <= last)
    4672                 :            :                 {
    4673                 :        126 :                   tree field = size_int (num_initialized_elts);
    4674                 :        126 :                   if (num_initialized_elts != last)
    4675                 :         93 :                     field = build2 (RANGE_EXPR, sizetype, field,
    4676                 :            :                                     size_int (last));
    4677                 :        126 :                   CONSTRUCTOR_APPEND_ELT (const_vec, field, e);
    4678                 :            :                 }
    4679                 :            :             }
    4680                 :            :         }
    4681                 :            : 
    4682                 :       1977 :       current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    4683                 :       1977 :       if (elt_init && !errors)
    4684                 :       1942 :         finish_expr_stmt (elt_init);
    4685                 :       1977 :       current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    4686                 :            : 
    4687                 :       1977 :       finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base, false,
    4688                 :            :                                            complain));
    4689                 :       1977 :       if (base2)
    4690                 :        112 :         finish_expr_stmt (cp_build_unary_op (PREINCREMENT_EXPR, base2, false,
    4691                 :            :                                              complain));
    4692                 :            : 
    4693                 :       1977 :       finish_for_stmt (for_stmt);
    4694                 :            :     }
    4695                 :            : 
    4696                 :            :   /* Make sure to cleanup any partially constructed elements.  */
    4697                 :       3039 :   if (flag_exceptions && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    4698                 :       4315 :       && from_array != 2)
    4699                 :            :     {
    4700                 :       1249 :       tree e;
    4701                 :       1249 :       tree m = cp_build_binary_op (input_location,
    4702                 :            :                                    MINUS_EXPR, maxindex, iterator,
    4703                 :            :                                    complain);
    4704                 :            : 
    4705                 :            :       /* Flatten multi-dimensional array since build_vec_delete only
    4706                 :            :          expects one-dimensional array.  */
    4707                 :       1249 :       if (TREE_CODE (type) == ARRAY_TYPE)
    4708                 :        214 :         m = cp_build_binary_op (input_location,
    4709                 :            :                                 MULT_EXPR, m,
    4710                 :            :                                 /* Avoid mixing signed and unsigned.  */
    4711                 :        107 :                                 convert (TREE_TYPE (m),
    4712                 :            :                                          array_type_nelts_total (type)),
    4713                 :            :                                 complain);
    4714                 :            : 
    4715                 :       1249 :       finish_cleanup_try_block (try_block);
    4716                 :       1249 :       e = build_vec_delete_1 (input_location, rval, m,
    4717                 :            :                               inner_elt_type, sfk_complete_destructor,
    4718                 :            :                               /*use_global_delete=*/0, complain);
    4719                 :       1249 :       if (e == error_mark_node)
    4720                 :          0 :         errors = true;
    4721                 :       1249 :       finish_cleanup (e, try_block);
    4722                 :            :     }
    4723                 :            : 
    4724                 :            :   /* The value of the array initialization is the array itself, RVAL
    4725                 :            :      is a pointer to the first element.  */
    4726                 :       3059 :   finish_stmt_expr_expr (rval, stmt_expr);
    4727                 :            : 
    4728                 :       3059 :   stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
    4729                 :            : 
    4730                 :       3059 :   current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
    4731                 :            : 
    4732                 :       3059 :   if (errors)
    4733                 :          3 :     return error_mark_node;
    4734                 :            : 
    4735                 :       3056 :   if (try_const)
    4736                 :            :     {
    4737                 :        527 :       if (!saw_non_const)
    4738                 :            :         {
    4739                 :        416 :           tree const_init = build_constructor (atype, const_vec);
    4740                 :        416 :           return build2 (INIT_EXPR, atype, obase, const_init);
    4741                 :            :         }
    4742                 :        111 :       else if (do_static_init && !vec_safe_is_empty (const_vec))
    4743                 :         10 :         DECL_INITIAL (obase) = build_constructor (atype, const_vec);
    4744                 :            :       else
    4745                 :        101 :         vec_free (const_vec);
    4746                 :            :     }
    4747                 :            : 
    4748                 :            :   /* Now make the result have the correct type.  */
    4749                 :       2640 :   if (TREE_CODE (atype) == ARRAY_TYPE)
    4750                 :            :     {
    4751                 :       2064 :       atype = build_pointer_type (atype);
    4752                 :       2064 :       stmt_expr = build1 (NOP_EXPR, atype, stmt_expr);
    4753                 :       2064 :       stmt_expr = cp_build_fold_indirect_ref (stmt_expr);
    4754                 :       2064 :       TREE_NO_WARNING (stmt_expr) = 1;
    4755                 :            :     }
    4756                 :            : 
    4757                 :       2640 :   return stmt_expr;
    4758                 :            : }
    4759                 :            : 
    4760                 :            : /* Call the DTOR_KIND destructor for EXP.  FLAGS are as for
    4761                 :            :    build_delete.  */
    4762                 :            : 
    4763                 :            : static tree
    4764                 :    1317960 : build_dtor_call (tree exp, special_function_kind dtor_kind, int flags,
    4765                 :            :                  tsubst_flags_t complain)
    4766                 :            : {
    4767                 :    1317960 :   tree name;
    4768                 :    1317960 :   switch (dtor_kind)
    4769                 :            :     {
    4770                 :    1301880 :     case sfk_complete_destructor:
    4771                 :    1301880 :       name = complete_dtor_identifier;
    4772                 :    1301880 :       break;
    4773                 :            : 
    4774                 :          0 :     case sfk_base_destructor:
    4775                 :          0 :       name = base_dtor_identifier;
    4776                 :          0 :       break;
    4777                 :            : 
    4778                 :      16086 :     case sfk_deleting_destructor:
    4779                 :      16086 :       name = deleting_dtor_identifier;
    4780                 :      16086 :       break;
    4781                 :            : 
    4782                 :          0 :     default:
    4783                 :          0 :       gcc_unreachable ();
    4784                 :            :     }
    4785                 :            : 
    4786                 :    1317960 :   return build_special_member_call (exp, name,
    4787                 :            :                                     /*args=*/NULL,
    4788                 :    1317960 :                                     /*binfo=*/TREE_TYPE (exp),
    4789                 :            :                                     flags,
    4790                 :    1317960 :                                     complain);
    4791                 :            : }
    4792                 :            : 
    4793                 :            : /* Generate a call to a destructor. TYPE is the type to cast ADDR to.
    4794                 :            :    ADDR is an expression which yields the store to be destroyed.
    4795                 :            :    AUTO_DELETE is the name of the destructor to call, i.e., either
    4796                 :            :    sfk_complete_destructor, sfk_base_destructor, or
    4797                 :            :    sfk_deleting_destructor.
    4798                 :            : 
    4799                 :            :    FLAGS is the logical disjunction of zero or more LOOKUP_
    4800                 :            :    flags.  See cp-tree.h for more info.  */
    4801                 :            : 
    4802                 :            : tree
    4803                 :    1320470 : build_delete (location_t loc, tree otype, tree addr,
    4804                 :            :               special_function_kind auto_delete,
    4805                 :            :               int flags, int use_global_delete, tsubst_flags_t complain)
    4806                 :            : {
    4807                 :    1320470 :   tree expr;
    4808                 :            : 
    4809                 :    1320470 :   if (addr == error_mark_node)
    4810                 :            :     return error_mark_node;
    4811                 :            : 
    4812                 :    1320470 :   tree type = TYPE_MAIN_VARIANT (otype);
    4813                 :            : 
    4814                 :            :   /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
    4815                 :            :      set to `error_mark_node' before it gets properly cleaned up.  */
    4816                 :    1320470 :   if (type == error_mark_node)
    4817                 :            :     return error_mark_node;
    4818                 :            : 
    4819                 :    1320470 :   if (TYPE_PTR_P (type))
    4820                 :     944781 :     type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
    4821                 :            : 
    4822                 :    1320470 :   if (TREE_CODE (type) == ARRAY_TYPE)
    4823                 :            :     {
    4824                 :       1613 :       if (TYPE_DOMAIN (type) == NULL_TREE)
    4825                 :            :         {
    4826                 :          0 :           if (complain & tf_error)
    4827                 :          0 :             error_at (loc, "unknown array size in delete");
    4828                 :          0 :           return error_mark_node;
    4829                 :            :         }
    4830                 :       1613 :       return build_vec_delete (loc, addr, array_type_nelts (type),
    4831                 :       1613 :                                auto_delete, use_global_delete, complain);
    4832                 :            :     }
    4833                 :            : 
    4834                 :    1318860 :   bool deleting = (auto_delete == sfk_deleting_destructor);
    4835                 :    1318860 :   gcc_assert (deleting == !(flags & LOOKUP_DESTRUCTOR));
    4836                 :            : 
    4837                 :    1318860 :   if (TYPE_PTR_P (otype))
    4838                 :            :     {
    4839                 :     944772 :       addr = mark_rvalue_use (addr);
    4840                 :            : 
    4841                 :            :       /* We don't want to warn about delete of void*, only other
    4842                 :            :           incomplete types.  Deleting other incomplete types
    4843                 :            :           invokes undefined behavior, but it is not ill-formed, so
    4844                 :            :           compile to something that would even do The Right Thing
    4845                 :            :           (TM) should the type have a trivial dtor and no delete
    4846                 :            :           operator.  */
    4847                 :     944772 :       if (!VOID_TYPE_P (type))
    4848                 :            :         {
    4849                 :     944745 :           complete_type (type);
    4850                 :     944745 :           if (deleting
    4851                 :     970443 :               && !verify_type_context (loc, TCTX_DEALLOCATION, type,
    4852                 :      25698 :                                        !(complain & tf_error)))
    4853                 :          0 :             return error_mark_node;
    4854                 :            : 
    4855                 :     944745 :           if (!COMPLETE_TYPE_P (type))
    4856                 :            :             {
    4857                 :         12 :               if (complain & tf_warning)
    4858                 :            :                 {
    4859                 :         24 :                   auto_diagnostic_group d;
    4860                 :         12 :                   if (warning_at (loc, OPT_Wdelete_incomplete,
    4861                 :            :                                   "possible problem detected in invocation of "
    4862                 :            :                                   "%<operator delete%>"))
    4863                 :            :                     {
    4864                 :          8 :                       cxx_incomplete_type_diagnostic (addr, type, DK_WARNING);
    4865                 :          8 :                       inform (loc,
    4866                 :            :                               "neither the destructor nor the class-specific "
    4867                 :            :                               "%<operator delete%> will be called, even if "
    4868                 :            :                               "they are declared when the class is defined");
    4869                 :            :                     }
    4870                 :            :                 }
    4871                 :            :             }
    4872                 :      25686 :           else if (deleting && warn_delnonvdtor
    4873                 :       1318 :                    && MAYBE_CLASS_TYPE_P (type) && !CLASSTYPE_FINAL (type)
    4874                 :     945378 :                    && TYPE_POLYMORPHIC_P (type))
    4875                 :            :             {
    4876                 :        362 :               tree dtor = CLASSTYPE_DESTRUCTOR (type);
    4877                 :        721 :               if (!dtor || !DECL_VINDEX (dtor))
    4878                 :            :                 {
    4879                 :         15 :                   if (CLASSTYPE_PURE_VIRTUALS (type))
    4880                 :          3 :                     warning_at (loc, OPT_Wdelete_non_virtual_dtor,
    4881                 :            :                                 "deleting object of abstract class type %qT"
    4882                 :            :                                 " which has non-virtual destructor"
    4883                 :            :                                 " will cause undefined behavior", type);
    4884                 :            :                   else
    4885                 :         12 :                     warning_at (loc, OPT_Wdelete_non_virtual_dtor,
    4886                 :            :                                 "deleting object of polymorphic class type %qT"
    4887                 :            :                                 " which has non-virtual destructor"
    4888                 :            :                                 " might cause undefined behavior", type);
    4889                 :            :                 }
    4890                 :            :             }
    4891                 :            :         }
    4892                 :            : 
    4893                 :            :       /* Throw away const and volatile on target type of addr.  */
    4894                 :     944772 :       addr = convert_force (build_pointer_type (type), addr, 0, complain);
    4895                 :            :     }
    4896                 :            :   else
    4897                 :            :     {
    4898                 :            :       /* Don't check PROTECT here; leave that decision to the
    4899                 :            :          destructor.  If the destructor is accessible, call it,
    4900                 :            :          else report error.  */
    4901                 :     374089 :       addr = cp_build_addr_expr (addr, complain);
    4902                 :     374089 :       if (addr == error_mark_node)
    4903                 :            :         return error_mark_node;
    4904                 :            : 
    4905                 :     374089 :       addr = convert_force (build_pointer_type (type), addr, 0, complain);
    4906                 :            :     }
    4907                 :            : 
    4908                 :    1318860 :   if (deleting)
    4909                 :            :     /* We will use ADDR multiple times so we must save it.  */
    4910                 :      25725 :     addr = save_expr (addr);
    4911                 :            : 
    4912                 :    1318860 :   bool virtual_p = false;
    4913                 :    1318860 :   if (type_build_dtor_call (type))
    4914                 :            :     {
    4915                 :    1317960 :       if (CLASSTYPE_LAZY_DESTRUCTOR (type))
    4916                 :      11354 :         lazily_declare_fn (sfk_destructor, type);
    4917                 :    1317960 :       virtual_p = DECL_VIRTUAL_P (CLASSTYPE_DESTRUCTOR (type));
    4918                 :            :     }
    4919                 :            : 
    4920                 :    1318860 :   tree head = NULL_TREE;
    4921                 :    1318860 :   tree do_delete = NULL_TREE;
    4922                 :    1318860 :   bool destroying_delete = false;
    4923                 :            : 
    4924                 :    1318860 :   if (!deleting)
    4925                 :            :     {
    4926                 :            :       /* Leave do_delete null.  */
    4927                 :            :     }
    4928                 :            :   /* For `::delete x', we must not use the deleting destructor
    4929                 :            :      since then we would not be sure to get the global `operator
    4930                 :            :      delete'.  */
    4931                 :      25725 :   else if (use_global_delete)
    4932                 :            :     {
    4933                 :         37 :       head = get_target_expr (build_headof (addr));
    4934                 :            :       /* Delete the object.  */
    4935                 :         37 :       do_delete = build_op_delete_call (DELETE_EXPR,
    4936                 :            :                                         head,
    4937                 :            :                                         cxx_sizeof_nowarn (type),
    4938                 :            :                                         /*global_p=*/true,
    4939                 :            :                                         /*placement=*/NULL_TREE,
    4940                 :            :                                         /*alloc_fn=*/NULL_TREE,
    4941                 :            :                                         complain);
    4942                 :            :       /* Otherwise, treat this like a complete object destructor
    4943                 :            :          call.  */
    4944                 :         37 :       auto_delete = sfk_complete_destructor;
    4945                 :            :     }
    4946                 :            :   /* If the destructor is non-virtual, there is no deleting
    4947                 :            :      variant.  Instead, we must explicitly call the appropriate
    4948                 :            :      `operator delete' here.  */
    4949                 :      25688 :   else if (!virtual_p)
    4950                 :            :     {
    4951                 :            :       /* Build the call.  */
    4952                 :       9602 :       do_delete = build_op_delete_call (DELETE_EXPR,
    4953                 :            :                                         addr,
    4954                 :            :                                         cxx_sizeof_nowarn (type),
    4955                 :            :                                         /*global_p=*/false,
    4956                 :            :                                         /*placement=*/NULL_TREE,
    4957                 :            :                                         /*alloc_fn=*/NULL_TREE,
    4958                 :            :                                         complain);
    4959                 :            :       /* Call the complete object destructor.  */
    4960                 :       9602 :       auto_delete = sfk_complete_destructor;
    4961                 :       9602 :       if (do_delete != error_mark_node)
    4962                 :            :         {
    4963                 :       9594 :           tree fn = get_callee_fndecl (do_delete);
    4964                 :       9594 :           destroying_delete = destroying_delete_p (fn);
    4965                 :            :         }
    4966                 :            :     }
    4967                 :      16086 :   else if (TYPE_GETS_REG_DELETE (type))
    4968                 :            :     {
    4969                 :            :       /* Make sure we have access to the member op delete, even though
    4970                 :            :          we'll actually be calling it from the destructor.  */
    4971                 :         13 :       build_op_delete_call (DELETE_EXPR, addr, cxx_sizeof_nowarn (type),
    4972                 :            :                             /*global_p=*/false,
    4973                 :            :                             /*placement=*/NULL_TREE,
    4974                 :            :                             /*alloc_fn=*/NULL_TREE,
    4975                 :            :                             complain);
    4976                 :            :     }
    4977                 :            : 
    4978                 :    1318860 :   if (!destroying_delete && type_build_dtor_call (type))
    4979                 :    1317960 :     expr = build_dtor_call (cp_build_fold_indirect_ref (addr),
    4980                 :            :                             auto_delete, flags, complain);
    4981                 :            :   else
    4982                 :        898 :     expr = build_trivial_dtor_call (addr);
    4983                 :    1318860 :   if (expr == error_mark_node)
    4984                 :            :     return error_mark_node;
    4985                 :            : 
    4986                 :    1318830 :   if (!deleting)
    4987                 :            :     {
    4988                 :    1293110 :       protected_set_expr_location (expr, loc);
    4989                 :    1293110 :       return expr;
    4990                 :            :     }
    4991                 :            : 
    4992                 :      25719 :   if (do_delete)
    4993                 :            :     {
    4994                 :       9633 :       tree do_delete_call_expr = extract_call_expr (do_delete);
    4995                 :       9633 :       if (TREE_CODE (do_delete_call_expr) == CALL_EXPR)
    4996                 :       9625 :         CALL_FROM_NEW_OR_DELETE_P (do_delete_call_expr) = 1;
    4997                 :            :     }
    4998                 :            : 
    4999                 :      35352 :   if (do_delete && !TREE_SIDE_EFFECTS (expr))
    5000                 :            :     expr = do_delete;
    5001                 :      25719 :   else if (do_delete)
    5002                 :            :     /* The delete operator must be called, regardless of whether
    5003                 :            :        the destructor throws.
    5004                 :            : 
    5005                 :            :        [expr.delete]/7 The deallocation function is called
    5006                 :            :        regardless of whether the destructor for the object or some
    5007                 :            :        element of the array throws an exception.  */
    5008                 :       9633 :     expr = build2 (TRY_FINALLY_EXPR, void_type_node, expr, do_delete);
    5009                 :            : 
    5010                 :            :   /* We need to calculate this before the dtor changes the vptr.  */
    5011                 :      25719 :   if (head)
    5012                 :         31 :     expr = build2 (COMPOUND_EXPR, void_type_node, head, expr);
    5013                 :            : 
    5014                 :            :   /* Handle deleting a null pointer.  */
    5015                 :      25719 :   warning_sentinel s (warn_address);
    5016                 :      25719 :   tree ifexp = cp_build_binary_op (loc, NE_EXPR, addr,
    5017                 :            :                                    nullptr_node, complain);
    5018                 :      25719 :   ifexp = cp_fully_fold (ifexp);
    5019                 :            : 
    5020                 :      25719 :   if (ifexp == error_mark_node)
    5021                 :            :     return error_mark_node;
    5022                 :            :   /* This is a compiler generated comparison, don't emit
    5023                 :            :      e.g. -Wnonnull-compare warning for it.  */
    5024                 :      25719 :   else if (TREE_CODE (ifexp) == NE_EXPR)
    5025                 :      25703 :     TREE_NO_WARNING (ifexp) = 1;
    5026                 :            : 
    5027                 :      25719 :   if (!integer_nonzerop (ifexp))
    5028                 :      25703 :     expr = build3 (COND_EXPR, void_type_node, ifexp, expr, void_node);
    5029                 :            : 
    5030                 :      25719 :   protected_set_expr_location (expr, loc);
    5031                 :      25719 :   return expr;
    5032                 :            : }
    5033                 :            : 
    5034                 :            : /* At the beginning of a destructor, push cleanups that will call the
    5035                 :            :    destructors for our base classes and members.
    5036                 :            : 
    5037                 :            :    Called from begin_destructor_body.  */
    5038                 :            : 
    5039                 :            : void
    5040                 :     630480 : push_base_cleanups (void)
    5041                 :            : {
    5042                 :     630480 :   tree binfo, base_binfo;
    5043                 :     630480 :   int i;
    5044                 :     630480 :   tree member;
    5045                 :     630480 :   tree expr;
    5046                 :     630480 :   vec<tree, va_gc> *vbases;
    5047                 :            : 
    5048                 :            :   /* Run destructors for all virtual baseclasses.  */
    5049                 :     630480 :   if (!ABSTRACT_CLASS_TYPE_P (current_class_type)
    5050                 :    1233590 :       && CLASSTYPE_VBASECLASSES (current_class_type))
    5051                 :            :     {
    5052                 :       4710 :       tree cond = (condition_conversion
    5053                 :       4710 :                    (build2 (BIT_AND_EXPR, integer_type_node,
    5054                 :       4710 :                             current_in_charge_parm,
    5055                 :            :                             integer_two_node)));
    5056                 :            : 
    5057                 :            :       /* The CLASSTYPE_VBASECLASSES vector is in initialization
    5058                 :            :          order, which is also the right order for pushing cleanups.  */
    5059                 :      20967 :       for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
    5060                 :      20967 :            vec_safe_iterate (vbases, i, &base_binfo); i++)
    5061                 :            :         {
    5062                 :      16257 :           if (type_build_dtor_call (BINFO_TYPE (base_binfo)))
    5063                 :            :             {
    5064                 :      16077 :               expr = build_special_member_call (current_class_ref,
    5065                 :            :                                                 base_dtor_identifier,
    5066                 :            :                                                 NULL,
    5067                 :            :                                                 base_binfo,
    5068                 :            :                                                 (LOOKUP_NORMAL
    5069                 :            :                                                  | LOOKUP_NONVIRTUAL),
    5070                 :            :                                                 tf_warning_or_error);
    5071                 :      16077 :               if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo)))
    5072                 :            :                 {
    5073                 :      16077 :                   expr = build3 (COND_EXPR, void_type_node, cond,
    5074                 :            :                                  expr, void_node);
    5075                 :      16077 :                   finish_decl_cleanup (NULL_TREE, expr);
    5076                 :            :                 }
    5077                 :            :             }
    5078                 :            :         }
    5079                 :            :     }
    5080                 :            : 
    5081                 :            :   /* Take care of the remaining baseclasses.  */
    5082                 :     922843 :   for (binfo = TYPE_BINFO (current_class_type), i = 0;
    5083                 :     922784 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    5084                 :            :     {
    5085                 :     292304 :       if (BINFO_VIRTUAL_P (base_binfo)
    5086                 :     292304 :           || !type_build_dtor_call (BINFO_TYPE (base_binfo)))
    5087                 :      52540 :         continue;
    5088                 :            : 
    5089                 :     239764 :       expr = build_special_member_call (current_class_ref,
    5090                 :            :                                         base_dtor_identifier,
    5091                 :            :                                         NULL, base_binfo,
    5092                 :            :                                         LOOKUP_NORMAL | LOOKUP_NONVIRTUAL,
    5093                 :            :                                         tf_warning_or_error);
    5094                 :     239764 :       if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo)))
    5095                 :     239379 :         finish_decl_cleanup (NULL_TREE, expr);
    5096                 :            :     }
    5097                 :            : 
    5098                 :            :   /* Don't automatically destroy union members.  */
    5099                 :     630480 :   if (TREE_CODE (current_class_type) == UNION_TYPE)
    5100                 :     630480 :     return;
    5101                 :            : 
    5102                 :   48921200 :   for (member = TYPE_FIELDS (current_class_type); member;
    5103                 :   24145400 :        member = DECL_CHAIN (member))
    5104                 :            :     {
    5105                 :   24145400 :       tree this_type = TREE_TYPE (member);
    5106                 :   47741700 :       if (this_type == error_mark_node
    5107                 :   24145400 :           || TREE_CODE (member) != FIELD_DECL
    5108                 :   24849800 :           || DECL_ARTIFICIAL (member))
    5109                 :   23596300 :         continue;
    5110                 :     734058 :       if (ANON_AGGR_TYPE_P (this_type))
    5111                 :      32959 :         continue;
    5112                 :     516072 :       if (type_build_dtor_call (this_type))
    5113                 :            :         {
    5114                 :      97942 :           tree this_member = (build_class_member_access_expr
    5115                 :      97942 :                               (current_class_ref, member,
    5116                 :            :                                /*access_path=*/NULL_TREE,
    5117                 :            :                                /*preserve_reference=*/false,
    5118                 :            :                                tf_warning_or_error));
    5119                 :      97942 :           expr = build_delete (input_location, this_type, this_member,
    5120                 :            :                                sfk_complete_destructor,
    5121                 :            :                                LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL,
    5122                 :            :                                0, tf_warning_or_error);
    5123                 :      97942 :           if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (this_type))
    5124                 :      91653 :             finish_decl_cleanup (NULL_TREE, expr);
    5125                 :            :         }
    5126                 :            :     }
    5127                 :            : }
    5128                 :            : 
    5129                 :            : /* Build a C++ vector delete expression.
    5130                 :            :    MAXINDEX is the number of elements to be deleted.
    5131                 :            :    ELT_SIZE is the nominal size of each element in the vector.
    5132                 :            :    BASE is the expression that should yield the store to be deleted.
    5133                 :            :    This function expands (or synthesizes) these calls itself.
    5134                 :            :    AUTO_DELETE_VEC says whether the container (vector) should be deallocated.
    5135                 :            : 
    5136                 :            :    This also calls delete for virtual baseclasses of elements of the vector.
    5137                 :            : 
    5138                 :            :    Update: MAXINDEX is no longer needed.  The size can be extracted from the
    5139                 :            :    start of the vector for pointers, and from the type for arrays.  We still
    5140                 :            :    use MAXINDEX for arrays because it happens to already have one of the
    5141                 :            :    values we'd have to extract.  (We could use MAXINDEX with pointers to
    5142                 :            :    confirm the size, and trap if the numbers differ; not clear that it'd
    5143                 :            :    be worth bothering.)  */
    5144                 :            : 
    5145                 :            : tree
    5146                 :       4170 : build_vec_delete (location_t loc, tree base, tree maxindex,
    5147                 :            :                   special_function_kind auto_delete_vec,
    5148                 :            :                   int use_global_delete, tsubst_flags_t complain)
    5149                 :            : {
    5150                 :       4170 :   tree type;
    5151                 :       4170 :   tree rval;
    5152                 :       4170 :   tree base_init = NULL_TREE;
    5153                 :            : 
    5154                 :       4170 :   type = TREE_TYPE (base);
    5155                 :            : 
    5156                 :       4170 :   if (TYPE_PTR_P (type))
    5157                 :            :     {
    5158                 :            :       /* Step back one from start of vector, and read dimension.  */
    5159                 :       2566 :       tree cookie_addr;
    5160                 :       2566 :       tree size_ptr_type = build_pointer_type (sizetype);
    5161                 :            : 
    5162                 :       2566 :       base = mark_rvalue_use (base);
    5163                 :       2566 :       if (TREE_SIDE_EFFECTS (base))
    5164                 :            :         {
    5165                 :         39 :           base_init = get_target_expr (base);
    5166                 :         39 :           base = TARGET_EXPR_SLOT (base_init);
    5167                 :            :         }
    5168                 :       2566 :       type = strip_array_types (TREE_TYPE (type));
    5169                 :       7698 :       cookie_addr = fold_build1_loc (loc, NEGATE_EXPR,
    5170                 :       2566 :                                  sizetype, TYPE_SIZE_UNIT (sizetype));
    5171                 :       2566 :       cookie_addr = fold_build_pointer_plus (fold_convert (size_ptr_type, base),
    5172                 :            :                                              cookie_addr);
    5173                 :       2566 :       maxindex = cp_build_fold_indirect_ref (cookie_addr);
    5174                 :            :     }
    5175                 :       1604 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    5176                 :            :     {
    5177                 :            :       /* Get the total number of things in the array, maxindex is a
    5178                 :            :          bad name.  */
    5179                 :       1604 :       maxindex = array_type_nelts_total (type);
    5180                 :       1604 :       type = strip_array_types (type);
    5181                 :       1604 :       base = decay_conversion (base, complain);
    5182                 :       1604 :       if (base == error_mark_node)
    5183                 :            :         return error_mark_node;
    5184                 :       1604 :       if (TREE_SIDE_EFFECTS (base))
    5185                 :            :         {
    5186                 :          0 :           base_init = get_target_expr (base);
    5187                 :          0 :           base = TARGET_EXPR_SLOT (base_init);
    5188                 :            :         }
    5189                 :            :     }
    5190                 :            :   else
    5191                 :            :     {
    5192                 :          0 :       if (base != error_mark_node && !(complain & tf_error))
    5193                 :          0 :         error_at (loc,
    5194                 :            :                   "type to vector delete is neither pointer or array type");
    5195                 :          0 :       return error_mark_node;
    5196                 :            :     }
    5197                 :            : 
    5198                 :       4170 :   rval = build_vec_delete_1 (loc, base, maxindex, type, auto_delete_vec,
    5199                 :            :                              use_global_delete, complain);
    5200                 :       4170 :   if (base_init && rval != error_mark_node)
    5201                 :         39 :     rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), base_init, rval);
    5202                 :            : 
    5203                 :       4170 :   protected_set_expr_location (rval, loc);
    5204                 :       4170 :   return rval;
    5205                 :            : }
    5206                 :            : 
    5207                 :            : #include "gt-cp-init.h"

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.