LCOV - code coverage report
Current view: top level - gcc/cp - cvt.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 786 1017 77.3 %
Date: 2020-03-28 11:57:23 Functions: 29 31 93.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Language-level data type conversion for GNU C++.
       2                 :            :    Copyright (C) 1987-2020 Free Software Foundation, Inc.
       3                 :            :    Hacked by Michael Tiemann (tiemann@cygnus.com)
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify
       8                 :            : it under the terms of the GNU General Public License as published by
       9                 :            : the Free Software Foundation; either version 3, or (at your option)
      10                 :            : any later version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful,
      13                 :            : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            : GNU General Public License for more details.
      16                 :            : 
      17                 :            : You should have received a copy of the GNU General Public License
      18                 :            : along with GCC; see the file COPYING3.  If not see
      19                 :            : <http://www.gnu.org/licenses/>.  */
      20                 :            : 
      21                 :            : 
      22                 :            : /* This file contains the functions for converting C++ expressions
      23                 :            :    to different data types.  The only entry point is `convert'.
      24                 :            :    Every language front end must have a `convert' function
      25                 :            :    but what kind of conversions it does will depend on the language.  */
      26                 :            : 
      27                 :            : #include "config.h"
      28                 :            : #include "system.h"
      29                 :            : #include "coretypes.h"
      30                 :            : #include "target.h"
      31                 :            : #include "cp-tree.h"
      32                 :            : #include "stor-layout.h"
      33                 :            : #include "flags.h"
      34                 :            : #include "intl.h"
      35                 :            : #include "convert.h"
      36                 :            : #include "stringpool.h"
      37                 :            : #include "attribs.h"
      38                 :            : #include "escaped_string.h"
      39                 :            : 
      40                 :            : static tree convert_to_pointer_force (tree, tree, tsubst_flags_t);
      41                 :            : static tree build_type_conversion (tree, tree);
      42                 :            : static tree build_up_reference (tree, tree, int, tree, tsubst_flags_t);
      43                 :            : static void diagnose_ref_binding (location_t, tree, tree, tree);
      44                 :            : 
      45                 :            : /* Change of width--truncation and extension of integers or reals--
      46                 :            :    is represented with NOP_EXPR.  Proper functioning of many things
      47                 :            :    assumes that no other conversions can be NOP_EXPRs.
      48                 :            : 
      49                 :            :    Conversion between integer and pointer is represented with CONVERT_EXPR.
      50                 :            :    Converting integer to real uses FLOAT_EXPR
      51                 :            :    and real to integer uses FIX_TRUNC_EXPR.
      52                 :            : 
      53                 :            :    Here is a list of all the functions that assume that widening and
      54                 :            :    narrowing is always done with a NOP_EXPR:
      55                 :            :      In convert.c, convert_to_integer[_maybe_fold].
      56                 :            :      In c-typeck.c, build_binary_op_nodefault (boolean ops),
      57                 :            :         and c_common_truthvalue_conversion.
      58                 :            :      In expr.c: expand_expr, for operands of a MULT_EXPR.
      59                 :            :      In fold-const.c: fold.
      60                 :            :      In tree.c: get_narrower and get_unwidened.
      61                 :            : 
      62                 :            :    C++: in multiple-inheritance, converting between pointers may involve
      63                 :            :    adjusting them by a delta stored within the class definition.  */
      64                 :            : 
      65                 :            : /* Subroutines of `convert'.  */
      66                 :            : 
      67                 :            : /* if converting pointer to pointer
      68                 :            :      if dealing with classes, check for derived->base or vice versa
      69                 :            :      else if dealing with method pointers, delegate
      70                 :            :      else convert blindly
      71                 :            :    else if converting class, pass off to build_type_conversion
      72                 :            :    else try C-style pointer conversion.  */
      73                 :            : 
      74                 :            : static tree
      75                 :    5425170 : cp_convert_to_pointer (tree type, tree expr, bool dofold,
      76                 :            :                        tsubst_flags_t complain)
      77                 :            : {
      78                 :    5425170 :   tree intype = TREE_TYPE (expr);
      79                 :    5425170 :   enum tree_code form;
      80                 :    5425170 :   tree rval;
      81                 :    5425170 :   location_t loc = cp_expr_loc_or_input_loc (expr);
      82                 :            : 
      83                 :    5425170 :   if (intype == error_mark_node)
      84                 :            :     return error_mark_node;
      85                 :            : 
      86                 :    5425200 :   if (MAYBE_CLASS_TYPE_P (intype))
      87                 :            :     {
      88                 :          4 :       intype = complete_type (intype);
      89                 :          4 :       if (!COMPLETE_TYPE_P (intype))
      90                 :            :         {
      91                 :          0 :           if (complain & tf_error)
      92                 :          0 :             error_at (loc, "cannot convert from incomplete type %qH to %qI",
      93                 :            :                       intype, type);
      94                 :          0 :           return error_mark_node;
      95                 :            :         }
      96                 :            : 
      97                 :          8 :       rval = build_type_conversion (type, expr);
      98                 :          4 :       if (rval)
      99                 :            :         {
     100                 :          0 :           if ((complain & tf_error)
     101                 :          0 :               && rval == error_mark_node)
     102                 :          0 :             error_at (loc, "conversion of %qE from %qH to %qI is ambiguous",
     103                 :            :                       expr, intype, type);
     104                 :          0 :           return rval;
     105                 :            :         }
     106                 :            :     }
     107                 :            : 
     108                 :            :   /* Handle anachronistic conversions from (::*)() to cv void* or (*)().  */
     109                 :    5425170 :   if (TYPE_PTR_P (type)
     110                 :   10844000 :       && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
     111                 :    5410240 :           || VOID_TYPE_P (TREE_TYPE (type))))
     112                 :            :     {
     113                 :         16 :       if (TYPE_PTRMEMFUNC_P (intype)
     114                 :     595604 :           || TREE_CODE (intype) == METHOD_TYPE)
     115                 :         12 :         return convert_member_func_to_ptr (type, expr, complain);
     116                 :     595588 :       if (TYPE_PTR_P (TREE_TYPE (expr)))
     117                 :     422122 :         return build_nop (type, expr);
     118                 :    5003030 :       intype = TREE_TYPE (expr);
     119                 :            :     }
     120                 :            : 
     121                 :    5003030 :   if (expr == error_mark_node)
     122                 :            :     return error_mark_node;
     123                 :            : 
     124                 :    5003030 :   form = TREE_CODE (intype);
     125                 :            : 
     126                 :    5003030 :   if (INDIRECT_TYPE_P (intype))
     127                 :            :     {
     128                 :    3437300 :       intype = TYPE_MAIN_VARIANT (intype);
     129                 :            : 
     130                 :    3437300 :       if (TYPE_MAIN_VARIANT (type) != intype
     131                 :    2356780 :           && TYPE_PTR_P (type)
     132                 :    2351860 :           && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
     133                 :     931851 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (type))
     134                 :     867804 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (intype))
     135                 :    4295450 :           && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE)
     136                 :            :         {
     137                 :     858150 :           enum tree_code code = PLUS_EXPR;
     138                 :     858150 :           tree binfo;
     139                 :     858150 :           tree intype_class;
     140                 :     858150 :           tree type_class;
     141                 :     858150 :           bool same_p;
     142                 :            : 
     143                 :     858150 :           intype_class = TREE_TYPE (intype);
     144                 :     858150 :           type_class = TREE_TYPE (type);
     145                 :            : 
     146                 :     858150 :           same_p = same_type_p (TYPE_MAIN_VARIANT (intype_class),
     147                 :            :                                 TYPE_MAIN_VARIANT (type_class));
     148                 :     858150 :           binfo = NULL_TREE;
     149                 :            :           /* Try derived to base conversion.  */
     150                 :     858150 :           if (!same_p)
     151                 :       2862 :             binfo = lookup_base (intype_class, type_class, ba_check,
     152                 :            :                                  NULL, complain);
     153                 :     858150 :           if (!same_p && !binfo)
     154                 :            :             {
     155                 :            :               /* Try base to derived conversion.  */
     156                 :         20 :               binfo = lookup_base (type_class, intype_class, ba_check,
     157                 :            :                                    NULL, complain);
     158                 :         20 :               code = MINUS_EXPR;
     159                 :            :             }
     160                 :     858150 :           if (binfo == error_mark_node)
     161                 :            :             return error_mark_node;
     162                 :     858141 :           if (binfo || same_p)
     163                 :            :             {
     164                 :     858141 :               if (binfo)
     165                 :       2853 :                 expr = build_base_path (code, expr, binfo, 0, complain);
     166                 :            :               /* Add any qualifier conversions.  */
     167                 :     858141 :               return build_nop (type, expr);
     168                 :            :             }
     169                 :            :         }
     170                 :            : 
     171                 :    2579150 :       if (TYPE_PTRMEMFUNC_P (type))
     172                 :            :         {
     173                 :          0 :           if (complain & tf_error)
     174                 :          0 :             error_at (loc, "cannot convert %qE from type %qH to type %qI",
     175                 :            :                       expr, intype, type);
     176                 :          0 :           return error_mark_node;
     177                 :            :         }
     178                 :            : 
     179                 :    2579150 :       return build_nop (type, expr);
     180                 :            :     }
     181                 :        997 :   else if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
     182                 :    1566620 :            || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
     183                 :        138 :     return convert_ptrmem (type, expr, /*allow_inverse_p=*/false,
     184                 :        138 :                            /*c_cast_p=*/false, complain);
     185                 :    1565600 :   else if (TYPE_PTRMEMFUNC_P (intype))
     186                 :            :     {
     187                 :          0 :       if (!warn_pmf2ptr)
     188                 :            :         {
     189                 :          0 :           if (TREE_CODE (expr) == PTRMEM_CST)
     190                 :          0 :             return cp_convert_to_pointer (type, PTRMEM_CST_MEMBER (expr),
     191                 :          0 :                                           dofold, complain);
     192                 :          0 :           else if (TREE_CODE (expr) == OFFSET_REF)
     193                 :            :             {
     194                 :          0 :               tree object = TREE_OPERAND (expr, 0);
     195                 :          0 :               return get_member_function_from_ptrfunc (&object,
     196                 :          0 :                                                        TREE_OPERAND (expr, 1),
     197                 :            :                                                        complain);
     198                 :            :             }
     199                 :            :         }
     200                 :          0 :       if (complain & tf_error)
     201                 :          0 :         error_at (loc, "cannot convert %qE from type %qH to type %qI",
     202                 :            :                   expr, intype, type);
     203                 :          0 :       return error_mark_node;
     204                 :            :     }
     205                 :            : 
     206                 :    1565600 :   if (null_ptr_cst_p (expr))
     207                 :            :     {
     208                 :    1308500 :       if (TYPE_PTRMEMFUNC_P (type))
     209                 :        414 :         return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
     210                 :        414 :                                  /*c_cast_p=*/false, complain);
     211                 :            : 
     212                 :    1308080 :       if (complain & tf_warning)
     213                 :     981184 :         maybe_warn_zero_as_null_pointer_constant (expr, loc);
     214                 :            : 
     215                 :            :       /* A NULL pointer-to-data-member is represented by -1, not by
     216                 :            :          zero.  */
     217                 :    1308080 :       tree val = (TYPE_PTRDATAMEM_P (type)
     218                 :    1308080 :                   ? build_int_cst_type (type, -1)
     219                 :    1307200 :                   : build_int_cst (type, 0));
     220                 :            : 
     221                 :    1308080 :       return (TREE_SIDE_EFFECTS (expr)
     222                 :    1308080 :               ? build2 (COMPOUND_EXPR, type, expr, val) : val);
     223                 :            :     }
     224                 :     257103 :   else if (TYPE_PTRMEM_P (type) && INTEGRAL_CODE_P (form))
     225                 :            :     {
     226                 :          0 :       if (complain & tf_error)
     227                 :          0 :         error_at (loc, "invalid conversion from %qH to %qI", intype, type);
     228                 :          0 :       return error_mark_node;
     229                 :            :     }
     230                 :            : 
     231                 :     257103 :   if (INTEGRAL_CODE_P (form))
     232                 :            :     {
     233                 :     264346 :       if (TYPE_PRECISION (intype) == POINTER_SIZE)
     234                 :     242903 :         return build1 (CONVERT_EXPR, type, expr);
     235                 :      14309 :       expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr,
     236                 :            :                          complain);
     237                 :            :       /* Modes may be different but sizes should be the same.  There
     238                 :            :          is supposed to be some integral type that is the same width
     239                 :            :          as a pointer.  */
     240                 :      42567 :       gcc_assert (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (expr)))
     241                 :            :                   == GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (type)));
     242                 :            : 
     243                 :            :       /* FIXME needed because convert_to_pointer_maybe_fold still folds
     244                 :            :          conversion of constants.  */
     245                 :      14189 :       if (!dofold)
     246                 :      14189 :         return build1 (CONVERT_EXPR, type, expr);
     247                 :            : 
     248                 :          0 :       return convert_to_pointer_maybe_fold (type, expr, dofold);
     249                 :            :     }
     250                 :            : 
     251                 :         11 :   if (type_unknown_p (expr))
     252                 :          0 :     return instantiate_type (type, expr, complain);
     253                 :            : 
     254                 :         11 :   if (complain & tf_error)
     255                 :         11 :     error_at (loc, "cannot convert %qE from type %qH to type %qI",
     256                 :            :               expr, intype, type);
     257                 :         11 :   return error_mark_node;
     258                 :            : }
     259                 :            : 
     260                 :            : /* Like convert, except permit conversions to take place which
     261                 :            :    are not normally allowed due to access restrictions
     262                 :            :    (such as conversion from sub-type to private super-type).  */
     263                 :            : 
     264                 :            : static tree
     265                 :    1567600 : convert_to_pointer_force (tree type, tree expr, tsubst_flags_t complain)
     266                 :            : {
     267                 :    1567600 :   tree intype = TREE_TYPE (expr);
     268                 :    1567600 :   enum tree_code form = TREE_CODE (intype);
     269                 :            : 
     270                 :    1567600 :   if (form == POINTER_TYPE)
     271                 :            :     {
     272                 :    1567600 :       intype = TYPE_MAIN_VARIANT (intype);
     273                 :            : 
     274                 :    1567600 :       if (TYPE_MAIN_VARIANT (type) != intype
     275                 :     487064 :           && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
     276                 :     487039 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (type))
     277                 :     487035 :           && MAYBE_CLASS_TYPE_P (TREE_TYPE (intype))
     278                 :    2054640 :           && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE)
     279                 :            :         {
     280                 :     487035 :           enum tree_code code = PLUS_EXPR;
     281                 :     487035 :           tree binfo;
     282                 :            : 
     283                 :     487035 :           binfo = lookup_base (TREE_TYPE (intype), TREE_TYPE (type),
     284                 :            :                                ba_unique, NULL, complain);
     285                 :     487035 :           if (!binfo)
     286                 :            :             {
     287                 :          0 :               binfo = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
     288                 :            :                                    ba_unique, NULL, complain);
     289                 :          0 :               code = MINUS_EXPR;
     290                 :            :             }
     291                 :     487035 :           if (binfo == error_mark_node)
     292                 :            :             return error_mark_node;
     293                 :     487035 :           if (binfo)
     294                 :            :             {
     295                 :     487035 :               expr = build_base_path (code, expr, binfo, 0, complain);
     296                 :     487035 :               if (expr == error_mark_node)
     297                 :            :                  return error_mark_node;
     298                 :            :               /* Add any qualifier conversions.  */
     299                 :     487035 :               if (!same_type_p (TREE_TYPE (TREE_TYPE (expr)),
     300                 :            :                                 TREE_TYPE (type)))
     301                 :     150299 :                 expr = build_nop (type, expr);
     302                 :     487035 :               return expr;
     303                 :            :             }
     304                 :            :         }
     305                 :            :     }
     306                 :            : 
     307                 :    1080570 :   return cp_convert_to_pointer (type, expr, /*fold*/false, complain);
     308                 :            : }
     309                 :            : 
     310                 :            : /* We are passing something to a function which requires a reference.
     311                 :            :    The type we are interested in is in TYPE. The initial
     312                 :            :    value we have to begin with is in ARG.
     313                 :            : 
     314                 :            :    FLAGS controls how we manage access checking.
     315                 :            :    DIRECT_BIND in FLAGS controls how any temporaries are generated.
     316                 :            :      If DIRECT_BIND is set, DECL is the reference we're binding to.  */
     317                 :            : 
     318                 :            : static tree
     319                 :        629 : build_up_reference (tree type, tree arg, int flags, tree decl,
     320                 :            :                     tsubst_flags_t complain)
     321                 :            : {
     322                 :        629 :   tree rval;
     323                 :        629 :   tree argtype = TREE_TYPE (arg);
     324                 :        629 :   tree target_type = TREE_TYPE (type);
     325                 :            : 
     326                 :        629 :   gcc_assert (TYPE_REF_P (type));
     327                 :            : 
     328                 :        629 :   if ((flags & DIRECT_BIND) && ! lvalue_p (arg))
     329                 :            :     {
     330                 :            :       /* Create a new temporary variable.  We can't just use a TARGET_EXPR
     331                 :            :          here because it needs to live as long as DECL.  */
     332                 :          0 :       tree targ = arg;
     333                 :            : 
     334                 :          0 :       arg = make_temporary_var_for_ref_to_temp (decl, target_type);
     335                 :            : 
     336                 :            :       /* Process the initializer for the declaration.  */
     337                 :          0 :       DECL_INITIAL (arg) = targ;
     338                 :          0 :       cp_finish_decl (arg, targ, /*init_const_expr_p=*/false, NULL_TREE,
     339                 :            :                       LOOKUP_ONLYCONVERTING|DIRECT_BIND);
     340                 :            :     }
     341                 :        629 :   else if (!(flags & DIRECT_BIND) && ! obvalue_p (arg))
     342                 :          0 :     return get_target_expr_sfinae (arg, complain);
     343                 :            : 
     344                 :            :   /* If we had a way to wrap this up, and say, if we ever needed its
     345                 :            :      address, transform all occurrences of the register, into a memory
     346                 :            :      reference we could win better.  */
     347                 :        629 :   rval = cp_build_addr_expr (arg, complain);
     348                 :        629 :   if (rval == error_mark_node)
     349                 :            :     return error_mark_node;
     350                 :            : 
     351                 :        629 :   if ((flags & LOOKUP_PROTECT)
     352                 :        629 :       && TYPE_MAIN_VARIANT (argtype) != TYPE_MAIN_VARIANT (target_type)
     353                 :          8 :       && MAYBE_CLASS_TYPE_P (argtype)
     354                 :        637 :       && MAYBE_CLASS_TYPE_P (target_type))
     355                 :            :     {
     356                 :            :       /* We go through lookup_base for the access control.  */
     357                 :          8 :       tree binfo = lookup_base (argtype, target_type, ba_check,
     358                 :            :                                 NULL, complain);
     359                 :          8 :       if (binfo == error_mark_node)
     360                 :            :         return error_mark_node;
     361                 :          8 :       if (binfo == NULL_TREE)
     362                 :          0 :         return error_not_base_type (target_type, argtype);
     363                 :          8 :       rval = build_base_path (PLUS_EXPR, rval, binfo, 1, complain);
     364                 :            :     }
     365                 :            :   else
     366                 :        621 :     rval
     367                 :        621 :       = convert_to_pointer_force (build_pointer_type (target_type),
     368                 :            :                                   rval, complain);
     369                 :        629 :   return build_nop (type, rval);
     370                 :            : }
     371                 :            : 
     372                 :            : /* Subroutine of convert_to_reference. REFTYPE is the target reference type.
     373                 :            :    INTYPE is the original rvalue type and DECL is an optional _DECL node
     374                 :            :    for diagnostics.
     375                 :            : 
     376                 :            :    [dcl.init.ref] says that if an rvalue is used to
     377                 :            :    initialize a reference, then the reference must be to a
     378                 :            :    non-volatile const type.  */
     379                 :            : 
     380                 :            : static void
     381                 :          3 : diagnose_ref_binding (location_t loc, tree reftype, tree intype, tree decl)
     382                 :            : {
     383                 :          3 :   tree ttl = TREE_TYPE (reftype);
     384                 :            : 
     385                 :          3 :   if (!TYPE_REF_IS_RVALUE (reftype)
     386                 :          3 :       && !CP_TYPE_CONST_NON_VOLATILE_P (ttl))
     387                 :            :     {
     388                 :          0 :       const char *msg;
     389                 :            : 
     390                 :          0 :       if (CP_TYPE_VOLATILE_P (ttl) && decl)
     391                 :            :         msg = G_("initialization of volatile reference type %q#T from "
     392                 :            :                  "rvalue of type %qT");
     393                 :          0 :       else if (CP_TYPE_VOLATILE_P (ttl))
     394                 :            :         msg = G_("conversion to volatile reference type %q#T "
     395                 :            :                  "from rvalue of type %qT");
     396                 :          0 :       else if (decl)
     397                 :            :         msg = G_("initialization of non-const reference type %q#T from "
     398                 :            :                  "rvalue of type %qT");
     399                 :            :       else
     400                 :          0 :         msg = G_("conversion to non-const reference type %q#T from "
     401                 :            :                  "rvalue of type %qT");
     402                 :            : 
     403                 :          0 :       permerror (loc, msg, reftype, intype);
     404                 :            :     }
     405                 :          3 : }
     406                 :            : 
     407                 :            : /* For C++: Only need to do one-level references, but cannot
     408                 :            :    get tripped up on signed/unsigned differences.
     409                 :            : 
     410                 :            :    DECL is either NULL_TREE or the _DECL node for a reference that is being
     411                 :            :    initialized.  It can be error_mark_node if we don't know the _DECL but
     412                 :            :    we know it's an initialization.  */
     413                 :            : 
     414                 :            : tree
     415                 :        629 : convert_to_reference (tree reftype, tree expr, int convtype,
     416                 :            :                       int flags, tree decl, tsubst_flags_t complain)
     417                 :            : {
     418                 :        629 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype));
     419                 :        629 :   tree intype;
     420                 :        629 :   tree rval = NULL_TREE;
     421                 :        629 :   tree rval_as_conversion = NULL_TREE;
     422                 :        629 :   bool can_convert_intype_to_type;
     423                 :        629 :   location_t loc = cp_expr_loc_or_input_loc (expr);
     424                 :            : 
     425                 :        629 :   if (TREE_CODE (type) == FUNCTION_TYPE
     426                 :        629 :       && TREE_TYPE (expr) == unknown_type_node)
     427                 :          0 :     expr = instantiate_type (type, expr, complain);
     428                 :            : 
     429                 :        629 :   if (expr == error_mark_node)
     430                 :            :     return error_mark_node;
     431                 :            : 
     432                 :        629 :   intype = TREE_TYPE (expr);
     433                 :            : 
     434                 :        629 :   gcc_assert (!TYPE_REF_P (intype));
     435                 :        629 :   gcc_assert (TYPE_REF_P (reftype));
     436                 :            : 
     437                 :        629 :   intype = TYPE_MAIN_VARIANT (intype);
     438                 :            : 
     439                 :        629 :   can_convert_intype_to_type = can_convert_standard (type, intype, complain);
     440                 :            : 
     441                 :        629 :   if (!can_convert_intype_to_type
     442                 :          0 :       && (convtype & CONV_IMPLICIT) && MAYBE_CLASS_TYPE_P (intype)
     443                 :        629 :       && ! (flags & LOOKUP_NO_CONVERSION))
     444                 :            :     {
     445                 :            :       /* Look for a user-defined conversion to lvalue that we can use.  */
     446                 :            : 
     447                 :          0 :       rval_as_conversion
     448                 :          0 :         = build_type_conversion (reftype, expr);
     449                 :            : 
     450                 :          0 :       if (rval_as_conversion && rval_as_conversion != error_mark_node
     451                 :          0 :           && lvalue_p (rval_as_conversion))
     452                 :            :         {
     453                 :            :           expr = rval_as_conversion;
     454                 :        629 :           rval_as_conversion = NULL_TREE;
     455                 :            :           intype = type;
     456                 :            :           can_convert_intype_to_type = 1;
     457                 :            :         }
     458                 :            :     }
     459                 :            : 
     460                 :        629 :   if (((convtype & CONV_STATIC)
     461                 :         26 :        && can_convert_standard (intype, type, complain))
     462                 :        629 :       || ((convtype & CONV_IMPLICIT) && can_convert_intype_to_type))
     463                 :            :     {
     464                 :        629 :       {
     465                 :        629 :         tree ttl = TREE_TYPE (reftype);
     466                 :        629 :         tree ttr = lvalue_type (expr);
     467                 :            : 
     468                 :        629 :         if ((complain & tf_error)
     469                 :        629 :             && ! lvalue_p (expr))
     470                 :          3 :           diagnose_ref_binding (loc, reftype, intype, decl);
     471                 :            : 
     472                 :        629 :         if (! (convtype & CONV_CONST)
     473                 :        629 :             && !at_least_as_qualified_p (ttl, ttr))
     474                 :            :           {
     475                 :          7 :             if (complain & tf_error)
     476                 :          7 :               permerror (loc, "conversion from %qH to %qI discards qualifiers",
     477                 :            :                          ttr, reftype);
     478                 :            :             else
     479                 :          0 :               return error_mark_node;
     480                 :            :           }
     481                 :            :       }
     482                 :            : 
     483                 :        629 :       return build_up_reference (reftype, expr, flags, decl, complain);
     484                 :            :     }
     485                 :          0 :   else if ((convtype & CONV_REINTERPRET) && obvalue_p (expr))
     486                 :            :     {
     487                 :            :       /* When casting an lvalue to a reference type, just convert into
     488                 :            :          a pointer to the new type and deference it.  This is allowed
     489                 :            :          by San Diego WP section 5.2.9 paragraph 12, though perhaps it
     490                 :            :          should be done directly (jason).  (int &)ri ---> *(int*)&ri */
     491                 :            : 
     492                 :            :       /* B* bp; A& ar = (A&)bp; is valid, but it's probably not what they
     493                 :            :          meant.  */
     494                 :          0 :       if ((complain & tf_warning)
     495                 :          0 :           && TYPE_PTR_P (intype)
     496                 :          0 :           && (comptypes (TREE_TYPE (intype), type,
     497                 :            :                          COMPARE_BASE | COMPARE_DERIVED)))
     498                 :          0 :         warning_at (loc, 0, "casting %qT to %qT does not dereference pointer",
     499                 :            :                     intype, reftype);
     500                 :            : 
     501                 :          0 :       rval = cp_build_addr_expr (expr, complain);
     502                 :          0 :       if (rval != error_mark_node)
     503                 :          0 :         rval = convert_force (build_pointer_type (TREE_TYPE (reftype)),
     504                 :            :                               rval, 0, complain);
     505                 :          0 :       if (rval != error_mark_node)
     506                 :          0 :         rval = build1 (NOP_EXPR, reftype, rval);
     507                 :            :     }
     508                 :            :   else
     509                 :            :     {
     510                 :          0 :       rval = convert_for_initialization (NULL_TREE, type, expr, flags,
     511                 :            :                                          ICR_CONVERTING, 0, 0, complain);
     512                 :          0 :       if (rval == NULL_TREE || rval == error_mark_node)
     513                 :            :         return rval;
     514                 :          0 :       if (complain & tf_error)
     515                 :          0 :         diagnose_ref_binding (loc, reftype, intype, decl);
     516                 :          0 :       rval = build_up_reference (reftype, rval, flags, decl, complain);
     517                 :            :     }
     518                 :            : 
     519                 :          0 :   if (rval)
     520                 :            :     {
     521                 :            :       /* If we found a way to convert earlier, then use it.  */
     522                 :            :       return rval;
     523                 :            :     }
     524                 :            : 
     525                 :          0 :   if (complain & tf_error)
     526                 :          0 :     error_at (loc, "cannot convert type %qH to type %qI", intype, reftype);
     527                 :            : 
     528                 :          0 :   return error_mark_node;
     529                 :            : }
     530                 :            : 
     531                 :            : /* We are using a reference VAL for its value. Bash that reference all the
     532                 :            :    way down to its lowest form.  */
     533                 :            : 
     534                 :            : tree
     535                 :  242323000 : convert_from_reference (tree val)
     536                 :            : {
     537                 :  242323000 :   if (TREE_TYPE (val)
     538                 :  242323000 :       && TYPE_REF_P (TREE_TYPE (val)))
     539                 :            :     {
     540                 :   25916100 :       tree t = TREE_TYPE (TREE_TYPE (val));
     541                 :   25916100 :       tree ref = build1 (INDIRECT_REF, t, val);
     542                 :            : 
     543                 :   25916100 :       mark_exp_read (val);
     544                 :            :        /* We *must* set TREE_READONLY when dereferencing a pointer to const,
     545                 :            :           so that we get the proper error message if the result is used
     546                 :            :           to assign to.  Also, &* is supposed to be a no-op.  */
     547                 :   25916100 :       TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
     548                 :   25916100 :       TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
     549                 :   51832200 :       TREE_SIDE_EFFECTS (ref)
     550                 :   51814300 :         = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (val));
     551                 :   25916100 :       val = ref;
     552                 :            :     }
     553                 :            : 
     554                 :  242323000 :   return val;
     555                 :            : }
     556                 :            : 
     557                 :            : /* Really perform an lvalue-to-rvalue conversion, including copying an
     558                 :            :    argument of class type into a temporary.  */
     559                 :            : 
     560                 :            : tree
     561                 :    5274030 : force_rvalue (tree expr, tsubst_flags_t complain)
     562                 :            : {
     563                 :    5274030 :   tree type = TREE_TYPE (expr);
     564                 :    5301710 :   if (MAYBE_CLASS_TYPE_P (type) && TREE_CODE (expr) != TARGET_EXPR)
     565                 :            :     {
     566                 :      49574 :       releasing_vec args (make_tree_vector_single (expr));
     567                 :      24787 :       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
     568                 :            :                                         &args, type, LOOKUP_NORMAL, complain);
     569                 :      24787 :       expr = build_cplus_new (type, expr, complain);
     570                 :            :     }
     571                 :            :   else
     572                 :    5249240 :     expr = decay_conversion (expr, complain);
     573                 :            : 
     574                 :    5274030 :   return expr;
     575                 :            : }
     576                 :            : 
     577                 :            : 
     578                 :            : /* If EXPR and ORIG are INTEGER_CSTs, return a version of EXPR that has
     579                 :            :    TREE_OVERFLOW set only if it is set in ORIG.  Otherwise, return EXPR
     580                 :            :    unchanged.  */
     581                 :            : 
     582                 :            : static tree
     583                 :   18767000 : ignore_overflows (tree expr, tree orig)
     584                 :            : {
     585                 :   18767000 :   tree stripped_expr = tree_strip_any_location_wrapper (expr);
     586                 :   18767000 :   tree stripped_orig = tree_strip_any_location_wrapper (orig);
     587                 :            : 
     588                 :   18767000 :   if (TREE_CODE (stripped_expr) == INTEGER_CST
     589                 :   12286500 :       && TREE_CODE (stripped_orig) == INTEGER_CST
     590                 :   31051200 :       && TREE_OVERFLOW (stripped_expr) != TREE_OVERFLOW (stripped_orig))
     591                 :            :     {
     592                 :      35575 :       gcc_assert (!TREE_OVERFLOW (stripped_orig));
     593                 :            :       /* Ensure constant sharing.  */
     594                 :      35575 :       stripped_expr = wide_int_to_tree (TREE_TYPE (stripped_expr),
     595                 :      71150 :                                         wi::to_wide (stripped_expr));
     596                 :            :     }
     597                 :            : 
     598                 :   18767000 :   return preserve_any_location_wrapper (stripped_expr, expr);
     599                 :            : }
     600                 :            : 
     601                 :            : /* Fold away simple conversions, but make sure TREE_OVERFLOW is set
     602                 :            :    properly.  */
     603                 :            : 
     604                 :            : tree
     605                 :    1507740 : cp_fold_convert (tree type, tree expr)
     606                 :            : {
     607                 :    1507740 :   tree conv;
     608                 :    1507740 :   if (TREE_TYPE (expr) == type)
     609                 :            :     conv = expr;
     610                 :    1403760 :   else if (TREE_CODE (expr) == PTRMEM_CST
     611                 :    1403830 :            && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type),
     612                 :            :                            PTRMEM_CST_CLASS (expr)))
     613                 :            :     {
     614                 :            :       /* Avoid wrapping a PTRMEM_CST in NOP_EXPR.  */
     615                 :         56 :       conv = copy_node (expr);
     616                 :         56 :       TREE_TYPE (conv) = type;
     617                 :            :     }
     618                 :    1403710 :   else if (TYPE_PTRMEM_P (type))
     619                 :            :     {
     620                 :         12 :       conv = convert_ptrmem (type, expr, true, false,
     621                 :            :                              tf_warning_or_error);
     622                 :         12 :       conv = cp_fully_fold (conv);
     623                 :            :     }
     624                 :            :   else
     625                 :            :     {
     626                 :    1403700 :       conv = fold_convert (type, expr);
     627                 :    1403700 :       conv = ignore_overflows (conv, expr);
     628                 :            :     }
     629                 :    1507740 :   return conv;
     630                 :            : }
     631                 :            : 
     632                 :            : /* C++ conversions, preference to static cast conversions.  */
     633                 :            : 
     634                 :            : tree
     635                 :   33096800 : cp_convert (tree type, tree expr, tsubst_flags_t complain)
     636                 :            : {
     637                 :   33096800 :   return ocp_convert (type, expr, CONV_OLD_CONVERT, LOOKUP_NORMAL, complain);
     638                 :            : }
     639                 :            : 
     640                 :            : /* C++ equivalent of convert_and_check but using cp_convert as the
     641                 :            :    conversion function.
     642                 :            : 
     643                 :            :    Convert EXPR to TYPE, warning about conversion problems with constants.
     644                 :            :    Invoke this function on every expression that is converted implicitly,
     645                 :            :    i.e. because of language rules and not because of an explicit cast.  */
     646                 :            : 
     647                 :            : tree
     648                 :    9396160 : cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain)
     649                 :            : {
     650                 :    9396160 :   tree result;
     651                 :            : 
     652                 :    9396160 :   if (TREE_TYPE (expr) == type)
     653                 :            :     return expr;
     654                 :    9396090 :   if (expr == error_mark_node)
     655                 :            :     return expr;
     656                 :    9396090 :   result = cp_convert (type, expr, complain);
     657                 :            : 
     658                 :    9396090 :   if ((complain & tf_warning)
     659                 :    7980100 :       && c_inhibit_evaluation_warnings == 0)
     660                 :            :     {
     661                 :    7796330 :       tree folded = cp_fully_fold (expr);
     662                 :    7796330 :       tree folded_result;
     663                 :    7796330 :       if (folded == expr)
     664                 :            :         folded_result = result;
     665                 :            :       else
     666                 :            :         {
     667                 :            :           /* Avoid bogus -Wparentheses warnings.  */
     668                 :    2922540 :           warning_sentinel w (warn_parentheses);
     669                 :    2922540 :           warning_sentinel c (warn_int_in_bool_context);
     670                 :    2922540 :           folded_result = cp_convert (type, folded, tf_none);
     671                 :            :         }
     672                 :    7796330 :       folded_result = fold_simple (folded_result);
     673                 :    6096160 :       if (!TREE_OVERFLOW_P (folded)
     674                 :   13892500 :           && folded_result != error_mark_node)
     675                 :   15592500 :         warnings_for_convert_and_check (cp_expr_loc_or_input_loc (expr),
     676                 :            :                                         type, folded, folded_result);
     677                 :            :     }
     678                 :            : 
     679                 :            :   return result;
     680                 :            : }
     681                 :            : 
     682                 :            : /* Conversion...
     683                 :            : 
     684                 :            :    FLAGS indicates how we should behave.  */
     685                 :            : 
     686                 :            : tree
     687                 :   51062200 : ocp_convert (tree type, tree expr, int convtype, int flags,
     688                 :            :              tsubst_flags_t complain)
     689                 :            : {
     690                 :   51062200 :   tree e = expr;
     691                 :   51062200 :   enum tree_code code = TREE_CODE (type);
     692                 :   51062200 :   const char *invalid_conv_diag;
     693                 :   51062200 :   tree e1;
     694                 :   51062200 :   location_t loc = cp_expr_loc_or_input_loc (expr);
     695                 :   51062200 :   bool dofold = (convtype & CONV_FOLD);
     696                 :            : 
     697                 :  102124000 :   if (error_operand_p (e) || type == error_mark_node)
     698                 :            :     return error_mark_node;
     699                 :            : 
     700                 :   51062000 :   if (TREE_CODE (e) == COMPOUND_EXPR)
     701                 :            :     {
     702                 :      28030 :       e = ocp_convert (type, TREE_OPERAND (e, 1), convtype, flags, complain);
     703                 :      28030 :       if (e == error_mark_node)
     704                 :            :         return error_mark_node;
     705                 :      28030 :       if (e == TREE_OPERAND (expr, 1))
     706                 :            :         return expr;
     707                 :      21655 :       return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e),
     708                 :      21655 :                          TREE_OPERAND (expr, 0), e);
     709                 :            :     }
     710                 :            : 
     711                 :   51034000 :   complete_type (type);
     712                 :   51034000 :   complete_type (TREE_TYPE (expr));
     713                 :            : 
     714                 :  102068000 :   if ((invalid_conv_diag
     715                 :   51034000 :        = targetm.invalid_conversion (TREE_TYPE (expr), type)))
     716                 :            :     {
     717                 :          0 :       if (complain & tf_error)
     718                 :          0 :         error (invalid_conv_diag);
     719                 :          0 :       return error_mark_node;
     720                 :            :     }
     721                 :            : 
     722                 :            :   /* FIXME remove when moving to c_fully_fold model.  */
     723                 :   53815000 :   if (!CLASS_TYPE_P (type))
     724                 :            :     {
     725                 :   48253500 :       e = mark_rvalue_use (e);
     726                 :   48253500 :       e = scalar_constant_value (e);
     727                 :            :     }
     728                 :  102068000 :   if (error_operand_p (e))
     729                 :            :     return error_mark_node;
     730                 :            : 
     731                 :   51034000 :   if (NULLPTR_TYPE_P (type) && null_ptr_cst_p (e))
     732                 :            :     {
     733                 :      14248 :       if (complain & tf_warning)
     734                 :       7159 :         maybe_warn_zero_as_null_pointer_constant (e, loc);
     735                 :            : 
     736                 :      14248 :       if (!TREE_SIDE_EFFECTS (e))
     737                 :      14245 :         return nullptr_node;
     738                 :            :     }
     739                 :            : 
     740                 :   53800800 :   if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP))
     741                 :            :     /* We need a new temporary; don't take this shortcut.  */;
     742                 :   50899800 :   else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e)))
     743                 :            :     {
     744                 :   26658800 :       tree etype = TREE_TYPE (e);
     745                 :   26658800 :       if (same_type_p (type, etype))
     746                 :            :         /* The call to fold will not always remove the NOP_EXPR as
     747                 :            :            might be expected, since if one of the types is a typedef;
     748                 :            :            the comparison in fold is just equality of pointers, not a
     749                 :            :            call to comptypes.  We don't call fold in this case because
     750                 :            :            that can result in infinite recursion; fold will call
     751                 :            :            convert, which will call ocp_convert, etc.  */
     752                 :            :         return e;
     753                 :            :       /* For complex data types, we need to perform componentwise
     754                 :            :          conversion.  */
     755                 :    1058150 :       else if (TREE_CODE (type) == COMPLEX_TYPE)
     756                 :        414 :         return convert_to_complex_maybe_fold (type, e, dofold);
     757                 :    1057740 :       else if (VECTOR_TYPE_P (type))
     758                 :       1798 :         return convert_to_vector (type, rvalue (e));
     759                 :    1055940 :       else if (TREE_CODE (e) == TARGET_EXPR)
     760                 :            :         {
     761                 :            :           /* Don't build a NOP_EXPR of class type.  Instead, change the
     762                 :            :              type of the temporary.  */
     763                 :      15301 :           gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, etype));
     764                 :      15301 :           TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type;
     765                 :      15301 :           return e;
     766                 :            :         }
     767                 :    1040640 :       else if (TREE_CODE (e) == CONSTRUCTOR)
     768                 :            :         {
     769                 :         78 :           gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, etype));
     770                 :         78 :           TREE_TYPE (e) = type;
     771                 :         78 :           return e;
     772                 :            :         }
     773                 :            :       else
     774                 :            :         {
     775                 :            :           /* We shouldn't be treating objects of ADDRESSABLE type as
     776                 :            :              rvalues.  */
     777                 :    1040560 :           gcc_assert (!TREE_ADDRESSABLE (type));
     778                 :    1040560 :           return build_nop (type, e);
     779                 :            :         }
     780                 :            :     }
     781                 :            : 
     782                 :   24361000 :   e1 = targetm.convert_to_type (type, e);
     783                 :   24361000 :   if (e1)
     784                 :            :     return e1;
     785                 :            : 
     786                 :   24361000 :   if (code == VOID_TYPE && (convtype & CONV_STATIC))
     787                 :            :     {
     788                 :         80 :       e = convert_to_void (e, ICV_CAST, complain);
     789                 :         80 :       return e;
     790                 :            :     }
     791                 :            : 
     792                 :   24360900 :   if (INTEGRAL_CODE_P (code))
     793                 :            :     {
     794                 :   18785200 :       tree intype = TREE_TYPE (e);
     795                 :   18785200 :       tree converted;
     796                 :            : 
     797                 :   18785200 :       if (TREE_CODE (type) == ENUMERAL_TYPE)
     798                 :            :         {
     799                 :            :           /* enum = enum, enum = int, enum = float, (enum)pointer are all
     800                 :            :              errors.  */
     801                 :      48447 :           if (((INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
     802                 :      48447 :                 || TREE_CODE (intype) == REAL_TYPE)
     803                 :      48447 :                && ! (convtype & CONV_STATIC))
     804                 :      48447 :               || TYPE_PTR_P (intype))
     805                 :            :             {
     806                 :          0 :               if (complain & tf_error)
     807                 :          0 :                 permerror (loc, "conversion from %q#T to %q#T", intype, type);
     808                 :            :               else
     809                 :          0 :                 return error_mark_node;
     810                 :            :             }
     811                 :            : 
     812                 :            :           /* [expr.static.cast]
     813                 :            : 
     814                 :            :              8. A value of integral or enumeration type can be explicitly
     815                 :            :              converted to an enumeration type. The value is unchanged if
     816                 :            :              the original value is within the range of the enumeration
     817                 :            :              values. Otherwise, the resulting enumeration value is
     818                 :            :              unspecified.  */
     819                 :      48447 :           tree val = fold_for_warn (e);
     820                 :      48447 :           if ((complain & tf_warning)
     821                 :      46381 :               && TREE_CODE (val) == INTEGER_CST
     822                 :      16197 :               && ENUM_UNDERLYING_TYPE (type)
     823                 :      64640 :               && !int_fits_type_p (val, ENUM_UNDERLYING_TYPE (type)))
     824                 :         97 :             warning_at (loc, OPT_Wconversion, 
     825                 :            :                         "the result of the conversion is unspecified because "
     826                 :            :                         "%qE is outside the range of type %qT",
     827                 :            :                         expr, type);
     828                 :            :         }
     829                 :   18785300 :       if (MAYBE_CLASS_TYPE_P (intype))
     830                 :            :         {
     831                 :          0 :           tree rval;
     832                 :          0 :           rval = build_type_conversion (type, e);
     833                 :          0 :           if (rval)
     834                 :            :             return rval;
     835                 :          0 :           if (complain & tf_error)
     836                 :          0 :             error_at (loc, "%q#T used where a %qT was expected", intype, type);
     837                 :          0 :           return error_mark_node;
     838                 :            :         }
     839                 :   18785200 :       if (code == BOOLEAN_TYPE)
     840                 :            :         {
     841                 :    1421820 :           if (VOID_TYPE_P (intype))
     842                 :            :             {
     843                 :         21 :               if (complain & tf_error)
     844                 :         21 :                 error_at (loc,
     845                 :            :                           "could not convert %qE from %<void%> to %<bool%>",
     846                 :            :                           expr);
     847                 :         21 :               return error_mark_node;
     848                 :            :             }
     849                 :            : 
     850                 :    1421800 :           if (VECTOR_TYPE_P (intype) && !gnu_vector_type_p (intype))
     851                 :            :             {
     852                 :          0 :               if (complain & tf_error)
     853                 :          0 :                 error_at (loc, "could not convert %qE from %qH to %qI", expr,
     854                 :          0 :                           TREE_TYPE (expr), type);
     855                 :          0 :               return error_mark_node;
     856                 :            :             }
     857                 :            : 
     858                 :            :           /* We can't implicitly convert a scoped enum to bool, so convert
     859                 :            :              to the underlying type first.  */
     860                 :    1421800 :           if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
     861                 :          6 :             e = build_nop (ENUM_UNDERLYING_TYPE (intype), e);
     862                 :    1421800 :           if (complain & tf_warning)
     863                 :     681789 :             return cp_truthvalue_conversion (e, complain);
     864                 :            :           else
     865                 :            :             {
     866                 :            :               /* Prevent bogus -Wint-in-bool-context warnings coming
     867                 :            :                  from c_common_truthvalue_conversion down the line.  */
     868                 :     740009 :               warning_sentinel w (warn_int_in_bool_context);
     869                 :     740009 :               warning_sentinel c (warn_sign_compare);
     870                 :     740009 :               return cp_truthvalue_conversion (e, complain);
     871                 :            :             }
     872                 :            :         }
     873                 :            : 
     874                 :   17363300 :       converted = convert_to_integer_maybe_fold (type, e, dofold);
     875                 :            : 
     876                 :            :       /* Ignore any integer overflow caused by the conversion.  */
     877                 :   17363300 :       return ignore_overflows (converted, e);
     878                 :            :     }
     879                 :    5575740 :   if (INDIRECT_TYPE_P (type) || TYPE_PTRMEM_P (type))
     880                 :    4344600 :     return cp_convert_to_pointer (type, e, dofold, complain);
     881                 :    1231140 :   if (code == VECTOR_TYPE)
     882                 :            :     {
     883                 :       4395 :       tree in_vtype = TREE_TYPE (e);
     884                 :       4395 :       if (MAYBE_CLASS_TYPE_P (in_vtype))
     885                 :            :         {
     886                 :          0 :           tree ret_val;
     887                 :          0 :           ret_val = build_type_conversion (type, e);
     888                 :          0 :           if (ret_val)
     889                 :            :             return ret_val;
     890                 :          0 :           if (complain & tf_error)
     891                 :          0 :             error_at (loc, "%q#T used where a %qT was expected",
     892                 :            :                       in_vtype, type);
     893                 :          0 :           return error_mark_node;
     894                 :            :         }
     895                 :       4395 :       return convert_to_vector (type, rvalue (e));
     896                 :            :     }
     897                 :    1226740 :   if (code == REAL_TYPE || code == COMPLEX_TYPE)
     898                 :            :     {
     899                 :    1106770 :       if (MAYBE_CLASS_TYPE_P (TREE_TYPE (e)))
     900                 :            :         {
     901                 :          0 :           tree rval;
     902                 :          0 :           rval = build_type_conversion (type, e);
     903                 :          0 :           if (rval)
     904                 :            :             return rval;
     905                 :          0 :           else if (complain & tf_error)
     906                 :          0 :             error_at (loc,
     907                 :            :                       "%q#T used where a floating-point value was expected",
     908                 :          0 :                       TREE_TYPE (e));
     909                 :            :         }
     910                 :    1106770 :       if (code == REAL_TYPE)
     911                 :    1076630 :         return convert_to_real_maybe_fold (type, e, dofold);
     912                 :      30142 :       else if (code == COMPLEX_TYPE)
     913                 :      30142 :         return convert_to_complex_maybe_fold (type, e, dofold);
     914                 :            :     }
     915                 :            : 
     916                 :            :   /* New C++ semantics:  since assignment is now based on
     917                 :            :      memberwise copying,  if the rhs type is derived from the
     918                 :            :      lhs type, then we may still do a conversion.  */
     919                 :     119970 :   if (RECORD_OR_UNION_CODE_P (code))
     920                 :            :     {
     921                 :     119964 :       tree dtype = TREE_TYPE (e);
     922                 :     119964 :       tree ctor = NULL_TREE;
     923                 :            : 
     924                 :     119964 :       dtype = TYPE_MAIN_VARIANT (dtype);
     925                 :            : 
     926                 :            :       /* Conversion between aggregate types.  New C++ semantics allow
     927                 :            :          objects of derived type to be cast to objects of base type.
     928                 :            :          Old semantics only allowed this between pointers.
     929                 :            : 
     930                 :            :          There may be some ambiguity between using a constructor
     931                 :            :          vs. using a type conversion operator when both apply.  */
     932                 :            : 
     933                 :     119964 :       ctor = e;
     934                 :            : 
     935                 :     119964 :       if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
     936                 :          0 :         return error_mark_node;
     937                 :            : 
     938                 :     122974 :       if (BRACE_ENCLOSED_INITIALIZER_P (ctor))
     939                 :       3010 :         ctor = perform_implicit_conversion (type, ctor, complain);
     940                 :     116954 :       else if ((flags & LOOKUP_ONLYCONVERTING)
     941                 :     228445 :                && ! (CLASS_TYPE_P (dtype) && DERIVED_FROM_P (type, dtype)))
     942                 :            :         /* For copy-initialization, first we create a temp of the proper type
     943                 :            :            with a user-defined conversion sequence, then we direct-initialize
     944                 :            :            the target with the temp (see [dcl.init]).  */
     945                 :      10490 :         ctor = build_user_type_conversion (type, ctor, flags, complain);
     946                 :            :       else
     947                 :            :         {
     948                 :     212928 :           releasing_vec ctor_vec (make_tree_vector_single (ctor));
     949                 :     106464 :           ctor = build_special_member_call (NULL_TREE,
     950                 :            :                                             complete_ctor_identifier,
     951                 :            :                                             &ctor_vec,
     952                 :            :                                             type, flags, complain);
     953                 :            :         }
     954                 :     119964 :       if (ctor)
     955                 :     119844 :         return build_cplus_new (type, ctor, complain);
     956                 :            :     }
     957                 :            : 
     958                 :        126 :   if (complain & tf_error)
     959                 :            :     {
     960                 :            :       /* If the conversion failed and expr was an invalid use of pointer to
     961                 :            :          member function, try to report a meaningful error.  */
     962                 :        126 :       if (invalid_nonstatic_memfn_p (loc, expr, complain))
     963                 :            :         /* We displayed the error message.  */;
     964                 :            :       else
     965                 :        122 :         error_at (loc, "conversion from %qH to non-scalar type %qI requested",
     966                 :        122 :                   TREE_TYPE (expr), type);
     967                 :            :     }
     968                 :        126 :   return error_mark_node;
     969                 :            : }
     970                 :            : 
     971                 :            : /* If CALL is a call, return the callee; otherwise null.  */
     972                 :            : 
     973                 :            : tree
     974                 :  110763000 : cp_get_callee (tree call)
     975                 :            : {
     976                 :  110763000 :   if (call == NULL_TREE)
     977                 :            :     return call;
     978                 :  110763000 :   else if (TREE_CODE (call) == CALL_EXPR)
     979                 :  107544000 :     return CALL_EXPR_FN (call);
     980                 :    3218660 :   else if (TREE_CODE (call) == AGGR_INIT_EXPR)
     981                 :    1107940 :     return AGGR_INIT_EXPR_FN (call);
     982                 :            :   return NULL_TREE;
     983                 :            : }
     984                 :            : 
     985                 :            : /* FN is the callee of a CALL_EXPR or AGGR_INIT_EXPR; return the FUNCTION_DECL
     986                 :            :    if we can.  */
     987                 :            : 
     988                 :            : tree
     989                 :   50735400 : cp_get_fndecl_from_callee (tree fn, bool fold /* = true */)
     990                 :            : {
     991                 :   50735400 :   if (fn == NULL_TREE)
     992                 :            :     return fn;
     993                 :   50497100 :   if (TREE_CODE (fn) == FUNCTION_DECL)
     994                 :            :     return fn;
     995                 :   50497100 :   tree type = TREE_TYPE (fn);
     996                 :   50497100 :   if (type == unknown_type_node)
     997                 :            :     return NULL_TREE;
     998                 :   50497100 :   gcc_assert (INDIRECT_TYPE_P (type));
     999                 :   50497100 :   if (fold)
    1000                 :     501077 :     fn = maybe_constant_init (fn);
    1001                 :   50497100 :   STRIP_NOPS (fn);
    1002                 :   50497100 :   if (TREE_CODE (fn) == ADDR_EXPR)
    1003                 :            :     {
    1004                 :   48827100 :       fn = TREE_OPERAND (fn, 0);
    1005                 :   48827100 :       if (TREE_CODE (fn) == FUNCTION_DECL)
    1006                 :   48827000 :         return fn;
    1007                 :            :     }
    1008                 :            :   return NULL_TREE;
    1009                 :            : }
    1010                 :            : 
    1011                 :            : /* Like get_callee_fndecl, but handles AGGR_INIT_EXPR as well and uses the
    1012                 :            :    constexpr machinery.  */
    1013                 :            : 
    1014                 :            : tree
    1015                 :          0 : cp_get_callee_fndecl (tree call)
    1016                 :            : {
    1017                 :          0 :   return cp_get_fndecl_from_callee (cp_get_callee (call));
    1018                 :            : }
    1019                 :            : 
    1020                 :            : /* As above, but not using the constexpr machinery.  */
    1021                 :            : 
    1022                 :            : tree
    1023                 :   50233400 : cp_get_callee_fndecl_nofold (tree call)
    1024                 :            : {
    1025                 :   50233400 :   return cp_get_fndecl_from_callee (cp_get_callee (call), false);
    1026                 :            : }
    1027                 :            : 
    1028                 :            : /* Subroutine of convert_to_void.  Warn if we're discarding something with
    1029                 :            :    attribute [[nodiscard]].  */
    1030                 :            : 
    1031                 :            : static void
    1032                 :     502258 : maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
    1033                 :            : {
    1034                 :     502258 :   tree call = expr;
    1035                 :     502258 :   if (TREE_CODE (expr) == TARGET_EXPR)
    1036                 :      12775 :     call = TARGET_EXPR_INITIAL (expr);
    1037                 :     502258 :   location_t loc = cp_expr_loc_or_input_loc (call);
    1038                 :     502258 :   tree callee = cp_get_callee (call);
    1039                 :     502258 :   if (!callee)
    1040                 :            :     return;
    1041                 :            : 
    1042                 :     501077 :   tree type = TREE_TYPE (callee);
    1043                 :     501077 :   if (TYPE_PTRMEMFUNC_P (type))
    1044                 :          0 :     type = TYPE_PTRMEMFUNC_FN_TYPE (type);
    1045                 :     501077 :   if (INDIRECT_TYPE_P (type))
    1046                 :     501077 :     type = TREE_TYPE (type);
    1047                 :            : 
    1048                 :     501077 :   tree rettype = TREE_TYPE (type);
    1049                 :     501077 :   tree fn = cp_get_fndecl_from_callee (callee);
    1050                 :     501077 :   tree attr;
    1051                 :     501077 :   if (implicit != ICV_CAST && fn
    1052                 :     991693 :       && (attr = lookup_attribute ("nodiscard", DECL_ATTRIBUTES (fn))))
    1053                 :            :     {
    1054                 :        172 :       escaped_string msg;
    1055                 :         86 :       tree args = TREE_VALUE (attr);
    1056                 :         86 :       if (args)
    1057                 :         22 :         msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
    1058                 :         86 :       const char *format
    1059                 :            :         = (msg
    1060                 :         86 :            ? G_("ignoring return value of %qD, "
    1061                 :            :                 "declared with attribute %<nodiscard%>: %<%s%>")
    1062                 :         86 :            : G_("ignoring return value of %qD, "
    1063                 :         86 :                 "declared with attribute %<nodiscard%>%s"));
    1064                 :         86 :       const char *raw_msg = msg ? (const char *) msg : "";
    1065                 :        172 :       auto_diagnostic_group d;
    1066                 :         86 :       if (warning_at (loc, OPT_Wunused_result, format, fn, raw_msg))
    1067                 :         86 :         inform (DECL_SOURCE_LOCATION (fn), "declared here");
    1068                 :            :     }
    1069                 :     500991 :   else if (implicit != ICV_CAST
    1070                 :     994260 :            && (attr = lookup_attribute ("nodiscard", TYPE_ATTRIBUTES (rettype))))
    1071                 :            :     {
    1072                 :        102 :       escaped_string msg;
    1073                 :         51 :       tree args = TREE_VALUE (attr);
    1074                 :         51 :       if (args)
    1075                 :         14 :         msg.escape (TREE_STRING_POINTER (TREE_VALUE (args)));
    1076                 :         51 :       const char *format
    1077                 :            :         = (msg
    1078                 :         51 :            ? G_("ignoring returned value of type %qT, "
    1079                 :            :                 "declared with attribute %<nodiscard%>: %<%s%>")
    1080                 :         51 :            : G_("ignoring returned value of type %qT, "
    1081                 :         51 :                 "declared with attribute %<nodiscard%>%s"));
    1082                 :         51 :       const char *raw_msg = msg ? (const char *) msg : "";
    1083                 :        102 :       auto_diagnostic_group d;
    1084                 :         51 :       if (warning_at (loc, OPT_Wunused_result, format, rettype, raw_msg))
    1085                 :            :         {
    1086                 :         51 :           if (fn)
    1087                 :         12 :             inform (DECL_SOURCE_LOCATION (fn),
    1088                 :            :                     "in call to %qD, declared here", fn);
    1089                 :         51 :           inform (DECL_SOURCE_LOCATION (TYPE_NAME (rettype)),
    1090                 :            :                   "%qT declared here", rettype);
    1091                 :            :         }
    1092                 :            :     }
    1093                 :     500940 :   else if (TREE_CODE (expr) == TARGET_EXPR
    1094                 :     512480 :            && lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (type)))
    1095                 :            :     {
    1096                 :            :       /* The TARGET_EXPR confuses do_warn_unused_result into thinking that the
    1097                 :            :          result is used, so handle that case here.  */
    1098                 :         80 :       if (fn)
    1099                 :            :         {
    1100                 :        160 :           auto_diagnostic_group d;
    1101                 :         80 :           if (warning_at (loc, OPT_Wunused_result,
    1102                 :            :                           "ignoring return value of %qD, "
    1103                 :            :                           "declared with attribute %<warn_unused_result%>",
    1104                 :            :                           fn))
    1105                 :         80 :             inform (DECL_SOURCE_LOCATION (fn), "declared here");
    1106                 :            :         }
    1107                 :            :       else
    1108                 :          0 :         warning_at (loc, OPT_Wunused_result,
    1109                 :            :                     "ignoring return value of function "
    1110                 :            :                     "declared with attribute %<warn_unused_result%>");
    1111                 :            :     }
    1112                 :            : }
    1113                 :            : 
    1114                 :            : /* When an expression is used in a void context, its value is discarded and
    1115                 :            :    no lvalue-rvalue and similar conversions happen [expr.static.cast/4,
    1116                 :            :    stmt.expr/1, expr.comma/1].  This permits dereferencing an incomplete type
    1117                 :            :    in a void context. The C++ standard does not define what an `access' to an
    1118                 :            :    object is, but there is reason to believe that it is the lvalue to rvalue
    1119                 :            :    conversion -- if it were not, `*&*p = 1' would violate [expr]/4 in that it
    1120                 :            :    accesses `*p' not to calculate the value to be stored. But, dcl.type.cv/8
    1121                 :            :    indicates that volatile semantics should be the same between C and C++
    1122                 :            :    where ever possible. C leaves it implementation defined as to what
    1123                 :            :    constitutes an access to a volatile. So, we interpret `*vp' as a read of
    1124                 :            :    the volatile object `vp' points to, unless that is an incomplete type. For
    1125                 :            :    volatile references we do not do this interpretation, because that would
    1126                 :            :    make it impossible to ignore the reference return value from functions. We
    1127                 :            :    issue warnings in the confusing cases.
    1128                 :            : 
    1129                 :            :    The IMPLICIT is ICV_CAST when the user is explicitly converting an expression
    1130                 :            :    to void via a cast. If an expression is being implicitly converted, IMPLICIT
    1131                 :            :    indicates the context of the implicit conversion.  */
    1132                 :            : 
    1133                 :            : tree
    1134                 :   12209800 : convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
    1135                 :            : {
    1136                 :   12209800 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    1137                 :            : 
    1138                 :   12209800 :   if (expr == error_mark_node
    1139                 :   24418800 :       || TREE_TYPE (expr) == error_mark_node)
    1140                 :            :     return error_mark_node;
    1141                 :            : 
    1142                 :   12209000 :   expr = maybe_undo_parenthesized_ref (expr);
    1143                 :            : 
    1144                 :   12209000 :   expr = mark_discarded_use (expr);
    1145                 :   12209000 :   if (implicit == ICV_CAST)
    1146                 :            :     /* An explicit cast to void avoids all -Wunused-but-set* warnings.  */
    1147                 :     128354 :     mark_exp_read (expr);
    1148                 :            : 
    1149                 :   12209000 :   if (!TREE_TYPE (expr))
    1150                 :            :     return expr;
    1151                 :   12209000 :   if (invalid_nonstatic_memfn_p (loc, expr, complain))
    1152                 :         20 :     return error_mark_node;
    1153                 :   12209000 :   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
    1154                 :            :     {
    1155                 :          8 :       if (complain & tf_error)
    1156                 :          8 :         error_at (loc, "pseudo-destructor is not called");
    1157                 :          8 :       return error_mark_node;
    1158                 :            :     }
    1159                 :            : 
    1160                 :            :   /* Explicitly evaluate void-converted concept checks since their
    1161                 :            :      satisfaction may produce ill-formed programs.  */
    1162                 :   12209000 :    if (concept_check_p (expr))
    1163                 :          5 :      expr = evaluate_concept_check (expr, tf_warning_or_error);
    1164                 :            : 
    1165                 :   12209000 :   if (VOID_TYPE_P (TREE_TYPE (expr)))
    1166                 :            :     return expr;
    1167                 :    5802190 :   switch (TREE_CODE (expr))
    1168                 :            :     {
    1169                 :        777 :     case COND_EXPR:
    1170                 :        777 :       {
    1171                 :            :         /* The two parts of a cond expr might be separate lvalues.  */
    1172                 :        777 :         tree op1 = TREE_OPERAND (expr,1);
    1173                 :        777 :         tree op2 = TREE_OPERAND (expr,2);
    1174                 :        777 :         bool side_effects = ((op1 && TREE_SIDE_EFFECTS (op1))
    1175                 :       1065 :                              || TREE_SIDE_EFFECTS (op2));
    1176                 :        777 :         tree new_op1, new_op2;
    1177                 :        777 :         new_op1 = NULL_TREE;
    1178                 :        777 :         if (implicit != ICV_CAST && !side_effects)
    1179                 :            :           {
    1180                 :         62 :             if (op1)
    1181                 :         62 :               new_op1 = convert_to_void (op1, ICV_SECOND_OF_COND, complain);
    1182                 :         62 :             new_op2 = convert_to_void (op2, ICV_THIRD_OF_COND, complain);
    1183                 :            :           }
    1184                 :            :         else
    1185                 :            :           {
    1186                 :        715 :             if (op1)
    1187                 :        715 :               new_op1 = convert_to_void (op1, ICV_CAST, complain);
    1188                 :        715 :             new_op2 = convert_to_void (op2, ICV_CAST, complain);
    1189                 :            :           }
    1190                 :            : 
    1191                 :        777 :         expr = build3 (COND_EXPR, TREE_TYPE (new_op2),
    1192                 :        777 :                        TREE_OPERAND (expr, 0), new_op1, new_op2);
    1193                 :        777 :         break;
    1194                 :            :       }
    1195                 :            : 
    1196                 :      30940 :     case COMPOUND_EXPR:
    1197                 :      30940 :       {
    1198                 :            :         /* The second part of a compound expr contains the value.  */
    1199                 :      30940 :         tree op1 = TREE_OPERAND (expr,1);
    1200                 :      30940 :         tree new_op1;
    1201                 :      30940 :         if (implicit != ICV_CAST && !TREE_NO_WARNING (expr))
    1202                 :       9837 :           new_op1 = convert_to_void (op1, ICV_RIGHT_OF_COMMA, complain);
    1203                 :            :         else
    1204                 :      21103 :           new_op1 = convert_to_void (op1, ICV_CAST, complain);
    1205                 :            : 
    1206                 :      30940 :         if (new_op1 != op1)
    1207                 :            :           {
    1208                 :      30940 :             tree t = build2 (COMPOUND_EXPR, TREE_TYPE (new_op1),
    1209                 :      30940 :                              TREE_OPERAND (expr, 0), new_op1);
    1210                 :      30940 :             expr = t;
    1211                 :            :           }
    1212                 :            : 
    1213                 :            :         break;
    1214                 :            :       }
    1215                 :            : 
    1216                 :            :     case NON_LVALUE_EXPR:
    1217                 :            :     case NOP_EXPR:
    1218                 :            :       /* These have already decayed to rvalue.  */
    1219                 :            :       break;
    1220                 :            : 
    1221                 :     362536 :     case CALL_EXPR:   /* We have a special meaning for volatile void fn().  */
    1222                 :            :       /* cdtors may return this or void, depending on
    1223                 :            :          targetm.cxx.cdtor_returns_this, but this shouldn't affect our
    1224                 :            :          decisions here: neither nodiscard warnings (nodiscard cdtors
    1225                 :            :          are nonsensical), nor should any constexpr or template
    1226                 :            :          instantiations be affected by an ABI property that is, or at
    1227                 :            :          least ought to be transparent to the language.  */
    1228                 :     362536 :       if (tree fn = cp_get_callee_fndecl_nofold (expr))
    1229                 :     720160 :         if (DECL_DESTRUCTOR_P (fn))
    1230                 :            :           return expr;
    1231                 :            : 
    1232                 :     362536 :       if (complain & tf_warning)
    1233                 :     362392 :         maybe_warn_nodiscard (expr, implicit);
    1234                 :            :       break;
    1235                 :            : 
    1236                 :     145150 :     case INDIRECT_REF:
    1237                 :     145150 :       {
    1238                 :     145150 :         tree type = TREE_TYPE (expr);
    1239                 :     145150 :         int is_reference = TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0)));
    1240                 :     145150 :         int is_volatile = TYPE_VOLATILE (type);
    1241                 :     145150 :         int is_complete = COMPLETE_TYPE_P (complete_type (type));
    1242                 :            : 
    1243                 :            :         /* Can't load the value if we don't know the type.  */
    1244                 :     145150 :         if (is_volatile && !is_complete)
    1245                 :            :           {
    1246                 :         52 :             if (complain & tf_warning)
    1247                 :         52 :               switch (implicit)
    1248                 :            :                 {
    1249                 :         32 :                   case ICV_CAST:
    1250                 :         32 :                     warning_at (loc, 0, "conversion to void will not access "
    1251                 :            :                                 "object of incomplete type %qT", type);
    1252                 :         32 :                     break;
    1253                 :          0 :                   case ICV_SECOND_OF_COND:
    1254                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1255                 :            :                                 "incomplete type %qT in second operand "
    1256                 :            :                                 "of conditional expression", type);
    1257                 :          0 :                     break;
    1258                 :          0 :                   case ICV_THIRD_OF_COND:
    1259                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1260                 :            :                                 "incomplete type %qT in third operand "
    1261                 :            :                                 "of conditional expression", type);
    1262                 :          0 :                     break;
    1263                 :          0 :                   case ICV_RIGHT_OF_COMMA:
    1264                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1265                 :            :                                 "incomplete type %qT in right operand of "
    1266                 :            :                                 "comma operator", type);
    1267                 :          0 :                     break;
    1268                 :          0 :                   case ICV_LEFT_OF_COMMA:
    1269                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1270                 :            :                                 "incomplete type %qT in left operand of "
    1271                 :            :                                 "comma operator", type);
    1272                 :          0 :                     break;
    1273                 :         20 :                   case ICV_STATEMENT:
    1274                 :         20 :                     warning_at (loc, 0, "indirection will not access object of "
    1275                 :            :                                 "incomplete type %qT in statement", type);
    1276                 :         20 :                      break;
    1277                 :          0 :                   case ICV_THIRD_IN_FOR:
    1278                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1279                 :            :                                 "incomplete type %qT in for increment "
    1280                 :            :                                 "expression", type);
    1281                 :          0 :                     break;
    1282                 :          0 :                   default:
    1283                 :          0 :                     gcc_unreachable ();
    1284                 :            :                 }
    1285                 :            :           }
    1286                 :            :         /* Don't load the value if this is an implicit dereference, or if
    1287                 :            :            the type needs to be handled by ctors/dtors.  */
    1288                 :     145098 :         else if (is_volatile && is_reference)
    1289                 :            :           {
    1290                 :         52 :             if (complain & tf_warning)
    1291                 :         52 :               switch (implicit)
    1292                 :            :                 {
    1293                 :         32 :                   case ICV_CAST:
    1294                 :         32 :                     warning_at (loc, 0, "conversion to void will not access "
    1295                 :            :                                 "object of type %qT", type);
    1296                 :         32 :                     break;
    1297                 :          0 :                   case ICV_SECOND_OF_COND:
    1298                 :          0 :                     warning_at (loc, 0, "implicit dereference will not access "
    1299                 :            :                                 "object of type %qT in second operand of "
    1300                 :            :                                 "conditional expression", type);
    1301                 :          0 :                     break;
    1302                 :          0 :                   case ICV_THIRD_OF_COND:
    1303                 :          0 :                     warning_at (loc, 0, "implicit dereference will not access "
    1304                 :            :                                 "object of type %qT in third operand of "
    1305                 :            :                                 "conditional expression", type);
    1306                 :          0 :                     break;
    1307                 :          0 :                   case ICV_RIGHT_OF_COMMA:
    1308                 :          0 :                     warning_at (loc, 0, "implicit dereference will not access "
    1309                 :            :                                 "object of type %qT in right operand of "
    1310                 :            :                                 "comma operator", type);
    1311                 :          0 :                     break;
    1312                 :          0 :                   case ICV_LEFT_OF_COMMA:
    1313                 :          0 :                     warning_at (loc, 0, "implicit dereference will not access "
    1314                 :            :                                 "object of type %qT in left operand of comma "
    1315                 :            :                                 "operator", type);
    1316                 :          0 :                     break;
    1317                 :         20 :                   case ICV_STATEMENT:
    1318                 :         20 :                     warning_at (loc, 0, "implicit dereference will not access "
    1319                 :            :                                 "object of type %qT in statement",  type);
    1320                 :         20 :                      break;
    1321                 :          0 :                   case ICV_THIRD_IN_FOR:
    1322                 :          0 :                     warning_at (loc, 0, "implicit dereference will not access "
    1323                 :            :                                 "object of type %qT in for increment expression",
    1324                 :            :                                 type);
    1325                 :          0 :                     break;
    1326                 :          0 :                   default:
    1327                 :          0 :                     gcc_unreachable ();
    1328                 :            :                 }
    1329                 :            :           }
    1330                 :     145046 :         else if (is_volatile && TREE_ADDRESSABLE (type))
    1331                 :            :           {
    1332                 :          4 :             if (complain & tf_warning)
    1333                 :          4 :               switch (implicit)
    1334                 :            :                 {
    1335                 :          0 :                   case ICV_CAST:
    1336                 :          0 :                     warning_at (loc, 0, "conversion to void will not access "
    1337                 :            :                                 "object of non-trivially-copyable type %qT",
    1338                 :            :                                 type);
    1339                 :          0 :                     break;
    1340                 :          0 :                   case ICV_SECOND_OF_COND:
    1341                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1342                 :            :                                 "non-trivially-copyable type %qT in second "
    1343                 :            :                                 "operand of conditional expression", type);
    1344                 :          0 :                     break;
    1345                 :          0 :                   case ICV_THIRD_OF_COND:
    1346                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1347                 :            :                                 "non-trivially-copyable type %qT in third "
    1348                 :            :                                 "operand of conditional expression", type);
    1349                 :          0 :                     break;
    1350                 :          0 :                   case ICV_RIGHT_OF_COMMA:
    1351                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1352                 :            :                                 "non-trivially-copyable type %qT in right "
    1353                 :            :                                 "operand of comma operator", type);
    1354                 :          0 :                     break;
    1355                 :          0 :                   case ICV_LEFT_OF_COMMA:
    1356                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1357                 :            :                                 "non-trivially-copyable type %qT in left "
    1358                 :            :                                 "operand of comma operator", type);
    1359                 :          0 :                     break;
    1360                 :          4 :                   case ICV_STATEMENT:
    1361                 :          4 :                     warning_at (loc, 0, "indirection will not access object of "
    1362                 :            :                                 "non-trivially-copyable type %qT in statement",
    1363                 :            :                                 type);
    1364                 :          4 :                      break;
    1365                 :          0 :                   case ICV_THIRD_IN_FOR:
    1366                 :          0 :                     warning_at (loc, 0, "indirection will not access object of "
    1367                 :            :                                 "non-trivially-copyable type %qT in for "
    1368                 :            :                                 "increment expression", type);
    1369                 :          0 :                     break;
    1370                 :          0 :                   default:
    1371                 :          0 :                     gcc_unreachable ();
    1372                 :            :                 }
    1373                 :            :           }
    1374                 :     145150 :         if (is_reference || !is_volatile || !is_complete || TREE_ADDRESSABLE (type))
    1375                 :            :           {
    1376                 :            :             /* Emit a warning (if enabled) when the "effect-less" INDIRECT_REF
    1377                 :            :                operation is stripped off. Note that we don't warn about
    1378                 :            :                - an expression with TREE_NO_WARNING set. (For an example of
    1379                 :            :                  such expressions, see build_over_call in call.c.)
    1380                 :            :                - automatic dereferencing of references, since the user cannot
    1381                 :            :                  control it. (See also warn_if_unused_value() in c-common.c.)  */
    1382                 :     145090 :             if (warn_unused_value
    1383                 :       6482 :                 && implicit != ICV_CAST
    1384                 :       6284 :                 && (complain & tf_warning)
    1385                 :       6284 :                 && !TREE_NO_WARNING (expr)
    1386                 :       4247 :                 && !is_reference)
    1387                 :          8 :               warning_at (loc, OPT_Wunused_value, "value computed is not used");
    1388                 :     145090 :             expr = TREE_OPERAND (expr, 0);
    1389                 :     145090 :             if (TREE_CODE (expr) == CALL_EXPR
    1390                 :     127251 :                 && (complain & tf_warning))
    1391                 :     127091 :               maybe_warn_nodiscard (expr, implicit);
    1392                 :            :           }
    1393                 :            : 
    1394                 :            :         break;
    1395                 :            :       }
    1396                 :            : 
    1397                 :       7931 :     case VAR_DECL:
    1398                 :       7931 :       {
    1399                 :            :         /* External variables might be incomplete.  */
    1400                 :       7931 :         tree type = TREE_TYPE (expr);
    1401                 :       7931 :         int is_complete = COMPLETE_TYPE_P (complete_type (type));
    1402                 :            : 
    1403                 :       7931 :         if (TYPE_VOLATILE (type) && !is_complete && (complain & tf_warning))
    1404                 :         20 :           switch (implicit)
    1405                 :            :             {
    1406                 :         16 :               case ICV_CAST:
    1407                 :         16 :                 warning_at (loc, 0, "conversion to void will not access "
    1408                 :            :                             "object %qE of incomplete type %qT", expr, type);
    1409                 :         16 :                 break;
    1410                 :          0 :               case ICV_SECOND_OF_COND:
    1411                 :          0 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1412                 :            :                             "not be accessed in second operand of "
    1413                 :            :                             "conditional expression", expr, type);
    1414                 :          0 :                 break;
    1415                 :          0 :               case ICV_THIRD_OF_COND:
    1416                 :          0 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1417                 :            :                             "not be accessed in third operand of "
    1418                 :            :                             "conditional expression", expr, type);
    1419                 :          0 :                 break;
    1420                 :          0 :               case ICV_RIGHT_OF_COMMA:
    1421                 :          0 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1422                 :            :                             "not be accessed in right operand of comma operator",
    1423                 :            :                             expr, type);
    1424                 :          0 :                 break;
    1425                 :          0 :               case ICV_LEFT_OF_COMMA:
    1426                 :          0 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1427                 :            :                             "not be accessed in left operand of comma operator",
    1428                 :            :                             expr, type);
    1429                 :          0 :                 break;
    1430                 :          4 :               case ICV_STATEMENT:
    1431                 :          4 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1432                 :            :                             "not be accessed in statement", expr, type);
    1433                 :          4 :                 break;
    1434                 :          0 :               case ICV_THIRD_IN_FOR:
    1435                 :          0 :                 warning_at (loc, 0, "variable %qE of incomplete type %qT will "
    1436                 :            :                             "not be accessed in for increment expression",
    1437                 :            :                             expr, type);
    1438                 :          0 :                 break;
    1439                 :          0 :               default:
    1440                 :          0 :                 gcc_unreachable ();
    1441                 :            :             }
    1442                 :            : 
    1443                 :            :         break;
    1444                 :            :       }
    1445                 :            : 
    1446                 :      12953 :     case TARGET_EXPR:
    1447                 :            :       /* Don't bother with the temporary object returned from a function if
    1448                 :            :          we don't use it, don't need to destroy it, and won't abort in
    1449                 :            :          assign_temp.  We'll still
    1450                 :            :          allocate space for it in expand_call or declare_return_variable,
    1451                 :            :          but we don't need to track it through all the tree phases.  */
    1452                 :      12953 :       if (TARGET_EXPR_IMPLICIT_P (expr)
    1453                 :      12953 :           && !TREE_ADDRESSABLE (TREE_TYPE (expr)))
    1454                 :            :         {
    1455                 :       8132 :           tree init = TARGET_EXPR_INITIAL (expr);
    1456                 :       8132 :           if (TREE_CODE (init) == AGGR_INIT_EXPR
    1457                 :       8132 :               && !AGGR_INIT_VIA_CTOR_P (init))
    1458                 :            :             {
    1459                 :          0 :               tree fn = AGGR_INIT_EXPR_FN (init);
    1460                 :          0 :               expr = build_call_array_loc (input_location,
    1461                 :          0 :                                            TREE_TYPE (TREE_TYPE
    1462                 :            :                                                       (TREE_TYPE (fn))),
    1463                 :            :                                            fn,
    1464                 :          0 :                                            aggr_init_expr_nargs (init),
    1465                 :          0 :                                            AGGR_INIT_EXPR_ARGP (init));
    1466                 :            :             }
    1467                 :            :         }
    1468                 :      12953 :       if (complain & tf_warning)
    1469                 :      12775 :         maybe_warn_nodiscard (expr, implicit);
    1470                 :            :       break;
    1471                 :            : 
    1472                 :    5802190 :     default:;
    1473                 :            :     }
    1474                 :    5802190 :   expr = resolve_nondeduced_context (expr, complain);
    1475                 :    5802190 :   {
    1476                 :    5802190 :     tree probe = expr;
    1477                 :            : 
    1478                 :    5802190 :     if (TREE_CODE (probe) == ADDR_EXPR)
    1479                 :        295 :       probe = TREE_OPERAND (expr, 0);
    1480                 :    5802190 :     if (type_unknown_p (probe))
    1481                 :            :       {
    1482                 :            :         /* [over.over] enumerates the places where we can take the address
    1483                 :            :            of an overloaded function, and this is not one of them.  */
    1484                 :         51 :         if (complain & tf_error)
    1485                 :         51 :           switch (implicit)
    1486                 :            :             {
    1487                 :         16 :               case ICV_CAST:
    1488                 :         16 :                 error_at (loc, "conversion to void "
    1489                 :            :                           "cannot resolve address of overloaded function");
    1490                 :         16 :                 break;
    1491                 :          0 :               case ICV_SECOND_OF_COND:
    1492                 :          0 :                 error_at (loc, "second operand of conditional expression "
    1493                 :            :                           "cannot resolve address of overloaded function");
    1494                 :          0 :                 break;
    1495                 :          0 :               case ICV_THIRD_OF_COND:
    1496                 :          0 :                 error_at (loc, "third operand of conditional expression "
    1497                 :            :                           "cannot resolve address of overloaded function");
    1498                 :          0 :                 break;
    1499                 :          0 :               case ICV_RIGHT_OF_COMMA:
    1500                 :          0 :                 error_at (loc, "right operand of comma operator "
    1501                 :            :                           "cannot resolve address of overloaded function");
    1502                 :          0 :                 break;
    1503                 :          0 :               case ICV_LEFT_OF_COMMA:
    1504                 :          0 :                 error_at (loc, "left operand of comma operator "
    1505                 :            :                           "cannot resolve address of overloaded function");
    1506                 :          0 :                 break;
    1507                 :         35 :               case ICV_STATEMENT:
    1508                 :         35 :                 error_at (loc, "statement "
    1509                 :            :                           "cannot resolve address of overloaded function");
    1510                 :         35 :                 break;
    1511                 :          0 :               case ICV_THIRD_IN_FOR:
    1512                 :          0 :                 error_at (loc, "for increment expression "
    1513                 :            :                           "cannot resolve address of overloaded function");
    1514                 :          0 :                 break;
    1515                 :            :             }
    1516                 :            :         else
    1517                 :          0 :           return error_mark_node;
    1518                 :         51 :         expr = void_node;
    1519                 :            :       }
    1520                 :    5802140 :     else if (implicit != ICV_CAST && probe == expr && is_overloaded_fn (probe))
    1521                 :            :       {
    1522                 :            :         /* Only warn when there is no &.  */
    1523                 :        109 :         if (complain & tf_warning)
    1524                 :        109 :           switch (implicit)
    1525                 :            :             {
    1526                 :          4 :               case ICV_SECOND_OF_COND:
    1527                 :          4 :                 warning_at (loc, OPT_Waddress,
    1528                 :            :                             "second operand of conditional expression "
    1529                 :            :                             "is a reference, not call, to function %qE", expr);
    1530                 :          4 :                 break;
    1531                 :          4 :               case ICV_THIRD_OF_COND:
    1532                 :          4 :                 warning_at (loc, OPT_Waddress,
    1533                 :            :                             "third operand of conditional expression "
    1534                 :            :                             "is a reference, not call, to function %qE", expr);
    1535                 :          4 :                 break;
    1536                 :          0 :               case ICV_RIGHT_OF_COMMA:
    1537                 :          0 :                 warning_at (loc, OPT_Waddress,
    1538                 :            :                             "right operand of comma operator "
    1539                 :            :                             "is a reference, not call, to function %qE", expr);
    1540                 :          0 :                 break;
    1541                 :         27 :               case ICV_LEFT_OF_COMMA:
    1542                 :         27 :                 warning_at (loc, OPT_Waddress,
    1543                 :            :                             "left operand of comma operator "
    1544                 :            :                             "is a reference, not call, to function %qE", expr);
    1545                 :         27 :                 break;
    1546                 :         74 :               case ICV_STATEMENT:
    1547                 :         74 :                 warning_at (loc, OPT_Waddress,
    1548                 :            :                             "statement is a reference, not call, to function %qE",
    1549                 :            :                             expr);
    1550                 :         74 :                 break;
    1551                 :          0 :               case ICV_THIRD_IN_FOR:
    1552                 :          0 :                 warning_at (loc, OPT_Waddress,
    1553                 :            :                             "for increment expression "
    1554                 :            :                             "is a reference, not call, to function %qE", expr);
    1555                 :          0 :                 break;
    1556                 :          0 :               default:
    1557                 :          0 :                 gcc_unreachable ();
    1558                 :            :             }
    1559                 :            : 
    1560                 :        109 :         if (TREE_CODE (expr) == COMPONENT_REF)
    1561                 :         12 :           expr = TREE_OPERAND (expr, 0);
    1562                 :            :       }
    1563                 :            :   }
    1564                 :            : 
    1565                 :   11604400 :   if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr)))
    1566                 :            :     {
    1567                 :    5770420 :       if (implicit != ICV_CAST
    1568                 :    5652000 :           && warn_unused_value
    1569                 :     344974 :           && !TREE_NO_WARNING (expr)
    1570                 :     305642 :           && !processing_template_decl
    1571                 :     264336 :           && !cp_unevaluated_operand)
    1572                 :            :         {
    1573                 :            :           /* The middle end does not warn about expressions that have
    1574                 :            :              been explicitly cast to void, so we must do so here.  */
    1575                 :     264327 :           if (!TREE_SIDE_EFFECTS (expr)) {
    1576                 :        124 :             if (complain & tf_warning)
    1577                 :        124 :               switch (implicit)
    1578                 :            :                 {
    1579                 :          4 :                   case ICV_SECOND_OF_COND:
    1580                 :          4 :                     warning_at (loc, OPT_Wunused_value,
    1581                 :            :                                 "second operand of conditional expression "
    1582                 :            :                                 "has no effect");
    1583                 :          4 :                     break;
    1584                 :          4 :                   case ICV_THIRD_OF_COND:
    1585                 :          4 :                     warning_at (loc, OPT_Wunused_value,
    1586                 :            :                                 "third operand of conditional expression "
    1587                 :            :                                 "has no effect");
    1588                 :          4 :                     break;
    1589                 :         48 :                   case ICV_RIGHT_OF_COMMA:
    1590                 :         48 :                     warning_at (loc, OPT_Wunused_value,
    1591                 :            :                                 "right operand of comma operator has no effect");
    1592                 :         48 :                     break;
    1593                 :         16 :                   case ICV_LEFT_OF_COMMA:
    1594                 :         16 :                     warning_at (loc, OPT_Wunused_value,
    1595                 :            :                                 "left operand of comma operator has no effect");
    1596                 :         16 :                     break;
    1597                 :         52 :                   case ICV_STATEMENT:
    1598                 :         52 :                     warning_at (loc, OPT_Wunused_value,
    1599                 :            :                                 "statement has no effect");
    1600                 :         52 :                     break;
    1601                 :          0 :                   case ICV_THIRD_IN_FOR:
    1602                 :          0 :                     warning_at (loc, OPT_Wunused_value,
    1603                 :            :                                 "for increment expression has no effect");
    1604                 :          0 :                     break;
    1605                 :          0 :                   default:
    1606                 :          0 :                     gcc_unreachable ();
    1607                 :            :                 }
    1608                 :            :           }
    1609                 :            :           else
    1610                 :            :             {
    1611                 :            :               tree e;
    1612                 :            :               enum tree_code code;
    1613                 :            :               enum tree_code_class tclass;
    1614                 :            : 
    1615                 :            :               e = expr;
    1616                 :            :               /* We might like to warn about (say) "(int) f()", as the
    1617                 :            :                  cast has no effect, but the compiler itself will
    1618                 :            :                  generate implicit conversions under some
    1619                 :            :                  circumstances.  (For example a block copy will be
    1620                 :            :                  turned into a call to "__builtin_memcpy", with a
    1621                 :            :                  conversion of the return value to an appropriate
    1622                 :            :                  type.)  So, to avoid false positives, we strip
    1623                 :            :                  conversions.  Do not use STRIP_NOPs because it will
    1624                 :            :                  not strip conversions to "void", as that is not a
    1625                 :            :                  mode-preserving conversion.  */
    1626                 :     264488 :               while (TREE_CODE (e) == NOP_EXPR)
    1627                 :        285 :                 e = TREE_OPERAND (e, 0);
    1628                 :            : 
    1629                 :     264203 :               code = TREE_CODE (e);
    1630                 :     264203 :               tclass = TREE_CODE_CLASS (code);
    1631                 :     264203 :               if ((tclass == tcc_comparison
    1632                 :     264203 :                    || tclass == tcc_unary
    1633                 :     264163 :                    || (tclass == tcc_binary
    1634                 :         16 :                        && !(code == MODIFY_EXPR
    1635                 :         16 :                             || code == INIT_EXPR
    1636                 :         16 :                             || code == PREDECREMENT_EXPR
    1637                 :            :                             || code == PREINCREMENT_EXPR
    1638                 :         16 :                             || code == POSTDECREMENT_EXPR
    1639                 :            :                             || code == POSTINCREMENT_EXPR))
    1640                 :            :                    || code == VEC_PERM_EXPR
    1641                 :     264147 :                    || code == VEC_COND_EXPR)
    1642                 :         64 :                   && (complain & tf_warning))
    1643                 :         64 :                 warning_at (loc, OPT_Wunused_value, "value computed is not used");
    1644                 :            :             }
    1645                 :            :         }
    1646                 :    5770420 :       expr = build1 (CONVERT_EXPR, void_type_node, expr);
    1647                 :            :     }
    1648                 :    5802180 :   if (! TREE_SIDE_EFFECTS (expr))
    1649                 :      57931 :     expr = void_node;
    1650                 :            :   return expr;
    1651                 :            : }
    1652                 :            : 
    1653                 :            : /* Create an expression whose value is that of EXPR,
    1654                 :            :    converted to type TYPE.  The TREE_TYPE of the value
    1655                 :            :    is always TYPE.  This function implements all reasonable
    1656                 :            :    conversions; callers should filter out those that are
    1657                 :            :    not permitted by the language being compiled.
    1658                 :            : 
    1659                 :            :    Most of this routine is from build_reinterpret_cast.
    1660                 :            : 
    1661                 :            :    The back end cannot call cp_convert (what was convert) because
    1662                 :            :    conversions to/from basetypes may involve memory references
    1663                 :            :    (vbases) and adding or subtracting small values (multiple
    1664                 :            :    inheritance), but it calls convert from the constant folding code
    1665                 :            :    on subtrees of already built trees after it has ripped them apart.
    1666                 :            : 
    1667                 :            :    Also, if we ever support range variables, we'll probably also have to
    1668                 :            :    do a little bit more work.  */
    1669                 :            : 
    1670                 :            : tree
    1671                 :   25364000 : convert (tree type, tree expr)
    1672                 :            : {
    1673                 :   25364000 :   tree intype;
    1674                 :            : 
    1675                 :   25364000 :   if (type == error_mark_node || expr == error_mark_node)
    1676                 :            :     return error_mark_node;
    1677                 :            : 
    1678                 :   25357300 :   intype = TREE_TYPE (expr);
    1679                 :            : 
    1680                 :   25357300 :   if (INDIRECT_TYPE_P (type) && INDIRECT_TYPE_P (intype))
    1681                 :    7617540 :     return build_nop (type, expr);
    1682                 :            : 
    1683                 :   17739800 :   return ocp_convert (type, expr, CONV_BACKEND_CONVERT,
    1684                 :            :                       LOOKUP_NORMAL|LOOKUP_NO_CONVERSION,
    1685                 :   17739800 :                       tf_warning_or_error);
    1686                 :            : }
    1687                 :            : 
    1688                 :            : /* Like cp_convert, except permit conversions to take place which
    1689                 :            :    are not normally allowed due to access restrictions
    1690                 :            :    (such as conversion from sub-type to private super-type).  */
    1691                 :            : 
    1692                 :            : tree
    1693                 :    1566980 : convert_force (tree type, tree expr, int convtype, tsubst_flags_t complain)
    1694                 :            : {
    1695                 :    1566980 :   tree e = expr;
    1696                 :    1566980 :   enum tree_code code = TREE_CODE (type);
    1697                 :            : 
    1698                 :    1566980 :   if (code == REFERENCE_TYPE)
    1699                 :          0 :     return convert_to_reference (type, e, CONV_C_CAST, 0,
    1700                 :          0 :                                  NULL_TREE, complain);
    1701                 :            : 
    1702                 :    1566980 :   if (code == POINTER_TYPE)
    1703                 :    1566980 :     return convert_to_pointer_force (type, e, complain);
    1704                 :            : 
    1705                 :            :   /* From typeck.c convert_for_assignment */
    1706                 :          0 :   if (((TYPE_PTR_P (TREE_TYPE (e)) && TREE_CODE (e) == ADDR_EXPR
    1707                 :          0 :         && TREE_CODE (TREE_TYPE (TREE_TYPE (e))) == METHOD_TYPE)
    1708                 :          0 :        || integer_zerop (e)
    1709                 :          0 :        || TYPE_PTRMEMFUNC_P (TREE_TYPE (e)))
    1710                 :          0 :       && TYPE_PTRMEMFUNC_P (type))
    1711                 :            :     /* compatible pointer to member functions.  */
    1712                 :          0 :     return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), e, 1,
    1713                 :          0 :                              /*c_cast_p=*/1, complain);
    1714                 :            : 
    1715                 :          0 :   return ocp_convert (type, e, CONV_C_CAST|convtype, LOOKUP_NORMAL, complain);
    1716                 :            : }
    1717                 :            : 
    1718                 :            : /* Convert an aggregate EXPR to type XTYPE.  If a conversion
    1719                 :            :    exists, return the attempted conversion.  This may
    1720                 :            :    return ERROR_MARK_NODE if the conversion is not
    1721                 :            :    allowed (references private members, etc).
    1722                 :            :    If no conversion exists, NULL_TREE is returned.
    1723                 :            : 
    1724                 :            :    FIXME: Ambiguity checking is wrong.  Should choose one by the implicit
    1725                 :            :    object parameter, or by the second standard conversion sequence if
    1726                 :            :    that doesn't do it.  This will probably wait for an overloading rewrite.
    1727                 :            :    (jason 8/9/95)  */
    1728                 :            : 
    1729                 :            : static tree
    1730                 :          4 : build_type_conversion (tree xtype, tree expr)
    1731                 :            : {
    1732                 :            :   /* C++: check to see if we can convert this aggregate type
    1733                 :            :      into the required type.  */
    1734                 :          4 :   return build_user_type_conversion (xtype, expr, LOOKUP_NORMAL,
    1735                 :          0 :                                      tf_warning_or_error);
    1736                 :            : }
    1737                 :            : 
    1738                 :            : /* Convert the given EXPR to one of a group of types suitable for use in an
    1739                 :            :    expression.  DESIRES is a combination of various WANT_* flags (q.v.)
    1740                 :            :    which indicates which types are suitable.  If COMPLAIN is true, complain
    1741                 :            :    about ambiguity; otherwise, the caller will deal with it.  */
    1742                 :            : 
    1743                 :            : tree
    1744                 :    3534280 : build_expr_type_conversion (int desires, tree expr, bool complain)
    1745                 :            : {
    1746                 :    3534280 :   tree basetype = TREE_TYPE (expr);
    1747                 :    3534280 :   tree conv = NULL_TREE;
    1748                 :    3534280 :   tree winner = NULL_TREE;
    1749                 :            : 
    1750                 :    3534280 :   if (null_node_p (expr)
    1751                 :            :       && (desires & WANT_INT)
    1752                 :    3534280 :       && !(desires & WANT_NULL))
    1753                 :            :     {
    1754                 :         48 :       location_t loc =
    1755                 :         48 :         expansion_point_location_if_in_system_header (input_location);
    1756                 :            : 
    1757                 :         48 :       warning_at (loc, OPT_Wconversion_null,
    1758                 :            :                   "converting NULL to non-pointer type");
    1759                 :            :     }
    1760                 :            : 
    1761                 :    3534280 :   if (basetype == error_mark_node)
    1762                 :            :     return error_mark_node;
    1763                 :            : 
    1764                 :    3534450 :   if (! MAYBE_CLASS_TYPE_P (basetype))
    1765                 :    3534080 :     switch (TREE_CODE (basetype))
    1766                 :            :       {
    1767                 :    2578140 :       case INTEGER_TYPE:
    1768                 :    2578140 :         if ((desires & WANT_NULL) && null_ptr_cst_p (expr))
    1769                 :            :           return expr;
    1770                 :            :         /* fall through.  */
    1771                 :            : 
    1772                 :    2587740 :       case BOOLEAN_TYPE:
    1773                 :    3076620 :         return (desires & WANT_INT) ? expr : NULL_TREE;
    1774                 :      37338 :       case ENUMERAL_TYPE:
    1775                 :      39226 :         return (desires & WANT_ENUM) ? expr : NULL_TREE;
    1776                 :      84969 :       case REAL_TYPE:
    1777                 :      85018 :         return (desires & WANT_FLOAT) ? expr : NULL_TREE;
    1778                 :     446101 :       case POINTER_TYPE:
    1779                 :     587950 :         return (desires & WANT_POINTER) ? expr : NULL_TREE;
    1780                 :            : 
    1781                 :     332070 :       case FUNCTION_TYPE:
    1782                 :     332070 :       case ARRAY_TYPE:
    1783                 :     332070 :         return (desires & WANT_POINTER) ? decay_conversion (expr,
    1784                 :            :                                                             tf_warning_or_error)
    1785                 :            :                                         : NULL_TREE;
    1786                 :            : 
    1787                 :      30440 :       case VECTOR_TYPE:
    1788                 :      30440 :         if (!gnu_vector_type_p (basetype))
    1789                 :            :           return NULL_TREE;
    1790                 :            :         /* FALLTHROUGH */
    1791                 :      45800 :       case COMPLEX_TYPE:
    1792                 :      45800 :         if ((desires & WANT_VECTOR_OR_COMPLEX) == 0)
    1793                 :            :           return NULL_TREE;
    1794                 :      28812 :         switch (TREE_CODE (TREE_TYPE (basetype)))
    1795                 :            :           {
    1796                 :        172 :           case INTEGER_TYPE:
    1797                 :        172 :           case BOOLEAN_TYPE:
    1798                 :        172 :             return (desires & WANT_INT) ? expr : NULL_TREE;
    1799                 :          0 :           case ENUMERAL_TYPE:
    1800                 :          0 :             return (desires & WANT_ENUM) ? expr : NULL_TREE;
    1801                 :      28640 :           case REAL_TYPE:
    1802                 :      28648 :             return (desires & WANT_FLOAT) ? expr : NULL_TREE;
    1803                 :            :           default:
    1804                 :            :             return NULL_TREE;
    1805                 :            :           }
    1806                 :            : 
    1807                 :            :       default:
    1808                 :            :         return NULL_TREE;
    1809                 :            :       }
    1810                 :            : 
    1811                 :            :   /* The code for conversions from class type is currently only used for
    1812                 :            :      delete expressions.  Other expressions are handled by build_new_op.  */
    1813                 :        176 :   if (!complete_type_or_maybe_complain (basetype, expr, complain))
    1814                 :          0 :     return error_mark_node;
    1815                 :        176 :   if (!TYPE_HAS_CONVERSION (basetype))
    1816                 :            :     return NULL_TREE;
    1817                 :            : 
    1818                 :        372 :   for (conv = lookup_conversions (basetype); conv; conv = TREE_CHAIN (conv))
    1819                 :            :     {
    1820                 :        207 :       int win = 0;
    1821                 :        207 :       tree candidate;
    1822                 :        207 :       tree cand = TREE_VALUE (conv);
    1823                 :        207 :       cand = OVL_FIRST (cand);
    1824                 :            : 
    1825                 :        207 :       if (winner && winner == cand)
    1826                 :          0 :         continue;
    1827                 :            : 
    1828                 :        414 :       if (DECL_NONCONVERTING_P (cand))
    1829                 :          3 :         continue;
    1830                 :            : 
    1831                 :        204 :       candidate = non_reference (TREE_TYPE (TREE_TYPE (cand)));
    1832                 :            : 
    1833                 :        204 :       switch (TREE_CODE (candidate))
    1834                 :            :         {
    1835                 :        141 :         case BOOLEAN_TYPE:
    1836                 :        141 :         case INTEGER_TYPE:
    1837                 :        141 :           win = (desires & WANT_INT); break;
    1838                 :         12 :         case ENUMERAL_TYPE:
    1839                 :         12 :           win = (desires & WANT_ENUM); break;
    1840                 :          3 :         case REAL_TYPE:
    1841                 :          3 :           win = (desires & WANT_FLOAT); break;
    1842                 :         44 :         case POINTER_TYPE:
    1843                 :         44 :           win = (desires & WANT_POINTER); break;
    1844                 :            : 
    1845                 :          0 :         case COMPLEX_TYPE:
    1846                 :          0 :         case VECTOR_TYPE:
    1847                 :          0 :           if ((desires & WANT_VECTOR_OR_COMPLEX) == 0)
    1848                 :            :             break;
    1849                 :          0 :           switch (TREE_CODE (TREE_TYPE (candidate)))
    1850                 :            :             {
    1851                 :          0 :             case BOOLEAN_TYPE:
    1852                 :          0 :             case INTEGER_TYPE:
    1853                 :          0 :               win = (desires & WANT_INT); break;
    1854                 :          0 :             case ENUMERAL_TYPE:
    1855                 :          0 :               win = (desires & WANT_ENUM); break;
    1856                 :          0 :             case REAL_TYPE:
    1857                 :          0 :               win = (desires & WANT_FLOAT); break;
    1858                 :            :             default:
    1859                 :            :               break;
    1860                 :            :             }
    1861                 :            :           break;
    1862                 :            : 
    1863                 :          4 :         default:
    1864                 :            :           /* A wildcard could be instantiated to match any desired
    1865                 :            :              type, but we can't deduce the template argument.  */
    1866                 :          4 :           if (WILDCARD_TYPE_P (candidate))
    1867                 :            :             win = true;
    1868                 :            :           break;
    1869                 :            :         }
    1870                 :            : 
    1871                 :        200 :       if (win)
    1872                 :            :         {
    1873                 :        189 :           if (TREE_CODE (cand) == TEMPLATE_DECL)
    1874                 :            :             {
    1875                 :          8 :               if (complain)
    1876                 :          8 :                 error ("default type conversion cannot deduce template"
    1877                 :            :                        " argument for %qD", cand);
    1878                 :          8 :               return error_mark_node;
    1879                 :            :             }
    1880                 :            : 
    1881                 :        181 :           if (winner)
    1882                 :            :             {
    1883                 :         19 :               tree winner_type
    1884                 :         19 :                 = non_reference (TREE_TYPE (TREE_TYPE (winner)));
    1885                 :            : 
    1886                 :         19 :               if (!same_type_ignoring_top_level_qualifiers_p (winner_type,
    1887                 :            :                                                               candidate))
    1888                 :            :                 {
    1889                 :          3 :                   if (complain)
    1890                 :            :                     {
    1891                 :          3 :                       error ("ambiguous default type conversion from %qT",
    1892                 :            :                              basetype);
    1893                 :          3 :                       inform (input_location,
    1894                 :            :                               "  candidate conversions include %qD and %qD",
    1895                 :            :                               winner, cand);
    1896                 :            :                     }
    1897                 :          3 :                   return error_mark_node;
    1898                 :            :                 }
    1899                 :            :             }
    1900                 :            : 
    1901                 :            :           winner = cand;
    1902                 :            :         }
    1903                 :            :     }
    1904                 :            : 
    1905                 :        165 :   if (winner)
    1906                 :            :     {
    1907                 :        159 :       tree type = non_reference (TREE_TYPE (TREE_TYPE (winner)));
    1908                 :        159 :       return build_user_type_conversion (type, expr, LOOKUP_NORMAL,
    1909                 :        159 :                                          tf_warning_or_error);
    1910                 :            :     }
    1911                 :            : 
    1912                 :            :   return NULL_TREE;
    1913                 :            : }
    1914                 :            : 
    1915                 :            : /* Implements integral promotion (4.1) and float->double promotion.  */
    1916                 :            : 
    1917                 :            : tree
    1918                 :   45088200 : type_promotes_to (tree type)
    1919                 :            : {
    1920                 :   45132500 :   tree promoted_type;
    1921                 :            : 
    1922                 :   45132500 :   if (type == error_mark_node)
    1923                 :            :     return error_mark_node;
    1924                 :            : 
    1925                 :   45132500 :   type = TYPE_MAIN_VARIANT (type);
    1926                 :            : 
    1927                 :            :   /* Check for promotions of target-defined types first.  */
    1928                 :   45132500 :   promoted_type = targetm.promoted_type (type);
    1929                 :   45132500 :   if (promoted_type)
    1930                 :            :     return promoted_type;
    1931                 :            : 
    1932                 :            :   /* bool always promotes to int (not unsigned), even if it's the same
    1933                 :            :      size.  */
    1934                 :   45132500 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
    1935                 :     549521 :     type = integer_type_node;
    1936                 :            : 
    1937                 :            :   /* Normally convert enums to int, but convert wide enums to something
    1938                 :            :      wider.  Scoped enums don't promote, but pretend they do for backward
    1939                 :            :      ABI bug compatibility wrt varargs.  */
    1940                 :   44583000 :   else if (TREE_CODE (type) == ENUMERAL_TYPE
    1941                 :   42726700 :            || type == char8_type_node
    1942                 :   42711500 :            || type == char16_type_node
    1943                 :   42671700 :            || type == char32_type_node
    1944                 :   42635600 :            || type == wchar_type_node)
    1945                 :            :     {
    1946                 :    2002010 :       tree prom = type;
    1947                 :            : 
    1948                 :    2002010 :       if (TREE_CODE (type) == ENUMERAL_TYPE)
    1949                 :            :         {
    1950                 :    1856250 :           prom = ENUM_UNDERLYING_TYPE (prom);
    1951                 :    1856250 :           if (!ENUM_IS_SCOPED (type)
    1952                 :    3712460 :               && ENUM_FIXED_UNDERLYING_TYPE_P (type))
    1953                 :            :             {
    1954                 :            :               /* ISO C++17, 7.6/4.  A prvalue of an unscoped enumeration type
    1955                 :            :                  whose underlying type is fixed (10.2) can be converted to a
    1956                 :            :                  prvalue of its underlying type. Moreover, if integral promotion
    1957                 :            :                  can be applied to its underlying type, a prvalue of an unscoped
    1958                 :            :                  enumeration type whose underlying type is fixed can also be 
    1959                 :            :                  converted to a prvalue of the promoted underlying type.  */
    1960                 :            :               return type_promotes_to (prom);
    1961                 :            :             }
    1962                 :            :         }
    1963                 :            : 
    1964                 :    1957750 :       int precision = MAX (TYPE_PRECISION (type),
    1965                 :            :                            TYPE_PRECISION (integer_type_node));
    1966                 :    1957750 :       tree totype = c_common_type_for_size (precision, 0);
    1967                 :    1957750 :       if (TYPE_UNSIGNED (prom)
    1968                 :    1957750 :           && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
    1969                 :      66958 :         prom = c_common_type_for_size (precision, 1);
    1970                 :            :       else
    1971                 :            :         prom = totype;
    1972                 :    1957750 :       if (SCOPED_ENUM_P (type))
    1973                 :            :         {
    1974                 :         33 :           if (abi_version_crosses (6)
    1975                 :         93 :               && TYPE_MODE (prom) != TYPE_MODE (type))
    1976                 :         30 :             warning (OPT_Wabi, "scoped enum %qT passed through %<...%> as "
    1977                 :            :                      "%qT before %<-fabi-version=6%>, %qT after",
    1978                 :         30 :                      type, prom, ENUM_UNDERLYING_TYPE (type));
    1979                 :         33 :           if (!abi_version_at_least (6))
    1980                 :          3 :             type = prom;
    1981                 :            :         }
    1982                 :            :       else
    1983                 :            :         type = prom;
    1984                 :            :     }
    1985                 :   42581000 :   else if (c_promoting_integer_type_p (type))
    1986                 :            :     {
    1987                 :            :       /* Retain unsignedness if really not getting bigger.  */
    1988                 :    1304620 :       if (TYPE_UNSIGNED (type)
    1989                 :    1304620 :           && TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    1990                 :          0 :         type = unsigned_type_node;
    1991                 :            :       else
    1992                 :    1304620 :         type = integer_type_node;
    1993                 :            :     }
    1994                 :   41276400 :   else if (type == float_type_node)
    1995                 :     358865 :     type = double_type_node;
    1996                 :            : 
    1997                 :            :   return type;
    1998                 :            : }
    1999                 :            : 
    2000                 :            : /* The routines below this point are carefully written to conform to
    2001                 :            :    the standard.  They use the same terminology, and follow the rules
    2002                 :            :    closely.  Although they are used only in pt.c at the moment, they
    2003                 :            :    should presumably be used everywhere in the future.  */
    2004                 :            : 
    2005                 :            : /* True iff EXPR can be converted to TYPE via a qualification conversion.
    2006                 :            :    Callers should check for identical types before calling this function.  */
    2007                 :            : 
    2008                 :            : bool
    2009                 :         67 : can_convert_qual (tree type, tree expr)
    2010                 :            : {
    2011                 :         67 :   tree expr_type = TREE_TYPE (expr);
    2012                 :         67 :   gcc_assert (!same_type_p (type, expr_type));
    2013                 :            : 
    2014                 :         67 :   if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type))
    2015                 :         16 :     return comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type));
    2016                 :         51 :   else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (expr_type))
    2017                 :         61 :     return (same_type_p (TYPE_PTRMEM_CLASS_TYPE (type),
    2018                 :            :                          TYPE_PTRMEM_CLASS_TYPE (expr_type))
    2019                 :        127 :             && comp_ptr_ttypes (TYPE_PTRMEM_POINTED_TO_TYPE (type),
    2020                 :         82 :                                 TYPE_PTRMEM_POINTED_TO_TYPE (expr_type)));
    2021                 :            :   else
    2022                 :            :     return false;
    2023                 :            : }
    2024                 :            : 
    2025                 :            : /* Attempt to perform qualification conversions on EXPR to convert it
    2026                 :            :    to TYPE.  Return the resulting expression, or error_mark_node if
    2027                 :            :    the conversion was impossible.  Since this is only used by
    2028                 :            :    convert_nontype_argument, we fold the conversion.  */
    2029                 :            : 
    2030                 :            : tree
    2031                 :       2333 : perform_qualification_conversions (tree type, tree expr)
    2032                 :            : {
    2033                 :       2333 :   tree expr_type;
    2034                 :            : 
    2035                 :       2333 :   expr_type = TREE_TYPE (expr);
    2036                 :            : 
    2037                 :       2333 :   if (same_type_p (type, expr_type))
    2038                 :            :     return expr;
    2039                 :         38 :   else if (can_convert_qual (type, expr))
    2040                 :         24 :     return cp_fold_convert (type, expr);
    2041                 :            :   else
    2042                 :         14 :     return error_mark_node;
    2043                 :            : }
    2044                 :            : 
    2045                 :            : /* True iff T is a transaction-safe function type.  */
    2046                 :            : 
    2047                 :            : bool
    2048                 :    3889710 : tx_safe_fn_type_p (tree t)
    2049                 :            : {
    2050                 :    3889710 :   if (!FUNC_OR_METHOD_TYPE_P (t))
    2051                 :            :     return false;
    2052                 :    3884880 :   return !!lookup_attribute ("transaction_safe", TYPE_ATTRIBUTES (t));
    2053                 :            : }
    2054                 :            : 
    2055                 :            : /* Return the transaction-unsafe variant of transaction-safe function type
    2056                 :            :    T.  */
    2057                 :            : 
    2058                 :            : tree
    2059                 :         50 : tx_unsafe_fn_variant (tree t)
    2060                 :            : {
    2061                 :         50 :   gcc_assert (tx_safe_fn_type_p (t));
    2062                 :         50 :   tree attrs = remove_attribute ("transaction_safe",
    2063                 :         50 :                                  TYPE_ATTRIBUTES (t));
    2064                 :         50 :   return cp_build_type_attribute_variant (t, attrs);
    2065                 :            : }
    2066                 :            : 
    2067                 :            : /* Return true iff FROM can convert to TO by a transaction-safety
    2068                 :            :    conversion.  */
    2069                 :            : 
    2070                 :            : static bool
    2071                 :   12222300 : can_convert_tx_safety (tree to, tree from)
    2072                 :            : {
    2073                 :       3462 :   return (flag_tm && tx_safe_fn_type_p (from)
    2074                 :   12222400 :           && same_type_p (to, tx_unsafe_fn_variant (from)));
    2075                 :            : }
    2076                 :            : 
    2077                 :            : /* Return true iff FROM can convert to TO by dropping noexcept.  */
    2078                 :            : 
    2079                 :            : static bool
    2080                 :   12251700 : noexcept_conv_p (tree to, tree from)
    2081                 :            : {
    2082                 :   12251700 :   if (!flag_noexcept_type)
    2083                 :            :     return false;
    2084                 :            : 
    2085                 :    3439210 :   tree t = non_reference (to);
    2086                 :    3439210 :   tree f = from;
    2087                 :    2901100 :   if (TYPE_PTRMEMFUNC_P (t)
    2088                 :    3439240 :       && TYPE_PTRMEMFUNC_P (f))
    2089                 :            :     {
    2090                 :          4 :       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
    2091                 :          4 :       f = TYPE_PTRMEMFUNC_FN_TYPE (f);
    2092                 :            :     }
    2093                 :    3439210 :   if (TYPE_PTR_P (t)
    2094                 :      25021 :       && TYPE_PTR_P (f))
    2095                 :            :     {
    2096                 :       2107 :       t = TREE_TYPE (t);
    2097                 :       2107 :       f = TREE_TYPE (f);
    2098                 :            :     }
    2099                 :    3439210 :   tree_code code = TREE_CODE (f);
    2100                 :    3439210 :   if (TREE_CODE (t) != code)
    2101                 :            :     return false;
    2102                 :    2324560 :   if (code != FUNCTION_TYPE && code != METHOD_TYPE)
    2103                 :            :     return false;
    2104                 :      49280 :   if (!type_throw_all_p (t)
    2105                 :      49280 :       || type_throw_all_p (f))
    2106                 :       4411 :     return false;
    2107                 :      44869 :   tree v = build_exception_variant (f, NULL_TREE);
    2108                 :      44869 :   return same_type_p (t, v);
    2109                 :            : }
    2110                 :            : 
    2111                 :            : /* Return true iff FROM can convert to TO by a function pointer conversion.  */
    2112                 :            : 
    2113                 :            : bool
    2114                 :   12251700 : fnptr_conv_p (tree to, tree from)
    2115                 :            : {
    2116                 :   12251700 :   tree t = non_reference (to);
    2117                 :   12251700 :   tree f = from;
    2118                 :       1740 :   if (TYPE_PTRMEMFUNC_P (t)
    2119                 :   12253400 :       && TYPE_PTRMEMFUNC_P (f))
    2120                 :            :     {
    2121                 :       1684 :       t = TYPE_PTRMEMFUNC_FN_TYPE (t);
    2122                 :       1684 :       f = TYPE_PTRMEMFUNC_FN_TYPE (f);
    2123                 :            :     }
    2124                 :   12251700 :   if (TYPE_PTR_P (t)
    2125                 :   11925900 :       && TYPE_PTR_P (f))
    2126                 :            :     {
    2127                 :   11925900 :       t = TREE_TYPE (t);
    2128                 :   11925900 :       f = TREE_TYPE (f);
    2129                 :            :     }
    2130                 :            : 
    2131                 :   12251700 :   return (noexcept_conv_p (t, f)
    2132                 :   12251700 :           || can_convert_tx_safety (t, f));
    2133                 :            : }
    2134                 :            : 
    2135                 :            : /* Return FN with any NOP_EXPRs stripped that represent function pointer
    2136                 :            :    conversions or conversions to the same type.  */
    2137                 :            : 
    2138                 :            : tree
    2139                 :       1691 : strip_fnptr_conv (tree fn)
    2140                 :            : {
    2141                 :       1719 :   while (TREE_CODE (fn) == NOP_EXPR)
    2142                 :            :     {
    2143                 :         46 :       tree op = TREE_OPERAND (fn, 0);
    2144                 :         46 :       tree ft = TREE_TYPE (fn);
    2145                 :         46 :       tree ot = TREE_TYPE (op);
    2146                 :         46 :       if (same_type_p (ft, ot)
    2147                 :         46 :           || fnptr_conv_p (ft, ot))
    2148                 :            :         fn = op;
    2149                 :            :       else
    2150                 :            :         break;
    2151                 :            :     }
    2152                 :       1691 :   return fn;
    2153                 :            : }

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.