LCOV - code coverage report
Current view: top level - gcc/cp - typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 91.9 % 5360 4925
Test Date: 2024-09-07 14:08:43 Functions: 97.1 % 174 169
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 "c-family/c-type-mismatch.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                 :   101898534 : require_complete_type (tree value,
      75                 :             :                        tsubst_flags_t complain /* = tf_warning_or_error */)
      76                 :             : {
      77                 :   101898534 :   tree type;
      78                 :             : 
      79                 :   101898534 :   if (processing_template_decl || value == error_mark_node)
      80                 :             :     return value;
      81                 :             : 
      82                 :    94003200 :   if (TREE_CODE (value) == OVERLOAD)
      83                 :           0 :     type = unknown_type_node;
      84                 :             :   else
      85                 :    94003200 :     type = TREE_TYPE (value);
      86                 :             : 
      87                 :    94003200 :   if (type == error_mark_node)
      88                 :             :     return error_mark_node;
      89                 :             : 
      90                 :             :   /* First, detect a valid value with a complete type.  */
      91                 :    94003188 :   if (COMPLETE_TYPE_P (type))
      92                 :             :     return value;
      93                 :             : 
      94                 :       96702 :   if (complete_type_or_maybe_complain (type, value, complain))
      95                 :             :     return value;
      96                 :             :   else
      97                 :          92 :     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                 : 11362860340 : complete_type (tree type)
     107                 :             : {
     108                 : 11362860340 :   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                 : 11362860340 :   if (type == error_mark_node || COMPLETE_TYPE_P (type))
     114                 :             :     ;
     115                 :  3773563090 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     116                 :             :     {
     117                 :      547616 :       tree t = complete_type (TREE_TYPE (type));
     118                 :      547616 :       unsigned int needs_constructing, has_nontrivial_dtor;
     119                 :      547616 :       if (COMPLETE_TYPE_P (t) && !dependent_type_p (type))
     120                 :      547482 :         layout_type (type);
     121                 :      547616 :       needs_constructing
     122                 :      547616 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
     123                 :      547616 :       has_nontrivial_dtor
     124                 :      547616 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
     125                 :     1715648 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
     126                 :             :         {
     127                 :     1168032 :           TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
     128                 :     1168032 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
     129                 :             :         }
     130                 :             :     }
     131                 :  3773015474 :   else if (CLASS_TYPE_P (type))
     132                 :             :     {
     133                 :  3699227776 :       if (modules_p ())
     134                 :             :         /* TYPE could be a class member we've not loaded the definition of.  */ 
     135                 :    18955193 :         lazy_load_pendings (TYPE_NAME (TYPE_MAIN_VARIANT (type)));
     136                 :             : 
     137                 :  3699227776 :       if (CLASSTYPE_TEMPLATE_INSTANTIATION (type))
     138                 :   725210424 :         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                 :  1147467255 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
     150                 :             : {
     151                 :  1147467255 :   type = complete_type (type);
     152                 :  1147467252 :   if (type == error_mark_node)
     153                 :             :     /* We already issued an error.  */
     154                 :             :     return NULL_TREE;
     155                 :  1147467105 :   else if (!COMPLETE_TYPE_P (type))
     156                 :             :     {
     157                 :        3684 :       if (complain & tf_error)
     158                 :         494 :         cxx_incomplete_type_diagnostic (value, type, DK_ERROR);
     159                 :        3684 :       note_failed_type_completion_for_satisfaction (type);
     160                 :        3684 :       return NULL_TREE;
     161                 :             :     }
     162                 :             :   else
     163                 :             :     return type;
     164                 :             : }
     165                 :             : 
     166                 :             : tree
     167                 :   132522792 : complete_type_or_else (tree type, tree value)
     168                 :             : {
     169                 :   132522792 :   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                 :     3954952 : commonparms (tree p1, tree p2)
     182                 :             : {
     183                 :     3954952 :   tree oldargs = p1, newargs, n;
     184                 :     3954952 :   int i, len;
     185                 :     3954952 :   int any_change = 0;
     186                 :             : 
     187                 :     3954952 :   len = list_length (p1);
     188                 :     3954952 :   newargs = tree_last (p1);
     189                 :             : 
     190                 :     3954952 :   if (newargs == void_list_node)
     191                 :             :     i = 1;
     192                 :             :   else
     193                 :             :     {
     194                 :       38095 :       i = 0;
     195                 :       38095 :       newargs = 0;
     196                 :             :     }
     197                 :             : 
     198                 :    13431492 :   for (; i < len; i++)
     199                 :     9476540 :     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
     200                 :             : 
     201                 :             :   n = newargs;
     202                 :             : 
     203                 :    17348349 :   for (i = 0; p1;
     204                 :    13393397 :        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
     205                 :             :     {
     206                 :    13393571 :       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
     207                 :             :         {
     208                 :         147 :           TREE_PURPOSE (n) = TREE_PURPOSE (p1);
     209                 :         147 :           any_change = 1;
     210                 :             :         }
     211                 :    13393250 :       else if (! TREE_PURPOSE (p1))
     212                 :             :         {
     213                 :    13393223 :           if (TREE_PURPOSE (p2))
     214                 :             :             {
     215                 :      407629 :               TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     216                 :      407629 :               any_change = 1;
     217                 :             :             }
     218                 :             :         }
     219                 :             :       else
     220                 :             :         {
     221                 :          27 :           if (simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)) != 1)
     222                 :          27 :             any_change = 1;
     223                 :          27 :           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     224                 :             :         }
     225                 :    13393397 :       if (TREE_VALUE (p1) != TREE_VALUE (p2))
     226                 :             :         {
     227                 :     3731901 :           any_change = 1;
     228                 :     3731901 :           TREE_VALUE (n) = merge_types (TREE_VALUE (p1), TREE_VALUE (p2));
     229                 :             :         }
     230                 :             :       else
     231                 :     9661496 :         TREE_VALUE (n) = TREE_VALUE (p1);
     232                 :             :     }
     233                 :     3954952 :   if (! any_change)
     234                 :     1342054 :     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                 :    31800702 : original_type (tree t)
     243                 :             : {
     244                 :    31800702 :   int quals = cp_type_quals (t);
     245                 :    31800702 :   while (t != error_mark_node
     246                 :    32880367 :          && TYPE_NAME (t) != NULL_TREE)
     247                 :             :     {
     248                 :    11127485 :       tree x = TYPE_NAME (t);
     249                 :    11127485 :       if (TREE_CODE (x) != TYPE_DECL)
     250                 :             :         break;
     251                 :    11127485 :       x = DECL_ORIGINAL_TYPE (x);
     252                 :    11127485 :       if (x == NULL_TREE)
     253                 :             :         break;
     254                 :             :       t = x;
     255                 :             :     }
     256                 :    31800702 :   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                 :       49666 : merge_type_attributes_from (tree type, tree other_type)
     264                 :             : {
     265                 :       49666 :   tree attrs = targetm.merge_type_attributes (type, other_type);
     266                 :       49666 :   attrs = restrict_type_identity_attributes_to (attrs, TYPE_ATTRIBUTES (type));
     267                 :       49666 :   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                 :     8023124 : cp_compare_floating_point_conversion_ranks (tree t1, tree t2)
     280                 :             : {
     281                 :     8023124 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
     282                 :     8023124 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
     283                 :     8023124 :   int extended1 = 0;
     284                 :     8023124 :   int extended2 = 0;
     285                 :             : 
     286                 :     8023124 :   if (mv1 == mv2)
     287                 :             :     return 0;
     288                 :             : 
     289                 :    64178272 :   for (int i = 0; i < NUM_FLOATN_NX_TYPES; ++i)
     290                 :             :     {
     291                 :    56155988 :       if (mv1 == FLOATN_NX_TYPE_NODE (i))
     292                 :     3608275 :         extended1 = i + 1;
     293                 :    56155988 :       if (mv2 == FLOATN_NX_TYPE_NODE (i))
     294                 :     3023631 :         extended2 = i + 1;
     295                 :             :     }
     296                 :     8022284 :   if (mv1 == bfloat16_type_node)
     297                 :      832542 :     extended1 = true;
     298                 :     8022284 :   if (mv2 == bfloat16_type_node)
     299                 :      686412 :     extended2 = true;
     300                 :     8022284 :   if (extended2 && !extended1)
     301                 :             :     {
     302                 :     3551194 :       int ret = cp_compare_floating_point_conversion_ranks (t2, t1);
     303                 :     3551194 :       return ret == 3 ? 3 : -ret;
     304                 :             :     }
     305                 :             : 
     306                 :     4471090 :   const struct real_format *fmt1 = REAL_MODE_FORMAT (TYPE_MODE (t1));
     307                 :     4471090 :   const struct real_format *fmt2 = REAL_MODE_FORMAT (TYPE_MODE (t2));
     308                 :     4471090 :   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                 :    35768720 :   int p1 = (MODE_COMPOSITE_P (TYPE_MODE (t1))
     315                 :     8942180 :             ? fmt1->emax - fmt1->emin + fmt1->p - 1 : fmt1->p);
     316                 :    35768720 :   int p2 = (MODE_COMPOSITE_P (TYPE_MODE (t2))
     317                 :     8942180 :             ? 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                 :     4471090 :   if ((p1 > p2 && fmt1->emax >= fmt2->emax)
     322                 :     3372378 :        || (p1 == p2 && fmt1->emax > fmt2->emax))
     323                 :             :     return 2;
     324                 :     3372378 :   if ((p1 < p2 && fmt1->emax <= fmt2->emax)
     325                 :     1068266 :        || (p1 == p2 && fmt1->emax < fmt2->emax))
     326                 :             :     return -2;
     327                 :     1068266 :   if ((p1 > p2 && fmt1->emax < fmt2->emax)
     328                 :     1063031 :        || (p1 < p2 && fmt1->emax > fmt2->emax))
     329                 :             :     return 3;
     330                 :     1057796 :   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                 :     1057796 :   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                 :     4231168 :   for (p = &float_type_node; p <= &long_double_type_node; ++p)
     375                 :             :     {
     376                 :     3173376 :       const struct real_format *fmt3 = REAL_MODE_FORMAT (TYPE_MODE (*p));
     377                 :     3173376 :       gcc_assert (fmt3->b == 2);
     378                 :    25387008 :       int p3 = (MODE_COMPOSITE_P (TYPE_MODE (*p))
     379                 :     6346752 :                 ? fmt3->emax - fmt3->emin + fmt3->p - 1 : fmt3->p);
     380                 :     3173376 :       if (p1 == p3 && fmt1->emax == fmt3->emax)
     381                 :     1016625 :         ++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                 :     1057792 :   if (cnt > 1 && mv2 == long_double_type_node)
     395                 :             :     return -2;
     396                 :             :   /* And similarly if t2 is float, t2 has lower rank.  */
     397                 :           0 :   if (cnt > 1 && mv2 == float_type_node)
     398                 :             :     return 2;
     399                 :             :   /* Otherwise, they have equal rank, but extended types
     400                 :             :      (other than std::bfloat16_t) have higher subrank.
     401                 :             :      std::bfloat16_t shouldn't have equal rank to any standard
     402                 :             :      floating point type.  */
     403                 :             :   return 1;
     404                 :             : }
     405                 :             : 
     406                 :             : /* Return the common type for two arithmetic types T1 and T2 under the
     407                 :             :    usual arithmetic conversions.  The default conversions have already
     408                 :             :    been applied, and enumerated types converted to their compatible
     409                 :             :    integer types.  */
     410                 :             : 
     411                 :             : static tree
     412                 :    91372646 : cp_common_type (tree t1, tree t2)
     413                 :             : {
     414                 :    91372646 :   enum tree_code code1 = TREE_CODE (t1);
     415                 :    91372646 :   enum tree_code code2 = TREE_CODE (t2);
     416                 :    91372646 :   tree attributes;
     417                 :    91372646 :   int i;
     418                 :             : 
     419                 :             : 
     420                 :             :   /* In what follows, we slightly generalize the rules given in [expr] so
     421                 :             :      as to deal with `long long' and `complex'.  First, merge the
     422                 :             :      attributes.  */
     423                 :    91372646 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     424                 :             : 
     425                 :    91372646 :   if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
     426                 :             :     {
     427                 :      833593 :       if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     428                 :      833593 :         return build_type_attribute_variant (t1, attributes);
     429                 :             :       else
     430                 :             :         return NULL_TREE;
     431                 :             :     }
     432                 :             : 
     433                 :             :   /* FIXME: Attributes.  */
     434                 :    90539053 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     435                 :             :               || VECTOR_TYPE_P (t1)
     436                 :             :               || UNSCOPED_ENUM_P (t1));
     437                 :    90539053 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     438                 :             :               || VECTOR_TYPE_P (t2)
     439                 :             :               || UNSCOPED_ENUM_P (t2));
     440                 :             : 
     441                 :             :   /* If one type is complex, form the common type of the non-complex
     442                 :             :      components, then make that complex.  Use T1 or T2 if it is the
     443                 :             :      required type.  */
     444                 :    90539053 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     445                 :             :     {
     446                 :      222205 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
     447                 :      222205 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
     448                 :      222205 :       tree subtype
     449                 :      222205 :         = type_after_usual_arithmetic_conversions (subtype1, subtype2);
     450                 :             : 
     451                 :      222205 :       if (subtype == error_mark_node)
     452                 :             :         return subtype;
     453                 :      222205 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
     454                 :      188873 :         return build_type_attribute_variant (t1, attributes);
     455                 :       33332 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
     456                 :       33272 :         return build_type_attribute_variant (t2, attributes);
     457                 :             :       else
     458                 :          60 :         return build_type_attribute_variant (build_complex_type (subtype),
     459                 :          60 :                                              attributes);
     460                 :             :     }
     461                 :             : 
     462                 :    90316848 :   if (code1 == VECTOR_TYPE)
     463                 :             :     {
     464                 :             :       /* When we get here we should have two vectors of the same size.
     465                 :             :          Just prefer the unsigned one if present.  */
     466                 :       49666 :       if (TYPE_UNSIGNED (t1))
     467                 :       10913 :         return merge_type_attributes_from (t1, t2);
     468                 :             :       else
     469                 :       38753 :         return merge_type_attributes_from (t2, t1);
     470                 :             :     }
     471                 :             : 
     472                 :             :   /* If only one is real, use it as the result.  */
     473                 :    90267182 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     474                 :     1054568 :     return build_type_attribute_variant (t1, attributes);
     475                 :    89212614 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     476                 :      996050 :     return build_type_attribute_variant (t2, attributes);
     477                 :             : 
     478                 :    88216564 :   if (code1 == REAL_TYPE
     479                 :    88216564 :       && (extended_float_type_p (t1) || extended_float_type_p (t2)))
     480                 :             :     {
     481                 :      153416 :       tree mv1 = TYPE_MAIN_VARIANT (t1);
     482                 :      153416 :       tree mv2 = TYPE_MAIN_VARIANT (t2);
     483                 :      153416 :       if (mv1 == mv2)
     484                 :      150458 :         return build_type_attribute_variant (t1, attributes);
     485                 :             : 
     486                 :        2958 :       int cmpret = cp_compare_floating_point_conversion_ranks (mv1, mv2);
     487                 :        2958 :       if (cmpret == 3)
     488                 :           0 :         return error_mark_node;
     489                 :        2958 :       else if (cmpret >= 0)
     490                 :        2696 :         return build_type_attribute_variant (t1, attributes);
     491                 :             :       else
     492                 :         262 :         return build_type_attribute_variant (t2, attributes);
     493                 :             :     }
     494                 :             : 
     495                 :             :   /* Both real or both integers; use the one with greater precision.  */
     496                 :    88063148 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     497                 :    13664067 :     return build_type_attribute_variant (t1, attributes);
     498                 :    74399081 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
     499                 :     1428375 :     return build_type_attribute_variant (t2, attributes);
     500                 :             : 
     501                 :             :   /* The types are the same; no need to do anything fancy.  */
     502                 :    72970706 :   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     503                 :    67273988 :     return build_type_attribute_variant (t1, attributes);
     504                 :             : 
     505                 :     5696718 :   if (code1 != REAL_TYPE)
     506                 :             :     {
     507                 :             :       /* If one is unsigned long long, then convert the other to unsigned
     508                 :             :          long long.  */
     509                 :     5696715 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node)
     510                 :     5696715 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_unsigned_type_node))
     511                 :      127453 :         return build_type_attribute_variant (long_long_unsigned_type_node,
     512                 :      127453 :                                              attributes);
     513                 :             :       /* If one is a long long, and the other is an unsigned long, and
     514                 :             :          long long can represent all the values of an unsigned long, then
     515                 :             :          convert to a long long.  Otherwise, convert to an unsigned long
     516                 :             :          long.  Otherwise, if either operand is long long, convert the
     517                 :             :          other to long long.
     518                 :             : 
     519                 :             :          Since we're here, we know the TYPE_PRECISION is the same;
     520                 :             :          therefore converting to long long cannot represent all the values
     521                 :             :          of an unsigned long, so we choose unsigned long long in that
     522                 :             :          case.  */
     523                 :     5569262 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_integer_type_node)
     524                 :     5569262 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_integer_type_node))
     525                 :             :         {
     526                 :         571 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     527                 :         571 :                     ? long_long_unsigned_type_node
     528                 :         289 :                     : long_long_integer_type_node);
     529                 :         289 :           return build_type_attribute_variant (t, attributes);
     530                 :             :         }
     531                 :             : 
     532                 :             :       /* Go through the same procedure, but for longs.  */
     533                 :     5568973 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_unsigned_type_node)
     534                 :     5568973 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_unsigned_type_node))
     535                 :      664327 :         return build_type_attribute_variant (long_unsigned_type_node,
     536                 :      664327 :                                              attributes);
     537                 :     4904646 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_integer_type_node)
     538                 :     4904646 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_integer_type_node))
     539                 :             :         {
     540                 :       79589 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     541                 :       79589 :                     ? long_unsigned_type_node : long_integer_type_node);
     542                 :       40124 :           return build_type_attribute_variant (t, attributes);
     543                 :             :         }
     544                 :             : 
     545                 :             :       /* For __intN types, either the type is __int128 (and is lower
     546                 :             :          priority than the types checked above, but higher than other
     547                 :             :          128-bit types) or it's known to not be the same size as other
     548                 :             :          types (enforced in toplev.cc).  Prefer the unsigned type. */
     549                 :     9729002 :       for (i = 0; i < NUM_INT_N_ENTS; i ++)
     550                 :             :         {
     551                 :     4864522 :           if (int_n_enabled_p [i]
     552                 :     4864522 :               && (same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].signed_type)
     553                 :     4786318 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].signed_type)
     554                 :     4786306 :                   || same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].unsigned_type)
     555                 :     4786306 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].unsigned_type)))
     556                 :             :             {
     557                 :          72 :               tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     558                 :          72 :                         ? int_n_trees[i].unsigned_type
     559                 :          42 :                         : int_n_trees[i].signed_type);
     560                 :          42 :               return build_type_attribute_variant (t, attributes);
     561                 :             :             }
     562                 :             :         }
     563                 :             : 
     564                 :             :       /* Otherwise prefer the unsigned one.  */
     565                 :     4864480 :       if (TYPE_UNSIGNED (t1))
     566                 :     3885489 :         return build_type_attribute_variant (t1, attributes);
     567                 :             :       else
     568                 :      978991 :         return build_type_attribute_variant (t2, attributes);
     569                 :             :     }
     570                 :             :   else
     571                 :             :     {
     572                 :           3 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_double_type_node)
     573                 :           3 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_double_type_node))
     574                 :           0 :         return build_type_attribute_variant (long_double_type_node,
     575                 :           0 :                                              attributes);
     576                 :           3 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), double_type_node)
     577                 :           3 :           || same_type_p (TYPE_MAIN_VARIANT (t2), double_type_node))
     578                 :           3 :         return build_type_attribute_variant (double_type_node,
     579                 :           3 :                                              attributes);
     580                 :           0 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), float_type_node)
     581                 :           0 :           || same_type_p (TYPE_MAIN_VARIANT (t2), float_type_node))
     582                 :           0 :         return build_type_attribute_variant (float_type_node,
     583                 :           0 :                                              attributes);
     584                 :             : 
     585                 :             :       /* Two floating-point types whose TYPE_MAIN_VARIANTs are none of
     586                 :             :          the standard C++ floating-point types.  Logic earlier in this
     587                 :             :          function has already eliminated the possibility that
     588                 :             :          TYPE_PRECISION (t2) != TYPE_PRECISION (t1), so there's no
     589                 :             :          compelling reason to choose one or the other.  */
     590                 :           0 :       return build_type_attribute_variant (t1, attributes);
     591                 :             :     }
     592                 :             : }
     593                 :             : 
     594                 :             : /* T1 and T2 are arithmetic or enumeration types.  Return the type
     595                 :             :    that will result from the "usual arithmetic conversions" on T1 and
     596                 :             :    T2 as described in [expr].  */
     597                 :             : 
     598                 :             : tree
     599                 :      897242 : type_after_usual_arithmetic_conversions (tree t1, tree t2)
     600                 :             : {
     601                 :      897242 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     602                 :             :               || VECTOR_TYPE_P (t1)
     603                 :             :               || UNSCOPED_ENUM_P (t1));
     604                 :      897242 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     605                 :             :               || VECTOR_TYPE_P (t2)
     606                 :             :               || UNSCOPED_ENUM_P (t2));
     607                 :             : 
     608                 :             :   /* Perform the integral promotions.  We do not promote real types here.  */
     609                 :      897242 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (t1)
     610                 :      674574 :       && INTEGRAL_OR_ENUMERATION_TYPE_P (t2))
     611                 :             :     {
     612                 :      674215 :       t1 = type_promotes_to (t1);
     613                 :      674215 :       t2 = type_promotes_to (t2);
     614                 :             :     }
     615                 :             : 
     616                 :      897242 :   return cp_common_type (t1, t2);
     617                 :             : }
     618                 :             : 
     619                 :             : static void
     620                 :          42 : composite_pointer_error (const op_location_t &location,
     621                 :             :                          diagnostic_t kind, tree t1, tree t2,
     622                 :             :                          composite_pointer_operation operation)
     623                 :             : {
     624                 :          42 :   switch (operation)
     625                 :             :     {
     626                 :          33 :     case CPO_COMPARISON:
     627                 :          33 :       emit_diagnostic (kind, location, 0,
     628                 :             :                        "comparison between "
     629                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     630                 :             :                        t1, t2);
     631                 :          33 :       break;
     632                 :           0 :     case CPO_CONVERSION:
     633                 :           0 :       emit_diagnostic (kind, location, 0,
     634                 :             :                        "conversion between "
     635                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     636                 :             :                        t1, t2);
     637                 :           0 :       break;
     638                 :           9 :     case CPO_CONDITIONAL_EXPR:
     639                 :           9 :       emit_diagnostic (kind, location, 0,
     640                 :             :                        "conditional expression between "
     641                 :             :                        "distinct pointer types %qT and %qT lacks a cast",
     642                 :             :                        t1, t2);
     643                 :           9 :       break;
     644                 :           0 :     default:
     645                 :           0 :       gcc_unreachable ();
     646                 :             :     }
     647                 :          42 : }
     648                 :             : 
     649                 :             : /* Subroutine of composite_pointer_type to implement the recursive
     650                 :             :    case.  See that function for documentation of the parameters.  And ADD_CONST
     651                 :             :    is used to track adding "const" where needed.  */
     652                 :             : 
     653                 :             : static tree
     654                 :     3424724 : composite_pointer_type_r (const op_location_t &location,
     655                 :             :                           tree t1, tree t2, bool *add_const,
     656                 :             :                           composite_pointer_operation operation,
     657                 :             :                           tsubst_flags_t complain)
     658                 :             : {
     659                 :     3424724 :   tree pointee1;
     660                 :     3424724 :   tree pointee2;
     661                 :     3424724 :   tree result_type;
     662                 :     3424724 :   tree attributes;
     663                 :             : 
     664                 :             :   /* Determine the types pointed to by T1 and T2.  */
     665                 :     3424724 :   if (TYPE_PTR_P (t1))
     666                 :             :     {
     667                 :     3424261 :       pointee1 = TREE_TYPE (t1);
     668                 :     3424261 :       pointee2 = TREE_TYPE (t2);
     669                 :             :     }
     670                 :             :   else
     671                 :             :     {
     672                 :         463 :       pointee1 = TYPE_PTRMEM_POINTED_TO_TYPE (t1);
     673                 :         463 :       pointee2 = TYPE_PTRMEM_POINTED_TO_TYPE (t2);
     674                 :             :     }
     675                 :             : 
     676                 :             :   /* [expr.type]
     677                 :             : 
     678                 :             :      If T1 and T2 are similar types, the result is the cv-combined type of
     679                 :             :      T1 and T2.  */
     680                 :     3424724 :   if (same_type_ignoring_top_level_qualifiers_p (pointee1, pointee2))
     681                 :             :     result_type = pointee1;
     682                 :          33 :   else if ((TYPE_PTR_P (pointee1) && TYPE_PTR_P (pointee2))
     683                 :         150 :            || (TYPE_PTRMEM_P (pointee1) && TYPE_PTRMEM_P (pointee2)))
     684                 :             :     {
     685                 :          33 :       result_type = composite_pointer_type_r (location, pointee1, pointee2,
     686                 :             :                                               add_const, operation, complain);
     687                 :          33 :       if (result_type == error_mark_node)
     688                 :             :         return error_mark_node;
     689                 :             :     }
     690                 :             :   else
     691                 :             :     {
     692                 :         117 :       if (complain & tf_error)
     693                 :          30 :         composite_pointer_error (location, DK_PERMERROR,
     694                 :             :                                  t1, t2, operation);
     695                 :             :       else
     696                 :          87 :         return error_mark_node;
     697                 :          30 :       result_type = void_type_node;
     698                 :             :     }
     699                 :     3424631 :   const int q1 = cp_type_quals (pointee1);
     700                 :     3424631 :   const int q2 = cp_type_quals (pointee2);
     701                 :     3424631 :   const int quals = q1 | q2;
     702                 :     3424631 :   result_type = cp_build_qualified_type (result_type,
     703                 :     3424631 :                                          (quals | (*add_const
     704                 :     3424631 :                                                    ? TYPE_QUAL_CONST
     705                 :             :                                                    : TYPE_UNQUALIFIED)));
     706                 :             :   /* The cv-combined type can add "const" as per [conv.qual]/3.3 (except for
     707                 :             :      the TLQ).  The reason is that both T1 and T2 can then be converted to the
     708                 :             :      cv-combined type of T1 and T2.  */
     709                 :     3424631 :   if (quals != q1 || quals != q2)
     710                 :      536484 :     *add_const = true;
     711                 :             :   /* If the original types were pointers to members, so is the
     712                 :             :      result.  */
     713                 :     3424631 :   if (TYPE_PTRMEM_P (t1))
     714                 :             :     {
     715                 :         453 :       if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     716                 :             :                         TYPE_PTRMEM_CLASS_TYPE (t2)))
     717                 :             :         {
     718                 :           0 :           if (complain & tf_error)
     719                 :           0 :             composite_pointer_error (location, DK_PERMERROR,
     720                 :             :                                      t1, t2, operation);
     721                 :             :           else
     722                 :           0 :             return error_mark_node;
     723                 :             :         }
     724                 :         453 :       result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
     725                 :             :                                        result_type);
     726                 :             :     }
     727                 :             :   else
     728                 :     3424178 :     result_type = build_pointer_type (result_type);
     729                 :             : 
     730                 :             :   /* Merge the attributes.  */
     731                 :     3424631 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     732                 :     3424631 :   return build_type_attribute_variant (result_type, attributes);
     733                 :             : }
     734                 :             : 
     735                 :             : /* Return the composite pointer type (see [expr.type]) for T1 and T2.
     736                 :             :    ARG1 and ARG2 are the values with those types.  The OPERATION is to
     737                 :             :    describe the operation between the pointer types,
     738                 :             :    in case an error occurs.
     739                 :             : 
     740                 :             :    This routine also implements the computation of a common type for
     741                 :             :    pointers-to-members as per [expr.eq].  */
     742                 :             : 
     743                 :             : tree
     744                 :     3568588 : composite_pointer_type (const op_location_t &location,
     745                 :             :                         tree t1, tree t2, tree arg1, tree arg2,
     746                 :             :                         composite_pointer_operation operation, 
     747                 :             :                         tsubst_flags_t complain)
     748                 :             : {
     749                 :     3568588 :   tree class1;
     750                 :     3568588 :   tree class2;
     751                 :             : 
     752                 :             :   /* [expr.type]
     753                 :             : 
     754                 :             :      If one operand is a null pointer constant, the composite pointer
     755                 :             :      type is the type of the other operand.  */
     756                 :     3568588 :   if (null_ptr_cst_p (arg1))
     757                 :             :     return t2;
     758                 :     3568230 :   if (null_ptr_cst_p (arg2))
     759                 :             :     return t1;
     760                 :             : 
     761                 :             :   /* We have:
     762                 :             : 
     763                 :             :        [expr.type]
     764                 :             : 
     765                 :             :        If one of the operands has type "pointer to cv1 void", then
     766                 :             :        the other has type "pointer to cv2 T", and the composite pointer
     767                 :             :        type is "pointer to cv12 void", where cv12 is the union of cv1
     768                 :             :        and cv2.
     769                 :             : 
     770                 :             :     If either type is a pointer to void, make sure it is T1.  */
     771                 :     3556168 :   if (TYPE_PTR_P (t2) && VOID_TYPE_P (TREE_TYPE (t2)))
     772                 :             :     std::swap (t1, t2);
     773                 :             : 
     774                 :             :   /* Now, if T1 is a pointer to void, merge the qualifiers.  */
     775                 :     3556168 :   if (TYPE_PTR_P (t1) && VOID_TYPE_P (TREE_TYPE (t1)))
     776                 :             :     {
     777                 :      131276 :       tree attributes;
     778                 :      131276 :       tree result_type;
     779                 :             : 
     780                 :      131276 :       if (TYPE_PTRFN_P (t2))
     781                 :             :         {
     782                 :          10 :           if (complain & tf_error)
     783                 :             :             {
     784                 :           9 :               switch (operation)
     785                 :             :                 {
     786                 :           9 :                 case CPO_COMPARISON:
     787                 :           9 :                   pedwarn (location, OPT_Wpedantic, 
     788                 :             :                            "ISO C++ forbids comparison between pointer "
     789                 :             :                            "of type %<void *%> and pointer-to-function");
     790                 :           9 :                   break;
     791                 :           0 :                 case CPO_CONVERSION:
     792                 :           0 :                   pedwarn (location, OPT_Wpedantic,
     793                 :             :                            "ISO C++ forbids conversion between pointer "
     794                 :             :                            "of type %<void *%> and pointer-to-function");
     795                 :           0 :                   break;
     796                 :           0 :                 case CPO_CONDITIONAL_EXPR:
     797                 :           0 :                   pedwarn (location, OPT_Wpedantic,
     798                 :             :                            "ISO C++ forbids conditional expression between "
     799                 :             :                            "pointer of type %<void *%> and "
     800                 :             :                            "pointer-to-function");
     801                 :           0 :                   break;
     802                 :           0 :                 default:
     803                 :           0 :                   gcc_unreachable ();
     804                 :             :                 }
     805                 :             :             }
     806                 :             :           else
     807                 :           1 :             return error_mark_node;
     808                 :             :         }
     809                 :      131275 :       result_type
     810                 :      131275 :         = cp_build_qualified_type (void_type_node,
     811                 :      131275 :                                    (cp_type_quals (TREE_TYPE (t1))
     812                 :      131275 :                                     | cp_type_quals (TREE_TYPE (t2))));
     813                 :      131275 :       result_type = build_pointer_type (result_type);
     814                 :             :       /* Merge the attributes.  */
     815                 :      131275 :       attributes = (*targetm.merge_type_attributes) (t1, t2);
     816                 :      131275 :       return build_type_attribute_variant (result_type, attributes);
     817                 :             :     }
     818                 :             : 
     819                 :     3424892 :   if (c_dialect_objc () && TYPE_PTR_P (t1)
     820                 :           0 :       && TYPE_PTR_P (t2))
     821                 :             :     {
     822                 :           0 :       if (objc_have_common_type (t1, t2, -3, NULL_TREE))
     823                 :           0 :         return objc_common_type (t1, t2);
     824                 :             :     }
     825                 :             : 
     826                 :             :   /* if T1 or T2 is "pointer to noexcept function" and the other type is
     827                 :             :      "pointer to function", where the function types are otherwise the same,
     828                 :             :      "pointer to function" */
     829                 :     3424892 :   if (fnptr_conv_p (t1, t2))
     830                 :             :     return t1;
     831                 :     3424806 :   if (fnptr_conv_p (t2, t1))
     832                 :             :     return t2;
     833                 :             : 
     834                 :             :   /* [expr.eq] permits the application of a pointer conversion to
     835                 :             :      bring the pointers to a common type.  */
     836                 :     3424246 :   if (TYPE_PTR_P (t1) && TYPE_PTR_P (t2)
     837                 :     3424246 :       && CLASS_TYPE_P (TREE_TYPE (t1))
     838                 :      657404 :       && CLASS_TYPE_P (TREE_TYPE (t2))
     839                 :     4082125 :       && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t1),
     840                 :      657401 :                                                      TREE_TYPE (t2)))
     841                 :             :     {
     842                 :       40193 :       class1 = TREE_TYPE (t1);
     843                 :       40193 :       class2 = TREE_TYPE (t2);
     844                 :             : 
     845                 :       40193 :       if (DERIVED_FROM_P (class1, class2))
     846                 :       22674 :         t2 = (build_pointer_type
     847                 :       11337 :               (cp_build_qualified_type (class1, cp_type_quals (class2))));
     848                 :       28856 :       else if (DERIVED_FROM_P (class2, class1))
     849                 :       57676 :         t1 = (build_pointer_type
     850                 :       28838 :               (cp_build_qualified_type (class2, cp_type_quals (class1))));
     851                 :             :       else
     852                 :             :         {
     853                 :          18 :           if (complain & tf_error)
     854                 :          12 :             composite_pointer_error (location, DK_ERROR, t1, t2, operation);
     855                 :          18 :           return error_mark_node;
     856                 :             :         }
     857                 :             :     }
     858                 :             :   /* [expr.eq] permits the application of a pointer-to-member
     859                 :             :      conversion to change the class type of one of the types.  */
     860                 :     3384145 :   else if (TYPE_PTRMEM_P (t1)
     861                 :     3384623 :            && !same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     862                 :             :                             TYPE_PTRMEM_CLASS_TYPE (t2)))
     863                 :             :     {
     864                 :          46 :       class1 = TYPE_PTRMEM_CLASS_TYPE (t1);
     865                 :          46 :       class2 = TYPE_PTRMEM_CLASS_TYPE (t2);
     866                 :             : 
     867                 :          46 :       if (DERIVED_FROM_P (class1, class2))
     868                 :          21 :         t1 = build_ptrmem_type (class2, TYPE_PTRMEM_POINTED_TO_TYPE (t1));
     869                 :          25 :       else if (DERIVED_FROM_P (class2, class1))
     870                 :          10 :         t2 = build_ptrmem_type (class1, TYPE_PTRMEM_POINTED_TO_TYPE (t2));
     871                 :             :       else
     872                 :             :         {
     873                 :          15 :           if (complain & tf_error)
     874                 :           3 :             switch (operation)
     875                 :             :               {
     876                 :           3 :               case CPO_COMPARISON:
     877                 :           3 :                 error_at (location, "comparison between distinct "
     878                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     879                 :             :                           t1, t2);
     880                 :           3 :                 break;
     881                 :           0 :               case CPO_CONVERSION:
     882                 :           0 :                 error_at (location, "conversion between distinct "
     883                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     884                 :             :                           t1, t2);
     885                 :           0 :                 break;
     886                 :           0 :               case CPO_CONDITIONAL_EXPR:
     887                 :           0 :                 error_at (location, "conditional expression between distinct "
     888                 :             :                           "pointer-to-member types %qT and %qT lacks a cast",
     889                 :             :                           t1, t2);
     890                 :           0 :                 break;
     891                 :           0 :               default:
     892                 :           0 :                 gcc_unreachable ();
     893                 :             :               }
     894                 :          15 :           return error_mark_node;
     895                 :             :         }
     896                 :             :     }
     897                 :             : 
     898                 :     3424691 :   bool add_const = false;
     899                 :     3424691 :   return composite_pointer_type_r (location, t1, t2, &add_const, operation,
     900                 :     3424691 :                                    complain);
     901                 :             : }
     902                 :             : 
     903                 :             : /* Return the merged type of two types.
     904                 :             :    We assume that comptypes has already been done and returned 1;
     905                 :             :    if that isn't so, this may crash.
     906                 :             : 
     907                 :             :    This just combines attributes and default arguments; any other
     908                 :             :    differences would cause the two types to compare unalike.  */
     909                 :             : 
     910                 :             : tree
     911                 :    27889146 : merge_types (tree t1, tree t2)
     912                 :             : {
     913                 :    27889146 :   enum tree_code code1;
     914                 :    27889146 :   enum tree_code code2;
     915                 :    27889146 :   tree attributes;
     916                 :             : 
     917                 :             :   /* Save time if the two types are the same.  */
     918                 :    27889146 :   if (t1 == t2)
     919                 :             :     return t1;
     920                 :    15900351 :   if (original_type (t1) == original_type (t2))
     921                 :             :     return t1;
     922                 :             : 
     923                 :             :   /* If one type is nonsense, use the other.  */
     924                 :    15842314 :   if (t1 == error_mark_node)
     925                 :             :     return t2;
     926                 :    15842314 :   if (t2 == error_mark_node)
     927                 :             :     return t1;
     928                 :             : 
     929                 :             :   /* Handle merging an auto redeclaration with a previous deduced
     930                 :             :      return type.  */
     931                 :    15842314 :   if (is_auto (t1))
     932                 :             :     return t2;
     933                 :             : 
     934                 :             :   /* Merge the attributes.  */
     935                 :    15832922 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     936                 :             : 
     937                 :    15832922 :   if (TYPE_PTRMEMFUNC_P (t1))
     938                 :          15 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
     939                 :    15832922 :   if (TYPE_PTRMEMFUNC_P (t2))
     940                 :          15 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
     941                 :             : 
     942                 :    15832922 :   code1 = TREE_CODE (t1);
     943                 :    15832922 :   code2 = TREE_CODE (t2);
     944                 :    15832922 :   if (code1 != code2)
     945                 :             :     {
     946                 :           0 :       gcc_assert (code1 == TYPENAME_TYPE || code2 == TYPENAME_TYPE);
     947                 :           0 :       if (code1 == TYPENAME_TYPE)
     948                 :             :         {
     949                 :           0 :           t1 = resolve_typename_type (t1, /*only_current_p=*/true);
     950                 :           0 :           code1 = TREE_CODE (t1);
     951                 :             :         }
     952                 :             :       else
     953                 :             :         {
     954                 :           0 :           t2 = resolve_typename_type (t2, /*only_current_p=*/true);
     955                 :           0 :           code2 = TREE_CODE (t2);
     956                 :             :         }
     957                 :             :     }
     958                 :             : 
     959                 :    15832922 :   switch (code1)
     960                 :             :     {
     961                 :     2730679 :     case POINTER_TYPE:
     962                 :     2730679 :     case REFERENCE_TYPE:
     963                 :             :       /* For two pointers, do this recursively on the target type.  */
     964                 :     2730679 :       {
     965                 :     2730679 :         tree target = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     966                 :     2730679 :         int quals = cp_type_quals (t1);
     967                 :             : 
     968                 :     2730679 :         if (code1 == POINTER_TYPE)
     969                 :             :           {
     970                 :      705463 :             t1 = build_pointer_type (target);
     971                 :      705463 :             if (TREE_CODE (target) == METHOD_TYPE)
     972                 :          15 :               t1 = build_ptrmemfunc_type (t1);
     973                 :             :           }
     974                 :             :         else
     975                 :     2025216 :           t1 = cp_build_reference_type (target, TYPE_REF_IS_RVALUE (t1));
     976                 :     2730679 :         t1 = build_type_attribute_variant (t1, attributes);
     977                 :     2730679 :         t1 = cp_build_qualified_type (t1, quals);
     978                 :             : 
     979                 :     2730679 :         return t1;
     980                 :             :       }
     981                 :             : 
     982                 :          12 :     case OFFSET_TYPE:
     983                 :          12 :       {
     984                 :          12 :         int quals;
     985                 :          12 :         tree pointee;
     986                 :          12 :         quals = cp_type_quals (t1);
     987                 :          12 :         pointee = merge_types (TYPE_PTRMEM_POINTED_TO_TYPE (t1),
     988                 :          12 :                                TYPE_PTRMEM_POINTED_TO_TYPE (t2));
     989                 :          12 :         t1 = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
     990                 :             :                                 pointee);
     991                 :          12 :         t1 = cp_build_qualified_type (t1, quals);
     992                 :          12 :         break;
     993                 :             :       }
     994                 :             : 
     995                 :       10547 :     case ARRAY_TYPE:
     996                 :       10547 :       {
     997                 :       10547 :         tree elt = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     998                 :             :         /* Save space: see if the result is identical to one of the args.  */
     999                 :       21094 :         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
    1000                 :       10525 :           return build_type_attribute_variant (t1, attributes);
    1001                 :          38 :         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
    1002                 :          16 :           return build_type_attribute_variant (t2, attributes);
    1003                 :             :         /* Merge the element types, and have a size if either arg has one.  */
    1004                 :           6 :         t1 = build_cplus_array_type
    1005                 :           6 :           (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
    1006                 :           6 :         break;
    1007                 :             :       }
    1008                 :             : 
    1009                 :     4094766 :     case FUNCTION_TYPE:
    1010                 :             :       /* Function types: prefer the one that specified arg types.
    1011                 :             :          If both do, merge the arg types.  Also merge the return types.  */
    1012                 :     4094766 :       {
    1013                 :     4094766 :         tree valtype = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1014                 :     4094766 :         tree p1 = TYPE_ARG_TYPES (t1);
    1015                 :     4094766 :         tree p2 = TYPE_ARG_TYPES (t2);
    1016                 :     4094766 :         tree parms;
    1017                 :             : 
    1018                 :             :         /* Save space: see if the result is identical to one of the args.  */
    1019                 :     4094766 :         if (valtype == TREE_TYPE (t1) && ! p2)
    1020                 :           0 :           return cp_build_type_attribute_variant (t1, attributes);
    1021                 :     4094766 :         if (valtype == TREE_TYPE (t2) && ! p1)
    1022                 :           0 :           return cp_build_type_attribute_variant (t2, attributes);
    1023                 :             : 
    1024                 :             :         /* Simple way if one arg fails to specify argument types.  */
    1025                 :     8189532 :         if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
    1026                 :             :           parms = p2;
    1027                 :     7909904 :         else if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
    1028                 :             :           parms = p1;
    1029                 :             :         else
    1030                 :     3954952 :           parms = commonparms (p1, p2);
    1031                 :             : 
    1032                 :     4094766 :         cp_cv_quals quals = type_memfn_quals (t1);
    1033                 :     4094766 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1034                 :     4094766 :         gcc_assert (quals == type_memfn_quals (t2));
    1035                 :     4094766 :         gcc_assert (rqual == type_memfn_rqual (t2));
    1036                 :             : 
    1037                 :     4094766 :         tree rval = build_function_type (valtype, parms);
    1038                 :     4094766 :         rval = apply_memfn_quals (rval, quals);
    1039                 :     4094766 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1040                 :     4094766 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1041                 :     4094766 :         bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1042                 :     4094766 :         t1 = build_cp_fntype_variant (rval, rqual, raises, late_return_type_p);
    1043                 :     4094766 :         break;
    1044                 :             :       }
    1045                 :             : 
    1046                 :     3857529 :     case METHOD_TYPE:
    1047                 :     3857529 :       {
    1048                 :             :         /* Get this value the long way, since TYPE_METHOD_BASETYPE
    1049                 :             :            is just the main variant of this.  */
    1050                 :     3857529 :         tree basetype = class_of_this_parm (t2);
    1051                 :     3857529 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1052                 :     3857529 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1053                 :     3857529 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1054                 :     3857529 :         tree t3;
    1055                 :     3857529 :         bool late_return_type_1_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1056                 :             : 
    1057                 :             :         /* If this was a member function type, get back to the
    1058                 :             :            original type of type member function (i.e., without
    1059                 :             :            the class instance variable up front.  */
    1060                 :     3857529 :         t1 = build_function_type (TREE_TYPE (t1),
    1061                 :     3857529 :                                   TREE_CHAIN (TYPE_ARG_TYPES (t1)));
    1062                 :     3857529 :         t2 = build_function_type (TREE_TYPE (t2),
    1063                 :     3857529 :                                   TREE_CHAIN (TYPE_ARG_TYPES (t2)));
    1064                 :     3857529 :         t3 = merge_types (t1, t2);
    1065                 :     3857529 :         t3 = build_method_type_directly (basetype, TREE_TYPE (t3),
    1066                 :     3857529 :                                          TYPE_ARG_TYPES (t3));
    1067                 :     3857529 :         t1 = build_cp_fntype_variant (t3, rqual, raises, late_return_type_1_p);
    1068                 :     3857529 :         break;
    1069                 :             :       }
    1070                 :             : 
    1071                 :             :     case TYPENAME_TYPE:
    1072                 :             :       /* There is no need to merge attributes into a TYPENAME_TYPE.
    1073                 :             :          When the type is instantiated it will have whatever
    1074                 :             :          attributes result from the instantiation.  */
    1075                 :             :       return t1;
    1076                 :             : 
    1077                 :     5130033 :     default:;
    1078                 :     5130033 :       if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1079                 :             :         return t1;
    1080                 :          12 :       else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1081                 :             :         return t2;
    1082                 :             :       break;
    1083                 :             :     }
    1084                 :             : 
    1085                 :     7952313 :   return cp_build_type_attribute_variant (t1, attributes);
    1086                 :             : }
    1087                 :             : 
    1088                 :             : /* Return the ARRAY_TYPE type without its domain.  */
    1089                 :             : 
    1090                 :             : tree
    1091                 :         224 : strip_array_domain (tree type)
    1092                 :             : {
    1093                 :         224 :   tree t2;
    1094                 :         224 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1095                 :         224 :   if (TYPE_DOMAIN (type) == NULL_TREE)
    1096                 :             :     return type;
    1097                 :         205 :   t2 = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
    1098                 :         205 :   return cp_build_type_attribute_variant (t2, TYPE_ATTRIBUTES (type));
    1099                 :             : }
    1100                 :             : 
    1101                 :             : /* Wrapper around cp_common_type that is used by c-common.cc and other
    1102                 :             :    front end optimizations that remove promotions.  
    1103                 :             : 
    1104                 :             :    Return the common type for two arithmetic types T1 and T2 under the
    1105                 :             :    usual arithmetic conversions.  The default conversions have already
    1106                 :             :    been applied, and enumerated types converted to their compatible
    1107                 :             :    integer types.  */
    1108                 :             : 
    1109                 :             : tree
    1110                 :      388438 : common_type (tree t1, tree t2)
    1111                 :             : {
    1112                 :             :   /* If one type is nonsense, use the other  */
    1113                 :      388438 :   if (t1 == error_mark_node)
    1114                 :             :     return t2;
    1115                 :      388438 :   if (t2 == error_mark_node)
    1116                 :             :     return t1;
    1117                 :             : 
    1118                 :      388438 :   return cp_common_type (t1, t2);
    1119                 :             : }
    1120                 :             : 
    1121                 :             : /* Return the common type of two pointer types T1 and T2.  This is the
    1122                 :             :    type for the result of most arithmetic operations if the operands
    1123                 :             :    have the given two types.
    1124                 :             :  
    1125                 :             :    We assume that comp_target_types has already been done and returned
    1126                 :             :    nonzero; if that isn't so, this may crash.  */
    1127                 :             : 
    1128                 :             : tree
    1129                 :     1183737 : common_pointer_type (tree t1, tree t2)
    1130                 :             : {
    1131                 :     1183737 :   gcc_assert ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
    1132                 :             :               || (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
    1133                 :             :               || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)));
    1134                 :             : 
    1135                 :     1183737 :   return composite_pointer_type (input_location, t1, t2,
    1136                 :             :                                  error_mark_node, error_mark_node,
    1137                 :     1183737 :                                  CPO_CONVERSION, tf_warning_or_error);
    1138                 :             : }
    1139                 :             : 
    1140                 :             : /* Compare two exception specifier types for exactness or subsetness, if
    1141                 :             :    allowed. Returns false for mismatch, true for match (same, or
    1142                 :             :    derived and !exact).
    1143                 :             : 
    1144                 :             :    [except.spec] "If a class X ... objects of class X or any class publicly
    1145                 :             :    and unambiguously derived from X. Similarly, if a pointer type Y * ...
    1146                 :             :    exceptions of type Y * or that are pointers to any type publicly and
    1147                 :             :    unambiguously derived from Y. Otherwise a function only allows exceptions
    1148                 :             :    that have the same type ..."
    1149                 :             :    This does not mention cv qualifiers and is different to what throw
    1150                 :             :    [except.throw] and catch [except.catch] will do. They will ignore the
    1151                 :             :    top level cv qualifiers, and allow qualifiers in the pointer to class
    1152                 :             :    example.
    1153                 :             : 
    1154                 :             :    We implement the letter of the standard.  */
    1155                 :             : 
    1156                 :             : static bool
    1157                 :        1753 : comp_except_types (tree a, tree b, bool exact)
    1158                 :             : {
    1159                 :        1753 :   if (same_type_p (a, b))
    1160                 :             :     return true;
    1161                 :         508 :   else if (!exact)
    1162                 :             :     {
    1163                 :          12 :       if (cp_type_quals (a) || cp_type_quals (b))
    1164                 :           0 :         return false;
    1165                 :             : 
    1166                 :          12 :       if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
    1167                 :             :         {
    1168                 :           7 :           a = TREE_TYPE (a);
    1169                 :           7 :           b = TREE_TYPE (b);
    1170                 :           7 :           if (cp_type_quals (a) || cp_type_quals (b))
    1171                 :           1 :             return false;
    1172                 :             :         }
    1173                 :             : 
    1174                 :          11 :       if (TREE_CODE (a) != RECORD_TYPE
    1175                 :          11 :           || TREE_CODE (b) != RECORD_TYPE)
    1176                 :             :         return false;
    1177                 :             : 
    1178                 :          10 :       if (publicly_uniquely_derived_p (a, b))
    1179                 :             :         return true;
    1180                 :             :     }
    1181                 :             :   return false;
    1182                 :             : }
    1183                 :             : 
    1184                 :             : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
    1185                 :             :    If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
    1186                 :             :    If EXACT is ce_type, the C++17 type compatibility rules apply.
    1187                 :             :    If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
    1188                 :             :    If EXACT is ce_exact, the specs must be exactly the same. Exception lists
    1189                 :             :    are unordered, but we've already filtered out duplicates. Most lists will
    1190                 :             :    be in order, we should try to make use of that.  */
    1191                 :             : 
    1192                 :             : bool
    1193                 :  1323005082 : comp_except_specs (const_tree t1, const_tree t2, int exact)
    1194                 :             : {
    1195                 :  1323005082 :   const_tree probe;
    1196                 :  1323005082 :   const_tree base;
    1197                 :  1323005082 :   int  length = 0;
    1198                 :             : 
    1199                 :  1323005082 :   if (t1 == t2)
    1200                 :             :     return true;
    1201                 :             : 
    1202                 :             :   /* First handle noexcept.  */
    1203                 :   517399832 :   if (exact < ce_exact)
    1204                 :             :     {
    1205                 :     7177770 :       if (exact == ce_type
    1206                 :    14286576 :           && (canonical_eh_spec (CONST_CAST_TREE (t1))
    1207                 :     7108806 :               == canonical_eh_spec (CONST_CAST_TREE (t2))))
    1208                 :             :         return true;
    1209                 :             : 
    1210                 :             :       /* noexcept(false) is compatible with no exception-specification,
    1211                 :             :          and less strict than any spec.  */
    1212                 :     7171462 :       if (t1 == noexcept_false_spec)
    1213                 :         102 :         return t2 == NULL_TREE || exact == ce_derived;
    1214                 :             :       /* Even a derived noexcept(false) is compatible with no
    1215                 :             :          exception-specification.  */
    1216                 :     7171360 :       if (t2 == noexcept_false_spec)
    1217                 :        1172 :         return t1 == NULL_TREE;
    1218                 :             : 
    1219                 :             :       /* Otherwise, if we aren't looking for an exact match, noexcept is
    1220                 :             :          equivalent to throw().  */
    1221                 :     7170188 :       if (t1 == noexcept_true_spec)
    1222                 :      654517 :         t1 = empty_except_spec;
    1223                 :     7170188 :       if (t2 == noexcept_true_spec)
    1224                 :     6223580 :         t2 = empty_except_spec;
    1225                 :             :     }
    1226                 :             : 
    1227                 :             :   /* If any noexcept is left, it is only comparable to itself;
    1228                 :             :      either we're looking for an exact match or we're redeclaring a
    1229                 :             :      template with dependent noexcept.  */
    1230                 :   496321719 :   if ((t1 && TREE_PURPOSE (t1))
    1231                 :   541254218 :       || (t2 && TREE_PURPOSE (t2)))
    1232                 :   508211669 :     return (t1 && t2
    1233                 :   508211669 :             && (exact == ce_exact
    1234                 :    57160478 :                 ? TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
    1235                 :      289225 :                 : cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))));
    1236                 :             : 
    1237                 :     9180581 :   if (t1 == NULL_TREE)                     /* T1 is ...  */
    1238                 :     6449796 :     return t2 == NULL_TREE || exact == ce_derived;
    1239                 :     2730785 :   if (!TREE_VALUE (t1))                    /* t1 is EMPTY */
    1240                 :     2698144 :     return t2 != NULL_TREE && !TREE_VALUE (t2);
    1241                 :       33929 :   if (t2 == NULL_TREE)                     /* T2 is ...  */
    1242                 :             :     return false;
    1243                 :        1630 :   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
    1244                 :          75 :     return exact == ce_derived;
    1245                 :             : 
    1246                 :             :   /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
    1247                 :             :      Count how many we find, to determine exactness. For exact matching and
    1248                 :             :      ordered T1, T2, this is an O(n) operation, otherwise its worst case is
    1249                 :             :      O(nm).  */
    1250                 :        2803 :   for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
    1251                 :             :     {
    1252                 :        2150 :       for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
    1253                 :             :         {
    1254                 :        1753 :           tree a = TREE_VALUE (probe);
    1255                 :        1753 :           tree b = TREE_VALUE (t2);
    1256                 :             : 
    1257                 :        1753 :           if (comp_except_types (a, b, exact))
    1258                 :             :             {
    1259                 :        1248 :               if (probe == base && exact > ce_derived)
    1260                 :        1213 :                 base = TREE_CHAIN (probe);
    1261                 :        1248 :               length++;
    1262                 :        1248 :               break;
    1263                 :             :             }
    1264                 :             :         }
    1265                 :        1645 :       if (probe == NULL_TREE)
    1266                 :             :         return false;
    1267                 :             :     }
    1268                 :        1158 :   return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
    1269                 :             : }
    1270                 :             : 
    1271                 :             : /* Compare the array types T1 and T2.  CB says how we should behave when
    1272                 :             :    comparing array bounds: bounds_none doesn't allow dimensionless arrays,
    1273                 :             :    bounds_either says than any array can be [], bounds_first means that
    1274                 :             :    onlt T1 can be an array with unknown bounds.  STRICT is true if
    1275                 :             :    qualifiers must match when comparing the types of the array elements.  */
    1276                 :             : 
    1277                 :             : static bool
    1278                 :     1142843 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
    1279                 :             :                   bool strict)
    1280                 :             : {
    1281                 :     1142843 :   tree d1;
    1282                 :     1142843 :   tree d2;
    1283                 :     1142843 :   tree max1, max2;
    1284                 :             : 
    1285                 :     1142843 :   if (t1 == t2)
    1286                 :             :     return true;
    1287                 :             : 
    1288                 :             :   /* The type of the array elements must be the same.  */
    1289                 :     1142779 :   if (strict
    1290                 :     1145086 :       ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    1291                 :        2307 :       : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1292                 :             :     return false;
    1293                 :             : 
    1294                 :      748543 :   d1 = TYPE_DOMAIN (t1);
    1295                 :      748543 :   d2 = TYPE_DOMAIN (t2);
    1296                 :             : 
    1297                 :      748543 :   if (d1 == d2)
    1298                 :             :     return true;
    1299                 :             : 
    1300                 :             :   /* If one of the arrays is dimensionless, and the other has a
    1301                 :             :      dimension, they are of different types.  However, it is valid to
    1302                 :             :      write:
    1303                 :             : 
    1304                 :             :        extern int a[];
    1305                 :             :        int a[3];
    1306                 :             : 
    1307                 :             :      by [basic.link]:
    1308                 :             : 
    1309                 :             :        declarations for an array object can specify
    1310                 :             :        array types that differ by the presence or absence of a major
    1311                 :             :        array bound (_dcl.array_).  */
    1312                 :      567879 :   if (!d1 && d2)
    1313                 :        1871 :     return cb >= bounds_either;
    1314                 :      566008 :   else if (d1 && !d2)
    1315                 :        3704 :     return cb == bounds_either;
    1316                 :             : 
    1317                 :             :   /* Check that the dimensions are the same.  */
    1318                 :             : 
    1319                 :      562304 :   if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    1320                 :             :     return false;
    1321                 :      562283 :   max1 = TYPE_MAX_VALUE (d1);
    1322                 :      562283 :   max2 = TYPE_MAX_VALUE (d2);
    1323                 :             : 
    1324                 :      562283 :   if (!cp_tree_equal (max1, max2))
    1325                 :             :     return false;
    1326                 :             : 
    1327                 :             :   return true;
    1328                 :             : }
    1329                 :             : 
    1330                 :             : /* Compare the relative position of T1 and T2 into their respective
    1331                 :             :    template parameter list.
    1332                 :             :    T1 and T2 must be template parameter types.
    1333                 :             :    Return TRUE if T1 and T2 have the same position, FALSE otherwise.  */
    1334                 :             : 
    1335                 :             : static bool
    1336                 :  1344586957 : comp_template_parms_position (tree t1, tree t2)
    1337                 :             : {
    1338                 :  1344586957 :   tree index1, index2;
    1339                 :  1344586957 :   gcc_assert (t1 && t2
    1340                 :             :               && TREE_CODE (t1) == TREE_CODE (t2)
    1341                 :             :               && (TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM
    1342                 :             :                   || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM
    1343                 :             :                   || TREE_CODE (t1) == TEMPLATE_TYPE_PARM));
    1344                 :             : 
    1345                 :  1344586957 :   index1 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t1));
    1346                 :  1344586957 :   index2 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t2));
    1347                 :             : 
    1348                 :             :   /* Then compare their relative position.  */
    1349                 :  1344586957 :   if (TEMPLATE_PARM_IDX (index1) != TEMPLATE_PARM_IDX (index2)
    1350                 :   804210738 :       || TEMPLATE_PARM_LEVEL (index1) != TEMPLATE_PARM_LEVEL (index2)
    1351                 :  1960230377 :       || (TEMPLATE_PARM_PARAMETER_PACK (index1)
    1352                 :   615643420 :           != TEMPLATE_PARM_PARAMETER_PACK (index2)))
    1353                 :             :     return false;
    1354                 :             : 
    1355                 :             :   /* In C++14 we can end up comparing 'auto' to a normal template
    1356                 :             :      parameter.  Don't confuse them.  */
    1357                 :   560928427 :   if (cxx_dialect >= cxx14 && (is_auto (t1) || is_auto (t2)))
    1358                 :   125121003 :     return TYPE_IDENTIFIER (t1) == TYPE_IDENTIFIER (t2);
    1359                 :             : 
    1360                 :             :   return true;
    1361                 :             : }
    1362                 :             : 
    1363                 :             : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    1364                 :             : 
    1365                 :             : static bool
    1366                 :         511 : cxx_safe_arg_type_equiv_p (tree t1, tree t2)
    1367                 :             : {
    1368                 :         511 :   t1 = TYPE_MAIN_VARIANT (t1);
    1369                 :         511 :   t2 = TYPE_MAIN_VARIANT (t2);
    1370                 :             : 
    1371                 :         511 :   if (TYPE_PTR_P (t1)
    1372                 :         141 :       && TYPE_PTR_P (t2))
    1373                 :             :     return true;
    1374                 :             : 
    1375                 :             :   /* The signedness of the parameter matters only when an integral
    1376                 :             :      type smaller than int is promoted to int, otherwise only the
    1377                 :             :      precision of the parameter matters.
    1378                 :             :      This check should make sure that the callee does not see
    1379                 :             :      undefined values in argument registers.  */
    1380                 :         376 :   if (INTEGRAL_TYPE_P (t1)
    1381                 :          67 :       && INTEGRAL_TYPE_P (t2)
    1382                 :          46 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
    1383                 :         419 :       && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2)
    1384                 :           0 :           || !targetm.calls.promote_prototypes (NULL_TREE)
    1385                 :           0 :           || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node)))
    1386                 :          43 :     return true;
    1387                 :             : 
    1388                 :         333 :   return same_type_p (t1, t2);
    1389                 :             : }
    1390                 :             : 
    1391                 :             : /* Check if a type cast between two function types can be considered safe.  */
    1392                 :             : 
    1393                 :             : static bool
    1394                 :        5229 : cxx_safe_function_type_cast_p (tree t1, tree t2)
    1395                 :             : {
    1396                 :        5229 :   if (TREE_TYPE (t1) == void_type_node &&
    1397                 :        5167 :       TYPE_ARG_TYPES (t1) == void_list_node)
    1398                 :             :     return true;
    1399                 :             : 
    1400                 :        4600 :   if (TREE_TYPE (t2) == void_type_node &&
    1401                 :        4395 :       TYPE_ARG_TYPES (t2) == void_list_node)
    1402                 :             :     return true;
    1403                 :             : 
    1404                 :         272 :   if (!cxx_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1405                 :             :     return false;
    1406                 :             : 
    1407                 :         111 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    1408                 :         314 :        t1 && t2;
    1409                 :         203 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1410                 :         239 :     if (!cxx_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1411                 :             :       return false;
    1412                 :             : 
    1413                 :             :   return true;
    1414                 :             : }
    1415                 :             : 
    1416                 :             : /* Subroutine in comptypes.  */
    1417                 :             : 
    1418                 :             : static bool
    1419                 : 10161692836 : structural_comptypes (tree t1, tree t2, int strict)
    1420                 :             : {
    1421                 :             :   /* Both should be types that are not obviously the same.  */
    1422                 : 10161692836 :   gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
    1423                 :             : 
    1424                 :             :   /* Suppress typename resolution under spec_hasher::equal in place of calling
    1425                 :             :      push_to_top_level there.  */
    1426                 : 10161692836 :   if (!comparing_specializations)
    1427                 :             :     {
    1428                 :             :       /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
    1429                 :             :          current instantiation.  */
    1430                 :  8275279193 :       if (TREE_CODE (t1) == TYPENAME_TYPE)
    1431                 :    75679338 :         t1 = resolve_typename_type (t1, /*only_current_p=*/true);
    1432                 :             : 
    1433                 :  8275279193 :       if (TREE_CODE (t2) == TYPENAME_TYPE)
    1434                 :    93553430 :         t2 = resolve_typename_type (t2, /*only_current_p=*/true);
    1435                 :             :     }
    1436                 :             : 
    1437                 : 10161692836 :   if (TYPE_PTRMEMFUNC_P (t1))
    1438                 :    30417031 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    1439                 : 10161692836 :   if (TYPE_PTRMEMFUNC_P (t2))
    1440                 :    33627788 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
    1441                 :             : 
    1442                 :             :   /* Different classes of types can't be compatible.  */
    1443                 : 10161692836 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1444                 :             :     return false;
    1445                 :             : 
    1446                 :             :   /* Qualifiers must match.  For array types, we will check when we
    1447                 :             :      recur on the array element types.  */
    1448                 :  6564275360 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1449                 :  6564275360 :       && cp_type_quals (t1) != cp_type_quals (t2))
    1450                 :             :     return false;
    1451                 :  6183559194 :   if (TREE_CODE (t1) == FUNCTION_TYPE
    1452                 :  6183559194 :       && type_memfn_quals (t1) != type_memfn_quals (t2))
    1453                 :             :     return false;
    1454                 :             :   /* Need to check this before TYPE_MAIN_VARIANT.
    1455                 :             :      FIXME function qualifiers should really change the main variant.  */
    1456                 :  6183492440 :   if (FUNC_OR_METHOD_TYPE_P (t1))
    1457                 :             :     {
    1458                 :    36388821 :       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
    1459                 :             :         return false;
    1460                 :    18255995 :       if (flag_noexcept_type
    1461                 :    36408964 :           && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
    1462                 :    18152969 :                                  TYPE_RAISES_EXCEPTIONS (t2),
    1463                 :             :                                  ce_type))
    1464                 :             :         return false;
    1465                 :             :     }
    1466                 :             : 
    1467                 :             :   /* Allow for two different type nodes which have essentially the same
    1468                 :             :      definition.  Note that we already checked for equality of the type
    1469                 :             :      qualifiers (just above).  */
    1470                 :  6158445642 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1471                 :  6158445642 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1472                 :   264846831 :     goto check_alias;
    1473                 :             : 
    1474                 :             :   /* Compare the types.  Return false on known not-same. Break on not
    1475                 :             :      known.   Never return true from this switch -- you'll break
    1476                 :             :      specialization comparison.    */
    1477                 :  5893598811 :   switch (TREE_CODE (t1))
    1478                 :             :     {
    1479                 :             :     case VOID_TYPE:
    1480                 :             :     case BOOLEAN_TYPE:
    1481                 :             :       /* All void and bool types are the same.  */
    1482                 :             :       break;
    1483                 :             : 
    1484                 :   443334226 :     case OPAQUE_TYPE:
    1485                 :   443334226 :     case INTEGER_TYPE:
    1486                 :   443334226 :     case FIXED_POINT_TYPE:
    1487                 :   443334226 :     case REAL_TYPE:
    1488                 :             :       /* With these nodes, we can't determine type equivalence by
    1489                 :             :          looking at what is stored in the nodes themselves, because
    1490                 :             :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1491                 :             :          represent the same type.  For example, wchar_t and int could
    1492                 :             :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1493                 :             :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1494                 :             :          and are distinct types. On the other hand, int and the
    1495                 :             :          following typedef
    1496                 :             : 
    1497                 :             :            typedef int INT __attribute((may_alias));
    1498                 :             : 
    1499                 :             :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1500                 :             :          represent the same type.  The canonical type system keeps
    1501                 :             :          track of equivalence in this case, so we fall back on it.  */
    1502                 :   443334226 :       if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1503                 :             :         return false;
    1504                 :             : 
    1505                 :             :       /* We don't need or want the attribute comparison.  */
    1506                 :        7648 :       goto check_alias;
    1507                 :             : 
    1508                 :     1031955 :     case TEMPLATE_TEMPLATE_PARM:
    1509                 :     1031955 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    1510                 :     1031955 :       if (!comp_template_parms_position (t1, t2))
    1511                 :             :         return false;
    1512                 :      801718 :       if (!comp_template_parms
    1513                 :     1603436 :           (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
    1514                 :     2221577 :            DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
    1515                 :             :         return false;
    1516                 :      546302 :       if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
    1517                 :             :         break;
    1518                 :             :       /* Don't check inheritance.  */
    1519                 :             :       strict = COMPARE_STRICT;
    1520                 :             :       /* Fall through.  */
    1521                 :             : 
    1522                 :  2836413459 :     case RECORD_TYPE:
    1523                 :  2836413459 :     case UNION_TYPE:
    1524                 :  5001228803 :       if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
    1525                 :  1766640414 :           && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
    1526                 :  1318979975 :               || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
    1527                 :  3284092556 :           && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
    1528                 :             :         break;
    1529                 :             : 
    1530                 :  2807101436 :       if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
    1531                 :             :         break;
    1532                 :  2807100232 :       else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
    1533                 :             :         break;
    1534                 :             : 
    1535                 :             :       return false;
    1536                 :             : 
    1537                 :       43161 :     case OFFSET_TYPE:
    1538                 :       43161 :       if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
    1539                 :             :                       strict & ~COMPARE_REDECLARATION))
    1540                 :             :         return false;
    1541                 :       41143 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1542                 :             :         return false;
    1543                 :             :       break;
    1544                 :             : 
    1545                 :   621570652 :     case REFERENCE_TYPE:
    1546                 :   621570652 :       if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
    1547                 :             :         return false;
    1548                 :             :       /* fall through to checks for pointer types */
    1549                 :   909460666 :       gcc_fallthrough ();
    1550                 :             : 
    1551                 :   909460666 :     case POINTER_TYPE:
    1552                 :   909460666 :       if (TYPE_MODE (t1) != TYPE_MODE (t2)
    1553                 :   909460666 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1554                 :   817582479 :         return false;
    1555                 :             :       break;
    1556                 :             : 
    1557                 :    11056231 :     case METHOD_TYPE:
    1558                 :    11056231 :     case FUNCTION_TYPE:
    1559                 :             :       /* Exception specs and memfn_rquals were checked above.  */
    1560                 :    11056231 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1561                 :             :         return false;
    1562                 :    10307807 :       if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
    1563                 :             :         return false;
    1564                 :             :       break;
    1565                 :             : 
    1566                 :     1140472 :     case ARRAY_TYPE:
    1567                 :             :       /* Target types must match incl. qualifiers.  */
    1568                 :     1140472 :       if (!comp_array_types (t1, t2, ((strict & COMPARE_REDECLARATION)
    1569                 :     1140472 :                                       ? bounds_either : bounds_none),
    1570                 :             :                              /*strict=*/true))
    1571                 :             :         return false;
    1572                 :             :       break;
    1573                 :             : 
    1574                 :  1343555002 :     case TEMPLATE_TYPE_PARM:
    1575                 :             :       /* If T1 and T2 don't have the same relative position in their
    1576                 :             :          template parameters set, they can't be equal.  */
    1577                 :  1343555002 :       if (!comp_template_parms_position (t1, t2))
    1578                 :             :         return false;
    1579                 :             :       /* If T1 and T2 don't represent the same class template deduction,
    1580                 :             :          they aren't equal.  */
    1581                 :   950926088 :       if (!cp_tree_equal (CLASS_PLACEHOLDER_TEMPLATE (t1),
    1582                 :   475463044 :                           CLASS_PLACEHOLDER_TEMPLATE (t2)))
    1583                 :             :         return false;
    1584                 :             :       /* Constrained 'auto's are distinct from parms that don't have the same
    1585                 :             :          constraints.  */
    1586                 :   455135769 :       if (!equivalent_placeholder_constraints (t1, t2))
    1587                 :             :         return false;
    1588                 :             :       break;
    1589                 :             : 
    1590                 :   109622681 :     case TYPENAME_TYPE:
    1591                 :   219245362 :       if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
    1592                 :   109622681 :                           TYPENAME_TYPE_FULLNAME (t2)))
    1593                 :             :         return false;
    1594                 :             :       /* Qualifiers don't matter on scopes.  */
    1595                 :    95658444 :       if (!same_type_ignoring_top_level_qualifiers_p (TYPE_CONTEXT (t1),
    1596                 :    95658444 :                                                       TYPE_CONTEXT (t2)))
    1597                 :             :         return false;
    1598                 :             :       break;
    1599                 :             : 
    1600                 :        6439 :     case UNBOUND_CLASS_TEMPLATE:
    1601                 :        6439 :       if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
    1602                 :             :         return false;
    1603                 :        6439 :       if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
    1604                 :             :         return false;
    1605                 :             :       break;
    1606                 :             : 
    1607                 :     2733278 :     case COMPLEX_TYPE:
    1608                 :     2733278 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1609                 :             :         return false;
    1610                 :             :       break;
    1611                 :             : 
    1612                 :     8546602 :     case VECTOR_TYPE:
    1613                 :     8546602 :       if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
    1614                 :    15678035 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1615                 :    15725103 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1616                 :     1415169 :         return false;
    1617                 :             :       break;
    1618                 :             : 
    1619                 :     6292089 :     case TYPE_PACK_EXPANSION:
    1620                 :     6292089 :       return (same_type_p (PACK_EXPANSION_PATTERN (t1),
    1621                 :             :                            PACK_EXPANSION_PATTERN (t2))
    1622                 :    12450554 :               && comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    1623                 :     6158465 :                                      PACK_EXPANSION_EXTRA_ARGS (t2)));
    1624                 :             : 
    1625                 :    11371713 :     case DECLTYPE_TYPE:
    1626                 :    22743426 :       if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t1)
    1627                 :    11371713 :           != DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t2))
    1628                 :             :         return false;
    1629                 :    11359045 :       if (DECLTYPE_FOR_LAMBDA_CAPTURE (t1) != DECLTYPE_FOR_LAMBDA_CAPTURE (t2))
    1630                 :             :         return false;
    1631                 :    11359045 :       if (DECLTYPE_FOR_LAMBDA_PROXY (t1) != DECLTYPE_FOR_LAMBDA_PROXY (t2))
    1632                 :             :         return false;
    1633                 :    11359045 :       if (!cp_tree_equal (DECLTYPE_TYPE_EXPR (t1), DECLTYPE_TYPE_EXPR (t2)))
    1634                 :             :         return false;
    1635                 :             :       break;
    1636                 :             : 
    1637                 :      514286 :     case TRAIT_TYPE:
    1638                 :      514286 :       if (TRAIT_TYPE_KIND (t1) != TRAIT_TYPE_KIND (t2))
    1639                 :             :         return false;
    1640                 :        2827 :       if (!cp_tree_equal (TRAIT_TYPE_TYPE1 (t1), TRAIT_TYPE_TYPE1 (t2))
    1641                 :        5654 :           || !cp_tree_equal (TRAIT_TYPE_TYPE2 (t1), TRAIT_TYPE_TYPE2 (t2)))
    1642                 :           0 :         return false;
    1643                 :             :       break;
    1644                 :             : 
    1645                 :           3 :     case TYPEOF_TYPE:
    1646                 :           3 :       if (!cp_tree_equal (TYPEOF_TYPE_EXPR (t1), TYPEOF_TYPE_EXPR (t2)))
    1647                 :             :         return false;
    1648                 :             :       break;
    1649                 :             : 
    1650                 :             :     default:
    1651                 :             :       return false;
    1652                 :             :     }
    1653                 :             : 
    1654                 :             :   /* If we get here, we know that from a target independent POV the
    1655                 :             :      types are the same.  Make sure the target attributes are also
    1656                 :             :      the same.  */
    1657                 :   593632259 :   if (!comp_type_attributes (t1, t2))
    1658                 :             :     return false;
    1659                 :             : 
    1660                 :   593631119 :  check_alias:
    1661                 :   858485598 :   if (comparing_dependent_aliases
    1662                 :   858485598 :       && (typedef_variant_p (t1) || typedef_variant_p (t2)))
    1663                 :             :     {
    1664                 :     2882269 :       tree dep1 = dependent_opaque_alias_p (t1) ? t1 : NULL_TREE;
    1665                 :     2882269 :       tree dep2 = dependent_opaque_alias_p (t2) ? t2 : NULL_TREE;
    1666                 :     2882269 :       if ((dep1 || dep2)
    1667                 :     2882269 :           && (!(dep1 && dep2)
    1668                 :           0 :               || !comp_type_attributes (DECL_ATTRIBUTES (TYPE_NAME (dep1)),
    1669                 :           0 :                                         DECL_ATTRIBUTES (TYPE_NAME (dep2)))))
    1670                 :          21 :         return false;
    1671                 :             : 
    1672                 :             :       /* Don't treat an alias template specialization with dependent
    1673                 :             :          arguments as equivalent to its underlying type when used as a
    1674                 :             :          template argument; we need them to be distinct so that we
    1675                 :             :          substitute into the specialization arguments at instantiation
    1676                 :             :          time.  And aliases can't be equivalent without being ==, so
    1677                 :             :          we don't need to look any deeper.  */
    1678                 :     2882248 :       ++processing_template_decl;
    1679                 :     2882248 :       dep1 = dependent_alias_template_spec_p (t1, nt_transparent);
    1680                 :     2882248 :       dep2 = dependent_alias_template_spec_p (t2, nt_transparent);
    1681                 :     2882248 :       --processing_template_decl;
    1682                 :     2882248 :       if ((dep1 || dep2) && dep1 != dep2)
    1683                 :             :         return false;
    1684                 :             :     }
    1685                 :             : 
    1686                 :             :   return true;
    1687                 :             : }
    1688                 :             : 
    1689                 :             : /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
    1690                 :             :    is a bitwise-or of the COMPARE_* flags.  */
    1691                 :             : 
    1692                 :             : bool
    1693                 : 16288151994 : comptypes (tree t1, tree t2, int strict)
    1694                 :             : {
    1695                 : 16288151994 :   gcc_checking_assert (t1 && t2);
    1696                 :             : 
    1697                 :             :   /* TYPE_ARGUMENT_PACKS are not really types.  */
    1698                 : 16288151994 :   gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
    1699                 :             :                        && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
    1700                 :             : 
    1701                 : 16288151994 :   if (t1 == t2)
    1702                 :             :     return true;
    1703                 :             : 
    1704                 :             :   /* Suppress errors caused by previously reported errors.  */
    1705                 : 10161693997 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1706                 :             :     return false;
    1707                 :             : 
    1708                 : 10161693836 :   if (strict == COMPARE_STRICT)
    1709                 :             :     {
    1710                 :  9020651171 :       if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
    1711                 :             :         /* At least one of the types requires structural equality, so
    1712                 :             :            perform a deep check. */
    1713                 :   783124294 :         return structural_comptypes (t1, t2, strict);
    1714                 :             : 
    1715                 :  8237526877 :       if (flag_checking && param_use_canonical_types)
    1716                 :             :         {
    1717                 :  8237525877 :           bool result = structural_comptypes (t1, t2, strict);
    1718                 :             :           
    1719                 :  8237525877 :           if (result && TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1720                 :             :             /* The two types are structurally equivalent, but their
    1721                 :             :                canonical types were different. This is a failure of the
    1722                 :             :                canonical type propagation code.*/
    1723                 :           0 :             internal_error 
    1724                 :           0 :               ("canonical types differ for identical types %qT and %qT",
    1725                 :             :                t1, t2);
    1726                 :  8237525877 :           else if (!result && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
    1727                 :             :             /* Two types are structurally different, but the canonical
    1728                 :             :                types are the same. This means we were over-eager in
    1729                 :             :                assigning canonical types. */
    1730                 :           0 :             internal_error 
    1731                 :           0 :               ("same canonical type node for different types %qT and %qT",
    1732                 :             :                t1, t2);
    1733                 :             :           
    1734                 :             :           return result;
    1735                 :             :         }
    1736                 :        1000 :       if (!flag_checking && param_use_canonical_types)
    1737                 :        1000 :         return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1738                 :             :       else
    1739                 :           0 :         return structural_comptypes (t1, t2, strict);
    1740                 :             :     }
    1741                 :  1141042665 :   else if (strict == COMPARE_STRUCTURAL)
    1742                 :  1109335089 :     return structural_comptypes (t1, t2, COMPARE_STRICT);
    1743                 :             :   else
    1744                 :    31707576 :     return structural_comptypes (t1, t2, strict);
    1745                 :             : }
    1746                 :             : 
    1747                 :             : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
    1748                 :             :    top-level qualifiers.  */
    1749                 :             : 
    1750                 :             : bool
    1751                 :  2174594445 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
    1752                 :             : {
    1753                 :  2174594445 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1754                 :             :     return false;
    1755                 :  2174594435 :   if (type1 == type2)
    1756                 :             :     return true;
    1757                 :             : 
    1758                 :  1294670154 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1759                 :  1294670154 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1760                 :  1294670154 :   return same_type_p (type1, type2);
    1761                 :             : }
    1762                 :             : 
    1763                 :             : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
    1764                 :             : 
    1765                 :             : bool
    1766                 :   190015101 : similar_type_p (tree type1, tree type2)
    1767                 :             : {
    1768                 :   190015101 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1769                 :             :     return false;
    1770                 :             : 
    1771                 :             :   /* Informally, two types are similar if, ignoring top-level cv-qualification:
    1772                 :             :      * they are the same type; or
    1773                 :             :      * they are both pointers, and the pointed-to types are similar; or
    1774                 :             :      * they are both pointers to member of the same class, and the types of
    1775                 :             :        the pointed-to members are similar; or
    1776                 :             :      * they are both arrays of the same size or both arrays of unknown bound,
    1777                 :             :        and the array element types are similar.  */
    1778                 :             : 
    1779                 :   190015101 :   if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
    1780                 :             :     return true;
    1781                 :             : 
    1782                 :    92096314 :   if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    1783                 :    92053552 :       || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    1784                 :    92053552 :       || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
    1785                 :       43254 :     return comp_ptr_ttypes_const (type1, type2, bounds_either);
    1786                 :             : 
    1787                 :             :   return false;
    1788                 :             : }
    1789                 :             : 
    1790                 :             : /* Helper function for layout_compatible_type_p and
    1791                 :             :    is_corresponding_member_aggr.  Advance to next members (NULL if
    1792                 :             :    no further ones) and return true if those members are still part of
    1793                 :             :    the common initial sequence.  */
    1794                 :             : 
    1795                 :             : bool
    1796                 :        2112 : next_common_initial_sequence (tree &memb1, tree &memb2)
    1797                 :             : {
    1798                 :        2587 :   while (memb1)
    1799                 :             :     {
    1800                 :        2623 :       if (TREE_CODE (memb1) != FIELD_DECL
    1801                 :        2206 :           || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
    1802                 :             :         {
    1803                 :         417 :           memb1 = DECL_CHAIN (memb1);
    1804                 :         417 :           continue;
    1805                 :             :         }
    1806                 :        1789 :       if (DECL_FIELD_IS_BASE (memb1))
    1807                 :             :         {
    1808                 :          58 :           memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
    1809                 :          58 :           continue;
    1810                 :             :         }
    1811                 :             :       break;
    1812                 :             :     }
    1813                 :        2557 :   while (memb2)
    1814                 :             :     {
    1815                 :        2593 :       if (TREE_CODE (memb2) != FIELD_DECL
    1816                 :        2176 :           || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
    1817                 :             :         {
    1818                 :         417 :           memb2 = DECL_CHAIN (memb2);
    1819                 :         417 :           continue;
    1820                 :             :         }
    1821                 :        1759 :       if (DECL_FIELD_IS_BASE (memb2))
    1822                 :             :         {
    1823                 :          28 :           memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
    1824                 :          28 :           continue;
    1825                 :             :         }
    1826                 :             :       break;
    1827                 :             :     }
    1828                 :        2112 :   if (memb1 == NULL_TREE && memb2 == NULL_TREE)
    1829                 :             :     return true;
    1830                 :        1731 :   if (memb1 == NULL_TREE || memb2 == NULL_TREE)
    1831                 :             :     return false;
    1832                 :        1731 :   if (DECL_BIT_FIELD_TYPE (memb1))
    1833                 :             :     {
    1834                 :         150 :       if (!DECL_BIT_FIELD_TYPE (memb2))
    1835                 :             :         return false;
    1836                 :          42 :       if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
    1837                 :          42 :                                      DECL_BIT_FIELD_TYPE (memb2)))
    1838                 :             :         return false;
    1839                 :          42 :       if (TYPE_PRECISION (TREE_TYPE (memb1))
    1840                 :          42 :           != TYPE_PRECISION (TREE_TYPE (memb2)))
    1841                 :             :         return false;
    1842                 :             :     }
    1843                 :        1581 :   else if (DECL_BIT_FIELD_TYPE (memb2))
    1844                 :             :     return false;
    1845                 :        1551 :   else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
    1846                 :             :     return false;
    1847                 :        1524 :   if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
    1848                 :        1524 :       != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
    1849                 :             :     return false;
    1850                 :        1494 :   if (DECL_ALIGN (memb1) != DECL_ALIGN (memb2))
    1851                 :             :     return false;
    1852                 :        1461 :   if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
    1853                 :             :     return false;
    1854                 :             :   return true;
    1855                 :             : }
    1856                 :             : 
    1857                 :             : /* Return true if TYPE1 and TYPE2 are layout-compatible types.  */
    1858                 :             : 
    1859                 :             : bool
    1860                 :        2709 : layout_compatible_type_p (tree type1, tree type2)
    1861                 :             : {
    1862                 :        2709 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1863                 :             :     return false;
    1864                 :        2709 :   if (type1 == type2)
    1865                 :             :     return true;
    1866                 :        1318 :   if (TREE_CODE (type1) != TREE_CODE (type2))
    1867                 :             :     return false;
    1868                 :             : 
    1869                 :        1280 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1870                 :        1280 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1871                 :             : 
    1872                 :        1280 :   if (TREE_CODE (type1) == ENUMERAL_TYPE)
    1873                 :          32 :     return (tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))
    1874                 :          32 :             && same_type_p (finish_underlying_type (type1),
    1875                 :             :                             finish_underlying_type (type2)));
    1876                 :             : 
    1877                 :         391 :   if (CLASS_TYPE_P (type1)
    1878                 :         391 :       && std_layout_type_p (type1)
    1879                 :         381 :       && std_layout_type_p (type2)
    1880                 :        1629 :       && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)))
    1881                 :             :     {
    1882                 :         336 :       tree field1 = TYPE_FIELDS (type1);
    1883                 :         336 :       tree field2 = TYPE_FIELDS (type2);
    1884                 :         336 :       if (TREE_CODE (type1) == RECORD_TYPE)
    1885                 :             :         {
    1886                 :        1011 :           while (1)
    1887                 :             :             {
    1888                 :         636 :               if (!next_common_initial_sequence (field1, field2))
    1889                 :             :                 return false;
    1890                 :         630 :               if (field1 == NULL_TREE)
    1891                 :             :                 return true;
    1892                 :         375 :               field1 = DECL_CHAIN (field1);
    1893                 :         375 :               field2 = DECL_CHAIN (field2);
    1894                 :             :             }
    1895                 :             :         }
    1896                 :             :       /* Otherwise both types must be union types.
    1897                 :             :          The standard says:
    1898                 :             :          "Two standard-layout unions are layout-compatible if they have
    1899                 :             :          the same number of non-static data members and corresponding
    1900                 :             :          non-static data members (in any order) have layout-compatible
    1901                 :             :          types."
    1902                 :             :          but the code anticipates that bitfield vs. non-bitfield,
    1903                 :             :          different bitfield widths or presence/absence of
    1904                 :             :          [[no_unique_address]] should be checked as well.  */
    1905                 :          75 :       auto_vec<tree, 16> vec;
    1906                 :          75 :       unsigned int count = 0;
    1907                 :         339 :       for (; field1; field1 = DECL_CHAIN (field1))
    1908                 :         264 :         if (TREE_CODE (field1) == FIELD_DECL)
    1909                 :         174 :           count++;
    1910                 :         339 :       for (; field2; field2 = DECL_CHAIN (field2))
    1911                 :         264 :         if (TREE_CODE (field2) == FIELD_DECL)
    1912                 :         174 :           vec.safe_push (field2);
    1913                 :             :       /* Discussions on core lean towards treating multiple union fields
    1914                 :             :          of the same type as the same field, so this might need changing
    1915                 :             :          in the future.  */
    1916                 :         150 :       if (count != vec.length ())
    1917                 :             :         return false;
    1918                 :         321 :       for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
    1919                 :             :         {
    1920                 :         252 :           if (TREE_CODE (field1) != FIELD_DECL)
    1921                 :          84 :             continue;
    1922                 :         168 :           unsigned int j;
    1923                 :         168 :           tree t1 = DECL_BIT_FIELD_TYPE (field1);
    1924                 :         168 :           if (t1 == NULL_TREE)
    1925                 :         165 :             t1 = TREE_TYPE (field1);
    1926                 :         276 :           FOR_EACH_VEC_ELT (vec, j, field2)
    1927                 :             :             {
    1928                 :         270 :               tree t2 = DECL_BIT_FIELD_TYPE (field2);
    1929                 :         270 :               if (t2 == NULL_TREE)
    1930                 :         258 :                 t2 = TREE_TYPE (field2);
    1931                 :         270 :               if (DECL_BIT_FIELD_TYPE (field1))
    1932                 :             :                 {
    1933                 :           6 :                   if (!DECL_BIT_FIELD_TYPE (field2))
    1934                 :           0 :                     continue;
    1935                 :           6 :                   if (TYPE_PRECISION (TREE_TYPE (field1))
    1936                 :           6 :                       != TYPE_PRECISION (TREE_TYPE (field2)))
    1937                 :           6 :                     continue;
    1938                 :             :                 }
    1939                 :         264 :               else if (DECL_BIT_FIELD_TYPE (field2))
    1940                 :           6 :                 continue;
    1941                 :         258 :               if (!layout_compatible_type_p (t1, t2))
    1942                 :          96 :                 continue;
    1943                 :         162 :               if ((!lookup_attribute ("no_unique_address",
    1944                 :         162 :                                       DECL_ATTRIBUTES (field1)))
    1945                 :         162 :                   != !lookup_attribute ("no_unique_address",
    1946                 :         162 :                                         DECL_ATTRIBUTES (field2)))
    1947                 :           0 :                 continue;
    1948                 :             :               break;
    1949                 :             :             }
    1950                 :         336 :           if (j == vec.length ())
    1951                 :             :             return false;
    1952                 :         162 :           vec.unordered_remove (j);
    1953                 :             :         }
    1954                 :             :       return true;
    1955                 :          75 :     }
    1956                 :             : 
    1957                 :         912 :   return same_type_p (type1, type2);
    1958                 :             : }
    1959                 :             : 
    1960                 :             : /* Returns 1 if TYPE1 is at least as qualified as TYPE2.  */
    1961                 :             : 
    1962                 :             : bool
    1963                 :   136528896 : at_least_as_qualified_p (const_tree type1, const_tree type2)
    1964                 :             : {
    1965                 :   136528896 :   int q1 = cp_type_quals (type1);
    1966                 :   136528896 :   int q2 = cp_type_quals (type2);
    1967                 :             : 
    1968                 :             :   /* All qualifiers for TYPE2 must also appear in TYPE1.  */
    1969                 :   136528896 :   return (q1 & q2) == q2;
    1970                 :             : }
    1971                 :             : 
    1972                 :             : /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
    1973                 :             :    more cv-qualified that TYPE1, and 0 otherwise.  */
    1974                 :             : 
    1975                 :             : int
    1976                 :     8956509 : comp_cv_qualification (int q1, int q2)
    1977                 :             : {
    1978                 :     8956509 :   if (q1 == q2)
    1979                 :             :     return 0;
    1980                 :             : 
    1981                 :     2717210 :   if ((q1 & q2) == q2)
    1982                 :             :     return 1;
    1983                 :      174153 :   else if ((q1 & q2) == q1)
    1984                 :      173567 :     return -1;
    1985                 :             : 
    1986                 :             :   return 0;
    1987                 :             : }
    1988                 :             : 
    1989                 :             : int
    1990                 :           0 : comp_cv_qualification (const_tree type1, const_tree type2)
    1991                 :             : {
    1992                 :           0 :   int q1 = cp_type_quals (type1);
    1993                 :           0 :   int q2 = cp_type_quals (type2);
    1994                 :           0 :   return comp_cv_qualification (q1, q2);
    1995                 :             : }
    1996                 :             : 
    1997                 :             : /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
    1998                 :             :    subset of the cv-qualification signature of TYPE2, and the types
    1999                 :             :    are similar.  Returns -1 if the other way 'round, and 0 otherwise.  */
    2000                 :             : 
    2001                 :             : int
    2002                 :         309 : comp_cv_qual_signature (tree type1, tree type2)
    2003                 :             : {
    2004                 :         309 :   if (comp_ptr_ttypes_real (type2, type1, -1))
    2005                 :             :     return 1;
    2006                 :         259 :   else if (comp_ptr_ttypes_real (type1, type2, -1))
    2007                 :             :     return -1;
    2008                 :             :   else
    2009                 :         247 :     return 0;
    2010                 :             : }
    2011                 :             : 
    2012                 :             : /* Subroutines of `comptypes'.  */
    2013                 :             : 
    2014                 :             : /* Return true if two parameter type lists PARMS1 and PARMS2 are
    2015                 :             :    equivalent in the sense that functions with those parameter types
    2016                 :             :    can have equivalent types.  The two lists must be equivalent,
    2017                 :             :    element by element.  */
    2018                 :             : 
    2019                 :             : bool
    2020                 :   705891325 : compparms (const_tree parms1, const_tree parms2)
    2021                 :             : {
    2022                 :   705891325 :   const_tree t1, t2;
    2023                 :             : 
    2024                 :             :   /* An unspecified parmlist matches any specified parmlist
    2025                 :             :      whose argument types don't need default promotions.  */
    2026                 :             : 
    2027                 :   705891325 :   for (t1 = parms1, t2 = parms2;
    2028                 :  1168160254 :        t1 || t2;
    2029                 :   462268929 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2030                 :             :     {
    2031                 :             :       /* If one parmlist is shorter than the other,
    2032                 :             :          they fail to match.  */
    2033                 :  1102616033 :       if (!t1 || !t2)
    2034                 :             :         return false;
    2035                 :  1101903043 :       if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2036                 :             :         return false;
    2037                 :             :     }
    2038                 :             :   return true;
    2039                 :             : }
    2040                 :             : 
    2041                 :             : 
    2042                 :             : /* Process a sizeof or alignof expression where the operand is a type.
    2043                 :             :    STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
    2044                 :             :    or GNU (preferred alignment) semantics; it is ignored if OP is
    2045                 :             :    SIZEOF_EXPR.  */
    2046                 :             : 
    2047                 :             : tree
    2048                 :    22771776 : cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op,
    2049                 :             :                             bool std_alignof, bool complain)
    2050                 :             : {
    2051                 :    22771776 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2052                 :    22771776 :   if (type == error_mark_node)
    2053                 :             :     return error_mark_node;
    2054                 :             : 
    2055                 :    22771774 :   type = non_reference (type);
    2056                 :    22771774 :   if (TREE_CODE (type) == METHOD_TYPE)
    2057                 :             :     {
    2058                 :           0 :       if (complain)
    2059                 :             :         {
    2060                 :           0 :           pedwarn (loc, OPT_Wpointer_arith,
    2061                 :             :                    "invalid application of %qs to a member function",
    2062                 :           0 :                    OVL_OP_INFO (false, op)->name);
    2063                 :           0 :           return size_one_node;
    2064                 :             :         }
    2065                 :             :       else
    2066                 :           0 :         return error_mark_node;
    2067                 :             :     }
    2068                 :    22771774 :   else if (VOID_TYPE_P (type) && std_alignof)
    2069                 :             :     {
    2070                 :          14 :       if (complain)
    2071                 :          14 :         error_at (loc, "invalid application of %qs to a void type",
    2072                 :          14 :                   OVL_OP_INFO (false, op)->name);
    2073                 :          14 :       return error_mark_node;
    2074                 :             :     }
    2075                 :             : 
    2076                 :    22771760 :   bool dependent_p = dependent_type_p (type);
    2077                 :    22771760 :   if (!dependent_p)
    2078                 :    19225070 :     complete_type (type);
    2079                 :    19225070 :   if (dependent_p
    2080                 :             :       /* VLA types will have a non-constant size.  In the body of an
    2081                 :             :          uninstantiated template, we don't need to try to compute the
    2082                 :             :          value, because the sizeof expression is not an integral
    2083                 :             :          constant expression in that case.  And, if we do try to
    2084                 :             :          compute the value, we'll likely end up with SAVE_EXPRs, which
    2085                 :             :          the template substitution machinery does not expect to see.  */
    2086                 :    19225070 :       || (processing_template_decl 
    2087                 :     1724649 :           && COMPLETE_TYPE_P (type)
    2088                 :     1724646 :           && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
    2089                 :             :     {
    2090                 :     3546690 :       tree value = build_min (op, size_type_node, type);
    2091                 :     3546690 :       TREE_READONLY (value) = 1;
    2092                 :     3546690 :       if (op == ALIGNOF_EXPR && std_alignof)
    2093                 :      428766 :         ALIGNOF_EXPR_STD_P (value) = true;
    2094                 :     3546690 :       SET_EXPR_LOCATION (value, loc);
    2095                 :     3546690 :       return value;
    2096                 :             :     }
    2097                 :             : 
    2098                 :    19225070 :   return c_sizeof_or_alignof_type (loc, complete_type (type),
    2099                 :             :                                    op == SIZEOF_EXPR, std_alignof,
    2100                 :    19225070 :                                    complain);
    2101                 :             : }
    2102                 :             : 
    2103                 :             : /* Return the size of the type, without producing any warnings for
    2104                 :             :    types whose size cannot be taken.  This routine should be used only
    2105                 :             :    in some other routine that has already produced a diagnostic about
    2106                 :             :    using the size of such a type.  */
    2107                 :             : tree 
    2108                 :     2052431 : cxx_sizeof_nowarn (tree type)
    2109                 :             : {
    2110                 :     2052431 :   if (TREE_CODE (type) == FUNCTION_TYPE
    2111                 :     2052431 :       || VOID_TYPE_P (type)
    2112                 :     2052347 :       || TREE_CODE (type) == ERROR_MARK)
    2113                 :          84 :     return size_one_node;
    2114                 :     2052347 :   else if (!COMPLETE_TYPE_P (type))
    2115                 :          23 :     return size_zero_node;
    2116                 :             :   else
    2117                 :     2052324 :     return cxx_sizeof_or_alignof_type (input_location, type,
    2118                 :     2052324 :                                        SIZEOF_EXPR, false, false);
    2119                 :             : }
    2120                 :             : 
    2121                 :             : /* Process a sizeof expression where the operand is an expression.  */
    2122                 :             : 
    2123                 :             : static tree
    2124                 :     1260893 : cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
    2125                 :             : {
    2126                 :     1260893 :   if (e == error_mark_node)
    2127                 :             :     return error_mark_node;
    2128                 :             : 
    2129                 :     1260166 :   if (instantiation_dependent_uneval_expression_p (e))
    2130                 :             :     {
    2131                 :      214728 :       e = build_min (SIZEOF_EXPR, size_type_node, e);
    2132                 :      214728 :       TREE_SIDE_EFFECTS (e) = 0;
    2133                 :      214728 :       TREE_READONLY (e) = 1;
    2134                 :      214728 :       SET_EXPR_LOCATION (e, loc);
    2135                 :             : 
    2136                 :      214728 :       return e;
    2137                 :             :     }
    2138                 :             : 
    2139                 :     1045438 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2140                 :     1045438 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2141                 :             : 
    2142                 :     1045438 :   if (TREE_CODE (e) == PARM_DECL
    2143                 :       37991 :       && DECL_ARRAY_PARAMETER_P (e)
    2144                 :     1045819 :       && (complain & tf_warning))
    2145                 :             :     {
    2146                 :         120 :       auto_diagnostic_group d;
    2147                 :         120 :       if (warning_at (e_loc, OPT_Wsizeof_array_argument,
    2148                 :             :                       "%<sizeof%> on array function parameter %qE "
    2149                 :         120 :                       "will return size of %qT", e, TREE_TYPE (e)))
    2150                 :          24 :         inform (DECL_SOURCE_LOCATION (e), "declared here");
    2151                 :         120 :     }
    2152                 :             : 
    2153                 :     1045438 :   e = mark_type_use (e);
    2154                 :             : 
    2155                 :     1045438 :   if (bitfield_p (e))
    2156                 :             :     {
    2157                 :          12 :       if (complain & tf_error)
    2158                 :           6 :         error_at (e_loc,
    2159                 :             :                   "invalid application of %<sizeof%> to a bit-field");
    2160                 :             :       else
    2161                 :           6 :         return error_mark_node;
    2162                 :           6 :       e = char_type_node;
    2163                 :             :     }
    2164                 :     1045426 :   else if (is_overloaded_fn (e))
    2165                 :             :     {
    2166                 :          33 :       if (complain & tf_error)
    2167                 :          12 :         permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to "
    2168                 :             :                    "an expression of function type");
    2169                 :             :       else
    2170                 :          21 :         return error_mark_node;
    2171                 :          12 :       e = char_type_node;
    2172                 :             :     }
    2173                 :     1045393 :   else if (type_unknown_p (e))
    2174                 :             :     {
    2175                 :           0 :       if (complain & tf_error)
    2176                 :           0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2177                 :             :       else
    2178                 :           0 :         return error_mark_node;
    2179                 :           0 :       e = char_type_node;
    2180                 :             :     }
    2181                 :             :   else
    2182                 :     1045393 :     e = TREE_TYPE (e);
    2183                 :             : 
    2184                 :     1045411 :   return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false,
    2185                 :     1045411 :                                      complain & tf_error);
    2186                 :             : }
    2187                 :             : 
    2188                 :             : /* Implement the __alignof keyword: Return the minimum required
    2189                 :             :    alignment of E, measured in bytes.  For VAR_DECL's and
    2190                 :             :    FIELD_DECL's return DECL_ALIGN (which can be set from an
    2191                 :             :    "aligned" __attribute__ specification).  STD_ALIGNOF acts
    2192                 :             :    like in cxx_sizeof_or_alignof_type.  */
    2193                 :             : 
    2194                 :             : static tree
    2195                 :      100845 : cxx_alignof_expr (location_t loc, tree e, bool std_alignof,
    2196                 :             :                   tsubst_flags_t complain)
    2197                 :             : {
    2198                 :      100845 :   tree t;
    2199                 :             : 
    2200                 :      100845 :   if (e == error_mark_node)
    2201                 :             :     return error_mark_node;
    2202                 :             : 
    2203                 :      100837 :   if (processing_template_decl)
    2204                 :             :     {
    2205                 :       19146 :       e = build_min (ALIGNOF_EXPR, size_type_node, e);
    2206                 :       19146 :       TREE_SIDE_EFFECTS (e) = 0;
    2207                 :       19146 :       TREE_READONLY (e) = 1;
    2208                 :       19146 :       SET_EXPR_LOCATION (e, loc);
    2209                 :       19146 :       ALIGNOF_EXPR_STD_P (e) = std_alignof;
    2210                 :             : 
    2211                 :       19146 :       return e;
    2212                 :             :     }
    2213                 :             : 
    2214                 :       81691 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2215                 :       81691 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2216                 :             : 
    2217                 :       81691 :   e = mark_type_use (e);
    2218                 :             : 
    2219                 :       81691 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e),
    2220                 :       81691 :                             !(complain & tf_error)))
    2221                 :             :     {
    2222                 :           0 :       if (!(complain & tf_error))
    2223                 :           0 :         return error_mark_node;
    2224                 :           0 :       t = size_one_node;
    2225                 :             :     }
    2226                 :       81691 :   else if (VAR_P (e))
    2227                 :       12258 :     t = size_int (DECL_ALIGN_UNIT (e));
    2228                 :       69433 :   else if (bitfield_p (e))
    2229                 :             :     {
    2230                 :           6 :       if (complain & tf_error)
    2231                 :           6 :         error_at (e_loc,
    2232                 :             :                   "invalid application of %<__alignof%> to a bit-field");
    2233                 :             :       else
    2234                 :           0 :         return error_mark_node;
    2235                 :           6 :       t = size_one_node;
    2236                 :             :     }
    2237                 :       69427 :   else if (TREE_CODE (e) == COMPONENT_REF
    2238                 :       69427 :            && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL)
    2239                 :       37792 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (e, 1)));
    2240                 :       31635 :   else if (is_overloaded_fn (e))
    2241                 :             :     {
    2242                 :           6 :       if (complain & tf_error)
    2243                 :           6 :         permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to "
    2244                 :             :                    "an expression of function type");
    2245                 :             :       else
    2246                 :           0 :         return error_mark_node;
    2247                 :           6 :       if (TREE_CODE (e) == FUNCTION_DECL)
    2248                 :           3 :         t = size_int (DECL_ALIGN_UNIT (e));
    2249                 :             :       else
    2250                 :           3 :         t = size_one_node;
    2251                 :             :     }
    2252                 :       31629 :   else if (type_unknown_p (e))
    2253                 :             :     {
    2254                 :           0 :       if (complain & tf_error)
    2255                 :           0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2256                 :             :       else
    2257                 :           0 :         return error_mark_node;
    2258                 :           0 :       t = size_one_node;
    2259                 :             :     }
    2260                 :             :   else
    2261                 :       31629 :     return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
    2262                 :             :                                        ALIGNOF_EXPR, std_alignof,
    2263                 :       31629 :                                        complain & tf_error);
    2264                 :             : 
    2265                 :       50062 :   return fold_convert_loc (loc, size_type_node, t);
    2266                 :             : }
    2267                 :             : 
    2268                 :             : /* Process a sizeof or alignof expression E with code OP where the operand
    2269                 :             :    is an expression. STD_ALIGNOF acts like in cxx_sizeof_or_alignof_type.  */
    2270                 :             : 
    2271                 :             : tree
    2272                 :     1361738 : cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
    2273                 :             :                             bool std_alignof, bool complain)
    2274                 :             : {
    2275                 :     1361738 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2276                 :     1361738 :   if (op == SIZEOF_EXPR)
    2277                 :     1928201 :     return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
    2278                 :             :   else
    2279                 :      100872 :     return cxx_alignof_expr (loc, e, std_alignof,
    2280                 :      100845 :                              complain? tf_warning_or_error : tf_none);
    2281                 :             : }
    2282                 :             : 
    2283                 :             : /*  Build a representation of an expression 'alignas(E).'  Return the
    2284                 :             :     folded integer value of E if it is an integral constant expression
    2285                 :             :     that resolves to a valid alignment.  If E depends on a template
    2286                 :             :     parameter, return a syntactic representation tree of kind
    2287                 :             :     ALIGNOF_EXPR.  Otherwise, return an error_mark_node if the
    2288                 :             :     expression is ill formed, or NULL_TREE if E is NULL_TREE.  */
    2289                 :             : 
    2290                 :             : tree
    2291                 :      162526 : cxx_alignas_expr (tree e)
    2292                 :             : {
    2293                 :      162526 :   if (e == NULL_TREE || e == error_mark_node
    2294                 :      325052 :       || (!TYPE_P (e) && !require_potential_rvalue_constant_expression (e)))
    2295                 :           0 :     return e;
    2296                 :             :   
    2297                 :      162526 :   if (TYPE_P (e))
    2298                 :             :     /* [dcl.align]/3:
    2299                 :             :        
    2300                 :             :            When the alignment-specifier is of the form
    2301                 :             :            alignas(type-id), it shall have the same effect as
    2302                 :             :            alignas(alignof(type-id)).  */
    2303                 :             : 
    2304                 :      115638 :     return cxx_sizeof_or_alignof_type (input_location,
    2305                 :             :                                        e, ALIGNOF_EXPR,
    2306                 :             :                                        /*std_alignof=*/true,
    2307                 :      115638 :                                        /*complain=*/true);
    2308                 :             :   
    2309                 :             :   /* If we reach this point, it means the alignas expression if of
    2310                 :             :      the form "alignas(assignment-expression)", so we should follow
    2311                 :             :      what is stated by [dcl.align]/2.  */
    2312                 :             : 
    2313                 :       46888 :   if (value_dependent_expression_p (e))
    2314                 :             :     /* Leave value-dependent expression alone for now. */
    2315                 :             :     return e;
    2316                 :             : 
    2317                 :       15477 :   e = instantiate_non_dependent_expr (e);
    2318                 :       15477 :   e = mark_rvalue_use (e);
    2319                 :             : 
    2320                 :             :   /* [dcl.align]/2 says:
    2321                 :             : 
    2322                 :             :          the assignment-expression shall be an integral constant
    2323                 :             :          expression.  */
    2324                 :             : 
    2325                 :       15477 :   if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (e)))
    2326                 :             :     {
    2327                 :           6 :       error ("%<alignas%> argument has non-integral type %qT", TREE_TYPE (e));
    2328                 :           6 :       return error_mark_node;
    2329                 :             :     }
    2330                 :             :   
    2331                 :       15471 :   return cxx_constant_value (e);
    2332                 :             : }
    2333                 :             : 
    2334                 :             : 
    2335                 :             : /* EXPR is being used in a context that is not a function call.
    2336                 :             :    Enforce:
    2337                 :             : 
    2338                 :             :      [expr.ref]
    2339                 :             : 
    2340                 :             :      The expression can be used only as the left-hand operand of a
    2341                 :             :      member function call.
    2342                 :             : 
    2343                 :             :      [expr.mptr.operator]
    2344                 :             : 
    2345                 :             :      If the result of .* or ->* is a function, then that result can be
    2346                 :             :      used only as the operand for the function call operator ().
    2347                 :             : 
    2348                 :             :    by issuing an error message if appropriate.  Returns true iff EXPR
    2349                 :             :    violates these rules.  */
    2350                 :             : 
    2351                 :             : bool
    2352                 :  1069707583 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
    2353                 :             : {
    2354                 :  1069707583 :   if (expr == NULL_TREE)
    2355                 :             :     return false;
    2356                 :             :   /* Don't enforce this in MS mode.  */
    2357                 :  1069706165 :   if (flag_ms_extensions)
    2358                 :             :     return false;
    2359                 :  1069701716 :   if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
    2360                 :    86311588 :     expr = get_first_fn (expr);
    2361                 :  1069701716 :   if (TREE_TYPE (expr)
    2362                 :  1069701716 :       && DECL_IOBJ_MEMBER_FUNCTION_P (expr))
    2363                 :             :     {
    2364                 :          91 :       if (complain & tf_error)
    2365                 :             :         {
    2366                 :          87 :           if (DECL_P (expr))
    2367                 :             :             {
    2368                 :          69 :               auto_diagnostic_group d;
    2369                 :          69 :               error_at (loc, "invalid use of non-static member function %qD",
    2370                 :             :                         expr);
    2371                 :          69 :               inform (DECL_SOURCE_LOCATION (expr), "declared here");
    2372                 :          69 :             }
    2373                 :             :           else
    2374                 :          18 :             error_at (loc, "invalid use of non-static member function of "
    2375                 :          18 :                       "type %qT", TREE_TYPE (expr));
    2376                 :             :         }
    2377                 :          91 :       return true;
    2378                 :             :     }
    2379                 :             :   return false;
    2380                 :             : }
    2381                 :             : 
    2382                 :             : /* If EXP is a reference to a bit-field, and the type of EXP does not
    2383                 :             :    match the declared type of the bit-field, return the declared type
    2384                 :             :    of the bit-field.  Otherwise, return NULL_TREE.  */
    2385                 :             : 
    2386                 :             : tree
    2387                 :  2505029284 : is_bitfield_expr_with_lowered_type (const_tree exp)
    2388                 :             : {
    2389                 :  3494872692 :   switch (TREE_CODE (exp))
    2390                 :             :     {
    2391                 :     4961475 :     case COND_EXPR:
    2392                 :     9922950 :       if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
    2393                 :     4961449 :                                                ? TREE_OPERAND (exp, 1)
    2394                 :          26 :                                                : TREE_OPERAND (exp, 0)))
    2395                 :             :         return NULL_TREE;
    2396                 :         135 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
    2397                 :             : 
    2398                 :      598188 :     case COMPOUND_EXPR:
    2399                 :      598188 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
    2400                 :             : 
    2401                 :   326904987 :     case MODIFY_EXPR:
    2402                 :   326904987 :     case SAVE_EXPR:
    2403                 :   326904987 :     case UNARY_PLUS_EXPR:
    2404                 :   326904987 :     case PREDECREMENT_EXPR:
    2405                 :   326904987 :     case PREINCREMENT_EXPR:
    2406                 :   326904987 :     case POSTDECREMENT_EXPR:
    2407                 :   326904987 :     case POSTINCREMENT_EXPR:
    2408                 :   326904987 :     case NEGATE_EXPR:
    2409                 :   326904987 :     case NON_LVALUE_EXPR:
    2410                 :   326904987 :     case BIT_NOT_EXPR:
    2411                 :   326904987 :     case CLEANUP_POINT_EXPR:
    2412                 :   326904987 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2413                 :             : 
    2414                 :   217295824 :     case COMPONENT_REF:
    2415                 :   217295824 :       {
    2416                 :   217295824 :         tree field;
    2417                 :             :         
    2418                 :   217295824 :         field = TREE_OPERAND (exp, 1);
    2419                 :   217295824 :         if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
    2420                 :             :           return NULL_TREE;
    2421                 :    31588470 :         if (same_type_ignoring_top_level_qualifiers_p
    2422                 :    31588470 :             (TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
    2423                 :             :           return NULL_TREE;
    2424                 :    31437561 :         return DECL_BIT_FIELD_TYPE (field);
    2425                 :             :       }
    2426                 :             : 
    2427                 :   484658335 :     case VAR_DECL:
    2428                 :   484658335 :       if (DECL_HAS_VALUE_EXPR_P (exp))
    2429                 :     1215765 :         return is_bitfield_expr_with_lowered_type (DECL_VALUE_EXPR
    2430                 :     1215765 :                                                    (CONST_CAST_TREE (exp)));
    2431                 :             :       return NULL_TREE;
    2432                 :             : 
    2433                 :   668080853 :     case VIEW_CONVERT_EXPR:
    2434                 :   668080853 :       if (location_wrapper_p (exp))
    2435                 :   661124333 :         return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2436                 :             :       else
    2437                 :             :         return NULL_TREE;
    2438                 :             : 
    2439                 :             :     default:
    2440                 :             :       return NULL_TREE;
    2441                 :             :     }
    2442                 :             : }
    2443                 :             : 
    2444                 :             : /* Like is_bitfield_with_lowered_type, except that if EXP is not a
    2445                 :             :    bitfield with a lowered type, the type of EXP is returned, rather
    2446                 :             :    than NULL_TREE.  */
    2447                 :             : 
    2448                 :             : tree
    2449                 :  1175650841 : unlowered_expr_type (const_tree exp)
    2450                 :             : {
    2451                 :  1175650841 :   tree type;
    2452                 :  1175650841 :   tree etype = TREE_TYPE (exp);
    2453                 :             : 
    2454                 :  1175650841 :   type = is_bitfield_expr_with_lowered_type (exp);
    2455                 :  1175650841 :   if (type)
    2456                 :    27339578 :     type = cp_build_qualified_type (type, cp_type_quals (etype));
    2457                 :             :   else
    2458                 :             :     type = etype;
    2459                 :             : 
    2460                 :  1175650841 :   return type;
    2461                 :             : }
    2462                 :             : 
    2463                 :             : /* Perform the conversions in [expr] that apply when an lvalue appears
    2464                 :             :    in an rvalue context: the lvalue-to-rvalue, array-to-pointer, and
    2465                 :             :    function-to-pointer conversions.  In addition, bitfield references are
    2466                 :             :    converted to their declared types. Note that this function does not perform
    2467                 :             :    the lvalue-to-rvalue conversion for class types. If you need that conversion
    2468                 :             :    for class types, then you probably need to use force_rvalue.
    2469                 :             : 
    2470                 :             :    Although the returned value is being used as an rvalue, this
    2471                 :             :    function does not wrap the returned expression in a
    2472                 :             :    NON_LVALUE_EXPR; the caller is expected to be mindful of the fact
    2473                 :             :    that the return value is no longer an lvalue.  */
    2474                 :             : 
    2475                 :             : tree
    2476                 :   857612288 : decay_conversion (tree exp,
    2477                 :             :                   tsubst_flags_t complain,
    2478                 :             :                   bool reject_builtin /* = true */)
    2479                 :             : {
    2480                 :   857612288 :   tree type;
    2481                 :   857612288 :   enum tree_code code;
    2482                 :   857612288 :   location_t loc = cp_expr_loc_or_input_loc (exp);
    2483                 :             : 
    2484                 :   857612288 :   type = TREE_TYPE (exp);
    2485                 :   857612288 :   if (type == error_mark_node)
    2486                 :             :     return error_mark_node;
    2487                 :             : 
    2488                 :   857612082 :   exp = resolve_nondeduced_context_or_error (exp, complain);
    2489                 :             : 
    2490                 :   857612082 :   code = TREE_CODE (type);
    2491                 :             : 
    2492                 :   857612082 :   if (error_operand_p (exp))
    2493                 :          90 :     return error_mark_node;
    2494                 :             : 
    2495                 :   857611992 :   if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp))
    2496                 :             :     {
    2497                 :     1392025 :       mark_rvalue_use (exp, loc, reject_builtin);
    2498                 :     1392025 :       return nullptr_node;
    2499                 :             :     }
    2500                 :             : 
    2501                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    2502                 :             :      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
    2503                 :   856219967 :   if (code == VOID_TYPE)
    2504                 :             :     {
    2505                 :        5749 :       if (complain & tf_error)
    2506                 :           3 :         error_at (loc, "void value not ignored as it ought to be");
    2507                 :        5749 :       return error_mark_node;
    2508                 :             :     }
    2509                 :   856214218 :   if (invalid_nonstatic_memfn_p (loc, exp, complain))
    2510                 :           6 :     return error_mark_node;
    2511                 :   856214212 :   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
    2512                 :             :     {
    2513                 :    88055108 :       exp = mark_lvalue_use (exp);
    2514                 :    88055108 :       if (reject_builtin && reject_gcc_builtin (exp, loc))
    2515                 :         110 :         return error_mark_node;
    2516                 :    88054998 :       return cp_build_addr_expr (exp, complain);
    2517                 :             :     }
    2518                 :   768159104 :   if (code == ARRAY_TYPE)
    2519                 :             :     {
    2520                 :     4548409 :       tree adr;
    2521                 :     4548409 :       tree ptrtype;
    2522                 :             : 
    2523                 :     4548409 :       exp = mark_lvalue_use (exp);
    2524                 :             : 
    2525                 :     4548409 :       if (INDIRECT_REF_P (exp))
    2526                 :       85144 :         return build_nop (build_pointer_type (TREE_TYPE (type)),
    2527                 :      170288 :                           TREE_OPERAND (exp, 0));
    2528                 :             : 
    2529                 :     4463265 :       if (TREE_CODE (exp) == COMPOUND_EXPR)
    2530                 :             :         {
    2531                 :           3 :           tree op1 = decay_conversion (TREE_OPERAND (exp, 1), complain);
    2532                 :           3 :           if (op1 == error_mark_node)
    2533                 :             :             return error_mark_node;
    2534                 :           3 :           return build2 (COMPOUND_EXPR, TREE_TYPE (op1),
    2535                 :           6 :                          TREE_OPERAND (exp, 0), op1);
    2536                 :             :         }
    2537                 :             : 
    2538                 :     4463262 :       if (!obvalue_p (exp)
    2539                 :     4463262 :           && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
    2540                 :             :         {
    2541                 :           0 :           if (complain & tf_error)
    2542                 :           0 :             error_at (loc, "invalid use of non-lvalue array");
    2543                 :           0 :           return error_mark_node;
    2544                 :             :         }
    2545                 :             : 
    2546                 :     4463262 :       ptrtype = build_pointer_type (TREE_TYPE (type));
    2547                 :             : 
    2548                 :     4463262 :       if (VAR_P (exp))
    2549                 :             :         {
    2550                 :      476115 :           if (!cxx_mark_addressable (exp))
    2551                 :           0 :             return error_mark_node;
    2552                 :      476115 :           adr = build_nop (ptrtype, build_address (exp));
    2553                 :      476115 :           return adr;
    2554                 :             :         }
    2555                 :             :       /* This way is better for a COMPONENT_REF since it can
    2556                 :             :          simplify the offset for a component.  */
    2557                 :     3987147 :       adr = cp_build_addr_expr (exp, complain);
    2558                 :     3987147 :       return cp_convert (ptrtype, adr, complain);
    2559                 :             :     }
    2560                 :             : 
    2561                 :             :   /* Otherwise, it's the lvalue-to-rvalue conversion.  */
    2562                 :   763610695 :   exp = mark_rvalue_use (exp, loc, reject_builtin);
    2563                 :             : 
    2564                 :             :   /* If a bitfield is used in a context where integral promotion
    2565                 :             :      applies, then the caller is expected to have used
    2566                 :             :      default_conversion.  That function promotes bitfields correctly
    2567                 :             :      before calling this function.  At this point, if we have a
    2568                 :             :      bitfield referenced, we may assume that is not subject to
    2569                 :             :      promotion, and that, therefore, the type of the resulting rvalue
    2570                 :             :      is the declared type of the bitfield.  */
    2571                 :   763610695 :   exp = convert_bitfield_to_declared_type (exp);
    2572                 :             : 
    2573                 :             :   /* We do not call rvalue() here because we do not want to wrap EXP
    2574                 :             :      in a NON_LVALUE_EXPR.  */
    2575                 :             : 
    2576                 :             :   /* [basic.lval]
    2577                 :             : 
    2578                 :             :      Non-class rvalues always have cv-unqualified types.  */
    2579                 :   763610695 :   type = TREE_TYPE (exp);
    2580                 :   763610695 :   if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    2581                 :   240817238 :     exp = build_nop (cv_unqualified (type), exp);
    2582                 :             : 
    2583                 :   763610695 :   if (!complete_type_or_maybe_complain (type, exp, complain))
    2584                 :          42 :     return error_mark_node;
    2585                 :             : 
    2586                 :             :   return exp;
    2587                 :             : }
    2588                 :             : 
    2589                 :             : /* Perform preparatory conversions, as part of the "usual arithmetic
    2590                 :             :    conversions".  In particular, as per [expr]:
    2591                 :             : 
    2592                 :             :      Whenever an lvalue expression appears as an operand of an
    2593                 :             :      operator that expects the rvalue for that operand, the
    2594                 :             :      lvalue-to-rvalue, array-to-pointer, or function-to-pointer
    2595                 :             :      standard conversions are applied to convert the expression to an
    2596                 :             :      rvalue.
    2597                 :             : 
    2598                 :             :    In addition, we perform integral promotions here, as those are
    2599                 :             :    applied to both operands to a binary operator before determining
    2600                 :             :    what additional conversions should apply.  */
    2601                 :             : 
    2602                 :             : static tree
    2603                 :   241502357 : cp_default_conversion (tree exp, tsubst_flags_t complain)
    2604                 :             : {
    2605                 :             :   /* Check for target-specific promotions.  */
    2606                 :   241502357 :   tree promoted_type = targetm.promoted_type (TREE_TYPE (exp));
    2607                 :   241502357 :   if (promoted_type)
    2608                 :           0 :     exp = cp_convert (promoted_type, exp, complain);
    2609                 :             :   /* Perform the integral promotions first so that bitfield
    2610                 :             :      expressions (which may promote to "int", even if the bitfield is
    2611                 :             :      declared "unsigned") are promoted correctly.  */
    2612                 :   241502357 :   else if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
    2613                 :   157231491 :     exp = cp_perform_integral_promotions (exp, complain);
    2614                 :             :   /* Perform the other conversions.  */
    2615                 :   241502357 :   exp = decay_conversion (exp, complain);
    2616                 :             : 
    2617                 :   241502357 :   return exp;
    2618                 :             : }
    2619                 :             : 
    2620                 :             : /* C version.  */
    2621                 :             : 
    2622                 :             : tree
    2623                 :    25493690 : default_conversion (tree exp)
    2624                 :             : {
    2625                 :    25493690 :   return cp_default_conversion (exp, tf_warning_or_error);
    2626                 :             : }
    2627                 :             : 
    2628                 :             : /* EXPR is an expression with an integral or enumeration type.
    2629                 :             :    Perform the integral promotions in [conv.prom], and return the
    2630                 :             :    converted value.  */
    2631                 :             : 
    2632                 :             : tree
    2633                 :   165549660 : cp_perform_integral_promotions (tree expr, tsubst_flags_t complain)
    2634                 :             : {
    2635                 :   165549660 :   tree type;
    2636                 :   165549660 :   tree promoted_type;
    2637                 :             : 
    2638                 :   165549660 :   expr = mark_rvalue_use (expr);
    2639                 :   165549660 :   if (error_operand_p (expr))
    2640                 :           3 :     return error_mark_node;
    2641                 :             : 
    2642                 :   165549657 :   type = TREE_TYPE (expr);
    2643                 :             : 
    2644                 :             :   /* [conv.prom]
    2645                 :             : 
    2646                 :             :      A prvalue for an integral bit-field (11.3.9) can be converted to a prvalue
    2647                 :             :      of type int if int can represent all the values of the bit-field;
    2648                 :             :      otherwise, it can be converted to unsigned int if unsigned int can
    2649                 :             :      represent all the values of the bit-field. If the bit-field is larger yet,
    2650                 :             :      no integral promotion applies to it. If the bit-field has an enumerated
    2651                 :             :      type, it is treated as any other value of that type for promotion
    2652                 :             :      purposes.  */
    2653                 :   165549657 :   tree bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    2654                 :   165549657 :   if (bitfield_type
    2655                 :   165549657 :       && (TREE_CODE (bitfield_type) == ENUMERAL_TYPE
    2656                 :      242707 :           || TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)))
    2657                 :             :     type = bitfield_type;
    2658                 :             : 
    2659                 :   165549657 :   gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type));
    2660                 :             :   /* Scoped enums don't promote.  */
    2661                 :   165549657 :   if (SCOPED_ENUM_P (type))
    2662                 :             :     return expr;
    2663                 :   165127150 :   promoted_type = type_promotes_to (type);
    2664                 :   165127150 :   if (type != promoted_type)
    2665                 :    49733326 :     expr = cp_convert (promoted_type, expr, complain);
    2666                 :   115393824 :   else if (bitfield_type && bitfield_type != type)
    2667                 :             :     /* Prevent decay_conversion from converting to bitfield_type.  */
    2668                 :         159 :     expr = build_nop (type, expr);
    2669                 :             :   return expr;
    2670                 :             : }
    2671                 :             : 
    2672                 :             : /* C version.  */
    2673                 :             : 
    2674                 :             : tree
    2675                 :     1697032 : perform_integral_promotions (tree expr)
    2676                 :             : {
    2677                 :     1697032 :   return cp_perform_integral_promotions (expr, tf_warning_or_error);
    2678                 :             : }
    2679                 :             : 
    2680                 :             : /* Returns nonzero iff exp is a STRING_CST or the result of applying
    2681                 :             :    decay_conversion to one.  */
    2682                 :             : 
    2683                 :             : int
    2684                 :     3109987 : string_conv_p (const_tree totype, const_tree exp, int warn)
    2685                 :             : {
    2686                 :     3109987 :   tree t;
    2687                 :             : 
    2688                 :     3109987 :   if (!TYPE_PTR_P (totype))
    2689                 :             :     return 0;
    2690                 :             : 
    2691                 :     3109936 :   t = TREE_TYPE (totype);
    2692                 :     3109936 :   if (!same_type_p (t, char_type_node)
    2693                 :     2955182 :       && !same_type_p (t, char8_type_node)
    2694                 :     2936557 :       && !same_type_p (t, char16_type_node)
    2695                 :     2877368 :       && !same_type_p (t, char32_type_node)
    2696                 :     5928117 :       && !same_type_p (t, wchar_type_node))
    2697                 :             :     return 0;
    2698                 :             : 
    2699                 :      341112 :   location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
    2700                 :             : 
    2701                 :      341112 :   STRIP_ANY_LOCATION_WRAPPER (exp);
    2702                 :             : 
    2703                 :      341112 :   if (TREE_CODE (exp) == STRING_CST)
    2704                 :             :     {
    2705                 :             :       /* Make sure that we don't try to convert between char and wide chars.  */
    2706                 :         108 :       if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t))
    2707                 :             :         return 0;
    2708                 :             :     }
    2709                 :             :   else
    2710                 :             :     {
    2711                 :             :       /* Is this a string constant which has decayed to 'const char *'?  */
    2712                 :      341004 :       t = build_pointer_type (cp_build_qualified_type (t, TYPE_QUAL_CONST));
    2713                 :      341004 :       if (!same_type_p (TREE_TYPE (exp), t))
    2714                 :             :         return 0;
    2715                 :       61018 :       STRIP_NOPS (exp);
    2716                 :       61018 :       if (TREE_CODE (exp) != ADDR_EXPR
    2717                 :       61018 :           || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
    2718                 :             :         return 0;
    2719                 :             :     }
    2720                 :         306 :   if (warn)
    2721                 :             :     {
    2722                 :         102 :       if (cxx_dialect >= cxx11)
    2723                 :          87 :         pedwarn (loc, OPT_Wwrite_strings,
    2724                 :             :                  "ISO C++ forbids converting a string constant to %qT",
    2725                 :             :                  totype);
    2726                 :             :       else
    2727                 :          15 :         warning_at (loc, OPT_Wwrite_strings,
    2728                 :             :                     "deprecated conversion from string constant to %qT",
    2729                 :             :                     totype);
    2730                 :             :     }
    2731                 :             : 
    2732                 :             :   return 1;
    2733                 :             : }
    2734                 :             : 
    2735                 :             : /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
    2736                 :             :    can, for example, use as an lvalue.  This code used to be in
    2737                 :             :    unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
    2738                 :             :    expressions, where we're dealing with aggregates.  But now it's again only
    2739                 :             :    called from unary_complex_lvalue.  The case (in particular) that led to
    2740                 :             :    this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
    2741                 :             :    get it there.  */
    2742                 :             : 
    2743                 :             : static tree
    2744                 :       89432 : rationalize_conditional_expr (enum tree_code code, tree t,
    2745                 :             :                               tsubst_flags_t complain)
    2746                 :             : {
    2747                 :       89432 :   location_t loc = cp_expr_loc_or_input_loc (t);
    2748                 :             : 
    2749                 :             :   /* For MIN_EXPR or MAX_EXPR, fold-const.cc has arranged things so that
    2750                 :             :      the first operand is always the one to be used if both operands
    2751                 :             :      are equal, so we know what conditional expression this used to be.  */
    2752                 :       89432 :   if (TREE_CODE (t) == MIN_EXPR || TREE_CODE (t) == MAX_EXPR)
    2753                 :             :     {
    2754                 :           0 :       tree op0 = TREE_OPERAND (t, 0);
    2755                 :           0 :       tree op1 = TREE_OPERAND (t, 1);
    2756                 :             : 
    2757                 :             :       /* The following code is incorrect if either operand side-effects.  */
    2758                 :           0 :       gcc_assert (!TREE_SIDE_EFFECTS (op0)
    2759                 :             :                   && !TREE_SIDE_EFFECTS (op1));
    2760                 :           0 :       return
    2761                 :           0 :         build_conditional_expr (loc,
    2762                 :             :                                 build_x_binary_op (loc,
    2763                 :           0 :                                                    (TREE_CODE (t) == MIN_EXPR
    2764                 :             :                                                     ? LE_EXPR : GE_EXPR),
    2765                 :           0 :                                                    op0, TREE_CODE (op0),
    2766                 :           0 :                                                    op1, TREE_CODE (op1),
    2767                 :             :                                                    NULL_TREE,
    2768                 :             :                                                    /*overload=*/NULL,
    2769                 :             :                                                    complain),
    2770                 :             :                                 cp_build_unary_op (code, op0, false, complain),
    2771                 :             :                                 cp_build_unary_op (code, op1, false, complain),
    2772                 :             :                                 complain);
    2773                 :             :     }
    2774                 :             : 
    2775                 :       89432 :   tree op1 = TREE_OPERAND (t, 1);
    2776                 :       89432 :   if (TREE_CODE (op1) != THROW_EXPR)
    2777                 :       89429 :     op1 = cp_build_unary_op (code, op1, false, complain);
    2778                 :       89432 :   tree op2 = TREE_OPERAND (t, 2);
    2779                 :       89432 :   if (TREE_CODE (op2) != THROW_EXPR)
    2780                 :       89426 :     op2 = cp_build_unary_op (code, op2, false, complain);
    2781                 :             : 
    2782                 :       89432 :   return
    2783                 :       89432 :     build_conditional_expr (loc, TREE_OPERAND (t, 0), op1, op2, complain);
    2784                 :             : }
    2785                 :             : 
    2786                 :             : /* Given the TYPE of an anonymous union field inside T, return the
    2787                 :             :    FIELD_DECL for the field.  If not found return NULL_TREE.  Because
    2788                 :             :    anonymous unions can nest, we must also search all anonymous unions
    2789                 :             :    that are directly reachable.  */
    2790                 :             : 
    2791                 :             : tree
    2792                 :     1004058 : lookup_anon_field (tree, tree type)
    2793                 :             : {
    2794                 :     1004058 :   tree field;
    2795                 :             : 
    2796                 :     1004058 :   type = TYPE_MAIN_VARIANT (type);
    2797                 :     1004058 :   field = ANON_AGGR_TYPE_FIELD (type);
    2798                 :     1004058 :   gcc_assert (field);
    2799                 :     1004058 :   return field;
    2800                 :             : }
    2801                 :             : 
    2802                 :             : /* Build an expression representing OBJECT.MEMBER.  OBJECT is an
    2803                 :             :    expression; MEMBER is a DECL or baselink.  If ACCESS_PATH is
    2804                 :             :    non-NULL, it indicates the path to the base used to name MEMBER.
    2805                 :             :    If PRESERVE_REFERENCE is true, the expression returned will have
    2806                 :             :    REFERENCE_TYPE if the MEMBER does.  Otherwise, the expression
    2807                 :             :    returned will have the type referred to by the reference.
    2808                 :             : 
    2809                 :             :    This function does not perform access control; that is either done
    2810                 :             :    earlier by the parser when the name of MEMBER is resolved to MEMBER
    2811                 :             :    itself, or later when overload resolution selects one of the
    2812                 :             :    functions indicated by MEMBER.  */
    2813                 :             : 
    2814                 :             : tree
    2815                 :    94709378 : build_class_member_access_expr (cp_expr object, tree member,
    2816                 :             :                                 tree access_path, bool preserve_reference,
    2817                 :             :                                 tsubst_flags_t complain)
    2818                 :             : {
    2819                 :    94709378 :   tree object_type;
    2820                 :    94709378 :   tree member_scope;
    2821                 :    94709378 :   tree result = NULL_TREE;
    2822                 :    94709378 :   tree using_decl = NULL_TREE;
    2823                 :             : 
    2824                 :    94709378 :   if (error_operand_p (object) || error_operand_p (member))
    2825                 :          48 :     return error_mark_node;
    2826                 :             : 
    2827                 :    94709330 :   gcc_assert (DECL_P (member) || BASELINK_P (member));
    2828                 :             : 
    2829                 :             :   /* [expr.ref]
    2830                 :             : 
    2831                 :             :      The type of the first expression shall be "class object" (of a
    2832                 :             :      complete type).  */
    2833                 :    94709330 :   object_type = TREE_TYPE (object);
    2834                 :    94709330 :   if (!currently_open_class (object_type)
    2835                 :    94709330 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    2836                 :           0 :     return error_mark_node;
    2837                 :    94709330 :   if (!CLASS_TYPE_P (object_type))
    2838                 :             :     {
    2839                 :           0 :       if (complain & tf_error)
    2840                 :             :         {
    2841                 :           0 :           if (INDIRECT_TYPE_P (object_type)
    2842                 :           0 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    2843                 :           0 :             error ("request for member %qD in %qE, which is of pointer "
    2844                 :             :                    "type %qT (maybe you meant to use %<->%> ?)",
    2845                 :             :                    member, object.get_value (), object_type);
    2846                 :             :           else
    2847                 :           0 :             error ("request for member %qD in %qE, which is of non-class "
    2848                 :             :                    "type %qT", member, object.get_value (), object_type);
    2849                 :             :         }
    2850                 :           0 :       return error_mark_node;
    2851                 :             :     }
    2852                 :             : 
    2853                 :             :   /* The standard does not seem to actually say that MEMBER must be a
    2854                 :             :      member of OBJECT_TYPE.  However, that is clearly what is
    2855                 :             :      intended.  */
    2856                 :    94709330 :   if (DECL_P (member))
    2857                 :             :     {
    2858                 :    40336330 :       member_scope = DECL_CLASS_CONTEXT (member);
    2859                 :    40336330 :       if (!mark_used (member, complain) && !(complain & tf_error))
    2860                 :           0 :         return error_mark_node;
    2861                 :             : 
    2862                 :    40336330 :       if (TREE_UNAVAILABLE (member))
    2863                 :          30 :         error_unavailable_use (member, NULL_TREE);
    2864                 :    40336300 :       else if (TREE_DEPRECATED (member))
    2865                 :          30 :         warn_deprecated_use (member, NULL_TREE);
    2866                 :             :     }
    2867                 :             :   else
    2868                 :    54373000 :     member_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (member));
    2869                 :             :   /* If MEMBER is from an anonymous aggregate, MEMBER_SCOPE will
    2870                 :             :      presently be the anonymous union.  Go outwards until we find a
    2871                 :             :      type related to OBJECT_TYPE.  */
    2872                 :    95717102 :   while ((ANON_AGGR_TYPE_P (member_scope) || UNSCOPED_ENUM_P (member_scope))
    2873                 :    96725248 :          && !same_type_ignoring_top_level_qualifiers_p (member_scope,
    2874                 :             :                                                         object_type))
    2875                 :     1007772 :     member_scope = TYPE_CONTEXT (member_scope);
    2876                 :    94709330 :   if (!member_scope || !DERIVED_FROM_P (member_scope, object_type))
    2877                 :             :     {
    2878                 :           3 :       if (complain & tf_error)
    2879                 :             :         {
    2880                 :           3 :           if (TREE_CODE (member) == FIELD_DECL)
    2881                 :           0 :             error ("invalid use of non-static data member %qE", member);
    2882                 :             :           else
    2883                 :           3 :             error ("%qD is not a member of %qT", member, object_type);
    2884                 :             :         }
    2885                 :           3 :       return error_mark_node;
    2886                 :             :     }
    2887                 :             : 
    2888                 :             :   /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x' into
    2889                 :             :      `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only an lvalue
    2890                 :             :      in the front end; only _DECLs and _REFs are lvalues in the back end.  */
    2891                 :    94709327 :   if (tree temp = unary_complex_lvalue (ADDR_EXPR, object))
    2892                 :             :     {
    2893                 :          38 :       temp = cp_build_fold_indirect_ref (temp);
    2894                 :          38 :       if (!lvalue_p (object) && lvalue_p (temp))
    2895                 :             :         /* Preserve rvalueness.  */
    2896                 :           6 :         temp = move (temp);
    2897                 :          38 :       object = temp;
    2898                 :             :     }
    2899                 :             : 
    2900                 :             :   /* In [expr.ref], there is an explicit list of the valid choices for
    2901                 :             :      MEMBER.  We check for each of those cases here.  */
    2902                 :    94709327 :   if (VAR_P (member))
    2903                 :             :     {
    2904                 :             :       /* A static data member.  */
    2905                 :       87237 :       result = member;
    2906                 :       87237 :       mark_exp_read (object);
    2907                 :             : 
    2908                 :       87237 :       if (tree wrap = maybe_get_tls_wrapper_call (result))
    2909                 :             :         /* Replace an evaluated use of the thread_local variable with
    2910                 :             :            a call to its wrapper.  */
    2911                 :         102 :         result = wrap;
    2912                 :             : 
    2913                 :             :       /* If OBJECT has side-effects, they are supposed to occur.  */
    2914                 :       87237 :       if (TREE_SIDE_EFFECTS (object))
    2915                 :          51 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);
    2916                 :             :     }
    2917                 :    94622090 :   else if (TREE_CODE (member) == FIELD_DECL)
    2918                 :             :     {
    2919                 :             :       /* A non-static data member.  */
    2920                 :    40248967 :       bool null_object_p;
    2921                 :    40248967 :       int type_quals;
    2922                 :    40248967 :       tree member_type;
    2923                 :             : 
    2924                 :    40248967 :       if (INDIRECT_REF_P (object))
    2925                 :    30236571 :         null_object_p =
    2926                 :    30236571 :           integer_zerop (tree_strip_nop_conversions (TREE_OPERAND (object, 0)));
    2927                 :             :       else
    2928                 :             :         null_object_p = false;
    2929                 :             : 
    2930                 :             :       /* Convert OBJECT to the type of MEMBER.  */
    2931                 :    40248967 :       if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
    2932                 :             :                         TYPE_MAIN_VARIANT (member_scope)))
    2933                 :             :         {
    2934                 :     1674317 :           tree binfo;
    2935                 :     1674317 :           base_kind kind;
    2936                 :             : 
    2937                 :             :           /* We didn't complain above about a currently open class, but now we
    2938                 :             :              must: we don't know how to refer to a base member before layout is
    2939                 :             :              complete.  But still don't complain in a template.  */
    2940                 :     1674317 :           if (!cp_unevaluated_operand
    2941                 :     1674164 :               && !dependent_type_p (object_type)
    2942                 :     3069860 :               && !complete_type_or_maybe_complain (object_type, object,
    2943                 :             :                                                    complain))
    2944                 :           9 :             return error_mark_node;
    2945                 :             : 
    2946                 :     2117279 :           binfo = lookup_base (access_path ? access_path : object_type,
    2947                 :             :                                member_scope, ba_unique, &kind, complain);
    2948                 :     1674314 :           if (binfo == error_mark_node)
    2949                 :             :             return error_mark_node;
    2950                 :             : 
    2951                 :             :           /* It is invalid to try to get to a virtual base of a
    2952                 :             :              NULL object.  The most common cause is invalid use of
    2953                 :             :              offsetof macro.  */
    2954                 :     1674314 :           if (null_object_p && kind == bk_via_virtual)
    2955                 :             :             {
    2956                 :           6 :               if (complain & tf_error)
    2957                 :             :                 {
    2958                 :           6 :                   error ("invalid access to non-static data member %qD in "
    2959                 :             :                          "virtual base of NULL object", member);
    2960                 :             :                 }
    2961                 :           6 :               return error_mark_node;
    2962                 :             :             }
    2963                 :             : 
    2964                 :             :           /* Convert to the base.  */
    2965                 :     1674308 :           object = build_base_path (PLUS_EXPR, object, binfo,
    2966                 :             :                                     /*nonnull=*/1, complain);
    2967                 :             :           /* If we found the base successfully then we should be able
    2968                 :             :              to convert to it successfully.  */
    2969                 :     1674308 :           gcc_assert (object != error_mark_node);
    2970                 :             :         }
    2971                 :             : 
    2972                 :             :       /* If MEMBER is from an anonymous aggregate, we have converted
    2973                 :             :          OBJECT so that it refers to the class containing the
    2974                 :             :          anonymous union.  Generate a reference to the anonymous union
    2975                 :             :          itself, and recur to find MEMBER.  */
    2976                 :    80497916 :       if (ANON_AGGR_TYPE_P (DECL_CONTEXT (member))
    2977                 :             :           /* When this code is called from build_field_call, the
    2978                 :             :              object already has the type of the anonymous union.
    2979                 :             :              That is because the COMPONENT_REF was already
    2980                 :             :              constructed, and was then disassembled before calling
    2981                 :             :              build_field_call.  After the function-call code is
    2982                 :             :              cleaned up, this waste can be eliminated.  */
    2983                 :    41253231 :           && (!same_type_ignoring_top_level_qualifiers_p
    2984                 :     1004273 :               (TREE_TYPE (object), DECL_CONTEXT (member))))
    2985                 :             :         {
    2986                 :     1003902 :           tree anonymous_union;
    2987                 :             : 
    2988                 :     1003902 :           anonymous_union = lookup_anon_field (TREE_TYPE (object),
    2989                 :     1003902 :                                                DECL_CONTEXT (member));
    2990                 :     1003902 :           object = build_class_member_access_expr (object,
    2991                 :             :                                                    anonymous_union,
    2992                 :             :                                                    /*access_path=*/NULL_TREE,
    2993                 :             :                                                    preserve_reference,
    2994                 :             :                                                    complain);
    2995                 :             :         }
    2996                 :             : 
    2997                 :             :       /* Compute the type of the field, as described in [expr.ref].  */
    2998                 :    40248958 :       type_quals = TYPE_UNQUALIFIED;
    2999                 :    40248958 :       member_type = TREE_TYPE (member);
    3000                 :    40248958 :       if (!TYPE_REF_P (member_type))
    3001                 :             :         {
    3002                 :    39494209 :           type_quals = (cp_type_quals (member_type)
    3003                 :    39494209 :                         | cp_type_quals (object_type));
    3004                 :             : 
    3005                 :             :           /* A field is const (volatile) if the enclosing object, or the
    3006                 :             :              field itself, is const (volatile).  But, a mutable field is
    3007                 :             :              not const, even within a const object.  */
    3008                 :    39494209 :           if (DECL_MUTABLE_P (member))
    3009                 :      323131 :             type_quals &= ~TYPE_QUAL_CONST;
    3010                 :    39494209 :           member_type = cp_build_qualified_type (member_type, type_quals);
    3011                 :             :         }
    3012                 :             : 
    3013                 :    40248958 :       result = build3_loc (input_location, COMPONENT_REF, member_type,
    3014                 :             :                            object, member, NULL_TREE);
    3015                 :             : 
    3016                 :             :       /* Mark the expression const or volatile, as appropriate.  Even
    3017                 :             :          though we've dealt with the type above, we still have to mark the
    3018                 :             :          expression itself.  */
    3019                 :    40248958 :       if (type_quals & TYPE_QUAL_CONST)
    3020                 :    12794420 :         TREE_READONLY (result) = 1;
    3021                 :    40248958 :       if (type_quals & TYPE_QUAL_VOLATILE)
    3022                 :      188611 :         TREE_THIS_VOLATILE (result) = 1;
    3023                 :             :     }
    3024                 :    54373123 :   else if (BASELINK_P (member))
    3025                 :             :     {
    3026                 :             :       /* The member is a (possibly overloaded) member function.  */
    3027                 :    54372997 :       tree functions;
    3028                 :    54372997 :       tree type;
    3029                 :             : 
    3030                 :             :       /* If the MEMBER is exactly one static member function, then we
    3031                 :             :          know the type of the expression.  Otherwise, we must wait
    3032                 :             :          until overload resolution has been performed.  */
    3033                 :    54372997 :       functions = BASELINK_FUNCTIONS (member);
    3034                 :    54372997 :       if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
    3035                 :    54372997 :         functions = OVL_FIRST (functions);
    3036                 :    54372997 :       if (TREE_CODE (functions) == FUNCTION_DECL
    3037                 :    54372997 :           && DECL_STATIC_FUNCTION_P (functions))
    3038                 :      423161 :         type = TREE_TYPE (functions);
    3039                 :             :       else
    3040                 :    53949836 :         type = unknown_type_node;
    3041                 :             :       /* Note that we do not convert OBJECT to the BASELINK_BINFO
    3042                 :             :          base.  That will happen when the function is called.  */
    3043                 :    54372997 :       result = build3_loc (input_location, COMPONENT_REF, type, object, member,
    3044                 :             :                            NULL_TREE);
    3045                 :             :     }
    3046                 :         126 :   else if (TREE_CODE (member) == CONST_DECL)
    3047                 :             :     {
    3048                 :             :       /* The member is an enumerator.  */
    3049                 :         110 :       result = member;
    3050                 :             :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3051                 :         110 :       if (TREE_SIDE_EFFECTS (object))
    3052                 :           6 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    3053                 :             :                          object, result);
    3054                 :             :     }
    3055                 :          16 :   else if ((using_decl = strip_using_decl (member)) != member)
    3056                 :           0 :     result = build_class_member_access_expr (object,
    3057                 :             :                                              using_decl,
    3058                 :             :                                              access_path, preserve_reference,
    3059                 :             :                                              complain);
    3060                 :             :   else
    3061                 :             :     {
    3062                 :          16 :       if (complain & tf_error)
    3063                 :          12 :         error ("invalid use of %qD", member);
    3064                 :          16 :       return error_mark_node;
    3065                 :             :     }
    3066                 :             : 
    3067                 :    94709302 :   if (!preserve_reference)
    3068                 :             :     /* [expr.ref]
    3069                 :             : 
    3070                 :             :        If E2 is declared to have type "reference to T", then ... the
    3071                 :             :        type of E1.E2 is T.  */
    3072                 :    89598204 :     result = convert_from_reference (result);
    3073                 :             : 
    3074                 :             :   return result;
    3075                 :             : }
    3076                 :             : 
    3077                 :             : /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
    3078                 :             :    SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
    3079                 :             : 
    3080                 :             : tree
    3081                 :      144150 : lookup_destructor (tree object, tree scope, tree dtor_name,
    3082                 :             :                    tsubst_flags_t complain)
    3083                 :             : {
    3084                 :      144150 :   tree object_type = TREE_TYPE (object);
    3085                 :      144150 :   tree dtor_type = TREE_OPERAND (dtor_name, 0);
    3086                 :      144150 :   tree expr;
    3087                 :             : 
    3088                 :             :   /* We've already complained about this destructor.  */
    3089                 :      144150 :   if (dtor_type == error_mark_node)
    3090                 :             :     return error_mark_node;
    3091                 :             : 
    3092                 :      144144 :   if (scope && !check_dtor_name (scope, dtor_type))
    3093                 :             :     {
    3094                 :           3 :       if (complain & tf_error)
    3095                 :           3 :         error ("qualified type %qT does not match destructor name ~%qT",
    3096                 :             :                scope, dtor_type);
    3097                 :           3 :       return error_mark_node;
    3098                 :             :     }
    3099                 :      144141 :   if (is_auto (dtor_type))
    3100                 :             :     dtor_type = object_type;
    3101                 :      144138 :   else if (identifier_p (dtor_type))
    3102                 :             :     {
    3103                 :             :       /* In a template, names we can't find a match for are still accepted
    3104                 :             :          destructor names, and we check them here.  */
    3105                 :          23 :       if (check_dtor_name (object_type, dtor_type))
    3106                 :             :         dtor_type = object_type;
    3107                 :             :       else
    3108                 :             :         {
    3109                 :           3 :           if (complain & tf_error)
    3110                 :           3 :             error ("object type %qT does not match destructor name ~%qT",
    3111                 :             :                    object_type, dtor_type);
    3112                 :           3 :           return error_mark_node;
    3113                 :             :         }
    3114                 :             :       
    3115                 :             :     }
    3116                 :      144115 :   else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
    3117                 :             :     {
    3118                 :           6 :       if (complain & tf_error)
    3119                 :           6 :         error ("the type being destroyed is %qT, but the destructor "
    3120                 :           6 :                "refers to %qT", TYPE_MAIN_VARIANT (object_type), dtor_type);
    3121                 :           6 :       return error_mark_node;
    3122                 :             :     }
    3123                 :      144132 :   expr = lookup_member (dtor_type, complete_dtor_identifier,
    3124                 :             :                         /*protect=*/1, /*want_type=*/false,
    3125                 :             :                         tf_warning_or_error);
    3126                 :      144132 :   if (!expr)
    3127                 :             :     {
    3128                 :           6 :       if (complain & tf_error)
    3129                 :           6 :         cxx_incomplete_type_error (dtor_name, dtor_type);
    3130                 :           6 :       return error_mark_node;
    3131                 :             :     }
    3132                 :      144126 :   expr = (adjust_result_of_qualified_name_lookup
    3133                 :      144126 :           (expr, dtor_type, object_type));
    3134                 :      144126 :   if (scope == NULL_TREE)
    3135                 :             :     /* We need to call adjust_result_of_qualified_name_lookup in case the
    3136                 :             :        destructor names a base class, but we unset BASELINK_QUALIFIED_P so
    3137                 :             :        that we still get virtual function binding.  */
    3138                 :      143983 :     BASELINK_QUALIFIED_P (expr) = false;
    3139                 :             :   return expr;
    3140                 :             : }
    3141                 :             : 
    3142                 :             : /* An expression of the form "A::template B" has been resolved to
    3143                 :             :    DECL.  Issue a diagnostic if B is not a template or template
    3144                 :             :    specialization.  */
    3145                 :             : 
    3146                 :             : void
    3147                 :     3197430 : check_template_keyword (tree decl)
    3148                 :             : {
    3149                 :             :   /* The standard says:
    3150                 :             : 
    3151                 :             :       [temp.names]
    3152                 :             : 
    3153                 :             :       If a name prefixed by the keyword template is not a member
    3154                 :             :       template, the program is ill-formed.
    3155                 :             : 
    3156                 :             :      DR 228 removed the restriction that the template be a member
    3157                 :             :      template.
    3158                 :             : 
    3159                 :             :      DR 96, if accepted would add the further restriction that explicit
    3160                 :             :      template arguments must be provided if the template keyword is
    3161                 :             :      used, but, as of 2005-10-16, that DR is still in "drafting".  If
    3162                 :             :      this DR is accepted, then the semantic checks here can be
    3163                 :             :      simplified, as the entity named must in fact be a template
    3164                 :             :      specialization, rather than, as at present, a set of overloaded
    3165                 :             :      functions containing at least one template function.  */
    3166                 :     3197430 :   if (TREE_CODE (decl) != TEMPLATE_DECL
    3167                 :     3197430 :       && TREE_CODE (decl) != TEMPLATE_ID_EXPR)
    3168                 :             :     {
    3169                 :     2960163 :       if (VAR_P (decl))
    3170                 :             :         {
    3171                 :        9755 :           if (DECL_USE_TEMPLATE (decl)
    3172                 :        9755 :               && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
    3173                 :             :             ;
    3174                 :             :           else
    3175                 :           0 :             permerror (input_location, "%qD is not a template", decl);
    3176                 :             :         }
    3177                 :     2950408 :       else if (!is_overloaded_fn (decl))
    3178                 :           0 :         permerror (input_location, "%qD is not a template", decl);
    3179                 :             :       else
    3180                 :             :         {
    3181                 :     2950408 :           bool found = false;
    3182                 :             : 
    3183                 :     5900816 :           for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl));
    3184                 :     5900818 :                !found && iter; ++iter)
    3185                 :             :             {
    3186                 :     2950410 :               tree fn = *iter;
    3187                 :     2950410 :               if (TREE_CODE (fn) == TEMPLATE_DECL
    3188                 :     2950014 :                   || TREE_CODE (fn) == TEMPLATE_ID_EXPR
    3189                 :     2950424 :                   || (TREE_CODE (fn) == FUNCTION_DECL
    3190                 :          14 :                       && DECL_USE_TEMPLATE (fn)
    3191                 :           6 :                       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (fn))))
    3192                 :             :                 found = true;
    3193                 :             :             }
    3194                 :     2950408 :           if (!found)
    3195                 :          12 :             permerror (input_location, "%qD is not a template", decl);
    3196                 :             :         }
    3197                 :             :     }
    3198                 :     3197430 : }
    3199                 :             : 
    3200                 :             : /* Record that an access failure occurred on BASETYPE_PATH attempting
    3201                 :             :    to access DECL, where DIAG_DECL should be used for diagnostics.  */
    3202                 :             : 
    3203                 :             : void
    3204                 :         406 : access_failure_info::record_access_failure (tree basetype_path,
    3205                 :             :                                             tree decl, tree diag_decl)
    3206                 :             : {
    3207                 :         406 :   m_was_inaccessible = true;
    3208                 :         406 :   m_basetype_path = basetype_path;
    3209                 :         406 :   m_decl = decl;
    3210                 :         406 :   m_diag_decl = diag_decl;
    3211                 :         406 : }
    3212                 :             : 
    3213                 :             : /* If an access failure was recorded, then attempt to locate an
    3214                 :             :    accessor function for the pertinent field.
    3215                 :             :    Otherwise, return NULL_TREE.  */
    3216                 :             : 
    3217                 :             : tree
    3218                 :    79925580 : access_failure_info::get_any_accessor (bool const_p) const
    3219                 :             : {
    3220                 :    79925580 :   if (!was_inaccessible_p ())
    3221                 :             :     return NULL_TREE;
    3222                 :             : 
    3223                 :         406 :   tree accessor
    3224                 :         406 :     = locate_field_accessor (m_basetype_path, m_diag_decl, const_p);
    3225                 :         406 :   if (!accessor)
    3226                 :             :     return NULL_TREE;
    3227                 :             : 
    3228                 :             :   /* The accessor must itself be accessible for it to be a reasonable
    3229                 :             :      suggestion.  */
    3230                 :         161 :   if (!accessible_p (m_basetype_path, accessor, true))
    3231                 :             :     return NULL_TREE;
    3232                 :             : 
    3233                 :             :   return accessor;
    3234                 :             : }
    3235                 :             : 
    3236                 :             : /* Add a fix-it hint to RICHLOC suggesting the use of ACCESSOR_DECL, by
    3237                 :             :    replacing the primary location in RICHLOC with "accessor()".  */
    3238                 :             : 
    3239                 :             : void
    3240                 :         140 : access_failure_info::add_fixit_hint (rich_location *richloc,
    3241                 :             :                                      tree accessor_decl)
    3242                 :             : {
    3243                 :         140 :   pretty_printer pp;
    3244                 :         140 :   pp_string (&pp, IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
    3245                 :         140 :   pp_string (&pp, "()");
    3246                 :         140 :   richloc->add_fixit_replace (pp_formatted_text (&pp));
    3247                 :         140 : }
    3248                 :             : 
    3249                 :             : /* If an access failure was recorded, then attempt to locate an
    3250                 :             :    accessor function for the pertinent field, and if one is
    3251                 :             :    available, add a note and fix-it hint suggesting using it.  */
    3252                 :             : 
    3253                 :             : void
    3254                 :    79925510 : access_failure_info::maybe_suggest_accessor (bool const_p) const
    3255                 :             : {
    3256                 :    79925510 :   tree accessor = get_any_accessor (const_p);
    3257                 :    79925510 :   if (accessor == NULL_TREE)
    3258                 :    79925412 :     return;
    3259                 :          98 :   rich_location richloc (line_table, input_location);
    3260                 :          98 :   add_fixit_hint (&richloc, accessor);
    3261                 :          98 :   inform (&richloc, "field %q#D can be accessed via %q#D",
    3262                 :          98 :           m_diag_decl, accessor);
    3263                 :          98 : }
    3264                 :             : 
    3265                 :             : /* Subroutine of finish_class_member_access_expr.
    3266                 :             :    Issue an error about NAME not being a member of ACCESS_PATH (or
    3267                 :             :    OBJECT_TYPE), potentially providing a fix-it hint for misspelled
    3268                 :             :    names.  */
    3269                 :             : 
    3270                 :             : static void
    3271                 :         263 : complain_about_unrecognized_member (tree access_path, tree name,
    3272                 :             :                                     tree object_type)
    3273                 :             : {
    3274                 :             :   /* Attempt to provide a hint about misspelled names.  */
    3275                 :         263 :   tree guessed_id = lookup_member_fuzzy (access_path, name,
    3276                 :             :                                          /*want_type=*/false);
    3277                 :         263 :   if (guessed_id == NULL_TREE)
    3278                 :             :     {
    3279                 :             :       /* No hint.  */
    3280                 :         153 :       error ("%q#T has no member named %qE",
    3281                 :         153 :              TREE_CODE (access_path) == TREE_BINFO
    3282                 :           6 :              ? TREE_TYPE (access_path) : object_type, name);
    3283                 :         153 :       return;
    3284                 :             :     }
    3285                 :             : 
    3286                 :         110 :   location_t bogus_component_loc = input_location;
    3287                 :         110 :   gcc_rich_location rich_loc (bogus_component_loc);
    3288                 :             : 
    3289                 :             :   /* Check that the guessed name is accessible along access_path.  */
    3290                 :         110 :   access_failure_info afi;
    3291                 :         110 :   lookup_member (access_path, guessed_id, /*protect=*/1,
    3292                 :             :                  /*want_type=*/false, /*complain=*/false,
    3293                 :             :                  &afi);
    3294                 :         110 :   if (afi.was_inaccessible_p ())
    3295                 :             :     {
    3296                 :          70 :       tree accessor = afi.get_any_accessor (TYPE_READONLY (object_type));
    3297                 :          70 :       if (accessor)
    3298                 :             :         {
    3299                 :             :           /* The guessed name isn't directly accessible, but can be accessed
    3300                 :             :              via an accessor member function.  */
    3301                 :          42 :           afi.add_fixit_hint (&rich_loc, accessor);
    3302                 :          42 :           error_at (&rich_loc,
    3303                 :             :                     "%q#T has no member named %qE;"
    3304                 :             :                     " did you mean %q#D? (accessible via %q#D)",
    3305                 :          42 :                     TREE_CODE (access_path) == TREE_BINFO
    3306                 :           0 :                     ? TREE_TYPE (access_path) : object_type,
    3307                 :             :                     name, afi.get_diag_decl (), accessor);
    3308                 :             :         }
    3309                 :             :       else
    3310                 :             :         {
    3311                 :             :           /* The guessed name isn't directly accessible, and no accessor
    3312                 :             :              member function could be found.  */
    3313                 :          28 :           auto_diagnostic_group d;
    3314                 :          28 :           error_at (&rich_loc,
    3315                 :             :                     "%q#T has no member named %qE;"
    3316                 :             :                     " did you mean %q#D? (not accessible from this context)",
    3317                 :          28 :                     TREE_CODE (access_path) == TREE_BINFO
    3318                 :           0 :                     ? TREE_TYPE (access_path) : object_type,
    3319                 :             :                     name, afi.get_diag_decl ());
    3320                 :          28 :           complain_about_access (afi.get_decl (), afi.get_diag_decl (),
    3321                 :             :                                  afi.get_diag_decl (), false, ak_none);
    3322                 :          28 :         }
    3323                 :             :     }
    3324                 :             :   else
    3325                 :             :     {
    3326                 :             :       /* The guessed name is directly accessible; suggest it.  */
    3327                 :          40 :       rich_loc.add_fixit_misspelled_id (bogus_component_loc,
    3328                 :             :                                         guessed_id);
    3329                 :          40 :       error_at (&rich_loc,
    3330                 :             :                 "%q#T has no member named %qE;"
    3331                 :             :                 " did you mean %qE?",
    3332                 :          40 :                 TREE_CODE (access_path) == TREE_BINFO
    3333                 :           0 :                 ? TREE_TYPE (access_path) : object_type,
    3334                 :             :                 name, guessed_id);
    3335                 :             :     }
    3336                 :         110 : }
    3337                 :             : 
    3338                 :             : /* This function is called by the parser to process a class member
    3339                 :             :    access expression of the form OBJECT.NAME.  NAME is a node used by
    3340                 :             :    the parser to represent a name; it is not yet a DECL.  It may,
    3341                 :             :    however, be a BASELINK where the BASELINK_FUNCTIONS is a
    3342                 :             :    TEMPLATE_ID_EXPR.  Templates must be looked up by the parser, and
    3343                 :             :    there is no reason to do the lookup twice, so the parser keeps the
    3344                 :             :    BASELINK.  TEMPLATE_P is true iff NAME was explicitly declared to
    3345                 :             :    be a template via the use of the "A::template B" syntax.  */
    3346                 :             : 
    3347                 :             : tree
    3348                 :   153934949 : finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
    3349                 :             :                                  tsubst_flags_t complain)
    3350                 :             : {
    3351                 :   153934949 :   tree expr;
    3352                 :   153934949 :   tree object_type;
    3353                 :   153934949 :   tree member;
    3354                 :   153934949 :   tree access_path = NULL_TREE;
    3355                 :   153934949 :   tree orig_object = object;
    3356                 :   153934949 :   tree orig_name = name;
    3357                 :             : 
    3358                 :   153934949 :   if (object == error_mark_node || name == error_mark_node)
    3359                 :             :     return error_mark_node;
    3360                 :             : 
    3361                 :             :   /* If OBJECT is an ObjC class instance, we must obey ObjC access rules.  */
    3362                 :   153934520 :   if (!objc_is_public (object, name))
    3363                 :           0 :     return error_mark_node;
    3364                 :             : 
    3365                 :   153934520 :   object_type = TREE_TYPE (object);
    3366                 :             : 
    3367                 :   153934520 :   if (processing_template_decl)
    3368                 :             :     {
    3369                 :   128809414 :       if (/* If OBJECT is dependent, so is OBJECT.NAME.  */
    3370                 :   128809414 :           type_dependent_object_expression_p (object)
    3371                 :             :           /* If NAME is "f<args>", where either 'f' or 'args' is
    3372                 :             :              dependent, then the expression is dependent.  */
    3373                 :    63554522 :           || (TREE_CODE (name) == TEMPLATE_ID_EXPR
    3374                 :      504967 :               && dependent_template_id_p (TREE_OPERAND (name, 0),
    3375                 :      504967 :                                           TREE_OPERAND (name, 1)))
    3376                 :             :           /* If NAME is "T::X" where "T" is dependent, then the
    3377                 :             :              expression is dependent.  */
    3378                 :    63338413 :           || (TREE_CODE (name) == SCOPE_REF
    3379                 :      106844 :               && TYPE_P (TREE_OPERAND (name, 0))
    3380                 :      106844 :               && dependent_scope_p (TREE_OPERAND (name, 0)))
    3381                 :             :           /* If NAME is operator T where "T" is dependent, we can't
    3382                 :             :              lookup until we instantiate the T.  */
    3383                 :   192041197 :           || (TREE_CODE (name) == IDENTIFIER_NODE
    3384                 :    62678951 :               && IDENTIFIER_CONV_OP_P (name)
    3385                 :          41 :               && dependent_type_p (TREE_TYPE (name))))
    3386                 :             :         {
    3387                 :    78556805 :         dependent:
    3388                 :    78556805 :           return build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF,
    3389                 :    78556805 :                                    orig_object, orig_name, NULL_TREE);
    3390                 :             :         }
    3391                 :             :     }
    3392                 :    25125106 :   else if (c_dialect_objc ()
    3393                 :    88356851 :            && identifier_p (name)
    3394                 :    25125106 :            && (expr = objc_maybe_build_component_ref (object, name)))
    3395                 :             :     return expr;
    3396                 :             :     
    3397                 :             :   /* [expr.ref]
    3398                 :             : 
    3399                 :             :      The type of the first expression shall be "class object" (of a
    3400                 :             :      complete type).  */
    3401                 :    88356851 :   if (!currently_open_class (object_type)
    3402                 :    88356851 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    3403                 :          76 :     return error_mark_node;
    3404                 :    88356775 :   if (!CLASS_TYPE_P (object_type))
    3405                 :             :     {
    3406                 :       50534 :       if (complain & tf_error)
    3407                 :             :         {
    3408                 :          78 :           if (INDIRECT_TYPE_P (object_type)
    3409                 :          78 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    3410                 :          21 :             error ("request for member %qD in %qE, which is of pointer "
    3411                 :             :                    "type %qT (maybe you meant to use %<->%> ?)",
    3412                 :             :                    name, object.get_value (), object_type);
    3413                 :             :           else
    3414                 :          57 :             error ("request for member %qD in %qE, which is of non-class "
    3415                 :             :                    "type %qT", name, object.get_value (), object_type);
    3416                 :             :         }
    3417                 :       50534 :       return error_mark_node;
    3418                 :             :     }
    3419                 :             : 
    3420                 :    88306241 :   if (BASELINK_P (name))
    3421                 :             :     /* A member function that has already been looked up.  */
    3422                 :             :     member = name;
    3423                 :             :   else
    3424                 :             :     {
    3425                 :    80102303 :       bool is_template_id = false;
    3426                 :    80102303 :       tree template_args = NULL_TREE;
    3427                 :    80102303 :       tree scope = NULL_TREE;
    3428                 :             : 
    3429                 :    80102303 :       access_path = object_type;
    3430                 :             : 
    3431                 :    80102303 :       if (TREE_CODE (name) == SCOPE_REF)
    3432                 :             :         {
    3433                 :             :           /* A qualified name.  The qualifying class or namespace `S'
    3434                 :             :              has already been looked up; it is either a TYPE or a
    3435                 :             :              NAMESPACE_DECL.  */
    3436                 :        1698 :           scope = TREE_OPERAND (name, 0);
    3437                 :        1698 :           name = TREE_OPERAND (name, 1);
    3438                 :             : 
    3439                 :             :           /* If SCOPE is a namespace, then the qualified name does not
    3440                 :             :              name a member of OBJECT_TYPE.  */
    3441                 :        1698 :           if (TREE_CODE (scope) == NAMESPACE_DECL)
    3442                 :             :             {
    3443                 :           0 :               if (complain & tf_error)
    3444                 :           0 :                 error ("%<%D::%D%> is not a member of %qT",
    3445                 :             :                        scope, name, object_type);
    3446                 :           0 :               return error_mark_node;
    3447                 :             :             }
    3448                 :             :         }
    3449                 :             :       
    3450                 :    80102303 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    3451                 :             :         {
    3452                 :      432491 :           is_template_id = true;
    3453                 :      432491 :           template_args = TREE_OPERAND (name, 1);
    3454                 :      432491 :           name = TREE_OPERAND (name, 0);
    3455                 :             : 
    3456                 :      826706 :           if (!identifier_p (name))
    3457                 :      394233 :             name = OVL_NAME (name);
    3458                 :             :         }
    3459                 :             : 
    3460                 :    80102303 :       if (scope)
    3461                 :             :         {
    3462                 :        1698 :           if (TREE_CODE (scope) == ENUMERAL_TYPE)
    3463                 :             :             {
    3464                 :          12 :               gcc_assert (!is_template_id);
    3465                 :             :               /* Looking up a member enumerator (c++/56793).  */
    3466                 :          24 :               if (!TYPE_CLASS_SCOPE_P (scope)
    3467                 :          21 :                   || !DERIVED_FROM_P (TYPE_CONTEXT (scope), object_type))
    3468                 :             :                 {
    3469                 :           3 :                   if (complain & tf_error)
    3470                 :           3 :                     error ("%<%D::%D%> is not a member of %qT",
    3471                 :             :                            scope, name, object_type);
    3472                 :           3 :                   return error_mark_node;
    3473                 :             :                 }
    3474                 :           9 :               tree val = lookup_enumerator (scope, name);
    3475                 :           9 :               if (!val)
    3476                 :             :                 {
    3477                 :           6 :                   if (complain & tf_error)
    3478                 :           6 :                     error ("%qD is not a member of %qD",
    3479                 :             :                            name, scope);
    3480                 :           6 :                   return error_mark_node;
    3481                 :             :                 }
    3482                 :             : 
    3483                 :           3 :               if (TREE_SIDE_EFFECTS (object))
    3484                 :           0 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val);
    3485                 :           3 :               return val;
    3486                 :             :             }
    3487                 :             : 
    3488                 :        1686 :           gcc_assert (CLASS_TYPE_P (scope));
    3489                 :        1686 :           gcc_assert (identifier_p (name) || TREE_CODE (name) == BIT_NOT_EXPR);
    3490                 :             : 
    3491                 :        1686 :           if (constructor_name_p (name, scope))
    3492                 :             :             {
    3493                 :           3 :               if (complain & tf_error)
    3494                 :           3 :                 error ("cannot call constructor %<%T::%D%> directly",
    3495                 :             :                        scope, name);
    3496                 :           3 :               return error_mark_node;
    3497                 :             :             }
    3498                 :             : 
    3499                 :             :           /* NAME may refer to a static data member, in which case there is
    3500                 :             :              one copy of the data member that is shared by all the objects of
    3501                 :             :              the class.  So NAME can be unambiguously referred to even if
    3502                 :             :              there are multiple indirect base classes containing NAME.  */
    3503                 :        5049 :           const base_access ba = [scope, name] ()
    3504                 :             :             {
    3505                 :        1683 :               if (identifier_p (name))
    3506                 :             :                 {
    3507                 :        1546 :                   tree m = lookup_member (scope, name, /*protect=*/0,
    3508                 :             :                                           /*want_type=*/false, tf_none);
    3509                 :        1546 :                   if (!m || shared_member_p (m))
    3510                 :          32 :                     return ba_any;
    3511                 :             :                 }
    3512                 :             :               return ba_check;
    3513                 :        1683 :             } ();
    3514                 :             : 
    3515                 :             :           /* Find the base of OBJECT_TYPE corresponding to SCOPE.  */
    3516                 :        1683 :           access_path = lookup_base (object_type, scope, ba, NULL, complain);
    3517                 :        1683 :           if (access_path == error_mark_node)
    3518                 :             :             return error_mark_node;
    3519                 :        1671 :           if (!access_path)
    3520                 :             :             {
    3521                 :          12 :               if (any_dependent_bases_p (object_type))
    3522                 :           6 :                 goto dependent;
    3523                 :           6 :               if (complain & tf_error)
    3524                 :           6 :                 error ("%qT is not a base of %qT", scope, object_type);
    3525                 :           6 :               return error_mark_node;
    3526                 :             :             }
    3527                 :             :         }
    3528                 :             : 
    3529                 :    80102264 :       if (TREE_CODE (name) == BIT_NOT_EXPR)
    3530                 :             :         {
    3531                 :      176754 :           if (dependent_type_p (object_type))
    3532                 :             :             /* The destructor isn't declared yet.  */
    3533                 :       32619 :             goto dependent;
    3534                 :      144135 :           member = lookup_destructor (object, scope, name, complain);
    3535                 :             :         }
    3536                 :             :       else
    3537                 :             :         {
    3538                 :             :           /* Look up the member.  */
    3539                 :    79925510 :           {
    3540                 :    79925510 :             auto_diagnostic_group d;
    3541                 :    79925510 :             access_failure_info afi;
    3542                 :    79925510 :             if (processing_template_decl)
    3543                 :             :               /* Even though this class member access expression is at this
    3544                 :             :                  point not dependent, the member itself may be dependent, and
    3545                 :             :                  we must not potentially push a access check for a dependent
    3546                 :             :                  member onto TI_DEFERRED_ACCESS_CHECKS.  So don't check access
    3547                 :             :                  ahead of time here; we're going to redo this member lookup at
    3548                 :             :                  instantiation time anyway.  */
    3549                 :    62967961 :               push_deferring_access_checks (dk_no_check);
    3550                 :    79925510 :             member = lookup_member (access_path, name, /*protect=*/1,
    3551                 :             :                                     /*want_type=*/false, complain,
    3552                 :             :                                     &afi);
    3553                 :    79925510 :             if (processing_template_decl)
    3554                 :    62967961 :               pop_deferring_access_checks ();
    3555                 :    79925510 :             afi.maybe_suggest_accessor (TYPE_READONLY (object_type));
    3556                 :    79925510 :           }
    3557                 :    79925510 :           if (member == NULL_TREE)
    3558                 :             :             {
    3559                 :     7752678 :               if (dependentish_scope_p (object_type))
    3560                 :             :                 /* Try again at instantiation time.  */
    3561                 :     7742317 :                 goto dependent;
    3562                 :       10361 :               if (complain & tf_error)
    3563                 :         263 :                 complain_about_unrecognized_member (access_path, name,
    3564                 :             :                                                     object_type);
    3565                 :       10361 :               return error_mark_node;
    3566                 :             :             }
    3567                 :    72172832 :           if (member == error_mark_node)
    3568                 :             :             return error_mark_node;
    3569                 :    72172789 :           if (DECL_P (member)
    3570                 :    72172789 :               && any_dependent_type_attributes_p (DECL_ATTRIBUTES (member)))
    3571                 :             :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3572                 :             :                wrong, so don't use it.  */
    3573                 :           6 :             goto dependent;
    3574                 :    72172783 :           if (TREE_CODE (member) == USING_DECL && DECL_DEPENDENT_P (member))
    3575                 :     5204188 :             goto dependent;
    3576                 :             :         }
    3577                 :             : 
    3578                 :    67112730 :       if (is_template_id)
    3579                 :             :         {
    3580                 :      432481 :           tree templ = member;
    3581                 :             : 
    3582                 :      432481 :           if (BASELINK_P (templ))
    3583                 :      432457 :             member = lookup_template_function (templ, template_args);
    3584                 :          24 :           else if (variable_template_p (templ))
    3585                 :          24 :             member = (lookup_and_finish_template_variable
    3586                 :          24 :                       (templ, template_args, complain));
    3587                 :             :           else
    3588                 :             :             {
    3589                 :           0 :               if (complain & tf_error)
    3590                 :           0 :                 error ("%qD is not a member template function", name);
    3591                 :           0 :               return error_mark_node;
    3592                 :             :             }
    3593                 :             :         }
    3594                 :             :     }
    3595                 :             : 
    3596                 :    75316668 :   if (TREE_UNAVAILABLE (member))
    3597                 :          30 :     error_unavailable_use (member, NULL_TREE);
    3598                 :    75316638 :   else if (TREE_DEPRECATED (member))
    3599                 :          30 :     warn_deprecated_use (member, NULL_TREE);
    3600                 :             : 
    3601                 :    75316668 :   if (template_p)
    3602                 :        9511 :     check_template_keyword (member);
    3603                 :             : 
    3604                 :    75316668 :   expr = build_class_member_access_expr (object, member, access_path,
    3605                 :             :                                          /*preserve_reference=*/false,
    3606                 :             :                                          complain);
    3607                 :    75316668 :   if (processing_template_decl && expr != error_mark_node)
    3608                 :             :     {
    3609                 :    50252545 :       if (BASELINK_P (member))
    3610                 :             :         {
    3611                 :    37259873 :           if (TREE_CODE (orig_name) == SCOPE_REF)
    3612                 :         169 :             BASELINK_QUALIFIED_P (member) = 1;
    3613                 :             :           orig_name = member;
    3614                 :             :         }
    3615                 :    50252545 :       return build_min_non_dep (COMPONENT_REF, expr,
    3616                 :             :                                 orig_object, orig_name,
    3617                 :    50252545 :                                 NULL_TREE);
    3618                 :             :     }
    3619                 :             : 
    3620                 :             :   return expr;
    3621                 :             : }
    3622                 :             : 
    3623                 :             : /* Build a COMPONENT_REF of OBJECT and MEMBER with the appropriate
    3624                 :             :    type.  */
    3625                 :             : 
    3626                 :             : tree
    3627                 :      172942 : build_simple_component_ref (tree object, tree member)
    3628                 :             : {
    3629                 :      172942 :   tree type = cp_build_qualified_type (TREE_TYPE (member),
    3630                 :      172942 :                                        cp_type_quals (TREE_TYPE (object)));
    3631                 :      172942 :   return build3_loc (input_location,
    3632                 :             :                      COMPONENT_REF, type,
    3633                 :      172942 :                      object, member, NULL_TREE);
    3634                 :             : }
    3635                 :             : 
    3636                 :             : /* Return an expression for the MEMBER_NAME field in the internal
    3637                 :             :    representation of PTRMEM, a pointer-to-member function.  (Each
    3638                 :             :    pointer-to-member function type gets its own RECORD_TYPE so it is
    3639                 :             :    more convenient to access the fields by name than by FIELD_DECL.)
    3640                 :             :    This routine converts the NAME to a FIELD_DECL and then creates the
    3641                 :             :    node for the complete expression.  */
    3642                 :             : 
    3643                 :             : tree
    3644                 :      172906 : build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
    3645                 :             : {
    3646                 :      172906 :   tree ptrmem_type;
    3647                 :      172906 :   tree member;
    3648                 :             : 
    3649                 :      172906 :   if (TREE_CODE (ptrmem) == CONSTRUCTOR)
    3650                 :             :     {
    3651                 :         183 :       for (auto &e: CONSTRUCTOR_ELTS (ptrmem))
    3652                 :          75 :         if (e.index && DECL_P (e.index) && DECL_NAME (e.index) == member_name)
    3653                 :          54 :           return e.value;
    3654                 :           0 :       gcc_unreachable ();
    3655                 :             :     }
    3656                 :             : 
    3657                 :             :   /* This code is a stripped down version of
    3658                 :             :      build_class_member_access_expr.  It does not work to use that
    3659                 :             :      routine directly because it expects the object to be of class
    3660                 :             :      type.  */
    3661                 :      172852 :   ptrmem_type = TREE_TYPE (ptrmem);
    3662                 :      172852 :   gcc_assert (TYPE_PTRMEMFUNC_P (ptrmem_type));
    3663                 :      259184 :   for (member = TYPE_FIELDS (ptrmem_type); member;
    3664                 :       86332 :        member = DECL_CHAIN (member))
    3665                 :      259184 :     if (DECL_NAME (member) == member_name)
    3666                 :             :       break;
    3667                 :      172852 :   return build_simple_component_ref (ptrmem, member);
    3668                 :             : }
    3669                 :             : 
    3670                 :             : /* Return a TREE_LIST of namespace-scope overloads for the given operator,
    3671                 :             :    and for any other relevant operator.  */
    3672                 :             : 
    3673                 :             : static tree
    3674                 :   110854218 : op_unqualified_lookup (tree_code code, bool is_assign)
    3675                 :             : {
    3676                 :   110854218 :   tree lookups = NULL_TREE;
    3677                 :             : 
    3678                 :   110854218 :   if (cxx_dialect >= cxx20 && !is_assign)
    3679                 :             :     {
    3680                 :    27381609 :       if (code == NE_EXPR)
    3681                 :             :         {
    3682                 :             :           /* != can get rewritten in terms of ==.  */
    3683                 :     1755856 :           tree fnname = ovl_op_identifier (false, EQ_EXPR);
    3684                 :     1755856 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3685                 :     1745610 :             lookups = tree_cons (fnname, fns, lookups);
    3686                 :             :         }
    3687                 :    25625753 :       else if (code == GT_EXPR || code == LE_EXPR
    3688                 :    25625753 :                || code == LT_EXPR || code == GE_EXPR)
    3689                 :             :         {
    3690                 :             :           /* These can get rewritten in terms of <=>.  */
    3691                 :     2430790 :           tree fnname = ovl_op_identifier (false, SPACESHIP_EXPR);
    3692                 :     2430790 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3693                 :     2317693 :             lookups = tree_cons (fnname, fns, lookups);
    3694                 :             :         }
    3695                 :             :     }
    3696                 :             : 
    3697                 :   110854218 :   tree fnname = ovl_op_identifier (is_assign, code);
    3698                 :   110854218 :   if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3699                 :    62638098 :     lookups = tree_cons (fnname, fns, lookups);
    3700                 :             : 
    3701                 :   110854218 :   if (lookups)
    3702                 :             :     return lookups;
    3703                 :             :   else
    3704                 :    48149482 :     return build_tree_list (NULL_TREE, NULL_TREE);
    3705                 :             : }
    3706                 :             : 
    3707                 :             : /* Create a DEPENDENT_OPERATOR_TYPE for a dependent operator expression of
    3708                 :             :    the given operator.  LOOKUPS, if non-NULL, is the result of phase 1
    3709                 :             :    name lookup for the given operator.  */
    3710                 :             : 
    3711                 :             : tree
    3712                 :   120570447 : build_dependent_operator_type (tree lookups, tree_code code, bool is_assign)
    3713                 :             : {
    3714                 :   120570447 :   if (lookups)
    3715                 :             :     /* We're partially instantiating a dependent operator expression, and
    3716                 :             :        LOOKUPS is the result of phase 1 name lookup that we performed
    3717                 :             :        earlier at template definition time, so just reuse the corresponding
    3718                 :             :        DEPENDENT_OPERATOR_TYPE.  */
    3719                 :     9716229 :     return TREE_TYPE (lookups);
    3720                 :             : 
    3721                 :             :   /* Otherwise we're processing a dependent operator expression at template
    3722                 :             :      definition time, so perform phase 1 name lookup now.  */
    3723                 :   110854218 :   lookups = op_unqualified_lookup (code, is_assign);
    3724                 :             : 
    3725                 :   110854218 :   tree type = cxx_make_type (DEPENDENT_OPERATOR_TYPE);
    3726                 :   110854218 :   DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (type) = lookups;
    3727                 :   110854218 :   TREE_TYPE (lookups) = type;
    3728                 :   110854218 :   return type;
    3729                 :             : }
    3730                 :             : 
    3731                 :             : /* Given an expression PTR for a pointer, return an expression
    3732                 :             :    for the value pointed to.
    3733                 :             :    ERRORSTRING is the name of the operator to appear in error messages.
    3734                 :             : 
    3735                 :             :    This function may need to overload OPERATOR_FNNAME.
    3736                 :             :    Must also handle REFERENCE_TYPEs for C++.  */
    3737                 :             : 
    3738                 :             : tree
    3739                 :    35710408 : build_x_indirect_ref (location_t loc, tree expr, ref_operator errorstring, 
    3740                 :             :                       tree lookups, tsubst_flags_t complain)
    3741                 :             : {
    3742                 :    35710408 :   tree orig_expr = expr;
    3743                 :    35710408 :   tree rval;
    3744                 :    35710408 :   tree overload = NULL_TREE;
    3745                 :             : 
    3746                 :    35710408 :   if (processing_template_decl)
    3747                 :             :     {
    3748                 :             :       /* Retain the type if we know the operand is a pointer.  */
    3749                 :    20891178 :       if (TREE_TYPE (expr) && INDIRECT_TYPE_P (TREE_TYPE (expr)))
    3750                 :             :         {
    3751                 :    11609259 :           if (expr == current_class_ptr
    3752                 :    11609259 :               || (TREE_CODE (expr) == NOP_EXPR
    3753                 :     7152029 :                   && TREE_OPERAND (expr, 0) == current_class_ptr
    3754                 :     7140534 :                   && (same_type_ignoring_top_level_qualifiers_p
    3755                 :     7140534 :                         (TREE_TYPE (expr), TREE_TYPE (current_class_ptr)))))
    3756                 :     7140533 :             return current_class_ref;
    3757                 :     4468726 :           return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
    3758                 :             :         }
    3759                 :     9281919 :       if (type_dependent_expression_p (expr))
    3760                 :             :         {
    3761                 :     9142209 :           expr = build_min_nt_loc (loc, INDIRECT_REF, expr);
    3762                 :     9142209 :           TREE_TYPE (expr)
    3763                 :     9142209 :             = build_dependent_operator_type (lookups, INDIRECT_REF, false);
    3764                 :     9142209 :           return expr;
    3765                 :             :         }
    3766                 :             :     }
    3767                 :             : 
    3768                 :    14958940 :   rval = build_new_op (loc, INDIRECT_REF, LOOKUP_NORMAL, expr,
    3769                 :             :                        NULL_TREE, NULL_TREE, lookups,
    3770                 :             :                        &overload, complain);
    3771                 :    14958940 :   if (!rval)
    3772                 :           0 :     rval = cp_build_indirect_ref (loc, expr, errorstring, complain);
    3773                 :             : 
    3774                 :    14958940 :   if (processing_template_decl && rval != error_mark_node)
    3775                 :             :     {
    3776                 :      137869 :       if (overload != NULL_TREE)
    3777                 :      137838 :         return (build_min_non_dep_op_overload
    3778                 :      137838 :                 (INDIRECT_REF, rval, overload, orig_expr));
    3779                 :             : 
    3780                 :          31 :       return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
    3781                 :             :     }
    3782                 :             :   else
    3783                 :             :     return rval;
    3784                 :             : }
    3785                 :             : 
    3786                 :             : /* Like c-family strict_aliasing_warning, but don't warn for dependent
    3787                 :             :    types or expressions.  */
    3788                 :             : 
    3789                 :             : static bool
    3790                 :      539611 : cp_strict_aliasing_warning (location_t loc, tree type, tree expr)
    3791                 :             : {
    3792                 :      539611 :   if (processing_template_decl)
    3793                 :             :     {
    3794                 :       38451 :       tree e = expr;
    3795                 :       38451 :       STRIP_NOPS (e);
    3796                 :       38451 :       if (dependent_type_p (type) || type_dependent_expression_p (e))
    3797                 :        6369 :         return false;
    3798                 :             :     }
    3799                 :      533242 :   return strict_aliasing_warning (loc, type, expr);
    3800                 :             : }
    3801                 :             : 
    3802                 :             : /* The implementation of the above, and of indirection implied by other
    3803                 :             :    constructs.  If DO_FOLD is true, fold away INDIRECT_REF of ADDR_EXPR.  */
    3804                 :             : 
    3805                 :             : static tree
    3806                 :   274157238 : cp_build_indirect_ref_1 (location_t loc, tree ptr, ref_operator errorstring,
    3807                 :             :                          tsubst_flags_t complain, bool do_fold)
    3808                 :             : {
    3809                 :   274157238 :   tree pointer, type;
    3810                 :             : 
    3811                 :             :   /* RO_NULL should only be used with the folding entry points below, not
    3812                 :             :      cp_build_indirect_ref.  */
    3813                 :   274157238 :   gcc_checking_assert (errorstring != RO_NULL || do_fold);
    3814                 :             : 
    3815                 :   274157238 :   if (ptr == current_class_ptr
    3816                 :   274157238 :       || (TREE_CODE (ptr) == NOP_EXPR
    3817                 :    26937415 :           && TREE_OPERAND (ptr, 0) == current_class_ptr
    3818                 :    14880853 :           && (same_type_ignoring_top_level_qualifiers_p
    3819                 :    14880853 :               (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr)))))
    3820                 :    16122247 :     return current_class_ref;
    3821                 :             : 
    3822                 :   258034991 :   pointer = (TYPE_REF_P (TREE_TYPE (ptr))
    3823                 :   258034991 :              ? ptr : decay_conversion (ptr, complain));
    3824                 :   258034991 :   if (pointer == error_mark_node)
    3825                 :             :     return error_mark_node;
    3826                 :             : 
    3827                 :   258029175 :   type = TREE_TYPE (pointer);
    3828                 :             : 
    3829                 :   258029175 :   if (INDIRECT_TYPE_P (type))
    3830                 :             :     {
    3831                 :             :       /* [expr.unary.op]
    3832                 :             : 
    3833                 :             :          If the type of the expression is "pointer to T," the type
    3834                 :             :          of  the  result  is  "T."  */
    3835                 :   258028900 :       tree t = TREE_TYPE (type);
    3836                 :             : 
    3837                 :   244885553 :       if ((CONVERT_EXPR_P (ptr)
    3838                 :   187261036 :            || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
    3839                 :   317477765 :           && (!CLASS_TYPE_P (t) || !CLASSTYPE_EMPTY_P (t)))
    3840                 :             :         {
    3841                 :             :           /* If a warning is issued, mark it to avoid duplicates from
    3842                 :             :              the backend.  This only needs to be done at
    3843                 :             :              warn_strict_aliasing > 2.  */
    3844                 :    49773306 :           if (warn_strict_aliasing > 2
    3845                 :    50237741 :               && cp_strict_aliasing_warning (EXPR_LOCATION (ptr),
    3846                 :      464435 :                                              type, TREE_OPERAND (ptr, 0)))
    3847                 :           6 :             suppress_warning (ptr, OPT_Wstrict_aliasing);
    3848                 :             :         }
    3849                 :             : 
    3850                 :   258028900 :       if (VOID_TYPE_P (t))
    3851                 :             :         {
    3852                 :             :           /* A pointer to incomplete type (other than cv void) can be
    3853                 :             :              dereferenced [expr.unary.op]/1  */
    3854                 :          70 :           if (complain & tf_error)
    3855                 :          19 :             error_at (loc, "%qT is not a pointer-to-object type", type);
    3856                 :          70 :           return error_mark_node;
    3857                 :             :         }
    3858                 :   249392222 :       else if (do_fold && TREE_CODE (pointer) == ADDR_EXPR
    3859                 :   263116740 :                && same_type_p (t, TREE_TYPE (TREE_OPERAND (pointer, 0))))
    3860                 :             :         /* The POINTER was something like `&x'.  We simplify `*&x' to
    3861                 :             :            `x'.  */
    3862                 :     5087910 :         return TREE_OPERAND (pointer, 0);
    3863                 :             :       else
    3864                 :             :         {
    3865                 :   252940920 :           tree ref = build1 (INDIRECT_REF, t, pointer);
    3866                 :             : 
    3867                 :             :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    3868                 :             :              so that we get the proper error message if the result is used
    3869                 :             :              to assign to.  Also, &* is supposed to be a no-op.  */
    3870                 :   252940920 :           TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
    3871                 :   252940920 :           TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
    3872                 :   252940920 :           TREE_SIDE_EFFECTS (ref)
    3873                 :   252940920 :             = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (pointer));
    3874                 :   252940920 :           return ref;
    3875                 :             :         }
    3876                 :             :     }
    3877                 :         275 :   else if (!(complain & tf_error))
    3878                 :             :     /* Don't emit any errors; we'll just return ERROR_MARK_NODE later.  */
    3879                 :             :     ;
    3880                 :             :   /* `pointer' won't be an error_mark_node if we were given a
    3881                 :             :      pointer to member, so it's cool to check for this here.  */
    3882                 :          33 :   else if (TYPE_PTRMEM_P (type))
    3883                 :          15 :     switch (errorstring)
    3884                 :             :       {
    3885                 :           0 :          case RO_ARRAY_INDEXING:
    3886                 :           0 :            error_at (loc,
    3887                 :             :                      "invalid use of array indexing on pointer to member");
    3888                 :           0 :            break;
    3889                 :          12 :          case RO_UNARY_STAR:
    3890                 :          12 :            error_at (loc, "invalid use of unary %<*%> on pointer to member");
    3891                 :          12 :            break;
    3892                 :           0 :          case RO_IMPLICIT_CONVERSION:
    3893                 :           0 :            error_at (loc, "invalid use of implicit conversion on pointer "
    3894                 :             :                      "to member");
    3895                 :           0 :            break;
    3896                 :           3 :          case RO_ARROW_STAR:
    3897                 :           3 :            error_at (loc, "left hand operand of %<->*%> must be a pointer to "
    3898                 :             :                      "class, but is a pointer to member of type %qT", type);
    3899                 :           3 :            break;
    3900                 :           0 :          default:
    3901                 :           0 :            gcc_unreachable ();
    3902                 :             :       }
    3903                 :          18 :   else if (pointer != error_mark_node)
    3904                 :          18 :     invalid_indirection_error (loc, type, errorstring);
    3905                 :             : 
    3906                 :         275 :   return error_mark_node;
    3907                 :             : }
    3908                 :             : 
    3909                 :             : /* Entry point used by c-common, which expects folding.  */
    3910                 :             : 
    3911                 :             : tree
    3912                 :       26374 : build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring)
    3913                 :             : {
    3914                 :       26374 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring,
    3915                 :       26374 :                                   tf_warning_or_error, true);
    3916                 :             : }
    3917                 :             : 
    3918                 :             : /* Entry point used by internal indirection needs that don't correspond to any
    3919                 :             :    syntactic construct.  */
    3920                 :             : 
    3921                 :             : tree
    3922                 :   252402435 : cp_build_fold_indirect_ref (tree pointer)
    3923                 :             : {
    3924                 :   252402435 :   return cp_build_indirect_ref_1 (input_location, pointer, RO_NULL,
    3925                 :   252402435 :                                   tf_warning_or_error, true);
    3926                 :             : }
    3927                 :             : 
    3928                 :             : /* Entry point used by indirection needs that correspond to some syntactic
    3929                 :             :    construct.  */
    3930                 :             : 
    3931                 :             : tree
    3932                 :    21728429 : cp_build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring,
    3933                 :             :                        tsubst_flags_t complain)
    3934                 :             : {
    3935                 :    21728429 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring, complain, false);
    3936                 :             : }
    3937                 :             : 
    3938                 :             : /* This handles expressions of the form "a[i]", which denotes
    3939                 :             :    an array reference.
    3940                 :             : 
    3941                 :             :    This is logically equivalent in C to *(a+i), but we may do it differently.
    3942                 :             :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    3943                 :             :    This avoids forcing the array out of registers, and can work on
    3944                 :             :    arrays that are not lvalues (for example, members of structures returned
    3945                 :             :    by functions).
    3946                 :             : 
    3947                 :             :    If INDEX is of some user-defined type, it must be converted to
    3948                 :             :    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
    3949                 :             :    will inherit the type of the array, which will be some pointer type.
    3950                 :             : 
    3951                 :             :    LOC is the location to use in building the array reference.  */
    3952                 :             : 
    3953                 :             : tree
    3954                 :     5108785 : cp_build_array_ref (location_t loc, tree array, tree idx,
    3955                 :             :                     tsubst_flags_t complain)
    3956                 :             : {
    3957                 :     5108785 :   tree first = NULL_TREE;
    3958                 :     5108785 :   tree ret;
    3959                 :             : 
    3960                 :     5108785 :   if (idx == 0)
    3961                 :             :     {
    3962                 :           0 :       if (complain & tf_error)
    3963                 :           0 :         error_at (loc, "subscript missing in array reference");
    3964                 :           0 :       return error_mark_node;
    3965                 :             :     }
    3966                 :             : 
    3967                 :     5108785 :   if (TREE_TYPE (array) == error_mark_node
    3968                 :     5108785 :       || TREE_TYPE (idx) == error_mark_node)
    3969                 :             :     return error_mark_node;
    3970                 :             : 
    3971                 :             :   /* If ARRAY is a COMPOUND_EXPR or COND_EXPR, move our reference
    3972                 :             :      inside it.  */
    3973                 :     5108785 :   switch (TREE_CODE (array))
    3974                 :             :     {
    3975                 :          26 :     case COMPOUND_EXPR:
    3976                 :          26 :       {
    3977                 :          26 :         tree value = cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    3978                 :             :                                          complain);
    3979                 :          26 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
    3980                 :          26 :                       TREE_OPERAND (array, 0), value);
    3981                 :          26 :         SET_EXPR_LOCATION (ret, loc);
    3982                 :          26 :         return ret;
    3983                 :             :       }
    3984                 :             : 
    3985                 :          13 :     case COND_EXPR:
    3986                 :          13 :       ret = build_conditional_expr
    3987                 :          26 :                (loc, TREE_OPERAND (array, 0),
    3988                 :          13 :                cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    3989                 :             :                                    complain),
    3990                 :          13 :                cp_build_array_ref (loc, TREE_OPERAND (array, 2), idx,
    3991                 :             :                                    complain),
    3992                 :             :                complain);
    3993                 :          13 :       protected_set_expr_location (ret, loc);
    3994                 :          13 :       return ret;
    3995                 :             : 
    3996                 :     5108746 :     default:
    3997                 :     5108746 :       break;
    3998                 :             :     }
    3999                 :             : 
    4000                 :     5108746 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, idx);
    4001                 :             : 
    4002                 :             :   /* 0[array] */
    4003                 :     5108746 :   if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE)
    4004                 :             :     {
    4005                 :           7 :       std::swap (array, idx);
    4006                 :           7 :       if (flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (array))
    4007                 :           6 :         idx = first = save_expr (idx);
    4008                 :             :     }
    4009                 :             : 
    4010                 :     5108746 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    4011                 :             :     {
    4012                 :     1623190 :       tree rval, type;
    4013                 :             : 
    4014                 :     1623190 :       warn_array_subscript_with_type_char (loc, idx);
    4015                 :             : 
    4016                 :     1623190 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
    4017                 :             :         {
    4018                 :           3 :           if (complain & tf_error)
    4019                 :           3 :             error_at (loc, "array subscript is not an integer");
    4020                 :           3 :           return error_mark_node;
    4021                 :             :         }
    4022                 :             : 
    4023                 :             :       /* Apply integral promotions *after* noticing character types.
    4024                 :             :          (It is unclear why we do these promotions -- the standard
    4025                 :             :          does not say that we should.  In fact, the natural thing would
    4026                 :             :          seem to be to convert IDX to ptrdiff_t; we're performing
    4027                 :             :          pointer arithmetic.)  */
    4028                 :     1623187 :       idx = cp_perform_integral_promotions (idx, complain);
    4029                 :             : 
    4030                 :     1623187 :       idx = maybe_fold_non_dependent_expr (idx, complain);
    4031                 :             : 
    4032                 :             :       /* An array that is indexed by a non-constant
    4033                 :             :          cannot be stored in a register; we must be able to do
    4034                 :             :          address arithmetic on its address.
    4035                 :             :          Likewise an array of elements of variable size.  */
    4036                 :     1623187 :       if (TREE_CODE (idx) != INTEGER_CST
    4037                 :     1623187 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    4038                 :      807327 :               && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))))
    4039                 :             :                   != INTEGER_CST)))
    4040                 :             :         {
    4041                 :      817111 :           if (!cxx_mark_addressable (array, true))
    4042                 :           0 :             return error_mark_node;
    4043                 :             :         }
    4044                 :             : 
    4045                 :             :       /* An array that is indexed by a constant value which is not within
    4046                 :             :          the array bounds cannot be stored in a register either; because we
    4047                 :             :          would get a crash in store_bit_field/extract_bit_field when trying
    4048                 :             :          to access a non-existent part of the register.  */
    4049                 :     1623187 :       if (TREE_CODE (idx) == INTEGER_CST
    4050                 :      807330 :           && TYPE_DOMAIN (TREE_TYPE (array))
    4051                 :     2429206 :           && ! int_fits_type_p (idx, TYPE_DOMAIN (TREE_TYPE (array))))
    4052                 :             :         {
    4053                 :        2761 :           if (!cxx_mark_addressable (array))
    4054                 :           0 :             return error_mark_node;
    4055                 :             :         }
    4056                 :             : 
    4057                 :             :       /* Note in C++ it is valid to subscript a `register' array, since
    4058                 :             :          it is valid to take the address of something with that
    4059                 :             :          storage specification.  */
    4060                 :     1623187 :       if (extra_warnings)
    4061                 :             :         {
    4062                 :       37030 :           tree foo = array;
    4063                 :       56882 :           while (TREE_CODE (foo) == COMPONENT_REF)
    4064                 :       19852 :             foo = TREE_OPERAND (foo, 0);
    4065                 :           8 :           if (VAR_P (foo) && DECL_REGISTER (foo)
    4066                 :       37030 :               && (complain & tf_warning))
    4067                 :           0 :             warning_at (loc, OPT_Wextra,
    4068                 :             :                         "subscripting array declared %<register%>");
    4069                 :             :         }
    4070                 :             : 
    4071                 :     1623187 :       type = TREE_TYPE (TREE_TYPE (array));
    4072                 :     1623187 :       rval = build4 (ARRAY_REF, type, array, idx, NULL_TREE, NULL_TREE);
    4073                 :             :       /* Array ref is const/volatile if the array elements are
    4074                 :             :          or if the array is..  */
    4075                 :     4869561 :       TREE_READONLY (rval)
    4076                 :     1623187 :         |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
    4077                 :     4869561 :       TREE_SIDE_EFFECTS (rval)
    4078                 :     1623187 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
    4079                 :     3246374 :       TREE_THIS_VOLATILE (rval)
    4080                 :     1623187 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
    4081                 :     1623187 :       ret = require_complete_type (rval, complain);
    4082                 :     1623187 :       protected_set_expr_location (ret, loc);
    4083                 :     1623187 :       if (non_lvalue)
    4084                 :        6024 :         ret = non_lvalue_loc (loc, ret);
    4085                 :     1623187 :       if (first)
    4086                 :           6 :         ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4087                 :     1623187 :       return ret;
    4088                 :             :     }
    4089                 :             : 
    4090                 :     3485556 :   {
    4091                 :     3485556 :     tree ar = cp_default_conversion (array, complain);
    4092                 :     3485556 :     tree ind = cp_default_conversion (idx, complain);
    4093                 :             : 
    4094                 :     3485556 :     if (!first && flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (ind))
    4095                 :      152217 :       ar = first = save_expr (ar);
    4096                 :             : 
    4097                 :             :     /* Put the integer in IND to simplify error checking.  */
    4098                 :     3485556 :     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
    4099                 :          57 :       std::swap (ar, ind);
    4100                 :             : 
    4101                 :     3485556 :     if (ar == error_mark_node || ind == error_mark_node)
    4102                 :             :       return error_mark_node;
    4103                 :             : 
    4104                 :     3485556 :     if (!TYPE_PTR_P (TREE_TYPE (ar)))
    4105                 :             :       {
    4106                 :          22 :         if (complain & tf_error)
    4107                 :           3 :           error_at (loc, "subscripted value is neither array nor pointer");
    4108                 :          22 :         return error_mark_node;
    4109                 :             :       }
    4110                 :     3485534 :     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
    4111                 :             :       {
    4112                 :           0 :         if (complain & tf_error)
    4113                 :           0 :           error_at (loc, "array subscript is not an integer");
    4114                 :           0 :         return error_mark_node;
    4115                 :             :       }
    4116                 :             : 
    4117                 :     3485534 :     warn_array_subscript_with_type_char (loc, idx);
    4118                 :             : 
    4119                 :     3485534 :     ret = cp_build_binary_op (input_location, PLUS_EXPR, ar, ind, complain);
    4120                 :     3485534 :     if (first)
    4121                 :      152217 :       ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4122                 :     3485534 :     ret = cp_build_indirect_ref (loc, ret, RO_ARRAY_INDEXING, complain);
    4123                 :     3485534 :     protected_set_expr_location (ret, loc);
    4124                 :     3485534 :     if (non_lvalue)
    4125                 :           0 :       ret = non_lvalue_loc (loc, ret);
    4126                 :             :     return ret;
    4127                 :             :   }
    4128                 :             : }
    4129                 :             : 
    4130                 :             : /* Entry point for Obj-C++.  */
    4131                 :             : 
    4132                 :             : tree
    4133                 :     3507683 : build_array_ref (location_t loc, tree array, tree idx)
    4134                 :             : {
    4135                 :     3507683 :   return cp_build_array_ref (loc, array, idx, tf_warning_or_error);
    4136                 :             : }
    4137                 :             : 
    4138                 :             : /* Resolve a pointer to member function.  INSTANCE is the object
    4139                 :             :    instance to use, if the member points to a virtual member.
    4140                 :             : 
    4141                 :             :    This used to avoid checking for virtual functions if basetype
    4142                 :             :    has no virtual functions, according to an earlier ANSI draft.
    4143                 :             :    With the final ISO C++ rules, such an optimization is
    4144                 :             :    incorrect: A pointer to a derived member can be static_cast
    4145                 :             :    to pointer-to-base-member, as long as the dynamic object
    4146                 :             :    later has the right member.  So now we only do this optimization
    4147                 :             :    when we know the dynamic type of the object.  */
    4148                 :             : 
    4149                 :             : tree
    4150                 :       86271 : get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function,
    4151                 :             :                                   tsubst_flags_t complain)
    4152                 :             : {
    4153                 :       86271 :   if (TREE_CODE (function) == OFFSET_REF)
    4154                 :           0 :     function = TREE_OPERAND (function, 1);
    4155                 :             : 
    4156                 :       86271 :   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
    4157                 :             :     {
    4158                 :       86271 :       tree idx, delta, e1, e2, e3, vtbl;
    4159                 :       86271 :       bool nonvirtual;
    4160                 :       86271 :       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
    4161                 :       86271 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (fntype));
    4162                 :             : 
    4163                 :       86271 :       tree instance_ptr = *instance_ptrptr;
    4164                 :       86271 :       tree instance_save_expr = 0;
    4165                 :       86271 :       if (instance_ptr == error_mark_node)
    4166                 :             :         {
    4167                 :           0 :           if (TREE_CODE (function) == PTRMEM_CST)
    4168                 :             :             {
    4169                 :             :               /* Extracting the function address from a pmf is only
    4170                 :             :                  allowed with -Wno-pmf-conversions. It only works for
    4171                 :             :                  pmf constants.  */
    4172                 :           0 :               e1 = build_addr_func (PTRMEM_CST_MEMBER (function), complain);
    4173                 :           0 :               e1 = convert (fntype, e1);
    4174                 :           0 :               return e1;
    4175                 :             :             }
    4176                 :             :           else
    4177                 :             :             {
    4178                 :           0 :               if (complain & tf_error)
    4179                 :           0 :                 error ("object missing in use of %qE", function);
    4180                 :           0 :               return error_mark_node;
    4181                 :             :             }
    4182                 :             :         }
    4183                 :             : 
    4184                 :             :       /* True if we know that the dynamic type of the object doesn't have
    4185                 :             :          virtual functions, so we can assume the PFN field is a pointer.  */
    4186                 :       86271 :       nonvirtual = (COMPLETE_TYPE_P (basetype)
    4187                 :       86229 :                     && !TYPE_POLYMORPHIC_P (basetype)
    4188                 :      115871 :                     && resolves_to_fixed_type_p (instance_ptr, 0));
    4189                 :             : 
    4190                 :             :       /* If we don't really have an object (i.e. in an ill-formed
    4191                 :             :          conversion from PMF to pointer), we can't resolve virtual
    4192                 :             :          functions anyway.  */
    4193                 :       86009 :       if (!nonvirtual && is_dummy_object (instance_ptr))
    4194                 :             :         nonvirtual = true;
    4195                 :             : 
    4196                 :       86271 :       if (TREE_SIDE_EFFECTS (instance_ptr))
    4197                 :       56744 :         instance_ptr = instance_save_expr = save_expr (instance_ptr);
    4198                 :             : 
    4199                 :       86271 :       if (TREE_SIDE_EFFECTS (function))
    4200                 :       37924 :         function = save_expr (function);
    4201                 :             : 
    4202                 :             :       /* Start by extracting all the information from the PMF itself.  */
    4203                 :       86271 :       e3 = pfn_from_ptrmemfunc (function);
    4204                 :       86271 :       delta = delta_from_ptrmemfunc (function);
    4205                 :       86271 :       idx = build1 (NOP_EXPR, vtable_index_type, e3);
    4206                 :       86271 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
    4207                 :             :         {
    4208                 :       86271 :           int flag_sanitize_save;
    4209                 :       86271 :         case ptrmemfunc_vbit_in_pfn:
    4210                 :       86271 :           e1 = cp_build_binary_op (input_location,
    4211                 :             :                                    BIT_AND_EXPR, idx, integer_one_node,
    4212                 :             :                                    complain);
    4213                 :       86271 :           idx = cp_build_binary_op (input_location,
    4214                 :             :                                     MINUS_EXPR, idx, integer_one_node,
    4215                 :             :                                     complain);
    4216                 :       86271 :           if (idx == error_mark_node)
    4217                 :             :             return error_mark_node;
    4218                 :       86271 :           break;
    4219                 :             : 
    4220                 :             :         case ptrmemfunc_vbit_in_delta:
    4221                 :             :           e1 = cp_build_binary_op (input_location,
    4222                 :             :                                    BIT_AND_EXPR, delta, integer_one_node,
    4223                 :             :                                    complain);
    4224                 :             :           /* Don't instrument the RSHIFT_EXPR we're about to create because
    4225                 :             :              we're going to use DELTA number of times, and that wouldn't play
    4226                 :             :              well with SAVE_EXPRs therein.  */
    4227                 :             :           flag_sanitize_save = flag_sanitize;
    4228                 :             :           flag_sanitize = 0;
    4229                 :             :           delta = cp_build_binary_op (input_location,
    4230                 :             :                                       RSHIFT_EXPR, delta, integer_one_node,
    4231                 :             :                                       complain);
    4232                 :             :           flag_sanitize = flag_sanitize_save;
    4233                 :             :           if (delta == error_mark_node)
    4234                 :             :             return error_mark_node;
    4235                 :             :           break;
    4236                 :             : 
    4237                 :             :         default:
    4238                 :             :           gcc_unreachable ();
    4239                 :             :         }
    4240                 :             : 
    4241                 :       86271 :       if (e1 == error_mark_node)
    4242                 :             :         return error_mark_node;
    4243                 :             : 
    4244                 :             :       /* Convert down to the right base before using the instance.  A
    4245                 :             :          special case is that in a pointer to member of class C, C may
    4246                 :             :          be incomplete.  In that case, the function will of course be
    4247                 :             :          a member of C, and no conversion is required.  In fact,
    4248                 :             :          lookup_base will fail in that case, because incomplete
    4249                 :             :          classes do not have BINFOs.  */
    4250                 :       86271 :       if (!same_type_ignoring_top_level_qualifiers_p
    4251                 :       86271 :           (basetype, TREE_TYPE (TREE_TYPE (instance_ptr))))
    4252                 :             :         {
    4253                 :          78 :           basetype = lookup_base (TREE_TYPE (TREE_TYPE (instance_ptr)),
    4254                 :             :                                   basetype, ba_check, NULL, complain);
    4255                 :          78 :           instance_ptr = build_base_path (PLUS_EXPR, instance_ptr, basetype,
    4256                 :             :                                           1, complain);
    4257                 :          78 :           if (instance_ptr == error_mark_node)
    4258                 :             :             return error_mark_node;
    4259                 :             :         }
    4260                 :             :       /* ...and then the delta in the PMF.  */
    4261                 :       86271 :       instance_ptr = fold_build_pointer_plus (instance_ptr, delta);
    4262                 :             : 
    4263                 :             :       /* Hand back the adjusted 'this' argument to our caller.  */
    4264                 :       86271 :       *instance_ptrptr = instance_ptr;
    4265                 :             : 
    4266                 :       86271 :       if (nonvirtual)
    4267                 :             :         /* Now just return the pointer.  */
    4268                 :             :         return e3;
    4269                 :             : 
    4270                 :             :       /* Next extract the vtable pointer from the object.  */
    4271                 :       85991 :       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
    4272                 :             :                      instance_ptr);
    4273                 :       85991 :       vtbl = cp_build_fold_indirect_ref (vtbl);
    4274                 :       85991 :       if (vtbl == error_mark_node)
    4275                 :             :         return error_mark_node;
    4276                 :             : 
    4277                 :             :       /* Finally, extract the function pointer from the vtable.  */
    4278                 :       85991 :       e2 = fold_build_pointer_plus_loc (input_location, vtbl, idx);
    4279                 :       85991 :       e2 = cp_build_fold_indirect_ref (e2);
    4280                 :       85991 :       if (e2 == error_mark_node)
    4281                 :             :         return error_mark_node;
    4282                 :       85991 :       TREE_CONSTANT (e2) = 1;
    4283                 :             : 
    4284                 :             :       /* When using function descriptors, the address of the
    4285                 :             :          vtable entry is treated as a function pointer.  */
    4286                 :       85991 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
    4287                 :             :         e2 = build1 (NOP_EXPR, TREE_TYPE (e2),
    4288                 :             :                      cp_build_addr_expr (e2, complain));
    4289                 :             : 
    4290                 :       85991 :       e2 = fold_convert (TREE_TYPE (e3), e2);
    4291                 :       85991 :       e1 = build_conditional_expr (input_location, e1, e2, e3, complain);
    4292                 :       85991 :       if (e1 == error_mark_node)
    4293                 :             :         return error_mark_node;
    4294                 :             : 
    4295                 :             :       /* Make sure this doesn't get evaluated first inside one of the
    4296                 :             :          branches of the COND_EXPR.  */
    4297                 :       85991 :       if (instance_save_expr)
    4298                 :       56696 :         e1 = build2 (COMPOUND_EXPR, TREE_TYPE (e1),
    4299                 :             :                      instance_save_expr, e1);
    4300                 :             : 
    4301                 :             :       function = e1;
    4302                 :             :     }
    4303                 :             :   return function;
    4304                 :             : }
    4305                 :             : 
    4306                 :             : /* Used by the C-common bits.  */
    4307                 :             : tree
    4308                 :           0 : build_function_call (location_t /*loc*/, 
    4309                 :             :                      tree function, tree params)
    4310                 :             : {
    4311                 :           0 :   return cp_build_function_call (function, params, tf_warning_or_error);
    4312                 :             : }
    4313                 :             : 
    4314                 :             : /* Used by the C-common bits.  */
    4315                 :             : tree
    4316                 :      228199 : build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
    4317                 :             :                          tree function, vec<tree, va_gc> *params,
    4318                 :             :                          vec<tree, va_gc> * /*origtypes*/, tree orig_function)
    4319                 :             : {
    4320                 :      228199 :   vec<tree, va_gc> *orig_params = params;
    4321                 :      228199 :   tree ret = cp_build_function_call_vec (function, &params,
    4322                 :             :                                          tf_warning_or_error, orig_function);
    4323                 :             : 
    4324                 :             :   /* cp_build_function_call_vec can reallocate PARAMS by adding
    4325                 :             :      default arguments.  That should never happen here.  Verify
    4326                 :             :      that.  */
    4327                 :      228199 :   gcc_assert (params == orig_params);
    4328                 :             : 
    4329                 :      228199 :   return ret;
    4330                 :             : }
    4331                 :             : 
    4332                 :             : /* Build a function call using a tree list of arguments.  */
    4333                 :             : 
    4334                 :             : static tree
    4335                 :           0 : cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
    4336                 :             : {
    4337                 :           0 :   tree ret;
    4338                 :             : 
    4339                 :           0 :   releasing_vec vec;
    4340                 :           0 :   for (; params != NULL_TREE; params = TREE_CHAIN (params))
    4341                 :           0 :     vec_safe_push (vec, TREE_VALUE (params));
    4342                 :           0 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4343                 :           0 :   return ret;
    4344                 :           0 : }
    4345                 :             : 
    4346                 :             : /* Build a function call using varargs.  */
    4347                 :             : 
    4348                 :             : tree
    4349                 :      461067 : cp_build_function_call_nary (tree function, tsubst_flags_t complain, ...)
    4350                 :             : {
    4351                 :      461067 :   va_list args;
    4352                 :      461067 :   tree ret, t;
    4353                 :             : 
    4354                 :      461067 :   releasing_vec vec;
    4355                 :      461067 :   va_start (args, complain);
    4356                 :     1137932 :   for (t = va_arg (args, tree); t != NULL_TREE; t = va_arg (args, tree))
    4357                 :      676865 :     vec_safe_push (vec, t);
    4358                 :      461067 :   va_end (args);
    4359                 :      461067 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4360                 :      461067 :   return ret;
    4361                 :      461067 : }
    4362                 :             : 
    4363                 :             : /* C++ implementation of callback for use when checking param types.  */
    4364                 :             : 
    4365                 :             : bool
    4366                 :          18 : cp_comp_parm_types (tree wanted_type, tree actual_type)
    4367                 :             : {
    4368                 :          18 :   if (TREE_CODE (wanted_type) == POINTER_TYPE
    4369                 :          18 :       && TREE_CODE (actual_type) == POINTER_TYPE)
    4370                 :          15 :     return same_or_base_type_p (TREE_TYPE (wanted_type),
    4371                 :             :                                 TREE_TYPE (actual_type));
    4372                 :             :   return false;
    4373                 :             : }
    4374                 :             : 
    4375                 :             : /* Build a function call using a vector of arguments.
    4376                 :             :    If FUNCTION is the result of resolving an overloaded target built-in,
    4377                 :             :    ORIG_FNDECL is the original function decl, otherwise it is null.
    4378                 :             :    PARAMS may be NULL if there are no parameters.  This changes the
    4379                 :             :    contents of PARAMS.  */
    4380                 :             : 
    4381                 :             : tree
    4382                 :     3459963 : cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
    4383                 :             :                             tsubst_flags_t complain, tree orig_fndecl)
    4384                 :             : {
    4385                 :     3459963 :   tree fntype, fndecl;
    4386                 :     3459963 :   int is_method;
    4387                 :     3459963 :   tree original = function;
    4388                 :     3459963 :   int nargs;
    4389                 :     3459963 :   tree *argarray;
    4390                 :     3459963 :   tree parm_types;
    4391                 :     3459963 :   vec<tree, va_gc> *allocated = NULL;
    4392                 :     3459963 :   tree ret;
    4393                 :             : 
    4394                 :             :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4395                 :             :      expressions, like those used for ObjC messenger dispatches.  */
    4396                 :     3459963 :   if (params != NULL && !vec_safe_is_empty (*params))
    4397                 :     1607077 :     function = objc_rewrite_function_call (function, (**params)[0]);
    4398                 :             : 
    4399                 :             :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4400                 :             :      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
    4401                 :     3459963 :   if (TREE_CODE (function) == NOP_EXPR
    4402                 :     3459963 :       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
    4403                 :          15 :     function = TREE_OPERAND (function, 0);
    4404                 :             : 
    4405                 :     3459963 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4406                 :             :     {
    4407                 :     1234291 :       if (!mark_used (function, complain))
    4408                 :          24 :         return error_mark_node;
    4409                 :     1234267 :       fndecl = function;
    4410                 :             : 
    4411                 :             :       /* Convert anything with function type to a pointer-to-function.  */
    4412                 :     1234267 :       if (DECL_MAIN_P (function))
    4413                 :             :         {
    4414                 :           0 :           if (complain & tf_error)
    4415                 :           0 :             pedwarn (input_location, OPT_Wpedantic, 
    4416                 :             :                      "ISO C++ forbids calling %<::main%> from within program");
    4417                 :             :           else
    4418                 :           0 :             return error_mark_node;
    4419                 :             :         }
    4420                 :     1234267 :       function = build_addr_func (function, complain);
    4421                 :             :     }
    4422                 :             :   else
    4423                 :             :     {
    4424                 :     2225672 :       fndecl = NULL_TREE;
    4425                 :             : 
    4426                 :     2225672 :       function = build_addr_func (function, complain);
    4427                 :             :     }
    4428                 :             : 
    4429                 :     3459939 :   if (function == error_mark_node)
    4430                 :             :     return error_mark_node;
    4431                 :             : 
    4432                 :     3459837 :   fntype = TREE_TYPE (function);
    4433                 :             : 
    4434                 :     3459837 :   if (TYPE_PTRMEMFUNC_P (fntype))
    4435                 :             :     {
    4436                 :          15 :       if (complain & tf_error)
    4437                 :          15 :         error ("must use %<.*%> or %<->*%> to call pointer-to-member "
    4438                 :             :                "function in %<%E (...)%>, e.g. %<(... ->* %E) (...)%>",
    4439                 :             :                original, original);
    4440                 :          15 :       return error_mark_node;
    4441                 :             :     }
    4442                 :             : 
    4443                 :     6919644 :   is_method = (TYPE_PTR_P (fntype)
    4444                 :     3459822 :                && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
    4445                 :             : 
    4446                 :     3459822 :   if (!(TYPE_PTRFN_P (fntype)
    4447                 :       87565 :         || is_method
    4448                 :        1367 :         || TREE_CODE (function) == TEMPLATE_ID_EXPR))
    4449                 :             :     {
    4450                 :        1367 :       if (complain & tf_error)
    4451                 :             :         {
    4452                 :         149 :           if (!flag_diagnostics_show_caret)
    4453                 :         149 :             error_at (input_location,
    4454                 :             :                       "%qE cannot be used as a function", original);
    4455                 :           0 :           else if (DECL_P (original))
    4456                 :           0 :             error_at (input_location,
    4457                 :             :                       "%qD cannot be used as a function", original);
    4458                 :             :           else 
    4459                 :           0 :             error_at (input_location,
    4460                 :             :                       "expression cannot be used as a function");
    4461                 :             :         }
    4462                 :             : 
    4463                 :        1367 :       return error_mark_node;
    4464                 :             :     }
    4465                 :             : 
    4466                 :             :   /* fntype now gets the type of function pointed to.  */
    4467                 :     3458455 :   fntype = TREE_TYPE (fntype);
    4468                 :     3458455 :   parm_types = TYPE_ARG_TYPES (fntype);
    4469                 :             : 
    4470                 :     3458455 :   if (params == NULL)
    4471                 :             :     {
    4472                 :      143315 :       allocated = make_tree_vector ();
    4473                 :      143315 :       params = &allocated;
    4474                 :             :     }
    4475                 :             : 
    4476                 :     3458455 :     nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
    4477                 :             :                                complain);
    4478                 :     3458455 :   if (nargs < 0)
    4479                 :        1215 :     return error_mark_node;
    4480                 :             : 
    4481                 :     3457240 :   argarray = (*params)->address ();
    4482                 :             : 
    4483                 :             :   /* Check for errors in format strings and inappropriately
    4484                 :             :      null parameters.  */
    4485                 :     3457240 :   bool warned_p = check_function_arguments (input_location, fndecl, fntype,
    4486                 :             :                                             nargs, argarray, NULL,
    4487                 :             :                                             cp_comp_parm_types);
    4488                 :             : 
    4489                 :     3457240 :   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
    4490                 :             : 
    4491                 :     3457240 :   if (warned_p)
    4492                 :             :     {
    4493                 :          27 :       tree c = extract_call_expr (ret);
    4494                 :          27 :       if (TREE_CODE (c) == CALL_EXPR)
    4495                 :          27 :         suppress_warning (c, OPT_Wnonnull);
    4496                 :             :     }
    4497                 :             : 
    4498                 :     3457240 :   if (allocated != NULL)
    4499                 :      143315 :     release_tree_vector (allocated);
    4500                 :             : 
    4501                 :             :   return ret;
    4502                 :             : }
    4503                 :             : 
    4504                 :             : /* Subroutine of convert_arguments.
    4505                 :             :    Print an error message about a wrong number of arguments.  */
    4506                 :             : 
    4507                 :             : static void
    4508                 :         147 : error_args_num (location_t loc, tree fndecl, bool too_many_p)
    4509                 :             : {
    4510                 :         147 :   if (fndecl)
    4511                 :             :     {
    4512                 :         114 :       auto_diagnostic_group d;
    4513                 :         114 :       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
    4514                 :             :         {
    4515                 :           0 :           if (DECL_NAME (fndecl) == NULL_TREE
    4516                 :           0 :               || (DECL_NAME (fndecl)
    4517                 :           0 :                   == DECL_NAME (TYPE_NAME (DECL_CONTEXT (fndecl)))))
    4518                 :           0 :             error_at (loc,
    4519                 :             :                       too_many_p
    4520                 :             :                       ? G_("too many arguments to constructor %q#D")
    4521                 :             :                       : G_("too few arguments to constructor %q#D"),
    4522                 :             :                       fndecl);
    4523                 :             :           else
    4524                 :           0 :             error_at (loc,
    4525                 :             :                       too_many_p
    4526                 :             :                       ? G_("too many arguments to member function %q#D")
    4527                 :             :                       : G_("too few arguments to member function %q#D"),
    4528                 :             :                       fndecl);
    4529                 :             :         }
    4530                 :             :       else
    4531                 :         171 :         error_at (loc,
    4532                 :             :                   too_many_p
    4533                 :             :                   ? G_("too many arguments to function %q#D")
    4534                 :             :                   : G_("too few arguments to function %q#D"),
    4535                 :             :                   fndecl);
    4536                 :         114 :       if (!DECL_IS_UNDECLARED_BUILTIN (fndecl))
    4537                 :          75 :         inform (DECL_SOURCE_LOCATION (fndecl), "declared here");
    4538                 :         114 :     }
    4539                 :             :   else
    4540                 :             :     {
    4541                 :          33 :       if (c_dialect_objc ()  &&  objc_message_selector ())
    4542                 :           0 :         error_at (loc,
    4543                 :             :                   too_many_p 
    4544                 :             :                   ? G_("too many arguments to method %q#D")
    4545                 :             :                   : G_("too few arguments to method %q#D"),
    4546                 :             :                   objc_message_selector ());
    4547                 :             :       else
    4548                 :          54 :         error_at (loc, too_many_p ? G_("too many arguments to function")
    4549                 :             :                                   : G_("too few arguments to function"));
    4550                 :             :     }
    4551                 :         147 : }
    4552                 :             : 
    4553                 :             : /* Convert the actual parameter expressions in the list VALUES to the
    4554                 :             :    types in the list TYPELIST.  The converted expressions are stored
    4555                 :             :    back in the VALUES vector.
    4556                 :             :    If parmdecls is exhausted, or when an element has NULL as its type,
    4557                 :             :    perform the default conversions.
    4558                 :             : 
    4559                 :             :    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
    4560                 :             : 
    4561                 :             :    This is also where warnings about wrong number of args are generated.
    4562                 :             : 
    4563                 :             :    Returns the actual number of arguments processed (which might be less
    4564                 :             :    than the length of the vector), or -1 on error.
    4565                 :             : 
    4566                 :             :    In C++, unspecified trailing parameters can be filled in with their
    4567                 :             :    default arguments, if such were specified.  Do so here.  */
    4568                 :             : 
    4569                 :             : static int
    4570                 :     3458455 : convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
    4571                 :             :                    int flags, tsubst_flags_t complain)
    4572                 :             : {
    4573                 :     3458455 :   tree typetail;
    4574                 :     3458455 :   unsigned int i;
    4575                 :             : 
    4576                 :             :   /* Argument passing is always copy-initialization.  */
    4577                 :     3458455 :   flags |= LOOKUP_ONLYCONVERTING;
    4578                 :             : 
    4579                 :     7095187 :   for (i = 0, typetail = typelist;
    4580                 :    14190374 :        i < vec_safe_length (*values);
    4581                 :             :        i++)
    4582                 :             :     {
    4583                 :     7275316 :       tree type = typetail ? TREE_VALUE (typetail) : 0;
    4584                 :     3637872 :       tree val = (**values)[i];
    4585                 :             : 
    4586                 :     3637872 :       if (val == error_mark_node || type == error_mark_node)
    4587                 :             :         return -1;
    4588                 :             : 
    4589                 :     3637866 :       if (type == void_type_node)
    4590                 :             :         {
    4591                 :         190 :           if (complain & tf_error)
    4592                 :             :             {
    4593                 :          69 :               error_args_num (input_location, fndecl, /*too_many_p=*/true);
    4594                 :          69 :               return i;
    4595                 :             :             }
    4596                 :             :           else
    4597                 :             :             return -1;
    4598                 :             :         }
    4599                 :             : 
    4600                 :             :       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4601                 :             :          Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
    4602                 :     3637676 :       if (TREE_CODE (val) == NOP_EXPR
    4603                 :      844294 :           && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
    4604                 :     3637694 :           && (type == 0 || !TYPE_REF_P (type)))
    4605                 :          18 :         val = TREE_OPERAND (val, 0);
    4606                 :             : 
    4607                 :     3637676 :       if (type == 0 || !TYPE_REF_P (type))
    4608                 :             :         {
    4609                 :     3426424 :           if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
    4610                 :     3426424 :               || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (val)))
    4611                 :       10960 :             val = decay_conversion (val, complain);
    4612                 :             :         }
    4613                 :             : 
    4614                 :     3637676 :       if (val == error_mark_node)
    4615                 :             :         return -1;
    4616                 :             : 
    4617                 :     3637676 :       if (type != 0)
    4618                 :             :         {
    4619                 :             :           /* Formal parm type is specified by a function prototype.  */
    4620                 :     3637248 :           tree parmval;
    4621                 :             : 
    4622                 :     3637248 :           if (!COMPLETE_TYPE_P (complete_type (type)))
    4623                 :             :             {
    4624                 :          18 :               if (complain & tf_error)
    4625                 :             :                 {
    4626                 :          12 :                   location_t loc = EXPR_LOC_OR_LOC (val, input_location);
    4627                 :          12 :                   if (fndecl)
    4628                 :             :                     {
    4629                 :          12 :                       auto_diagnostic_group d;
    4630                 :          12 :                       error_at (loc,
    4631                 :             :                                 "parameter %P of %qD has incomplete type %qT",
    4632                 :             :                                 i, fndecl, type);
    4633                 :          12 :                       inform (get_fndecl_argument_location (fndecl, i),
    4634                 :             :                               "  declared here");
    4635                 :          12 :                     }
    4636                 :             :                   else
    4637                 :           0 :                     error_at (loc, "parameter %P has incomplete type %qT", i,
    4638                 :             :                               type);
    4639                 :             :                 }
    4640                 :          18 :               parmval = error_mark_node;
    4641                 :             :             }
    4642                 :             :           else
    4643                 :             :             {
    4644                 :     3637230 :               parmval = convert_for_initialization
    4645                 :     3637230 :                 (NULL_TREE, type, val, flags,
    4646                 :             :                  ICR_ARGPASS, fndecl, i, complain);
    4647                 :     3637230 :               parmval = convert_for_arg_passing (type, parmval, complain);
    4648                 :             :             }
    4649                 :             : 
    4650                 :     3637248 :           if (parmval == error_mark_node)
    4651                 :             :             return -1;
    4652                 :             : 
    4653                 :     3636304 :           (**values)[i] = parmval;
    4654                 :             :         }
    4655                 :             :       else
    4656                 :             :         {
    4657                 :         428 :           int magic = fndecl ? magic_varargs_p (fndecl) : 0;
    4658                 :           3 :           if (magic)
    4659                 :             :             {
    4660                 :             :               /* Don't truncate excess precision to the semantic type.  */
    4661                 :           0 :               if (magic == 1 && TREE_CODE (val) == EXCESS_PRECISION_EXPR)
    4662                 :           0 :                 val = TREE_OPERAND (val, 0);
    4663                 :             :               /* Don't do ellipsis conversion for __built_in_constant_p
    4664                 :             :                  as this will result in spurious errors for non-trivial
    4665                 :             :                  types.  */
    4666                 :           0 :               val = require_complete_type (val, complain);
    4667                 :             :             }
    4668                 :             :           else
    4669                 :         428 :             val = convert_arg_to_ellipsis (val, complain);
    4670                 :             : 
    4671                 :         428 :           (**values)[i] = val;
    4672                 :             :         }
    4673                 :             : 
    4674                 :     3636732 :       if (typetail)
    4675                 :     3636304 :         typetail = TREE_CHAIN (typetail);
    4676                 :             :     }
    4677                 :             : 
    4678                 :     3457315 :   if (typetail != 0 && typetail != void_list_node)
    4679                 :             :     {
    4680                 :             :       /* See if there are default arguments that can be used.  Because
    4681                 :             :          we hold default arguments in the FUNCTION_TYPE (which is so
    4682                 :             :          wrong), we can see default parameters here from deduced
    4683                 :             :          contexts (and via typeof) for indirect function calls.
    4684                 :             :          Fortunately we know whether we have a function decl to
    4685                 :             :          provide default arguments in a language conformant
    4686                 :             :          manner.  */
    4687                 :          57 :       if (fndecl && TREE_PURPOSE (typetail)
    4688                 :         147 :           && TREE_CODE (TREE_PURPOSE (typetail)) != DEFERRED_PARSE)
    4689                 :             :         {
    4690                 :           6 :           for (; typetail != void_list_node; ++i)
    4691                 :             :             {
    4692                 :             :               /* After DR777, with explicit template args we can end up with a
    4693                 :             :                  default argument followed by no default argument.  */
    4694                 :           6 :               if (!TREE_PURPOSE (typetail))
    4695                 :             :                 break;
    4696                 :           3 :               tree parmval
    4697                 :           3 :                 = convert_default_arg (TREE_VALUE (typetail),
    4698                 :           3 :                                        TREE_PURPOSE (typetail),
    4699                 :           3 :                                        fndecl, i, complain);
    4700                 :             : 
    4701                 :           3 :               if (parmval == error_mark_node)
    4702                 :           0 :                 return -1;
    4703                 :             : 
    4704                 :           3 :               vec_safe_push (*values, parmval);
    4705                 :           3 :               typetail = TREE_CHAIN (typetail);
    4706                 :             :               /* ends with `...'.  */
    4707                 :           3 :               if (typetail == NULL_TREE)
    4708                 :             :                 break;
    4709                 :             :             }
    4710                 :             :         }
    4711                 :             : 
    4712                 :         144 :       if (typetail && typetail != void_list_node)
    4713                 :             :         {
    4714                 :         144 :           if (complain & tf_error)
    4715                 :          78 :             error_args_num (input_location, fndecl, /*too_many_p=*/false);
    4716                 :         144 :           return -1;
    4717                 :             :         }
    4718                 :             :     }
    4719                 :             : 
    4720                 :     3457171 :   return (int) i;
    4721                 :             : }
    4722                 :             : 
    4723                 :             : /* Build a binary-operation expression, after performing default
    4724                 :             :    conversions on the operands.  CODE is the kind of expression to
    4725                 :             :    build.  ARG1 and ARG2 are the arguments.  ARG1_CODE and ARG2_CODE
    4726                 :             :    are the tree codes which correspond to ARG1 and ARG2 when issuing
    4727                 :             :    warnings about possibly misplaced parentheses.  They may differ
    4728                 :             :    from the TREE_CODE of ARG1 and ARG2 if the parser has done constant
    4729                 :             :    folding (e.g., if the parser sees "a | 1 + 1", it may call this
    4730                 :             :    routine with ARG2 being an INTEGER_CST and ARG2_CODE == PLUS_EXPR).
    4731                 :             :    To avoid issuing any parentheses warnings, pass ARG1_CODE and/or
    4732                 :             :    ARG2_CODE as ERROR_MARK.  */
    4733                 :             : 
    4734                 :             : tree
    4735                 :   180862968 : build_x_binary_op (const op_location_t &loc, enum tree_code code, tree arg1,
    4736                 :             :                    enum tree_code arg1_code, tree arg2,
    4737                 :             :                    enum tree_code arg2_code, tree lookups,
    4738                 :             :                    tree *overload_p, tsubst_flags_t complain)
    4739                 :             : {
    4740                 :   180862968 :   tree orig_arg1;
    4741                 :   180862968 :   tree orig_arg2;
    4742                 :   180862968 :   tree expr;
    4743                 :   180862968 :   tree overload = NULL_TREE;
    4744                 :             : 
    4745                 :   180862968 :   orig_arg1 = arg1;
    4746                 :   180862968 :   orig_arg2 = arg2;
    4747                 :             : 
    4748                 :   180862968 :   if (processing_template_decl)
    4749                 :             :     {
    4750                 :   106869205 :       if (type_dependent_expression_p (arg1)
    4751                 :   106869205 :           || type_dependent_expression_p (arg2))
    4752                 :             :         {
    4753                 :    78304059 :           expr = build_min_nt_loc (loc, code, arg1, arg2);
    4754                 :    78304059 :           TREE_TYPE (expr)
    4755                 :    78304059 :             = build_dependent_operator_type (lookups, code, false);
    4756                 :    78304059 :           return expr;
    4757                 :             :         }
    4758                 :             :     }
    4759                 :             : 
    4760                 :   102558909 :   if (code == DOTSTAR_EXPR)
    4761                 :      105674 :     expr = build_m_component_ref (arg1, arg2, complain);
    4762                 :             :   else
    4763                 :   102453235 :     expr = build_new_op (loc, code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
    4764                 :             :                          lookups, &overload, complain);
    4765                 :             : 
    4766                 :   102558876 :   if (overload_p != NULL)
    4767                 :    41706758 :     *overload_p = overload;
    4768                 :             : 
    4769                 :             :   /* Check for cases such as x+y<<z which users are likely to
    4770                 :             :      misinterpret.  But don't warn about obj << x + y, since that is a
    4771                 :             :      common idiom for I/O.  */
    4772                 :   102558876 :   if (warn_parentheses
    4773                 :     1102679 :       && (complain & tf_warning)
    4774                 :     1065822 :       && !processing_template_decl
    4775                 :      747970 :       && !error_operand_p (arg1)
    4776                 :      747964 :       && !error_operand_p (arg2)
    4777                 :   103306828 :       && (code != LSHIFT_EXPR
    4778                 :       69688 :           || !CLASS_TYPE_P (TREE_TYPE (arg1))))
    4779                 :      746999 :     warn_about_parentheses (loc, code, arg1_code, orig_arg1,
    4780                 :             :                             arg2_code, orig_arg2);
    4781                 :             : 
    4782                 :   102558876 :   if (processing_template_decl && expr != error_mark_node)
    4783                 :             :     {
    4784                 :    28564963 :       if (overload != NULL_TREE)
    4785                 :     1933013 :         return (build_min_non_dep_op_overload
    4786                 :     1933013 :                 (code, expr, overload, orig_arg1, orig_arg2));
    4787                 :             : 
    4788                 :    26631950 :       return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
    4789                 :             :     }
    4790                 :             : 
    4791                 :             :   return expr;
    4792                 :             : }
    4793                 :             : 
    4794                 :             : /* Build and return an ARRAY_REF expression.  */
    4795                 :             : 
    4796                 :             : tree
    4797                 :     1711930 : build_x_array_ref (location_t loc, tree arg1, tree arg2,
    4798                 :             :                    tsubst_flags_t complain)
    4799                 :             : {
    4800                 :     1711930 :   tree orig_arg1 = arg1;
    4801                 :     1711930 :   tree orig_arg2 = arg2;
    4802                 :     1711930 :   tree expr;
    4803                 :     1711930 :   tree overload = NULL_TREE;
    4804                 :             : 
    4805                 :     1711930 :   if (processing_template_decl)
    4806                 :             :     {
    4807                 :         618 :       if (type_dependent_expression_p (arg1)
    4808                 :         618 :           || type_dependent_expression_p (arg2))
    4809                 :         600 :         return build_min_nt_loc (loc, ARRAY_REF, arg1, arg2,
    4810                 :         600 :                                  NULL_TREE, NULL_TREE);
    4811                 :             :     }
    4812                 :             : 
    4813                 :     1711330 :   expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, arg1, arg2,
    4814                 :             :                        NULL_TREE, NULL_TREE, &overload, complain);
    4815                 :             : 
    4816                 :     1711330 :   if (processing_template_decl && expr != error_mark_node)
    4817                 :             :     {
    4818                 :          15 :       if (overload != NULL_TREE)
    4819                 :           1 :         return (build_min_non_dep_op_overload
    4820                 :           1 :                 (ARRAY_REF, expr, overload, orig_arg1, orig_arg2));
    4821                 :             : 
    4822                 :          14 :       return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
    4823                 :          14 :                                 NULL_TREE, NULL_TREE);
    4824                 :             :     }
    4825                 :             :   return expr;
    4826                 :             : }
    4827                 :             : 
    4828                 :             : /* Build an OpenMP array section reference, creating an exact type for the
    4829                 :             :    resulting expression based on the element type and bounds if possible.  If
    4830                 :             :    we have variable bounds, create an incomplete array type for the result
    4831                 :             :    instead.  */
    4832                 :             : 
    4833                 :             : tree
    4834                 :       10327 : build_omp_array_section (location_t loc, tree array_expr, tree index,
    4835                 :             :                          tree length)
    4836                 :             : {
    4837                 :       10327 :   tree type = TREE_TYPE (array_expr);
    4838                 :       10327 :   gcc_assert (type);
    4839                 :       10327 :   type = non_reference (type);
    4840                 :             : 
    4841                 :       10327 :   tree sectype, eltype = TREE_TYPE (type);
    4842                 :             : 
    4843                 :             :   /* It's not an array or pointer type.  Just reuse the type of the
    4844                 :             :      original expression as the type of the array section (an error will be
    4845                 :             :      raised anyway, later).  */
    4846                 :       10327 :   if (eltype == NULL_TREE)
    4847                 :          51 :     sectype = TREE_TYPE (array_expr);
    4848                 :             :   else
    4849                 :             :     {
    4850                 :       10276 :       tree idxtype = NULL_TREE;
    4851                 :             : 
    4852                 :             :       /* If we know the integer bounds, create an index type with exact
    4853                 :             :          low/high (or zero/length) bounds.  Otherwise, create an incomplete
    4854                 :             :          array type.  (This mostly only affects diagnostics.)  */
    4855                 :       10276 :       if (index != NULL_TREE
    4856                 :       10276 :           && length != NULL_TREE
    4857                 :        7429 :           && TREE_CODE (index) == INTEGER_CST
    4858                 :        6591 :           && TREE_CODE (length) == INTEGER_CST)
    4859                 :             :         {
    4860                 :        5183 :           tree low = fold_convert (sizetype, index);
    4861                 :        5183 :           tree high = fold_convert (sizetype, length);
    4862                 :        5183 :           high = size_binop (PLUS_EXPR, low, high);
    4863                 :        5183 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    4864                 :        5183 :           idxtype = build_range_type (sizetype, low, high);
    4865                 :        5183 :         }
    4866                 :        2906 :       else if ((index == NULL_TREE || integer_zerop (index))
    4867                 :        3418 :                && length != NULL_TREE
    4868                 :        6999 :                && TREE_CODE (length) == INTEGER_CST)
    4869                 :        1361 :         idxtype = build_index_type (length);
    4870                 :             : 
    4871                 :       10276 :       sectype = build_array_type (eltype, idxtype);
    4872                 :             :     }
    4873                 :             : 
    4874                 :       10327 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array_expr, index,
    4875                 :       10327 :                      length);
    4876                 :             : }
    4877                 :             : 
    4878                 :             : /* Return whether OP is an expression of enum type cast to integer
    4879                 :             :    type.  In C++ even unsigned enum types are cast to signed integer
    4880                 :             :    types.  We do not want to issue warnings about comparisons between
    4881                 :             :    signed and unsigned types when one of the types is an enum type.
    4882                 :             :    Those warnings are always false positives in practice.  */
    4883                 :             : 
    4884                 :             : static bool
    4885                 :      608444 : enum_cast_to_int (tree op)
    4886                 :             : {
    4887                 :      596924 :   if (CONVERT_EXPR_P (op)
    4888                 :       12582 :       && TREE_TYPE (op) == integer_type_node
    4889                 :         763 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == ENUMERAL_TYPE
    4890                 :      608482 :       && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 0))))
    4891                 :             :     return true;
    4892                 :             : 
    4893                 :             :   /* The cast may have been pushed into a COND_EXPR.  */
    4894                 :      608414 :   if (TREE_CODE (op) == COND_EXPR)
    4895                 :         755 :     return (enum_cast_to_int (TREE_OPERAND (op, 1))
    4896                 :         755 :             || enum_cast_to_int (TREE_OPERAND (op, 2)));
    4897                 :             : 
    4898                 :             :   return false;
    4899                 :             : }
    4900                 :             : 
    4901                 :             : /* For the c-common bits.  */
    4902                 :             : tree
    4903                 :     5208092 : build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
    4904                 :             :                  bool /*convert_p*/)
    4905                 :             : {
    4906                 :     5208092 :   return cp_build_binary_op (location, code, op0, op1, tf_warning_or_error);
    4907                 :             : }
    4908                 :             : 
    4909                 :             : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
    4910                 :             :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
    4911                 :             : 
    4912                 :             : static tree
    4913                 :        6528 : build_vec_cmp (tree_code code, tree type,
    4914                 :             :                tree arg0, tree arg1)
    4915                 :             : {
    4916                 :        6528 :   tree zero_vec = build_zero_cst (type);
    4917                 :        6528 :   tree minus_one_vec = build_minus_one_cst (type);
    4918                 :        6528 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
    4919                 :        6528 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
    4920                 :        6528 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
    4921                 :             : }
    4922                 :             : 
    4923                 :             : /* Possibly warn about an address never being NULL.  */
    4924                 :             : 
    4925                 :             : static void
    4926                 :     1524087 : warn_for_null_address (location_t location, tree op, tsubst_flags_t complain)
    4927                 :             : {
    4928                 :             :   /* Prevent warnings issued for macro expansion.  */
    4929                 :     1524087 :   if (!warn_address
    4930                 :       39466 :       || (complain & tf_warning) == 0
    4931                 :       23502 :       || c_inhibit_evaluation_warnings != 0
    4932                 :       23462 :       || from_macro_expansion_at (location)
    4933                 :     1541099 :       || warning_suppressed_p (op, OPT_Waddress))
    4934                 :     1507422 :     return;
    4935                 :             : 
    4936                 :       16979 :   tree cop = fold_for_warn (op);
    4937                 :             : 
    4938                 :       16979 :   if (TREE_CODE (cop) == NON_LVALUE_EXPR)
    4939                 :             :     /* Unwrap the expression for C++ 98.  */
    4940                 :           1 :     cop = TREE_OPERAND (cop, 0);
    4941                 :             : 
    4942                 :       16979 :   if (TREE_CODE (cop) == PTRMEM_CST)
    4943                 :             :     {
    4944                 :             :       /* The address of a nonstatic data member is never null.  */
    4945                 :          30 :       warning_at (location, OPT_Waddress,
    4946                 :             :                   "the address %qE will never be NULL",
    4947                 :             :                   cop);
    4948                 :          30 :       return;
    4949                 :             :     }
    4950                 :             : 
    4951                 :       16949 :   if (TREE_CODE (cop) == NOP_EXPR)
    4952                 :             :     {
    4953                 :             :       /* Allow casts to intptr_t to suppress the warning.  */
    4954                 :        1086 :       tree type = TREE_TYPE (cop);
    4955                 :        1086 :       if (TREE_CODE (type) == INTEGER_TYPE)
    4956                 :             :         return;
    4957                 :             : 
    4958                 :        1086 :       STRIP_NOPS (cop);
    4959                 :             :     }
    4960                 :             : 
    4961                 :       16949 :   auto_diagnostic_group d;
    4962                 :       16949 :   bool warned = false;
    4963                 :       16949 :   if (TREE_CODE (cop) == ADDR_EXPR)
    4964                 :             :     {
    4965                 :         821 :       cop = TREE_OPERAND (cop, 0);
    4966                 :             : 
    4967                 :             :       /* Set to true in the loop below if OP dereferences its operand.
    4968                 :             :          In such a case the ultimate target need not be a decl for
    4969                 :             :          the null [in]equality test to be necessarily constant.  */
    4970                 :         821 :       bool deref = false;
    4971                 :             : 
    4972                 :             :       /* Get the outermost array or object, or member.  */
    4973                 :         992 :       while (handled_component_p (cop))
    4974                 :             :         {
    4975                 :         270 :           if (TREE_CODE (cop) == COMPONENT_REF)
    4976                 :             :             {
    4977                 :             :               /* Get the member (its address is never null).  */
    4978                 :          99 :               cop = TREE_OPERAND (cop, 1);
    4979                 :          99 :               break;
    4980                 :             :             }
    4981                 :             : 
    4982                 :             :           /* Get the outer array/object to refer to in the warning.  */
    4983                 :         171 :           cop = TREE_OPERAND (cop, 0);
    4984                 :         171 :           deref = true;
    4985                 :             :         }
    4986                 :             : 
    4987                 :         671 :       if ((!deref && !decl_with_nonnull_addr_p (cop))
    4988                 :         639 :           || from_macro_expansion_at (location)
    4989                 :        1460 :           || warning_suppressed_p (cop, OPT_Waddress))
    4990                 :         182 :         return;
    4991                 :             : 
    4992                 :         639 :       warned = warning_at (location, OPT_Waddress,
    4993                 :             :                            "the address of %qD will never be NULL", cop);
    4994                 :         639 :       op = cop;
    4995                 :             :     }
    4996                 :       16128 :   else if (TREE_CODE (cop) == POINTER_PLUS_EXPR)
    4997                 :             :     {
    4998                 :             :       /* Adding zero to the null pointer is well-defined in C++.  When
    4999                 :             :          the offset is unknown (i.e., not a constant) warn anyway since
    5000                 :             :          it's less likely that the pointer operand is null than not.  */
    5001                 :         102 :       tree off = TREE_OPERAND (cop, 1);
    5002                 :         102 :       if (!integer_zerop (off)
    5003                 :         102 :           && !warning_suppressed_p (cop, OPT_Waddress))
    5004                 :             :         {
    5005                 :         102 :           tree base = TREE_OPERAND (cop, 0);
    5006                 :         102 :           STRIP_NOPS (base);
    5007                 :         102 :           if (TYPE_REF_P (TREE_TYPE (base)))
    5008                 :          12 :             warning_at (location, OPT_Waddress, "the compiler can assume that "
    5009                 :             :                         "the address of %qE will never be NULL", base);
    5010                 :             :           else
    5011                 :          90 :             warning_at (location, OPT_Waddress, "comparing the result of "
    5012                 :             :                         "pointer addition %qE and NULL", cop);
    5013                 :             :         }
    5014                 :         102 :       return;
    5015                 :             :     }
    5016                 :       15221 :   else if (CONVERT_EXPR_P (op)
    5017                 :       16088 :            && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0))))
    5018                 :             :     {
    5019                 :          62 :       STRIP_NOPS (op);
    5020                 :             : 
    5021                 :          62 :       if (TREE_CODE (op) == COMPONENT_REF)
    5022                 :          24 :         op = TREE_OPERAND (op, 1);
    5023                 :             : 
    5024                 :          62 :       if (DECL_P (op))
    5025                 :          62 :         warned = warning_at (location, OPT_Waddress,
    5026                 :             :                              "the compiler can assume that the address of "
    5027                 :             :                              "%qD will never be NULL", op);
    5028                 :             :     }
    5029                 :             : 
    5030                 :         701 :   if (warned && DECL_P (op))
    5031                 :         665 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
    5032                 :       16949 : }
    5033                 :             : 
    5034                 :             : /* Warn about [expr.arith.conv]/2: If one operand is of enumeration type and
    5035                 :             :    the other operand is of a different enumeration type or a floating-point
    5036                 :             :    type, this behavior is deprecated ([depr.arith.conv.enum]).  CODE is the
    5037                 :             :    code of the binary operation, TYPE0 and TYPE1 are the types of the operands,
    5038                 :             :    and LOC is the location for the whole binary expression.
    5039                 :             :    For C++26 this is ill-formed rather than deprecated.
    5040                 :             :    Return true for SFINAE errors.
    5041                 :             :    TODO: Consider combining this with -Wenum-compare in build_new_op_1.  */
    5042                 :             : 
    5043                 :             : static bool
    5044                 :    90038158 : do_warn_enum_conversions (location_t loc, enum tree_code code, tree type0,
    5045                 :             :                           tree type1, tsubst_flags_t complain)
    5046                 :             : {
    5047                 :    90038158 :   if (TREE_CODE (type0) == ENUMERAL_TYPE
    5048                 :     2575057 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5049                 :    92081190 :       && TYPE_MAIN_VARIANT (type0) != TYPE_MAIN_VARIANT (type1))
    5050                 :             :     {
    5051                 :         198 :       if (cxx_dialect >= cxx26)
    5052                 :             :         {
    5053                 :          60 :           if ((complain & tf_warning_or_error) == 0)
    5054                 :             :             return true;
    5055                 :             :         }
    5056                 :         138 :       else if ((complain & tf_warning) == 0)
    5057                 :             :         return false;
    5058                 :             :       /* In C++20, -Wdeprecated-enum-enum-conversion is on by default.
    5059                 :             :          Otherwise, warn if -Wenum-conversion is on.  */
    5060                 :         190 :       enum opt_code opt;
    5061                 :         190 :       if (warn_deprecated_enum_enum_conv)
    5062                 :             :         opt = OPT_Wdeprecated_enum_enum_conversion;
    5063                 :          97 :       else if (warn_enum_conversion)
    5064                 :             :         opt = OPT_Wenum_conversion;
    5065                 :             :       else
    5066                 :             :         return false;
    5067                 :             : 
    5068                 :         115 :       switch (code)
    5069                 :             :         {
    5070                 :             :         case GT_EXPR:
    5071                 :             :         case LT_EXPR:
    5072                 :             :         case GE_EXPR:
    5073                 :             :         case LE_EXPR:
    5074                 :             :         case EQ_EXPR:
    5075                 :             :         case NE_EXPR:
    5076                 :             :           /* Comparisons are handled by -Wenum-compare.  */
    5077                 :             :           return false;
    5078                 :             :         case SPACESHIP_EXPR:
    5079                 :             :           /* This is invalid, don't warn.  */
    5080                 :             :           return false;
    5081                 :          17 :         case BIT_AND_EXPR:
    5082                 :          17 :         case BIT_IOR_EXPR:
    5083                 :          17 :         case BIT_XOR_EXPR:
    5084                 :          17 :           if (cxx_dialect >= cxx26)
    5085                 :           5 :             pedwarn (loc, opt, "bitwise operation between different "
    5086                 :             :                      "enumeration types %qT and %qT", type0, type1);
    5087                 :             :           else
    5088                 :          12 :             warning_at (loc, opt, "bitwise operation between different "
    5089                 :             :                         "enumeration types %qT and %qT is deprecated",
    5090                 :             :                         type0, type1);
    5091                 :          17 :           return false;
    5092                 :          41 :         default:
    5093                 :          41 :           if (cxx_dialect >= cxx26)
    5094                 :          12 :             pedwarn (loc, opt, "arithmetic between different enumeration "
    5095                 :             :                      "types %qT and %qT", type0, type1);
    5096                 :             :           else
    5097                 :          29 :             warning_at (loc, opt, "arithmetic between different enumeration "
    5098                 :             :                         "types %qT and %qT is deprecated", type0, type1);
    5099                 :          41 :           return false;
    5100                 :             :         }
    5101                 :             :     }
    5102                 :    90037960 :   else if ((TREE_CODE (type0) == ENUMERAL_TYPE
    5103                 :     2574859 :             && SCALAR_FLOAT_TYPE_P (type1))
    5104                 :    90037883 :            || (SCALAR_FLOAT_TYPE_P (type0)
    5105                 :    31414779 :                && TREE_CODE (type1) == ENUMERAL_TYPE))
    5106                 :             :     {
    5107                 :         154 :       if (cxx_dialect >= cxx26)
    5108                 :             :         {
    5109                 :          46 :           if ((complain & tf_warning_or_error) == 0)
    5110                 :             :             return true;
    5111                 :             :         }
    5112                 :         108 :       else if ((complain & tf_warning) == 0)
    5113                 :             :         return false;
    5114                 :         142 :       const bool enum_first_p = TREE_CODE (type0) == ENUMERAL_TYPE;
    5115                 :             :       /* In C++20, -Wdeprecated-enum-float-conversion is on by default.
    5116                 :             :          Otherwise, warn if -Wenum-conversion is on.  */
    5117                 :         142 :       enum opt_code opt;
    5118                 :         142 :       if (warn_deprecated_enum_float_conv)
    5119                 :             :         opt = OPT_Wdeprecated_enum_float_conversion;
    5120                 :          75 :       else if (warn_enum_conversion)
    5121                 :             :         opt = OPT_Wenum_conversion;
    5122                 :             :       else
    5123                 :             :         return false;
    5124                 :             : 
    5125                 :          84 :       switch (code)
    5126                 :             :         {
    5127                 :          34 :         case GT_EXPR:
    5128                 :          34 :         case LT_EXPR:
    5129                 :          34 :         case GE_EXPR:
    5130                 :          34 :         case LE_EXPR:
    5131                 :          34 :         case EQ_EXPR:
    5132                 :          34 :         case NE_EXPR:
    5133                 :          34 :           if (enum_first_p && cxx_dialect >= cxx26)
    5134                 :           5 :             pedwarn (loc, opt, "comparison of enumeration type %qT with "
    5135                 :             :                      "floating-point type %qT", type0, type1);
    5136                 :          29 :           else if (cxx_dialect >= cxx26)
    5137                 :           5 :             pedwarn (loc, opt, "comparison of floating-point type %qT "
    5138                 :             :                       "with enumeration type %qT", type0, type1);
    5139                 :          24 :           else if (enum_first_p)
    5140                 :          12 :             warning_at (loc, opt, "comparison of enumeration type %qT with "
    5141                 :             :                         "floating-point type %qT is deprecated",
    5142                 :             :                         type0, type1);
    5143                 :             :           else
    5144                 :          12 :             warning_at (loc, opt, "comparison of floating-point type %qT "
    5145                 :             :                         "with enumeration type %qT is deprecated",
    5146                 :             :                         type0, type1);
    5147                 :          34 :           return false;
    5148                 :             :         case SPACESHIP_EXPR:
    5149                 :             :           /* This is invalid, don't warn.  */
    5150                 :             :           return false;
    5151                 :          38 :         default:
    5152                 :          38 :           if (enum_first_p && cxx_dialect >= cxx26)
    5153                 :           5 :             pedwarn (loc, opt, "arithmetic between enumeration type %qT "
    5154                 :             :                      "and floating-point type %qT", type0, type1);
    5155                 :          33 :           else if (cxx_dialect >= cxx26)
    5156                 :           6 :             pedwarn (loc, opt, "arithmetic between floating-point type %qT "
    5157                 :             :                      "and enumeration type %qT", type0, type1);
    5158                 :          27 :           else if (enum_first_p)
    5159                 :          12 :             warning_at (loc, opt, "arithmetic between enumeration type %qT "
    5160                 :             :                         "and floating-point type %qT is deprecated",
    5161                 :             :                         type0, type1);
    5162                 :             :           else
    5163                 :          15 :             warning_at (loc, opt, "arithmetic between floating-point type %qT "
    5164                 :             :                         "and enumeration type %qT is deprecated",
    5165                 :             :                         type0, type1);
    5166                 :          38 :           return false;
    5167                 :             :         }
    5168                 :             :     }
    5169                 :             :   return false;
    5170                 :             : }
    5171                 :             : 
    5172                 :             : /* Build a binary-operation expression without default conversions.
    5173                 :             :    CODE is the kind of expression to build.
    5174                 :             :    LOCATION is the location_t of the operator in the source code.
    5175                 :             :    This function differs from `build' in several ways:
    5176                 :             :    the data type of the result is computed and recorded in it,
    5177                 :             :    warnings are generated if arg data types are invalid,
    5178                 :             :    special handling for addition and subtraction of pointers is known,
    5179                 :             :    and some optimization is done (operations on narrow ints
    5180                 :             :    are done in the narrower type when that gives the same result).
    5181                 :             :    Constant folding is also done before the result is returned.
    5182                 :             : 
    5183                 :             :    Note that the operands will never have enumeral types
    5184                 :             :    because either they have just had the default conversions performed
    5185                 :             :    or they have both just been converted to some other type in which
    5186                 :             :    the arithmetic is to be done.
    5187                 :             : 
    5188                 :             :    C++: must do special pointer arithmetic when implementing
    5189                 :             :    multiple inheritance, and deal with pointer to member functions.  */
    5190                 :             : 
    5191                 :             : tree
    5192                 :   114022499 : cp_build_binary_op (const op_location_t &location,
    5193                 :             :                     enum tree_code code, tree orig_op0, tree orig_op1,
    5194                 :             :                     tsubst_flags_t complain)
    5195                 :             : {
    5196                 :   114022499 :   tree op0, op1;
    5197                 :   114022499 :   enum tree_code code0, code1;
    5198                 :   114022499 :   tree type0, type1, orig_type0, orig_type1;
    5199                 :   114022499 :   const char *invalid_op_diag;
    5200                 :             : 
    5201                 :             :   /* Expression code to give to the expression when it is built.
    5202                 :             :      Normally this is CODE, which is what the caller asked for,
    5203                 :             :      but in some special cases we change it.  */
    5204                 :   114022499 :   enum tree_code resultcode = code;
    5205                 :             : 
    5206                 :             :   /* Data type in which the computation is to be performed.
    5207                 :             :      In the simplest cases this is the common type of the arguments.  */
    5208                 :   114022499 :   tree result_type = NULL_TREE;
    5209                 :             : 
    5210                 :             :   /* When the computation is in excess precision, the type of the
    5211                 :             :      final EXCESS_PRECISION_EXPR.  */
    5212                 :   114022499 :   tree semantic_result_type = NULL;
    5213                 :             : 
    5214                 :             :   /* Nonzero means operands have already been type-converted
    5215                 :             :      in whatever way is necessary.
    5216                 :             :      Zero means they need to be converted to RESULT_TYPE.  */
    5217                 :   114022499 :   int converted = 0;
    5218                 :             : 
    5219                 :             :   /* Nonzero means create the expression with this type, rather than
    5220                 :             :      RESULT_TYPE.  */
    5221                 :   114022499 :   tree build_type = 0;
    5222                 :             : 
    5223                 :             :   /* Nonzero means after finally constructing the expression
    5224                 :             :      convert it to this type.  */
    5225                 :   114022499 :   tree final_type = 0;
    5226                 :             : 
    5227                 :   114022499 :   tree result;
    5228                 :             : 
    5229                 :             :   /* Nonzero if this is an operation like MIN or MAX which can
    5230                 :             :      safely be computed in short if both args are promoted shorts.
    5231                 :             :      Also implies COMMON.
    5232                 :             :      -1 indicates a bitwise operation; this makes a difference
    5233                 :             :      in the exact conditions for when it is safe to do the operation
    5234                 :             :      in a narrower mode.  */
    5235                 :   114022499 :   int shorten = 0;
    5236                 :             : 
    5237                 :             :   /* Nonzero if this is a comparison operation;
    5238                 :             :      if both args are promoted shorts, compare the original shorts.
    5239                 :             :      Also implies COMMON.  */
    5240                 :   114022499 :   int short_compare = 0;
    5241                 :             : 
    5242                 :             :   /* Nonzero if this is a right-shift operation, which can be computed on the
    5243                 :             :      original short and then promoted if the operand is a promoted short.  */
    5244                 :   114022499 :   int short_shift = 0;
    5245                 :             : 
    5246                 :             :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
    5247                 :   114022499 :   int common = 0;
    5248                 :             : 
    5249                 :             :   /* True if both operands have arithmetic type.  */
    5250                 :   114022499 :   bool arithmetic_types_p;
    5251                 :             : 
    5252                 :             :   /* Remember whether we're doing / or %.  */
    5253                 :   114022499 :   bool doing_div_or_mod = false;
    5254                 :             : 
    5255                 :             :   /* Remember whether we're doing << or >>.  */
    5256                 :   114022499 :   bool doing_shift = false;
    5257                 :             : 
    5258                 :             :   /* Tree holding instrumentation expression.  */
    5259                 :   114022499 :   tree instrument_expr = NULL_TREE;
    5260                 :             : 
    5261                 :             :   /* True means this is an arithmetic operation that may need excess
    5262                 :             :      precision.  */
    5263                 :   114022499 :   bool may_need_excess_precision;
    5264                 :             : 
    5265                 :             :   /* Apply default conversions.  */
    5266                 :   114022499 :   op0 = resolve_nondeduced_context (orig_op0, complain);
    5267                 :   114022499 :   op1 = resolve_nondeduced_context (orig_op1, complain);
    5268                 :             : 
    5269                 :   114022499 :   if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
    5270                 :   106950970 :       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
    5271                 :   104518779 :       || code == TRUTH_XOR_EXPR)
    5272                 :             :     {
    5273                 :     9503720 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5274                 :     9503702 :         op0 = decay_conversion (op0, complain);
    5275                 :     9503720 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5276                 :     9503720 :         op1 = decay_conversion (op1, complain);
    5277                 :             :     }
    5278                 :             :   else
    5279                 :             :     {
    5280                 :   104518779 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5281                 :   104518764 :         op0 = cp_default_conversion (op0, complain);
    5282                 :   104518779 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5283                 :   104518776 :         op1 = cp_default_conversion (op1, complain);
    5284                 :             :     }
    5285                 :             : 
    5286                 :             :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    5287                 :   121072087 :   STRIP_TYPE_NOPS (op0);
    5288                 :   139697228 :   STRIP_TYPE_NOPS (op1);
    5289                 :             : 
    5290                 :             :   /* DTRT if one side is an overloaded function, but complain about it.  */
    5291                 :   114022499 :   if (type_unknown_p (op0))
    5292                 :             :     {
    5293                 :           9 :       tree t = instantiate_type (TREE_TYPE (op1), op0, tf_none);
    5294                 :           9 :       if (t != error_mark_node)
    5295                 :             :         {
    5296                 :           0 :           if (complain & tf_error)
    5297                 :           0 :             permerror (location,
    5298                 :             :                        "assuming cast to type %qT from overloaded function",
    5299                 :           0 :                        TREE_TYPE (t));
    5300                 :             :           op0 = t;
    5301                 :             :         }
    5302                 :             :     }
    5303                 :   114022499 :   if (type_unknown_p (op1))
    5304                 :             :     {
    5305                 :           3 :       tree t = instantiate_type (TREE_TYPE (op0), op1, tf_none);
    5306                 :           3 :       if (t != error_mark_node)
    5307                 :             :         {
    5308                 :           3 :           if (complain & tf_error)
    5309                 :           3 :             permerror (location,
    5310                 :             :                        "assuming cast to type %qT from overloaded function",
    5311                 :           3 :                        TREE_TYPE (t));
    5312                 :             :           op1 = t;
    5313                 :             :         }
    5314                 :             :     }
    5315                 :             : 
    5316                 :   114022499 :   orig_type0 = type0 = TREE_TYPE (op0);
    5317                 :   114022499 :   orig_type1 = type1 = TREE_TYPE (op1);
    5318                 :   114022499 :   tree non_ep_op0 = op0;
    5319                 :   114022499 :   tree non_ep_op1 = op1;
    5320                 :             : 
    5321                 :             :   /* The expression codes of the data types of the arguments tell us
    5322                 :             :      whether the arguments are integers, floating, pointers, etc.  */
    5323                 :   114022499 :   code0 = TREE_CODE (type0);
    5324                 :   114022499 :   code1 = TREE_CODE (type1);
    5325                 :             : 
    5326                 :             :   /* If an error was already reported for one of the arguments,
    5327                 :             :      avoid reporting another error.  */
    5328                 :   114022499 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
    5329                 :          93 :     return error_mark_node;
    5330                 :             : 
    5331                 :   228044812 :   if ((invalid_op_diag
    5332                 :   114022406 :        = targetm.invalid_binary_op (code, type0, type1)))
    5333                 :             :     {
    5334                 :           0 :       if (complain & tf_error)
    5335                 :             :         {
    5336                 :           0 :           if (code0 == REAL_TYPE
    5337                 :           0 :               && code1 == REAL_TYPE
    5338                 :           0 :               && (extended_float_type_p (type0)
    5339                 :           0 :                   || extended_float_type_p (type1))
    5340                 :           0 :               && cp_compare_floating_point_conversion_ranks (type0,
    5341                 :             :                                                              type1) == 3)
    5342                 :             :             {
    5343                 :           0 :               rich_location richloc (line_table, location);
    5344                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    5345                 :           0 :             }
    5346                 :             :           else
    5347                 :           0 :             error (invalid_op_diag);
    5348                 :             :         }
    5349                 :           0 :       return error_mark_node;
    5350                 :             :     }
    5351                 :             : 
    5352                 :   114022406 :   switch (code)
    5353                 :             :     {
    5354                 :             :     case PLUS_EXPR:
    5355                 :             :     case MINUS_EXPR:
    5356                 :             :     case MULT_EXPR:
    5357                 :             :     case TRUNC_DIV_EXPR:
    5358                 :             :     case CEIL_DIV_EXPR:
    5359                 :             :     case FLOOR_DIV_EXPR:
    5360                 :             :     case ROUND_DIV_EXPR:
    5361                 :             :     case EXACT_DIV_EXPR:
    5362                 :             :       may_need_excess_precision = true;
    5363                 :             :       break;
    5364                 :    39370117 :     case EQ_EXPR:
    5365                 :    39370117 :     case NE_EXPR:
    5366                 :    39370117 :     case LE_EXPR:
    5367                 :    39370117 :     case GE_EXPR:
    5368                 :    39370117 :     case LT_EXPR:
    5369                 :    39370117 :     case GT_EXPR:
    5370                 :    39370117 :     case SPACESHIP_EXPR:
    5371                 :             :       /* Excess precision for implicit conversions of integers to
    5372                 :             :          floating point.  */
    5373                 :     8283575 :       may_need_excess_precision = (ANY_INTEGRAL_TYPE_P (type0)
    5374                 :    47647722 :                                    || ANY_INTEGRAL_TYPE_P (type1));
    5375                 :             :       break;
    5376                 :             :     default:
    5377                 :   114022406 :       may_need_excess_precision = false;
    5378                 :             :       break;
    5379                 :             :     }
    5380                 :   114022406 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
    5381                 :             :     {
    5382                 :       16948 :       op0 = TREE_OPERAND (op0, 0);
    5383                 :       16948 :       type0 = TREE_TYPE (op0);
    5384                 :             :     }
    5385                 :   114005458 :   else if (may_need_excess_precision
    5386                 :    90055099 :            && (code0 == REAL_TYPE || code0 == COMPLEX_TYPE))
    5387                 :    27441252 :     if (tree eptype = excess_precision_type (type0))
    5388                 :             :       {
    5389                 :       45297 :         type0 = eptype;
    5390                 :       45297 :         op0 = convert (eptype, op0);
    5391                 :             :       }
    5392                 :   114022406 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    5393                 :             :     {
    5394                 :       21320 :       op1 = TREE_OPERAND (op1, 0);
    5395                 :       21320 :       type1 = TREE_TYPE (op1);
    5396                 :             :     }
    5397                 :   114001086 :   else if (may_need_excess_precision
    5398                 :    90053106 :            && (code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
    5399                 :    27379000 :     if (tree eptype = excess_precision_type (type1))
    5400                 :             :       {
    5401                 :       29941 :         type1 = eptype;
    5402                 :       29941 :         op1 = convert (eptype, op1);
    5403                 :             :       }
    5404                 :             : 
    5405                 :             :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    5406                 :   228044727 :   if ((null_node_p (orig_op0) || null_node_p (orig_op1))
    5407                 :             :       /* It's reasonable to use pointer values as operands of &&
    5408                 :             :          and ||, so NULL is no exception.  */
    5409                 :       12201 :       && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR 
    5410                 :       12186 :       && ( /* Both are NULL (or 0) and the operation was not a
    5411                 :             :               comparison or a pointer subtraction.  */
    5412                 :       12259 :           (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1) 
    5413                 :          27 :            && code != EQ_EXPR && code != NE_EXPR && code != MINUS_EXPR) 
    5414                 :             :           /* Or if one of OP0 or OP1 is neither a pointer nor NULL.  */
    5415                 :       12174 :           || (!null_ptr_cst_p (orig_op0)
    5416                 :       12113 :               && !TYPE_PTR_OR_PTRMEM_P (type0))
    5417                 :       12162 :           || (!null_ptr_cst_p (orig_op1) 
    5418                 :          46 :               && !TYPE_PTR_OR_PTRMEM_P (type1)))
    5419                 :   114022445 :       && (complain & tf_warning))
    5420                 :             :     {
    5421                 :          39 :       location_t loc =
    5422                 :          39 :         expansion_point_location_if_in_system_header (input_location);
    5423                 :             : 
    5424                 :          39 :       warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic");
    5425                 :             :     }
    5426                 :             : 
    5427                 :             :   /* In case when one of the operands of the binary operation is
    5428                 :             :      a vector and another is a scalar -- convert scalar to vector.  */
    5429                 :   114078959 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
    5430                 :   114078152 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
    5431                 :             :     {
    5432                 :         891 :       enum stv_conv convert_flag
    5433                 :         891 :         = scalar_to_vector (location, code, non_ep_op0, non_ep_op1,
    5434                 :             :                             complain & tf_error);
    5435                 :             : 
    5436                 :         891 :       switch (convert_flag)
    5437                 :             :         {
    5438                 :          21 :           case stv_error:
    5439                 :          21 :             return error_mark_node;
    5440                 :          54 :           case stv_firstarg:
    5441                 :          54 :             {
    5442                 :          54 :               op0 = convert (TREE_TYPE (type1), op0);
    5443                 :          54 :               op0 = save_expr (op0);
    5444                 :          54 :               op0 = build_vector_from_val (type1, op0);
    5445                 :          54 :               orig_type0 = type0 = TREE_TYPE (op0);
    5446                 :          54 :               code0 = TREE_CODE (type0);
    5447                 :          54 :               converted = 1;
    5448                 :          54 :               break;
    5449                 :             :             }
    5450                 :         711 :           case stv_secondarg:
    5451                 :         711 :             {
    5452                 :         711 :               op1 = convert (TREE_TYPE (type0), op1);
    5453                 :         711 :               op1 = save_expr (op1);
    5454                 :         711 :               op1 = build_vector_from_val (type0, op1);
    5455                 :         711 :               orig_type1 = type1 = TREE_TYPE (op1);
    5456                 :         711 :               code1 = TREE_CODE (type1);
    5457                 :         711 :               converted = 1;
    5458                 :         711 :               break;
    5459                 :             :             }
    5460                 :             :           default:
    5461                 :             :             break;
    5462                 :             :         }
    5463                 :             :     }
    5464                 :             : 
    5465                 :   114022385 :   switch (code)
    5466                 :             :     {
    5467                 :    13673484 :     case MINUS_EXPR:
    5468                 :             :       /* Subtraction of two similar pointers.
    5469                 :             :          We must subtract them as integers, then divide by object size.  */
    5470                 :    13673484 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
    5471                 :    14857223 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    5472                 :     1183739 :                                                         TREE_TYPE (type1)))
    5473                 :             :         {
    5474                 :     1183737 :           result = pointer_diff (location, op0, op1,
    5475                 :             :                                  common_pointer_type (type0, type1), complain,
    5476                 :             :                                  &instrument_expr);
    5477                 :     1183737 :           if (instrument_expr != NULL)
    5478                 :          84 :             result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    5479                 :             :                              instrument_expr, result);
    5480                 :             : 
    5481                 :     1183737 :           return result;
    5482                 :             :         }
    5483                 :             :       /* In all other cases except pointer - int, the usual arithmetic
    5484                 :             :          rules apply.  */
    5485                 :    12489747 :       else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE))
    5486                 :             :         {
    5487                 :             :           common = 1;
    5488                 :             :           break;
    5489                 :             :         }
    5490                 :             :       /* The pointer - int case is just like pointer + int; fall
    5491                 :             :          through.  */
    5492                 :    18139580 :       gcc_fallthrough ();
    5493                 :    18139580 :     case PLUS_EXPR:
    5494                 :    18139580 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    5495                 :     5859571 :           && (code0 == INTEGER_TYPE || code1 == INTEGER_TYPE))
    5496                 :             :         {
    5497                 :     5859562 :           tree ptr_operand;
    5498                 :     5859562 :           tree int_operand;
    5499                 :     5859562 :           ptr_operand = ((code0 == POINTER_TYPE) ? op0 : op1);
    5500                 :       17366 :           int_operand = ((code0 == INTEGER_TYPE) ? op0 : op1);
    5501                 :     5859562 :           if (processing_template_decl)
    5502                 :             :             {
    5503                 :     2007383 :               result_type = TREE_TYPE (ptr_operand);
    5504                 :     2007383 :               break;
    5505                 :             :             }
    5506                 :     3852179 :           return cp_pointer_int_sum (location, code,
    5507                 :             :                                      ptr_operand,
    5508                 :             :                                      int_operand,
    5509                 :     3852179 :                                      complain);
    5510                 :             :         }
    5511                 :             :       common = 1;
    5512                 :             :       break;
    5513                 :             : 
    5514                 :             :     case MULT_EXPR:
    5515                 :    17831985 :       common = 1;
    5516                 :             :       break;
    5517                 :             : 
    5518                 :     9081083 :     case TRUNC_DIV_EXPR:
    5519                 :     9081083 :     case CEIL_DIV_EXPR:
    5520                 :     9081083 :     case FLOOR_DIV_EXPR:
    5521                 :     9081083 :     case ROUND_DIV_EXPR:
    5522                 :     9081083 :     case EXACT_DIV_EXPR:
    5523                 :     9081083 :       if (TREE_CODE (op0) == SIZEOF_EXPR && TREE_CODE (op1) == SIZEOF_EXPR)
    5524                 :             :         {
    5525                 :       95184 :           tree type0 = TREE_OPERAND (op0, 0);
    5526                 :       95184 :           tree type1 = TREE_OPERAND (op1, 0);
    5527                 :       95184 :           tree first_arg = tree_strip_any_location_wrapper (type0);
    5528                 :       95184 :           if (!TYPE_P (type0))
    5529                 :       76810 :             type0 = TREE_TYPE (type0);
    5530                 :       95184 :           if (!TYPE_P (type1))
    5531                 :       42763 :             type1 = TREE_TYPE (type1);
    5532                 :       95184 :           if (type0
    5533                 :       95184 :               && type1
    5534                 :       94541 :               && INDIRECT_TYPE_P (type0)
    5535                 :       95259 :               && same_type_p (TREE_TYPE (type0), type1))
    5536                 :             :             {
    5537                 :          27 :               if (!(TREE_CODE (first_arg) == PARM_DECL
    5538                 :          21 :                     && DECL_ARRAY_PARAMETER_P (first_arg)
    5539                 :           3 :                     && warn_sizeof_array_argument)
    5540                 :          42 :                   && (complain & tf_warning))
    5541                 :             :                 {
    5542                 :          21 :                   auto_diagnostic_group d;
    5543                 :          21 :                   if (warning_at (location, OPT_Wsizeof_pointer_div,
    5544                 :             :                                   "division %<sizeof (%T) / sizeof (%T)%> does "
    5545                 :             :                                   "not compute the number of array elements",
    5546                 :             :                                   type0, type1))
    5547                 :          18 :                     if (DECL_P (first_arg))
    5548                 :          18 :                       inform (DECL_SOURCE_LOCATION (first_arg),
    5549                 :             :                               "first %<sizeof%> operand was declared here");
    5550                 :          21 :                 }
    5551                 :             :             }
    5552                 :       95160 :           else if (!dependent_type_p (type0)
    5553                 :       42210 :                    && !dependent_type_p (type1)
    5554                 :       42122 :                    && TREE_CODE (type0) == ARRAY_TYPE
    5555                 :       40518 :                    && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0)))
    5556                 :             :                    /* Set by finish_parenthesized_expr.  */
    5557                 :       39929 :                    && !warning_suppressed_p (op1, OPT_Wsizeof_array_div)
    5558                 :      135071 :                    && (complain & tf_warning))
    5559                 :       39893 :             maybe_warn_sizeof_array_div (location, first_arg, type0,
    5560                 :             :                                          op1, non_reference (type1));
    5561                 :             :         }
    5562                 :             : 
    5563                 :     9081083 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5564                 :             :            || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
    5565                 :     9081065 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5566                 :             :               || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
    5567                 :             :         {
    5568                 :     9081056 :           enum tree_code tcode0 = code0, tcode1 = code1;
    5569                 :     9081056 :           doing_div_or_mod = true;
    5570                 :     9081056 :           warn_for_div_by_zero (location, fold_for_warn (op1));
    5571                 :             : 
    5572                 :     9081056 :           if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
    5573                 :       58532 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
    5574                 :     9081056 :           if (tcode1 == COMPLEX_TYPE || tcode1 == VECTOR_TYPE)
    5575                 :       29980 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
    5576                 :             : 
    5577                 :     9081056 :           if (!(tcode0 == INTEGER_TYPE && tcode1 == INTEGER_TYPE))
    5578                 :             :             resultcode = RDIV_EXPR;
    5579                 :             :           else
    5580                 :             :             {
    5581                 :             :               /* When dividing two signed integers, we have to promote to int.
    5582                 :             :                  unless we divide by a constant != -1.  Note that default
    5583                 :             :                  conversion will have been performed on the operands at this
    5584                 :             :                  point, so we have to dig out the original type to find out if
    5585                 :             :                  it was unsigned.  */
    5586                 :     3552345 :               tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5587                 :     3552345 :               shorten = may_shorten_divmod (op0, stripped_op1);
    5588                 :             :             }
    5589                 :             : 
    5590                 :             :           common = 1;
    5591                 :             :         }
    5592                 :             :       break;
    5593                 :             : 
    5594                 :     1954438 :     case BIT_AND_EXPR:
    5595                 :     1954438 :     case BIT_IOR_EXPR:
    5596                 :     1954438 :     case BIT_XOR_EXPR:
    5597                 :     1954438 :       if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5598                 :     1954438 :           || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5599                 :       17292 :               && !VECTOR_FLOAT_TYPE_P (type0)
    5600                 :       17274 :               && !VECTOR_FLOAT_TYPE_P (type1)))
    5601                 :             :         shorten = -1;
    5602                 :             :       break;
    5603                 :             : 
    5604                 :     1077024 :     case TRUNC_MOD_EXPR:
    5605                 :     1077024 :     case FLOOR_MOD_EXPR:
    5606                 :     1077024 :       doing_div_or_mod = true;
    5607                 :     1077024 :       warn_for_div_by_zero (location, fold_for_warn (op1));
    5608                 :             : 
    5609                 :     1077024 :       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5610                 :          20 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5611                 :     1077044 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    5612                 :             :         common = 1;
    5613                 :     1077004 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5614                 :             :         {
    5615                 :             :           /* Although it would be tempting to shorten always here, that loses
    5616                 :             :              on some targets, since the modulo instruction is undefined if the
    5617                 :             :              quotient can't be represented in the computation mode.  We shorten
    5618                 :             :              only if unsigned or if dividing by something we know != -1.  */
    5619                 :     1076980 :           tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5620                 :     1076980 :           shorten = may_shorten_divmod (op0, stripped_op1);
    5621                 :     1076980 :           common = 1;
    5622                 :             :         }
    5623                 :             :       break;
    5624                 :             : 
    5625                 :     9503705 :     case TRUTH_ANDIF_EXPR:
    5626                 :     9503705 :     case TRUTH_ORIF_EXPR:
    5627                 :     9503705 :     case TRUTH_AND_EXPR:
    5628                 :     9503705 :     case TRUTH_OR_EXPR:
    5629                 :     9503705 :       if (!VECTOR_TYPE_P (type0) && gnu_vector_type_p (type1))
    5630                 :             :         {
    5631                 :           3 :           if (!COMPARISON_CLASS_P (op1))
    5632                 :           3 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5633                 :             :                                       build_zero_cst (type1), complain);
    5634                 :           3 :           if (code == TRUTH_ANDIF_EXPR)
    5635                 :             :             {
    5636                 :           0 :               tree z = build_zero_cst (TREE_TYPE (op1));
    5637                 :           0 :               return build_conditional_expr (location, op0, op1, z, complain);
    5638                 :             :             }
    5639                 :           3 :           else if (code == TRUTH_ORIF_EXPR)
    5640                 :             :             {
    5641                 :           3 :               tree m1 = build_all_ones_cst (TREE_TYPE (op1));
    5642                 :           3 :               return build_conditional_expr (location, op0, m1, op1, complain);
    5643                 :             :             }
    5644                 :             :           else
    5645                 :           0 :             gcc_unreachable ();
    5646                 :             :         }
    5647                 :     9503702 :       if (gnu_vector_type_p (type0)
    5648                 :     9503702 :           && (!VECTOR_TYPE_P (type1) || gnu_vector_type_p (type1)))
    5649                 :             :         {
    5650                 :          24 :           if (!COMPARISON_CLASS_P (op0))
    5651                 :          24 :             op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0,
    5652                 :             :                                       build_zero_cst (type0), complain);
    5653                 :          24 :           if (!VECTOR_TYPE_P (type1))
    5654                 :             :             {
    5655                 :           9 :               tree m1 = build_all_ones_cst (TREE_TYPE (op0));
    5656                 :           9 :               tree z = build_zero_cst (TREE_TYPE (op0));
    5657                 :           9 :               op1 = build_conditional_expr (location, op1, m1, z, complain);
    5658                 :             :             }
    5659                 :          15 :           else if (!COMPARISON_CLASS_P (op1))
    5660                 :          15 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5661                 :             :                                       build_zero_cst (type1), complain);
    5662                 :             : 
    5663                 :          24 :           if (code == TRUTH_ANDIF_EXPR)
    5664                 :             :             code = BIT_AND_EXPR;
    5665                 :           9 :           else if (code == TRUTH_ORIF_EXPR)
    5666                 :             :             code = BIT_IOR_EXPR;
    5667                 :             :           else
    5668                 :           0 :             gcc_unreachable ();
    5669                 :             : 
    5670                 :          24 :           return cp_build_binary_op (location, code, op0, op1, complain);
    5671                 :             :         }
    5672                 :             : 
    5673                 :     9503678 :       result_type = boolean_type_node;
    5674                 :     9503678 :       break;
    5675                 :             : 
    5676                 :             :       /* Shift operations: result has same type as first operand;
    5677                 :             :          always convert second operand to int.
    5678                 :             :          Also set SHORT_SHIFT if shifting rightward.  */
    5679                 :             : 
    5680                 :      865551 :     case RSHIFT_EXPR:
    5681                 :      865551 :       if (gnu_vector_type_p (type0)
    5682                 :         170 :           && code1 == INTEGER_TYPE
    5683                 :      865598 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    5684                 :             :         {
    5685                 :             :           result_type = type0;
    5686                 :             :           converted = 1;
    5687                 :             :         }
    5688                 :      865504 :       else if (gnu_vector_type_p (type0)
    5689                 :         123 :                && gnu_vector_type_p (type1)
    5690                 :         123 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5691                 :         120 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    5692                 :      865624 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    5693                 :             :                             TYPE_VECTOR_SUBPARTS (type1)))
    5694                 :             :         {
    5695                 :             :           result_type = type0;
    5696                 :             :           converted = 1;
    5697                 :             :         }
    5698                 :      865384 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5699                 :             :         {
    5700                 :      865357 :           tree const_op1 = fold_for_warn (op1);
    5701                 :      865357 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    5702                 :       68158 :             const_op1 = op1;
    5703                 :      865357 :           result_type = type0;
    5704                 :      865357 :           doing_shift = true;
    5705                 :      865357 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    5706                 :             :             {
    5707                 :      797199 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    5708                 :             :                 {
    5709                 :          48 :                   if ((complain & tf_warning)
    5710                 :          48 :                       && c_inhibit_evaluation_warnings == 0)
    5711                 :          36 :                     warning_at (location, OPT_Wshift_count_negative,
    5712                 :             :                                 "right shift count is negative");
    5713                 :             :                 }
    5714                 :             :               else
    5715                 :             :                 {
    5716                 :      797151 :                   if (!integer_zerop (const_op1))
    5717                 :      797065 :                     short_shift = 1;
    5718                 :             : 
    5719                 :      797151 :                   if (compare_tree_int (const_op1, TYPE_PRECISION (type0)) >= 0
    5720                 :          46 :                       && (complain & tf_warning)
    5721                 :      797197 :                       && c_inhibit_evaluation_warnings == 0)
    5722                 :          34 :                     warning_at (location, OPT_Wshift_count_overflow,
    5723                 :             :                                 "right shift count >= width of type");
    5724                 :             :                 }
    5725                 :             :             }
    5726                 :             :           /* Avoid converting op1 to result_type later.  */
    5727                 :             :           converted = 1;
    5728                 :             :         }
    5729                 :             :       break;
    5730                 :             : 
    5731                 :     2668855 :     case LSHIFT_EXPR:
    5732                 :     2668855 :       if (gnu_vector_type_p (type0)
    5733                 :         183 :           && code1 == INTEGER_TYPE
    5734                 :     2668892 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    5735                 :             :         {
    5736                 :             :           result_type = type0;
    5737                 :             :           converted = 1;
    5738                 :             :         }
    5739                 :     2668818 :       else if (gnu_vector_type_p (type0)
    5740                 :         146 :                && gnu_vector_type_p (type1)
    5741                 :         146 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5742                 :         143 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    5743                 :     2668958 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    5744                 :             :                             TYPE_VECTOR_SUBPARTS (type1)))
    5745                 :             :         {
    5746                 :             :           result_type = type0;
    5747                 :             :           converted = 1;
    5748                 :             :         }
    5749                 :     2668678 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5750                 :             :         {
    5751                 :     2668648 :           tree const_op0 = fold_for_warn (op0);
    5752                 :     2668648 :           if (TREE_CODE (const_op0) != INTEGER_CST)
    5753                 :      110285 :             const_op0 = op0;
    5754                 :     2668648 :           tree const_op1 = fold_for_warn (op1);
    5755                 :     2668648 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    5756                 :      166204 :             const_op1 = op1;
    5757                 :     2668648 :           result_type = type0;
    5758                 :     2668648 :           doing_shift = true;
    5759                 :     2668648 :           if (TREE_CODE (const_op0) == INTEGER_CST
    5760                 :     2558363 :               && tree_int_cst_sgn (const_op0) < 0
    5761                 :         280 :               && !TYPE_OVERFLOW_WRAPS (type0)
    5762                 :         196 :               && (complain & tf_warning)
    5763                 :     2668844 :               && c_inhibit_evaluation_warnings == 0)
    5764                 :         196 :             warning_at (location, OPT_Wshift_negative_value,
    5765                 :             :                         "left shift of negative value");
    5766                 :     2668648 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    5767                 :             :             {
    5768                 :     2502444 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    5769                 :             :                 {
    5770                 :          57 :                   if ((complain & tf_warning)
    5771                 :          57 :                       && c_inhibit_evaluation_warnings == 0)
    5772                 :          39 :                     warning_at (location, OPT_Wshift_count_negative,
    5773                 :             :                                 "left shift count is negative");
    5774                 :             :                 }
    5775                 :     2502387 :               else if (compare_tree_int (const_op1,
    5776                 :     2502387 :                                          TYPE_PRECISION (type0)) >= 0)
    5777                 :             :                 {
    5778                 :          83 :                   if ((complain & tf_warning)
    5779                 :          61 :                       && c_inhibit_evaluation_warnings == 0)
    5780                 :          45 :                     warning_at (location, OPT_Wshift_count_overflow,
    5781                 :             :                                 "left shift count >= width of type");
    5782                 :             :                 }
    5783                 :     2502304 :               else if (TREE_CODE (const_op0) == INTEGER_CST
    5784                 :     2412932 :                        && (complain & tf_warning))
    5785                 :     2281293 :                 maybe_warn_shift_overflow (location, const_op0, const_op1);
    5786                 :             :             }
    5787                 :             :           /* Avoid converting op1 to result_type later.  */
    5788                 :             :           converted = 1;
    5789                 :             :         }
    5790                 :             :       break;
    5791                 :             : 
    5792                 :    20242313 :     case EQ_EXPR:
    5793                 :    20242313 :     case NE_EXPR:
    5794                 :    20242313 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    5795                 :        2395 :         goto vector_compare;
    5796                 :    20239918 :       if ((complain & tf_warning)
    5797                 :    19254034 :           && c_inhibit_evaluation_warnings == 0
    5798                 :    38930088 :           && (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)))
    5799                 :      792535 :         warning_at (location, OPT_Wfloat_equal,
    5800                 :             :                     "comparing floating-point with %<==%> "
    5801                 :             :                     "or %<!=%> is unsafe");
    5802                 :    20239918 :       if (complain & tf_warning)
    5803                 :             :         {
    5804                 :    19254034 :           tree stripped_orig_op0 = tree_strip_any_location_wrapper (orig_op0);
    5805                 :    19254034 :           tree stripped_orig_op1 = tree_strip_any_location_wrapper (orig_op1);
    5806                 :    19254034 :           if ((TREE_CODE (stripped_orig_op0) == STRING_CST
    5807                 :          39 :                && !integer_zerop (cp_fully_fold (op1)))
    5808                 :    19254070 :               || (TREE_CODE (stripped_orig_op1) == STRING_CST
    5809                 :          62 :                   && !integer_zerop (cp_fully_fold (op0))))
    5810                 :          41 :             warning_at (location, OPT_Waddress,
    5811                 :             :                         "comparison with string literal results in "
    5812                 :             :                         "unspecified behavior");
    5813                 :    19253993 :           else if (warn_array_compare
    5814                 :      356131 :                    && TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    5815                 :    19254105 :                    && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE)
    5816                 :          12 :             do_warn_array_compare (location, code, stripped_orig_op0,
    5817                 :             :                                    stripped_orig_op1);
    5818                 :             :         }
    5819                 :             : 
    5820                 :    20239918 :       build_type = boolean_type_node;
    5821                 :    20239918 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5822                 :             :            || code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
    5823                 :    17225388 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5824                 :             :               || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
    5825                 :             :         short_compare = 1;
    5826                 :       21919 :       else if (((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0))
    5827                 :     3014113 :                 && null_ptr_cst_p (orig_op1))
    5828                 :             :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    5829                 :     4566645 :                || (code0 == POINTER_TYPE
    5830                 :     1509933 :                    && TYPE_PTR_P (type1) && integer_zerop (op1)))
    5831                 :             :         {
    5832                 :     1522935 :           if (TYPE_PTR_P (type1))
    5833                 :       19122 :             result_type = composite_pointer_type (location,
    5834                 :             :                                                   type0, type1, op0, op1,
    5835                 :             :                                                   CPO_COMPARISON, complain);
    5836                 :             :           else
    5837                 :             :             result_type = type0;
    5838                 :             : 
    5839                 :     1522935 :           if (char_type_p (TREE_TYPE (orig_op1)))
    5840                 :             :             {
    5841                 :          10 :               auto_diagnostic_group d;
    5842                 :          10 :               if (warning_at (location, OPT_Wpointer_compare,
    5843                 :             :                               "comparison between pointer and zero character "
    5844                 :             :                               "constant"))
    5845                 :          10 :                 inform (location,
    5846                 :             :                         "did you mean to dereference the pointer?");
    5847                 :          10 :             }
    5848                 :     1522935 :           warn_for_null_address (location, op0, complain);
    5849                 :             :         }
    5850                 :         849 :       else if (((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1))
    5851                 :     1511836 :                 && null_ptr_cst_p (orig_op0))
    5852                 :             :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    5853                 :     3023695 :                || (code1 == POINTER_TYPE
    5854                 :     1510576 :                    && TYPE_PTR_P (type0) && integer_zerop (op0)))
    5855                 :             :         {
    5856                 :         961 :           if (TYPE_PTR_P (type0))
    5857                 :          68 :             result_type = composite_pointer_type (location,
    5858                 :             :                                                   type0, type1, op0, op1,
    5859                 :             :                                                   CPO_COMPARISON, complain);
    5860                 :             :           else
    5861                 :             :             result_type = type1;
    5862                 :             : 
    5863                 :         961 :           if (char_type_p (TREE_TYPE (orig_op0)))
    5864                 :             :             {
    5865                 :          10 :               auto_diagnostic_group d;
    5866                 :          10 :               if (warning_at (location, OPT_Wpointer_compare,
    5867                 :             :                              "comparison between pointer and zero character "
    5868                 :             :                              "constant"))
    5869                 :          10 :                 inform (location,
    5870                 :             :                         "did you mean to dereference the pointer?");
    5871                 :          10 :             }
    5872                 :         961 :           warn_for_null_address (location, op1, complain);
    5873                 :             :         }
    5874                 :     1511333 :       else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    5875                 :       20648 :                || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1)))
    5876                 :     1491052 :         result_type = composite_pointer_type (location,
    5877                 :             :                                               type0, type1, op0, op1,
    5878                 :             :                                               CPO_COMPARISON, complain);
    5879                 :       20281 :       else if (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1))
    5880                 :             :         /* One of the operands must be of nullptr_t type.  */
    5881                 :          65 :         result_type = TREE_TYPE (nullptr_node);
    5882                 :       20216 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    5883                 :             :         {
    5884                 :          58 :           result_type = type0;
    5885                 :          58 :           if (complain & tf_error)
    5886                 :          56 :             permerror (location, "ISO C++ forbids comparison between "
    5887                 :             :                        "pointer and integer");
    5888                 :             :           else
    5889                 :           2 :             return error_mark_node;
    5890                 :             :         }
    5891                 :       20158 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    5892                 :             :         {
    5893                 :       19823 :           result_type = type1;
    5894                 :       19823 :           if (complain & tf_error)
    5895                 :          69 :             permerror (location, "ISO C++ forbids comparison between "
    5896                 :             :                        "pointer and integer");
    5897                 :             :           else
    5898                 :       19754 :             return error_mark_node;
    5899                 :             :         }
    5900                 :         335 :       else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (orig_op1))
    5901                 :             :         {
    5902                 :         191 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    5903                 :             :               == ptrmemfunc_vbit_in_delta)
    5904                 :             :             {
    5905                 :             :               tree pfn0, delta0, e1, e2;
    5906                 :             : 
    5907                 :             :               if (TREE_SIDE_EFFECTS (op0))
    5908                 :             :                 op0 = cp_save_expr (op0);
    5909                 :             : 
    5910                 :             :               pfn0 = pfn_from_ptrmemfunc (op0);
    5911                 :             :               delta0 = delta_from_ptrmemfunc (op0);
    5912                 :             :               {
    5913                 :             :                 /* If we will warn below about a null-address compare
    5914                 :             :                    involving the orig_op0 ptrmemfunc, we'd likely also
    5915                 :             :                    warn about the pfn0's null-address compare, and
    5916                 :             :                    that would be redundant, so suppress it.  */
    5917                 :             :                 warning_sentinel ws (warn_address);
    5918                 :             :                 e1 = cp_build_binary_op (location,
    5919                 :             :                                          EQ_EXPR,
    5920                 :             :                                          pfn0,
    5921                 :             :                                          build_zero_cst (TREE_TYPE (pfn0)),
    5922                 :             :                                          complain);
    5923                 :             :               }
    5924                 :             :               e2 = cp_build_binary_op (location,
    5925                 :             :                                        BIT_AND_EXPR,
    5926                 :             :                                        delta0,
    5927                 :             :                                        integer_one_node,
    5928                 :             :                                        complain);
    5929                 :             : 
    5930                 :             :               if (complain & tf_warning)
    5931                 :             :                 maybe_warn_zero_as_null_pointer_constant (op1, input_location);
    5932                 :             : 
    5933                 :             :               e2 = cp_build_binary_op (location,
    5934                 :             :                                        EQ_EXPR, e2, integer_zero_node,
    5935                 :             :                                        complain);
    5936                 :             :               op0 = cp_build_binary_op (location,
    5937                 :             :                                         TRUTH_ANDIF_EXPR, e1, e2,
    5938                 :             :                                         complain);
    5939                 :             :               op1 = cp_convert (TREE_TYPE (op0), integer_one_node, complain);
    5940                 :             :             }
    5941                 :             :           else 
    5942                 :             :             {
    5943                 :         191 :               op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
    5944                 :         191 :               op1 = cp_convert (TREE_TYPE (op0), op1, complain);
    5945                 :             :             }
    5946                 :         191 :           result_type = TREE_TYPE (op0);
    5947                 :             : 
    5948                 :         191 :           warn_for_null_address (location, orig_op0, complain);
    5949                 :             :         }
    5950                 :         144 :       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (orig_op0))
    5951                 :          36 :         return cp_build_binary_op (location, code, op1, op0, complain);
    5952                 :         108 :       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
    5953                 :             :         {
    5954                 :          87 :           tree type;
    5955                 :             :           /* E will be the final comparison.  */
    5956                 :          87 :           tree e;
    5957                 :             :           /* E1 and E2 are for scratch.  */
    5958                 :          87 :           tree e1;
    5959                 :          87 :           tree e2;
    5960                 :          87 :           tree pfn0;
    5961                 :          87 :           tree pfn1;
    5962                 :          87 :           tree delta0;
    5963                 :          87 :           tree delta1;
    5964                 :             : 
    5965                 :          87 :           type = composite_pointer_type (location, type0, type1, op0, op1, 
    5966                 :             :                                          CPO_COMPARISON, complain);
    5967                 :             : 
    5968                 :          87 :           if (!same_type_p (TREE_TYPE (op0), type))
    5969                 :           6 :             op0 = cp_convert_and_check (type, op0, complain);
    5970                 :          87 :           if (!same_type_p (TREE_TYPE (op1), type))
    5971                 :           9 :             op1 = cp_convert_and_check (type, op1, complain);
    5972                 :             : 
    5973                 :          87 :           if (op0 == error_mark_node || op1 == error_mark_node)
    5974                 :             :             return error_mark_node;
    5975                 :             : 
    5976                 :          84 :           if (TREE_SIDE_EFFECTS (op0))
    5977                 :          31 :             op0 = save_expr (op0);
    5978                 :          84 :           if (TREE_SIDE_EFFECTS (op1))
    5979                 :           0 :             op1 = save_expr (op1);
    5980                 :             : 
    5981                 :          84 :           pfn0 = pfn_from_ptrmemfunc (op0);
    5982                 :          84 :           pfn0 = cp_fully_fold (pfn0);
    5983                 :             :           /* Avoid -Waddress warnings (c++/64877).  */
    5984                 :          84 :           if (TREE_CODE (pfn0) == ADDR_EXPR)
    5985                 :           9 :             suppress_warning (pfn0, OPT_Waddress);
    5986                 :          84 :           pfn1 = pfn_from_ptrmemfunc (op1);
    5987                 :          84 :           pfn1 = cp_fully_fold (pfn1);
    5988                 :          84 :           delta0 = delta_from_ptrmemfunc (op0);
    5989                 :          84 :           delta1 = delta_from_ptrmemfunc (op1);
    5990                 :          84 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    5991                 :             :               == ptrmemfunc_vbit_in_delta)
    5992                 :             :             {
    5993                 :             :               /* We generate:
    5994                 :             : 
    5995                 :             :                  (op0.pfn == op1.pfn
    5996                 :             :                   && ((op0.delta == op1.delta)
    5997                 :             :                        || (!op0.pfn && op0.delta & 1 == 0 
    5998                 :             :                            && op1.delta & 1 == 0))
    5999                 :             : 
    6000                 :             :                  The reason for the `!op0.pfn' bit is that a NULL
    6001                 :             :                  pointer-to-member is any member with a zero PFN and
    6002                 :             :                  LSB of the DELTA field is 0.  */
    6003                 :             : 
    6004                 :             :               e1 = cp_build_binary_op (location, BIT_AND_EXPR,
    6005                 :             :                                        delta0, 
    6006                 :             :                                        integer_one_node,
    6007                 :             :                                        complain);
    6008                 :             :               e1 = cp_build_binary_op (location,
    6009                 :             :                                        EQ_EXPR, e1, integer_zero_node,
    6010                 :             :                                        complain);
    6011                 :             :               e2 = cp_build_binary_op (location, BIT_AND_EXPR,
    6012                 :             :                                        delta1,
    6013                 :             :                                        integer_one_node,
    6014                 :             :                                        complain);
    6015                 :             :               e2 = cp_build_binary_op (location,
    6016                 :             :                                        EQ_EXPR, e2, integer_zero_node,
    6017                 :             :                                        complain);
    6018                 :             :               e1 = cp_build_binary_op (location,
    6019                 :             :                                        TRUTH_ANDIF_EXPR, e2, e1,
    6020                 :             :                                        complain);
    6021                 :             :               e2 = cp_build_binary_op (location, EQ_EXPR,
    6022                 :             :                                        pfn0,
    6023                 :             :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6024                 :             :                                        complain);
    6025                 :             :               e2 = cp_build_binary_op (location,
    6026                 :             :                                        TRUTH_ANDIF_EXPR, e2, e1, complain);
    6027                 :             :               e1 = cp_build_binary_op (location,
    6028                 :             :                                        EQ_EXPR, delta0, delta1, complain);
    6029                 :             :               e1 = cp_build_binary_op (location,
    6030                 :             :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6031                 :             :             }
    6032                 :             :           else
    6033                 :             :             {
    6034                 :             :               /* We generate:
    6035                 :             : 
    6036                 :             :                  (op0.pfn == op1.pfn
    6037                 :             :                  && (!op0.pfn || op0.delta == op1.delta))
    6038                 :             : 
    6039                 :             :                  The reason for the `!op0.pfn' bit is that a NULL
    6040                 :             :                  pointer-to-member is any member with a zero PFN; the
    6041                 :             :                  DELTA field is unspecified.  */
    6042                 :             :  
    6043                 :          84 :               e1 = cp_build_binary_op (location,
    6044                 :             :                                        EQ_EXPR, delta0, delta1, complain);
    6045                 :          84 :               e2 = cp_build_binary_op (location,
    6046                 :             :                                        EQ_EXPR,
    6047                 :             :                                        pfn0,
    6048                 :          84 :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6049                 :             :                                        complain);
    6050                 :          84 :               e1 = cp_build_binary_op (location,
    6051                 :             :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6052                 :             :             }
    6053                 :          84 :           e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
    6054                 :          84 :           e = cp_build_binary_op (location,
    6055                 :             :                                   TRUTH_ANDIF_EXPR, e2, e1, complain);
    6056                 :          84 :           if (code == EQ_EXPR)
    6057                 :             :             return e;
    6058                 :          24 :           return cp_build_binary_op (location,
    6059                 :          24 :                                      EQ_EXPR, e, integer_zero_node, complain);
    6060                 :             :         }
    6061                 :             :       else
    6062                 :             :         {
    6063                 :          21 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type0)
    6064                 :             :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0),
    6065                 :             :                                        type1));
    6066                 :          21 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type1)
    6067                 :             :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1),
    6068                 :             :                                        type0));
    6069                 :             :         }
    6070                 :             : 
    6071                 :             :       break;
    6072                 :             : 
    6073                 :         241 :     case MAX_EXPR:
    6074                 :         241 :     case MIN_EXPR:
    6075                 :         241 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
    6076                 :         241 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
    6077                 :             :         shorten = 1;
    6078                 :           0 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6079                 :           0 :         result_type = composite_pointer_type (location,
    6080                 :             :                                               type0, type1, op0, op1,
    6081                 :             :                                               CPO_COMPARISON, complain);
    6082                 :             :       break;
    6083                 :             : 
    6084                 :    19127804 :     case LE_EXPR:
    6085                 :    19127804 :     case GE_EXPR:
    6086                 :    19127804 :     case LT_EXPR:
    6087                 :    19127804 :     case GT_EXPR:
    6088                 :    19127804 :     case SPACESHIP_EXPR:
    6089                 :    19127804 :       if (TREE_CODE (orig_op0) == STRING_CST
    6090                 :    19127804 :           || TREE_CODE (orig_op1) == STRING_CST)
    6091                 :             :         {
    6092                 :           0 :           if (complain & tf_warning)
    6093                 :           0 :             warning_at (location, OPT_Waddress,
    6094                 :             :                         "comparison with string literal results "
    6095                 :             :                         "in unspecified behavior");
    6096                 :             :         }
    6097                 :    19127804 :       else if (warn_array_compare
    6098                 :      223389 :                && TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6099                 :          13 :                && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE
    6100                 :          13 :                && code != SPACESHIP_EXPR
    6101                 :    19127816 :                && (complain & tf_warning))
    6102                 :          12 :         do_warn_array_compare (location, code,
    6103                 :             :                                tree_strip_any_location_wrapper (orig_op0),
    6104                 :             :                                tree_strip_any_location_wrapper (orig_op1));
    6105                 :             : 
    6106                 :    19127804 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6107                 :             :         {
    6108                 :        6537 :         vector_compare:
    6109                 :        6537 :           tree intt;
    6110                 :        6537 :           if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    6111                 :        6537 :                                                           TREE_TYPE (type1))
    6112                 :        6537 :               && !vector_types_compatible_elements_p (type0, type1))
    6113                 :             :             {
    6114                 :           3 :               if (complain & tf_error)
    6115                 :             :                 {
    6116                 :           3 :                   auto_diagnostic_group d;
    6117                 :           3 :                   error_at (location, "comparing vectors with different "
    6118                 :             :                                       "element types");
    6119                 :           3 :                   inform (location, "operand types are %qT and %qT",
    6120                 :             :                           type0, type1);
    6121                 :           3 :                 }
    6122                 :           3 :               return error_mark_node;
    6123                 :             :             }
    6124                 :             : 
    6125                 :        6534 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
    6126                 :       13068 :                         TYPE_VECTOR_SUBPARTS (type1)))
    6127                 :             :             {
    6128                 :           3 :               if (complain & tf_error)
    6129                 :             :                 {
    6130                 :           3 :                   auto_diagnostic_group d;
    6131                 :           3 :                   error_at (location, "comparing vectors with different "
    6132                 :             :                                       "number of elements");
    6133                 :           3 :                   inform (location, "operand types are %qT and %qT",
    6134                 :             :                           type0, type1);
    6135                 :           3 :                 }
    6136                 :           3 :               return error_mark_node;
    6137                 :             :             }
    6138                 :             : 
    6139                 :             :           /* It's not precisely specified how the usual arithmetic
    6140                 :             :              conversions apply to the vector types.  Here, we use
    6141                 :             :              the unsigned type if one of the operands is signed and
    6142                 :             :              the other one is unsigned.  */
    6143                 :        6531 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
    6144                 :             :             {
    6145                 :          36 :               if (!TYPE_UNSIGNED (type0))
    6146                 :          36 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
    6147                 :             :               else
    6148                 :           0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
    6149                 :          36 :               warning_at (location, OPT_Wsign_compare, "comparison between "
    6150                 :             :                           "types %qT and %qT", type0, type1);
    6151                 :             :             }
    6152                 :             : 
    6153                 :        6531 :           if (resultcode == SPACESHIP_EXPR)
    6154                 :             :             {
    6155                 :           3 :               if (complain & tf_error)
    6156                 :           3 :                 sorry_at (location, "three-way comparison of vectors");
    6157                 :           3 :               return error_mark_node;
    6158                 :             :             }
    6159                 :             : 
    6160                 :             :           /* Always construct signed integer vector type.  */
    6161                 :        6528 :           intt = c_common_type_for_size
    6162                 :       13056 :             (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (type0))), 0);
    6163                 :        6528 :           if (!intt)
    6164                 :             :             {
    6165                 :           0 :               if (complain & tf_error)
    6166                 :           0 :                 error_at (location, "could not find an integer type "
    6167                 :           0 :                           "of the same size as %qT", TREE_TYPE (type0));
    6168                 :           0 :               return error_mark_node;
    6169                 :             :             }
    6170                 :        6528 :           result_type = build_opaque_vector_type (intt,
    6171                 :        6528 :                                                   TYPE_VECTOR_SUBPARTS (type0));
    6172                 :        6528 :           return build_vec_cmp (resultcode, result_type, op0, op1);
    6173                 :             :         }
    6174                 :    19123662 :       build_type = boolean_type_node;
    6175                 :    19123662 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6176                 :             :            || code0 == ENUMERAL_TYPE)
    6177                 :    18263032 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6178                 :             :                || code1 == ENUMERAL_TYPE))
    6179                 :             :         short_compare = 1;
    6180                 :      860717 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6181                 :      860485 :         result_type = composite_pointer_type (location,
    6182                 :             :                                               type0, type1, op0, op1,
    6183                 :             :                                               CPO_COMPARISON, complain);
    6184                 :          74 :       else if ((code0 == POINTER_TYPE && null_ptr_cst_p (orig_op1))
    6185                 :         160 :                || (code1 == POINTER_TYPE && null_ptr_cst_p (orig_op0))
    6186                 :         338 :                || (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)))
    6187                 :             :         {
    6188                 :             :           /* Core Issue 1512 made this ill-formed.  */
    6189                 :         191 :           if (complain & tf_error)
    6190                 :         188 :             error_at (location, "ordered comparison of pointer with "
    6191                 :             :                       "integer zero (%qT and %qT)", type0, type1);
    6192                 :         191 :           return error_mark_node;
    6193                 :             :         }
    6194                 :          41 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6195                 :             :         {
    6196                 :           0 :           result_type = type0;
    6197                 :           0 :           if (complain & tf_error)
    6198                 :           0 :             permerror (location, "ISO C++ forbids comparison between "
    6199                 :             :                        "pointer and integer");
    6200                 :             :           else
    6201                 :           0 :             return error_mark_node;
    6202                 :             :         }
    6203                 :          41 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6204                 :             :         {
    6205                 :          24 :           result_type = type1;
    6206                 :          24 :           if (complain & tf_error)
    6207                 :          24 :             permerror (location, "ISO C++ forbids comparison between "
    6208                 :             :                        "pointer and integer");
    6209                 :             :           else
    6210                 :           0 :             return error_mark_node;
    6211                 :             :         }
    6212                 :             : 
    6213                 :    19123471 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    6214                 :      860511 :           && !processing_template_decl
    6215                 :    19775299 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
    6216                 :             :         {
    6217                 :          49 :           op0 = save_expr (op0);
    6218                 :          49 :           op1 = save_expr (op1);
    6219                 :             : 
    6220                 :          49 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
    6221                 :          49 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
    6222                 :             :         }
    6223                 :             : 
    6224                 :             :       break;
    6225                 :             : 
    6226                 :           0 :     case UNORDERED_EXPR:
    6227                 :           0 :     case ORDERED_EXPR:
    6228                 :           0 :     case UNLT_EXPR:
    6229                 :           0 :     case UNLE_EXPR:
    6230                 :           0 :     case UNGT_EXPR:
    6231                 :           0 :     case UNGE_EXPR:
    6232                 :           0 :     case UNEQ_EXPR:
    6233                 :           0 :       build_type = integer_type_node;
    6234                 :           0 :       if (code0 != REAL_TYPE || code1 != REAL_TYPE)
    6235                 :             :         {
    6236                 :           0 :           if (complain & tf_error)
    6237                 :           0 :             error ("unordered comparison on non-floating-point argument");
    6238                 :           0 :           return error_mark_node;
    6239                 :             :         }
    6240                 :             :       common = 1;
    6241                 :             :       break;
    6242                 :             : 
    6243                 :             :     default:
    6244                 :             :       break;
    6245                 :             :     }
    6246                 :             : 
    6247                 :   108959835 :   if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
    6248                 :             :         || code0 == ENUMERAL_TYPE)
    6249                 :    93899143 :        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6250                 :             :            || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
    6251                 :             :     arithmetic_types_p = 1;
    6252                 :             :   else
    6253                 :             :     {
    6254                 :    15259829 :       arithmetic_types_p = 0;
    6255                 :             :       /* Vector arithmetic is only allowed when both sides are vectors.  */
    6256                 :    15259829 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6257                 :             :         {
    6258                 :       49959 :           if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
    6259                 :       49959 :               || !vector_types_compatible_elements_p (type0, type1))
    6260                 :             :             {
    6261                 :          18 :               if (complain & tf_error)
    6262                 :             :                 {
    6263                 :             :                   /* "location" already embeds the locations of the
    6264                 :             :                      operands, so we don't need to add them separately
    6265                 :             :                      to richloc.  */
    6266                 :          18 :                   rich_location richloc (line_table, location);
    6267                 :          18 :                   binary_op_error (&richloc, code, type0, type1);
    6268                 :          18 :                 }
    6269                 :          18 :               return error_mark_node;
    6270                 :             :             }
    6271                 :             :           arithmetic_types_p = 1;
    6272                 :             :         }
    6273                 :             :     }
    6274                 :             :   /* Determine the RESULT_TYPE, if it is not already known.  */
    6275                 :   108959817 :   if (!result_type
    6276                 :   108959817 :       && arithmetic_types_p
    6277                 :    90038233 :       && (shorten || common || short_compare))
    6278                 :             :     {
    6279                 :    90038158 :       result_type = cp_common_type (type0, type1);
    6280                 :    90038158 :       if (result_type == error_mark_node)
    6281                 :             :         {
    6282                 :           0 :           tree t1 = type0;
    6283                 :           0 :           tree t2 = type1;
    6284                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6285                 :           0 :             t1 = TREE_TYPE (t1);
    6286                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6287                 :           0 :             t2 = TREE_TYPE (t2);
    6288                 :           0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6289                 :             :                                && TREE_CODE (t2) == REAL_TYPE
    6290                 :             :                                && (extended_float_type_p (t1)
    6291                 :             :                                    || extended_float_type_p (t2))
    6292                 :             :                                && cp_compare_floating_point_conversion_ranks
    6293                 :             :                                     (t1, t2) == 3);
    6294                 :           0 :           if (complain & tf_error)
    6295                 :             :             {
    6296                 :           0 :               rich_location richloc (line_table, location);
    6297                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    6298                 :           0 :             }
    6299                 :           0 :           return error_mark_node;
    6300                 :             :         }
    6301                 :    90038158 :       if (complain & tf_warning)
    6302                 :    85840388 :         do_warn_double_promotion (result_type, type0, type1,
    6303                 :             :                                   "implicit conversion from %qH to %qI "
    6304                 :             :                                   "to match other operand of binary "
    6305                 :             :                                   "expression", location);
    6306                 :    90038158 :       if (do_warn_enum_conversions (location, code, TREE_TYPE (orig_op0),
    6307                 :    90038158 :                                     TREE_TYPE (orig_op1), complain))
    6308                 :           6 :         return error_mark_node;
    6309                 :             :     }
    6310                 :   108959811 :   if (may_need_excess_precision
    6311                 :    85010019 :       && (orig_type0 != type0 || orig_type1 != type1)
    6312                 :       64499 :       && build_type == NULL_TREE
    6313                 :       64499 :       && result_type)
    6314                 :             :     {
    6315                 :       48808 :       gcc_assert (common);
    6316                 :       48808 :       semantic_result_type = cp_common_type (orig_type0, orig_type1);
    6317                 :       48808 :       if (semantic_result_type == error_mark_node)
    6318                 :             :         {
    6319                 :           0 :           tree t1 = orig_type0;
    6320                 :           0 :           tree t2 = orig_type1;
    6321                 :           0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6322                 :           0 :             t1 = TREE_TYPE (t1);
    6323                 :           0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6324                 :           0 :             t2 = TREE_TYPE (t2);
    6325                 :           0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6326                 :             :                                && TREE_CODE (t2) == REAL_TYPE
    6327                 :             :                                && (extended_float_type_p (t1)
    6328                 :             :                                    || extended_float_type_p (t2))
    6329                 :             :                                && cp_compare_floating_point_conversion_ranks
    6330                 :             :                                     (t1, t2) == 3);
    6331                 :           0 :           if (complain & tf_error)
    6332                 :             :             {
    6333                 :           0 :               rich_location richloc (line_table, location);
    6334                 :           0 :               binary_op_error (&richloc, code, type0, type1);
    6335                 :           0 :             }
    6336                 :           0 :           return error_mark_node;
    6337                 :             :         }
    6338                 :             :     }
    6339                 :             : 
    6340                 :   108959811 :   if (code == SPACESHIP_EXPR)
    6341                 :             :     {
    6342                 :      132051 :       iloc_sentinel s (location);
    6343                 :             : 
    6344                 :      132051 :       tree orig_type0 = TREE_TYPE (orig_op0);
    6345                 :      132051 :       tree_code orig_code0 = TREE_CODE (orig_type0);
    6346                 :      132051 :       tree orig_type1 = TREE_TYPE (orig_op1);
    6347                 :      132051 :       tree_code orig_code1 = TREE_CODE (orig_type1);
    6348                 :      132051 :       if (!result_type || result_type == error_mark_node)
    6349                 :             :         /* Nope.  */
    6350                 :             :         result_type = NULL_TREE;
    6351                 :      132030 :       else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE))
    6352                 :             :         /* "If one of the operands is of type bool and the other is not, the
    6353                 :             :            program is ill-formed."  */
    6354                 :             :         result_type = NULL_TREE;
    6355                 :      132027 :       else if (code0 == POINTER_TYPE && orig_code0 != POINTER_TYPE
    6356                 :          17 :                && code1 == POINTER_TYPE && orig_code1 != POINTER_TYPE)
    6357                 :             :         /* We only do array/function-to-pointer conversion if "at least one of
    6358                 :             :            the operands is of pointer type".  */
    6359                 :             :         result_type = NULL_TREE;
    6360                 :      132010 :       else if (TYPE_PTRFN_P (result_type) || NULLPTR_TYPE_P (result_type))
    6361                 :             :         /* <=> no longer supports equality relations.  */
    6362                 :             :         result_type = NULL_TREE;
    6363                 :      132007 :       else if (orig_code0 == ENUMERAL_TYPE && orig_code1 == ENUMERAL_TYPE
    6364                 :      132043 :                && !(same_type_ignoring_top_level_qualifiers_p
    6365                 :          36 :                     (orig_type0, orig_type1)))
    6366                 :             :         /* "If both operands have arithmetic types, or one operand has integral
    6367                 :             :            type and the other operand has unscoped enumeration type, the usual
    6368                 :             :            arithmetic conversions are applied to the operands."  So we don't do
    6369                 :             :            arithmetic conversions if the operands both have enumeral type.  */
    6370                 :             :         result_type = NULL_TREE;
    6371                 :      131992 :       else if ((orig_code0 == ENUMERAL_TYPE && orig_code1 == REAL_TYPE)
    6372                 :      131986 :                || (orig_code0 == REAL_TYPE && orig_code1 == ENUMERAL_TYPE))
    6373                 :             :         /* [depr.arith.conv.enum]: Three-way comparisons between such operands
    6374                 :             :            [where one is of enumeration type and the other is of a different
    6375                 :             :            enumeration type or a floating-point type] are ill-formed.  */
    6376                 :             :         result_type = NULL_TREE;
    6377                 :             : 
    6378                 :      131980 :       if (result_type)
    6379                 :             :         {
    6380                 :      131980 :           build_type = spaceship_type (result_type, complain);
    6381                 :      131980 :           if (build_type == error_mark_node)
    6382                 :             :             return error_mark_node;
    6383                 :             :         }
    6384                 :             : 
    6385                 :      132036 :       if (result_type && arithmetic_types_p)
    6386                 :             :         {
    6387                 :             :           /* If a narrowing conversion is required, other than from an integral
    6388                 :             :              type to a floating point type, the program is ill-formed.  */
    6389                 :       65827 :           bool ok = true;
    6390                 :       65827 :           if (TREE_CODE (result_type) == REAL_TYPE
    6391                 :         496 :               && CP_INTEGRAL_TYPE_P (orig_type0))
    6392                 :             :             /* OK */;
    6393                 :       65816 :           else if (!check_narrowing (result_type, orig_op0, complain))
    6394                 :       65827 :             ok = false;
    6395                 :       65827 :           if (TREE_CODE (result_type) == REAL_TYPE
    6396                 :         496 :               && CP_INTEGRAL_TYPE_P (orig_type1))
    6397                 :             :             /* OK */;
    6398                 :       65816 :           else if (!check_narrowing (result_type, orig_op1, complain))
    6399                 :             :             ok = false;
    6400                 :       65827 :           if (!ok && !(complain & tf_error))
    6401                 :           4 :             return error_mark_node;
    6402                 :             :         }
    6403                 :      132051 :     }
    6404                 :             : 
    6405                 :   108959792 :   if (!result_type)
    6406                 :             :     {
    6407                 :         476 :       if (complain & tf_error)
    6408                 :             :         {
    6409                 :         199 :           binary_op_rich_location richloc (location,
    6410                 :         199 :                                            orig_op0, orig_op1, true);
    6411                 :         199 :           error_at (&richloc,
    6412                 :             :                     "invalid operands of types %qT and %qT to binary %qO",
    6413                 :         199 :                     TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code);
    6414                 :         199 :         }
    6415                 :         476 :       return error_mark_node;
    6416                 :             :     }
    6417                 :             : 
    6418                 :             :   /* If we're in a template, the only thing we need to know is the
    6419                 :             :      RESULT_TYPE.  */
    6420                 :   108959316 :   if (processing_template_decl)
    6421                 :             :     {
    6422                 :             :       /* Since the middle-end checks the type when doing a build2, we
    6423                 :             :          need to build the tree in pieces.  This built tree will never
    6424                 :             :          get out of the front-end as we replace it when instantiating
    6425                 :             :          the template.  */
    6426                 :    44268376 :       tree tmp = build2 (resultcode,
    6427                 :             :                          build_type ? build_type : result_type,
    6428                 :             :                          NULL_TREE, op1);
    6429                 :    28370523 :       TREE_OPERAND (tmp, 0) = op0;
    6430                 :    28370523 :       if (semantic_result_type)
    6431                 :           0 :         tmp = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, tmp);
    6432                 :    28370523 :       return tmp;
    6433                 :             :     }
    6434                 :             : 
    6435                 :             :   /* Remember the original type; RESULT_TYPE might be changed later on
    6436                 :             :      by shorten_binary_op.  */
    6437                 :    80588793 :   tree orig_type = result_type;
    6438                 :             : 
    6439                 :    80588793 :   if (arithmetic_types_p)
    6440                 :             :     {
    6441                 :    71480169 :       bool first_complex = (code0 == COMPLEX_TYPE);
    6442                 :    71480169 :       bool second_complex = (code1 == COMPLEX_TYPE);
    6443                 :    71480169 :       int none_complex = (!first_complex && !second_complex);
    6444                 :             : 
    6445                 :             :       /* Adapted from patch for c/24581.  */
    6446                 :    71480169 :       if (first_complex != second_complex
    6447                 :      160922 :           && (code == PLUS_EXPR
    6448                 :             :               || code == MINUS_EXPR
    6449                 :      160922 :               || code == MULT_EXPR
    6450                 :       42065 :               || (code == TRUNC_DIV_EXPR && first_complex))
    6451                 :      147415 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
    6452                 :    71627423 :           && flag_signed_zeros)
    6453                 :             :         {
    6454                 :             :           /* An operation on mixed real/complex operands must be
    6455                 :             :              handled specially, but the language-independent code can
    6456                 :             :              more easily optimize the plain complex arithmetic if
    6457                 :             :              -fno-signed-zeros.  */
    6458                 :      147254 :           tree real_type = TREE_TYPE (result_type);
    6459                 :      147254 :           tree real, imag;
    6460                 :      147254 :           if (first_complex)
    6461                 :             :             {
    6462                 :      114253 :               if (TREE_TYPE (op0) != result_type)
    6463                 :           6 :                 op0 = cp_convert_and_check (result_type, op0, complain);
    6464                 :      114253 :               if (TREE_TYPE (op1) != real_type)
    6465                 :          26 :                 op1 = cp_convert_and_check (real_type, op1, complain);
    6466                 :             :             }
    6467                 :             :           else
    6468                 :             :             {
    6469                 :       33001 :               if (TREE_TYPE (op0) != real_type)
    6470                 :          31 :                 op0 = cp_convert_and_check (real_type, op0, complain);
    6471                 :       33001 :               if (TREE_TYPE (op1) != result_type)
    6472                 :          32 :                 op1 = cp_convert_and_check (result_type, op1, complain);
    6473                 :             :             }
    6474                 :      147254 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
    6475                 :           0 :             return error_mark_node;
    6476                 :      147254 :           if (first_complex)
    6477                 :             :             {
    6478                 :      114253 :               op0 = save_expr (op0);
    6479                 :      114253 :               real = cp_build_unary_op (REALPART_EXPR, op0, true, complain);
    6480                 :      114253 :               imag = cp_build_unary_op (IMAGPART_EXPR, op0, true, complain);
    6481                 :      114253 :               switch (code)
    6482                 :             :                 {
    6483                 :       57109 :                 case MULT_EXPR:
    6484                 :       57109 :                 case TRUNC_DIV_EXPR:
    6485                 :       57109 :                   op1 = save_expr (op1);
    6486                 :       57109 :                   imag = build2 (resultcode, real_type, imag, op1);
    6487                 :             :                   /* Fall through.  */
    6488                 :      114253 :                 case PLUS_EXPR:
    6489                 :      114253 :                 case MINUS_EXPR:
    6490                 :      114253 :                   real = build2 (resultcode, real_type, real, op1);
    6491                 :      114253 :                   break;
    6492                 :           0 :                 default:
    6493                 :           0 :                   gcc_unreachable();
    6494                 :             :                 }
    6495                 :             :             }
    6496                 :             :           else
    6497                 :             :             {
    6498                 :       33001 :               op1 = save_expr (op1);
    6499                 :       33001 :               real = cp_build_unary_op (REALPART_EXPR, op1, true, complain);
    6500                 :       33001 :               imag = cp_build_unary_op (IMAGPART_EXPR, op1, true, complain);
    6501                 :       33001 :               switch (code)
    6502                 :             :                 {
    6503                 :         632 :                 case MULT_EXPR:
    6504                 :         632 :                   op0 = save_expr (op0);
    6505                 :         632 :                   imag = build2 (resultcode, real_type, op0, imag);
    6506                 :             :                   /* Fall through.  */
    6507                 :       17254 :                 case PLUS_EXPR:
    6508                 :       17254 :                   real = build2 (resultcode, real_type, op0, real);
    6509                 :       17254 :                   break;
    6510                 :       15747 :                 case MINUS_EXPR:
    6511                 :       15747 :                   real = build2 (resultcode, real_type, op0, real);
    6512                 :       15747 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
    6513                 :       15747 :                   break;
    6514                 :           0 :                 default:
    6515                 :           0 :                   gcc_unreachable();
    6516                 :             :                 }
    6517                 :             :             }
    6518                 :      147254 :           result = build2 (COMPLEX_EXPR, result_type, real, imag);
    6519                 :      147254 :           if (semantic_result_type)
    6520                 :          24 :             result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6521                 :             :                              result);
    6522                 :      147254 :           return result;
    6523                 :             :         }
    6524                 :             : 
    6525                 :             :       /* For certain operations (which identify themselves by shorten != 0)
    6526                 :             :          if both args were extended from the same smaller type,
    6527                 :             :          do the arithmetic in that type and then extend.
    6528                 :             : 
    6529                 :             :          shorten !=0 and !=1 indicates a bitwise operation.
    6530                 :             :          For them, this optimization is safe only if
    6531                 :             :          both args are zero-extended or both are sign-extended.
    6532                 :             :          Otherwise, we might change the result.
    6533                 :             :          E.g., (short)-1 | (unsigned short)-1 is (int)-1
    6534                 :             :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
    6535                 :             : 
    6536                 :    71332915 :       if (shorten && none_complex)
    6537                 :             :         {
    6538                 :     3707513 :           final_type = result_type;
    6539                 :     3707513 :           result_type = shorten_binary_op (result_type, op0, op1,
    6540                 :             :                                            shorten == -1);
    6541                 :             :         }
    6542                 :             : 
    6543                 :             :       /* Shifts can be shortened if shifting right.  */
    6544                 :             : 
    6545                 :    71332915 :       if (short_shift)
    6546                 :             :         {
    6547                 :      704244 :           int unsigned_arg;
    6548                 :      704244 :           tree arg0 = get_narrower (op0, &unsigned_arg);
    6549                 :             :           /* We're not really warning here but when we set short_shift we
    6550                 :             :              used fold_for_warn to fold the operand.  */
    6551                 :      704244 :           tree const_op1 = fold_for_warn (op1);
    6552                 :             : 
    6553                 :      704244 :           final_type = result_type;
    6554                 :             : 
    6555                 :      704244 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
    6556                 :      647648 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
    6557                 :             : 
    6558                 :      704244 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
    6559                 :        1284 :               && tree_int_cst_sgn (const_op1) > 0
    6560                 :             :               /* We can shorten only if the shift count is less than the
    6561                 :             :                  number of bits in the smaller type size.  */
    6562                 :        1284 :               && compare_tree_int (const_op1,
    6563                 :        1284 :                                    TYPE_PRECISION (TREE_TYPE (arg0))) < 0
    6564                 :             :               /* We cannot drop an unsigned shift after sign-extension.  */
    6565                 :      705518 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
    6566                 :             :             {
    6567                 :             :               /* Do an unsigned shift if the operand was zero-extended.  */
    6568                 :        1267 :               result_type
    6569                 :        1267 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
    6570                 :        1267 :                                                     TREE_TYPE (arg0));
    6571                 :             :               /* Convert value-to-be-shifted to that type.  */
    6572                 :        1267 :               if (TREE_TYPE (op0) != result_type)
    6573                 :        1267 :                 op0 = convert (result_type, op0);
    6574                 :             :               converted = 1;
    6575                 :             :             }
    6576                 :             :         }
    6577                 :             : 
    6578                 :             :       /* Comparison operations are shortened too but differently.
    6579                 :             :          They identify themselves by setting short_compare = 1.  */
    6580                 :             : 
    6581                 :    71332915 :       if (short_compare)
    6582                 :             :         {
    6583                 :             :           /* We call shorten_compare only for diagnostics.  */
    6584                 :    23562754 :           tree xop0 = fold_simple (op0);
    6585                 :    23562754 :           tree xop1 = fold_simple (op1);
    6586                 :    23562754 :           tree xresult_type = result_type;
    6587                 :    23562754 :           enum tree_code xresultcode = resultcode;
    6588                 :    23562754 :           shorten_compare (location, &xop0, &xop1, &xresult_type,
    6589                 :             :                            &xresultcode);
    6590                 :             :         }
    6591                 :             : 
    6592                 :    47770074 :       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
    6593                 :    23562943 :           && warn_sign_compare
    6594                 :             :           /* Do not warn until the template is instantiated; we cannot
    6595                 :             :              bound the ranges of the arguments until that point.  */
    6596                 :      323536 :           && !processing_template_decl
    6597                 :      323536 :           && (complain & tf_warning)
    6598                 :      318196 :           && c_inhibit_evaluation_warnings == 0
    6599                 :             :           /* Even unsigned enum types promote to signed int.  We don't
    6600                 :             :              want to issue -Wsign-compare warnings for this case.  */
    6601                 :      303467 :           && !enum_cast_to_int (orig_op0)
    6602                 :    71636382 :           && !enum_cast_to_int (orig_op1))
    6603                 :             :         {
    6604                 :      303437 :           warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
    6605                 :             :                                  result_type, resultcode);
    6606                 :             :         }
    6607                 :             :     }
    6608                 :             : 
    6609                 :             :   /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
    6610                 :             :      Then the expression will be built.
    6611                 :             :      It will be given type FINAL_TYPE if that is nonzero;
    6612                 :             :      otherwise, it will be given type RESULT_TYPE.  */
    6613                 :    80441539 :   if (! converted)
    6614                 :             :     {
    6615                 :    77223854 :       warning_sentinel w (warn_sign_conversion, short_compare);
    6616                 :    77223854 :       if (!same_type_p (TREE_TYPE (op0), result_type))
    6617                 :     3195014 :         op0 = cp_convert_and_check (result_type, op0, complain);
    6618                 :    77223854 :       if (!same_type_p (TREE_TYPE (op1), result_type))
    6619                 :    15213261 :         op1 = cp_convert_and_check (result_type, op1, complain);
    6620                 :             : 
    6621                 :    77223854 :       if (op0 == error_mark_node || op1 == error_mark_node)
    6622                 :          67 :         return error_mark_node;
    6623                 :    77223854 :     }
    6624                 :             : 
    6625                 :    80441472 :   if (build_type == NULL_TREE)
    6626                 :    53570799 :     build_type = result_type;
    6627                 :             : 
    6628                 :    80441472 :   if (doing_shift
    6629                 :     3217122 :       && flag_strong_eval_order == 2
    6630                 :     3086776 :       && TREE_SIDE_EFFECTS (op1)
    6631                 :    80460692 :       && !processing_template_decl)
    6632                 :             :     {
    6633                 :             :       /* In C++17, in both op0 << op1 and op0 >> op1 op0 is sequenced before
    6634                 :             :          op1, so if op1 has side-effects, use SAVE_EXPR around op0.  */
    6635                 :       19220 :       op0 = cp_save_expr (op0);
    6636                 :       19220 :       instrument_expr = op0;
    6637                 :             :     }
    6638                 :             : 
    6639                 :    80441472 :   if (sanitize_flags_p ((SANITIZE_SHIFT
    6640                 :             :                          | SANITIZE_DIVIDE
    6641                 :             :                          | SANITIZE_FLOAT_DIVIDE
    6642                 :             :                          | SANITIZE_SI_OVERFLOW))
    6643                 :       11976 :       && current_function_decl != NULL_TREE
    6644                 :        9886 :       && !processing_template_decl
    6645                 :    80451358 :       && (doing_div_or_mod || doing_shift))
    6646                 :             :     {
    6647                 :             :       /* OP0 and/or OP1 might have side-effects.  */
    6648                 :         869 :       op0 = cp_save_expr (op0);
    6649                 :         869 :       op1 = cp_save_expr (op1);
    6650                 :         869 :       op0 = fold_non_dependent_expr (op0, complain);
    6651                 :         869 :       op1 = fold_non_dependent_expr (op1, complain);
    6652                 :         869 :       tree instrument_expr1 = NULL_TREE;
    6653                 :         869 :       if (doing_div_or_mod
    6654                 :         869 :           && sanitize_flags_p (SANITIZE_DIVIDE
    6655                 :             :                                | SANITIZE_FLOAT_DIVIDE
    6656                 :             :                                | SANITIZE_SI_OVERFLOW))
    6657                 :             :         {
    6658                 :             :           /* For diagnostics we want to use the promoted types without
    6659                 :             :              shorten_binary_op.  So convert the arguments to the
    6660                 :             :              original result_type.  */
    6661                 :         441 :           tree cop0 = op0;
    6662                 :         441 :           tree cop1 = op1;
    6663                 :         441 :           if (TREE_TYPE (cop0) != orig_type)
    6664                 :           6 :             cop0 = cp_convert (orig_type, op0, complain);
    6665                 :         441 :           if (TREE_TYPE (cop1) != orig_type)
    6666                 :          28 :             cop1 = cp_convert (orig_type, op1, complain);
    6667                 :         441 :           instrument_expr1 = ubsan_instrument_division (location, cop0, cop1);
    6668                 :             :         }
    6669                 :         428 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
    6670                 :         347 :         instrument_expr1 = ubsan_instrument_shift (location, code, op0, op1);
    6671                 :         869 :       if (instrument_expr != NULL)
    6672                 :          18 :         instrument_expr = add_stmt_to_compound (instrument_expr,
    6673                 :             :                                                 instrument_expr1);
    6674                 :             :       else
    6675                 :         851 :         instrument_expr = instrument_expr1;
    6676                 :             :     }
    6677                 :             : 
    6678                 :    80441472 :   result = build2_loc (location, resultcode, build_type, op0, op1);
    6679                 :    80441472 :   if (final_type != 0)
    6680                 :     4411757 :     result = cp_convert (final_type, result, complain);
    6681                 :             : 
    6682                 :    80441472 :   if (instrument_expr != NULL)
    6683                 :       19716 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    6684                 :             :                      instrument_expr, result);
    6685                 :             : 
    6686                 :    80441472 :   if (resultcode == SPACESHIP_EXPR && !processing_template_decl)
    6687                 :      111390 :     result = get_target_expr (result, complain);
    6688                 :             : 
    6689                 :    80441472 :   if (semantic_result_type)
    6690                 :       48784 :     result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, result);
    6691                 :             : 
    6692                 :    80441472 :   if (!c_inhibit_evaluation_warnings)
    6693                 :             :     {
    6694                 :    72828503 :       if (!processing_template_decl)
    6695                 :             :         {
    6696                 :    72828503 :           op0 = cp_fully_fold (op0);
    6697                 :             :           /* Only consider the second argument if the first isn't overflowed.  */
    6698                 :    72828503 :           if (!CONSTANT_CLASS_P (op0) || TREE_OVERFLOW_P (op0))
    6699                 :             :             return result;
    6700                 :    19038830 :           op1 = cp_fully_fold (op1);
    6701                 :    19038830 :           if (!CONSTANT_CLASS_P (op1) || TREE_OVERFLOW_P (op1))
    6702                 :             :             return result;
    6703                 :             :         }
    6704                 :           0 :       else if (!CONSTANT_CLASS_P (op0) || !CONSTANT_CLASS_P (op1)
    6705                 :           0 :                || TREE_OVERFLOW_P (op0) || TREE_OVERFLOW_P (op1))
    6706                 :             :         return result;
    6707                 :             : 
    6708                 :    13951368 :       tree result_ovl = fold_build2 (resultcode, build_type, op0, op1);
    6709                 :    13951368 :       if (TREE_OVERFLOW_P (result_ovl))
    6710                 :         188 :         overflow_warning (location, result_ovl);
    6711                 :             :     }
    6712                 :             : 
    6713                 :             :   return result;
    6714                 :             : }
    6715                 :             : 
    6716                 :             : /* Build a VEC_PERM_EXPR.
    6717                 :             :    This is a simple wrapper for c_build_vec_perm_expr.  */
    6718                 :             : tree
    6719                 :       14554 : build_x_vec_perm_expr (location_t loc,
    6720                 :             :                         tree arg0, tree arg1, tree arg2,
    6721                 :             :                         tsubst_flags_t complain)
    6722                 :             : {
    6723                 :       14554 :   tree orig_arg0 = arg0;
    6724                 :       14554 :   tree orig_arg1 = arg1;
    6725                 :       14554 :   tree orig_arg2 = arg2;
    6726                 :       14554 :   if (processing_template_decl)
    6727                 :             :     {
    6728                 :          19 :       if (type_dependent_expression_p (arg0)
    6729                 :          13 :           || type_dependent_expression_p (arg1)
    6730                 :          32 :           || type_dependent_expression_p (arg2))
    6731                 :           6 :         return build_min_nt_loc (loc, VEC_PERM_EXPR, arg0, arg1, arg2);
    6732                 :             :     }
    6733                 :       14548 :   tree exp = c_build_vec_perm_expr (loc, arg0, arg1, arg2, complain & tf_error);
    6734                 :       14548 :   if (processing_template_decl && exp != error_mark_node)
    6735                 :          13 :     return build_min_non_dep (VEC_PERM_EXPR, exp, orig_arg0,
    6736                 :          13 :                               orig_arg1, orig_arg2);
    6737                 :             :   return exp;
    6738                 :             : }
    6739                 :             : 
    6740                 :             : /* Build a VEC_PERM_EXPR.
    6741                 :             :    This is a simple wrapper for c_build_shufflevector.  */
    6742                 :             : tree
    6743                 :       34001 : build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
    6744                 :             :                        tsubst_flags_t complain)
    6745                 :             : {
    6746                 :       34001 :   tree arg0 = (*args)[0];
    6747                 :       34001 :   tree arg1 = (*args)[1];
    6748                 :       34001 :   if (processing_template_decl)
    6749                 :             :     {
    6750                 :          43 :       for (unsigned i = 0; i < args->length (); ++i)
    6751                 :          40 :         if (i <= 1
    6752                 :          40 :             ? type_dependent_expression_p ((*args)[i])
    6753                 :           9 :             : instantiation_dependent_expression_p ((*args)[i]))
    6754                 :             :           {
    6755                 :          22 :             tree exp = build_min_nt_call_vec (NULL, args);
    6756                 :          22 :             CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    6757                 :          22 :             return exp;
    6758                 :             :           }
    6759                 :             :     }
    6760                 :       33979 :   auto_vec<tree, 16> mask;
    6761                 :      459887 :   for (unsigned i = 2; i < args->length (); ++i)
    6762                 :             :     {
    6763                 :      425908 :       tree idx = fold_non_dependent_expr ((*args)[i], complain);
    6764                 :      425908 :       mask.safe_push (idx);
    6765                 :             :     }
    6766                 :       33979 :   tree exp = c_build_shufflevector (loc, arg0, arg1, mask, complain & tf_error);
    6767                 :       33979 :   if (processing_template_decl && exp != error_mark_node)
    6768                 :             :     {
    6769                 :           3 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    6770                 :           3 :       CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    6771                 :             :     }
    6772                 :       33979 :   return exp;
    6773                 :       33979 : }
    6774                 :             : 
    6775                 :             : /* Return a tree for the sum or difference (RESULTCODE says which)
    6776                 :             :    of pointer PTROP and integer INTOP.  */
    6777                 :             : 
    6778                 :             : static tree
    6779                 :     3852179 : cp_pointer_int_sum (location_t loc, enum tree_code resultcode, tree ptrop,
    6780                 :             :                     tree intop, tsubst_flags_t complain)
    6781                 :             : {
    6782                 :     3852179 :   tree res_type = TREE_TYPE (ptrop);
    6783                 :             : 
    6784                 :             :   /* pointer_int_sum() uses size_in_bytes() on the TREE_TYPE(res_type)
    6785                 :             :      in certain circumstance (when it's valid to do so).  So we need
    6786                 :             :      to make sure it's complete.  We don't need to check here, if we
    6787                 :             :      can actually complete it at all, as those checks will be done in
    6788                 :             :      pointer_int_sum() anyway.  */
    6789                 :     3852179 :   complete_type (TREE_TYPE (res_type));
    6790                 :             : 
    6791                 :     3852179 :   return pointer_int_sum (loc, resultcode, ptrop,
    6792                 :     3852179 :                           intop, complain & tf_warning_or_error);
    6793                 :             : }
    6794                 :             : 
    6795                 :             : /* Return a tree for the difference of pointers OP0 and OP1.
    6796                 :             :    The resulting tree has type int.  If POINTER_SUBTRACT sanitization is
    6797                 :             :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    6798                 :             : 
    6799                 :             : static tree
    6800                 :     1183737 : pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
    6801                 :             :               tsubst_flags_t complain, tree *instrument_expr)
    6802                 :             : {
    6803                 :     1183737 :   tree result, inttype;
    6804                 :     1183737 :   tree restype = ptrdiff_type_node;
    6805                 :     1183737 :   tree target_type = TREE_TYPE (ptrtype);
    6806                 :             : 
    6807                 :     1183737 :   if (!complete_type_or_maybe_complain (target_type, NULL_TREE, complain))
    6808                 :          12 :     return error_mark_node;
    6809                 :             : 
    6810                 :     1183725 :   if (VOID_TYPE_P (target_type))
    6811                 :             :     {
    6812                 :           0 :       if (complain & tf_error)
    6813                 :           0 :         permerror (loc, "ISO C++ forbids using pointer of "
    6814                 :             :                    "type %<void *%> in subtraction");
    6815                 :             :       else
    6816                 :           0 :         return error_mark_node;
    6817                 :             :     }
    6818                 :     1183725 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    6819                 :             :     {
    6820                 :          15 :       if (complain & tf_error)
    6821                 :           3 :         permerror (loc, "ISO C++ forbids using pointer to "
    6822                 :             :                    "a function in subtraction");
    6823                 :             :       else
    6824                 :          12 :         return error_mark_node;
    6825                 :             :     }
    6826                 :     1183713 :   if (TREE_CODE (target_type) == METHOD_TYPE)
    6827                 :             :     {
    6828                 :           0 :       if (complain & tf_error)
    6829                 :           0 :         permerror (loc, "ISO C++ forbids using pointer to "
    6830                 :             :                    "a method in subtraction");
    6831                 :             :       else
    6832                 :           0 :         return error_mark_node;
    6833                 :             :     }
    6834                 :     2367426 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    6835                 :     1183713 :                                  TREE_TYPE (TREE_TYPE (op0)),
    6836                 :     1183713 :                                  !(complain & tf_error))
    6837                 :     2367426 :            || !verify_type_context (loc, TCTX_POINTER_ARITH,
    6838                 :     1183713 :                                     TREE_TYPE (TREE_TYPE (op1)),
    6839                 :             :                                     !(complain & tf_error)))
    6840                 :           0 :     return error_mark_node;
    6841                 :             : 
    6842                 :             :   /* Determine integer type result of the subtraction.  This will usually
    6843                 :             :      be the same as the result type (ptrdiff_t), but may need to be a wider
    6844                 :             :      type if pointers for the address space are wider than ptrdiff_t.  */
    6845                 :     1183713 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    6846                 :           0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    6847                 :             :   else
    6848                 :             :     inttype = restype;
    6849                 :             : 
    6850                 :     1183713 :   if (!processing_template_decl
    6851                 :     1183713 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    6852                 :             :     {
    6853                 :          84 :       op0 = save_expr (op0);
    6854                 :          84 :       op1 = save_expr (op1);
    6855                 :             : 
    6856                 :          84 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    6857                 :          84 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    6858                 :             :     }
    6859                 :             : 
    6860                 :             :   /* First do the subtraction, then build the divide operator
    6861                 :             :      and only convert at the very end.
    6862                 :             :      Do not do default conversions in case restype is a short type.  */
    6863                 :             : 
    6864                 :             :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    6865                 :             :      pointers.  If some platform cannot provide that, or has a larger
    6866                 :             :      ptrdiff_type to support differences larger than half the address
    6867                 :             :      space, cast the pointers to some larger integer type and do the
    6868                 :             :      computations in that type.  */
    6869                 :     1183713 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    6870                 :           0 :     op0 = cp_build_binary_op (loc,
    6871                 :             :                               MINUS_EXPR,
    6872                 :             :                               cp_convert (inttype, op0, complain),
    6873                 :             :                               cp_convert (inttype, op1, complain),
    6874                 :             :                               complain);
    6875                 :             :   else
    6876                 :     1183713 :     op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    6877                 :             : 
    6878                 :             :   /* This generates an error if op1 is a pointer to an incomplete type.  */
    6879                 :     1183713 :   if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
    6880                 :             :     {
    6881                 :           0 :       if (complain & tf_error)
    6882                 :           0 :         error_at (loc, "invalid use of a pointer to an incomplete type in "
    6883                 :             :                   "pointer arithmetic");
    6884                 :             :       else
    6885                 :           0 :         return error_mark_node;
    6886                 :             :     }
    6887                 :             : 
    6888                 :     1183713 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (op1)))
    6889                 :             :     {
    6890                 :          15 :       if (complain & tf_error)
    6891                 :          15 :         error_at (loc, "arithmetic on pointer to an empty aggregate");
    6892                 :             :       else
    6893                 :           0 :         return error_mark_node;
    6894                 :             :     }
    6895                 :             : 
    6896                 :     1183713 :   op1 = (TYPE_PTROB_P (ptrtype)
    6897                 :     2367426 :          ? size_in_bytes_loc (loc, target_type)
    6898                 :             :          : integer_one_node);
    6899                 :             : 
    6900                 :             :   /* Do the division.  */
    6901                 :             : 
    6902                 :     1183713 :   result = build2_loc (loc, EXACT_DIV_EXPR, inttype, op0,
    6903                 :             :                        cp_convert (inttype, op1, complain));
    6904                 :     1183713 :   return cp_convert (restype, result, complain);
    6905                 :             : }
    6906                 :             : 
    6907                 :             : /* Construct and perhaps optimize a tree representation
    6908                 :             :    for a unary operation.  CODE, a tree_code, specifies the operation
    6909                 :             :    and XARG is the operand.  */
    6910                 :             : 
    6911                 :             : tree
    6912                 :    53502822 : build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg,
    6913                 :             :                   tree lookups, tsubst_flags_t complain)
    6914                 :             : {
    6915                 :    53502822 :   tree orig_expr = xarg;
    6916                 :    53502822 :   tree exp;
    6917                 :    53502822 :   int ptrmem = 0;
    6918                 :    53502822 :   tree overload = NULL_TREE;
    6919                 :             : 
    6920                 :    53502822 :   if (processing_template_decl)
    6921                 :             :     {
    6922                 :    37299875 :       if (type_dependent_expression_p (xarg))
    6923                 :             :         {
    6924                 :    25039823 :           tree e = build_min_nt_loc (loc, code, xarg.get_value (), NULL_TREE);
    6925                 :    25039823 :           TREE_TYPE (e) = build_dependent_operator_type (lookups, code, false);
    6926                 :    25039823 :           return e;
    6927                 :             :         }
    6928                 :             :     }
    6929                 :             : 
    6930                 :    28462999 :   exp = NULL_TREE;
    6931                 :             : 
    6932                 :             :   /* [expr.unary.op] says:
    6933                 :             : 
    6934                 :             :        The address of an object of incomplete type can be taken.
    6935                 :             : 
    6936                 :             :      (And is just the ordinary address operator, not an overloaded
    6937                 :             :      "operator &".)  However, if the type is a template
    6938                 :             :      specialization, we must complete the type at this point so that
    6939                 :             :      an overloaded "operator &" will be available if required.  */
    6940                 :    28462999 :   if (code == ADDR_EXPR
    6941                 :     3267332 :       && TREE_CODE (xarg) != TEMPLATE_ID_EXPR
    6942                 :    31729929 :       && ((CLASS_TYPE_P (TREE_TYPE (xarg))
    6943                 :     1578408 :            && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (xarg))))
    6944                 :     3264911 :           || (TREE_CODE (xarg) == OFFSET_REF)))
    6945                 :             :     /* Don't look for a function.  */;
    6946                 :             :   else
    6947                 :    28397388 :     exp = build_new_op (loc, code, LOOKUP_NORMAL, xarg, NULL_TREE,
    6948                 :             :                         NULL_TREE, lookups, &overload, complain);
    6949                 :             : 
    6950                 :    28462999 :   if (!exp && code == ADDR_EXPR)
    6951                 :             :     {
    6952                 :     3267072 :       if (is_overloaded_fn (xarg))
    6953                 :             :         {
    6954                 :      358802 :           tree fn = get_first_fn (xarg);
    6955                 :      717604 :           if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
    6956                 :             :             {
    6957                 :          12 :               if (complain & tf_error)
    6958                 :          21 :                 error_at (loc, DECL_CONSTRUCTOR_P (fn)
    6959                 :             :                           ? G_("taking address of constructor %qD")
    6960                 :             :                           : G_("taking address of destructor %qD"),
    6961                 :             :                           fn);
    6962                 :          12 :               return error_mark_node;
    6963                 :             :             }
    6964                 :             :         }
    6965                 :             : 
    6966                 :             :       /* A pointer to member-function can be formed only by saying
    6967                 :             :          &X::mf.  */
    6968                 :     3267054 :       if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
    6969                 :     3327091 :           && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
    6970                 :             :         {
    6971                 :           9 :           if (TREE_CODE (xarg) != OFFSET_REF
    6972                 :           9 :               || !TYPE_P (TREE_OPERAND (xarg, 0)))
    6973                 :             :             {
    6974                 :           9 :               if (complain & tf_error)
    6975                 :             :                 {
    6976                 :           9 :                   auto_diagnostic_group d;
    6977                 :           9 :                   error_at (loc, "invalid use of %qE to form a "
    6978                 :             :                             "pointer-to-member-function", xarg.get_value ());
    6979                 :           9 :                   if (TREE_CODE (xarg) != OFFSET_REF)
    6980                 :           6 :                     inform (loc, "  a qualified-id is required");
    6981                 :           9 :                 }
    6982                 :           9 :               return error_mark_node;
    6983                 :             :             }
    6984                 :             :           else
    6985                 :             :             {
    6986                 :           0 :               if (complain & tf_error)
    6987                 :           0 :                 error_at (loc, "parentheses around %qE cannot be used to "
    6988                 :             :                           "form a pointer-to-member-function",
    6989                 :             :                           xarg.get_value ());
    6990                 :             :               else
    6991                 :           0 :                 return error_mark_node;
    6992                 :           0 :               PTRMEM_OK_P (xarg) = 1;
    6993                 :             :             }
    6994                 :             :         }
    6995                 :             : 
    6996                 :     3267051 :       if (TREE_CODE (xarg) == OFFSET_REF)
    6997                 :             :         {
    6998                 :       63577 :           ptrmem = PTRMEM_OK_P (xarg);
    6999                 :             : 
    7000                 :           0 :           if (!ptrmem && !flag_ms_extensions
    7001                 :       63577 :               && TREE_CODE (TREE_TYPE (TREE_OPERAND (xarg, 1))) == METHOD_TYPE)
    7002                 :             :             {
    7003                 :             :               /* A single non-static member, make sure we don't allow a
    7004                 :             :                  pointer-to-member.  */
    7005                 :           0 :               xarg = build2 (OFFSET_REF, TREE_TYPE (xarg),
    7006                 :           0 :                              TREE_OPERAND (xarg, 0),
    7007                 :           0 :                              ovl_make (TREE_OPERAND (xarg, 1)));
    7008                 :           0 :               PTRMEM_OK_P (xarg) = ptrmem;
    7009                 :             :             }
    7010                 :             :         }
    7011                 :             : 
    7012                 :     6534102 :       exp = cp_build_addr_expr_strict (xarg, complain);
    7013                 :             : 
    7014                 :     3267051 :       if (TREE_CODE (exp) == PTRMEM_CST)
    7015                 :       62677 :         PTRMEM_CST_LOCATION (exp) = loc;
    7016                 :             :       else
    7017                 :     3204374 :         protected_set_expr_location (exp, loc);
    7018                 :             :     }
    7019                 :             : 
    7020                 :    28462978 :   if (processing_template_decl && exp != error_mark_node)
    7021                 :             :     {
    7022                 :    12259940 :       if (overload != NULL_TREE)
    7023                 :      157097 :         return (build_min_non_dep_op_overload
    7024                 :      157097 :                 (code, exp, overload, orig_expr, integer_zero_node));
    7025                 :             : 
    7026                 :    12102843 :       exp = build_min_non_dep (code, exp, orig_expr,
    7027                 :             :                                /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
    7028                 :             :     }
    7029                 :    28305881 :   if (TREE_CODE (exp) == ADDR_EXPR)
    7030                 :     2501757 :     PTRMEM_OK_P (exp) = ptrmem;
    7031                 :             :   return exp;
    7032                 :             : }
    7033                 :             : 
    7034                 :             : /* Construct and perhaps optimize a tree representation
    7035                 :             :    for __builtin_addressof operation.  ARG specifies the operand.  */
    7036                 :             : 
    7037                 :             : tree
    7038                 :      399446 : cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain)
    7039                 :             : {
    7040                 :      399446 :   tree orig_expr = arg;
    7041                 :             : 
    7042                 :      399446 :   if (processing_template_decl)
    7043                 :             :     {
    7044                 :      138864 :       if (type_dependent_expression_p (arg))
    7045                 :      138864 :         return build_min_nt_loc (loc, ADDRESSOF_EXPR, arg, NULL_TREE);
    7046                 :             :     }
    7047                 :             : 
    7048                 :      521164 :   tree exp = cp_build_addr_expr_strict (arg, complain);
    7049                 :             : 
    7050                 :      260582 :   if (processing_template_decl && exp != error_mark_node)
    7051                 :           0 :     exp = build_min_non_dep (ADDRESSOF_EXPR, exp, orig_expr, NULL_TREE);
    7052                 :             :   return exp;
    7053                 :             : }
    7054                 :             : 
    7055                 :             : /* Like c_common_truthvalue_conversion, but handle pointer-to-member
    7056                 :             :    constants, where a null value is represented by an INTEGER_CST of
    7057                 :             :    -1.  */
    7058                 :             : 
    7059                 :             : tree
    7060                 :     8165160 : cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
    7061                 :             : {
    7062                 :     8165160 :   tree type = TREE_TYPE (expr);
    7063                 :     8165160 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    7064                 :     7131088 :   if (TYPE_PTR_OR_PTRMEM_P (type)
    7065                 :             :       /* Avoid ICE on invalid use of non-static member function.  */
    7066                 :    15295970 :       || TREE_CODE (expr) == FUNCTION_DECL)
    7067                 :     1034350 :     return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain);
    7068                 :             :   else
    7069                 :     7130810 :     return c_common_truthvalue_conversion (loc, expr);
    7070                 :             : }
    7071                 :             : 
    7072                 :             : /* Returns EXPR contextually converted to bool.  */
    7073                 :             : 
    7074                 :             : tree
    7075                 :    44913442 : contextual_conv_bool (tree expr, tsubst_flags_t complain)
    7076                 :             : {
    7077                 :    44913442 :   return perform_implicit_conversion_flags (boolean_type_node, expr,
    7078                 :    44913442 :                                             complain, LOOKUP_NORMAL);
    7079                 :             : }
    7080                 :             : 
    7081                 :             : /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  This
    7082                 :             :    is a low-level function; most callers should use maybe_convert_cond.  */
    7083                 :             : 
    7084                 :             : tree
    7085                 :    40403786 : condition_conversion (tree expr)
    7086                 :             : {
    7087                 :    40403786 :   tree t = contextual_conv_bool (expr, tf_warning_or_error);
    7088                 :    40403786 :   if (!processing_template_decl)
    7089                 :    19481068 :     t = fold_build_cleanup_point_expr (boolean_type_node, t);
    7090                 :    40403786 :   return t;
    7091                 :             : }
    7092                 :             : 
    7093                 :             : /* Returns the address of T.  This function will fold away
    7094                 :             :    ADDR_EXPR of INDIRECT_REF.  This is only for low-level usage;
    7095                 :             :    most places should use cp_build_addr_expr instead.  */
    7096                 :             : 
    7097                 :             : tree
    7098                 :   240557338 : build_address (tree t)
    7099                 :             : {
    7100                 :   240557338 :   if (error_operand_p (t) || !cxx_mark_addressable (t))
    7101                 :          21 :     return error_mark_node;
    7102                 :   240557317 :   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR
    7103                 :             :                        || processing_template_decl);
    7104                 :   240557317 :   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
    7105                 :   240557317 :   if (TREE_CODE (t) != ADDR_EXPR)
    7106                 :    43916094 :     t = rvalue (t);
    7107                 :             :   return t;
    7108                 :             : }
    7109                 :             : 
    7110                 :             : /* Return a NOP_EXPR converting EXPR to TYPE.  */
    7111                 :             : 
    7112                 :             : tree
    7113                 :   411811876 : build_nop (tree type, tree expr)
    7114                 :             : {
    7115                 :   411811876 :   if (type == error_mark_node || error_operand_p (expr))
    7116                 :             :     return expr;
    7117                 :   411811800 :   return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr);
    7118                 :             : }
    7119                 :             : 
    7120                 :             : /* Take the address of ARG, whatever that means under C++ semantics.
    7121                 :             :    If STRICT_LVALUE is true, require an lvalue; otherwise, allow xvalues
    7122                 :             :    and class rvalues as well.
    7123                 :             : 
    7124                 :             :    Nothing should call this function directly; instead, callers should use
    7125                 :             :    cp_build_addr_expr or cp_build_addr_expr_strict.  */
    7126                 :             : 
    7127                 :             : static tree
    7128                 :   181053177 : cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
    7129                 :             : {
    7130                 :   181053177 :   tree argtype;
    7131                 :   181053177 :   tree val;
    7132                 :             : 
    7133                 :   181053177 :   if (!arg || error_operand_p (arg))
    7134                 :          12 :     return error_mark_node;
    7135                 :             : 
    7136                 :   181053165 :   arg = mark_lvalue_use (arg);
    7137                 :   181053165 :   if (error_operand_p (arg))
    7138                 :           3 :     return error_mark_node;
    7139                 :             : 
    7140                 :   181053162 :   argtype = lvalue_type (arg);
    7141                 :   181053162 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    7142                 :             : 
    7143                 :   181053162 :   gcc_assert (!(identifier_p (arg) && IDENTIFIER_ANY_OP_P (arg)));
    7144                 :             : 
    7145                 :    11580784 :   if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
    7146                 :   181053356 :       && !really_overloaded_fn (arg))
    7147                 :             :     {
    7148                 :             :       /* They're trying to take the address of a unique non-static
    7149                 :             :          member function.  This is ill-formed (except in MS-land),
    7150                 :             :          but let's try to DTRT.
    7151                 :             :          Note: We only handle unique functions here because we don't
    7152                 :             :          want to complain if there's a static overload; non-unique
    7153                 :             :          cases will be handled by instantiate_type.  But we need to
    7154                 :             :          handle this case here to allow casts on the resulting PMF.
    7155                 :             :          We could defer this in non-MS mode, but it's easier to give
    7156                 :             :          a useful error here.  */
    7157                 :             : 
    7158                 :             :       /* Inside constant member functions, the `this' pointer
    7159                 :             :          contains an extra const qualifier.  TYPE_MAIN_VARIANT
    7160                 :             :          is used here to remove this const from the diagnostics
    7161                 :             :          and the created OFFSET_REF.  */
    7162                 :          70 :       tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
    7163                 :          70 :       tree fn = get_first_fn (TREE_OPERAND (arg, 1));
    7164                 :          70 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7165                 :           0 :         return error_mark_node;
    7166                 :             :       /* Until microsoft headers are known to incorrectly take the address of
    7167                 :             :          unqualified xobj member functions we should not support this
    7168                 :             :          extension.
    7169                 :             :          See comment in class.cc:resolve_address_of_overloaded_function for
    7170                 :             :          the extended reasoning.  */
    7171                 :          70 :       if (!flag_ms_extensions || DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7172                 :             :         {
    7173                 :          64 :           auto_diagnostic_group d;
    7174                 :          64 :           tree name = DECL_NAME (fn);
    7175                 :          64 :           if (!(complain & tf_error))
    7176                 :           0 :             return error_mark_node;
    7177                 :          64 :           else if (current_class_type
    7178                 :          64 :                    && TREE_OPERAND (arg, 0) == current_class_ref)
    7179                 :             :             /* An expression like &memfn.  */
    7180                 :          31 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7181                 :          21 :               permerror (loc,
    7182                 :             :                          "ISO C++ forbids taking the address of an unqualified"
    7183                 :             :                          " or parenthesized non-static member function to form"
    7184                 :             :                          " a pointer to member function.  Say %<&%T::%D%>",
    7185                 :             :                          base, name);
    7186                 :             :             else
    7187                 :          10 :               error_at (loc,
    7188                 :             :                         "ISO C++ forbids taking the address of an unqualified"
    7189                 :             :                         " or parenthesized non-static member function to form"
    7190                 :             :                         " a pointer to explicit object member function");
    7191                 :             :           else
    7192                 :          33 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7193                 :           9 :               permerror (loc,
    7194                 :             :                          "ISO C++ forbids taking the address of a bound member"
    7195                 :             :                          " function to form a pointer to member function."
    7196                 :             :                          "  Say %<&%T::%D%>",
    7197                 :             :                          base, name);
    7198                 :             :             else
    7199                 :          24 :               error_at (loc,
    7200                 :             :                         "ISO C++ forbids taking the address of a bound member"
    7201                 :             :                         " function to form a pointer to explicit object member"
    7202                 :             :                         " function");
    7203                 :          64 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7204                 :          34 :             inform (loc,
    7205                 :             :                     "a pointer to explicit object member function can only be "
    7206                 :             :                     "formed with %<&%T::%D%>", base, name);
    7207                 :          64 :         }
    7208                 :          70 :       arg = build_offset_ref (base, fn, /*address_p=*/true, complain);
    7209                 :             :     }
    7210                 :             : 
    7211                 :             :   /* Uninstantiated types are all functions.  Taking the
    7212                 :             :      address of a function is a no-op, so just return the
    7213                 :             :      argument.  */
    7214                 :   181053162 :   if (type_unknown_p (arg))
    7215                 :        1764 :     return build1 (ADDR_EXPR, unknown_type_node, arg);
    7216                 :             : 
    7217                 :   181051398 :   if (TREE_CODE (arg) == OFFSET_REF)
    7218                 :             :     /* We want a pointer to member; bypass all the code for actually taking
    7219                 :             :        the address of something.  */
    7220                 :       62790 :     goto offset_ref;
    7221                 :             : 
    7222                 :             :   /* Anything not already handled and not a true memory reference
    7223                 :             :      is an error.  */
    7224                 :   180988608 :   if (!FUNC_OR_METHOD_TYPE_P (argtype))
    7225                 :             :     {
    7226                 :    92585367 :       cp_lvalue_kind kind = lvalue_kind (arg);
    7227                 :    92585367 :       if (kind == clk_none)
    7228                 :             :         {
    7229                 :          23 :           if (complain & tf_error)
    7230                 :          23 :             lvalue_error (loc, lv_addressof);
    7231                 :          23 :           return error_mark_node;
    7232                 :             :         }
    7233                 :    92585344 :       if (strict_lvalue && (kind & (clk_rvalueref|clk_class)))
    7234                 :             :         {
    7235                 :          36 :           if (!(complain & tf_error))
    7236                 :           9 :             return error_mark_node;
    7237                 :             :           /* Make this a permerror because we used to accept it.  */
    7238                 :          27 :           permerror (loc, "taking address of rvalue");
    7239                 :             :         }
    7240                 :             :     }
    7241                 :             : 
    7242                 :   180988576 :   if (TYPE_REF_P (argtype))
    7243                 :             :     {
    7244                 :         345 :       tree type = build_pointer_type (TREE_TYPE (argtype));
    7245                 :         345 :       arg = build1 (CONVERT_EXPR, type, arg);
    7246                 :         345 :       return arg;
    7247                 :             :     }
    7248                 :   180988231 :   else if (pedantic && DECL_MAIN_P (tree_strip_any_location_wrapper (arg)))
    7249                 :             :     {
    7250                 :             :       /* ARM $3.4 */
    7251                 :             :       /* Apparently a lot of autoconf scripts for C++ packages do this,
    7252                 :             :          so only complain if -Wpedantic.  */
    7253                 :           9 :       if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
    7254                 :           9 :         pedwarn (loc, OPT_Wpedantic,
    7255                 :             :                  "ISO C++ forbids taking address of function %<::main%>");
    7256                 :           0 :       else if (flag_pedantic_errors)
    7257                 :           0 :         return error_mark_node;
    7258                 :             :     }
    7259                 :             : 
    7260                 :             :   /* Let &* cancel out to simplify resulting code.  */
    7261                 :   180988231 :   if (INDIRECT_REF_P (arg))
    7262                 :             :     {
    7263                 :    58217614 :       arg = TREE_OPERAND (arg, 0);
    7264                 :    58217614 :       if (TYPE_REF_P (TREE_TYPE (arg)))
    7265                 :             :         {
    7266                 :    32230154 :           tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
    7267                 :    32230154 :           arg = build1 (CONVERT_EXPR, type, arg);
    7268                 :             :         }
    7269                 :             :       else
    7270                 :             :         /* Don't let this be an lvalue.  */
    7271                 :    25987460 :         arg = rvalue (arg);
    7272                 :    58217614 :       return arg;
    7273                 :             :     }
    7274                 :             : 
    7275                 :             :   /* Handle complex lvalues (when permitted)
    7276                 :             :      by reduction to simpler cases.  */
    7277                 :   122770617 :   val = unary_complex_lvalue (ADDR_EXPR, arg);
    7278                 :   122770617 :   if (val != 0)
    7279                 :             :     return val;
    7280                 :             : 
    7281                 :   122315397 :   switch (TREE_CODE (arg))
    7282                 :             :     {
    7283                 :           0 :     CASE_CONVERT:
    7284                 :           0 :     case FLOAT_EXPR:
    7285                 :           0 :     case FIX_TRUNC_EXPR:
    7286                 :             :       /* We should have handled this above in the lvalue_kind check.  */
    7287                 :           0 :       gcc_unreachable ();
    7288                 :       56497 :       break;
    7289                 :             : 
    7290                 :       56497 :     case BASELINK:
    7291                 :       56497 :       arg = BASELINK_FUNCTIONS (arg);
    7292                 :             :       /* Fall through.  */
    7293                 :             : 
    7294                 :       56497 :     case OVERLOAD: