LCOV - code coverage report
Current view: top level - gcc/cp - typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.6 % 5317 4873
Test Date: 2024-04-20 14:03:02 Functions: 97.1 % 173 168
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Build expressions with type checking for C++ compiler.
       2                 :             :    Copyright (C) 1987-2024 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 is part of the C++ front end.
      23                 :             :    It contains routines to build C++ expressions given their operands,
      24                 :             :    including computing the types of the result, C and C++ specific error
      25                 :             :    checks, and some optimization.  */
      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 "varasm.h"
      34                 :             : #include "intl.h"
      35                 :             : #include "convert.h"
      36                 :             : #include "c-family/c-objc.h"
      37                 :             : #include "c-family/c-ubsan.h"
      38                 :             : #include "gcc-rich-location.h"
      39                 :             : #include "stringpool.h"
      40                 :             : #include "attribs.h"
      41                 :             : #include "asan.h"
      42                 :             : #include "gimplify.h"
      43                 :             : 
      44                 :             : static tree cp_build_addr_expr_strict (tree, tsubst_flags_t);
      45                 :             : static tree cp_build_function_call (tree, tree, tsubst_flags_t);
      46                 :             : static tree pfn_from_ptrmemfunc (tree);
      47                 :             : static tree delta_from_ptrmemfunc (tree);
      48                 :             : static tree convert_for_assignment (tree, tree, impl_conv_rhs, tree, int,
      49                 :             :                                     tsubst_flags_t, int);
      50                 :             : static tree cp_pointer_int_sum (location_t, enum tree_code, tree, tree,
      51                 :             :                                 tsubst_flags_t);
      52                 :             : static tree rationalize_conditional_expr (enum tree_code, tree, 
      53                 :             :                                           tsubst_flags_t);
      54                 :             : static bool comp_ptr_ttypes_real (tree, tree, int);
      55                 :             : static bool comp_except_types (tree, tree, bool);
      56                 :             : static bool comp_array_types (const_tree, const_tree, compare_bounds_t, bool);
      57                 :             : static tree pointer_diff (location_t, tree, tree, tree, tsubst_flags_t, tree *);
      58                 :             : static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t);
      59                 :             : static void casts_away_constness_r (tree *, tree *, tsubst_flags_t);
      60                 :             : static bool casts_away_constness (tree, tree, tsubst_flags_t);
      61                 :             : static bool maybe_warn_about_returning_address_of_local (tree, location_t = UNKNOWN_LOCATION);
      62                 :             : static void error_args_num (location_t, tree, bool);
      63                 :             : static int convert_arguments (tree, vec<tree, va_gc> **, tree, int,
      64                 :             :                               tsubst_flags_t);
      65                 :             : static bool is_std_move_p (tree);
      66                 :             : static bool is_std_forward_p (tree);
      67                 :             : 
      68                 :             : /* Do `exp = require_complete_type (exp);' to make sure exp
      69                 :             :    does not have an incomplete type.  (That includes void types.)
      70                 :             :    Returns error_mark_node if the VALUE does not have
      71                 :             :    complete type when this function returns.  */
      72                 :             : 
      73                 :             : tree
      74                 :   100024111 : require_complete_type (tree value,
      75                 :             :                        tsubst_flags_t complain /* = tf_warning_or_error */)
      76                 :             : {
      77                 :   100024111 :   tree type;
      78                 :             : 
      79                 :   100024111 :   if (processing_template_decl || value == error_mark_node)
      80                 :             :     return value;
      81                 :             : 
      82                 :    92246774 :   if (TREE_CODE (value) == OVERLOAD)
      83                 :           0 :     type = unknown_type_node;
      84                 :             :   else
      85                 :    92246774 :     type = TREE_TYPE (value);
      86                 :             : 
      87                 :    92246774 :   if (type == error_mark_node)
      88                 :             :     return error_mark_node;
      89                 :             : 
      90                 :             :   /* First, detect a valid value with a complete type.  */
      91                 :    92246758 :   if (COMPLETE_TYPE_P (type))
      92                 :             :     return value;
      93                 :             : 
      94                 :       95270 :   if (complete_type_or_maybe_complain (type, value, complain))
      95                 :             :     return value;
      96                 :             :   else
      97                 :         102 :     return error_mark_node;
      98                 :             : }
      99                 :             : 
     100                 :             : /* Try to complete TYPE, if it is incomplete.  For example, if TYPE is
     101                 :             :    a template instantiation, do the instantiation.  Returns TYPE,
     102                 :             :    whether or not it could be completed, unless something goes
     103                 :             :    horribly wrong, in which case the error_mark_node is returned.  */
     104                 :             : 
     105                 :             : tree
     106                 : 11271892170 : complete_type (tree type)
     107                 :             : {
     108                 : 11271892170 :   if (type == NULL_TREE)
     109                 :             :     /* Rather than crash, we return something sure to cause an error
     110                 :             :        at some point.  */
     111                 :           0 :     return error_mark_node;
     112                 :             : 
     113                 : 11271892170 :   if (type == error_mark_node || COMPLETE_TYPE_P (type))
     114                 :             :     ;
     115                 :  3784295656 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     116                 :             :     {
     117                 :      554244 :       tree t = complete_type (TREE_TYPE (type));
     118                 :      554244 :       unsigned int needs_constructing, has_nontrivial_dtor;
     119                 :      554244 :       if (COMPLETE_TYPE_P (t) && !dependent_type_p (type))
     120                 :      554091 :         layout_type (type);
     121                 :      554244 :       needs_constructing
     122                 :      554244 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
     123                 :      554244 :       has_nontrivial_dtor
     124                 :      554244 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
     125                 :     1740774 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
     126                 :             :         {
     127                 :     1186530 :           TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
     128                 :     1186530 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
     129                 :             :         }
     130                 :             :     }
     131                 :  3783741412 :   else if (CLASS_TYPE_P (type))
     132                 :             :     {
     133                 :  3710377785 :       if (modules_p ())
     134                 :             :         /* TYPE could be a class member we've not loaded the definition of.  */ 
     135                 :    19487135 :         lazy_load_pendings (TYPE_NAME (TYPE_MAIN_VARIANT (type)));
     136                 :             : 
     137                 :  3710377785 :       if (CLASSTYPE_TEMPLATE_INSTANTIATION (type))
     138                 :   732255907 :         instantiate_class_template (TYPE_MAIN_VARIANT (type));
     139                 :             :     }
     140                 :             : 
     141                 :             :   return type;
     142                 :             : }
     143                 :             : 
     144                 :             : /* Like complete_type, but issue an error if the TYPE cannot be completed.
     145                 :             :    VALUE is used for informative diagnostics.
     146                 :             :    Returns NULL_TREE if the type cannot be made complete.  */
     147                 :             : 
     148                 :             : tree
     149                 :  1133468779 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
     150                 :             : {
     151                 :  1133468779 :   type = complete_type (type);
     152                 :  1133468776 :   if (type == error_mark_node)
     153                 :             :     /* We already issued an error.  */
     154                 :             :     return NULL_TREE;
     155                 :  1133468632 :   else if (!COMPLETE_TYPE_P (type))
     156                 :             :     {
     157                 :        2820 :       if (complain & tf_error)
     158                 :         556 :         cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
     159                 :        2820 :       note_failed_type_completion_for_satisfaction (type);
     160                 :        2820 :       return NULL_TREE;
     161                 :             :     }
     162                 :             :   else
     163                 :             :     return type;
     164                 :             : }
     165                 :             : 
     166                 :             : tree
     167                 :   132909441 : complete_type_or_else (tree type, tree value)
     168                 :             : {
     169                 :   132909441 :   return complete_type_or_maybe_complain (type, value, tf_warning_or_error);
     170                 :             : }
     171                 :             : 
     172                 :             : 
     173                 :             : /* Return the common type of two parameter lists.
     174                 :             :    We assume that comptypes has already been done and returned 1;
     175                 :             :    if that isn't so, this may crash.
     176                 :             : 
     177                 :             :    As an optimization, free the space we allocate if the parameter
     178                 :             :    lists are already common.  */
     179                 :             : 
     180                 :             : static tree
     181                 :     3947478 : commonparms (tree p1, tree p2)
     182                 :             : {
     183                 :     3947478 :   tree oldargs = p1, newargs, n;
     184                 :     3947478 :   int i, len;
     185                 :     3947478 :   int any_change = 0;
     186                 :             : 
     187                 :     3947478 :   len = list_length (p1);
     188                 :     3947478 :   newargs = tree_last (p1);
     189                 :             : 
     190                 :     3947478 :   if (newargs == void_list_node)
     191                 :             :     i = 1;
     192                 :             :   else
     193                 :             :     {
     194                 :       38629 :       i = 0;
     195                 :       38629 :       newargs = 0;
     196                 :             :     }
     197                 :             : 
     198                 :    13401190 :   for (; i < len; i++)
     199                 :     9453712 :     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
     200                 :             : 
     201                 :             :   n = newargs;
     202                 :             : 
     203                 :    17310039 :   for (i = 0; p1;
     204                 :    13362561 :        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
     205                 :             :     {
     206                 :    13362789 :       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
     207                 :             :         {
     208                 :         192 :           TREE_PURPOSE (n) = TREE_PURPOSE (p1);
     209                 :         192 :           any_change = 1;
     210                 :             :         }
     211                 :    13362369 :       else if (! TREE_PURPOSE (p1))
     212                 :             :         {
     213                 :    13362333 :           if (TREE_PURPOSE (p2))
     214                 :             :             {
     215                 :      406237 :               TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     216                 :      406237 :               any_change = 1;
     217                 :             :             }
     218                 :             :         }
     219                 :             :       else
     220                 :             :         {
     221                 :          36 :           if (simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)) != 1)
     222                 :          36 :             any_change = 1;
     223                 :          36 :           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     224                 :             :         }
     225                 :    13362561 :       if (TREE_VALUE (p1) != TREE_VALUE (p2))
     226                 :             :         {
     227                 :     3726832 :           any_change = 1;
     228                 :     3726832 :           TREE_VALUE (n) = merge_types (TREE_VALUE (p1), TREE_VALUE (p2));
     229                 :             :         }
     230                 :             :       else
     231                 :     9635729 :         TREE_VALUE (n) = TREE_VALUE (p1);
     232                 :             :     }
     233                 :     3947478 :   if (! any_change)
     234                 :     1339495 :     return oldargs;
     235                 :             : 
     236                 :             :   return newargs;
     237                 :             : }
     238                 :             : 
     239                 :             : /* Given a type, perhaps copied for a typedef,
     240                 :             :    find the "original" version of it.  */
     241                 :             : static tree
     242                 :    31693152 : original_type (tree t)
     243                 :             : {
     244                 :    31693152 :   int quals = cp_type_quals (t);
     245                 :    31693152 :   while (t != error_mark_node
     246                 :    32772205 :          && TYPE_NAME (t) != NULL_TREE)
     247                 :             :     {
     248                 :    11114179 :       tree x = TYPE_NAME (t);
     249                 :    11114179 :       if (TREE_CODE (x) != TYPE_DECL)
     250                 :             :         break;
     251                 :    11114179 :       x = DECL_ORIGINAL_TYPE (x);
     252                 :    11114179 :       if (x == NULL_TREE)
     253                 :             :         break;
     254                 :             :       t = x;
     255                 :             :     }
     256                 :    31693152 :   return cp_build_qualified_type (t, quals);
     257                 :             : }
     258                 :             : 
     259                 :             : /* Merge the attributes of type OTHER_TYPE into the attributes of type TYPE
     260                 :             :    and return a variant of TYPE with the merged attributes.  */
     261                 :             : 
     262                 :             : static tree
     263                 :       52384 : merge_type_attributes_from (tree type, tree other_type)
     264                 :             : {
     265                 :       52384 :   tree attrs = targetm.merge_type_attributes (type, other_type);
     266                 :       52384 :   attrs = restrict_type_identity_attributes_to (attrs, TYPE_ATTRIBUTES (type));
     267                 :       52384 :   return cp_build_type_attribute_variant (type, attrs);
     268                 :             : }
     269                 :             : 
     270                 :             : /* Compare floating point conversion ranks and subranks of T1 and T2
     271                 :             :    types.  If T1 and T2 have unordered conversion ranks, return 3.
     272                 :             :    If T1 has greater conversion rank than T2, return 2.
     273                 :             :    If T2 has greater conversion rank than T1, return -2.
     274                 :             :    If T1 has equal conversion rank as T2, return -1, 0 or 1 depending
     275                 :             :    on if T1 has smaller, equal or greater conversion subrank than
     276                 :             :    T2.  */
     277                 :             : 
     278                 :             : int
     279                 :     7611636 : cp_compare_floating_point_conversion_ranks (tree t1, tree t2)
     280                 :             : {
     281                 :     7611636 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
     282                 :     7611636 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
     283                 :     7611636 :   int extended1 = 0;
     284                 :     7611636 :   int extended2 = 0;
     285                 :             : 
     286                 :     7611636 :   if (mv1 == mv2)
     287                 :             :     return 0;
     288                 :             : 
     289                 :    60886368 :   for (int i = 0; i < NUM_FLOATN_NX_TYPES; ++i)
     290                 :             :     {
     291                 :    53275572 :       if (mv1 == FLOATN_NX_TYPE_NODE (i))
     292                 :     3423857 :         extended1 = i + 1;
     293                 :    53275572 :       if (mv2 == FLOATN_NX_TYPE_NODE (i))
     294                 :     2866720 :         extended2 = i + 1;
     295                 :             :     }
     296                 :     7610796 :   if (mv1 == bfloat16_type_node)
     297                 :      790258 :     extended1 = true;
     298                 :     7610796 :   if (mv2 == bfloat16_type_node)
     299                 :      651149 :     extended2 = true;
     300                 :     7610796 :   if (extended2 && !extended1)
     301                 :             :     {
     302                 :     3368614 :       int ret = cp_compare_floating_point_conversion_ranks (t2, t1);
     303                 :     3368614 :       return ret == 3 ? 3 : -ret;
     304                 :             :     }
     305                 :             : 
     306                 :     4242182 :   const struct real_format *fmt1 = REAL_MODE_FORMAT (TYPE_MODE (t1));
     307                 :     4242182 :   const struct real_format *fmt2 = REAL_MODE_FORMAT (TYPE_MODE (t2));
     308                 :     4242182 :   gcc_assert (fmt1->b == 2 && fmt2->b == 2);
     309                 :             :   /* For {ibm,mips}_extended_format formats, the type has variable
     310                 :             :      precision up to ~2150 bits when the first double is around maximum
     311                 :             :      representable double and second double is subnormal minimum.
     312                 :             :      So, e.g. for __ibm128 vs. std::float128_t, they have unordered
     313                 :             :      ranks.  */
     314                 :    33937456 :   int p1 = (MODE_COMPOSITE_P (TYPE_MODE (t1))
     315                 :     8484364 :             ? fmt1->emax - fmt1->emin + fmt1->p - 1 : fmt1->p);
     316                 :    33937456 :   int p2 = (MODE_COMPOSITE_P (TYPE_MODE (t2))
     317                 :     8484364 :             ? fmt2->emax - fmt2->emin + fmt2->p - 1 : fmt2->p);
     318                 :             :   /* The rank of a floating point type T is greater than the rank of
     319                 :             :      any floating-point type whose set of values is a proper subset
     320                 :             :      of the set of values of T.  */
     321                 :     4242182 :   if ((p1 > p2 && fmt1->emax >= fmt2->emax)
     322                 :     3201713 :        || (p1 == p2 && fmt1->emax > fmt2->emax))
     323                 :             :     return 2;
     324                 :     3201713 :   if ((p1 < p2 && fmt1->emax <= fmt2->emax)
     325                 :     1015518 :        || (p1 == p2 && fmt1->emax < fmt2->emax))
     326                 :             :     return -2;
     327                 :     1015518 :   if ((p1 > p2 && fmt1->emax < fmt2->emax)
     328                 :     1010517 :        || (p1 < p2 && fmt1->emax > fmt2->emax))
     329                 :             :     return 3;
     330                 :     1005516 :   if (!extended1 && !extended2)
     331                 :             :     {
     332                 :             :       /* The rank of long double is greater than the rank of double, which
     333                 :             :          is greater than the rank of float.  */
     334                 :           0 :       if (t1 == long_double_type_node)
     335                 :             :         return 2;
     336                 :           0 :       else if (t2 == long_double_type_node)
     337                 :             :         return -2;
     338                 :           0 :       if (t1 == double_type_node)
     339                 :             :         return 2;
     340                 :           0 :       else if (t2 == double_type_node)
     341                 :             :         return -2;
     342                 :           0 :       if (t1 == float_type_node)
     343                 :             :         return 2;
     344                 :           0 :       else if (t2 == float_type_node)
     345                 :             :         return -2;
     346                 :             :       return 0;
     347                 :             :     }
     348                 :             :   /* Two extended floating-point types with the same set of values have equal
     349                 :             :      ranks.  */
     350                 :     1005516 :   if (extended1 && extended2)
     351                 :             :     {
     352                 :           4 :       if ((extended1 <= NUM_FLOATN_TYPES) == (extended2 <= NUM_FLOATN_TYPES))
     353                 :             :         {
     354                 :             :           /* Prefer higher extendedN value.  */
     355                 :           0 :           if (extended1 > extended2)
     356                 :             :             return 1;
     357                 :           0 :           else if (extended1 < extended2)
     358                 :             :             return -1;
     359                 :             :           else
     360                 :             :             return 0;
     361                 :             :         }
     362                 :           4 :       else if (extended1 <= NUM_FLOATN_TYPES)
     363                 :             :         /* Prefer _FloatN type over _FloatMx type.  */
     364                 :             :         return 1;
     365                 :           2 :       else if (extended2 <= NUM_FLOATN_TYPES)
     366                 :             :         return -1;
     367                 :             :       else
     368                 :             :         return 0;
     369                 :             :     }
     370                 :             : 
     371                 :             :   /* gcc_assert (extended1 && !extended2);  */
     372                 :             :   tree *p;
     373                 :             :   int cnt = 0;
     374                 :     4022048 :   for (p = &float_type_node; p <= &long_double_type_node; ++p)
     375                 :             :     {
     376                 :     3016536 :       const struct real_format *fmt3 = REAL_MODE_FORMAT (TYPE_MODE (*p));
     377                 :     3016536 :       gcc_assert (fmt3->b == 2);
     378                 :    24132288 :       int p3 = (MODE_COMPOSITE_P (TYPE_MODE (*p))
     379                 :     6033072 :                 ? fmt3->emax - fmt3->emin + fmt3->p - 1 : fmt3->p);
     380                 :     3016536 :       if (p1 == p3 && fmt1->emax == fmt3->emax)
     381                 :      964322 :         ++cnt;
     382                 :             :     }
     383                 :             :   /* An extended floating-point type with the same set of values
     384                 :             :      as exactly one cv-unqualified standard floating-point type
     385                 :             :      has a rank equal to the rank of that standard floating-point
     386                 :             :      type.
     387                 :             : 
     388                 :             :      An extended floating-point type with the same set of values
     389                 :             :      as more than one cv-unqualified standard floating-point type
     390                 :             :      has a rank equal to the rank of double.
     391                 :             : 
     392                 :             :      Thus, if the latter is true and t2 is long double, t2
     393                 :             :      has higher rank.  */
     394                 :     1005512 :   if (cnt > 1 && mv2 == long_double_type_node)
     395                 :             :     return -2;
     396                 :             :   /* Otherwise, they have equal rank, but extended types
     397                 :             :      (other than std::bfloat16_t) have higher subrank.
     398                 :             :      std::bfloat16_t shouldn't have equal rank to any standard
     399                 :             :      floating point type.  */
     400                 :             :   return 1;
     401                 :             : }
     402                 :             : 
     403                 :             : /* Return the common type for two arithmetic types T1 and T2 under the
     404                 :             :    usual arithmetic conversions.  The default conversions have already
     405                 :             :    been applied, and enumerated types converted to their compatible
     406                 :             :    integer types.  */
     407                 :             : 
     408                 :             : static tree
     409                 :    90425244 : cp_common_type (tree t1, tree t2)
     410                 :             : {
     411                 :    90425244 :   enum tree_code code1 = TREE_CODE (t1);
     412                 :    90425244 :   enum tree_code code2 = TREE_CODE (t2);
     413                 :    90425244 :   tree attributes;
     414                 :    90425244 :   int i;
     415                 :             : 
     416                 :             : 
     417                 :             :   /* In what follows, we slightly generalize the rules given in [expr] so
     418                 :             :      as to deal with `long long' and `complex'.  First, merge the
     419                 :             :      attributes.  */
     420                 :    90425244 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     421                 :             : 
     422                 :    90425244 :   if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
     423                 :             :     {
     424                 :      809278 :       if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     425                 :      809278 :         return build_type_attribute_variant (t1, attributes);
     426                 :             :       else
     427                 :             :         return NULL_TREE;
     428                 :             :     }
     429                 :             : 
     430                 :             :   /* FIXME: Attributes.  */
     431                 :    89615966 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     432                 :             :               || VECTOR_TYPE_P (t1)
     433                 :             :               || UNSCOPED_ENUM_P (t1));
     434                 :    89615966 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     435                 :             :               || VECTOR_TYPE_P (t2)
     436                 :             :               || UNSCOPED_ENUM_P (t2));
     437                 :             : 
     438                 :             :   /* If one type is complex, form the common type of the non-complex
     439                 :             :      components, then make that complex.  Use T1 or T2 if it is the
     440                 :             :      required type.  */
     441                 :    89615966 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     442                 :             :     {
     443                 :      222207 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
     444                 :      222207 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
     445                 :      222207 :       tree subtype
     446                 :      222207 :         = type_after_usual_arithmetic_conversions (subtype1, subtype2);
     447                 :             : 
     448                 :      222207 :       if (subtype == error_mark_node)
     449                 :             :         return subtype;
     450                 :      222207 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
     451                 :      188712 :         return build_type_attribute_variant (t1, attributes);
     452                 :       33495 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
     453                 :       33428 :         return build_type_attribute_variant (t2, attributes);
     454                 :             :       else
     455                 :          67 :         return build_type_attribute_variant (build_complex_type (subtype),
     456                 :          67 :                                              attributes);
     457                 :             :     }
     458                 :             : 
     459                 :    89393759 :   if (code1 == VECTOR_TYPE)
     460                 :             :     {
     461                 :             :       /* When we get here we should have two vectors of the same size.
     462                 :             :          Just prefer the unsigned one if present.  */
     463                 :       52384 :       if (TYPE_UNSIGNED (t1))
     464                 :       11706 :         return merge_type_attributes_from (t1, t2);
     465                 :             :       else
     466                 :       40678 :         return merge_type_attributes_from (t2, t1);
     467                 :             :     }
     468                 :             : 
     469                 :             :   /* If only one is real, use it as the result.  */
     470                 :    89341375 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     471                 :     1045920 :     return build_type_attribute_variant (t1, attributes);
     472                 :    88295455 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     473                 :      989173 :     return build_type_attribute_variant (t2, attributes);
     474                 :             : 
     475                 :    87306282 :   if (code1 == REAL_TYPE
     476                 :    87306282 :       && (extended_float_type_p (t1) || extended_float_type_p (t2)))
     477                 :             :     {
     478                 :      145912 :       tree mv1 = TYPE_MAIN_VARIANT (t1);
     479                 :      145912 :       tree mv2 = TYPE_MAIN_VARIANT (t2);
     480                 :      145912 :       if (mv1 == mv2)
     481                 :      143248 :         return build_type_attribute_variant (t1, attributes);
     482                 :             : 
     483                 :        2664 :       int cmpret = cp_compare_floating_point_conversion_ranks (mv1, mv2);
     484                 :        2664 :       if (cmpret == 3)
     485                 :           0 :         return error_mark_node;
     486                 :        2664 :       else if (cmpret >= 0)
     487                 :        2416 :         return build_type_attribute_variant (t1, attributes);
     488                 :             :       else
     489                 :         248 :         return build_type_attribute_variant (t2, attributes);
     490                 :             :     }
     491                 :             : 
     492                 :             :   /* Both real or both integers; use the one with greater precision.  */
     493                 :    87160370 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     494                 :    13397487 :     return build_type_attribute_variant (t1, attributes);
     495                 :    73762883 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
     496                 :     1412076 :     return build_type_attribute_variant (t2, attributes);
     497                 :             : 
     498                 :             :   /* The types are the same; no need to do anything fancy.  */
     499                 :    72350807 :   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     500                 :    66718251 :     return build_type_attribute_variant (t1, attributes);
     501                 :             : 
     502                 :     5632556 :   if (code1 != REAL_TYPE)
     503                 :             :     {
     504                 :             :       /* If one is unsigned long long, then convert the other to unsigned
     505                 :             :          long long.  */
     506                 :     5632552 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node)
     507                 :     5632552 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_unsigned_type_node))
     508                 :      126844 :         return build_type_attribute_variant (long_long_unsigned_type_node,
     509                 :      126844 :                                              attributes);
     510                 :             :       /* If one is a long long, and the other is an unsigned long, and
     511                 :             :          long long can represent all the values of an unsigned long, then
     512                 :             :          convert to a long long.  Otherwise, convert to an unsigned long
     513                 :             :          long.  Otherwise, if either operand is long long, convert the
     514                 :             :          other to long long.
     515                 :             : 
     516                 :             :          Since we're here, we know the TYPE_PRECISION is the same;
     517                 :             :          therefore converting to long long cannot represent all the values
     518                 :             :          of an unsigned long, so we choose unsigned long long in that
     519                 :             :          case.  */
     520                 :     5505708 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_integer_type_node)
     521                 :     5505708 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_integer_type_node))
     522                 :             :         {
     523                 :         629 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     524                 :         629 :                     ? long_long_unsigned_type_node
     525                 :         318 :                     : long_long_integer_type_node);
     526                 :         318 :           return build_type_attribute_variant (t, attributes);
     527                 :             :         }
     528                 :             : 
     529                 :             :       /* Go through the same procedure, but for longs.  */
     530                 :     5505390 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_unsigned_type_node)
     531                 :     5505390 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_unsigned_type_node))
     532                 :      656599 :         return build_type_attribute_variant (long_unsigned_type_node,
     533                 :      656599 :                                              attributes);
     534                 :     4848791 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_integer_type_node)
     535                 :     4848791 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_integer_type_node))
     536                 :             :         {
     537                 :       78656 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     538                 :       78656 :                     ? long_unsigned_type_node : long_integer_type_node);
     539                 :       39650 :           return build_type_attribute_variant (t, attributes);
     540                 :             :         }
     541                 :             : 
     542                 :             :       /* For __intN types, either the type is __int128 (and is lower
     543                 :             :          priority than the types checked above, but higher than other
     544                 :             :          128-bit types) or it's known to not be the same size as other
     545                 :             :          types (enforced in toplev.cc).  Prefer the unsigned type. */
     546                 :     9618240 :       for (i = 0; i < NUM_INT_N_ENTS; i ++)
     547                 :             :         {
     548                 :     4809141 :           if (int_n_enabled_p [i]
     549                 :     4809141 :               && (same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].signed_type)
     550                 :     4731943 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].signed_type)
     551                 :     4731931 :                   || same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].unsigned_type)
     552                 :     4731931 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].unsigned_type)))
     553                 :             :             {
     554                 :          72 :               tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     555                 :          72 :                         ? int_n_trees[i].unsigned_type
     556                 :          42 :                         : int_n_trees[i].signed_type);
     557                 :          42 :               return build_type_attribute_variant (t, attributes);
     558                 :             :             }
     559                 :             :         }
     560                 :             : 
     561                 :             :       /* Otherwise prefer the unsigned one.  */
     562                 :     4809099 :       if (TYPE_UNSIGNED (t1))
     563                 :     3841980 :         return build_type_attribute_variant (t1, attributes);
     564                 :             :       else
     565                 :      967119 :         return build_type_attribute_variant (t2, attributes);
     566                 :             :     }
     567                 :             :   else
     568                 :             :     {
     569                 :           4 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_double_type_node)
     570                 :           4 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_double_type_node))
     571                 :           0 :         return build_type_attribute_variant (long_double_type_node,
     572                 :           0 :                                              attributes);
     573                 :           4 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), double_type_node)
     574                 :           4 :           || same_type_p (TYPE_MAIN_VARIANT (t2), double_type_node))
     575                 :           4 :         return build_type_attribute_variant (double_type_node,
     576                 :           4 :                                              attributes);
     577                 :           0 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), float_type_node)
     578                 :           0 :           || same_type_p (TYPE_MAIN_VARIANT (t2), float_type_node))
     579                 :           0 :         return build_type_attribute_variant (float_type_node,
     580                 :           0 :                                              attributes);
     581                 :             : 
     582                 :             :       /* Two floating-point types whose TYPE_MAIN_VARIANTs are none of
     583                 :             :          the standard C++ floating-point types.  Logic earlier in this
     584                 :             :          function has already eliminated the possibility that
     585                 :             :          TYPE_PRECISION (t2) != TYPE_PRECISION (t1), so there's no
     586                 :             :          compelling reason to choose one or the other.  */
     587                 :           0 :       return build_type_attribute_variant (t1, attributes);
     588                 :             :     }
     589                 :             : }
     590                 :             : 
     591                 :             : /* T1 and T2 are arithmetic or enumeration types.  Return the type
     592                 :             :    that will result from the "usual arithmetic conversions" on T1 and
     593                 :             :    T2 as described in [expr].  */
     594                 :             : 
     595                 :             : tree
     596                 :      890170 : type_after_usual_arithmetic_conversions (tree t1, tree t2)
     597                 :             : {
     598                 :      890170 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     599                 :             :               || VECTOR_TYPE_P (t1)
     600                 :             :               || UNSCOPED_ENUM_P (t1));
     601                 :      890170 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     602                 :             :               || VECTOR_TYPE_P (t2)
     603                 :             :               || UNSCOPED_ENUM_P (t2));
     604                 :             : 
     605                 :             :   /* Perform the integral promotions.  We do not promote real types here.  */
     606                 :      890170 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (t1)
     607                 :      667577 :       && INTEGRAL_OR_ENUMERATION_TYPE_P (t2))
     608                 :             :     {
     609                 :      667198 :       t1 = type_promotes_to (t1);
     610                 :      667198 :       t2 = type_promotes_to (t2);
     611                 :             :     }
     612                 :             : 
     613                 :      890170 :   return cp_common_type (t1, t2);
     614                 :             : }
     615                 :             : 
     616                 :             : static void
     617                 :          56 : composite_pointer_error (const op_location_t &location,
     618                 :             :                          diagnostic_t kind, tree t1, tree t2,
     619                 :             :                          composite_pointer_operation operation)
     620                 :             : {
     621                 :          56 :   switch (operation)
     622                 :             :     {
     623                 :          44 :     case CPO_COMPARISON:
     624                 :          44 :       emit_diagnostic (kind, location, 0,
     625                 :             :                        "comparison between "
     626                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     627                 :             :                        t1, t2);
     628                 :          44 :       break;
     629                 :           0 :     case CPO_CONVERSION:
     630                 :           0 :       emit_diagnostic (kind, location, 0,
     631                 :             :                        "conversion between "
     632                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     633                 :             :                        t1, t2);
     634                 :           0 :       break;
     635                 :          12 :     case CPO_CONDITIONAL_EXPR:
     636                 :          12 :       emit_diagnostic (kind, location, 0,
     637                 :             :                        "conditional expression between "
     638                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     639                 :             :                        t1, t2);
     640                 :          12 :       break;
     641                 :           0 :     default:
     642                 :           0 :       gcc_unreachable ();
     643                 :             :     }
     644                 :          56 : }
     645                 :             : 
     646                 :             : /* Subroutine of composite_pointer_type to implement the recursive
     647                 :             :    case.  See that function for documentation of the parameters.  And ADD_CONST
     648                 :             :    is used to track adding "const" where needed.  */
     649                 :             : 
     650                 :             : static tree
     651                 :     3346700 : composite_pointer_type_r (const op_location_t &location,
     652                 :             :                           tree t1, tree t2, bool *add_const,
     653                 :             :                           composite_pointer_operation operation,
     654                 :             :                           tsubst_flags_t complain)
     655                 :             : {
     656                 :     3346700 :   tree pointee1;
     657                 :     3346700 :   tree pointee2;
     658                 :     3346700 :   tree result_type;
     659                 :     3346700 :   tree attributes;
     660                 :             : 
     661                 :             :   /* Determine the types pointed to by T1 and T2.  */
     662                 :     3346700 :   if (TYPE_PTR_P (t1))
     663                 :             :     {
     664                 :     3346177 :       pointee1 = TREE_TYPE (t1);
     665                 :     3346177 :       pointee2 = TREE_TYPE (t2);
     666                 :             :     }
     667                 :             :   else
     668                 :             :     {
     669                 :         523 :       pointee1 = TYPE_PTRMEM_POINTED_TO_TYPE (t1);
     670                 :         523 :       pointee2 = TYPE_PTRMEM_POINTED_TO_TYPE (t2);
     671                 :             :     }
     672                 :             : 
     673                 :             :   /* [expr.type]
     674                 :             : 
     675                 :             :      If T1 and T2 are similar types, the result is the cv-combined type of
     676                 :             :      T1 and T2.  */
     677                 :     3346700 :   if (same_type_ignoring_top_level_qualifiers_p (pointee1, pointee2))
     678                 :             :     result_type = pointee1;
     679                 :          36 :   else if ((TYPE_PTR_P (pointee1) && TYPE_PTR_P (pointee2))
     680                 :         155 :            || (TYPE_PTRMEM_P (pointee1) && TYPE_PTRMEM_P (pointee2)))
     681                 :             :     {
     682                 :          36 :       result_type = composite_pointer_type_r (location, pointee1, pointee2,
     683                 :             :                                               add_const, operation, complain);
     684                 :          36 :       if (result_type == error_mark_node)
     685                 :             :         return error_mark_node;
     686                 :             :     }
     687                 :             :   else
     688                 :             :     {
     689                 :         119 :       if (complain & tf_error)
     690                 :          40 :         composite_pointer_error (location, DK_PERMERROR,
     691                 :             :                                  t1, t2, operation);
     692                 :             :       else
     693                 :          79 :         return error_mark_node;
     694                 :          40 :       result_type = void_type_node;
     695                 :             :     }
     696                 :     3346613 :   const int q1 = cp_type_quals (pointee1);
     697                 :     3346613 :   const int q2 = cp_type_quals (pointee2);
     698                 :     3346613 :   const int quals = q1 | q2;
     699                 :     3346613 :   result_type = cp_build_qualified_type (result_type,
     700                 :     3346613 :                                          (quals | (*add_const
     701                 :     3346613 :                                                    ? TYPE_QUAL_CONST
     702                 :             :                                                    : TYPE_UNQUALIFIED)));
     703                 :             :   /* The cv-combined type can add "const" as per [conv.qual]/3.3 (except for
     704                 :             :      the TLQ).  The reason is that both T1 and T2 can then be converted to the
     705                 :             :      cv-combined type of T1 and T2.  */
     706                 :     3346613 :   if (quals != q1 || quals != q2)
     707                 :      536258 :     *add_const = true;
     708                 :             :   /* If the original types were pointers to members, so is the
     709                 :             :      result.  */
     710                 :     3346613 :   if (TYPE_PTRMEM_P (t1))
     711                 :             :     {
     712                 :         511 :       if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     713                 :             :                         TYPE_PTRMEM_CLASS_TYPE (t2)))
     714                 :             :         {
     715                 :           0 :           if (complain & tf_error)
     716                 :           0 :             composite_pointer_error (location, DK_PERMERROR,
     717                 :             :                                      t1, t2, operation);
     718                 :             :           else
     719                 :           0 :             return error_mark_node;
     720                 :             :         }
     721                 :         511 :       result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
     722                 :             :                                        result_type);
     723                 :             :     }
     724                 :             :   else
     725                 :     3346102 :     result_type = build_pointer_type (result_type);
     726                 :             : 
     727                 :             :   /* Merge the attributes.  */
     728                 :     3346613 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     729                 :     3346613 :   return build_type_attribute_variant (result_type, attributes);
     730                 :             : }
     731                 :             : 
     732                 :             : /* Return the composite pointer type (see [expr.type]) for T1 and T2.
     733                 :             :    ARG1 and ARG2 are the values with those types.  The OPERATION is to
     734                 :             :    describe the operation between the pointer types,
     735                 :             :    in case an error occurs.
     736                 :             : 
     737                 :             :    This routine also implements the computation of a common type for
     738                 :             :    pointers-to-members as per [expr.eq].  */
     739                 :             : 
     740                 :             : tree
     741                 :     3488732 : composite_pointer_type (const op_location_t &location,
     742                 :             :                         tree t1, tree t2, tree arg1, tree arg2,
     743                 :             :                         composite_pointer_operation operation, 
     744                 :             :                         tsubst_flags_t complain)
     745                 :             : {
     746                 :     3488732 :   tree class1;
     747                 :     3488732 :   tree class2;
     748                 :             : 
     749                 :             :   /* [expr.type]
     750                 :             : 
     751                 :             :      If one operand is a null pointer constant, the composite pointer
     752                 :             :      type is the type of the other operand.  */
     753                 :     3488732 :   if (null_ptr_cst_p (arg1))
     754                 :             :     return t2;
     755                 :     3488368 :   if (null_ptr_cst_p (arg2))
     756                 :             :     return t1;
     757                 :             : 
     758                 :             :   /* We have:
     759                 :             : 
     760                 :             :        [expr.type]
     761                 :             : 
     762                 :             :        If one of the operands has type "pointer to cv1 void", then
     763                 :             :        the other has type "pointer to cv2 T", and the composite pointer
     764                 :             :        type is "pointer to cv12 void", where cv12 is the union of cv1
     765                 :             :        and cv2.
     766                 :             : 
     767                 :             :     If either type is a pointer to void, make sure it is T1.  */
     768                 :     3476344 :   if (TYPE_PTR_P (t2) && VOID_TYPE_P (TREE_TYPE (t2)))
     769                 :             :     std::swap (t1, t2);
     770                 :             : 
     771                 :             :   /* Now, if T1 is a pointer to void, merge the qualifiers.  */
     772                 :     3476344 :   if (TYPE_PTR_P (t1) && VOID_TYPE_P (TREE_TYPE (t1)))
     773                 :             :     {
     774                 :      129470 :       tree attributes;
     775                 :      129470 :       tree result_type;
     776                 :             : 
     777                 :      129470 :       if (TYPE_PTRFN_P (t2))
     778                 :             :         {
     779                 :          13 :           if (complain & tf_error)
     780                 :             :             {
     781                 :          12 :               switch (operation)
     782                 :             :                 {
     783                 :          12 :                 case CPO_COMPARISON:
     784                 :          12 :                   pedwarn (location, OPT_Wpedantic, 
     785                 :             :                            "ISO C++ forbids comparison between pointer "
     786                 :             :                            "of type %<void *%> and pointer-to-function");
     787                 :          12 :                   break;
     788                 :           0 :                 case CPO_CONVERSION:
     789                 :           0 :                   pedwarn (location, OPT_Wpedantic,
     790                 :             :                            "ISO C++ forbids conversion between pointer "
     791                 :             :                            "of type %<void *%> and pointer-to-function");
     792                 :           0 :                   break;
     793                 :           0 :                 case CPO_CONDITIONAL_EXPR:
     794                 :           0 :                   pedwarn (location, OPT_Wpedantic,
     795                 :             :                            "ISO C++ forbids conditional expression between "
     796                 :             :                            "pointer of type %<void *%> and "
     797                 :             :                            "pointer-to-function");
     798                 :           0 :                   break;
     799                 :           0 :                 default:
     800                 :           0 :                   gcc_unreachable ();
     801                 :             :                 }
     802                 :             :             }
     803                 :             :           else
     804                 :           1 :             return error_mark_node;
     805                 :             :         }
     806                 :      129469 :       result_type
     807                 :      129469 :         = cp_build_qualified_type (void_type_node,
     808                 :      129469 :                                    (cp_type_quals (TREE_TYPE (t1))
     809                 :      129469 :                                     | cp_type_quals (TREE_TYPE (t2))));
     810                 :      129469 :       result_type = build_pointer_type (result_type);
     811                 :             :       /* Merge the attributes.  */
     812                 :      129469 :       attributes = (*targetm.merge_type_attributes) (t1, t2);
     813                 :      129469 :       return build_type_attribute_variant (result_type, attributes);
     814                 :             :     }
     815                 :             : 
     816                 :     3346874 :   if (c_dialect_objc () && TYPE_PTR_P (t1)
     817                 :           0 :       && TYPE_PTR_P (t2))
     818                 :             :     {
     819                 :           0 :       if (objc_have_common_type (t1, t2, -3, NULL_TREE))
     820                 :           0 :         return objc_common_type (t1, t2);
     821                 :             :     }
     822                 :             : 
     823                 :             :   /* if T1 or T2 is "pointer to noexcept function" and the other type is
     824                 :             :      "pointer to function", where the function types are otherwise the same,
     825                 :             :      "pointer to function" */
     826                 :     3346874 :   if (fnptr_conv_p (t1, t2))
     827                 :             :     return t1;
     828                 :     3346792 :   if (fnptr_conv_p (t2, t1))
     829                 :             :     return t2;
     830                 :             : 
     831                 :             :   /* [expr.eq] permits the application of a pointer conversion to
     832                 :             :      bring the pointers to a common type.  */
     833                 :     3346165 :   if (TYPE_PTR_P (t1) && TYPE_PTR_P (t2)
     834                 :     3346165 :       && CLASS_TYPE_P (TREE_TYPE (t1))
     835                 :      652065 :       && CLASS_TYPE_P (TREE_TYPE (t2))
     836                 :     3998767 :       && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t1),
     837                 :      652061 :                                                      TREE_TYPE (t2)))
     838                 :             :     {
     839                 :       40158 :       class1 = TREE_TYPE (t1);
     840                 :       40158 :       class2 = TREE_TYPE (t2);
     841                 :             : 
     842                 :       40158 :       if (DERIVED_FROM_P (class1, class2))
     843                 :       22936 :         t2 = (build_pointer_type
     844                 :       11468 :               (cp_build_qualified_type (class1, cp_type_quals (class2))));
     845                 :       28690 :       else if (DERIVED_FROM_P (class2, class1))
     846                 :       57332 :         t1 = (build_pointer_type
     847                 :       28666 :               (cp_build_qualified_type (class2, cp_type_quals (class1))));
     848                 :             :       else
     849                 :             :         {
     850                 :          24 :           if (complain & tf_error)
     851                 :          16 :             composite_pointer_error (location, DK_ERROR, t1, t2, operation);
     852                 :          24 :           return error_mark_node;
     853                 :             :         }
     854                 :             :     }
     855                 :             :   /* [expr.eq] permits the application of a pointer-to-member
     856                 :             :      conversion to change the class type of one of the types.  */
     857                 :     3306117 :   else if (TYPE_PTRMEM_P (t1)
     858                 :     3306658 :            && !same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     859                 :             :                             TYPE_PTRMEM_CLASS_TYPE (t2)))
     860                 :             :     {
     861                 :          57 :       class1 = TYPE_PTRMEM_CLASS_TYPE (t1);
     862                 :          57 :       class2 = TYPE_PTRMEM_CLASS_TYPE (t2);
     863                 :             : 
     864                 :          57 :       if (DERIVED_FROM_P (class1, class2))
     865                 :          26 :         t1 = build_ptrmem_type (class2, TYPE_PTRMEM_POINTED_TO_TYPE (t1));
     866                 :          31 :       else if (DERIVED_FROM_P (class2, class1))
     867                 :          13 :         t2 = build_ptrmem_type (class1, TYPE_PTRMEM_POINTED_TO_TYPE (t2));
     868                 :             :       else
     869                 :             :         {
     870                 :          18 :           if (complain & tf_error)
     871                 :           4 :             switch (operation)
     872                 :             :               {
     873                 :           4 :               case CPO_COMPARISON:
     874                 :           4 :                 error_at (location, "comparison between distinct "
     875                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     876                 :             :                           t1, t2);
     877                 :           4 :                 break;
     878                 :           0 :               case CPO_CONVERSION:
     879                 :           0 :                 error_at (location, "conversion between distinct "
     880                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     881                 :             :                           t1, t2);
     882                 :           0 :                 break;
     883                 :           0 :               case CPO_CONDITIONAL_EXPR:
     884                 :           0 :                 error_at (location, "conditional expression between distinct "
     885                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     886                 :             :                           t1, t2);
     887                 :           0 :                 break;
     888                 :           0 :               default:
     889                 :           0 :                 gcc_unreachable ();
     890                 :             :               }
     891                 :          18 :           return error_mark_node;
     892                 :             :         }
     893                 :             :     }
     894                 :             : 
     895                 :     3346664 :   bool add_const = false;
     896                 :     3346664 :   return composite_pointer_type_r (location, t1, t2, &add_const, operation,
     897                 :     3346664 :                                    complain);
     898                 :             : }
     899                 :             : 
     900                 :             : /* Return the merged type of two types.
     901                 :             :    We assume that comptypes has already been done and returned 1;
     902                 :             :    if that isn't so, this may crash.
     903                 :             : 
     904                 :             :    This just combines attributes and default arguments; any other
     905                 :             :    differences would cause the two types to compare unalike.  */
     906                 :             : 
     907                 :             : tree
     908                 :    27834307 : merge_types (tree t1, tree t2)
     909                 :             : {
     910                 :    27834307 :   enum tree_code code1;
     911                 :    27834307 :   enum tree_code code2;
     912                 :    27834307 :   tree attributes;
     913                 :             : 
     914                 :             :   /* Save time if the two types are the same.  */
     915                 :    27834307 :   if (t1 == t2)
     916                 :             :     return t1;
     917                 :    15846576 :   if (original_type (t1) == original_type (t2))
     918                 :             :     return t1;
     919                 :             : 
     920                 :             :   /* If one type is nonsense, use the other.  */
     921                 :    15788109 :   if (t1 == error_mark_node)
     922                 :             :     return t2;
     923                 :    15788109 :   if (t2 == error_mark_node)
     924                 :             :     return t1;
     925                 :             : 
     926                 :             :   /* Handle merging an auto redeclaration with a previous deduced
     927                 :             :      return type.  */
     928                 :    15788109 :   if (is_auto (t1))
     929                 :             :     return t2;
     930                 :             : 
     931                 :             :   /* Merge the attributes.  */
     932                 :    15778779 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     933                 :             : 
     934                 :    15778779 :   if (TYPE_PTRMEMFUNC_P (t1))
     935                 :          20 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
     936                 :    15778779 :   if (TYPE_PTRMEMFUNC_P (t2))
     937                 :          20 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
     938                 :             : 
     939                 :    15778779 :   code1 = TREE_CODE (t1);
     940                 :    15778779 :   code2 = TREE_CODE (t2);
     941                 :    15778779 :   if (code1 != code2)
     942                 :             :     {
     943                 :           0 :       gcc_assert (code1 == TYPENAME_TYPE || code2 == TYPENAME_TYPE);
     944                 :           0 :       if (code1 == TYPENAME_TYPE)
     945                 :             :         {
     946                 :           0 :           t1 = resolve_typename_type (t1, /*only_current_p=*/true);
     947                 :           0 :           code1 = TREE_CODE (t1);
     948                 :             :         }
     949                 :             :       else
     950                 :             :         {
     951                 :           0 :           t2 = resolve_typename_type (t2, /*only_current_p=*/true);
     952                 :           0 :           code2 = TREE_CODE (t2);
     953                 :             :         }
     954                 :             :     }
     955                 :             : 
     956                 :    15778779 :   switch (code1)
     957                 :             :     {
     958                 :     2728201 :     case POINTER_TYPE:
     959                 :     2728201 :     case REFERENCE_TYPE:
     960                 :             :       /* For two pointers, do this recursively on the target type.  */
     961                 :     2728201 :       {
     962                 :     2728201 :         tree target = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     963                 :     2728201 :         int quals = cp_type_quals (t1);
     964                 :             : 
     965                 :     2728201 :         if (code1 == POINTER_TYPE)
     966                 :             :           {
     967                 :      705259 :             t1 = build_pointer_type (target);
     968                 :      705259 :             if (TREE_CODE (target) == METHOD_TYPE)
     969                 :          20 :               t1 = build_ptrmemfunc_type (t1);
     970                 :             :           }
     971                 :             :         else
     972                 :     2022942 :           t1 = cp_build_reference_type (target, TYPE_REF_IS_RVALUE (t1));
     973                 :     2728201 :         t1 = build_type_attribute_variant (t1, attributes);
     974                 :     2728201 :         t1 = cp_build_qualified_type (t1, quals);
     975                 :             : 
     976                 :     2728201 :         return t1;
     977                 :             :       }
     978                 :             : 
     979                 :          15 :     case OFFSET_TYPE:
     980                 :          15 :       {
     981                 :          15 :         int quals;
     982                 :          15 :         tree pointee;
     983                 :          15 :         quals = cp_type_quals (t1);
     984                 :          15 :         pointee = merge_types (TYPE_PTRMEM_POINTED_TO_TYPE (t1),
     985                 :          15 :                                TYPE_PTRMEM_POINTED_TO_TYPE (t2));
     986                 :          15 :         t1 = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
     987                 :             :                                 pointee);
     988                 :          15 :         t1 = cp_build_qualified_type (t1, quals);
     989                 :          15 :         break;
     990                 :             :       }
     991                 :             : 
     992                 :       10451 :     case ARRAY_TYPE:
     993                 :       10451 :       {
     994                 :       10451 :         tree elt = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     995                 :             :         /* Save space: see if the result is identical to one of the args.  */
     996                 :       20902 :         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
     997                 :       10425 :           return build_type_attribute_variant (t1, attributes);
     998                 :          44 :         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
     999                 :          18 :           return build_type_attribute_variant (t2, attributes);
    1000                 :             :         /* Merge the element types, and have a size if either arg has one.  */
    1001                 :           8 :         t1 = build_cplus_array_type
    1002                 :           8 :           (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
    1003                 :           8 :         break;
    1004                 :             :       }
    1005                 :             : 
    1006                 :     4088203 :     case FUNCTION_TYPE:
    1007                 :             :       /* Function types: prefer the one that specified arg types.
    1008                 :             :          If both do, merge the arg types.  Also merge the return types.  */
    1009                 :     4088203 :       {
    1010                 :     4088203 :         tree valtype = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1011                 :     4088203 :         tree p1 = TYPE_ARG_TYPES (t1);
    1012                 :     4088203 :         tree p2 = TYPE_ARG_TYPES (t2);
    1013                 :     4088203 :         tree parms;
    1014                 :             : 
    1015                 :             :         /* Save space: see if the result is identical to one of the args.  */
    1016                 :     4088203 :         if (valtype == TREE_TYPE (t1) && ! p2)
    1017                 :           0 :           return cp_build_type_attribute_variant (t1, attributes);
    1018                 :     4088203 :         if (valtype == TREE_TYPE (t2) && ! p1)
    1019                 :           0 :           return cp_build_type_attribute_variant (t2, attributes);
    1020                 :             : 
    1021                 :             :         /* Simple way if one arg fails to specify argument types.  */
    1022                 :     8176406 :         if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
    1023                 :             :           parms = p2;
    1024                 :     7894956 :         else if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
    1025                 :             :           parms = p1;
    1026                 :             :         else
    1027                 :     3947478 :           parms = commonparms (p1, p2);
    1028                 :             : 
    1029                 :     4088203 :         cp_cv_quals quals = type_memfn_quals (t1);
    1030                 :     4088203 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1031                 :     4088203 :         gcc_assert (quals == type_memfn_quals (t2));
    1032                 :     4088203 :         gcc_assert (rqual == type_memfn_rqual (t2));
    1033                 :             : 
    1034                 :     4088203 :         tree rval = build_function_type (valtype, parms);
    1035                 :     4088203 :         rval = apply_memfn_quals (rval, quals);
    1036                 :     4088203 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1037                 :     4088203 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1038                 :     4088203 :         bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1039                 :     4088203 :         t1 = build_cp_fntype_variant (rval, rqual, raises, late_return_type_p);
    1040                 :     4088203 :         break;
    1041                 :             :       }
    1042                 :             : 
    1043                 :     3820049 :     case METHOD_TYPE:
    1044                 :     3820049 :       {
    1045                 :             :         /* Get this value the long way, since TYPE_METHOD_BASETYPE
    1046                 :             :            is just the main variant of this.  */
    1047                 :     3820049 :         tree basetype = class_of_this_parm (t2);
    1048                 :     3820049 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1049                 :     3820049 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1050                 :     3820049 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1051                 :     3820049 :         tree t3;
    1052                 :     3820049 :         bool late_return_type_1_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1053                 :             : 
    1054                 :             :         /* If this was a member function type, get back to the
    1055                 :             :            original type of type member function (i.e., without
    1056                 :             :            the class instance variable up front.  */
    1057                 :     3820049 :         t1 = build_function_type (TREE_TYPE (t1),
    1058                 :     3820049 :                                   TREE_CHAIN (TYPE_ARG_TYPES (t1)));
    1059                 :     3820049 :         t2 = build_function_type (TREE_TYPE (t2),
    1060                 :     3820049 :                                   TREE_CHAIN (TYPE_ARG_TYPES (t2)));
    1061                 :     3820049 :         t3 = merge_types (t1, t2);
    1062                 :     3820049 :         t3 = build_method_type_directly (basetype, TREE_TYPE (t3),
    1063                 :     3820049 :                                          TYPE_ARG_TYPES (t3));
    1064                 :     3820049 :         t1 = build_cp_fntype_variant (t3, rqual, raises, late_return_type_1_p);
    1065                 :     3820049 :         break;
    1066                 :             :       }
    1067                 :             : 
    1068                 :             :     case TYPENAME_TYPE:
    1069                 :             :       /* There is no need to merge attributes into a TYPENAME_TYPE.
    1070                 :             :          When the type is instantiated it will have whatever
    1071                 :             :          attributes result from the instantiation.  */
    1072                 :             :       return t1;
    1073                 :             : 
    1074                 :     5122558 :     default:;
    1075                 :     5122558 :       if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1076                 :             :         return t1;
    1077                 :          15 :       else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1078                 :             :         return t2;
    1079                 :             :       break;
    1080                 :             :     }
    1081                 :             : 
    1082                 :     7908275 :   return cp_build_type_attribute_variant (t1, attributes);
    1083                 :             : }
    1084                 :             : 
    1085                 :             : /* Return the ARRAY_TYPE type without its domain.  */
    1086                 :             : 
    1087                 :             : tree
    1088                 :         226 : strip_array_domain (tree type)
    1089                 :             : {
    1090                 :         226 :   tree t2;
    1091                 :         226 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1092                 :         226 :   if (TYPE_DOMAIN (type) == NULL_TREE)
    1093                 :             :     return type;
    1094                 :         204 :   t2 = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
    1095                 :         204 :   return cp_build_type_attribute_variant (t2, TYPE_ATTRIBUTES (type));
    1096                 :             : }
    1097                 :             : 
    1098                 :             : /* Wrapper around cp_common_type that is used by c-common.cc and other
    1099                 :             :    front end optimizations that remove promotions.  
    1100                 :             : 
    1101                 :             :    Return the common type for two arithmetic types T1 and T2 under the
    1102                 :             :    usual arithmetic conversions.  The default conversions have already
    1103                 :             :    been applied, and enumerated types converted to their compatible
    1104                 :             :    integer types.  */
    1105                 :             : 
    1106                 :             : tree
    1107                 :      382325 : common_type (tree t1, tree t2)
    1108                 :             : {
    1109                 :             :   /* If one type is nonsense, use the other  */
    1110                 :      382325 :   if (t1 == error_mark_node)
    1111                 :             :     return t2;
    1112                 :      382325 :   if (t2 == error_mark_node)
    1113                 :             :     return t1;
    1114                 :             : 
    1115                 :      382325 :   return cp_common_type (t1, t2);
    1116                 :             : }
    1117                 :             : 
    1118                 :             : /* Return the common type of two pointer types T1 and T2.  This is the
    1119                 :             :    type for the result of most arithmetic operations if the operands
    1120                 :             :    have the given two types.
    1121                 :             :  
    1122                 :             :    We assume that comp_target_types has already been done and returned
    1123                 :             :    nonzero; if that isn't so, this may crash.  */
    1124                 :             : 
    1125                 :             : tree
    1126                 :     1153579 : common_pointer_type (tree t1, tree t2)
    1127                 :             : {
    1128                 :     1153579 :   gcc_assert ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
    1129                 :             :               || (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
    1130                 :             :               || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)));
    1131                 :             : 
    1132                 :     1153579 :   return composite_pointer_type (input_location, t1, t2,
    1133                 :             :                                  error_mark_node, error_mark_node,
    1134                 :     1153579 :                                  CPO_CONVERSION, tf_warning_or_error);
    1135                 :             : }
    1136                 :             : 
    1137                 :             : /* Compare two exception specifier types for exactness or subsetness, if
    1138                 :             :    allowed. Returns false for mismatch, true for match (same, or
    1139                 :             :    derived and !exact).
    1140                 :             : 
    1141                 :             :    [except.spec] "If a class X ... objects of class X or any class publicly
    1142                 :             :    and unambiguously derived from X. Similarly, if a pointer type Y * ...
    1143                 :             :    exceptions of type Y * or that are pointers to any type publicly and
    1144                 :             :    unambiguously derived from Y. Otherwise a function only allows exceptions
    1145                 :             :    that have the same type ..."
    1146                 :             :    This does not mention cv qualifiers and is different to what throw
    1147                 :             :    [except.throw] and catch [except.catch] will do. They will ignore the
    1148                 :             :    top level cv qualifiers, and allow qualifiers in the pointer to class
    1149                 :             :    example.
    1150                 :             : 
    1151                 :             :    We implement the letter of the standard.  */
    1152                 :             : 
    1153                 :             : static bool
    1154                 :        2415 : comp_except_types (tree a, tree b, bool exact)
    1155                 :             : {
    1156                 :        2415 :   if (same_type_p (a, b))
    1157                 :             :     return true;
    1158                 :         989 :   else if (!exact)
    1159                 :             :     {
    1160                 :          22 :       if (cp_type_quals (a) || cp_type_quals (b))
    1161                 :           0 :         return false;
    1162                 :             : 
    1163                 :          22 :       if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
    1164                 :             :         {
    1165                 :          14 :           a = TREE_TYPE (a);
    1166                 :          14 :           b = TREE_TYPE (b);
    1167                 :          14 :           if (cp_type_quals (a) || cp_type_quals (b))
    1168                 :           2 :             return false;
    1169                 :             :         }
    1170                 :             : 
    1171                 :          20 :       if (TREE_CODE (a) != RECORD_TYPE
    1172                 :          20 :           || TREE_CODE (b) != RECORD_TYPE)
    1173                 :             :         return false;
    1174                 :             : 
    1175                 :          18 :       if (publicly_uniquely_derived_p (a, b))
    1176                 :             :         return true;
    1177                 :             :     }
    1178                 :             :   return false;
    1179                 :             : }
    1180                 :             : 
    1181                 :             : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
    1182                 :             :    If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
    1183                 :             :    If EXACT is ce_type, the C++17 type compatibility rules apply.
    1184                 :             :    If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
    1185                 :             :    If EXACT is ce_exact, the specs must be exactly the same. Exception lists
    1186                 :             :    are unordered, but we've already filtered out duplicates. Most lists will
    1187                 :             :    be in order, we should try to make use of that.  */
    1188                 :             : 
    1189                 :             : bool
    1190                 :  1606698330 : comp_except_specs (const_tree t1, const_tree t2, int exact)
    1191                 :             : {
    1192                 :  1606698330 :   const_tree probe;
    1193                 :  1606698330 :   const_tree base;
    1194                 :  1606698330 :   int  length = 0;
    1195                 :             : 
    1196                 :  1606698330 :   if (t1 == t2)
    1197                 :             :     return true;
    1198                 :             : 
    1199                 :             :   /* First handle noexcept.  */
    1200                 :   566029354 :   if (exact < ce_exact)
    1201                 :             :     {
    1202                 :     6835396 :       if (exact == ce_type
    1203                 :    13630071 :           && (canonical_eh_spec (CONST_CAST_TREE (t1))
    1204                 :     6794675 :               == canonical_eh_spec (CONST_CAST_TREE (t2))))
    1205                 :             :         return true;
    1206                 :             : 
    1207                 :             :       /* noexcept(false) is compatible with no exception-specification,
    1208                 :             :          and less strict than any spec.  */
    1209                 :     6829152 :       if (t1 == noexcept_false_spec)
    1210                 :         102 :         return t2 == NULL_TREE || exact == ce_derived;
    1211                 :             :       /* Even a derived noexcept(false) is compatible with no
    1212                 :             :          exception-specification.  */
    1213                 :     6829050 :       if (t2 == noexcept_false_spec)
    1214                 :        1131 :         return t1 == NULL_TREE;
    1215                 :             : 
    1216                 :             :       /* Otherwise, if we aren't looking for an exact match, noexcept is
    1217                 :             :          equivalent to throw().  */
    1218                 :     6827919 :       if (t1 == noexcept_true_spec)
    1219                 :      653479 :         t1 = empty_except_spec;
    1220                 :     6827919 :       if (t2 == noexcept_true_spec)
    1221                 :     5982628 :         t2 = empty_except_spec;
    1222                 :             :     }
    1223                 :             : 
    1224                 :             :   /* If any noexcept is left, it is only comparable to itself;
    1225                 :             :      either we're looking for an exact match or we're redeclaring a
    1226                 :             :      template with dependent noexcept.  */
    1227                 :   550003530 :   if ((t1 && TREE_PURPOSE (t1))
    1228                 :   585034328 :       || (t2 && TREE_PURPOSE (t2)))
    1229                 :   556882023 :     return (t1 && t2
    1230                 :   618795743 :             && cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)));
    1231                 :             : 
    1232                 :     9139854 :   if (t1 == NULL_TREE)                     /* T1 is ...  */
    1233                 :     6218239 :     return t2 == NULL_TREE || exact == ce_derived;
    1234                 :     2921615 :   if (!TREE_VALUE (t1))                    /* t1 is EMPTY */
    1235                 :     2888868 :     return t2 != NULL_TREE && !TREE_VALUE (t2);
    1236                 :       34799 :   if (t2 == NULL_TREE)                     /* T2 is ...  */
    1237                 :             :     return false;
    1238                 :        2143 :   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
    1239                 :         114 :     return exact == ce_derived;
    1240                 :             : 
    1241                 :             :   /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
    1242                 :             :      Count how many we find, to determine exactness. For exact matching and
    1243                 :             :      ordered T1, T2, this is an O(n) operation, otherwise its worst case is
    1244                 :             :      O(nm).  */
    1245                 :        3461 :   for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
    1246                 :             :     {
    1247                 :        3188 :       for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
    1248                 :             :         {
    1249                 :        2415 :           tree a = TREE_VALUE (probe);
    1250                 :        2415 :           tree b = TREE_VALUE (t2);
    1251                 :             : 
    1252                 :        2415 :           if (comp_except_types (a, b, exact))
    1253                 :             :             {
    1254                 :        1432 :               if (probe == base && exact > ce_derived)
    1255                 :        1362 :                 base = TREE_CHAIN (probe);
    1256                 :        1432 :               length++;
    1257                 :        1432 :               break;
    1258                 :             :             }
    1259                 :             :         }
    1260                 :        2205 :       if (probe == NULL_TREE)
    1261                 :             :         return false;
    1262                 :             :     }
    1263                 :        1256 :   return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
    1264                 :             : }
    1265                 :             : 
    1266                 :             : /* Compare the array types T1 and T2.  CB says how we should behave when
    1267                 :             :    comparing array bounds: bounds_none doesn't allow dimensionless arrays,
    1268                 :             :    bounds_either says than any array can be [], bounds_first means that
    1269                 :             :    onlt T1 can be an array with unknown bounds.  STRICT is true if
    1270                 :             :    qualifiers must match when comparing the types of the array elements.  */
    1271                 :             : 
    1272                 :             : static bool
    1273                 :     1121090 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
    1274                 :             :                   bool strict)
    1275                 :             : {
    1276                 :     1121090 :   tree d1;
    1277                 :     1121090 :   tree d2;
    1278                 :     1121090 :   tree max1, max2;
    1279                 :             : 
    1280                 :     1121090 :   if (t1 == t2)
    1281                 :             :     return true;
    1282                 :             : 
    1283                 :             :   /* The type of the array elements must be the same.  */
    1284                 :     1121041 :   if (strict
    1285                 :     1123140 :       ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    1286                 :        2099 :       : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1287                 :             :     return false;
    1288                 :             : 
    1289                 :      731502 :   d1 = TYPE_DOMAIN (t1);
    1290                 :      731502 :   d2 = TYPE_DOMAIN (t2);
    1291                 :             : 
    1292                 :      731502 :   if (d1 == d2)
    1293                 :             :     return true;
    1294                 :             : 
    1295                 :             :   /* If one of the arrays is dimensionless, and the other has a
    1296                 :             :      dimension, they are of different types.  However, it is valid to
    1297                 :             :      write:
    1298                 :             : 
    1299                 :             :        extern int a[];
    1300                 :             :        int a[3];
    1301                 :             : 
    1302                 :             :      by [basic.link]:
    1303                 :             : 
    1304                 :             :        declarations for an array object can specify
    1305                 :             :        array types that differ by the presence or absence of a major
    1306                 :             :        array bound (_dcl.array_).  */
    1307                 :      555581 :   if (!d1 && d2)
    1308                 :        1642 :     return cb >= bounds_either;
    1309                 :      553939 :   else if (d1 && !d2)
    1310                 :       16402 :     return cb == bounds_either;
    1311                 :             : 
    1312                 :             :   /* Check that the dimensions are the same.  */
    1313                 :             : 
    1314                 :      537537 :   if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    1315                 :             :     return false;
    1316                 :      537509 :   max1 = TYPE_MAX_VALUE (d1);
    1317                 :      537509 :   max2 = TYPE_MAX_VALUE (d2);
    1318                 :             : 
    1319                 :      537509 :   if (!cp_tree_equal (max1, max2))
    1320                 :             :     return false;
    1321                 :             : 
    1322                 :             :   return true;
    1323                 :             : }
    1324                 :             : 
    1325                 :             : /* Compare the relative position of T1 and T2 into their respective
    1326                 :             :    template parameter list.
    1327                 :             :    T1 and T2 must be template parameter types.
    1328                 :             :    Return TRUE if T1 and T2 have the same position, FALSE otherwise.  */
    1329                 :             : 
    1330                 :             : static bool
    1331                 :  1396349809 : comp_template_parms_position (tree t1, tree t2)
    1332                 :             : {
    1333                 :  1396349809 :   tree index1, index2;
    1334                 :  1396349809 :   gcc_assert (t1 && t2
    1335                 :             :               && TREE_CODE (t1) == TREE_CODE (t2)
    1336                 :             :               && (TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM
    1337                 :             :                   || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM
    1338                 :             :                   || TREE_CODE (t1) == TEMPLATE_TYPE_PARM));
    1339                 :             : 
    1340                 :  1396349809 :   index1 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t1));
    1341                 :  1396349809 :   index2 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t2));
    1342                 :             : 
    1343                 :             :   /* Then compare their relative position.  */
    1344                 :  1396349809 :   if (TEMPLATE_PARM_IDX (index1) != TEMPLATE_PARM_IDX (index2)
    1345                 :   947907823 :       || TEMPLATE_PARM_LEVEL (index1) != TEMPLATE_PARM_LEVEL (index2)
    1346                 :  2114626001 :       || (TEMPLATE_PARM_PARAMETER_PACK (index1)
    1347                 :   718276192 :           != TEMPLATE_PARM_PARAMETER_PACK (index2)))
    1348                 :             :     return false;
    1349                 :             : 
    1350                 :             :   /* In C++14 we can end up comparing 'auto' to a normal template
    1351                 :             :      parameter.  Don't confuse them.  */
    1352                 :   648479737 :   if (cxx_dialect >= cxx14 && (is_auto (t1) || is_auto (t2)))
    1353                 :   215363155 :     return TYPE_IDENTIFIER (t1) == TYPE_IDENTIFIER (t2);
    1354                 :             : 
    1355                 :             :   return true;
    1356                 :             : }
    1357                 :             : 
    1358                 :             : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    1359                 :             : 
    1360                 :             : static bool
    1361                 :         610 : cxx_safe_arg_type_equiv_p (tree t1, tree t2)
    1362                 :             : {
    1363                 :         610 :   t1 = TYPE_MAIN_VARIANT (t1);
    1364                 :         610 :   t2 = TYPE_MAIN_VARIANT (t2);
    1365                 :             : 
    1366                 :         610 :   if (TYPE_PTR_P (t1)
    1367                 :         177 :       && TYPE_PTR_P (t2))
    1368                 :             :     return true;
    1369                 :             : 
    1370                 :             :   /* The signedness of the parameter matters only when an integral
    1371                 :             :      type smaller than int is promoted to int, otherwise only the
    1372                 :             :      precision of the parameter matters.
    1373                 :             :      This check should make sure that the callee does not see
    1374                 :             :      undefined values in argument registers.  */
    1375                 :         441 :   if (INTEGRAL_TYPE_P (t1)
    1376                 :          87 :       && INTEGRAL_TYPE_P (t2)
    1377                 :          60 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
    1378                 :         497 :       && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2)
    1379                 :           0 :           || !targetm.calls.promote_prototypes (NULL_TREE)
    1380                 :           0 :           || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node)))
    1381                 :          56 :     return true;
    1382                 :             : 
    1383                 :         385 :   return same_type_p (t1, t2);
    1384                 :             : }
    1385                 :             : 
    1386                 :             : /* Check if a type cast between two function types can be considered safe.  */
    1387                 :             : 
    1388                 :             : static bool
    1389                 :        4899 : cxx_safe_function_type_cast_p (tree t1, tree t2)
    1390                 :             : {
    1391                 :        4899 :   if (TREE_TYPE (t1) == void_type_node &&
    1392                 :        4820 :       TYPE_ARG_TYPES (t1) == void_list_node)
    1393                 :             :     return true;
    1394                 :             : 
    1395                 :        4319 :   if (TREE_TYPE (t2) == void_type_node &&
    1396                 :        4096 :       TYPE_ARG_TYPES (t2) == void_list_node)
    1397                 :             :     return true;
    1398                 :             : 
    1399                 :         308 :   if (!cxx_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1400                 :             :     return false;
    1401                 :             : 
    1402                 :         141 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    1403                 :         396 :        t1 && t2;
    1404                 :         255 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1405                 :         302 :     if (!cxx_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1406                 :             :       return false;
    1407                 :             : 
    1408                 :             :   return true;
    1409                 :             : }
    1410                 :             : 
    1411                 :             : /* Subroutine in comptypes.  */
    1412                 :             : 
    1413                 :             : static bool
    1414                 : 10124099248 : structural_comptypes (tree t1, tree t2, int strict)
    1415                 :             : {
    1416                 :             :   /* Both should be types that are not obviously the same.  */
    1417                 : 10124099248 :   gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
    1418                 :             : 
    1419                 :             :   /* Suppress typename resolution under spec_hasher::equal in place of calling
    1420                 :             :      push_to_top_level there.  */
    1421                 : 10124099248 :   if (!comparing_specializations)
    1422                 :             :     {
    1423                 :             :       /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
    1424                 :             :          current instantiation.  */
    1425                 :  8156570413 :       if (TREE_CODE (t1) == TYPENAME_TYPE)
    1426                 :    75300063 :         t1 = resolve_typename_type (t1, /*only_current_p=*/true);
    1427                 :             : 
    1428                 :  8156570413 :       if (TREE_CODE (t2) == TYPENAME_TYPE)
    1429                 :    94132356 :         t2 = resolve_typename_type (t2, /*only_current_p=*/true);
    1430                 :             :     }
    1431                 :             : 
    1432                 : 10124099248 :   if (TYPE_PTRMEMFUNC_P (t1))
    1433                 :    30247257 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    1434                 : 10124099248 :   if (TYPE_PTRMEMFUNC_P (t2))
    1435                 :    33718151 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
    1436                 :             : 
    1437                 :             :   /* Different classes of types can't be compatible.  */
    1438                 : 10124099248 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1439                 :             :     return false;
    1440                 :             : 
    1441                 :             :   /* Qualifiers must match.  For array types, we will check when we
    1442                 :             :      recur on the array element types.  */
    1443                 :  6405891852 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1444                 :  6405891852 :       && cp_type_quals (t1) != cp_type_quals (t2))
    1445                 :             :     return false;
    1446                 :  6029217008 :   if (TREE_CODE (t1) == FUNCTION_TYPE
    1447                 :  6029217008 :       && type_memfn_quals (t1) != type_memfn_quals (t2))
    1448                 :             :     return false;
    1449                 :             :   /* Need to check this before TYPE_MAIN_VARIANT.
    1450                 :             :      FIXME function qualifiers should really change the main variant.  */
    1451                 :  6029151164 :   if (FUNC_OR_METHOD_TYPE_P (t1))
    1452                 :             :     {
    1453                 :    35695518 :       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
    1454                 :             :         return false;
    1455                 :    17660080 :       if (flag_noexcept_type
    1456                 :    35160485 :           && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
    1457                 :    17500405 :                                  TYPE_RAISES_EXCEPTIONS (t2),
    1458                 :             :                                  ce_type))
    1459                 :             :         return false;
    1460                 :             :     }
    1461                 :             : 
    1462                 :             :   /* Allow for two different type nodes which have essentially the same
    1463                 :             :      definition.  Note that we already checked for equality of the type
    1464                 :             :      qualifiers (just above).  */
    1465                 :  6004481660 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1466                 :  6004481660 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1467                 :   262856080 :     goto check_alias;
    1468                 :             : 
    1469                 :             :   /* Compare the types.  Return false on known not-same. Break on not
    1470                 :             :      known.   Never return true from this switch -- you'll break
    1471                 :             :      specialization comparison.    */
    1472                 :  5741625580 :   switch (TREE_CODE (t1))
    1473                 :             :     {
    1474                 :             :     case VOID_TYPE:
    1475                 :             :     case BOOLEAN_TYPE:
    1476                 :             :       /* All void and bool types are the same.  */
    1477                 :             :       break;
    1478                 :             : 
    1479                 :   433961888 :     case OPAQUE_TYPE:
    1480                 :   433961888 :     case INTEGER_TYPE:
    1481                 :   433961888 :     case FIXED_POINT_TYPE:
    1482                 :   433961888 :     case REAL_TYPE:
    1483                 :             :       /* With these nodes, we can't determine type equivalence by
    1484                 :             :          looking at what is stored in the nodes themselves, because
    1485                 :             :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1486                 :             :          represent the same type.  For example, wchar_t and int could
    1487                 :             :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1488                 :             :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1489                 :             :          and are distinct types. On the other hand, int and the
    1490                 :             :          following typedef
    1491                 :             : 
    1492                 :             :            typedef int INT __attribute((may_alias));
    1493                 :             : 
    1494                 :             :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1495                 :             :          represent the same type.  The canonical type system keeps
    1496                 :             :          track of equivalence in this case, so we fall back on it.  */
    1497                 :   433961888 :       if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1498                 :             :         return false;
    1499                 :             : 
    1500                 :             :       /* We don't need or want the attribute comparison.  */
    1501                 :        1173 :       goto check_alias;
    1502                 :             : 
    1503                 :     1012834 :     case TEMPLATE_TEMPLATE_PARM:
    1504                 :     1012834 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    1505                 :     1012834 :       if (!comp_template_parms_position (t1, t2))
    1506                 :             :         return false;
    1507                 :      830403 :       if (!comp_template_parms
    1508                 :     1660806 :           (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
    1509                 :     2341059 :            DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
    1510                 :             :         return false;
    1511                 :      574150 :       if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
    1512                 :             :         break;
    1513                 :             :       /* Don't check inheritance.  */
    1514                 :             :       strict = COMPARE_STRICT;
    1515                 :             :       /* Fall through.  */
    1516                 :             : 
    1517                 :  2686143563 :     case RECORD_TYPE:
    1518                 :  2686143563 :     case UNION_TYPE:
    1519                 :  4726711607 :       if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
    1520                 :  1645075512 :           && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
    1521                 :  1194971946 :               || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
    1522                 :  3136273796 :           && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
    1523                 :             :         break;
    1524                 :             : 
    1525                 :  2657159869 :       if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
    1526                 :             :         break;
    1527                 :  2657158578 :       else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
    1528                 :             :         break;
    1529                 :             : 
    1530                 :             :       return false;
    1531                 :             : 
    1532                 :       43558 :     case OFFSET_TYPE:
    1533                 :       43558 :       if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
    1534                 :             :                       strict & ~COMPARE_REDECLARATION))
    1535                 :             :         return false;
    1536                 :       41274 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1537                 :             :         return false;
    1538                 :             :       break;
    1539                 :             : 
    1540                 :   625991155 :     case REFERENCE_TYPE:
    1541                 :   625991155 :       if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
    1542                 :             :         return false;
    1543                 :             :       /* fall through to checks for pointer types */
    1544                 :   871142345 :       gcc_fallthrough ();
    1545                 :             : 
    1546                 :   871142345 :     case POINTER_TYPE:
    1547                 :   871142345 :       if (TYPE_MODE (t1) != TYPE_MODE (t2)
    1548                 :   871142345 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1549                 :   780254236 :         return false;
    1550                 :             :       break;
    1551                 :             : 
    1552                 :    10769582 :     case METHOD_TYPE:
    1553                 :    10769582 :     case FUNCTION_TYPE:
    1554                 :             :       /* Exception specs and memfn_rquals were checked above.  */
    1555                 :    10769582 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1556                 :             :         return false;
    1557                 :    10120140 :       if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
    1558                 :             :         return false;
    1559                 :             :       break;
    1560                 :             : 
    1561                 :     1118942 :     case ARRAY_TYPE:
    1562                 :             :       /* Target types must match incl. qualifiers.  */
    1563                 :     1118942 :       if (!comp_array_types (t1, t2, ((strict & COMPARE_REDECLARATION)
    1564                 :     1118942 :                                       ? bounds_either : bounds_none),
    1565                 :             :                              /*strict=*/true))
    1566                 :             :         return false;
    1567                 :             :       break;
    1568                 :             : 
    1569                 :  1395336975 :     case TEMPLATE_TYPE_PARM:
    1570                 :             :       /* If T1 and T2 don't have the same relative position in their
    1571                 :             :          template parameters set, they can't be equal.  */
    1572                 :  1395336975 :       if (!comp_template_parms_position (t1, t2))
    1573                 :             :         return false;
    1574                 :             :       /* If T1 and T2 don't represent the same class template deduction,
    1575                 :             :          they aren't equal.  */
    1576                 :   928611072 :       if (!cp_tree_equal (CLASS_PLACEHOLDER_TEMPLATE (t1),
    1577                 :   464305536 :                           CLASS_PLACEHOLDER_TEMPLATE (t2)))
    1578                 :             :         return false;
    1579                 :             :       /* Constrained 'auto's are distinct from parms that don't have the same
    1580                 :             :          constraints.  */
    1581                 :   457420773 :       if (!equivalent_placeholder_constraints (t1, t2))
    1582                 :             :         return false;
    1583                 :             :       break;
    1584                 :             : 
    1585                 :   108632741 :     case TYPENAME_TYPE:
    1586                 :   217265482 :       if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
    1587                 :   108632741 :                           TYPENAME_TYPE_FULLNAME (t2)))
    1588                 :             :         return false;
    1589                 :             :       /* Qualifiers don't matter on scopes.  */
    1590                 :    94924314 :       if (!same_type_ignoring_top_level_qualifiers_p (TYPE_CONTEXT (t1),
    1591                 :    94924314 :                                                       TYPE_CONTEXT (t2)))
    1592                 :             :         return false;
    1593                 :             :       break;
    1594                 :             : 
    1595                 :        5974 :     case UNBOUND_CLASS_TEMPLATE:
    1596                 :        5974 :       if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
    1597                 :             :         return false;
    1598                 :        5974 :       if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
    1599                 :             :         return false;
    1600                 :             :       break;
    1601                 :             : 
    1602                 :     2666877 :     case COMPLEX_TYPE:
    1603                 :     2666877 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1604                 :             :         return false;
    1605                 :             :       break;
    1606                 :             : 
    1607                 :     7634806 :     case VECTOR_TYPE:
    1608                 :     7634806 :       if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
    1609                 :    13960210 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1610                 :    14007197 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1611                 :     1309402 :         return false;
    1612                 :             :       break;
    1613                 :             : 
    1614                 :     6259276 :     case TYPE_PACK_EXPANSION:
    1615                 :     6259276 :       return (same_type_p (PACK_EXPANSION_PATTERN (t1),
    1616                 :             :                            PACK_EXPANSION_PATTERN (t2))
    1617                 :    12388373 :               && comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    1618                 :     6129097 :                                      PACK_EXPANSION_EXTRA_ARGS (t2)));
    1619                 :             : 
    1620                 :    11166021 :     case DECLTYPE_TYPE:
    1621                 :    22332042 :       if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t1)
    1622                 :    11166021 :           != DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t2))
    1623                 :             :         return false;
    1624                 :    11156309 :       if (DECLTYPE_FOR_LAMBDA_CAPTURE (t1) != DECLTYPE_FOR_LAMBDA_CAPTURE (t2))
    1625                 :             :         return false;
    1626                 :    11156309 :       if (DECLTYPE_FOR_LAMBDA_PROXY (t1) != DECLTYPE_FOR_LAMBDA_PROXY (t2))
    1627                 :             :         return false;
    1628                 :    11156309 :       if (!cp_tree_equal (DECLTYPE_TYPE_EXPR (t1), DECLTYPE_TYPE_EXPR (t2)))
    1629                 :             :         return false;
    1630                 :             :       break;
    1631                 :             : 
    1632                 :         194 :     case TRAIT_TYPE:
    1633                 :         194 :       if (TRAIT_TYPE_KIND (t1) != TRAIT_TYPE_KIND (t2))
    1634                 :             :         return false;
    1635                 :         194 :       if (!cp_tree_equal (TRAIT_TYPE_TYPE1 (t1), TRAIT_TYPE_TYPE1 (t2))
    1636                 :         388 :           || !cp_tree_equal (TRAIT_TYPE_TYPE2 (t1), TRAIT_TYPE_TYPE2 (t2)))
    1637                 :           0 :         return false;
    1638                 :             :       break;
    1639                 :             : 
    1640                 :           3 :     case TYPEOF_TYPE:
    1641                 :           3 :       if (!cp_tree_equal (TYPEOF_TYPE_EXPR (t1), TYPEOF_TYPE_EXPR (t2)))
    1642                 :             :         return false;
    1643                 :             :       break;
    1644                 :             : 
    1645                 :             :     default:
    1646                 :             :       return false;
    1647                 :             :     }
    1648                 :             : 
    1649                 :             :   /* If we get here, we know that from a target independent POV the
    1650                 :             :      types are the same.  Make sure the target attributes are also
    1651                 :             :      the same.  */
    1652                 :   588427135 :   if (!comp_type_attributes (t1, t2))
    1653                 :             :     return false;
    1654                 :             : 
    1655                 :   588425923 :  check_alias:
    1656                 :   851283176 :   if (comparing_dependent_aliases)
    1657                 :             :     {
    1658                 :             :       /* Don't treat an alias template specialization with dependent
    1659                 :             :          arguments as equivalent to its underlying type when used as a
    1660                 :             :          template argument; we need them to be distinct so that we
    1661                 :             :          substitute into the specialization arguments at instantiation
    1662                 :             :          time.  And aliases can't be equivalent without being ==, so
    1663                 :             :          we don't need to look any deeper.  */
    1664                 :   252371827 :       ++processing_template_decl;
    1665                 :   252371827 :       tree dep1 = dependent_alias_template_spec_p (t1, nt_transparent);
    1666                 :   252371827 :       tree dep2 = dependent_alias_template_spec_p (t2, nt_transparent);
    1667                 :   252371827 :       --processing_template_decl;
    1668                 :   252371827 :       if ((dep1 || dep2) && dep1 != dep2)
    1669                 :             :         return false;
    1670                 :             :     }
    1671                 :             : 
    1672                 :             :   return true;
    1673                 :             : }
    1674                 :             : 
    1675                 :             : /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
    1676                 :             :    is a bitwise-or of the COMPARE_* flags.  */
    1677                 :             : 
    1678                 :             : bool
    1679                 : 16178551612 : comptypes (tree t1, tree t2, int strict)
    1680                 :             : {
    1681                 : 16178551612 :   gcc_checking_assert (t1 && t2);
    1682                 :             : 
    1683                 :             :   /* TYPE_ARGUMENT_PACKS are not really types.  */
    1684                 : 16178551612 :   gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
    1685                 :             :                        && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
    1686                 :             : 
    1687                 : 16178551612 :   if (t1 == t2)
    1688                 :             :     return true;
    1689                 :             : 
    1690                 :             :   /* Suppress errors caused by previously reported errors.  */
    1691                 : 10124100773 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1692                 :             :     return false;
    1693                 :             : 
    1694                 : 10124100584 :   if (strict == COMPARE_STRICT)
    1695                 :             :     {
    1696                 :  8838595948 :       if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
    1697                 :             :         /* At least one of the types requires structural equality, so
    1698                 :             :            perform a deep check. */
    1699                 :   778058810 :         return structural_comptypes (t1, t2, strict);
    1700                 :             : 
    1701                 :  8060537138 :       if (flag_checking && param_use_canonical_types)
    1702                 :             :         {
    1703                 :  8060535802 :           bool result = structural_comptypes (t1, t2, strict);
    1704                 :             :           
    1705                 :  8060535802 :           if (result && TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1706                 :             :             /* The two types are structurally equivalent, but their
    1707                 :             :                canonical types were different. This is a failure of the
    1708                 :             :                canonical type propagation code.*/
    1709                 :           0 :             internal_error 
    1710                 :           0 :               ("canonical types differ for identical types %qT and %qT",
    1711                 :             :                t1, t2);
    1712                 :  8060535802 :           else if (!result && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
    1713                 :             :             /* Two types are structurally different, but the canonical
    1714                 :             :                types are the same. This means we were over-eager in
    1715                 :             :                assigning canonical types. */
    1716                 :           0 :             internal_error 
    1717                 :           0 :               ("same canonical type node for different types %qT and %qT",
    1718                 :             :                t1, t2);
    1719                 :             :           
    1720                 :             :           return result;
    1721                 :             :         }
    1722                 :        1336 :       if (!flag_checking && param_use_canonical_types)
    1723                 :        1336 :         return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1724                 :             :       else
    1725                 :           0 :         return structural_comptypes (t1, t2, strict);
    1726                 :             :     }
    1727                 :  1285504636 :   else if (strict == COMPARE_STRUCTURAL)
    1728                 :  1254449452 :     return structural_comptypes (t1, t2, COMPARE_STRICT);
    1729                 :             :   else
    1730                 :    31055184 :     return structural_comptypes (t1, t2, strict);
    1731                 :             : }
    1732                 :             : 
    1733                 :             : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
    1734                 :             :    top-level qualifiers.  */
    1735                 :             : 
    1736                 :             : bool
    1737                 :  2135830336 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
    1738                 :             : {
    1739                 :  2135830336 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1740                 :             :     return false;
    1741                 :  2135830329 :   if (type1 == type2)
    1742                 :             :     return true;
    1743                 :             : 
    1744                 :  1270054438 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1745                 :  1270054438 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1746                 :  1270054438 :   return same_type_p (type1, type2);
    1747                 :             : }
    1748                 :             : 
    1749                 :             : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
    1750                 :             : 
    1751                 :             : bool
    1752                 :   186906523 : similar_type_p (tree type1, tree type2)
    1753                 :             : {
    1754                 :   186906523 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1755                 :             :     return false;
    1756                 :             : 
    1757                 :             :   /* Informally, two types are similar if, ignoring top-level cv-qualification:
    1758                 :             :      * they are the same type; or
    1759                 :             :      * they are both pointers, and the pointed-to types are similar; or
    1760                 :             :      * they are both pointers to member of the same class, and the types of
    1761                 :             :        the pointed-to members are similar; or
    1762                 :             :      * they are both arrays of the same size or both arrays of unknown bound,
    1763                 :             :        and the array element types are similar.  */
    1764                 :             : 
    1765                 :   186906523 :   if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
    1766                 :             :     return true;
    1767                 :             : 
    1768                 :    90376267 :   if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    1769                 :    90340561 :       || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    1770                 :    90340561 :       || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
    1771                 :       36154 :     return comp_ptr_ttypes_const (type1, type2, bounds_either);
    1772                 :             : 
    1773                 :             :   return false;
    1774                 :             : }
    1775                 :             : 
    1776                 :             : /* Helper function for layout_compatible_type_p and
    1777                 :             :    is_corresponding_member_aggr.  Advance to next members (NULL if
    1778                 :             :    no further ones) and return true if those members are still part of
    1779                 :             :    the common initial sequence.  */
    1780                 :             : 
    1781                 :             : bool
    1782                 :         758 : next_common_initial_sequence (tree &memb1, tree &memb2)
    1783                 :             : {
    1784                 :         935 :   while (memb1)
    1785                 :             :     {
    1786                 :         947 :       if (TREE_CODE (memb1) != FIELD_DECL
    1787                 :         792 :           || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
    1788                 :             :         {
    1789                 :         155 :           memb1 = DECL_CHAIN (memb1);
    1790                 :         155 :           continue;
    1791                 :             :         }
    1792                 :         637 :       if (DECL_FIELD_IS_BASE (memb1))
    1793                 :             :         {
    1794                 :          22 :           memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
    1795                 :          22 :           continue;
    1796                 :             :         }
    1797                 :             :       break;
    1798                 :             :     }
    1799                 :         925 :   while (memb2)
    1800                 :             :     {
    1801                 :         937 :       if (TREE_CODE (memb2) != FIELD_DECL
    1802                 :         782 :           || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
    1803                 :             :         {
    1804                 :         155 :           memb2 = DECL_CHAIN (memb2);
    1805                 :         155 :           continue;
    1806                 :             :         }
    1807                 :         627 :       if (DECL_FIELD_IS_BASE (memb2))
    1808                 :             :         {
    1809                 :          12 :           memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
    1810                 :          12 :           continue;
    1811                 :             :         }
    1812                 :             :       break;
    1813                 :             :     }
    1814                 :         758 :   if (memb1 == NULL_TREE && memb2 == NULL_TREE)
    1815                 :             :     return true;
    1816                 :         615 :   if (memb1 == NULL_TREE || memb2 == NULL_TREE)
    1817                 :             :     return false;
    1818                 :         615 :   if (DECL_BIT_FIELD_TYPE (memb1))
    1819                 :             :     {
    1820                 :          50 :       if (!DECL_BIT_FIELD_TYPE (memb2))
    1821                 :             :         return false;
    1822                 :          14 :       if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
    1823                 :          14 :                                      DECL_BIT_FIELD_TYPE (memb2)))
    1824                 :             :         return false;
    1825                 :          14 :       if (TYPE_PRECISION (TREE_TYPE (memb1))
    1826                 :          14 :           != TYPE_PRECISION (TREE_TYPE (memb2)))
    1827                 :             :         return false;
    1828                 :             :     }
    1829                 :         565 :   else if (DECL_BIT_FIELD_TYPE (memb2))
    1830                 :             :     return false;
    1831                 :         555 :   else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
    1832                 :             :     return false;
    1833                 :         546 :   if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
    1834                 :         546 :       != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
    1835                 :             :     return false;
    1836                 :         536 :   if (DECL_ALIGN (memb1) != DECL_ALIGN (memb2))
    1837                 :             :     return false;
    1838                 :         517 :   if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
    1839                 :             :     return false;
    1840                 :             :   return true;
    1841                 :             : }
    1842                 :             : 
    1843                 :             : /* Return true if TYPE1 and TYPE2 are layout-compatible types.  */
    1844                 :             : 
    1845                 :             : bool
    1846                 :        1011 : layout_compatible_type_p (tree type1, tree type2)
    1847                 :             : {
    1848                 :        1011 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1849                 :             :     return false;
    1850                 :        1011 :   if (type1 == type2)
    1851                 :             :     return true;
    1852                 :         482 :   if (TREE_CODE (type1) != TREE_CODE (type2))
    1853                 :             :     return false;
    1854                 :             : 
    1855                 :         464 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1856                 :         464 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1857                 :             : 
    1858                 :         464 :   if (TREE_CODE (type1) == ENUMERAL_TYPE)
    1859                 :          24 :     return (tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))
    1860                 :          24 :             && same_type_p (finish_underlying_type (type1),
    1861                 :             :                             finish_underlying_type (type2)));
    1862                 :             : 
    1863                 :         141 :   if (CLASS_TYPE_P (type1)
    1864                 :         141 :       && std_layout_type_p (type1)
    1865                 :         135 :       && std_layout_type_p (type2)
    1866                 :         575 :       && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)))
    1867                 :             :     {
    1868                 :         120 :       tree field1 = TYPE_FIELDS (type1);
    1869                 :         120 :       tree field2 = TYPE_FIELDS (type2);
    1870                 :         120 :       if (TREE_CODE (type1) == RECORD_TYPE)
    1871                 :             :         {
    1872                 :         361 :           while (1)
    1873                 :             :             {
    1874                 :         228 :               if (!next_common_initial_sequence (field1, field2))
    1875                 :             :                 return false;
    1876                 :         226 :               if (field1 == NULL_TREE)
    1877                 :             :                 return true;
    1878                 :         133 :               field1 = DECL_CHAIN (field1);
    1879                 :         133 :               field2 = DECL_CHAIN (field2);
    1880                 :             :             }
    1881                 :             :         }
    1882                 :             :       /* Otherwise both types must be union types.
    1883                 :             :          The standard says:
    1884                 :             :          "Two standard-layout unions are layout-compatible if they have
    1885                 :             :          the same number of non-static data members and corresponding
    1886                 :             :          non-static data members (in any order) have layout-compatible
    1887                 :             :          types."
    1888                 :             :          but the code anticipates that bitfield vs. non-bitfield,
    1889                 :             :          different bitfield widths or presence/absence of
    1890                 :             :          [[no_unique_address]] should be checked as well.  */
    1891                 :          25 :       auto_vec<tree, 16> vec;
    1892                 :          25 :       unsigned int count = 0;
    1893                 :         113 :       for (; field1; field1 = DECL_CHAIN (field1))
    1894                 :          88 :         if (TREE_CODE (field1) == FIELD_DECL)
    1895                 :          58 :           count++;
    1896                 :         113 :       for (; field2; field2 = DECL_CHAIN (field2))
    1897                 :          88 :         if (TREE_CODE (field2) == FIELD_DECL)
    1898                 :          58 :           vec.safe_push (field2);
    1899                 :             :       /* Discussions on core lean towards treating multiple union fields
    1900                 :             :          of the same type as the same field, so this might need changing
    1901                 :             :          in the future.  */
    1902                 :          50 :       if (count != vec.length ())
    1903                 :             :         return false;
    1904                 :         107 :       for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
    1905                 :             :         {
    1906                 :          84 :           if (TREE_CODE (field1) != FIELD_DECL)
    1907                 :          28 :             continue;
    1908                 :          56 :           unsigned int j;
    1909                 :          56 :           tree t1 = DECL_BIT_FIELD_TYPE (field1);
    1910                 :          56 :           if (t1 == NULL_TREE)
    1911                 :          55 :             t1 = TREE_TYPE (field1);
    1912                 :          92 :           FOR_EACH_VEC_ELT (vec, j, field2)
    1913                 :             :             {
    1914                 :          90 :               tree t2 = DECL_BIT_FIELD_TYPE (field2);
    1915                 :          90 :               if (t2 == NULL_TREE)
    1916                 :          86 :                 t2 = TREE_TYPE (field2);
    1917                 :          90 :               if (DECL_BIT_FIELD_TYPE (field1))
    1918                 :             :                 {
    1919                 :           2 :                   if (!DECL_BIT_FIELD_TYPE (field2))
    1920                 :           0 :                     continue;
    1921                 :           2 :                   if (TYPE_PRECISION (TREE_TYPE (field1))
    1922                 :           2 :                       != TYPE_PRECISION (TREE_TYPE (field2)))
    1923                 :           2 :                     continue;
    1924                 :             :                 }
    1925                 :          88 :               else if (DECL_BIT_FIELD_TYPE (field2))
    1926                 :           2 :                 continue;
    1927                 :          86 :               if (!layout_compatible_type_p (t1, t2))
    1928                 :          32 :                 continue;
    1929                 :          54 :               if ((!lookup_attribute ("no_unique_address",
    1930                 :          54 :                                       DECL_ATTRIBUTES (field1)))
    1931                 :          54 :                   != !lookup_attribute ("no_unique_address",
    1932                 :          54 :                                         DECL_ATTRIBUTES (field2)))
    1933                 :           0 :                 continue;
    1934                 :             :               break;
    1935                 :             :             }
    1936                 :         112 :           if (j == vec.length ())
    1937                 :             :             return false;
    1938                 :          54 :           vec.unordered_remove (j);
    1939                 :             :         }
    1940                 :             :       return true;
    1941                 :          25 :     }
    1942                 :             : 
    1943                 :         320 :   return same_type_p (type1, type2);
    1944                 :             : }
    1945                 :             : 
    1946                 :             : /* Returns 1 if TYPE1 is at least as qualified as TYPE2.  */
    1947                 :             : 
    1948                 :             : bool
    1949                 :   133959801 : at_least_as_qualified_p (const_tree type1, const_tree type2)
    1950                 :             : {
    1951                 :   133959801 :   int q1 = cp_type_quals (type1);
    1952                 :   133959801 :   int q2 = cp_type_quals (type2);
    1953                 :             : 
    1954                 :             :   /* All qualifiers for TYPE2 must also appear in TYPE1.  */
    1955                 :   133959801 :   return (q1 & q2) == q2;
    1956                 :             : }
    1957                 :             : 
    1958                 :             : /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
    1959                 :             :    more cv-qualified that TYPE1, and 0 otherwise.  */
    1960                 :             : 
    1961                 :             : int
    1962                 :     8791910 : comp_cv_qualification (int q1, int q2)
    1963                 :             : {
    1964                 :     8791910 :   if (q1 == q2)
    1965                 :             :     return 0;
    1966                 :             : 
    1967                 :     2696791 :   if ((q1 & q2) == q2)
    1968                 :             :     return 1;
    1969                 :      167529 :   else if ((q1 & q2) == q1)
    1970                 :      166937 :     return -1;
    1971                 :             : 
    1972                 :             :   return 0;
    1973                 :             : }
    1974                 :             : 
    1975                 :             : int
    1976                 :           0 : comp_cv_qualification (const_tree type1, const_tree type2)
    1977                 :             : {
    1978                 :           0 :   int q1 = cp_type_quals (type1);
    1979                 :           0 :   int q2 = cp_type_quals (type2);
    1980                 :           0 :   return comp_cv_qualification (q1, q2);
    1981                 :             : }
    1982                 :             : 
    1983                 :             : /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
    1984                 :             :    subset of the cv-qualification signature of TYPE2, and the types
    1985                 :             :    are similar.  Returns -1 if the other way 'round, and 0 otherwise.  */
    1986                 :             : 
    1987                 :             : int
    1988                 :         319 : comp_cv_qual_signature (tree type1, tree type2)
    1989                 :             : {
    1990                 :         319 :   if (comp_ptr_ttypes_real (type2, type1, -1))
    1991                 :             :     return 1;
    1992                 :         270 :   else if (comp_ptr_ttypes_real (type1, type2, -1))
    1993                 :             :     return -1;
    1994                 :             :   else
    1995                 :         256 :     return 0;
    1996                 :             : }
    1997                 :             : 
    1998                 :             : /* Subroutines of `comptypes'.  */
    1999                 :             : 
    2000                 :             : /* Return true if two parameter type lists PARMS1 and PARMS2 are
    2001                 :             :    equivalent in the sense that functions with those parameter types
    2002                 :             :    can have equivalent types.  The two lists must be equivalent,
    2003                 :             :    element by element.  */
    2004                 :             : 
    2005                 :             : bool
    2006                 :   713045091 : compparms (const_tree parms1, const_tree parms2)
    2007                 :             : {
    2008                 :   713045091 :   const_tree t1, t2;
    2009                 :             : 
    2010                 :             :   /* An unspecified parmlist matches any specified parmlist
    2011                 :             :      whose argument types don't need default promotions.  */
    2012                 :             : 
    2013                 :   713045091 :   for (t1 = parms1, t2 = parms2;
    2014                 :  1173799911 :        t1 || t2;
    2015                 :   460754820 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2016                 :             :     {
    2017                 :             :       /* If one parmlist is shorter than the other,
    2018                 :             :          they fail to match.  */
    2019                 :  1108713044 :       if (!t1 || !t2)
    2020                 :             :         return false;
    2021                 :  1108001702 :       if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2022                 :             :         return false;
    2023                 :             :     }
    2024                 :             :   return true;
    2025                 :             : }
    2026                 :             : 
    2027                 :             : 
    2028                 :             : /* Process a sizeof or alignof expression where the operand is a type.
    2029                 :             :    STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
    2030                 :             :    or GNU (preferred alignment) semantics; it is ignored if OP is
    2031                 :             :    SIZEOF_EXPR.  */
    2032                 :             : 
    2033                 :             : tree
    2034                 :    22380960 : cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op,
    2035                 :             :                             bool std_alignof, bool complain)
    2036                 :             : {
    2037                 :    22380960 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2038                 :    22380960 :   if (type == error_mark_node)
    2039                 :             :     return error_mark_node;
    2040                 :             : 
    2041                 :    22380958 :   type = non_reference (type);
    2042                 :    22380958 :   if (TREE_CODE (type) == METHOD_TYPE)
    2043                 :             :     {
    2044                 :           0 :       if (complain)
    2045                 :             :         {
    2046                 :           0 :           pedwarn (loc, OPT_Wpointer_arith,
    2047                 :             :                    "invalid application of %qs to a member function",
    2048                 :           0 :                    OVL_OP_INFO (false, op)->name);
    2049                 :           0 :           return size_one_node;
    2050                 :             :         }
    2051                 :             :       else
    2052                 :           0 :         return error_mark_node;
    2053                 :             :     }
    2054                 :    22380958 :   else if (VOID_TYPE_P (type) && std_alignof)
    2055                 :             :     {
    2056                 :          12 :       if (complain)
    2057                 :          12 :         error_at (loc, "invalid application of %qs to a void type",
    2058                 :          12 :                   OVL_OP_INFO (false, op)->name);
    2059                 :          12 :       return error_mark_node;
    2060                 :             :     }
    2061                 :             : 
    2062                 :    22380946 :   bool dependent_p = dependent_type_p (type);
    2063                 :    22380946 :   if (!dependent_p)
    2064                 :    18971151 :     complete_type (type);
    2065                 :    18971151 :   if (dependent_p
    2066                 :             :       /* VLA types will have a non-constant size.  In the body of an
    2067                 :             :          uninstantiated template, we don't need to try to compute the
    2068                 :             :          value, because the sizeof expression is not an integral
    2069                 :             :          constant expression in that case.  And, if we do try to
    2070                 :             :          compute the value, we'll likely end up with SAVE_EXPRs, which
    2071                 :             :          the template substitution machinery does not expect to see.  */
    2072                 :    18971151 :       || (processing_template_decl 
    2073                 :     1677295 :           && COMPLETE_TYPE_P (type)
    2074                 :     1677291 :           && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
    2075                 :             :     {
    2076                 :     3409795 :       tree value = build_min (op, size_type_node, type);
    2077                 :     3409795 :       TREE_READONLY (value) = 1;
    2078                 :     3409795 :       if (op == ALIGNOF_EXPR && std_alignof)
    2079                 :      354675 :         ALIGNOF_EXPR_STD_P (value) = true;
    2080                 :     3409795 :       SET_EXPR_LOCATION (value, loc);
    2081                 :     3409795 :       return value;
    2082                 :             :     }
    2083                 :             : 
    2084                 :    18971151 :   return c_sizeof_or_alignof_type (loc, complete_type (type),
    2085                 :             :                                    op == SIZEOF_EXPR, std_alignof,
    2086                 :    18971151 :                                    complain);
    2087                 :             : }
    2088                 :             : 
    2089                 :             : /* Return the size of the type, without producing any warnings for
    2090                 :             :    types whose size cannot be taken.  This routine should be used only
    2091                 :             :    in some other routine that has already produced a diagnostic about
    2092                 :             :    using the size of such a type.  */
    2093                 :             : tree 
    2094                 :     2033193 : cxx_sizeof_nowarn (tree type)
    2095                 :             : {
    2096                 :     2033193 :   if (TREE_CODE (type) == FUNCTION_TYPE
    2097                 :     2033193 :       || VOID_TYPE_P (type)
    2098                 :     2033082 :       || TREE_CODE (type) == ERROR_MARK)
    2099                 :         111 :     return size_one_node;
    2100                 :     2033082 :   else if (!COMPLETE_TYPE_P (type))
    2101                 :          24 :     return size_zero_node;
    2102                 :             :   else
    2103                 :     2033058 :     return cxx_sizeof_or_alignof_type (input_location, type,
    2104                 :     2033058 :                                        SIZEOF_EXPR, false, false);
    2105                 :             : }
    2106                 :             : 
    2107                 :             : /* Process a sizeof expression where the operand is an expression.  */
    2108                 :             : 
    2109                 :             : static tree
    2110                 :     1246797 : cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
    2111                 :             : {
    2112                 :     1246797 :   if (e == error_mark_node)
    2113                 :             :     return error_mark_node;
    2114                 :             : 
    2115                 :     1245863 :   if (instantiation_dependent_uneval_expression_p (e))
    2116                 :             :     {
    2117                 :      212439 :       e = build_min (SIZEOF_EXPR, size_type_node, e);
    2118                 :      212439 :       TREE_SIDE_EFFECTS (e) = 0;
    2119                 :      212439 :       TREE_READONLY (e) = 1;
    2120                 :      212439 :       SET_EXPR_LOCATION (e, loc);
    2121                 :             : 
    2122                 :      212439 :       return e;
    2123                 :             :     }
    2124                 :             : 
    2125                 :     1033424 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2126                 :     1033424 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2127                 :             : 
    2128                 :             :   /* To get the size of a static data member declared as an array of
    2129                 :             :      unknown bound, we need to instantiate it.  */
    2130                 :     1033424 :   if (VAR_P (e)
    2131                 :      504672 :       && VAR_HAD_UNKNOWN_BOUND (e)
    2132                 :     1033534 :       && DECL_TEMPLATE_INSTANTIATION (e))
    2133                 :          71 :     instantiate_decl (e, /*defer_ok*/true, /*expl_inst_mem*/false);
    2134                 :             : 
    2135                 :     1033424 :   if (TREE_CODE (e) == PARM_DECL
    2136                 :       36607 :       && DECL_ARRAY_PARAMETER_P (e)
    2137                 :     1033884 :       && (complain & tf_warning))
    2138                 :             :     {
    2139                 :         140 :       auto_diagnostic_group d;
    2140                 :         140 :       if (warning_at (e_loc, OPT_Wsizeof_array_argument,
    2141                 :             :                       "%<sizeof%> on array function parameter %qE "
    2142                 :         140 :                       "will return size of %qT", e, TREE_TYPE (e)))
    2143                 :          32 :         inform (DECL_SOURCE_LOCATION (e), "declared here");
    2144                 :         140 :     }
    2145                 :             : 
    2146                 :     1033424 :   e = mark_type_use (e);
    2147                 :             : 
    2148                 :     1033424 :   if (bitfield_p (e))
    2149                 :             :     {
    2150                 :          14 :       if (complain & tf_error)
    2151                 :           6 :         error_at (e_loc,
    2152                 :             :                   "invalid application of %<sizeof%> to a bit-field");
    2153                 :             :       else
    2154                 :           8 :         return error_mark_node;
    2155                 :           6 :       e = char_type_node;
    2156                 :             :     }
    2157                 :     1033410 :   else if (is_overloaded_fn (e))
    2158                 :             :     {
    2159                 :          44 :       if (complain & tf_error)
    2160                 :          16 :         permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to "
    2161                 :             :                    "an expression of function type");
    2162                 :             :       else
    2163                 :          28 :         return error_mark_node;
    2164                 :          16 :       e = char_type_node;
    2165                 :             :     }
    2166                 :     1033366 :   else if (type_unknown_p (e))
    2167                 :             :     {
    2168                 :           0 :       if (complain & tf_error)
    2169                 :           0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2170                 :             :       else
    2171                 :           0 :         return error_mark_node;
    2172                 :           0 :       e = char_type_node;
    2173                 :             :     }
    2174                 :             :   else
    2175                 :     1033366 :     e = TREE_TYPE (e);
    2176                 :             : 
    2177                 :     1033388 :   return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false,
    2178                 :     1033388 :                                      complain & tf_error);
    2179                 :             : }
    2180                 :             : 
    2181                 :             : /* Implement the __alignof keyword: Return the minimum required
    2182                 :             :    alignment of E, measured in bytes.  For VAR_DECL's and
    2183                 :             :    FIELD_DECL's return DECL_ALIGN (which can be set from an
    2184                 :             :    "aligned" __attribute__ specification).  STD_ALIGNOF acts
    2185                 :             :    like in cxx_sizeof_or_alignof_type.  */
    2186                 :             : 
    2187                 :             : static tree
    2188                 :      121403 : cxx_alignof_expr (location_t loc, tree e, bool std_alignof,
    2189                 :             :                   tsubst_flags_t complain)
    2190                 :             : {
    2191                 :      121403 :   tree t;
    2192                 :             : 
    2193                 :      121403 :   if (e == error_mark_node)
    2194                 :             :     return error_mark_node;
    2195                 :             : 
    2196                 :      121397 :   if (processing_template_decl)
    2197                 :             :     {
    2198                 :       29256 :       e = build_min (ALIGNOF_EXPR, size_type_node, e);
    2199                 :       29256 :       TREE_SIDE_EFFECTS (e) = 0;
    2200                 :       29256 :       TREE_READONLY (e) = 1;
    2201                 :       29256 :       SET_EXPR_LOCATION (e, loc);
    2202                 :       29256 :       ALIGNOF_EXPR_STD_P (e) = std_alignof;
    2203                 :             : 
    2204                 :       29256 :       return e;
    2205                 :             :     }
    2206                 :             : 
    2207                 :       92141 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2208                 :       92141 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2209                 :             : 
    2210                 :       92141 :   e = mark_type_use (e);
    2211                 :             : 
    2212                 :       92141 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e),
    2213                 :       92141 :                             !(complain & tf_error)))
    2214                 :             :     {
    2215                 :           0 :       if (!(complain & tf_error))
    2216                 :           0 :         return error_mark_node;
    2217                 :           0 :       t = size_one_node;
    2218                 :             :     }
    2219                 :       92141 :   else if (VAR_P (e))
    2220                 :       12279 :     t = size_int (DECL_ALIGN_UNIT (e));
    2221                 :       79862 :   else if (bitfield_p (e))
    2222                 :             :     {
    2223                 :           8 :       if (complain & tf_error)
    2224                 :           8 :         error_at (e_loc,
    2225                 :             :                   "invalid application of %<__alignof%> to a bit-field");
    2226                 :             :       else
    2227                 :           0 :         return error_mark_node;
    2228                 :           8 :       t = size_one_node;
    2229                 :             :     }
    2230                 :       79854 :   else if (TREE_CODE (e) == COMPONENT_REF
    2231                 :       79854 :            && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL)
    2232                 :       48094 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (e, 1)));
    2233                 :       31760 :   else if (is_overloaded_fn (e))
    2234                 :             :     {
    2235                 :           8 :       if (complain & tf_error)
    2236                 :           8 :         permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to "
    2237                 :             :                    "an expression of function type");
    2238                 :             :       else
    2239                 :           0 :         return error_mark_node;
    2240                 :           8 :       if (TREE_CODE (e) == FUNCTION_DECL)
    2241                 :           4 :         t = size_int (DECL_ALIGN_UNIT (e));
    2242                 :             :       else
    2243                 :           4 :         t = size_one_node;
    2244                 :             :     }
    2245                 :       31752 :   else if (type_unknown_p (e))
    2246                 :             :     {
    2247                 :           0 :       if (complain & tf_error)
    2248                 :           0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2249                 :             :       else
    2250                 :           0 :         return error_mark_node;
    2251                 :           0 :       t = size_one_node;
    2252                 :             :     }
    2253                 :             :   else
    2254                 :       31752 :     return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
    2255                 :             :                                        ALIGNOF_EXPR, std_alignof,
    2256                 :       31752 :                                        complain & tf_error);
    2257                 :             : 
    2258                 :       60389 :   return fold_convert_loc (loc, size_type_node, t);
    2259                 :             : }
    2260                 :             : 
    2261                 :             : /* Process a sizeof or alignof expression E with code OP where the operand
    2262                 :             :    is an expression. STD_ALIGNOF acts like in cxx_sizeof_or_alignof_type.  */
    2263                 :             : 
    2264                 :             : tree
    2265                 :     1368200 : cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
    2266                 :             :                             bool std_alignof, bool complain)
    2267                 :             : {
    2268                 :     1368200 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2269                 :     1368200 :   if (op == SIZEOF_EXPR)
    2270                 :     1907440 :     return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
    2271                 :             :   else
    2272                 :      121430 :     return cxx_alignof_expr (loc, e, std_alignof,
    2273                 :      121403 :                              complain? tf_warning_or_error : tf_none);
    2274                 :             : }
    2275                 :             : 
    2276                 :             : /*  Build a representation of an expression 'alignas(E).'  Return the
    2277                 :             :     folded integer value of E if it is an integral constant expression
    2278                 :             :     that resolves to a valid alignment.  If E depends on a template
    2279                 :             :     parameter, return a syntactic representation tree of kind
    2280                 :             :     ALIGNOF_EXPR.  Otherwise, return an error_mark_node if the
    2281                 :             :     expression is ill formed, or NULL_TREE if E is NULL_TREE.  */
    2282                 :             : 
    2283                 :             : tree
    2284                 :      150956 : cxx_alignas_expr (tree e)
    2285                 :             : {
    2286                 :      150956 :   if (e == NULL_TREE || e == error_mark_node
    2287                 :      301912 :       || (!TYPE_P (e) && !require_potential_rvalue_constant_expression (e)))
    2288                 :           0 :     return e;
    2289                 :             :   
    2290                 :      150956 :   if (TYPE_P (e))
    2291                 :             :     /* [dcl.align]/3:
    2292                 :             :        
    2293                 :             :            When the alignment-specifier is of the form
    2294                 :             :            alignas(type-id), it shall have the same effect as
    2295                 :             :            alignas(alignof(type-id)).  */
    2296                 :             : 
    2297                 :      104655 :     return cxx_sizeof_or_alignof_type (input_location,
    2298                 :             :                                        e, ALIGNOF_EXPR,
    2299                 :             :                                        /*std_alignof=*/true,
    2300                 :      104655 :                                        /*complain=*/true);
    2301                 :             :   
    2302                 :             :   /* If we reach this point, it means the alignas expression if of
    2303                 :             :      the form "alignas(assignment-expression)", so we should follow
    2304                 :             :      what is stated by [dcl.align]/2.  */
    2305                 :             : 
    2306                 :       46301 :   if (value_dependent_expression_p (e))
    2307                 :             :     /* Leave value-dependent expression alone for now. */
    2308                 :             :     return e;
    2309                 :             : 
    2310                 :       15083 :   e = instantiate_non_dependent_expr (e);
    2311                 :       15083 :   e = mark_rvalue_use (e);
    2312                 :             : 
    2313                 :             :   /* [dcl.align]/2 says:
    2314                 :             : 
    2315                 :             :          the assignment-expression shall be an integral constant
    2316                 :             :          expression.  */
    2317                 :             : 
    2318                 :       15083 :   if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (e)))
    2319                 :             :     {
    2320                 :           6 :       error ("%<alignas%> argument has non-integral type %qT", TREE_TYPE (e));
    2321                 :           6 :       return error_mark_node;
    2322                 :             :     }
    2323                 :             :   
    2324                 :       15077 :   return cxx_constant_value (e);
    2325                 :             : }
    2326                 :             : 
    2327                 :             : 
    2328                 :             : /* EXPR is being used in a context that is not a function call.
    2329                 :             :    Enforce:
    2330                 :             : 
    2331                 :             :      [expr.ref]
    2332                 :             : 
    2333                 :             :      The expression can be used only as the left-hand operand of a
    2334                 :             :      member function call.
    2335                 :             : 
    2336                 :             :      [expr.mptr.operator]
    2337                 :             : 
    2338                 :             :      If the result of .* or ->* is a function, then that result can be
    2339                 :             :      used only as the operand for the function call operator ().
    2340                 :             : 
    2341                 :             :    by issuing an error message if appropriate.  Returns true iff EXPR
    2342                 :             :    violates these rules.  */
    2343                 :             : 
    2344                 :             : bool
    2345                 :  1052494313 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
    2346                 :             : {
    2347                 :  1052494313 :   if (expr == NULL_TREE)
    2348                 :             :     return false;
    2349                 :             :   /* Don't enforce this in MS mode.  */
    2350                 :  1052493070 :   if (flag_ms_extensions)
    2351                 :             :     return false;
    2352                 :  1052487138 :   if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
    2353                 :    83528768 :     expr = get_first_fn (expr);
    2354                 :  1052487138 :   if (TREE_TYPE (expr)
    2355                 :  1052487138 :       && DECL_IOBJ_MEMBER_FUNCTION_P (expr))
    2356                 :             :     {
    2357                 :         107 :       if (complain & tf_error)
    2358                 :             :         {
    2359                 :         103 :           if (DECL_P (expr))
    2360                 :             :             {
    2361                 :          81 :               error_at (loc, "invalid use of non-static member function %qD",
    2362                 :             :                         expr);
    2363                 :          81 :               inform (DECL_SOURCE_LOCATION (expr), "declared here");
    2364                 :             :             }
    2365                 :             :           else
    2366                 :          22 :             error_at (loc, "invalid use of non-static member function of "
    2367                 :          22 :                       "type %qT", TREE_TYPE (expr));
    2368                 :             :         }
    2369                 :         107 :       return true;
    2370                 :             :     }
    2371                 :             :   return false;
    2372                 :             : }
    2373                 :             : 
    2374                 :             : /* If EXP is a reference to a bit-field, and the type of EXP does not
    2375                 :             :    match the declared type of the bit-field, return the declared type
    2376                 :             :    of the bit-field.  Otherwise, return NULL_TREE.  */
    2377                 :             : 
    2378                 :             : tree
    2379                 :  2452949589 : is_bitfield_expr_with_lowered_type (const_tree exp)
    2380                 :             : {
    2381                 :  3426281024 :   switch (TREE_CODE (exp))
    2382                 :             :     {
    2383                 :     4873793 :     case COND_EXPR:
    2384                 :     9747586 :       if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
    2385                 :     4873766 :                                                ? TREE_OPERAND (exp, 1)
    2386                 :          27 :                                                : TREE_OPERAND (exp, 0)))
    2387                 :             :         return NULL_TREE;
    2388                 :         159 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
    2389                 :             : 
    2390                 :      596415 :     case COMPOUND_EXPR:
    2391                 :      596415 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
    2392                 :             : 
    2393                 :   320649622 :     case MODIFY_EXPR:
    2394                 :   320649622 :     case SAVE_EXPR:
    2395                 :   320649622 :     case UNARY_PLUS_EXPR:
    2396                 :   320649622 :     case PREDECREMENT_EXPR:
    2397                 :   320649622 :     case PREINCREMENT_EXPR:
    2398                 :   320649622 :     case POSTDECREMENT_EXPR:
    2399                 :   320649622 :     case POSTINCREMENT_EXPR:
    2400                 :   320649622 :     case NEGATE_EXPR:
    2401                 :   320649622 :     case NON_LVALUE_EXPR:
    2402                 :   320649622 :     case BIT_NOT_EXPR:
    2403                 :   320649622 :     case CLEANUP_POINT_EXPR:
    2404                 :   320649622 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2405                 :             : 
    2406                 :   213013514 :     case COMPONENT_REF:
    2407                 :   213013514 :       {
    2408                 :   213013514 :         tree field;
    2409                 :             :         
    2410                 :   213013514 :         field = TREE_OPERAND (exp, 1);
    2411                 :   213013514 :         if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
    2412                 :             :           return NULL_TREE;
    2413                 :    29753403 :         if (same_type_ignoring_top_level_qualifiers_p
    2414                 :    29753403 :             (TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
    2415                 :             :           return NULL_TREE;
    2416                 :    29602520 :         return DECL_BIT_FIELD_TYPE (field);
    2417                 :             :       }
    2418                 :             : 
    2419                 :   476773047 :     case VAR_DECL:
    2420                 :   476773047 :       if (DECL_HAS_VALUE_EXPR_P (exp))
    2421                 :     1169608 :         return is_bitfield_expr_with_lowered_type (DECL_VALUE_EXPR
    2422                 :     1169608 :                                                    (CONST_CAST_TREE (exp)));
    2423                 :             :       return NULL_TREE;
    2424                 :             : 
    2425                 :   657765378 :     case VIEW_CONVERT_EXPR:
    2426                 :   657765378 :       if (location_wrapper_p (exp))
    2427                 :   650915631 :         return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2428                 :             :       else
    2429                 :             :         return NULL_TREE;
    2430                 :             : 
    2431                 :             :     default:
    2432                 :             :       return NULL_TREE;
    2433                 :             :     }
    2434                 :             : }
    2435                 :             : 
    2436                 :             : /* Like is_bitfield_with_lowered_type, except that if EXP is not a
    2437                 :             :    bitfield with a lowered type, the type of EXP is returned, rather
    2438                 :             :    than NULL_TREE.  */
    2439                 :             : 
    2440                 :             : tree
    2441                 :  1153887410 : unlowered_expr_type (const_tree exp)
    2442                 :             : {
    2443                 :  1153887410 :   tree type;
    2444                 :  1153887410 :   tree etype = TREE_TYPE (exp);
    2445                 :             : 
    2446                 :  1153887410 :   type = is_bitfield_expr_with_lowered_type (exp);
    2447                 :  1153887410 :   if (type)
    2448                 :    25776870 :     type = cp_build_qualified_type (type, cp_type_quals (etype));
    2449                 :             :   else
    2450                 :             :     type = etype;
    2451                 :             : 
    2452                 :  1153887410 :   return type;
    2453                 :             : }
    2454                 :             : 
    2455                 :             : /* Perform the conversions in [expr] that apply when an lvalue appears
    2456                 :             :    in an rvalue context: the lvalue-to-rvalue, array-to-pointer, and
    2457                 :             :    function-to-pointer conversions.  In addition, bitfield references are
    2458                 :             :    converted to their declared types. Note that this function does not perform
    2459                 :             :    the lvalue-to-rvalue conversion for class types. If you need that conversion
    2460                 :             :    for class types, then you probably need to use force_rvalue.
    2461                 :             : 
    2462                 :             :    Although the returned value is being used as an rvalue, this
    2463                 :             :    function does not wrap the returned expression in a
    2464                 :             :    NON_LVALUE_EXPR; the caller is expected to be mindful of the fact
    2465                 :             :    that the return value is no longer an lvalue.  */
    2466                 :             : 
    2467                 :             : tree
    2468                 :   845317343 : decay_conversion (tree exp,
    2469                 :             :                   tsubst_flags_t complain,
    2470                 :             :                   bool reject_builtin /* = true */)
    2471                 :             : {
    2472                 :   845317343 :   tree type;
    2473                 :   845317343 :   enum tree_code code;
    2474                 :   845317343 :   location_t loc = cp_expr_loc_or_input_loc (exp);
    2475                 :             : 
    2476                 :   845317343 :   type = TREE_TYPE (exp);
    2477                 :   845317343 :   if (type == error_mark_node)
    2478                 :             :     return error_mark_node;
    2479                 :             : 
    2480                 :   845317093 :   exp = resolve_nondeduced_context_or_error (exp, complain);
    2481                 :             : 
    2482                 :   845317093 :   code = TREE_CODE (type);
    2483                 :             : 
    2484                 :   845317093 :   if (error_operand_p (exp))
    2485                 :         117 :     return error_mark_node;
    2486                 :             : 
    2487                 :   845316976 :   if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp))
    2488                 :             :     {
    2489                 :     1382898 :       mark_rvalue_use (exp, loc, reject_builtin);
    2490                 :     1382898 :       return nullptr_node;
    2491                 :             :     }
    2492                 :             : 
    2493                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    2494                 :             :      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
    2495                 :   843934078 :   if (code == VOID_TYPE)
    2496                 :             :     {
    2497                 :        5746 :       if (complain & tf_error)
    2498                 :           4 :         error_at (loc, "void value not ignored as it ought to be");
    2499                 :        5746 :       return error_mark_node;
    2500                 :             :     }
    2501                 :   843928332 :   if (invalid_nonstatic_memfn_p (loc, exp, complain))
    2502                 :           4 :     return error_mark_node;
    2503                 :   843928328 :   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
    2504                 :             :     {
    2505                 :    85183745 :       exp = mark_lvalue_use (exp);
    2506                 :    85183745 :       if (reject_builtin && reject_gcc_builtin (exp, loc))
    2507                 :         147 :         return error_mark_node;
    2508                 :    85183598 :       return cp_build_addr_expr (exp, complain);
    2509                 :             :     }
    2510                 :   758744583 :   if (code == ARRAY_TYPE)
    2511                 :             :     {
    2512                 :     4361634 :       tree adr;
    2513                 :     4361634 :       tree ptrtype;
    2514                 :             : 
    2515                 :     4361634 :       exp = mark_lvalue_use (exp);
    2516                 :             : 
    2517                 :     4361634 :       if (INDIRECT_REF_P (exp))
    2518                 :       73612 :         return build_nop (build_pointer_type (TREE_TYPE (type)),
    2519                 :      147224 :                           TREE_OPERAND (exp, 0));
    2520                 :             : 
    2521                 :     4288022 :       if (TREE_CODE (exp) == COMPOUND_EXPR)
    2522                 :             :         {
    2523                 :           4 :           tree op1 = decay_conversion (TREE_OPERAND (exp, 1), complain);
    2524                 :           4 :           if (op1 == error_mark_node)
    2525                 :             :             return error_mark_node;
    2526                 :           4 :           return build2 (COMPOUND_EXPR, TREE_TYPE (op1),
    2527                 :           8 :                          TREE_OPERAND (exp, 0), op1);
    2528                 :             :         }
    2529                 :             : 
    2530                 :     4288018 :       if (!obvalue_p (exp)
    2531                 :     4288018 :           && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
    2532                 :             :         {
    2533                 :           0 :           if (complain & tf_error)
    2534                 :           0 :             error_at (loc, "invalid use of non-lvalue array");
    2535                 :           0 :           return error_mark_node;
    2536                 :             :         }
    2537                 :             : 
    2538                 :     4288018 :       ptrtype = build_pointer_type (TREE_TYPE (type));
    2539                 :             : 
    2540                 :     4288018 :       if (VAR_P (exp))
    2541                 :             :         {
    2542                 :      475751 :           if (!cxx_mark_addressable (exp))
    2543                 :           0 :             return error_mark_node;
    2544                 :      475751 :           adr = build_nop (ptrtype, build_address (exp));
    2545                 :      475751 :           return adr;
    2546                 :             :         }
    2547                 :             :       /* This way is better for a COMPONENT_REF since it can
    2548                 :             :          simplify the offset for a component.  */
    2549                 :     3812267 :       adr = cp_build_addr_expr (exp, complain);
    2550                 :     3812267 :       return cp_convert (ptrtype, adr, complain);
    2551                 :             :     }
    2552                 :             : 
    2553                 :             :   /* Otherwise, it's the lvalue-to-rvalue conversion.  */
    2554                 :   754382949 :   exp = mark_rvalue_use (exp, loc, reject_builtin);
    2555                 :             : 
    2556                 :             :   /* If a bitfield is used in a context where integral promotion
    2557                 :             :      applies, then the caller is expected to have used
    2558                 :             :      default_conversion.  That function promotes bitfields correctly
    2559                 :             :      before calling this function.  At this point, if we have a
    2560                 :             :      bitfield referenced, we may assume that is not subject to
    2561                 :             :      promotion, and that, therefore, the type of the resulting rvalue
    2562                 :             :      is the declared type of the bitfield.  */
    2563                 :   754382949 :   exp = convert_bitfield_to_declared_type (exp);
    2564                 :             : 
    2565                 :             :   /* We do not call rvalue() here because we do not want to wrap EXP
    2566                 :             :      in a NON_LVALUE_EXPR.  */
    2567                 :             : 
    2568                 :             :   /* [basic.lval]
    2569                 :             : 
    2570                 :             :      Non-class rvalues always have cv-unqualified types.  */
    2571                 :   754382949 :   type = TREE_TYPE (exp);
    2572                 :   754382949 :   if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    2573                 :   238041441 :     exp = build_nop (cv_unqualified (type), exp);
    2574                 :             : 
    2575                 :   754382949 :   if (!complete_type_or_maybe_complain (type, exp, complain))
    2576                 :          54 :     return error_mark_node;
    2577                 :             : 
    2578                 :             :   return exp;
    2579                 :             : }
    2580                 :             : 
    2581                 :             : /* Perform preparatory conversions, as part of the "usual arithmetic
    2582                 :             :    conversions".  In particular, as per [expr]:
    2583                 :             : 
    2584                 :             :      Whenever an lvalue expression appears as an operand of an
    2585                 :             :      operator that expects the rvalue for that operand, the
    2586                 :             :      lvalue-to-rvalue, array-to-pointer, or function-to-pointer
    2587                 :             :      standard conversions are applied to convert the expression to an
    2588                 :             :      rvalue.
    2589                 :             : 
    2590                 :             :    In addition, we perform integral promotions here, as those are
    2591                 :             :    applied to both operands to a binary operator before determining
    2592                 :             :    what additional conversions should apply.  */
    2593                 :             : 
    2594                 :             : static tree
    2595                 :   240622624 : cp_default_conversion (tree exp, tsubst_flags_t complain)
    2596                 :             : {
    2597                 :             :   /* Check for target-specific promotions.  */
    2598                 :   240622624 :   tree promoted_type = targetm.promoted_type (TREE_TYPE (exp));
    2599                 :   240622624 :   if (promoted_type)
    2600                 :           0 :     exp = cp_convert (promoted_type, exp, complain);
    2601                 :             :   /* Perform the integral promotions first so that bitfield
    2602                 :             :      expressions (which may promote to "int", even if the bitfield is
    2603                 :             :      declared "unsigned") are promoted correctly.  */
    2604                 :   240622624 :   else if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
    2605                 :   157235583 :     exp = cp_perform_integral_promotions (exp, complain);
    2606                 :             :   /* Perform the other conversions.  */
    2607                 :   240622624 :   exp = decay_conversion (exp, complain);
    2608                 :             : 
    2609                 :   240622624 :   return exp;
    2610                 :             : }
    2611                 :             : 
    2612                 :             : /* C version.  */
    2613                 :             : 
    2614                 :             : tree
    2615                 :    27061947 : default_conversion (tree exp)
    2616                 :             : {
    2617                 :    27061947 :   return cp_default_conversion (exp, tf_warning_or_error);
    2618                 :             : }
    2619                 :             : 
    2620                 :             : /* EXPR is an expression with an integral or enumeration type.
    2621                 :             :    Perform the integral promotions in [conv.prom], and return the
    2622                 :             :    converted value.  */
    2623                 :             : 
    2624                 :             : tree
    2625                 :   165354994 : cp_perform_integral_promotions (tree expr, tsubst_flags_t complain)
    2626                 :             : {
    2627                 :   165354994 :   tree type;
    2628                 :   165354994 :   tree promoted_type;
    2629                 :             : 
    2630                 :   165354994 :   expr = mark_rvalue_use (expr);
    2631                 :   165354994 :   if (error_operand_p (expr))
    2632                 :           3 :     return error_mark_node;
    2633                 :             : 
    2634                 :   165354991 :   type = TREE_TYPE (expr);
    2635                 :             : 
    2636                 :             :   /* [conv.prom]
    2637                 :             : 
    2638                 :             :      A prvalue for an integral bit-field (11.3.9) can be converted to a prvalue
    2639                 :             :      of type int if int can represent all the values of the bit-field;
    2640                 :             :      otherwise, it can be converted to unsigned int if unsigned int can
    2641                 :             :      represent all the values of the bit-field. If the bit-field is larger yet,
    2642                 :             :      no integral promotion applies to it. If the bit-field has an enumerated
    2643                 :             :      type, it is treated as any other value of that type for promotion
    2644                 :             :      purposes.  */
    2645                 :   165354991 :   tree bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    2646                 :   165354991 :   if (bitfield_type
    2647                 :   165354991 :       && (TREE_CODE (bitfield_type) == ENUMERAL_TYPE
    2648                 :      227687 :           || TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)))
    2649                 :             :     type = bitfield_type;
    2650                 :             : 
    2651                 :   165354991 :   gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type));
    2652                 :             :   /* Scoped enums don't promote.  */
    2653                 :   165354991 :   if (SCOPED_ENUM_P (type))
    2654                 :             :     return expr;
    2655                 :   164939869 :   promoted_type = type_promotes_to (type);
    2656                 :   164939869 :   if (type != promoted_type)
    2657                 :    48507388 :     expr = cp_convert (promoted_type, expr, complain);
    2658                 :   116432481 :   else if (bitfield_type && bitfield_type != type)
    2659                 :             :     /* Prevent decay_conversion from converting to bitfield_type.  */
    2660                 :         159 :     expr = build_nop (type, expr);
    2661                 :             :   return expr;
    2662                 :             : }
    2663                 :             : 
    2664                 :             : /* C version.  */
    2665                 :             : 
    2666                 :             : tree
    2667                 :     1621301 : perform_integral_promotions (tree expr)
    2668                 :             : {
    2669                 :     1621301 :   return cp_perform_integral_promotions (expr, tf_warning_or_error);
    2670                 :             : }
    2671                 :             : 
    2672                 :             : /* Returns nonzero iff exp is a STRING_CST or the result of applying
    2673                 :             :    decay_conversion to one.  */
    2674                 :             : 
    2675                 :             : int
    2676                 :     3083790 : string_conv_p (const_tree totype, const_tree exp, int warn)
    2677                 :             : {
    2678                 :     3083790 :   tree t;
    2679                 :             : 
    2680                 :     3083790 :   if (!TYPE_PTR_P (totype))
    2681                 :             :     return 0;
    2682                 :             : 
    2683                 :     3083726 :   t = TREE_TYPE (totype);
    2684                 :     3083726 :   if (!same_type_p (t, char_type_node)
    2685                 :     2928725 :       && !same_type_p (t, char8_type_node)
    2686                 :     2910577 :       && !same_type_p (t, char16_type_node)
    2687                 :     2851320 :       && !same_type_p (t, char32_type_node)
    2688                 :     5875791 :       && !same_type_p (t, wchar_type_node))
    2689                 :             :     return 0;
    2690                 :             : 
    2691                 :      340555 :   location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
    2692                 :             : 
    2693                 :      340555 :   STRIP_ANY_LOCATION_WRAPPER (exp);
    2694                 :             : 
    2695                 :      340555 :   if (TREE_CODE (exp) == STRING_CST)
    2696                 :             :     {
    2697                 :             :       /* Make sure that we don't try to convert between char and wide chars.  */
    2698                 :         127 :       if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t))
    2699                 :             :         return 0;
    2700                 :             :     }
    2701                 :             :   else
    2702                 :             :     {
    2703                 :             :       /* Is this a string constant which has decayed to 'const char *'?  */
    2704                 :      340428 :       t = build_pointer_type (cp_build_qualified_type (t, TYPE_QUAL_CONST));
    2705                 :      340428 :       if (!same_type_p (TREE_TYPE (exp), t))
    2706                 :             :         return 0;
    2707                 :       61286 :       STRIP_NOPS (exp);
    2708                 :       61286 :       if (TREE_CODE (exp) != ADDR_EXPR
    2709                 :       61286 :           || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
    2710                 :             :         return 0;
    2711                 :             :     }
    2712                 :         363 :   if (warn)
    2713                 :             :     {
    2714                 :         120 :       if (cxx_dialect >= cxx11)
    2715                 :         102 :         pedwarn (loc, OPT_Wwrite_strings,
    2716                 :             :                  "ISO C++ forbids converting a string constant to %qT",
    2717                 :             :                  totype);
    2718                 :             :       else
    2719                 :          18 :         warning_at (loc, OPT_Wwrite_strings,
    2720                 :             :                     "deprecated conversion from string constant to %qT",
    2721                 :             :                     totype);
    2722                 :             :     }
    2723                 :             : 
    2724                 :             :   return 1;
    2725                 :             : }
    2726                 :             : 
    2727                 :             : /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
    2728                 :             :    can, for example, use as an lvalue.  This code used to be in
    2729                 :             :    unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
    2730                 :             :    expressions, where we're dealing with aggregates.  But now it's again only
    2731                 :             :    called from unary_complex_lvalue.  The case (in particular) that led to
    2732                 :             :    this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
    2733                 :             :    get it there.  */
    2734                 :             : 
    2735                 :             : static tree
    2736                 :       84832 : rationalize_conditional_expr (enum tree_code code, tree t,
    2737                 :             :                               tsubst_flags_t complain)
    2738                 :             : {
    2739                 :       84832 :   location_t loc = cp_expr_loc_or_input_loc (t);
    2740                 :             : 
    2741                 :             :   /* For MIN_EXPR or MAX_EXPR, fold-const.cc has arranged things so that
    2742                 :             :      the first operand is always the one to be used if both operands
    2743                 :             :      are equal, so we know what conditional expression this used to be.  */
    2744                 :       84832 :   if (TREE_CODE (t) == MIN_EXPR || TREE_CODE (t) == MAX_EXPR)
    2745                 :             :     {
    2746                 :           0 :       tree op0 = TREE_OPERAND (t, 0);
    2747                 :           0 :       tree op1 = TREE_OPERAND (t, 1);
    2748                 :             : 
    2749                 :             :       /* The following code is incorrect if either operand side-effects.  */
    2750                 :           0 :       gcc_assert (!TREE_SIDE_EFFECTS (op0)
    2751                 :             :                   && !TREE_SIDE_EFFECTS (op1));
    2752                 :           0 :       return
    2753                 :           0 :         build_conditional_expr (loc,
    2754                 :             :                                 build_x_binary_op (loc,
    2755                 :           0 :                                                    (TREE_CODE (t) == MIN_EXPR
    2756                 :             :                                                     ? LE_EXPR : GE_EXPR),
    2757                 :           0 :                                                    op0, TREE_CODE (op0),
    2758                 :           0 :                                                    op1, TREE_CODE (op1),
    2759                 :             :                                                    NULL_TREE,
    2760                 :             :                                                    /*overload=*/NULL,
    2761                 :             :                                                    complain),
    2762                 :             :                                 cp_build_unary_op (code, op0, false, complain),
    2763                 :             :                                 cp_build_unary_op (code, op1, false, complain),
    2764                 :             :                                 complain);
    2765                 :             :     }
    2766                 :             : 
    2767                 :       84832 :   tree op1 = TREE_OPERAND (t, 1);
    2768                 :       84832 :   if (TREE_CODE (op1) != THROW_EXPR)
    2769                 :       84828 :     op1 = cp_build_unary_op (code, op1, false, complain);
    2770                 :       84832 :   tree op2 = TREE_OPERAND (t, 2);
    2771                 :       84832 :   if (TREE_CODE (op2) != THROW_EXPR)
    2772                 :       84825 :     op2 = cp_build_unary_op (code, op2, false, complain);
    2773                 :             : 
    2774                 :       84832 :   return
    2775                 :       84832 :     build_conditional_expr (loc, TREE_OPERAND (t, 0), op1, op2, complain);
    2776                 :             : }
    2777                 :             : 
    2778                 :             : /* Given the TYPE of an anonymous union field inside T, return the
    2779                 :             :    FIELD_DECL for the field.  If not found return NULL_TREE.  Because
    2780                 :             :    anonymous unions can nest, we must also search all anonymous unions
    2781                 :             :    that are directly reachable.  */
    2782                 :             : 
    2783                 :             : tree
    2784                 :      983013 : lookup_anon_field (tree, tree type)
    2785                 :             : {
    2786                 :      983013 :   tree field;
    2787                 :             : 
    2788                 :      983013 :   type = TYPE_MAIN_VARIANT (type);
    2789                 :      983013 :   field = ANON_AGGR_TYPE_FIELD (type);
    2790                 :      983013 :   gcc_assert (field);
    2791                 :      983013 :   return field;
    2792                 :             : }
    2793                 :             : 
    2794                 :             : /* Build an expression representing OBJECT.MEMBER.  OBJECT is an
    2795                 :             :    expression; MEMBER is a DECL or baselink.  If ACCESS_PATH is
    2796                 :             :    non-NULL, it indicates the path to the base used to name MEMBER.
    2797                 :             :    If PRESERVE_REFERENCE is true, the expression returned will have
    2798                 :             :    REFERENCE_TYPE if the MEMBER does.  Otherwise, the expression
    2799                 :             :    returned will have the type referred to by the reference.
    2800                 :             : 
    2801                 :             :    This function does not perform access control; that is either done
    2802                 :             :    earlier by the parser when the name of MEMBER is resolved to MEMBER
    2803                 :             :    itself, or later when overload resolution selects one of the
    2804                 :             :    functions indicated by MEMBER.  */
    2805                 :             : 
    2806                 :             : tree
    2807                 :    93208781 : build_class_member_access_expr (cp_expr object, tree member,
    2808                 :             :                                 tree access_path, bool preserve_reference,
    2809                 :             :                                 tsubst_flags_t complain)
    2810                 :             : {
    2811                 :    93208781 :   tree object_type;
    2812                 :    93208781 :   tree member_scope;
    2813                 :    93208781 :   tree result = NULL_TREE;
    2814                 :    93208781 :   tree using_decl = NULL_TREE;
    2815                 :             : 
    2816                 :    93208781 :   if (error_operand_p (object) || error_operand_p (member))
    2817                 :          49 :     return error_mark_node;
    2818                 :             : 
    2819                 :    93208732 :   gcc_assert (DECL_P (member) || BASELINK_P (member));
    2820                 :             : 
    2821                 :             :   /* [expr.ref]
    2822                 :             : 
    2823                 :             :      The type of the first expression shall be "class object" (of a
    2824                 :             :      complete type).  */
    2825                 :    93208732 :   object_type = TREE_TYPE (object);
    2826                 :    93208732 :   if (!currently_open_class (object_type)
    2827                 :    93208732 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    2828                 :           0 :     return error_mark_node;
    2829                 :    93208732 :   if (!CLASS_TYPE_P (object_type))
    2830                 :             :     {
    2831                 :           0 :       if (complain & tf_error)
    2832                 :             :         {
    2833                 :           0 :           if (INDIRECT_TYPE_P (object_type)
    2834                 :           0 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    2835                 :           0 :             error ("request for member %qD in %qE, which is of pointer "
    2836                 :             :                    "type %qT (maybe you meant to use %<->%> ?)",
    2837                 :             :                    member, object.get_value (), object_type);
    2838                 :             :           else
    2839                 :           0 :             error ("request for member %qD in %qE, which is of non-class "
    2840                 :             :                    "type %qT", member, object.get_value (), object_type);
    2841                 :             :         }
    2842                 :           0 :       return error_mark_node;
    2843                 :             :     }
    2844                 :             : 
    2845                 :             :   /* The standard does not seem to actually say that MEMBER must be a
    2846                 :             :      member of OBJECT_TYPE.  However, that is clearly what is
    2847                 :             :      intended.  */
    2848                 :    93208732 :   if (DECL_P (member))
    2849                 :             :     {
    2850                 :    39676879 :       member_scope = DECL_CLASS_CONTEXT (member);
    2851                 :    39676879 :       if (!mark_used (member, complain) && !(complain & tf_error))
    2852                 :           0 :         return error_mark_node;
    2853                 :             : 
    2854                 :    39676879 :       if (TREE_UNAVAILABLE (member))
    2855                 :          40 :         error_unavailable_use (member, NULL_TREE);
    2856                 :    39676839 :       else if (TREE_DEPRECATED (member))
    2857                 :          40 :         warn_deprecated_use (member, NULL_TREE);
    2858                 :             :     }
    2859                 :             :   else
    2860                 :    53531853 :     member_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (member));
    2861                 :             :   /* If MEMBER is from an anonymous aggregate, MEMBER_SCOPE will
    2862                 :             :      presently be the anonymous union.  Go outwards until we find a
    2863                 :             :      type related to OBJECT_TYPE.  */
    2864                 :    94195547 :   while ((ANON_AGGR_TYPE_P (member_scope) || UNSCOPED_ENUM_P (member_scope))
    2865                 :    95182800 :          && !same_type_ignoring_top_level_qualifiers_p (member_scope,
    2866                 :             :                                                         object_type))
    2867                 :      986815 :     member_scope = TYPE_CONTEXT (member_scope);
    2868                 :    93208732 :   if (!member_scope || !DERIVED_FROM_P (member_scope, object_type))
    2869                 :             :     {
    2870                 :           4 :       if (complain & tf_error)
    2871                 :             :         {
    2872                 :           4 :           if (TREE_CODE (member) == FIELD_DECL)
    2873                 :           0 :             error ("invalid use of non-static data member %qE", member);
    2874                 :             :           else
    2875                 :           4 :             error ("%qD is not a member of %qT", member, object_type);
    2876                 :             :         }
    2877                 :           4 :       return error_mark_node;
    2878                 :             :     }
    2879                 :             : 
    2880                 :             :   /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x' into
    2881                 :             :      `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only an lvalue
    2882                 :             :      in the front end; only _DECLs and _REFs are lvalues in the back end.  */
    2883                 :    93208728 :   if (tree temp = unary_complex_lvalue (ADDR_EXPR, object))
    2884                 :             :     {
    2885                 :          42 :       temp = cp_build_fold_indirect_ref (temp);
    2886                 :          42 :       if (!lvalue_p (object) && lvalue_p (temp))
    2887                 :             :         /* Preserve rvalueness.  */
    2888                 :           6 :         temp = move (temp);
    2889                 :          42 :       object = temp;
    2890                 :             :     }
    2891                 :             : 
    2892                 :             :   /* In [expr.ref], there is an explicit list of the valid choices for
    2893                 :             :      MEMBER.  We check for each of those cases here.  */
    2894                 :    93208728 :   if (VAR_P (member))
    2895                 :             :     {
    2896                 :             :       /* A static data member.  */
    2897                 :       80689 :       result = member;
    2898                 :       80689 :       mark_exp_read (object);
    2899                 :             : 
    2900                 :       80689 :       if (tree wrap = maybe_get_tls_wrapper_call (result))
    2901                 :             :         /* Replace an evaluated use of the thread_local variable with
    2902                 :             :            a call to its wrapper.  */
    2903                 :         102 :         result = wrap;
    2904                 :             : 
    2905                 :             :       /* If OBJECT has side-effects, they are supposed to occur.  */
    2906                 :       80689 :       if (TREE_SIDE_EFFECTS (object))
    2907                 :          58 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);
    2908                 :             :     }
    2909                 :    93128039 :   else if (TREE_CODE (member) == FIELD_DECL)
    2910                 :             :     {
    2911                 :             :       /* A non-static data member.  */
    2912                 :    39596055 :       bool null_object_p;
    2913                 :    39596055 :       int type_quals;
    2914                 :    39596055 :       tree member_type;
    2915                 :             : 
    2916                 :    39596055 :       if (INDIRECT_REF_P (object))
    2917                 :    29789075 :         null_object_p =
    2918                 :    29789075 :           integer_zerop (tree_strip_nop_conversions (TREE_OPERAND (object, 0)));
    2919                 :             :       else
    2920                 :             :         null_object_p = false;
    2921                 :             : 
    2922                 :             :       /* Convert OBJECT to the type of MEMBER.  */
    2923                 :    39596055 :       if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
    2924                 :             :                         TYPE_MAIN_VARIANT (member_scope)))
    2925                 :             :         {
    2926                 :     1655768 :           tree binfo;
    2927                 :     1655768 :           base_kind kind;
    2928                 :             : 
    2929                 :             :           /* We didn't complain above about a currently open class, but now we
    2930                 :             :              must: we don't know how to refer to a base member before layout is
    2931                 :             :              complete.  But still don't complain in a template.  */
    2932                 :     1655768 :           if (!cp_unevaluated_operand
    2933                 :     1655614 :               && !dependent_type_p (object_type)
    2934                 :     3033383 :               && !complete_type_or_maybe_complain (object_type, object,
    2935                 :             :                                                    complain))
    2936                 :          12 :             return error_mark_node;
    2937                 :             : 
    2938                 :     2097226 :           binfo = lookup_base (access_path ? access_path : object_type,
    2939                 :             :                                member_scope, ba_unique, &kind, complain);
    2940                 :     1655764 :           if (binfo == error_mark_node)
    2941                 :             :             return error_mark_node;
    2942                 :             : 
    2943                 :             :           /* It is invalid to try to get to a virtual base of a
    2944                 :             :              NULL object.  The most common cause is invalid use of
    2945                 :             :              offsetof macro.  */
    2946                 :     1655764 :           if (null_object_p && kind == bk_via_virtual)
    2947                 :             :             {
    2948                 :           8 :               if (complain & tf_error)
    2949                 :             :                 {
    2950                 :           8 :                   error ("invalid access to non-static data member %qD in "
    2951                 :             :                          "virtual base of NULL object", member);
    2952                 :             :                 }
    2953                 :           8 :               return error_mark_node;
    2954                 :             :             }
    2955                 :             : 
    2956                 :             :           /* Convert to the base.  */
    2957                 :     1655756 :           object = build_base_path (PLUS_EXPR, object, binfo,
    2958                 :             :                                     /*nonnull=*/1, complain);
    2959                 :             :           /* If we found the base successfully then we should be able
    2960                 :             :              to convert to it successfully.  */
    2961                 :     1655756 :           gcc_assert (object != error_mark_node);
    2962                 :             :         }
    2963                 :             : 
    2964                 :             :       /* If MEMBER is from an anonymous aggregate, we have converted
    2965                 :             :          OBJECT so that it refers to the class containing the
    2966                 :             :          anonymous union.  Generate a reference to the anonymous union
    2967                 :             :          itself, and recur to find MEMBER.  */
    2968                 :    79192086 :       if (ANON_AGGR_TYPE_P (DECL_CONTEXT (member))
    2969                 :             :           /* When this code is called from build_field_call, the
    2970                 :             :              object already has the type of the anonymous union.
    2971                 :             :              That is because the COMPONENT_REF was already
    2972                 :             :              constructed, and was then disassembled before calling
    2973                 :             :              build_field_call.  After the function-call code is
    2974                 :             :              cleaned up, this waste can be eliminated.  */
    2975                 :    40579436 :           && (!same_type_ignoring_top_level_qualifiers_p
    2976                 :      983393 :               (TREE_TYPE (object), DECL_CONTEXT (member))))
    2977                 :             :         {
    2978                 :      982958 :           tree anonymous_union;
    2979                 :             : 
    2980                 :      982958 :           anonymous_union = lookup_anon_field (TREE_TYPE (object),
    2981                 :      982958 :                                                DECL_CONTEXT (member));
    2982                 :      982958 :           object = build_class_member_access_expr (object,
    2983                 :             :                                                    anonymous_union,
    2984                 :             :                                                    /*access_path=*/NULL_TREE,
    2985                 :             :                                                    preserve_reference,
    2986                 :             :                                                    complain);
    2987                 :             :         }
    2988                 :             : 
    2989                 :             :       /* Compute the type of the field, as described in [expr.ref].  */
    2990                 :    39596043 :       type_quals = TYPE_UNQUALIFIED;
    2991                 :    39596043 :       member_type = TREE_TYPE (member);
    2992                 :    39596043 :       if (!TYPE_REF_P (member_type))
    2993                 :             :         {
    2994                 :    38881749 :           type_quals = (cp_type_quals (member_type)
    2995                 :    38881749 :                         | cp_type_quals (object_type));
    2996                 :             : 
    2997                 :             :           /* A field is const (volatile) if the enclosing object, or the
    2998                 :             :              field itself, is const (volatile).  But, a mutable field is
    2999                 :             :              not const, even within a const object.  */
    3000                 :    38881749 :           if (DECL_MUTABLE_P (member))
    3001                 :      320220 :             type_quals &= ~TYPE_QUAL_CONST;
    3002                 :    38881749 :           member_type = cp_build_qualified_type (member_type, type_quals);
    3003                 :             :         }
    3004                 :             : 
    3005                 :    39596043 :       result = build3_loc (input_location, COMPONENT_REF, member_type,
    3006                 :             :                            object, member, NULL_TREE);
    3007                 :             : 
    3008                 :             :       /* Mark the expression const or volatile, as appropriate.  Even
    3009                 :             :          though we've dealt with the type above, we still have to mark the
    3010                 :             :          expression itself.  */
    3011                 :    39596043 :       if (type_quals & TYPE_QUAL_CONST)
    3012                 :    12527670 :         TREE_READONLY (result) = 1;
    3013                 :    39596043 :       if (type_quals & TYPE_QUAL_VOLATILE)
    3014                 :      187988 :         TREE_THIS_VOLATILE (result) = 1;
    3015                 :             :     }
    3016                 :    53531984 :   else if (BASELINK_P (member))
    3017                 :             :     {
    3018                 :             :       /* The member is a (possibly overloaded) member function.  */
    3019                 :    53531849 :       tree functions;
    3020                 :    53531849 :       tree type;
    3021                 :             : 
    3022                 :             :       /* If the MEMBER is exactly one static member function, then we
    3023                 :             :          know the type of the expression.  Otherwise, we must wait
    3024                 :             :          until overload resolution has been performed.  */
    3025                 :    53531849 :       functions = BASELINK_FUNCTIONS (member);
    3026                 :    53531849 :       if (TREE_CODE (functions) == FUNCTION_DECL
    3027                 :    53531849 :           && DECL_STATIC_FUNCTION_P (functions))
    3028                 :      420478 :         type = TREE_TYPE (functions);
    3029                 :             :       else
    3030                 :    53111371 :         type = unknown_type_node;
    3031                 :             :       /* Note that we do not convert OBJECT to the BASELINK_BINFO
    3032                 :             :          base.  That will happen when the function is called.  */
    3033                 :    53531849 :       result = build3_loc (input_location, COMPONENT_REF, type, object, member,
    3034                 :             :                            NULL_TREE);
    3035                 :             :     }
    3036                 :         135 :   else if (TREE_CODE (member) == CONST_DECL)
    3037                 :             :     {
    3038                 :             :       /* The member is an enumerator.  */
    3039                 :         117 :       result = member;
    3040                 :             :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3041                 :         117 :       if (TREE_SIDE_EFFECTS (object))
    3042                 :           8 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    3043                 :             :                          object, result);
    3044                 :             :     }
    3045                 :          18 :   else if ((using_decl = strip_using_decl (member)) != member)
    3046                 :           0 :     result = build_class_member_access_expr (object,
    3047                 :             :                                              using_decl,
    3048                 :             :                                              access_path, preserve_reference,
    3049                 :             :                                              complain);
    3050                 :             :   else
    3051                 :             :     {
    3052                 :          18 :       if (complain & tf_error)
    3053                 :          14 :         error ("invalid use of %qD", member);
    3054                 :          18 :       return error_mark_node;
    3055                 :             :     }
    3056                 :             : 
    3057                 :    93208698 :   if (!preserve_reference)
    3058                 :             :     /* [expr.ref]
    3059                 :             : 
    3060                 :             :        If E2 is declared to have type "reference to T", then ... the
    3061                 :             :        type of E1.E2 is T.  */
    3062                 :    88164035 :     result = convert_from_reference (result);
    3063                 :             : 
    3064                 :             :   return result;
    3065                 :             : }
    3066                 :             : 
    3067                 :             : /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
    3068                 :             :    SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
    3069                 :             : 
    3070                 :             : tree
    3071                 :      141484 : lookup_destructor (tree object, tree scope, tree dtor_name,
    3072                 :             :                    tsubst_flags_t complain)
    3073                 :             : {
    3074                 :      141484 :   tree object_type = TREE_TYPE (object);
    3075                 :      141484 :   tree dtor_type = TREE_OPERAND (dtor_name, 0);
    3076                 :      141484 :   tree expr;
    3077                 :             : 
    3078                 :             :   /* We've already complained about this destructor.  */
    3079                 :      141484 :   if (dtor_type == error_mark_node)
    3080                 :             :     return error_mark_node;
    3081                 :             : 
    3082                 :      141476 :   if (scope && !check_dtor_name (scope, dtor_type))
    3083                 :             :     {
    3084                 :           4 :       if (complain & tf_error)
    3085                 :           4 :         error ("qualified type %qT does not match destructor name ~%qT",
    3086                 :             :                scope, dtor_type);
    3087                 :           4 :       return error_mark_node;
    3088                 :             :     }
    3089                 :      141472 :   if (is_auto (dtor_type))
    3090                 :             :     dtor_type = object_type;
    3091                 :      141469 :   else if (identifier_p (dtor_type))
    3092                 :             :     {
    3093                 :             :       /* In a template, names we can't find a match for are still accepted
    3094                 :             :          destructor names, and we check them here.  */
    3095                 :          19 :       if (check_dtor_name (object_type, dtor_type))
    3096                 :             :         dtor_type = object_type;
    3097                 :             :       else
    3098                 :             :         {
    3099                 :           4 :           if (complain & tf_error)
    3100                 :           4 :             error ("object type %qT does not match destructor name ~%qT",
    3101                 :             :                    object_type, dtor_type);
    3102                 :           4 :           return error_mark_node;
    3103                 :             :         }
    3104                 :             :       
    3105                 :             :     }
    3106                 :      141450 :   else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
    3107                 :             :     {
    3108                 :           8 :       if (complain & tf_error)
    3109                 :           8 :         error ("the type being destroyed is %qT, but the destructor "
    3110                 :           8 :                "refers to %qT", TYPE_MAIN_VARIANT (object_type), dtor_type);
    3111                 :           8 :       return error_mark_node;
    3112                 :             :     }
    3113                 :      141460 :   expr = lookup_member (dtor_type, complete_dtor_identifier,
    3114                 :             :                         /*protect=*/1, /*want_type=*/false,
    3115                 :             :                         tf_warning_or_error);
    3116                 :      141460 :   if (!expr)
    3117                 :             :     {
    3118                 :           6 :       if (complain & tf_error)
    3119                 :           6 :         cxx_incomplete_type_error (dtor_name, dtor_type);
    3120                 :           6 :       return error_mark_node;
    3121                 :             :     }
    3122                 :      141454 :   expr = (adjust_result_of_qualified_name_lookup
    3123                 :      141454 :           (expr, dtor_type, object_type));
    3124                 :      141454 :   if (scope == NULL_TREE)
    3125                 :             :     /* We need to call adjust_result_of_qualified_name_lookup in case the
    3126                 :             :        destructor names a base class, but we unset BASELINK_QUALIFIED_P so
    3127                 :             :        that we still get virtual function binding.  */
    3128                 :      141283 :     BASELINK_QUALIFIED_P (expr) = false;
    3129                 :             :   return expr;
    3130                 :             : }
    3131                 :             : 
    3132                 :             : /* An expression of the form "A::template B" has been resolved to
    3133                 :             :    DECL.  Issue a diagnostic if B is not a template or template
    3134                 :             :    specialization.  */
    3135                 :             : 
    3136                 :             : void
    3137                 :     3193651 : check_template_keyword (tree decl)
    3138                 :             : {
    3139                 :             :   /* The standard says:
    3140                 :             : 
    3141                 :             :       [temp.names]
    3142                 :             : 
    3143                 :             :       If a name prefixed by the keyword template is not a member
    3144                 :             :       template, the program is ill-formed.
    3145                 :             : 
    3146                 :             :      DR 228 removed the restriction that the template be a member
    3147                 :             :      template.
    3148                 :             : 
    3149                 :             :      DR 96, if accepted would add the further restriction that explicit
    3150                 :             :      template arguments must be provided if the template keyword is
    3151                 :             :      used, but, as of 2005-10-16, that DR is still in "drafting".  If
    3152                 :             :      this DR is accepted, then the semantic checks here can be
    3153                 :             :      simplified, as the entity named must in fact be a template
    3154                 :             :      specialization, rather than, as at present, a set of overloaded
    3155                 :             :      functions containing at least one template function.  */
    3156                 :     3193651 :   if (TREE_CODE (decl) != TEMPLATE_DECL
    3157                 :     3193651 :       && TREE_CODE (decl) != TEMPLATE_ID_EXPR)
    3158                 :             :     {
    3159                 :     2956060 :       if (VAR_P (decl))
    3160                 :             :         {
    3161                 :        9574 :           if (DECL_USE_TEMPLATE (decl)
    3162                 :        9574 :               && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
    3163                 :             :             ;
    3164                 :             :           else
    3165                 :           0 :             permerror (input_location, "%qD is not a template", decl);
    3166                 :             :         }
    3167                 :     2946486 :       else if (!is_overloaded_fn (decl))
    3168                 :           0 :         permerror (input_location, "%qD is not a template", decl);
    3169                 :             :       else
    3170                 :             :         {
    3171                 :     2946486 :           bool found = false;
    3172                 :             : 
    3173                 :     5892972 :           for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl));
    3174                 :     5892975 :                !found && iter; ++iter)
    3175                 :             :             {
    3176                 :     2946489 :               tree fn = *iter;
    3177                 :     2946489 :               if (TREE_CODE (fn) == TEMPLATE_DECL
    3178                 :     2946088 :                   || TREE_CODE (fn) == TEMPLATE_ID_EXPR
    3179                 :     2946508 :                   || (TREE_CODE (fn) == FUNCTION_DECL
    3180                 :          19 :                       && DECL_USE_TEMPLATE (fn)
    3181                 :           8 :                       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (fn))))
    3182                 :             :                 found = true;
    3183                 :             :             }
    3184                 :     2946486 :           if (!found)
    3185                 :          16 :             permerror (input_location, "%qD is not a template", decl);
    3186                 :             :         }
    3187                 :             :     }
    3188                 :     3193651 : }
    3189                 :             : 
    3190                 :             : /* Record that an access failure occurred on BASETYPE_PATH attempting
    3191                 :             :    to access DECL, where DIAG_DECL should be used for diagnostics.  */
    3192                 :             : 
    3193                 :             : void
    3194                 :         460 : access_failure_info::record_access_failure (tree basetype_path,
    3195                 :             :                                             tree decl, tree diag_decl)
    3196                 :             : {
    3197                 :         460 :   m_was_inaccessible = true;
    3198                 :         460 :   m_basetype_path = basetype_path;
    3199                 :         460 :   m_decl = decl;
    3200                 :         460 :   m_diag_decl = diag_decl;
    3201                 :         460 : }
    3202                 :             : 
    3203                 :             : /* If an access failure was recorded, then attempt to locate an
    3204                 :             :    accessor function for the pertinent field.
    3205                 :             :    Otherwise, return NULL_TREE.  */
    3206                 :             : 
    3207                 :             : tree
    3208                 :    78793903 : access_failure_info::get_any_accessor (bool const_p) const
    3209                 :             : {
    3210                 :    78793903 :   if (!was_inaccessible_p ())
    3211                 :             :     return NULL_TREE;
    3212                 :             : 
    3213                 :         460 :   tree accessor
    3214                 :         460 :     = locate_field_accessor (m_basetype_path, m_diag_decl, const_p);
    3215                 :         460 :   if (!accessor)
    3216                 :             :     return NULL_TREE;
    3217                 :             : 
    3218                 :             :   /* The accessor must itself be accessible for it to be a reasonable
    3219                 :             :      suggestion.  */
    3220                 :         161 :   if (!accessible_p (m_basetype_path, accessor, true))
    3221                 :             :     return NULL_TREE;
    3222                 :             : 
    3223                 :             :   return accessor;
    3224                 :             : }
    3225                 :             : 
    3226                 :             : /* Add a fix-it hint to RICHLOC suggesting the use of ACCESSOR_DECL, by
    3227                 :             :    replacing the primary location in RICHLOC with "accessor()".  */
    3228                 :             : 
    3229                 :             : void
    3230                 :         140 : access_failure_info::add_fixit_hint (rich_location *richloc,
    3231                 :             :                                      tree accessor_decl)
    3232                 :             : {
    3233                 :         140 :   pretty_printer pp;
    3234                 :         140 :   pp_string (&pp, IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
    3235                 :         140 :   pp_string (&pp, "()");
    3236                 :         140 :   richloc->add_fixit_replace (pp_formatted_text (&pp));
    3237                 :         140 : }
    3238                 :             : 
    3239                 :             : /* If an access failure was recorded, then attempt to locate an
    3240                 :             :    accessor function for the pertinent field, and if one is
    3241                 :             :    available, add a note and fix-it hint suggesting using it.  */
    3242                 :             : 
    3243                 :             : void
    3244                 :    78793833 : access_failure_info::maybe_suggest_accessor (bool const_p) const
    3245                 :             : {
    3246                 :    78793833 :   tree accessor = get_any_accessor (const_p);
    3247                 :    78793833 :   if (accessor == NULL_TREE)
    3248                 :    78793735 :     return;
    3249                 :          98 :   rich_location richloc (line_table, input_location);
    3250                 :          98 :   add_fixit_hint (&richloc, accessor);
    3251                 :          98 :   inform (&richloc, "field %q#D can be accessed via %q#D",
    3252                 :          98 :           m_diag_decl, accessor);
    3253                 :          98 : }
    3254                 :             : 
    3255                 :             : /* Subroutine of finish_class_member_access_expr.
    3256                 :             :    Issue an error about NAME not being a member of ACCESS_PATH (or
    3257                 :             :    OBJECT_TYPE), potentially providing a fix-it hint for misspelled
    3258                 :             :    names.  */
    3259                 :             : 
    3260                 :             : static void
    3261                 :         256 : complain_about_unrecognized_member (tree access_path, tree name,
    3262                 :             :                                     tree object_type)
    3263                 :             : {
    3264                 :             :   /* Attempt to provide a hint about misspelled names.  */
    3265                 :         256 :   tree guessed_id = lookup_member_fuzzy (access_path, name,
    3266                 :             :                                          /*want_type=*/false);
    3267                 :         256 :   if (guessed_id == NULL_TREE)
    3268                 :             :     {
    3269                 :             :       /* No hint.  */
    3270                 :         133 :       error ("%q#T has no member named %qE",
    3271                 :         133 :              TREE_CODE (access_path) == TREE_BINFO
    3272                 :           8 :              ? TREE_TYPE (access_path) : object_type, name);
    3273                 :         133 :       return;
    3274                 :             :     }
    3275                 :             : 
    3276                 :         123 :   location_t bogus_component_loc = input_location;
    3277                 :         123 :   gcc_rich_location rich_loc (bogus_component_loc);
    3278                 :             : 
    3279                 :             :   /* Check that the guessed name is accessible along access_path.  */
    3280                 :         123 :   access_failure_info afi;
    3281                 :         123 :   lookup_member (access_path, guessed_id, /*protect=*/1,
    3282                 :             :                  /*want_type=*/false, /*complain=*/false,
    3283                 :             :                  &afi);
    3284                 :         123 :   if (afi.was_inaccessible_p ())
    3285                 :             :     {
    3286                 :          70 :       tree accessor = afi.get_any_accessor (TYPE_READONLY (object_type));
    3287                 :          70 :       if (accessor)
    3288                 :             :         {
    3289                 :             :           /* The guessed name isn't directly accessible, but can be accessed
    3290                 :             :              via an accessor member function.  */
    3291                 :          42 :           afi.add_fixit_hint (&rich_loc, accessor);
    3292                 :          42 :           error_at (&rich_loc,
    3293                 :             :                     "%q#T has no member named %qE;"
    3294                 :             :                     " did you mean %q#D? (accessible via %q#D)",
    3295                 :          42 :                     TREE_CODE (access_path) == TREE_BINFO
    3296                 :           0 :                     ? TREE_TYPE (access_path) : object_type,
    3297                 :             :                     name, afi.get_diag_decl (), accessor);
    3298                 :             :         }
    3299                 :             :       else
    3300                 :             :         {
    3301                 :             :           /* The guessed name isn't directly accessible, and no accessor
    3302                 :             :              member function could be found.  */
    3303                 :          28 :           error_at (&rich_loc,
    3304                 :             :                     "%q#T has no member named %qE;"
    3305                 :             :                     " did you mean %q#D? (not accessible from this context)",
    3306                 :          28 :                     TREE_CODE (access_path) == TREE_BINFO
    3307                 :           0 :                     ? TREE_TYPE (access_path) : object_type,
    3308                 :             :                     name, afi.get_diag_decl ());
    3309                 :          28 :           complain_about_access (afi.get_decl (), afi.get_diag_decl (),
    3310                 :             :                                  afi.get_diag_decl (), false, ak_none);
    3311                 :             :         }
    3312                 :             :     }
    3313                 :             :   else
    3314                 :             :     {
    3315                 :             :       /* The guessed name is directly accessible; suggest it.  */
    3316                 :          53 :       rich_loc.add_fixit_misspelled_id (bogus_component_loc,
    3317                 :             :                                         guessed_id);
    3318                 :          53 :       error_at (&rich_loc,
    3319                 :             :                 "%q#T has no member named %qE;"
    3320                 :             :                 " did you mean %qE?",
    3321                 :          53 :                 TREE_CODE (access_path) == TREE_BINFO
    3322                 :           0 :                 ? TREE_TYPE (access_path) : object_type,
    3323                 :             :                 name, guessed_id);
    3324                 :             :     }
    3325                 :         123 : }
    3326                 :             : 
    3327                 :             : /* This function is called by the parser to process a class member
    3328                 :             :    access expression of the form OBJECT.NAME.  NAME is a node used by
    3329                 :             :    the parser to represent a name; it is not yet a DECL.  It may,
    3330                 :             :    however, be a BASELINK where the BASELINK_FUNCTIONS is a
    3331                 :             :    TEMPLATE_ID_EXPR.  Templates must be looked up by the parser, and
    3332                 :             :    there is no reason to do the lookup twice, so the parser keeps the
    3333                 :             :    BASELINK.  TEMPLATE_P is true iff NAME was explicitly declared to
    3334                 :             :    be a template via the use of the "A::template B" syntax.  */
    3335                 :             : 
    3336                 :             : tree
    3337                 :   151966054 : finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
    3338                 :             :                                  tsubst_flags_t complain)
    3339                 :             : {
    3340                 :   151966054 :   tree expr;
    3341                 :   151966054 :   tree object_type;
    3342                 :   151966054 :   tree member;
    3343                 :   151966054 :   tree access_path = NULL_TREE;
    3344                 :   151966054 :   tree orig_object = object;
    3345                 :   151966054 :   tree orig_name = name;
    3346                 :             : 
    3347                 :   151966054 :   if (object == error_mark_node || name == error_mark_node)
    3348                 :             :     return error_mark_node;
    3349                 :             : 
    3350                 :             :   /* If OBJECT is an ObjC class instance, we must obey ObjC access rules.  */
    3351                 :   151965571 :   if (!objc_is_public (object, name))
    3352                 :           0 :     return error_mark_node;
    3353                 :             : 
    3354                 :   151965571 :   object_type = TREE_TYPE (object);
    3355                 :             : 
    3356                 :   151965571 :   if (processing_template_decl)
    3357                 :             :     {
    3358                 :   127351766 :       if (/* If OBJECT is dependent, so is OBJECT.NAME.  */
    3359                 :   127351766 :           type_dependent_object_expression_p (object)
    3360                 :             :           /* If NAME is "f<args>", where either 'f' or 'args' is
    3361                 :             :              dependent, then the expression is dependent.  */
    3362                 :    62756673 :           || (TREE_CODE (name) == TEMPLATE_ID_EXPR
    3363                 :      490211 :               && dependent_template_id_p (TREE_OPERAND (name, 0),
    3364                 :      490211 :                                           TREE_OPERAND (name, 1)))
    3365                 :             :           /* If NAME is "T::X" where "T" is dependent, then the
    3366                 :             :              expression is dependent.  */
    3367                 :    62551948 :           || (TREE_CODE (name) == SCOPE_REF
    3368                 :      106427 :               && TYPE_P (TREE_OPERAND (name, 0))
    3369                 :      106427 :               && dependent_scope_p (TREE_OPERAND (name, 0)))
    3370                 :             :           /* If NAME is operator T where "T" is dependent, we can't
    3371                 :             :              lookup until we instantiate the T.  */
    3372                 :   189797606 :           || (TREE_CODE (name) == IDENTIFIER_NODE
    3373                 :   123537434 :               && IDENTIFIER_CONV_OP_P (name)
    3374                 :          43 :               && dependent_type_p (TREE_TYPE (name))))
    3375                 :             :         {
    3376                 :    77778834 :         dependent:
    3377                 :    77778834 :           return build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF,
    3378                 :    77778834 :                                    orig_object, orig_name, NULL_TREE);
    3379                 :             :         }
    3380                 :             :     }
    3381                 :    24613805 :   else if (c_dialect_objc ()
    3382                 :    87059606 :            && identifier_p (name)
    3383                 :    24613805 :            && (expr = objc_maybe_build_component_ref (object, name)))
    3384                 :             :     return expr;
    3385                 :             :     
    3386                 :             :   /* [expr.ref]
    3387                 :             : 
    3388                 :             :      The type of the first expression shall be "class object" (of a
    3389                 :             :      complete type).  */
    3390                 :    87059606 :   if (!currently_open_class (object_type)
    3391                 :    87059606 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    3392                 :          79 :     return error_mark_node;
    3393                 :    87059527 :   if (!CLASS_TYPE_P (object_type))
    3394                 :             :     {
    3395                 :       47386 :       if (complain & tf_error)
    3396                 :             :         {
    3397                 :         102 :           if (INDIRECT_TYPE_P (object_type)
    3398                 :         102 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    3399                 :          28 :             error ("request for member %qD in %qE, which is of pointer "
    3400                 :             :                    "type %qT (maybe you meant to use %<->%> ?)",
    3401                 :             :                    name, object.get_value (), object_type);
    3402                 :             :           else
    3403                 :          74 :             error ("request for member %qD in %qE, which is of non-class "
    3404                 :             :                    "type %qT", name, object.get_value (), object_type);
    3405                 :             :         }
    3406                 :       47386 :       return error_mark_node;
    3407                 :             :     }
    3408                 :             : 
    3409                 :    87012141 :   if (BASELINK_P (name))
    3410                 :             :     /* A member function that has already been looked up.  */
    3411                 :             :     member = name;
    3412                 :             :   else
    3413                 :             :     {
    3414                 :    78967728 :       bool is_template_id = false;
    3415                 :    78967728 :       tree template_args = NULL_TREE;
    3416                 :    78967728 :       tree scope = NULL_TREE;
    3417                 :             : 
    3418                 :    78967728 :       access_path = object_type;
    3419                 :             : 
    3420                 :    78967728 :       if (TREE_CODE (name) == SCOPE_REF)
    3421                 :             :         {
    3422                 :             :           /* A qualified name.  The qualifying class or namespace `S'
    3423                 :             :              has already been looked up; it is either a TYPE or a
    3424                 :             :              NAMESPACE_DECL.  */
    3425                 :        2084 :           scope = TREE_OPERAND (name, 0);
    3426                 :        2084 :           name = TREE_OPERAND (name, 1);
    3427                 :             : 
    3428                 :             :           /* If SCOPE is a namespace, then the qualified name does not
    3429                 :             :              name a member of OBJECT_TYPE.  */
    3430                 :        2084 :           if (TREE_CODE (scope) == NAMESPACE_DECL)
    3431                 :             :             {
    3432                 :           0 :               if (complain & tf_error)
    3433                 :           0 :                 error ("%<%D::%D%> is not a member of %qT",
    3434                 :             :                        scope, name, object_type);
    3435                 :           0 :               return error_mark_node;
    3436                 :             :             }
    3437                 :             :         }
    3438                 :             :       
    3439                 :    78967728 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    3440                 :             :         {
    3441                 :      422803 :           is_template_id = true;
    3442                 :      422803 :           template_args = TREE_OPERAND (name, 1);
    3443                 :      422803 :           name = TREE_OPERAND (name, 0);
    3444                 :             : 
    3445                 :      810093 :           if (!identifier_p (name))
    3446                 :      387308 :             name = OVL_NAME (name);
    3447                 :             :         }
    3448                 :             : 
    3449                 :    78967728 :       if (scope)
    3450                 :             :         {
    3451                 :        2084 :           if (TREE_CODE (scope) == ENUMERAL_TYPE)
    3452                 :             :             {
    3453                 :          12 :               gcc_assert (!is_template_id);
    3454                 :             :               /* Looking up a member enumerator (c++/56793).  */
    3455                 :          24 :               if (!TYPE_CLASS_SCOPE_P (scope)
    3456                 :          21 :                   || !DERIVED_FROM_P (TYPE_CONTEXT (scope), object_type))
    3457                 :             :                 {
    3458                 :           3 :                   if (complain & tf_error)
    3459                 :           3 :                     error ("%<%D::%D%> is not a member of %qT",
    3460                 :             :                            scope, name, object_type);
    3461                 :           3 :                   return error_mark_node;
    3462                 :             :                 }
    3463                 :           9 :               tree val = lookup_enumerator (scope, name);
    3464                 :           9 :               if (!val)
    3465                 :             :                 {
    3466                 :           6 :                   if (complain & tf_error)
    3467                 :           6 :                     error ("%qD is not a member of %qD",
    3468                 :             :                            name, scope);
    3469                 :           6 :                   return error_mark_node;
    3470                 :             :                 }
    3471                 :             : 
    3472                 :           3 :               if (TREE_SIDE_EFFECTS (object))
    3473                 :           0 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val);
    3474                 :           3 :               return val;
    3475                 :             :             }
    3476                 :             : 
    3477                 :        2072 :           gcc_assert (CLASS_TYPE_P (scope));
    3478                 :        2072 :           gcc_assert (identifier_p (name) || TREE_CODE (name) == BIT_NOT_EXPR);
    3479                 :             : 
    3480                 :        2072 :           if (constructor_name_p (name, scope))
    3481                 :             :             {
    3482                 :           4 :               if (complain & tf_error)
    3483                 :           4 :                 error ("cannot call constructor %<%T::%D%> directly",
    3484                 :             :                        scope, name);
    3485                 :           4 :               return error_mark_node;
    3486                 :             :             }
    3487                 :             : 
    3488                 :             :           /* NAME may refer to a static data member, in which case there is
    3489                 :             :              one copy of the data member that is shared by all the objects of
    3490                 :             :              the class.  So NAME can be unambiguously referred to even if
    3491                 :             :              there are multiple indirect base classes containing NAME.  */
    3492                 :        6204 :           const base_access ba = [scope, name] ()
    3493                 :             :             {
    3494                 :        2068 :               if (identifier_p (name))
    3495                 :             :                 {
    3496                 :        1905 :                   tree m = lookup_member (scope, name, /*protect=*/0,
    3497                 :             :                                           /*want_type=*/false, tf_none);
    3498                 :        1905 :                   if (!m || shared_member_p (m))
    3499                 :          38 :                     return ba_any;
    3500                 :             :                 }
    3501                 :             :               return ba_check;
    3502                 :        2068 :             } ();
    3503                 :             : 
    3504                 :             :           /* Find the base of OBJECT_TYPE corresponding to SCOPE.  */
    3505                 :        2068 :           access_path = lookup_base (object_type, scope, ba, NULL, complain);
    3506                 :        2068 :           if (access_path == error_mark_node)
    3507                 :             :             return error_mark_node;
    3508                 :        2053 :           if (!access_path)
    3509                 :             :             {
    3510                 :          15 :               if (any_dependent_bases_p (object_type))
    3511                 :           7 :                 goto dependent;
    3512                 :           8 :               if (complain & tf_error)
    3513                 :           8 :                 error ("%qT is not a base of %qT", scope, object_type);
    3514                 :           8 :               return error_mark_node;
    3515                 :             :             }
    3516                 :             :         }
    3517                 :             : 
    3518                 :    78967682 :       if (TREE_CODE (name) == BIT_NOT_EXPR)
    3519                 :             :         {
    3520                 :      173849 :           if (dependent_type_p (object_type))
    3521                 :             :             /* The destructor isn't declared yet.  */
    3522                 :       32385 :             goto dependent;
    3523                 :      141464 :           member = lookup_destructor (object, scope, name, complain);
    3524                 :             :         }
    3525                 :             :       else
    3526                 :             :         {
    3527                 :             :           /* Look up the member.  */
    3528                 :    78793833 :           access_failure_info afi;
    3529                 :    78793833 :           if (processing_template_decl)
    3530                 :             :             /* Even though this class member access expression is at this
    3531                 :             :                point not dependent, the member itself may be dependent, and
    3532                 :             :                we must not potentially push a access check for a dependent
    3533                 :             :                member onto TI_DEFERRED_ACCESS_CHECKS.  So don't check access
    3534                 :             :                ahead of time here; we're going to redo this member lookup at
    3535                 :             :                instantiation time anyway.  */
    3536                 :    62183394 :             push_deferring_access_checks (dk_no_check);
    3537                 :    78793833 :           member = lookup_member (access_path, name, /*protect=*/1,
    3538                 :             :                                   /*want_type=*/false, complain,
    3539                 :             :                                   &afi);
    3540                 :    78793833 :           if (processing_template_decl)
    3541                 :    62183394 :             pop_deferring_access_checks ();
    3542                 :    78793833 :           afi.maybe_suggest_accessor (TYPE_READONLY (object_type));
    3543                 :    78793833 :           if (member == NULL_TREE)
    3544                 :             :             {
    3545                 :     7845871 :               if (dependent_type_p (object_type))
    3546                 :             :                 /* Try again at instantiation time.  */
    3547                 :    12840477 :                 goto dependent;
    3548                 :        9978 :               if (complain & tf_error)
    3549                 :         256 :                 complain_about_unrecognized_member (access_path, name,
    3550                 :             :                                                     object_type);
    3551                 :       10024 :               return error_mark_node;
    3552                 :             :             }
    3553                 :    70947962 :           if (member == error_mark_node)
    3554                 :             :             return error_mark_node;
    3555                 :    70947916 :           if (DECL_P (member)
    3556                 :    70947916 :               && any_dependent_type_attributes_p (DECL_ATTRIBUTES (member)))
    3557                 :             :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3558                 :             :                wrong, so don't use it.  */
    3559                 :           8 :             goto dependent;
    3560                 :    70947908 :           if (TREE_CODE (member) == USING_DECL && DECL_DEPENDENT_P (member))
    3561                 :     5004576 :             goto dependent;
    3562                 :             :         }
    3563                 :             : 
    3564                 :    66084796 :       if (is_template_id)
    3565                 :             :         {
    3566                 :      422790 :           tree templ = member;
    3567                 :             : 
    3568                 :      422790 :           if (BASELINK_P (templ))
    3569                 :      422766 :             member = lookup_template_function (templ, template_args);
    3570                 :          24 :           else if (variable_template_p (templ))
    3571                 :          24 :             member = (lookup_and_finish_template_variable
    3572                 :          24 :                       (templ, template_args, complain));
    3573                 :             :           else
    3574                 :             :             {
    3575                 :           0 :               if (complain & tf_error)
    3576                 :           0 :                 error ("%qD is not a member template function", name);
    3577                 :           0 :               return error_mark_node;
    3578                 :             :             }
    3579                 :             :         }
    3580                 :             :     }
    3581                 :             : 
    3582                 :    74129209 :   if (TREE_UNAVAILABLE (member))
    3583                 :          40 :     error_unavailable_use (member, NULL_TREE);
    3584                 :    74129169 :   else if (TREE_DEPRECATED (member))
    3585                 :          40 :     warn_deprecated_use (member, NULL_TREE);
    3586                 :             : 
    3587                 :    74129209 :   if (template_p)
    3588                 :        9476 :     check_template_keyword (member);
    3589                 :             : 
    3590                 :    74129209 :   expr = build_class_member_access_expr (object, member, access_path,
    3591                 :             :                                          /*preserve_reference=*/false,
    3592                 :             :                                          complain);
    3593                 :    74129209 :   if (processing_template_decl && expr != error_mark_node)
    3594                 :             :     {
    3595                 :    49572894 :       if (BASELINK_P (member))
    3596                 :             :         {
    3597                 :    36761536 :           if (TREE_CODE (orig_name) == SCOPE_REF)
    3598                 :         268 :             BASELINK_QUALIFIED_P (member) = 1;
    3599                 :             :           orig_name = member;
    3600                 :             :         }
    3601                 :    49572894 :       return build_min_non_dep (COMPONENT_REF, expr,
    3602                 :             :                                 orig_object, orig_name,
    3603                 :    49572894 :                                 NULL_TREE);
    3604                 :             :     }
    3605                 :             : 
    3606                 :             :   return expr;
    3607                 :             : }
    3608                 :             : 
    3609                 :             : /* Build a COMPONENT_REF of OBJECT and MEMBER with the appropriate
    3610                 :             :    type.  */
    3611                 :             : 
    3612                 :             : tree
    3613                 :      171765 : build_simple_component_ref (tree object, tree member)
    3614                 :             : {
    3615                 :      171765 :   tree type = cp_build_qualified_type (TREE_TYPE (member),
    3616                 :      171765 :                                        cp_type_quals (TREE_TYPE (object)));
    3617                 :      171765 :   return build3_loc (input_location,
    3618                 :             :                      COMPONENT_REF, type,
    3619                 :      171765 :                      object, member, NULL_TREE);
    3620                 :             : }
    3621                 :             : 
    3622                 :             : /* Return an expression for the MEMBER_NAME field in the internal
    3623                 :             :    representation of PTRMEM, a pointer-to-member function.  (Each
    3624                 :             :    pointer-to-member function type gets its own RECORD_TYPE so it is
    3625                 :             :    more convenient to access the fields by name than by FIELD_DECL.)
    3626                 :             :    This routine converts the NAME to a FIELD_DECL and then creates the
    3627                 :             :    node for the complete expression.  */
    3628                 :             : 
    3629                 :             : tree
    3630                 :      171748 : build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
    3631                 :             : {
    3632                 :      171748 :   tree ptrmem_type;
    3633                 :      171748 :   tree member;
    3634                 :             : 
    3635                 :      171748 :   if (TREE_CODE (ptrmem) == CONSTRUCTOR)
    3636                 :             :     {
    3637                 :         247 :       for (auto &e: CONSTRUCTOR_ELTS (ptrmem))
    3638                 :         101 :         if (e.index && DECL_P (e.index) && DECL_NAME (e.index) == member_name)
    3639                 :          73 :           return e.value;
    3640                 :           0 :       gcc_unreachable ();
    3641                 :             :     }
    3642                 :             : 
    3643                 :             :   /* This code is a stripped down version of
    3644                 :             :      build_class_member_access_expr.  It does not work to use that
    3645                 :             :      routine directly because it expects the object to be of class
    3646                 :             :      type.  */
    3647                 :      171675 :   ptrmem_type = TREE_TYPE (ptrmem);
    3648                 :      171675 :   gcc_assert (TYPE_PTRMEMFUNC_P (ptrmem_type));
    3649                 :      257404 :   for (member = TYPE_FIELDS (ptrmem_type); member;
    3650                 :       85729 :        member = DECL_CHAIN (member))
    3651                 :      257404 :     if (DECL_NAME (member) == member_name)
    3652                 :             :       break;
    3653                 :      171675 :   return build_simple_component_ref (ptrmem, member);
    3654                 :             : }
    3655                 :             : 
    3656                 :             : /* Return a TREE_LIST of namespace-scope overloads for the given operator,
    3657                 :             :    and for any other relevant operator.  */
    3658                 :             : 
    3659                 :             : static tree
    3660                 :   110058469 : op_unqualified_lookup (tree_code code, bool is_assign)
    3661                 :             : {
    3662                 :   110058469 :   tree lookups = NULL_TREE;
    3663                 :             : 
    3664                 :   110058469 :   if (cxx_dialect >= cxx20 && !is_assign)
    3665                 :             :     {
    3666                 :    26300411 :       if (code == NE_EXPR)
    3667                 :             :         {
    3668                 :             :           /* != can get rewritten in terms of ==.  */
    3669                 :     1696258 :           tree fnname = ovl_op_identifier (false, EQ_EXPR);
    3670                 :     1696258 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3671                 :     1684682 :             lookups = tree_cons (fnname, fns, lookups);
    3672                 :             :         }
    3673                 :    24604153 :       else if (code == GT_EXPR || code == LE_EXPR
    3674                 :    24604153 :                || code == LT_EXPR || code == GE_EXPR)
    3675                 :             :         {
    3676                 :             :           /* These can get rewritten in terms of <=>.  */
    3677                 :     2328345 :           tree fnname = ovl_op_identifier (false, SPACESHIP_EXPR);
    3678                 :     2328345 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3679                 :     2221524 :             lookups = tree_cons (fnname, fns, lookups);
    3680                 :             :         }
    3681                 :             :     }
    3682                 :             : 
    3683                 :   110058469 :   tree fnname = ovl_op_identifier (is_assign, code);
    3684                 :   110058469 :   if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3685                 :    62401975 :     lookups = tree_cons (fnname, fns, lookups);
    3686                 :             : 
    3687                 :   110058469 :   if (lookups)
    3688                 :             :     return lookups;
    3689                 :             :   else
    3690                 :    47591758 :     return build_tree_list (NULL_TREE, NULL_TREE);
    3691                 :             : }
    3692                 :             : 
    3693                 :             : /* Create a DEPENDENT_OPERATOR_TYPE for a dependent operator expression of
    3694                 :             :    the given operator.  LOOKUPS, if non-NULL, is the result of phase 1
    3695                 :             :    name lookup for the given operator.  */
    3696                 :             : 
    3697                 :             : tree
    3698                 :   119799745 : build_dependent_operator_type (tree lookups, tree_code code, bool is_assign)
    3699                 :             : {
    3700                 :   119799745 :   if (lookups)
    3701                 :             :     /* We're partially instantiating a dependent operator expression, and
    3702                 :             :        LOOKUPS is the result of phase 1 name lookup that we performed
    3703                 :             :        earlier at template definition time, so just reuse the corresponding
    3704                 :             :        DEPENDENT_OPERATOR_TYPE.  */
    3705                 :     9741276 :     return TREE_TYPE (lookups);
    3706                 :             : 
    3707                 :             :   /* Otherwise we're processing a dependent operator expression at template
    3708                 :             :      definition time, so perform phase 1 name lookup now.  */
    3709                 :   110058469 :   lookups = op_unqualified_lookup (code, is_assign);
    3710                 :             : 
    3711                 :   110058469 :   tree type = cxx_make_type (DEPENDENT_OPERATOR_TYPE);
    3712                 :   110058469 :   DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (type) = lookups;
    3713                 :   110058469 :   TREE_TYPE (lookups) = type;
    3714                 :   110058469 :   return type;
    3715                 :             : }
    3716                 :             : 
    3717                 :             : /* Given an expression PTR for a pointer, return an expression
    3718                 :             :    for the value pointed to.
    3719                 :             :    ERRORSTRING is the name of the operator to appear in error messages.
    3720                 :             : 
    3721                 :             :    This function may need to overload OPERATOR_FNNAME.
    3722                 :             :    Must also handle REFERENCE_TYPEs for C++.  */
    3723                 :             : 
    3724                 :             : tree
    3725                 :    35241788 : build_x_indirect_ref (location_t loc, tree expr, ref_operator errorstring, 
    3726                 :             :                       tree lookups, tsubst_flags_t complain)
    3727                 :             : {
    3728                 :    35241788 :   tree orig_expr = expr;
    3729                 :    35241788 :   tree rval;
    3730                 :    35241788 :   tree overload = NULL_TREE;
    3731                 :             : 
    3732                 :    35241788 :   if (processing_template_decl)
    3733                 :             :     {
    3734                 :             :       /* Retain the type if we know the operand is a pointer.  */
    3735                 :    20733393 :       if (TREE_TYPE (expr) && INDIRECT_TYPE_P (TREE_TYPE (expr)))
    3736                 :             :         {
    3737                 :    11453549 :           if (expr == current_class_ptr
    3738                 :    11453549 :               || (TREE_CODE (expr) == NOP_EXPR
    3739                 :     7044996 :                   && TREE_OPERAND (expr, 0) == current_class_ptr
    3740                 :     7033593 :                   && (same_type_ignoring_top_level_qualifiers_p
    3741                 :     7033593 :                         (TREE_TYPE (expr), TREE_TYPE (current_class_ptr)))))
    3742                 :     7033593 :             return current_class_ref;
    3743                 :     4419956 :           return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
    3744                 :             :         }
    3745                 :     9279844 :       if (type_dependent_expression_p (expr))
    3746                 :             :         {
    3747                 :     9140854 :           expr = build_min_nt_loc (loc, INDIRECT_REF, expr);
    3748                 :     9140854 :           TREE_TYPE (expr)
    3749                 :     9140854 :             = build_dependent_operator_type (lookups, INDIRECT_REF, false);
    3750                 :     9140854 :           return expr;
    3751                 :             :         }
    3752                 :             :     }
    3753                 :             : 
    3754                 :    14647385 :   rval = build_new_op (loc, INDIRECT_REF, LOOKUP_NORMAL, expr,
    3755                 :             :                        NULL_TREE, NULL_TREE, lookups,
    3756                 :             :                        &overload, complain);
    3757                 :    14647385 :   if (!rval)
    3758                 :           0 :     rval = cp_build_indirect_ref (loc, expr, errorstring, complain);
    3759                 :             : 
    3760                 :    14647385 :   if (processing_template_decl && rval != error_mark_node)
    3761                 :             :     {
    3762                 :      137155 :       if (overload != NULL_TREE)
    3763                 :      137121 :         return (build_min_non_dep_op_overload
    3764                 :      137121 :                 (INDIRECT_REF, rval, overload, orig_expr));
    3765                 :             : 
    3766                 :          34 :       return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
    3767                 :             :     }
    3768                 :             :   else
    3769                 :             :     return rval;
    3770                 :             : }
    3771                 :             : 
    3772                 :             : /* Like c-family strict_aliasing_warning, but don't warn for dependent
    3773                 :             :    types or expressions.  */
    3774                 :             : 
    3775                 :             : static bool
    3776                 :      495799 : cp_strict_aliasing_warning (location_t loc, tree type, tree expr)
    3777                 :             : {
    3778                 :      495799 :   if (processing_template_decl)
    3779                 :             :     {
    3780                 :       35265 :       tree e = expr;
    3781                 :       35265 :       STRIP_NOPS (e);
    3782                 :       35265 :       if (dependent_type_p (type) || type_dependent_expression_p (e))
    3783                 :        6272 :         return false;
    3784                 :             :     }
    3785                 :      489527 :   return strict_aliasing_warning (loc, type, expr);
    3786                 :             : }
    3787                 :             : 
    3788                 :             : /* The implementation of the above, and of indirection implied by other
    3789                 :             :    constructs.  If DO_FOLD is true, fold away INDIRECT_REF of ADDR_EXPR.  */
    3790                 :             : 
    3791                 :             : static tree
    3792                 :   270798484 : cp_build_indirect_ref_1 (location_t loc, tree ptr, ref_operator errorstring,
    3793                 :             :                          tsubst_flags_t complain, bool do_fold)
    3794                 :             : {
    3795                 :   270798484 :   tree pointer, type;
    3796                 :             : 
    3797                 :             :   /* RO_NULL should only be used with the folding entry points below, not
    3798                 :             :      cp_build_indirect_ref.  */
    3799                 :   270798484 :   gcc_checking_assert (errorstring != RO_NULL || do_fold);
    3800                 :             : 
    3801                 :   270798484 :   if (ptr == current_class_ptr
    3802                 :   270798484 :       || (TREE_CODE (ptr) == NOP_EXPR
    3803                 :    26499320 :           && TREE_OPERAND (ptr, 0) == current_class_ptr
    3804                 :    14579317 :           && (same_type_ignoring_top_level_qualifiers_p
    3805                 :    14579317 :               (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr)))))
    3806                 :    15802593 :     return current_class_ref;
    3807                 :             : 
    3808                 :   254995891 :   pointer = (TYPE_REF_P (TREE_TYPE (ptr))
    3809                 :   254995891 :              ? ptr : decay_conversion (ptr, complain));
    3810                 :   254995891 :   if (pointer == error_mark_node)
    3811                 :             :     return error_mark_node;
    3812                 :             : 
    3813                 :   254990072 :   type = TREE_TYPE (pointer);
    3814                 :             : 
    3815                 :   254990072 :   if (INDIRECT_TYPE_P (type))
    3816                 :             :     {
    3817                 :             :       /* [expr.unary.op]
    3818                 :             : 
    3819                 :             :          If the type of the expression is "pointer to T," the type
    3820                 :             :          of  the  result  is  "T."  */
    3821                 :   254989808 :       tree t = TREE_TYPE (type);
    3822                 :             : 
    3823                 :   241992014 :       if ((CONVERT_EXPR_P (ptr)
    3824                 :   185495545 :            || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
    3825                 :   313286502 :           && (!CLASS_TYPE_P (t) || !CLASSTYPE_EMPTY_P (t)))
    3826                 :             :         {
    3827                 :             :           /* If a warning is issued, mark it to avoid duplicates from
    3828                 :             :              the backend.  This only needs to be done at
    3829                 :             :              warn_strict_aliasing > 2.  */
    3830                 :    48716810 :           if (warn_strict_aliasing > 2
    3831                 :    49138148 :               && cp_strict_aliasing_warning (EXPR_LOCATION (ptr),
    3832                 :      421338 :                                              type, TREE_OPERAND (ptr, 0)))
    3833                 :           8 :             suppress_warning (ptr, OPT_Wstrict_aliasing);
    3834                 :             :         }
    3835                 :             : 
    3836                 :   254989808 :       if (VOID_TYPE_P (t))
    3837                 :             :         {
    3838                 :             :           /* A pointer to incomplete type (other than cv void) can be
    3839                 :             :              dereferenced [expr.unary.op]/1  */
    3840                 :          76 :           if (complain & tf_error)
    3841                 :          25 :             error_at (loc, "%qT is not a pointer-to-object type", type);
    3842                 :          76 :           return error_mark_node;
    3843                 :             :         }
    3844                 :   246498338 :       else if (do_fold && TREE_CODE (pointer) == ADDR_EXPR
    3845                 :   259867344 :                && same_type_p (t, TREE_TYPE (TREE_OPERAND (pointer, 0))))
    3846                 :             :         /* The POINTER was something like `&x'.  We simplify `*&x' to
    3847                 :             :            `x'.  */
    3848                 :     4877612 :         return TREE_OPERAND (pointer, 0);
    3849                 :             :       else
    3850                 :             :         {
    3851                 :   250112120 :           tree ref = build1 (INDIRECT_REF, t, pointer);
    3852                 :             : 
    3853                 :             :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3854                 :             :              so that we get the proper error message if the result is used
    3855                 :             :              to assign to.  Also, &* is supposed to be a no-op.  */
    3856                 :   250112120 :           TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
    3857                 :   250112120 :           TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
    3858                 :   250112120 :           TREE_SIDE_EFFECTS (ref)
    3859                 :   250112120 :             = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (pointer));
    3860                 :   250112120 :           return ref;
    3861                 :             :         }
    3862                 :             :     }
    3863                 :         264 :   else if (!(complain & tf_error))
    3864                 :             :     /* Don't emit any errors; we'll just return ERROR_MARK_NODE later.  */
    3865                 :             :     ;
    3866                 :             :   /* `pointer' won't be an error_mark_node if we were given a
    3867                 :             :      pointer to member, so it's cool to check for this here.  */
    3868                 :          41 :   else if (TYPE_PTRMEM_P (type))
    3869                 :          20 :     switch (errorstring)
    3870                 :             :       {
    3871                 :           0 :          case RO_ARRAY_INDEXING:
    3872                 :           0 :            error_at (loc,
    3873                 :             :                      "invalid use of array indexing on pointer to member");
    3874                 :           0 :            break;
    3875                 :          16 :          case RO_UNARY_STAR:
    3876                 :          16 :            error_at (loc, "invalid use of unary %<*%> on pointer to member");
    3877                 :          16 :            break;
    3878                 :           0 :          case RO_IMPLICIT_CONVERSION:
    3879                 :           0 :            error_at (loc, "invalid use of implicit conversion on pointer "
    3880                 :             :                      "to member");
    3881                 :           0 :            break;
    3882                 :           4 :          case RO_ARROW_STAR:
    3883                 :           4 :            error_at (loc, "left hand operand of %<->*%> must be a pointer to "
    3884                 :             :                      "class, but is a pointer to member of type %qT", type);
    3885                 :           4 :            break;
    3886                 :           0 :          default:
    3887                 :           0 :            gcc_unreachable ();
    3888                 :             :       }
    3889                 :          21 :   else if (pointer != error_mark_node)
    3890                 :          21 :     invalid_indirection_error (loc, type, errorstring);
    3891                 :             : 
    3892                 :         264 :   return error_mark_node;
    3893                 :             : }
    3894                 :             : 
    3895                 :             : /* Entry point used by c-common, which expects folding.  */
    3896                 :             : 
    3897                 :             : tree
    3898                 :       26633 : build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring)
    3899                 :             : {
    3900                 :       26633 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring,
    3901                 :       26633 :                                   tf_warning_or_error, true);
    3902                 :             : }
    3903                 :             : 
    3904                 :             : /* Entry point used by internal indirection needs that don't correspond to any
    3905                 :             :    syntactic construct.  */
    3906                 :             : 
    3907                 :             : tree
    3908                 :   249480349 : cp_build_fold_indirect_ref (tree pointer)
    3909                 :             : {
    3910                 :   249480349 :   return cp_build_indirect_ref_1 (input_location, pointer, RO_NULL,
    3911                 :   249480349 :                                   tf_warning_or_error, true);
    3912                 :             : }
    3913                 :             : 
    3914                 :             : /* Entry point used by indirection needs that correspond to some syntactic
    3915                 :             :    construct.  */
    3916                 :             : 
    3917                 :             : tree
    3918                 :    21291502 : cp_build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring,
    3919                 :             :                        tsubst_flags_t complain)
    3920                 :             : {
    3921                 :    21291502 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring, complain, false);
    3922                 :             : }
    3923                 :             : 
    3924                 :             : /* This handles expressions of the form "a[i]", which denotes
    3925                 :             :    an array reference.
    3926                 :             : 
    3927                 :             :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3928                 :             :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3929                 :             :    This avoids forcing the array out of registers, and can work on
    3930                 :             :    arrays that are not lvalues (for example, members of structures returned
    3931                 :             :    by functions).
    3932                 :             : 
    3933                 :             :    If INDEX is of some user-defined type, it must be converted to
    3934                 :             :    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
    3935                 :             :    will inherit the type of the array, which will be some pointer type.
    3936                 :             : 
    3937                 :             :    LOC is the location to use in building the array reference.  */
    3938                 :             : 
    3939                 :             : tree
    3940                 :     5049268 : cp_build_array_ref (location_t loc, tree array, tree idx,
    3941                 :             :                     tsubst_flags_t complain)
    3942                 :             : {
    3943                 :     5049268 :   tree first = NULL_TREE;
    3944                 :     5049268 :   tree ret;
    3945                 :             : 
    3946                 :     5049268 :   if (idx == 0)
    3947                 :             :     {
    3948                 :           0 :       if (complain & tf_error)
    3949                 :           0 :         error_at (loc, "subscript missing in array reference");
    3950                 :           0 :       return error_mark_node;
    3951                 :             :     }
    3952                 :             : 
    3953                 :     5049268 :   if (TREE_TYPE (array) == error_mark_node
    3954                 :     5049268 :       || TREE_TYPE (idx) == error_mark_node)
    3955                 :             :     return error_mark_node;
    3956                 :             : 
    3957                 :             :   /* If ARRAY is a COMPOUND_EXPR or COND_EXPR, move our reference
    3958                 :             :      inside it.  */
    3959                 :     5049268 :   switch (TREE_CODE (array))
    3960                 :             :     {
    3961                 :          34 :     case COMPOUND_EXPR:
    3962                 :          34 :       {
    3963                 :          34 :         tree value = cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    3964                 :             :                                          complain);
    3965                 :          34 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
    3966                 :          34 :                       TREE_OPERAND (array, 0), value);
    3967                 :          34 :         SET_EXPR_LOCATION (ret, loc);
    3968                 :          34 :         return ret;
    3969                 :             :       }
    3970                 :             : 
    3971                 :          15 :     case COND_EXPR:
    3972                 :          15 :       ret = build_conditional_expr
    3973                 :          30 :                (loc, TREE_OPERAND (array, 0),
    3974                 :          15 :                cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    3975                 :             :                                    complain),
    3976                 :          15 :                cp_build_array_ref (loc, TREE_OPERAND (array, 2), idx,
    3977                 :             :                                    complain),
    3978                 :             :                complain);
    3979                 :          15 :       protected_set_expr_location (ret, loc);
    3980                 :          15 :       return ret;
    3981                 :             : 
    3982                 :     5049219 :     default:
    3983                 :     5049219 :       break;
    3984                 :             :     }
    3985                 :             : 
    3986                 :     5049219 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, idx);
    3987                 :             : 
    3988                 :             :   /* 0[array] */
    3989                 :     5049219 :   if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE)
    3990                 :             :     {
    3991                 :           8 :       std::swap (array, idx);
    3992                 :           8 :       if (flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (array))
    3993                 :           6 :         idx = first = save_expr (idx);
    3994                 :             :     }
    3995                 :             : 
    3996                 :     5049219 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    3997                 :             :     {
    3998                 :     1623532 :       tree rval, type;
    3999                 :             : 
    4000                 :     1623532 :       warn_array_subscript_with_type_char (loc, idx);
    4001                 :             : 
    4002                 :     1623532 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
    4003                 :             :         {
    4004                 :           3 :           if (complain & tf_error)
    4005                 :           3 :             error_at (loc, "array subscript is not an integer");
    4006                 :           3 :           return error_mark_node;
    4007                 :             :         }
    4008                 :             : 
    4009                 :             :       /* Apply integral promotions *after* noticing character types.
    4010                 :             :          (It is unclear why we do these promotions -- the standard
    4011                 :             :          does not say that we should.  In fact, the natural thing would
    4012                 :             :          seem to be to convert IDX to ptrdiff_t; we're performing
    4013                 :             :          pointer arithmetic.)  */
    4014                 :     1623529 :       idx = cp_perform_integral_promotions (idx, complain);
    4015                 :             : 
    4016                 :     1623529 :       idx = maybe_fold_non_dependent_expr (idx, complain);
    4017                 :             : 
    4018                 :             :       /* An array that is indexed by a non-constant
    4019                 :             :          cannot be stored in a register; we must be able to do
    4020                 :             :          address arithmetic on its address.
    4021                 :             :          Likewise an array of elements of variable size.  */
    4022                 :     1623529 :       if (TREE_CODE (idx) != INTEGER_CST
    4023                 :     1623529 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    4024                 :      813189 :               && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))))
    4025                 :             :                   != INTEGER_CST)))
    4026                 :             :         {
    4027                 :      811998 :           if (!cxx_mark_addressable (array, true))
    4028                 :           0 :             return error_mark_node;
    4029                 :             :         }
    4030                 :             : 
    4031                 :             :       /* An array that is indexed by a constant value which is not within
    4032                 :             :          the array bounds cannot be stored in a register either; because we
    4033                 :             :          would get a crash in store_bit_field/extract_bit_field when trying
    4034                 :             :          to access a non-existent part of the register.  */
    4035                 :     1623529 :       if (TREE_CODE (idx) == INTEGER_CST
    4036                 :      813193 :           && TYPE_DOMAIN (TREE_TYPE (array))
    4037                 :     2435064 :           && ! int_fits_type_p (idx, TYPE_DOMAIN (TREE_TYPE (array))))
    4038                 :             :         {
    4039                 :        3233 :           if (!cxx_mark_addressable (array))
    4040                 :           0 :             return error_mark_node;
    4041                 :             :         }
    4042                 :             : 
    4043                 :             :       /* Note in C++ it is valid to subscript a `register' array, since
    4044                 :             :          it is valid to take the address of something with that
    4045                 :             :          storage specification.  */
    4046                 :     1623529 :       if (extra_warnings)
    4047                 :             :         {
    4048                 :       36841 :           tree foo = array;
    4049                 :       56608 :           while (TREE_CODE (foo) == COMPONENT_REF)
    4050                 :       19767 :             foo = TREE_OPERAND (foo, 0);
    4051                 :           8 :           if (VAR_P (foo) && DECL_REGISTER (foo)
    4052                 :       36841 :               && (complain & tf_warning))
    4053                 :           0 :             warning_at (loc, OPT_Wextra,
    4054                 :             :                         "subscripting array declared %<register%>");
    4055                 :             :         }
    4056                 :             : 
    4057                 :     1623529 :       type = TREE_TYPE (TREE_TYPE (array));
    4058                 :     1623529 :       rval = build4 (ARRAY_REF, type, array, idx, NULL_TREE, NULL_TREE);
    4059                 :             :       /* Array ref is const/volatile if the array elements are
    4060                 :             :          or if the array is..  */
    4061                 :     4870587 :       TREE_READONLY (rval)
    4062                 :     1623529 :         |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
    4063                 :     4870587 :       TREE_SIDE_EFFECTS (rval)
    4064                 :     1623529 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
    4065                 :     3247058 :       TREE_THIS_VOLATILE (rval)
    4066                 :     1623529 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
    4067                 :     1623529 :       ret = require_complete_type (rval, complain);
    4068                 :     1623529 :       protected_set_expr_location (ret, loc);
    4069                 :     1623529 :       if (non_lvalue)
    4070                 :        5078 :         ret = non_lvalue_loc (loc, ret);
    4071                 :     1623529 :       if (first)
    4072                 :           6 :         ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4073                 :     1623529 :       return ret;
    4074                 :             :     }
    4075                 :             : 
    4076                 :     3425687 :   {
    4077                 :     3425687 :     tree ar = cp_default_conversion (array, complain);
    4078                 :     3425687 :     tree ind = cp_default_conversion (idx, complain);
    4079                 :             : 
    4080                 :     3425687 :     if (!first && flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (ind))
    4081                 :      148094 :       ar = first = save_expr (ar);
    4082                 :             : 
    4083                 :             :     /* Put the integer in IND to simplify error checking.  */
    4084                 :     3425687 :     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
    4085                 :          45 :       std::swap (ar, ind);
    4086                 :             : 
    4087                 :     3425687 :     if (ar == error_mark_node || ind == error_mark_node)
    4088                 :             :       return error_mark_node;
    4089                 :             : 
    4090                 :     3425687 :     if (!TYPE_PTR_P (TREE_TYPE (ar)))
    4091                 :             :       {
    4092                 :           8 :         if (complain & tf_error)
    4093                 :           4 :           error_at (loc, "subscripted value is neither array nor pointer");
    4094                 :           8 :         return error_mark_node;
    4095                 :             :       }
    4096                 :     3425679 :     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
    4097                 :             :       {
    4098                 :           0 :         if (complain & tf_error)
    4099                 :           0 :           error_at (loc, "array subscript is not an integer");
    4100                 :           0 :         return error_mark_node;
    4101                 :             :       }
    4102                 :             : 
    4103                 :     3425679 :     warn_array_subscript_with_type_char (loc, idx);
    4104                 :             : 
    4105                 :     3425679 :     ret = cp_build_binary_op (input_location, PLUS_EXPR, ar, ind, complain);
    4106                 :     3425679 :     if (first)
    4107                 :      148094 :       ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4108                 :     3425679 :     ret = cp_build_indirect_ref (loc, ret, RO_ARRAY_INDEXING, complain);
    4109                 :     3425679 :     protected_set_expr_location (ret, loc);
    4110                 :     3425679 :     if (non_lvalue)
    4111                 :           0 :       ret = non_lvalue_loc (loc, ret);
    4112                 :             :     return ret;
    4113                 :             :   }
    4114                 :             : }
    4115                 :             : 
    4116                 :             : /* Entry point for Obj-C++.  */
    4117                 :             : 
    4118                 :             : tree
    4119                 :     3482895 : build_array_ref (location_t loc, tree array, tree idx)
    4120                 :             : {
    4121                 :     3482895 :   return cp_build_array_ref (loc, array, idx, tf_warning_or_error);
    4122                 :             : }
    4123                 :             : 
    4124                 :             : /* Resolve a pointer to member function.  INSTANCE is the object
    4125                 :             :    instance to use, if the member points to a virtual member.
    4126                 :             : 
    4127                 :             :    This used to avoid checking for virtual functions if basetype
    4128                 :             :    has no virtual functions, according to an earlier ANSI draft.
    4129                 :             :    With the final ISO C++ rules, such an optimization is
    4130                 :             :    incorrect: A pointer to a derived member can be static_cast
    4131                 :             :    to pointer-to-base-member, as long as the dynamic object
    4132                 :             :    later has the right member.  So now we only do this optimization
    4133                 :             :    when we know the dynamic type of the object.  */
    4134                 :             : 
    4135                 :             : tree
    4136                 :       85635 : get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function,
    4137                 :             :                                   tsubst_flags_t complain)
    4138                 :             : {
    4139                 :       85635 :   if (TREE_CODE (function) == OFFSET_REF)
    4140                 :           0 :     function = TREE_OPERAND (function, 1);
    4141                 :             : 
    4142                 :       85635 :   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
    4143                 :             :     {
    4144                 :       85635 :       tree idx, delta, e1, e2, e3, vtbl;
    4145                 :       85635 :       bool nonvirtual;
    4146                 :       85635 :       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
    4147                 :       85635 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (fntype));
    4148                 :             : 
    4149                 :       85635 :       tree instance_ptr = *instance_ptrptr;
    4150                 :       85635 :       tree instance_save_expr = 0;
    4151                 :       85635 :       if (instance_ptr == error_mark_node)
    4152                 :             :         {
    4153                 :           0 :           if (TREE_CODE (function) == PTRMEM_CST)
    4154                 :             :             {
    4155                 :             :               /* Extracting the function address from a pmf is only
    4156                 :             :                  allowed with -Wno-pmf-conversions. It only works for
    4157                 :             :                  pmf constants.  */
    4158                 :           0 :               e1 = build_addr_func (PTRMEM_CST_MEMBER (function), complain);
    4159                 :           0 :               e1 = convert (fntype, e1);
    4160                 :           0 :               return e1;
    4161                 :             :             }
    4162                 :             :           else
    4163                 :             :             {
    4164                 :           0 :               if (complain & tf_error)
    4165                 :           0 :                 error ("object missing in use of %qE", function);
    4166                 :           0 :               return error_mark_node;
    4167                 :             :             }
    4168                 :             :         }
    4169                 :             : 
    4170                 :             :       /* True if we know that the dynamic type of the object doesn't have
    4171                 :             :          virtual functions, so we can assume the PFN field is a pointer.  */
    4172                 :       85635 :       nonvirtual = (COMPLETE_TYPE_P (basetype)
    4173                 :       85602 :                     && !TYPE_POLYMORPHIC_P (basetype)
    4174                 :      114943 :                     && resolves_to_fixed_type_p (instance_ptr, 0));
    4175                 :             : 
    4176                 :             :       /* If we don't really have an object (i.e. in an ill-formed
    4177                 :             :          conversion from PMF to pointer), we can't resolve virtual
    4178                 :             :          functions anyway.  */
    4179                 :       85352 :       if (!nonvirtual && is_dummy_object (instance_ptr))
    4180                 :             :         nonvirtual = true;
    4181                 :             : 
    4182                 :       85635 :       if (TREE_SIDE_EFFECTS (instance_ptr))
    4183                 :       56390 :         instance_ptr = instance_save_expr = save_expr (instance_ptr);
    4184                 :             : 
    4185                 :       85635 :       if (TREE_SIDE_EFFECTS (function))
    4186                 :       37665 :         function = save_expr (function);
    4187                 :             : 
    4188                 :             :       /* Start by extracting all the information from the PMF itself.  */
    4189                 :       85635 :       e3 = pfn_from_ptrmemfunc (function);
    4190                 :       85635 :       delta = delta_from_ptrmemfunc (function);
    4191                 :       85635 :       idx = build1 (NOP_EXPR, vtable_index_type, e3);
    4192                 :       85635 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
    4193                 :             :         {
    4194                 :       85635 :           int flag_sanitize_save;
    4195                 :       85635 :         case ptrmemfunc_vbit_in_pfn:
    4196                 :       85635 :           e1 = cp_build_binary_op (input_location,
    4197                 :             :                                    BIT_AND_EXPR, idx, integer_one_node,
    4198                 :             :                                    complain);
    4199                 :       85635 :           idx = cp_build_binary_op (input_location,
    4200                 :             :                                     MINUS_EXPR, idx, integer_one_node,
    4201                 :             :                                     complain);
    4202                 :       85635 :           if (idx == error_mark_node)
    4203                 :             :             return error_mark_node;
    4204                 :       85635 :           break;
    4205                 :             : 
    4206                 :             :         case ptrmemfunc_vbit_in_delta:
    4207                 :             :           e1 = cp_build_binary_op (input_location,
    4208                 :             :                                    BIT_AND_EXPR, delta, integer_one_node,
    4209                 :             :                                    complain);
    4210                 :             :           /* Don't instrument the RSHIFT_EXPR we're about to create because
    4211                 :             :              we're going to use DELTA number of times, and that wouldn't play
    4212                 :             :              well with SAVE_EXPRs therein.  */
    4213                 :             :           flag_sanitize_save = flag_sanitize;
    4214                 :             :           flag_sanitize = 0;
    4215                 :             :           delta = cp_build_binary_op (input_location,
    4216                 :             :                                       RSHIFT_EXPR, delta, integer_one_node,
    4217                 :             :                                       complain);
    4218                 :             :           flag_sanitize = flag_sanitize_save;
    4219                 :             :           if (delta == error_mark_node)
    4220                 :             :             return error_mark_node;
    4221                 :             :           break;
    4222                 :             : 
    4223                 :             :         default:
    4224                 :             :           gcc_unreachable ();
    4225                 :             :         }
    4226                 :             : 
    4227                 :       85635 :       if (e1 == error_mark_node)
    4228                 :             :         return error_mark_node;
    4229                 :             : 
    4230                 :             :       /* Convert down to the right base before using the instance.  A
    4231                 :             :          special case is that in a pointer to member of class C, C may
    4232                 :             :          be incomplete.  In that case, the function will of course be
    4233                 :             :          a member of C, and no conversion is required.  In fact,
    4234                 :             :          lookup_base will fail in that case, because incomplete
    4235                 :             :          classes do not have BINFOs.  */
    4236                 :       85635 :       if (!same_type_ignoring_top_level_qualifiers_p
    4237                 :       85635 :           (basetype, TREE_TYPE (TREE_TYPE (instance_ptr))))
    4238                 :             :         {
    4239                 :          72 :           basetype = lookup_base (TREE_TYPE (TREE_TYPE (instance_ptr)),
    4240                 :             :                                   basetype, ba_check, NULL, complain);
    4241                 :          72 :           instance_ptr = build_base_path (PLUS_EXPR, instance_ptr, basetype,
    4242                 :             :                                           1, complain);
    4243                 :          72 :           if (instance_ptr == error_mark_node)
    4244                 :             :             return error_mark_node;
    4245                 :             :         }
    4246                 :             :       /* ...and then the delta in the PMF.  */
    4247                 :       85635 :       instance_ptr = fold_build_pointer_plus (instance_ptr, delta);
    4248                 :             : 
    4249                 :             :       /* Hand back the adjusted 'this' argument to our caller.  */
    4250                 :       85635 :       *instance_ptrptr = instance_ptr;
    4251                 :             : 
    4252                 :       85635 :       if (nonvirtual)
    4253                 :             :         /* Now just return the pointer.  */
    4254                 :             :         return e3;
    4255                 :             : 
    4256                 :             :       /* Next extract the vtable pointer from the object.  */
    4257                 :       85328 :       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
    4258                 :             :                      instance_ptr);
    4259                 :       85328 :       vtbl = cp_build_fold_indirect_ref (vtbl);
    4260                 :       85328 :       if (vtbl == error_mark_node)
    4261                 :             :         return error_mark_node;
    4262                 :             : 
    4263                 :             :       /* Finally, extract the function pointer from the vtable.  */
    4264                 :       85328 :       e2 = fold_build_pointer_plus_loc (input_location, vtbl, idx);
    4265                 :       85328 :       e2 = cp_build_fold_indirect_ref (e2);
    4266                 :       85328 :       if (e2 == error_mark_node)
    4267                 :             :         return error_mark_node;
    4268                 :       85328 :       TREE_CONSTANT (e2) = 1;
    4269                 :             : 
    4270                 :             :       /* When using function descriptors, the address of the
    4271                 :             :          vtable entry is treated as a function pointer.  */
    4272                 :       85328 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
    4273                 :             :         e2 = build1 (NOP_EXPR, TREE_TYPE (e2),
    4274                 :             :                      cp_build_addr_expr (e2, complain));
    4275                 :             : 
    4276                 :       85328 :       e2 = fold_convert (TREE_TYPE (e3), e2);
    4277                 :       85328 :       e1 = build_conditional_expr (input_location, e1, e2, e3, complain);
    4278                 :       85328 :       if (e1 == error_mark_node)
    4279                 :             :         return error_mark_node;
    4280                 :             : 
    4281                 :             :       /* Make sure this doesn't get evaluated first inside one of the
    4282                 :             :          branches of the COND_EXPR.  */
    4283                 :       85328 :       if (instance_save_expr)
    4284                 :       56345 :         e1 = build2 (COMPOUND_EXPR, TREE_TYPE (e1),
    4285                 :             :                      instance_save_expr, e1);
    4286                 :             : 
    4287                 :             :       function = e1;
    4288                 :             :     }
    4289                 :             :   return function;
    4290                 :             : }
    4291                 :             : 
    4292                 :             : /* Used by the C-common bits.  */
    4293                 :             : tree
    4294                 :           0 : build_function_call (location_t /*loc*/, 
    4295                 :             :                      tree function, tree params)
    4296                 :             : {
    4297                 :           0 :   return cp_build_function_call (function, params, tf_warning_or_error);
    4298                 :             : }
    4299                 :             : 
    4300                 :             : /* Used by the C-common bits.  */
    4301                 :             : tree
    4302                 :      226829 : build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
    4303                 :             :                          tree function, vec<tree, va_gc> *params,
    4304                 :             :                          vec<tree, va_gc> * /*origtypes*/, tree orig_function)
    4305                 :             : {
    4306                 :      226829 :   vec<tree, va_gc> *orig_params = params;
    4307                 :      226829 :   tree ret = cp_build_function_call_vec (function, &params,
    4308                 :             :                                          tf_warning_or_error, orig_function);
    4309                 :             : 
    4310                 :             :   /* cp_build_function_call_vec can reallocate PARAMS by adding
    4311                 :             :      default arguments.  That should never happen here.  Verify
    4312                 :             :      that.  */
    4313                 :      226829 :   gcc_assert (params == orig_params);
    4314                 :             : 
    4315                 :      226829 :   return ret;
    4316                 :             : }
    4317                 :             : 
    4318                 :             : /* Build a function call using a tree list of arguments.  */
    4319                 :             : 
    4320                 :             : static tree
    4321                 :           0 : cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
    4322                 :             : {
    4323                 :           0 :   tree ret;
    4324                 :             : 
    4325                 :           0 :   releasing_vec vec;
    4326                 :           0 :   for (; params != NULL_TREE; params = TREE_CHAIN (params))
    4327                 :           0 :     vec_safe_push (vec, TREE_VALUE (params));
    4328                 :           0 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4329                 :           0 :   return ret;
    4330                 :           0 : }
    4331                 :             : 
    4332                 :             : /* Build a function call using varargs.  */
    4333                 :             : 
    4334                 :             : tree
    4335                 :      463376 : cp_build_function_call_nary (tree function, tsubst_flags_t complain, ...)
    4336                 :             : {
    4337                 :      463376 :   va_list args;
    4338                 :      463376 :   tree ret, t;
    4339                 :             : 
    4340                 :      463376 :   releasing_vec vec;
    4341                 :      463376 :   va_start (args, complain);
    4342                 :     1141729 :   for (t = va_arg (args, tree); t != NULL_TREE; t = va_arg (args, tree))
    4343                 :      678353 :     vec_safe_push (vec, t);
    4344                 :      463376 :   va_end (args);
    4345                 :      463376 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4346                 :      463376 :   return ret;
    4347                 :      463376 : }
    4348                 :             : 
    4349                 :             : /* Build a function call using a vector of arguments.
    4350                 :             :    If FUNCTION is the result of resolving an overloaded target built-in,
    4351                 :             :    ORIG_FNDECL is the original function decl, otherwise it is null.
    4352                 :             :    PARAMS may be NULL if there are no parameters.  This changes the
    4353                 :             :    contents of PARAMS.  */
    4354                 :             : 
    4355                 :             : tree
    4356                 :     3374747 : cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
    4357                 :             :                             tsubst_flags_t complain, tree orig_fndecl)
    4358                 :             : {
    4359                 :     3374747 :   tree fntype, fndecl;
    4360                 :     3374747 :   int is_method;
    4361                 :     3374747 :   tree original = function;
    4362                 :     3374747 :   int nargs;
    4363                 :     3374747 :   tree *argarray;
    4364                 :     3374747 :   tree parm_types;
    4365                 :     3374747 :   vec<tree, va_gc> *allocated = NULL;
    4366                 :     3374747 :   tree ret;
    4367                 :             : 
    4368                 :             :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4369                 :             :      expressions, like those used for ObjC messenger dispatches.  */
    4370                 :     3374747 :   if (params != NULL && !vec_safe_is_empty (*params))
    4371                 :     1603000 :     function = objc_rewrite_function_call (function, (**params)[0]);
    4372                 :             : 
    4373                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4374                 :             :      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
    4375                 :     3374747 :   if (TREE_CODE (function) == NOP_EXPR
    4376                 :     3374747 :       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
    4377                 :          12 :     function = TREE_OPERAND (function, 0);
    4378                 :             : 
    4379                 :     3374747 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4380                 :             :     {
    4381                 :     1238400 :       if (!mark_used (function, complain))
    4382                 :          17 :         return error_mark_node;
    4383                 :     1238383 :       fndecl = function;
    4384                 :             : 
    4385                 :             :       /* Convert anything with function type to a pointer-to-function.  */
    4386                 :     1238383 :       if (DECL_MAIN_P (function))
    4387                 :             :         {
    4388                 :           0 :           if (complain & tf_error)
    4389                 :           0 :             pedwarn (input_location, OPT_Wpedantic, 
    4390                 :             :                      "ISO C++ forbids calling %<::main%> from within program");
    4391                 :             :           else
    4392                 :           0 :             return error_mark_node;
    4393                 :             :         }
    4394                 :     1238383 :       function = build_addr_func (function, complain);
    4395                 :             :     }
    4396                 :             :   else
    4397                 :             :     {
    4398                 :     2136347 :       fndecl = NULL_TREE;
    4399                 :             : 
    4400                 :     2136347 :       function = build_addr_func (function, complain);
    4401                 :             :     }
    4402                 :             : 
    4403                 :     3374730 :   if (function == error_mark_node)
    4404                 :             :     return error_mark_node;
    4405                 :             : 
    4406                 :     3374599 :   fntype = TREE_TYPE (function);
    4407                 :             : 
    4408                 :     3374599 :   if (TYPE_PTRMEMFUNC_P (fntype))
    4409                 :             :     {
    4410                 :          20 :       if (complain & tf_error)
    4411                 :          20 :         error ("must use %<.*%> or %<->*%> to call pointer-to-member "
    4412                 :             :                "function in %<%E (...)%>, e.g. %<(... ->* %E) (...)%>",
    4413                 :             :                original, original);
    4414                 :          20 :       return error_mark_node;
    4415                 :             :     }
    4416                 :             : 
    4417                 :     6749158 :   is_method = (TYPE_PTR_P (fntype)
    4418                 :     3374579 :                && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
    4419                 :             : 
    4420                 :     3374579 :   if (!(TYPE_PTRFN_P (fntype)
    4421                 :       86823 :         || is_method
    4422                 :        1270 :         || TREE_CODE (function) == TEMPLATE_ID_EXPR))
    4423                 :             :     {
    4424                 :        1270 :       if (complain & tf_error)
    4425                 :             :         {
    4426                 :         191 :           if (!flag_diagnostics_show_caret)
    4427                 :         191 :             error_at (input_location,
    4428                 :             :                       "%qE cannot be used as a function", original);
    4429                 :           0 :           else if (DECL_P (original))
    4430                 :           0 :             error_at (input_location,
    4431                 :             :                       "%qD cannot be used as a function", original);
    4432                 :             :           else 
    4433                 :           0 :             error_at (input_location,
    4434                 :             :                       "expression cannot be used as a function");
    4435                 :             :         }
    4436                 :             : 
    4437                 :        1270 :       return error_mark_node;
    4438                 :             :     }
    4439                 :             : 
    4440                 :             :   /* fntype now gets the type of function pointed to.  */
    4441                 :     3373309 :   fntype = TREE_TYPE (fntype);
    4442                 :     3373309 :   parm_types = TYPE_ARG_TYPES (fntype);
    4443                 :             : 
    4444                 :     3373309 :   if (params == NULL)
    4445                 :             :     {
    4446                 :      148972 :       allocated = make_tree_vector ();
    4447                 :      148972 :       params = &allocated;
    4448                 :             :     }
    4449                 :             : 
    4450                 :     3373309 :     nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
    4451                 :             :                                complain);
    4452                 :     3373309 :   if (nargs < 0)
    4453                 :        1106 :     return error_mark_node;
    4454                 :             : 
    4455                 :     3372203 :   argarray = (*params)->address ();
    4456                 :             : 
    4457                 :             :   /* Check for errors in format strings and inappropriately
    4458                 :             :      null parameters.  */
    4459                 :     3372203 :   bool warned_p = check_function_arguments (input_location, fndecl, fntype,
    4460                 :             :                                             nargs, argarray, NULL);
    4461                 :             : 
    4462                 :     3372203 :   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
    4463                 :             : 
    4464                 :     3372203 :   if (warned_p)
    4465                 :             :     {
    4466                 :          33 :       tree c = extract_call_expr (ret);
    4467                 :          33 :       if (TREE_CODE (c) == CALL_EXPR)
    4468                 :          33 :         suppress_warning (c, OPT_Wnonnull);
    4469                 :             :     }
    4470                 :             : 
    4471                 :     3372203 :   if (allocated != NULL)
    4472                 :      148972 :     release_tree_vector (allocated);
    4473                 :             : 
    4474                 :             :   return ret;
    4475                 :             : }
    4476                 :             : 
    4477                 :             : /* Subroutine of convert_arguments.
    4478                 :             :    Print an error message about a wrong number of arguments.  */
    4479                 :             : 
    4480                 :             : static void
    4481                 :         185 : error_args_num (location_t loc, tree fndecl, bool too_many_p)
    4482                 :             : {
    4483                 :         185 :   if (fndecl)
    4484                 :             :     {
    4485                 :         141 :       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
    4486                 :             :         {
    4487                 :           0 :           if (DECL_NAME (fndecl) == NULL_TREE
    4488                 :           0 :               || (DECL_NAME (fndecl)
    4489                 :           0 :                   == DECL_NAME (TYPE_NAME (DECL_CONTEXT (fndecl)))))
    4490                 :           0 :             error_at (loc,
    4491                 :             :                       too_many_p
    4492                 :             :                       ? G_("too many arguments to constructor %q#D")
    4493                 :             :                       : G_("too few arguments to constructor %q#D"),
    4494                 :             :                       fndecl);
    4495                 :             :           else
    4496                 :           0 :             error_at (loc,
    4497                 :             :                       too_many_p
    4498                 :             :                       ? G_("too many arguments to member function %q#D")
    4499                 :             :                       : G_("too few arguments to member function %q#D"),
    4500                 :             :                       fndecl);
    4501                 :             :         }
    4502                 :             :       else
    4503                 :         213 :         error_at (loc,
    4504                 :             :                   too_many_p
    4505                 :             :                   ? G_("too many arguments to function %q#D")
    4506                 :             :                   : G_("too few arguments to function %q#D"),
    4507                 :             :                   fndecl);
    4508                 :         141 :       if (!DECL_IS_UNDECLARED_BUILTIN (fndecl))
    4509                 :          89 :         inform (DECL_SOURCE_LOCATION (fndecl), "declared here");
    4510                 :             :     }
    4511                 :             :   else
    4512                 :             :     {
    4513                 :          44 :       if (c_dialect_objc ()  &&  objc_message_selector ())
    4514                 :           0 :         error_at (loc,
    4515                 :             :                   too_many_p 
    4516                 :             :                   ? G_("too many arguments to method %q#D")
    4517                 :             :                   : G_("too few arguments to method %q#D"),
    4518                 :             :                   objc_message_selector ());
    4519                 :             :       else
    4520                 :          72 :         error_at (loc, too_many_p ? G_("too many arguments to function")
    4521                 :             :                                   : G_("too few arguments to function"));
    4522                 :             :     }
    4523                 :         185 : }
    4524                 :             : 
    4525                 :             : /* Convert the actual parameter expressions in the list VALUES to the
    4526                 :             :    types in the list TYPELIST.  The converted expressions are stored
    4527                 :             :    back in the VALUES vector.
    4528                 :             :    If parmdecls is exhausted, or when an element has NULL as its type,
    4529                 :             :    perform the default conversions.
    4530                 :             : 
    4531                 :             :    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
    4532                 :             : 
    4533                 :             :    This is also where warnings about wrong number of args are generated.
    4534                 :             : 
    4535                 :             :    Returns the actual number of arguments processed (which might be less
    4536                 :             :    than the length of the vector), or -1 on error.
    4537                 :             : 
    4538                 :             :    In C++, unspecified trailing parameters can be filled in with their
    4539                 :             :    default arguments, if such were specified.  Do so here.  */
    4540                 :             : 
    4541                 :             : static int
    4542                 :     3373309 : convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
    4543                 :             :                    int flags, tsubst_flags_t complain)
    4544                 :             : {
    4545                 :     3373309 :   tree typetail;
    4546                 :     3373309 :   unsigned int i;
    4547                 :             : 
    4548                 :             :   /* Argument passing is always copy-initialization.  */
    4549                 :     3373309 :   flags |= LOOKUP_ONLYCONVERTING;
    4550                 :             : 
    4551                 :     6996124 :   for (i = 0, typetail = typelist;
    4552                 :    13992248 :        i < vec_safe_length (*values);
    4553                 :             :        i++)
    4554                 :             :     {
    4555                 :     7247286 :       tree type = typetail ? TREE_VALUE (typetail) : 0;
    4556                 :     3623865 :       tree val = (**values)[i];
    4557                 :             : 
    4558                 :     3623865 :       if (val == error_mark_node || type == error_mark_node)
    4559                 :             :         return -1;
    4560                 :             : 
    4561                 :     3623857 :       if (type == void_type_node)
    4562                 :             :         {
    4563                 :         150 :           if (complain & tf_error)
    4564                 :             :             {
    4565                 :          85 :               error_args_num (input_location, fndecl, /*too_many_p=*/true);
    4566                 :          85 :               return i;
    4567                 :             :             }
    4568                 :             :           else
    4569                 :             :             return -1;
    4570                 :             :         }
    4571                 :             : 
    4572                 :             :       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4573                 :             :          Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
    4574                 :     3623707 :       if (TREE_CODE (val) == NOP_EXPR
    4575                 :      837717 :           && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
    4576                 :     3623727 :           && (type == 0 || !TYPE_REF_P (type)))
    4577                 :          20 :         val = TREE_OPERAND (val, 0);
    4578                 :             : 
    4579                 :     3623707 :       if (type == 0 || !TYPE_REF_P (type))
    4580                 :             :         {
    4581                 :     3414308 :           if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
    4582                 :     3414308 :               || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (val)))
    4583                 :       11276 :             val = decay_conversion (val, complain);
    4584                 :             :         }
    4585                 :             : 
    4586                 :     3623707 :       if (val == error_mark_node)
    4587                 :             :         return -1;
    4588                 :             : 
    4589                 :     3623707 :       if (type != 0)
    4590                 :             :         {
    4591                 :             :           /* Formal parm type is specified by a function prototype.  */
    4592                 :     3623263 :           tree parmval;
    4593                 :             : 
    4594                 :     3623263 :           if (!COMPLETE_TYPE_P (complete_type (type)))
    4595                 :             :             {
    4596                 :          17 :               if (complain & tf_error)
    4597                 :             :                 {
    4598                 :          11 :                   location_t loc = EXPR_LOC_OR_LOC (val, input_location);
    4599                 :          11 :                   if (fndecl)
    4600                 :             :                     {
    4601                 :          11 :                       auto_diagnostic_group d;
    4602                 :          11 :                       error_at (loc,
    4603                 :             :                                 "parameter %P of %qD has incomplete type %qT",
    4604                 :             :                                 i, fndecl, type);
    4605                 :          11 :                       inform (get_fndecl_argument_location (fndecl, i),
    4606                 :             :                               "  declared here");
    4607                 :          11 :                     }
    4608                 :             :                   else
    4609                 :           0 :                     error_at (loc, "parameter %P has incomplete type %qT", i,
    4610                 :             :                               type);
    4611                 :             :                 }
    4612                 :          17 :               parmval = error_mark_node;
    4613                 :             :             }
    4614                 :             :           else
    4615                 :             :             {
    4616                 :     3623246 :               parmval = convert_for_initialization
    4617                 :     3623246 :                 (NULL_TREE, type, val, flags,
    4618                 :             :                  ICR_ARGPASS, fndecl, i, complain);
    4619                 :     3623246 :               parmval = convert_for_arg_passing (type, parmval, complain);
    4620                 :             :             }
    4621                 :             : 
    4622                 :     3623263 :           if (parmval == error_mark_node)
    4623                 :             :             return -1;
    4624                 :             : 
    4625                 :     3622371 :           (**values)[i] = parmval;
    4626                 :             :         }
    4627                 :             :       else
    4628                 :             :         {
    4629                 :         444 :           int magic = fndecl ? magic_varargs_p (fndecl) : 0;
    4630                 :           4 :           if (magic)
    4631                 :             :             {
    4632                 :             :               /* Don't truncate excess precision to the semantic type.  */
    4633                 :           0 :               if (magic == 1 && TREE_CODE (val) == EXCESS_PRECISION_EXPR)
    4634                 :           0 :                 val = TREE_OPERAND (val, 0);
    4635                 :             :               /* Don't do ellipsis conversion for __built_in_constant_p
    4636                 :             :                  as this will result in spurious errors for non-trivial
    4637                 :             :                  types.  */
    4638                 :           0 :               val = require_complete_type (val, complain);
    4639                 :             :             }
    4640                 :             :           else
    4641                 :         444 :             val = convert_arg_to_ellipsis (val, complain);
    4642                 :             : 
    4643                 :         444 :           (**values)[i] = val;
    4644                 :             :         }
    4645                 :             : 
    4646                 :     3622815 :       if (typetail)
    4647                 :     3622371 :         typetail = TREE_CHAIN (typetail);
    4648                 :             :     }
    4649                 :             : 
    4650                 :     3372259 :   if (typetail != 0 && typetail != void_list_node)
    4651                 :             :     {
    4652                 :             :       /* See if there are default arguments that can be used.  Because
    4653                 :             :          we hold default arguments in the FUNCTION_TYPE (which is so
    4654                 :             :          wrong), we can see default parameters here from deduced
    4655                 :             :          contexts (and via typeof) for indirect function calls.
    4656                 :             :          Fortunately we know whether we have a function decl to
    4657                 :             :          provide default arguments in a language conformant
    4658                 :             :          manner.  */
    4659                 :          72 :       if (fndecl && TREE_PURPOSE (typetail)
    4660                 :         144 :           && TREE_CODE (TREE_PURPOSE (typetail)) != DEFERRED_PARSE)
    4661                 :             :         {
    4662                 :           6 :           for (; typetail != void_list_node; ++i)
    4663                 :             :             {
    4664                 :             :               /* After DR777, with explicit template args we can end up with a
    4665                 :             :                  default argument followed by no default argument.  */
    4666                 :           6 :               if (!TREE_PURPOSE (typetail))
    4667                 :             :                 break;
    4668                 :           3 :               tree parmval
    4669                 :           3 :                 = convert_default_arg (TREE_VALUE (typetail),
    4670                 :           3 :                                        TREE_PURPOSE (typetail),
    4671                 :           3 :                                        fndecl, i, complain);
    4672                 :             : 
    4673                 :           3 :               if (parmval == error_mark_node)
    4674                 :           0 :                 return -1;
    4675                 :             : 
    4676                 :           3 :               vec_safe_push (*values, parmval);
    4677                 :           3 :               typetail = TREE_CHAIN (typetail);
    4678                 :             :               /* ends with `...'.  */
    4679                 :           3 :               if (typetail == NULL_TREE)
    4680                 :             :                 break;
    4681                 :             :             }
    4682                 :             :         }
    4683                 :             : 
    4684                 :         141 :       if (typetail && typetail != void_list_node)
    4685                 :             :         {
    4686                 :         141 :           if (complain & tf_error)
    4687                 :         100 :             error_args_num (input_location, fndecl, /*too_many_p=*/false);
    4688                 :         141 :           return -1;
    4689                 :             :         }
    4690                 :             :     }
    4691                 :             : 
    4692                 :     3372118 :   return (int) i;
    4693                 :             : }
    4694                 :             : 
    4695                 :             : /* Build a binary-operation expression, after performing default
    4696                 :             :    conversions on the operands.  CODE is the kind of expression to
    4697                 :             :    build.  ARG1 and ARG2 are the arguments.  ARG1_CODE and ARG2_CODE
    4698                 :             :    are the tree codes which correspond to ARG1 and ARG2 when issuing
    4699                 :             :    warnings about possibly misplaced parentheses.  They may differ
    4700                 :             :    from the TREE_CODE of ARG1 and ARG2 if the parser has done constant
    4701                 :             :    folding (e.g., if the parser sees "a | 1 + 1", it may call this
    4702                 :             :    routine with ARG2 being an INTEGER_CST and ARG2_CODE == PLUS_EXPR).
    4703                 :             :    To avoid issuing any parentheses warnings, pass ARG1_CODE and/or
    4704                 :             :    ARG2_CODE as ERROR_MARK.  */
    4705                 :             : 
    4706                 :             : tree
    4707                 :   179439130 : build_x_binary_op (const op_location_t &loc, enum tree_code code, tree arg1,
    4708                 :             :                    enum tree_code arg1_code, tree arg2,
    4709                 :             :                    enum tree_code arg2_code, tree lookups,
    4710                 :             :                    tree *overload_p, tsubst_flags_t complain)
    4711                 :             : {
    4712                 :   179439130 :   tree orig_arg1;
    4713                 :   179439130 :   tree orig_arg2;
    4714                 :   179439130 :   tree expr;
    4715                 :   179439130 :   tree overload = NULL_TREE;
    4716                 :             : 
    4717                 :   179439130 :   orig_arg1 = arg1;
    4718                 :   179439130 :   orig_arg2 = arg2;
    4719                 :             : 
    4720                 :   179439130 :   if (processing_template_decl)
    4721                 :             :     {
    4722                 :   106161401 :       if (type_dependent_expression_p (arg1)
    4723                 :   106161401 :           || type_dependent_expression_p (arg2))
    4724                 :             :         {
    4725                 :    78065099 :           expr = build_min_nt_loc (loc, code, arg1, arg2);
    4726                 :    78065099 :           TREE_TYPE (expr)
    4727                 :    78065099 :             = build_dependent_operator_type (lookups, code, false);
    4728                 :    78065099 :           return expr;
    4729                 :             :         }
    4730                 :             :     }
    4731                 :             : 
    4732                 :   101374031 :   if (code == DOTSTAR_EXPR)
    4733                 :      105023 :     expr = build_m_component_ref (arg1, arg2, complain);
    4734                 :             :   else
    4735                 :   101269008 :     expr = build_new_op (loc, code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
    4736                 :             :                          lookups, &overload, complain);
    4737                 :             : 
    4738                 :   101373998 :   if (overload_p != NULL)
    4739                 :    41479115 :     *overload_p = overload;
    4740                 :             : 
    4741                 :             :   /* Check for cases such as x+y<<z which users are likely to
    4742                 :             :      misinterpret.  But don't warn about obj << x + y, since that is a
    4743                 :             :      common idiom for I/O.  */
    4744                 :   101373998 :   if (warn_parentheses
    4745                 :     1012218 :       && (complain & tf_warning)
    4746                 :      980849 :       && !processing_template_decl
    4747                 :      678081 :       && !error_operand_p (arg1)
    4748                 :      678073 :       && !error_operand_p (arg2)
    4749                 :   102052055 :       && (code != LSHIFT_EXPR
    4750                 :       67293 :           || !CLASS_TYPE_P (TREE_TYPE (arg1))))
    4751                 :      677104 :     warn_about_parentheses (loc, code, arg1_code, orig_arg1,
    4752                 :             :                             arg2_code, orig_arg2);
    4753                 :             : 
    4754                 :   101373998 :   if (processing_template_decl && expr != error_mark_node)
    4755                 :             :     {
    4756                 :    28096081 :       if (overload != NULL_TREE)
    4757                 :     1919377 :         return (build_min_non_dep_op_overload
    4758                 :     1919377 :                 (code, expr, overload, orig_arg1, orig_arg2));
    4759                 :             : 
    4760                 :    26176704 :       return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
    4761                 :             :     }
    4762                 :             : 
    4763                 :             :   return expr;
    4764                 :             : }
    4765                 :             : 
    4766                 :             : /* Build and return an ARRAY_REF expression.  */
    4767                 :             : 
    4768                 :             : tree
    4769                 :     1669818 : build_x_array_ref (location_t loc, tree arg1, tree arg2,
    4770                 :             :                    tsubst_flags_t complain)
    4771                 :             : {
    4772                 :     1669818 :   tree orig_arg1 = arg1;
    4773                 :     1669818 :   tree orig_arg2 = arg2;
    4774                 :     1669818 :   tree expr;
    4775                 :     1669818 :   tree overload = NULL_TREE;
    4776                 :             : 
    4777                 :     1669818 :   if (processing_template_decl)
    4778                 :             :     {
    4779                 :         592 :       if (type_dependent_expression_p (arg1)
    4780                 :         592 :           || type_dependent_expression_p (arg2))
    4781                 :         590 :         return build_min_nt_loc (loc, ARRAY_REF, arg1, arg2,
    4782                 :         590 :                                  NULL_TREE, NULL_TREE);
    4783                 :             :     }
    4784                 :             : 
    4785                 :     1669228 :   expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, arg1, arg2,
    4786                 :             :                        NULL_TREE, NULL_TREE, &overload, complain);
    4787                 :             : 
    4788                 :     1669228 :   if (processing_template_decl && expr != error_mark_node)
    4789                 :             :     {
    4790                 :           2 :       if (overload != NULL_TREE)
    4791                 :           0 :         return (build_min_non_dep_op_overload
    4792                 :           0 :                 (ARRAY_REF, expr, overload, orig_arg1, orig_arg2));
    4793                 :             : 
    4794                 :           2 :       return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
    4795                 :           2 :                                 NULL_TREE, NULL_TREE);
    4796                 :             :     }
    4797                 :             :   return expr;
    4798                 :             : }
    4799                 :             : 
    4800                 :             : /* Build an OpenMP array section reference, creating an exact type for the
    4801                 :             :    resulting expression based on the element type and bounds if possible.  If
    4802                 :             :    we have variable bounds, create an incomplete array type for the result
    4803                 :             :    instead.  */
    4804                 :             : 
    4805                 :             : tree
    4806                 :       12540 : build_omp_array_section (location_t loc, tree array_expr, tree index,
    4807                 :             :                          tree length)
    4808                 :             : {
    4809                 :       12540 :   tree type = TREE_TYPE (array_expr);
    4810                 :       12540 :   gcc_assert (type);
    4811                 :       12540 :   type = non_reference (type);
    4812                 :             : 
    4813                 :       12540 :   tree sectype, eltype = TREE_TYPE (type);
    4814                 :             : 
    4815                 :             :   /* It's not an array or pointer type.  Just reuse the type of the
    4816                 :             :      original expression as the type of the array section (an error will be
    4817                 :             :      raised anyway, later).  */
    4818                 :       12540 :   if (eltype == NULL_TREE)
    4819                 :          68 :     sectype = TREE_TYPE (array_expr);
    4820                 :             :   else
    4821                 :             :     {
    4822                 :       12472 :       tree idxtype = NULL_TREE;
    4823                 :             : 
    4824                 :             :       /* If we know the integer bounds, create an index type with exact
    4825                 :             :          low/high (or zero/length) bounds.  Otherwise, create an incomplete
    4826                 :             :          array type.  (This mostly only affects diagnostics.)  */
    4827                 :       12472 :       if (index != NULL_TREE
    4828                 :       12472 :           && length != NULL_TREE
    4829                 :        8881 :           && TREE_CODE (index) == INTEGER_CST
    4830                 :        7889 :           && TREE_CODE (length) == INTEGER_CST)
    4831                 :             :         {
    4832                 :        6252 :           tree low = fold_convert (sizetype, index);
    4833                 :        6252 :           tree high = fold_convert (sizetype, length);
    4834                 :        6252 :           high = size_binop (PLUS_EXPR, low, high);
    4835                 :        6252 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    4836                 :        6252 :           idxtype = build_range_type (sizetype, low, high);
    4837                 :        6252 :         }
    4838                 :        3509 :       else if ((index == NULL_TREE || integer_zerop (index))
    4839                 :        4132 :                && length != NULL_TREE
    4840                 :        8510 :                && TREE_CODE (length) == INTEGER_CST)
    4841                 :        1696 :         idxtype = build_index_type (length);
    4842                 :             : 
    4843                 :       12472 :       sectype = build_array_type (eltype, idxtype);
    4844                 :             :     }
    4845                 :             : 
    4846                 :       12540 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array_expr, index,
    4847                 :       12540 :                      length);
    4848                 :             : }
    4849                 :             : 
    4850                 :             : /* Return whether OP is an expression of enum type cast to integer
    4851                 :             :    type.  In C++ even unsigned enum types are cast to signed integer
    4852                 :             :    types.  We do not want to issue warnings about comparisons between
    4853                 :             :    signed and unsigned types when one of the types is an enum type.
    4854                 :             :    Those warnings are always false positives in practice.  */
    4855                 :             : 
    4856                 :             : static bool
    4857                 :      567664 : enum_cast_to_int (tree op)
    4858                 :             : {
    4859                 :      556823 :   if (CONVERT_EXPR_P (op)
    4860                 :       11892 :       && TREE_TYPE (op) == integer_type_node
    4861                 :         719 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == ENUMERAL_TYPE
    4862                 :      567704 :       && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 0))))
    4863                 :             :     return true;
    4864                 :             : 
    4865                 :             :   /* The cast may have been pushed into a COND_EXPR.  */
    4866                 :      567632 :   if (TREE_CODE (op) == COND_EXPR)
    4867                 :         751 :     return (enum_cast_to_int (TREE_OPERAND (op, 1))
    4868                 :         751 :             || enum_cast_to_int (TREE_OPERAND (op, 2)));
    4869                 :             : 
    4870                 :             :   return false;
    4871                 :             : }
    4872                 :             : 
    4873                 :             : /* For the c-common bits.  */
    4874                 :             : tree
    4875                 :     5076939 : build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
    4876                 :             :                  bool /*convert_p*/)
    4877                 :             : {
    4878                 :     5076939 :   return cp_build_binary_op (location, code, op0, op1, tf_warning_or_error);
    4879                 :             : }
    4880                 :             : 
    4881                 :             : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
    4882                 :             :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
    4883                 :             : 
    4884                 :             : static tree
    4885                 :        6949 : build_vec_cmp (tree_code code, tree type,
    4886                 :             :                tree arg0, tree arg1)
    4887                 :             : {
    4888                 :        6949 :   tree zero_vec = build_zero_cst (type);
    4889                 :        6949 :   tree minus_one_vec = build_minus_one_cst (type);
    4890                 :        6949 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
    4891                 :        6949 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
    4892                 :        6949 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
    4893                 :             : }
    4894                 :             : 
    4895                 :             : /* Possibly warn about an address never being NULL.  */
    4896                 :             : 
    4897                 :             : static void
    4898                 :     1515754 : warn_for_null_address (location_t location, tree op, tsubst_flags_t complain)
    4899                 :             : {
    4900                 :             :   /* Prevent warnings issued for macro expansion.  */
    4901                 :     1515754 :   if (!warn_address
    4902                 :       39687 :       || (complain & tf_warning) == 0
    4903                 :       23687 :       || c_inhibit_evaluation_warnings != 0
    4904                 :       23647 :       || from_macro_expansion_at (location)
    4905                 :     1532965 :       || warning_suppressed_p (op, OPT_Waddress))
    4906                 :     1498586 :     return;
    4907                 :             : 
    4908                 :       17168 :   tree cop = fold_for_warn (op);
    4909                 :             : 
    4910                 :       17168 :   if (TREE_CODE (cop) == NON_LVALUE_EXPR)
    4911                 :             :     /* Unwrap the expression for C++ 98.  */
    4912                 :           1 :     cop = TREE_OPERAND (cop, 0);
    4913                 :             : 
    4914                 :       17168 :   if (TREE_CODE (cop) == PTRMEM_CST)
    4915                 :             :     {
    4916                 :             :       /* The address of a nonstatic data member is never null.  */
    4917                 :          40 :       warning_at (location, OPT_Waddress,
    4918                 :             :                   "the address %qE will never be NULL",
    4919                 :             :                   cop);
    4920                 :          40 :       return;
    4921                 :             :     }
    4922                 :             : 
    4923                 :       17128 :   if (TREE_CODE (cop) == NOP_EXPR)
    4924                 :             :     {
    4925                 :             :       /* Allow casts to intptr_t to suppress the warning.  */
    4926                 :        1168 :       tree type = TREE_TYPE (cop);
    4927                 :        1168 :       if (TREE_CODE (type) == INTEGER_TYPE)
    4928                 :             :         return;
    4929                 :             : 
    4930                 :        1168 :       STRIP_NOPS (cop);
    4931                 :             :     }
    4932                 :             : 
    4933                 :       17128 :   bool warned = false;
    4934                 :       17128 :   if (TREE_CODE (cop) == ADDR_EXPR)
    4935                 :             :     {
    4936                 :        1049 :       cop = TREE_OPERAND (cop, 0);
    4937                 :             : 
    4938                 :             :       /* Set to true in the loop below if OP dereferences its operand.
    4939                 :             :          In such a case the ultimate target need not be a decl for
    4940                 :             :          the null [in]equality test to be necessarily constant.  */
    4941                 :        1049 :       bool deref = false;
    4942                 :             : 
    4943                 :             :       /* Get the outermost array or object, or member.  */
    4944                 :        1277 :       while (handled_component_p (cop))
    4945                 :             :         {
    4946                 :         360 :           if (TREE_CODE (cop) == COMPONENT_REF)
    4947                 :             :             {
    4948                 :             :               /* Get the member (its address is never null).  */
    4949                 :         132 :               cop = TREE_OPERAND (cop, 1);
    4950                 :         132 :               break;
    4951                 :             :             }
    4952                 :             : 
    4953                 :             :           /* Get the outer array/object to refer to in the warning.  */
    4954                 :         228 :           cop = TREE_OPERAND (cop, 0);
    4955                 :         228 :           deref = true;
    4956                 :             :         }
    4957                 :             : 
    4958                 :         849 :       if ((!deref && !decl_with_nonnull_addr_p (cop))
    4959                 :         839 :           || from_macro_expansion_at (location)
    4960                 :        1888 :           || warning_suppressed_p (cop, OPT_Waddress))
    4961                 :         210 :         return;
    4962                 :             : 
    4963                 :         839 :       warned = warning_at (location, OPT_Waddress,
    4964                 :             :                            "the address of %qD will never be NULL", cop);
    4965                 :         839 :       op = cop;
    4966                 :             :     }
    4967                 :       16079 :   else if (TREE_CODE (cop) == POINTER_PLUS_EXPR)
    4968                 :             :     {
    4969                 :             :       /* Adding zero to the null pointer is well-defined in C++.  When
    4970                 :             :          the offset is unknown (i.e., not a constant) warn anyway since
    4971                 :             :          it's less likely that the pointer operand is null than not.  */
    4972                 :         126 :       tree off = TREE_OPERAND (cop, 1);
    4973                 :         126 :       if (!integer_zerop (off)
    4974                 :         126 :           && !warning_suppressed_p (cop, OPT_Waddress))
    4975                 :             :         {
    4976                 :         126 :           tree base = TREE_OPERAND (cop, 0);
    4977                 :         126 :           STRIP_NOPS (base);
    4978                 :         126 :           if (TYPE_REF_P (TREE_TYPE (base)))
    4979                 :          12 :             warning_at (location, OPT_Waddress, "the compiler can assume that "
    4980                 :             :                         "the address of %qE will never be NULL", base);
    4981                 :             :           else
    4982                 :         114 :             warning_at (location, OPT_Waddress, "comparing the result of "
    4983                 :             :                         "pointer addition %qE and NULL", cop);
    4984                 :             :         }
    4985                 :         126 :       return;
    4986                 :             :     }
    4987                 :       15159 :   else if (CONVERT_EXPR_P (op)
    4988                 :       16035 :            && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0))))
    4989                 :             :     {
    4990                 :          82 :       STRIP_NOPS (op);
    4991                 :             : 
    4992                 :          82 :       if (TREE_CODE (op) == COMPONENT_REF)
    4993                 :          32 :         op = TREE_OPERAND (op, 1);
    4994                 :             : 
    4995                 :          82 :       if (DECL_P (op))
    4996                 :          82 :         warned = warning_at (location, OPT_Waddress,
    4997                 :             :                              "the compiler can assume that the address of "
    4998                 :             :                              "%qD will never be NULL", op);
    4999                 :             :     }
    5000                 :             : 
    5001                 :         921 :   if (warned && DECL_P (op))
    5002                 :         873 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
    5003                 :             : }
    5004                 :             : 
    5005                 :             : /* Warn about [expr.arith.conv]/2: If one operand is of enumeration type and
    5006                 :             :    the other operand is of a different enumeration type or a floating-point
    5007                 :             :    type, this behavior is deprecated ([depr.arith.conv.enum]).  CODE is the
    5008                 :             :    code of the binary operation, TYPE0 and TYPE1 are the types of the operands,
    5009                 :             :    and LOC is the location for the whole binary expression.
    5010                 :             :    For C++26 this is ill-formed rather than deprecated.
    5011                 :             :    Return true for SFINAE errors.
    5012                 :             :    TODO: Consider combining this with -Wenum-compare in build_new_op_1.  */
    5013                 :             : 
    5014                 :             : static bool
    5015                 :    89106053 : do_warn_enum_conversions (location_t loc, enum tree_code code, tree type0,
    5016                 :             :                           tree type1, tsubst_flags_t complain)
    5017                 :             : {
    5018                 :    89106053 :   if (TREE_CODE (type0) == ENUMERAL_TYPE
    5019                 :     2532717 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5020                 :    91108990 :       && TYPE_MAIN_VARIANT (type0) != TYPE_MAIN_VARIANT (type1))
    5021                 :             :     {
    5022                 :         207 :       if (cxx_dialect >= cxx26)
    5023                 :             :         {
    5024                 :           0 :           if ((complain & tf_warning_or_error) == 0)
    5025                 :             :             return true;
    5026                 :             :         }
    5027                 :         207 :       else if ((complain & tf_warning) == 0)
    5028                 :             :         return false;
    5029                 :             :       /* In C++20, -Wdeprecated-enum-enum-conversion is on by default.
    5030                 :             :          Otherwise, warn if -Wenum-conversion is on.  */
    5031                 :         204 :       enum opt_code opt;
    5032                 :         204 :       if (warn_deprecated_enum_enum_conv)
    5033                 :             :         opt = OPT_Wdeprecated_enum_enum_conversion;
    5034                 :         171 :       else if (warn_enum_conversion)
    5035                 :             :         opt = OPT_Wenum_conversion;
    5036                 :             :       else
    5037                 :             :         return false;
    5038                 :             : 
    5039                 :          99 :       switch (code)
    5040                 :             :         {
    5041                 :             :         case GT_EXPR:
    5042                 :             :         case LT_EXPR:
    5043                 :             :         case GE_EXPR:
    5044                 :             :         case LE_EXPR:
    5045                 :             :         case EQ_EXPR:
    5046                 :             :         case NE_EXPR:
    5047                 :             :           /* Comparisons are handled by -Wenum-compare.  */
    5048                 :             :           return false;
    5049                 :             :         case SPACESHIP_EXPR:
    5050                 :             :           /* This is invalid, don't warn.  */
    5051                 :             :           return false;
    5052                 :          16 :         case BIT_AND_EXPR:
    5053                 :          16 :         case BIT_IOR_EXPR:
    5054                 :          16 :         case BIT_XOR_EXPR:
    5055                 :          16 :           if (cxx_dialect >= cxx26)
    5056                 :           0 :             pedwarn (loc, opt, "bitwise operation between different "
    5057                 :             :                      "enumeration types %qT and %qT", type0, type1);
    5058                 :             :           else
    5059                 :          16 :             warning_at (loc, opt, "bitwise operation between different "
    5060                 :             :                         "enumeration types %qT and %qT is deprecated",
    5061                 :             :                         type0, type1);
    5062                 :          16 :           return false;
    5063                 :          38 :         default:
    5064                 :          38 :           if (cxx_dialect >= cxx26)
    5065                 :           0 :             pedwarn (loc, opt, "arithmetic between different enumeration "
    5066                 :             :                      "types %qT and %qT", type0, type1);
    5067                 :             :           else
    5068                 :          38 :             warning_at (loc, opt, "arithmetic between different enumeration "
    5069                 :             :                         "types %qT and %qT is deprecated", type0, type1);
    5070                 :          38 :           return false;
    5071                 :             :         }
    5072                 :             :     }
    5073                 :    89105846 :   else if ((TREE_CODE (type0) == ENUMERAL_TYPE
    5074                 :     2532510 :             && SCALAR_FLOAT_TYPE_P (type1))
    5075                 :    89105771 :            || (SCALAR_FLOAT_TYPE_P (type0)
    5076                 :    31177059 :                && TREE_CODE (type1) == ENUMERAL_TYPE))
    5077                 :             :     {
    5078                 :         151 :       if (cxx_dialect >= cxx26)
    5079                 :             :         {
    5080                 :           0 :           if ((complain & tf_warning_or_error) == 0)
    5081                 :             :             return true;
    5082                 :             :         }
    5083                 :         151 :       else if ((complain & tf_warning) == 0)
    5084                 :             :         return false;
    5085                 :         147 :       const bool enum_first_p = TREE_CODE (type0) == ENUMERAL_TYPE;
    5086                 :             :       /* In C++20, -Wdeprecated-enum-float-conversion is on by default.
    5087                 :             :          Otherwise, warn if -Wenum-conversion is on.  */
    5088                 :         147 :       enum opt_code opt;
    5089                 :         147 :       if (warn_deprecated_enum_float_conv)
    5090                 :             :         opt = OPT_Wdeprecated_enum_float_conversion;
    5091                 :         126 :       else if (warn_enum_conversion)
    5092                 :             :         opt = OPT_Wenum_conversion;
    5093                 :             :       else
    5094                 :             :         return false;
    5095                 :             : 
    5096                 :          72 :       switch (code)
    5097                 :             :         {
    5098                 :          32 :         case GT_EXPR:
    5099                 :          32 :         case LT_EXPR:
    5100                 :          32 :         case GE_EXPR:
    5101                 :          32 :         case LE_EXPR:
    5102                 :          32 :         case EQ_EXPR:
    5103                 :          32 :         case NE_EXPR:
    5104                 :          32 :           if (enum_first_p && cxx_dialect >= cxx26)
    5105                 :           0 :             pedwarn (loc, opt, "comparison of enumeration type %qT with "
    5106                 :             :                      "floating-point type %qT", type0, type1);
    5107                 :          32 :           else if (cxx_dialect >= cxx26)
    5108                 :           0 :             pedwarn (loc, opt, "comparison of floating-point type %qT "
    5109                 :             :                       "with enumeration type %qT", type0, type1);
    5110                 :          32 :           else if (enum_first_p)
    5111                 :          16 :             warning_at (loc, opt, "comparison of enumeration type %qT with "
    5112                 :             :                         "floating-point type %qT is deprecated",
    5113                 :             :                         type0, type1);
    5114                 :             :           else
    5115                 :          16 :             warning_at (loc, opt, "comparison of floating-point type %qT "
    5116                 :             :                         "with enumeration type %qT is deprecated",
    5117                 :             :                         type0, type1);
    5118                 :          32 :           return false;
    5119                 :             :         case SPACESHIP_EXPR:
    5120                 :             :           /* This is invalid, don't warn.  */
    5121                 :             :           return false;
    5122                 :          36 :         default:
    5123                 :          36 :           if (enum_first_p && cxx_dialect >= cxx26)
    5124                 :           0 :             pedwarn (loc, opt, "arithmetic between enumeration type %qT "
    5125                 :             :                      "and floating-point type %qT", type0, type1);
    5126                 :          36 :           else if (cxx_dialect >= cxx26)
    5127                 :           0 :             pedwarn (loc, opt, "arithmetic between floating-point type %qT "
    5128                 :             :                      "and enumeration type %qT", type0, type1);
    5129                 :          36 :           else if (enum_first_p)
    5130                 :          16 :             warning_at (loc, opt, "arithmetic between enumeration type %qT "
    5131                 :             :                         "and floating-point type %qT is deprecated",
    5132                 :             :                         type0, type1);
    5133                 :             :           else
    5134                 :          20 :             warning_at (loc, opt, "arithmetic between floating-point type %qT "
    5135                 :             :                         "and enumeration type %qT is deprecated",
    5136                 :             :                         type0, type1);
    5137                 :          36 :           return false;
    5138                 :             :         }
    5139                 :             :     }
    5140                 :             :   return false;
    5141                 :             : }
    5142                 :             : 
    5143                 :             : /* Build a binary-operation expression without default conversions.
    5144                 :             :    CODE is the kind of expression to build.
    5145                 :             :    LOCATION is the location_t of the operator in the source code.
    5146                 :             :    This function differs from `build' in several ways:
    5147                 :             :    the data type of the result is computed and recorded in it,
    5148                 :             :    warnings are generated if arg data types are invalid,
    5149                 :             :    special handling for addition and subtraction of pointers is known,
    5150                 :             :    and some optimization is done (operations on narrow ints
    5151                 :             :    are done in the narrower type when that gives the same result).
    5152                 :             :    Constant folding is also done before the result is returned.
    5153                 :             : 
    5154                 :             :    Note that the operands will never have enumeral types
    5155                 :             :    because either they have just had the default conversions performed
    5156                 :             :    or they have both just been converted to some other type in which
    5157                 :             :    the arithmetic is to be done.
    5158                 :             : 
    5159                 :             :    C++: must do special pointer arithmetic when implementing
    5160                 :             :    multiple inheritance, and deal with pointer to member functions.  */
    5161                 :             : 
    5162                 :             : tree
    5163                 :   112664107 : cp_build_binary_op (const op_location_t &location,
    5164                 :             :                     enum tree_code code, tree orig_op0, tree orig_op1,
    5165                 :             :                     tsubst_flags_t complain)
    5166                 :             : {
    5167                 :   112664107 :   tree op0, op1;
    5168                 :   112664107 :   enum tree_code code0, code1;
    5169                 :   112664107 :   tree type0, type1, orig_type0, orig_type1;
    5170                 :   112664107 :   const char *invalid_op_diag;
    5171                 :             : 
    5172                 :             :   /* Expression code to give to the expression when it is built.
    5173                 :             :      Normally this is CODE, which is what the caller asked for,
    5174                 :             :      but in some special cases we change it.  */
    5175                 :   112664107 :   enum tree_code resultcode = code;
    5176                 :             : 
    5177                 :             :   /* Data type in which the computation is to be performed.
    5178                 :             :      In the simplest cases this is the common type of the arguments.  */
    5179                 :   112664107 :   tree result_type = NULL_TREE;
    5180                 :             : 
    5181                 :             :   /* When the computation is in excess precision, the type of the
    5182                 :             :      final EXCESS_PRECISION_EXPR.  */
    5183                 :   112664107 :   tree semantic_result_type = NULL;
    5184                 :             : 
    5185                 :             :   /* Nonzero means operands have already been type-converted
    5186                 :             :      in whatever way is necessary.
    5187                 :             :      Zero means they need to be converted to RESULT_TYPE.  */
    5188                 :   112664107 :   int converted = 0;
    5189                 :             : 
    5190                 :             :   /* Nonzero means create the expression with this type, rather than
    5191                 :             :      RESULT_TYPE.  */
    5192                 :   112664107 :   tree build_type = 0;
    5193                 :             : 
    5194                 :             :   /* Nonzero means after finally constructing the expression
    5195                 :             :      convert it to this type.  */
    5196                 :   112664107 :   tree final_type = 0;
    5197                 :             : 
    5198                 :   112664107 :   tree result;
    5199                 :             : 
    5200                 :             :   /* Nonzero if this is an operation like MIN or MAX which can
    5201                 :             :      safely be computed in short if both args are promoted shorts.
    5202                 :             :      Also implies COMMON.
    5203                 :             :      -1 indicates a bitwise operation; this makes a difference
    5204                 :             :      in the exact conditions for when it is safe to do the operation
    5205                 :             :      in a narrower mode.  */
    5206                 :   112664107 :   int shorten = 0;
    5207                 :             : 
    5208                 :             :   /* Nonzero if this is a comparison operation;
    5209                 :             :      if both args are promoted shorts, compare the original shorts.
    5210                 :             :      Also implies COMMON.  */
    5211                 :   112664107 :   int short_compare = 0;
    5212                 :             : 
    5213                 :             :   /* Nonzero if this is a right-shift operation, which can be computed on the
    5214                 :             :      original short and then promoted if the operand is a promoted short.  */
    5215                 :   112664107 :   int short_shift = 0;
    5216                 :             : 
    5217                 :             :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
    5218                 :   112664107 :   int common = 0;
    5219                 :             : 
    5220                 :             :   /* True if both operands have arithmetic type.  */
    5221                 :   112664107 :   bool arithmetic_types_p;
    5222                 :             : 
    5223                 :             :   /* Remember whether we're doing / or %.  */
    5224                 :   112664107 :   bool doing_div_or_mod = false;
    5225                 :             : 
    5226                 :             :   /* Remember whether we're doing << or >>.  */
    5227                 :   112664107 :   bool doing_shift = false;
    5228                 :             : 
    5229                 :             :   /* Tree holding instrumentation expression.  */
    5230                 :   112664107 :   tree instrument_expr = NULL_TREE;
    5231                 :             : 
    5232                 :             :   /* True means this is an arithmetic operation that may need excess
    5233                 :             :      precision.  */
    5234                 :   112664107 :   bool may_need_excess_precision;
    5235                 :             : 
    5236                 :             :   /* Apply default conversions.  */
    5237                 :   112664107 :   op0 = resolve_nondeduced_context (orig_op0, complain);
    5238                 :   112664107 :   op1 = resolve_nondeduced_context (orig_op1, complain);
    5239                 :             : 
    5240                 :   112664107 :   if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
    5241                 :   105759263 :       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
    5242                 :   103354653 :       || code == TRUTH_XOR_EXPR)
    5243                 :             :     {
    5244                 :     9309454 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5245                 :     9309433 :         op0 = decay_conversion (op0, complain);
    5246                 :     9309454 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5247                 :     9309454 :         op1 = decay_conversion (op1, complain);
    5248                 :             :     }
    5249                 :             :   else
    5250                 :             :     {
    5251                 :   103354653 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5252                 :   103354634 :         op0 = cp_default_conversion (op0, complain);
    5253                 :   103354653 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5254                 :   103354649 :         op1 = cp_default_conversion (op1, complain);
    5255                 :             :     }
    5256                 :             : 
    5257                 :             :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    5258                 :   119723012 :   STRIP_TYPE_NOPS (op0);
    5259                 :   137979555 :   STRIP_TYPE_NOPS (op1);
    5260                 :             : 
    5261                 :             :   /* DTRT if one side is an overloaded function, but complain about it.  */
    5262                 :   112664107 :   if (type_unknown_p (op0))
    5263                 :             :     {
    5264                 :          12 :       tree t = instantiate_type (TREE_TYPE (op1), op0, tf_none);
    5265                 :          12 :       if (t != error_mark_node)
    5266                 :             :         {
    5267                 :           0 :           if (complain & tf_error)
    5268                 :           0 :             permerror (location,
    5269                 :             :                        "assuming cast to type %qT from overloaded function",
    5270                 :           0 :                        TREE_TYPE (t));
    5271                 :             :           op0 = t;
    5272                 :             :         }
    5273                 :             :     }
    5274                 :   112664107 :   if (type_unknown_p (op1))
    5275                 :             :     {
    5276                 :           4 :       tree t = instantiate_type (TREE_TYPE (op0), op1, tf_none);
    5277                 :           4 :       if (t != error_mark_node)
    5278                 :             :         {
    5279                 :           4 :           if (complain & tf_error)
    5280                 :           4 :             permerror (location,
    5281                 :             :                        "assuming cast to type %qT from overloaded function",
    5282                 :           4 :                        TREE_TYPE (t));
    5283                 :             :           op1 = t;
    5284                 :             :         }
    5285                 :             :     }
    5286                 :             : 
    5287                 :   112664107 :   orig_type0 = type0 = TREE_TYPE (op0);
    5288                 :   112664107 :   orig_type1 = type1 = TREE_TYPE (op1);
    5289                 :   112664107 :   tree non_ep_op0 = op0;
    5290                 :   112664107 :   tree non_ep_op1 = op1;
    5291                 :             : 
    5292                 :             :   /* The expression codes of the data types of the arguments tell us
    5293                 :             :      whether the arguments are integers, floating, pointers, etc.  */
    5294                 :   112664107 :   code0 = TREE_CODE (type0);
    5295                 :   112664107 :   code1 = TREE_CODE (type1);
    5296                 :             : 
    5297                 :             :   /* If an error was already reported for one of the arguments,
    5298                 :             :      avoid reporting another error.  */
    5299                 :   112664107 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
    5300                 :         123 :     return error_mark_node;
    5301                 :             : 
    5302                 :   225327968 :   if ((invalid_op_diag
    5303                 :   112663984 :        = targetm.invalid_binary_op (code, type0, type1)))
    5304                 :             :     {
    5305                 :           0 :       if (complain & tf_error)
    5306                 :             :         {
    5307                 :           0 :           if (code0 == REAL_TYPE
    5308                 :           0 :               && code1 == REAL_TYPE
    5309                 :           0 :               && (extended_float_type_p (type0)
    5310                 :           0 :                   || extended_float_type_p (type1))
    5311                 :           0 :               && cp_compare_floating_point_conversion_ranks (type0,
    5312                 :             :                                                              type1) == 3)
    5313                 :             :             {
    5314                 :           0 :               rich_location richloc (line_table, location);
    5315                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    5316                 :           0 :             }
    5317                 :             :           else
    5318                 :           0 :             error (invalid_op_diag);
    5319                 :             :         }
    5320                 :           0 :       return error_mark_node;
    5321                 :             :     }
    5322                 :             : 
    5323                 :   112663984 :   switch (code)
    5324                 :             :     {
    5325                 :             :     case PLUS_EXPR:
    5326                 :             :     case MINUS_EXPR:
    5327                 :             :     case MULT_EXPR:
    5328                 :             :     case TRUNC_DIV_EXPR:
    5329                 :             :     case CEIL_DIV_EXPR:
    5330                 :             :     case FLOOR_DIV_EXPR:
    5331                 :             :     case ROUND_DIV_EXPR:
    5332                 :             :     case EXACT_DIV_EXPR:
    5333                 :             :       may_need_excess_precision = true;
    5334                 :             :       break;
    5335                 :    38687424 :     case EQ_EXPR:
    5336                 :    38687424 :     case NE_EXPR:
    5337                 :    38687424 :     case LE_EXPR:
    5338                 :    38687424 :     case GE_EXPR:
    5339                 :    38687424 :     case LT_EXPR:
    5340                 :    38687424 :     case GT_EXPR:
    5341                 :    38687424 :     case SPACESHIP_EXPR:
    5342                 :             :       /* Excess precision for implicit conversions of integers to
    5343                 :             :          floating point.  */
    5344                 :     8193083 :       may_need_excess_precision = (ANY_INTEGRAL_TYPE_P (type0)
    5345                 :    46874213 :                                    || ANY_INTEGRAL_TYPE_P (type1));
    5346                 :             :       break;
    5347                 :             :     default:
    5348                 :   112663984 :       may_need_excess_precision = false;
    5349                 :             :       break;
    5350                 :             :     }
    5351                 :   112663984 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
    5352                 :             :     {
    5353                 :       16262 :       op0 = TREE_OPERAND (op0, 0);
    5354                 :       16262 :       type0 = TREE_TYPE (op0);
    5355                 :             :     }
    5356                 :   112647722 :   else if (may_need_excess_precision
    5357                 :    89021402 :            && (code0 == REAL_TYPE || code0 == COMPLEX_TYPE))
    5358                 :    27233144 :     if (tree eptype = excess_precision_type (type0))
    5359                 :             :       {
    5360                 :       43239 :         type0 = eptype;
    5361                 :       43239 :         op0 = convert (eptype, op0);
    5362                 :             :       }
    5363                 :   112663984 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    5364                 :             :     {
    5365                 :       20134 :       op1 = TREE_OPERAND (op1, 0);
    5366                 :       20134 :       type1 = TREE_TYPE (op1);
    5367                 :             :     }
    5368                 :   112643850 :   else if (may_need_excess_precision
    5369                 :    89019580 :            && (code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
    5370                 :    27172960 :     if (tree eptype = excess_precision_type (type1))
    5371                 :             :       {
    5372                 :       28735 :         type1 = eptype;
    5373                 :       28735 :         op1 = convert (eptype, op1);
    5374                 :             :       }
    5375                 :             : 
    5376                 :             :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    5377                 :   225327857 :   if ((null_node_p (orig_op0) || null_node_p (orig_op1))
    5378                 :             :       /* It's reasonable to use pointer values as operands of &&
    5379                 :             :          and ||, so NULL is no exception.  */
    5380                 :       12233 :       && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR 
    5381                 :       12213 :       && ( /* Both are NULL (or 0) and the operation was not a
    5382                 :             :               comparison or a pointer subtraction.  */
    5383                 :       12308 :           (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1) 
    5384                 :          36 :            && code != EQ_EXPR && code != NE_EXPR && code != MINUS_EXPR) 
    5385                 :             :           /* Or if one of OP0 or OP1 is neither a pointer nor NULL.  */
    5386                 :       12197 :           || (!null_ptr_cst_p (orig_op0)
    5387                 :       12118 :               && !TYPE_PTR_OR_PTRMEM_P (type0))
    5388                 :       12181 :           || (!null_ptr_cst_p (orig_op1) 
    5389                 :          59 :               && !TYPE_PTR_OR_PTRMEM_P (type1)))
    5390                 :   112664036 :       && (complain & tf_warning))
    5391                 :             :     {
    5392                 :          52 :       location_t loc =
    5393                 :          52 :         expansion_point_location_if_in_system_header (input_location);
    5394                 :             : 
    5395                 :          52 :       warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic");
    5396                 :             :     }
    5397                 :             : 
    5398                 :             :   /* In case when one of the operands of the binary operation is
    5399                 :             :      a vector and another is a scalar -- convert scalar to vector.  */
    5400                 :   112723682 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
    5401                 :   112722791 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
    5402                 :             :     {
    5403                 :         994 :       enum stv_conv convert_flag
    5404                 :         994 :         = scalar_to_vector (location, code, non_ep_op0, non_ep_op1,
    5405                 :             :                             complain & tf_error);
    5406                 :             : 
    5407                 :         994 :       switch (convert_flag)
    5408                 :             :         {
    5409                 :          27 :           case stv_error:
    5410                 :          27 :             return error_mark_node;
    5411                 :          63 :           case stv_firstarg:
    5412                 :          63 :             {
    5413                 :          63 :               op0 = convert (TREE_TYPE (type1), op0);
    5414                 :          63 :               op0 = save_expr (op0);
    5415                 :          63 :               op0 = build_vector_from_val (type1, op0);
    5416                 :          63 :               orig_type0 = type0 = TREE_TYPE (op0);
    5417                 :          63 :               code0 = TREE_CODE (type0);
    5418                 :          63 :               converted = 1;
    5419                 :          63 :               break;
    5420                 :             :             }
    5421                 :         800 :           case stv_secondarg:
    5422                 :         800 :             {
    5423                 :         800 :               op1 = convert (TREE_TYPE (type0), op1);
    5424                 :         800 :               op1 = save_expr (op1);
    5425                 :         800 :               op1 = build_vector_from_val (type0, op1);
    5426                 :         800 :               orig_type1 = type1 = TREE_TYPE (op1);
    5427                 :         800 :               code1 = TREE_CODE (type1);
    5428                 :         800 :               converted = 1;
    5429                 :         800 :               break;
    5430                 :             :             }
    5431                 :             :           default:
    5432                 :             :             break;
    5433                 :             :         }
    5434                 :             :     }
    5435                 :             : 
    5436                 :   112663957 :   switch (code)
    5437                 :             :     {
    5438                 :    13541112 :     case MINUS_EXPR:
    5439                 :             :       /* Subtraction of two similar pointers.
    5440                 :             :          We must subtract them as integers, then divide by object size.  */
    5441                 :    13541112 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
    5442                 :    14694693 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    5443                 :     1153581 :                                                         TREE_TYPE (type1)))
    5444                 :             :         {
    5445                 :     1153579 :           result = pointer_diff (location, op0, op1,
    5446                 :             :                                  common_pointer_type (type0, type1), complain,
    5447                 :             :                                  &instrument_expr);
    5448                 :     1153579 :           if (instrument_expr != NULL)
    5449                 :          84 :             result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    5450                 :             :                              instrument_expr, result);
    5451                 :             : 
    5452                 :     1153579 :           return result;
    5453                 :             :         }
    5454                 :             :       /* In all other cases except pointer - int, the usual arithmetic
    5455                 :             :          rules apply.  */
    5456                 :    12387533 :       else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE))
    5457                 :             :         {
    5458                 :             :           common = 1;
    5459                 :             :           break;
    5460                 :             :         }
    5461                 :             :       /* The pointer - int case is just like pointer + int; fall
    5462                 :             :          through.  */
    5463                 :    18087773 :       gcc_fallthrough ();
    5464                 :    18087773 :     case PLUS_EXPR:
    5465                 :    18087773 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    5466                 :     5728595 :           && (code0 == INTEGER_TYPE || code1 == INTEGER_TYPE))
    5467                 :             :         {
    5468                 :     5728584 :           tree ptr_operand;
    5469                 :     5728584 :           tree int_operand;
    5470                 :     5728584 :           ptr_operand = ((code0 == POINTER_TYPE) ? op0 : op1);
    5471                 :       17049 :           int_operand = ((code0 == INTEGER_TYPE) ? op0 : op1);
    5472                 :     5728584 :           if (processing_template_decl)
    5473                 :             :             {
    5474                 :     1964734 :               result_type = TREE_TYPE (ptr_operand);
    5475                 :     1964734 :               break;
    5476                 :             :             }
    5477                 :     3763850 :           return cp_pointer_int_sum (location, code,
    5478                 :             :                                      ptr_operand,
    5479                 :             :                                      int_operand,
    5480                 :     3763850 :                                      complain);
    5481                 :             :         }
    5482                 :             :       common = 1;
    5483                 :             :       break;
    5484                 :             : 
    5485                 :             :     case MULT_EXPR:
    5486                 :    17663029 :       common = 1;
    5487                 :             :       break;
    5488                 :             : 
    5489                 :     8989313 :     case TRUNC_DIV_EXPR:
    5490                 :     8989313 :     case CEIL_DIV_EXPR:
    5491                 :     8989313 :     case FLOOR_DIV_EXPR:
    5492                 :     8989313 :     case ROUND_DIV_EXPR:
    5493                 :     8989313 :     case EXACT_DIV_EXPR:
    5494                 :     8989313 :       if (TREE_CODE (op0) == SIZEOF_EXPR && TREE_CODE (op1) == SIZEOF_EXPR)
    5495                 :             :         {
    5496                 :       95057 :           tree type0 = TREE_OPERAND (op0, 0);
    5497                 :       95057 :           tree type1 = TREE_OPERAND (op1, 0);
    5498                 :       95057 :           tree first_arg = tree_strip_any_location_wrapper (type0);
    5499                 :       95057 :           if (!TYPE_P (type0))
    5500                 :       76740 :             type0 = TREE_TYPE (type0);
    5501                 :       95057 :           if (!TYPE_P (type1))
    5502                 :       42570 :             type1 = TREE_TYPE (type1);
    5503                 :       95057 :           if (type0
    5504                 :       94501 :               && INDIRECT_TYPE_P (type0)
    5505                 :       95153 :               && same_type_p (TREE_TYPE (type0), type1))
    5506                 :             :             {
    5507                 :          32 :               if (!(TREE_CODE (first_arg) == PARM_DECL
    5508                 :          28 :                     && DECL_ARRAY_PARAMETER_P (first_arg)
    5509                 :           4 :                     && warn_sizeof_array_argument)
    5510                 :          52 :                   && (complain & tf_warning))
    5511                 :             :                 {
    5512                 :          24 :                   auto_diagnostic_group d;
    5513                 :          24 :                   if (warning_at (location, OPT_Wsizeof_pointer_div,
    5514                 :             :                                   "division %<sizeof (%T) / sizeof (%T)%> does "
    5515                 :             :                                   "not compute the number of array elements",
    5516                 :             :                                   type0, type1))
    5517                 :          24 :                     if (DECL_P (first_arg))
    5518                 :          24 :                       inform (DECL_SOURCE_LOCATION (first_arg),
    5519                 :             :                               "first %<sizeof%> operand was declared here");
    5520                 :          24 :                 }
    5521                 :             :             }
    5522                 :       95029 :           else if (!dependent_type_p (type0)
    5523                 :       42016 :                    && !dependent_type_p (type1)
    5524                 :       41937 :                    && TREE_CODE (type0) == ARRAY_TYPE
    5525                 :       40415 :                    && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0)))
    5526                 :             :                    /* Set by finish_parenthesized_expr.  */
    5527                 :       39816 :                    && !warning_suppressed_p (op1, OPT_Wsizeof_array_div)
    5528                 :      134829 :                    && (complain & tf_warning))
    5529                 :       39780 :             maybe_warn_sizeof_array_div (location, first_arg, type0,
    5530                 :             :                                          op1, non_reference (type1));
    5531                 :             :         }
    5532                 :             : 
    5533                 :     8989313 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5534                 :             :            || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
    5535                 :     8989289 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5536                 :             :               || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
    5537                 :             :         {
    5538                 :     8989277 :           enum tree_code tcode0 = code0, tcode1 = code1;
    5539                 :     8989277 :           doing_div_or_mod = true;
    5540                 :     8989277 :           warn_for_div_by_zero (location, fold_for_warn (op1));
    5541                 :             : 
    5542                 :     8989277 :           if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
    5543                 :       58441 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
    5544                 :     8989277 :           if (tcode1 == COMPLEX_TYPE || tcode1 == VECTOR_TYPE)
    5545                 :       30003 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
    5546                 :             : 
    5547                 :     8989277 :           if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
    5548                 :             :             resultcode = RDIV_EXPR;
    5549                 :             :           else
    5550                 :             :             {
    5551                 :             :               /* When dividing two signed integers, we have to promote to int.
    5552                 :             :                  unless we divide by a constant != -1.  Note that default
    5553                 :             :                  conversion will have been performed on the operands at this
    5554                 :             :                  point, so we have to dig out the original type to find out if
    5555                 :             :                  it was unsigned.  */
    5556                 :     3502740 :               tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5557                 :     3502740 :               shorten = may_shorten_divmod (op0, stripped_op1);
    5558                 :             :             }
    5559                 :             : 
    5560                 :             :           common = 1;
    5561                 :             :         }
    5562                 :             :       break;
    5563                 :             : 
    5564                 :     1929879 :     case BIT_AND_EXPR:
    5565                 :     1929879 :     case BIT_IOR_EXPR:
    5566                 :     1929879 :     case BIT_XOR_EXPR:
    5567                 :     1929879 :       if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5568                 :     1929879 :           || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5569                 :       18123 :               && !VECTOR_FLOAT_TYPE_P (type0)
    5570                 :       18099 :               && !VECTOR_FLOAT_TYPE_P (type1)))
    5571                 :             :         shorten = -1;
    5572                 :             :       break;
    5573                 :             : 
    5574                 :     1069612 :     case TRUNC_MOD_EXPR:
    5575                 :     1069612 :     case FLOOR_MOD_EXPR:
    5576                 :     1069612 :       doing_div_or_mod = true;
    5577                 :     1069612 :       warn_for_div_by_zero (location, fold_for_warn (op1));
    5578                 :             : 
    5579                 :     1069612 :       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5580                 :          24 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5581                 :     1069636 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    5582                 :             :         common = 1;
    5583                 :     1069588 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5584                 :             :         {
    5585                 :             :           /* Although it would be tempting to shorten always here, that loses
    5586                 :             :              on some targets, since the modulo instruction is undefined if the
    5587                 :             :              quotient can't be represented in the computation mode.  We shorten
    5588                 :             :              only if unsigned or if dividing by something we know != -1.  */
    5589                 :     1069556 :           tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5590                 :     1069556 :           shorten = may_shorten_divmod (op0, stripped_op1);
    5591                 :     1069556 :           common = 1;
    5592                 :             :         }
    5593                 :             :       break;
    5594                 :             : 
    5595                 :     9309434 :     case TRUTH_ANDIF_EXPR:
    5596                 :     9309434 :     case TRUTH_ORIF_EXPR:
    5597                 :     9309434 :     case TRUTH_AND_EXPR:
    5598                 :     9309434 :     case TRUTH_OR_EXPR:
    5599                 :     9309434 :       if (!VECTOR_TYPE_P (type0) && gnu_vector_type_p (type1))
    5600                 :             :         {
    5601                 :           4 :           if (!COMPARISON_CLASS_P (op1))
    5602                 :           4 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5603                 :             :                                       build_zero_cst (type1), complain);
    5604                 :           4 :           if (code == TRUTH_ANDIF_EXPR)
    5605                 :             :             {
    5606                 :           0 :               tree z = build_zero_cst (TREE_TYPE (op1));
    5607                 :           0 :               return build_conditional_expr (location, op0, op1, z, complain);
    5608                 :             :             }
    5609                 :           4 :           else if (code == TRUTH_ORIF_EXPR)
    5610                 :             :             {
    5611                 :           4 :               tree m1 = build_all_ones_cst (TREE_TYPE (op1));
    5612                 :           4 :               return build_conditional_expr (location, op0, m1, op1, complain);
    5613                 :             :             }
    5614                 :             :           else
    5615                 :           0 :             gcc_unreachable ();
    5616                 :             :         }
    5617                 :     9309430 :       if (gnu_vector_type_p (type0)
    5618                 :     9309430 :           && (!VECTOR_TYPE_P (type1) || gnu_vector_type_p (type1)))
    5619                 :             :         {
    5620                 :          32 :           if (!COMPARISON_CLASS_P (op0))
    5621                 :          32 :             op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0,
    5622                 :             :                                       build_zero_cst (type0), complain);
    5623                 :          32 :           if (!VECTOR_TYPE_P (type1))
    5624                 :             :             {
    5625                 :          12 :               tree m1 = build_all_ones_cst (TREE_TYPE (op0));
    5626                 :          12 :               tree z = build_zero_cst (TREE_TYPE (op0));
    5627                 :          12 :               op1 = build_conditional_expr (location, op1, m1, z, complain);
    5628                 :             :             }
    5629                 :          20 :           else if (!COMPARISON_CLASS_P (op1))
    5630                 :          20 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5631                 :             :                                       build_zero_cst (type1), complain);
    5632                 :             : 
    5633                 :          32 :           if (code == TRUTH_ANDIF_EXPR)
    5634                 :             :             code = BIT_AND_EXPR;
    5635                 :          12 :           else if (code == TRUTH_ORIF_EXPR)
    5636                 :             :             code = BIT_IOR_EXPR;
    5637                 :             :           else
    5638                 :           0 :             gcc_unreachable ();
    5639                 :             : 
    5640                 :          32 :           return cp_build_binary_op (location, code, op0, op1, complain);
    5641                 :             :         }
    5642                 :             : 
    5643                 :     9309398 :       result_type = boolean_type_node;
    5644                 :     9309398 :       break;
    5645                 :             : 
    5646                 :             :       /* Shift operations: result has same type as first operand;
    5647                 :             :          always convert second operand to int.
    5648                 :             :          Also set SHORT_SHIFT if shifting rightward.  */
    5649                 :             : 
    5650                 :      859715 :     case RSHIFT_EXPR:
    5651                 :      859715 :       if (gnu_vector_type_p (type0)
    5652                 :         170 :           && code1 == INTEGER_TYPE
    5653                 :      859760 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    5654                 :             :         {
    5655                 :             :           result_type = type0;
    5656                 :             :           converted = 1;
    5657                 :             :         }
    5658                 :      859670 :       else if (gnu_vector_type_p (type0)
    5659                 :         125 :                && gnu_vector_type_p (type1)
    5660                 :         125 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5661                 :         121 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    5662                 :      859791 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    5663                 :             :                             TYPE_VECTOR_SUBPARTS (type1)))
    5664                 :             :         {
    5665                 :             :           result_type = type0;
    5666                 :             :           converted = 1;
    5667                 :             :         }
    5668                 :      859549 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5669                 :             :         {
    5670                 :      859513 :           tree const_op1 = fold_for_warn (op1);
    5671                 :      859513 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    5672                 :       68364 :             const_op1 = op1;
    5673                 :      859513 :           result_type = type0;
    5674                 :      859513 :           doing_shift = true;
    5675                 :      859513 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    5676                 :             :             {
    5677                 :      791149 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    5678                 :             :                 {
    5679                 :          63 :                   if ((complain & tf_warning)
    5680                 :          63 :                       && c_inhibit_evaluation_warnings == 0)
    5681                 :          47 :                     warning_at (location, OPT_Wshift_count_negative,
    5682                 :             :                                 "right shift count is negative");
    5683                 :             :                 }
    5684                 :             :               else
    5685                 :             :                 {
    5686                 :      791086 :                   if (!integer_zerop (const_op1))
    5687                 :      790990 :                     short_shift = 1;
    5688                 :             : 
    5689                 :      791086 :                   if (compare_tree_int (const_op1, TYPE_PRECISION (type0)) >= 0
    5690                 :          63 :                       && (complain & tf_warning)
    5691                 :      791149 :                       && c_inhibit_evaluation_warnings == 0)
    5692                 :          43 :                     warning_at (location, OPT_Wshift_count_overflow,
    5693                 :             :                                 "right shift count >= width of type");
    5694                 :             :                 }
    5695                 :             :             }
    5696                 :             :           /* Avoid converting op1 to result_type later.  */
    5697                 :             :           converted = 1;
    5698                 :             :         }
    5699                 :             :       break;
    5700                 :             : 
    5701                 :     2662921 :     case LSHIFT_EXPR:
    5702                 :     2662921 :       if (gnu_vector_type_p (type0)
    5703                 :         182 :           && code1 == INTEGER_TYPE
    5704                 :     2662952 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    5705                 :             :         {
    5706                 :             :           result_type = type0;
    5707                 :             :           converted = 1;
    5708                 :             :         }
    5709                 :     2662890 :       else if (gnu_vector_type_p (type0)
    5710                 :         151 :                && gnu_vector_type_p (type1)
    5711                 :         151 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5712                 :         147 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    5713                 :     2663033 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    5714                 :             :                             TYPE_VECTOR_SUBPARTS (type1)))
    5715                 :             :         {
    5716                 :             :           result_type = type0;
    5717                 :             :           converted = 1;
    5718                 :             :         }
    5719                 :     2662747 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5720                 :             :         {
    5721                 :     2662707 :           tree const_op0 = fold_for_warn (op0);
    5722                 :     2662707 :           if (TREE_CODE (const_op0) != INTEGER_CST)
    5723                 :      106172 :             const_op0 = op0;
    5724                 :     2662707 :           tree const_op1 = fold_for_warn (op1);
    5725                 :     2662707 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    5726                 :      166297 :             const_op1 = op1;
    5727                 :     2662707 :           result_type = type0;
    5728                 :     2662707 :           doing_shift = true;
    5729                 :     2662707 :           if (TREE_CODE (const_op0) == INTEGER_CST
    5730                 :     2556535 :               && tree_int_cst_sgn (const_op0) < 0
    5731                 :         345 :               && !TYPE_OVERFLOW_WRAPS (type0)
    5732                 :         238 :               && (complain & tf_warning)
    5733                 :     2662945 :               && c_inhibit_evaluation_warnings == 0)
    5734                 :         238 :             warning_at (location, OPT_Wshift_negative_value,
    5735                 :             :                         "left shift of negative value");
    5736                 :     2662707 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    5737                 :             :             {
    5738                 :     2496410 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    5739                 :             :                 {
    5740                 :          73 :                   if ((complain & tf_warning)
    5741                 :          73 :                       && c_inhibit_evaluation_warnings == 0)
    5742                 :          51 :                     warning_at (location, OPT_Wshift_count_negative,
    5743                 :             :                                 "left shift count is negative");
    5744                 :             :                 }
    5745                 :     2496337 :               else if (compare_tree_int (const_op1,
    5746                 :     2496337 :                                          TYPE_PRECISION (type0)) >= 0)
    5747                 :             :                 {
    5748                 :         107 :                   if ((complain & tf_warning)
    5749                 :          79 :                       && c_inhibit_evaluation_warnings == 0)
    5750                 :          59 :                     warning_at (location, OPT_Wshift_count_overflow,
    5751                 :             :                                 "left shift count >= width of type");
    5752                 :             :                 }
    5753                 :     2496230 :               else if (TREE_CODE (const_op0) == INTEGER_CST
    5754                 :     2411711 :                        && (complain & tf_warning))
    5755                 :     2280038 :                 maybe_warn_shift_overflow (location, const_op0, const_op1);
    5756                 :             :             }
    5757                 :             :           /* Avoid converting op1 to result_type later.  */
    5758                 :             :           converted = 1;
    5759                 :             :         }
    5760                 :             :       break;
    5761                 :             : 
    5762                 :    19996068 :     case EQ_EXPR:
    5763                 :    19996068 :     case NE_EXPR:
    5764                 :    19996068 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    5765                 :        2554 :         goto vector_compare;
    5766                 :    19993514 :       if ((complain & tf_warning)
    5767                 :    19029580 :           && c_inhibit_evaluation_warnings == 0
    5768                 :    38477301 :           && (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)))
    5769                 :      787764 :         warning_at (location, OPT_Wfloat_equal,
    5770                 :             :                     "comparing floating-point with %<==%> "
    5771                 :             :                     "or %<!=%> is unsafe");
    5772                 :    19993514 :       if (complain & tf_warning)
    5773                 :             :         {
    5774                 :    19029580 :           tree stripped_orig_op0 = tree_strip_any_location_wrapper (orig_op0);
    5775                 :    19029580 :           tree stripped_orig_op1 = tree_strip_any_location_wrapper (orig_op1);
    5776                 :    19029580 :           if ((TREE_CODE (stripped_orig_op0) == STRING_CST
    5777                 :          52 :                && !integer_zerop (cp_fully_fold (op1)))
    5778                 :    19029628 :               || (TREE_CODE (stripped_orig_op1) == STRING_CST
    5779                 :          75 :                   && !integer_zerop (cp_fully_fold (op0))))
    5780                 :          47 :             warning_at (location, OPT_Waddress,
    5781                 :             :                         "comparison with string literal results in "
    5782                 :             :                         "unspecified behavior");
    5783                 :    19029533 :           else if (warn_array_compare
    5784                 :      341183 :                    && TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    5785                 :    19029677 :                    && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE)
    5786                 :          12 :             do_warn_array_compare (location, code, stripped_orig_op0,
    5787                 :             :                                    stripped_orig_op1);
    5788                 :             :         }
    5789                 :             : 
    5790                 :    19993514 :       build_type = boolean_type_node;
    5791                 :    19993514 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5792                 :             :            || code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
    5793                 :    16889625 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5794                 :             :               || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
    5795                 :             :         short_compare = 1;
    5796                 :       20680 :       else if (((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0))
    5797                 :     3103421 :                 && null_ptr_cst_p (orig_op1))
    5798                 :             :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    5799                 :     4751311 :                || (code0 == POINTER_TYPE
    5800                 :     1607818 :                    && TYPE_PTR_P (type1) && integer_zerop (op1)))
    5801                 :             :         {
    5802                 :     1514292 :           if (TYPE_PTR_P (type1))
    5803                 :       19099 :             result_type = composite_pointer_type (location,
    5804                 :             :                                                   type0, type1, op0, op1,
    5805                 :             :                                                   CPO_COMPARISON, complain);
    5806                 :             :           else
    5807                 :             :             result_type = type0;
    5808                 :             : 
    5809                 :     1514292 :           if (char_type_p (TREE_TYPE (orig_op1)))
    5810                 :             :             {
    5811                 :          10 :               auto_diagnostic_group d;
    5812                 :          10 :               if (warning_at (location, OPT_Wpointer_compare,
    5813                 :             :                               "comparison between pointer and zero character "
    5814                 :             :                               "constant"))
    5815                 :          10 :                 inform (location,
    5816                 :             :                         "did you mean to dereference the pointer?");
    5817                 :          10 :             }
    5818                 :     1514292 :           warn_for_null_address (location, op0, complain);
    5819                 :             :         }
    5820                 :         951 :       else if (((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1))
    5821                 :     1608447 :                 && null_ptr_cst_p (orig_op0))
    5822                 :             :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    5823                 :     3216765 :                || (code1 == POINTER_TYPE
    5824                 :     1606882 :                    && TYPE_PTR_P (type0) && integer_zerop (op0)))
    5825                 :             :         {
    5826                 :        1241 :           if (TYPE_PTR_P (type0))
    5827                 :          86 :             result_type = composite_pointer_type (location,
    5828                 :             :                                                   type0, type1, op0, op1,
    5829                 :             :                                                   CPO_COMPARISON, complain);
    5830                 :             :           else
    5831                 :             :             result_type = type1;
    5832                 :             : 
    5833                 :        1241 :           if (char_type_p (TREE_TYPE (orig_op0)))
    5834                 :             :             {
    5835                 :          10 :               auto_diagnostic_group d;
    5836                 :          10 :               if (warning_at (location, OPT_Wpointer_compare,
    5837                 :             :                              "comparison between pointer and zero character "
    5838                 :             :                              "constant"))
    5839                 :          10 :                 inform (location,
    5840                 :             :                         "did you mean to dereference the pointer?");
    5841                 :          10 :             }
    5842                 :        1241 :           warn_for_null_address (location, op1, complain);
    5843                 :             :         }
    5844                 :     1607719 :       else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    5845                 :       19144 :                || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1)))
    5846                 :     1588985 :         result_type = composite_pointer_type (location,
    5847                 :             :                                               type0, type1, op0, op1,
    5848                 :             :                                               CPO_COMPARISON, complain);
    5849                 :       18734 :       else if (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1))
    5850                 :             :         /* One of the operands must be of nullptr_t type.  */
    5851                 :          65 :         result_type = TREE_TYPE (nullptr_node);
    5852                 :       18669 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    5853                 :             :         {
    5854                 :          58 :           result_type = type0;
    5855                 :          58 :           if (complain & tf_error)
    5856                 :          56 :             permerror (location, "ISO C++ forbids comparison between "
    5857                 :             :                        "pointer and integer");
    5858                 :             :           else
    5859                 :           2 :             return error_mark_node;
    5860                 :             :         }
    5861                 :       18611 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    5862                 :             :         {
    5863                 :       18221 :           result_type = type1;
    5864                 :       18221 :           if (complain & tf_error)
    5865                 :          74 :             permerror (location, "ISO C++ forbids comparison between "
    5866                 :             :                        "pointer and integer");
    5867                 :             :           else
    5868                 :       18147 :             return error_mark_node;
    5869                 :             :         }
    5870                 :         390 :       else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (orig_op1))
    5871                 :             :         {
    5872                 :         221 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    5873                 :             :               == ptrmemfunc_vbit_in_delta)
    5874                 :             :             {
    5875                 :             :               tree pfn0, delta0, e1, e2;
    5876                 :             : 
    5877                 :             :               if (TREE_SIDE_EFFECTS (op0))
    5878                 :             :                 op0 = cp_save_expr (op0);
    5879                 :             : 
    5880                 :             :               pfn0 = pfn_from_ptrmemfunc (op0);
    5881                 :             :               delta0 = delta_from_ptrmemfunc (op0);
    5882                 :             :               {
    5883                 :             :                 /* If we will warn below about a null-address compare
    5884                 :             :                    involving the orig_op0 ptrmemfunc, we'd likely also
    5885                 :             :                    warn about the pfn0's null-address compare, and
    5886                 :             :                    that would be redundant, so suppress it.  */
    5887                 :             :                 warning_sentinel ws (warn_address);
    5888                 :             :                 e1 = cp_build_binary_op (location,
    5889                 :             :                                          EQ_EXPR,
    5890                 :             :                                          pfn0,
    5891                 :             :                                          build_zero_cst (TREE_TYPE (pfn0)),
    5892                 :             :                                          complain);
    5893                 :             :               }
    5894                 :             :               e2 = cp_build_binary_op (location,
    5895                 :             :                                        BIT_AND_EXPR,
    5896                 :             :                                        delta0,
    5897                 :             :                                        integer_one_node,
    5898                 :             :                                        complain);
    5899                 :             : 
    5900                 :             :               if (complain & tf_warning)
    5901                 :             :                 maybe_warn_zero_as_null_pointer_constant (op1, input_location);
    5902                 :             : 
    5903                 :             :               e2 = cp_build_binary_op (location,
    5904                 :             :                                        EQ_EXPR, e2, integer_zero_node,
    5905                 :             :                                        complain);
    5906                 :             :               op0 = cp_build_binary_op (location,
    5907                 :             :                                         TRUTH_ANDIF_EXPR, e1, e2,
    5908                 :             :                                         complain);
    5909                 :             :               op1 = cp_convert (TREE_TYPE (op0), integer_one_node, complain);
    5910                 :             :             }
    5911                 :             :           else 
    5912                 :             :             {
    5913                 :         221 :               op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
    5914                 :         221 :               op1 = cp_convert (TREE_TYPE (op0), op1, complain);
    5915                 :             :             }
    5916                 :         221 :           result_type = TREE_TYPE (op0);
    5917                 :             : 
    5918                 :         221 :           warn_for_null_address (location, orig_op0, complain);
    5919                 :             :         }
    5920                 :         169 :       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (orig_op0))
    5921                 :          40 :         return cp_build_binary_op (location, code, op1, op0, complain);
    5922                 :         129 :       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
    5923                 :             :         {
    5924                 :         105 :           tree type;
    5925                 :             :           /* E will be the final comparison.  */
    5926                 :         105 :           tree e;
    5927                 :             :           /* E1 and E2 are for scratch.  */
    5928                 :         105 :           tree e1;
    5929                 :         105 :           tree e2;
    5930                 :         105 :           tree pfn0;
    5931                 :         105 :           tree pfn1;
    5932                 :         105 :           tree delta0;
    5933                 :         105 :           tree delta1;
    5934                 :             : 
    5935                 :         105 :           type = composite_pointer_type (location, type0, type1, op0, op1, 
    5936                 :             :                                          CPO_COMPARISON, complain);
    5937                 :             : 
    5938                 :         105 :           if (!same_type_p (TREE_TYPE (op0), type))
    5939                 :           8 :             op0 = cp_convert_and_check (type, op0, complain);
    5940                 :         105 :           if (!same_type_p (TREE_TYPE (op1), type))
    5941                 :          12 :             op1 = cp_convert_and_check (type, op1, complain);
    5942                 :             : 
    5943                 :         105 :           if (op0 == error_mark_node || op1 == error_mark_node)
    5944                 :             :             return error_mark_node;
    5945                 :             : 
    5946                 :         101 :           if (TREE_SIDE_EFFECTS (op0))
    5947                 :          34 :             op0 = save_expr (op0);
    5948                 :         101 :           if (TREE_SIDE_EFFECTS (op1))
    5949                 :           0 :             op1 = save_expr (op1);
    5950                 :             : 
    5951                 :         101 :           pfn0 = pfn_from_ptrmemfunc (op0);
    5952                 :         101 :           pfn0 = cp_fully_fold (pfn0);
    5953                 :             :           /* Avoid -Waddress warnings (c++/64877).  */
    5954                 :         101 :           if (TREE_CODE (pfn0) == ADDR_EXPR)
    5955                 :          11 :             suppress_warning (pfn0, OPT_Waddress);
    5956                 :         101 :           pfn1 = pfn_from_ptrmemfunc (op1);
    5957                 :         101 :           pfn1 = cp_fully_fold (pfn1);
    5958                 :         101 :           delta0 = delta_from_ptrmemfunc (op0);
    5959                 :         101 :           delta1 = delta_from_ptrmemfunc (op1);
    5960                 :         101 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    5961                 :             :               == ptrmemfunc_vbit_in_delta)
    5962                 :             :             {
    5963                 :             :               /* We generate:
    5964                 :             : 
    5965                 :             :                  (op0.pfn == op1.pfn
    5966                 :             :                   && ((op0.delta == op1.delta)
    5967                 :             :                        || (!op0.pfn && op0.delta & 1 == 0 
    5968                 :             :                            && op1.delta & 1 == 0))
    5969                 :             : 
    5970                 :             :                  The reason for the `!op0.pfn' bit is that a NULL
    5971                 :             :                  pointer-to-member is any member with a zero PFN and
    5972                 :             :                  LSB of the DELTA field is 0.  */
    5973                 :             : 
    5974                 :             :               e1 = cp_build_binary_op (location, BIT_AND_EXPR,
    5975                 :             :                                        delta0, 
    5976                 :             :                                        integer_one_node,
    5977                 :             :                                        complain);
    5978                 :             :               e1 = cp_build_binary_op (location,
    5979                 :             :                                        EQ_EXPR, e1, integer_zero_node,
    5980                 :             :                                        complain);
    5981                 :             :               e2 = cp_build_binary_op (location, BIT_AND_EXPR,
    5982                 :             :                                        delta1,
    5983                 :             :                                        integer_one_node,
    5984                 :             :                                        complain);
    5985                 :             :               e2 = cp_build_binary_op (location,
    5986                 :             :                                        EQ_EXPR, e2, integer_zero_node,
    5987                 :             :                                        complain);
    5988                 :             :               e1 = cp_build_binary_op (location,
    5989                 :             :                                        TRUTH_ANDIF_EXPR, e2, e1,
    5990                 :             :                                        complain);
    5991                 :             :               e2 = cp_build_binary_op (location, EQ_EXPR,
    5992                 :             :                                        pfn0,
    5993                 :             :                                        build_zero_cst (TREE_TYPE (pfn0)),
    5994                 :             :                                        complain);
    5995                 :             :               e2 = cp_build_binary_op (location,
    5996                 :             :                                        TRUTH_ANDIF_EXPR, e2, e1, complain);
    5997                 :             :               e1 = cp_build_binary_op (location,
    5998                 :             :                                        EQ_EXPR, delta0, delta1, complain);
    5999                 :             :               e1 = cp_build_binary_op (location,
    6000                 :             :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6001                 :             :             }
    6002                 :             :           else
    6003                 :             :             {
    6004                 :             :               /* We generate:
    6005                 :             : 
    6006                 :             :                  (op0.pfn == op1.pfn
    6007                 :             :                  && (!op0.pfn || op0.delta == op1.delta))
    6008                 :             : 
    6009                 :             :                  The reason for the `!op0.pfn' bit is that a NULL
    6010                 :             :                  pointer-to-member is any member with a zero PFN; the
    6011                 :             :                  DELTA field is unspecified.  */
    6012                 :             :  
    6013                 :         101 :               e1 = cp_build_binary_op (location,
    6014                 :             :                                        EQ_EXPR, delta0, delta1, complain);
    6015                 :         101 :               e2 = cp_build_binary_op (location,
    6016                 :             :                                        EQ_EXPR,
    6017                 :             :                                        pfn0,
    6018                 :         101 :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6019                 :             :                                        complain);
    6020                 :         101 :               e1 = cp_build_binary_op (location,
    6021                 :             :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6022                 :             :             }
    6023                 :         101 :           e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
    6024                 :         101 :           e = cp_build_binary_op (location,
    6025                 :             :                                   TRUTH_ANDIF_EXPR, e2, e1, complain);
    6026                 :         101 :           if (code == EQ_EXPR)
    6027                 :             :             return e;
    6028                 :          32 :           return cp_build_binary_op (location,
    6029                 :          32 :                                      EQ_EXPR, e, integer_zero_node, complain);
    6030                 :             :         }
    6031                 :             :       else
    6032                 :             :         {
    6033                 :          24 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type0)
    6034                 :             :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0),
    6035                 :             :                                        type1));
    6036                 :          24 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type1)
    6037                 :             :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1),
    6038                 :             :                                        type0));
    6039                 :             :         }
    6040                 :             : 
    6041                 :             :       break;
    6042                 :             : 
    6043                 :         292 :     case MAX_EXPR:
    6044                 :         292 :     case MIN_EXPR:
    6045                 :         292 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
    6046                 :         292 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
    6047                 :             :         shorten = 1;
    6048                 :           0 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6049                 :           0 :         result_type = composite_pointer_type (location,
    6050                 :             :                                               type0, type1, op0, op1,
    6051                 :             :                                               CPO_COMPARISON, complain);
    6052                 :             :       break;
    6053                 :             : 
    6054                 :    18691356 :     case LE_EXPR:
    6055                 :    18691356 :     case GE_EXPR:
    6056                 :    18691356 :     case LT_EXPR:
    6057                 :    18691356 :     case GT_EXPR:
    6058                 :    18691356 :     case SPACESHIP_EXPR:
    6059                 :    18691356 :       if (TREE_CODE (orig_op0) == STRING_CST
    6060                 :    18691356 :           || TREE_CODE (orig_op1) == STRING_CST)
    6061                 :             :         {
    6062                 :           0 :           if (complain & tf_warning)
    6063                 :           0 :             warning_at (location, OPT_Waddress,
    6064                 :             :                         "comparison with string literal results "
    6065                 :             :                         "in unspecified behavior");
    6066                 :             :         }
    6067                 :    18691356 :       else if (warn_array_compare
    6068                 :      206066 :                && TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6069                 :          17 :                && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE
    6070                 :          17 :                && code != SPACESHIP_EXPR
    6071                 :    18691372 :                && (complain & tf_warning))
    6072                 :          16 :         do_warn_array_compare (location, code,
    6073                 :             :                                tree_strip_any_location_wrapper (orig_op0),
    6074                 :             :                                tree_strip_any_location_wrapper (orig_op1));
    6075                 :             : 
    6076                 :    18691356 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6077                 :             :         {
    6078                 :        6958 :         vector_compare:
    6079                 :        6958 :           tree intt;
    6080                 :        6958 :           if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    6081                 :        6958 :                                                           TREE_TYPE (type1))
    6082                 :        6958 :               && !vector_types_compatible_elements_p (type0, type1))
    6083                 :             :             {
    6084                 :           4 :               if (complain & tf_error)
    6085                 :             :                 {
    6086                 :           4 :                   error_at (location, "comparing vectors with different "
    6087                 :             :                                       "element types");
    6088                 :           4 :                   inform (location, "operand types are %qT and %qT",
    6089                 :             :                           type0, type1);
    6090                 :             :                 }
    6091                 :           4 :               return error_mark_node;
    6092                 :             :             }
    6093                 :             : 
    6094                 :        6954 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
    6095                 :       13908 :                         TYPE_VECTOR_SUBPARTS (type1)))
    6096                 :             :             {
    6097                 :           4 :               if (complain & tf_error)
    6098                 :             :                 {
    6099                 :           4 :                   error_at (location, "comparing vectors with different "
    6100                 :             :                                       "number of elements");
    6101                 :           4 :                   inform (location, "operand types are %qT and %qT",
    6102                 :             :                           type0, type1);
    6103                 :             :                 }
    6104                 :           4 :               return error_mark_node;
    6105                 :             :             }
    6106                 :             : 
    6107                 :             :           /* It's not precisely specified how the usual arithmetic
    6108                 :             :              conversions apply to the vector types.  Here, we use
    6109                 :             :              the unsigned type if one of the operands is signed and
    6110                 :             :              the other one is unsigned.  */
    6111                 :        6950 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
    6112                 :             :             {
    6113                 :          48 :               if (!TYPE_UNSIGNED (type0))
    6114                 :          48 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
    6115                 :             :               else
    6116                 :           0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
    6117                 :          48 :               warning_at (location, OPT_Wsign_compare, "comparison between "
    6118                 :             :                           "types %qT and %qT", type0, type1);
    6119                 :             :             }
    6120                 :             : 
    6121                 :        6950 :           if (resultcode == SPACESHIP_EXPR)
    6122                 :             :             {
    6123                 :           1 :               if (complain & tf_error)
    6124                 :           1 :                 sorry_at (location, "three-way comparison of vectors");
    6125                 :           1 :               return error_mark_node;
    6126                 :             :             }
    6127                 :             : 
    6128                 :             :           /* Always construct signed integer vector type.  */
    6129                 :        6949 :           intt = c_common_type_for_size
    6130                 :       13898 :             (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (type0))), 0);
    6131                 :        6949 :           if (!intt)
    6132                 :             :             {
    6133                 :           0 :               if (complain & tf_error)
    6134                 :           0 :                 error_at (location, "could not find an integer type "
    6135                 :           0 :                           "of the same size as %qT", TREE_TYPE (type0));
    6136                 :           0 :               return error_mark_node;
    6137                 :             :             }
    6138                 :        6949 :           result_type = build_opaque_vector_type (intt,
    6139                 :        6949 :                                                   TYPE_VECTOR_SUBPARTS (type0));
    6140                 :        6949 :           return build_vec_cmp (resultcode, result_type, op0, op1);
    6141                 :             :         }
    6142                 :    18686952 :       build_type = boolean_type_node;
    6143                 :    18686952 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6144                 :             :            || code0 == ENUMERAL_TYPE)
    6145                 :    17973962 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6146                 :             :                || code1 == ENUMERAL_TYPE))
    6147                 :             :         short_compare = 1;
    6148                 :      713080 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6149                 :      712856 :         result_type = composite_pointer_type (location,
    6150                 :             :                                               type0, type1, op0, op1,
    6151                 :             :                                               CPO_COMPARISON, complain);
    6152                 :          79 :       else if ((code0 == POINTER_TYPE && null_ptr_cst_p (orig_op1))
    6153                 :         148 :                || (code1 == POINTER_TYPE && null_ptr_cst_p (orig_op0))
    6154                 :         318 :                || (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)))
    6155                 :             :         {
    6156                 :             :           /* Core Issue 1512 made this ill-formed.  */
    6157                 :         181 :           if (complain & tf_error)
    6158                 :         178 :             error_at (location, "ordered comparison of pointer with "
    6159                 :             :                       "integer zero (%qT and %qT)", type0, type1);
    6160                 :         181 :           return error_mark_node;
    6161                 :             :         }
    6162                 :          43 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6163                 :             :         {
    6164                 :           0 :           result_type = type0;
    6165                 :           0 :           if (complain & tf_error)
    6166                 :           0 :             permerror (location, "ISO C++ forbids comparison between "
    6167                 :             :                        "pointer and integer");
    6168                 :             :           else
    6169                 :           0 :             return error_mark_node;
    6170                 :             :         }
    6171                 :          43 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6172                 :             :         {
    6173                 :          32 :           result_type = type1;
    6174                 :          32 :           if (complain & tf_error)
    6175                 :          32 :             permerror (location, "ISO C++ forbids comparison between "
    6176                 :             :                        "pointer and integer");
    6177                 :             :           else
    6178                 :           0 :             return error_mark_node;
    6179                 :             :         }
    6180                 :             : 
    6181                 :    18686771 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    6182                 :      712891 :           && !processing_template_decl
    6183                 :    19201724 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
    6184                 :             :         {
    6185                 :          49 :           op0 = save_expr (op0);
    6186                 :          49 :           op1 = save_expr (op1);
    6187                 :             : 
    6188                 :          49 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
    6189                 :          49 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
    6190                 :             :         }
    6191                 :             : 
    6192                 :             :       break;
    6193                 :             : 
    6194                 :           0 :     case UNORDERED_EXPR:
    6195                 :           0 :     case ORDERED_EXPR:
    6196                 :           0 :     case UNLT_EXPR:
    6197                 :           0 :     case UNLE_EXPR:
    6198                 :           0 :     case UNGT_EXPR:
    6199                 :           0 :     case UNGE_EXPR:
    6200                 :           0 :     case UNEQ_EXPR:
    6201                 :           0 :       build_type = integer_type_node;
    6202                 :           0 :       if (code0 != REAL_TYPE || code1 != REAL_TYPE)
    6203                 :             :         {
    6204                 :           0 :           if (complain & tf_error)
    6205                 :           0 :             error ("unordered comparison on non-floating-point argument");
    6206                 :           0 :           return error_mark_node;
    6207                 :             :         }
    6208                 :             :       common = 1;
    6209                 :             :       break;
    6210                 :             : 
    6211                 :             :     default:
    6212                 :             :       break;
    6213                 :             :     }
    6214                 :             : 
    6215                 :   107721059 :   if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
    6216                 :             :         || code0 == ENUMERAL_TYPE)
    6217                 :    92923059 :        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6218                 :             :            || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
    6219                 :             :     arithmetic_types_p = 1;
    6220                 :             :   else
    6221                 :             :     {
    6222                 :    14990500 :       arithmetic_types_p = 0;
    6223                 :             :       /* Vector arithmetic is only allowed when both sides are vectors.  */
    6224                 :    14990500 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6225                 :             :         {
    6226                 :       52692 :           if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
    6227                 :       52692 :               || !vector_types_compatible_elements_p (type0, type1))
    6228                 :             :             {
    6229                 :          24 :               if (complain & tf_error)
    6230                 :             :                 {
    6231                 :             :                   /* "location" already embeds the locations of the
    6232                 :             :                      operands, so we don't need to add them separately
    6233                 :             :                      to richloc.  */
    6234                 :          24 :                   rich_location richloc (line_table, location);
    6235                 :          24 :                   binary_op_error (&richloc, code, type0, type1);
    6236                 :          24 :                 }
    6237                 :          24 :               return error_mark_node;
    6238                 :             :             }
    6239                 :             :           arithmetic_types_p = 1;
    6240                 :             :         }
    6241                 :             :     }
    6242                 :             :   /* Determine the RESULT_TYPE, if it is not already known.  */
    6243                 :   107721035 :   if (!result_type
    6244                 :   107721035 :       && arithmetic_types_p
    6245                 :    89106147 :       && (shorten || common || short_compare))
    6246                 :             :     {
    6247                 :    89106053 :       result_type = cp_common_type (type0, type1);
    6248                 :    89106053 :       if (result_type == error_mark_node)
    6249                 :             :         {
    6250                 :           0 :           tree t1 = type0;
    6251                 :           0 :           tree t2 = type1;
    6252                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6253                 :           0 :             t1 = TREE_TYPE (t1);
    6254                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6255                 :           0 :             t2 = TREE_TYPE (t2);
    6256                 :           0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6257                 :             :                                && TREE_CODE (t2) == REAL_TYPE
    6258                 :             :                                && (extended_float_type_p (t1)
    6259                 :             :                                    || extended_float_type_p (t2))
    6260                 :             :                                && cp_compare_floating_point_conversion_ranks
    6261                 :             :                                     (t1, t2) == 3);
    6262                 :           0 :           if (complain & tf_error)
    6263                 :             :             {
    6264                 :           0 :               rich_location richloc (line_table, location);
    6265                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    6266                 :           0 :             }
    6267                 :           0 :           return error_mark_node;
    6268                 :             :         }
    6269                 :    89106053 :       if (complain & tf_warning)
    6270                 :    84964661 :         do_warn_double_promotion (result_type, type0, type1,
    6271                 :             :                                   "implicit conversion from %qH to %qI "
    6272                 :             :                                   "to match other operand of binary "
    6273                 :             :                                   "expression", location);
    6274                 :    89106053 :       if (do_warn_enum_conversions (location, code, TREE_TYPE (orig_op0),
    6275                 :    89106053 :                                     TREE_TYPE (orig_op1), complain))
    6276                 :           0 :         return error_mark_node;
    6277                 :             :     }
    6278                 :   107721035 :   if (may_need_excess_precision
    6279                 :    84095352 :       && (orig_type0 != type0 || orig_type1 != type1)
    6280                 :       61606 :       && build_type == NULL_TREE
    6281                 :       61606 :       && result_type)
    6282                 :             :     {
    6283                 :       46696 :       gcc_assert (common);
    6284                 :       46696 :       semantic_result_type = cp_common_type (orig_type0, orig_type1);
    6285                 :       46696 :       if (semantic_result_type == error_mark_node)
    6286                 :             :         {
    6287                 :           0 :           tree t1 = orig_type0;
    6288                 :           0 :           tree t2 = orig_type1;
    6289                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6290                 :           0 :             t1 = TREE_TYPE (t1);
    6291                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6292                 :           0 :             t2 = TREE_TYPE (t2);
    6293                 :           0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6294                 :             :                                && TREE_CODE (t2) == REAL_TYPE
    6295                 :             :                                && (extended_float_type_p (t1)
    6296                 :             :                                    || extended_float_type_p (t2))
    6297                 :             :                                && cp_compare_floating_point_conversion_ranks
    6298                 :             :                                     (t1, t2) == 3);
    6299                 :           0 :           if (complain & tf_error)
    6300                 :             :             {
    6301                 :           0 :               rich_location richloc (line_table, location);
    6302                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    6303                 :           0 :             }
    6304                 :           0 :           return error_mark_node;
    6305                 :             :         }
    6306                 :             :     }
    6307                 :             : 
    6308                 :   107721035 :   if (code == SPACESHIP_EXPR)
    6309                 :             :     {
    6310                 :      125883 :       iloc_sentinel s (location);
    6311                 :             : 
    6312                 :      125883 :       tree orig_type0 = TREE_TYPE (orig_op0);
    6313                 :      125883 :       tree_code orig_code0 = TREE_CODE (orig_type0);
    6314                 :      125883 :       tree orig_type1 = TREE_TYPE (orig_op1);
    6315                 :      125883 :       tree_code orig_code1 = TREE_CODE (orig_type1);
    6316                 :      125883 :       if (!result_type || result_type == error_mark_node)
    6317                 :             :         /* Nope.  */
    6318                 :             :         result_type = NULL_TREE;
    6319                 :      125876 :       else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE))
    6320                 :             :         /* "If one of the operands is of type bool and the other is not, the
    6321                 :             :            program is ill-formed."  */
    6322                 :             :         result_type = NULL_TREE;
    6323                 :      125875 :       else if (code0 == POINTER_TYPE && orig_code0 != POINTER_TYPE
    6324                 :          15 :                && code1 == POINTER_TYPE && orig_code1 != POINTER_TYPE)
    6325                 :             :         /* We only do array/function-to-pointer conversion if "at least one of
    6326                 :             :            the operands is of pointer type".  */
    6327                 :             :         result_type = NULL_TREE;
    6328                 :      125860 :       else if (TYPE_PTRFN_P (result_type) || NULLPTR_TYPE_P (result_type))
    6329                 :             :         /* <=> no longer supports equality relations.  */
    6330                 :             :         result_type = NULL_TREE;
    6331                 :      125859 :       else if (orig_code0 == ENUMERAL_TYPE && orig_code1 == ENUMERAL_TYPE
    6332                 :      125879 :                && !(same_type_ignoring_top_level_qualifiers_p
    6333                 :          20 :                     (orig_type0, orig_type1)))
    6334                 :             :         /* "If both operands have arithmetic types, or one operand has integral
    6335                 :             :            type and the other operand has unscoped enumeration type, the usual
    6336                 :             :            arithmetic conversions are applied to the operands."  So we don't do
    6337                 :             :            arithmetic conversions if the operands both have enumeral type.  */
    6338                 :             :         result_type = NULL_TREE;
    6339                 :      125854 :       else if ((orig_code0 == ENUMERAL_TYPE && orig_code1 == REAL_TYPE)
    6340                 :      125852 :                || (orig_code0 == REAL_TYPE && orig_code1 == ENUMERAL_TYPE))
    6341                 :             :         /* [depr.arith.conv.enum]: Three-way comparisons between such operands
    6342                 :             :            [where one is of enumeration type and the other is of a different
    6343                 :             :            enumeration type or a floating-point type] are ill-formed.  */
    6344                 :             :         result_type = NULL_TREE;
    6345                 :             : 
    6346                 :      125850 :       if (result_type)
    6347                 :             :         {
    6348                 :      125850 :           build_type = spaceship_type (result_type, complain);
    6349                 :      125850 :           if (build_type == error_mark_node)
    6350                 :             :             return error_mark_node;
    6351                 :             :         }
    6352                 :             : 
    6353                 :      125878 :       if (result_type && arithmetic_types_p)
    6354                 :             :         {
    6355                 :             :           /* If a narrowing conversion is required, other than from an integral
    6356                 :             :              type to a floating point type, the program is ill-formed.  */
    6357                 :       63098 :           bool ok = true;
    6358                 :       63098 :           if (TREE_CODE (result_type) == REAL_TYPE
    6359                 :         382 :               && CP_INTEGRAL_TYPE_P (orig_type0))
    6360                 :             :             /* OK */;
    6361                 :       63089 :           else if (!check_narrowing (result_type, orig_op0, complain))
    6362                 :       63098 :             ok = false;
    6363                 :       63098 :           if (TREE_CODE (result_type) == REAL_TYPE
    6364                 :         382 :               && CP_INTEGRAL_TYPE_P (orig_type1))
    6365                 :             :             /* OK */;
    6366                 :       63089 :           else if (!check_narrowing (result_type, orig_op1, complain))
    6367                 :             :             ok = false;
    6368                 :       63098 :           if (!ok && !(complain & tf_error))
    6369                 :           4 :             return error_mark_node;
    6370                 :             :         }
    6371                 :      125883 :     }
    6372                 :             : 
    6373                 :   107721026 :   if (!result_type)
    6374                 :             :     {
    6375                 :         505 :       if (complain & tf_error)
    6376                 :             :         {
    6377                 :         206 :           binary_op_rich_location richloc (location,
    6378                 :         206 :                                            orig_op0, orig_op1, true);
    6379                 :         206 :           error_at (&richloc,
    6380                 :             :                     "invalid operands of types %qT and %qT to binary %qO",
    6381                 :         206 :                     TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code);
    6382                 :         206 :         }
    6383                 :         505 :       return error_mark_node;
    6384                 :             :     }
    6385                 :             : 
    6386                 :             :   /* If we're in a template, the only thing we need to know is the
    6387                 :             :      RESULT_TYPE.  */
    6388                 :   107720521 :   if (processing_template_decl)
    6389                 :             :     {
    6390                 :             :       /* Since the middle-end checks the type when doing a build2, we
    6391                 :             :          need to build the tree in pieces.  This built tree will never
    6392                 :             :          get out of the front-end as we replace it when instantiating
    6393                 :             :          the template.  */
    6394                 :    43527452 :       tree tmp = build2 (resultcode,
    6395                 :             :                          build_type ? build_type : result_type,
    6396                 :             :                          NULL_TREE, op1);
    6397                 :    27896785 :       TREE_OPERAND (tmp, 0) = op0;
    6398                 :    27896785 :       if (semantic_result_type)
    6399                 :           0 :         tmp = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, tmp);
    6400                 :    27896785 :       return tmp;
    6401                 :             :     }
    6402                 :             : 
    6403                 :             :   /* Remember the original type; RESULT_TYPE might be changed later on
    6404                 :             :      by shorten_binary_op.  */
    6405                 :    79823736 :   tree orig_type = result_type;
    6406                 :             : 
    6407                 :    79823736 :   if (arithmetic_types_p)
    6408                 :             :     {
    6409                 :    70860325 :       bool first_complex = (code0 == COMPLEX_TYPE);
    6410                 :    70860325 :       bool second_complex = (code1 == COMPLEX_TYPE);
    6411                 :    70860325 :       int none_complex = (!first_complex && !second_complex);
    6412                 :             : 
    6413                 :             :       /* Adapted from patch for c/24581.  */
    6414                 :    70860325 :       if (first_complex != second_complex
    6415                 :      160618 :           && (code == PLUS_EXPR
    6416                 :             :               || code == MINUS_EXPR
    6417                 :      160618 :               || code == MULT_EXPR
    6418                 :       41966 :               || (code == TRUNC_DIV_EXPR && first_complex))
    6419                 :      147098 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
    6420                 :    71007226 :           && flag_signed_zeros)
    6421                 :             :         {
    6422                 :             :           /* An operation on mixed real/complex operands must be
    6423                 :             :              handled specially, but the language-independent code can
    6424                 :             :              more easily optimize the plain complex arithmetic if
    6425                 :             :              -fno-signed-zeros.  */
    6426                 :      146901 :           tree real_type = TREE_TYPE (result_type);
    6427                 :      146901 :           tree real, imag;
    6428                 :      146901 :           if (first_complex)
    6429                 :             :             {
    6430                 :      113811 :               if (TREE_TYPE (op0) != result_type)
    6431                 :           8 :                 op0 = cp_convert_and_check (result_type, op0, complain);
    6432                 :      113811 :               if (TREE_TYPE (op1) != real_type)
    6433                 :          32 :                 op1 = cp_convert_and_check (real_type, op1, complain);
    6434                 :             :             }
    6435                 :             :           else
    6436                 :             :             {
    6437                 :       33090 :               if (TREE_TYPE (op0) != real_type)
    6438                 :          36 :                 op0 = cp_convert_and_check (real_type, op0, complain);
    6439                 :       33090 :               if (TREE_TYPE (op1) != result_type)
    6440                 :          35 :                 op1 = cp_convert_and_check (result_type, op1, complain);
    6441                 :             :             }
    6442                 :      146901 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
    6443                 :           0 :             return error_mark_node;
    6444                 :      146901 :           if (first_complex)
    6445                 :             :             {
    6446                 :      113811 :               op0 = save_expr (op0);
    6447                 :      113811 :               real = cp_build_unary_op (REALPART_EXPR, op0, true, complain);
    6448                 :      113811 :               imag = cp_build_unary_op (IMAGPART_EXPR, op0, true, complain);
    6449                 :      113811 :               switch (code)
    6450                 :             :                 {
    6451                 :       56885 :                 case MULT_EXPR:
    6452                 :       56885 :                 case TRUNC_DIV_EXPR:
    6453                 :       56885 :                   op1 = save_expr (op1);
    6454                 :       56885 :                   imag = build2 (resultcode, real_type, imag, op1);
    6455                 :             :                   /* Fall through.  */
    6456                 :      113811 :                 case PLUS_EXPR:
    6457                 :      113811 :                 case MINUS_EXPR:
    6458                 :      113811 :                   real = build2 (resultcode, real_type, real, op1);
    6459                 :      113811 :                   break;
    6460                 :           0 :                 default:
    6461                 :           0 :                   gcc_unreachable();
    6462                 :             :                 }
    6463                 :             :             }
    6464                 :             :           else
    6465                 :             :             {
    6466                 :       33090 :               op1 = save_expr (op1);
    6467                 :       33090 :               real = cp_build_unary_op (REALPART_EXPR, op1, true, complain);
    6468                 :       33090 :               imag = cp_build_unary_op (IMAGPART_EXPR, op1, true, complain);
    6469                 :       33090 :               switch (code)
    6470                 :             :                 {
    6471                 :         701 :                 case MULT_EXPR:
    6472                 :         701 :                   op0 = save_expr (op0);
    6473                 :         701 :                   imag = build2 (resultcode, real_type, op0, imag);
    6474                 :             :                   /* Fall through.  */
    6475                 :       17342 :                 case PLUS_EXPR:
    6476                 :       17342 :                   real = build2 (resultcode, real_type, op0, real);
    6477                 :       17342 :                   break;
    6478                 :       15748 :                 case MINUS_EXPR:
    6479                 :       15748 :                   real = build2 (resultcode, real_type, op0, real);
    6480                 :       15748 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
    6481                 :       15748 :                   break;
    6482                 :           0 :                 default:
    6483                 :           0 :                   gcc_unreachable();
    6484                 :             :                 }
    6485                 :             :             }
    6486                 :      146901 :           result = build2 (COMPLEX_EXPR, result_type, real, imag);
    6487                 :      146901 :           if (semantic_result_type)
    6488                 :          32 :             result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6489                 :             :                              result);
    6490                 :      146901 :           return result;
    6491                 :             :         }
    6492                 :             : 
    6493                 :             :       /* For certain operations (which identify themselves by shorten != 0)
    6494                 :             :          if both args were extended from the same smaller type,
    6495                 :             :          do the arithmetic in that type and then extend.
    6496                 :             : 
    6497                 :             :          shorten !=0 and !=1 indicates a bitwise operation.
    6498                 :             :          For them, this optimization is safe only if
    6499                 :             :          both args are zero-extended or both are sign-extended.
    6500                 :             :          Otherwise, we might change the result.
    6501                 :             :          E.g., (short)-1 | (unsigned short)-1 is (int)-1
    6502                 :             :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
    6503                 :             : 
    6504                 :    70713424 :       if (shorten && none_complex)
    6505                 :             :         {
    6506                 :     3661400 :           final_type = result_type;
    6507                 :     3661400 :           result_type = shorten_binary_op (result_type, op0, op1,
    6508                 :             :                                            shorten == -1);
    6509                 :             :         }
    6510                 :             : 
    6511                 :             :       /* Shifts can be shortened if shifting right.  */
    6512                 :             : 
    6513                 :    70713424 :       if (short_shift)
    6514                 :             :         {
    6515                 :      703037 :           int unsigned_arg;
    6516                 :      703037 :           tree arg0 = get_narrower (op0, &unsigned_arg);
    6517                 :             :           /* We're not really warning here but when we set short_shift we
    6518                 :             :              used fold_for_warn to fold the operand.  */
    6519                 :      703037 :           tree const_op1 = fold_for_warn (op1);
    6520                 :             : 
    6521                 :      703037 :           final_type = result_type;
    6522                 :             : 
    6523                 :      703037 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
    6524                 :      647763 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
    6525                 :             : 
    6526                 :      703037 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
    6527                 :        1296 :               && tree_int_cst_sgn (const_op1) > 0
    6528                 :             :               /* We can shorten only if the shift count is less than the
    6529                 :             :                  number of bits in the smaller type size.  */
    6530                 :        1296 :               && compare_tree_int (const_op1,
    6531                 :        1296 :                                    TYPE_PRECISION (TREE_TYPE (arg0))) < 0
    6532                 :             :               /* We cannot drop an unsigned shift after sign-extension.  */
    6533                 :      704321 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
    6534                 :             :             {
    6535                 :             :               /* Do an unsigned shift if the operand was zero-extended.  */
    6536                 :        1277 :               result_type
    6537                 :        1277 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
    6538                 :        1277 :                                                     TREE_TYPE (arg0));
    6539                 :             :               /* Convert value-to-be-shifted to that type.  */
    6540                 :        1277 :               if (TREE_TYPE (op0) != result_type)
    6541                 :        1277 :                 op0 = convert (result_type, op0);
    6542                 :             :               converted = 1;
    6543                 :             :             }
    6544                 :             :         }
    6545                 :             : 
    6546                 :             :       /* Comparison operations are shortened too but differently.
    6547                 :             :          They identify themselves by setting short_compare = 1.  */
    6548                 :             : 
    6549                 :    70713424 :       if (short_compare)
    6550                 :             :         {
    6551                 :             :           /* We call shorten_compare only for diagnostics.  */
    6552                 :    23141552 :           tree xop0 = fold_simple (op0);
    6553                 :    23141552 :           tree xop1 = fold_simple (op1);
    6554                 :    23141552 :           tree xresult_type = result_type;
    6555                 :    23141552 :           enum tree_code xresultcode = resultcode;
    6556                 :    23141552 :           shorten_compare (location, &xop0, &xop1, &xresult_type,
    6557                 :             :                            &xresultcode);
    6558                 :             :         }
    6559                 :             : 
    6560                 :    47571766 :       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
    6561                 :    23141782 :           && warn_sign_compare
    6562                 :             :           /* Do not warn until the template is instantiated; we cannot
    6563                 :             :              bound the ranges of the arguments until that point.  */
    6564                 :      301956 :           && !processing_template_decl
    6565                 :      301956 :           && (complain & tf_warning)
    6566                 :      297350 :           && c_inhibit_evaluation_warnings == 0
    6567                 :             :           /* Even unsigned enum types promote to signed int.  We don't
    6568                 :             :              want to issue -Wsign-compare warnings for this case.  */
    6569                 :      283081 :           && !enum_cast_to_int (orig_op0)
    6570                 :    70996505 :           && !enum_cast_to_int (orig_op1))
    6571                 :             :         {
    6572                 :      283049 :           warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
    6573                 :             :                                  result_type, resultcode);
    6574                 :             :         }
    6575                 :             :     }
    6576                 :             : 
    6577                 :             :   /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
    6578                 :             :      Then the expression will be built.
    6579                 :             :      It will be given type FINAL_TYPE if that is nonzero;
    6580                 :             :      otherwise, it will be given type RESULT_TYPE.  */
    6581                 :    79676835 :   if (! converted)
    6582                 :             :     {
    6583                 :    76462563 :       warning_sentinel w (warn_sign_conversion, short_compare);
    6584                 :    76462563 :       if (!same_type_p (TREE_TYPE (op0), result_type))
    6585                 :     3135840 :         op0 = cp_convert_and_check (result_type, op0, complain);
    6586                 :    76462563 :       if (!same_type_p (TREE_TYPE (op1), result_type))
    6587                 :    14959068 :         op1 = cp_convert_and_check (result_type, op1, complain);
    6588                 :             : 
    6589                 :    76462563 :       if (op0 == error_mark_node || op1 == error_mark_node)
    6590                 :          73 :         return error_mark_node;
    6591                 :    76462563 :     }
    6592                 :             : 
    6593                 :    79676762 :   if (build_type == NULL_TREE)
    6594                 :    53281014 :     build_type = result_type;
    6595                 :             : 
    6596                 :    79676762 :   if (doing_shift
    6597                 :     3213652 :       && flag_strong_eval_order == 2
    6598                 :     3056980 :       && TREE_SIDE_EFFECTS (op1)
    6599                 :    79695848 :       && !processing_template_decl)
    6600                 :             :     {
    6601                 :             :       /* In C++17, in both op0 << op1 and op0 >> op1 op0 is sequenced before
    6602                 :             :          op1, so if op1 has side-effects, use SAVE_EXPR around op0.  */
    6603                 :       19086 :       op0 = cp_save_expr (op0);
    6604                 :       19086 :       instrument_expr = op0;
    6605                 :             :     }
    6606                 :             : 
    6607                 :    79676762 :   if (sanitize_flags_p ((SANITIZE_SHIFT
    6608                 :             :                          | SANITIZE_DIVIDE
    6609                 :             :                          | SANITIZE_FLOAT_DIVIDE
    6610                 :             :                          | SANITIZE_SI_OVERFLOW))
    6611                 :       11773 :       && current_function_decl != NULL_TREE
    6612                 :        9394 :       && !processing_template_decl
    6613                 :    79686156 :       && (doing_div_or_mod || doing_shift))
    6614                 :             :     {
    6615                 :             :       /* OP0 and/or OP1 might have side-effects.  */
    6616                 :        1017 :       op0 = cp_save_expr (op0);
    6617                 :        1017 :       op1 = cp_save_expr (op1);
    6618                 :        1017 :       op0 = fold_non_dependent_expr (op0, complain);
    6619                 :        1017 :       op1 = fold_non_dependent_expr (op1, complain);
    6620                 :        1017 :       tree instrument_expr1 = NULL_TREE;
    6621                 :        1017 :       if (doing_div_or_mod
    6622                 :        1017 :           && sanitize_flags_p (SANITIZE_DIVIDE
    6623                 :             :                                | SANITIZE_FLOAT_DIVIDE
    6624                 :             :                                | SANITIZE_SI_OVERFLOW))
    6625                 :             :         {
    6626                 :             :           /* For diagnostics we want to use the promoted types without
    6627                 :             :              shorten_binary_op.  So convert the arguments to the
    6628                 :             :              original result_type.  */
    6629                 :         551 :           tree cop0 = op0;
    6630                 :         551 :           tree cop1 = op1;
    6631                 :         551 :           if (TREE_TYPE (cop0) != orig_type)
    6632                 :           8 :             cop0 = cp_convert (orig_type, op0, complain);
    6633                 :         551 :           if (TREE_TYPE (cop1) != orig_type)
    6634                 :          35 :             cop1 = cp_convert (orig_type, op1, complain);
    6635                 :         551 :           instrument_expr1 = ubsan_instrument_division (location, cop0, cop1);
    6636                 :             :         }
    6637                 :         466 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
    6638                 :         358 :         instrument_expr1 = ubsan_instrument_shift (location, code, op0, op1);
    6639                 :        1017 :       if (instrument_expr != NULL)
    6640                 :          18 :         instrument_expr = add_stmt_to_compound (instrument_expr,
    6641                 :             :                                                 instrument_expr1);
    6642                 :             :       else
    6643                 :         999 :         instrument_expr = instrument_expr1;
    6644                 :             :     }
    6645                 :             : 
    6646                 :    79676762 :   result = build2_loc (location, resultcode, build_type, op0, op1);
    6647                 :    79676762 :   if (final_type != 0)
    6648                 :     4364437 :     result = cp_convert (final_type, result, complain);
    6649                 :             : 
    6650                 :    79676762 :   if (instrument_expr != NULL)
    6651                 :       19718 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    6652                 :             :                      instrument_expr, result);
    6653                 :             : 
    6654                 :    79676762 :   if (resultcode == SPACESHIP_EXPR && !processing_template_decl)
    6655                 :      106573 :     result = get_target_expr (result, complain);
    6656                 :             : 
    6657                 :    79676762 :   if (semantic_result_type)
    6658                 :       46664 :     result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, result);
    6659                 :             : 
    6660                 :    79676762 :   if (!c_inhibit_evaluation_warnings)
    6661                 :             :     {
    6662                 :    72152250 :       if (!processing_template_decl)
    6663                 :             :         {
    6664                 :    72152250 :           op0 = cp_fully_fold (op0);
    6665                 :             :           /* Only consider the second argument if the first isn't overflowed.  */
    6666                 :    72152250 :           if (!CONSTANT_CLASS_P (op0) || TREE_OVERFLOW_P (op0))
    6667                 :             :             return result;
    6668                 :    18795366 :           op1 = cp_fully_fold (op1);
    6669                 :    18795366 :           if (!CONSTANT_CLASS_P (op1) || TREE_OVERFLOW_P (op1))
    6670                 :             :             return result;
    6671                 :             :         }
    6672                 :           0 :       else if (!CONSTANT_CLASS_P (op0) || !CONSTANT_CLASS_P (op1)
    6673                 :           0 :                || TREE_OVERFLOW_P (op0) || TREE_OVERFLOW_P (op1))
    6674                 :             :         return result;
    6675                 :             : 
    6676                 :    13756923 :       tree result_ovl = fold_build2 (resultcode, build_type, op0, op1);
    6677                 :    13756923 :       if (TREE_OVERFLOW_P (result_ovl))
    6678                 :         232 :         overflow_warning (location, result_ovl);
    6679                 :             :     }
    6680                 :             : 
    6681                 :             :   return result;
    6682                 :             : }
    6683                 :             : 
    6684                 :             : /* Build a VEC_PERM_EXPR.
    6685                 :             :    This is a simple wrapper for c_build_vec_perm_expr.  */
    6686                 :             : tree
    6687                 :       15236 : build_x_vec_perm_expr (location_t loc,
    6688                 :             :                         tree arg0, tree arg1, tree arg2,
    6689                 :             :                         tsubst_flags_t complain)
    6690                 :             : {
    6691                 :       15236 :   tree orig_arg0 = arg0;
    6692                 :       15236 :   tree orig_arg1 = arg1;
    6693                 :       15236 :   tree orig_arg2 = arg2;
    6694                 :       15236 :   if (processing_template_decl)
    6695                 :             :     {
    6696                 :          14 :       if (type_dependent_expression_p (arg0)
    6697                 :           8 :           || type_dependent_expression_p (arg1)
    6698                 :          22 :           || type_dependent_expression_p (arg2))
    6699                 :           6 :         return build_min_nt_loc (loc, VEC_PERM_EXPR, arg0, arg1, arg2);
    6700                 :             :     }
    6701                 :       15230 :   tree exp = c_build_vec_perm_expr (loc, arg0, arg1, arg2, complain & tf_error);
    6702                 :       15230 :   if (processing_template_decl && exp != error_mark_node)
    6703                 :           8 :     return build_min_non_dep (VEC_PERM_EXPR, exp, orig_arg0,
    6704                 :           8 :                               orig_arg1, orig_arg2);
    6705                 :             :   return exp;
    6706                 :             : }
    6707                 :             : 
    6708                 :             : /* Build a VEC_PERM_EXPR.
    6709                 :             :    This is a simple wrapper for c_build_shufflevector.  */
    6710                 :             : tree
    6711                 :       35564 : build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
    6712                 :             :                        tsubst_flags_t complain)
    6713                 :             : {
    6714                 :       35564 :   tree arg0 = (*args)[0];
    6715                 :       35564 :   tree arg1 = (*args)[1];
    6716                 :       35564 :   if (processing_template_decl)
    6717                 :             :     {
    6718                 :          39 :       for (unsigned i = 0; i < args->length (); ++i)
    6719                 :          35 :         if (i <= 1
    6720                 :          35 :             ? type_dependent_expression_p ((*args)[i])
    6721                 :          10 :             : instantiation_dependent_expression_p ((*args)[i]))
    6722                 :             :           {
    6723                 :          15 :             tree exp = build_min_nt_call_vec (NULL, args);
    6724                 :          15 :             CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    6725                 :          15 :             return exp;
    6726                 :             :           }
    6727                 :             :     }
    6728                 :       35549 :   auto_vec<tree, 16> mask;
    6729                 :      481153 :   for (unsigned i = 2; i < args->length (); ++i)
    6730                 :             :     {
    6731                 :      445604 :       tree idx = fold_non_dependent_expr ((*args)[i], complain);
    6732                 :      445604 :       mask.safe_push (idx);
    6733                 :             :     }
    6734                 :       35549 :   tree exp = c_build_shufflevector (loc, arg0, arg1, mask, complain & tf_error);
    6735                 :       35549 :   if (processing_template_decl && exp != error_mark_node)
    6736                 :             :     {
    6737                 :           4 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    6738                 :           4 :       CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    6739                 :             :     }
    6740                 :       35549 :   return exp;
    6741                 :       35549 : }
    6742                 :             : 
    6743                 :             : /* Return a tree for the sum or difference (RESULTCODE says which)
    6744                 :             :    of pointer PTROP and integer INTOP.  */
    6745                 :             : 
    6746                 :             : static tree
    6747                 :     3763850 : cp_pointer_int_sum (location_t loc, enum tree_code resultcode, tree ptrop,
    6748                 :             :                     tree intop, tsubst_flags_t complain)
    6749                 :             : {
    6750                 :     3763850 :   tree res_type = TREE_TYPE (ptrop);
    6751                 :             : 
    6752                 :             :   /* pointer_int_sum() uses size_in_bytes() on the TREE_TYPE(res_type)
    6753                 :             :      in certain circumstance (when it's valid to do so).  So we need
    6754                 :             :      to make sure it's complete.  We don't need to check here, if we
    6755                 :             :      can actually complete it at all, as those checks will be done in
    6756                 :             :      pointer_int_sum() anyway.  */
    6757                 :     3763850 :   complete_type (TREE_TYPE (res_type));
    6758                 :             : 
    6759                 :     3763850 :   return pointer_int_sum (loc, resultcode, ptrop,
    6760                 :     3763850 :                           intop, complain & tf_warning_or_error);
    6761                 :             : }
    6762                 :             : 
    6763                 :             : /* Return a tree for the difference of pointers OP0 and OP1.
    6764                 :             :    The resulting tree has type int.  If POINTER_SUBTRACT sanitization is
    6765                 :             :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    6766                 :             : 
    6767                 :             : static tree
    6768                 :     1153579 : pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
    6769                 :             :               tsubst_flags_t complain, tree *instrument_expr)
    6770                 :             : {
    6771                 :     1153579 :   tree result, inttype;
    6772                 :     1153579 :   tree restype = ptrdiff_type_node;
    6773                 :     1153579 :   tree target_type = TREE_TYPE (ptrtype);
    6774                 :             : 
    6775                 :     1153579 :   if (!complete_type_or_maybe_complain (target_type, NULL_TREE, complain))
    6776                 :          10 :     return error_mark_node;
    6777                 :             : 
    6778                 :     1153569 :   if (VOID_TYPE_P (target_type))
    6779                 :             :     {
    6780                 :           0 :       if (complain & tf_error)
    6781                 :           0 :         permerror (loc, "ISO C++ forbids using pointer of "
    6782                 :             :                    "type %<void *%> in subtraction");
    6783                 :             :       else
    6784                 :           0 :         return error_mark_node;
    6785                 :             :     }
    6786                 :     1153569 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    6787                 :             :     {
    6788                 :          16 :       if (complain & tf_error)
    6789                 :           4 :         permerror (loc, "ISO C++ forbids using pointer to "
    6790                 :             :                    "a function in subtraction");
    6791                 :             :       else
    6792                 :          12 :         return error_mark_node;
    6793                 :             :     }
    6794                 :     1153557 :   if (TREE_CODE (target_type) == METHOD_TYPE)
    6795                 :             :     {
    6796                 :           0 :       if (complain & tf_error)
    6797                 :           0 :         permerror (loc, "ISO C++ forbids using pointer to "
    6798                 :             :                    "a method in subtraction");
    6799                 :             :       else
    6800                 :           0 :         return error_mark_node;
    6801                 :             :     }
    6802                 :     2307114 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    6803                 :     1153557 :                                  TREE_TYPE (TREE_TYPE (op0)),
    6804                 :     1153557 :                                  !(complain & tf_error))
    6805                 :     2307114 :            || !verify_type_context (loc, TCTX_POINTER_ARITH,
    6806                 :     1153557 :                                     TREE_TYPE (TREE_TYPE (op1)),
    6807                 :             :                                     !(complain & tf_error)))
    6808                 :           0 :     return error_mark_node;
    6809                 :             : 
    6810                 :             :   /* Determine integer type result of the subtraction.  This will usually
    6811                 :             :      be the same as the result type (ptrdiff_t), but may need to be a wider
    6812                 :             :      type if pointers for the address space are wider than ptrdiff_t.  */
    6813                 :     1153557 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    6814                 :           0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    6815                 :             :   else
    6816                 :             :     inttype = restype;
    6817                 :             : 
    6818                 :     1153557 :   if (!processing_template_decl
    6819                 :     1153557 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    6820                 :             :     {
    6821                 :          84 :       op0 = save_expr (op0);
    6822                 :          84 :       op1 = save_expr (op1);
    6823                 :             : 
    6824                 :          84 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    6825                 :          84 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    6826                 :             :     }
    6827                 :             : 
    6828                 :             :   /* First do the subtraction, then build the divide operator
    6829                 :             :      and only convert at the very end.
    6830                 :             :      Do not do default conversions in case restype is a short type.  */
    6831                 :             : 
    6832                 :             :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    6833                 :             :      pointers.  If some platform cannot provide that, or has a larger
    6834                 :             :      ptrdiff_type to support differences larger than half the address
    6835                 :             :      space, cast the pointers to some larger integer type and do the
    6836                 :             :      computations in that type.  */
    6837                 :     1153557 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    6838                 :           0 :     op0 = cp_build_binary_op (loc,
    6839                 :             :                               MINUS_EXPR,
    6840                 :             :                               cp_convert (inttype, op0, complain),
    6841                 :             :                               cp_convert (inttype, op1, complain),
    6842                 :             :                               complain);
    6843                 :             :   else
    6844                 :     1153557 :     op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    6845                 :             : 
    6846                 :             :   /* This generates an error if op1 is a pointer to an incomplete type.  */
    6847                 :     1153557 :   if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
    6848                 :             :     {
    6849                 :           0 :       if (complain & tf_error)
    6850                 :           0 :         error_at (loc, "invalid use of a pointer to an incomplete type in "
    6851                 :             :                   "pointer arithmetic");
    6852                 :             :       else
    6853                 :           0 :         return error_mark_node;
    6854                 :             :     }
    6855                 :             : 
    6856                 :     1153557 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (op1)))
    6857                 :             :     {
    6858                 :          20 :       if (complain & tf_error)
    6859                 :          20 :         error_at (loc, "arithmetic on pointer to an empty aggregate");
    6860                 :             :       else
    6861                 :           0 :         return error_mark_node;
    6862                 :             :     }
    6863                 :             : 
    6864                 :     1153557 :   op1 = (TYPE_PTROB_P (ptrtype)
    6865                 :     2307114 :          ? size_in_bytes_loc (loc, target_type)
    6866                 :             :          : integer_one_node);
    6867                 :             : 
    6868                 :             :   /* Do the division.  */
    6869                 :             : 
    6870                 :     1153557 :   result = build2_loc (loc, EXACT_DIV_EXPR, inttype, op0,
    6871                 :             :                        cp_convert (inttype, op1, complain));
    6872                 :     1153557 :   return cp_convert (restype, result, complain);
    6873                 :             : }
    6874                 :             : 
    6875                 :             : /* Construct and perhaps optimize a tree representation
    6876                 :             :    for a unary operation.  CODE, a tree_code, specifies the operation
    6877                 :             :    and XARG is the operand.  */
    6878                 :             : 
    6879                 :             : tree
    6880                 :    52373137 : build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg,
    6881                 :             :                   tree lookups, tsubst_flags_t complain)
    6882                 :             : {
    6883                 :    52373137 :   tree orig_expr = xarg;
    6884                 :    52373137 :   tree exp;
    6885                 :    52373137 :   int ptrmem = 0;
    6886                 :    52373137 :   tree overload = NULL_TREE;
    6887                 :             : 
    6888                 :    52373137 :   if (processing_template_decl)
    6889                 :             :     {
    6890                 :    36346391 :       if (type_dependent_expression_p (xarg))
    6891                 :             :         {
    6892                 :    24612440 :           tree e = build_min_nt_loc (loc, code, xarg.get_value (), NULL_TREE);
    6893                 :    24612440 :           TREE_TYPE (e) = build_dependent_operator_type (lookups, code, false);
    6894                 :    24612440 :           return e;
    6895                 :             :         }
    6896                 :             :     }
    6897                 :             : 
    6898                 :    27760697 :   exp = NULL_TREE;
    6899                 :             : 
    6900                 :             :   /* [expr.unary.op] says:
    6901                 :             : 
    6902                 :             :        The address of an object of incomplete type can be taken.
    6903                 :             : 
    6904                 :             :      (And is just the ordinary address operator, not an overloaded
    6905                 :             :      "operator &".)  However, if the type is a template
    6906                 :             :      specialization, we must complete the type at this point so that
    6907                 :             :      an overloaded "operator &" will be available if required.  */
    6908                 :    27760697 :   if (code == ADDR_EXPR
    6909                 :     3254813 :       && TREE_CODE (xarg) != TEMPLATE_ID_EXPR
    6910                 :    31015171 :       && ((CLASS_TYPE_P (TREE_TYPE (xarg))
    6911                 :     1646144 :            && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (xarg))))
    6912                 :     3252489 :           || (TREE_CODE (xarg) == OFFSET_REF)))
    6913                 :             :     /* Don't look for a function.  */;
    6914                 :             :   else
    6915                 :    27695571 :     exp = build_new_op (loc, code, LOOKUP_NORMAL, xarg, NULL_TREE,
    6916                 :             :                         NULL_TREE, lookups, &overload, complain);
    6917                 :             : 
    6918                 :    27760697 :   if (!exp && code == ADDR_EXPR)
    6919                 :             :     {
    6920                 :     3254524 :       if (is_overloaded_fn (xarg))
    6921                 :             :         {
    6922                 :      360719 :           tree fn = get_first_fn (xarg);
    6923                 :      721438 :           if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
    6924                 :             :             {
    6925                 :          16 :               if (complain & tf_error)
    6926                 :          28 :                 error_at (loc, DECL_CONSTRUCTOR_P (fn)
    6927                 :             :                           ? G_("taking address of constructor %qD")
    6928                 :             :                           : G_("taking address of destructor %qD"),
    6929                 :             :                           fn);
    6930                 :          16 :               return error_mark_node;
    6931                 :             :             }
    6932                 :             :         }
    6933                 :             : 
    6934                 :             :       /* A pointer to member-function can be formed only by saying
    6935                 :             :          &X::mf.  */
    6936                 :     3254500 :       if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
    6937                 :     3314487 :           && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
    6938                 :             :         {
    6939                 :          12 :           if (TREE_CODE (xarg) != OFFSET_REF
    6940                 :          12 :               || !TYPE_P (TREE_OPERAND (xarg, 0)))
    6941                 :             :             {
    6942                 :          12 :               if (complain & tf_error)
    6943                 :             :                 {
    6944                 :          12 :                   error_at (loc, "invalid use of %qE to form a "
    6945                 :             :                             "pointer-to-member-function", xarg.get_value ());
    6946                 :          12 :                   if (TREE_CODE (xarg) != OFFSET_REF)
    6947                 :           8 :                     inform (loc, "  a qualified-id is required");
    6948                 :             :                 }
    6949                 :          12 :               return error_mark_node;
    6950                 :             :             }
    6951                 :             :           else
    6952                 :             :             {
    6953                 :           0 :               if (complain & tf_error)
    6954                 :           0 :                 error_at (loc, "parentheses around %qE cannot be used to "
    6955                 :             :                           "form a pointer-to-member-function",
    6956                 :             :                           xarg.get_value ());
    6957                 :             :               else
    6958                 :           0 :                 return error_mark_node;
    6959                 :           0 :               PTRMEM_OK_P (xarg) = 1;
    6960                 :             :             }
    6961                 :             :         }
    6962                 :             : 
    6963                 :     3254496 :       if (TREE_CODE (xarg) == OFFSET_REF)
    6964                 :             :         {
    6965                 :       63121 :           ptrmem = PTRMEM_OK_P (xarg);
    6966                 :             : 
    6967                 :           0 :           if (!ptrmem && !flag_ms_extensions
    6968                 :       63121 :               && TREE_CODE (TREE_TYPE (TREE_OPERAND (xarg, 1))) == METHOD_TYPE)
    6969                 :             :             {
    6970                 :             :               /* A single non-static member, make sure we don't allow a
    6971                 :             :                  pointer-to-member.  */
    6972                 :           0 :               xarg = build2 (OFFSET_REF, TREE_TYPE (xarg),
    6973                 :           0 :                              TREE_OPERAND (xarg, 0),
    6974                 :           0 :                              ovl_make (TREE_OPERAND (xarg, 1)));
    6975                 :           0 :               PTRMEM_OK_P (xarg) = ptrmem;
    6976                 :             :             }
    6977                 :             :         }
    6978                 :             : 
    6979                 :     6508992 :       exp = cp_build_addr_expr_strict (xarg, complain);
    6980                 :             : 
    6981                 :     3254496 :       if (TREE_CODE (exp) == PTRMEM_CST)
    6982                 :       62150 :         PTRMEM_CST_LOCATION (exp) = loc;
    6983                 :             :       else
    6984                 :     3192346 :         protected_set_expr_location (exp, loc);
    6985                 :             :     }
    6986                 :             : 
    6987                 :    27760669 :   if (processing_template_decl && exp != error_mark_node)
    6988                 :             :     {
    6989                 :    11733791 :       if (overload != NULL_TREE)
    6990                 :      154397 :         return (build_min_non_dep_op_overload
    6991                 :      154397 :                 (code, exp, overload, orig_expr, integer_zero_node));
    6992                 :             : 
    6993                 :    11579394 :       exp = build_min_non_dep (code, exp, orig_expr,
    6994                 :             :                                /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
    6995                 :             :     }
    6996                 :    27606272 :   if (TREE_CODE (exp) == ADDR_EXPR)
    6997                 :     2492999 :     PTRMEM_OK_P (exp) = ptrmem;
    6998                 :             :   return exp;
    6999                 :             : }
    7000                 :             : 
    7001                 :             : /* Construct and perhaps optimize a tree representation
    7002                 :             :    for __builtin_addressof operation.  ARG specifies the operand.  */
    7003                 :             : 
    7004                 :             : tree
    7005                 :      373007 : cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain)
    7006                 :             : {
    7007                 :      373007 :   tree orig_expr = arg;
    7008                 :             : 
    7009                 :      373007 :   if (processing_template_decl)
    7010                 :             :     {
    7011                 :      116453 :       if (type_dependent_expression_p (arg))
    7012                 :      116453 :         return build_min_nt_loc (loc, ADDRESSOF_EXPR, arg, NULL_TREE);
    7013                 :             :     }
    7014                 :             : 
    7015                 :      513108 :   tree exp = cp_build_addr_expr_strict (arg, complain);
    7016                 :             : 
    7017                 :      256554 :   if (processing_template_decl && exp != error_mark_node)
    7018                 :           0 :     exp = build_min_non_dep (ADDRESSOF_EXPR, exp, orig_expr, NULL_TREE);
    7019                 :             :   return exp;
    7020                 :             : }
    7021                 :             : 
    7022                 :             : /* Like c_common_truthvalue_conversion, but handle pointer-to-member
    7023                 :             :    constants, where a null value is represented by an INTEGER_CST of
    7024                 :             :    -1.  */
    7025                 :             : 
    7026                 :             : tree
    7027                 :     8036963 : cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
    7028                 :             : {
    7029                 :     8036963 :   tree type = TREE_TYPE (expr);
    7030                 :     8036963 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    7031                 :     7007450 :   if (TYPE_PTR_OR_PTRMEM_P (type)
    7032                 :             :       /* Avoid ICE on invalid use of non-static member function.  */
    7033                 :    15044095 :       || TREE_CODE (expr) == FUNCTION_DECL)
    7034                 :     1029831 :     return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain);
    7035                 :             :   else
    7036                 :     7007132 :     return c_common_truthvalue_conversion (loc, expr);
    7037                 :             : }
    7038                 :             : 
    7039                 :             : /* Returns EXPR contextually converted to bool.  */
    7040                 :             : 
    7041                 :             : tree
    7042                 :    42671359 : contextual_conv_bool (tree expr, tsubst_flags_t complain)
    7043                 :             : {
    7044                 :    42671359 :   return perform_implicit_conversion_flags (boolean_type_node, expr,
    7045                 :    42671359 :                                             complain, LOOKUP_NORMAL);
    7046                 :             : }
    7047                 :             : 
    7048                 :             : /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  This
    7049                 :             :    is a low-level function; most callers should use maybe_convert_cond.  */
    7050                 :             : 
    7051                 :             : tree
    7052                 :    38248897 : condition_conversion (tree expr)
    7053                 :             : {
    7054                 :    38248897 :   tree t = contextual_conv_bool (expr, tf_warning_or_error);
    7055                 :    38248897 :   if (!processing_template_decl)
    7056                 :    18936979 :     t = fold_build_cleanup_point_expr (boolean_type_node, t);
    7057                 :    38248897 :   return t;
    7058                 :             : }
    7059                 :             : 
    7060                 :             : /* Returns the address of T.  This function will fold away
    7061                 :             :    ADDR_EXPR of INDIRECT_REF.  This is only for low-level usage;
    7062                 :             :    most places should use cp_build_addr_expr instead.  */
    7063                 :             : 
    7064                 :             : tree
    7065                 :   235121112 : build_address (tree t)
    7066                 :             : {
    7067                 :   235121112 :   if (error_operand_p (t) || !cxx_mark_addressable (t))
    7068                 :          28 :     return error_mark_node;
    7069                 :   235121084 :   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR
    7070                 :             :                        || processing_template_decl);
    7071                 :   235121084 :   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
    7072                 :   235121084 :   if (TREE_CODE (t) != ADDR_EXPR)
    7073                 :    43624343 :     t = rvalue (t);
    7074                 :             :   return t;
    7075                 :             : }
    7076                 :             : 
    7077                 :             : /* Return a NOP_EXPR converting EXPR to TYPE.  */
    7078                 :             : 
    7079                 :             : tree
    7080                 :   406462797 : build_nop (tree type, tree expr)
    7081                 :             : {
    7082                 :   406462797 :   if (type == error_mark_node || error_operand_p (expr))
    7083                 :             :     return expr;
    7084                 :   406462708 :   return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr);
    7085                 :             : }
    7086                 :             : 
    7087                 :             : /* Take the address of ARG, whatever that means under C++ semantics.
    7088                 :             :    If STRICT_LVALUE is true, require an lvalue; otherwise, allow xvalues
    7089                 :             :    and class rvalues as well.
    7090                 :             : 
    7091                 :             :    Nothing should call this function directly; instead, callers should use
    7092                 :             :    cp_build_addr_expr or cp_build_addr_expr_strict.  */
    7093                 :             : 
    7094                 :             : static tree
    7095                 :   176357324 : cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
    7096                 :             : {
    7097                 :   176357324 :   tree argtype;
    7098                 :   176357324 :   tree val;
    7099                 :             : 
    7100                 :   176357324 :   if (!arg || error_operand_p (arg))
    7101                 :          13 :     return error_mark_node;
    7102                 :             : 
    7103                 :   176357311 :   arg = mark_lvalue_use (arg);
    7104                 :   176357311 :   if (error_operand_p (arg))
    7105                 :           3 :     return error_mark_node;
    7106                 :             : 
    7107                 :   176357308 :   argtype = lvalue_type (arg);
    7108                 :   176357308 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    7109                 :             : 
    7110                 :   176357308 :   gcc_assert (!(identifier_p (arg) && IDENTIFIER_ANY_OP_P (arg)));
    7111                 :             : 
    7112                 :    11444333 :   if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
    7113                 :   176357544 :       && !really_overloaded_fn (arg))
    7114                 :             :     {
    7115                 :             :       /* They're trying to take the address of a unique non-static
    7116                 :             :          member function.  This is ill-formed (except in MS-land),
    7117                 :             :          but let's try to DTRT.
    7118                 :             :          Note: We only handle unique functions here because we don't
    7119                 :             :          want to complain if there's a static overload; non-unique
    7120                 :             :          cases will be handled by instantiate_type.  But we need to
    7121                 :             :          handle this case here to allow casts on the resulting PMF.
    7122                 :             :          We could defer this in non-MS mode, but it's easier to give
    7123                 :             :          a useful error here.  */
    7124                 :             : 
    7125                 :             :       /* Inside constant member functions, the `this' pointer
    7126                 :             :          contains an extra const qualifier.  TYPE_MAIN_VARIANT
    7127                 :             :          is used here to remove this const from the diagnostics
    7128                 :             :          and the created OFFSET_REF.  */
    7129                 :          82 :       tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
    7130                 :          82 :       tree fn = get_first_fn (TREE_OPERAND (arg, 1));
    7131                 :          82 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7132                 :           0 :         return error_mark_node;
    7133                 :             :       /* Until microsoft headers are known to incorrectly take the address of
    7134                 :             :          unqualified xobj member functions we should not support this
    7135                 :             :          extension.
    7136                 :             :          See comment in class.cc:resolve_address_of_overloaded_function for
    7137                 :             :          the extended reasoning.  */
    7138                 :          82 :       if (!flag_ms_extensions || DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7139                 :             :         {
    7140                 :          74 :           auto_diagnostic_group d;
    7141                 :          74 :           tree name = DECL_NAME (fn);
    7142                 :          74 :           if (!(complain & tf_error))
    7143                 :           0 :             return error_mark_node;
    7144                 :          74 :           else if (current_class_type
    7145                 :          74 :                    && TREE_OPERAND (arg, 0) == current_class_ref)
    7146                 :             :             /* An expression like &memfn.  */
    7147                 :          38 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7148                 :          28 :               permerror (loc,
    7149                 :             :                          "ISO C++ forbids taking the address of an unqualified"
    7150                 :             :                          " or parenthesized non-static member function to form"
    7151                 :             :                          " a pointer to member function.  Say %<&%T::%D%>",
    7152                 :             :                          base, name);
    7153                 :             :             else
    7154                 :          10 :               error_at (loc,
    7155                 :             :                         "ISO C++ forbids taking the address of an unqualified"
    7156                 :             :                         " or parenthesized non-static member function to form"
    7157                 :             :                         " a pointer to explicit object member function");
    7158                 :             :           else
    7159                 :          36 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7160                 :          12 :               permerror (loc,
    7161                 :             :                          "ISO C++ forbids taking the address of a bound member"
    7162                 :             :                          " function to form a pointer to member function."
    7163                 :             :                          "  Say %<&%T::%D%>",
    7164                 :             :                          base, name);
    7165                 :             :             else
    7166                 :          24 :               error_at (loc,
    7167                 :             :                         "ISO C++ forbids taking the address of a bound member"
    7168                 :             :                         " function to form a pointer to explicit object member"
    7169                 :             :                         " function");
    7170                 :          74 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7171                 :          34 :             inform (loc,
    7172                 :             :                     "a pointer to explicit object member function can only be "
    7173                 :             :                     "formed with %<&%T::%D%>", base, name);
    7174                 :          74 :         }
    7175                 :          82 :       arg = build_offset_ref (base, fn, /*address_p=*/true, complain);
    7176                 :             :     }
    7177                 :             : 
    7178                 :             :   /* Uninstantiated types are all functions.  Taking the
    7179                 :             :      address of a function is a no-op, so just return the
    7180                 :             :      argument.  */
    7181                 :   176357308 :   if (type_unknown_p (arg))
    7182                 :        1850 :     return build1 (ADDR_EXPR, unknown_type_node, arg);
    7183                 :             : 
    7184                 :   176355458 :   if (TREE_CODE (arg) == OFFSET_REF)
    7185                 :             :     /* We want a pointer to member; bypass all the code for actually taking
    7186                 :             :        the address of something.  */
    7187                 :       62266 :     goto offset_ref;
    7188                 :             : 
    7189                 :             :   /* Anything not already handled and not a true memory reference
    7190                 :             :      is an error.  */
    7191                 :   176293192 :   if (!FUNC_OR_METHOD_TYPE_P (argtype))
    7192                 :             :     {
    7193                 :    90759714 :       cp_lvalue_kind kind = lvalue_kind (arg);
    7194                 :    90759714 :       if (kind == clk_none)
    7195                 :             :         {
    7196                 :          28 :           if (complain & tf_error)
    7197                 :          28 :             lvalue_error (loc, lv_addressof);
    7198                 :          28 :           return error_mark_node;
    7199                 :             :         }
    7200                 :    90759686 :       if (strict_lvalue && (kind & (clk_rvalueref|clk_class)))
    7201                 :             :         {
    7202                 :          43 :           if (!(complain & tf_error))
    7203                 :           9 :             return error_mark_node;
    7204                 :             :           /* Make this a permerror because we used to accept it.  */
    7205                 :          34 :           permerror (loc, "taking address of rvalue");
    7206                 :             :         }
    7207                 :             :     }
    7208                 :             : 
    7209                 :   176293155 :   if (TYPE_REF_P (argtype))
    7210                 :             :     {
    7211                 :         243 :       tree type = build_pointer_type (TREE_TYPE (argtype));
    7212                 :         243 :       arg = build1 (CONVERT_EXPR, type, arg);
    7213                 :         243 :       return arg;
    7214                 :             :     }
    7215                 :   176292912 :   else if (pedantic && DECL_MAIN_P (tree_strip_any_location_wrapper (arg)))
    7216                 :             :     {
    7217                 :             :       /* ARM $3.4 */
    7218                 :             :       /* Apparently a lot of autoconf scripts for C++ packages do this,
    7219                 :             :          so only complain if -Wpedantic.  */
    7220                 :          12 :       if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
    7221                 :          12 :         pedwarn (loc, OPT_Wpedantic,
    7222                 :             :                  "ISO C++ forbids taking address of function %<::main%>");
    7223                 :           0 :       else if (flag_pedantic_errors)
    7224                 :           0 :         return error_mark_node;
    7225                 :             :     }
    7226                 :             : 
    7227                 :             :   /* Let &* cancel out to simplify resulting code.  */
    7228                 :   176292912 :   if (INDIRECT_REF_P (arg))
    7229                 :             :     {
    7230                 :    57108414 :       arg = TREE_OPERAND (arg, 0);
    7231                 :    57108414 :       if (TYPE_REF_P (TREE_TYPE (arg)))
    7232                 :             :         {
    7233                 :    31490802 :           tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
    7234                 :    31490802 :           arg = build1 (CONVERT_EXPR, type, arg);
    7235                 :             :         }
    7236                 :             :       else
    7237                 :             :         /* Don't let this be an lvalue.  */
    7238                 :    25617612 :         arg = rvalue (arg);
    7239                 :    57108414 :       return arg;
    7240                 :             :     }
    7241                 :             : 
    7242                 :             :   /* Handle complex lvalues (when permitted)
    7243                 :             :      by reduction to simpler cases.  */
    7244                 :   119184498 :   val = unary_complex_lvalue (ADDR_EXPR, arg);
    7245                 :   119184498 :   if (val != 0)
    7246                 :             :     return val;
    7247                 :             : 
    7248                 :   118735712 :   switch (TREE_CODE (arg))
    7249                 :             :     {
    7250                 :           0 :     CASE_CONVERT:
    7251                 :           0 :     case FLOAT_EXPR:
    7252                 :           0 :     case FIX_TRUNC_EXPR:
    7253                 :             :       /* We should have handled this above in the lvalue_kind check.  */
    7254                 :           0 :       gcc_unreachable ();
    7255                 :       55903 :       break;
    7256                 :             : 
    7257                 :       55903 :     case BASELINK:
    7258                 :       55903 :       arg = BASELINK_FUNCTIONS (arg);
    7259                 :             :       /* Fall through.  */
    7260                 :             : 
    7261                 :       55903 :     case OVERLOAD:
    7262                 :       55903 :       arg = OVL_FIRST (arg);
    7263                 :             :       break;
    7264                 :             : 
    7265                 :       62266 :     case OFFSET_REF:
    7266                 :       62266 :     offset_ref:
    7267                 :             :       /* Turn a reference to a non-static data member into a
    7268                 :             :          pointer-to-member.  */
    7269                 :       62266 :       {
    7270                 :       62266 :         tree type;
    7271                 :       62266 :         tree t;
    7272                 :             : 
    7273                 :       62266 :         gcc_assert (PTRMEM_OK_P (arg));
    7274                 :             : 
    7275                 :       62266 :         t = TREE_OPERAND (arg, 1);
    7276                 :       62266 :         if (TYPE_REF_P (TREE_TYPE (t)))
    7277                 :             :           {
    7278                 :          18 :             if (complain & tf_error)
    7279                 :          18 :               error_at (loc,
    7280                 :             :                         "cannot create pointer to reference member %qD", t);
    7281                 :          18 :             return error_mark_node;
    7282                 :             :           }
    7283                 :             : 
    7284                 :             :         /* Forming a pointer-to-member is a use of non-pure-virtual fns.  */
    7285                 :       62248 :         if (TREE_CODE (t) == FUNCTION_DECL
    7286                 :       60110 :             && !DECL_PURE_VIRTUAL_P (t)
    7287                 :      122332 :             && !mark_used (t, complain) && !(complain & tf_error))
    7288                 :           3 :           return error_mark_node;
    7289                 :             : 
    7290                 :             :         /* Pull out the function_decl for a single xobj member function, and
    7291                 :             :            let the rest of this function handle it.  This is similar to how
    7292                 :             :            static member functions are handled in the BASELINK case above.  */
    7293                 :       62245 :         if (DECL_XOBJ_MEMBER_FUNCTION_P (t))
    7294                 :             :           {
    7295                 :             :             arg = t;
    7296                 :             :             break;
    7297                 :             :           }
    7298                 :             : 
    7299                 :       62189 :         type = build_ptrmem_type (context_for_name_lookup (t),
    7300                 :       62189 :                                   TREE_TYPE (t));
    7301                 :       62189 :         t = make_ptrmem_cst (type, t);
    7302                 :       62189 :         return t;
    7303                 :             :       }
    7304                 :             : 
    7305                 :             :     default:
    7306                 :             :       break;
    7307                 :             :     }
    7308                 :             : 
    7309                 :   118735768 :   if (argtype != error_mark_node)
    7310                 :   118735768 :     argtype = build_pointer_type (argtype);
    7311                 :             : 
    7312                 :   118735768 :   if (bitfield_p (arg))
    7313                 :             :     {
    7314                 :          41 :       if (complain & tf_error)
    7315                 :          41 :         error_at (loc, "attempt to take address of bit-field");
    7316                 :          41 :       return error_mark_node;
    7317                 :             :     }
    7318                 :             : 
    7319                 :             :   /* In a template, we are processing a non-dependent expression
    7320                 :             :      so we can just form an ADDR_EXPR with the correct type.  */
    7321                 :   118735727 :   if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
    7322                 :             :     {
    7323                 :   107564041 :       if (!mark_single_function (arg, complain))
    7324                 :           3 :         return error_mark_node;
    7325                 :   107564038 :       val = build_address (arg);
    7326                 :   107564038 :       if (TREE_CODE (arg) == OFFSET_REF)
    7327                 :           0 :         PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
    7328                 :             :     }
    7329                 :    11171686 :   else if (BASELINK_P (TREE_OPERAND (arg, 1)))
    7330                 :             :     {
    7331                 :          32 :       tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
    7332                 :             : 
    7333                 :             :       /* We can only get here with a single static member
    7334                 :             :          function.  */
    7335                 :          32 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    7336                 :             :                   && DECL_STATIC_FUNCTION_P (fn));
    7337                 :          32 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7338                 :           0 :         return error_mark_node;
    7339                 :          32 :       val = build_address (fn);
    7340                 :          32 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
    7341                 :             :         /* Do not lose object's side effects.  */
    7342                 :          16 :         val = build2 (COMPOUND_EXPR, TREE_TYPE (val),
    7343                 :          16 :                       TREE_OPERAND (arg, 0), val);
    7344                 :             :     }
    7345                 :             :   else
    7346                 :             :     {
    7347                 :    11171654 :       tree object = TREE_OPERAND (arg, 0);
    7348                 :    11171654 :       tree field = TREE_OPERAND (arg, 1);
    7349                 :    11171654 :       gcc_assert (same_type_ignoring_top_level_qualifiers_p
    7350                 :             :                   (TREE_TYPE (object), decl_type_context (field)));
    7351                 :    11171654 :       val = build_address (arg);
    7352                 :             :     }
    7353                 :             : 
    7354                 :   118735724 :   if (TYPE_PTR_P (argtype)
    7355                 :   118735724 :       && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
    7356                 :             :     {
    7357                 :        1148 :       build_ptrmemfunc_type (argtype);
    7358                 :        1148 :       val = build_ptrmemfunc (argtype, val, 0,
    7359                 :             :                               /*c_cast_p=*/false,
    7360                 :             :                               complain);
    7361                 :             :     }
    7362                 :             : 
    7363                 :             :   /* Ensure we have EXPR_LOCATION set for possible later diagnostics.  */
    7364                 :   118735724 :   if (TREE_CODE (val) == ADDR_EXPR
    7365                 :   118735724 :       && TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
    7366                 :    83856140 :     SET_EXPR_LOCATION (val, input_location);
    7367                 :             : 
    7368                 :             :   return val;
    7369                 :             : }
    7370                 :             : 
    7371                 :             : /* Take the address of ARG if it has one, even if it's an rvalue.  */
    7372                 :             : 
    7373                 :             : tree
    7374                 :   172846274 : cp_build_addr_expr (tree arg, tsubst_flags_t complain)
    7375                 :             : {
    7376                 :   172846274 :   return cp_build_addr_expr_1 (arg, 0, complain);
    7377                 :             : }
    7378                 :             : 
    7379                 :             : /* Take the address of ARG, but only if it's an lvalue.  */
    7380                 :             : 
    7381                 :             : static tree
    7382                 :     3511050 : cp_build_addr_expr_strict (tree arg, tsubst_flags_t complain)
    7383                 :             : {
    7384                 :     3511050 :   return cp_build_addr_expr_1 (arg, 1, complain);
    7385                 :             : }
    7386                 :             : 
    7387                 :             : /* C++: Must handle pointers to members.
    7388                 :             : 
    7389                 :             :    Perhaps type instantiation should be extended to handle conversion
    7390                 :             :    from aggregates to types we don't yet know we want?  (Or are those
    7391                 :             :    cases typically errors which should be reported?)
    7392                 :             : 
    7393                 :             :    NOCONVERT suppresses the default promotions (such as from short to int).  */
    7394                 :             : 
    7395                 :             : tree
    7396                 :    24820449 : cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
    7397                 :             :                    tsubst_flags_t complain)
    7398                 :             : {
    7399                 :             :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    7400                 :    24820449 :   tree arg = xarg;
    7401                 :    24820449 :   location_t location = cp_expr_loc_or_input_loc (arg);
    7402                 :    24820449 :   tree argtype = 0;
    7403                 :    24820449 :   tree eptype = NULL_TREE;
    7404                 :    24820449 :   const char *errstring = NULL;
    7405                 :    24820449 :   tree val;
    7406                 :    24820449 :   const char *invalid_op_diag;
    7407                 :             : 
    7408                 :    24820449 :   if (!arg || error_operand_p (arg))
    7409                 :           0 :     return error_mark_node;
    7410                 :             : 
    7411                 :    24820449 :   arg = resolve_nondeduced_context (arg, complain);
    7412                 :             : 
    7413                 :    49640898 :   if ((invalid_op_diag
    7414                 :    24820449 :        = targetm.invalid_unary_op ((code == UNARY_PLUS_EXPR
    7415                 :             :                                     ? CONVERT_EXPR
    7416                 :             :                                     : code),
    7417                 :    24820449 :                                    TREE_TYPE (arg))))
    7418                 :             :     {
    7419                 :           0 :       if (complain & tf_error)
    7420                 :           0 :         error (invalid_op_diag);
    7421                 :           0 :       return error_mark_node;
    7422                 :             :     }
    7423                 :             : 
    7424                 :    24820449 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    7425                 :             :     {
    7426                 :        6808 :       eptype = TREE_TYPE (arg);
    7427                 :        6808 :       arg = TREE_OPERAND (arg, 0);
    7428                 :             :     }
    7429                 :             : 
    7430                 :    24820449 :   switch (code)
    7431                 :             :     {
    7432                 :     2276190 :     case UNARY_PLUS_EXPR:
    7433                 :     2276190 :     case NEGATE_EXPR:
    7434                 :     2276190 :       {
    7435                 :     2276190 :         int flags = WANT_ARITH | WANT_ENUM;
    7436                 :             :         /* Unary plus (but not unary minus) is allowed on pointers.  */
    7437                 :     2276190 :         if (code == UNARY_PLUS_EXPR)
    7438                 :      160479 :           flags |= WANT_POINTER;
    7439                 :     2276190 :         arg = build_expr_type_conversion (flags, arg, true);
    7440                 :     2276190 :         if (!arg)
    7441                 :          27 :           errstring = (code == NEGATE_EXPR
    7442                 :          22 :                        ? _("wrong type argument to unary minus")
    7443                 :           5 :                        : _("wrong type argument to unary plus"));
    7444                 :             :         else
    7445                 :             :           {
    7446                 :     2276163 :             if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    7447                 :      556204 :               arg = cp_perform_integral_promotions (arg, complain);
    7448                 :             : 
    7449                 :             :             /* Make sure the result is not an lvalue: a unary plus or minus
    7450                 :             :                expression is always a rvalue.  */
    7451                 :     2276163 :             arg = rvalue (arg);
    7452                 :             :           }
    7453                 :             :       }
    7454                 :             :       break;
    7455                 :             : 
    7456                 :      815036 :     case BIT_NOT_EXPR:
    7457                 :      815036 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    7458                 :             :         {
    7459                 :          20 :           code = CONJ_EXPR;
    7460                 :          20 :           if (!noconvert)
    7461                 :             :             {
    7462                 :          20 :               arg = cp_default_conversion (arg, complain);
    7463                 :          20 :               if (arg == error_mark_node)
    7464                 :             :                 return error_mark_node;
    7465                 :             :             }
    7466                 :             :         }
    7467                 :      815016 :       else if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM
    7468                 :             :                                                    | WANT_VECTOR_OR_COMPLEX,
    7469                 :             :                                                    arg, true)))
    7470                 :          16 :         errstring = _("wrong type argument to bit-complement");
    7471                 :      815000 :       else if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    7472                 :             :         {
    7473                 :             :           /* Warn if the expression has boolean value.  */
    7474                 :      814808 :           if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
    7475                 :          87 :               && (complain & tf_warning)
    7476                 :      814887 :               && warning_at (location, OPT_Wbool_operation,
    7477                 :             :                              "%<~%> on an expression of type %<bool%>"))
    7478                 :          54 :             inform (location, "did you mean to use logical not (%<!%>)?");
    7479                 :      814808 :           arg = cp_perform_integral_promotions (arg, complain);
    7480                 :             :         }
    7481                 :         192 :       else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
    7482                 :         192 :         arg = mark_rvalue_use (arg);
    7483                 :             :       break;
    7484                 :             : 
    7485                 :           0 :     case ABS_EXPR:
    7486                 :           0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    7487                 :           0 :         errstring = _("wrong type argument to abs");
    7488                 :           0 :       else if (!noconvert)
    7489                 :             :         {
    7490                 :           0 :           arg = cp_default_conversion (arg, complain);
    7491                 :           0 :           if (arg == error_mark_node)
    7492                 :             :             return error_mark_node;
    7493                 :             :         }
    7494                 :             :       break;
    7495                 :             : 
    7496                 :           0 :     case CONJ_EXPR:
    7497                 :             :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    7498                 :           0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    7499                 :           0 :         errstring = _("wrong type argument to conjugation");
    7500                 :           0 :       else if (!noconvert)
    7501                 :             :         {
    7502                 :           0 :           arg = cp_default_conversion (arg, complain);
    7503                 :           0 :           if (arg == error_mark_node)
    7504                 :             :             return error_mark_node;
    7505                 :             :         }
    7506                 :             :       break;
    7507                 :             : 
    7508                 :    13550238 :     case TRUTH_NOT_EXPR:
    7509                 :    13550238 :       if (gnu_vector_type_p (TREE_TYPE (arg)))
    7510                 :          65 :         return cp_build_binary_op (input_location, EQ_EXPR, arg,
    7511                 :          65 :                                    build_zero_cst (TREE_TYPE (arg)), complain);
    7512                 :    13550173 :       arg = perform_implicit_conversion (boolean_type_node, arg,
    7513                 :             :                                          complain);
    7514                 :    13550173 :       if (arg != error_mark_node)
    7515                 :             :         {
    7516                 :    13550161 :           if (processing_template_decl)
    7517                 :     5986897 :             return build1_loc (location, TRUTH_NOT_EXPR, boolean_type_node, arg);
    7518                 :     7563264 :           val = invert_truthvalue_loc (location, arg);
    7519                 :     7563264 :           if (obvalue_p (val))
    7520                 :       12668 :             val = non_lvalue_loc (location, val);
    7521                 :     7563264 :           return val;
    7522                 :             :         }
    7523                 :          12 :       errstring = _("in argument to unary !");
    7524                 :          12 :       break;
    7525                 :             : 
    7526                 :             :     case NOP_EXPR:
    7527                 :             :       break;
    7528                 :             : 
    7529                 :      452781 :     case REALPART_EXPR:
    7530                 :      452781 :     case IMAGPART_EXPR:
    7531                 :      452781 :       val = build_real_imag_expr (input_location, code, arg);
    7532                 :      452781 :       if (eptype && TREE_CODE (eptype) == COMPLEX_EXPR)
    7533                 :           0 :         val = build1_loc (input_location, EXCESS_PRECISION_EXPR,
    7534                 :           0 :                           TREE_TYPE (eptype), val);
    7535                 :             :       return val;
    7536                 :             : 
    7537                 :     7188009 :     case PREINCREMENT_EXPR:
    7538                 :     7188009 :     case POSTINCREMENT_EXPR:
    7539                 :     7188009 :     case PREDECREMENT_EXPR:
    7540                 :     7188009 :     case POSTDECREMENT_EXPR:
    7541                 :             :       /* Handle complex lvalues (when permitted)
    7542                 :             :          by reduction to simpler cases.  */
    7543                 :             : 
    7544                 :     7188009 :       val = unary_complex_lvalue (code, arg);
    7545                 :     7188009 :       if (val != 0)
    7546                 :          34 :         goto return_build_unary_op;
    7547                 :             : 
    7548                 :     7187975 :       arg = mark_lvalue_use (arg);
    7549                 :             : 
    7550                 :             :       /* Increment or decrement the real part of the value,
    7551                 :             :          and don't change the imaginary part.  */
    7552                 :     7187975 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    7553                 :             :         {
    7554                 :          24 :           tree real, imag;
    7555                 :             : 
    7556                 :          24 :           arg = cp_stabilize_reference (arg);
    7557                 :          24 :           real = cp_build_unary_op (REALPART_EXPR, arg, true, complain);
    7558                 :          24 :           imag = cp_build_unary_op (IMAGPART_EXPR, arg, true, complain);
    7559                 :          24 :           real = cp_build_unary_op (code, real, true, complain);
    7560                 :          24 :           if (real == error_mark_node || imag == error_mark_node)
    7561                 :             :             return error_mark_node;
    7562                 :          20 :           val = build2 (COMPLEX_EXPR, TREE_TYPE (arg), real, imag);
    7563                 :          20 :           goto return_build_unary_op;
    7564                 :             :         }
    7565                 :             : 
    7566                 :             :       /* Report invalid types.  */
    7567                 :             : 
    7568                 :     7187951 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
    7569                 :             :                                               arg, true)))
    7570                 :             :         {
    7571                 :          48 :           if (code == PREINCREMENT_EXPR)
    7572                 :          12 :             errstring = _("no pre-increment operator for type");
    7573                 :          36 :           else if (code == POSTINCREMENT_EXPR)
    7574                 :          12 :             errstring = _("no post-increment operator for type");
    7575                 :          24 :           else if (code == PREDECREMENT_EXPR)
    7576                 :          12 :             errstring = _("no pre-decrement operator for type");
    7577                 :             :           else
    7578                 :          12 :             errstring = _("no post-decrement operator for type");
    7579                 :             :           break;
    7580                 :             :         }
    7581                 :     7187903 :       else if (arg == error_mark_node)
    7582                 :             :         return error_mark_node;
    7583                 :             : 
    7584                 :             :       /* Report something read-only.  */
    7585                 :             : 
    7586                 :     7187903 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg))
    7587                 :     7187903 :           || TREE_READONLY (arg)) 
    7588                 :             :         {
    7589                 :          41 :           if (complain & tf_error)
    7590                 :          41 :             cxx_readonly_error (location, arg,
    7591                 :          41 :                                 ((code == PREINCREMENT_EXPR
    7592                 :          41 :                                   || code == POSTINCREMENT_EXPR)
    7593                 :             :                                  ? lv_increment : lv_decrement));
    7594                 :             :           else
    7595                 :           0 :             return error_mark_node;
    7596                 :             :         }
    7597                 :             : 
    7598                 :     7187903 :       {
    7599                 :     7187903 :         tree inc;
    7600                 :     7187903 :         tree declared_type = unlowered_expr_type (arg);
    7601                 :             : 
    7602                 :     7187903 :         argtype = TREE_TYPE (arg);
    7603                 :             : 
    7604                 :             :         /* ARM $5.2.5 last annotation says this should be forbidden.  */
    7605                 :     7187903 :         if (TREE_CODE (argtype) == ENUMERAL_TYPE)
    7606                 :             :           {
    7607                 :           0 :             if (complain & tf_error)
    7608                 :           0 :               permerror (location, (code == PREINCREMENT_EXPR
    7609                 :           0 :                                     || code == POSTINCREMENT_EXPR)
    7610                 :             :                          ? G_("ISO C++ forbids incrementing an enum")
    7611                 :             :                          : G_("ISO C++ forbids decrementing an enum"));
    7612                 :             :             else
    7613                 :           0 :               return error_mark_node;
    7614                 :             :           }
    7615                 :             : 
    7616                 :             :         /* Compute the increment.  */
    7617                 :             : 
    7618                 :     7187903 :         if (TYPE_PTR_P (argtype))
    7619                 :             :           {
    7620                 :     1988720 :             tree type = complete_type (TREE_TYPE (argtype));
    7621                 :             : 
    7622                 :     1988720 :             if (!COMPLETE_OR_VOID_TYPE_P (type))
    7623                 :             :               {
    7624                 :          14 :                 if (complain & tf_error)
    7625                 :          12 :                   error_at (location, ((code == PREINCREMENT_EXPR
    7626                 :          12 :                                         || code == POSTINCREMENT_EXPR))
    7627                 :             :                             ? G_("cannot increment a pointer to incomplete "
    7628                 :             :                                  "type %qT")
    7629                 :             :                             : G_("cannot decrement a pointer to incomplete "
    7630                 :             :                                  "type %qT"),
    7631                 :          12 :                             TREE_TYPE (argtype));
    7632                 :             :                 else
    7633                 :           2 :                   return error_mark_node;
    7634                 :             :               }
    7635                 :     1988706 :             else if (!TYPE_PTROB_P (argtype)) 
    7636                 :             :               {
    7637                 :          96 :                 if (complain & tf_error)
    7638                 :          84 :                   pedwarn (location, OPT_Wpointer_arith,
    7639                 :          84 :                            (code == PREINCREMENT_EXPR
    7640                 :          84 :                               || code == POSTINCREMENT_EXPR)
    7641                 :             :                            ? G_("ISO C++ forbids incrementing a pointer "
    7642                 :             :                                 "of type %qT")
    7643                 :             :                            : G_("ISO C++ forbids decrementing a pointer "
    7644                 :             :                                 "of type %qT"),
    7645                 :             :                            argtype);
    7646                 :             :                 else
    7647                 :          12 :                   return error_mark_node;
    7648                 :             :               }
    7649                 :     1988610 :             else if (!verify_type_context (location, TCTX_POINTER_ARITH,
    7650                 :     1988610 :                                            TREE_TYPE (argtype),
    7651                 :     1988610 :                                            !(complain & tf_error)))
    7652                 :           0 :               return error_mark_node;
    7653                 :             : 
    7654                 :     1988706 :             inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
    7655                 :             :           }
    7656                 :             :         else
    7657                 :     5199183 :           inc = VECTOR_TYPE_P (argtype)
    7658                 :     5199183 :             ? build_one_cst (argtype)
    7659                 :             :             : integer_one_node;
    7660                 :             : 
    7661                 :     7187889 :         inc = cp_convert (argtype, inc, complain);
    7662                 :             : 
    7663                 :             :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    7664                 :             :            need to ask Objective-C to build the increment or decrement
    7665                 :             :            expression for it.  */
    7666                 :     7187889 :         if (objc_is_property_ref (arg))
    7667                 :           0 :           return objc_build_incr_expr_for_property_ref (input_location, code, 
    7668                 :           0 :                                                         arg, inc);      
    7669                 :             : 
    7670                 :             :         /* Complain about anything else that is not a true lvalue.  */
    7671                 :     7187889 :         if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
    7672                 :     7187889 :                                     || code == POSTINCREMENT_EXPR)
    7673                 :             :                                    ? lv_increment : lv_decrement),
    7674                 :             :                              complain))
    7675                 :          44 :           return error_mark_node;
    7676                 :             : 
    7677                 :             :         /* [depr.volatile.type] "Postfix ++ and -- expressions and
    7678                 :             :            prefix ++ and -- expressions of volatile-qualified arithmetic
    7679                 :             :            and pointer types are deprecated."  */
    7680                 :     7187491 :         if ((TREE_THIS_VOLATILE (arg) || CP_TYPE_VOLATILE_P (TREE_TYPE (arg)))
    7681                 :     7187845 :             && (complain & tf_warning))
    7682                 :         460 :           warning_at (location, OPT_Wvolatile,
    7683                 :             :                       "%qs expression of %<volatile%>-qualified type is "
    7684                 :             :                       "deprecated",
    7685                 :             :                       ((code == PREINCREMENT_EXPR
    7686                 :             :                         || code == POSTINCREMENT_EXPR)
    7687                 :             :                        ? "++" : "--"));
    7688                 :             : 
    7689                 :             :         /* Forbid using -- or ++ in C++17 on `bool'.  */
    7690                 :     7187845 :         if (TREE_CODE (declared_type) == BOOLEAN_TYPE)
    7691                 :             :           {
    7692                 :         118 :             if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
    7693                 :             :               {
    7694                 :          40 :                 if (complain & tf_error)
    7695                 :          40 :                   error_at (location,
    7696                 :             :                             "use of an operand of type %qT in %<operator--%> "
    7697                 :             :                             "is forbidden", boolean_type_node);
    7698                 :          40 :                 return error_mark_node;
    7699                 :             :               }
    7700                 :             :             else
    7701                 :             :               {
    7702                 :          78 :                 if (cxx_dialect >= cxx17)
    7703                 :             :                   {
    7704                 :          32 :                     if (complain & tf_error)
    7705                 :          30 :                       error_at (location,
    7706                 :             :                                 "use of an operand of type %qT in "
    7707                 :             :                                 "%<operator++%> is forbidden in C++17",
    7708                 :             :                                 boolean_type_node);
    7709                 :          32 :                     return error_mark_node;
    7710                 :             :                   }
    7711                 :             :                 /* Otherwise, [depr.incr.bool] says this is deprecated.  */
    7712                 :          46 :                 else if (complain & tf_warning)
    7713                 :          44 :                   warning_at (location, OPT_Wdeprecated,
    7714                 :             :                               "use of an operand of type %qT "
    7715                 :             :                               "in %<operator++%> is deprecated",
    7716                 :             :                               boolean_type_node);
    7717                 :             :               }
    7718                 :          46 :             val = boolean_increment (code, arg);
    7719                 :             :           }
    7720                 :     7187727 :         else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    7721                 :             :           /* An rvalue has no cv-qualifiers.  */
    7722                 :      967762 :           val = build2 (code, cv_unqualified (TREE_TYPE (arg)), arg, inc);
    7723                 :             :         else
    7724                 :     6219965 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    7725                 :             : 
    7726                 :     7187773 :         TREE_SIDE_EFFECTS (val) = 1;
    7727                 :     7187773 :         goto return_build_unary_op;
    7728                 :             :       }
    7729                 :             : 
    7730                 :      538195 :     case ADDR_EXPR:
    7731                 :             :       /* Note that this operation never does default_conversion
    7732                 :             :          regardless of NOCONVERT.  */
    7733                 :      538195 :       return cp_build_addr_expr (arg, complain);
    7734                 :             : 
    7735                 :             :     default:
    7736                 :             :       break;
    7737                 :             :     }
    7738                 :             : 
    7739                 :     3091286 :   if (!errstring)
    7740                 :             :     {
    7741                 :     3091183 :       if (argtype == 0)
    7742                 :     3091183 :         argtype = TREE_TYPE (arg);
    7743                 :     3091183 :       val = build1 (code, argtype, arg);
    7744                 :    10279010 :     return_build_unary_op:
    7745                 :    10279010 :       if (eptype)
    7746                 :        6796 :         val = build1 (EXCESS_PRECISION_EXPR, eptype, val);
    7747                 :    10279010 :       return val;
    7748                 :             :     }
    7749                 :             : 
    7750                 :         103 :   if (complain & tf_error)
    7751                 :          62 :     error_at (location, "%s", errstring);
    7752                 :         103 :   return error_mark_node;
    7753                 :             : }
    7754                 :             : 
    7755                 :             : /* Hook for the c-common bits that build a unary op.  */
    7756                 :             : tree
    7757                 :        4915 : build_unary_op (location_t /*location*/,
    7758                 :             :                 enum tree_code code, tree xarg, bool noconvert)
    7759                 :             : {
    7760                 :        4915 :   return cp_build_unary_op (code, xarg, noconvert, tf_warning_or_error);
    7761                 :             : }
    7762                 :             : 
    7763                 :             : /* Adjust LVALUE, an MODIFY_EXPR, PREINCREMENT_EXPR or PREDECREMENT_EXPR,
    7764                 :             :    so that it is a valid lvalue even for GENERIC by replacing
    7765                 :             :    (lhs = rhs) with ((lhs = rhs), lhs)
    7766                 :             :    (--lhs) with ((--lhs), lhs)
    7767                 :             :    (++lhs) with ((++lhs), lhs)
    7768                 :             :    and if lhs has side-effects, calling cp_stabilize_reference on it, so
    7769                 :             :    that it can be evaluated multiple times.  */
    7770                 :             : 
    7771                 :             : tree
    7772                 :      363818 : genericize_compound_lvalue (tree lvalue)
    7773                 :             : {
    7774                 :      363818 :   if (TREE_SIDE_EFFECTS (TREE_OPERAND (lvalue, 0)))
    7775                 :         161 :     lvalue = build2 (TREE_CODE (lvalue), TREE_TYPE (lvalue),
    7776                 :         161 :                      cp_stabilize_reference (TREE_OPERAND (lvalue, 0)),
    7777                 :         161 :                      TREE_OPERAND (lvalue, 1));
    7778                 :      363818 :   return build2 (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (lvalue, 0)),
    7779                 :      363818 :                  lvalue, TREE_OPERAND (lvalue, 0));
    7780                 :             : }
    7781                 :             : 
    7782                 :             : /* Apply unary lvalue-demanding operator CODE to the expression ARG
    7783                 :             :    for certain kinds of expressions which are not really lvalues
    7784                 :             :    but which we can accept as lvalues.
    7785                 :             : 
    7786                 :             :    If ARG is not a kind of expression we can handle, return
    7787                 :             :    NULL_TREE.  */
    7788                 :             : 
    7789                 :             : tree
    7790                 :   226362960 : unary_complex_lvalue (enum tree_code code, tree arg)
    7791                 :             : {
    7792                 :             :   /* Inside a template, making these kinds of adjustments is
    7793                 :             :      pointless; we are only concerned with the type of the
    7794                 :             :      expression.  */
    7795                 :   226726576 :   if (processing_template_decl)
    7796                 :             :     return NULL_TREE;
    7797                 :             : 
    7798                 :             :   /* Handle (a, b) used as an "lvalue".  */
    7799                 :   152691704 :   if (TREE_CODE (arg) == COMPOUND_EXPR)
    7800                 :             :     {
    7801                 :      363983 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 1), false,
    7802                 :             :                                             tf_warning_or_error);
    7803                 :      363983 :       return build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    7804                 :      727966 :                      TREE_OPERAND (arg, 0), real_result);
    7805                 :             :     }
    7806                 :             : 
    7807                 :             :   /* Handle (a ? b : c) used as an "lvalue".  */
    7808                 :   152327721 :   if (TREE_CODE (arg) == COND_EXPR
    7809                 :   152242889 :       || TREE_CODE (arg) == MIN_EXPR || TREE_CODE (arg) == MAX_EXPR)
    7810                 :       84832 :     return rationalize_conditional_expr (code, arg, tf_warning_or_error);
    7811                 :             : 
    7812                 :             :   /* Handle (a = b), (++a), and (--a) used as an "lvalue".  */
    7813                 :   152242889 :   if (TREE_CODE (arg) == MODIFY_EXPR
    7814                 :   151879458 :       || TREE_CODE (arg) == PREINCREMENT_EXPR
    7815                 :   151879367 :       || TREE_CODE (arg) == PREDECREMENT_EXPR)
    7816                 :      363616 :     return unary_complex_lvalue (code, genericize_compound_lvalue (arg));
    7817                 :             : 
    7818                 :   151879273 :   if (code != ADDR_EXPR)
    7819                 :             :     return NULL_TREE;
    7820                 :             : 
    7821                 :             :   /* Handle (a = b) used as an "lvalue" for `&'.  */
    7822                 :   149054531 :   if (TREE_CODE (arg) == MODIFY_EXPR
    7823                 :   149054531 :       || TREE_CODE (arg) == INIT_EXPR)
    7824                 :             :     {
    7825                 :           0 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 0), false,
    7826                 :             :                                             tf_warning_or_error);
    7827                 :           0 :       arg = build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    7828                 :             :                     arg, real_result);
    7829                 :           0 :       suppress_warning (arg /* What warning? */);
    7830                 :           0 :       return arg;
    7831                 :             :     }
    7832                 :             : 
    7833                 :   233181997 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (arg))
    7834                 :   233180877 :       || TREE_CODE (arg) == OFFSET_REF)
    7835                 :             :     return NULL_TREE;
    7836                 :             : 
    7837                 :             :   /* We permit compiler to make function calls returning
    7838                 :             :      objects of aggregate type look like lvalues.  */
    7839                 :    84126346 :   {
    7840                 :    84126346 :     tree targ = arg;
    7841                 :             : 
    7842                 :    84126346 :     if (TREE_CODE (targ) == SAVE_EXPR)
    7843                 :           0 :       targ = TREE_OPERAND (targ, 0);
    7844                 :             : 
    7845                 :    84126346 :     if (TREE_CODE (targ) == CALL_EXPR && MAYBE_CLASS_TYPE_P (TREE_TYPE (targ)))
    7846                 :             :       {
    7847                 :          47 :         if (TREE_CODE (arg) == SAVE_EXPR)
    7848                 :             :           targ = arg;
    7849                 :             :         else
    7850                 :          47 :           targ = build_cplus_new (TREE_TYPE (arg), arg, tf_warning_or_error);
    7851                 :          47 :         return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
    7852                 :             :       }
    7853                 :             : 
    7854                 :    84126299 :     if (TREE_CODE (arg) == SAVE_EXPR && INDIRECT_REF_P (targ))
    7855                 :           0 :       return build3 (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
    7856                 :           0 :                      TREE_OPERAND (targ, 0), current_function_decl, NULL);
    7857                 :             :   }
    7858                 :             : 
    7859                 :             :   /* Don't let anything else be handled specially.  */
    7860                 :             :   return NULL_TREE;
    7861                 :             : }
    7862                 :             : 
    7863                 :             : /* Mark EXP saying that we need to be able to take the
    7864                 :             :    address of it; it should not be allocated in a register.
    7865                 :             :    Value is true if successful.  ARRAY_REF_P is true if this
    7866                 :             :    is for ARRAY_REF construction - in that case we don't want
    7867                 :             :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    7868                 :             :    it is fine to use ARRAY_REFs for vector subscripts on vector
    7869                 :             :    register variables.
    7870                 :             : 
    7871                 :             :    C++: we do not allow `current_class_ptr' to be addressable.  */
    7872                 :             : 
    7873                 :             : bool
    7874                 :   247784579 : cxx_mark_addressable (tree exp, bool array_ref_p)
    7875                 :             : {
    7876                 :   247784579 :   tree x = exp;
    7877                 :             : 
    7878                 :   292247227 :   while (1)
    7879                 :   292247227 :     switch (TREE_CODE (x))
    7880                 :             :       {
    7881                 :    21610330 :       case VIEW_CONVERT_EXPR:
    7882                 :    21610330 :         if (array_ref_p
    7883                 :      707491 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    7884                 :    22153459 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    7885                 :             :           return true;
    7886                 :    21607431 :         x = TREE_OPERAND (x, 0);
    7887                 :    21607431 :         break;
    7888                 :             : 
    7889                 :    22622359 :       case COMPONENT_REF:
    7890                 :    22622359 :         if (bitfield_p (x))
    7891                 :          12 :           error ("attempt to take address of bit-field");
    7892                 :             :         /* FALLTHRU */
    7893                 :    22855217 :       case ADDR_EXPR:
    7894                 :    22855217 :       case ARRAY_REF:
    7895                 :    22855217 :       case REALPART_EXPR:
    7896                 :    22855217 :       case IMAGPART_EXPR:
    7897                 :    22855217 :         x = TREE_OPERAND (x, 0);
    7898                 :    22855217 :         break;
    7899                 :             : 
    7900                 :     4081953 :       case PARM_DECL:
    7901                 :     4081953 :         if (x == current_class_ptr)
    7902                 :             :           {
    7903                 :          24 :             error ("cannot take the address of %<this%>, which is an rvalue expression");
    7904                 :          24 :             TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later.  */
    7905                 :          24 :             return true;
    7906                 :             :           }
    7907                 :             :         /* Fall through.  */
    7908                 :             : 
    7909                 :    46188213 :       case VAR_DECL:
    7910                 :             :         /* Caller should not be trying to mark initialized
    7911                 :             :            constant fields addressable.  */
    7912                 :    46188213 :         gcc_assert (DECL_LANG_SPECIFIC (x) == 0
    7913                 :             :                     || DECL_IN_AGGR_P (x) == 0
    7914                 :             :                     || TREE_STATIC (x)
    7915                 :             :                     || DECL_EXTERNAL (x));
    7916                 :             :         /* Fall through.  */
    7917                 :             : 
    7918                 :    46285976 :       case RESULT_DECL:
    7919                 :    46286028 :         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
    7920                 :    46286020 :             && !DECL_ARTIFICIAL (x))
    7921                 :             :           {
    7922                 :          30 :             if (VAR_P (x) && DECL_HARD_REGISTER (x))
    7923                 :             :               {
    7924                 :          16 :                 error
    7925                 :          16 :                   ("address of explicit register variable %qD requested", x);
    7926                 :          16 :                 return false;
    7927                 :             :               }
    7928                 :          14 :             else if (extra_warnings)
    7929                 :           4 :               warning
    7930                 :           4 :                 (OPT_Wextra, "address requested for %qD, which is declared %<register%>", x);
    7931                 :             :           }
    7932                 :    46285960 :         TREE_ADDRESSABLE (x) = 1;
    7933                 :    46285960 :         return true;
    7934                 :             : 
    7935                 :   121297476 :       case CONST_DECL:
    7936                 :   121297476 :       case FUNCTION_DECL:
    7937                 :   121297476 :         TREE_ADDRESSABLE (x) = 1;
    7938                 :   121297476 :         return true;
    7939                 :             : 
    7940                 :       49745 :       case CONSTRUCTOR:
    7941                 :       49745 :         TREE_ADDRESSABLE (x) = 1;
    7942                 :       49745 :         return true;
    7943                 :             : 
    7944                 :    10767085 :       case TARGET_EXPR:
    7945                 :    10767085 :         TREE_ADDRESSABLE (x) = 1;
    7946                 :    10767085 :         cxx_mark_addressable (TREE_OPERAND (x, 0));
    7947                 :    10767085 :         return true;
    7948                 :             : 
    7949                 :             :       default:
    7950                 :             :         return true;
    7951                 :             :     }
    7952                 :             : }
    7953                 :             : 
    7954                 :             : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
    7955                 :             : 
    7956                 :             : tree
    7957                 :     5809813 : build_x_conditional_expr (location_t loc, tree ifexp, tree op1, tree op2, 
    7958                 :             :                           tsubst_flags_t complain)
    7959                 :             : {
    7960                 :     5809813 :   tree orig_ifexp = ifexp;
    7961                 :     5809813 :   tree orig_op1 = op1;
    7962                 :     5809813 :   tree orig_op2 = op2;
    7963                 :     5809813 :   tree expr;
    7964                 :             : 
    7965                 :     5809813 :   if (processing_template_decl)
    7966                 :             :     {
    7967                 :             :       /* The standard says that the expression is type-dependent if
    7968                 :             :          IFEXP is type-dependent, even though the eventual type of the
    7969                 :             :          expression doesn't dependent on IFEXP.  */
    7970                 :     2388121 :       if (type_dependent_expression_p (ifexp)
    7971                 :             :           /* As a GNU extension, the middle operand may be omitted.  */
    7972                 :     1184955 :           || (op1 && type_dependent_expression_p (op1))
    7973                 :     3163195 :           || type_dependent_expression_p (op2))
    7974                 :     1638248 :         return build_min_nt_loc (loc, COND_EXPR, ifexp, op1, op2);
    7975                 :             :     }
    7976                 :             : 
    7977                 :     4171565 :   expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
    7978                 :     4171565 :   if (processing_template_decl && expr != error_mark_node)
    7979                 :             :     {
    7980                 :      749865 :       tree min = build_min_non_dep (COND_EXPR, expr,
    7981                 :             :                                     orig_ifexp, orig_op1, orig_op2);
    7982                 :      749865 :       expr = convert_from_reference (min);
    7983                 :             :     }
    7984                 :             :   return expr;
    7985                 :             : }
    7986                 :             : 
    7987                 :             : /* Given a list of expressions, return a compound expression
    7988                 :             :    that performs them all and returns the value of the last of them.  */
    7989                 :             : 
    7990                 :             : tree
    7991                 :    28374588 : build_x_compound_expr_from_list (tree list, expr_list_kind exp,
    7992                 :             :                                  tsubst_flags_t complain)
    7993                 :             : {
    7994                 :    28374588 :   tree expr = TREE_VALUE (list);
    7995                 :             : 
    7996                 :      222676 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    7997                 :    28597260 :       && !CONSTRUCTOR_IS_DIRECT_INIT (expr))
    7998                 :             :     {
    7999                 :          20 :       if (complain & tf_error)
    8000                 :          40 :         pedwarn (cp_expr_loc_or_input_loc (expr), 0,
    8001                 :             :                  "list-initializer for non-class type must not "
    8002                 :             :                  "be parenthesized");
    8003                 :             :       else
    8004                 :           0 :         return error_mark_node;
    8005                 :             :     }
    8006                 :             : 
    8007                 :    28374588 :   if (TREE_CHAIN (list))
    8008                 :             :     {
    8009                 :          27 :       if (complain & tf_error)
    8010                 :          17 :         switch (exp)
    8011                 :             :           {
    8012                 :          14 :           case ELK_INIT:
    8013                 :          14 :             permerror (input_location, "expression list treated as compound "
    8014                 :             :                                        "expression in initializer");
    8015                 :          14 :             break;
    8016                 :           3 :           case ELK_MEM_INIT:
    8017                 :           3 :             permerror (input_location, "expression list treated as compound "
    8018                 :             :                                        "expression in mem-initializer");
    8019                 :           3 :             break;
    8020                 :           0 :           case ELK_FUNC_CAST:
    8021                 :           0 :             permerror (input_location, "expression list treated as compound "
    8022                 :             :                                        "expression in functional cast");
    8023                 :           0 :             break;
    8024                 :           0 :           default:
    8025                 :           0 :             gcc_unreachable ();
    8026                 :             :           }
    8027                 :             :       else
    8028                 :          10 :         return error_mark_node;
    8029                 :             : 
    8030                 :          34 :       for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
    8031                 :          34 :         expr = build_x_compound_expr (EXPR_LOCATION (TREE_VALUE (list)),
    8032                 :          17 :                                       expr, TREE_VALUE (list), NULL_TREE,
    8033                 :             :                                       complain);
    8034                 :             :     }
    8035                 :             : 
    8036                 :             :   return expr;
    8037                 :             : }
    8038                 :             : 
    8039                 :             : /* Like build_x_compound_expr_from_list, but using a VEC.  */
    8040                 :             : 
    8041                 :             : tree
    8042                 :       98189 : build_x_compound_expr_from_vec (vec<tree, va_gc> *vec, const char *msg,
    8043                 :             :                                 tsubst_flags_t complain)
    8044                 :             : {
    8045                 :       98189 :   if (vec_safe_is_empty (vec))
    8046                 :             :     return NULL_TREE;
    8047                 :       98189 :   else if (vec->length () == 1)
    8048                 :       98178 :     return (*vec)[0];
    8049                 :             :   else
    8050                 :             :     {
    8051                 :          11 :       tree expr;
    8052                 :          11 :       unsigned int ix;
    8053                 :          11 :       tree t;
    8054                 :             : 
    8055                 :          11 :       if (msg != NULL)
    8056                 :             :         {
    8057                 :           5 :           if (complain & tf_error)
    8058                 :           0 :             permerror (input_location,
    8059                 :             :                        "%s expression list treated as compound expression",
    8060                 :             :                        msg);
    8061                 :             :           else
    8062                 :           5 :             return error_mark_node;
    8063                 :             :         }
    8064                 :             : 
    8065                 :           6 :       expr = (*vec)[0];
    8066                 :          14 :       for (ix = 1; vec->iterate (ix, &t); ++ix)
    8067                 :           8 :         expr = build_x_compound_expr (EXPR_LOCATION (t), expr,
    8068                 :             :                                       t, NULL_TREE, complain);
    8069                 :             : 
    8070                 :           6 :       return expr;
    8071                 :             :     }
    8072                 :             : }
    8073                 :             : 
    8074                 :             : /* Handle overloading of the ',' operator when needed.  */
    8075                 :             : 
    8076                 :             : tree
    8077                 :     2534047 : build_x_compound_expr (location_t loc, tree op1, tree op2,
    8078                 :             :                        tree lookups, tsubst_flags_t complain)
    8079                 :             : {
    8080                 :     2534047 :   tree result;
    8081                 :     2534047 :   tree orig_op1 = op1;
    8082                 :     2534047 :   tree orig_op2 = op2;
    8083                 :     2534047 :   tree overload = NULL_TREE;
    8084                 :             : 
    8085                 :     2534047 :   if (processing_template_decl)
    8086                 :             :     {
    8087                 :     2419171 :       if (type_dependent_expression_p (op1)
    8088                 :     2419171 :           || type_dependent_expression_p (op2))
    8089                 :             :         {
    8090                 :     2152753 :           result = build_min_nt_loc (loc, COMPOUND_EXPR, op1, op2);
    8091                 :     2152753 :           TREE_TYPE (result)
    8092                 :     2152753 :             = build_dependent_operator_type (lookups, COMPOUND_EXPR, false);
    8093                 :     2152753 :           return result;
    8094                 :             :         }
    8095                 :             :     }
    8096                 :             : 
    8097                 :      381294 :   result = build_new_op (loc, COMPOUND_EXPR, LOOKUP_NORMAL, op1, op2,
    8098                 :             :                          NULL_TREE, lookups, &overload, complain);
    8099                 :      381294 :   if (!result)
    8100                 :      374305 :     result = cp_build_compound_expr (op1, op2, complain);
    8101                 :             : 
    8102                 :      381294 :   if (processing_template_decl && result != error_mark_node)
    8103                 :             :     {
    8104                 :      264597 :       if (overload != NULL_TREE)
    8105                 :          56 :         return (build_min_non_dep_op_overload
    8106                 :          56 :                 (COMPOUND_EXPR, result, overload, orig_op1, orig_op2));
    8107                 :             : 
    8108                 :      264541 :       return build_min_non_dep (COMPOUND_EXPR, result, orig_op1, orig_op2);
    8109                 :             :     }
    8110                 :             : 
    8111                 :             :   return result;
    8112                 :             : }
    8113                 :             : 
    8114                 :             : /* Like cp_build_compound_expr, but for the c-common bits.  */
    8115                 :             : 
    8116                 :             : tree
    8117                 :       10728 : build_compound_expr (location_t /*loc*/, tree lhs, tree rhs)
    8118                 :             : {
    8119                 :       10728 :   return cp_build_compound_expr (lhs, rhs, tf_warning_or_error);
    8120                 :             : }
    8121                 :             : 
    8122                 :             : /* Build a compound expression.  */
    8123                 :             : 
    8124                 :             : tree
    8125                 :      386883 : cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
    8126                 :             : {
    8127                 :      386883 :   lhs = convert_to_void (lhs, ICV_LEFT_OF_COMMA, complain);
    8128                 :             : 
    8129                 :      386883 :   if (lhs == error_mark_node || rhs == error_mark_node)
    8130                 :             :     return error_mark_node;
    8131                 :             : 
    8132                 :      386879 :   if (TREE_CODE (lhs) == EXCESS_PRECISION_EXPR)
    8133                 :           0 :     lhs = TREE_OPERAND (lhs, 0);
    8134                 :      386879 :   tree eptype = NULL_TREE;
    8135                 :      386879 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8136                 :             :     {
    8137                 :           4 :       eptype = TREE_TYPE (rhs);
    8138                 :           4 :       rhs = TREE_OPERAND (rhs, 0);
    8139                 :             :     }
    8140                 :             : 
    8141                 :      386879 :   if (TREE_CODE (rhs) == TARGET_EXPR)
    8142                 :             :     {
    8143                 :             :       /* If the rhs is a TARGET_EXPR, then build the compound
    8144                 :             :          expression inside the target_expr's initializer. This
    8145                 :             :          helps the compiler to eliminate unnecessary temporaries.  */
    8146                 :        2384 :       tree init = TREE_OPERAND (rhs, 1);
    8147                 :             : 
    8148                 :        2384 :       init = build2 (COMPOUND_EXPR, TREE_TYPE (init), lhs, init);
    8149                 :        2384 :       TREE_OPERAND (rhs, 1) = init;
    8150                 :             : 
    8151                 :        2384 :       if (eptype)
    8152                 :           0 :         rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    8153                 :        2384 :       return rhs;
    8154                 :             :     }
    8155                 :             : 
    8156                 :      384495 :   if (type_unknown_p (rhs))
    8157                 :             :     {
    8158                 :          47 :       if (complain & tf_error)
    8159                 :          71 :         error_at (cp_expr_loc_or_input_loc (rhs),
    8160                 :             :                   "no context to resolve type of %qE", rhs);
    8161                 :          47 :       return error_mark_node;
    8162                 :             :     }
    8163                 :             :   
    8164                 :      384448 :   tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
    8165                 :      384448 :   if (eptype)
    8166                 :           4 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    8167                 :             :   return ret;
    8168                 :             : }
    8169                 :             : 
    8170                 :             : /* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
    8171                 :             :    casts away constness.  CAST gives the type of cast.  Returns true
    8172                 :             :    if the cast is ill-formed, false if it is well-formed.
    8173                 :             : 
    8174                 :             :    ??? This function warns for casting away any qualifier not just
    8175                 :             :    const.  We would like to specify exactly what qualifiers are casted
    8176                 :             :    away.
    8177                 :             : */
    8178                 :             : 
    8179                 :             : static bool
    8180                 :      597877 : check_for_casting_away_constness (location_t loc, tree src_type,
    8181                 :             :                                   tree dest_type, enum tree_code cast,
    8182                 :             :                                   tsubst_flags_t complain)
    8183                 :             : {
    8184                 :             :   /* C-style casts are allowed to cast away constness.  With
    8185                 :             :      WARN_CAST_QUAL, we still want to issue a warning.  */
    8186                 :      597877 :   if (cast == CAST_EXPR && !warn_cast_qual)
    8187                 :             :     return false;
    8188                 :             :   
    8189                 :      549344 :   if (!casts_away_constness (src_type, dest_type, complain))
    8190                 :             :     return false;
    8191                 :             : 
    8192                 :         421 :   switch (cast)
    8193                 :             :     {
    8194                 :         358 :     case CAST_EXPR:
    8195                 :         358 :       if (complain & tf_warning)
    8196                 :         358 :         warning_at (loc, OPT_Wcast_qual,
    8197                 :             :                     "cast from type %qT to type %qT casts away qualifiers",
    8198                 :             :                     src_type, dest_type);
    8199                 :             :       return false;
    8200                 :             : 
    8201                 :          45 :     case STATIC_CAST_EXPR:
    8202                 :          45 :       if (complain & tf_error)
    8203                 :          32 :         error_at (loc, "%<static_cast%> from type %qT to type %qT casts "
    8204                 :             :                   "away qualifiers",
    8205                 :             :                   src_type, dest_type);
    8206                 :             :       return true;
    8207                 :             : 
    8208                 :          18 :     case REINTERPRET_CAST_EXPR:
    8209                 :          18 :       if (complain & tf_error)
    8210                 :          10 :         error_at (loc, "%<reinterpret_cast%> from type %qT to type %qT "
    8211                 :             :                   "casts away qualifiers",
    8212                 :             :                   src_type, dest_type);
    8213                 :             :       return true;
    8214                 :             : 
    8215                 :           0 :     default:
    8216                 :           0 :       gcc_unreachable();
    8217                 :             :     }
    8218                 :             : }
    8219                 :             : 
    8220                 :             : /* Warns if the cast from expression EXPR to type TYPE is useless.  */
    8221                 :             : void
    8222                 :    40487597 : maybe_warn_about_useless_cast (location_t loc, tree type, tree expr,
    8223                 :             :                                tsubst_flags_t complain)
    8224                 :             : {
    8225                 :    40487597 :   if (warn_useless_cast
    8226                 :         191 :       && complain & tf_warning)
    8227                 :             :     {
    8228                 :         191 :       if (TYPE_REF_P (type)
    8229                 :         191 :           ? ((TYPE_REF_IS_RVALUE (type)
    8230                 :         110 :               ? xvalue_p (expr) : lvalue_p (expr))
    8231                 :         220 :              && same_type_p (TREE_TYPE (expr), TREE_TYPE (type)))
    8232                 :             :           /* Don't warn when converting a class object to a non-reference type,
    8233                 :             :              because that's a common way to create a temporary.  */
    8234                 :          81 :           : (!glvalue_p (expr) && same_type_p (TREE_TYPE (expr), type)))
    8235                 :         126 :         warning_at (loc, OPT_Wuseless_cast,
    8236                 :             :                     "useless cast to type %q#T", type);
    8237                 :             :     }
    8238                 :    40487597 : }
    8239                 :             : 
    8240                 :             : /* Warns if the cast ignores cv-qualifiers on TYPE.  */
    8241                 :             : static void
    8242                 :    40479311 : maybe_warn_about_cast_ignoring_quals (location_t loc, tree type,
    8243                 :             :                                       tsubst_flags_t complain)
    8244                 :             : {
    8245                 :    40479311 :   if (warn_ignored_qualifiers
    8246                 :      246838 :       && complain & tf_warning
    8247                 :      246514 :       && !CLASS_TYPE_P (type)
    8248                 :    40721812 :       && (cp_type_quals (type) & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)))
    8249                 :          36 :     warning_at (loc, OPT_Wignored_qualifiers,
    8250                 :             :                 "type qualifiers ignored on cast result type");
    8251                 :    40479311 : }
    8252                 :             : 
    8253                 :             : /* Convert EXPR (an expression with pointer-to-member type) to TYPE
    8254                 :             :    (another pointer-to-member type in the same hierarchy) and return
    8255                 :             :    the converted expression.  If ALLOW_INVERSE_P is permitted, a
    8256                 :             :    pointer-to-derived may be converted to pointer-to-base; otherwise,
    8257                 :             :    only the other direction is permitted.  If C_CAST_P is true, this
    8258                 :             :    conversion is taking place as part of a C-style cast.  */
    8259                 :             : 
    8260                 :             : tree
    8261                 :       28823 : convert_ptrmem (tree type, tree expr, bool allow_inverse_p,
    8262                 :             :                 bool c_cast_p, tsubst_flags_t complain)
    8263                 :             : {
    8264                 :       28823 :   if (same_type_p (type, TREE_TYPE (expr)))
    8265                 :             :     return expr;
    8266                 :             : 
    8267                 :       28823 :   if (TYPE_PTRDATAMEM_P (type))
    8268                 :             :     {
    8269                 :         411 :       tree obase = TYPE_PTRMEM_CLASS_TYPE (TREE_TYPE (expr));
    8270                 :         411 :       tree nbase = TYPE_PTRMEM_CLASS_TYPE (type);
    8271                 :         411 :       tree delta = (get_delta_difference
    8272                 :         411 :                     (obase, nbase,
    8273                 :             :                      allow_inverse_p, c_cast_p, complain));
    8274                 :             : 
    8275                 :         411 :       if (delta == error_mark_node)
    8276                 :             :         return error_mark_node;
    8277                 :             : 
    8278                 :         404 :       if (!same_type_p (obase, nbase))
    8279                 :             :         {
    8280                 :         316 :           if (TREE_CODE (expr) == PTRMEM_CST)
    8281                 :         176 :             expr = cplus_expand_constant (expr);
    8282                 :             : 
    8283                 :         316 :           tree cond = cp_build_binary_op (input_location, EQ_EXPR, expr,
    8284                 :         316 :                                           build_int_cst (TREE_TYPE (expr), -1),
    8285                 :             :                                           complain);
    8286                 :         316 :           tree op1 = build_nop (ptrdiff_type_node, expr);
    8287                 :         316 :           tree op2 = cp_build_binary_op (input_location, PLUS_EXPR, op1, delta,
    8288                 :             :                                          complain);
    8289                 :             : 
    8290                 :         316 :           expr = fold_build3_loc (input_location,
    8291                 :             :                                   COND_EXPR, ptrdiff_type_node, cond, op1, op2);
    8292                 :             :         }
    8293                 :             : 
    8294                 :         404 :       return build_nop (type, expr);
    8295                 :             :     }
    8296                 :             :   else
    8297                 :       28412 :     return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr,
    8298                 :       28412 :                              allow_inverse_p, c_cast_p, complain);
    8299                 :             : }
    8300                 :             : 
    8301                 :             : /* Perform a static_cast from EXPR to TYPE.  When C_CAST_P is true,
    8302                 :             :    this static_cast is being attempted as one of the possible casts
    8303                 :             :    allowed by a C-style cast.  (In that case, accessibility of base
    8304                 :             :    classes is not considered, and it is OK to cast away
    8305                 :             :    constness.)  Return the result of the cast.  *VALID_P is set to
    8306                 :             :    indicate whether or not the cast was valid.  */
    8307                 :             : 
    8308                 :             : static tree
    8309                 :    40222695 : build_static_cast_1 (location_t loc, tree type, tree expr, bool c_cast_p,
    8310                 :             :                      bool *valid_p, tsubst_flags_t complain)
    8311                 :             : {
    8312                 :    40222695 :   tree intype;
    8313                 :    40222695 :   tree result;
    8314                 :    40222695 :   cp_lvalue_kind clk;
    8315                 :             : 
    8316                 :             :   /* Assume the cast is valid.  */
    8317                 :    40222695 :   *valid_p = true;
    8318                 :             : 
    8319                 :    40222695 :   intype = unlowered_expr_type (expr);
    8320                 :             : 
    8321                 :             :   /* Save casted types in the function's used types hash table.  */
    8322                 :    40222695 :   used_types_insert (type);
    8323                 :             : 
    8324                 :             :   /* A prvalue of non-class type is cv-unqualified.  */
    8325                 :    40222695 :   if (!CLASS_TYPE_P (type))
    8326                 :    38889378 :     type = cv_unqualified (type);
    8327                 :             : 
    8328                 :             :   /* [expr.static.cast]
    8329                 :             : 
    8330                 :             :      An lvalue of type "cv1 B", where B is a class type, can be cast
    8331                 :             :      to type "reference to cv2 D", where D is a class derived (clause
    8332                 :             :      _class.derived_) from B, if a valid standard conversion from
    8333                 :             :      "pointer to D" to "pointer to B" exists (_conv.ptr_), cv2 is the
    8334                 :             :      same cv-qualification as, or greater cv-qualification than, cv1,
    8335                 :             :      and B is not a virtual base class of D.  */
    8336                 :             :   /* We check this case before checking the validity of "TYPE t =
    8337                 :             :      EXPR;" below because for this case:
    8338                 :             : 
    8339                 :             :        struct B {};
    8340                 :             :        struct D : public B { D(const B&); };
    8341                 :             :        extern B& b;
    8342                 :             :        void f() { static_cast<const D&>(b); }
    8343                 :             : 
    8344                 :             :      we want to avoid constructing a new D.  The standard is not
    8345                 :             :      completely clear about this issue, but our interpretation is
    8346                 :             :      consistent with other compilers.  */
    8347                 :    40222695 :   if (TYPE_REF_P (type)
    8348                 :     2743998 :       && CLASS_TYPE_P (TREE_TYPE (type))
    8349                 :     2203821 :       && CLASS_TYPE_P (intype)
    8350                 :     2203803 :       && (TYPE_REF_IS_RVALUE (type) || lvalue_p (expr))
    8351                 :     2203066 :       && DERIVED_FROM_P (intype, TREE_TYPE (type))
    8352                 :     2171039 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT (intype)),
    8353                 :     2171039 :                       build_pointer_type (TYPE_MAIN_VARIANT
    8354                 :             :                                           (TREE_TYPE (type))),
    8355                 :             :                       complain)
    8356                 :    42393734 :       && (c_cast_p
    8357                 :     2171007 :           || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    8358                 :             :     {
    8359                 :     2171039 :       tree base;
    8360                 :             : 
    8361                 :     2171039 :       if (processing_template_decl)
    8362                 :             :         return expr;
    8363                 :             : 
    8364                 :             :       /* There is a standard conversion from "D*" to "B*" even if "B"
    8365                 :             :          is ambiguous or inaccessible.  If this is really a
    8366                 :             :          static_cast, then we check both for inaccessibility and
    8367                 :             :          ambiguity.  However, if this is a static_cast being performed
    8368                 :             :          because the user wrote a C-style cast, then accessibility is
    8369                 :             :          not considered.  */
    8370                 :     4015364 :       base = lookup_base (TREE_TYPE (type), intype,
    8371                 :             :                           c_cast_p ? ba_unique : ba_check,
    8372                 :             :                           NULL, complain);
    8373                 :     2007698 :       expr = cp_build_addr_expr (expr, complain);
    8374                 :             : 
    8375                 :     2007698 :       if (sanitize_flags_p (SANITIZE_VPTR))
    8376                 :             :         {
    8377                 :         159 :           tree ubsan_check
    8378                 :         159 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    8379                 :             :                                                   intype, expr);
    8380                 :         159 :           if (ubsan_check)
    8381                 :     2007698 :             expr = ubsan_check;
    8382                 :             :         }
    8383                 :             : 
    8384                 :             :       /* Convert from "B*" to "D*".  This function will check that "B"
    8385                 :             :          is not a virtual base of "D".  Even if we don't have a guarantee
    8386                 :             :          that expr is NULL, if the static_cast is to a reference type,
    8387                 :             :          it is UB if it would be NULL, so omit the non-NULL check.  */
    8388                 :     2007698 :       expr = build_base_path (MINUS_EXPR, expr, base,
    8389                 :             :                               /*nonnull=*/flag_delete_null_pointer_checks,
    8390                 :             :                               complain);
    8391                 :             : 
    8392                 :             :       /* Convert the pointer to a reference -- but then remember that
    8393                 :             :          there are no expressions with reference type in C++.
    8394                 :             : 
    8395                 :             :          We call rvalue so that there's an actual tree code
    8396                 :             :          (NON_LVALUE_EXPR) for the static_cast; otherwise, if the operand
    8397                 :             :          is a variable with the same type, the conversion would get folded
    8398                 :             :          away, leaving just the variable and causing lvalue_kind to give
    8399                 :             :          the wrong answer.  */
    8400                 :     2007698 :       expr = cp_fold_convert (type, expr);
    8401                 :             : 
    8402                 :             :       /* When -fsanitize=null, make sure to diagnose reference binding to
    8403                 :             :          NULL even when the reference is converted to pointer later on.  */
    8404                 :     2007698 :       if (sanitize_flags_p (SANITIZE_NULL)
    8405                 :         167 :           && TREE_CODE (expr) == COND_EXPR
    8406                 :           8 :           && TREE_OPERAND (expr, 2)
    8407                 :           8 :           && TREE_CODE (TREE_OPERAND (expr, 2)) == INTEGER_CST
    8408                 :     2007706 :           && TREE_TYPE (TREE_OPERAND (expr, 2)) == type)
    8409                 :           8 :         ubsan_maybe_instrument_reference (&TREE_OPERAND (expr, 2));
    8410                 :             : 
    8411                 :     2007698 :       return convert_from_reference (rvalue (expr));
    8412                 :             :     }
    8413                 :             : 
    8414                 :             :   /* "A glvalue of type cv1 T1 can be cast to type rvalue reference to
    8415                 :             :      cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)."  */
    8416                 :    38051656 :   if (TYPE_REF_P (type)
    8417                 :      572959 :       && TYPE_REF_IS_RVALUE (type)
    8418                 :      354543 :       && (clk = real_lvalue_p (expr))
    8419                 :      351992 :       && reference_compatible_p (TREE_TYPE (type), intype)
    8420                 :    38403645 :       && (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    8421                 :             :     {
    8422                 :      351989 :       if (processing_template_decl)
    8423                 :             :         return expr;
    8424                 :      351850 :       if (clk == clk_ordinary)
    8425                 :             :         {
    8426                 :             :           /* Handle the (non-bit-field) lvalue case here by casting to
    8427                 :             :              lvalue reference and then changing it to an rvalue reference.
    8428                 :             :              Casting an xvalue to rvalue reference will be handled by the
    8429                 :             :              main code path.  */
    8430                 :      351847 :           tree lref = cp_build_reference_type (TREE_TYPE (type), false);
    8431                 :      351847 :           result = (perform_direct_initialization_if_possible
    8432                 :      351847 :                     (lref, expr, c_cast_p, complain));
    8433                 :      351847 :           result = build1 (NON_LVALUE_EXPR, type, result);
    8434                 :      351847 :           return convert_from_reference (result);
    8435                 :             :         }
    8436                 :             :       else
    8437                 :             :         /* For a bit-field or packed field, bind to a temporary.  */
    8438                 :           3 :         expr = rvalue (expr);
    8439                 :             :     }
    8440                 :             : 
    8441                 :             :   /* Resolve overloaded address here rather than once in
    8442                 :             :      implicit_conversion and again in the inverse code below.  */
    8443                 :    37699670 :   if (TYPE_PTRMEMFUNC_P (type) && type_unknown_p (expr))
    8444                 :             :     {
    8445                 :          23 :       expr = instantiate_type (type, expr, complain);
    8446                 :          23 :       intype = TREE_TYPE (expr);
    8447                 :             :     }
    8448                 :             : 
    8449                 :             :   /* [expr.static.cast]
    8450                 :             : 
    8451                 :             :      Any expression can be explicitly converted to type cv void.  */
    8452                 :    37699670 :   if (VOID_TYPE_P (type))
    8453                 :             :     {
    8454                 :      134091 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8455                 :           0 :         expr = TREE_OPERAND (expr, 0);
    8456                 :      134091 :       return convert_to_void (expr, ICV_CAST, complain);
    8457                 :             :     }
    8458                 :             : 
    8459                 :             :   /* [class.abstract]
    8460                 :             :      An abstract class shall not be used ... as the type of an explicit
    8461                 :             :      conversion.  */
    8462                 :    37565579 :   if (abstract_virtuals_error (ACU_CAST, type, complain))
    8463                 :           6 :     return error_mark_node;
    8464                 :             : 
    8465                 :             :   /* [expr.static.cast]
    8466                 :             : 
    8467                 :             :      An expression e can be explicitly converted to a type T using a
    8468                 :             :      static_cast of the form static_cast<T>(e) if the declaration T
    8469                 :             :      t(e);" is well-formed, for some invented temporary variable
    8470                 :             :      t.  */
    8471                 :    37565573 :   result = perform_direct_initialization_if_possible (type, expr,
    8472                 :             :                                                       c_cast_p, complain);
    8473                 :             :   /* P1975 allows static_cast<Aggr>(42), as well as static_cast<T[5]>(42),
    8474                 :             :      which initialize the first element of the aggregate.  We need to handle
    8475                 :             :      the array case specifically.  */
    8476                 :    37565573 :   if (result == NULL_TREE
    8477                 :     3686356 :       && cxx_dialect >= cxx20
    8478                 :      838654 :       && TREE_CODE (type) == ARRAY_TYPE)
    8479                 :             :     {
    8480                 :             :       /* Create { EXPR } and perform direct-initialization from it.  */
    8481                 :           5 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
    8482                 :           5 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
    8483                 :           5 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
    8484                 :           5 :       result = perform_direct_initialization_if_possible (type, e, c_cast_p,
    8485                 :             :                                                           complain);
    8486                 :             :     }
    8487                 :     3686356 :   if (result)
    8488                 :             :     {
    8489                 :    33879222 :       if (processing_template_decl)
    8490                 :             :         return expr;
    8491                 :             : 
    8492                 :    33256597 :       result = convert_from_reference (result);
    8493                 :             : 
    8494                 :             :       /* [expr.static.cast]
    8495                 :             : 
    8496                 :             :          If T is a reference type, the result is an lvalue; otherwise,
    8497                 :             :          the result is an rvalue.  */
    8498                 :    33256597 :       if (!TYPE_REF_P (type))
    8499                 :             :         {
    8500                 :    33035737 :           result = rvalue (result);
    8501                 :             : 
    8502                 :    33035737 :           if (result == expr && SCALAR_TYPE_P (type))
    8503                 :             :             /* Leave some record of the cast.  */
    8504                 :     1766190 :             result = build_nop (type, expr);
    8505                 :             :         }
    8506                 :    33256597 :       return result;
    8507                 :             :     }
    8508                 :             : 
    8509                 :             :   /* [expr.static.cast]
    8510                 :             : 
    8511                 :             :      The inverse of any standard conversion sequence (clause _conv_),
    8512                 :             :      other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer
    8513                 :             :      (_conv.array_), function-to-pointer (_conv.func_), and boolean
    8514                 :             :      (_conv.bool_) conversions, can be performed explicitly using
    8515                 :             :      static_cast subject to the restriction that the explicit
    8516                 :             :      conversion does not cast away constness (_expr.const.cast_), and
    8517                 :             :      the following additional rules for specific cases:  */
    8518                 :             :   /* For reference, the conversions not excluded are: integral
    8519                 :             :      promotions, floating-point promotion, integral conversions,
    8520                 :             :      floating-point conversions, floating-integral conversions,
    8521                 :             :      pointer conversions, and pointer to member conversions.  */
    8522                 :             :   /* DR 128
    8523                 :             : 
    8524                 :             :      A value of integral _or enumeration_ type can be explicitly
    8525                 :             :      converted to an enumeration type.  */
    8526                 :             :   /* The effect of all that is that any conversion between any two
    8527                 :             :      types which are integral, floating, or enumeration types can be
    8528                 :             :      performed.  */
    8529                 :     3686351 :   if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    8530                 :     2091497 :        || SCALAR_FLOAT_TYPE_P (type))
    8531                 :     1714081 :       && (INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
    8532                 :      221403 :           || SCALAR_FLOAT_TYPE_P (intype)))
    8533                 :             :     {
    8534                 :     1611895 :       if (processing_template_decl)
    8535                 :             :         return expr;
    8536                 :     1527366 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8537                 :           0 :         expr = TREE_OPERAND (expr, 0);
    8538                 :             :       /* [expr.static.cast]: "If the value is not a bit-field, the result
    8539                 :             :          refers to the object or the specified base class subobject thereof;
    8540                 :             :          otherwise, the lvalue-to-rvalue conversion is applied to the
    8541                 :             :          bit-field and the resulting prvalue is used as the operand of the
    8542                 :             :          static_cast."  There are no prvalue bit-fields; the l-to-r conversion
    8543                 :             :          will give us an object of the underlying type of the bit-field.  */
    8544                 :     1527366 :       expr = decay_conversion (expr, complain);
    8545                 :     1527366 :       return ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL, complain);
    8546                 :             :     }
    8547                 :             : 
    8548                 :      688797 :   if (TYPE_PTR_P (type) && TYPE_PTR_P (intype)
    8549                 :      684369 :       && CLASS_TYPE_P (TREE_TYPE (type))
    8550                 :      196778 :       && CLASS_TYPE_P (TREE_TYPE (intype))
    8551                 :     2115699 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT
    8552                 :             :                                           (TREE_TYPE (intype))),
    8553                 :       41243 :                       build_pointer_type (TYPE_MAIN_VARIANT
    8554                 :             :                                           (TREE_TYPE (type))),
    8555                 :             :                       complain))
    8556                 :             :     {
    8557                 :       40813 :       tree base;
    8558                 :             : 
    8559                 :       40813 :       if (processing_template_decl)
    8560                 :             :         return expr;
    8561                 :             : 
    8562                 :       40791 :       if (!c_cast_p
    8563                 :       40791 :           && check_for_casting_away_constness (loc, intype, type,
    8564                 :             :                                                STATIC_CAST_EXPR,
    8565                 :             :                                                complain))
    8566                 :           7 :         return error_mark_node;
    8567                 :       80868 :       base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
    8568                 :             :                           c_cast_p ? ba_unique : ba_check,
    8569                 :             :                           NULL, complain);
    8570                 :       40784 :       expr = build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false,
    8571                 :             :                               complain);
    8572                 :             : 
    8573                 :       40784 :       if (sanitize_flags_p (SANITIZE_VPTR))
    8574                 :             :         {
    8575                 :          51 :           tree ubsan_check
    8576                 :          51 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    8577                 :             :                                                   intype, expr);
    8578                 :          51 :           if (ubsan_check)
    8579                 :       40784 :             expr = ubsan_check;
    8580                 :             :         }
    8581                 :             : 
    8582                 :       40784 :       return cp_fold_convert (type, expr);
    8583                 :             :     }
    8584                 :             : 
    8585                 :         113 :   if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    8586                 :     2033643 :       || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
    8587                 :             :     {
    8588                 :         299 :       tree c1;
    8589                 :         299 :       tree c2;
    8590                 :         299 :       tree t1;
    8591                 :         299 :       tree t2;
    8592                 :             : 
    8593                 :         299 :       c1 = TYPE_PTRMEM_CLASS_TYPE (intype);
    8594                 :         299 :       c2 = TYPE_PTRMEM_CLASS_TYPE (type);
    8595                 :             : 
    8596                 :         299 :       if (TYPE_PTRDATAMEM_P (type))
    8597                 :             :         {
    8598                 :         113 :           t1 = (build_ptrmem_type
    8599                 :         113 :                 (c1,
    8600                 :         113 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (intype))));
    8601                 :         113 :           t2 = (build_ptrmem_type
    8602                 :         113 :                 (c2,
    8603                 :         113 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (type))));
    8604                 :             :         }
    8605                 :             :       else
    8606                 :             :         {
    8607                 :             :           t1 = intype;
    8608                 :             :           t2 = type;
    8609                 :             :         }
    8610                 :         299 :       if (can_convert (t1, t2, complain) || can_convert (t2, t1, complain))
    8611                 :             :         {
    8612                 :         196 :           if (!c_cast_p
    8613                 :         196 :               && check_for_casting_away_constness (loc, intype, type,
    8614                 :             :                                                    STATIC_CAST_EXPR,
    8615                 :             :                                                    complain))
    8616                 :          11 :             return error_mark_node;
    8617                 :         185 :           if (processing_template_decl)
    8618                 :             :             return expr;
    8619                 :         185 :           return convert_ptrmem (type, expr, /*allow_inverse_p=*/1,
    8620                 :         185 :                                  c_cast_p, complain);
    8621                 :             :         }
    8622                 :             :     }
    8623                 :             : 
    8624                 :             :   /* [expr.static.cast]
    8625                 :             : 
    8626                 :             :      An rvalue of type "pointer to cv void" can be explicitly
    8627                 :             :      converted to a pointer to object type.  A value of type pointer
    8628                 :             :      to object converted to "pointer to cv void" and back to the
    8629                 :             :      original pointer type will have its original value.  */
    8630                 :     2033447 :   if (TYPE_PTR_P (intype)
    8631                 :      743544 :       && VOID_TYPE_P (TREE_TYPE (intype))
    8632                 :     2652513 :       && TYPE_PTROB_P (type))
    8633                 :             :     {
    8634                 :      585792 :       if (!c_cast_p
    8635                 :      585792 :           && check_for_casting_away_constness (loc, intype, type,
    8636                 :             :                                                STATIC_CAST_EXPR,
    8637                 :             :                                                complain))
    8638                 :          27 :         return error_mark_node;
    8639                 :      585765 :       if (processing_template_decl)
    8640                 :             :         return expr;
    8641                 :      500856 :       return build_nop (type, expr);
    8642                 :             :     }
    8643                 :             : 
    8644                 :     1447655 :   *valid_p = false;
    8645                 :     1447655 :   return error_mark_node;
    8646                 :             : }
    8647                 :             : 
    8648                 :             : /* Return an expression representing static_cast<TYPE>(EXPR).  */
    8649                 :             : 
    8650                 :             : tree
    8651                 :    11141442 : build_static_cast (location_t loc, tree type, tree oexpr,
    8652                 :             :                    tsubst_flags_t complain)
    8653                 :             : {
    8654                 :    11141442 :   tree expr = oexpr;
    8655                 :    11141442 :   tree result;
    8656                 :    11141442 :   bool valid_p;
    8657                 :             : 
    8658                 :    11141442 :   if (type == error_mark_node || expr == error_mark_node)
    8659                 :             :     return error_mark_node;
    8660                 :             : 
    8661                 :    11141390 :   bool dependent = (dependent_type_p (type)
    8662                 :    11141390 :                     || type_dependent_expression_p (expr));
    8663                 :     7321744 :   if (dependent)
    8664                 :             :     {
    8665                 :     4775243 :     tmpl:
    8666                 :     4775243 :       expr = build_min (STATIC_CAST_EXPR, type, oexpr);
    8667                 :             :       /* We don't know if it will or will not have side effects.  */
    8668                 :     4775243 :       TREE_SIDE_EFFECTS (expr) = 1;
    8669                 :     4775243 :       result = convert_from_reference (expr);
    8670                 :     4775243 :       protected_set_expr_location (result, loc);
    8671                 :     4775243 :       return result;
    8672                 :             :     }
    8673                 :             : 
    8674                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    8675                 :             :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    8676                 :     7321744 :   if (!TYPE_REF_P (type)
    8677                 :     4578034 :       && TREE_CODE (expr) == NOP_EXPR
    8678                 :     7412085 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    8679                 :          64 :     expr = TREE_OPERAND (expr, 0);
    8680                 :             : 
    8681                 :     7321744 :   result = build_static_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    8682                 :             :                                 &valid_p, complain);
    8683                 :     7321744 :   if (valid_p)
    8684                 :             :     {
    8685                 :     7321554 :       if (result != error_mark_node)
    8686                 :             :         {
    8687                 :     7321437 :           maybe_warn_about_useless_cast (loc, type, expr, complain);
    8688                 :     7321437 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    8689                 :             :         }
    8690                 :     7321554 :       if (processing_template_decl)
    8691                 :      955597 :         goto tmpl;
    8692                 :     6365957 :       protected_set_expr_location (result, loc);
    8693                 :     6365957 :       return result;
    8694                 :             :     }
    8695                 :             : 
    8696                 :         190 :   if (complain & tf_error)
    8697                 :             :     {
    8698                 :         170 :       error_at (loc, "invalid %<static_cast%> from type %qT to type %qT",
    8699                 :         170 :                 TREE_TYPE (expr), type);
    8700                 :         170 :       if ((TYPE_PTR_P (type) || TYPE_REF_P (type))
    8701                 :         136 :           && CLASS_TYPE_P (TREE_TYPE (type))
    8702                 :         209 :             && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    8703                 :          23 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (TREE_TYPE (type))),
    8704                 :          23 :                 "class type %qT is incomplete", TREE_TYPE (type));
    8705                 :         170 :       tree expr_type = TREE_TYPE (expr);
    8706                 :         170 :       if (TYPE_PTR_P (expr_type))
    8707                 :          42 :         expr_type = TREE_TYPE (expr_type);
    8708                 :         170 :       if (CLASS_TYPE_P (expr_type) && !COMPLETE_TYPE_P (expr_type))
    8709                 :          16 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (expr_type)),
    8710                 :             :                 "class type %qT is incomplete", expr_type);
    8711                 :             :     }
    8712                 :         190 :   return error_mark_node;
    8713                 :             : }
    8714                 :             : 
    8715                 :             : /* EXPR is an expression with member function or pointer-to-member
    8716                 :             :    function type.  TYPE is a pointer type.  Converting EXPR to TYPE is
    8717                 :             :    not permitted by ISO C++, but we accept it in some modes.  If we
    8718                 :             :    are not in one of those modes, issue a diagnostic.  Return the
    8719                 :             :    converted expression.  */
    8720                 :             : 
    8721                 :             : tree
    8722                 :         222 : convert_member_func_to_ptr (tree type, tree expr, tsubst_flags_t complain)
    8723                 :             : {
    8724                 :         222 :   tree intype;
    8725                 :         222 :   tree decl;
    8726                 :             : 
    8727                 :         222 :   intype = TREE_TYPE (expr);
    8728                 :         222 :   gcc_assert (TYPE_PTRMEMFUNC_P (intype)
    8729                 :             :               || TREE_CODE (intype) == METHOD_TYPE);
    8730                 :             : 
    8731                 :         222 :   if (!(complain & tf_warning_or_error))
    8732                 :           0 :     return error_mark_node;
    8733                 :             : 
    8734                 :         222 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    8735                 :             : 
    8736                 :         222 :   if (pedantic || warn_pmf2ptr)
    8737                 :         280 :     pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpmf_conversions,
    8738                 :             :              "converting from %qH to %qI", intype, type);
    8739                 :             : 
    8740                 :         222 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    8741                 :             : 
    8742                 :         222 :   if (TREE_CODE (intype) == METHOD_TYPE)
    8743                 :          97 :     expr = build_addr_func (expr, complain);
    8744                 :         125 :   else if (TREE_CODE (expr) == PTRMEM_CST)
    8745                 :         101 :     expr = build_address (PTRMEM_CST_MEMBER (expr));
    8746                 :             :   else
    8747                 :             :     {
    8748                 :          24 :       decl = maybe_dummy_object (TYPE_PTRMEM_CLASS_TYPE (intype), 0);
    8749                 :          24 :       decl = build_address (decl);
    8750                 :          24 :       expr = get_member_function_from_ptrfunc (&decl, expr, complain);
    8751                 :             :     }
    8752                 :             : 
    8753                 :         222 :   if (expr == error_mark_node)
    8754                 :             :     return error_mark_node;
    8755                 :             : 
    8756                 :         222 :   expr = build_nop (type, expr);
    8757                 :         222 :   SET_EXPR_LOCATION (expr, loc);
    8758                 :         222 :   return expr;
    8759                 :             : }
    8760                 :             : 
    8761                 :             : /* Build a NOP_EXPR to TYPE, but mark it as a reinterpret_cast so that
    8762                 :             :    constexpr evaluation knows to reject it.  */
    8763                 :             : 
    8764                 :             : static tree
    8765                 :       91780 : build_nop_reinterpret (tree type, tree expr)
    8766                 :             : {
    8767                 :       91780 :   tree ret = build_nop (type, expr);
    8768                 :       91780 :   if (ret != expr)
    8769                 :       91780 :     REINTERPRET_CAST_P (ret) = true;
    8770                 :       91780 :   return ret;
    8771                 :             : }
    8772                 :             : 
    8773                 :             : /* Return a representation for a reinterpret_cast from EXPR to TYPE.
    8774                 :             :    If C_CAST_P is true, this reinterpret cast is being done as part of
    8775                 :             :    a C-style cast.  If VALID_P is non-NULL, *VALID_P is set to
    8776                 :             :    indicate whether or not reinterpret_cast was valid.  */
    8777                 :             : 
    8778                 :             : static tree
    8779                 :     1560585 : build_reinterpret_cast_1 (location_t loc, tree type, tree expr,
    8780                 :             :                           bool c_cast_p, bool *valid_p,
    8781                 :             :                           tsubst_flags_t complain)
    8782                 :             : {
    8783                 :     1560585 :   tree intype;
    8784                 :             : 
    8785                 :             :   /* Assume the cast is invalid.  */
    8786                 :     1560585 :   if (valid_p)
    8787                 :     1447532 :     *valid_p = true;
    8788                 :             : 
    8789                 :     1560585 :   if (type == error_mark_node || error_operand_p (expr))
    8790                 :             :     return error_mark_node;
    8791                 :             : 
    8792                 :     1560585 :   intype = TREE_TYPE (expr);
    8793                 :             : 
    8794                 :             :   /* Save casted types in the function's used types hash table.  */
    8795                 :     1560585 :   used_types_insert (type);
    8796                 :             : 
    8797                 :             :   /* A prvalue of non-class type is cv-unqualified.  */
    8798                 :     1560585 :   if (!CLASS_TYPE_P (type))
    8799                 :     1560573 :     type = cv_unqualified (type);
    8800                 :             : 
    8801                 :             :   /* [expr.reinterpret.cast]
    8802                 :             :      A glvalue of type T1, designating an object x, can be cast to the type
    8803                 :             :      "reference to T2" if an expression of type "pointer to T1" can be
    8804                 :             :      explicitly converted to the type "pointer to T2" using a reinterpret_cast.
    8805                 :             :      The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x
    8806                 :             :      of type "pointer to T1". No temporary is created, no copy is made, and no
    8807                 :             :      constructors (11.4.4) or conversion functions (11.4.7) are called.  */
    8808                 :     1560585 :   if (TYPE_REF_P (type))
    8809                 :             :     {
    8810                 :       11742 :       if (!glvalue_p (expr))
    8811                 :             :         {
    8812                 :          10 :           if (complain & tf_error)
    8813                 :          10 :             error_at (loc, "invalid cast of a prvalue expression of type "
    8814                 :             :                       "%qT to type %qT",
    8815                 :             :                       intype, type);
    8816                 :          10 :           return error_mark_node;
    8817                 :             :         }
    8818                 :             : 
    8819                 :             :       /* Warn about a reinterpret_cast from "A*" to "B&" if "A" and
    8820                 :             :          "B" are related class types; the reinterpret_cast does not
    8821                 :             :          adjust the pointer.  */
    8822                 :       11732 :       if (TYPE_PTR_P (intype)
    8823                 :           4 :           && (complain & tf_warning)
    8824                 :       11736 :           && (comptypes (TREE_TYPE (intype), TREE_TYPE (type),
    8825                 :             :                          COMPARE_BASE | COMPARE_DERIVED)))
    8826                 :           4 :         warning_at (loc, 0, "casting %qT to %qT does not dereference pointer",
    8827                 :             :                     intype, type);
    8828                 :             : 
    8829                 :       11732 :       expr = cp_build_addr_expr (expr, complain);
    8830                 :             : 
    8831                 :       11732 :       if (warn_strict_aliasing > 2)
    8832                 :          74 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    8833                 :             : 
    8834                 :       11732 :       if (expr != error_mark_node)
    8835                 :       11732 :         expr = build_reinterpret_cast_1
    8836                 :       11732 :           (loc, build_pointer_type (TREE_TYPE (type)), expr, c_cast_p,
    8837                 :             :            valid_p, complain);
    8838                 :       11732 :       if (expr != error_mark_node)
    8839                 :             :         /* cp_build_indirect_ref isn't right for rvalue refs.  */
    8840                 :       11728 :         expr = convert_from_reference (fold_convert (type, expr));
    8841                 :       11732 :       return expr;
    8842                 :             :     }
    8843                 :             : 
    8844                 :             :   /* As a G++ extension, we consider conversions from member
    8845                 :             :      functions, and pointers to member functions to
    8846                 :             :      pointer-to-function and pointer-to-void types.  If
    8847                 :             :      -Wno-pmf-conversions has not been specified,
    8848                 :             :      convert_member_func_to_ptr will issue an error message.  */
    8849                 :         321 :   if ((TYPE_PTRMEMFUNC_P (intype)
    8850                 :     1548616 :        || TREE_CODE (intype) == METHOD_TYPE)
    8851                 :         324 :       && TYPE_PTR_P (type)
    8852                 :     1549065 :       && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    8853                 :         166 :           || VOID_TYPE_P (TREE_TYPE (type))))
    8854                 :         210 :     return convert_member_func_to_ptr (type, expr, complain);
    8855                 :             : 
    8856                 :             :   /* If the cast is not to a reference type, the lvalue-to-rvalue,
    8857                 :             :      array-to-pointer, and function-to-pointer conversions are
    8858                 :             :      performed.  */
    8859                 :     1548633 :   expr = decay_conversion (expr, complain);
    8860                 :             : 
    8861                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    8862                 :             :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    8863                 :     1548633 :   if (TREE_CODE (expr) == NOP_EXPR
    8864                 :     1548633 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    8865                 :          37 :     expr = TREE_OPERAND (expr, 0);
    8866                 :             : 
    8867                 :     1548633 :   if (error_operand_p (expr))
    8868                 :          37 :     return error_mark_node;
    8869                 :             : 
    8870                 :     1548596 :   intype = TREE_TYPE (expr);
    8871                 :             : 
    8872                 :             :   /* [expr.reinterpret.cast]
    8873                 :             :      A pointer can be converted to any integral type large enough to
    8874                 :             :      hold it. ... A value of type std::nullptr_t can be converted to
    8875                 :             :      an integral type; the conversion has the same meaning and
    8876                 :             :      validity as a conversion of (void*)0 to the integral type.  */
    8877                 :     1548596 :   if (CP_INTEGRAL_TYPE_P (type)
    8878                 :      136214 :       && (TYPE_PTR_P (intype) || NULLPTR_TYPE_P (intype)))
    8879                 :             :     {
    8880                 :      134255 :       if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))
    8881                 :             :         {
    8882                 :          26 :           if (complain & tf_error)
    8883                 :          18 :             permerror (loc, "cast from %qH to %qI loses precision",
    8884                 :             :                        intype, type);
    8885                 :             :           else
    8886                 :           8 :             return error_mark_node;
    8887                 :             :         }
    8888                 :      134247 :       if (NULLPTR_TYPE_P (intype))
    8889                 :          98 :         return build_int_cst (type, 0);
    8890                 :             :     }
    8891                 :             :   /* [expr.reinterpret.cast]
    8892                 :             :      A value of integral or enumeration type can be explicitly
    8893                 :             :      converted to a pointer.  */
    8894                 :     1414341 :   else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype))
    8895                 :             :     /* OK */
    8896                 :             :     ;
    8897                 :     1379729 :   else if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    8898                 :     1377751 :             || TYPE_PTR_OR_PTRMEM_P (type))
    8899                 :     1474040 :            && same_type_p (type, intype))
    8900                 :             :     /* DR 799 */
    8901                 :        2493 :     return rvalue (expr);
    8902                 :     1377236 :   else if (TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
    8903                 :             :     {
    8904                 :        4797 :       if ((complain & tf_warning)
    8905                 :        9594 :           && !cxx_safe_function_type_cast_p (TREE_TYPE (type),
    8906                 :        4797 :                                              TREE_TYPE (intype)))
    8907                 :         148 :         warning_at (loc, OPT_Wcast_function_type,
    8908                 :             :                     "cast between incompatible function types"
    8909                 :             :                     " from %qH to %qI", intype, type);
    8910                 :        4797 :       return build_nop_reinterpret (type, expr);
    8911                 :             :     }
    8912                 :     1372439 :   else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype))
    8913                 :             :     {
    8914                 :         102 :       if ((complain & tf_warning)
    8915                 :         204 :           && !cxx_safe_function_type_cast_p
    8916                 :         102 :                 (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (type)),
    8917                 :         102 :                  TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (intype))))
    8918                 :          66 :         warning_at (loc, OPT_Wcast_function_type,
    8919                 :             :                     "cast between incompatible pointer to member types"
    8920                 :             :                     " from %qH to %qI", intype, type);
    8921                 :         102 :       return build_nop_reinterpret (type, expr);
    8922                 :             :     }
    8923                 :          27 :   else if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    8924                 :     1372337 :            || (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype)))
    8925                 :             :     {
    8926                 :       86593 :       if (!c_cast_p
    8927                 :       86593 :           && check_for_casting_away_constness (loc, intype, type,
    8928                 :             :                                                REINTERPRET_CAST_EXPR,
    8929                 :             :                                                complain))
    8930                 :          18 :         return error_mark_node;
    8931                 :             :       /* Warn about possible alignment problems.  */
    8932                 :       86575 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    8933                 :          32 :           && (complain & tf_warning)
    8934                 :          32 :           && !VOID_TYPE_P (type)
    8935                 :          32 :           && TREE_CODE (TREE_TYPE (intype)) != FUNCTION_TYPE
    8936                 :          32 :           && COMPLETE_TYPE_P (TREE_TYPE (type))
    8937                 :          32 :           && COMPLETE_TYPE_P (TREE_TYPE (intype))
    8938                 :       86639 :           && min_align_of_type (TREE_TYPE (type))
    8939                 :          32 :              > min_align_of_type (TREE_TYPE (intype)))
    8940                 :          24 :         warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    8941                 :             :                     "increases required alignment of target type",
    8942                 :             :                     intype, type);
    8943                 :             : 
    8944                 :       86575 :       if (warn_strict_aliasing <= 2)
    8945                 :             :         /* strict_aliasing_warning STRIP_NOPs its expr.  */
    8946                 :       74387 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    8947                 :             : 
    8948                 :       86575 :       return build_nop_reinterpret (type, expr);
    8949                 :             :     }
    8950                 :         334 :   else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
    8951                 :     1285935 :            || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
    8952                 :             :     {
    8953                 :         306 :       if (complain & tf_warning)
    8954                 :             :         /* C++11 5.2.10 p8 says that "Converting a function pointer to an
    8955                 :             :            object pointer type or vice versa is conditionally-supported."  */
    8956                 :         306 :         warning_at (loc, OPT_Wconditionally_supported,
    8957                 :             :                     "casting between pointer-to-function and "
    8958                 :             :                     "pointer-to-object is conditionally-supported");
    8959                 :         306 :       return build_nop_reinterpret (type, expr);
    8960                 :             :     }
    8961                 :     1285438 :   else if (gnu_vector_type_p (type) && scalarish_type_p (intype))
    8962                 :     1283412 :     return convert_to_vector (type, rvalue (expr));
    8963                 :        2026 :   else if (gnu_vector_type_p (intype)
    8964                 :        2026 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    8965                 :        1901 :     return convert_to_integer_nofold (type, expr);
    8966                 :             :   else
    8967                 :             :     {
    8968                 :         125 :       if (valid_p)
    8969                 :         102 :         *valid_p = false;
    8970                 :         125 :       if (complain & tf_error)
    8971                 :         115 :         error_at (loc, "invalid cast from type %qT to type %qT",
    8972                 :             :                   intype, type);
    8973                 :         125 :       return error_mark_node;
    8974                 :             :     }
    8975                 :             : 
    8976                 :      168761 :   expr = cp_convert (type, expr, complain);
    8977                 :      168761 :   if (TREE_CODE (expr) == NOP_EXPR)
    8978                 :             :     /* Mark any nop_expr that created as a reintepret_cast.  */
    8979                 :           0 :     REINTERPRET_CAST_P (expr) = true;
    8980                 :             :   return expr;
    8981                 :             : }
    8982                 :             : 
    8983                 :             : tree
    8984                 :      526749 : build_reinterpret_cast (location_t loc, tree type, tree expr,
    8985                 :             :                         tsubst_flags_t complain)
    8986                 :             : {
    8987                 :      526749 :   tree r;
    8988                 :             : 
    8989                 :      526749 :   if (type == error_mark_node || expr == error_mark_node)
    8990                 :             :     return error_mark_node;
    8991                 :             : 
    8992                 :      526743 :   if (processing_template_decl)
    8993                 :             :     {
    8994                 :      425355 :       tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
    8995                 :             : 
    8996                 :      425355 :       if (!TREE_SIDE_EFFECTS (t)
    8997                 :      425355 :           && type_dependent_expression_p (expr))
    8998                 :             :         /* There might turn out to be side effects inside expr.  */
    8999                 :      198275 :         TREE_SIDE_EFFECTS (t) = 1;
    9000                 :      425355 :       r = convert_from_reference (t);
    9001                 :      425355 :       protected_set_expr_location (r, loc);
    9002                 :      425355 :       return r;
    9003                 :             :     }
    9004                 :             : 
    9005                 :      101388 :   r = build_reinterpret_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    9006                 :             :                                 /*valid_p=*/NULL, complain);
    9007                 :      101388 :   if (r != error_mark_node)
    9008                 :             :     {
    9009                 :      101317 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9010                 :      101317 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9011                 :             :     }
    9012                 :      101388 :   protected_set_expr_location (r, loc);
    9013                 :      101388 :   return r;
    9014                 :             : }
    9015                 :             : 
    9016                 :             : /* Perform a const_cast from EXPR to TYPE.  If the cast is valid,
    9017                 :             :    return an appropriate expression.  Otherwise, return
    9018                 :             :    error_mark_node.  If the cast is not valid, and COMPLAIN is true,
    9019                 :             :    then a diagnostic will be issued.  If VALID_P is non-NULL, we are
    9020                 :             :    performing a C-style cast, its value upon return will indicate
    9021                 :             :    whether or not the conversion succeeded.  */
    9022                 :             : 
    9023                 :             : static tree
    9024                 :    33056956 : build_const_cast_1 (location_t loc, tree dst_type, tree expr,
    9025                 :             :                     tsubst_flags_t complain, bool *valid_p)
    9026                 :             : {
    9027                 :    33056956 :   tree src_type;
    9028                 :    33056956 :   tree reference_type;
    9029                 :             : 
    9030                 :             :   /* Callers are responsible for handling error_mark_node as a
    9031                 :             :      destination type.  */
    9032                 :    33056956 :   gcc_assert (dst_type != error_mark_node);
    9033                 :             :   /* In a template, callers should be building syntactic
    9034                 :             :      representations of casts, not using this machinery.  */
    9035                 :    33056956 :   gcc_assert (!processing_template_decl);
    9036                 :             : 
    9037                 :             :   /* Assume the conversion is invalid.  */
    9038                 :    33056956 :   if (valid_p)
    9039                 :    32936576 :     *valid_p = false;
    9040                 :             : 
    9041                 :    33056956 :   if (!INDIRECT_TYPE_P (dst_type) && !TYPE_PTRDATAMEM_P (dst_type))
    9042                 :             :     {
    9043                 :    32516715 :       if (complain & tf_error)
    9044                 :          11 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9045                 :             :                   "which is not a pointer, reference, "
    9046                 :             :                   "nor a pointer-to-data-member type", dst_type);
    9047                 :    32516715 :       return error_mark_node;
    9048                 :             :     }
    9049                 :             : 
    9050                 :      540241 :   if (TREE_CODE (TREE_TYPE (dst_type)) == FUNCTION_TYPE)
    9051                 :             :     {
    9052                 :         872 :       if (complain & tf_error)
    9053                 :           8 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9054                 :             :                   "which is a pointer or reference to a function type",
    9055                 :             :                   dst_type);
    9056                 :         872 :        return error_mark_node;
    9057                 :             :     }
    9058                 :             : 
    9059                 :             :   /* A prvalue of non-class type is cv-unqualified.  */
    9060                 :      539369 :   dst_type = cv_unqualified (dst_type);
    9061                 :             : 
    9062                 :             :   /* Save casted types in the function's used types hash table.  */
    9063                 :      539369 :   used_types_insert (dst_type);
    9064                 :             : 
    9065                 :      539369 :   src_type = TREE_TYPE (expr);
    9066                 :             :   /* Expressions do not really have reference types.  */
    9067                 :      539369 :   if (TYPE_REF_P (src_type))
    9068                 :           0 :     src_type = TREE_TYPE (src_type);
    9069                 :             : 
    9070                 :             :   /* [expr.const.cast]
    9071                 :             : 
    9072                 :             :      For two object types T1 and T2, if a pointer to T1 can be explicitly
    9073                 :             :      converted to the type "pointer to T2" using a const_cast, then the
    9074                 :             :      following conversions can also be made:
    9075                 :             : 
    9076                 :             :      -- an lvalue of type T1 can be explicitly converted to an lvalue of
    9077                 :             :      type T2 using the cast const_cast<T2&>;
    9078                 :             : 
    9079                 :             :      -- a glvalue of type T1 can be explicitly converted to an xvalue of
    9080                 :             :      type T2 using the cast const_cast<T2&&>; and
    9081                 :             : 
    9082                 :             :      -- if T1 is a class type, a prvalue of type T1 can be explicitly
    9083                 :             :      converted to an xvalue of type T2 using the cast const_cast<T2&&>.  */
    9084                 :             : 
    9085                 :      539369 :   if (TYPE_REF_P (dst_type))
    9086                 :             :     {
    9087                 :       43589 :       reference_type = dst_type;
    9088                 :       43589 :       if (!TYPE_REF_IS_RVALUE (dst_type)
    9089                 :       43589 :           ? lvalue_p (expr)
    9090                 :         239 :           : obvalue_p (expr))
    9091                 :             :         /* OK.  */;
    9092                 :             :       else
    9093                 :             :         {
    9094                 :          40 :           if (complain & tf_error)
    9095                 :           9 :             error_at (loc, "invalid %<const_cast%> of an rvalue of type %qT "
    9096                 :             :                       "to type %qT",
    9097                 :             :                       src_type, dst_type);
    9098                 :          40 :           return error_mark_node;
    9099                 :             :         }
    9100                 :       43549 :       dst_type = build_pointer_type (TREE_TYPE (dst_type));
    9101                 :       43549 :       src_type = build_pointer_type (src_type);
    9102                 :             :     }
    9103                 :             :   else
    9104                 :             :     {
    9105                 :      495780 :       reference_type = NULL_TREE;
    9106                 :             :       /* If the destination type is not a reference type, the
    9107                 :             :          lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9108                 :             :          conversions are performed.  */
    9109                 :      495780 :       src_type = type_decays_to (src_type);
    9110                 :      495780 :       if (src_type == error_mark_node)
    9111                 :             :         return error_mark_node;
    9112                 :             :     }
    9113                 :             : 
    9114                 :      539329 :   if (TYPE_PTR_P (src_type) || TYPE_PTRDATAMEM_P (src_type))
    9115                 :             :     {
    9116                 :      419843 :       if (comp_ptr_ttypes_const (dst_type, src_type, bounds_none))
    9117                 :             :         {
    9118                 :      155924 :           if (valid_p)
    9119                 :             :             {
    9120                 :       35625 :               *valid_p = true;
    9121                 :             :               /* This cast is actually a C-style cast.  Issue a warning if
    9122                 :             :                  the user is making a potentially unsafe cast.  */
    9123                 :       35625 :               check_for_casting_away_constness (loc, src_type, dst_type,
    9124                 :             :                                                 CAST_EXPR, complain);
    9125                 :             :               /* ??? comp_ptr_ttypes_const ignores TYPE_ALIGN.  */
    9126                 :       35625 :               if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    9127                 :           4 :                   && (complain & tf_warning)
    9128                 :       35633 :                   && min_align_of_type (TREE_TYPE (dst_type))
    9129                 :           4 :                      > min_align_of_type (TREE_TYPE (src_type)))
    9130                 :           4 :                 warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    9131                 :             :                             "increases required alignment of target type",
    9132                 :             :                             src_type, dst_type);
    9133                 :             :             }
    9134                 :      155924 :           if (reference_type)
    9135                 :             :             {
    9136                 :       43298 :               expr = cp_build_addr_expr (expr, complain);
    9137                 :       43298 :               if (expr == error_mark_node)
    9138                 :             :                 return error_mark_node;
    9139                 :       43274 :               expr = build_nop (reference_type, expr);
    9140                 :       43274 :               return convert_from_reference (expr);
    9141                 :             :             }
    9142                 :             :           else
    9143                 :             :             {
    9144                 :      112626 :               expr = decay_conversion (expr, complain);
    9145                 :      112626 :               if (expr == error_mark_node)
    9146                 :             :                 return error_mark_node;
    9147                 :             : 
    9148                 :             :               /* build_c_cast puts on a NOP_EXPR to make the result not an
    9149                 :             :                  lvalue.  Strip such NOP_EXPRs if VALUE is being used in
    9150                 :             :                  non-lvalue context.  */
    9151                 :      112626 :               if (TREE_CODE (expr) == NOP_EXPR
    9152                 :      112626 :                   && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9153                 :           4 :                 expr = TREE_OPERAND (expr, 0);
    9154                 :      112626 :               return build_nop (dst_type, expr);
    9155                 :             :             }
    9156                 :             :         }
    9157                 :      263919 :       else if (valid_p
    9158                 :      527793 :                && !at_least_as_qualified_p (TREE_TYPE (dst_type),
    9159                 :      263874 :                                             TREE_TYPE (src_type)))
    9160                 :       13398 :         check_for_casting_away_constness (loc, src_type, dst_type,
    9161                 :             :                                           CAST_EXPR, complain);
    9162                 :             :     }
    9163                 :             : 
    9164                 :      383405 :   if (complain & tf_error)
    9165                 :          21 :     error_at (loc, "invalid %<const_cast%> from type %qT to type %qT",
    9166                 :             :               src_type, dst_type);
    9167                 :      383405 :   return error_mark_node;
    9168                 :             : }
    9169                 :             : 
    9170                 :             : tree
    9171                 :      588294 : build_const_cast (location_t loc, tree type, tree expr,
    9172                 :             :                   tsubst_flags_t complain)
    9173                 :             : {
    9174                 :      588294 :   tree r;
    9175                 :             : 
    9176                 :      588294 :   if (type == error_mark_node || error_operand_p (expr))
    9177                 :             :     return error_mark_node;
    9178                 :             : 
    9179                 :      588286 :   if (processing_template_decl)
    9180                 :             :     {
    9181                 :      467906 :       tree t = build_min (CONST_CAST_EXPR, type, expr);
    9182                 :             : 
    9183                 :      467906 :       if (!TREE_SIDE_EFFECTS (t)
    9184                 :      467906 :           && type_dependent_expression_p (expr))
    9185                 :             :         /* There might turn out to be side effects inside expr.  */
    9186                 :      384219 :         TREE_SIDE_EFFECTS (t) = 1;
    9187                 :      467906 :       r = convert_from_reference (t);
    9188                 :      467906 :       protected_set_expr_location (r, loc);
    9189                 :      467906 :       return r;
    9190                 :             :     }
    9191                 :             : 
    9192                 :      120380 :   r = build_const_cast_1 (loc, type, expr, complain, /*valid_p=*/NULL);
    9193                 :      120380 :   if (r != error_mark_node)
    9194                 :             :     {
    9195                 :      120299 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9196                 :      120299 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9197                 :             :     }
    9198                 :      120380 :   protected_set_expr_location (r, loc);
    9199                 :      120380 :   return r;
    9200                 :             : }
    9201                 :             : 
    9202                 :             : /* Like cp_build_c_cast, but for the c-common bits.  */
    9203                 :             : 
    9204                 :             : tree
    9205                 :           0 : build_c_cast (location_t loc, tree type, tree expr)
    9206                 :             : {
    9207                 :           0 :   return cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9208                 :             : }
    9209                 :             : 
    9210                 :             : /* Like the "build_c_cast" used for c-common, but using cp_expr to
    9211                 :             :    preserve location information even for tree nodes that don't
    9212                 :             :    support it.  */
    9213                 :             : 
    9214                 :             : cp_expr
    9215                 :     7857656 : build_c_cast (location_t loc, tree type, cp_expr expr)
    9216                 :             : {
    9217                 :     7857656 :   cp_expr result = cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9218                 :     7857656 :   result.set_location (loc);
    9219                 :     7857656 :   return result;
    9220                 :             : }
    9221                 :             : 
    9222                 :             : /* Build an expression representing an explicit C-style cast to type
    9223                 :             :    TYPE of expression EXPR.  */
    9224                 :             : 
    9225                 :             : tree
    9226                 :    34553362 : cp_build_c_cast (location_t loc, tree type, tree expr,
    9227                 :             :                  tsubst_flags_t complain)
    9228                 :             : {
    9229                 :    34553362 :   tree value = expr;
    9230                 :    34553362 :   tree result;
    9231                 :    34553362 :   bool valid_p;
    9232                 :             : 
    9233                 :    34553362 :   if (type == error_mark_node || error_operand_p (expr))
    9234                 :             :     return error_mark_node;
    9235                 :             : 
    9236                 :    34553184 :   if (processing_template_decl)
    9237                 :             :     {
    9238                 :     1616596 :       tree t = build_min (CAST_EXPR, type,
    9239                 :             :                           tree_cons (NULL_TREE, value, NULL_TREE));
    9240                 :             :       /* We don't know if it will or will not have side effects.  */
    9241                 :     1616596 :       TREE_SIDE_EFFECTS (t) = 1;
    9242                 :     1616596 :       return convert_from_reference (t);
    9243                 :             :     }
    9244                 :             : 
    9245                 :             :   /* Casts to a (pointer to a) specific ObjC class (or 'id' or
    9246                 :             :      'Class') should always be retained, because this information aids
    9247                 :             :      in method lookup.  */
    9248                 :    32936588 :   if (objc_is_object_ptr (type)
    9249                 :    32936588 :       && objc_is_object_ptr (TREE_TYPE (expr)))
    9250                 :           0 :     return build_nop (type, expr);
    9251                 :             : 
    9252                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9253                 :             :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9254                 :    32936588 :   if (!TYPE_REF_P (type)
    9255                 :    32936109 :       && TREE_CODE (value) == NOP_EXPR
    9256                 :    33125282 :       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
    9257                 :       58432 :     value = TREE_OPERAND (value, 0);
    9258                 :             : 
    9259                 :    32936588 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9260                 :             :     {
    9261                 :             :       /* Allow casting from T1* to T2[] because Cfront allows it.
    9262                 :             :          NIHCL uses it. It is not valid ISO C++ however.  */
    9263                 :           4 :       if (TYPE_PTR_P (TREE_TYPE (expr)))
    9264                 :             :         {
    9265                 :           0 :           if (complain & tf_error)
    9266                 :           0 :             permerror (loc, "ISO C++ forbids casting to an array type %qT",
    9267                 :             :                        type);
    9268                 :             :           else
    9269                 :           0 :             return error_mark_node;
    9270                 :           0 :           type = build_pointer_type (TREE_TYPE (type));
    9271                 :             :         }
    9272                 :             :       else
    9273                 :             :         {
    9274                 :           4 :           if (complain & tf_error)
    9275                 :           4 :             error_at (loc, "ISO C++ forbids casting to an array type %qT",
    9276                 :             :                       type);
    9277                 :           4 :           return error_mark_node;
    9278                 :             :         }
    9279                 :             :     }
    9280                 :             : 
    9281                 :    32936584 :   if (FUNC_OR_METHOD_TYPE_P (type))
    9282                 :             :     {
    9283                 :          20 :       if (complain & tf_error)
    9284                 :          20 :         error_at (loc, "invalid cast to function type %qT", type);
    9285                 :          20 :       return error_mark_node;
    9286                 :             :     }
    9287                 :             : 
    9288                 :    32936564 :   if (TYPE_PTR_P (type)
    9289                 :      419243 :       && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
    9290                 :             :       /* Casting to an integer of smaller size is an error detected elsewhere.  */
    9291                 :      118039 :       && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (value))
    9292                 :             :       /* Don't warn about converting any constant.  */
    9293                 :    32999867 :       && !TREE_CONSTANT (value))
    9294                 :          62 :     warning_at (loc, OPT_Wint_to_pointer_cast, 
    9295                 :             :                 "cast to pointer from integer of different size");
    9296                 :             : 
    9297                 :             :   /* A C-style cast can be a const_cast.  */
    9298                 :    32936564 :   result = build_const_cast_1 (loc, type, value, complain & tf_warning,
    9299                 :             :                                &valid_p);
    9300                 :    32936564 :   if (valid_p)
    9301                 :             :     {
    9302                 :       35613 :       if (result != error_mark_node)
    9303                 :             :         {
    9304                 :       35601 :           maybe_warn_about_useless_cast (loc, type, value, complain);
    9305                 :       35601 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9306                 :             :         }
    9307                 :          12 :       else if (complain & tf_error)
    9308                 :          12 :         build_const_cast_1 (loc, type, value, tf_error, &valid_p);
    9309                 :       35613 :       return result;
    9310                 :             :     }
    9311                 :             : 
    9312                 :             :   /* Or a static cast.  */
    9313                 :    32900951 :   result = build_static_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9314                 :             :                                 &valid_p, complain);
    9315                 :             :   /* Or a reinterpret_cast.  */
    9316                 :    32900951 :   if (!valid_p)
    9317                 :     1447465 :     result = build_reinterpret_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9318                 :             :                                        &valid_p, complain);
    9319                 :             :   /* The static_cast or reinterpret_cast may be followed by a
    9320                 :             :      const_cast.  */
    9321                 :    32900951 :   if (valid_p
    9322                 :             :       /* A valid cast may result in errors if, for example, a
    9323                 :             :          conversion to an ambiguous base class is required.  */
    9324                 :    32900951 :       && !error_operand_p (result))
    9325                 :             :     {
    9326                 :    32900657 :       tree result_type;
    9327                 :             : 
    9328                 :    32900657 :       maybe_warn_about_useless_cast (loc, type, value, complain);
    9329                 :    32900657 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9330                 :             : 
    9331                 :             :       /* Non-class rvalues always have cv-unqualified type.  */
    9332                 :    32900657 :       if (!CLASS_TYPE_P (type))
    9333                 :    31708545 :         type = TYPE_MAIN_VARIANT (type);
    9334                 :    32900657 :       result_type = TREE_TYPE (result);
    9335                 :    32900657 :       if (!CLASS_TYPE_P (result_type) && !TYPE_REF_P (type))
    9336                 :    31708265 :         result_type = TYPE_MAIN_VARIANT (result_type);
    9337                 :             :       /* If the type of RESULT does not match TYPE, perform a
    9338                 :             :          const_cast to make it match.  If the static_cast or
    9339                 :             :          reinterpret_cast succeeded, we will differ by at most
    9340                 :             :          cv-qualification, so the follow-on const_cast is guaranteed
    9341                 :             :          to succeed.  */
    9342                 :    32900657 :       if (!same_type_p (non_reference (type), non_reference (result_type)))
    9343                 :             :         {
    9344                 :           0 :           result = build_const_cast_1 (loc, type, result, tf_none, &valid_p);
    9345                 :           0 :           gcc_assert (valid_p);
    9346                 :             :         }
    9347                 :    32900657 :       return result;
    9348                 :             :     }
    9349                 :             : 
    9350                 :         294 :   return error_mark_node;
    9351                 :             : }
    9352                 :             : 
    9353                 :             : /* Warn when a value is moved to itself with std::move.  LHS is the target,
    9354                 :             :    RHS may be the std::move call, and LOC is the location of the whole
    9355                 :             :    assignment.  */
    9356                 :             : 
    9357                 :             : static void
    9358                 :    22570887 : maybe_warn_self_move (location_t loc, tree lhs, tree rhs)
    9359                 :             : {
    9360                 :    22570887 :   if (!warn_self_move)
    9361                 :    22569512 :     return;
    9362                 :             : 
    9363                 :             :   /* C++98 doesn't know move.  */
    9364                 :      278948 :   if (cxx_dialect < cxx11)
    9365                 :             :     return;
    9366                 :             : 
    9367                 :      261510 :   if (processing_template_decl)
    9368                 :             :     return;
    9369                 :             : 
    9370                 :       10997 :   if (!REFERENCE_REF_P (rhs)
    9371                 :      215198 :       || TREE_CODE (TREE_OPERAND (rhs, 0)) != CALL_EXPR)
    9372                 :             :     return;
    9373                 :        2247 :   tree fn = TREE_OPERAND (rhs, 0);
    9374                 :        2247 :   if (!is_std_move_p (fn))
    9375                 :             :     return;
    9376                 :             : 
    9377                 :             :   /* Just a little helper to strip * and various NOPs.  */
    9378                 :        4125 :   auto extract_op = [] (tree &op) {
    9379                 :        2750 :     STRIP_NOPS (op);
    9380                 :        3905 :     while (INDIRECT_REF_P (op))
    9381                 :        1155 :       op = TREE_OPERAND (op, 0);
    9382                 :        2750 :     op = maybe_undo_parenthesized_ref (op);
    9383                 :        2750 :     STRIP_ANY_LOCATION_WRAPPER (op);
    9384                 :        2750 :   };
    9385                 :             : 
    9386                 :        1375 :   tree arg = CALL_EXPR_ARG (fn, 0);
    9387                 :        1375 :   extract_op (arg);
    9388                 :        1375 :   if (TREE_CODE (arg) == ADDR_EXPR)
    9389                 :         691 :     arg = TREE_OPERAND (arg, 0);
    9390                 :        1375 :   tree type = TREE_TYPE (lhs);
    9391                 :        1375 :   tree orig_lhs = lhs;
    9392                 :        1375 :   extract_op (lhs);
    9393                 :        1375 :   if (cp_tree_equal (lhs, arg))
    9394                 :             :     {
    9395                 :         111 :       auto_diagnostic_group d;
    9396                 :         111 :       if (warning_at (loc, OPT_Wself_move,
    9397                 :             :                       "moving %qE of type %qT to itself", orig_lhs, type))
    9398                 :         111 :         inform (loc, "remove %<std::move%> call");
    9399                 :         111 :     }
    9400                 :             : }
    9401                 :             : 
    9402                 :             : /* For use from the C common bits.  */
    9403                 :             : tree
    9404                 :        6745 : build_modify_expr (location_t location,
    9405                 :             :                    tree lhs, tree /*lhs_origtype*/,
    9406                 :             :                    enum tree_code modifycode, 
    9407                 :             :                    location_t /*rhs_location*/, tree rhs,
    9408                 :             :                    tree /*rhs_origtype*/)
    9409                 :             : {
    9410                 :        6745 :   return cp_build_modify_expr (location, lhs, modifycode, rhs,
    9411                 :        6745 :                                tf_warning_or_error);
    9412                 :             : }
    9413                 :             : 
    9414                 :             : /* Build an assignment expression of lvalue LHS from value RHS.
    9415                 :             :    MODIFYCODE is the code for a binary operator that we use
    9416                 :             :    to combine the old value of LHS with RHS to get the new value.
    9417                 :             :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    9418                 :             : 
    9419                 :             :    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.  */
    9420                 :             : 
    9421                 :             : tree
    9422                 :    29441247 : cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
    9423                 :             :                       tree rhs, tsubst_flags_t complain)
    9424                 :             : {
    9425                 :    29441247 :   lhs = mark_lvalue_use_nonread (lhs);
    9426                 :             : 
    9427                 :    29441247 :   tree result = NULL_TREE;
    9428                 :    29441247 :   tree newrhs = rhs;
    9429                 :    29441247 :   tree lhstype = TREE_TYPE (lhs);
    9430                 :    29441247 :   tree olhs = lhs;
    9431                 :    29441247 :   tree olhstype = lhstype;
    9432                 :    29441247 :   bool plain_assign = (modifycode == NOP_EXPR);
    9433                 :    29441247 :   bool compound_side_effects_p = false;
    9434                 :    29441247 :   tree preeval = NULL_TREE;
    9435                 :             : 
    9436                 :             :   /* Avoid duplicate error messages from operands that had errors.  */
    9437                 :    29441247 :   if (error_operand_p (lhs) || error_operand_p (rhs))
    9438                 :          25 :     return error_mark_node;
    9439                 :             : 
    9440                 :    29441312 :   while (TREE_CODE (lhs) == COMPOUND_EXPR)
    9441                 :             :     {
    9442                 :          90 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
    9443                 :          78 :         compound_side_effects_p = true;
    9444                 :          90 :       lhs = TREE_OPERAND (lhs, 1);
    9445                 :             :     }
    9446                 :             : 
    9447                 :             :   /* Handle control structure constructs used as "lvalues".  Note that we
    9448                 :             :      leave COMPOUND_EXPR on the LHS because it is sequenced after the RHS.  */
    9449                 :    29441222 :   switch (TREE_CODE (lhs))
    9450                 :             :     {
    9451                 :             :       /* Handle --foo = 5; as these are valid constructs in C++.  */
    9452                 :          28 :     case PREDECREMENT_EXPR:
    9453                 :          28 :     case PREINCREMENT_EXPR:
    9454                 :          28 :       if (compound_side_effects_p)
    9455                 :          12 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
    9456                 :          28 :       lhs = genericize_compound_lvalue (lhs);
    9457                 :         140 :     maybe_add_compound:
    9458                 :             :       /* If we had (bar, --foo) = 5; or (bar, (baz, --foo)) = 5;
    9459                 :             :          and looked through the COMPOUND_EXPRs, readd them now around
    9460                 :             :          the resulting lhs.  */
    9461                 :         140 :       if (TREE_CODE (olhs) == COMPOUND_EXPR)
    9462                 :             :         {
    9463                 :          12 :           lhs = build2 (COMPOUND_EXPR, lhstype, TREE_OPERAND (olhs, 0), lhs);
    9464                 :          12 :           tree *ptr = &TREE_OPERAND (lhs, 1);
    9465                 :          12 :           for (olhs = TREE_OPERAND (olhs, 1);
    9466                 :          16 :                TREE_CODE (olhs) == COMPOUND_EXPR;
    9467                 :           4 :                olhs = TREE_OPERAND (olhs, 1))
    9468                 :             :             {
    9469                 :           4 :               *ptr = build2 (COMPOUND_EXPR, lhstype,
    9470                 :           4 :                              TREE_OPERAND (olhs, 0), *ptr);
    9471                 :           4 :               ptr = &TREE_OPERAND (*ptr, 1);
    9472                 :             :             }
    9473                 :             :         }
    9474                 :             :       break;
    9475                 :             : 
    9476                 :         112 :     case MODIFY_EXPR:
    9477                 :         112 :       if (compound_side_effects_p)
    9478                 :           0 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
    9479                 :         112 :       lhs = genericize_compound_lvalue (lhs);
    9480                 :         112 :       goto maybe_add_compound;
    9481                 :             : 
    9482                 :           0 :     case MIN_EXPR:
    9483                 :           0 :     case MAX_EXPR:
    9484                 :             :       /* MIN_EXPR and MAX_EXPR are currently only permitted as lvalues,
    9485                 :             :          when neither operand has side-effects.  */
    9486                 :           0 :       if (!lvalue_or_else (lhs, lv_assign, complain))
    9487                 :           0 :         return error_mark_node;
    9488                 :             : 
    9489                 :           0 :       gcc_assert (!TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0))
    9490                 :             :                   && !TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 1)));
    9491                 :             : 
    9492                 :           0 :       lhs = build3 (COND_EXPR, TREE_TYPE (lhs),
    9493                 :           0 :                     build2 (TREE_CODE (lhs) == MIN_EXPR ? LE_EXPR : GE_EXPR,
    9494                 :             :                             boolean_type_node,
    9495                 :           0 :                             TREE_OPERAND (lhs, 0),
    9496                 :           0 :                             TREE_OPERAND (lhs, 1)),
    9497                 :           0 :                     TREE_OPERAND (lhs, 0),
    9498                 :           0 :                     TREE_OPERAND (lhs, 1));
    9499                 :         243 :       gcc_fallthrough ();
    9500                 :             : 
    9501                 :             :       /* Handle (a ? b : c) used as an "lvalue".  */
    9502                 :         243 :     case COND_EXPR:
    9503                 :         243 :       {
    9504                 :             :         /* Produce (a ? (b = rhs) : (c = rhs))
    9505                 :             :            except that the RHS goes through a save-expr
    9506                 :             :            so the code to compute it is only emitted once.  */
    9507                 :         243 :         if (VOID_TYPE_P (TREE_TYPE (rhs)))
    9508                 :             :           {
    9509                 :          24 :             if (complain & tf_error)
    9510                 :          32 :               error_at (cp_expr_loc_or_loc (rhs, loc),
    9511                 :             :                         "void value not ignored as it ought to be");
    9512                 :          24 :             return error_mark_node;
    9513                 :             :           }
    9514                 :             : 
    9515                 :         219 :         rhs = stabilize_expr (rhs, &preeval);
    9516                 :             : 
    9517                 :             :         /* Check this here to avoid odd errors when trying to convert
    9518                 :             :            a throw to the type of the COND_EXPR.  */
    9519                 :         219 :         if (!lvalue_or_else (lhs, lv_assign, complain))
    9520                 :           8 :           return error_mark_node;
    9521                 :             : 
    9522                 :         211 :         tree op1 = TREE_OPERAND (lhs, 1);
    9523                 :         211 :         if (TREE_CODE (op1) != THROW_EXPR)
    9524                 :         203 :           op1 = cp_build_modify_expr (loc, op1, modifycode, rhs, complain);
    9525                 :             :         /* When sanitizing undefined behavior, even when rhs doesn't need
    9526                 :             :            stabilization at this point, the sanitization might add extra
    9527                 :             :            SAVE_EXPRs in there and so make sure there is no tree sharing
    9528                 :             :            in the rhs, otherwise those SAVE_EXPRs will have initialization
    9529                 :             :            only in one of the two branches.  */
    9530                 :         211 :         if (sanitize_flags_p (SANITIZE_UNDEFINED
    9531                 :             :                               | SANITIZE_UNDEFINED_NONDEFAULT))
    9532                 :           3 :           rhs = unshare_expr (rhs);
    9533                 :         211 :         tree op2 = TREE_OPERAND (lhs, 2);
    9534                 :         211 :         if (TREE_CODE (op2) != THROW_EXPR)
    9535                 :         203 :           op2 = cp_build_modify_expr (loc, op2, modifycode, rhs, complain);
    9536                 :         211 :         tree cond = build_conditional_expr (input_location,
    9537                 :         211 :                                             TREE_OPERAND (lhs, 0), op1, op2,
    9538                 :             :                                             complain);
    9539                 :             : 
    9540                 :         211 :         if (cond == error_mark_node)
    9541                 :             :           return cond;
    9542                 :             :         /* If we had (e, (a ? b : c)) = d; or (e, (f, (a ? b : c))) = d;
    9543                 :             :            and looked through the COMPOUND_EXPRs, readd them now around
    9544                 :             :            the resulting cond before adding the preevaluated rhs.  */
    9545                 :         211 :         if (TREE_CODE (olhs) == COMPOUND_EXPR)
    9546                 :             :           {
    9547                 :          20 :             cond = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
    9548                 :          20 :                            TREE_OPERAND (olhs, 0), cond);
    9549                 :          20 :             tree *ptr = &TREE_OPERAND (cond, 1);
    9550                 :          20 :             for (olhs = TREE_OPERAND (olhs, 1);
    9551                 :          24 :                  TREE_CODE (olhs) == COMPOUND_EXPR;
    9552                 :           4 :                  olhs = TREE_OPERAND (olhs, 1))
    9553                 :             :               {
    9554                 :           4 :                 *ptr = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
    9555                 :           4 :                                TREE_OPERAND (olhs, 0), *ptr);
    9556                 :           4 :                 ptr = &TREE_OPERAND (*ptr, 1);
    9557                 :             :               }
    9558                 :             :           }
    9559                 :             :         /* Make sure the code to compute the rhs comes out
    9560                 :             :            before the split.  */
    9561                 :         211 :         result = cond;
    9562                 :         211 :         goto ret;
    9563                 :             :       }
    9564                 :             : 
    9565                 :             :     default:
    9566                 :             :       lhs = olhs;
    9567                 :             :       break;
    9568                 :             :     }
    9569                 :             : 
    9570                 :    29440979 :   if (modifycode == INIT_EXPR)
    9571                 :             :     {
    9572                 :     3041932 :       if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
    9573                 :             :         /* Do the default thing.  */;
    9574                 :     2874579 :       else if (TREE_CODE (rhs) == CONSTRUCTOR)
    9575                 :             :         {
    9576                 :             :           /* Compound literal.  */
    9577                 :         126 :           if (! same_type_p (TREE_TYPE (rhs), lhstype))
    9578                 :             :             /* Call convert to generate an error; see PR 11063.  */
    9579                 :           0 :             rhs = convert (lhstype, rhs);
    9580                 :         126 :           result = cp_build_init_expr (lhs, rhs);
    9581                 :         126 :           TREE_SIDE_EFFECTS (result) = 1;
    9582                 :         126 :           goto ret;
    9583                 :             :         }
    9584                 :     2874453 :       else if (! MAYBE_CLASS_TYPE_P (lhstype))
    9585                 :             :         /* Do the default thing.  */;
    9586                 :             :       else
    9587                 :             :         {
    9588                 :       43187 :           releasing_vec rhs_vec = make_tree_vector_single (rhs);
    9589                 :       43187 :           result = build_special_member_call (lhs, complete_ctor_identifier,
    9590                 :             :                                               &rhs_vec, lhstype, LOOKUP_NORMAL,
    9591                 :             :                                               complain);
    9592                 :       43187 :           if (result == NULL_TREE)
    9593                 :           0 :             return error_mark_node;
    9594                 :       43187 :           goto ret;
    9595                 :       43187 :         }
    9596                 :             :     }
    9597                 :             :   else
    9598                 :             :     {
    9599                 :    26399047 :       lhs = require_complete_type (lhs, complain);
    9600                 :    26399047 :       if (lhs == error_mark_node)
    9601                 :             :         return error_mark_node;
    9602                 :             : 
    9603                 :    26399005 :       if (modifycode == NOP_EXPR)
    9604                 :             :         {
    9605                 :    22570887 :           maybe_warn_self_move (loc, lhs, rhs);
    9606                 :             : 
    9607                 :    22570887 :           if (c_dialect_objc ())
    9608                 :             :             {
    9609                 :           0 :               result = objc_maybe_build_modify_expr (lhs, rhs);
    9610                 :           0 :               if (result)
    9611                 :           0 :                 goto ret;
    9612                 :             :             }
    9613                 :             : 
    9614                 :             :           /* `operator=' is not an inheritable operator.  */
    9615                 :    22570887 :           if (! MAYBE_CLASS_TYPE_P (lhstype))
    9616                 :             :             /* Do the default thing.  */;
    9617                 :             :           else
    9618                 :             :             {
    9619                 :     1727031 :               result = build_new_op (input_location, MODIFY_EXPR,
    9620                 :             :                                      LOOKUP_NORMAL, lhs, rhs,
    9621                 :             :                                      make_node (NOP_EXPR), NULL_TREE,
    9622                 :             :                                      /*overload=*/NULL, complain);
    9623                 :     1727031 :               if (result == NULL_TREE)
    9624                 :           0 :                 return error_mark_node;
    9625                 :     1727031 :               goto ret;
    9626                 :             :             }
    9627                 :             :           lhstype = olhstype;
    9628                 :             :         }
    9629                 :             :       else
    9630                 :             :         {
    9631                 :     3828118 :           tree init = NULL_TREE;
    9632                 :             : 
    9633                 :             :           /* A binary op has been requested.  Combine the old LHS
    9634                 :             :              value with the RHS producing the value we should actually
    9635                 :             :              store into the LHS.  */
    9636                 :     3828118 :           gcc_assert (!((TYPE_REF_P (lhstype)
    9637                 :             :                          && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype)))
    9638                 :             :                         || MAYBE_CLASS_TYPE_P (lhstype)));
    9639                 :             : 
    9640                 :             :           /* Preevaluate the RHS to make sure its evaluation is complete
    9641                 :             :              before the lvalue-to-rvalue conversion of the LHS:
    9642                 :             : 
    9643                 :             :              [expr.ass] With respect to an indeterminately-sequenced
    9644                 :             :              function call, the operation of a compound assignment is a
    9645                 :             :              single evaluation. [ Note: Therefore, a function call shall
    9646                 :             :              not intervene between the lvalue-to-rvalue conversion and the
    9647                 :             :              side effect associated with any single compound assignment
    9648                 :             :              operator. -- end note ]  */
    9649                 :     3828118 :           lhs = cp_stabilize_reference (lhs);
    9650                 :     3828118 :           rhs = decay_conversion (rhs, complain);
    9651                 :     3828118 :           if (rhs == error_mark_node)
    9652                 :         164 :             return error_mark_node;
    9653                 :     3828114 :           rhs = stabilize_expr (rhs, &init);
    9654                 :     3828114 :           newrhs = cp_build_binary_op (loc, modifycode, lhs, rhs, complain);
    9655                 :     3828114 :           if (newrhs == error_mark_node)
    9656                 :             :             {
    9657                 :         160 :               if (complain & tf_error)
    9658                 :          32 :                 inform (loc, "  in evaluation of %<%Q(%#T, %#T)%>",
    9659                 :          32 :                         modifycode, TREE_TYPE (lhs), TREE_TYPE (rhs));
    9660                 :         160 :               return error_mark_node;
    9661                 :             :             }
    9662                 :             : 
    9663                 :     3827954 :           if (init)
    9664                 :      257687 :             newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), init, newrhs);
    9665                 :             : 
    9666                 :             :           /* Now it looks like a plain assignment.  */
    9667                 :     3827954 :           modifycode = NOP_EXPR;
    9668                 :     3827954 :           if (c_dialect_objc ())
    9669                 :             :             {
    9670                 :           0 :               result = objc_maybe_build_modify_expr (lhs, newrhs);
    9671                 :           0 :               if (result)
    9672                 :           0 :                 goto ret;
    9673                 :             :             }
    9674                 :             :         }
    9675                 :    24671810 :       gcc_assert (!TYPE_REF_P (lhstype));
    9676                 :    24671810 :       gcc_assert (!TYPE_REF_P (TREE_TYPE (newrhs)));
    9677                 :             :     }
    9678                 :             : 
    9679                 :             :   /* The left-hand side must be an lvalue.  */
    9680                 :    27670429 :   if (!lvalue_or_else (lhs, lv_assign, complain))
    9681                 :         171 :     return error_mark_node;
    9682                 :             : 
    9683                 :             :   /* Warn about modifying something that is `const'.  Don't warn if
    9684                 :             :      this is initialization.  */
    9685                 :    27670258 :   if (modifycode != INIT_EXPR
    9686                 :    27670258 :       && (TREE_READONLY (lhs) || CP_TYPE_CONST_P (lhstype)
    9687                 :             :           /* Functions are not modifiable, even though they are
    9688                 :             :              lvalues.  */
    9689                 :    24629086 :           || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (lhs))
    9690                 :             :           /* If it's an aggregate and any field is const, then it is
    9691                 :             :              effectively const.  */
    9692                 :    24629059 :           || (CLASS_TYPE_P (lhstype)
    9693                 :           0 :               && C_TYPE_FIELDS_READONLY (lhstype))))
    9694                 :             :     {
    9695                 :       42580 :       if (complain & tf_error)
    9696                 :          90 :         cxx_readonly_error (loc, lhs, lv_assign);
    9697                 :       42580 :       return error_mark_node;
    9698                 :             :     }
    9699                 :             : 
    9700                 :             :   /* If storing into a structure or union member, it may have been given a
    9701                 :             :      lowered bitfield type.  We need to convert to the declared type first,
    9702                 :             :      so retrieve it now.  */
    9703                 :             : 
    9704                 :    27627678 :   olhstype = unlowered_expr_type (lhs);
    9705                 :             : 
    9706                 :             :   /* Convert new value to destination type.  */
    9707                 :             : 
    9708                 :    27627678 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
    9709                 :             :     {
    9710                 :         198 :       int from_array;
    9711                 :             : 
    9712                 :         198 :       if (BRACE_ENCLOSED_INITIALIZER_P (newrhs))
    9713                 :             :         {
    9714                 :          12 :           if (modifycode != INIT_EXPR)
    9715                 :             :             {
    9716                 :          12 :               if (complain & tf_error)
    9717                 :          12 :                 error_at (loc,
    9718                 :             :                           "assigning to an array from an initializer list");
    9719                 :          12 :               return error_mark_node;
    9720                 :             :             }
    9721                 :           0 :           if (check_array_initializer (lhs, lhstype, newrhs))
    9722                 :           0 :             return error_mark_node;
    9723                 :           0 :           newrhs = digest_init (lhstype, newrhs, complain);
    9724                 :           0 :           if (newrhs == error_mark_node)
    9725                 :             :             return error_mark_node;
    9726                 :             :         }
    9727                 :             : 
    9728                 :             :       /* C++11 8.5/17: "If the destination type is an array of characters,
    9729                 :             :          an array of char16_t, an array of char32_t, or an array of wchar_t,
    9730                 :             :          and the initializer is a string literal...".  */
    9731                 :         186 :       else if ((TREE_CODE (tree_strip_any_location_wrapper (newrhs))
    9732                 :             :                 == STRING_CST)
    9733                 :          48 :                && char_type_p (TREE_TYPE (TYPE_MAIN_VARIANT (lhstype)))
    9734                 :         234 :                && modifycode == INIT_EXPR)
    9735                 :             :         {
    9736                 :          28 :           newrhs = digest_init (lhstype, newrhs, complain);
    9737                 :          28 :           if (newrhs == error_mark_node)
    9738                 :             :             return error_mark_node;
    9739                 :             :         }
    9740                 :             : 
    9741                 :         158 :       else if (!same_or_base_type_p (TYPE_MAIN_VARIANT (lhstype),
    9742                 :             :                                      TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))))
    9743                 :             :         {
    9744                 :          26 :           if (complain & tf_error)
    9745                 :          21 :             error_at (loc, "incompatible types in assignment of %qT to %qT",
    9746                 :          21 :                       TREE_TYPE (rhs), lhstype);
    9747                 :          26 :           return error_mark_node;
    9748                 :             :         }
    9749                 :             : 
    9750                 :             :       /* Allow array assignment in compiler-generated code.  */
    9751                 :         132 :       else if (DECL_P (lhs) && DECL_ARTIFICIAL (lhs))
    9752                 :             :         /* OK, used by coroutines (co-await-initlist1.C).  */;
    9753                 :         130 :       else if (!current_function_decl
    9754                 :         130 :                || !DECL_DEFAULTED_FN (current_function_decl))
    9755                 :             :         {
    9756                 :             :           /* This routine is used for both initialization and assignment.
    9757                 :             :              Make sure the diagnostic message differentiates the context.  */
    9758                 :          72 :           if (complain & tf_error)
    9759                 :             :             {
    9760                 :          39 :               if (modifycode == INIT_EXPR)
    9761                 :          11 :                 error_at (loc, "array used as initializer");
    9762                 :             :               else
    9763                 :          28 :                 error_at (loc, "invalid array assignment");
    9764                 :             :             }
    9765                 :          72 :           return error_mark_node;
    9766                 :             :         }
    9767                 :             : 
    9768                 :          88 :       from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
    9769                 :          88 :                    ? 1 + (modifycode != INIT_EXPR): 0;
    9770                 :          88 :       result = build_vec_init (lhs, NULL_TREE, newrhs,
    9771                 :             :                                /*explicit_value_init_p=*/false,
    9772                 :             :                                from_array, complain);
    9773                 :          88 :       goto ret;
    9774                 :             :     }
    9775                 :             : 
    9776                 :    27627480 :   if (modifycode == INIT_EXPR)
    9777                 :             :     /* Calls with INIT_EXPR are all direct-initialization, so don't set
    9778                 :             :        LOOKUP_ONLYCONVERTING.  */
    9779                 :     2998553 :     newrhs = convert_for_initialization (lhs, olhstype, newrhs, LOOKUP_NORMAL,
    9780                 :             :                                          ICR_INIT, NULL_TREE, 0,
    9781                 :             :                                          complain | tf_no_cleanup);
    9782                 :             :   else
    9783                 :    24628927 :     newrhs = convert_for_assignment (olhstype, newrhs, ICR_ASSIGN,
    9784                 :             :                                      NULL_TREE, 0, complain, LOOKUP_IMPLICIT);
    9785                 :             : 
    9786                 :    27627480 :   if (!same_type_p (lhstype, olhstype))
    9787                 :      170731 :     newrhs = cp_convert_and_check (lhstype, newrhs, complain);
    9788                 :             : 
    9789                 :    27627480 :   if (modifycode != INIT_EXPR)
    9790                 :             :     {
    9791                 :    24628927 :       if (TREE_CODE (newrhs) == CALL_EXPR
    9792                 :    24628927 :           && TYPE_NEEDS_CONSTRUCTING (lhstype))
    9793                 :           0 :         newrhs = build_cplus_new (lhstype, newrhs, complain);
    9794                 :             : 
    9795                 :             :       /* Can't initialize directly from a TARGET_EXPR, since that would
    9796                 :             :          cause the lhs to be constructed twice, and possibly result in
    9797                 :             :          accidental self-initialization.  So we force the TARGET_EXPR to be
    9798                 :             :          expanded without a target.  */
    9799                 :    24628927 :       if (TREE_CODE (newrhs) == TARGET_EXPR)
    9800                 :          92 :         newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), newrhs,
    9801                 :          92 :                          TREE_OPERAND (newrhs, 0));
    9802                 :             :     }
    9803                 :             : 
    9804                 :    27627480 :   if (newrhs == error_mark_node)
    9805                 :             :     return error_mark_node;
    9806                 :             : 
    9807                 :    27626791 :   if (c_dialect_objc () && flag_objc_gc)
    9808                 :             :     {
    9809                 :           0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
    9810                 :             : 
    9811                 :           0 :       if (result)
    9812                 :           0 :         goto ret;
    9813                 :             :     }
    9814                 :             : 
    9815                 :    30625300 :   result = build2_loc (loc, modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
    9816                 :             :                        lhstype, lhs, newrhs);
    9817                 :    27626791 :   if (modifycode == INIT_EXPR)
    9818                 :     2998509 :     set_target_expr_eliding (newrhs);
    9819                 :             : 
    9820                 :    27626791 :   TREE_SIDE_EFFECTS (result) = 1;
    9821                 :    27626791 :   if (!plain_assign)
    9822                 :     6826426 :     suppress_warning (result, OPT_Wparentheses);
    9823                 :             : 
    9824                 :    20800365 :  ret:
    9825                 :    29397434 :   if (preeval)
    9826                 :          39 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), preeval, result);
    9827                 :             :   return result;
    9828                 :             : }
    9829                 :             : 
    9830                 :             : cp_expr
    9831                 :    52579871 : build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
    9832                 :             :                      tree rhs, tree lookups, tsubst_flags_t complain)
    9833                 :             : {
    9834                 :    52579871 :   tree orig_lhs = lhs;
    9835                 :    52579871 :   tree orig_rhs = rhs;
    9836                 :    52579871 :   tree overload = NULL_TREE;
    9837                 :             : 
    9838                 :    52579871 :   if (lhs == error_mark_node || rhs == error_mark_node)
    9839                 :        2630 :     return cp_expr (error_mark_node, loc);
    9840                 :             : 
    9841                 :    52577241 :   tree op = build_min (modifycode, void_type_node, NULL_TREE, NULL_TREE);
    9842                 :             : 
    9843                 :    52577241 :   if (processing_template_decl)
    9844                 :             :     {
    9845                 :    35140780 :       if (type_dependent_expression_p (lhs)
    9846                 :    35140780 :           || type_dependent_expression_p (rhs))
    9847                 :             :         {
    9848                 :    26422177 :           tree rval = build_min_nt_loc (loc, MODOP_EXPR, lhs, op, rhs);
    9849                 :    26422177 :           if (modifycode != NOP_EXPR)
    9850                 :     5335901 :             TREE_TYPE (rval)
    9851                 :    10671802 :               = build_dependent_operator_type (lookups, modifycode, true);
    9852                 :    26422177 :           return rval;
    9853                 :             :         }
    9854                 :             :     }
    9855                 :             : 
    9856                 :    26155064 :   tree rval;
    9857                 :    26155064 :   if (modifycode == NOP_EXPR)
    9858                 :    20808522 :     rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, complain);
    9859                 :             :   else
    9860                 :     5346542 :     rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
    9861                 :             :                          lhs, rhs, op, lookups, &overload, complain);
    9862                 :    26155064 :   if (rval == error_mark_node)
    9863                 :        1972 :     return error_mark_node;
    9864                 :    26153092 :   if (processing_template_decl)
    9865                 :             :     {
    9866                 :     8718579 :       if (overload != NULL_TREE)
    9867                 :     1140501 :         return (build_min_non_dep_op_overload
    9868                 :     1140501 :                 (MODIFY_EXPR, rval, overload, orig_lhs, orig_rhs));
    9869                 :             : 
    9870                 :     7578078 :       return (build_min_non_dep
    9871                 :     7578078 :               (MODOP_EXPR, rval, orig_lhs, op, orig_rhs));
    9872                 :             :     }
    9873                 :    17434513 :   return rval;
    9874                 :             : }
    9875                 :             : 
    9876                 :             : /* Helper function for get_delta_difference which assumes FROM is a base
    9877                 :             :    class of TO.  Returns a delta for the conversion of pointer-to-member
    9878                 :             :    of FROM to pointer-to-member of TO.  If the conversion is invalid and 
    9879                 :             :    tf_error is not set in COMPLAIN returns error_mark_node, otherwise
    9880                 :             :    returns zero.  If FROM is not a base class of TO, returns NULL_TREE.
    9881                 :             :    If C_CAST_P is true, this conversion is taking place as part of a 
    9882                 :             :    C-style cast.  */
    9883                 :             : 
    9884                 :             : static tree
    9885                 :       28923 : get_delta_difference_1 (tree from, tree to, bool c_cast_p,
    9886                 :             :                         tsubst_flags_t complain)
    9887                 :             : {
    9888                 :       28923 :   tree binfo;
    9889                 :       28923 :   base_kind kind;
    9890                 :             : 
    9891                 :       57518 :   binfo = lookup_base (to, from, c_cast_p ? ba_unique : ba_check,
    9892                 :             :                        &kind, complain);
    9893                 :             : 
    9894                 :       28923 :   if (binfo == error_mark_node)
    9895                 :             :     {
    9896                 :          68 :       if (!(complain & tf_error))
    9897                 :             :         return error_mark_node;
    9898                 :             : 
    9899                 :          68 :       inform (input_location, "   in pointer to member function conversion");
    9900                 :          68 :       return size_zero_node;
    9901                 :             :     }
    9902                 :       28855 :   else if (binfo)
    9903                 :             :     {
    9904                 :       28667 :       if (kind != bk_via_virtual)
    9905                 :       28545 :         return BINFO_OFFSET (binfo);
    9906                 :             :       else
    9907                 :             :         /* FROM is a virtual base class of TO.  Issue an error or warning
    9908                 :             :            depending on whether or not this is a reinterpret cast.  */
    9909                 :             :         {
    9910                 :         122 :           if (!(complain & tf_error))
    9911                 :             :             return error_mark_node;
    9912                 :             : 
    9913                 :         104 :           error ("pointer to member conversion via virtual base %qT",
    9914                 :         104 :                  BINFO_TYPE (binfo_from_vbase (binfo)));
    9915                 :             : 
    9916                 :         104 :           return size_zero_node;
    9917                 :             :         }
    9918                 :             :       }
    9919                 :             :   else
    9920                 :             :     return NULL_TREE;
    9921                 :             : }
    9922                 :             : 
    9923                 :             : /* Get difference in deltas for different pointer to member function
    9924                 :             :    types.  If the conversion is invalid and tf_error is not set in
    9925                 :             :    COMPLAIN, returns error_mark_node, otherwise returns an integer
    9926                 :             :    constant of type PTRDIFF_TYPE_NODE and its value is zero if the
    9927                 :             :    conversion is invalid.  If ALLOW_INVERSE_P is true, then allow reverse
    9928                 :             :    conversions as well.  If C_CAST_P is true this conversion is taking
    9929                 :             :    place as part of a C-style cast.
    9930                 :             : 
    9931                 :             :    Note that the naming of FROM and TO is kind of backwards; the return
    9932                 :             :    value is what we add to a TO in order to get a FROM.  They are named
    9933                 :             :    this way because we call this function to find out how to convert from
    9934                 :             :    a pointer to member of FROM to a pointer to member of TO.  */
    9935                 :             : 
    9936                 :             : static tree
    9937                 :       89893 : get_delta_difference (tree from, tree to,
    9938                 :             :                       bool allow_inverse_p,
    9939                 :             :                       bool c_cast_p, tsubst_flags_t complain)
    9940                 :             : {
    9941                 :       89893 :   tree result;
    9942                 :             : 
    9943                 :       89893 :   if (same_type_ignoring_top_level_qualifiers_p (from, to))
    9944                 :             :     /* Pointer to member of incomplete class is permitted*/
    9945                 :       61158 :     result = size_zero_node;
    9946                 :             :   else
    9947                 :       28735 :     result = get_delta_difference_1 (from, to, c_cast_p, complain);
    9948                 :             : 
    9949                 :       89893 :   if (result == error_mark_node)
    9950                 :             :     return error_mark_node;
    9951                 :             : 
    9952                 :       89875 :   if (!result)
    9953                 :             :   {
    9954                 :         188 :     if (!allow_inverse_p)
    9955                 :             :       {
    9956                 :           0 :         if (!(complain & tf_error))
    9957                 :             :           return error_mark_node;
    9958                 :             : 
    9959                 :           0 :         error_not_base_type (from, to);
    9960                 :           0 :         inform (input_location, "   in pointer to member conversion");
    9961                 :           0 :         result = size_zero_node;
    9962                 :             :       }
    9963                 :             :     else
    9964                 :             :       {
    9965                 :         188 :         result = get_delta_difference_1 (to, from, c_cast_p, complain);
    9966                 :             : 
    9967                 :         188 :         if (result == error_mark_node)
    9968                 :             :           return error_mark_node;
    9969                 :             : 
    9970                 :         188 :         if (result)
    9971                 :         188 :           result = size_diffop_loc (input_location,
    9972                 :             :                                     size_zero_node, result);
    9973                 :             :         else
    9974                 :             :           {
    9975                 :           0 :             if (!(complain & tf_error))
    9976                 :             :               return error_mark_node;
    9977                 :             : 
    9978                 :           0 :             error_not_base_type (from, to);
    9979                 :           0 :             inform (input_location, "   in pointer to member conversion");
    9980                 :           0 :             result = size_zero_node;
    9981                 :             :           }
    9982                 :             :       }
    9983                 :             :   }
    9984                 :             : 
    9985                 :       89875 :   return convert_to_integer (ptrdiff_type_node, result);
    9986                 :             : }
    9987                 :             : 
    9988                 :             : /* Return a constructor for the pointer-to-member-function TYPE using
    9989                 :             :    the other components as specified.  */
    9990                 :             : 
    9991                 :             : tree
    9992                 :       61593 : build_ptrmemfunc1 (tree type, tree delta, tree pfn)
    9993                 :             : {
    9994                 :       61593 :   tree u = NULL_TREE;
    9995                 :       61593 :   tree delta_field;
    9996                 :       61593 :   tree pfn_field;
    9997                 :       61593 :   vec<constructor_elt, va_gc> *v;
    9998                 :             : 
    9999                 :             :   /* Pull the FIELD_DECLs out of the type.  */
   10000                 :       61593 :   pfn_field = TYPE_FIELDS (type);
   10001                 :       61593 :   delta_field = DECL_CHAIN (pfn_field);
   10002                 :             : 
   10003                 :             :   /* Make sure DELTA has the type we want.  */
   10004                 :       61593 :   delta = convert_and_check (input_location, delta_type_node, delta);
   10005                 :             : 
   10006                 :             :   /* Convert to the correct target type if necessary.  */
   10007                 :       61593 :   pfn = fold_convert (TREE_TYPE (pfn_field), pfn);
   10008                 :             : 
   10009                 :             :   /* Finish creating the initializer.  */
   10010                 :       61593 :   vec_alloc (v, 2);
   10011                 :       61593 :   CONSTRUCTOR_APPEND_ELT(v, pfn_field, pfn);
   10012                 :       61593 :   CONSTRUCTOR_APPEND_ELT(v, delta_field, delta);
   10013                 :       61593 :   u = build_constructor (type, v);
   10014                 :       61593 :   TREE_CONSTANT (u) = TREE_CONSTANT (pfn) & TREE_CONSTANT (delta);
   10015                 :       61593 :   TREE_STATIC (u) = (TREE_CONSTANT (u)
   10016                 :       61471 :                      && (initializer_constant_valid_p (pfn, TREE_TYPE (pfn))
   10017                 :             :                          != NULL_TREE)
   10018                 :      123064 :                      && (initializer_constant_valid_p (delta, TREE_TYPE (delta))
   10019                 :             :                          != NULL_TREE));
   10020                 :       61593 :   return u;
   10021                 :             : }
   10022                 :             : 
   10023                 :             : /* Build a constructor for a pointer to member function.  It can be
   10024                 :             :    used to initialize global variables, local variable, or used
   10025                 :             :    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
   10026                 :             :    want to be.
   10027                 :             : 
   10028                 :             :    If FORCE is nonzero, then force this conversion, even if
   10029                 :             :    we would rather not do it.  Usually set when using an explicit
   10030                 :             :    cast.  A C-style cast is being processed iff C_CAST_P is true.
   10031                 :             : 
   10032                 :             :    Return error_mark_node, if something goes wrong.  */
   10033                 :             : 
   10034                 :             : tree
   10035                 :       30352 : build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p,
   10036                 :             :                   tsubst_flags_t complain)
   10037                 :             : {
   10038                 :       30352 :   tree fn;
   10039                 :       30352 :   tree pfn_type;
   10040                 :       30352 :   tree to_type;
   10041                 :             : 
   10042                 :       30352 :   if (error_operand_p (pfn))
   10043                 :           0 :     return error_mark_node;
   10044                 :             : 
   10045                 :       30352 :   pfn_type = TREE_TYPE (pfn);
   10046                 :       30352 :   to_type = build_ptrmemfunc_type (type);
   10047                 :             : 
   10048                 :             :   /* Handle multiple conversions of pointer to member functions.  */
   10049                 :       30352 :   if (TYPE_PTRMEMFUNC_P (pfn_type))
   10050                 :             :     {
   10051                 :       28412 :       tree delta = NULL_TREE;
   10052                 :       28412 :       tree npfn = NULL_TREE;
   10053                 :       28412 :       tree n;
   10054                 :             : 
   10055                 :       28412 :       if (!force
   10056                 :       28412 :           && !can_convert_arg (to_type, TREE_TYPE (pfn), pfn,
   10057                 :             :                                LOOKUP_NORMAL, complain))
   10058                 :             :         {
   10059                 :           0 :           if (complain & tf_error)
   10060                 :           0 :             error ("invalid conversion to type %qT from type %qT",
   10061                 :             :                    to_type, pfn_type);
   10062                 :             :           else
   10063                 :           0 :             return error_mark_node;
   10064                 :             :         }
   10065                 :             : 
   10066                 :       28412 :       n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
   10067                 :       28412 :                                 TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
   10068                 :             :                                 force,
   10069                 :             :                                 c_cast_p, complain);
   10070                 :       28412 :       if (n == error_mark_node)
   10071                 :             :         return error_mark_node;
   10072                 :             : 
   10073                 :       28401 :       STRIP_ANY_LOCATION_WRAPPER (pfn);
   10074                 :             : 
   10075                 :             :       /* We don't have to do any conversion to convert a
   10076                 :             :          pointer-to-member to its own type.  But, we don't want to
   10077                 :             :          just return a PTRMEM_CST if there's an explicit cast; that
   10078                 :             :          cast should make the expression an invalid template argument.  */
   10079                 :       28401 :       if (TREE_CODE (pfn) != PTRMEM_CST
   10080                 :       28401 :           && same_type_p (to_type, pfn_type))
   10081                 :             :         return pfn;
   10082                 :             : 
   10083                 :       28401 :       if (TREE_SIDE_EFFECTS (pfn))
   10084                 :           9 :         pfn = save_expr (pfn);
   10085                 :             : 
   10086                 :             :       /* Obtain the function pointer and the current DELTA.  */
   10087                 :       28401 :       if (TREE_CODE (pfn) == PTRMEM_CST)
   10088                 :       28292 :         expand_ptrmemfunc_cst (pfn, &delta, &npfn);
   10089                 :             :       else
   10090                 :             :         {
   10091                 :         109 :           npfn = build_ptrmemfunc_access_expr (pfn, pfn_identifier);
   10092                 :         109 :           delta = build_ptrmemfunc_access_expr (pfn, delta_identifier);
   10093                 :             :         }
   10094                 :             : 
   10095                 :             :       /* Just adjust the DELTA field.  */
   10096                 :       28401 :       gcc_assert  (same_type_ignoring_top_level_qualifiers_p
   10097                 :             :                    (TREE_TYPE (delta), ptrdiff_type_node));
   10098                 :       28401 :       if (!integer_zerop (n))
   10099                 :             :         {
   10100                 :          64 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
   10101                 :             :             n = cp_build_binary_op (input_location,
   10102                 :             :                                     LSHIFT_EXPR, n, integer_one_node,
   10103                 :             :                                     complain);
   10104                 :          64 :           delta = cp_build_binary_op (input_location,
   10105                 :             :                                       PLUS_EXPR, delta, n, complain);
   10106                 :             :         }
   10107                 :       28401 :       return build_ptrmemfunc1 (to_type, delta, npfn);
   10108                 :             :     }
   10109                 :             : 
   10110                 :             :   /* Handle null pointer to member function conversions.  */
   10111                 :        1940 :   if (null_ptr_cst_p (pfn))
   10112                 :             :     {
   10113                 :         792 :       pfn = cp_build_c_cast (input_location,
   10114                 :         792 :                              TYPE_PTRMEMFUNC_FN_TYPE_RAW (to_type),
   10115                 :             :                              pfn, complain);
   10116                 :         792 :       return build_ptrmemfunc1 (to_type,
   10117                 :             :                                 integer_zero_node,
   10118                 :         792 :                                 pfn);
   10119                 :             :     }
   10120                 :             : 
   10121                 :        1148 :   if (type_unknown_p (pfn))
   10122                 :           0 :     return instantiate_type (type, pfn, complain);
   10123                 :             : 
   10124                 :        1148 :   fn = TREE_OPERAND (pfn, 0);
   10125                 :        1148 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
   10126                 :             :               /* In a template, we will have preserved the
   10127                 :             :                  OFFSET_REF.  */
   10128                 :             :               || (processing_template_decl && TREE_CODE (fn) == OFFSET_REF));
   10129                 :        1148 :   return make_ptrmem_cst (to_type, fn);
   10130                 :             : }
   10131                 :             : 
   10132                 :             : /* Return the DELTA, IDX, PFN, and DELTA2 values for the PTRMEM_CST
   10133                 :             :    given by CST.
   10134                 :             : 
   10135                 :             :    ??? There is no consistency as to the types returned for the above
   10136                 :             :    values.  Some code acts as if it were a sizetype and some as if it were
   10137                 :             :    integer_type_node.  */
   10138                 :             : 
   10139                 :             : void
   10140                 :       61070 : expand_ptrmemfunc_cst (tree cst, tree *delta, tree *pfn)
   10141                 :             : {
   10142                 :       61070 :   tree type = TREE_TYPE (cst);
   10143                 :       61070 :   tree fn = PTRMEM_CST_MEMBER (cst);
   10144                 :       61070 :   tree ptr_class, fn_class;
   10145                 :             : 
   10146                 :       61070 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
   10147                 :             : 
   10148                 :             :   /* The class that the function belongs to.  */
   10149                 :       61070 :   fn_class = DECL_CONTEXT (fn);
   10150                 :             : 
   10151                 :             :   /* The class that we're creating a pointer to member of.  */
   10152                 :       61070 :   ptr_class = TYPE_PTRMEMFUNC_OBJECT_TYPE (type);
   10153                 :             : 
   10154                 :             :   /* First, calculate the adjustment to the function's class.  */
   10155                 :       61070 :   *delta = get_delta_difference (fn_class, ptr_class, /*force=*/0,
   10156                 :             :                                  /*c_cast_p=*/0, tf_warning_or_error);
   10157                 :             : 
   10158                 :       61070 :   if (!DECL_VIRTUAL_P (fn))
   10159                 :             :     {
   10160                 :       59857 :       tree t = build_addr_func (fn, tf_warning_or_error);
   10161                 :       59857 :       if (TREE_CODE (t) == ADDR_EXPR)
   10162                 :       59857 :         SET_EXPR_LOCATION (t, PTRMEM_CST_LOCATION (cst));
   10163                 :       59857 :       *pfn = convert (TYPE_PTRMEMFUNC_FN_TYPE (type), t);
   10164                 :             :     }
   10165                 :             :   else
   10166                 :             :     {
   10167                 :             :       /* If we're dealing with a virtual function, we have to adjust 'this'
   10168                 :             :          again, to point to the base which provides the vtable entry for
   10169                 :             :          fn; the call will do the opposite adjustment.  */
   10170                 :        1213 :       tree orig_class = DECL_CONTEXT (fn);
   10171                 :        1213 :       tree binfo = binfo_or_else (orig_class, fn_class);
   10172                 :        1213 :       *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10173                 :             :                             *delta, BINFO_OFFSET (binfo));
   10174                 :             : 
   10175                 :             :       /* We set PFN to the vtable offset at which the function can be
   10176                 :             :          found, plus one (unless ptrmemfunc_vbit_in_delta, in which
   10177                 :             :          case delta is shifted left, and then incremented).  */
   10178                 :        1213 :       *pfn = DECL_VINDEX (fn);
   10179                 :        1213 :       *pfn = fold_build2 (MULT_EXPR, integer_type_node, *pfn,
   10180                 :             :                           TYPE_SIZE_UNIT (vtable_entry_type));
   10181                 :             : 
   10182                 :        1213 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
   10183                 :             :         {
   10184                 :        1213 :         case ptrmemfunc_vbit_in_pfn:
   10185                 :        1213 :           *pfn = fold_build2 (PLUS_EXPR, integer_type_node, *pfn,
   10186                 :             :                               integer_one_node);
   10187                 :        1213 :           break;
   10188                 :             : 
   10189                 :             :         case ptrmemfunc_vbit_in_delta:
   10190                 :             :           *delta = fold_build2 (LSHIFT_EXPR, TREE_TYPE (*delta),
   10191                 :             :                                 *delta, integer_one_node);
   10192                 :             :           *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10193                 :             :                                 *delta, integer_one_node);
   10194                 :             :           break;
   10195                 :             : 
   10196                 :             :         default:
   10197                 :             :           gcc_unreachable ();
   10198                 :             :         }
   10199                 :             : 
   10200                 :        1213 :       *pfn = fold_convert (TYPE_PTRMEMFUNC_FN_TYPE (type), *pfn);
   10201                 :             :     }
   10202                 :       61070 : }
   10203                 :             : 
   10204                 :             : /* Return an expression for PFN from the pointer-to-member function
   10205                 :             :    given by T.  */
   10206                 :             : 
   10207                 :             : static tree
   10208                 :       85837 : pfn_from_ptrmemfunc (tree t)
   10209                 :             : {
   10210                 :       85837 :   if (TREE_CODE (t) == PTRMEM_CST)
   10211                 :             :     {
   10212                 :         189 :       tree delta;
   10213                 :         189 :       tree pfn;
   10214                 :             : 
   10215                 :         189 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10216                 :         189 :       if (pfn)
   10217                 :         189 :         return pfn;
   10218                 :             :     }
   10219                 :             : 
   10220                 :       85648 :   return build_ptrmemfunc_access_expr (t, pfn_identifier);
   10221                 :             : }
   10222                 :             : 
   10223                 :             : /* Return an expression for DELTA from the pointer-to-member function
   10224                 :             :    given by T.  */
   10225                 :             : 
   10226                 :             : static tree
   10227                 :       85837 : delta_from_ptrmemfunc (tree t)
   10228                 :             : {
   10229                 :       85837 :   if (TREE_CODE (t) == PTRMEM_CST)
   10230                 :             :     {
   10231                 :         189 :       tree delta;
   10232                 :         189 :       tree pfn;
   10233                 :             : 
   10234                 :         189 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10235                 :         189 :       if (delta)
   10236                 :         189 :         return delta;
   10237                 :             :     }
   10238                 :             : 
   10239                 :       85648 :   return build_ptrmemfunc_access_expr (t, delta_identifier);
   10240                 :             : }
   10241                 :             : 
   10242                 :             : /* Convert value RHS to type TYPE as preparation for an assignment to
   10243                 :             :    an lvalue of type TYPE.  ERRTYPE indicates what kind of error the
   10244                 :             :    implicit conversion is.  If FNDECL is non-NULL, we are doing the
   10245                 :             :    conversion in order to pass the PARMNUMth argument of FNDECL.
   10246                 :             :    If FNDECL is NULL, we are doing the conversion in function pointer
   10247                 :             :    argument passing, conversion in initialization, etc. */
   10248                 :             : 
   10249                 :             : static tree
   10250                 :   103504097 : convert_for_assignment (tree type, tree rhs,
   10251                 :             :                         impl_conv_rhs errtype, tree fndecl, int parmnum,
   10252                 :             :                         tsubst_flags_t complain, int flags)
   10253                 :             : {
   10254                 :   103504116 :   tree rhstype;
   10255                 :   103504116 :   enum tree_code coder;
   10256                 :             : 
   10257                 :   103504116 :   location_t rhs_loc = cp_expr_loc_or_input_loc (rhs);
   10258                 :   103504116 :   bool has_loc = EXPR_LOCATION (rhs) != UNKNOWN_LOCATION;
   10259                 :             :   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue,
   10260                 :             :      but preserve location wrappers.  */
   10261                 :   103504116 :   if (TREE_CODE (rhs) == NON_LVALUE_EXPR
   10262                 :   103504116 :       && !location_wrapper_p (rhs))
   10263                 :       94430 :     rhs = TREE_OPERAND (rhs, 0);
   10264                 :             : 
   10265                 :             :   /* Handle [dcl.init.list] direct-list-initialization from
   10266                 :             :      single element of enumeration with a fixed underlying type.  */
   10267                 :   103504116 :   if (is_direct_enum_init (type, rhs))
   10268                 :             :     {
   10269                 :          38 :       tree elt = CONSTRUCTOR_ELT (rhs, 0)->value;
   10270                 :          38 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
   10271                 :             :         {
   10272                 :          20 :           warning_sentinel w (warn_useless_cast);
   10273                 :          20 :           warning_sentinel w2 (warn_ignored_qualifiers);
   10274                 :          20 :           rhs = cp_build_c_cast (rhs_loc, type, elt, complain);
   10275                 :          20 :         }
   10276                 :             :       else
   10277                 :          18 :         rhs = error_mark_node;
   10278                 :             :     }
   10279                 :             : 
   10280                 :   103504116 :   rhstype = TREE_TYPE (rhs);
   10281                 :   103504116 :   coder = TREE_CODE (rhstype);
   10282                 :             : 
   10283                 :     1105727 :   if (VECTOR_TYPE_P (type) && coder == VECTOR_TYPE
   10284                 :   104609819 :       && vector_types_convertible_p (type, rhstype, true))
   10285                 :             :     {
   10286                 :     1105691 :       rhs = mark_rvalue_use (rhs);
   10287                 :     1105691 :       return convert (type, rhs);
   10288                 :             :     }
   10289                 :             : 
   10290                 :   102398425 :   if (rhs == error_mark_node || rhstype == error_mark_node)
   10291                 :             :     return error_mark_node;
   10292                 :   102398407 :   if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
   10293                 :             :     return error_mark_node;
   10294                 :             : 
   10295                 :             :   /* The RHS of an assignment cannot have void type.  */
   10296                 :   102398407 :   if (coder == VOID_TYPE)
   10297                 :             :     {
   10298                 :          49 :       if (complain & tf_error)
   10299                 :          31 :         error_at (rhs_loc, "void value not ignored as it ought to be");
   10300                 :          49 :       return error_mark_node;
   10301                 :             :     }
   10302                 :             : 
   10303                 :   102398358 :   if (c_dialect_objc ())
   10304                 :             :     {
   10305                 :           0 :       int parmno;
   10306                 :           0 :       tree selector;
   10307                 :           0 :       tree rname = fndecl;
   10308                 :             : 
   10309                 :           0 :       switch (errtype)
   10310                 :             :         {
   10311                 :             :           case ICR_ASSIGN:
   10312                 :             :             parmno = -1;
   10313                 :             :             break;
   10314                 :           0 :           case ICR_INIT:
   10315                 :           0 :             parmno = -2;
   10316                 :           0 :             break;
   10317                 :           0 :           default:
   10318                 :           0 :             selector = objc_message_selector ();
   10319                 :           0 :             parmno = parmnum;
   10320                 :           0 :             if (selector && parmno > 1)
   10321                 :             :               {
   10322                 :           0 :                 rname = selector;
   10323                 :           0 :                 parmno -= 1;
   10324                 :             :               }
   10325                 :             :         }
   10326                 :             : 
   10327                 :           0 :       if (objc_compare_types (type, rhstype, parmno, rname))
   10328                 :             :         {
   10329                 :           0 :           rhs = mark_rvalue_use (rhs);
   10330                 :           0 :           return convert (type, rhs);
   10331                 :             :         }
   10332                 :             :     }
   10333                 :             : 
   10334                 :             :   /* [expr.ass]
   10335                 :             : 
   10336                 :             :      The expression is implicitly converted (clause _conv_) to the
   10337                 :             :      cv-unqualified type of the left operand.
   10338                 :             : 
   10339                 :             :      We allow bad conversions here because by the time we get to this point
   10340                 :             :      we are committed to doing the conversion.  If we end up doing a bad
   10341                 :             :      conversion, convert_like will complain.  */
   10342                 :   102398358 :   if (!can_convert_arg_bad (type, rhstype, rhs, flags, complain))
   10343                 :             :     {
   10344                 :             :       /* When -Wno-pmf-conversions is use, we just silently allow
   10345                 :             :          conversions from pointers-to-members to plain pointers.  If
   10346                 :             :          the conversion doesn't work, cp_convert will complain.  */
   10347                 :        1507 :       if (!warn_pmf2ptr
   10348                 :          12 :           && TYPE_PTR_P (type)
   10349                 :        1519 :           && TYPE_PTRMEMFUNC_P (rhstype))
   10350                 :          12 :         rhs = cp_convert (strip_top_quals (type), rhs, complain);
   10351                 :             :       else
   10352                 :             :         {
   10353                 :        1495 :           if (complain & tf_error)
   10354                 :             :             {
   10355                 :             :               /* If the right-hand side has unknown type, then it is an
   10356                 :             :                  overloaded function.  Call instantiate_type to get error
   10357                 :             :                  messages.  */
   10358                 :        1349 :               if (rhstype == unknown_type_node)
   10359                 :             :                 {
   10360                 :         223 :                   tree r = instantiate_type (type, rhs, tf_warning_or_error);
   10361                 :             :                   /* -fpermissive might allow this; recurse.  */
   10362                 :         223 :                   if (!seen_error ())
   10363                 :             :                     return convert_for_assignment (type, r, errtype, fndecl,
   10364                 :             :                                                    parmnum, complain, flags);
   10365                 :             :                 }
   10366                 :        1126 :               else if (fndecl)
   10367                 :          99 :                 complain_about_bad_argument (rhs_loc,
   10368                 :             :                                              rhstype, type,
   10369                 :             :                                              fndecl, parmnum);
   10370                 :             :               else
   10371                 :             :                 {
   10372                 :        1027 :                   range_label_for_type_mismatch label (rhstype, type);
   10373                 :        1027 :                   gcc_rich_location richloc (rhs_loc, has_loc ? &label : NULL);
   10374                 :        1027 :                   auto_diagnostic_group d;
   10375                 :             : 
   10376                 :        1027 :                   switch (errtype)
   10377                 :             :                     {
   10378                 :           0 :                     case ICR_DEFAULT_ARGUMENT:
   10379                 :           0 :                       error_at (&richloc,
   10380                 :             :                                 "cannot convert %qH to %qI in default argument",
   10381                 :             :                                 rhstype, type);
   10382                 :           0 :                       break;
   10383                 :           8 :                     case ICR_ARGPASS:
   10384                 :           8 :                       error_at (&richloc,
   10385                 :             :                                 "cannot convert %qH to %qI in argument passing",
   10386                 :             :                                 rhstype, type);
   10387                 :           8 :                       break;
   10388                 :           0 :                     case ICR_CONVERTING:
   10389                 :           0 :                       error_at (&richloc, "cannot convert %qH to %qI",
   10390                 :             :                                 rhstype, type);
   10391                 :           0 :                       break;
   10392                 :         472 :                     case ICR_INIT:
   10393                 :         472 :                       error_at (&richloc,
   10394                 :             :                                 "cannot convert %qH to %qI in initialization",
   10395                 :             :                                 rhstype, type);
   10396                 :         472 :                       break;
   10397                 :          19 :                     case ICR_RETURN:
   10398                 :          19 :                       error_at (&richloc, "cannot convert %qH to %qI in return",
   10399                 :             :                                 rhstype, type);
   10400                 :          19 :                       break;
   10401                 :         528 :                     case ICR_ASSIGN:
   10402                 :         528 :                       error_at (&richloc,
   10403                 :             :                                 "cannot convert %qH to %qI in assignment",
   10404                 :             :                                 rhstype, type);
   10405                 :         528 :                       break;
   10406                 :           0 :                     default:
   10407                 :           0 :                       gcc_unreachable();
   10408                 :             :                   }
   10409                 :        1027 :                 }
   10410                 :             : 
   10411                 :             :               /* See if we can be more helpful.  */
   10412                 :        1330 :               maybe_show_nonconverting_candidate (type, rhstype, rhs, flags);
   10413                 :             : 
   10414                 :        1330 :               if (TYPE_PTR_P (rhstype)
   10415                 :         512 :                   && TYPE_PTR_P (type)
   10416                 :         496 :                   && CLASS_TYPE_P (TREE_TYPE (rhstype))
   10417                 :         370 :                   && CLASS_TYPE_P (TREE_TYPE (type))
   10418                 :        1412 :                   && !COMPLETE_TYPE_P (TREE_TYPE (rhstype)))
   10419                 :           4 :                 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL
   10420                 :             :                                               (TREE_TYPE (rhstype))),
   10421                 :           4 :                         "class type %qT is incomplete", TREE_TYPE (rhstype));
   10422                 :             :             }
   10423                 :        1476 :           return error_mark_node;
   10424                 :             :         }
   10425                 :             :     }
   10426                 :   102396863 :   if (warn_suggest_attribute_format)
   10427                 :             :     {
   10428                 :        2423 :       const enum tree_code codel = TREE_CODE (type);
   10429                 :        2423 :       if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
   10430                 :         588 :           && coder == codel
   10431                 :         500 :           && check_missing_format_attribute (type, rhstype)
   10432                 :        2447 :           && (complain & tf_warning))
   10433                 :          24 :         switch (errtype)
   10434                 :             :           {
   10435                 :           0 :             case ICR_ARGPASS:
   10436                 :           0 :             case ICR_DEFAULT_ARGUMENT:
   10437                 :           0 :               if (fndecl)
   10438                 :           0 :                 warning (OPT_Wsuggest_attribute_format,
   10439                 :             :                          "parameter %qP of %qD might be a candidate "
   10440                 :             :                          "for a format attribute", parmnum, fndecl);
   10441                 :             :               else
   10442                 :           0 :                 warning (OPT_Wsuggest_attribute_format,
   10443                 :             :                          "parameter might be a candidate "
   10444                 :             :                          "for a format attribute");
   10445                 :             :               break;
   10446                 :           0 :             case ICR_CONVERTING:
   10447                 :           0 :               warning (OPT_Wsuggest_attribute_format,
   10448                 :             :                        "target of conversion might be a candidate "
   10449                 :             :                        "for a format attribute");
   10450                 :           0 :               break;
   10451                 :           8 :             case ICR_INIT:
   10452                 :           8 :               warning (OPT_Wsuggest_attribute_format,
   10453                 :             :                        "target of initialization might be a candidate "
   10454                 :             :                        "for a format attribute");
   10455                 :           8 :               break;
   10456                 :           8 :             case ICR_RETURN:
   10457                 :           8 :               warning (OPT_Wsuggest_attribute_format,
   10458                 :             :                        "return type might be a candidate "
   10459                 :             :                        "for a format attribute");
   10460                 :           8 :               break;
   10461                 :           8 :             case ICR_ASSIGN:
   10462                 :           8 :               warning (OPT_Wsuggest_attribute_format,
   10463                 :             :                        "left-hand side of assignment might be a candidate "
   10464                 :             :                        "for a format attribute");
   10465                 :           8 :               break;
   10466                 :           0 :             default:
   10467                 :           0 :               gcc_unreachable();
   10468                 :             :           }
   10469                 :             :     }
   10470                 :             : 
   10471                 :   102396863 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
   10472                 :    19327116 :     maybe_warn_unparenthesized_assignment (rhs, /*nested_p=*/true, complain);
   10473                 :             : 
   10474                 :   102396863 :   if (complain & tf_warning)
   10475                 :   101496109 :     warn_for_address_of_packed_member (type, rhs);
   10476                 :             : 
   10477                 :   102396863 :   return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
   10478                 :   102396863 :                                             complain, flags);
   10479                 :             : }
   10480                 :             : 
   10481                 :             : /* Convert RHS to be of type TYPE.
   10482                 :             :    If EXP is nonzero, it is the target of the initialization.
   10483                 :             :    ERRTYPE indicates what kind of error the implicit conversion is.
   10484                 :             : 
   10485                 :             :    Two major differences between the behavior of
   10486                 :             :    `convert_for_assignment' and `convert_for_initialization'
   10487                 :             :    are that references are bashed in the former, while
   10488                 :             :    copied in the latter, and aggregates are assigned in
   10489                 :             :    the former (operator=) while initialized in the
   10490                 :             :    latter (X(X&)).
   10491                 :             : 
   10492                 :             :    If using constructor make sure no conversion operator exists, if one does
   10493                 :             :    exist, an ambiguity exists.  */
   10494                 :             : 
   10495                 :             : tree
   10496                 :    89814899 : convert_for_initialization (tree exp, tree type, tree rhs, int flags,
   10497                 :             :                             impl_conv_rhs errtype, tree fndecl, int parmnum,
   10498                 :             :                             tsubst_flags_t complain)
   10499                 :             : {
   10500                 :    89814899 :   enum tree_code codel = TREE_CODE (type);
   10501                 :    89814899 :   tree rhstype;
   10502                 :    89814899 :   enum tree_code coder;
   10503                 :             : 
   10504                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
   10505                 :             :      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
   10506                 :    89814899 :   if (TREE_CODE (rhs) == NOP_EXPR
   10507                 :     4235183 :       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
   10508                 :    90143464 :       && codel != REFERENCE_TYPE)
   10509                 :      328565 :     rhs = TREE_OPERAND (rhs, 0);
   10510                 :             : 
   10511                 :    89814899 :   if (type == error_mark_node
   10512                 :    89814865 :       || rhs == error_mark_node
   10513                 :   179629706 :       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
   10514                 :             :     return error_mark_node;
   10515                 :             : 
   10516                 :    89814807 :   if (MAYBE_CLASS_TYPE_P (non_reference (type)))
   10517                 :             :     ;
   10518                 :    80421236 :   else if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
   10519                 :     1078145 :             && TREE_CODE (type) != ARRAY_TYPE
   10520                 :     1078145 :             && (!TYPE_REF_P (type)
   10521                 :        4890 :                 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
   10522                 :    79347978 :            || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
   10523                 :        9010 :                && !TYPE_REFFN_P (type))
   10524                 :   159761441 :            || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
   10525                 :     1081035 :     rhs = decay_conversion (rhs, complain);
   10526                 :             : 
   10527                 :    89814807 :   rhstype = TREE_TYPE (rhs);
   10528                 :    89814807 :   coder = TREE_CODE (rhstype);
   10529                 :             : 
   10530                 :    89814807 :   if (coder == ERROR_MARK)
   10531                 :           8 :     return error_mark_node;
   10532                 :             : 
   10533                 :             :   /* We accept references to incomplete types, so we can
   10534                 :             :      return here before checking if RHS is of complete type.  */
   10535                 :             : 
   10536                 :    89814799 :   if (codel == REFERENCE_TYPE)
   10537                 :             :     {
   10538                 :     4609643 :       auto_diagnostic_group d;
   10539                 :             :       /* This should eventually happen in convert_arguments.  */
   10540                 :     4609643 :       int savew = 0, savee = 0;
   10541                 :             : 
   10542                 :     4609643 :       if (fndecl)
   10543                 :      238267 :         savew = warningcount + werrorcount, savee = errorcount;
   10544                 :     4609643 :       rhs = initialize_reference (type, rhs, flags, complain);
   10545                 :             : 
   10546                 :     4609643 :       if (fndecl
   10547                 :     4609643 :           && (warningcount + werrorcount > savew || errorcount > savee))
   10548                 :          41 :         inform (get_fndecl_argument_location (fndecl, parmnum),
   10549                 :             :                 "in passing argument %P of %qD", parmnum, fndecl);
   10550                 :     4609643 :       return rhs;
   10551                 :     4609643 :     }
   10552                 :             : 
   10553                 :    85205156 :   if (exp != 0)
   10554                 :     2998439 :     exp = require_complete_type (exp, complain);
   10555                 :    85205156 :   if (exp == error_mark_node)
   10556                 :             :     return error_mark_node;
   10557                 :             : 
   10558                 :    85205156 :   type = complete_type (type);
   10559                 :             : 
   10560                 :    85205156 :   if (DIRECT_INIT_EXPR_P (type, rhs))
   10561                 :             :     /* Don't try to do copy-initialization if we already have
   10562                 :             :        direct-initialization.  */
   10563                 :             :     return rhs;
   10564                 :             : 
   10565                 :    85200432 :   if (MAYBE_CLASS_TYPE_P (type))
   10566                 :     6325262 :     return perform_implicit_conversion_flags (type, rhs, complain, flags);
   10567                 :             : 
   10568                 :    78875170 :   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum,
   10569                 :    78875170 :                                  complain, flags);
   10570                 :             : }
   10571                 :             : 
   10572                 :             : /* If RETVAL is the address of, or a reference to, a local variable or
   10573                 :             :    temporary give an appropriate warning and return true.  */
   10574                 :             : 
   10575                 :             : static bool
   10576                 :    31987261 : maybe_warn_about_returning_address_of_local (tree retval, location_t loc)
   10577                 :             : {
   10578                 :    31987486 :   tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
   10579                 :    31987486 :   tree whats_returned = fold_for_warn (retval);
   10580                 :    31987486 :   if (!loc)
   10581                 :    31987486 :     loc = cp_expr_loc_or_input_loc (retval);
   10582                 :             : 
   10583                 :    38725082 :   for (;;)
   10584                 :             :     {
   10585                 :    38725082 :       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
   10586                 :      423454 :         whats_returned = TREE_OPERAND (whats_returned, 1);
   10587                 :    38301628 :       else if (CONVERT_EXPR_P (whats_returned)
   10588                 :    32006098 :                || TREE_CODE (whats_returned) == NON_LVALUE_EXPR)
   10589                 :     6314142 :         whats_returned = TREE_OPERAND (whats_returned, 0);
   10590                 :             :       else
   10591                 :             :         break;
   10592                 :             :     }
   10593                 :             : 
   10594                 :    31987486 :   if (TREE_CODE (whats_returned) == TARGET_EXPR
   10595                 :    31987486 :       && is_std_init_list (TREE_TYPE (whats_returned)))
   10596                 :             :     {
   10597                 :          14 :       tree init = TARGET_EXPR_INITIAL (whats_returned);
   10598                 :          14 :       if (TREE_CODE (init) == CONSTRUCTOR)
   10599                 :             :         /* Pull out the array address.  */
   10600                 :           6 :         whats_returned = CONSTRUCTOR_ELT (init, 0)->value;
   10601                 :           8 :       else if (TREE_CODE (init) == INDIRECT_REF)
   10602                 :             :         /* The source of a trivial copy looks like *(T*)&var.  */
   10603                 :           5 :         whats_returned = TREE_OPERAND (init, 0);
   10604                 :             :       else
   10605                 :             :         return false;
   10606                 :          11 :       STRIP_NOPS (whats_returned);
   10607                 :             :     }
   10608                 :             : 
   10609                 :             :   /* As a special case, we handle a call to std::move or std::forward.  */
   10610                 :    31987483 :   if (TREE_CODE (whats_returned) == CALL_EXPR
   10611                 :    31987483 :       && (is_std_move_p (whats_returned)
   10612                 :     8722275 :           || is_std_forward_p (whats_returned)))
   10613                 :             :     {
   10614                 :         213 :       tree arg = CALL_EXPR_ARG (whats_returned, 0);
   10615                 :         213 :       return maybe_warn_about_returning_address_of_local (arg, loc);
   10616                 :             :     }
   10617                 :             : 
   10618                 :    31987270 :   if (TREE_CODE (whats_returned) != ADDR_EXPR)
   10619                 :             :     return false;
   10620                 :      678730 :   whats_returned = TREE_OPERAND (whats_returned, 0);
   10621                 :             : 
   10622                 :      678730 :   while (TREE_CODE (whats_returned) == COMPONENT_REF
   10623                 :     1331510 :          || TREE_CODE (whats_returned) == ARRAY_REF)
   10624                 :      652780 :     whats_returned = TREE_OPERAND (whats_returned, 0);
   10625                 :             : 
   10626                 :      678730 :   if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR
   10627                 :      678730 :       || TREE_CODE (whats_returned) == TARGET_EXPR)
   10628                 :             :     {
   10629                 :          60 :       if (TYPE_REF_P (valtype))
   10630                 :             :         /* P2748 made this an error in C++26.  */
   10631                 :         100 :         emit_diagnostic (cxx_dialect >= cxx26 ? DK_PERMERROR : DK_WARNING,
   10632                 :             :                          loc, OPT_Wreturn_local_addr,
   10633                 :             :                          "returning reference to temporary");
   10634                 :          10 :       else if (TYPE_PTR_P (valtype))
   10635                 :           4 :         warning_at (loc, OPT_Wreturn_local_addr,
   10636                 :             :                     "returning pointer to temporary");
   10637                 :           6 :       else if (is_std_init_list (valtype))
   10638                 :           6 :         warning_at (loc, OPT_Winit_list_lifetime,
   10639                 :             :                     "returning temporary %<initializer_list%> does not extend "
   10640                 :             :                     "the lifetime of the underlying array");
   10641                 :          60 :       return true;
   10642                 :             :     }
   10643                 :             : 
   10644                 :      678670 :   STRIP_ANY_LOCATION_WRAPPER (whats_returned);
   10645                 :             : 
   10646                 :      678670 :   if (DECL_P (whats_returned)
   10647                 :       57384 :       && DECL_NAME (whats_returned)
   10648                 :       57384 :       && DECL_FUNCTION_SCOPE_P (whats_returned)
   10649                 :       14322 :       && !is_capture_proxy (whats_returned)
   10650                 :      692989 :       && !(TREE_STATIC (whats_returned)
   10651                 :             :            || TREE_PUBLIC (whats_returned)))
   10652                 :             :     {
   10653                 :         162 :       if (VAR_P (whats_returned)
   10654                 :         119 :           && DECL_DECOMPOSITION_P (whats_returned)
   10655                 :          38 :           && DECL_DECOMP_BASE (whats_returned)
   10656                 :         200 :           && DECL_HAS_VALUE_EXPR_P (whats_returned))
   10657                 :             :         {
   10658                 :             :           /* When returning address of a structured binding, if the structured
   10659                 :             :              binding is not a reference, continue normally, if it is a
   10660                 :             :              reference, recurse on the initializer of the structured
   10661                 :             :              binding.  */
   10662                 :          38 :           tree base = DECL_DECOMP_BASE (whats_returned);
   10663                 :          38 :           if (TYPE_REF_P (TREE_TYPE (base)))
   10664                 :             :             {
   10665                 :          14 :               if (tree init = DECL_INITIAL (base))
   10666                 :             :                 return maybe_warn_about_returning_address_of_local (init, loc);
   10667                 :             :               else
   10668                 :             :                 return false;
   10669                 :             :             }
   10670                 :             :         }
   10671                 :         148 :       bool w = false;
   10672                 :         148 :       auto_diagnostic_group d;
   10673                 :         148 :       if (TYPE_REF_P (valtype))
   10674                 :          90 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   10675                 :             :                         "reference to local variable %qD returned",
   10676                 :             :                         whats_returned);
   10677                 :          58 :       else if (is_std_init_list (valtype))
   10678                 :           3 :         w = warning_at (loc, OPT_Winit_list_lifetime,
   10679                 :             :                         "returning local %<initializer_list%> variable %qD "
   10680                 :             :                         "does not extend the lifetime of the underlying array",
   10681                 :             :                         whats_returned);
   10682                 :          55 :       else if (POINTER_TYPE_P (valtype)
   10683                 :          47 :                && TREE_CODE (whats_returned) == LABEL_DECL)
   10684                 :           8 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   10685                 :             :                         "address of label %qD returned",
   10686                 :             :                         whats_returned);
   10687                 :          47 :       else if (POINTER_TYPE_P (valtype))
   10688                 :          39 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   10689                 :             :                         "address of local variable %qD returned",
   10690                 :             :                         whats_returned);
   10691                 :         140 :       if (w)
   10692                 :         115 :         inform (DECL_SOURCE_LOCATION (whats_returned),
   10693                 :             :                 "declared here");
   10694                 :         148 :       return true;
   10695                 :         148 :     }
   10696                 :             : 
   10697                 :             :   return false;
   10698                 :             : }
   10699                 :             : 
   10700                 :             : /* Returns true if DECL is in the std namespace.  */
   10701                 :             : 
   10702                 :             : bool
   10703                 :    63681740 : decl_in_std_namespace_p (tree decl)
   10704                 :             : {
   10705                 :    75279120 :   while (decl)
   10706                 :             :     {
   10707                 :    74868877 :       decl = decl_namespace_context (decl);
   10708                 :    74868877 :       if (DECL_NAMESPACE_STD_P (decl))
   10709                 :             :         return true;
   10710                 :             :       /* Allow inline namespaces inside of std namespace, e.g. with
   10711                 :             :          --enable-symvers=gnu-versioned-namespace std::forward would be
   10712                 :             :          actually std::_8::forward.  */
   10713                 :    35145955 :       if (!DECL_NAMESPACE_INLINE_P (decl))
   10714                 :             :         return false;
   10715                 :    11597380 :       decl = CP_DECL_CONTEXT (decl);
   10716                 :             :     }
   10717                 :             :   return false;
   10718                 :             : }
   10719                 :             : 
   10720                 :             : /* Returns true if FN, a CALL_EXPR, is a call to std::forward.  */
   10721                 :             : 
   10722                 :             : static bool
   10723                 :     8722275 : is_std_forward_p (tree fn)
   10724                 :             : {
   10725                 :             :   /* std::forward only takes one argument.  */
   10726                 :     8722275 :   if (call_expr_nargs (fn) != 1)
   10727                 :             :     return false;
   10728                 :             : 
   10729                 :     4033913 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   10730                 :     4033913 :   if (!decl_in_std_namespace_p (fndecl))
   10731                 :             :     return false;
   10732                 :             : 
   10733                 :     1320787 :   tree name = DECL_NAME (fndecl);
   10734                 :     1320787 :   return name && id_equal (name, "forward");
   10735                 :             : }
   10736                 :             : 
   10737                 :             : /* Returns true if FN, a CALL_EXPR, is a call to std::move.  */
   10738                 :             : 
   10739                 :             : static bool
   10740                 :     8726562 : is_std_move_p (tree fn)
   10741                 :             : {
   10742                 :             :   /* std::move only takes one argument.  */
   10743                 :     8726562 :   if (call_expr_nargs (fn) != 1)
   10744                 :             :     return false;
   10745                 :             : 
   10746                 :     4037906 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   10747                 :     4037906 :   if (!decl_in_std_namespace_p (fndecl))
   10748                 :             :     return false;
   10749                 :             : 
   10750                 :     1324504 :   tree name = DECL_NAME (fndecl);
   10751                 :     1324504 :   return name && id_equal (name, "move");
   10752                 :             : }
   10753                 :             : 
   10754                 :             : /* Returns true if RETVAL is a good candidate for the NRVO as per
   10755                 :             :    [class.copy.elision].  FUNCTYPE is the type the function is declared
   10756                 :             :    to return.  */
   10757                 :             : 
   10758                 :             : static bool
   10759                 :    40714372 : can_do_nrvo_p (tree retval, tree functype)
   10760                 :             : {
   10761                 :    40714372 :   if (functype == error_mark_node)
   10762                 :             :     return false;
   10763                 :    40714335 :   if (retval)
   10764                 :    39448996 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   10765                 :    40714335 :   tree result = DECL_RESULT (current_function_decl);
   10766                 :    40714335 :   return (retval != NULL_TREE
   10767                 :    39448996 :           && !processing_template_decl
   10768                 :             :           /* Must be a local, automatic variable.  */
   10769                 :    32675553 :           && VAR_P (retval)
   10770                 :     2987639 :           && DECL_CONTEXT (retval) == current_function_decl
   10771                 :     2341878 :           && !TREE_STATIC (retval)
   10772                 :             :           /* And not a lambda or anonymous union proxy.  */
   10773                 :     2338943 :           && !DECL_HAS_VALUE_EXPR_P (retval)
   10774                 :     2338746 :           && (DECL_ALIGN (retval) <= DECL_ALIGN (result))
   10775                 :             :           /* The cv-unqualified type of the returned value must be the
   10776                 :             :              same as the cv-unqualified return type of the
   10777                 :             :              function.  */
   10778                 :     2338644 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   10779                 :             :                           TYPE_MAIN_VARIANT (functype))
   10780                 :             :           /* And the returned value must be non-volatile.  */
   10781                 :    43029135 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   10782                 :             : }
   10783                 :             : 
   10784                 :             : /* True if we would like to perform NRVO, i.e. can_do_nrvo_p is true and we
   10785                 :             :    would otherwise return in memory.  */
   10786                 :             : 
   10787                 :             : static bool
   10788                 :    40714078 : want_nrvo_p (tree retval, tree functype)
   10789                 :             : {
   10790                 :    40714078 :   return (can_do_nrvo_p (retval, functype)
   10791                 :    40714078 :           && aggregate_value_p (functype, current_function_decl));
   10792                 :             : }
   10793                 :             : 
   10794                 :             : /* Like can_do_nrvo_p, but we check if we're trying to move a class
   10795                 :             :    prvalue.  */
   10796                 :             : 
   10797                 :             : static bool
   10798                 :         993 : can_elide_copy_prvalue_p (tree retval, tree functype)
   10799                 :             : {
   10800                 :         993 :   if (functype == error_mark_node)
   10801                 :             :     return false;
   10802                 :         993 :   if (retval)
   10803                 :         993 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   10804                 :         993 :   return (retval != NULL_TREE
   10805                 :         993 :           && !glvalue_p (retval)
   10806                 :         135 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   10807                 :             :                           TYPE_MAIN_VARIANT (functype))
   10808                 :        1101 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   10809                 :             : }
   10810                 :             : 
   10811                 :             : /* If we should treat RETVAL, an expression being returned, as if it were
   10812                 :             :    designated by an rvalue, returns it adjusted accordingly; otherwise, returns
   10813                 :             :    NULL_TREE.  See [class.copy.elision].  RETURN_P is true if this is a return
   10814                 :             :    context (rather than throw).  */
   10815                 :             : 
   10816                 :             : tree
   10817                 :     7126105 : treat_lvalue_as_rvalue_p (tree expr, bool return_p)
   10818                 :             : {
   10819                 :     7126105 :   if (cxx_dialect == cxx98)
   10820                 :             :     return NULL_TREE;
   10821                 :             : 
   10822                 :     7110938 :   tree retval = expr;
   10823                 :     7110938 :   STRIP_ANY_LOCATION_WRAPPER (retval);
   10824                 :     7110938 :   if (REFERENCE_REF_P (retval))
   10825                 :      419578 :     retval = TREE_OPERAND (retval, 0);
   10826                 :             : 
   10827                 :             :   /* An implicitly movable entity is a variable of automatic storage duration
   10828                 :             :      that is either a non-volatile object or (C++20) an rvalue reference to a
   10829                 :             :      non-volatile object type.  */
   10830                 :     7110938 :   if (!(((VAR_P (retval) && !DECL_HAS_VALUE_EXPR_P (retval))
   10831                 :     6319782 :          || TREE_CODE (retval) == PARM_DECL)
   10832                 :     1026416 :         && !TREE_STATIC (retval)
   10833                 :     1003205 :         && !CP_TYPE_VOLATILE_P (non_reference (TREE_TYPE (retval)))
   10834                 :     1003202 :         && (TREE_CODE (TREE_TYPE (retval)) != REFERENCE_TYPE
   10835                 :       79812 :             || (cxx_dialect >= cxx20
   10836                 :       61150 :                 && TYPE_REF_IS_RVALUE (TREE_TYPE (retval))))))
   10837                 :     6186990 :     return NULL_TREE;
   10838                 :             : 
   10839                 :             :   /* If the expression in a return or co_return statement is a (possibly
   10840                 :             :      parenthesized) id-expression that names an implicitly movable entity
   10841                 :             :      declared in the body or parameter-declaration-clause of the innermost
   10842                 :             :      enclosing function or lambda-expression, */
   10843                 :      923948 :   if (return_p)
   10844                 :             :     {
   10845                 :      923853 :       if (DECL_CONTEXT (retval) != current_function_decl)
   10846                 :             :         return NULL_TREE;
   10847                 :      923838 :       expr = move (expr);
   10848                 :      923838 :       if (expr == error_mark_node)
   10849                 :             :         return NULL_TREE;
   10850                 :      923838 :       return set_implicit_rvalue_p (expr);
   10851                 :             :     }
   10852                 :             : 
   10853                 :             :   /* if the id-expression (possibly parenthesized) is the operand of
   10854                 :             :      a throw-expression, and names an implicitly movable entity that belongs
   10855                 :             :      to a scope that does not contain the compound-statement of the innermost
   10856                 :             :      lambda-expression, try-block, or function-try-block (if any) whose
   10857                 :             :      compound-statement or ctor-initializer contains the throw-expression.  */
   10858                 :             : 
   10859                 :             :   /* C++20 added move on throw of parms.  */
   10860                 :          95 :   if (TREE_CODE (retval) == PARM_DECL && cxx_dialect < cxx20)
   10861                 :             :     return NULL_TREE;
   10862                 :             : 
   10863                 :             :   /* We don't check for lambda-expression here, because we should not get past
   10864                 :             :      the DECL_HAS_VALUE_EXPR_P check above.  */
   10865                 :          77 :   for (cp_binding_level *b = current_binding_level;
   10866                 :         126 :        b->kind != sk_namespace; b = b->level_chain)
   10867                 :             :     {
   10868                 :         123 :       for (tree decl = b->names; decl; decl = TREE_CHAIN (decl))
   10869                 :          57 :         if (decl == retval)
   10870                 :          52 :           return set_implicit_rvalue_p (move (expr));
   10871                 :          66 :       if (b->kind == sk_try)
   10872                 :             :         return NULL_TREE;
   10873                 :             :     }
   10874                 :             : 
   10875                 :           8 :   return set_implicit_rvalue_p (move (expr));
   10876                 :             : }
   10877                 :             : 
   10878                 :             : /* Warn about dubious usage of std::move (in a return statement, if RETURN_P
   10879                 :             :    is true).  EXPR is the std::move expression; TYPE is the type of the object
   10880                 :             :    being initialized.  */
   10881                 :             : 
   10882                 :             : void
   10883                 :   114964564 : maybe_warn_pessimizing_move (tree expr, tree type, bool return_p)
   10884                 :             : {
   10885                 :   114964564 :   if (!(warn_pessimizing_move || warn_redundant_move))
   10886                 :             :     return;
   10887                 :             : 
   10888                 :     3995926 :   const location_t loc = cp_expr_loc_or_input_loc (expr);
   10889                 :             : 
   10890                 :             :   /* C++98 doesn't know move.  */
   10891                 :     3995926 :   if (cxx_dialect < cxx11)
   10892                 :             :     return;
   10893                 :             : 
   10894                 :             :   /* Wait until instantiation time, since we can't gauge if we should do
   10895                 :             :      the NRVO until then.  */
   10896                 :     3931758 :   if (processing_template_decl)
   10897                 :             :     return;
   10898                 :             : 
   10899                 :             :   /* This is only interesting for class types.  */
   10900                 :     3857059 :   if (!CLASS_TYPE_P (type))
   10901                 :             :     return;
   10902                 :             : 
   10903                 :       75708 :   bool wrapped_p = false;
   10904                 :             :   /* A a = std::move (A());  */
   10905                 :       75708 :   if (TREE_CODE (expr) == TREE_LIST)
   10906                 :             :     {
   10907                 :        6750 :       if (list_length (expr) == 1)
   10908                 :             :         {
   10909                 :        4434 :           expr = TREE_VALUE (expr);
   10910                 :        4434 :           wrapped_p = true;
   10911                 :             :         }
   10912                 :             :       else
   10913                 :             :         return;
   10914                 :             :     }
   10915                 :             :   /* A a = {std::move (A())};
   10916                 :             :      A a{std::move (A())};  */
   10917                 :       68958 :   else if (TREE_CODE (expr) == CONSTRUCTOR)
   10918                 :             :     {
   10919                 :        4530 :       if (CONSTRUCTOR_NELTS (expr) == 1)
   10920                 :             :         {
   10921                 :         602 :           expr = CONSTRUCTOR_ELT (expr, 0)->value;
   10922                 :         602 :           wrapped_p = true;
   10923                 :             :         }
   10924                 :             :       else
   10925                 :             :         return;
   10926                 :             :     }
   10927                 :             : 
   10928                 :             :   /* First, check if this is a call to std::move.  */
   10929                 :        4650 :   if (!REFERENCE_REF_P (expr)
   10930                 :       72978 :       || TREE_CODE (TREE_OPERAND (expr, 0)) != CALL_EXPR)
   10931                 :             :     return;
   10932                 :        2023 :   tree fn = TREE_OPERAND (expr, 0);
   10933                 :        2023 :   if (!is_std_move_p (fn))
   10934                 :             :     return;
   10935                 :        1558 :   tree arg = CALL_EXPR_ARG (fn, 0);
   10936                 :        1558 :   if (TREE_CODE (arg) != NOP_EXPR)
   10937                 :             :     return;
   10938                 :             :   /* If we're looking at *std::move<T&> ((T &) &arg), do the pessimizing N/RVO
   10939                 :             :      and implicitly-movable warnings.  */
   10940                 :        1558 :   if (TREE_CODE (TREE_OPERAND (arg, 0)) == ADDR_EXPR)
   10941                 :             :     {
   10942                 :         993 :       arg = TREE_OPERAND (arg, 0);
   10943                 :         993 :       arg = TREE_OPERAND (arg, 0);
   10944                 :         993 :       arg = convert_from_reference (arg);
   10945                 :         993 :       if (can_elide_copy_prvalue_p (arg, type))
   10946                 :             :         {
   10947                 :         108 :           auto_diagnostic_group d;
   10948                 :         108 :           if (warning_at (loc, OPT_Wpessimizing_move,
   10949                 :             :                           "moving a temporary object prevents copy elision"))
   10950                 :         108 :             inform (loc, "remove %<std::move%> call");
   10951                 :         108 :         }
   10952                 :             :       /* The rest of the warnings is only relevant for when we are returning
   10953                 :             :          from a function.  */
   10954                 :         993 :       if (!return_p)
   10955                 :             :         return;
   10956                 :             : 
   10957                 :         294 :       tree moved;
   10958                 :             :       /* Warn if we could do copy elision were it not for the move.  */
   10959                 :         294 :       if (can_do_nrvo_p (arg, type))
   10960                 :             :         {
   10961                 :          48 :           auto_diagnostic_group d;
   10962                 :          48 :           if (!warning_suppressed_p (expr, OPT_Wpessimizing_move)
   10963                 :          48 :               && warning_at (loc, OPT_Wpessimizing_move,
   10964                 :             :                              "moving a local object in a return statement "
   10965                 :             :                              "prevents copy elision"))
   10966                 :          42 :             inform (loc, "remove %<std::move%> call");
   10967                 :          48 :         }
   10968                 :             :       /* Warn if the move is redundant.  It is redundant when we would
   10969                 :             :          do maybe-rvalue overload resolution even without std::move.  */
   10970                 :         246 :       else if (warn_redundant_move
   10971                 :             :                /* This doesn't apply for return {std::move (t)};.  */
   10972                 :         152 :                && !wrapped_p
   10973                 :         149 :                && !warning_suppressed_p (expr, OPT_Wredundant_move)
   10974                 :         342 :                && (moved = treat_lvalue_as_rvalue_p (arg, /*return*/true)))
   10975                 :             :         {
   10976                 :             :           /* Make sure that overload resolution would actually succeed
   10977                 :             :              if we removed the std::move call.  */
   10978                 :          54 :           tree t = convert_for_initialization (NULL_TREE, type,
   10979                 :             :                                                moved,
   10980                 :             :                                                (LOOKUP_NORMAL
   10981                 :             :                                                 | LOOKUP_ONLYCONVERTING),
   10982                 :             :                                                ICR_RETURN, NULL_TREE, 0,
   10983                 :             :                                                tf_none);
   10984                 :             :           /* If this worked, implicit rvalue would work, so the call to
   10985                 :             :              std::move is redundant.  */
   10986                 :          54 :           if (t != error_mark_node)
   10987                 :             :             {
   10988                 :          54 :               auto_diagnostic_group d;
   10989                 :          54 :               if (warning_at (loc, OPT_Wredundant_move,
   10990                 :             :                               "redundant move in return statement"))
   10991                 :          54 :                 inform (loc, "remove %<std::move%> call");
   10992                 :          54 :             }
   10993                 :             :         }
   10994                 :             :      }
   10995                 :             :   /* Also try to warn about redundant std::move in code such as
   10996                 :             :       T f (const T& t)
   10997                 :             :       {
   10998                 :             :         return std::move(t);
   10999                 :             :       }
   11000                 :             :     for which EXPR will be something like
   11001                 :             :       *std::move<const T&> ((const struct T &) (const struct T *) t)
   11002                 :             :      and where the std::move does nothing if T does not have a T(const T&&)
   11003                 :             :      constructor, because the argument is const.  It will not use T(T&&)
   11004                 :             :      because that would mean losing the const.  */
   11005                 :         565 :   else if (warn_redundant_move
   11006                 :         445 :            && !warning_suppressed_p (expr, OPT_Wredundant_move)
   11007                 :          64 :            && TYPE_REF_P (TREE_TYPE (arg))
   11008                 :         629 :            && CP_TYPE_CONST_P (TREE_TYPE (TREE_TYPE (arg))))
   11009                 :             :     {
   11010                 :          18 :       tree rtype = TREE_TYPE (TREE_TYPE (arg));
   11011                 :          18 :       if (!same_type_ignoring_top_level_qualifiers_p (rtype, type))
   11012                 :           9 :         return;
   11013                 :             :       /* Check for the unlikely case there's T(const T&&) (we don't care if
   11014                 :             :          it's deleted).  */
   11015                 :          54 :       for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (rtype)))
   11016                 :          30 :         if (move_fn_p (fn))
   11017                 :             :           {
   11018                 :          15 :             tree t = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (fn));
   11019                 :          15 :             if (UNLIKELY (CP_TYPE_CONST_P (TREE_TYPE (t))))
   11020                 :           6 :               return;
   11021                 :             :           }
   11022                 :           9 :       auto_diagnostic_group d;
   11023                 :           9 :       if (return_p
   11024                 :           9 :           ? warning_at (loc, OPT_Wredundant_move,
   11025                 :             :                         "redundant move in return statement")
   11026                 :           3 :           : warning_at (loc, OPT_Wredundant_move,
   11027                 :             :                         "redundant move in initialization"))
   11028                 :           9 :         inform (loc, "remove %<std::move%> call");
   11029                 :           9 :     }
   11030                 :             : }
   11031                 :             : 
   11032                 :             : /* Check that returning RETVAL from the current function is valid.
   11033                 :             :    Return an expression explicitly showing all conversions required to
   11034                 :             :    change RETVAL into the function return type, and to assign it to
   11035                 :             :    the DECL_RESULT for the function.  Set *NO_WARNING to true if
   11036                 :             :    code reaches end of non-void function warning shouldn't be issued
   11037                 :             :    on this RETURN_EXPR.  Set *DANGLING to true if code returns the
   11038                 :             :    address of a local variable.  */
   11039                 :             : 
   11040                 :             : tree
   11041                 :    95680479 : check_return_expr (tree retval, bool *no_warning, bool *dangling)
   11042                 :             : {
   11043                 :    95680479 :   tree result;
   11044                 :             :   /* The type actually returned by the function.  */
   11045                 :    95680479 :   tree valtype;
   11046                 :             :   /* The type the function is declared to return, or void if
   11047                 :             :      the declared type is incomplete.  */
   11048                 :    95680479 :   tree functype;
   11049                 :    95680479 :   int fn_returns_value_p;
   11050                 :    95680479 :   location_t loc = cp_expr_loc_or_input_loc (retval);
   11051                 :             : 
   11052                 :    95680479 :   *no_warning = false;
   11053                 :    95680479 :   *dangling = false;
   11054                 :             : 
   11055                 :             :   /* A `volatile' function is one that isn't supposed to return, ever.
   11056                 :             :      (This is a G++ extension, used to get better code for functions
   11057                 :             :      that call the `volatile' function.)  */
   11058                 :    95680479 :   if (TREE_THIS_VOLATILE (current_function_decl))
   11059                 :           4 :     warning (0, "function declared %<noreturn%> has a %<return%> statement");
   11060                 :             : 
   11061                 :             :   /* Check for various simple errors.  */
   11062                 :   191360958 :   if (DECL_DESTRUCTOR_P (current_function_decl))
   11063                 :             :     {
   11064                 :        1529 :       if (retval)
   11065                 :           4 :         error_at (loc, "returning a value from a destructor");
   11066                 :             : 
   11067                 :        1529 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11068                 :           0 :         retval = current_class_ptr;
   11069                 :             :       else
   11070                 :             :         return NULL_TREE;
   11071                 :             :     }
   11072                 :    95678950 :   else if (DECL_CONSTRUCTOR_P (current_function_decl))
   11073                 :             :     {
   11074                 :       26665 :       if (in_function_try_handler)
   11075                 :             :         /* If a return statement appears in a handler of the
   11076                 :             :            function-try-block of a constructor, the program is ill-formed.  */
   11077                 :           0 :         error ("cannot return from a handler of a function-try-block of a constructor");
   11078                 :       26665 :       else if (retval)
   11079                 :             :         /* You can't return a value from a constructor.  */
   11080                 :           4 :         error_at (loc, "returning a value from a constructor");
   11081                 :             : 
   11082                 :       26665 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11083                 :           0 :         retval = current_class_ptr;
   11084                 :             :       else
   11085                 :             :         return NULL_TREE;
   11086                 :             :     }
   11087                 :             : 
   11088                 :    95652285 :   const tree saved_retval = retval;
   11089                 :             : 
   11090                 :    95652285 :   if (processing_template_decl)
   11091                 :             :     {
   11092                 :    62396111 :       current_function_returns_value = 1;
   11093                 :             : 
   11094                 :    62396111 :       if (check_for_bare_parameter_packs (retval))
   11095                 :          10 :         return error_mark_node;
   11096                 :             : 
   11097                 :             :       /* If one of the types might be void, we can't tell whether we're
   11098                 :             :          returning a value.  */
   11099                 :    62396101 :       if ((WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
   11100                 :    23788348 :            && !FNDECL_USED_AUTO (current_function_decl))
   11101                 :    38607753 :           || (retval != NULL_TREE
   11102                 :    37731044 :               && (TREE_TYPE (retval) == NULL_TREE
   11103                 :    26494131 :                   || WILDCARD_TYPE_P (TREE_TYPE (retval)))))
   11104                 :    42050983 :         goto dependent;
   11105                 :             :     }
   11106                 :             : 
   11107                 :    53601292 :   functype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11108                 :             : 
   11109                 :             :   /* Deduce auto return type from a return statement.  */
   11110                 :    53601292 :   if (FNDECL_USED_AUTO (current_function_decl))
   11111                 :             :     {
   11112                 :      608666 :       tree pattern = DECL_SAVED_AUTO_RETURN_TYPE (current_function_decl);
   11113                 :      608666 :       tree auto_node;
   11114                 :      608666 :       tree type;
   11115                 :             : 
   11116                 :      608666 :       if (!retval && !is_auto (pattern))
   11117                 :             :         {
   11118                 :             :           /* Give a helpful error message.  */
   11119                 :           3 :           error ("return-statement with no value, in function returning %qT",
   11120                 :             :                  pattern);
   11121                 :           3 :           inform (input_location, "only plain %<auto%> return type can be "
   11122                 :             :                   "deduced to %<void%>");
   11123                 :           3 :           type = error_mark_node;
   11124                 :             :         }
   11125                 :      608663 :       else if (retval && BRACE_ENCLOSED_INITIALIZER_P (retval))
   11126                 :             :         {
   11127                 :           6 :           error ("returning initializer list");
   11128                 :           6 :           type = error_mark_node;
   11129                 :             :         }
   11130                 :             :       else
   11131                 :             :         {
   11132                 :      608657 :           if (!retval)
   11133                 :        4021 :             retval = void_node;
   11134                 :      608657 :           auto_node = type_uses_auto (pattern);
   11135                 :      608657 :           type = do_auto_deduction (pattern, retval, auto_node,
   11136                 :             :                                     tf_warning_or_error, adc_return_type);
   11137                 :             :         }
   11138                 :             : 
   11139                 :      608666 :       if (type == error_mark_node)
   11140                 :             :         /* Leave it.  */;
   11141                 :      608515 :       else if (functype == pattern)
   11142                 :      384759 :         apply_deduced_return_type (current_function_decl, type);
   11143                 :      223756 :       else if (!same_type_p (type, functype))
   11144                 :             :         {
   11145                 :          25 :           if (LAMBDA_FUNCTION_P (current_function_decl))
   11146                 :           6 :             error_at (loc, "inconsistent types %qT and %qT deduced for "
   11147                 :             :                       "lambda return type", functype, type);
   11148                 :             :           else
   11149                 :          13 :             error_at (loc, "inconsistent deduction for auto return type: "
   11150                 :             :                       "%qT and then %qT", functype, type);
   11151                 :             :         }
   11152                 :             :       functype = type;
   11153                 :             :     }
   11154                 :             : 
   11155                 :    53601292 :   result = DECL_RESULT (current_function_decl);
   11156                 :    53601292 :   valtype = TREE_TYPE (result);
   11157                 :    53601292 :   gcc_assert (valtype != NULL_TREE);
   11158                 :    53601292 :   fn_returns_value_p = !VOID_TYPE_P (valtype);
   11159                 :             : 
   11160                 :             :   /* Check for a return statement with no return value in a function
   11161                 :             :      that's supposed to return a value.  */
   11162                 :    53601292 :   if (!retval && fn_returns_value_p)
   11163                 :             :     {
   11164                 :          34 :       if (functype != error_mark_node)
   11165                 :          31 :         permerror (input_location, "return-statement with no value, in "
   11166                 :             :                    "function returning %qT", valtype);
   11167                 :             :       /* Remember that this function did return.  */
   11168                 :          34 :       current_function_returns_value = 1;
   11169                 :             :       /* And signal caller that TREE_NO_WARNING should be set on the
   11170                 :             :          RETURN_EXPR to avoid control reaches end of non-void function
   11171                 :             :          warnings in tree-cfg.cc.  */
   11172                 :          34 :       *no_warning = true;
   11173                 :             :     }
   11174                 :             :   /* Check for a return statement with a value in a function that
   11175                 :             :      isn't supposed to return a value.  */
   11176                 :    53601258 :   else if (retval && !fn_returns_value_p)
   11177                 :             :     {
   11178                 :      191491 :       if (VOID_TYPE_P (TREE_TYPE (retval)))
   11179                 :             :         /* You can return a `void' value from a function of `void'
   11180                 :             :            type.  In that case, we have to evaluate the expression for
   11181                 :             :            its side-effects.  */
   11182                 :      191461 :         finish_expr_stmt (retval);
   11183                 :          30 :       else if (retval != error_mark_node)
   11184                 :          26 :         permerror (loc, "return-statement with a value, in function "
   11185                 :             :                    "returning %qT", valtype);
   11186                 :      191491 :       current_function_returns_null = 1;
   11187                 :             : 
   11188                 :             :       /* There's really no value to return, after all.  */
   11189                 :      191491 :       return NULL_TREE;
   11190                 :             :     }
   11191                 :    53409767 :   else if (!retval)
   11192                 :             :     /* Remember that this function can sometimes return without a
   11193                 :             :        value.  */
   11194                 :     1265325 :     current_function_returns_null = 1;
   11195                 :             :   else
   11196                 :             :     /* Remember that this function did return a value.  */
   11197                 :    52144442 :     current_function_returns_value = 1;
   11198                 :             : 
   11199                 :             :   /* Check for erroneous operands -- but after giving ourselves a
   11200                 :             :      chance to provide an error about returning a value from a void
   11201                 :             :      function.  */
   11202                 :    53409801 :   if (error_operand_p (retval))
   11203                 :             :     {
   11204                 :         977 :       current_function_return_value = error_mark_node;
   11205                 :         977 :       return error_mark_node;
   11206                 :             :     }
   11207                 :             : 
   11208                 :             :   /* Only operator new(...) throw(), can return NULL [expr.new/13].  */
   11209                 :    64910272 :   if (IDENTIFIER_NEW_OP_P (DECL_NAME (current_function_decl))
   11210                 :       29547 :       && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
   11211                 :        2768 :       && ! flag_check_new
   11212                 :    53411580 :       && retval && null_ptr_cst_p (retval))
   11213                 :          32 :     warning (0, "%<operator new%> must not return NULL unless it is "
   11214                 :             :              "declared %<throw()%> (or %<-fcheck-new%> is in effect)");
   11215                 :             : 
   11216                 :             :   /* Effective C++ rule 15.  See also start_function.  */
   11217                 :    53408824 :   if (warn_ecpp
   11218                 :          56 :       && DECL_NAME (current_function_decl) == assign_op_identifier
   11219                 :    53408864 :       && !type_dependent_expression_p (retval))
   11220                 :             :     {
   11221                 :          36 :       bool warn = true;
   11222                 :             : 
   11223                 :             :       /* The function return type must be a reference to the current
   11224                 :             :         class.  */
   11225                 :          36 :       if (TYPE_REF_P (valtype)
   11226                 :          60 :           && same_type_ignoring_top_level_qualifiers_p
   11227                 :          24 :               (TREE_TYPE (valtype), TREE_TYPE (current_class_ref)))
   11228                 :             :         {
   11229                 :             :           /* Returning '*this' is obviously OK.  */
   11230                 :          24 :           if (retval == current_class_ref)
   11231                 :             :             warn = false;
   11232                 :             :           /* If we are calling a function whose return type is the same of
   11233                 :             :              the current class reference, it is ok.  */
   11234                 :           8 :           else if (INDIRECT_REF_P (retval)
   11235                 :           8 :                    && TREE_CODE (TREE_OPERAND (retval, 0)) == CALL_EXPR)
   11236                 :             :             warn = false;
   11237                 :             :         }
   11238                 :             : 
   11239                 :             :       if (warn)
   11240                 :          12 :         warning_at (loc, OPT_Weffc__,
   11241                 :             :                     "%<operator=%> should return a reference to %<*this%>");
   11242                 :             :     }
   11243                 :             : 
   11244                 :    53408824 :   if (dependent_type_p (functype)
   11245                 :    53408824 :       || type_dependent_expression_p (retval))
   11246                 :             :     {
   11247                 :    54745729 :     dependent:
   11248                 :             :       /* We should not have changed the return value.  */
   11249                 :    54745729 :       gcc_assert (retval == saved_retval);
   11250                 :             :       /* We don't know if this is an lvalue or rvalue use, but
   11251                 :             :          either way we can mark it as read.  */
   11252                 :    54745729 :       mark_exp_read (retval);
   11253                 :    54745729 :       return retval;
   11254                 :             :     }
   11255                 :             : 
   11256                 :             :   /* The fabled Named Return Value optimization, as per [class.copy]/15:
   11257                 :             : 
   11258                 :             :      [...]      For  a function with a class return type, if the expression
   11259                 :             :      in the return statement is the name of a local  object,  and  the  cv-
   11260                 :             :      unqualified  type  of  the  local  object  is the same as the function
   11261                 :             :      return type, an implementation is permitted to omit creating the  tem-
   11262                 :             :      porary  object  to  hold  the function return value [...]
   11263                 :             : 
   11264                 :             :      So, if this is a value-returning function that always returns the same
   11265                 :             :      local variable, remember it.
   11266                 :             : 
   11267                 :             :      We choose the first suitable variable even if the function sometimes
   11268                 :             :      returns something else, but only if the variable is out of scope at the
   11269                 :             :      other return sites, or else we run the risk of clobbering the variable we
   11270                 :             :      chose if the other returned expression uses the chosen variable somehow.
   11271                 :             : 
   11272                 :             :      We don't currently do this if the first return is a non-variable, as it
   11273                 :             :      would be complicated to determine whether an NRV selected later was in
   11274                 :             :      scope at the point of the earlier return.  We also don't currently support
   11275                 :             :      multiple variables with non-overlapping scopes (53637).
   11276                 :             : 
   11277                 :             :      See finish_function and finalize_nrv for the rest of this optimization.  */
   11278                 :    40714078 :   tree bare_retval = NULL_TREE;
   11279                 :    40714078 :   if (retval)
   11280                 :             :     {
   11281                 :    39448736 :       retval = maybe_undo_parenthesized_ref (retval);
   11282                 :    39448736 :       bare_retval = tree_strip_any_location_wrapper (retval);
   11283                 :             :     }
   11284                 :             : 
   11285                 :    40714078 :   bool named_return_value_okay_p = want_nrvo_p (bare_retval, functype);
   11286                 :    40714078 :   if (fn_returns_value_p && flag_elide_constructors
   11287                 :    39448709 :       && current_function_return_value != bare_retval)
   11288                 :             :     {
   11289                 :    39440504 :       if (named_return_value_okay_p
   11290                 :      203142 :           && current_function_return_value == NULL_TREE)
   11291                 :      163574 :         current_function_return_value = bare_retval;
   11292                 :    39276930 :       else if (current_function_return_value
   11293                 :     7339816 :                && VAR_P (current_function_return_value)
   11294                 :         119 :                && DECL_NAME (current_function_return_value)
   11295                 :    39277049 :                && !decl_in_scope_p (current_function_return_value))
   11296                 :             :         {
   11297                 :             :           /* The earlier NRV is out of scope at this point, so it's safe to
   11298                 :          52 :              leave it alone; the current return can't refer to it.  */;
   11299                 :          52 :           if (named_return_value_okay_p
   11300                 :          52 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11301                 :             :             {
   11302                 :           9 :               warning (OPT_Wnrvo, "not eliding copy on return from %qD",
   11303                 :             :                        bare_retval);
   11304                 :           9 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   11305                 :             :             }
   11306                 :             :         }
   11307                 :             :       else
   11308                 :             :         {
   11309                 :    39276878 :           if ((named_return_value_okay_p
   11310                 :    39237321 :                || (current_function_return_value
   11311                 :     7300207 :                    && current_function_return_value != error_mark_node))
   11312                 :    39276922 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11313                 :             :             {
   11314                 :       39547 :               warning (OPT_Wnrvo, "not eliding copy on return in %qD",
   11315                 :             :                        current_function_decl);
   11316                 :       39547 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   11317                 :             :             }
   11318                 :    39276878 :           current_function_return_value = error_mark_node;
   11319                 :             :         }
   11320                 :             :     }
   11321                 :             : 
   11322                 :             :   /* We don't need to do any conversions when there's nothing being
   11323                 :             :      returned.  */
   11324                 :    40714078 :   if (!retval)
   11325                 :             :     return NULL_TREE;
   11326                 :             : 
   11327                 :    39448736 :   if (!named_return_value_okay_p)
   11328                 :    39237409 :     maybe_warn_pessimizing_move (retval, functype, /*return_p*/true);
   11329                 :             : 
   11330                 :             :   /* Do any required conversions.  */
   11331                 :    78897174 :   if (bare_retval == result || DECL_CONSTRUCTOR_P (current_function_decl))
   11332                 :             :     /* No conversions are required.  */
   11333                 :             :     ;
   11334                 :             :   else
   11335                 :             :     {
   11336                 :    39448438 :       int flags = LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING;
   11337                 :             : 
   11338                 :             :       /* The functype's return type will have been set to void, if it
   11339                 :             :          was an incomplete type.  Just treat this as 'return;' */
   11340                 :    39448438 :       if (VOID_TYPE_P (functype))
   11341                 :           7 :         return error_mark_node;
   11342                 :             : 
   11343                 :             :       /* Under C++11 [12.8/32 class.copy], a returned lvalue is sometimes
   11344                 :             :          treated as an rvalue for the purposes of overload resolution to
   11345                 :             :          favor move constructors over copy constructors.
   11346                 :             : 
   11347                 :             :          Note that these conditions are similar to, but not as strict as,
   11348                 :             :          the conditions for the named return value optimization.  */
   11349                 :    39448431 :       bool converted = false;
   11350                 :    39448431 :       tree moved;
   11351                 :             :       /* Until C++23, this was only interesting for class type, but in C++23,
   11352                 :             :          we should do the below when we're converting rom/to a class/reference
   11353                 :             :          (a non-scalar type).  */
   11354                 :    39448431 :         if ((cxx_dialect < cxx23
   11355                 :     4667210 :              ? CLASS_TYPE_P (functype)
   11356                 :     6805693 :              : !SCALAR_TYPE_P (functype) || !SCALAR_TYPE_P (TREE_TYPE (retval)))
   11357                 :    46089915 :             && (moved = treat_lvalue_as_rvalue_p (retval, /*return*/true)))
   11358                 :             :           /* In C++20 and earlier we treat the return value as an rvalue
   11359                 :             :              that can bind to lvalue refs.  In C++23, such an expression is just
   11360                 :             :              an xvalue (see reference_binding).  */
   11361                 :             :           retval = moved;
   11362                 :             : 
   11363                 :             :       /* The call in a (lambda) thunk needs no conversions.  */
   11364                 :    39448431 :       if (TREE_CODE (retval) == CALL_EXPR
   11365                 :    39448431 :           && call_from_lambda_thunk_p (retval))
   11366                 :             :         converted = true;
   11367                 :             : 
   11368                 :             :       /* First convert the value to the function's return type, then
   11369                 :             :          to the type of return value's location to handle the
   11370                 :             :          case that functype is smaller than the valtype.  */
   11371                 :    39441090 :       if (!converted)
   11372                 :    39441090 :         retval = convert_for_initialization
   11373                 :    39441090 :           (NULL_TREE, functype, retval, flags, ICR_RETURN, NULL_TREE, 0,
   11374                 :             :            tf_warning_or_error);
   11375                 :    39448431 :       retval = convert (valtype, retval);
   11376                 :             : 
   11377                 :             :       /* If the conversion failed, treat this just like `return;'.  */
   11378                 :    39448431 :       if (retval == error_mark_node)
   11379                 :             :         return retval;
   11380                 :             :       /* We can't initialize a register from a AGGR_INIT_EXPR.  */
   11381                 :    39448248 :       else if (! cfun->returns_struct
   11382                 :    38099741 :                && TREE_CODE (retval) == TARGET_EXPR
   11383                 :    43402805 :                && TREE_CODE (TREE_OPERAND (retval, 1)) == AGGR_INIT_EXPR)
   11384                 :      687558 :         retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval,
   11385                 :      687558 :                          TREE_OPERAND (retval, 0));
   11386                 :    38760690 :       else if (!processing_template_decl
   11387                 :    31987261 :                && maybe_warn_about_returning_address_of_local (retval, loc)
   11388                 :    38760898 :                && INDIRECT_TYPE_P (valtype))
   11389                 :         191 :         *dangling = true;
   11390                 :             :     }
   11391                 :             : 
   11392                 :             :   /* A naive attempt to reduce the number of -Wdangling-reference false
   11393                 :             :      positives: if we know that this function can return a variable with
   11394                 :             :      static storage duration rather than one of its parameters, suppress
   11395                 :             :      the warning.  */
   11396                 :    39448546 :   if (warn_dangling_reference
   11397                 :      952807 :       && TYPE_REF_P (functype)
   11398                 :       28332 :       && bare_retval
   11399                 :             :       && VAR_P (bare_retval)
   11400                 :       28332 :       && TREE_STATIC (bare_retval))
   11401                 :          56 :     suppress_warning (current_function_decl, OPT_Wdangling_reference);
   11402                 :             : 
   11403                 :    39448546 :   if (processing_template_decl)
   11404                 :             :     return saved_retval;
   11405                 :             : 
   11406                 :             :   /* Actually copy the value returned into the appropriate location.  */
   11407                 :    32675117 :   if (retval && retval != result)
   11408                 :             :     {
   11409                 :             :       /* If there's a postcondition for a scalar return value, wrap
   11410                 :             :          retval in a call to the postcondition function.  */
   11411                 :    32674819 :       if (tree post = apply_postcondition_to_return (retval))
   11412                 :          57 :         retval = post;
   11413                 :    32674819 :       retval = cp_build_init_expr (result, retval);
   11414                 :             :     }
   11415                 :             : 
   11416                 :    32675117 :   if (current_function_return_value == bare_retval)
   11417                 :      171759 :     INIT_EXPR_NRV_P (retval) = true;
   11418                 :             : 
   11419                 :    32675117 :   if (tree set = maybe_set_retval_sentinel ())
   11420                 :      129005 :     retval = build2 (COMPOUND_EXPR, void_type_node, retval, set);
   11421                 :             : 
   11422                 :             :   /* If there's a postcondition for an aggregate return value, call the
   11423                 :             :      postcondition function after the return object is initialized.  */
   11424                 :    32675117 :   if (tree post = apply_postcondition_to_return (result))
   11425                 :           2 :     retval = build2 (COMPOUND_EXPR, void_type_node, retval, post);
   11426                 :             : 
   11427                 :             :   return retval;
   11428                 :             : }
   11429                 :             : 
   11430                 :             : 
   11431                 :             : /* Returns nonzero if the pointer-type FROM can be converted to the
   11432                 :             :    pointer-type TO via a qualification conversion.  If CONSTP is -1,
   11433                 :             :    then we return nonzero if the pointers are similar, and the
   11434                 :             :    cv-qualification signature of FROM is a proper subset of that of TO.
   11435                 :             : 
   11436                 :             :    If CONSTP is positive, then all outer pointers have been
   11437                 :             :    const-qualified.  */
   11438                 :             : 
   11439                 :             : static bool
   11440                 :   108394959 : comp_ptr_ttypes_real (tree to, tree from, int constp)
   11441                 :             : {
   11442                 :   108394959 :   bool to_more_cv_qualified = false;
   11443                 :   108394959 :   bool is_opaque_pointer = false;
   11444                 :             : 
   11445                 :      509705 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   11446                 :             :     {
   11447                 :   108904664 :       if (TREE_CODE (to) != TREE_CODE (from))
   11448                 :             :         return false;
   11449                 :             : 
   11450                 :    68353891 :       if (TREE_CODE (from) == OFFSET_TYPE
   11451                 :    68353891 :           && !same_type_p (TYPE_OFFSET_BASETYPE (from),
   11452                 :             :                            TYPE_OFFSET_BASETYPE (to)))
   11453                 :             :         return false;
   11454                 :             : 
   11455                 :             :       /* Const and volatile mean something different for function and
   11456                 :             :          array types, so the usual checks are not appropriate.  We'll
   11457                 :             :          check the array type elements in further iterations.  */
   11458                 :    68353891 :       if (!FUNC_OR_METHOD_TYPE_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   11459                 :             :         {
   11460                 :    68135488 :           if (!at_least_as_qualified_p (to, from))
   11461                 :             :             return false;
   11462                 :             : 
   11463                 :    60125327 :           if (!at_least_as_qualified_p (from, to))
   11464                 :             :             {
   11465                 :    42040314 :               if (constp == 0)
   11466                 :             :                 return false;
   11467                 :             :               to_more_cv_qualified = true;
   11468                 :             :             }
   11469                 :             : 
   11470                 :    60125055 :           if (constp > 0)
   11471                 :    60121713 :             constp &= TYPE_READONLY (to);
   11472                 :             :         }
   11473                 :             : 
   11474                 :    60343458 :       if (VECTOR_TYPE_P (to))
   11475                 :        6255 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   11476                 :             : 
   11477                 :             :       /* P0388R4 allows a conversion from int[N] to int[] but not the
   11478                 :             :          other way round.  When both arrays have bounds but they do
   11479                 :             :          not match, then no conversion is possible.  */
   11480                 :    60343458 :       if (TREE_CODE (to) == ARRAY_TYPE
   11481                 :    60343458 :           && !comp_array_types (to, from, bounds_first, /*strict=*/false))
   11482                 :             :         return false;
   11483                 :             : 
   11484                 :    60343203 :       if (!TYPE_PTR_P (to)
   11485                 :             :           && !TYPE_PTRDATAMEM_P (to)
   11486                 :             :           /* CWG 330 says we need to look through arrays.  */
   11487                 :             :           && TREE_CODE (to) != ARRAY_TYPE)
   11488                 :    59833498 :         return ((constp >= 0 || to_more_cv_qualified)
   11489                 :    59833498 :                 && (is_opaque_pointer
   11490                 :    59832986 :                     || same_type_ignoring_top_level_qualifiers_p (to, from)));
   11491                 :             :     }
   11492                 :             : }
   11493                 :             : 
   11494                 :             : /* When comparing, say, char ** to char const **, this function takes
   11495                 :             :    the 'char *' and 'char const *'.  Do not pass non-pointer/reference
   11496                 :             :    types to this function.  */
   11497                 :             : 
   11498                 :             : int
   11499                 :   108394370 : comp_ptr_ttypes (tree to, tree from)
   11500                 :             : {
   11501                 :   108394370 :   return comp_ptr_ttypes_real (to, from, 1);
   11502                 :             : }
   11503                 :             : 
   11504                 :             : /* Returns true iff FNTYPE is a non-class type that involves
   11505                 :             :    error_mark_node.  We can get FUNCTION_TYPE with buried error_mark_node
   11506                 :             :    if a parameter type is ill-formed.  */
   11507                 :             : 
   11508                 :             : bool
   11509                 :      602632 : error_type_p (const_tree type)
   11510                 :             : {
   11511                 :      644308 :   tree t;
   11512                 :             : 
   11513                 :      644308 :   switch (TREE_CODE (type))
   11514                 :             :     {
   11515                 :             :     case ERROR_MARK:
   11516                 :             :       return true;
   11517                 :             : 
   11518                 :       41586 :     case POINTER_TYPE:
   11519                 :       41586 :     case REFERENCE_TYPE:
   11520                 :       41586 :     case OFFSET_TYPE:
   11521                 :       41586 :       return error_type_p (TREE_TYPE (type));
   11522                 :             : 
   11523                 :        3596 :     case FUNCTION_TYPE:
   11524                 :        3596 :     case METHOD_TYPE:
   11525                 :        3596 :       if (error_type_p (TREE_TYPE (type)))
   11526                 :             :         return true;
   11527                 :        9895 :       for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
   11528                 :        6307 :         if (error_type_p (TREE_VALUE (t)))
   11529                 :             :           return true;
   11530                 :             :       return false;
   11531                 :             : 
   11532                 :      192368 :     case RECORD_TYPE:
   11533                 :      192368 :       if (TYPE_PTRMEMFUNC_P (type))
   11534                 :          90 :         return error_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type));
   11535                 :             :       return false;
   11536                 :             : 
   11537                 :             :     default:
   11538                 :             :       return false;
   11539                 :             :     }
   11540                 :             : }
   11541                 :             : 
   11542                 :             : /* Returns true if to and from are (possibly multi-level) pointers to the same
   11543                 :             :    type or inheritance-related types, regardless of cv-quals.  */
   11544                 :             : 
   11545                 :             : bool
   11546                 :    76645234 : ptr_reasonably_similar (const_tree to, const_tree from)
   11547                 :             : {
   11548                 :        2336 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   11549                 :             :     {
   11550                 :             :       /* Any target type is similar enough to void.  */
   11551                 :    76647570 :       if (VOID_TYPE_P (to))
   11552                 :        1028 :         return !error_type_p (from);
   11553                 :    76646542 :       if (VOID_TYPE_P (from))
   11554                 :      588821 :         return !error_type_p (to);
   11555                 :             : 
   11556                 :    76057721 :       if (TREE_CODE (to) != TREE_CODE (from))
   11557                 :             :         return false;
   11558                 :             : 
   11559                 :    35975946 :       if (TREE_CODE (from) == OFFSET_TYPE
   11560                 :    35975946 :           && comptypes (TYPE_OFFSET_BASETYPE (to),
   11561                 :           4 :                         TYPE_OFFSET_BASETYPE (from),
   11562                 :             :                         COMPARE_BASE | COMPARE_DERIVED))
   11563                 :           4 :         continue;
   11564                 :             : 
   11565                 :    35975938 :       if (VECTOR_TYPE_P (to)
   11566                 :    35975938 :           && vector_types_convertible_p (to, from, false))
   11567                 :             :         return true;
   11568                 :             : 
   11569                 :    35975821 :       if (TREE_CODE (to) == INTEGER_TYPE
   11570                 :    35975821 :           && TYPE_PRECISION (to) == TYPE_PRECISION (from))
   11571                 :             :         return true;
   11572                 :             : 
   11573                 :    35826583 :       if (TREE_CODE (to) == FUNCTION_TYPE)
   11574                 :        1440 :         return !error_type_p (to) && !error_type_p (from);
   11575                 :             : 
   11576                 :    35825143 :       if (!TYPE_PTR_P (to))
   11577                 :             :         {
   11578                 :             :           /* When either type is incomplete avoid DERIVED_FROM_P,
   11579                 :             :              which may call complete_type (c++/57942).  */
   11580                 :    35822811 :           bool b = !COMPLETE_TYPE_P (to) || !COMPLETE_TYPE_P (from);
   11581                 :             :           return comptypes
   11582                 :    35822811 :             (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from),
   11583                 :    35822811 :              b ? COMPARE_STRICT : COMPARE_BASE | COMPARE_DERIVED);
   11584                 :             :         }
   11585                 :        2336 :     }
   11586                 :             : }
   11587                 :             : 
   11588                 :             : /* Return true if TO and FROM (both of which are POINTER_TYPEs or
   11589                 :             :    pointer-to-member types) are the same, ignoring cv-qualification at
   11590                 :             :    all levels.  CB says how we should behave when comparing array bounds.  */
   11591                 :             : 
   11592                 :             : bool
   11593                 :      621378 : comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
   11594                 :             : {
   11595                 :      621378 :   bool is_opaque_pointer = false;
   11596                 :             : 
   11597                 :      622405 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   11598                 :             :     {
   11599                 :     1243783 :       if (TREE_CODE (to) != TREE_CODE (from))
   11600                 :             :         return false;
   11601                 :             : 
   11602                 :      905788 :       if (TREE_CODE (from) == OFFSET_TYPE
   11603                 :      905747 :           && same_type_p (TYPE_OFFSET_BASETYPE (from),
   11604                 :             :                           TYPE_OFFSET_BASETYPE (to)))
   11605                 :          41 :           continue;
   11606                 :             : 
   11607                 :      905706 :       if (VECTOR_TYPE_P (to))
   11608                 :       11941 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   11609                 :             : 
   11610                 :      905706 :       if (TREE_CODE (to) == ARRAY_TYPE
   11611                 :             :           /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
   11612                 :             :              we must fail.  */
   11613                 :      905706 :           && !comp_array_types (to, from, cb, /*strict=*/false))
   11614                 :             :         return false;
   11615                 :             : 
   11616                 :             :       /* CWG 330 says we need to look through arrays.  */
   11617                 :      905304 :       if (!TYPE_PTR_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   11618                 :      282940 :         return (is_opaque_pointer
   11619                 :      282940 :                 || same_type_ignoring_top_level_qualifiers_p (to, from));
   11620                 :             :     }
   11621                 :             : }
   11622                 :             : 
   11623                 :             : /* Returns the type qualifiers for this type, including the qualifiers on the
   11624                 :             :    elements for an array type.  */
   11625                 :             : 
   11626                 :             : int
   11627                 : 41788157626 : cp_type_quals (const_tree type)
   11628                 :             : {
   11629                 : 41788157626 :   int quals;
   11630                 :             :   /* This CONST_CAST is okay because strip_array_types returns its
   11631                 :             :      argument unmodified and we assign it to a const_tree.  */
   11632                 : 41788157626 :   type = strip_array_types (CONST_CAST_TREE (type));
   11633                 : 41788157626 :   if (type == error_mark_node
   11634                 :             :       /* Quals on a FUNCTION_TYPE are memfn quals.  */
   11635                 : 41761716915 :       || TREE_CODE (type) == FUNCTION_TYPE)
   11636                 :             :     return TYPE_UNQUALIFIED;
   11637                 : 41721644643 :   quals = TYPE_QUALS (type);
   11638                 :             :   /* METHOD and REFERENCE_TYPEs should never have quals.  */
   11639                 : 41721644643 :   gcc_assert ((TREE_CODE (type) != METHOD_TYPE
   11640                 :             :                && !TYPE_REF_P (type))
   11641                 :             :               || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
   11642                 :             :                   == TYPE_UNQUALIFIED));
   11643                 :             :   return quals;
   11644                 :             : }
   11645                 :             : 
   11646                 :             : /* Returns the function-ref-qualifier for TYPE */
   11647                 :             : 
   11648                 :             : cp_ref_qualifier
   11649                 :  2862180348 : type_memfn_rqual (const_tree type)
   11650                 :             : {
   11651                 :  2862180348 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
   11652                 :             : 
   11653                 :  2862180348 :   if (!FUNCTION_REF_QUALIFIED (type))
   11654                 :             :     return REF_QUAL_NONE;
   11655                 :    36652247 :   else if (FUNCTION_RVALUE_QUALIFIED (type))
   11656                 :             :     return REF_QUAL_RVALUE;
   11657                 :             :   else
   11658                 :    18368194 :     return REF_QUAL_LVALUE;
   11659                 :             : }
   11660                 :             : 
   11661                 :             : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
   11662                 :             :    METHOD_TYPE.  */
   11663                 :             : 
   11664                 :             : int
   11665                 :   907700426 : type_memfn_quals (const_tree type)
   11666                 :             : {
   11667                 :   907700426 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   11668                 :    69809503 :     return TYPE_QUALS (type);
   11669                 :   837890923 :   else if (TREE_CODE (type) == METHOD_TYPE)
   11670                 :   837890923 :     return cp_type_quals (class_of_this_parm (type));
   11671                 :             :   else
   11672                 :           0 :     gcc_unreachable ();
   11673                 :             : }
   11674                 :             : 
   11675                 :             : /* Returns the FUNCTION_TYPE TYPE with its function-cv-quals changed to
   11676                 :             :    MEMFN_QUALS and its ref-qualifier to RQUAL. */
   11677                 :             : 
   11678                 :             : tree
   11679                 :    49288506 : apply_memfn_quals (tree type, cp_cv_quals memfn_quals, cp_ref_qualifier rqual)
   11680                 :             : {
   11681                 :             :   /* Could handle METHOD_TYPE here if necessary.  */
   11682                 :    49288506 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
   11683                 :    49288506 :   if (TYPE_QUALS (type) == memfn_quals
   11684                 :    49288506 :       && type_memfn_rqual (type) == rqual)
   11685                 :             :     return type;
   11686                 :             : 
   11687                 :             :   /* This should really have a different TYPE_MAIN_VARIANT, but that gets
   11688                 :             :      complex.  */
   11689                 :      531563 :   tree result = build_qualified_type (type, memfn_quals);
   11690                 :      531563 :   return build_ref_qualified_type (result, rqual);
   11691                 :             : }
   11692                 :             : 
   11693                 :             : /* Returns nonzero if TYPE is const or volatile.  */
   11694                 :             : 
   11695                 :             : bool
   11696                 :   886293862 : cv_qualified_p (const_tree type)
   11697                 :             : {
   11698                 :   886293862 :   int quals = cp_type_quals (type);
   11699                 :   886293862 :   return (quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)) != 0;
   11700                 :             : }
   11701                 :             : 
   11702                 :             : /* Returns nonzero if the TYPE contains a mutable member.  */
   11703                 :             : 
   11704                 :             : bool
   11705                 :   748091651 : cp_has_mutable_p (const_tree type)
   11706                 :             : {
   11707                 :             :   /* This CONST_CAST is okay because strip_array_types returns its
   11708                 :             :      argument unmodified and we assign it to a const_tree.  */
   11709                 :   748091651 :   type = strip_array_types (CONST_CAST_TREE(type));
   11710                 :             : 
   11711                 :   748091651 :   return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
   11712                 :             : }
   11713                 :             : 
   11714                 :             : /* Set TREE_READONLY and TREE_VOLATILE on DECL as indicated by the
   11715                 :             :    TYPE_QUALS.  For a VAR_DECL, this may be an optimistic
   11716                 :             :    approximation.  In particular, consider:
   11717                 :             : 
   11718                 :             :      int f();
   11719                 :             :      struct S { int i; };
   11720                 :             :      const S s = { f(); }
   11721                 :             : 
   11722                 :             :    Here, we will make "s" as TREE_READONLY (because it is declared
   11723                 :             :    "const") -- only to reverse ourselves upon seeing that the
   11724                 :             :    initializer is non-constant.  */
   11725                 :             : 
   11726                 :             : void
   11727                 :   799234543 : cp_apply_type_quals_to_decl (int type_quals, tree decl)
   11728                 :             : {
   11729                 :   799234543 :   tree type = TREE_TYPE (decl);
   11730                 :             : 
   11731                 :   799234543 :   if (type == error_mark_node)
   11732                 :             :     return;
   11733                 :             : 
   11734                 :   799233865 :   if (TREE_CODE (decl) == TYPE_DECL)
   11735                 :             :     return;
   11736                 :             : 
   11737                 :   712322066 :   gcc_assert (!(TREE_CODE (type) == FUNCTION_TYPE
   11738                 :             :                 && type_quals != TYPE_UNQUALIFIED));
   11739                 :             : 
   11740                 :             :   /* Avoid setting TREE_READONLY incorrectly.  */
   11741                 :             :   /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
   11742                 :             :      constructor can produce constant init, so rely on cp_finish_decl to
   11743                 :             :      clear TREE_READONLY if the variable has non-constant init.  */
   11744                 :             : 
   11745                 :             :   /* If the type has (or might have) a mutable component, that component
   11746                 :             :      might be modified.  */
   11747                 :   712322066 :   if (TYPE_HAS_MUTABLE_P (type) || !COMPLETE_TYPE_P (type))
   11748                 :    63335425 :     type_quals &= ~TYPE_QUAL_CONST;
   11749                 :             : 
   11750                 :   712322066 :   c_apply_type_quals_to_decl (type_quals, decl);
   11751                 :             : }
   11752                 :             : 
   11753                 :             : /* Subroutine of casts_away_constness.  Make T1 and T2 point at
   11754                 :             :    exemplar types such that casting T1 to T2 is casting away constness
   11755                 :             :    if and only if there is no implicit conversion from T1 to T2.  */
   11756                 :             : 
   11757                 :             : static void
   11758                 :     1099092 : casts_away_constness_r (tree *t1, tree *t2, tsubst_flags_t complain)
   11759                 :             : {
   11760                 :     1099092 :   int quals1;
   11761                 :     1099092 :   int quals2;
   11762                 :             : 
   11763                 :             :   /* [expr.const.cast]
   11764                 :             : 
   11765                 :             :      For multi-level pointer to members and multi-level mixed pointers
   11766                 :             :      and pointers to members (conv.qual), the "member" aspect of a
   11767                 :             :      pointer to member level is ignored when determining if a const
   11768                 :             :      cv-qualifier has been cast away.  */
   11769                 :             :   /* [expr.const.cast]
   11770                 :             : 
   11771                 :             :      For  two  pointer types:
   11772                 :             : 
   11773                 :             :             X1 is T1cv1,1 * ... cv1,N *   where T1 is not a pointer type
   11774                 :             :             X2 is T2cv2,1 * ... cv2,M *   where T2 is not a pointer type
   11775                 :             :             K is min(N,M)
   11776                 :             : 
   11777                 :             :      casting from X1 to X2 casts away constness if, for a non-pointer
   11778                 :             :      type T there does not exist an implicit conversion (clause
   11779                 :             :      _conv_) from:
   11780                 :             : 
   11781                 :             :             Tcv1,(N-K+1) * cv1,(N-K+2) * ... cv1,N *
   11782                 :             : 
   11783                 :             :      to
   11784                 :             : 
   11785                 :             :             Tcv2,(M-K+1) * cv2,(M-K+2) * ... cv2,M *.  */
   11786                 :     1099092 :   if ((!TYPE_PTR_P (*t1) && !TYPE_PTRDATAMEM_P (*t1))
   11787                 :      549924 :       || (!TYPE_PTR_P (*t2) && !TYPE_PTRDATAMEM_P (*t2)))
   11788                 :             :     {
   11789                 :      549316 :       *t1 = cp_build_qualified_type (void_type_node,
   11790                 :             :                                      cp_type_quals (*t1));
   11791                 :      549316 :       *t2 = cp_build_qualified_type (void_type_node,
   11792                 :             :                                      cp_type_quals (*t2));
   11793                 :      549316 :       return;
   11794                 :             :     }
   11795                 :             : 
   11796                 :      549776 :   quals1 = cp_type_quals (*t1);
   11797                 :      549776 :   quals2 = cp_type_quals (*t2);
   11798                 :             : 
   11799                 :      549776 :   if (TYPE_PTRDATAMEM_P (*t1))
   11800                 :           0 :     *t1 = TYPE_PTRMEM_POINTED_TO_TYPE (*t1);
   11801                 :             :   else
   11802                 :      549776 :     *t1 = TREE_TYPE (*t1);
   11803                 :      549776 :   if (TYPE_PTRDATAMEM_P (*t2))
   11804                 :           0 :     *t2 = TYPE_PTRMEM_POINTED_TO_TYPE (*t2);
   11805                 :             :   else
   11806                 :      549776 :     *t2 = TREE_TYPE (*t2);
   11807                 :             : 
   11808                 :      549776 :   casts_away_constness_r (t1, t2, complain);
   11809                 :      549776 :   *t1 = build_pointer_type (*t1);
   11810                 :      549776 :   *t2 = build_pointer_type (*t2);
   11811                 :      549776 :   *t1 = cp_build_qualified_type (*t1, quals1);
   11812                 :      549776 :   *t2 = cp_build_qualified_type (*t2, quals2);
   11813                 :             : }
   11814                 :             : 
   11815                 :             : /* Returns nonzero if casting from TYPE1 to TYPE2 casts away
   11816                 :             :    constness.  
   11817                 :             : 
   11818                 :             :    ??? This function returns non-zero if casting away qualifiers not
   11819                 :             :    just const.  We would like to return to the caller exactly which
   11820                 :             :    qualifiers are casted away to give more accurate diagnostics.
   11821                 :             : */
   11822                 :             : 
   11823                 :             : static bool
   11824                 :      549403 : casts_away_constness (tree t1, tree t2, tsubst_flags_t complain)
   11825                 :             : {
   11826                 :      549403 :   if (TYPE_REF_P (t2))
   11827                 :             :     {
   11828                 :             :       /* [expr.const.cast]
   11829                 :             : 
   11830                 :             :          Casting from an lvalue of type T1 to an lvalue of type T2
   11831                 :             :          using a reference cast casts away constness if a cast from an
   11832                 :             :          rvalue of type "pointer to T1" to the type "pointer to T2"
   11833                 :             :          casts away constness.  */
   11834                 :           0 :       t1 = (TYPE_REF_P (t1) ? TREE_TYPE (t1) : t1);
   11835                 :           0 :       return casts_away_constness (build_pointer_type (t1),
   11836                 :           0 :                                    build_pointer_type (TREE_TYPE (t2)),
   11837                 :           0 :                                    complain);
   11838                 :             :     }
   11839                 :             : 
   11840                 :      549403 :   if (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
   11841                 :             :     /* [expr.const.cast]
   11842                 :             : 
   11843                 :             :        Casting from an rvalue of type "pointer to data member of X
   11844                 :             :        of type T1" to the type "pointer to data member of Y of type
   11845                 :             :        T2" casts away constness if a cast from an rvalue of type
   11846                 :             :        "pointer to T1" to the type "pointer to T2" casts away
   11847                 :             :        constness.  */
   11848                 :          59 :     return casts_away_constness
   11849                 :          59 :       (build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t1)),
   11850                 :          59 :        build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t2)),
   11851                 :          59 :        complain);
   11852                 :             : 
   11853                 :             :   /* Casting away constness is only something that makes sense for
   11854                 :             :      pointer or reference types.  */
   11855                 :      549344 :   if (!TYPE_PTR_P (t1) || !TYPE_PTR_P (t2))
   11856                 :             :     return false;
   11857                 :             : 
   11858                 :             :   /* Top-level qualifiers don't matter.  */
   11859                 :      549316 :   t1 = TYPE_MAIN_VARIANT (t1);
   11860                 :      549316 :   t2 = TYPE_MAIN_VARIANT (t2);
   11861                 :      549316 :   casts_away_constness_r (&t1, &t2, complain);
   11862                 :      549316 :   if (!can_convert (t2, t1, complain))
   11863                 :             :     return true;
   11864                 :             : 
   11865                 :             :   return false;
   11866                 :             : }
   11867                 :             : 
   11868                 :             : /* If T is a REFERENCE_TYPE return the type to which T refers.
   11869                 :             :    Otherwise, return T itself.  */
   11870                 :             : 
   11871                 :             : tree
   11872                 :  2402932122 : non_reference (tree t)
   11873                 :             : {
   11874                 :  2402932122 :   if (t && TYPE_REF_P (t))
   11875                 :   239206368 :     t = TREE_TYPE (t);
   11876                 :  2402932122 :   return t;
   11877                 :             : }
   11878                 :             : 
   11879                 :             : 
   11880                 :             : /* Return nonzero if REF is an lvalue valid for this language;
   11881                 :             :    otherwise, print an error message and return zero.  USE says
   11882                 :             :    how the lvalue is being used and so selects the error message.  */
   11883                 :             : 
   11884                 :             : int
   11885                 :    34879243 : lvalue_or_else (tree ref, enum lvalue_use use, tsubst_flags_t complain)
   11886                 :             : {
   11887                 :    34879243 :   cp_lvalue_kind kind = lvalue_kind (ref);
   11888                 :             : 
   11889                 :    34879243 :   if (kind == clk_none)
   11890                 :             :     {
   11891                 :         137 :       if (complain & tf_error)
   11892                 :         130 :         lvalue_error (cp_expr_loc_or_input_loc (ref), use);
   11893                 :         137 :       return 0;
   11894                 :             :     }
   11895                 :    34879106 :   else if (kind & (clk_rvalueref|clk_class))
   11896                 :             :     {
   11897                 :         106 :       if (!(complain & tf_error))
   11898                 :             :         return 0;
   11899                 :             :       /* Make this a permerror because we used to accept it.  */
   11900                 :          20 :       permerror (cp_expr_loc_or_input_loc (ref),
   11901                 :             :                  "using rvalue as lvalue");
   11902                 :             :     }
   11903                 :             :   return 1;
   11904                 :             : }
   11905                 :             : 
   11906                 :             : /* Return true if a user-defined literal operator is a raw operator.  */
   11907                 :             : 
   11908                 :             : bool
   11909                 :      115185 : check_raw_literal_operator (const_tree decl)
   11910                 :             : {
   11911                 :      115185 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   11912                 :      115185 :   tree argtype;
   11913                 :      115185 :   int arity;
   11914                 :      115185 :   bool maybe_raw_p = false;
   11915                 :             : 
   11916                 :             :   /* Count the number and type of arguments and check for ellipsis.  */
   11917                 :      115185 :   for (argtype = argtypes, arity = 0;
   11918                 :      172794 :        argtype && argtype != void_list_node;
   11919                 :       57609 :        ++arity, argtype = TREE_CHAIN (argtype))
   11920                 :             :     {
   11921                 :       57609 :       tree t = TREE_VALUE (argtype);
   11922                 :             : 
   11923                 :       57609 :       if (same_type_p (t, const_string_type_node))
   11924                 :           9 :         maybe_raw_p = true;
   11925                 :             :     }
   11926                 :      115185 :   if (!argtype)
   11927                 :             :     return false; /* Found ellipsis.  */
   11928                 :             : 
   11929                 :      115185 :   if (!maybe_raw_p || arity != 1)
   11930                 :      115179 :     return false;
   11931                 :             : 
   11932                 :             :   return true;
   11933                 :             : }
   11934                 :             : 
   11935                 :             : 
   11936                 :             : /* Return true if a user-defined literal operator has one of the allowed
   11937                 :             :    argument types.  */
   11938                 :             : 
   11939                 :             : bool
   11940                 :      271474 : check_literal_operator_args (const_tree decl,
   11941                 :             :                              bool *long_long_unsigned_p, bool *long_double_p)
   11942                 :             : {
   11943                 :      271474 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   11944                 :             : 
   11945                 :      271474 :   *long_long_unsigned_p = false;
   11946                 :      271474 :   *long_double_p = false;
   11947                 :      271474 :   if (processing_template_decl || processing_specialization)
   11948                 :       57695 :     return argtypes == void_list_node;
   11949                 :             :   else
   11950                 :             :     {
   11951                 :             :       tree argtype;
   11952                 :             :       int arity;
   11953                 :             :       int max_arity = 2;
   11954                 :             : 
   11955                 :             :       /* Count the number and type of arguments and check for ellipsis.  */
   11956                 :      213702 :       for (argtype = argtypes, arity = 0;
   11957                 :      427481 :            argtype && argtype != void_list_node;
   11958                 :      213702 :            argtype = TREE_CHAIN (argtype))
   11959                 :             :         {
   11960                 :      213785 :           tree t = TREE_VALUE (argtype);
   11961                 :      213785 :           ++arity;
   11962                 :             : 
   11963                 :      213785 :           if (TYPE_PTR_P (t))
   11964                 :             :             {
   11965                 :       95921 :               bool maybe_raw_p = false;
   11966                 :       95921 :               t = TREE_TYPE (t);
   11967                 :       95921 :               if (cp_type_quals (t) != TYPE_QUAL_CONST)
   11968                 :             :                 return false;
   11969                 :       95918 :               t = TYPE_MAIN_VARIANT (t);
   11970                 :       95918 :               if ((maybe_raw_p = same_type_p (t, char_type_node))
   11971                 :       73013 :                   || same_type_p (t, wchar_type_node)
   11972                 :       50236 :                   || same_type_p (t, char8_type_node)
   11973                 :       45566 :                   || same_type_p (t, char16_type_node)
   11974                 :      118701 :                   || same_type_p (t, char32_type_node))
   11975                 :             :                 {
   11976                 :       95915 :                   argtype = TREE_CHAIN (argtype);
   11977                 :       95915 :                   if (!argtype)
   11978                 :             :                     return false;
   11979                 :       95915 :                   t = TREE_VALUE (argtype);
   11980                 :       95915 :                   if (maybe_raw_p && argtype == void_list_node)
   11981                 :             :                     return true;
   11982                 :       95859 :                   else if (same_type_p (t, size_type_node))
   11983                 :             :                     {
   11984                 :       95853 :                       ++arity;
   11985                 :       95853 :                       continue;
   11986                 :             :                     }
   11987                 :             :                   else
   11988                 :             :                     return false;
   11989                 :             :                 }
   11990                 :             :             }
   11991                 :      117864 :           else if (same_type_p (t, long_long_unsigned_type_node))
   11992                 :             :             {
   11993                 :       32002 :               max_arity = 1;
   11994                 :       32002 :               *long_long_unsigned_p = true;
   11995                 :             :             }
   11996                 :       85862 :           else if (same_type_p (t, long_double_type_node))
   11997                 :             :             {
   11998                 :       85763 :               max_arity = 1;
   11999                 :       85763 :               *long_double_p = true;
   12000                 :             :             }
   12001                 :          99 :           else if (same_type_p (t, char_type_node))
   12002                 :             :             max_arity = 1;
   12003                 :          55 :           else if (same_type_p (t, wchar_type_node))
   12004                 :             :             max_arity = 1;
   12005                 :          44 :           else if (same_type_p (t, char8_type_node))
   12006                 :             :             max_arity = 1;
   12007                 :          40 :           else if (same_type_p (t, char16_type_node))
   12008                 :             :             max_arity = 1;
   12009                 :          29 :           else if (same_type_p (t, char32_type_node))
   12010                 :             :             max_arity = 1;
   12011                 :             :           else
   12012                 :             :             return false;
   12013                 :             :         }
   12014                 :      213696 :       if (!argtype)
   12015                 :             :         return false; /* Found ellipsis.  */
   12016                 :             : 
   12017                 :      213693 :       if (arity != max_arity)
   12018                 :             :         return false;
   12019                 :             : 
   12020                 :             :       return true;
   12021                 :             :     }
   12022                 :             : }
   12023                 :             : 
   12024                 :             : /* Always returns false since unlike C90, C++ has no concept of implicit
   12025                 :             :    function declarations.  */
   12026                 :             : 
   12027                 :             : bool
   12028                 :         502 : c_decl_implicit (const_tree)
   12029                 :             : {
   12030                 :         502 :   return false;
   12031                 :             : }
        

Generated by: LCOV version 2.1-beta

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,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.