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

           Branch data     Line data    Source code
       1                 :            : /* Perform optimizations on tree structure.
       2                 :            :    Copyright (C) 1998-2020 Free Software Foundation, Inc.
       3                 :            :    Written by Mark Michell (mark@codesourcery.com).
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it
       8                 :            : 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, but
      13                 :            : WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :            : 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                 :            : #include "config.h"
      22                 :            : #include "system.h"
      23                 :            : #include "coretypes.h"
      24                 :            : #include "target.h"
      25                 :            : #include "cp-tree.h"
      26                 :            : #include "stringpool.h"
      27                 :            : #include "cgraph.h"
      28                 :            : #include "debug.h"
      29                 :            : #include "tree-inline.h"
      30                 :            : #include "tree-iterator.h"
      31                 :            : 
      32                 :            : /* Prototypes.  */
      33                 :            : 
      34                 :            : static void update_cloned_parm (tree, tree, bool);
      35                 :            : 
      36                 :            : /* CLONED_PARM is a copy of CLONE, generated for a cloned constructor
      37                 :            :    or destructor.  Update it to ensure that the source-position for
      38                 :            :    the cloned parameter matches that for the original, and that the
      39                 :            :    debugging generation code will be able to find the original PARM.  */
      40                 :            : 
      41                 :            : static void
      42                 :    7045410 : update_cloned_parm (tree parm, tree cloned_parm, bool first)
      43                 :            : {
      44                 :    7045410 :   DECL_ABSTRACT_ORIGIN (cloned_parm) = parm;
      45                 :            : 
      46                 :            :   /* We may have taken its address.  */
      47                 :    7045410 :   TREE_ADDRESSABLE (cloned_parm) = TREE_ADDRESSABLE (parm);
      48                 :            : 
      49                 :   14090800 :   DECL_BY_REFERENCE (cloned_parm) = DECL_BY_REFERENCE (parm);
      50                 :            : 
      51                 :            :   /* The definition might have different constness.  */
      52                 :    7045410 :   TREE_READONLY (cloned_parm) = TREE_READONLY (parm);
      53                 :            : 
      54                 :    7045410 :   TREE_USED (cloned_parm) = !first || TREE_USED (parm);
      55                 :            : 
      56                 :            :   /* The name may have changed from the declaration.  */
      57                 :    7045410 :   DECL_NAME (cloned_parm) = DECL_NAME (parm);
      58                 :    7045410 :   DECL_SOURCE_LOCATION (cloned_parm) = DECL_SOURCE_LOCATION (parm);
      59                 :    7045410 :   TREE_TYPE (cloned_parm) = TREE_TYPE (parm);
      60                 :            : 
      61                 :    7045410 :   DECL_GIMPLE_REG_P (cloned_parm) = DECL_GIMPLE_REG_P (parm);
      62                 :    7045410 : }
      63                 :            : 
      64                 :            : /* Like copy_decl_no_change, but handle DECL_OMP_PRIVATIZED_MEMBER
      65                 :            :    properly.  */
      66                 :            : 
      67                 :            : static tree
      68                 :     970738 : cxx_copy_decl (tree decl, copy_body_data *id)
      69                 :            : {
      70                 :     970738 :   tree copy = copy_decl_no_change (decl, id);
      71                 :     970738 :   if (VAR_P (decl)
      72                 :     306018 :       && DECL_HAS_VALUE_EXPR_P (decl)
      73                 :         17 :       && DECL_ARTIFICIAL (decl)
      74                 :         17 :       && DECL_LANG_SPECIFIC (decl)
      75                 :     970744 :       && DECL_OMP_PRIVATIZED_MEMBER (decl))
      76                 :            :     {
      77                 :          6 :       tree expr = DECL_VALUE_EXPR (copy);
      78                 :          6 :       walk_tree (&expr, copy_tree_body_r, id, NULL);
      79                 :          6 :       SET_DECL_VALUE_EXPR (copy, expr);
      80                 :            :     }
      81                 :     970738 :   return copy;
      82                 :            : }
      83                 :            : 
      84                 :            : /* FN is a function in High GIMPLE form that has a complete body and no
      85                 :            :    CFG.  CLONE is a function whose body is to be set to a copy of FN,
      86                 :            :    mapping argument declarations according to the ARG_MAP splay_tree.  */
      87                 :            : 
      88                 :            : static void
      89                 :    2204840 : clone_body (tree clone, tree fn, void *arg_map)
      90                 :            : {
      91                 :    2204840 :   copy_body_data id;
      92                 :    2204840 :   tree stmts;
      93                 :            : 
      94                 :            :   /* Clone the body, as if we were making an inline call.  But, remap
      95                 :            :      the parameters in the callee to the parameters of caller.  */
      96                 :    2204840 :   memset (&id, 0, sizeof (id));
      97                 :    2204840 :   id.src_fn = fn;
      98                 :    2204840 :   id.dst_fn = clone;
      99                 :    2204840 :   id.src_cfun = DECL_STRUCT_FUNCTION (fn);
     100                 :    2204840 :   id.decl_map = static_cast<hash_map<tree, tree> *> (arg_map);
     101                 :            : 
     102                 :    2204840 :   id.copy_decl = cxx_copy_decl;
     103                 :    2204840 :   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
     104                 :    2204840 :   id.transform_new_cfg = true;
     105                 :    2204840 :   id.transform_return_to_modify = false;
     106                 :    2204840 :   id.transform_lang_insert_block = NULL;
     107                 :            : 
     108                 :            :   /* We're not inside any EH region.  */
     109                 :    2204840 :   id.eh_lp_nr = 0;
     110                 :            : 
     111                 :    2204840 :   stmts = DECL_SAVED_TREE (fn);
     112                 :    2204840 :   walk_tree (&stmts, copy_tree_body_r, &id, NULL);
     113                 :            : 
     114                 :            :   /* Also remap the initializer of any static variables so that they (in
     115                 :            :      particular, any label addresses) correspond to the base variant rather
     116                 :            :      than the abstract one.  */
     117                 :    2204840 :   if (DECL_NAME (clone) == base_dtor_identifier
     118                 :    2204840 :       || DECL_NAME (clone) == base_ctor_identifier)
     119                 :            :     {
     120                 :    2143630 :       unsigned ix;
     121                 :    2143630 :       tree decl;
     122                 :            : 
     123                 :    2143760 :       FOR_EACH_LOCAL_DECL (DECL_STRUCT_FUNCTION (fn), ix, decl)
     124                 :         78 :         walk_tree (&DECL_INITIAL (decl), copy_tree_body_r, &id, NULL);
     125                 :            :     }
     126                 :            : 
     127                 :    2204840 :   append_to_statement_list_force (stmts, &DECL_SAVED_TREE (clone));
     128                 :    2204840 : }
     129                 :            : 
     130                 :            : /* DELETE_DTOR is a delete destructor whose body will be built.
     131                 :            :    COMPLETE_DTOR is the corresponding complete destructor.  */
     132                 :            : 
     133                 :            : static void
     134                 :      99124 : build_delete_destructor_body (tree delete_dtor, tree complete_dtor)
     135                 :            : {
     136                 :      99124 :   tree parm = DECL_ARGUMENTS (delete_dtor);
     137                 :      99124 :   tree virtual_size = cxx_sizeof (current_class_type);
     138                 :            : 
     139                 :            :   /* Call the delete function.  */
     140                 :      99124 :   tree call_delete = build_op_delete_call (DELETE_EXPR, current_class_ptr,
     141                 :            :                                            virtual_size,
     142                 :            :                                            /*global_p=*/false,
     143                 :            :                                            /*placement=*/NULL_TREE,
     144                 :            :                                            /*alloc_fn=*/NULL_TREE,
     145                 :            :                                            tf_warning_or_error);
     146                 :            : 
     147                 :      99124 :   tree op = get_callee_fndecl (call_delete);
     148                 :      99124 :   if (op && DECL_P (op) && destroying_delete_p (op))
     149                 :            :     {
     150                 :            :       /* The destroying delete will handle calling complete_dtor.  */
     151                 :          1 :       add_stmt (call_delete);
     152                 :            :     }
     153                 :            :   else
     154                 :            :     {
     155                 :            :       /* Call the corresponding complete destructor.  */
     156                 :      99123 :       gcc_assert (complete_dtor);
     157                 :      99123 :       tree call_dtor = build_cxx_call (complete_dtor, 1, &parm,
     158                 :            :                                        tf_warning_or_error);
     159                 :            : 
     160                 :            :       /* Operator delete must be called, whether or not the dtor throws.  */
     161                 :      99123 :       add_stmt (build2 (TRY_FINALLY_EXPR, void_type_node,
     162                 :            :                         call_dtor, call_delete));
     163                 :            :     }
     164                 :            : 
     165                 :            :   /* Return the address of the object.
     166                 :            :      ??? How is it useful to return an invalid address?  */
     167                 :      99124 :   if (targetm.cxx.cdtor_returns_this ())
     168                 :            :     {
     169                 :          0 :       tree val = DECL_ARGUMENTS (delete_dtor);
     170                 :          0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
     171                 :          0 :                     DECL_RESULT (delete_dtor), val);
     172                 :          0 :       add_stmt (build_stmt (0, RETURN_EXPR, val));
     173                 :            :     }
     174                 :      99124 : }
     175                 :            : 
     176                 :            : /* Return name of comdat group for complete and base ctor (or dtor)
     177                 :            :    that have the same body.  If dtor is virtual, deleting dtor goes
     178                 :            :    into this comdat group as well.  */
     179                 :            : 
     180                 :            : static tree
     181                 :    1953380 : cdtor_comdat_group (tree complete, tree base)
     182                 :            : {
     183                 :    1953380 :   tree complete_name = DECL_ASSEMBLER_NAME (complete);
     184                 :    1953380 :   tree base_name = DECL_ASSEMBLER_NAME (base);
     185                 :    1953380 :   char *grp_name;
     186                 :    1953380 :   const char *p, *q;
     187                 :    1953380 :   bool diff_seen = false;
     188                 :    1953380 :   size_t idx;
     189                 :    1953380 :   gcc_assert (IDENTIFIER_LENGTH (complete_name)
     190                 :            :               == IDENTIFIER_LENGTH (base_name));
     191                 :    1953380 :   grp_name = XALLOCAVEC (char, IDENTIFIER_LENGTH (complete_name) + 1);
     192                 :    1953380 :   p = IDENTIFIER_POINTER (complete_name);
     193                 :    1953380 :   q = IDENTIFIER_POINTER (base_name);
     194                 :  128557000 :   for (idx = 0; idx < IDENTIFIER_LENGTH (complete_name); idx++)
     195                 :  126603000 :     if (p[idx] == q[idx])
     196                 :  124650000 :       grp_name[idx] = p[idx];
     197                 :            :     else
     198                 :            :       {
     199                 :    1953380 :         gcc_assert (!diff_seen
     200                 :            :                     && idx > 0
     201                 :            :                     && (p[idx - 1] == 'C' || p[idx - 1] == 'D'
     202                 :            :                         || p[idx - 1] == 'I')
     203                 :            :                     && p[idx] == '1'
     204                 :            :                     && q[idx] == '2');
     205                 :    1953380 :         grp_name[idx] = '5';
     206                 :    1953380 :         diff_seen = true;
     207                 :            :       }
     208                 :    1953380 :   grp_name[idx] = '\0';
     209                 :    1953380 :   gcc_assert (diff_seen);
     210                 :    1953380 :   return get_identifier (grp_name);
     211                 :            : }
     212                 :            : 
     213                 :            : /* Returns true iff we can make the base and complete [cd]tor aliases of
     214                 :            :    the same symbol rather than separate functions.  */
     215                 :            : 
     216                 :            : static bool
     217                 :    2176530 : can_alias_cdtor (tree fn)
     218                 :            : {
     219                 :            :   /* If aliases aren't supported by the assembler, fail.  */
     220                 :    2176530 :   if (!TARGET_SUPPORTS_ALIASES)
     221                 :            :     return false;
     222                 :            : 
     223                 :            :   /* We can't use an alias if there are virtual bases.  */
     224                 :    2176530 :   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     225                 :            :     return false;
     226                 :    2164640 :   gcc_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn));
     227                 :            :   /* Don't use aliases for weak/linkonce definitions unless we can put both
     228                 :            :      symbols in the same COMDAT group.  */
     229                 :    2164640 :   return (DECL_INTERFACE_KNOWN (fn)
     230                 :    2164640 :           && (SUPPORTS_ONE_ONLY || !DECL_WEAK (fn))
     231                 :    2164640 :           && (!DECL_ONE_ONLY (fn)
     232                 :    1985470 :               || (HAVE_COMDAT_GROUP && DECL_WEAK (fn))));
     233                 :            : }
     234                 :            : 
     235                 :            : /* FN is a [cd]tor, fns is a pointer to an array of length 3.  Fill fns
     236                 :            :    with pointers to the base, complete, and deleting variants.  */
     237                 :            : 
     238                 :            : static void
     239                 :    2176910 : populate_clone_array (tree fn, tree *fns)
     240                 :            : {
     241                 :    2176910 :   tree clone;
     242                 :            : 
     243                 :    2176910 :   fns[0] = NULL_TREE;
     244                 :    2176910 :   fns[1] = NULL_TREE;
     245                 :    2176910 :   fns[2] = NULL_TREE;
     246                 :            : 
     247                 :    2176910 :   tree ctx = DECL_CONTEXT (fn);
     248                 :            : 
     249                 :   12904500 :   FOR_EACH_CLONE (clone, fn)
     250                 :    4452970 :     if (DECL_NAME (clone) == complete_dtor_identifier
     251                 :    4452970 :         || DECL_NAME (clone) == complete_ctor_identifier)
     252                 :    2176900 :       fns[1] = clone;
     253                 :    2276070 :     else if (DECL_NAME (clone) == base_dtor_identifier
     254                 :    2276070 :              || DECL_NAME (clone) == base_ctor_identifier)
     255                 :            :       {
     256                 :            :         /* We don't need to define the base variants for a final class.  */
     257                 :    2177680 :         if (!CLASSTYPE_FINAL (ctx))
     258                 :    2144400 :           fns[0] = clone;
     259                 :            :       }
     260                 :      99175 :     else if (DECL_NAME (clone) == deleting_dtor_identifier)
     261                 :      99175 :       fns[2] = clone;
     262                 :            :     else
     263                 :          0 :       gcc_unreachable ();
     264                 :    2176910 : }
     265                 :            : 
     266                 :            : /* FN is a constructor or destructor, and there are FUNCTION_DECLs
     267                 :            :    cloned from it nearby.  Instead of cloning this body, leave it
     268                 :            :    alone and create tiny one-call bodies for the cloned
     269                 :            :    FUNCTION_DECLs.  These clones are sibcall candidates, and their
     270                 :            :    resulting code will be very thunk-esque.  */
     271                 :            : 
     272                 :            : static bool
     273                 :      29113 : maybe_thunk_body (tree fn, bool force)
     274                 :            : {
     275                 :      29113 :   tree bind, block, call, clone, clone_result, fn_parm, fn_parm_typelist;
     276                 :      29113 :   tree last_arg, modify, *args;
     277                 :      29113 :   int parmno, vtt_parmno, max_parms;
     278                 :      29113 :   tree fns[3];
     279                 :            : 
     280                 :      29113 :   if (!force && !flag_declone_ctor_dtor)
     281                 :            :     return 0;
     282                 :            : 
     283                 :            :   /* If function accepts variable arguments, give up.  */
     284                 :        774 :   last_arg = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fn)));
     285                 :        387 :   if (last_arg != void_list_node)
     286                 :            :     return 0;
     287                 :            : 
     288                 :            :   /* If we got this far, we've decided to turn the clones into thunks.  */
     289                 :            : 
     290                 :            :   /* We're going to generate code for fn, so it is no longer "abstract."
     291                 :            :      Also make the unified ctor/dtor private to either the translation unit
     292                 :            :      (for non-vague linkage ctors) or the COMDAT group (otherwise).  */
     293                 :            : 
     294                 :        387 :   populate_clone_array (fn, fns);
     295                 :            : 
     296                 :            :   /* Can happen during error recovery (c++/71464).  */
     297                 :        387 :   if (!fns[0] || !fns[1])
     298                 :            :     return 0;
     299                 :            : 
     300                 :            :   /* Don't use thunks if the base clone omits inherited parameters.  */
     301                 :        386 :   if (ctor_omit_inherited_parms (fns[0]))
     302                 :            :     return 0;
     303                 :            : 
     304                 :        386 :   DECL_ABSTRACT_P (fn) = false;
     305                 :        386 :   if (!DECL_WEAK (fn))
     306                 :            :     {
     307                 :         85 :       TREE_PUBLIC (fn) = false;
     308                 :         85 :       DECL_EXTERNAL (fn) = false;
     309                 :         85 :       DECL_INTERFACE_KNOWN (fn) = true;
     310                 :            :     }
     311                 :        301 :   else if (HAVE_COMDAT_GROUP)
     312                 :            :     {
     313                 :            :       /* At eof, defer creation of mangling aliases temporarily.  */
     314                 :        301 :       bool save_defer_mangling_aliases = defer_mangling_aliases;
     315                 :        301 :       defer_mangling_aliases = true;
     316                 :        301 :       tree comdat_group = cdtor_comdat_group (fns[1], fns[0]);
     317                 :        301 :       defer_mangling_aliases = save_defer_mangling_aliases;
     318                 :        301 :       cgraph_node::get_create (fns[0])->set_comdat_group (comdat_group);
     319                 :        301 :       cgraph_node::get_create (fns[1])->add_to_same_comdat_group
     320                 :        301 :         (cgraph_node::get_create (fns[0]));
     321                 :        301 :       symtab_node::get (fn)->add_to_same_comdat_group
     322                 :        301 :         (symtab_node::get (fns[0]));
     323                 :        301 :       if (fns[2])
     324                 :            :         /* If *[CD][12]* dtors go into the *[CD]5* comdat group and dtor is
     325                 :            :            virtual, it goes into the same comdat group as well.  */
     326                 :         41 :         cgraph_node::get_create (fns[2])->add_to_same_comdat_group
     327                 :         41 :           (symtab_node::get (fns[0]));
     328                 :            :       /* Emit them now that the thunks are same comdat group aliases.  */
     329                 :        301 :       if (!save_defer_mangling_aliases)
     330                 :          0 :         generate_mangling_aliases ();
     331                 :        301 :       TREE_PUBLIC (fn) = false;
     332                 :        301 :       DECL_EXTERNAL (fn) = false;
     333                 :        301 :       DECL_INTERFACE_KNOWN (fn) = true;
     334                 :            :       /* function_and_variable_visibility doesn't want !PUBLIC decls to
     335                 :            :          have these flags set.  */
     336                 :        301 :       DECL_WEAK (fn) = false;
     337                 :        301 :       DECL_COMDAT (fn) = false;
     338                 :            :     }
     339                 :            : 
     340                 :            :   /* Find the vtt_parm, if present.  */
     341                 :       1151 :   for (vtt_parmno = -1, parmno = 0, fn_parm = DECL_ARGUMENTS (fn);
     342                 :       1151 :        fn_parm;
     343                 :        765 :        ++parmno, fn_parm = TREE_CHAIN (fn_parm))
     344                 :            :     {
     345                 :       1097 :       if (DECL_ARTIFICIAL (fn_parm)
     346                 :       2147 :           && DECL_NAME (fn_parm) == vtt_parm_identifier)
     347                 :            :         {
     348                 :            :           /* Compensate for removed in_charge parameter.  */
     349                 :            :           vtt_parmno = parmno;
     350                 :            :           break;
     351                 :            :         }
     352                 :            :     }
     353                 :            : 
     354                 :            :   /* Allocate an argument buffer for build_cxx_call().
     355                 :            :      Make sure it is large enough for any of the clones.  */
     356                 :        386 :   max_parms = 0;
     357                 :       2382 :   FOR_EACH_CLONE (clone, fn)
     358                 :            :     {
     359                 :        823 :       int length = list_length (DECL_ARGUMENTS (fn));
     360                 :        823 :       if (length > max_parms)
     361                 :            :         max_parms = length;
     362                 :            :     }
     363                 :        386 :   args = XALLOCAVEC (tree, max_parms);
     364                 :            : 
     365                 :            :   /* We know that any clones immediately follow FN in TYPE_FIELDS.  */
     366                 :       2768 :   FOR_EACH_CLONE (clone, fn)
     367                 :            :     {
     368                 :        823 :       tree clone_parm;
     369                 :            : 
     370                 :            :       /* If we've already generated a body for this clone, avoid
     371                 :            :          duplicating it.  (Is it possible for a clone-list to grow after we
     372                 :            :          first see it?)  */
     373                 :        823 :       if (DECL_SAVED_TREE (clone) || TREE_ASM_WRITTEN (clone))
     374                 :          0 :         continue;
     375                 :            : 
     376                 :            :       /* Start processing the function.  */
     377                 :        823 :       start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
     378                 :            : 
     379                 :        823 :       if (clone == fns[2])
     380                 :            :         {
     381                 :        102 :           for (clone_parm = DECL_ARGUMENTS (clone); clone_parm;
     382                 :         51 :                clone_parm = TREE_CHAIN (clone_parm))
     383                 :         51 :             DECL_ABSTRACT_ORIGIN (clone_parm) = NULL_TREE;
     384                 :            :           /* Build the delete destructor by calling complete destructor and
     385                 :            :              delete function.  */
     386                 :         51 :           build_delete_destructor_body (clone, fns[1]);
     387                 :            :         }
     388                 :            :       else
     389                 :            :         {
     390                 :            :           /* Walk parameter lists together, creating parameter list for
     391                 :            :              call to original function.  */
     392                 :       3008 :           for (parmno = 0,
     393                 :        772 :                  fn_parm = DECL_ARGUMENTS (fn),
     394                 :       1544 :                  fn_parm_typelist = TYPE_ARG_TYPES (TREE_TYPE (fn)),
     395                 :        772 :                  clone_parm = DECL_ARGUMENTS (clone);
     396                 :       3008 :                fn_parm;
     397                 :            :                ++parmno,
     398                 :       2236 :                  fn_parm = TREE_CHAIN (fn_parm))
     399                 :            :             {
     400                 :       2900 :               if (parmno == vtt_parmno && ! DECL_HAS_VTT_PARM_P (clone))
     401                 :            :                 {
     402                 :        332 :                   gcc_assert (fn_parm_typelist);
     403                 :            :                   /* Clobber argument with formal parameter type.  */
     404                 :        664 :                   args[parmno]
     405                 :        332 :                     = convert (TREE_VALUE (fn_parm_typelist),
     406                 :            :                                null_pointer_node);
     407                 :            :                 }
     408                 :       2656 :               else if (parmno == 1 && DECL_HAS_IN_CHARGE_PARM_P (fn))
     409                 :            :                 {
     410                 :        664 :                   tree in_charge
     411                 :        664 :                     = copy_node (in_charge_arg_for_name (DECL_NAME (clone)));
     412                 :        664 :                   args[parmno] = in_charge;
     413                 :            :                 }
     414                 :            :               /* Map other parameters to their equivalents in the cloned
     415                 :            :                  function.  */
     416                 :            :               else
     417                 :            :                 {
     418                 :       1240 :                   gcc_assert (clone_parm);
     419                 :       1240 :                   DECL_ABSTRACT_ORIGIN (clone_parm) = NULL;
     420                 :       1240 :                   args[parmno] = clone_parm;
     421                 :            :                   /* Clear TREE_ADDRESSABLE on thunk arguments.  */
     422                 :       1240 :                   TREE_ADDRESSABLE (clone_parm) = 0;
     423                 :       1240 :                   clone_parm = TREE_CHAIN (clone_parm);
     424                 :            :                 }
     425                 :       2236 :               if (fn_parm_typelist)
     426                 :       2236 :                 fn_parm_typelist = TREE_CHAIN (fn_parm_typelist);
     427                 :            :             }
     428                 :            : 
     429                 :            :           /* We built this list backwards; fix now.  */
     430                 :        772 :           mark_used (fn);
     431                 :        772 :           call = build_cxx_call (fn, parmno, args, tf_warning_or_error);
     432                 :            :           /* Arguments passed to the thunk by invisible reference should
     433                 :            :              be transmitted to the callee unchanged.  Do not create a
     434                 :            :              temporary and invoke the copy constructor.  The thunking
     435                 :            :              transformation must not introduce any constructor calls.  */
     436                 :        772 :           CALL_FROM_THUNK_P (call) = 1;
     437                 :        772 :           block = make_node (BLOCK);
     438                 :        772 :           if (targetm.cxx.cdtor_returns_this ())
     439                 :            :             {
     440                 :          0 :               clone_result = DECL_RESULT (clone);
     441                 :          0 :               modify = build2 (MODIFY_EXPR, TREE_TYPE (clone_result),
     442                 :            :                                clone_result, call);
     443                 :          0 :               modify = build1 (RETURN_EXPR, void_type_node, modify);
     444                 :          0 :               add_stmt (modify);
     445                 :            :             }
     446                 :            :           else
     447                 :            :             {
     448                 :        772 :               add_stmt (call);
     449                 :            :             }
     450                 :        772 :           bind = c_build_bind_expr (DECL_SOURCE_LOCATION (clone),
     451                 :        772 :                                     block, cur_stmt_list);
     452                 :        772 :           DECL_SAVED_TREE (clone) = push_stmt_list ();
     453                 :        772 :           add_stmt (bind);
     454                 :            :         }
     455                 :            : 
     456                 :        823 :       DECL_ABSTRACT_ORIGIN (clone) = NULL;
     457                 :        823 :       expand_or_defer_fn (finish_function (/*inline_p=*/false));
     458                 :            :     }
     459                 :            :   return 1;
     460                 :            : }
     461                 :            : 
     462                 :            : /* FN is a function that has a complete body.  Clone the body as
     463                 :            :    necessary.  Returns nonzero if there's no longer any need to
     464                 :            :    process the main body.  */
     465                 :            : 
     466                 :            : bool
     467                 :   14116800 : maybe_clone_body (tree fn)
     468                 :            : {
     469                 :   14116800 :   tree comdat_group = NULL_TREE;
     470                 :   14116800 :   tree clone;
     471                 :   14116800 :   tree fns[3];
     472                 :   14116800 :   bool first = true;
     473                 :   14116800 :   int idx;
     474                 :   14116800 :   bool need_alias = false;
     475                 :            : 
     476                 :            :   /* We only clone constructors and destructors.  */
     477                 :   14116800 :   if (!DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
     478                 :            :     return 0;
     479                 :            : 
     480                 :    2176530 :   populate_clone_array (fn, fns);
     481                 :            : 
     482                 :            :   /* Remember if we can't have multiple clones for some reason.  We need to
     483                 :            :      check this before we remap local static initializers in clone_body.  */
     484                 :    2176530 :   if (!tree_versionable_function_p (fn) && fns[0] && fns[1])
     485                 :            :     need_alias = true;
     486                 :            : 
     487                 :            :   /* We know that any clones immediately follow FN in the TYPE_FIELDS
     488                 :            :      list.  */
     489                 :    2176530 :   push_to_top_level ();
     490                 :    8706110 :   for (idx = 0; idx < 3; idx++)
     491                 :            :     {
     492                 :    6529580 :       tree parm;
     493                 :    6529580 :       tree clone_parm;
     494                 :            : 
     495                 :    6529580 :       clone = fns[idx];
     496                 :    6529580 :       if (!clone)
     497                 :    2109930 :         continue;      
     498                 :            : 
     499                 :            :       /* Update CLONE's source position information to match FN's.  */
     500                 :    4419650 :       DECL_SOURCE_LOCATION (clone) = DECL_SOURCE_LOCATION (fn);
     501                 :    4419650 :       DECL_DECLARED_INLINE_P (clone) = DECL_DECLARED_INLINE_P (fn);
     502                 :   13259000 :       DECL_DECLARED_CONSTEXPR_P (clone) = DECL_DECLARED_CONSTEXPR_P (fn);
     503                 :    4419650 :       DECL_COMDAT (clone) = DECL_COMDAT (fn);
     504                 :    4419650 :       DECL_WEAK (clone) = DECL_WEAK (fn);
     505                 :            : 
     506                 :            :       /* We don't copy the comdat group from fn to clone because the assembler
     507                 :            :          name of fn was corrupted by write_mangled_name by adding *INTERNAL*
     508                 :            :          to it. By doing so, it also corrupted the comdat group. */
     509                 :    4419650 :       if (DECL_ONE_ONLY (fn))
     510                 :    4041510 :         cgraph_node::get_create (clone)->set_comdat_group (cxx_comdat_group (clone));
     511                 :    4419650 :       DECL_USE_TEMPLATE (clone) = DECL_USE_TEMPLATE (fn);
     512                 :    4419650 :       DECL_EXTERNAL (clone) = DECL_EXTERNAL (fn);
     513                 :    4419650 :       DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn);
     514                 :    4419650 :       DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
     515                 :    4419650 :       TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
     516                 :    4419650 :       DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
     517                 :    4419650 :       DECL_VISIBILITY_SPECIFIED (clone) = DECL_VISIBILITY_SPECIFIED (fn);
     518                 :    4419650 :       DECL_DLLIMPORT_P (clone) = DECL_DLLIMPORT_P (fn);
     519                 :    4419650 :       DECL_ATTRIBUTES (clone) = copy_list (DECL_ATTRIBUTES (fn));
     520                 :    4419650 :       DECL_DISREGARD_INLINE_LIMITS (clone) = DECL_DISREGARD_INLINE_LIMITS (fn);
     521                 :    4419650 :       set_decl_section_name (clone, DECL_SECTION_NAME (fn));
     522                 :            : 
     523                 :            :       /* Adjust the parameter names and locations.  */
     524                 :    4419650 :       parm = DECL_ARGUMENTS (fn);
     525                 :    4419650 :       clone_parm = DECL_ARGUMENTS (clone);
     526                 :            :       /* Update the `this' parameter, which is always first.  */
     527                 :    4419650 :       update_cloned_parm (parm, clone_parm, first);
     528                 :    4419650 :       parm = DECL_CHAIN (parm);
     529                 :    4419650 :       clone_parm = DECL_CHAIN (clone_parm);
     530                 :    8839300 :       if (DECL_HAS_IN_CHARGE_PARM_P (fn))
     531                 :    1354980 :         parm = DECL_CHAIN (parm);
     532                 :    4419650 :       if (DECL_HAS_VTT_PARM_P (fn))
     533                 :      27600 :         parm = DECL_CHAIN (parm);
     534                 :    8839300 :       if (DECL_HAS_VTT_PARM_P (clone))
     535                 :      11870 :         clone_parm = DECL_CHAIN (clone_parm);
     536                 :    9671170 :       for (; parm && clone_parm;
     537                 :    2625760 :            parm = DECL_CHAIN (parm), clone_parm = DECL_CHAIN (clone_parm))
     538                 :            :         /* Update this parameter.  */
     539                 :    2625760 :         update_cloned_parm (parm, clone_parm, first);
     540                 :            :     }
     541                 :            : 
     542                 :    2176530 :   bool can_alias = can_alias_cdtor (fn);
     543                 :            : 
     544                 :            :   /* If we decide to turn clones into thunks, they will branch to fn.
     545                 :            :      Must have original function available to call.  */
     546                 :    2176530 :   if (!can_alias && maybe_thunk_body (fn, need_alias))
     547                 :            :     {
     548                 :        386 :       pop_from_top_level ();
     549                 :            :       /* We still need to emit the original function.  */
     550                 :        386 :       return 0;
     551                 :            :     }
     552                 :            : 
     553                 :            :   /* Emit the DWARF1 abstract instance.  */
     554                 :    2176140 :   (*debug_hooks->deferred_inline_function) (fn);
     555                 :            : 
     556                 :            :   /* We know that any clones immediately follow FN in the TYPE_FIELDS. */
     557                 :    8704560 :   for (idx = 0; idx < 3; idx++)
     558                 :            :     {
     559                 :    6528420 :       tree parm;
     560                 :    6528420 :       tree clone_parm;
     561                 :    6528420 :       int parmno;
     562                 :    6528420 :       hash_map<tree, tree> *decl_map;
     563                 :    6528420 :       bool alias = false;
     564                 :            : 
     565                 :    6528420 :       clone = fns[idx];
     566                 :    6528420 :       if (!clone)
     567                 :    2109590 :         continue;
     568                 :            : 
     569                 :            :       /* Start processing the function.  */
     570                 :    4418830 :       start_preparsed_function (clone, NULL_TREE, SF_PRE_PARSED);
     571                 :            : 
     572                 :            :       /* Tell cgraph if both ctors or both dtors are known to have
     573                 :            :          the same body.  */
     574                 :    4418830 :       if (can_alias
     575                 :    4357590 :           && fns[0]
     576                 :    4312090 :           && idx == 1
     577                 :    8648660 :           && cgraph_node::get_create (fns[0])->create_same_body_alias
     578                 :    2114920 :                (clone, fns[0]))
     579                 :            :         {
     580                 :    2114920 :           alias = true;
     581                 :    2114920 :           if (DECL_ONE_ONLY (fns[0]))
     582                 :            :             {
     583                 :            :               /* For comdat base and complete cdtors put them
     584                 :            :                  into the same, *[CD]5* comdat group instead of
     585                 :            :                  *[CD][12]*.  */
     586                 :    1953080 :               comdat_group = cdtor_comdat_group (fns[1], fns[0]);
     587                 :    1953080 :               cgraph_node::get_create (fns[0])->set_comdat_group (comdat_group);
     588                 :    1953080 :               if (symtab_node::get (clone)->same_comdat_group)
     589                 :    1708170 :                 symtab_node::get (clone)->remove_from_same_comdat_group ();
     590                 :    1953080 :               symtab_node::get (clone)->add_to_same_comdat_group
     591                 :    1953080 :                 (symtab_node::get (fns[0]));
     592                 :            :             }
     593                 :            :         }
     594                 :            : 
     595                 :            :       /* Build the delete destructor by calling complete destructor
     596                 :            :          and delete function.  */
     597                 :    4418830 :       if (idx == 2)
     598                 :            :         {
     599                 :      99073 :           build_delete_destructor_body (clone, fns[1]);
     600                 :            :           /* If *[CD][12]* dtors go into the *[CD]5* comdat group and dtor is
     601                 :            :              virtual, it goes into the same comdat group as well.  */
     602                 :      99073 :           if (comdat_group)
     603                 :      78151 :             cgraph_node::get_create (clone)->add_to_same_comdat_group
     604                 :      78151 :               (symtab_node::get (fns[0]));
     605                 :            :         }
     606                 :    4319760 :       else if (alias)
     607                 :            :         /* No need to populate body.  */ ;
     608                 :            :       else
     609                 :            :         {
     610                 :            :           /* If we can't have multiple copies of FN (say, because there's a
     611                 :            :              static local initialized with the address of a label), we need
     612                 :            :              to use an alias for the complete variant.  */
     613                 :    2204840 :           if (idx == 1 && need_alias)
     614                 :            :             {
     615                 :          0 :               if (DECL_STRUCT_FUNCTION (fn)->cannot_be_copied_set)
     616                 :          0 :                 sorry (DECL_STRUCT_FUNCTION (fn)->cannot_be_copied_reason, fn);
     617                 :            :               else
     618                 :          0 :                 sorry ("making multiple clones of %qD", fn);
     619                 :            :             }
     620                 :            : 
     621                 :            :           /* Remap the parameters.  */
     622                 :    2204840 :           decl_map = new hash_map<tree, tree>;
     623                 :    2204840 :           for (parmno = 0,
     624                 :    2204840 :                 parm = DECL_ARGUMENTS (fn),
     625                 :    2204840 :                 clone_parm = DECL_ARGUMENTS (clone);
     626                 :    6420370 :               parm;
     627                 :            :               ++parmno,
     628                 :    4215530 :                 parm = DECL_CHAIN (parm))
     629                 :            :             {
     630                 :            :               /* Map the in-charge parameter to an appropriate constant.  */
     631                 :    8431060 :               if (DECL_HAS_IN_CHARGE_PARM_P (fn) && parmno == 1)
     632                 :            :                 {
     633                 :     648779 :                   tree in_charge;
     634                 :     648779 :                   in_charge = in_charge_arg_for_name (DECL_NAME (clone));
     635                 :     648779 :                   decl_map->put (parm, in_charge);
     636                 :            :                 }
     637                 :    3566750 :               else if (DECL_ARTIFICIAL (parm)
     638                 :    3566750 :                        && DECL_NAME (parm) == vtt_parm_identifier)
     639                 :            :                 {
     640                 :            :                   /* For a subobject constructor or destructor, the next
     641                 :            :                      argument is the VTT parameter.  Remap the VTT_PARM
     642                 :            :                      from the CLONE to this parameter.  */
     643                 :      46164 :                   if (DECL_HAS_VTT_PARM_P (clone))
     644                 :            :                     {
     645                 :      11538 :                       DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
     646                 :      11538 :                       decl_map->put (parm, clone_parm);
     647                 :      11538 :                       clone_parm = DECL_CHAIN (clone_parm);
     648                 :            :                     }
     649                 :            :                   /* Otherwise, map the VTT parameter to `NULL'.  */
     650                 :            :                   else
     651                 :            :                     {
     652                 :      11544 :                       tree t
     653                 :      11544 :                         = fold_convert (TREE_TYPE (parm), null_pointer_node);
     654                 :      11544 :                       decl_map->put (parm, t);
     655                 :            :                     }
     656                 :            :                 }
     657                 :            :               /* Map other parameters to their equivalents in the cloned
     658                 :            :                  function.  */
     659                 :            :               else
     660                 :            :                 {
     661                 :    3543670 :                   tree replacement;
     662                 :    3543670 :                   if (clone_parm)
     663                 :            :                     {
     664                 :    3543640 :                       replacement = clone_parm;
     665                 :    3543640 :                       clone_parm = DECL_CHAIN (clone_parm);
     666                 :            :                     }
     667                 :            :                   else
     668                 :            :                     {
     669                 :            :                       /* Inheriting ctors can omit parameters from the base
     670                 :            :                          clone.  Replace them with null lvalues.  */
     671                 :         24 :                       tree reftype = build_reference_type (TREE_TYPE (parm));
     672                 :         24 :                       replacement = fold_convert (reftype, null_pointer_node);
     673                 :         24 :                       replacement = convert_from_reference (replacement);
     674                 :            :                     }
     675                 :    3543670 :                   decl_map->put (parm, replacement);
     676                 :            :                 }
     677                 :            :             }
     678                 :            : 
     679                 :    2204840 :           if (targetm.cxx.cdtor_returns_this ())
     680                 :            :             {
     681                 :          0 :               parm = DECL_RESULT (fn);
     682                 :          0 :               clone_parm = DECL_RESULT (clone);
     683                 :          0 :               decl_map->put (parm, clone_parm);
     684                 :            :             }
     685                 :            : 
     686                 :            :           /* Clone the body.  */
     687                 :    2204840 :           clone_body (clone, fn, decl_map);
     688                 :            : 
     689                 :            :           /* Clean up.  */
     690                 :    2204840 :           delete decl_map;
     691                 :            :         }
     692                 :            : 
     693                 :            :       /* The clone can throw iff the original function can throw.  */
     694                 :    4418830 :       cp_function_chain->can_throw = !TREE_NOTHROW (fn);
     695                 :            : 
     696                 :            :       /* Now, expand this function into RTL, if appropriate.  */
     697                 :    4418830 :       finish_function (/*inline_p=*/false);
     698                 :    4418830 :       BLOCK_ABSTRACT_ORIGIN (DECL_INITIAL (clone)) = DECL_INITIAL (fn);
     699                 :    4418830 :       if (alias)
     700                 :            :         {
     701                 :    2114920 :           if (expand_or_defer_fn_1 (clone))
     702                 :    2114540 :             emit_associated_thunks (clone);
     703                 :            :           /* We didn't generate a body, so remove the empty one.  */
     704                 :    2114920 :           DECL_SAVED_TREE (clone) = NULL_TREE;
     705                 :            :         }
     706                 :            :       else
     707                 :    2303910 :         expand_or_defer_fn (clone);
     708                 :    4418830 :       first = false;
     709                 :            :     }
     710                 :    2176140 :   pop_from_top_level ();
     711                 :            : 
     712                 :            :   /* We don't need to process the original function any further.  */
     713                 :    2176140 :   return 1;
     714                 :            : }

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.