LCOV - code coverage report
Current view: top level - gcc/cp - typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.1 % 5559 5120
Test Date: 2026-08-22 16:33:35 Functions: 97.8 % 178 174
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Build expressions with type checking for C++ compiler.
       2              :    Copyright (C) 1987-2026 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    152016160 : require_complete_type (tree value,
      75              :                        tsubst_flags_t complain /* = tf_warning_or_error */)
      76              : {
      77    152016160 :   tree type;
      78              : 
      79    152016160 :   if (processing_template_decl || value == error_mark_node)
      80              :     return value;
      81              : 
      82    141178468 :   if (TREE_CODE (value) == OVERLOAD)
      83            0 :     type = unknown_type_node;
      84              :   else
      85    141178468 :     type = TREE_TYPE (value);
      86              : 
      87    141178468 :   if (type == error_mark_node)
      88              :     return error_mark_node;
      89              : 
      90              :   /* First, detect a valid value with a complete type.  */
      91    141178456 :   if (COMPLETE_TYPE_P (type))
      92              :     return value;
      93              : 
      94       135788 :   if (complete_type_or_maybe_complain (type, value, complain))
      95              :     return value;
      96              :   else
      97          213 :     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  15999786881 : complete_type (tree type)
     107              : {
     108  15999786881 :   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  15999786881 :   if (type == error_mark_node || COMPLETE_TYPE_P (type))
     114              :     ;
     115   5221978585 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     116              :     {
     117       808674 :       tree t = complete_type (TREE_TYPE (type));
     118       808674 :       unsigned int needs_constructing, has_nontrivial_dtor;
     119       808674 :       if (COMPLETE_TYPE_P (t) && !dependent_type_p (type))
     120       789646 :         layout_type (type);
     121       808674 :       needs_constructing
     122       808674 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
     123       808674 :       has_nontrivial_dtor
     124       808674 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
     125      2681600 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
     126              :         {
     127      1872926 :           TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
     128      1872926 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
     129              :         }
     130              :     }
     131   5221169911 :   else if (CLASS_TYPE_P (type))
     132              :     {
     133   5124826976 :       if (modules_p ())
     134              :         /* TYPE could be a class member we've not loaded the definition of.  */
     135     20067173 :         lazy_load_pendings (TYPE_NAME (TYPE_MAIN_VARIANT (type)));
     136              : 
     137   5124826976 :       if (CLASSTYPE_TEMPLATE_INSTANTIATION (type))
     138    981527381 :         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   1724148789 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
     150              : {
     151   1724148789 :   type = complete_type (type);
     152   1724148786 :   if (type == error_mark_node)
     153              :     /* We already issued an error.  */
     154              :     return NULL_TREE;
     155   1724148628 :   else if (!COMPLETE_TYPE_P (type))
     156              :     {
     157         3966 :       if (complain & tf_error)
     158          476 :         cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
     159         3966 :       note_failed_type_completion (type, complain);
     160         3966 :       return NULL_TREE;
     161              :     }
     162              :   else
     163              :     return type;
     164              : }
     165              : 
     166              : tree
     167    173187443 : complete_type_or_else (tree type, tree value)
     168              : {
     169    173187443 :   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      4367270 : commonparms (tree p1, tree p2)
     182              : {
     183      4367270 :   tree oldargs = p1, newargs, n;
     184      4367270 :   int i, len;
     185      4367270 :   int any_change = 0;
     186              : 
     187      4367270 :   len = list_length (p1);
     188      4367270 :   newargs = tree_last (p1);
     189              : 
     190      4367270 :   if (newargs == void_list_node)
     191      4367270 :     i = 1;
     192              :   else
     193              :     {
     194        41856 :       i = 0;
     195        41856 :       newargs = 0;
     196              :     }
     197              : 
     198     14449693 :   for (; i < len; i++)
     199     10082423 :     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
     200              : 
     201              :   n = newargs;
     202              : 
     203     18775107 :   for (i = 0; p1;
     204     14407837 :        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
     205              :     {
     206     14408044 :       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
     207              :         {
     208          174 :           TREE_PURPOSE (n) = TREE_PURPOSE (p1);
     209          174 :           any_change = 1;
     210              :         }
     211     14407663 :       else if (! TREE_PURPOSE (p1))
     212              :         {
     213     14407630 :           if (TREE_PURPOSE (p2))
     214              :             {
     215       437083 :               TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     216       437083 :               any_change = 1;
     217              :             }
     218              :         }
     219              :       else
     220              :         {
     221           33 :           if (simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)) != 1)
     222           33 :             any_change = 1;
     223           33 :           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     224              :         }
     225     14407837 :       if (TREE_VALUE (p1) != TREE_VALUE (p2))
     226              :         {
     227      4019598 :           any_change = 1;
     228      4019598 :           TREE_VALUE (n) = merge_types (TREE_VALUE (p1), TREE_VALUE (p2));
     229              :         }
     230              :       else
     231     10388239 :         TREE_VALUE (n) = TREE_VALUE (p1);
     232              :     }
     233      4367270 :   if (! any_change)
     234      1456731 :     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     34156280 : original_type (tree t)
     243              : {
     244     34156280 :   int quals = cp_type_quals (t);
     245     34156280 :   while (t != error_mark_node
     246     35332903 :          && TYPE_NAME (t) != NULL_TREE)
     247              :     {
     248     11888433 :       tree x = TYPE_NAME (t);
     249     11888433 :       if (TREE_CODE (x) != TYPE_DECL)
     250              :         break;
     251     11888433 :       x = DECL_ORIGINAL_TYPE (x);
     252     11888433 :       if (x == NULL_TREE)
     253              :         break;
     254              :       t = x;
     255              :     }
     256     34156280 :   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        59861 : merge_type_attributes_from (tree type, tree other_type)
     264              : {
     265        59861 :   tree attrs = targetm.merge_type_attributes (type, other_type);
     266        59861 :   attrs = restrict_type_identity_attributes_to (attrs, TYPE_ATTRIBUTES (type));
     267        59861 :   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      7365205 : cp_compare_floating_point_conversion_ranks (tree t1, tree t2)
     280              : {
     281      7365205 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
     282      7365205 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
     283      7365205 :   int extended1 = 0;
     284      7365205 :   int extended2 = 0;
     285              : 
     286      7365205 :   if (mv1 == mv2)
     287              :     return 0;
     288              : 
     289     58902312 :   for (int i = 0; i < NUM_FLOATN_NX_TYPES; ++i)
     290              :     {
     291     51539523 :       if (mv1 == FLOATN_NX_TYPE_NODE (i))
     292      3313754 :         extended1 = i + 1;
     293     51539523 :       if (mv2 == FLOATN_NX_TYPE_NODE (i))
     294      2798678 :         extended2 = i + 1;
     295              :     }
     296      7362789 :   if (mv1 == bfloat16_type_node)
     297       804167 :     extended1 = true;
     298      7362789 :   if (mv2 == bfloat16_type_node)
     299       615008 :     extended2 = true;
     300      7362789 :   if (extended2 && !extended1)
     301              :     {
     302      3203698 :       int ret = cp_compare_floating_point_conversion_ranks (t2, t1);
     303      3203698 :       return ret == 3 ? 3 : -ret;
     304              :     }
     305              : 
     306      4159091 :   const struct real_format *fmt1 = REAL_MODE_FORMAT (TYPE_MODE (t1));
     307      4159091 :   const struct real_format *fmt2 = REAL_MODE_FORMAT (TYPE_MODE (t2));
     308              :   /* Currently, extended floating point types are only binary, and
     309              :      they never have a proper subset or superset of values with
     310              :      decimal floating point types except for the _Float16 vs. _Decimal128
     311              :      pair, so return 3 for unordered conversion ranks.  */
     312      4159091 :   gcc_assert (fmt1->b == 2);
     313      4159091 :   if (fmt2->b == 10)
     314              :     {
     315              :       /* _Float16 needs at most 21 decimal digits (e.g.
     316              :          0x1.a3cp-14f16 is exactly 0.000100076198577880859375DL),
     317              :          so it is not a proper subset of _Decimal64 but is subset
     318              :          of _Decimal128.  While std::bfloat16_t needs at most 96
     319              :          decimal digits, so even _Decimal128 doesn't cover it.
     320              :          _Float32 has at least one value which needs 112 decimal
     321              :          digits, _Float64 at least 767 decimal digits.  */
     322           33 :       if (fmt1->emin == -13
     323           15 :           && fmt1->emax == 16
     324           15 :           && fmt1->p == 11
     325           15 :           && fmt2->emin == -6142
     326           15 :           && fmt2->emax == 6145
     327           15 :           && fmt2->p == 34)
     328              :         return -2;
     329           18 :       return 3;
     330              :     }
     331      4159058 :   gcc_assert (fmt2->b == 2);
     332              :   /* For {ibm,mips}_extended_format formats, the type has variable
     333              :      precision up to ~2150 bits when the first double is around maximum
     334              :      representable double and second double is subnormal minimum.
     335              :      So, e.g. for __ibm128 vs. std::float128_t, they have unordered
     336              :      ranks.  */
     337     33272464 :   int p1 = (MODE_COMPOSITE_P (TYPE_MODE (t1))
     338      8318116 :             ? fmt1->emax - fmt1->emin + fmt1->p - 1 : fmt1->p);
     339     33272464 :   int p2 = (MODE_COMPOSITE_P (TYPE_MODE (t2))
     340      8318116 :             ? fmt2->emax - fmt2->emin + fmt2->p - 1 : fmt2->p);
     341              :   /* The rank of a floating point type T is greater than the rank of
     342              :      any floating-point type whose set of values is a proper subset
     343              :      of the set of values of T.  */
     344      4159058 :   if ((p1 > p2 && fmt1->emax >= fmt2->emax)
     345      3261280 :        || (p1 == p2 && fmt1->emax > fmt2->emax))
     346              :     return 2;
     347      3261280 :   if ((p1 < p2 && fmt1->emax <= fmt2->emax)
     348      1073337 :        || (p1 == p2 && fmt1->emax < fmt2->emax))
     349              :     return -2;
     350      1073337 :   if ((p1 > p2 && fmt1->emax < fmt2->emax)
     351      1060169 :        || (p1 < p2 && fmt1->emax > fmt2->emax))
     352              :     return 3;
     353      1047103 :   if (!extended1 && !extended2)
     354              :     {
     355              :       /* The rank of long double is greater than the rank of double, which
     356              :          is greater than the rank of float.  */
     357            0 :       if (t1 == long_double_type_node)
     358              :         return 2;
     359            0 :       else if (t2 == long_double_type_node)
     360              :         return -2;
     361            0 :       if (t1 == double_type_node)
     362              :         return 2;
     363            0 :       else if (t2 == double_type_node)
     364              :         return -2;
     365            0 :       if (t1 == float_type_node)
     366              :         return 2;
     367            0 :       else if (t2 == float_type_node)
     368              :         return -2;
     369            0 :       return 0;
     370              :     }
     371              :   /* Two extended floating-point types with the same set of values have equal
     372              :      ranks.  */
     373      1047103 :   if (extended1 && extended2)
     374              :     {
     375            6 :       if ((extended1 <= NUM_FLOATN_TYPES) == (extended2 <= NUM_FLOATN_TYPES))
     376              :         {
     377              :           /* Prefer higher extendedN value.  */
     378            0 :           if (extended1 > extended2)
     379              :             return 1;
     380            0 :           else if (extended1 < extended2)
     381              :             return -1;
     382              :           else
     383            0 :             return 0;
     384              :         }
     385            6 :       else if (extended1 <= NUM_FLOATN_TYPES)
     386              :         /* Prefer _FloatN type over _FloatMx type.  */
     387              :         return 1;
     388            3 :       else if (extended2 <= NUM_FLOATN_TYPES)
     389              :         return -1;
     390              :       else
     391            0 :         return 0;
     392              :     }
     393              : 
     394              :   /* gcc_assert (extended1 && !extended2);  */
     395              :   tree *p;
     396              :   int cnt = 0;
     397      4188388 :   for (p = &float_type_node; p <= &long_double_type_node; ++p)
     398              :     {
     399      3141291 :       const struct real_format *fmt3 = REAL_MODE_FORMAT (TYPE_MODE (*p));
     400      3141291 :       gcc_assert (fmt3->b == 2);
     401     25130328 :       int p3 = (MODE_COMPOSITE_P (TYPE_MODE (*p))
     402      6282582 :                 ? fmt3->emax - fmt3->emin + fmt3->p - 1 : fmt3->p);
     403      3141291 :       if (p1 == p3 && fmt1->emax == fmt3->emax)
     404       929564 :         ++cnt;
     405              :     }
     406              :   /* An extended floating-point type with the same set of values
     407              :      as exactly one cv-unqualified standard floating-point type
     408              :      has a rank equal to the rank of that standard floating-point
     409              :      type.
     410              : 
     411              :      An extended floating-point type with the same set of values
     412              :      as more than one cv-unqualified standard floating-point type
     413              :      has a rank equal to the rank of double.
     414              : 
     415              :      Thus, if the latter is true and t2 is long double, t2
     416              :      has higher rank.  */
     417      1047097 :   if (cnt > 1 && mv2 == long_double_type_node)
     418              :     return -2;
     419              :   /* And similarly if t2 is float, t2 has lower rank.  */
     420            0 :   if (cnt > 1 && mv2 == float_type_node)
     421            0 :     return 2;
     422              :   /* Otherwise, they have equal rank, but extended types
     423              :      (other than std::bfloat16_t) have higher subrank.
     424              :      std::bfloat16_t shouldn't have equal rank to any standard
     425              :      floating point type.  */
     426              :   return 1;
     427              : }
     428              : 
     429              : /* Return the common type for two arithmetic types T1 and T2 under the
     430              :    usual arithmetic conversions.  The default conversions have already
     431              :    been applied, and enumerated types converted to their compatible
     432              :    integer types.  */
     433              : 
     434              : static tree
     435    116118165 : cp_common_type (tree t1, tree t2)
     436              : {
     437    116118165 :   enum tree_code code1 = TREE_CODE (t1);
     438    116118165 :   enum tree_code code2 = TREE_CODE (t2);
     439    116118165 :   tree attributes;
     440    116118165 :   int i;
     441              : 
     442              : 
     443              :   /* In what follows, we slightly generalize the rules given in [expr] so
     444              :      as to deal with `long long' and `complex'.  First, merge the
     445              :      attributes.  */
     446    116118165 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     447              : 
     448    116118165 :   if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
     449              :     {
     450      2166197 :       if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     451      2166197 :         return build_type_attribute_variant (t1, attributes);
     452              :       else
     453              :         return NULL_TREE;
     454              :     }
     455              : 
     456              :   /* FIXME: Attributes.  */
     457    113951968 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     458              :               || VECTOR_TYPE_P (t1)
     459              :               || UNSCOPED_ENUM_P (t1));
     460    113951968 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     461              :               || VECTOR_TYPE_P (t2)
     462              :               || UNSCOPED_ENUM_P (t2));
     463              : 
     464              :   /* If one type is complex, form the common type of the non-complex
     465              :      components, then make that complex.  Use T1 or T2 if it is the
     466              :      required type.  */
     467    113951968 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     468              :     {
     469       223304 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
     470       223304 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
     471       223304 :       tree subtype
     472       223304 :         = type_after_usual_arithmetic_conversions (subtype1, subtype2);
     473              : 
     474       223304 :       if (subtype == error_mark_node)
     475              :         return subtype;
     476       223304 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
     477       189896 :         return build_type_attribute_variant (t1, attributes);
     478        33408 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
     479        33348 :         return build_type_attribute_variant (t2, attributes);
     480              :       else
     481           60 :         return build_type_attribute_variant (build_complex_type (subtype),
     482           60 :                                              attributes);
     483              :     }
     484              : 
     485    113728664 :   if (code1 == VECTOR_TYPE)
     486              :     {
     487              :       /* When we get here we should have two vectors of the same size.
     488              :          Just prefer the unsigned one if present.  */
     489        59861 :       if (TYPE_UNSIGNED (t1))
     490        12887 :         return merge_type_attributes_from (t1, t2);
     491              :       else
     492        46974 :         return merge_type_attributes_from (t2, t1);
     493              :     }
     494              : 
     495              :   /* If only one is real, use it as the result.  */
     496    113668803 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     497      1167756 :     return build_type_attribute_variant (t1, attributes);
     498    112501047 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     499      1046449 :     return build_type_attribute_variant (t2, attributes);
     500              : 
     501    111454598 :   if (code1 == REAL_TYPE
     502    111454598 :       && (extended_float_type_p (t1) || extended_float_type_p (t2)))
     503              :     {
     504       138007 :       tree mv1 = TYPE_MAIN_VARIANT (t1);
     505       138007 :       tree mv2 = TYPE_MAIN_VARIANT (t2);
     506       138007 :       if (mv1 == mv2)
     507       135014 :         return build_type_attribute_variant (t1, attributes);
     508              : 
     509         2993 :       int cmpret = cp_compare_floating_point_conversion_ranks (mv1, mv2);
     510         2993 :       if (cmpret == 3)
     511            6 :         return error_mark_node;
     512         2987 :       else if (cmpret >= 0)
     513         2612 :         return build_type_attribute_variant (t1, attributes);
     514              :       else
     515          375 :         return build_type_attribute_variant (t2, attributes);
     516              :     }
     517              : 
     518              :   /* Both real or both integers; use the one with greater precision.  */
     519    111316591 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     520     17726201 :     return build_type_attribute_variant (t1, attributes);
     521     93590390 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
     522      2249875 :     return build_type_attribute_variant (t2, attributes);
     523              : 
     524              :   /* The types are the same; no need to do anything fancy.  */
     525     91340515 :   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     526     83776210 :     return build_type_attribute_variant (t1, attributes);
     527              : 
     528      7564305 :   if (code1 != REAL_TYPE)
     529              :     {
     530              :       /* If one is unsigned long long, then convert the other to unsigned
     531              :          long long.  */
     532      7564302 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node)
     533      7564302 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_unsigned_type_node))
     534       159333 :         return build_type_attribute_variant (long_long_unsigned_type_node,
     535       159333 :                                              attributes);
     536              :       /* If one is a long long, and the other is an unsigned long, and
     537              :          long long can represent all the values of an unsigned long, then
     538              :          convert to a long long.  Otherwise, convert to an unsigned long
     539              :          long.  Otherwise, if either operand is long long, convert the
     540              :          other to long long.
     541              : 
     542              :          Since we're here, we know the TYPE_PRECISION is the same;
     543              :          therefore converting to long long cannot represent all the values
     544              :          of an unsigned long, so we choose unsigned long long in that
     545              :          case.  */
     546      7404969 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_integer_type_node)
     547      7404969 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_integer_type_node))
     548              :         {
     549         1356 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     550          684 :                     ? long_long_unsigned_type_node
     551          684 :                     : long_long_integer_type_node);
     552          684 :           return build_type_attribute_variant (t, attributes);
     553              :         }
     554              : 
     555              :       /* Go through the same procedure, but for longs.  */
     556      7404285 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_unsigned_type_node)
     557      7404285 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_unsigned_type_node))
     558       941030 :         return build_type_attribute_variant (long_unsigned_type_node,
     559       941030 :                                              attributes);
     560      6463255 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_integer_type_node)
     561      6463255 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_integer_type_node))
     562              :         {
     563        75943 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     564        75943 :                     ? long_unsigned_type_node : long_integer_type_node);
     565        38446 :           return build_type_attribute_variant (t, attributes);
     566              :         }
     567              : 
     568              :       /* For __intN types, either the type is __int128 (and is lower
     569              :          priority than the types checked above, but higher than other
     570              :          128-bit types) or it's known to not be the same size as other
     571              :          types (enforced in toplev.cc).  Prefer the unsigned type. */
     572     12849586 :       for (i = 0; i < NUM_INT_N_ENTS; i ++)
     573              :         {
     574      6424809 :           if (int_n_enabled_p [i]
     575      6424809 :               && (same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].signed_type)
     576      6335576 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].signed_type)
     577      6335572 :                   || same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].unsigned_type)
     578      6335572 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].unsigned_type)))
     579              :             {
     580           60 :               tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     581           32 :                         ? int_n_trees[i].unsigned_type
     582           32 :                         : int_n_trees[i].signed_type);
     583           32 :               return build_type_attribute_variant (t, attributes);
     584              :             }
     585              :         }
     586              : 
     587              :       /* Otherwise prefer the unsigned one.  */
     588      6424777 :       if (TYPE_UNSIGNED (t1))
     589      5188165 :         return build_type_attribute_variant (t1, attributes);
     590              :       else
     591      1236612 :         return build_type_attribute_variant (t2, attributes);
     592              :     }
     593              :   else
     594              :     {
     595            3 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_double_type_node)
     596            3 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_double_type_node))
     597            0 :         return build_type_attribute_variant (long_double_type_node,
     598            0 :                                              attributes);
     599            3 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), double_type_node)
     600            3 :           || same_type_p (TYPE_MAIN_VARIANT (t2), double_type_node))
     601            3 :         return build_type_attribute_variant (double_type_node,
     602            3 :                                              attributes);
     603            0 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), float_type_node)
     604            0 :           || same_type_p (TYPE_MAIN_VARIANT (t2), float_type_node))
     605            0 :         return build_type_attribute_variant (float_type_node,
     606            0 :                                              attributes);
     607              : 
     608              :       /* Two floating-point types whose TYPE_MAIN_VARIANTs are none of
     609              :          the standard C++ floating-point types.  Logic earlier in this
     610              :          function has already eliminated the possibility that
     611              :          TYPE_PRECISION (t2) != TYPE_PRECISION (t1), so there's no
     612              :          compelling reason to choose one or the other.  */
     613            0 :       return build_type_attribute_variant (t1, attributes);
     614              :     }
     615              : }
     616              : 
     617              : /* T1 and T2 are arithmetic or enumeration types.  Return the type
     618              :    that will result from the "usual arithmetic conversions" on T1 and
     619              :    T2 as described in [expr].  */
     620              : 
     621              : tree
     622      1232846 : type_after_usual_arithmetic_conversions (tree t1, tree t2)
     623              : {
     624      1232846 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     625              :               || VECTOR_TYPE_P (t1)
     626              :               || UNSCOPED_ENUM_P (t1));
     627      1232846 :   gcc_assert (ARITHMETIC_TYPE_P (t2)
     628              :               || VECTOR_TYPE_P (t2)
     629              :               || UNSCOPED_ENUM_P (t2));
     630              : 
     631              :   /* Perform the integral promotions.  We do not promote real types here.  */
     632      1232846 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (t1)
     633      1009006 :       && INTEGRAL_OR_ENUMERATION_TYPE_P (t2))
     634              :     {
     635      1008687 :       t1 = type_promotes_to (t1);
     636      1008687 :       t2 = type_promotes_to (t2);
     637              :     }
     638              : 
     639      1232846 :   return cp_common_type (t1, t2);
     640              : }
     641              : 
     642              : static void
     643           42 : composite_pointer_error (const op_location_t &location,
     644              :                          enum diagnostics::kind kind, tree t1, tree t2,
     645              :                          composite_pointer_operation operation)
     646              : {
     647           42 :   switch (operation)
     648              :     {
     649           33 :     case CPO_COMPARISON:
     650           33 :       emit_diagnostic (kind, location, 0,
     651              :                        "comparison between "
     652              :                        "distinct pointer types %qT and %qT lacks a cast",
     653              :                        t1, t2);
     654           33 :       break;
     655            0 :     case CPO_CONVERSION:
     656            0 :       emit_diagnostic (kind, location, 0,
     657              :                        "conversion between "
     658              :                        "distinct pointer types %qT and %qT lacks a cast",
     659              :                        t1, t2);
     660            0 :       break;
     661            9 :     case CPO_CONDITIONAL_EXPR:
     662            9 :       emit_diagnostic (kind, location, 0,
     663              :                        "conditional expression between "
     664              :                        "distinct pointer types %qT and %qT lacks a cast",
     665              :                        t1, t2);
     666            9 :       break;
     667            0 :     default:
     668            0 :       gcc_unreachable ();
     669              :     }
     670           42 : }
     671              : 
     672              : /* Subroutine of composite_pointer_type to implement the recursive
     673              :    case.  See that function for documentation of the parameters.  And ADD_CONST
     674              :    is used to track adding "const" where needed.  */
     675              : 
     676              : static tree
     677      6328590 : composite_pointer_type_r (const op_location_t &location,
     678              :                           tree t1, tree t2, bool *add_const,
     679              :                           composite_pointer_operation operation,
     680              :                           tsubst_flags_t complain)
     681              : {
     682      6328590 :   tree pointee1;
     683      6328590 :   tree pointee2;
     684      6328590 :   tree result_type;
     685      6328590 :   tree attributes;
     686              : 
     687              :   /* Determine the types pointed to by T1 and T2.  */
     688      6328590 :   if (TYPE_PTR_P (t1))
     689              :     {
     690      6327999 :       pointee1 = TREE_TYPE (t1);
     691      6327999 :       pointee2 = TREE_TYPE (t2);
     692              :     }
     693              :   else
     694              :     {
     695          591 :       pointee1 = TYPE_PTRMEM_POINTED_TO_TYPE (t1);
     696          591 :       pointee2 = TYPE_PTRMEM_POINTED_TO_TYPE (t2);
     697              :     }
     698              : 
     699              :   /* [expr.type]
     700              : 
     701              :      If T1 and T2 are similar types, the result is the cv-combined type of
     702              :      T1 and T2.  */
     703      6328590 :   if (same_type_ignoring_top_level_qualifiers_p (pointee1, pointee2))
     704              :     result_type = pointee1;
     705           33 :   else if ((TYPE_PTR_P (pointee1) && TYPE_PTR_P (pointee2))
     706          134 :            || (TYPE_PTRMEM_P (pointee1) && TYPE_PTRMEM_P (pointee2)))
     707              :     {
     708           33 :       result_type = composite_pointer_type_r (location, pointee1, pointee2,
     709              :                                               add_const, operation, complain);
     710           33 :       if (result_type == error_mark_node)
     711              :         return error_mark_node;
     712              :     }
     713              :   else
     714              :     {
     715          101 :       if (complain & tf_error)
     716           30 :         composite_pointer_error (location, diagnostics::kind::permerror,
     717              :                                  t1, t2, operation);
     718              :       else
     719           71 :         return error_mark_node;
     720           30 :       result_type = void_type_node;
     721              :     }
     722      6328513 :   const int q1 = cp_type_quals (pointee1);
     723      6328513 :   const int q2 = cp_type_quals (pointee2);
     724      6328513 :   const int quals = q1 | q2;
     725      6328513 :   result_type = cp_build_qualified_type (result_type,
     726      6328513 :                                          (quals | (*add_const
     727      6328513 :                                                    ? TYPE_QUAL_CONST
     728              :                                                    : TYPE_UNQUALIFIED)));
     729              :   /* The cv-combined type can add "const" as per [conv.qual]/3.3 (except for
     730              :      the TLQ).  The reason is that both T1 and T2 can then be converted to the
     731              :      cv-combined type of T1 and T2.  */
     732      6328513 :   if (quals != q1 || quals != q2)
     733       766867 :     *add_const = true;
     734              :   /* If the original types were pointers to members, so is the
     735              :      result.  */
     736      6328513 :   if (TYPE_PTRMEM_P (t1))
     737              :     {
     738          577 :       if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     739              :                         TYPE_PTRMEM_CLASS_TYPE (t2)))
     740              :         {
     741            0 :           if (complain & tf_error)
     742            0 :             composite_pointer_error (location, diagnostics::kind::permerror,
     743              :                                      t1, t2, operation);
     744              :           else
     745            0 :             return error_mark_node;
     746              :         }
     747          577 :       result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
     748              :                                        result_type);
     749              :     }
     750              :   else
     751      6327936 :     result_type = build_pointer_type (result_type);
     752              : 
     753              :   /* Merge the attributes.  */
     754      6328513 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     755      6328513 :   return build_type_attribute_variant (result_type, attributes);
     756              : }
     757              : 
     758              : /* Return the composite pointer type (see [expr.type]) for T1 and T2.
     759              :    ARG1 and ARG2 are the values with those types.  The OPERATION is to
     760              :    describe the operation between the pointer types,
     761              :    in case an error occurs.
     762              : 
     763              :    This routine also implements the computation of a common type for
     764              :    pointers-to-members as per [expr.eq].  */
     765              : 
     766              : tree
     767      6802364 : composite_pointer_type (const op_location_t &location,
     768              :                         tree t1, tree t2, tree arg1, tree arg2,
     769              :                         composite_pointer_operation operation,
     770              :                         tsubst_flags_t complain)
     771              : {
     772      6802364 :   tree class1;
     773      6802364 :   tree class2;
     774              : 
     775              :   /* [expr.type]
     776              : 
     777              :      If one operand is a null pointer constant, the composite pointer
     778              :      type is the type of the other operand.  */
     779      6802364 :   if (null_ptr_cst_p (arg1))
     780              :     return t2;
     781      6802180 :   if (null_ptr_cst_p (arg2))
     782              :     return t1;
     783              : 
     784              :   /* We have:
     785              : 
     786              :        [expr.type]
     787              : 
     788              :        If one of the operands has type "pointer to cv1 void", then
     789              :        the other has type "pointer to cv2 T", and the composite pointer
     790              :        type is "pointer to cv12 void", where cv12 is the union of cv1
     791              :        and cv2.
     792              : 
     793              :     If either type is a pointer to void, make sure it is T1.  */
     794      6780269 :   if (TYPE_PTR_P (t2) && VOID_TYPE_P (TREE_TYPE (t2)))
     795              :     std::swap (t1, t2);
     796              : 
     797              :   /* Now, if T1 is a pointer to void, merge the qualifiers.  */
     798      6780269 :   if (TYPE_PTR_P (t1) && VOID_TYPE_P (TREE_TYPE (t1)))
     799              :     {
     800       451607 :       tree attributes;
     801       451607 :       tree result_type;
     802              : 
     803       451607 :       if (TYPE_PTRFN_P (t2))
     804              :         {
     805           11 :           if (complain & tf_error)
     806              :             {
     807            9 :               switch (operation)
     808              :                 {
     809            9 :                 case CPO_COMPARISON:
     810            9 :                   pedwarn (location, OPT_Wpedantic,
     811              :                            "ISO C++ forbids comparison between pointer "
     812              :                            "of type %<void *%> and pointer-to-function");
     813            9 :                   break;
     814            0 :                 case CPO_CONVERSION:
     815            0 :                   pedwarn (location, OPT_Wpedantic,
     816              :                            "ISO C++ forbids conversion between pointer "
     817              :                            "of type %<void *%> and pointer-to-function");
     818            0 :                   break;
     819            0 :                 case CPO_CONDITIONAL_EXPR:
     820            0 :                   pedwarn (location, OPT_Wpedantic,
     821              :                            "ISO C++ forbids conditional expression between "
     822              :                            "pointer of type %<void *%> and "
     823              :                            "pointer-to-function");
     824            0 :                   break;
     825            0 :                 default:
     826            0 :                   gcc_unreachable ();
     827              :                 }
     828              :             }
     829              :           else
     830            2 :             return error_mark_node;
     831              :         }
     832       451605 :       result_type
     833       451605 :         = cp_build_qualified_type (void_type_node,
     834       451605 :                                    (cp_type_quals (TREE_TYPE (t1))
     835       451605 :                                     | cp_type_quals (TREE_TYPE (t2))));
     836       451605 :       result_type = build_pointer_type (result_type);
     837              :       /* Merge the attributes.  */
     838       451605 :       attributes = (*targetm.merge_type_attributes) (t1, t2);
     839       451605 :       return build_type_attribute_variant (result_type, attributes);
     840              :     }
     841              : 
     842      6328662 :   if (c_dialect_objc () && TYPE_PTR_P (t1)
     843            0 :       && TYPE_PTR_P (t2))
     844              :     {
     845            0 :       if (objc_have_common_type (t1, t2, -3, NULL_TREE))
     846            0 :         return objc_common_type (t1, t2);
     847              :     }
     848              : 
     849              :   /* if T1 or T2 is "pointer to noexcept function" and the other type is
     850              :      "pointer to function", where the function types are otherwise the same,
     851              :      "pointer to function" */
     852      6328662 :   if (fnptr_conv_p (t1, t2))
     853              :     return t1;
     854      6328627 :   if (fnptr_conv_p (t2, t1))
     855              :     return t2;
     856              : 
     857              :   /* [expr.eq] permits the application of a pointer conversion to
     858              :      bring the pointers to a common type.  */
     859      6327984 :   if (TYPE_PTR_P (t1) && TYPE_PTR_P (t2)
     860      6327984 :       && CLASS_TYPE_P (TREE_TYPE (t1))
     861       974184 :       && CLASS_TYPE_P (TREE_TYPE (t2))
     862      7302777 :       && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t1),
     863       974181 :                                                      TREE_TYPE (t2)))
     864              :     {
     865        30500 :       class1 = TREE_TYPE (t1);
     866        30500 :       class2 = TREE_TYPE (t2);
     867              : 
     868        30500 :       if (DERIVED_FROM_P (class1, class2))
     869         3184 :         t2 = (build_pointer_type
     870         1592 :               (cp_build_qualified_type (class1, cp_type_quals (class2))));
     871        28908 :       else if (DERIVED_FROM_P (class2, class1))
     872        57780 :         t1 = (build_pointer_type
     873        28890 :               (cp_build_qualified_type (class2, cp_type_quals (class1))));
     874              :       else
     875              :         {
     876           18 :           if (complain & tf_error)
     877           12 :             composite_pointer_error (location, diagnostics::kind::error,
     878              :                                      t1, t2, operation);
     879           18 :           return error_mark_node;
     880              :         }
     881              :     }
     882              :   /* [expr.eq] permits the application of a pointer-to-member
     883              :      conversion to change the class type of one of the types.  */
     884      6297647 :   else if (TYPE_PTRMEM_P (t1)
     885      6298259 :            && !same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1),
     886              :                             TYPE_PTRMEM_CLASS_TYPE (t2)))
     887              :     {
     888           79 :       class1 = TYPE_PTRMEM_CLASS_TYPE (t1);
     889           79 :       class2 = TYPE_PTRMEM_CLASS_TYPE (t2);
     890              : 
     891           79 :       if (DERIVED_FROM_P (class1, class2))
     892           43 :         t1 = build_ptrmem_type (class2, TYPE_PTRMEM_POINTED_TO_TYPE (t1));
     893           36 :       else if (DERIVED_FROM_P (class2, class1))
     894           15 :         t2 = build_ptrmem_type (class1, TYPE_PTRMEM_POINTED_TO_TYPE (t2));
     895              :       else
     896              :         {
     897           21 :           if (complain & tf_error)
     898            3 :             switch (operation)
     899              :               {
     900            3 :               case CPO_COMPARISON:
     901            3 :                 error_at (location, "comparison between distinct "
     902              :                           "pointer-to-member types %qT and %qT lacks a cast",
     903              :                           t1, t2);
     904            3 :                 break;
     905            0 :               case CPO_CONVERSION:
     906            0 :                 error_at (location, "conversion between distinct "
     907              :                           "pointer-to-member types %qT and %qT lacks a cast",
     908              :                           t1, t2);
     909            0 :                 break;
     910            0 :               case CPO_CONDITIONAL_EXPR:
     911            0 :                 error_at (location, "conditional expression between distinct "
     912              :                           "pointer-to-member types %qT and %qT lacks a cast",
     913              :                           t1, t2);
     914            0 :                 break;
     915            0 :               default:
     916            0 :                 gcc_unreachable ();
     917              :               }
     918           21 :           return error_mark_node;
     919              :         }
     920              :     }
     921              : 
     922      6328557 :   bool add_const = false;
     923      6328557 :   return composite_pointer_type_r (location, t1, t2, &add_const, operation,
     924      6328557 :                                    complain);
     925              : }
     926              : 
     927              : /* Return the merged type of two types.
     928              :    We assume that comptypes has already been done and returned 1;
     929              :    if that isn't so, this may crash.
     930              : 
     931              :    This just combines attributes and default arguments; any other
     932              :    differences would cause the two types to compare unalike.  */
     933              : 
     934              : tree
     935     31136514 : merge_types (tree t1, tree t2)
     936              : {
     937     31136514 :   enum tree_code code1;
     938     31136514 :   enum tree_code code2;
     939     31136514 :   tree attributes;
     940              : 
     941              :   /* Save time if the two types are the same.  */
     942     31136514 :   if (t1 == t2)
     943              :     return t1;
     944     17078140 :   if (original_type (t1) == original_type (t2))
     945              :     return t1;
     946              : 
     947              :   /* If one type is nonsense, use the other.  */
     948     16951584 :   if (t1 == error_mark_node)
     949              :     return t2;
     950     16951584 :   if (t2 == error_mark_node)
     951              :     return t1;
     952              : 
     953              :   /* Handle merging an auto redeclaration with a previous deduced
     954              :      return type.  */
     955     16951584 :   if (is_auto (t1))
     956              :     return t2;
     957              : 
     958              :   /* Merge the attributes.  */
     959     16936782 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     960              : 
     961     16936782 :   if (TYPE_PTRMEMFUNC_P (t1))
     962           15 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
     963     16936782 :   if (TYPE_PTRMEMFUNC_P (t2))
     964           15 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
     965              : 
     966     16936782 :   code1 = TREE_CODE (t1);
     967     16936782 :   code2 = TREE_CODE (t2);
     968     16936782 :   if (code1 != code2)
     969              :     {
     970            0 :       gcc_assert (code1 == TYPENAME_TYPE || code2 == TYPENAME_TYPE);
     971            0 :       if (code1 == TYPENAME_TYPE)
     972              :         {
     973            0 :           t1 = resolve_typename_type (t1, /*only_current_p=*/true);
     974            0 :           code1 = TREE_CODE (t1);
     975              :         }
     976              :       else
     977              :         {
     978            0 :           t2 = resolve_typename_type (t2, /*only_current_p=*/true);
     979            0 :           code2 = TREE_CODE (t2);
     980              :         }
     981              :     }
     982              : 
     983     16936782 :   switch (code1)
     984              :     {
     985      2885196 :     case POINTER_TYPE:
     986      2885196 :     case REFERENCE_TYPE:
     987              :       /* For two pointers, do this recursively on the target type.  */
     988      2885196 :       {
     989      2885196 :         tree target = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     990      2885196 :         int quals = cp_type_quals (t1);
     991              : 
     992      2885196 :         if (code1 == POINTER_TYPE)
     993              :           {
     994       777412 :             t1 = build_pointer_type (target);
     995       777412 :             if (TREE_CODE (target) == METHOD_TYPE)
     996           15 :               t1 = build_ptrmemfunc_type (t1);
     997              :           }
     998              :         else
     999      2107784 :           t1 = cp_build_reference_type (target, TYPE_REF_IS_RVALUE (t1));
    1000      2885196 :         t1 = build_type_attribute_variant (t1, attributes);
    1001      2885196 :         t1 = cp_build_qualified_type (t1, quals);
    1002              : 
    1003      2885196 :         return t1;
    1004              :       }
    1005              : 
    1006           12 :     case OFFSET_TYPE:
    1007           12 :       {
    1008           12 :         int quals;
    1009           12 :         tree pointee;
    1010           12 :         quals = cp_type_quals (t1);
    1011           12 :         pointee = merge_types (TYPE_PTRMEM_POINTED_TO_TYPE (t1),
    1012           12 :                                TYPE_PTRMEM_POINTED_TO_TYPE (t2));
    1013           12 :         t1 = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
    1014              :                                 pointee);
    1015           12 :         t1 = cp_build_qualified_type (t1, quals);
    1016           12 :         break;
    1017              :       }
    1018              : 
    1019        10722 :     case ARRAY_TYPE:
    1020        10722 :       {
    1021        10722 :         tree elt = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1022              :         /* Save space: see if the result is identical to one of the args.  */
    1023        21444 :         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
    1024        10697 :           return build_type_attribute_variant (t1, attributes);
    1025           44 :         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
    1026           19 :           return build_type_attribute_variant (t2, attributes);
    1027              :         /* Merge the element types, and have a size if either arg has one.  */
    1028            6 :         t1 = build_cplus_array_type
    1029            6 :           (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
    1030            6 :         break;
    1031              :       }
    1032              : 
    1033      4522594 :     case FUNCTION_TYPE:
    1034              :       /* Function types: prefer the one that specified arg types.
    1035              :          If both do, merge the arg types.  Also merge the return types.  */
    1036      4522594 :       {
    1037      4522594 :         tree valtype = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1038      4522594 :         tree p1 = TYPE_ARG_TYPES (t1);
    1039      4522594 :         tree p2 = TYPE_ARG_TYPES (t2);
    1040      4522594 :         tree parms;
    1041              : 
    1042              :         /* Save space: see if the result is identical to one of the args.  */
    1043      4522594 :         if (valtype == TREE_TYPE (t1) && ! p2)
    1044            0 :           return cp_build_type_attribute_variant (t1, attributes);
    1045      4522594 :         if (valtype == TREE_TYPE (t2) && ! p1)
    1046            0 :           return cp_build_type_attribute_variant (t2, attributes);
    1047              : 
    1048              :         /* Simple way if one arg fails to specify argument types.  */
    1049      9045188 :         if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
    1050              :           parms = p2;
    1051      8734540 :         else if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
    1052              :           parms = p1;
    1053              :         else
    1054      4367270 :           parms = commonparms (p1, p2);
    1055              : 
    1056      4522594 :         cp_cv_quals quals = type_memfn_quals (t1);
    1057      4522594 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1058      4522594 :         gcc_assert (quals == type_memfn_quals (t2));
    1059      4522594 :         gcc_assert (rqual == type_memfn_rqual (t2));
    1060              : 
    1061      4522594 :         tree rval = cp_build_function_type (valtype, parms);
    1062      4522594 :         rval = apply_memfn_quals (rval, quals);
    1063      4522594 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1064      4522594 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1065      4522594 :         bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1066      4522594 :         t1 = build_cp_fntype_variant (rval, rqual, raises, late_return_type_p);
    1067      4522594 :         break;
    1068              :       }
    1069              : 
    1070      4115133 :     case METHOD_TYPE:
    1071      4115133 :       {
    1072              :         /* Get this value the long way, since TYPE_METHOD_BASETYPE
    1073              :            is just the main variant of this.  */
    1074      4115133 :         tree basetype = class_of_this_parm (t2);
    1075      4115133 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1076      4115133 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1077      4115133 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1078      4115133 :         tree t3;
    1079      4115133 :         bool late_return_type_1_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1080              : 
    1081              :         /* If this was a member function type, get back to the
    1082              :            original type of type member function (i.e., without
    1083              :            the class instance variable up front.  */
    1084      4115133 :         t1 = cp_build_function_type (TREE_TYPE (t1),
    1085      4115133 :                                      TREE_CHAIN (TYPE_ARG_TYPES (t1)));
    1086      4115133 :         t2 = cp_build_function_type (TREE_TYPE (t2),
    1087      4115133 :                                      TREE_CHAIN (TYPE_ARG_TYPES (t2)));
    1088      4115133 :         t3 = merge_types (t1, t2);
    1089      4115133 :         t3 = build_method_type_directly (basetype, TREE_TYPE (t3),
    1090      4115133 :                                          TYPE_ARG_TYPES (t3));
    1091      4115133 :         t1 = build_cp_fntype_variant (t3, rqual, raises, late_return_type_1_p);
    1092      4115133 :         break;
    1093              :       }
    1094              : 
    1095              :     case TYPENAME_TYPE:
    1096              :       /* There is no need to merge attributes into a TYPENAME_TYPE.
    1097              :          When the type is instantiated it will have whatever
    1098              :          attributes result from the instantiation.  */
    1099              :       return t1;
    1100              : 
    1101      5392799 :     default:;
    1102      5392799 :       if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1103              :         return t1;
    1104           12 :       else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1105              :         return t2;
    1106              :       break;
    1107              :     }
    1108              : 
    1109      8637745 :   return cp_build_type_attribute_variant (t1, attributes);
    1110              : }
    1111              : 
    1112              : /* Return the ARRAY_TYPE type without its domain.  */
    1113              : 
    1114              : tree
    1115          391 : strip_array_domain (tree type)
    1116              : {
    1117          391 :   tree t2;
    1118          391 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1119          391 :   if (TYPE_DOMAIN (type) == NULL_TREE)
    1120              :     return type;
    1121          226 :   t2 = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
    1122          226 :   return cp_build_type_attribute_variant (t2, TYPE_ATTRIBUTES (type));
    1123              : }
    1124              : 
    1125              : /* Wrapper around cp_common_type that is used by c-common.cc and other
    1126              :    front end optimizations that remove promotions.
    1127              : 
    1128              :    Return the common type for two arithmetic types T1 and T2 under the
    1129              :    usual arithmetic conversions.  The default conversions have already
    1130              :    been applied, and enumerated types converted to their compatible
    1131              :    integer types.  */
    1132              : 
    1133              : tree
    1134       658654 : common_type (tree t1, tree t2)
    1135              : {
    1136              :   /* If one type is nonsense, use the other  */
    1137       658654 :   if (t1 == error_mark_node)
    1138              :     return t2;
    1139       658654 :   if (t2 == error_mark_node)
    1140              :     return t1;
    1141              : 
    1142       658654 :   return cp_common_type (t1, t2);
    1143              : }
    1144              : 
    1145              : /* Return the common type of two pointer types T1 and T2.  This is the
    1146              :    type for the result of most arithmetic operations if the operands
    1147              :    have the given two types.
    1148              : 
    1149              :    We assume that comp_target_types has already been done and returned
    1150              :    nonzero; if that isn't so, this may crash.  */
    1151              : 
    1152              : tree
    1153      1577256 : common_pointer_type (tree t1, tree t2)
    1154              : {
    1155      1577256 :   gcc_assert ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
    1156              :               || (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
    1157              :               || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)));
    1158              : 
    1159      1577256 :   return composite_pointer_type (input_location, t1, t2,
    1160              :                                  error_mark_node, error_mark_node,
    1161      1577256 :                                  CPO_CONVERSION, tf_warning_or_error);
    1162              : }
    1163              : 
    1164              : /* Compare two exception specifier types for exactness or subsetness, if
    1165              :    allowed. Returns false for mismatch, true for match (same, or
    1166              :    derived and !exact).
    1167              : 
    1168              :    [except.spec] "If a class X ... objects of class X or any class publicly
    1169              :    and unambiguously derived from X. Similarly, if a pointer type Y * ...
    1170              :    exceptions of type Y * or that are pointers to any type publicly and
    1171              :    unambiguously derived from Y. Otherwise a function only allows exceptions
    1172              :    that have the same type ..."
    1173              :    This does not mention cv qualifiers and is different to what throw
    1174              :    [except.throw] and catch [except.catch] will do. They will ignore the
    1175              :    top level cv qualifiers, and allow qualifiers in the pointer to class
    1176              :    example.
    1177              : 
    1178              :    We implement the letter of the standard.  */
    1179              : 
    1180              : static bool
    1181         1798 : comp_except_types (tree a, tree b, bool exact)
    1182              : {
    1183         1798 :   if (same_type_p (a, b))
    1184              :     return true;
    1185          506 :   else if (!exact)
    1186              :     {
    1187           11 :       if (cp_type_quals (a) || cp_type_quals (b))
    1188              :         return false;
    1189              : 
    1190           11 :       if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
    1191              :         {
    1192            7 :           a = TREE_TYPE (a);
    1193            7 :           b = TREE_TYPE (b);
    1194            7 :           if (cp_type_quals (a) || cp_type_quals (b))
    1195              :             return false;
    1196              :         }
    1197              : 
    1198           10 :       if (TREE_CODE (a) != RECORD_TYPE
    1199           10 :           || TREE_CODE (b) != RECORD_TYPE)
    1200              :         return false;
    1201              : 
    1202            9 :       if (publicly_uniquely_derived_p (a, b))
    1203              :         return true;
    1204              :     }
    1205              :   return false;
    1206              : }
    1207              : 
    1208              : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
    1209              :    If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
    1210              :    If EXACT is ce_type, the C++17 type compatibility rules apply.
    1211              :    If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
    1212              :    If EXACT is ce_exact, the specs must be exactly the same. Exception lists
    1213              :    are unordered, but we've already filtered out duplicates. Most lists will
    1214              :    be in order, we should try to make use of that.  */
    1215              : 
    1216              : bool
    1217   1705007437 : comp_except_specs (const_tree t1, const_tree t2, int exact)
    1218              : {
    1219   1705007437 :   const_tree probe;
    1220   1705007437 :   const_tree base;
    1221   1705007437 :   int  length = 0;
    1222              : 
    1223   1705007437 :   if (t1 == t2)
    1224              :     return true;
    1225              : 
    1226              :   /* First handle noexcept.  */
    1227    696424526 :   if (exact < ce_exact)
    1228              :     {
    1229      9792411 :       if (exact == ce_type
    1230     19540124 :           && (canonical_eh_spec (const_cast<tree> (t1))
    1231      9747713 :               == canonical_eh_spec (const_cast<tree> (t2))))
    1232              :         return true;
    1233              : 
    1234              :       /* noexcept(false) is compatible with no exception-specification,
    1235              :          and less strict than any spec.  */
    1236      9761742 :       if (t1 == noexcept_false_spec)
    1237          236 :         return t2 == NULL_TREE || exact == ce_derived;
    1238              :       /* Even a derived noexcept(false) is compatible with no
    1239              :          exception-specification.  */
    1240      9761506 :       if (t2 == noexcept_false_spec)
    1241         1363 :         return t1 == NULL_TREE;
    1242              : 
    1243              :       /* Otherwise, if we aren't looking for an exact match, noexcept is
    1244              :          equivalent to throw().  */
    1245      9760143 :       if (t1 == noexcept_true_spec)
    1246       743788 :         t1 = empty_except_spec;
    1247      9760143 :       if (t2 == noexcept_true_spec)
    1248      8819687 :         t2 = empty_except_spec;
    1249              :     }
    1250              : 
    1251              :   /* If any noexcept is left, it is only comparable to itself;
    1252              :      either we're looking for an exact match or we're redeclaring a
    1253              :      template with dependent noexcept.  */
    1254    665911488 :   if ((t1 && TREE_PURPOSE (t1))
    1255    729881649 :       || (t2 && TREE_PURPOSE (t2)))
    1256    684390016 :     return (t1 && t2
    1257    684390016 :             && (exact == ce_exact
    1258     84674036 :                 ? TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
    1259       193645 :                 : cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))));
    1260              : 
    1261     12002242 :   if (t1 == NULL_TREE)                     /* T1 is ...  */
    1262      9058697 :     return t2 == NULL_TREE || exact == ce_derived;
    1263      2943545 :   if (!TREE_VALUE (t1))                    /* t1 is EMPTY */
    1264      2909425 :     return t2 != NULL_TREE && !TREE_VALUE (t2);
    1265        35530 :   if (t2 == NULL_TREE)                     /* T2 is ...  */
    1266              :     return false;
    1267         1676 :   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
    1268           76 :     return exact == ce_derived;
    1269              : 
    1270              :   /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
    1271              :      Count how many we find, to determine exactness. For exact matching and
    1272              :      ordered T1, T2, this is an O(n) operation, otherwise its worst case is
    1273              :      O(nm).  */
    1274         2895 :   for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
    1275              :     {
    1276         2194 :       for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
    1277              :         {
    1278         1798 :           tree a = TREE_VALUE (probe);
    1279         1798 :           tree b = TREE_VALUE (t2);
    1280              : 
    1281         1798 :           if (comp_except_types (a, b, exact))
    1282              :             {
    1283         1295 :               if (probe == base && exact > ce_derived)
    1284         1260 :                 base = TREE_CHAIN (probe);
    1285         1295 :               length++;
    1286         1295 :               break;
    1287              :             }
    1288              :         }
    1289         1295 :       if (probe == NULL_TREE)
    1290              :         return false;
    1291              :     }
    1292         1204 :   return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
    1293              : }
    1294              : 
    1295              : /* Compare the array types T1 and T2.  CB says how we should behave when
    1296              :    comparing array bounds: bounds_none doesn't allow dimensionless arrays,
    1297              :    bounds_either says than any array can be [], bounds_first means that
    1298              :    onlt T1 can be an array with unknown bounds.  STRICT is true if
    1299              :    qualifiers must match when comparing the types of the array elements.  */
    1300              : 
    1301              : static bool
    1302      1989498 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
    1303              :                   bool strict)
    1304              : {
    1305      1989498 :   tree d1;
    1306      1989498 :   tree d2;
    1307      1989498 :   tree max1, max2;
    1308              : 
    1309      1989498 :   if (t1 == t2)
    1310              :     return true;
    1311              : 
    1312              :   /* The type of the array elements must be the same.  */
    1313      1988611 :   if (strict
    1314      1988611 :       ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    1315        14673 :       : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1316              :     return false;
    1317              : 
    1318      1239804 :   d1 = TYPE_DOMAIN (t1);
    1319      1239804 :   d2 = TYPE_DOMAIN (t2);
    1320              : 
    1321      1239804 :   if (d1 == d2)
    1322              :     return true;
    1323              : 
    1324              :   /* If one of the arrays is dimensionless, and the other has a
    1325              :      dimension, they are of different types.  However, it is valid to
    1326              :      write:
    1327              : 
    1328              :        extern int a[];
    1329              :        int a[3];
    1330              : 
    1331              :      by [basic.link]:
    1332              : 
    1333              :        declarations for an array object can specify
    1334              :        array types that differ by the presence or absence of a major
    1335              :        array bound (_dcl.array_).  */
    1336       684185 :   if (!d1 && d2)
    1337         7871 :     return cb >= bounds_either;
    1338       676314 :   else if (d1 && !d2)
    1339        10781 :     return cb == bounds_either;
    1340              : 
    1341              :   /* Check that the dimensions are the same.  */
    1342              : 
    1343       665533 :   if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    1344              :     return false;
    1345       665512 :   max1 = TYPE_MAX_VALUE (d1);
    1346       665512 :   max2 = TYPE_MAX_VALUE (d2);
    1347              : 
    1348       665512 :   if (!cp_tree_equal (max1, max2))
    1349              :     return false;
    1350              : 
    1351              :   return true;
    1352              : }
    1353              : 
    1354              : /* Compare the relative position of T1 and T2 into their respective
    1355              :    template parameter list.
    1356              :    T1 and T2 must be template parameter types.
    1357              :    Return TRUE if T1 and T2 have the same position, FALSE otherwise.  */
    1358              : 
    1359              : static bool
    1360   1924617029 : comp_template_parms_position (tree t1, tree t2)
    1361              : {
    1362   1924617029 :   tree index1, index2;
    1363   1924617029 :   gcc_assert (t1 && t2
    1364              :               && TREE_CODE (t1) == TREE_CODE (t2)
    1365              :               && (TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM
    1366              :                   || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM
    1367              :                   || TREE_CODE (t1) == TEMPLATE_TYPE_PARM));
    1368              : 
    1369   1924617029 :   index1 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t1));
    1370   1924617029 :   index2 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t2));
    1371              : 
    1372              :   /* Then compare their relative position.  */
    1373   1924617029 :   if (TEMPLATE_PARM_IDX (index1) != TEMPLATE_PARM_IDX (index2)
    1374   1308860156 :       || TEMPLATE_PARM_LEVEL (index1) != TEMPLATE_PARM_LEVEL (index2)
    1375   2848074651 :       || (TEMPLATE_PARM_PARAMETER_PACK (index1)
    1376    923457622 :           != TEMPLATE_PARM_PARAMETER_PACK (index2)))
    1377              :     return false;
    1378              : 
    1379              :   /* In C++14 we can end up comparing 'auto' to a normal template
    1380              :      parameter.  Don't confuse them.  */
    1381    829704059 :   if (cxx_dialect >= cxx14 && (is_auto (t1) || is_auto (t2)))
    1382    246543336 :     return TYPE_IDENTIFIER (t1) == TYPE_IDENTIFIER (t2);
    1383              : 
    1384              :   return true;
    1385              : }
    1386              : 
    1387              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    1388              : 
    1389              : static bool
    1390          512 : cxx_safe_arg_type_equiv_p (tree t1, tree t2)
    1391              : {
    1392          512 :   t1 = TYPE_MAIN_VARIANT (t1);
    1393          512 :   t2 = TYPE_MAIN_VARIANT (t2);
    1394              : 
    1395          512 :   if (TYPE_PTR_P (t1)
    1396          141 :       && TYPE_PTR_P (t2))
    1397              :     return true;
    1398              : 
    1399              :   /* Only the precision of the parameter matters.  This check should
    1400              :      make sure that the callee does not see undefined values in argument
    1401              :      registers.  */
    1402          377 :   if (INTEGRAL_TYPE_P (t1)
    1403           68 :       && INTEGRAL_TYPE_P (t2)
    1404          424 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    1405              :     return true;
    1406              : 
    1407          333 :   return same_type_p (t1, t2);
    1408              : }
    1409              : 
    1410              : /* Check if a type cast between two function types can be considered safe.  */
    1411              : 
    1412              : static bool
    1413          361 : cxx_safe_function_type_cast_p (tree t1, tree t2)
    1414              : {
    1415          361 :   if (TREE_TYPE (t1) == void_type_node &&
    1416          280 :       TYPE_ARG_TYPES (t1) == void_list_node)
    1417              :     return true;
    1418              : 
    1419          309 :   if (TREE_TYPE (t2) == void_type_node &&
    1420          103 :       TYPE_ARG_TYPES (t2) == void_list_node)
    1421              :     return true;
    1422              : 
    1423          273 :   if (!cxx_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1424              :     return false;
    1425              : 
    1426          112 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    1427          315 :        t1 && t2;
    1428          203 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1429          239 :     if (!cxx_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1430              :       return false;
    1431              : 
    1432              :   return true;
    1433              : }
    1434              : 
    1435              : /* Subroutine in comptypes.  */
    1436              : 
    1437              : static bool
    1438  17142735103 : structural_comptypes (tree t1, tree t2, int strict)
    1439              : {
    1440              :   /* Both should be types that are not obviously the same.  */
    1441  17142735103 :   gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
    1442              : 
    1443              :   /* Suppress typename resolution under spec_hasher::equal in place of calling
    1444              :      push_to_top_level there.  */
    1445  17142735103 :   if (!comparing_specializations)
    1446              :     {
    1447              :       /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
    1448              :          current instantiation.  */
    1449  13610230240 :       if (TREE_CODE (t1) == TYPENAME_TYPE)
    1450    105663347 :         t1 = resolve_typename_type (t1, /*only_current_p=*/true);
    1451              : 
    1452  13610230240 :       if (TREE_CODE (t2) == TYPENAME_TYPE)
    1453    135479294 :         t2 = resolve_typename_type (t2, /*only_current_p=*/true);
    1454              :     }
    1455              : 
    1456  17142735103 :   if (TYPE_PTRMEMFUNC_P (t1))
    1457     26361681 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    1458  17142735103 :   if (TYPE_PTRMEMFUNC_P (t2))
    1459     29637864 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
    1460              : 
    1461              :   /* Different classes of types can't be compatible.  */
    1462  17142735103 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1463              :     return false;
    1464              : 
    1465              :   /* Qualifiers must match.  For array types, we will check when we
    1466              :      recur on the array element types.  */
    1467  11298914889 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1468  11298914889 :       && cp_type_quals (t1) != cp_type_quals (t2))
    1469              :     return false;
    1470  10588308429 :   if (TREE_CODE (t1) == FUNCTION_TYPE
    1471  10588308429 :       && type_memfn_quals (t1) != type_memfn_quals (t2))
    1472              :     return false;
    1473              :   /* Need to check this before TYPE_MAIN_VARIANT.
    1474              :      FIXME function qualifiers should really change the main variant.  */
    1475  10588226864 :   if (FUNC_OR_METHOD_TYPE_P (t1))
    1476              :     {
    1477     38740668 :       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
    1478              :         return false;
    1479     23314438 :       if (flag_noexcept_type
    1480     46547903 :           && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
    1481     23233465 :                                  TYPE_RAISES_EXCEPTIONS (t2),
    1482              :                                  ce_type))
    1483              :         return false;
    1484              :     }
    1485              : 
    1486              :   /* Allow for two different type nodes which have essentially the same
    1487              :      definition.  Note that we already checked for equality of the type
    1488              :      qualifiers (just above).  */
    1489  10563236994 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1490  10563236994 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1491    524796557 :     goto check_alias;
    1492              : 
    1493              :   /* Compare the types.  Return false on known not-same. Break on not
    1494              :      known.   Never return true from this switch -- you'll break
    1495              :      specialization comparison.    */
    1496  10038440437 :   switch (TREE_CODE (t1))
    1497              :     {
    1498              :     case VOID_TYPE:
    1499              :     case BOOLEAN_TYPE:
    1500              :       /* All void and bool types are the same.  */
    1501              :       break;
    1502              : 
    1503    827647901 :     case OPAQUE_TYPE:
    1504    827647901 :     case INTEGER_TYPE:
    1505    827647901 :     case FIXED_POINT_TYPE:
    1506    827647901 :     case REAL_TYPE:
    1507              :       /* With these nodes, we can't determine type equivalence by
    1508              :          looking at what is stored in the nodes themselves, because
    1509              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1510              :          represent the same type.  For example, wchar_t and int could
    1511              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1512              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1513              :          and are distinct types. On the other hand, int and the
    1514              :          following typedef
    1515              : 
    1516              :            typedef int INT __attribute((may_alias));
    1517              : 
    1518              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1519              :          represent the same type.  The canonical type system keeps
    1520              :          track of equivalence in this case, so we fall back on it.  */
    1521    827647901 :       if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1522              :         return false;
    1523              : 
    1524              :       /* We don't need or want the attribute comparison.  */
    1525         9637 :       goto check_alias;
    1526              : 
    1527      1935238 :     case TEMPLATE_TEMPLATE_PARM:
    1528      1935238 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    1529      1935238 :       if (!comp_template_parms_position (t1, t2))
    1530              :         return false;
    1531      1412090 :       if (!comp_template_parms
    1532      2824180 :           (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
    1533      3967596 :            DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
    1534              :         return false;
    1535       971654 :       if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
    1536              :         break;
    1537              :       /* Don't check inheritance.  */
    1538              :       strict = COMPARE_STRICT;
    1539              :       /* Fall through.  */
    1540              : 
    1541   4663131217 :     case RECORD_TYPE:
    1542   4663131217 :     case UNION_TYPE:
    1543   8207477091 :       if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
    1544   2951019333 :           && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
    1545   2085389706 :               || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
    1546   5528858088 :           && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
    1547              :         break;
    1548              : 
    1549   4600464961 :       if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
    1550              :         break;
    1551   4600464927 :       else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
    1552              :         break;
    1553              : 
    1554              :       return false;
    1555              : 
    1556        60692 :     case OFFSET_TYPE:
    1557        60692 :       if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
    1558              :                       strict & ~COMPARE_REDECLARATION))
    1559              :         return false;
    1560        58593 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1561              :         return false;
    1562              :       break;
    1563              : 
    1564   1466260606 :     case REFERENCE_TYPE:
    1565   1466260606 :       if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
    1566              :         return false;
    1567              :       /* fall through to checks for pointer types */
    1568   1826574001 :       gcc_fallthrough ();
    1569              : 
    1570   1826574001 :     case POINTER_TYPE:
    1571   1826574001 :       if (TYPE_MODE (t1) != TYPE_MODE (t2)
    1572   1826574001 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1573              :         return false;
    1574              :       break;
    1575              : 
    1576      5945843 :     case FUNCTION_TYPE:
    1577      5945843 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (t1) != TYPE_NO_NAMED_ARGS_STDARG_P (t2))
    1578              :         return false;
    1579              :       /* FALLTHRU */
    1580     13436992 :     case METHOD_TYPE:
    1581              :       /* Exception specs and memfn_rquals were checked above.  */
    1582     13436992 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1583              :         return false;
    1584     12803651 :       if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
    1585              :         return false;
    1586              :       break;
    1587              : 
    1588      1973938 :     case ARRAY_TYPE:
    1589              :       /* Target types must match incl. qualifiers.  */
    1590      1973938 :       if (!comp_array_types (t1, t2, ((strict & COMPARE_REDECLARATION)
    1591      1973938 :                                       ? bounds_either : bounds_none),
    1592              :                              /*strict=*/true))
    1593              :         return false;
    1594              :       break;
    1595              : 
    1596   1922681791 :     case TEMPLATE_TYPE_PARM:
    1597              :       /* If T1 and T2 don't have the same relative position in their
    1598              :          template parameters set, they can't be equal.  */
    1599   1922681791 :       if (!comp_template_parms_position (t1, t2))
    1600              :         return false;
    1601              :       /* If T1 and T2 don't represent the same class template deduction,
    1602              :          they aren't equal.  */
    1603   1308359498 :       if (!cp_tree_equal (CLASS_PLACEHOLDER_TEMPLATE (t1),
    1604    654179749 :                           CLASS_PLACEHOLDER_TEMPLATE (t2)))
    1605              :         return false;
    1606              :       /* Constrained 'auto's are distinct from parms that don't have the same
    1607              :          constraints.  */
    1608    620534016 :       if (!equivalent_placeholder_constraints (t1, t2))
    1609              :         return false;
    1610              :       break;
    1611              : 
    1612    304270648 :     case TYPENAME_TYPE:
    1613    608541296 :       if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
    1614    304270648 :                           TYPENAME_TYPE_FULLNAME (t2)))
    1615              :         return false;
    1616              :       /* Qualifiers don't matter on scopes.  */
    1617    267053827 :       if (!same_type_ignoring_top_level_qualifiers_p (TYPE_CONTEXT (t1),
    1618    267053827 :                                                       TYPE_CONTEXT (t2)))
    1619              :         return false;
    1620              :       break;
    1621              : 
    1622        28975 :     case UNBOUND_CLASS_TEMPLATE:
    1623        28975 :       if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
    1624              :         return false;
    1625        28975 :       if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
    1626              :         return false;
    1627              :       break;
    1628              : 
    1629      2541111 :     case COMPLEX_TYPE:
    1630      2541111 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1631              :         return false;
    1632              :       break;
    1633              : 
    1634     12841462 :     case VECTOR_TYPE:
    1635     12841462 :       if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
    1636     23983323 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1637     23983323 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1638              :         return false;
    1639              :       break;
    1640              : 
    1641      7919550 :     case TYPE_PACK_EXPANSION:
    1642      7919550 :       return (same_type_p (PACK_EXPANSION_PATTERN (t1),
    1643              :                            PACK_EXPANSION_PATTERN (t2))
    1644     15661812 :               && comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    1645      7742262 :                                      PACK_EXPANSION_EXTRA_ARGS (t2)));
    1646              : 
    1647           34 :     case PACK_INDEX_TYPE:
    1648           34 :       return (cp_tree_equal (PACK_INDEX_PACK (t1),
    1649           34 :                              PACK_INDEX_PACK (t2))
    1650           40 :               && cp_tree_equal (PACK_INDEX_INDEX (t1),
    1651            6 :                                 PACK_INDEX_INDEX (t2)));
    1652              : 
    1653     32629167 :     case DECLTYPE_TYPE:
    1654     65258334 :       if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t1)
    1655     32629167 :           != DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t2))
    1656              :         return false;
    1657     32535031 :       if (DECLTYPE_FOR_LAMBDA_CAPTURE (t1) != DECLTYPE_FOR_LAMBDA_CAPTURE (t2))
    1658              :         return false;
    1659     32535031 :       if (DECLTYPE_FOR_LAMBDA_PROXY (t1) != DECLTYPE_FOR_LAMBDA_PROXY (t2))
    1660              :         return false;
    1661     32535031 :       if (!cp_tree_equal (DECLTYPE_TYPE_EXPR (t1), DECLTYPE_TYPE_EXPR (t2)))
    1662              :         return false;
    1663              :       break;
    1664              : 
    1665       768689 :     case TRAIT_TYPE:
    1666       768689 :       if (TRAIT_TYPE_KIND (t1) != TRAIT_TYPE_KIND (t2))
    1667              :         return false;
    1668         1452 :       if (!cp_tree_equal (TRAIT_TYPE_TYPE1 (t1), TRAIT_TYPE_TYPE1 (t2))
    1669         2904 :           || !cp_tree_equal (TRAIT_TYPE_TYPE2 (t1), TRAIT_TYPE_TYPE2 (t2)))
    1670              :         return false;
    1671              :       break;
    1672              : 
    1673            3 :     case TYPEOF_TYPE:
    1674            3 :       if (!cp_tree_equal (TYPEOF_TYPE_EXPR (t1), TYPEOF_TYPE_EXPR (t2)))
    1675              :         return false;
    1676              :       break;
    1677              : 
    1678              :     default:
    1679              :       return false;
    1680              :     }
    1681              : 
    1682              :   /* If we get here, we know that from a target independent POV the
    1683              :      types are the same.  Make sure the target attributes are also
    1684              :      the same.  */
    1685    868472519 :   if (!comp_type_attributes (t1, t2))
    1686              :     return false;
    1687              : 
    1688    868471332 :  check_alias:
    1689   1393277526 :   if (comparing_dependent_aliases
    1690   1393277526 :       && (typedef_variant_p (t1) || typedef_variant_p (t2)))
    1691              :     {
    1692      5260965 :       tree dep1 = dependent_opaque_alias_p (t1) ? t1 : NULL_TREE;
    1693      5260965 :       tree dep2 = dependent_opaque_alias_p (t2) ? t2 : NULL_TREE;
    1694      5260965 :       if ((dep1 || dep2)
    1695      5260965 :           && (!(dep1 && dep2)
    1696            0 :               || !comp_type_attributes (DECL_ATTRIBUTES (TYPE_NAME (dep1)),
    1697            0 :                                         DECL_ATTRIBUTES (TYPE_NAME (dep2)))))
    1698              :         return false;
    1699              : 
    1700              :       /* Don't treat an alias template specialization with dependent
    1701              :          arguments as equivalent to its underlying type when used as a
    1702              :          template argument; we need them to be distinct so that we
    1703              :          substitute into the specialization arguments at instantiation
    1704              :          time.  And aliases can't be equivalent without being ==, so
    1705              :          we don't need to look any deeper.  */
    1706      5260884 :       ++processing_template_decl;
    1707      5260884 :       dep1 = dependent_alias_template_spec_p (t1, nt_transparent);
    1708      5260884 :       dep2 = dependent_alias_template_spec_p (t2, nt_transparent);
    1709      5260884 :       --processing_template_decl;
    1710      5260884 :       if ((dep1 || dep2) && dep1 != dep2)
    1711              :         return false;
    1712              :     }
    1713              : 
    1714              :   return true;
    1715              : }
    1716              : 
    1717              : /* C++ implementation of compatible_types_for_indirection_note_p.  */
    1718              : 
    1719              : bool
    1720         1611 : compatible_types_for_indirection_note_p (tree type1, tree type2)
    1721              : {
    1722         1611 :   return same_type_p (type1, type2);
    1723              : }
    1724              : 
    1725              : /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
    1726              :    is a bitwise-or of the COMPARE_* flags.  */
    1727              : 
    1728              : bool
    1729  25874845514 : comptypes (tree t1, tree t2, int strict)
    1730              : {
    1731  25874845514 :   gcc_checking_assert (t1 && t2);
    1732              : 
    1733              :   /* TYPE_ARGUMENT_PACKS are not really types.  */
    1734  25874845514 :   gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
    1735              :                        && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
    1736              : 
    1737  25874845514 :   if (t1 == t2)
    1738              :     return true;
    1739              : 
    1740              :   /* Suppress errors caused by previously reported errors.  */
    1741  17142736268 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1742              :     return false;
    1743              : 
    1744  17142736106 :   if (strict == COMPARE_STRICT)
    1745              :     {
    1746  15447771480 :       if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
    1747              :         /* At least one of the types requires structural equality, so
    1748              :            perform a deep check. */
    1749   1796182079 :         return structural_comptypes (t1, t2, strict);
    1750              : 
    1751  13651589401 :       if (flag_checking && param_use_canonical_types)
    1752              :         {
    1753  13651588398 :           bool result = structural_comptypes (t1, t2, strict);
    1754              : 
    1755  13651588398 :           if (result && TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1756              :             /* The two types are structurally equivalent, but their
    1757              :                canonical types were different. This is a failure of the
    1758              :                canonical type propagation code.*/
    1759            0 :             internal_error
    1760            0 :               ("canonical types differ for identical types %qT and %qT",
    1761              :                t1, t2);
    1762  13651588398 :           else if (!result && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
    1763              :             /* Two types are structurally different, but the canonical
    1764              :                types are the same. This means we were over-eager in
    1765              :                assigning canonical types. */
    1766            0 :             internal_error
    1767            0 :               ("same canonical type node for different types %qT and %qT",
    1768              :                t1, t2);
    1769              : 
    1770              :           return result;
    1771              :         }
    1772         1003 :       if (!flag_checking && param_use_canonical_types)
    1773         1003 :         return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1774              :       else
    1775            0 :         return structural_comptypes (t1, t2, strict);
    1776              :     }
    1777   1694964626 :   else if (strict == COMPARE_STRUCTURAL)
    1778   1628078446 :     return structural_comptypes (t1, t2, COMPARE_STRICT);
    1779              :   else
    1780     66886180 :     return structural_comptypes (t1, t2, strict);
    1781              : }
    1782              : 
    1783              : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
    1784              :    top-level qualifiers.  */
    1785              : 
    1786              : bool
    1787   4477127576 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
    1788              : {
    1789   4477127576 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1790              :     return false;
    1791   4477126786 :   if (type1 == type2)
    1792              :     return true;
    1793              : 
    1794   2509472843 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1795   2509472843 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1796   2509472843 :   return same_type_p (type1, type2);
    1797              : }
    1798              : 
    1799              : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
    1800              : 
    1801              : bool
    1802    390018840 : similar_type_p (tree type1, tree type2)
    1803              : {
    1804    390018840 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1805              :     return false;
    1806              : 
    1807              :   /* Informally, two types are similar if, ignoring top-level cv-qualification:
    1808              :      * they are the same type; or
    1809              :      * they are both pointers, and the pointed-to types are similar; or
    1810              :      * they are both pointers to member of the same class, and the types of
    1811              :        the pointed-to members are similar; or
    1812              :      * they are both arrays of the same size or both arrays of unknown bound,
    1813              :        and the array element types are similar.  */
    1814              : 
    1815    390018840 :   if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
    1816              :     return true;
    1817              : 
    1818    160186503 :   if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    1819    159911785 :       || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    1820    159909919 :       || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
    1821       279934 :     return comp_ptr_ttypes_const (type1, type2, bounds_either);
    1822              : 
    1823              :   return false;
    1824              : }
    1825              : 
    1826              : /* Helper function for layout_compatible_type_p and
    1827              :    is_corresponding_member_aggr.  Advance to next members (NULL if
    1828              :    no further ones) and return true if those members are still part of
    1829              :    the common initial sequence.  */
    1830              : 
    1831              : bool
    1832         2210 : next_common_initial_sequence (tree &memb1, tree &memb2)
    1833              : {
    1834         2733 :   while (memb1)
    1835              :     {
    1836         2772 :       if (TREE_CODE (memb1) != FIELD_DECL
    1837         2313 :           || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
    1838              :         {
    1839          459 :           memb1 = DECL_CHAIN (memb1);
    1840          459 :           continue;
    1841              :         }
    1842         1854 :       if (DECL_FIELD_IS_BASE (memb1))
    1843              :         {
    1844           64 :           memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
    1845           64 :           continue;
    1846              :         }
    1847              :       break;
    1848              :     }
    1849         2694 :   while (memb2)
    1850              :     {
    1851         2730 :       if (TREE_CODE (memb2) != FIELD_DECL
    1852         2274 :           || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
    1853              :         {
    1854          456 :           memb2 = DECL_CHAIN (memb2);
    1855          456 :           continue;
    1856              :         }
    1857         1818 :       if (DECL_FIELD_IS_BASE (memb2))
    1858              :         {
    1859           28 :           memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
    1860           28 :           continue;
    1861              :         }
    1862              :       break;
    1863              :     }
    1864         2210 :   if (memb1 == NULL_TREE && memb2 == NULL_TREE)
    1865              :     return true;
    1866         1790 :   if (memb1 == NULL_TREE || memb2 == NULL_TREE)
    1867              :     return false;
    1868         1790 :   if (DECL_BIT_FIELD_TYPE (memb1))
    1869              :     {
    1870          165 :       if (!DECL_BIT_FIELD_TYPE (memb2))
    1871              :         return false;
    1872           66 :       if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
    1873           66 :                                      DECL_BIT_FIELD_TYPE (memb2)))
    1874              :         return false;
    1875           66 :       if (TYPE_PRECISION (TREE_TYPE (memb1))
    1876           66 :           != TYPE_PRECISION (TREE_TYPE (memb2)))
    1877              :         return false;
    1878              :     }
    1879         1625 :   else if (DECL_BIT_FIELD_TYPE (memb2))
    1880              :     return false;
    1881         1598 :   else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
    1882              :     return false;
    1883         1598 :   if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
    1884         1598 :       != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
    1885              :     return false;
    1886         1571 :   if (DECL_ALIGN (memb1) != DECL_ALIGN (memb2))
    1887              :     return false;
    1888         1512 :   if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
    1889              :     return false;
    1890              :   return true;
    1891              : }
    1892              : 
    1893              : /* Return true if TYPE1 and TYPE2 are layout-compatible types.  */
    1894              : 
    1895              : bool
    1896         2773 : layout_compatible_type_p (tree type1, tree type2, bool explain/*=false*/)
    1897              : {
    1898         2773 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1899              :     return false;
    1900         2773 :   if (type1 == type2)
    1901              :     return true;
    1902              : 
    1903         1359 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1904         1359 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1905         1359 :   if (same_type_p (type1, type2))
    1906              :     return true;
    1907              : 
    1908          654 :   if (TREE_CODE (type1) != TREE_CODE (type2)
    1909          602 :       || (TREE_CODE (type1) != ENUMERAL_TYPE
    1910          564 :           && !CLASS_TYPE_P (type1))
    1911         1107 :       || (TREE_CODE (type2) != ENUMERAL_TYPE
    1912          415 :           && !CLASS_TYPE_P (type2)))
    1913              :     {
    1914          201 :       if (explain)
    1915            6 :         inform (input_location, "%q#T and %q#T are not both the same type, "
    1916              :                 "layout-compatible enumerations, or "
    1917              :                 "layout-compatible standard-layout class types",
    1918              :                 type1, type2);
    1919              :       return false;
    1920              :     }
    1921              : 
    1922          453 :   if (!std_layout_type_p (type1))
    1923              :     {
    1924           16 :       if (explain)
    1925            3 :         inform (location_of (type1),
    1926              :                 "%qT is not a standard-layout type", type1);
    1927              :       return false;
    1928              :     }
    1929          437 :   if (!std_layout_type_p (type2))
    1930              :     {
    1931            0 :       if (explain)
    1932            0 :         inform (location_of (type2),
    1933              :                 "%qT is not a standard-layout type", type2);
    1934              :       return false;
    1935              :     }
    1936              : 
    1937          437 :   if (TREE_CODE (type1) == ENUMERAL_TYPE)
    1938              :     {
    1939           38 :       tree underlying1 = finish_underlying_type (type1);
    1940           38 :       tree underlying2 = finish_underlying_type (type2);
    1941           38 :       if (!same_type_p (underlying1, underlying2))
    1942              :         {
    1943           25 :           if (explain)
    1944              :             {
    1945            3 :               inform (location_of (type1),
    1946              :                       "the underlying type of %qT is %qT, but",
    1947              :                       type1, underlying1);
    1948            3 :               inform (location_of (type2),
    1949              :                       "the underlying type of %qT is %qT",
    1950              :                       type2, underlying2);
    1951              :             }
    1952              :           return false;
    1953              :         }
    1954              :     }
    1955          399 :   else if (TREE_CODE (type1) == RECORD_TYPE)
    1956              :     {
    1957          315 :       tree field1 = TYPE_FIELDS (type1);
    1958          315 :       tree field2 = TYPE_FIELDS (type2);
    1959         1179 :       while (1)
    1960              :         {
    1961          747 :           if (!next_common_initial_sequence (field1, field2))
    1962              :             {
    1963           27 :               if (explain)
    1964              :                 {
    1965            6 :                   if (field1 && field2)
    1966              :                     {
    1967            6 :                       inform (DECL_SOURCE_LOCATION (field1),
    1968              :                               "%qD and %qD do not correspond",
    1969              :                               field1, field2);
    1970            6 :                       inform (DECL_SOURCE_LOCATION (field2),
    1971              :                               "%qD declared here", field2);
    1972              :                     }
    1973            0 :                   else if (field1)
    1974            0 :                     inform (DECL_SOURCE_LOCATION (field1),
    1975              :                             "%qT has no member corresponding to %qD",
    1976              :                             type2, field1);
    1977            0 :                   else if (field2)
    1978            0 :                     inform (DECL_SOURCE_LOCATION (field2),
    1979              :                             "%qT has no member corresponding to %qD",
    1980              :                             type1, field2);
    1981              :                 }
    1982           27 :               return false;
    1983              :             }
    1984          720 :           if (field1 == NULL_TREE)
    1985              :             break;
    1986          432 :           field1 = DECL_CHAIN (field1);
    1987          432 :           field2 = DECL_CHAIN (field2);
    1988              :         }
    1989              :     }
    1990           84 :   else if (TREE_CODE (type1) == UNION_TYPE)
    1991              :     {
    1992              :       /* The standard says:
    1993              :          "Two standard-layout unions are layout-compatible if they have
    1994              :          the same number of non-static data members and corresponding
    1995              :          non-static data members (in any order) have layout-compatible
    1996              :          types."
    1997              :          but the code anticipates that bitfield vs. non-bitfield,
    1998              :          different bitfield widths or presence/absence of
    1999              :          [[no_unique_address]] should be checked as well.  */
    2000           84 :       tree field1 = TYPE_FIELDS (type1);
    2001           84 :       tree field2 = TYPE_FIELDS (type2);
    2002           84 :       auto_vec<tree, 16> vec;
    2003           84 :       unsigned int count = 0;
    2004          378 :       for (; field1; field1 = DECL_CHAIN (field1))
    2005          294 :         if (TREE_CODE (field1) == FIELD_DECL)
    2006          195 :           count++;
    2007          372 :       for (; field2; field2 = DECL_CHAIN (field2))
    2008          288 :         if (TREE_CODE (field2) == FIELD_DECL)
    2009          189 :           vec.safe_push (field2);
    2010              : 
    2011              :       /* Discussions on core lean towards treating multiple union fields
    2012              :          of the same type as the same field, so this might need changing
    2013              :          in the future.  */
    2014          168 :       if (count != vec.length ())
    2015              :         {
    2016            6 :           if (explain)
    2017              :             {
    2018            3 :               inform_n (location_of (type1), count,
    2019              :                         "%qT has %u field, but",
    2020              :                         "%qT has %u fields, but",
    2021              :                         type1, count);
    2022            6 :               inform_n (location_of (type2), vec.length (),
    2023              :                         "%qT has %u field",
    2024              :                         "%qT has %u fields",
    2025              :                         type2, vec.length ());
    2026              :             }
    2027              :           return false;
    2028              :         }
    2029              : 
    2030          324 :       for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
    2031              :         {
    2032          258 :           if (TREE_CODE (field1) != FIELD_DECL)
    2033           81 :             continue;
    2034          177 :           unsigned int j;
    2035          177 :           tree t1 = DECL_BIT_FIELD_TYPE (field1);
    2036          177 :           if (t1 == NULL_TREE)
    2037          174 :             t1 = TREE_TYPE (field1);
    2038          474 :           FOR_EACH_VEC_ELT (vec, j, field2)
    2039              :             {
    2040          285 :               tree t2 = DECL_BIT_FIELD_TYPE (field2);
    2041          285 :               if (t2 == NULL_TREE)
    2042          273 :                 t2 = TREE_TYPE (field2);
    2043          285 :               if (DECL_BIT_FIELD_TYPE (field1))
    2044              :                 {
    2045            6 :                   if (!DECL_BIT_FIELD_TYPE (field2))
    2046            0 :                     continue;
    2047            6 :                   if (TYPE_PRECISION (TREE_TYPE (field1))
    2048            6 :                       != TYPE_PRECISION (TREE_TYPE (field2)))
    2049            6 :                     continue;
    2050              :                 }
    2051          279 :               else if (DECL_BIT_FIELD_TYPE (field2))
    2052            6 :                 continue;
    2053          273 :               if (!layout_compatible_type_p (t1, t2))
    2054          108 :                 continue;
    2055          165 :               if ((!lookup_attribute ("no_unique_address",
    2056          165 :                                       DECL_ATTRIBUTES (field1)))
    2057          165 :                   != !lookup_attribute ("no_unique_address",
    2058          165 :                                         DECL_ATTRIBUTES (field2)))
    2059            0 :                 continue;
    2060              :               break;
    2061              :             }
    2062          354 :           if (j == vec.length ())
    2063              :             {
    2064           12 :               if (explain)
    2065              :                 {
    2066            3 :                   inform (DECL_SOURCE_LOCATION (field1),
    2067              :                           "%qT has no member corresponding to %qD",
    2068              :                           type2, field1);
    2069            3 :                   inform (location_of (type2), "%qT declared here", type2);
    2070              :                 }
    2071              :               return false;
    2072              :             }
    2073          165 :           vec.unordered_remove (j);
    2074              :         }
    2075           84 :     }
    2076              :   else
    2077            0 :     gcc_unreachable ();
    2078              : 
    2079              :   return true;
    2080              : }
    2081              : 
    2082              : /* Returns 1 if TYPE1 is at least as qualified as TYPE2.  */
    2083              : 
    2084              : bool
    2085    254173701 : at_least_as_qualified_p (const_tree type1, const_tree type2)
    2086              : {
    2087    254173701 :   int q1 = cp_type_quals (type1);
    2088    254173701 :   int q2 = cp_type_quals (type2);
    2089              : 
    2090              :   /* All qualifiers for TYPE2 must also appear in TYPE1.  */
    2091    254173701 :   return (q1 & q2) == q2;
    2092              : }
    2093              : 
    2094              : /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
    2095              :    more cv-qualified that TYPE1, and 0 otherwise.  */
    2096              : 
    2097              : int
    2098     15266733 : comp_cv_qualification (int q1, int q2)
    2099              : {
    2100     15266733 :   if (q1 == q2)
    2101              :     return 0;
    2102              : 
    2103      3455860 :   if ((q1 & q2) == q2)
    2104              :     return 1;
    2105       367618 :   else if ((q1 & q2) == q1)
    2106       367033 :     return -1;
    2107              : 
    2108              :   return 0;
    2109              : }
    2110              : 
    2111              : int
    2112            0 : comp_cv_qualification (const_tree type1, const_tree type2)
    2113              : {
    2114            0 :   int q1 = cp_type_quals (type1);
    2115            0 :   int q2 = cp_type_quals (type2);
    2116            0 :   return comp_cv_qualification (q1, q2);
    2117              : }
    2118              : 
    2119              : /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
    2120              :    subset of the cv-qualification signature of TYPE2, and the types
    2121              :    are similar.  Returns -1 if the other way 'round, and 0 otherwise.  */
    2122              : 
    2123              : int
    2124          355 : comp_cv_qual_signature (tree type1, tree type2)
    2125              : {
    2126          355 :   if (comp_ptr_ttypes_real (type2, type1, -1))
    2127              :     return 1;
    2128          281 :   else if (comp_ptr_ttypes_real (type1, type2, -1))
    2129              :     return -1;
    2130              :   else
    2131          269 :     return 0;
    2132              : }
    2133              : 
    2134              : /* Subroutines of `comptypes'.  */
    2135              : 
    2136              : /* Return true if two parameter type lists PARMS1 and PARMS2 are
    2137              :    equivalent in the sense that functions with those parameter types
    2138              :    can have equivalent types.  The two lists must be equivalent,
    2139              :    element by element.  */
    2140              : 
    2141              : bool
    2142   1119250736 : compparms (const_tree parms1, const_tree parms2)
    2143              : {
    2144   1119250736 :   const_tree t1, t2;
    2145              : 
    2146              :   /* An unspecified parmlist matches any specified parmlist
    2147              :      whose argument types don't need default promotions.  */
    2148              : 
    2149   1119250736 :   for (t1 = parms1, t2 = parms2;
    2150   1782396337 :        t1 || t2;
    2151    663145601 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2152              :     {
    2153              :       /* If one parmlist is shorter than the other,
    2154              :          they fail to match.  */
    2155   1668463845 :       if (!t1 || !t2)
    2156              :         return false;
    2157   1667865862 :       if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2158              :         return false;
    2159              :     }
    2160              :   return true;
    2161              : }
    2162              : 
    2163              : 
    2164              : /* Process a sizeof or alignof expression where the operand is a type.
    2165              :    STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
    2166              :    or GNU (preferred alignment) semantics; it is ignored if OP is
    2167              :    SIZEOF_EXPR.  */
    2168              : 
    2169              : tree
    2170     29551736 : cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op,
    2171              :                             bool std_alignof, bool complain)
    2172              : {
    2173     29551736 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2174     29551736 :   if (type == error_mark_node)
    2175              :     return error_mark_node;
    2176              : 
    2177     29551734 :   type = non_reference (type);
    2178     29551734 :   if (TREE_CODE (type) == METHOD_TYPE)
    2179              :     {
    2180            0 :       if (complain)
    2181              :         {
    2182            0 :           pedwarn (loc, OPT_Wpointer_arith,
    2183              :                    "invalid application of %qs to a member function",
    2184            0 :                    OVL_OP_INFO (false, op)->name);
    2185            0 :           return size_one_node;
    2186              :         }
    2187              :       else
    2188            0 :         return error_mark_node;
    2189              :     }
    2190     29551734 :   else if (VOID_TYPE_P (type) && std_alignof)
    2191              :     {
    2192           12 :       if (complain)
    2193           12 :         error_at (loc, "invalid application of %qs to a void type",
    2194           12 :                   OVL_OP_INFO (false, op)->name);
    2195           12 :       return error_mark_node;
    2196              :     }
    2197              : 
    2198     29551722 :   bool dependent_p = dependent_type_p (type);
    2199     29551722 :   if (!dependent_p)
    2200              :     {
    2201     24441871 :       complete_type (type);
    2202     24441871 :       if (!COMPLETE_TYPE_P (type))
    2203              :         /* Call this here because the incompleteness diagnostic comes from
    2204              :            c_sizeof_or_alignof_type instead of
    2205              :            complete_type_or_maybe_complain.  */
    2206          285 :         note_failed_type_completion (type, complain);
    2207              :     }
    2208     24441871 :   if (dependent_p
    2209              :       /* VLA types will have a non-constant size.  In the body of an
    2210              :          uninstantiated template, we don't need to try to compute the
    2211              :          value, because the sizeof expression is not an integral
    2212              :          constant expression in that case.  And, if we do try to
    2213              :          compute the value, we'll likely end up with SAVE_EXPRs, which
    2214              :          the template substitution machinery does not expect to see.  */
    2215     24441871 :       || (processing_template_decl
    2216      2174201 :           && COMPLETE_TYPE_P (type)
    2217      2174195 :           && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
    2218              :     {
    2219      5109851 :       tree value = build_min (op, size_type_node, type);
    2220      5109851 :       TREE_READONLY (value) = 1;
    2221      5109851 :       if (op == ALIGNOF_EXPR && std_alignof)
    2222       589992 :         ALIGNOF_EXPR_STD_P (value) = true;
    2223      5109851 :       SET_EXPR_LOCATION (value, loc);
    2224      5109851 :       return value;
    2225              :     }
    2226              : 
    2227     24441871 :   return c_sizeof_or_alignof_type (loc, complete_type (type),
    2228              :                                    op == SIZEOF_EXPR, std_alignof,
    2229     24441871 :                                    complain & (tf_warning_or_error));
    2230              : }
    2231              : 
    2232              : /* Return the size of the type, without producing any warnings for
    2233              :    types whose size cannot be taken.  This routine should be used only
    2234              :    in some other routine that has already produced a diagnostic about
    2235              :    using the size of such a type.  */
    2236              : tree
    2237      2901420 : cxx_sizeof_nowarn (tree type)
    2238              : {
    2239      2901420 :   if (TREE_CODE (type) == FUNCTION_TYPE
    2240      2901420 :       || VOID_TYPE_P (type)
    2241      2901338 :       || TREE_CODE (type) == ERROR_MARK)
    2242           82 :     return size_one_node;
    2243      2901338 :   else if (!COMPLETE_TYPE_P (type))
    2244           25 :     return size_zero_node;
    2245              :   else
    2246      2901313 :     return cxx_sizeof_or_alignof_type (input_location, type,
    2247      2901313 :                                        SIZEOF_EXPR, false, false);
    2248              : }
    2249              : 
    2250              : /* Process a sizeof expression where the operand is an expression.  */
    2251              : 
    2252              : static tree
    2253      1341075 : cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
    2254              : {
    2255      1341075 :   if (e == error_mark_node)
    2256              :     return error_mark_node;
    2257              : 
    2258      1340340 :   if (instantiation_dependent_uneval_expression_p (e))
    2259              :     {
    2260       371377 :       e = build_min (SIZEOF_EXPR, size_type_node, e);
    2261       371377 :       TREE_SIDE_EFFECTS (e) = 0;
    2262       371377 :       TREE_READONLY (e) = 1;
    2263       371377 :       SET_EXPR_LOCATION (e, loc);
    2264              : 
    2265       371377 :       return e;
    2266              :     }
    2267              : 
    2268       968963 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2269       968963 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2270              : 
    2271       968963 :   if (TREE_CODE (e) == PARM_DECL
    2272        35958 :       && DECL_ARRAY_PARAMETER_P (e)
    2273       969340 :       && (complain & tf_warning))
    2274              :     {
    2275          120 :       auto_diagnostic_group d;
    2276          120 :       if (warning_at (e_loc, OPT_Wsizeof_array_argument,
    2277              :                       "%<sizeof%> on array function parameter %qE "
    2278          120 :                       "will return size of %qT", e, TREE_TYPE (e)))
    2279           24 :         inform (DECL_SOURCE_LOCATION (e), "declared here");
    2280          120 :     }
    2281              : 
    2282       968963 :   e = mark_type_use (e);
    2283              : 
    2284       968963 :   if (bitfield_p (e))
    2285              :     {
    2286           12 :       if (complain & tf_error)
    2287            6 :         error_at (e_loc,
    2288              :                   "invalid application of %<sizeof%> to a bit-field");
    2289              :       else
    2290            6 :         return error_mark_node;
    2291            6 :       e = char_type_node;
    2292              :     }
    2293       968951 :   else if (is_overloaded_fn (e))
    2294              :     {
    2295           33 :       if (complain & tf_error)
    2296           12 :         permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to "
    2297              :                    "an expression of function type");
    2298              :       else
    2299           21 :         return error_mark_node;
    2300           12 :       e = char_type_node;
    2301              :     }
    2302       968918 :   else if (type_unknown_p (e))
    2303              :     {
    2304            0 :       if (complain & tf_error)
    2305            0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2306              :       else
    2307            0 :         return error_mark_node;
    2308            0 :       e = char_type_node;
    2309              :     }
    2310              :   else
    2311       968918 :     e = TREE_TYPE (e);
    2312              : 
    2313       968936 :   return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false,
    2314       968936 :                                      complain & tf_error);
    2315              : }
    2316              : 
    2317              : /* Implement the __alignof keyword: Return the minimum required
    2318              :    alignment of E, measured in bytes.  For VAR_DECL's and
    2319              :    FIELD_DECL's return DECL_ALIGN (which can be set from an
    2320              :    "aligned" __attribute__ specification).  STD_ALIGNOF acts
    2321              :    like in cxx_sizeof_or_alignof_type.  */
    2322              : 
    2323              : static tree
    2324       101019 : cxx_alignof_expr (location_t loc, tree e, bool std_alignof,
    2325              :                   tsubst_flags_t complain)
    2326              : {
    2327       101019 :   tree t;
    2328              : 
    2329       101019 :   if (e == error_mark_node)
    2330              :     return error_mark_node;
    2331              : 
    2332       101011 :   if (processing_template_decl)
    2333              :     {
    2334        19304 :       e = build_min (ALIGNOF_EXPR, size_type_node, e);
    2335        19304 :       TREE_SIDE_EFFECTS (e) = 0;
    2336        19304 :       TREE_READONLY (e) = 1;
    2337        19304 :       SET_EXPR_LOCATION (e, loc);
    2338        19304 :       ALIGNOF_EXPR_STD_P (e) = std_alignof;
    2339              : 
    2340        19304 :       return e;
    2341              :     }
    2342              : 
    2343        81707 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2344        81707 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2345              : 
    2346        81707 :   e = mark_type_use (e);
    2347              : 
    2348        81707 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e),
    2349        81707 :                             !(complain & tf_error)))
    2350              :     {
    2351            0 :       if (!(complain & tf_error))
    2352            0 :         return error_mark_node;
    2353            0 :       t = size_one_node;
    2354              :     }
    2355        81707 :   else if (VAR_P (e))
    2356        12270 :     t = size_int (DECL_ALIGN_UNIT (e));
    2357        69437 :   else if (bitfield_p (e))
    2358              :     {
    2359            6 :       if (complain & tf_error)
    2360            6 :         error_at (e_loc,
    2361              :                   "invalid application of %<__alignof%> to a bit-field");
    2362              :       else
    2363            0 :         return error_mark_node;
    2364            6 :       t = size_one_node;
    2365              :     }
    2366        69431 :   else if (TREE_CODE (e) == COMPONENT_REF
    2367        69431 :            && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL)
    2368        37792 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (e, 1)));
    2369        31639 :   else if (is_overloaded_fn (e))
    2370              :     {
    2371            6 :       if (complain & tf_error)
    2372            6 :         permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to "
    2373              :                    "an expression of function type");
    2374              :       else
    2375            0 :         return error_mark_node;
    2376            6 :       if (TREE_CODE (e) == FUNCTION_DECL)
    2377            3 :         t = size_int (DECL_ALIGN_UNIT (e));
    2378              :       else
    2379            3 :         t = size_one_node;
    2380              :     }
    2381        31633 :   else if (type_unknown_p (e))
    2382              :     {
    2383            0 :       if (complain & tf_error)
    2384            0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2385              :       else
    2386            0 :         return error_mark_node;
    2387            0 :       t = size_one_node;
    2388              :     }
    2389              :   else
    2390        31633 :     return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
    2391              :                                        ALIGNOF_EXPR, std_alignof,
    2392        31633 :                                        complain & tf_error);
    2393              : 
    2394        50074 :   return fold_convert_loc (loc, size_type_node, t);
    2395              : }
    2396              : 
    2397              : /* Process a sizeof or alignof expression E with code OP where the operand
    2398              :    is an expression. STD_ALIGNOF acts like in cxx_sizeof_or_alignof_type.  */
    2399              : 
    2400              : tree
    2401      1442094 : cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
    2402              :                             bool std_alignof, bool complain)
    2403              : {
    2404      1442094 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2405      1442094 :   if (op == SIZEOF_EXPR)
    2406      1961232 :     return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
    2407              :   else
    2408       101046 :     return cxx_alignof_expr (loc, e, std_alignof,
    2409       101019 :                              complain? tf_warning_or_error : tf_none);
    2410              : }
    2411              : 
    2412              : /*  Build a representation of an expression 'alignas(E).'  Return the
    2413              :     folded integer value of E if it is an integral constant expression
    2414              :     that resolves to a valid alignment.  If E depends on a template
    2415              :     parameter, return a syntactic representation tree of kind
    2416              :     ALIGNOF_EXPR.  Otherwise, return an error_mark_node if the
    2417              :     expression is ill formed, or NULL_TREE if E is NULL_TREE.  */
    2418              : 
    2419              : tree
    2420       279598 : cxx_alignas_expr (tree e)
    2421              : {
    2422       279598 :   if (e == NULL_TREE || e == error_mark_node
    2423       559196 :       || (!TYPE_P (e) && !require_potential_rvalue_constant_expression (e)))
    2424              :     return e;
    2425              : 
    2426       279598 :   if (TYPE_P (e))
    2427              :     /* [dcl.align]/3:
    2428              : 
    2429              :            When the alignment-specifier is of the form
    2430              :            alignas(type-id), it shall have the same effect as
    2431              :            alignas(alignof(type-id)).  */
    2432              : 
    2433       146750 :     return cxx_sizeof_or_alignof_type (input_location,
    2434              :                                        e, ALIGNOF_EXPR,
    2435              :                                        /*std_alignof=*/true,
    2436       146750 :                                        /*complain=*/true);
    2437              : 
    2438              :   /* If we reach this point, it means the alignas expression if of
    2439              :      the form "alignas(assignment-expression)", so we should follow
    2440              :      what is stated by [dcl.align]/2.  */
    2441              : 
    2442       132848 :   if (value_dependent_expression_p (e))
    2443              :     /* Leave value-dependent expression alone for now. */
    2444              :     return e;
    2445              : 
    2446        68303 :   e = instantiate_non_dependent_expr (e);
    2447        68303 :   e = mark_rvalue_use (e);
    2448              : 
    2449              :   /* [dcl.align]/2 says:
    2450              : 
    2451              :          the assignment-expression shall be an integral constant
    2452              :          expression.  */
    2453              : 
    2454        68303 :   if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (e)))
    2455              :     {
    2456           18 :       error ("%<alignas%> argument has non-integral type %qT", TREE_TYPE (e));
    2457           18 :       return error_mark_node;
    2458              :     }
    2459              : 
    2460        68285 :   return cxx_constant_value (e);
    2461              : }
    2462              : 
    2463              : 
    2464              : /* EXPR is being used in a context that is not a function call.
    2465              :    Enforce:
    2466              : 
    2467              :      [expr.ref]
    2468              : 
    2469              :      The expression can be used only as the left-hand operand of a
    2470              :      member function call.
    2471              : 
    2472              :      [expr.mptr.operator]
    2473              : 
    2474              :      If the result of .* or ->* is a function, then that result can be
    2475              :      used only as the operand for the function call operator ().
    2476              : 
    2477              :    by issuing an error message if appropriate.  Returns true iff EXPR
    2478              :    violates these rules.  */
    2479              : 
    2480              : bool
    2481   1556311759 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
    2482              : {
    2483   1556311759 :   if (expr == NULL_TREE)
    2484              :     return false;
    2485              :   /* Don't enforce this in MS mode.  */
    2486   1556310317 :   if (flag_ms_extensions)
    2487              :     return false;
    2488   1556302256 :   if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
    2489    129671580 :     expr = get_first_fn (expr);
    2490   1556302256 :   if (TREE_TYPE (expr)
    2491   1556302256 :       && DECL_IOBJ_MEMBER_FUNCTION_P (expr))
    2492              :     {
    2493           96 :       if (complain & tf_error)
    2494              :         {
    2495           88 :           if (DECL_P (expr))
    2496              :             {
    2497           70 :               auto_diagnostic_group d;
    2498           70 :               error_at (loc, "invalid use of non-static member function %qD",
    2499              :                         expr);
    2500           70 :               inform (DECL_SOURCE_LOCATION (expr), "declared here");
    2501           70 :             }
    2502              :           else
    2503           18 :             error_at (loc, "invalid use of non-static member function of "
    2504           18 :                       "type %qT", TREE_TYPE (expr));
    2505              :         }
    2506              :       return true;
    2507              :     }
    2508              :   return false;
    2509              : }
    2510              : 
    2511              : /* If EXP is a reference to a bit-field, and the type of EXP does not
    2512              :    match the declared type of the bit-field, return the declared type
    2513              :    of the bit-field.  Otherwise, return NULL_TREE.  */
    2514              : 
    2515              : tree
    2516   3692461744 : is_bitfield_expr_with_lowered_type (const_tree exp)
    2517              : {
    2518   5041087893 :   switch (TREE_CODE (exp))
    2519              :     {
    2520      8812124 :     case COND_EXPR:
    2521     17624248 :       if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
    2522      8812098 :                                                ? TREE_OPERAND (exp, 1)
    2523           26 :                                                : TREE_OPERAND (exp, 0)))
    2524              :         return NULL_TREE;
    2525          141 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
    2526              : 
    2527       973301 :     case COMPOUND_EXPR:
    2528       973301 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
    2529              : 
    2530    431137729 :     case MODIFY_EXPR:
    2531    431137729 :     case SAVE_EXPR:
    2532    431137729 :     case UNARY_PLUS_EXPR:
    2533    431137729 :     case PREDECREMENT_EXPR:
    2534    431137729 :     case PREINCREMENT_EXPR:
    2535    431137729 :     case POSTDECREMENT_EXPR:
    2536    431137729 :     case POSTINCREMENT_EXPR:
    2537    431137729 :     case NEGATE_EXPR:
    2538    431137729 :     case NON_LVALUE_EXPR:
    2539    431137729 :     case BIT_NOT_EXPR:
    2540    431137729 :     case CLEANUP_POINT_EXPR:
    2541    431137729 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2542              : 
    2543    265402379 :     case COMPONENT_REF:
    2544    265402379 :       {
    2545    265402379 :         tree field;
    2546              : 
    2547    265402379 :         field = TREE_OPERAND (exp, 1);
    2548    265402379 :         if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
    2549              :           return NULL_TREE;
    2550     22389688 :         if (same_type_ignoring_top_level_qualifiers_p
    2551     22389688 :             (TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
    2552              :           return NULL_TREE;
    2553     22221752 :         return DECL_BIT_FIELD_TYPE (field);
    2554              :       }
    2555              : 
    2556    692918986 :     case VAR_DECL:
    2557    692918986 :       if (DECL_HAS_VALUE_EXPR_P (exp))
    2558      1379910 :         return is_bitfield_expr_with_lowered_type (DECL_VALUE_EXPR
    2559      1379910 :                                                    (const_cast<tree> (exp)));
    2560              :       return NULL_TREE;
    2561              : 
    2562    922362518 :     case VIEW_CONVERT_EXPR:
    2563    922362518 :       if (location_wrapper_p (exp))
    2564    915135068 :         return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2565              :       else
    2566              :         return NULL_TREE;
    2567              : 
    2568              :     default:
    2569              :       return NULL_TREE;
    2570              :     }
    2571              : }
    2572              : 
    2573              : /* Like is_bitfield_with_lowered_type, except that if EXP is not a
    2574              :    bitfield with a lowered type, the type of EXP is returned, rather
    2575              :    than NULL_TREE.  */
    2576              : 
    2577              : tree
    2578   1751633388 : unlowered_expr_type (const_tree exp)
    2579              : {
    2580   1751633388 :   tree type;
    2581   1751633388 :   tree etype = TREE_TYPE (exp);
    2582              : 
    2583   1751633388 :   type = is_bitfield_expr_with_lowered_type (exp);
    2584   1751633388 :   if (type)
    2585     17825041 :     type = cp_build_qualified_type (type, cp_type_quals (etype));
    2586              :   else
    2587              :     type = etype;
    2588              : 
    2589   1751633388 :   return type;
    2590              : }
    2591              : 
    2592              : /* Perform the conversions in [expr] that apply when an lvalue appears
    2593              :    in an rvalue context: the lvalue-to-rvalue, array-to-pointer, and
    2594              :    function-to-pointer conversions.  In addition, bitfield references are
    2595              :    converted to their declared types. Note that this function does not perform
    2596              :    the lvalue-to-rvalue conversion for class types. If you need that conversion
    2597              :    for class types, then you probably need to use force_rvalue.
    2598              : 
    2599              :    Although the returned value is being used as an rvalue, this
    2600              :    function does not wrap the returned expression in a
    2601              :    NON_LVALUE_EXPR; the caller is expected to be mindful of the fact
    2602              :    that the return value is no longer an lvalue.  */
    2603              : 
    2604              : tree
    2605   1232341471 : decay_conversion (tree exp,
    2606              :                   tsubst_flags_t complain,
    2607              :                   bool reject_builtin /* = true */)
    2608              : {
    2609   1232341471 :   tree type;
    2610   1232341471 :   enum tree_code code;
    2611   1232341471 :   location_t loc = cp_expr_loc_or_input_loc (exp);
    2612              : 
    2613   1232341471 :   type = TREE_TYPE (exp);
    2614   1232341471 :   if (type == error_mark_node)
    2615              :     return error_mark_node;
    2616              : 
    2617   1232341257 :   exp = resolve_nondeduced_context_or_error (exp, complain);
    2618              : 
    2619   1232341257 :   code = TREE_CODE (type);
    2620              : 
    2621   1232341257 :   if (error_operand_p (exp))
    2622           90 :     return error_mark_node;
    2623              : 
    2624   1232341167 :   if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp))
    2625              :     {
    2626      1801968 :       mark_rvalue_use (exp, loc, reject_builtin);
    2627      1801968 :       return nullptr_node;
    2628              :     }
    2629              : 
    2630              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    2631              :      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
    2632   1230539199 :   if (code == VOID_TYPE)
    2633              :     {
    2634         5798 :       if (complain & tf_error)
    2635            3 :         error_at (loc, "void value not ignored as it ought to be");
    2636         5798 :       return error_mark_node;
    2637              :     }
    2638   1230533401 :   if (invalid_nonstatic_memfn_p (loc, exp, complain))
    2639            6 :     return error_mark_node;
    2640   1230533395 :   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
    2641              :     {
    2642    135327230 :       exp = mark_lvalue_use (exp);
    2643    135327230 :       if (reject_builtin && reject_gcc_builtin (exp, loc))
    2644          109 :         return error_mark_node;
    2645    135327121 :       return cp_build_addr_expr (exp, complain);
    2646              :     }
    2647   1095206165 :   if (code == ARRAY_TYPE)
    2648              :     {
    2649      6857687 :       tree adr;
    2650      6857687 :       tree ptrtype;
    2651              : 
    2652      6857687 :       exp = mark_lvalue_use (exp);
    2653              : 
    2654      6857687 :       if (INDIRECT_REF_P (exp))
    2655       170058 :         return build_nop (build_pointer_type (TREE_TYPE (type)),
    2656       340116 :                           TREE_OPERAND (exp, 0));
    2657              : 
    2658      6687629 :       if (TREE_CODE (exp) == COMPOUND_EXPR)
    2659              :         {
    2660            3 :           tree op1 = decay_conversion (TREE_OPERAND (exp, 1), complain);
    2661            3 :           if (op1 == error_mark_node)
    2662              :             return error_mark_node;
    2663            3 :           return build2 (COMPOUND_EXPR, TREE_TYPE (op1),
    2664            6 :                          TREE_OPERAND (exp, 0), op1);
    2665              :         }
    2666              : 
    2667      6687626 :       if (!obvalue_p (exp)
    2668      6687626 :           && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
    2669              :         {
    2670            0 :           if (complain & tf_error)
    2671            0 :             error_at (loc, "invalid use of non-lvalue array");
    2672            0 :           return error_mark_node;
    2673              :         }
    2674              : 
    2675      6687626 :       ptrtype = build_pointer_type (TREE_TYPE (type));
    2676              : 
    2677      6687626 :       if (VAR_P (exp))
    2678              :         {
    2679       581660 :           if (!cxx_mark_addressable (exp))
    2680            0 :             return error_mark_node;
    2681       581660 :           adr = build_nop (ptrtype, build_address (exp));
    2682       581660 :           return adr;
    2683              :         }
    2684              :       /* This way is better for a COMPONENT_REF since it can
    2685              :          simplify the offset for a component.  */
    2686      6105966 :       adr = cp_build_addr_expr (exp, complain);
    2687      6105966 :       return cp_convert (ptrtype, adr, complain);
    2688              :     }
    2689              : 
    2690              :   /* Otherwise, it's the lvalue-to-rvalue conversion.  */
    2691   1088348478 :   exp = mark_rvalue_use (exp, loc, reject_builtin);
    2692              : 
    2693              :   /* If a bitfield is used in a context where integral promotion
    2694              :      applies, then the caller is expected to have used
    2695              :      default_conversion.  That function promotes bitfields correctly
    2696              :      before calling this function.  At this point, if we have a
    2697              :      bitfield referenced, we may assume that is not subject to
    2698              :      promotion, and that, therefore, the type of the resulting rvalue
    2699              :      is the declared type of the bitfield.  */
    2700   1088348478 :   exp = convert_bitfield_to_declared_type (exp);
    2701              : 
    2702              :   /* We do not call rvalue() here because we do not want to wrap EXP
    2703              :      in a NON_LVALUE_EXPR.  */
    2704              : 
    2705              :   /* [basic.lval]
    2706              : 
    2707              :      Non-class rvalues always have cv-unqualified types.  */
    2708   1088348478 :   type = TREE_TYPE (exp);
    2709   1088348478 :   if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    2710    335119034 :     exp = build_nop (cv_unqualified (type), exp);
    2711              : 
    2712   1088348478 :   if (!complete_type_or_maybe_complain (type, exp, complain))
    2713           42 :     return error_mark_node;
    2714              : 
    2715              :   return exp;
    2716              : }
    2717              : 
    2718              : /* Perform preparatory conversions, as part of the "usual arithmetic
    2719              :    conversions".  In particular, as per [expr]:
    2720              : 
    2721              :      Whenever an lvalue expression appears as an operand of an
    2722              :      operator that expects the rvalue for that operand, the
    2723              :      lvalue-to-rvalue, array-to-pointer, or function-to-pointer
    2724              :      standard conversions are applied to convert the expression to an
    2725              :      rvalue.
    2726              : 
    2727              :    In addition, we perform integral promotions here, as those are
    2728              :    applied to both operands to a binary operator before determining
    2729              :    what additional conversions should apply.  */
    2730              : 
    2731              : static tree
    2732    321912872 : cp_default_conversion (tree exp, tsubst_flags_t complain)
    2733              : {
    2734              :   /* Check for target-specific promotions.  */
    2735    321912872 :   tree promoted_type = targetm.promoted_type (TREE_TYPE (exp));
    2736    321912872 :   if (promoted_type)
    2737            0 :     exp = cp_convert (promoted_type, exp, complain);
    2738              :   /* Perform the integral promotions first so that bitfield
    2739              :      expressions (which may promote to "int", even if the bitfield is
    2740              :      declared "unsigned") are promoted correctly.  */
    2741    321912872 :   else if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
    2742    223973806 :     exp = cp_perform_integral_promotions (exp, complain);
    2743              :   /* Perform the other conversions.  */
    2744    321912872 :   exp = decay_conversion (exp, complain);
    2745              : 
    2746    321912872 :   return exp;
    2747              : }
    2748              : 
    2749              : /* C version.  */
    2750              : 
    2751              : tree
    2752     42052189 : default_conversion (tree exp)
    2753              : {
    2754     42052189 :   return cp_default_conversion (exp, tf_warning_or_error);
    2755              : }
    2756              : 
    2757              : /* EXPR is an expression with an integral or enumeration type.
    2758              :    Perform the integral promotions in [conv.prom], and return the
    2759              :    converted value.  */
    2760              : 
    2761              : tree
    2762    230381854 : cp_perform_integral_promotions (tree expr, tsubst_flags_t complain)
    2763              : {
    2764    230381854 :   tree type;
    2765    230381854 :   tree promoted_type;
    2766              : 
    2767    230381854 :   expr = mark_rvalue_use (expr);
    2768    230381854 :   if (error_operand_p (expr))
    2769            6 :     return error_mark_node;
    2770              : 
    2771    230381848 :   type = TREE_TYPE (expr);
    2772              : 
    2773              :   /* [conv.prom]
    2774              : 
    2775              :      A prvalue for an integral bit-field (11.3.9) can be converted to a prvalue
    2776              :      of type int if int can represent all the values of the bit-field;
    2777              :      otherwise, it can be converted to unsigned int if unsigned int can
    2778              :      represent all the values of the bit-field. If the bit-field is larger yet,
    2779              :      no integral promotion applies to it. If the bit-field has an enumerated
    2780              :      type, it is treated as any other value of that type for promotion
    2781              :      purposes.  */
    2782    230381848 :   tree bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    2783    230381848 :   if (bitfield_type
    2784    230381848 :       && (TREE_CODE (bitfield_type) == ENUMERAL_TYPE
    2785       561331 :           || TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)))
    2786              :     type = bitfield_type;
    2787              : 
    2788    230381848 :   gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type));
    2789              :   /* Scoped enums don't promote.  */
    2790    230381848 :   if (SCOPED_ENUM_P (type))
    2791              :     return expr;
    2792    229747356 :   promoted_type = type_promotes_to (type);
    2793    229747356 :   if (type != promoted_type)
    2794     69737447 :     expr = cp_convert (promoted_type, expr, complain);
    2795    160009909 :   else if (bitfield_type && bitfield_type != type)
    2796              :     /* Prevent decay_conversion from converting to bitfield_type.  */
    2797          159 :     expr = build_nop (type, expr);
    2798              :   return expr;
    2799              : }
    2800              : 
    2801              : /* C version.  */
    2802              : 
    2803              : tree
    2804      1862335 : perform_integral_promotions (tree expr)
    2805              : {
    2806      1862335 :   return cp_perform_integral_promotions (expr, tf_warning_or_error);
    2807              : }
    2808              : 
    2809              : /* Returns nonzero iff exp is a STRING_CST or the result of applying
    2810              :    decay_conversion to one.  */
    2811              : 
    2812              : int
    2813      3904445 : string_conv_p (const_tree totype, const_tree exp, int warn)
    2814              : {
    2815      3904445 :   tree t;
    2816              : 
    2817      3904445 :   if (!TYPE_PTR_P (totype))
    2818              :     return 0;
    2819              : 
    2820      3903554 :   t = TREE_TYPE (totype);
    2821      3903554 :   if (!same_type_p (t, char_type_node)
    2822      3750003 :       && !same_type_p (t, char8_type_node)
    2823      3684712 :       && !same_type_p (t, char16_type_node)
    2824      3631442 :       && !same_type_p (t, char32_type_node)
    2825      7481727 :       && !same_type_p (t, wchar_type_node))
    2826              :     return 0;
    2827              : 
    2828       367754 :   location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
    2829              : 
    2830       367754 :   STRIP_ANY_LOCATION_WRAPPER (exp);
    2831              : 
    2832       367754 :   if (TREE_CODE (exp) == STRING_CST)
    2833              :     {
    2834              :       /* Make sure that we don't try to convert between char and wide chars.  */
    2835          108 :       if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t))
    2836              :         return 0;
    2837              :     }
    2838              :   else
    2839              :     {
    2840              :       /* Is this a string constant which has decayed to 'const char *'?  */
    2841       367646 :       t = build_pointer_type (cp_build_qualified_type (t, TYPE_QUAL_CONST));
    2842       367646 :       if (!same_type_p (TREE_TYPE (exp), t))
    2843              :         return 0;
    2844        14971 :       STRIP_NOPS (exp);
    2845        14971 :       if (TREE_CODE (exp) != ADDR_EXPR
    2846        14971 :           || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
    2847              :         return 0;
    2848              :     }
    2849          306 :   if (warn)
    2850              :     {
    2851          102 :       if (cxx_dialect >= cxx11)
    2852           87 :         pedwarn (loc, OPT_Wwrite_strings,
    2853              :                  "ISO C++ forbids converting a string constant to %qT",
    2854              :                  totype);
    2855              :       else
    2856           15 :         warning_at (loc, OPT_Wwrite_strings,
    2857              :                     "deprecated conversion from string constant to %qT",
    2858              :                     totype);
    2859              :     }
    2860              : 
    2861              :   return 1;
    2862              : }
    2863              : 
    2864              : /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
    2865              :    can, for example, use as an lvalue.  This code used to be in
    2866              :    unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
    2867              :    expressions, where we're dealing with aggregates.  But now it's again only
    2868              :    called from unary_complex_lvalue.  The case (in particular) that led to
    2869              :    this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
    2870              :    get it there.  */
    2871              : 
    2872              : static tree
    2873        88117 : rationalize_conditional_expr (enum tree_code code, tree t,
    2874              :                               tsubst_flags_t complain)
    2875              : {
    2876        88117 :   location_t loc = cp_expr_loc_or_input_loc (t);
    2877              : 
    2878              :   /* For MIN_EXPR or MAX_EXPR, fold-const.cc has arranged things so that
    2879              :      the first operand is always the one to be used if both operands
    2880              :      are equal, so we know what conditional expression this used to be.  */
    2881        88117 :   if (TREE_CODE (t) == MIN_EXPR || TREE_CODE (t) == MAX_EXPR)
    2882              :     {
    2883            0 :       tree op0 = TREE_OPERAND (t, 0);
    2884            0 :       tree op1 = TREE_OPERAND (t, 1);
    2885              : 
    2886              :       /* The following code is incorrect if either operand side-effects.  */
    2887            0 :       gcc_assert (!TREE_SIDE_EFFECTS (op0)
    2888              :                   && !TREE_SIDE_EFFECTS (op1));
    2889            0 :       return
    2890            0 :         build_conditional_expr (loc,
    2891            0 :                                 build_x_binary_op (loc,
    2892            0 :                                                    (TREE_CODE (t) == MIN_EXPR
    2893              :                                                     ? LE_EXPR : GE_EXPR),
    2894            0 :                                                    op0, TREE_CODE (op0),
    2895            0 :                                                    op1, TREE_CODE (op1),
    2896              :                                                    NULL_TREE,
    2897              :                                                    /*overload=*/NULL,
    2898              :                                                    complain),
    2899              :                                 cp_build_unary_op (code, op0, false, complain),
    2900              :                                 cp_build_unary_op (code, op1, false, complain),
    2901              :                                 complain);
    2902              :     }
    2903              : 
    2904        88117 :   tree op1 = TREE_OPERAND (t, 1);
    2905        88117 :   if (TREE_CODE (op1) != THROW_EXPR)
    2906        88114 :     op1 = cp_build_unary_op (code, op1, false, complain);
    2907        88117 :   tree op2 = TREE_OPERAND (t, 2);
    2908        88117 :   if (TREE_CODE (op2) != THROW_EXPR)
    2909        88111 :     op2 = cp_build_unary_op (code, op2, false, complain);
    2910              : 
    2911        88117 :   return
    2912        88117 :     build_conditional_expr (loc, TREE_OPERAND (t, 0), op1, op2, complain);
    2913              : }
    2914              : 
    2915              : /* Given the TYPE of an anonymous union field inside T, return the
    2916              :    FIELD_DECL for the field.  If not found return NULL_TREE.  Because
    2917              :    anonymous unions can nest, we must also search all anonymous unions
    2918              :    that are directly reachable.  */
    2919              : 
    2920              : tree
    2921      1545450 : lookup_anon_field (tree, tree type)
    2922              : {
    2923      1545450 :   tree field;
    2924              : 
    2925      1545450 :   type = TYPE_MAIN_VARIANT (type);
    2926      1545450 :   field = ANON_AGGR_TYPE_FIELD (type);
    2927      1545450 :   gcc_assert (field);
    2928      1545450 :   return field;
    2929              : }
    2930              : 
    2931              : /* Build an expression representing OBJECT.MEMBER.  OBJECT is an
    2932              :    expression; MEMBER is a DECL or baselink.  If ACCESS_PATH is
    2933              :    non-NULL, it indicates the path to the base used to name MEMBER.
    2934              :    If PRESERVE_REFERENCE is true, the expression returned will have
    2935              :    REFERENCE_TYPE if the MEMBER does.  Otherwise, the expression
    2936              :    returned will have the type referred to by the reference.
    2937              : 
    2938              :    This function does not perform access control; that is either done
    2939              :    earlier by the parser when the name of MEMBER is resolved to MEMBER
    2940              :    itself, or later when overload resolution selects one of the
    2941              :    functions indicated by MEMBER.  */
    2942              : 
    2943              : tree
    2944    125289208 : build_class_member_access_expr (cp_expr object, tree member,
    2945              :                                 tree access_path, bool preserve_reference,
    2946              :                                 tsubst_flags_t complain)
    2947              : {
    2948    125289208 :   tree object_type;
    2949    125289208 :   tree member_scope;
    2950    125289208 :   tree result = NULL_TREE;
    2951    125289208 :   tree using_decl = NULL_TREE;
    2952              : 
    2953    125289208 :   if (error_operand_p (object) || error_operand_p (member))
    2954           59 :     return error_mark_node;
    2955              : 
    2956    125289149 :   gcc_assert (DECL_P (member) || BASELINK_P (member));
    2957              : 
    2958              :   /* [expr.ref]
    2959              : 
    2960              :      The type of the first expression shall be "class object" (of a
    2961              :      complete type).  */
    2962    125289149 :   object_type = TREE_TYPE (object);
    2963    125289149 :   if (!currently_open_class (object_type)
    2964    125289149 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    2965            0 :     return error_mark_node;
    2966    125289149 :   if (!CLASS_TYPE_P (object_type))
    2967              :     {
    2968            0 :       if (complain & tf_error)
    2969              :         {
    2970            0 :           if (INDIRECT_TYPE_P (object_type)
    2971            0 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    2972            0 :             error ("request for member %qD in %qE, which is of pointer "
    2973              :                    "type %qT (maybe you meant to use %<->%> ?)",
    2974              :                    member, object.get_value (), object_type);
    2975              :           else
    2976            0 :             error ("request for member %qD in %qE, which is of non-class "
    2977              :                    "type %qT", member, object.get_value (), object_type);
    2978              :         }
    2979            0 :       return error_mark_node;
    2980              :     }
    2981              : 
    2982              :   /* The standard does not seem to actually say that MEMBER must be a
    2983              :      member of OBJECT_TYPE.  However, that is clearly what is
    2984              :      intended.  */
    2985    125289149 :   if (DECL_P (member))
    2986              :     {
    2987     54660149 :       member_scope = DECL_CLASS_CONTEXT (member);
    2988     54660149 :       if (!mark_used (member, complain) && !(complain & tf_error))
    2989            0 :         return error_mark_node;
    2990              : 
    2991     54660149 :       if (TREE_UNAVAILABLE (member))
    2992           30 :         error_unavailable_use (member, NULL_TREE);
    2993     54660119 :       else if (TREE_DEPRECATED (member))
    2994           30 :         warn_deprecated_use (member, NULL_TREE);
    2995              :     }
    2996              :   else
    2997     70629000 :     member_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (member));
    2998              :   /* If MEMBER is from an anonymous aggregate, MEMBER_SCOPE will
    2999              :      presently be the anonymous union.  Go outwards until we find a
    3000              :      type related to OBJECT_TYPE.  */
    3001    126838206 :   while ((ANON_AGGR_TYPE_P (member_scope) || UNSCOPED_ENUM_P (member_scope))
    3002    128387827 :          && !same_type_ignoring_top_level_qualifiers_p (member_scope,
    3003              :                                                         object_type))
    3004      1549057 :     member_scope = TYPE_CONTEXT (member_scope);
    3005    125289149 :   if (!member_scope || !DERIVED_FROM_P (member_scope, object_type))
    3006              :     {
    3007           19 :       if (complain & tf_error)
    3008              :         {
    3009           19 :           if (TREE_CODE (member) == FIELD_DECL)
    3010            4 :             error ("invalid use of non-static data member %qE", member);
    3011              :           else
    3012           15 :             error ("%qD is not a member of %qT", member, object_type);
    3013              :         }
    3014           19 :       return error_mark_node;
    3015              :     }
    3016              : 
    3017              :   /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x' into
    3018              :      `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only an lvalue
    3019              :      in the front end; only _DECLs and _REFs are lvalues in the back end.  */
    3020    125289130 :   if (tree temp = unary_complex_lvalue (ADDR_EXPR, object))
    3021              :     {
    3022           44 :       temp = cp_build_fold_indirect_ref (temp);
    3023           44 :       if (!lvalue_p (object) && lvalue_p (temp))
    3024              :         /* Preserve rvalueness.  */
    3025            6 :         temp = move (temp);
    3026           44 :       object = temp;
    3027              :     }
    3028              : 
    3029              :   /* In [expr.ref], there is an explicit list of the valid choices for
    3030              :      MEMBER.  We check for each of those cases here.  */
    3031    125289130 :   if (VAR_P (member))
    3032              :     {
    3033              :       /* A static data member.  */
    3034       116981 :       result = member;
    3035       116981 :       mark_exp_read (object);
    3036              : 
    3037       116981 :       if (tree wrap = maybe_get_tls_wrapper_call (result))
    3038              :         /* Replace an evaluated use of the thread_local variable with
    3039              :            a call to its wrapper.  */
    3040          102 :         result = wrap;
    3041              : 
    3042              :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3043       116981 :       if (TREE_SIDE_EFFECTS (object))
    3044         4827 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);
    3045              :     }
    3046    125172149 :   else if (TREE_CODE (member) == FIELD_DECL)
    3047              :     {
    3048              :       /* A non-static data member.  */
    3049     54542937 :       bool null_object_p;
    3050     54542937 :       int type_quals;
    3051     54542937 :       tree member_type;
    3052              : 
    3053     54542937 :       if (INDIRECT_REF_P (object))
    3054     40997558 :         null_object_p =
    3055     40997558 :           integer_zerop (tree_strip_nop_conversions (TREE_OPERAND (object, 0)));
    3056              :       else
    3057              :         null_object_p = false;
    3058              : 
    3059              :       /* Convert OBJECT to the type of MEMBER.  */
    3060     54542937 :       if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
    3061              :                         TYPE_MAIN_VARIANT (member_scope)))
    3062              :         {
    3063      2067859 :           tree binfo;
    3064      2067859 :           base_kind kind;
    3065              : 
    3066              :           /* We didn't complain above about a currently open class, but now we
    3067              :              must: we don't know how to refer to a base member before layout is
    3068              :              complete.  But still don't complain in a template.  */
    3069      2067859 :           if (!cp_unevaluated_operand
    3070      2067338 :               && !dependent_type_p (object_type)
    3071      3842730 :               && !complete_type_or_maybe_complain (object_type, object,
    3072              :                                                    complain))
    3073           17 :             return error_mark_node;
    3074              : 
    3075      2798199 :           binfo = lookup_base (access_path ? access_path : object_type,
    3076              :                                member_scope, ba_unique, &kind, complain);
    3077      2067856 :           if (binfo == error_mark_node)
    3078              :             return error_mark_node;
    3079              : 
    3080              :           /* It is invalid to try to get to a virtual base of a
    3081              :              NULL object.  The most common cause is invalid use of
    3082              :              offsetof macro.  */
    3083      2067848 :           if (null_object_p && kind == bk_via_virtual)
    3084              :             {
    3085            6 :               if (complain & tf_error)
    3086              :                 {
    3087            6 :                   error ("invalid access to non-static data member %qD in "
    3088              :                          "virtual base of NULL object", member);
    3089              :                 }
    3090            6 :               return error_mark_node;
    3091              :             }
    3092              : 
    3093              :           /* Convert to the base.  */
    3094      2067842 :           object = build_base_path (PLUS_EXPR, object, binfo,
    3095              :                                     /*nonnull=*/1, complain);
    3096              :           /* If we found the base successfully then we should be able
    3097              :              to convert to it successfully.  */
    3098      2067842 :           gcc_assert (object != error_mark_node || seen_error ());
    3099              :         }
    3100              : 
    3101              :       /* If MEMBER is from an anonymous aggregate, we have converted
    3102              :          OBJECT so that it refers to the class containing the
    3103              :          anonymous union.  Generate a reference to the anonymous union
    3104              :          itself, and recur to find MEMBER.  */
    3105    109085840 :       if (ANON_AGGR_TYPE_P (DECL_CONTEXT (member))
    3106              :           /* When this code is called from build_field_call, the
    3107              :              object already has the type of the anonymous union.
    3108              :              That is because the COMPONENT_REF was already
    3109              :              constructed, and was then disassembled before calling
    3110              :              build_field_call.  After the function-call code is
    3111              :              cleaned up, this waste can be eliminated.  */
    3112     56088788 :           && (!same_type_ignoring_top_level_qualifiers_p
    3113      1545868 :               (TREE_TYPE (object), DECL_CONTEXT (member))))
    3114              :         {
    3115      1545310 :           tree anonymous_union;
    3116              : 
    3117      1545310 :           anonymous_union = lookup_anon_field (TREE_TYPE (object),
    3118      1545310 :                                                DECL_CONTEXT (member));
    3119      1545310 :           object = build_class_member_access_expr (object,
    3120              :                                                    anonymous_union,
    3121              :                                                    /*access_path=*/NULL_TREE,
    3122              :                                                    preserve_reference,
    3123              :                                                    complain);
    3124              :         }
    3125              : 
    3126              :       /* Compute the type of the field, as described in [expr.ref].  */
    3127     54542920 :       type_quals = TYPE_UNQUALIFIED;
    3128     54542920 :       member_type = TREE_TYPE (member);
    3129     54542920 :       if (!TYPE_REF_P (member_type))
    3130              :         {
    3131     53516163 :           type_quals = (cp_type_quals (member_type)
    3132     53516163 :                         | cp_type_quals (object_type));
    3133              : 
    3134              :           /* A field is const (volatile) if the enclosing object, or the
    3135              :              field itself, is const (volatile).  But, a mutable field is
    3136              :              not const, even within a const object.  */
    3137     53516163 :           if (DECL_MUTABLE_P (member))
    3138       328930 :             type_quals &= ~TYPE_QUAL_CONST;
    3139     53516163 :           member_type = cp_build_qualified_type (member_type, type_quals);
    3140              :         }
    3141              : 
    3142     54542920 :       result = build3_loc (input_location, COMPONENT_REF, member_type,
    3143              :                            object, member, NULL_TREE);
    3144              : 
    3145              :       /* Mark the expression const or volatile, as appropriate.  Even
    3146              :          though we've dealt with the type above, we still have to mark the
    3147              :          expression itself.  */
    3148     54542920 :       if (type_quals & TYPE_QUAL_CONST)
    3149     16911284 :         TREE_READONLY (result) = 1;
    3150     54542920 :       if (type_quals & TYPE_QUAL_VOLATILE)
    3151       187485 :         TREE_THIS_VOLATILE (result) = 1;
    3152              :     }
    3153     70629212 :   else if (BASELINK_P (member))
    3154              :     {
    3155              :       /* The member is a (possibly overloaded) member function.  */
    3156     70628985 :       tree functions;
    3157     70628985 :       tree type;
    3158              : 
    3159              :       /* If the MEMBER is exactly one static member function, then we
    3160              :          know the type of the expression.  Otherwise, we must wait
    3161              :          until overload resolution has been performed.  */
    3162     70628985 :       functions = BASELINK_FUNCTIONS (member);
    3163     70628985 :       if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
    3164     70628985 :         functions = OVL_FIRST (functions);
    3165     70628985 :       if (TREE_CODE (functions) == FUNCTION_DECL
    3166     70628985 :           && DECL_STATIC_FUNCTION_P (functions))
    3167       637693 :         type = TREE_TYPE (functions);
    3168              :       else
    3169     69991292 :         type = unknown_type_node;
    3170              :       /* Note that we do not convert OBJECT to the BASELINK_BINFO
    3171              :          base.  That will happen when the function is called.  */
    3172     70628985 :       result = build3_loc (input_location, COMPONENT_REF, type, object, member,
    3173              :                            NULL_TREE);
    3174              :     }
    3175          227 :   else if (TREE_CODE (member) == CONST_DECL)
    3176              :     {
    3177              :       /* The member is an enumerator.  */
    3178          215 :       result = member;
    3179              :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3180          215 :       if (TREE_SIDE_EFFECTS (object))
    3181            6 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    3182              :                          object, result);
    3183              :     }
    3184           12 :   else if ((using_decl = strip_using_decl (member)) != member)
    3185            0 :     result = build_class_member_access_expr (object,
    3186              :                                              using_decl,
    3187              :                                              access_path, preserve_reference,
    3188              :                                              complain);
    3189              :   else
    3190              :     {
    3191           12 :       if (complain & tf_error)
    3192           12 :         error ("invalid use of %qD", member);
    3193           12 :       return error_mark_node;
    3194              :     }
    3195              : 
    3196    125289101 :   if (!preserve_reference)
    3197              :     /* [expr.ref]
    3198              : 
    3199              :        If E2 is declared to have type "reference to T", then ... the
    3200              :        type of E1.E2 is T.  */
    3201    118304867 :     result = convert_from_reference (result);
    3202              : 
    3203              :   return result;
    3204              : }
    3205              : 
    3206              : /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
    3207              :    SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
    3208              : 
    3209              : tree
    3210       220387 : lookup_destructor (tree object, tree scope, tree dtor_name,
    3211              :                    tsubst_flags_t complain)
    3212              : {
    3213       220387 :   tree object_type = TREE_TYPE (object);
    3214       220387 :   tree dtor_type = TREE_OPERAND (dtor_name, 0);
    3215       220387 :   tree expr;
    3216              : 
    3217              :   /* We've already complained about this destructor.  */
    3218       220387 :   if (dtor_type == error_mark_node)
    3219              :     return error_mark_node;
    3220              : 
    3221       220381 :   if (scope && !check_dtor_name (scope, dtor_type))
    3222              :     {
    3223            3 :       if (complain & tf_error)
    3224            3 :         error ("qualified type %qT does not match destructor name ~%qT",
    3225              :                scope, dtor_type);
    3226            3 :       return error_mark_node;
    3227              :     }
    3228       220378 :   if (is_auto (dtor_type))
    3229              :     dtor_type = object_type;
    3230       220375 :   else if (identifier_p (dtor_type))
    3231              :     {
    3232              :       /* In a template, names we can't find a match for are still accepted
    3233              :          destructor names, and we check them here.  */
    3234           23 :       if (check_dtor_name (object_type, dtor_type))
    3235              :         dtor_type = object_type;
    3236              :       else
    3237              :         {
    3238            3 :           if (complain & tf_error)
    3239            3 :             error ("object type %qT does not match destructor name ~%qT",
    3240              :                    object_type, dtor_type);
    3241            3 :           return error_mark_node;
    3242              :         }
    3243              : 
    3244              :     }
    3245       220352 :   else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
    3246              :     {
    3247            8 :       if (complain & tf_error)
    3248            8 :         error ("the type being destroyed is %qT, but the destructor "
    3249            8 :                "refers to %qT", TYPE_MAIN_VARIANT (object_type), dtor_type);
    3250            8 :       return error_mark_node;
    3251              :     }
    3252       220367 :   expr = lookup_member (dtor_type, complete_dtor_identifier,
    3253              :                         /*protect=*/1, /*want_type=*/false,
    3254              :                         complain);
    3255       220367 :   if (expr == error_mark_node)
    3256              :     return error_mark_node;
    3257       220367 :   if (!expr)
    3258              :     {
    3259            6 :       if (complain & tf_error)
    3260            6 :         cxx_incomplete_type_error (dtor_name, dtor_type);
    3261            6 :       return error_mark_node;
    3262              :     }
    3263       220361 :   expr = (adjust_result_of_qualified_name_lookup
    3264       220361 :           (expr, dtor_type, object_type));
    3265       220361 :   if (scope == NULL_TREE)
    3266              :     /* We need to call adjust_result_of_qualified_name_lookup in case the
    3267              :        destructor names a base class, but we unset BASELINK_QUALIFIED_P so
    3268              :        that we still get virtual function binding.  */
    3269       220218 :     BASELINK_QUALIFIED_P (expr) = false;
    3270              :   return expr;
    3271              : }
    3272              : 
    3273              : /* An expression of the form "A::template B" has been resolved to
    3274              :    DECL.  Issue a diagnostic if B is not a template or template
    3275              :    specialization.  */
    3276              : 
    3277              : void
    3278       280272 : check_template_keyword (tree decl)
    3279              : {
    3280              :   /* The standard says:
    3281              : 
    3282              :       [temp.names]
    3283              : 
    3284              :       If a name prefixed by the keyword template is not a member
    3285              :       template, the program is ill-formed.
    3286              : 
    3287              :      DR 228 removed the restriction that the template be a member
    3288              :      template.
    3289              : 
    3290              :      DR 96, if accepted would add the further restriction that explicit
    3291              :      template arguments must be provided if the template keyword is
    3292              :      used, but, as of 2005-10-16, that DR is still in "drafting".  If
    3293              :      this DR is accepted, then the semantic checks here can be
    3294              :      simplified, as the entity named must in fact be a template
    3295              :      specialization, rather than, as at present, a set of overloaded
    3296              :      functions containing at least one template function.  */
    3297       280272 :   if (TREE_CODE (decl) != TEMPLATE_DECL
    3298       280272 :       && TREE_CODE (decl) != TEMPLATE_ID_EXPR)
    3299              :     {
    3300        68071 :       if (VAR_P (decl))
    3301              :         {
    3302         9729 :           if (DECL_USE_TEMPLATE (decl)
    3303         9729 :               && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
    3304              :             ;
    3305              :           else
    3306            0 :             permerror (input_location, "%qD is not a template", decl);
    3307              :         }
    3308        58342 :       else if (!is_overloaded_fn (decl))
    3309            0 :         permerror (input_location, "%qD is not a template", decl);
    3310              :       else
    3311              :         {
    3312        58342 :           bool found = false;
    3313              : 
    3314       116684 :           for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl));
    3315       116686 :                !found && iter; ++iter)
    3316              :             {
    3317        58344 :               tree fn = *iter;
    3318        58344 :               if (TREE_CODE (fn) == TEMPLATE_DECL
    3319        57948 :                   || TREE_CODE (fn) == TEMPLATE_ID_EXPR
    3320        58358 :                   || (TREE_CODE (fn) == FUNCTION_DECL
    3321           14 :                       && DECL_USE_TEMPLATE (fn)
    3322            6 :                       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (fn))))
    3323              :                 found = true;
    3324              :             }
    3325        58342 :           if (!found)
    3326           12 :             permerror (input_location, "%qD is not a template", decl);
    3327              :         }
    3328              :     }
    3329       280272 : }
    3330              : 
    3331              : /* Record that an access failure occurred on BASETYPE_PATH attempting
    3332              :    to access DECL, where DIAG_DECL should be used for diagnostics.  */
    3333              : 
    3334              : void
    3335          412 : access_failure_info::record_access_failure (tree basetype_path,
    3336              :                                             tree decl, tree diag_decl)
    3337              : {
    3338          412 :   m_was_inaccessible = true;
    3339          412 :   m_basetype_path = basetype_path;
    3340          412 :   m_decl = decl;
    3341          412 :   m_diag_decl = diag_decl;
    3342          412 : }
    3343              : 
    3344              : /* If an access failure was recorded, then attempt to locate an
    3345              :    accessor function for the pertinent field.
    3346              :    Otherwise, return NULL_TREE.  */
    3347              : 
    3348              : tree
    3349    100085117 : access_failure_info::get_any_accessor (bool const_p) const
    3350              : {
    3351    100085117 :   if (!was_inaccessible_p ())
    3352              :     return NULL_TREE;
    3353              : 
    3354          412 :   tree accessor
    3355          412 :     = locate_field_accessor (m_basetype_path, m_diag_decl, const_p);
    3356          412 :   if (!accessor)
    3357              :     return NULL_TREE;
    3358              : 
    3359              :   /* The accessor must itself be accessible for it to be a reasonable
    3360              :      suggestion.  */
    3361          161 :   if (!accessible_p (m_basetype_path, accessor, true))
    3362           21 :     return NULL_TREE;
    3363              : 
    3364              :   return accessor;
    3365              : }
    3366              : 
    3367              : /* Add a fix-it hint to RICHLOC suggesting the use of ACCESSOR_DECL, by
    3368              :    replacing the primary location in RICHLOC with "accessor()".  */
    3369              : 
    3370              : void
    3371          140 : access_failure_info::add_fixit_hint (rich_location *richloc,
    3372              :                                      tree accessor_decl)
    3373              : {
    3374          140 :   pretty_printer pp;
    3375          140 :   pp_string (&pp, IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
    3376          140 :   pp_string (&pp, "()");
    3377          140 :   richloc->add_fixit_replace (pp_formatted_text (&pp));
    3378          140 : }
    3379              : 
    3380              : /* If an access failure was recorded, then attempt to locate an
    3381              :    accessor function for the pertinent field, and if one is
    3382              :    available, add a note and fix-it hint suggesting using it.  */
    3383              : 
    3384              : void
    3385    100085047 : access_failure_info::maybe_suggest_accessor (bool const_p) const
    3386              : {
    3387    100085047 :   tree accessor = get_any_accessor (const_p);
    3388    100085047 :   if (accessor == NULL_TREE)
    3389              :     return;
    3390           98 :   rich_location richloc (line_table, input_location);
    3391           98 :   add_fixit_hint (&richloc, accessor);
    3392           98 :   inform (&richloc, "field %q#D can be accessed via %q#D",
    3393           98 :           m_diag_decl, accessor);
    3394           98 : }
    3395              : 
    3396              : /* Subroutine of finish_class_member_access_expr.
    3397              :    Issue an error about NAME not being a member of ACCESS_PATH (or
    3398              :    OBJECT_TYPE), potentially providing a fix-it hint for misspelled
    3399              :    names.  */
    3400              : 
    3401              : static void
    3402          339 : complain_about_unrecognized_member (tree access_path, tree name,
    3403              :                                     tree object_type)
    3404              : {
    3405              :   /* Attempt to provide a hint about misspelled names.  */
    3406          339 :   tree guessed_id = lookup_member_fuzzy (access_path, name,
    3407              :                                          /*want_type=*/false);
    3408          339 :   if (guessed_id == NULL_TREE)
    3409              :     {
    3410              :       /* No hint.  */
    3411          223 :       error ("%q#T has no member named %qE",
    3412          223 :              TREE_CODE (access_path) == TREE_BINFO
    3413            6 :              ? TREE_TYPE (access_path) : object_type, name);
    3414          223 :       return;
    3415              :     }
    3416              : 
    3417          116 :   location_t bogus_component_loc = input_location;
    3418          116 :   gcc_rich_location rich_loc (bogus_component_loc);
    3419              : 
    3420              :   /* Check that the guessed name is accessible along access_path.  */
    3421          116 :   access_failure_info afi;
    3422          116 :   lookup_member (access_path, guessed_id, /*protect=*/1,
    3423              :                  /*want_type=*/false, /*complain=*/false,
    3424              :                  &afi);
    3425          116 :   if (afi.was_inaccessible_p ())
    3426              :     {
    3427           70 :       tree accessor = afi.get_any_accessor (TYPE_READONLY (object_type));
    3428           70 :       if (accessor)
    3429              :         {
    3430              :           /* The guessed name isn't directly accessible, but can be accessed
    3431              :              via an accessor member function.  */
    3432           42 :           afi.add_fixit_hint (&rich_loc, accessor);
    3433           42 :           error_at (&rich_loc,
    3434              :                     "%q#T has no member named %qE;"
    3435              :                     " did you mean %q#D? (accessible via %q#D)",
    3436           42 :                     TREE_CODE (access_path) == TREE_BINFO
    3437            0 :                     ? TREE_TYPE (access_path) : object_type,
    3438              :                     name, afi.get_diag_decl (), accessor);
    3439              :         }
    3440              :       else
    3441              :         {
    3442              :           /* The guessed name isn't directly accessible, and no accessor
    3443              :              member function could be found.  */
    3444           28 :           auto_diagnostic_group d;
    3445           28 :           error_at (&rich_loc,
    3446              :                     "%q#T has no member named %qE;"
    3447              :                     " did you mean %q#D? (not accessible from this context)",
    3448           28 :                     TREE_CODE (access_path) == TREE_BINFO
    3449            0 :                     ? TREE_TYPE (access_path) : object_type,
    3450              :                     name, afi.get_diag_decl ());
    3451           28 :           complain_about_access (afi.get_decl (), afi.get_diag_decl (),
    3452              :                                  afi.get_diag_decl (), false, ak_none);
    3453           28 :         }
    3454              :     }
    3455              :   else
    3456              :     {
    3457              :       /* The guessed name is directly accessible; suggest it.  */
    3458           46 :       rich_loc.add_fixit_misspelled_id (bogus_component_loc,
    3459              :                                         guessed_id);
    3460           46 :       error_at (&rich_loc,
    3461              :                 "%q#T has no member named %qE;"
    3462              :                 " did you mean %qE?",
    3463           46 :                 TREE_CODE (access_path) == TREE_BINFO
    3464            0 :                 ? TREE_TYPE (access_path) : object_type,
    3465              :                 name, guessed_id);
    3466              :     }
    3467          116 : }
    3468              : 
    3469              : /* This function is called by the parser to process a class member
    3470              :    access expression of the form OBJECT.NAME.  NAME is a node used by
    3471              :    the parser to represent a name; it is not yet a DECL, except when
    3472              :    SPLICE_P.  It may, however, be a BASELINK where the BASELINK_FUNCTIONS
    3473              :    is a TEMPLATE_ID_EXPR.  Templates must be looked up by the parser, and
    3474              :    there is no reason to do the lookup twice, so the parser keeps the
    3475              :    BASELINK.  TEMPLATE_P is true iff NAME was explicitly declared to
    3476              :    be a template via the use of the "A::template B" syntax.  SPLICE_P
    3477              :    is true if NAME was designated by a splice-expression.  */
    3478              : 
    3479              : tree
    3480    200114360 : finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
    3481              :                                  tsubst_flags_t complain,
    3482              :                                  bool splice_p/*=false*/)
    3483              : {
    3484    200114360 :   tree expr;
    3485    200114360 :   tree object_type;
    3486    200114360 :   tree member;
    3487    200114360 :   tree access_path = NULL_TREE;
    3488    200114360 :   tree orig_object = object;
    3489    200114360 :   tree orig_name = name;
    3490              : 
    3491    200114360 :   if (object == error_mark_node || name == error_mark_node)
    3492              :     return error_mark_node;
    3493              : 
    3494              :   /* If OBJECT is an ObjC class instance, we must obey ObjC access rules.  */
    3495    200113817 :   if (!objc_is_public (object, name))
    3496            0 :     return error_mark_node;
    3497              : 
    3498    200113817 :   object_type = TREE_TYPE (object);
    3499              : 
    3500    200113817 :   if (processing_template_decl)
    3501              :     {
    3502    165069033 :       if (/* If OBJECT is dependent, so is OBJECT.NAME.  */
    3503    165069033 :           type_dependent_object_expression_p (object)
    3504              :           /* If NAME is "f<args>", where either 'f' or 'args' is
    3505              :              dependent, then the expression is dependent.  */
    3506     77532475 :           || (TREE_CODE (name) == TEMPLATE_ID_EXPR
    3507       629359 :               && dependent_template_id_p (TREE_OPERAND (name, 0),
    3508       629359 :                                           TREE_OPERAND (name, 1)))
    3509              :           /* If NAME is "T::X" where "T" is dependent, then the
    3510              :              expression is dependent.  */
    3511     77209714 :           || (TREE_CODE (name) == SCOPE_REF
    3512       107851 :               && TYPE_P (TREE_OPERAND (name, 0))
    3513       107851 :               && dependent_scope_p (TREE_OPERAND (name, 0)))
    3514              :           /* If NAME is operator T where "T" is dependent, we can't
    3515              :              lookup until we instantiate the T.  */
    3516     77102086 :           || (TREE_CODE (name) == IDENTIFIER_NODE
    3517     76456587 :               && IDENTIFIER_CONV_OP_P (name)
    3518          100 :               && dependent_type_p (TREE_TYPE (name)))
    3519              :           /* This is OBJECT.[:R:], which is dependent.  */
    3520     77101992 :           || dependent_splice_p (name)
    3521              :           /* This is OBJECT.[:T::R:], which is dependent.  */
    3522    242170601 :           || (TREE_CODE (name) == SCOPE_REF
    3523          223 :               && dependent_splice_p (TREE_OPERAND (name, 1))))
    3524              :         {
    3525    102839046 :         dependent:
    3526    102839046 :           expr = build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF,
    3527              :                                    orig_object, orig_name, NULL_TREE);
    3528    102839046 :           COMPONENT_REF_SPLICE_P (expr) = splice_p;
    3529    102839046 :           return expr;
    3530              :         }
    3531              :     }
    3532     35044784 :   else if (c_dialect_objc ()
    3533    112146352 :            && identifier_p (name)
    3534     35044784 :            && (expr = objc_maybe_build_component_ref (object, name)))
    3535              :     return expr;
    3536              : 
    3537              :   /* [expr.ref]
    3538              : 
    3539              :      The type of the first expression shall be "class object" (of a
    3540              :      complete type).  */
    3541    112146352 :   if (!currently_open_class (object_type)
    3542    112146352 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    3543           74 :     return error_mark_node;
    3544    112146278 :   if (!CLASS_TYPE_P (object_type))
    3545              :     {
    3546       288834 :       if (complain & tf_error)
    3547              :         {
    3548          135 :           if (INDIRECT_TYPE_P (object_type)
    3549          135 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    3550           23 :             error ("request for member %qD in %qE, which is of pointer "
    3551              :                    "type %qT (maybe you meant to use %<->%> ?)",
    3552              :                    name, object.get_value (), object_type);
    3553              :           else
    3554          112 :             error ("request for member %qD in %qE, which is of non-class "
    3555              :                    "type %qT", name, object.get_value (), object_type);
    3556              :         }
    3557       288834 :       return error_mark_node;
    3558              :     }
    3559              : 
    3560    111857444 :   if (BASELINK_P (name))
    3561              :     /* A member function that has already been looked up.  */
    3562              :     member = name;
    3563    100354050 :   else if (TREE_CODE (name) == TREE_BINFO)
    3564              :     {
    3565              :       /* Splicing a base class subobject.  We can only get here via
    3566              :          e1.[:e2:].  */
    3567           94 :       expr = build_base_path (PLUS_EXPR, object, name, /*nonnull=*/true,
    3568              :                               complain);
    3569           94 :       if (expr == error_mark_node && (complain & tf_error))
    3570            4 :         error_not_base_type (BINFO_TYPE (name), object_type);
    3571              :       return expr;
    3572              :     }
    3573              :   else
    3574              :     {
    3575    100353956 :       bool is_template_id = false;
    3576    100353956 :       tree template_args = NULL_TREE;
    3577    100353956 :       tree scope = NULL_TREE;
    3578              : 
    3579    100353956 :       access_path = object_type;
    3580              : 
    3581    100353956 :       if (TREE_CODE (name) == SCOPE_REF)
    3582              :         {
    3583              :           /* A qualified name.  The qualifying class or namespace `S'
    3584              :              has already been looked up; it is either a TYPE or a
    3585              :              NAMESPACE_DECL.  */
    3586         1814 :           scope = TREE_OPERAND (name, 0);
    3587         1814 :           name = TREE_OPERAND (name, 1);
    3588              : 
    3589              :           /* If SCOPE is a namespace, then the qualified name does not
    3590              :              name a member of OBJECT_TYPE.  */
    3591         1814 :           if (TREE_CODE (scope) == NAMESPACE_DECL)
    3592              :             {
    3593            0 :               if (complain & tf_error)
    3594            0 :                 error ("%<%D::%D%> is not a member of %qT",
    3595              :                        scope, name, object_type);
    3596            0 :               return error_mark_node;
    3597              :             }
    3598              :         }
    3599    100352142 :       else if (splice_p && valid_splice_for_member_access_p (name))
    3600              :         {
    3601          256 :           scope = context_for_name_lookup (OVL_FIRST (name));
    3602          256 :           if (!CLASS_TYPE_P (scope))
    3603              :             {
    3604           10 :               if (complain & tf_error)
    3605              :                 {
    3606           10 :                   auto_diagnostic_group d;
    3607           10 :                   error ("%q#D is not a member of %qT", name, object_type);
    3608           20 :                   inform (DECL_SOURCE_LOCATION (OVL_FIRST (name)), "declared here");
    3609           10 :                 }
    3610           10 :               return error_mark_node;
    3611              :             }
    3612              :         }
    3613              : 
    3614    100353946 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    3615              :         {
    3616       470832 :           is_template_id = true;
    3617       470832 :           template_args = TREE_OPERAND (name, 1);
    3618       470832 :           name = TREE_OPERAND (name, 0);
    3619              : 
    3620       470832 :           if (splice_p
    3621       471318 :               && (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (name))
    3622          162 :                   || variable_template_p (name)))
    3623          162 :             scope = DECL_CONTEXT (OVL_FIRST (name));
    3624       912357 :           else if (!identifier_p (name))
    3625       441757 :             name = OVL_NAME (name);
    3626              :         }
    3627              : 
    3628    100353946 :       if (scope)
    3629              :         {
    3630         2222 :           if (TREE_CODE (scope) == ENUMERAL_TYPE)
    3631              :             {
    3632           12 :               gcc_assert (!is_template_id);
    3633              :               /* Looking up a member enumerator (c++/56793).  */
    3634           24 :               if (!TYPE_CLASS_SCOPE_P (scope)
    3635           21 :                   || !DERIVED_FROM_P (TYPE_CONTEXT (scope), object_type))
    3636              :                 {
    3637            3 :                   if (complain & tf_error)
    3638            3 :                     error ("%<%D::%D%> is not a member of %qT",
    3639              :                            scope, name, object_type);
    3640            3 :                   return error_mark_node;
    3641              :                 }
    3642            9 :               tree val;
    3643            9 :               if (splice_p && TREE_CODE (name) == CONST_DECL)
    3644              :                 val = name;
    3645              :               else
    3646            9 :                 val = lookup_enumerator (scope, name);
    3647            9 :               if (!val)
    3648              :                 {
    3649            6 :                   if (complain & tf_error)
    3650            6 :                     error ("%qD is not a member of %qD",
    3651              :                            name, scope);
    3652            6 :                   return error_mark_node;
    3653              :                 }
    3654              : 
    3655            3 :               if (TREE_SIDE_EFFECTS (object))
    3656            0 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val);
    3657              :               return val;
    3658              :             }
    3659              : 
    3660         2210 :           gcc_assert (CLASS_TYPE_P (scope));
    3661         2210 :           gcc_assert (identifier_p (name)
    3662              :                       || TREE_CODE (name) == BIT_NOT_EXPR
    3663              :                       || (splice_p && valid_splice_for_member_access_p (name)));
    3664              : 
    3665         2210 :           if (constructor_name_p (name, scope))
    3666              :             {
    3667            3 :               if (complain & tf_error)
    3668            3 :                 error ("cannot call constructor %<%T::%D%> directly",
    3669              :                        scope, name);
    3670            3 :               return error_mark_node;
    3671              :             }
    3672              : 
    3673              :           /* NAME may refer to a static data member, in which case there is
    3674              :              one copy of the data member that is shared by all the objects of
    3675              :              the class.  So NAME can be unambiguously referred to even if
    3676              :              there are multiple indirect base classes containing NAME.  */
    3677         6621 :           const base_access ba = [scope, name, splice_p] ()
    3678              :             {
    3679              :               /* [class.access.base]/5: A member m is accessible at the
    3680              :                  point R when designated in class N if
    3681              :                  -- m is designated by a splice-expression  */
    3682         2207 :               if (splice_p)
    3683              :                 return ba_unique;
    3684         1799 :               if (identifier_p (name))
    3685              :                 {
    3686         1662 :                   tree m = lookup_member (scope, name, /*protect=*/0,
    3687              :                                           /*want_type=*/false, tf_none);
    3688         1662 :                   if (!m || shared_member_p (m))
    3689           38 :                     return ba_any;
    3690              :                 }
    3691              :               return ba_check;
    3692         2207 :             } ();
    3693              : 
    3694              :           /* Find the base of OBJECT_TYPE corresponding to SCOPE.  */
    3695         2207 :           access_path = lookup_base (object_type, scope, ba, NULL, complain);
    3696         2207 :           if (access_path == error_mark_node)
    3697              :             return error_mark_node;
    3698         2177 :           if (!access_path)
    3699              :             {
    3700           36 :               if (any_dependent_bases_p (object_type))
    3701            6 :                 goto dependent;
    3702           30 :               if (complain & tf_error)
    3703           30 :                 error ("%qT is not a base of %qT", scope, object_type);
    3704           30 :               return error_mark_node;
    3705              :             }
    3706              :         }
    3707              : 
    3708    100353865 :       if (TREE_CODE (name) == BIT_NOT_EXPR)
    3709              :         {
    3710       268452 :           if (dependent_type_p (object_type))
    3711              :             /* The destructor isn't declared yet.  */
    3712        48080 :             goto dependent;
    3713       220372 :           member = lookup_destructor (object, scope, name, complain);
    3714              :         }
    3715    100085413 :       else if (splice_p && valid_splice_for_member_access_p (name))
    3716              :         {
    3717          366 :           member = name;
    3718          366 :           name = OVL_FIRST (name);
    3719          366 :           if (any_dependent_type_attributes_p (DECL_ATTRIBUTES (name)))
    3720              :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3721              :                wrong, so don't use it.  */
    3722            0 :             goto dependent;
    3723          366 :           if (is_overloaded_fn (name))
    3724            0 :             member
    3725            0 :               = build_baselink (access_path, TYPE_BINFO (object_type), member,
    3726            0 :                                 IDENTIFIER_CONV_OP_P (DECL_NAME (name))
    3727            0 :                                 ? TREE_TYPE (DECL_NAME (name)) : NULL_TREE);
    3728              :         }
    3729              :       else
    3730              :         {
    3731              :           /* Look up the member.  */
    3732    100085047 :           {
    3733    100085047 :             auto_diagnostic_group d;
    3734    100085047 :             access_failure_info afi;
    3735    100085047 :             if (processing_template_decl)
    3736              :               /* Even though this class member access expression is at this
    3737              :                  point not dependent, the member itself may be dependent, and
    3738              :                  we must not potentially push a access check for a dependent
    3739              :                  member onto TI_DEFERRED_ACCESS_CHECKS.  So don't check access
    3740              :                  ahead of time here; we're going to redo this member lookup at
    3741              :                  instantiation time anyway.  */
    3742     76763132 :               push_deferring_access_checks (dk_no_check);
    3743    100085047 :             member = lookup_member (access_path, name, /*protect=*/1,
    3744              :                                     /*want_type=*/false, complain,
    3745              :                                     &afi);
    3746    100085047 :             if (processing_template_decl)
    3747     76763132 :               pop_deferring_access_checks ();
    3748    100085047 :             afi.maybe_suggest_accessor (TYPE_READONLY (object_type));
    3749    100085047 :           }
    3750    100085047 :           if (member == NULL_TREE)
    3751              :             {
    3752      9461675 :               if (dependentish_scope_p (object_type))
    3753              :                 /* Try again at instantiation time.  */
    3754      9437695 :                 goto dependent;
    3755        23980 :               if (complain & tf_error)
    3756          339 :                 complain_about_unrecognized_member (access_path, name,
    3757              :                                                     object_type);
    3758        23980 :               return error_mark_node;
    3759              :             }
    3760     90623372 :           if (member == error_mark_node)
    3761              :             return error_mark_node;
    3762     90623326 :           if (DECL_P (member)
    3763     90623326 :               && any_dependent_type_attributes_p (DECL_ATTRIBUTES (member)))
    3764              :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3765              :                wrong, so don't use it.  */
    3766            6 :             goto dependent;
    3767     90623320 :           if (TREE_CODE (member) == USING_DECL && DECL_DEPENDENT_P (member))
    3768      5385794 :             goto dependent;
    3769              :         }
    3770              : 
    3771     85458264 :       if (is_template_id)
    3772              :         {
    3773       470542 :           tree templ = member;
    3774              : 
    3775       470542 :           if (BASELINK_P (templ))
    3776       470288 :             member = lookup_template_function (templ, template_args);
    3777          254 :           else if (variable_template_p (templ))
    3778          254 :             member = (lookup_and_finish_template_variable
    3779          254 :                       (templ, template_args, complain));
    3780              :           else
    3781              :             {
    3782            0 :               if (complain & tf_error)
    3783            0 :                 error ("%qD is not a member template function", name);
    3784            0 :               return error_mark_node;
    3785              :             }
    3786              :         }
    3787              :     }
    3788              : 
    3789     96961658 :   if (TREE_UNAVAILABLE (member))
    3790           30 :     error_unavailable_use (member, NULL_TREE);
    3791     96961628 :   else if (TREE_DEPRECATED (member))
    3792           30 :     warn_deprecated_use (member, NULL_TREE);
    3793              : 
    3794     96961658 :   if (template_p)
    3795         9771 :     check_template_keyword (member);
    3796              : 
    3797     96961658 :   expr = build_class_member_access_expr (object, member, access_path,
    3798              :                                          /*preserve_reference=*/false,
    3799              :                                          complain);
    3800     96961658 :   if (processing_template_decl && expr != error_mark_node)
    3801              :     {
    3802     62229890 :       if (BASELINK_P (member))
    3803              :         {
    3804     46179751 :           if (TREE_CODE (orig_name) == SCOPE_REF)
    3805          175 :             BASELINK_QUALIFIED_P (member) = 1;
    3806              :           orig_name = member;
    3807              :         }
    3808     62229890 :       expr = build_min_non_dep (COMPONENT_REF, expr,
    3809              :                                 orig_object, orig_name,
    3810              :                                 NULL_TREE);
    3811    124459780 :       COMPONENT_REF_SPLICE_P (STRIP_REFERENCE_REF (expr)) = splice_p;
    3812              :     }
    3813              : 
    3814              :   return expr;
    3815              : }
    3816              : 
    3817              : /* Build a COMPONENT_REF of OBJECT and MEMBER with the appropriate
    3818              :    type.  */
    3819              : 
    3820              : tree
    3821       174919 : build_simple_component_ref (tree object, tree member)
    3822              : {
    3823       174919 :   tree type = cp_build_qualified_type (TREE_TYPE (member),
    3824       174919 :                                        cp_type_quals (TREE_TYPE (object)));
    3825       174919 :   return build3_loc (input_location,
    3826              :                      COMPONENT_REF, type,
    3827       174919 :                      object, member, NULL_TREE);
    3828              : }
    3829              : 
    3830              : /* Return an expression for the MEMBER_NAME field in the internal
    3831              :    representation of PTRMEM, a pointer-to-member function.  (Each
    3832              :    pointer-to-member function type gets its own RECORD_TYPE so it is
    3833              :    more convenient to access the fields by name than by FIELD_DECL.)
    3834              :    This routine converts the NAME to a FIELD_DECL and then creates the
    3835              :    node for the complete expression.  */
    3836              : 
    3837              : tree
    3838       174835 : build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
    3839              : {
    3840       174835 :   tree ptrmem_type;
    3841       174835 :   tree member;
    3842              : 
    3843       174835 :   if (TREE_CODE (ptrmem) == CONSTRUCTOR)
    3844              :     {
    3845          234 :       for (auto &e: CONSTRUCTOR_ELTS (ptrmem))
    3846           90 :         if (e.index && DECL_P (e.index) && DECL_NAME (e.index) == member_name)
    3847           72 :           return e.value;
    3848            0 :       gcc_unreachable ();
    3849              :     }
    3850              : 
    3851              :   /* This code is a stripped down version of
    3852              :      build_class_member_access_expr.  It does not work to use that
    3853              :      routine directly because it expects the object to be of class
    3854              :      type.  */
    3855       174763 :   ptrmem_type = TREE_TYPE (ptrmem);
    3856       174763 :   gcc_assert (TYPE_PTRMEMFUNC_P (ptrmem_type));
    3857       262032 :   for (member = TYPE_FIELDS (ptrmem_type); member;
    3858        87269 :        member = DECL_CHAIN (member))
    3859       262032 :     if (DECL_NAME (member) == member_name)
    3860              :       break;
    3861       174763 :   return build_simple_component_ref (ptrmem, member);
    3862              : }
    3863              : 
    3864              : /* Return a TREE_LIST of namespace-scope overloads for the given operator,
    3865              :    and for any other relevant operator.  */
    3866              : 
    3867              : static tree
    3868    144435200 : op_unqualified_lookup (tree_code code, bool is_assign)
    3869              : {
    3870    144435200 :   tree lookups = NULL_TREE;
    3871              : 
    3872    144435200 :   if (cxx_dialect >= cxx20 && !is_assign)
    3873              :     {
    3874    136504143 :       if (code == NE_EXPR)
    3875              :         {
    3876              :           /* != can get rewritten in terms of ==.  */
    3877      8803662 :           tree fnname = ovl_op_identifier (false, EQ_EXPR);
    3878      8803662 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3879      8700618 :             lookups = tree_cons (fnname, fns, lookups);
    3880              :         }
    3881    127700481 :       else if (code == GT_EXPR || code == LE_EXPR
    3882    127700481 :                || code == LT_EXPR || code == GE_EXPR)
    3883              :         {
    3884              :           /* These can get rewritten in terms of <=>.  */
    3885     11939613 :           tree fnname = ovl_op_identifier (false, SPACESHIP_EXPR);
    3886     11939613 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3887     11285038 :             lookups = tree_cons (fnname, fns, lookups);
    3888              :         }
    3889              :     }
    3890              : 
    3891    144435200 :   tree fnname = ovl_op_identifier (is_assign, code);
    3892    144435200 :   if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3893     78109493 :     lookups = tree_cons (fnname, fns, lookups);
    3894              : 
    3895    144435200 :   if (lookups)
    3896              :     return lookups;
    3897              :   else
    3898     66092123 :     return build_tree_list (NULL_TREE, NULL_TREE);
    3899              : }
    3900              : 
    3901              : /* Create a DEPENDENT_OPERATOR_TYPE for a dependent operator expression of
    3902              :    the given operator.  LOOKUPS, if non-NULL, is the result of phase 1
    3903              :    name lookup for the given operator.  */
    3904              : 
    3905              : tree
    3906    150879910 : build_dependent_operator_type (tree lookups, tree_code code, bool is_assign)
    3907              : {
    3908    150879910 :   if (lookups)
    3909              :     /* We're partially instantiating a dependent operator expression, and
    3910              :        LOOKUPS is the result of phase 1 name lookup that we performed
    3911              :        earlier at template definition time, so just reuse the corresponding
    3912              :        DEPENDENT_OPERATOR_TYPE.  */
    3913      6444710 :     return TREE_TYPE (lookups);
    3914              : 
    3915              :   /* Otherwise we're processing a dependent operator expression at template
    3916              :      definition time, so perform phase 1 name lookup now.  */
    3917    144435200 :   lookups = op_unqualified_lookup (code, is_assign);
    3918              : 
    3919    144435200 :   tree type = cxx_make_type (DEPENDENT_OPERATOR_TYPE);
    3920    144435200 :   DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (type) = lookups;
    3921    144435200 :   TREE_TYPE (lookups) = type;
    3922    144435200 :   return type;
    3923              : }
    3924              : 
    3925              : /* Given an expression PTR for a pointer, return an expression
    3926              :    for the value pointed to.
    3927              :    ERRORSTRING is the name of the operator to appear in error messages.
    3928              : 
    3929              :    This function may need to overload OPERATOR_FNNAME.
    3930              :    Must also handle REFERENCE_TYPEs for C++.  */
    3931              : 
    3932              : tree
    3933     52435126 : build_x_indirect_ref (location_t loc, tree expr, ref_operator errorstring,
    3934              :                       tree lookups, tsubst_flags_t complain)
    3935              : {
    3936     52435126 :   tree orig_expr = expr;
    3937     52435126 :   tree rval;
    3938     52435126 :   tree overload = NULL_TREE;
    3939              : 
    3940     52435126 :   if (processing_template_decl)
    3941              :     {
    3942              :       /* Retain the type if we know the operand is a pointer.  */
    3943     30371273 :       if (TREE_TYPE (expr) && INDIRECT_TYPE_P (TREE_TYPE (expr)))
    3944              :         {
    3945     14881495 :           if (expr == current_class_ptr
    3946     14881495 :               || (TREE_CODE (expr) == NOP_EXPR
    3947      9879277 :                   && TREE_OPERAND (expr, 0) == current_class_ptr
    3948      9764760 :                   && (same_type_ignoring_top_level_qualifiers_p
    3949      9764760 :                         (TREE_TYPE (expr), TREE_TYPE (current_class_ptr)))))
    3950      9764759 :             return current_class_ref;
    3951      5116736 :           return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
    3952              :         }
    3953     15489778 :       if (type_dependent_expression_p (expr))
    3954              :         {
    3955     15347766 :           expr = build_min_nt_loc (loc, INDIRECT_REF, expr);
    3956     15347766 :           TREE_TYPE (expr)
    3957     15347766 :             = build_dependent_operator_type (lookups, INDIRECT_REF, false);
    3958     15347766 :           return expr;
    3959              :         }
    3960              :     }
    3961              : 
    3962     22205865 :   rval = build_new_op (loc, INDIRECT_REF, LOOKUP_NORMAL, expr,
    3963              :                        NULL_TREE, NULL_TREE, lookups,
    3964              :                        &overload, complain);
    3965     22205865 :   if (!rval)
    3966            0 :     rval = cp_build_indirect_ref (loc, expr, errorstring, complain);
    3967              : 
    3968     22205865 :   if (processing_template_decl && rval != error_mark_node)
    3969              :     {
    3970       140179 :       if (overload != NULL_TREE)
    3971       140148 :         return (build_min_non_dep_op_overload
    3972       140148 :                 (INDIRECT_REF, rval, overload, orig_expr));
    3973              : 
    3974           31 :       return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
    3975              :     }
    3976              :   else
    3977              :     return rval;
    3978              : }
    3979              : 
    3980              : /* Like c-family strict_aliasing_warning, but don't warn for dependent
    3981              :    types or expressions.  */
    3982              : 
    3983              : static bool
    3984       658168 : cp_strict_aliasing_warning (location_t loc, tree type, tree expr)
    3985              : {
    3986       658168 :   if (processing_template_decl)
    3987              :     {
    3988        45357 :       tree e = expr;
    3989        45357 :       STRIP_NOPS (e);
    3990        45357 :       if (dependent_type_p (type) || type_dependent_expression_p (e))
    3991              :         return false;
    3992              :     }
    3993       650736 :   return strict_aliasing_warning (loc, type, expr);
    3994              : }
    3995              : 
    3996              : /* The implementation of the above, and of indirection implied by other
    3997              :    constructs.  If DO_FOLD is true, fold away INDIRECT_REF of ADDR_EXPR.  */
    3998              : 
    3999              : static tree
    4000    370555756 : cp_build_indirect_ref_1 (location_t loc, tree ptr, ref_operator errorstring,
    4001              :                          tsubst_flags_t complain, bool do_fold)
    4002              : {
    4003    370555756 :   tree pointer, type;
    4004              : 
    4005              :   /* RO_NULL should only be used with the folding entry points below, not
    4006              :      cp_build_indirect_ref.  */
    4007    370555756 :   gcc_checking_assert (errorstring != RO_NULL || do_fold);
    4008              : 
    4009    370555756 :   if (ptr == current_class_ptr
    4010    370555756 :       || (TREE_CODE (ptr) == NOP_EXPR
    4011     40017825 :           && TREE_OPERAND (ptr, 0) == current_class_ptr
    4012     21260544 :           && (same_type_ignoring_top_level_qualifiers_p
    4013     21260544 :               (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr)))))
    4014     22806726 :     return current_class_ref;
    4015              : 
    4016    347749030 :   pointer = (TYPE_REF_P (TREE_TYPE (ptr))
    4017    347749030 :              ? ptr : decay_conversion (ptr, complain));
    4018    347749030 :   if (pointer == error_mark_node)
    4019              :     return error_mark_node;
    4020              : 
    4021    347743171 :   type = TREE_TYPE (pointer);
    4022              : 
    4023    347743171 :   if (INDIRECT_TYPE_P (type))
    4024              :     {
    4025              :       /* [expr.unary.op]
    4026              : 
    4027              :          If the type of the expression is "pointer to T," the type
    4028              :          of  the  result  is  "T."  */
    4029    347742577 :       tree t = TREE_TYPE (type);
    4030              : 
    4031    327640741 :       if ((CONVERT_EXPR_P (ptr)
    4032    239212809 :            || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
    4033    438630201 :           && (!CLASS_TYPE_P (t) || !CLASSTYPE_EMPTY_P (t)))
    4034              :         {
    4035              :           /* If a warning is issued, mark it to avoid duplicates from
    4036              :              the backend.  This only needs to be done at
    4037              :              warn_strict_aliasing > 2.  */
    4038     86966557 :           if (warn_strict_aliasing > 2
    4039     87520411 :               && cp_strict_aliasing_warning (EXPR_LOCATION (ptr),
    4040       553854 :                                              type, TREE_OPERAND (ptr, 0)))
    4041            6 :             suppress_warning (ptr, OPT_Wstrict_aliasing);
    4042              :         }
    4043              : 
    4044    347742577 :       if (VOID_TYPE_P (t))
    4045              :         {
    4046              :           /* A pointer to incomplete type (other than cv void) can be
    4047              :              dereferenced [expr.unary.op]/1  */
    4048           48 :           if (complain & tf_error)
    4049           19 :             error_at (loc, "%qT is not a pointer-to-object type", type);
    4050           48 :           return error_mark_node;
    4051              :         }
    4052    336483506 :       else if (do_fold && TREE_CODE (pointer) == ADDR_EXPR
    4053    355371579 :                && same_type_p (t, TREE_TYPE (TREE_OPERAND (pointer, 0))))
    4054              :         /* The POINTER was something like `&x'.  We simplify `*&x' to
    4055              :            `x'.  This can change the value category: '*&TARGET_EXPR'
    4056              :            is an lvalue and folding it into 'TARGET_EXPR' turns it into
    4057              :            a prvalue of class type.  */
    4058      7628972 :         return TREE_OPERAND (pointer, 0);
    4059              :       else
    4060              :         {
    4061    340113557 :           tree ref = build1 (INDIRECT_REF, t, pointer);
    4062              : 
    4063              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    4064              :              so that we get the proper error message if the result is used
    4065              :              to assign to.  Also, &* is supposed to be a no-op.  */
    4066    340113557 :           TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
    4067    340113557 :           TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
    4068    340113557 :           TREE_SIDE_EFFECTS (ref)
    4069    340113557 :             = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (pointer));
    4070    340113557 :           return ref;
    4071              :         }
    4072              :     }
    4073          594 :   else if (!(complain & tf_error))
    4074              :     /* Don't emit any errors; we'll just return ERROR_MARK_NODE later.  */
    4075              :     ;
    4076              :   /* `pointer' won't be an error_mark_node if we were given a
    4077              :      pointer to member, so it's cool to check for this here.  */
    4078           41 :   else if (TYPE_PTRMEM_P (type))
    4079           15 :     switch (errorstring)
    4080              :       {
    4081            0 :          case RO_ARRAY_INDEXING:
    4082            0 :            error_at (loc,
    4083              :                      "invalid use of array indexing on pointer to member");
    4084            0 :            break;
    4085           12 :          case RO_UNARY_STAR:
    4086           12 :            error_at (loc, "invalid use of unary %<*%> on pointer to member");
    4087           12 :            break;
    4088            0 :          case RO_IMPLICIT_CONVERSION:
    4089            0 :            error_at (loc, "invalid use of implicit conversion on pointer "
    4090              :                      "to member");
    4091            0 :            break;
    4092            3 :          case RO_ARROW_STAR:
    4093            3 :            error_at (loc, "left hand operand of %<->*%> must be a pointer to "
    4094              :                      "class, but is a pointer to member of type %qT", type);
    4095            3 :            break;
    4096            0 :          default:
    4097            0 :            gcc_unreachable ();
    4098              :       }
    4099           26 :   else if (pointer != error_mark_node)
    4100           26 :     invalid_indirection_error (loc, type, errorstring);
    4101              : 
    4102          594 :   return error_mark_node;
    4103              : }
    4104              : 
    4105              : /* Entry point used by c-common, which expects folding.  */
    4106              : 
    4107              : tree
    4108        70310 : build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring)
    4109              : {
    4110        70310 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring,
    4111        70310 :                                   tf_warning_or_error, true);
    4112              : }
    4113              : 
    4114              : /* Entry point used by internal indirection needs that don't correspond to any
    4115              :    syntactic construct.  */
    4116              : 
    4117              : tree
    4118    340336781 : cp_build_fold_indirect_ref (tree pointer)
    4119              : {
    4120    340336781 :   return cp_build_indirect_ref_1 (input_location, pointer, RO_NULL,
    4121    340336781 :                                   tf_warning_or_error, true);
    4122              : }
    4123              : 
    4124              : /* Entry point used by indirection needs that correspond to some syntactic
    4125              :    construct.  */
    4126              : 
    4127              : tree
    4128     30148665 : cp_build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring,
    4129              :                        tsubst_flags_t complain)
    4130              : {
    4131     30148665 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring, complain, false);
    4132              : }
    4133              : 
    4134              : /* This handles expressions of the form "a[i]", which denotes
    4135              :    an array reference.
    4136              : 
    4137              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    4138              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    4139              :    This avoids forcing the array out of registers, and can work on
    4140              :    arrays that are not lvalues (for example, members of structures returned
    4141              :    by functions).
    4142              : 
    4143              :    If INDEX is of some user-defined type, it must be converted to
    4144              :    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
    4145              :    will inherit the type of the array, which will be some pointer type.
    4146              : 
    4147              :    LOC is the location to use in building the array reference.  */
    4148              : 
    4149              : tree
    4150      6303148 : cp_build_array_ref (location_t loc, tree array, tree idx,
    4151              :                     tsubst_flags_t complain)
    4152              : {
    4153      6303148 :   tree ret;
    4154              : 
    4155      6303148 :   if (idx == 0)
    4156              :     {
    4157            0 :       if (complain & tf_error)
    4158            0 :         error_at (loc, "subscript missing in array reference");
    4159            0 :       return error_mark_node;
    4160              :     }
    4161              : 
    4162      6303148 :   if (TREE_TYPE (array) == error_mark_node
    4163      6303148 :       || TREE_TYPE (idx) == error_mark_node)
    4164              :     return error_mark_node;
    4165              : 
    4166              :   /* 0[array] */
    4167      6303148 :   if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE
    4168      6303148 :       && TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
    4169              :     {
    4170           10 :       std::swap (array, idx);
    4171              : 
    4172           10 :       tree first = NULL_TREE;
    4173           10 :       if (flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (array))
    4174            9 :         idx = first = save_expr (idx);
    4175           10 :       ret = cp_build_array_ref (loc, array, idx, complain);
    4176              : 
    4177           10 :       if (first)
    4178            9 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4179              :       return ret;
    4180              :     }
    4181              : 
    4182              :   /* If ARRAY is a COMPOUND_EXPR or COND_EXPR, move our reference
    4183              :      inside it.  */
    4184      6303138 :   switch (TREE_CODE (array))
    4185              :     {
    4186           28 :     case COMPOUND_EXPR:
    4187           28 :       {
    4188           28 :         tree value = cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    4189              :                                          complain);
    4190           28 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
    4191           28 :                       TREE_OPERAND (array, 0), value);
    4192           28 :         SET_EXPR_LOCATION (ret, loc);
    4193           28 :         return ret;
    4194              :       }
    4195              : 
    4196           73 :     case COND_EXPR:
    4197           73 :       tree op0, op1, op2;
    4198           73 :       op0 = TREE_OPERAND (array, 0);
    4199           73 :       op1 = TREE_OPERAND (array, 1);
    4200           73 :       op2 = TREE_OPERAND (array, 2);
    4201           73 :       if (TREE_SIDE_EFFECTS (idx) || !tree_invariant_p (idx))
    4202              :         {
    4203              :           /* If idx could possibly have some SAVE_EXPRs, turning
    4204              :              (op0 ? op1 : op2)[idx] into
    4205              :              op0 ? op1[idx] : op2[idx] can lead into temporaries
    4206              :              initialized in one conditional path and uninitialized
    4207              :              uses of them in the other path.
    4208              :              And if idx is a really large expression, evaluating it
    4209              :              twice is also not optimal.
    4210              :              On the other side, op0 must be sequenced before evaluation
    4211              :              of op1 and op2 and for C++17 op0, op1 and op2 must be
    4212              :              sequenced before idx.
    4213              :              If idx is INTEGER_CST, we can just do the optimization
    4214              :              without any SAVE_EXPRs, if op1 and op2 are both ARRAY_TYPE
    4215              :              VAR_DECLs or COMPONENT_REFs thereof (so their address
    4216              :              is constant or relative to frame), optimize into
    4217              :              (SAVE_EXPR <op0>, SAVE_EXPR <idx>, SAVE_EXPR <op0>)
    4218              :              ? op1[SAVE_EXPR <idx>] : op2[SAVE_EXPR <idx>]
    4219              :              Otherwise avoid this optimization.  */
    4220           58 :           if (flag_strong_eval_order == 2)
    4221              :             {
    4222           39 :               if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    4223              :                 {
    4224           30 :                   if (!address_invariant_p (op1) || !address_invariant_p (op2))
    4225              :                     {
    4226              :                       /* Force default conversion on array if
    4227              :                          we can't optimize this and array is ARRAY_TYPE
    4228              :                          COND_EXPR, we can't leave COND_EXPRs with
    4229              :                          ARRAY_TYPE in the IL.  */
    4230            8 :                       array = cp_default_conversion (array, complain);
    4231            8 :                       if (error_operand_p (array))
    4232            0 :                         return error_mark_node;
    4233              :                       break;
    4234              :                     }
    4235              :                 }
    4236           16 :               else if (!POINTER_TYPE_P (TREE_TYPE (array))
    4237            2 :                        || !tree_invariant_p (op1)
    4238           11 :                        || !tree_invariant_p (op2))
    4239              :                 break;
    4240              :             }
    4241           43 :           if (TREE_SIDE_EFFECTS (idx))
    4242              :             {
    4243           18 :               idx = save_expr (idx);
    4244           18 :               op0 = save_expr (op0);
    4245           18 :               warning_sentinel w (warn_unused_value);
    4246           18 :               tree tem = build_compound_expr (loc, op0, idx);
    4247           18 :               op0 = build_compound_expr (loc, tem, op0);
    4248           18 :             }
    4249              :         }
    4250           58 :       op1 = cp_build_array_ref (loc, op1, idx, complain);
    4251           58 :       op2 = cp_build_array_ref (loc, op2, idx, complain);
    4252           58 :       ret = build_conditional_expr (loc, op0, op1, op2, complain);
    4253           58 :       protected_set_expr_location (ret, loc);
    4254           58 :       return ret;
    4255              : 
    4256              :     default:
    4257              :       break;
    4258              :     }
    4259              : 
    4260      6303052 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, idx);
    4261              : 
    4262      6303052 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    4263              :     {
    4264      1938093 :       tree rval, type;
    4265              : 
    4266      1938093 :       warn_array_subscript_with_type_char (loc, idx);
    4267              : 
    4268      1938093 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
    4269              :         {
    4270            6 :           if (complain & tf_error)
    4271            6 :             error_at (loc, "array subscript is not an integer");
    4272            6 :           return error_mark_node;
    4273              :         }
    4274              : 
    4275              :       /* Apply integral promotions *after* noticing character types.
    4276              :          (It is unclear why we do these promotions -- the standard
    4277              :          does not say that we should.  In fact, the natural thing would
    4278              :          seem to be to convert IDX to ptrdiff_t; we're performing
    4279              :          pointer arithmetic.)  */
    4280      1938087 :       idx = cp_perform_integral_promotions (idx, complain);
    4281              : 
    4282      1938087 :       idx = maybe_fold_non_dependent_expr (idx, complain);
    4283              : 
    4284              :       /* An array that is indexed by a non-constant
    4285              :          cannot be stored in a register; we must be able to do
    4286              :          address arithmetic on its address.
    4287              :          Likewise an array of elements of variable size.  */
    4288      1938087 :       if (TREE_CODE (idx) != INTEGER_CST
    4289      1938087 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    4290       939293 :               && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))))
    4291              :                   != INTEGER_CST)))
    4292              :         {
    4293      1000054 :           if (!cxx_mark_addressable (array, true))
    4294            0 :             return error_mark_node;
    4295              :         }
    4296              : 
    4297              :       /* An array that is indexed by a constant value which is not within
    4298              :          the array bounds cannot be stored in a register either; because we
    4299              :          would get a crash in store_bit_field/extract_bit_field when trying
    4300              :          to access a non-existent part of the register.  */
    4301      1938087 :       if (TREE_CODE (idx) == INTEGER_CST
    4302       939296 :           && TYPE_DOMAIN (TREE_TYPE (array))
    4303      2875985 :           && ! int_fits_type_p (idx, TYPE_DOMAIN (TREE_TYPE (array))))
    4304              :         {
    4305         3124 :           if (!cxx_mark_addressable (array))
    4306            0 :             return error_mark_node;
    4307              :         }
    4308              : 
    4309              :       /* Note in C++ it is valid to subscript a `register' array, since
    4310              :          it is valid to take the address of something with that
    4311              :          storage specification.  */
    4312      1938087 :       if (extra_warnings)
    4313              :         {
    4314        38850 :           tree foo = array;
    4315        59536 :           while (TREE_CODE (foo) == COMPONENT_REF)
    4316        20686 :             foo = TREE_OPERAND (foo, 0);
    4317            8 :           if (VAR_P (foo) && DECL_REGISTER (foo)
    4318        38850 :               && (complain & tf_warning))
    4319            0 :             warning_at (loc, OPT_Wextra,
    4320              :                         "subscripting array declared %<register%>");
    4321              :         }
    4322              : 
    4323      1938087 :       type = TREE_TYPE (TREE_TYPE (array));
    4324      1938087 :       rval = build4 (ARRAY_REF, type, array, idx, NULL_TREE, NULL_TREE);
    4325              :       /* Array ref is const/volatile if the array elements are
    4326              :          or if the array is..  */
    4327      5814261 :       TREE_READONLY (rval)
    4328      1938087 :         |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
    4329      5814261 :       TREE_SIDE_EFFECTS (rval)
    4330      1938087 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
    4331      3876174 :       TREE_THIS_VOLATILE (rval)
    4332      1938087 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
    4333      1938087 :       ret = require_complete_type (rval, complain);
    4334      1938087 :       protected_set_expr_location (ret, loc);
    4335      1938087 :       if (non_lvalue)
    4336        38459 :         ret = non_lvalue_loc (loc, ret);
    4337              :       return ret;
    4338              :     }
    4339              : 
    4340      4364959 :   {
    4341      4364959 :     tree ar = cp_default_conversion (array, complain);
    4342      4364959 :     tree ind = cp_default_conversion (idx, complain);
    4343      4364959 :     tree first = NULL_TREE;
    4344              : 
    4345      2825298 :     if (!processing_template_decl && flag_strong_eval_order == 2
    4346      7148072 :         && TREE_SIDE_EFFECTS (ind))
    4347        94367 :       ar = first = save_expr (ar);
    4348              : 
    4349              :     /* Put the integer in IND to simplify error checking.  */
    4350      4364959 :     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
    4351           57 :       std::swap (ar, ind);
    4352              : 
    4353      4364959 :     if (ar == error_mark_node || ind == error_mark_node)
    4354              :       return error_mark_node;
    4355              : 
    4356      4364959 :     if (!TYPE_PTR_P (TREE_TYPE (ar)))
    4357              :       {
    4358           74 :         if (complain & tf_error)
    4359            3 :           error_at (loc, "subscripted value is neither array nor pointer");
    4360           74 :         return error_mark_node;
    4361              :       }
    4362      4364885 :     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
    4363              :       {
    4364            0 :         if (complain & tf_error)
    4365            0 :           error_at (loc, "array subscript is not an integer");
    4366            0 :         return error_mark_node;
    4367              :       }
    4368              : 
    4369      4364885 :     warn_array_subscript_with_type_char (loc, idx);
    4370              : 
    4371      4364885 :     ret = cp_build_binary_op (input_location, PLUS_EXPR, ar, ind, complain);
    4372      4364885 :     if (first)
    4373        94367 :       ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4374      4364885 :     ret = cp_build_indirect_ref (loc, ret, RO_ARRAY_INDEXING, complain);
    4375      4364885 :     protected_set_expr_location (ret, loc);
    4376      4364885 :     if (non_lvalue)
    4377            0 :       ret = non_lvalue_loc (loc, ret);
    4378              :     return ret;
    4379              :   }
    4380              : }
    4381              : 
    4382              : /* Entry point for Obj-C++.  */
    4383              : 
    4384              : tree
    4385      3804575 : build_array_ref (location_t loc, tree array, tree idx)
    4386              : {
    4387      3804575 :   return cp_build_array_ref (loc, array, idx, tf_warning_or_error);
    4388              : }
    4389              : 
    4390              : /* Resolve a pointer to member function.  INSTANCE is the object
    4391              :    instance to use, if the member points to a virtual member.
    4392              : 
    4393              :    This used to avoid checking for virtual functions if basetype
    4394              :    has no virtual functions, according to an earlier ANSI draft.
    4395              :    With the final ISO C++ rules, such an optimization is
    4396              :    incorrect: A pointer to a derived member can be static_cast
    4397              :    to pointer-to-base-member, as long as the dynamic object
    4398              :    later has the right member.  So now we only do this optimization
    4399              :    when we know the dynamic type of the object.  */
    4400              : 
    4401              : tree
    4402        87091 : get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function,
    4403              :                                   tsubst_flags_t complain)
    4404              : {
    4405        87091 :   if (TREE_CODE (function) == OFFSET_REF)
    4406            0 :     function = TREE_OPERAND (function, 1);
    4407              : 
    4408        87091 :   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
    4409              :     {
    4410        87091 :       tree idx, delta, e1, e2, e3, vtbl;
    4411        87091 :       bool nonvirtual;
    4412        87091 :       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
    4413        87091 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (fntype));
    4414              : 
    4415        87091 :       tree instance_ptr = *instance_ptrptr;
    4416        87091 :       tree instance_save_expr = 0;
    4417        87091 :       if (instance_ptr == error_mark_node)
    4418              :         {
    4419            0 :           if (TREE_CODE (function) == PTRMEM_CST)
    4420              :             {
    4421              :               /* Extracting the function address from a pmf is only
    4422              :                  allowed with -Wno-pmf-conversions. It only works for
    4423              :                  pmf constants.  */
    4424            0 :               e1 = build_addr_func (PTRMEM_CST_MEMBER (function), complain);
    4425            0 :               e1 = convert (fntype, e1);
    4426            0 :               return e1;
    4427              :             }
    4428              :           else
    4429              :             {
    4430            0 :               if (complain & tf_error)
    4431            0 :                 error ("object missing in use of %qE", function);
    4432            0 :               return error_mark_node;
    4433              :             }
    4434              :         }
    4435              : 
    4436              :       /* True if we know that the dynamic type of the object doesn't have
    4437              :          virtual functions, so we can assume the PFN field is a pointer.  */
    4438        87091 :       nonvirtual = (COMPLETE_TYPE_P (basetype)
    4439        87055 :                     && !TYPE_POLYMORPHIC_P (basetype)
    4440       117095 :                     && resolves_to_fixed_type_p (instance_ptr, 0));
    4441              : 
    4442              :       /* If we don't really have an object (i.e. in an ill-formed
    4443              :          conversion from PMF to pointer), we can't resolve virtual
    4444              :          functions anyway.  */
    4445        86837 :       if (!nonvirtual && is_dummy_object (instance_ptr))
    4446              :         nonvirtual = true;
    4447              : 
    4448              :       /* Use force_target_expr even when instance_ptr doesn't have
    4449              :          side-effects, unless it is a simple decl or constant, so
    4450              :          that we don't ubsan instrument the expression multiple times.
    4451              :          Don't use save_expr, as save_expr can avoid building a SAVE_EXPR
    4452              :          and building a SAVE_EXPR manually can be optimized away during
    4453              :          cp_fold.  See PR116449 and PR117259.  */
    4454        87091 :       if (TREE_SIDE_EFFECTS (instance_ptr)
    4455        87091 :           || (!nonvirtual
    4456        48575 :               && !DECL_P (instance_ptr)
    4457        48575 :               && !TREE_CONSTANT (instance_ptr)))
    4458        86518 :         instance_ptr = instance_save_expr
    4459        86518 :           = get_internal_target_expr (instance_ptr);
    4460              : 
    4461              :       /* See above comment.  */
    4462        87091 :       if (TREE_SIDE_EFFECTS (function)
    4463        87091 :           || (!nonvirtual
    4464        67527 :               && !DECL_P (function)
    4465        67515 :               && !TREE_CONSTANT (function)))
    4466        86636 :         function = get_internal_target_expr (function);
    4467              : 
    4468              :       /* Start by extracting all the information from the PMF itself.  */
    4469        87091 :       e3 = pfn_from_ptrmemfunc (function);
    4470        87091 :       delta = delta_from_ptrmemfunc (function);
    4471        87091 :       idx = build1 (NOP_EXPR, vtable_index_type, e3);
    4472        87091 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
    4473              :         {
    4474        87091 :           sanitize_code_type flag_sanitize_save;
    4475        87091 :         case ptrmemfunc_vbit_in_pfn:
    4476        87091 :           e1 = cp_build_binary_op (input_location,
    4477              :                                    BIT_AND_EXPR, idx, integer_one_node,
    4478              :                                    complain);
    4479        87091 :           idx = cp_build_binary_op (input_location,
    4480              :                                     MINUS_EXPR, idx, integer_one_node,
    4481              :                                     complain);
    4482        87091 :           if (idx == error_mark_node)
    4483              :             return error_mark_node;
    4484        87091 :           break;
    4485              : 
    4486              :         case ptrmemfunc_vbit_in_delta:
    4487              :           e1 = cp_build_binary_op (input_location,
    4488              :                                    BIT_AND_EXPR, delta, integer_one_node,
    4489              :                                    complain);
    4490              :           /* Don't instrument the RSHIFT_EXPR we're about to create because
    4491              :              we're going to use DELTA number of times, and that wouldn't play
    4492              :              well with SAVE_EXPRs therein.  */
    4493              :           flag_sanitize_save = flag_sanitize;
    4494              :           flag_sanitize = 0;
    4495              :           delta = cp_build_binary_op (input_location,
    4496              :                                       RSHIFT_EXPR, delta, integer_one_node,
    4497              :                                       complain);
    4498              :           flag_sanitize = flag_sanitize_save;
    4499              :           if (delta == error_mark_node)
    4500              :             return error_mark_node;
    4501              :           break;
    4502              : 
    4503              :         default:
    4504              :           gcc_unreachable ();
    4505              :         }
    4506              : 
    4507        87091 :       if (e1 == error_mark_node)
    4508              :         return error_mark_node;
    4509              : 
    4510              :       /* Convert down to the right base before using the instance.  A
    4511              :          special case is that in a pointer to member of class C, C may
    4512              :          be incomplete.  In that case, the function will of course be
    4513              :          a member of C, and no conversion is required.  In fact,
    4514              :          lookup_base will fail in that case, because incomplete
    4515              :          classes do not have BINFOs.  */
    4516        87091 :       if (!same_type_ignoring_top_level_qualifiers_p
    4517        87091 :           (basetype, TREE_TYPE (TREE_TYPE (instance_ptr))))
    4518              :         {
    4519           81 :           basetype = lookup_base (TREE_TYPE (TREE_TYPE (instance_ptr)),
    4520              :                                   basetype, ba_check, NULL, complain);
    4521           81 :           instance_ptr = build_base_path (PLUS_EXPR, instance_ptr, basetype,
    4522              :                                           1, complain);
    4523           81 :           if (instance_ptr == error_mark_node)
    4524              :             return error_mark_node;
    4525              :         }
    4526              :       /* ...and then the delta in the PMF.  */
    4527        87091 :       instance_ptr = fold_build_pointer_plus (instance_ptr, delta);
    4528              : 
    4529              :       /* Hand back the adjusted 'this' argument to our caller.  */
    4530        87091 :       *instance_ptrptr = instance_ptr;
    4531              : 
    4532        87091 :       if (nonvirtual)
    4533              :         /* Now just return the pointer.  */
    4534              :         return e3;
    4535              : 
    4536              :       /* Next extract the vtable pointer from the object.  */
    4537        86819 :       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
    4538              :                      instance_ptr);
    4539        86819 :       vtbl = cp_build_fold_indirect_ref (vtbl);
    4540        86819 :       if (vtbl == error_mark_node)
    4541              :         return error_mark_node;
    4542              : 
    4543              :       /* Finally, extract the function pointer from the vtable.  */
    4544        86819 :       e2 = fold_build_pointer_plus_loc (input_location, vtbl, idx);
    4545        86819 :       e2 = cp_build_fold_indirect_ref (e2);
    4546        86819 :       if (e2 == error_mark_node)
    4547              :         return error_mark_node;
    4548        86819 :       TREE_CONSTANT (e2) = 1;
    4549              : 
    4550              :       /* When using function descriptors, the address of the
    4551              :          vtable entry is treated as a function pointer.  */
    4552        86819 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
    4553              :         e2 = build1 (NOP_EXPR, TREE_TYPE (e2),
    4554              :                      cp_build_addr_expr (e2, complain));
    4555              : 
    4556        86819 :       e2 = fold_convert (TREE_TYPE (e3), e2);
    4557        86819 :       e1 = build_conditional_expr (input_location, e1, e2, e3, complain);
    4558        86819 :       if (e1 == error_mark_node)
    4559              :         return error_mark_node;
    4560              : 
    4561              :       /* Make sure this doesn't get evaluated first inside one of the
    4562              :          branches of the COND_EXPR.  */
    4563        86819 :       if (instance_save_expr)
    4564        86470 :         e1 = build2 (COMPOUND_EXPR, TREE_TYPE (e1),
    4565              :                      instance_save_expr, e1);
    4566              : 
    4567              :       function = e1;
    4568              :     }
    4569              :   return function;
    4570              : }
    4571              : 
    4572              : /* Used by the C-common bits.  */
    4573              : tree
    4574            0 : build_function_call (location_t /*loc*/,
    4575              :                      tree function, tree params)
    4576              : {
    4577            0 :   return cp_build_function_call (function, params, tf_warning_or_error);
    4578              : }
    4579              : 
    4580              : /* Used by the C-common bits.  */
    4581              : tree
    4582       343413 : build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
    4583              :                          tree function, vec<tree, va_gc> *params,
    4584              :                          vec<tree, va_gc> * /*origtypes*/, tree orig_function)
    4585              : {
    4586       343413 :   vec<tree, va_gc> *orig_params = params;
    4587       343413 :   tree ret = cp_build_function_call_vec (function, &params,
    4588              :                                          tf_warning_or_error, orig_function);
    4589              : 
    4590              :   /* cp_build_function_call_vec can reallocate PARAMS by adding
    4591              :      default arguments.  That should never happen here.  Verify
    4592              :      that.  */
    4593       343413 :   gcc_assert (params == orig_params);
    4594              : 
    4595       343413 :   return ret;
    4596              : }
    4597              : 
    4598              : /* Build a function call using a tree list of arguments.  */
    4599              : 
    4600              : static tree
    4601            0 : cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
    4602              : {
    4603            0 :   tree ret;
    4604              : 
    4605            0 :   releasing_vec vec;
    4606            0 :   for (; params != NULL_TREE; params = TREE_CHAIN (params))
    4607            0 :     vec_safe_push (vec, TREE_VALUE (params));
    4608            0 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4609            0 :   return ret;
    4610            0 : }
    4611              : 
    4612              : /* Build a function call using varargs.  */
    4613              : 
    4614              : tree
    4615       608265 : cp_build_function_call_nary (tree function, tsubst_flags_t complain, ...)
    4616              : {
    4617       608265 :   va_list args;
    4618       608265 :   tree ret, t;
    4619              : 
    4620       608265 :   releasing_vec vec;
    4621       608265 :   va_start (args, complain);
    4622      1519675 :   for (t = va_arg (args, tree); t != NULL_TREE; t = va_arg (args, tree))
    4623       911410 :     vec_safe_push (vec, t);
    4624       608265 :   va_end (args);
    4625       608265 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4626       608265 :   return ret;
    4627       608265 : }
    4628              : 
    4629              : /* C++ implementation of callback for use when checking param types.  */
    4630              : 
    4631              : bool
    4632           18 : cp_comp_parm_types (tree wanted_type, tree actual_type)
    4633              : {
    4634           18 :   if (TREE_CODE (wanted_type) == POINTER_TYPE
    4635           18 :       && TREE_CODE (actual_type) == POINTER_TYPE)
    4636           15 :     return same_or_base_type_p (TREE_TYPE (wanted_type),
    4637              :                                 TREE_TYPE (actual_type));
    4638              :   return false;
    4639              : }
    4640              : 
    4641              : /* Build a function call using a vector of arguments.
    4642              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4643              :    ORIG_FNDECL is the original function decl, otherwise it is null.
    4644              :    PARAMS may be NULL if there are no parameters.  This changes the
    4645              :    contents of PARAMS.  */
    4646              : 
    4647              : tree
    4648      7853733 : cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
    4649              :                             tsubst_flags_t complain, tree orig_fndecl)
    4650              : {
    4651      7853733 :   tree fntype, fndecl;
    4652      7853733 :   int is_method;
    4653      7853733 :   tree original = function;
    4654      7853733 :   int nargs;
    4655      7853733 :   tree *argarray;
    4656      7853733 :   tree parm_types;
    4657      7853733 :   vec<tree, va_gc> *allocated = NULL;
    4658      7853733 :   tree ret;
    4659              : 
    4660              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4661              :      expressions, like those used for ObjC messenger dispatches.  */
    4662      7853733 :   if (params != NULL && !vec_safe_is_empty (*params))
    4663      2238440 :     function = objc_rewrite_function_call (function, (**params)[0]);
    4664              : 
    4665              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4666              :      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
    4667      7853733 :   if (TREE_CODE (function) == NOP_EXPR
    4668      7853733 :       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
    4669           15 :     function = TREE_OPERAND (function, 0);
    4670              : 
    4671      7853733 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4672              :     {
    4673      1686230 :       if (!mark_used (function, complain))
    4674           24 :         return error_mark_node;
    4675      1686206 :       fndecl = function;
    4676              : 
    4677              :       /* For target_version semantics, the function set cannot be called
    4678              :          if there is no default version in scope.  */
    4679      1686206 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    4680              :            && !is_function_default_version (fndecl))
    4681              :          {
    4682              :            if (complain & tf_error)
    4683              :             error ("no default version in scope");
    4684              :            return error_mark_node;
    4685              :          }
    4686              : 
    4687              :       /* Convert anything with function type to a pointer-to-function.  */
    4688      1686206 :       if (DECL_MAIN_P (function))
    4689              :         {
    4690            0 :           if (complain & tf_error)
    4691            0 :             pedwarn (input_location, OPT_Wpedantic,
    4692              :                      "ISO C++ forbids calling %<::main%> from within program");
    4693              :           else
    4694            0 :             return error_mark_node;
    4695              :         }
    4696      1686206 :       function = build_addr_func (function, complain);
    4697              :     }
    4698              :   else
    4699              :     {
    4700      6167503 :       fndecl = NULL_TREE;
    4701              : 
    4702      6167503 :       function = build_addr_func (function, complain);
    4703              :     }
    4704              : 
    4705      7853709 :   if (function == error_mark_node)
    4706              :     return error_mark_node;
    4707              : 
    4708      7853607 :   fntype = TREE_TYPE (function);
    4709              : 
    4710      7853607 :   if (TYPE_PTRMEMFUNC_P (fntype))
    4711              :     {
    4712           15 :       if (complain & tf_error)
    4713           15 :         error ("must use %<.*%> or %<->*%> to call pointer-to-member "
    4714              :                "function in %<%E (...)%>, e.g. %<(... ->* %E) (...)%>",
    4715              :                original, original);
    4716           15 :       return error_mark_node;
    4717              :     }
    4718              : 
    4719     15707184 :   is_method = (TYPE_PTR_P (fntype)
    4720      7853592 :                && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
    4721              : 
    4722      7853592 :   if (!(TYPE_PTRFN_P (fntype)
    4723        89302 :         || is_method
    4724         2269 :         || TREE_CODE (function) == TEMPLATE_ID_EXPR))
    4725              :     {
    4726         2269 :       if (complain & tf_error)
    4727              :         {
    4728          178 :           if (is_stub_object (original))
    4729            3 :             error_at (input_location,
    4730              :                       "%qT cannot be used as a function",
    4731            3 :                       TREE_TYPE (original));
    4732          175 :           else if (!flag_diagnostics_show_caret)
    4733          175 :             error_at (input_location,
    4734              :                       "%qE cannot be used as a function", original);
    4735            0 :           else if (DECL_P (original))
    4736            0 :             error_at (input_location,
    4737              :                       "%qD cannot be used as a function", original);
    4738              :           else
    4739            0 :             error_at (input_location,
    4740              :                       "expression cannot be used as a function");
    4741              :         }
    4742              : 
    4743         2269 :       return error_mark_node;
    4744              :     }
    4745              : 
    4746              :   /* fntype now gets the type of function pointed to.  */
    4747      7851323 :   fntype = TREE_TYPE (fntype);
    4748      7851323 :   parm_types = TYPE_ARG_TYPES (fntype);
    4749              : 
    4750      7851323 :   if (params == NULL)
    4751              :     {
    4752       159624 :       allocated = make_tree_vector ();
    4753       159624 :       params = &allocated;
    4754              :     }
    4755              : 
    4756      7851323 :     nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
    4757              :                                complain);
    4758      7851323 :   if (nargs < 0)
    4759         1970 :     return error_mark_node;
    4760              : 
    4761      7849353 :   argarray = (*params)->address ();
    4762              : 
    4763              :   /* Check for errors in format strings and inappropriately
    4764              :      null parameters.  */
    4765      7849353 :   bool warned_p
    4766      7849353 :     = ((complain & tf_warning)
    4767      7849353 :        && check_function_arguments (input_location, fndecl, fntype,
    4768              :                                     nargs, argarray, NULL,
    4769      7849353 :                                     cp_comp_parm_types));
    4770              : 
    4771      7849353 :   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
    4772              : 
    4773      7849353 :   if (warned_p)
    4774              :     {
    4775           27 :       tree c = extract_call_expr (ret);
    4776           27 :       if (TREE_CODE (c) == CALL_EXPR)
    4777           27 :         suppress_warning (c, OPT_Wnonnull);
    4778              :     }
    4779              : 
    4780      7849353 :   if (allocated != NULL)
    4781       159624 :     release_tree_vector (allocated);
    4782              : 
    4783              :   return ret;
    4784              : }
    4785              : 
    4786              : /* Subroutine of convert_arguments.
    4787              :    Print an error message about a wrong number of arguments.  */
    4788              : 
    4789              : static void
    4790          162 : error_args_num (location_t loc, tree fndecl, bool too_many_p)
    4791              : {
    4792          162 :   if (fndecl)
    4793              :     {
    4794          126 :       auto_diagnostic_group d;
    4795          126 :       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
    4796              :         {
    4797            0 :           if (DECL_NAME (fndecl) == NULL_TREE
    4798            0 :               || (DECL_NAME (fndecl)
    4799            0 :                   == DECL_NAME (TYPE_NAME (DECL_CONTEXT (fndecl)))))
    4800            0 :             error_at (loc,
    4801              :                       too_many_p
    4802              :                       ? G_("too many arguments to constructor %q#D")
    4803              :                       : G_("too few arguments to constructor %q#D"),
    4804              :                       fndecl);
    4805              :           else
    4806            0 :             error_at (loc,
    4807              :                       too_many_p
    4808              :                       ? G_("too many arguments to member function %q#D")
    4809              :                       : G_("too few arguments to member function %q#D"),
    4810              :                       fndecl);
    4811              :         }
    4812              :       else
    4813          189 :         error_at (loc,
    4814              :                   too_many_p
    4815              :                   ? G_("too many arguments to function %q#D")
    4816              :                   : G_("too few arguments to function %q#D"),
    4817              :                   fndecl);
    4818          126 :       if (!DECL_IS_UNDECLARED_BUILTIN (fndecl))
    4819           87 :         inform (DECL_SOURCE_LOCATION (fndecl), "declared here");
    4820          126 :     }
    4821              :   else
    4822              :     {
    4823           36 :       if (c_dialect_objc ()  &&  objc_message_selector ())
    4824            0 :         error_at (loc,
    4825              :                   too_many_p
    4826              :                   ? G_("too many arguments to method %q#D")
    4827              :                   : G_("too few arguments to method %q#D"),
    4828              :                   objc_message_selector ());
    4829              :       else
    4830           57 :         error_at (loc, too_many_p ? G_("too many arguments to function")
    4831              :                                   : G_("too few arguments to function"));
    4832              :     }
    4833          162 : }
    4834              : 
    4835              : /* Convert the actual parameter expressions in the list VALUES to the
    4836              :    types in the list TYPELIST.  The converted expressions are stored
    4837              :    back in the VALUES vector.
    4838              :    If parmdecls is exhausted, or when an element has NULL as its type,
    4839              :    perform the default conversions.
    4840              : 
    4841              :    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
    4842              : 
    4843              :    This is also where warnings about wrong number of args are generated.
    4844              : 
    4845              :    Returns the actual number of arguments processed (which might be less
    4846              :    than the length of the vector), or -1 on error.
    4847              : 
    4848              :    In C++, unspecified trailing parameters can be filled in with their
    4849              :    default arguments, if such were specified.  Do so here.  */
    4850              : 
    4851              : static int
    4852      7851323 : convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
    4853              :                    int flags, tsubst_flags_t complain)
    4854              : {
    4855      7851323 :   tree typetail;
    4856      7851323 :   unsigned int i;
    4857              : 
    4858              :   /* Argument passing is always copy-initialization.  */
    4859      7851323 :   flags |= LOOKUP_ONLYCONVERTING;
    4860              : 
    4861     12715217 :   for (i = 0, typetail = typelist;
    4862     12715217 :        i < vec_safe_length (*values);
    4863              :        i++)
    4864              :     {
    4865      9730942 :       tree type = typetail ? TREE_VALUE (typetail) : 0;
    4866      4865694 :       tree val = (**values)[i];
    4867              : 
    4868      4865694 :       if (val == error_mark_node || type == error_mark_node)
    4869              :         return -1;
    4870              : 
    4871      4865688 :       if (type == void_type_node)
    4872              :         {
    4873          212 :           if (complain & tf_error)
    4874           78 :             error_args_num (input_location, fndecl, /*too_many_p=*/true);
    4875              :           return -1;
    4876              :         }
    4877              : 
    4878              :       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4879              :          Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
    4880      4865476 :       if (TREE_CODE (val) == NOP_EXPR
    4881      1270289 :           && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
    4882      4865494 :           && (type == 0 || !TYPE_REF_P (type)))
    4883           18 :         val = TREE_OPERAND (val, 0);
    4884              : 
    4885      4865476 :       if (type == 0 || !TYPE_REF_P (type))
    4886              :         {
    4887      4658654 :           if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
    4888      4658654 :               || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (val)))
    4889        11506 :             val = decay_conversion (val, complain);
    4890              :         }
    4891              : 
    4892      4865476 :       if (val == error_mark_node)
    4893              :         return -1;
    4894              : 
    4895      4865476 :       if (type != 0)
    4896              :         {
    4897              :           /* Formal parm type is specified by a function prototype.  */
    4898      4865030 :           tree parmval;
    4899              : 
    4900      4865030 :           if (!COMPLETE_TYPE_P (complete_type (type)))
    4901              :             {
    4902           18 :               if (complain & tf_error)
    4903              :                 {
    4904           12 :                   location_t loc = EXPR_LOC_OR_LOC (val, input_location);
    4905           12 :                   if (fndecl)
    4906              :                     {
    4907           12 :                       auto_diagnostic_group d;
    4908           12 :                       error_at (loc,
    4909              :                                 "parameter %P of %qD has incomplete type %qT",
    4910              :                                 i, fndecl, type);
    4911           12 :                       inform (get_fndecl_argument_location (fndecl, i),
    4912              :                               "  declared here");
    4913           12 :                     }
    4914              :                   else
    4915            0 :                     error_at (loc, "parameter %P has incomplete type %qT", i,
    4916              :                               type);
    4917              :                 }
    4918           18 :               parmval = error_mark_node;
    4919              :             }
    4920              :           else
    4921              :             {
    4922      4865012 :               parmval = convert_for_initialization
    4923      4865012 :                 (NULL_TREE, type, val, flags,
    4924              :                  ICR_ARGPASS, fndecl, i, complain);
    4925      4865012 :               parmval = convert_for_arg_passing (type, parmval, complain);
    4926              :             }
    4927              : 
    4928      4865030 :           if (parmval == error_mark_node)
    4929              :             return -1;
    4930              : 
    4931      4863448 :           (**values)[i] = parmval;
    4932              :         }
    4933              :       else
    4934              :         {
    4935          446 :           int magic = fndecl ? magic_varargs_p (fndecl) : 0;
    4936           21 :           if (magic)
    4937              :             {
    4938              :               /* Don't truncate excess precision to the semantic type.  */
    4939            0 :               if (magic == 1 && TREE_CODE (val) == EXCESS_PRECISION_EXPR)
    4940            0 :                 val = TREE_OPERAND (val, 0);
    4941              :               /* Don't do ellipsis conversion for __built_in_constant_p
    4942              :                  as this will result in spurious errors for non-trivial
    4943              :                  types.  */
    4944            0 :               val = require_complete_type (val, complain);
    4945              :             }
    4946              :           else
    4947          446 :             val = convert_arg_to_ellipsis (val, complain);
    4948              : 
    4949          446 :           (**values)[i] = val;
    4950              :         }
    4951              : 
    4952      4863894 :       if (typetail)
    4953      4863448 :         typetail = TREE_CHAIN (typetail);
    4954              :     }
    4955              : 
    4956      7849523 :   if (typetail != 0 && typetail != void_list_node)
    4957              :     {
    4958              :       /* See if there are default arguments that can be used.  Because
    4959              :          we hold default arguments in the FUNCTION_TYPE (which is so
    4960              :          wrong), we can see default parameters here from deduced
    4961              :          contexts (and via typeof) for indirect function calls.
    4962              :          Fortunately we know whether we have a function decl to
    4963              :          provide default arguments in a language conformant
    4964              :          manner.  */
    4965           63 :       if (fndecl && TREE_PURPOSE (typetail)
    4966          173 :           && TREE_CODE (TREE_PURPOSE (typetail)) != DEFERRED_PARSE)
    4967              :         {
    4968            6 :           for (; typetail != void_list_node; ++i)
    4969              :             {
    4970              :               /* After DR777, with explicit template args we can end up with a
    4971              :                  default argument followed by no default argument.  */
    4972            6 :               if (!TREE_PURPOSE (typetail))
    4973              :                 break;
    4974            3 :               tree parmval
    4975            3 :                 = convert_default_arg (TREE_VALUE (typetail),
    4976            3 :                                        TREE_PURPOSE (typetail),
    4977            3 :                                        fndecl, i, complain);
    4978              : 
    4979            3 :               if (parmval == error_mark_node)
    4980            0 :                 return -1;
    4981              : 
    4982            3 :               vec_safe_push (*values, parmval);
    4983            3 :               typetail = TREE_CHAIN (typetail);
    4984              :               /* ends with `...'.  */
    4985            3 :               if (typetail == NULL_TREE)
    4986              :                 break;
    4987              :             }
    4988              :         }
    4989              : 
    4990          170 :       if (typetail && typetail != void_list_node)
    4991              :         {
    4992          170 :           if (complain & tf_error)
    4993           84 :             error_args_num (input_location, fndecl, /*too_many_p=*/false);
    4994              :           return -1;
    4995              :         }
    4996              :     }
    4997              : 
    4998      7849353 :   return (int) i;
    4999              : }
    5000              : 
    5001              : /* Build a binary-operation expression, after performing default
    5002              :    conversions on the operands.  CODE is the kind of expression to
    5003              :    build.  ARG1 and ARG2 are the arguments.  ARG1_CODE and ARG2_CODE
    5004              :    are the tree codes which correspond to ARG1 and ARG2 when issuing
    5005              :    warnings about possibly misplaced parentheses.  They may differ
    5006              :    from the TREE_CODE of ARG1 and ARG2 if the parser has done constant
    5007              :    folding (e.g., if the parser sees "a | 1 + 1", it may call this
    5008              :    routine with ARG2 being an INTEGER_CST and ARG2_CODE == PLUS_EXPR).
    5009              :    To avoid issuing any parentheses warnings, pass ARG1_CODE and/or
    5010              :    ARG2_CODE as ERROR_MARK.  */
    5011              : 
    5012              : tree
    5013    239848903 : build_x_binary_op (const op_location_t &loc, enum tree_code code, tree arg1,
    5014              :                    enum tree_code arg1_code, tree arg2,
    5015              :                    enum tree_code arg2_code, tree lookups,
    5016              :                    tree *overload_p, tsubst_flags_t complain)
    5017              : {
    5018    239848903 :   tree orig_arg1;
    5019    239848903 :   tree orig_arg2;
    5020    239848903 :   tree expr;
    5021    239848903 :   tree overload = NULL_TREE;
    5022              : 
    5023    239848903 :   orig_arg1 = arg1;
    5024    239848903 :   orig_arg2 = arg2;
    5025              : 
    5026    239848903 :   if (processing_template_decl)
    5027              :     {
    5028    140204199 :       if (type_dependent_expression_p (arg1)
    5029    140204199 :           || type_dependent_expression_p (arg2))
    5030              :         {
    5031     95935755 :           expr = build_min_nt_loc (loc, code, arg1, arg2);
    5032     95935755 :           TREE_TYPE (expr)
    5033     95935755 :             = build_dependent_operator_type (lookups, code, false);
    5034     95935755 :           return expr;
    5035              :         }
    5036              :     }
    5037              : 
    5038    143913148 :   if (code == DOTSTAR_EXPR)
    5039        87299 :     expr = build_m_component_ref (arg1, arg2, complain);
    5040              :   else
    5041    143825849 :     expr = build_new_op (loc, code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
    5042              :                          lookups, &overload, complain);
    5043              : 
    5044    143913115 :   if (overload_p != NULL)
    5045     63750583 :     *overload_p = overload;
    5046              : 
    5047              :   /* Check for cases such as x+y<<z which users are likely to
    5048              :      misinterpret.  But don't warn about obj << x + y, since that is a
    5049              :      common idiom for I/O.  */
    5050    143913115 :   if (warn_parentheses
    5051      1253165 :       && (complain & tf_warning)
    5052      1195725 :       && !processing_template_decl
    5053       820854 :       && !error_operand_p (arg1)
    5054       820848 :       && !error_operand_p (arg2)
    5055    144733951 :       && (code != LSHIFT_EXPR
    5056        71167 :           || !CLASS_TYPE_P (TREE_TYPE (arg1))))
    5057       819789 :     warn_about_parentheses (loc, code, arg1_code, orig_arg1,
    5058              :                             arg2_code, orig_arg2);
    5059              : 
    5060    143913115 :   if (processing_template_decl && expr != error_mark_node)
    5061              :     {
    5062     44268213 :       if (overload != NULL_TREE)
    5063      3953590 :         return (build_min_non_dep_op_overload
    5064      3953590 :                 (code, expr, overload, orig_arg1, orig_arg2));
    5065              : 
    5066     40314623 :       return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
    5067              :     }
    5068              : 
    5069              :   return expr;
    5070              : }
    5071              : 
    5072              : /* Build and return an ARRAY_REF expression.  */
    5073              : 
    5074              : tree
    5075      2653288 : build_x_array_ref (location_t loc, tree arg1, tree arg2,
    5076              :                    tsubst_flags_t complain)
    5077              : {
    5078      2653288 :   tree orig_arg1 = arg1;
    5079      2653288 :   tree orig_arg2 = arg2;
    5080      2653288 :   tree expr;
    5081      2653288 :   tree overload = NULL_TREE;
    5082              : 
    5083      2653288 :   if (processing_template_decl)
    5084              :     {
    5085         9508 :       if (type_dependent_expression_p (arg1)
    5086         9508 :           || type_dependent_expression_p (arg2))
    5087         4560 :         return build_min_nt_loc (loc, ARRAY_REF, arg1, arg2,
    5088         4560 :                                  NULL_TREE, NULL_TREE);
    5089              :     }
    5090              : 
    5091      2648728 :   expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, arg1, arg2,
    5092              :                        NULL_TREE, NULL_TREE, &overload, complain);
    5093              : 
    5094      2648728 :   if (processing_template_decl && expr != error_mark_node)
    5095              :     {
    5096         4945 :       if (overload != NULL_TREE)
    5097         4936 :         return (build_min_non_dep_op_overload
    5098         4936 :                 (ARRAY_REF, expr, overload, orig_arg1, orig_arg2));
    5099              : 
    5100            9 :       return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
    5101            9 :                                 NULL_TREE, NULL_TREE);
    5102              :     }
    5103              :   return expr;
    5104              : }
    5105              : 
    5106              : /* Build an OpenMP array section reference, creating an exact type for the
    5107              :    resulting expression based on the element type and bounds if possible.  If
    5108              :    we have variable bounds, create an incomplete array type for the result
    5109              :    instead.  */
    5110              : 
    5111              : tree
    5112        11078 : build_omp_array_section (location_t loc, tree array_expr, tree index,
    5113              :                          tree length)
    5114              : {
    5115        11078 :   if (TREE_CODE (array_expr) == TYPE_DECL
    5116        11078 :       || type_dependent_expression_p (array_expr))
    5117          274 :     return build3_loc (loc, OMP_ARRAY_SECTION, NULL_TREE, array_expr, index,
    5118          274 :                        length);
    5119              : 
    5120        10804 :   tree type = TREE_TYPE (array_expr);
    5121        10804 :   gcc_assert (type);
    5122        10804 :   type = non_reference (type);
    5123              : 
    5124        10804 :   tree sectype, eltype = TREE_TYPE (type);
    5125              : 
    5126              :   /* It's not an array or pointer type.  Just reuse the type of the
    5127              :      original expression as the type of the array section (an error will be
    5128              :      raised anyway, later).  */
    5129        10804 :   if (eltype == NULL_TREE)
    5130           42 :     sectype = TREE_TYPE (array_expr);
    5131              :   else
    5132              :     {
    5133        10762 :       tree idxtype = NULL_TREE;
    5134              : 
    5135              :       /* If we know the integer bounds, create an index type with exact
    5136              :          low/high (or zero/length) bounds.  Otherwise, create an incomplete
    5137              :          array type.  (This mostly only affects diagnostics.)  */
    5138        10762 :       if (index != NULL_TREE
    5139        10762 :           && length != NULL_TREE
    5140         7685 :           && TREE_CODE (index) == INTEGER_CST
    5141         6868 :           && TREE_CODE (length) == INTEGER_CST)
    5142              :         {
    5143         5365 :           tree low = fold_convert (sizetype, index);
    5144         5365 :           tree high = fold_convert (sizetype, length);
    5145         5365 :           high = size_binop (PLUS_EXPR, low, high);
    5146         5365 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    5147         5365 :           idxtype = build_range_type (sizetype, low, high);
    5148         5365 :         }
    5149         3007 :       else if ((index == NULL_TREE || integer_zerop (index))
    5150         3714 :                && length != NULL_TREE
    5151         7607 :                && TREE_CODE (length) == INTEGER_CST)
    5152         1496 :         idxtype = build_index_type (length);
    5153              : 
    5154        10762 :       sectype = build_array_type (eltype, idxtype);
    5155              :     }
    5156              : 
    5157        10804 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array_expr, index,
    5158        10804 :                      length);
    5159              : }
    5160              : 
    5161              : /* Return whether OP is an expression of enum type cast to integer
    5162              :    type.  In C++ even unsigned enum types are cast to signed integer
    5163              :    types.  We do not want to issue warnings about comparisons between
    5164              :    signed and unsigned types when one of the types is an enum type.
    5165              :    Those warnings are always false positives in practice.  */
    5166              : 
    5167              : static bool
    5168       644188 : enum_cast_to_int (tree op)
    5169              : {
    5170       631167 :   if (CONVERT_EXPR_P (op)
    5171        14048 :       && TREE_TYPE (op) == integer_type_node
    5172          908 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == ENUMERAL_TYPE
    5173       644203 :       && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 0))))
    5174              :     return true;
    5175              : 
    5176              :   /* The cast may have been pushed into a COND_EXPR.  */
    5177       644181 :   if (TREE_CODE (op) == COND_EXPR)
    5178          765 :     return (enum_cast_to_int (TREE_OPERAND (op, 1))
    5179          765 :             || enum_cast_to_int (TREE_OPERAND (op, 2)));
    5180              : 
    5181              :   return false;
    5182              : }
    5183              : 
    5184              : /* For the c-common bits.  */
    5185              : tree
    5186      5163482 : build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
    5187              :                  bool /*convert_p*/)
    5188              : {
    5189      5163482 :   return cp_build_binary_op (location, code, op0, op1, tf_warning_or_error);
    5190              : }
    5191              : 
    5192              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
    5193              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
    5194              : 
    5195              : static tree
    5196         8229 : build_vec_cmp (tree_code code, tree type,
    5197              :                tree arg0, tree arg1)
    5198              : {
    5199         8229 :   tree zero_vec = build_zero_cst (type);
    5200         8229 :   tree minus_one_vec = build_minus_one_cst (type);
    5201         8229 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
    5202         8229 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
    5203         8229 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
    5204              : }
    5205              : 
    5206              : /* Possibly warn about an address never being NULL.  */
    5207              : 
    5208              : static void
    5209      1857808 : warn_for_null_address (location_t location, tree op, tsubst_flags_t complain)
    5210              : {
    5211              :   /* Prevent warnings issued for macro expansion.  */
    5212      1857808 :   if (!warn_address
    5213        41725 :       || (complain & tf_warning) == 0
    5214        24950 :       || c_inhibit_evaluation_warnings != 0
    5215        24934 :       || from_macro_expansion_at (location)
    5216      1876011 :       || warning_suppressed_p (op, OPT_Waddress))
    5217      1839928 :     return;
    5218              : 
    5219        18170 :   tree cop = fold_for_warn (op);
    5220              : 
    5221        18170 :   if (TREE_CODE (cop) == NON_LVALUE_EXPR)
    5222              :     /* Unwrap the expression for C++ 98.  */
    5223            1 :     cop = TREE_OPERAND (cop, 0);
    5224              : 
    5225        18170 :   if (TREE_CODE (cop) == PTRMEM_CST)
    5226              :     {
    5227              :       /* The address of a nonstatic data member is never null.  */
    5228           30 :       warning_at (location, OPT_Waddress,
    5229              :                   "the address %qE will never be NULL",
    5230              :                   cop);
    5231           30 :       return;
    5232              :     }
    5233              : 
    5234        18140 :   if (TREE_CODE (cop) == NOP_EXPR)
    5235              :     {
    5236              :       /* Allow casts to intptr_t to suppress the warning.  */
    5237         1245 :       tree type = TREE_TYPE (cop);
    5238         1245 :       if (TREE_CODE (type) == INTEGER_TYPE)
    5239              :         return;
    5240              : 
    5241         1245 :       STRIP_NOPS (cop);
    5242              :     }
    5243              : 
    5244        18140 :   auto_diagnostic_group d;
    5245        18140 :   bool warned = false;
    5246        18140 :   if (TREE_CODE (cop) == ADDR_EXPR)
    5247              :     {
    5248          789 :       cop = TREE_OPERAND (cop, 0);
    5249              : 
    5250              :       /* Set to true in the loop below if OP dereferences its operand.
    5251              :          In such a case the ultimate target need not be a decl for
    5252              :          the null [in]equality test to be necessarily constant.  */
    5253          789 :       bool deref = false;
    5254              : 
    5255              :       /* Get the outermost array or object, or member.  */
    5256          960 :       while (handled_component_p (cop))
    5257              :         {
    5258          270 :           if (TREE_CODE (cop) == COMPONENT_REF)
    5259              :             {
    5260              :               /* Get the member (its address is never null).  */
    5261           99 :               cop = TREE_OPERAND (cop, 1);
    5262           99 :               break;
    5263              :             }
    5264              : 
    5265              :           /* Get the outer array/object to refer to in the warning.  */
    5266          171 :           cop = TREE_OPERAND (cop, 0);
    5267          171 :           deref = true;
    5268              :         }
    5269              : 
    5270          639 :       if ((!deref && !decl_with_nonnull_addr_p (cop))
    5271          631 :           || from_macro_expansion_at (location)
    5272         1420 :           || warning_suppressed_p (cop, OPT_Waddress))
    5273              :         return;
    5274              : 
    5275          631 :       warned = warning_at (location, OPT_Waddress,
    5276              :                            "the address of %qD will never be NULL", cop);
    5277          631 :       op = cop;
    5278              :     }
    5279        17351 :   else if (TREE_CODE (cop) == POINTER_PLUS_EXPR)
    5280              :     {
    5281              :       /* Adding zero to the null pointer is well-defined in C++.  When
    5282              :          the offset is unknown (i.e., not a constant) warn anyway since
    5283              :          it's less likely that the pointer operand is null than not.  */
    5284          102 :       tree off = TREE_OPERAND (cop, 1);
    5285          102 :       if (!integer_zerop (off)
    5286          102 :           && !warning_suppressed_p (cop, OPT_Waddress))
    5287              :         {
    5288          102 :           tree base = TREE_OPERAND (cop, 0);
    5289          102 :           STRIP_NOPS (base);
    5290          102 :           if (TYPE_REF_P (TREE_TYPE (base)))
    5291           12 :             warning_at (location, OPT_Waddress, "the compiler can assume that "
    5292              :                         "the address of %qE will never be NULL", base);
    5293              :           else
    5294           90 :             warning_at (location, OPT_Waddress, "comparing the result of "
    5295              :                         "pointer addition %qE and NULL", cop);
    5296              :         }
    5297              :       return;
    5298              :     }
    5299        16285 :   else if (CONVERT_EXPR_P (op)
    5300        17311 :            && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0))))
    5301              :     {
    5302           62 :       STRIP_NOPS (op);
    5303              : 
    5304           62 :       if (TREE_CODE (op) == COMPONENT_REF)
    5305           24 :         op = TREE_OPERAND (op, 1);
    5306              : 
    5307           62 :       if (DECL_P (op))
    5308           62 :         warned = warning_at (location, OPT_Waddress,
    5309              :                              "the compiler can assume that the address of "
    5310              :                              "%qD will never be NULL", op);
    5311              :     }
    5312              : 
    5313          693 :   if (warned && DECL_P (op))
    5314          657 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
    5315        18140 : }
    5316              : 
    5317              : /* Warn about [expr.arith.conv]/2: If one operand is of enumeration type and
    5318              :    the other operand is of a different enumeration type or a floating-point
    5319              :    type, this behavior is deprecated ([depr.arith.conv.enum]).  CODE is the
    5320              :    code of the binary operation, TYPE0 and TYPE1 are the types of the operands,
    5321              :    and LOC is the location for the whole binary expression.
    5322              :    For C++26 this is ill-formed rather than deprecated.
    5323              :    Return true for SFINAE errors.
    5324              :    TODO: Consider combining this with -Wenum-compare in build_new_op_1.  */
    5325              : 
    5326              : static bool
    5327    114183347 : do_warn_enum_conversions (location_t loc, enum tree_code code, tree type0,
    5328              :                           tree type1, tsubst_flags_t complain)
    5329              : {
    5330    114183347 :   if (TREE_CODE (type0) == ENUMERAL_TYPE
    5331      3382194 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5332    117025569 :       && TYPE_MAIN_VARIANT (type0) != TYPE_MAIN_VARIANT (type1))
    5333              :     {
    5334          200 :       if (cxx_dialect >= cxx26)
    5335              :         {
    5336           65 :           if ((complain & tf_warning_or_error) == 0)
    5337              :             return true;
    5338              :         }
    5339          135 :       else if ((complain & tf_warning) == 0)
    5340              :         return false;
    5341              :       /* In C++20, -Wdeprecated-enum-enum-conversion is on by default.
    5342              :          Otherwise, warn if -Wenum-conversion is on.  */
    5343          193 :       enum opt_code opt;
    5344          193 :       if (warn_deprecated_enum_enum_conv)
    5345              :         opt = OPT_Wdeprecated_enum_enum_conversion;
    5346           93 :       else if (warn_enum_conversion)
    5347              :         opt = OPT_Wenum_conversion;
    5348              :       else
    5349              :         return false;
    5350              : 
    5351          122 :       switch (code)
    5352              :         {
    5353              :         case GT_EXPR:
    5354              :         case LT_EXPR:
    5355              :         case GE_EXPR:
    5356              :         case LE_EXPR:
    5357              :         case EQ_EXPR:
    5358              :         case NE_EXPR:
    5359              :           /* Comparisons are handled by -Wenum-compare.  */
    5360              :           return false;
    5361              :         case SPACESHIP_EXPR:
    5362              :           /* This is invalid, don't warn.  */
    5363              :           return false;
    5364           18 :         case BIT_AND_EXPR:
    5365           18 :         case BIT_IOR_EXPR:
    5366           18 :         case BIT_XOR_EXPR:
    5367           18 :           if (cxx_dialect >= cxx26)
    5368            6 :             pedwarn (loc, opt, "bitwise operation between different "
    5369              :                      "enumeration types %qT and %qT", type0, type1);
    5370              :           else
    5371           12 :             warning_at (loc, opt, "bitwise operation between different "
    5372              :                         "enumeration types %qT and %qT is deprecated",
    5373              :                         type0, type1);
    5374              :           return false;
    5375           42 :         default:
    5376           42 :           if (cxx_dialect >= cxx26)
    5377           13 :             pedwarn (loc, opt, "arithmetic between different enumeration "
    5378              :                      "types %qT and %qT", type0, type1);
    5379              :           else
    5380           29 :             warning_at (loc, opt, "arithmetic between different enumeration "
    5381              :                         "types %qT and %qT is deprecated", type0, type1);
    5382              :           return false;
    5383              :         }
    5384              :     }
    5385    114183147 :   else if ((TREE_CODE (type0) == ENUMERAL_TYPE
    5386      3381994 :             && SCALAR_FLOAT_TYPE_P (type1))
    5387    114183075 :            || (SCALAR_FLOAT_TYPE_P (type0)
    5388     31814366 :                && TREE_CODE (type1) == ENUMERAL_TYPE))
    5389              :     {
    5390          151 :       if (cxx_dialect >= cxx26)
    5391              :         {
    5392           54 :           if ((complain & tf_warning_or_error) == 0)
    5393              :             return true;
    5394              :         }
    5395           97 :       else if ((complain & tf_warning) == 0)
    5396              :         return false;
    5397          139 :       const bool enum_first_p = TREE_CODE (type0) == ENUMERAL_TYPE;
    5398              :       /* In C++20, -Wdeprecated-enum-float-conversion is on by default.
    5399              :          Otherwise, warn if -Wenum-conversion is on.  */
    5400          139 :       enum opt_code opt;
    5401          139 :       if (warn_deprecated_enum_float_conv)
    5402              :         opt = OPT_Wdeprecated_enum_float_conversion;
    5403           68 :       else if (warn_enum_conversion)
    5404              :         opt = OPT_Wenum_conversion;
    5405              :       else
    5406              :         return false;
    5407              : 
    5408           88 :       switch (code)
    5409              :         {
    5410           36 :         case GT_EXPR:
    5411           36 :         case LT_EXPR:
    5412           36 :         case GE_EXPR:
    5413           36 :         case LE_EXPR:
    5414           36 :         case EQ_EXPR:
    5415           36 :         case NE_EXPR:
    5416           36 :           if (enum_first_p && cxx_dialect >= cxx26)
    5417            6 :             pedwarn (loc, opt, "comparison of enumeration type %qT with "
    5418              :                      "floating-point type %qT", type0, type1);
    5419           30 :           else if (cxx_dialect >= cxx26)
    5420            6 :             pedwarn (loc, opt, "comparison of floating-point type %qT "
    5421              :                       "with enumeration type %qT", type0, type1);
    5422           24 :           else if (enum_first_p)
    5423           12 :             warning_at (loc, opt, "comparison of enumeration type %qT with "
    5424              :                         "floating-point type %qT is deprecated",
    5425              :                         type0, type1);
    5426              :           else
    5427           12 :             warning_at (loc, opt, "comparison of floating-point type %qT "
    5428              :                         "with enumeration type %qT is deprecated",
    5429              :                         type0, type1);
    5430              :           return false;
    5431              :         case SPACESHIP_EXPR:
    5432              :           /* This is invalid, don't warn.  */
    5433              :           return false;
    5434           40 :         default:
    5435           40 :           if (enum_first_p && cxx_dialect >= cxx26)
    5436            6 :             pedwarn (loc, opt, "arithmetic between enumeration type %qT "
    5437              :                      "and floating-point type %qT", type0, type1);
    5438           34 :           else if (cxx_dialect >= cxx26)
    5439            7 :             pedwarn (loc, opt, "arithmetic between floating-point type %qT "
    5440              :                      "and enumeration type %qT", type0, type1);
    5441           27 :           else if (enum_first_p)
    5442           12 :             warning_at (loc, opt, "arithmetic between enumeration type %qT "
    5443              :                         "and floating-point type %qT is deprecated",
    5444              :                         type0, type1);
    5445              :           else
    5446           15 :             warning_at (loc, opt, "arithmetic between floating-point type %qT "
    5447              :                         "and enumeration type %qT is deprecated",
    5448              :                         type0, type1);
    5449              :           return false;
    5450              :         }
    5451              :     }
    5452              :   return false;
    5453              : }
    5454              : 
    5455              : /* Build a binary-operation expression without default conversions.
    5456              :    CODE is the kind of expression to build.
    5457              :    LOCATION is the location_t of the operator in the source code.
    5458              :    This function differs from `build' in several ways:
    5459              :    the data type of the result is computed and recorded in it,
    5460              :    warnings are generated if arg data types are invalid,
    5461              :    special handling for addition and subtraction of pointers is known,
    5462              :    and some optimization is done (operations on narrow ints
    5463              :    are done in the narrower type when that gives the same result).
    5464              :    Constant folding is also done before the result is returned.
    5465              : 
    5466              :    Note that the operands will never have enumeral types
    5467              :    because either they have just had the default conversions performed
    5468              :    or they have both just been converted to some other type in which
    5469              :    the arithmetic is to be done.
    5470              : 
    5471              :    C++: must do special pointer arithmetic when implementing
    5472              :    multiple inheritance, and deal with pointer to member functions.  */
    5473              : 
    5474              : tree
    5475    154018146 : cp_build_binary_op (const op_location_t &location,
    5476              :                     enum tree_code code, tree orig_op0, tree orig_op1,
    5477              :                     tsubst_flags_t complain)
    5478              : {
    5479    154018146 :   tree op0, op1;
    5480    154018146 :   enum tree_code code0, code1;
    5481    154018146 :   tree type0, type1, orig_type0, orig_type1;
    5482    154018146 :   const char *invalid_op_diag;
    5483              : 
    5484              :   /* Expression code to give to the expression when it is built.
    5485              :      Normally this is CODE, which is what the caller asked for,
    5486              :      but in some special cases we change it.  */
    5487    154018146 :   enum tree_code resultcode = code;
    5488              : 
    5489              :   /* Data type in which the computation is to be performed.
    5490              :      In the simplest cases this is the common type of the arguments.  */
    5491    154018146 :   tree result_type = NULL_TREE;
    5492              : 
    5493              :   /* When the computation is in excess precision, the type of the
    5494              :      final EXCESS_PRECISION_EXPR.  */
    5495    154018146 :   tree semantic_result_type = NULL;
    5496              : 
    5497              :   /* Nonzero means operands have already been type-converted
    5498              :      in whatever way is necessary.
    5499              :      Zero means they need to be converted to RESULT_TYPE.  */
    5500    154018146 :   int converted = 0;
    5501              : 
    5502              :   /* Nonzero means create the expression with this type, rather than
    5503              :      RESULT_TYPE.  */
    5504    154018146 :   tree build_type = 0;
    5505              : 
    5506              :   /* Nonzero means after finally constructing the expression
    5507              :      convert it to this type.  */
    5508    154018146 :   tree final_type = 0;
    5509              : 
    5510    154018146 :   tree result;
    5511              : 
    5512              :   /* Nonzero if this is an operation like MIN or MAX which can
    5513              :      safely be computed in short if both args are promoted shorts.
    5514              :      Also implies COMMON.
    5515              :      -1 indicates a bitwise operation; this makes a difference
    5516              :      in the exact conditions for when it is safe to do the operation
    5517              :      in a narrower mode.  */
    5518    154018146 :   int shorten = 0;
    5519              : 
    5520              :   /* Nonzero if this is a comparison operation;
    5521              :      if both args are promoted shorts, compare the original shorts.
    5522              :      Also implies COMMON.  */
    5523    154018146 :   int short_compare = 0;
    5524              : 
    5525              :   /* Nonzero if this is a right-shift operation, which can be computed on the
    5526              :      original short and then promoted if the operand is a promoted short.  */
    5527    154018146 :   int short_shift = 0;
    5528              : 
    5529              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
    5530    154018146 :   int common = 0;
    5531              : 
    5532              :   /* True if both operands have arithmetic type.  */
    5533    154018146 :   bool arithmetic_types_p;
    5534              : 
    5535              :   /* Remember whether we're doing / or %.  */
    5536    154018146 :   bool doing_div_or_mod = false;
    5537              : 
    5538              :   /* Remember whether we're doing << or >>.  */
    5539    154018146 :   bool doing_shift = false;
    5540              : 
    5541              :   /* Tree holding instrumentation expression.  */
    5542    154018146 :   tree instrument_expr = NULL_TREE;
    5543              : 
    5544              :   /* True means this is an arithmetic operation that may need excess
    5545              :      precision.  */
    5546    154018146 :   bool may_need_excess_precision;
    5547              : 
    5548              :   /* Apply default conversions.  */
    5549    154018146 :   op0 = resolve_nondeduced_context (orig_op0, complain);
    5550    154018146 :   op1 = resolve_nondeduced_context (orig_op1, complain);
    5551              : 
    5552    154018146 :   if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
    5553    139256561 :       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
    5554    135565405 :       || code == TRUTH_XOR_EXPR)
    5555              :     {
    5556     18452741 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5557     18452723 :         op0 = decay_conversion (op0, complain);
    5558     18452741 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5559     18452741 :         op1 = decay_conversion (op1, complain);
    5560              :     }
    5561              :   else
    5562              :     {
    5563    135565405 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5564    135565356 :         op0 = cp_default_conversion (op0, complain);
    5565    135565405 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5566    135565386 :         op1 = cp_default_conversion (op1, complain);
    5567              :     }
    5568              : 
    5569              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    5570    162837424 :   STRIP_TYPE_NOPS (op0);
    5571    189040825 :   STRIP_TYPE_NOPS (op1);
    5572              : 
    5573              :   /* DTRT if one side is an overloaded function, but complain about it.  */
    5574    154018146 :   if (type_unknown_p (op0))
    5575              :     {
    5576            9 :       tree t = instantiate_type (TREE_TYPE (op1), op0, tf_none);
    5577            9 :       if (t != error_mark_node)
    5578              :         {
    5579            0 :           if (complain & tf_error)
    5580            0 :             permerror (location,
    5581              :                        "assuming cast to type %qT from overloaded function",
    5582            0 :                        TREE_TYPE (t));
    5583              :           op0 = t;
    5584              :         }
    5585              :     }
    5586    154018146 :   if (type_unknown_p (op1))
    5587              :     {
    5588            3 :       tree t = instantiate_type (TREE_TYPE (op0), op1, tf_none);
    5589            3 :       if (t != error_mark_node)
    5590              :         {
    5591            3 :           if (complain & tf_error)
    5592            3 :             permerror (location,
    5593              :                        "assuming cast to type %qT from overloaded function",
    5594            3 :                        TREE_TYPE (t));
    5595              :           op1 = t;
    5596              :         }
    5597              :     }
    5598              : 
    5599    154018146 :   orig_type0 = type0 = TREE_TYPE (op0);
    5600    154018146 :   orig_type1 = type1 = TREE_TYPE (op1);
    5601    154018146 :   tree non_ep_op0 = op0;
    5602    154018146 :   tree non_ep_op1 = op1;
    5603              : 
    5604              :   /* The expression codes of the data types of the arguments tell us
    5605              :      whether the arguments are integers, floating, pointers, etc.  */
    5606    154018146 :   code0 = TREE_CODE (type0);
    5607    154018146 :   code1 = TREE_CODE (type1);
    5608              : 
    5609              :   /* If an error was already reported for one of the arguments,
    5610              :      avoid reporting another error.  */
    5611    154018146 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
    5612          101 :     return error_mark_node;
    5613              : 
    5614    308036090 :   if ((invalid_op_diag
    5615    154018045 :        = targetm.invalid_binary_op (code, type0, type1)))
    5616              :     {
    5617            0 :       if (complain & tf_error)
    5618              :         {
    5619            0 :           if (code0 == REAL_TYPE
    5620            0 :               && code1 == REAL_TYPE
    5621            0 :               && (extended_float_type_p (type0)
    5622            0 :                   || extended_float_type_p (type1))
    5623            0 :               && cp_compare_floating_point_conversion_ranks (type0,
    5624              :                                                              type1) == 3)
    5625              :             {
    5626            0 :               rich_location richloc (line_table, location);
    5627            0 :               binary_op_error (&richloc, code, type0, type1);
    5628            0 :             }
    5629              :           else
    5630            0 :             error (invalid_op_diag);
    5631              :         }
    5632            0 :       return error_mark_node;
    5633              :     }
    5634              : 
    5635    154018045 :   switch (code)
    5636              :     {
    5637              :     case PLUS_EXPR:
    5638              :     case MINUS_EXPR:
    5639              :     case MULT_EXPR:
    5640              :     case TRUNC_DIV_EXPR:
    5641              :     case CEIL_DIV_EXPR:
    5642              :     case FLOOR_DIV_EXPR:
    5643              :     case ROUND_DIV_EXPR:
    5644              :     case EXACT_DIV_EXPR:
    5645              :       may_need_excess_precision = true;
    5646              :       break;
    5647     54524190 :     case EQ_EXPR:
    5648     54524190 :     case NE_EXPR:
    5649     54524190 :     case LE_EXPR:
    5650     54524190 :     case GE_EXPR:
    5651     54524190 :     case LT_EXPR:
    5652     54524190 :     case GT_EXPR:
    5653     54524190 :     case SPACESHIP_EXPR:
    5654              :       /* Excess precision for implicit conversions of integers to
    5655              :          floating point.  */
    5656     11669398 :       may_need_excess_precision = (ANY_INTEGRAL_TYPE_P (type0)
    5657     66186037 :                                    || ANY_INTEGRAL_TYPE_P (type1));
    5658              :       break;
    5659              :     default:
    5660    154018045 :       may_need_excess_precision = false;
    5661              :       break;
    5662              :     }
    5663    154018045 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
    5664              :     {
    5665        14933 :       op0 = TREE_OPERAND (op0, 0);
    5666        14933 :       type0 = TREE_TYPE (op0);
    5667              :     }
    5668    154003112 :   else if (may_need_excess_precision
    5669    115277180 :            && (code0 == REAL_TYPE || code0 == COMPLEX_TYPE))
    5670     27735985 :     if (tree eptype = excess_precision_type (type0))
    5671              :       {
    5672        39993 :         type0 = eptype;
    5673        39993 :         op0 = convert (eptype, op0);
    5674              :       }
    5675    154018045 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    5676              :     {
    5677        18869 :       op1 = TREE_OPERAND (op1, 0);
    5678        18869 :       type1 = TREE_TYPE (op1);
    5679              :     }
    5680    153999176 :   else if (may_need_excess_precision
    5681    115275450 :            && (code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
    5682     27611538 :     if (tree eptype = excess_precision_type (type1))
    5683              :       {
    5684        26638 :         type1 = eptype;
    5685        26638 :         op1 = convert (eptype, op1);
    5686              :       }
    5687              : 
    5688              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    5689    308036005 :   if ((null_node_p (orig_op0) || null_node_p (orig_op1))
    5690              :       /* It's reasonable to use pointer values as operands of &&
    5691              :          and ||, so NULL is no exception.  */
    5692        12506 :       && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR
    5693        12491 :       && ( /* Both are NULL (or 0) and the operation was not a
    5694              :               comparison or a pointer subtraction.  */
    5695        12564 :           (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)
    5696           27 :            && code != EQ_EXPR && code != NE_EXPR && code != MINUS_EXPR)
    5697              :           /* Or if one of OP0 or OP1 is neither a pointer nor NULL.  */
    5698        12479 :           || (!null_ptr_cst_p (orig_op0)
    5699        12418 :               && !TYPE_PTR_OR_PTRMEM_P (type0))
    5700        12467 :           || (!null_ptr_cst_p (orig_op1)
    5701           46 :               && !TYPE_PTR_OR_PTRMEM_P (type1)))
    5702    154018084 :       && (complain & tf_warning))
    5703              :     {
    5704           39 :       location_t loc =
    5705           39 :         expansion_point_location_if_in_system_header (input_location);
    5706              : 
    5707           39 :       warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic");
    5708              :     }
    5709              : 
    5710              :   /* In case when one of the operands of the binary operation is
    5711              :      a vector and another is a scalar -- convert scalar to vector.  */
    5712    154086613 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
    5713    154085478 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
    5714              :     {
    5715         1220 :       enum stv_conv convert_flag
    5716         1220 :         = scalar_to_vector (location, code, non_ep_op0, non_ep_op1,
    5717              :                             complain & tf_error);
    5718              : 
    5719         1220 :       switch (convert_flag)
    5720              :         {
    5721           21 :           case stv_error:
    5722           21 :             return error_mark_node;
    5723           55 :           case stv_firstarg:
    5724           55 :             {
    5725           55 :               op0 = convert (TREE_TYPE (type1), op0);
    5726           55 :               op0 = cp_save_expr (op0);
    5727           55 :               op0 = build_vector_from_val (type1, op0);
    5728           55 :               orig_type0 = type0 = TREE_TYPE (op0);
    5729           55 :               code0 = TREE_CODE (type0);
    5730           55 :               converted = 1;
    5731           55 :               break;
    5732              :             }
    5733         1007 :           case stv_secondarg:
    5734         1007 :             {
    5735         1007 :               op1 = convert (TREE_TYPE (type0), op1);
    5736         1007 :               op1 = cp_save_expr (op1);
    5737         1007 :               op1 = build_vector_from_val (type0, op1);
    5738         1007 :               orig_type1 = type1 = TREE_TYPE (op1);
    5739         1007 :               code1 = TREE_CODE (type1);
    5740         1007 :               converted = 1;
    5741         1007 :               break;
    5742              :             }
    5743              :           default:
    5744              :             break;
    5745              :         }
    5746              :     }
    5747              : 
    5748    154018024 :   switch (code)
    5749              :     {
    5750     16861599 :     case MINUS_EXPR:
    5751              :       /* Subtraction of two similar pointers.
    5752              :          We must subtract them as integers, then divide by object size.  */
    5753     16861599 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
    5754     18438858 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    5755      1577259 :                                                         TREE_TYPE (type1)))
    5756              :         {
    5757      1577256 :           result = pointer_diff (location, op0, op1,
    5758              :                                  common_pointer_type (type0, type1), complain,
    5759              :                                  &instrument_expr);
    5760      1577256 :           if (instrument_expr != NULL)
    5761           84 :             result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    5762              :                              instrument_expr, result);
    5763              : 
    5764              :           return result;
    5765              :         }
    5766              :       /* In all other cases except pointer - int, the usual arithmetic
    5767              :          rules apply.  */
    5768     15284343 :       else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE))
    5769              :         {
    5770              :           common = 1;
    5771              :           break;
    5772              :         }
    5773              :       /* The pointer - int case is just like pointer + int; fall
    5774              :          through.  */
    5775     22405480 :       gcc_fallthrough ();
    5776     22405480 :     case PLUS_EXPR:
    5777     22405480 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    5778      8196609 :           && (code0 == INTEGER_TYPE || code1 == INTEGER_TYPE))
    5779              :         {
    5780      8196600 :           tree ptr_operand;
    5781      8196600 :           tree int_operand;
    5782      8196600 :           ptr_operand = ((code0 == POINTER_TYPE) ? op0 : op1);
    5783       131322 :           int_operand = ((code0 == INTEGER_TYPE) ? op0 : op1);
    5784      8196600 :           if (processing_template_decl)
    5785              :             {
    5786      2285543 :               result_type = TREE_TYPE (ptr_operand);
    5787      2285543 :               break;
    5788              :             }
    5789      5911057 :           return cp_pointer_int_sum (location, code,
    5790              :                                      ptr_operand,
    5791              :                                      int_operand,
    5792      5911057 :                                      complain);
    5793              :         }
    5794              :       common = 1;
    5795              :       break;
    5796              : 
    5797              :     case MULT_EXPR:
    5798    146482312 :       common = 1;
    5799              :       break;
    5800              : 
    5801     12489703 :     case TRUNC_DIV_EXPR:
    5802     12489703 :     case CEIL_DIV_EXPR:
    5803     12489703 :     case FLOOR_DIV_EXPR:
    5804     12489703 :     case ROUND_DIV_EXPR:
    5805     12489703 :     case EXACT_DIV_EXPR:
    5806     12489703 :       if (TREE_CODE (op0) == SIZEOF_EXPR && TREE_CODE (op1) == SIZEOF_EXPR)
    5807              :         {
    5808       130155 :           tree type0 = TREE_OPERAND (op0, 0);
    5809       130155 :           tree type1 = TREE_OPERAND (op1, 0);
    5810       130155 :           tree first_arg = tree_strip_any_location_wrapper (type0);
    5811       130155 :           if (!TYPE_P (type0))
    5812        87285 :             type0 = TREE_TYPE (type0);
    5813       130155 :           if (!TYPE_P (type1))
    5814        50532 :             type1 = TREE_TYPE (type1);
    5815       130155 :           if (type0
    5816       130155 :               && type1
    5817       110332 :               && INDIRECT_TYPE_P (type0)
    5818       130230 :               && same_type_p (TREE_TYPE (type0), type1))
    5819              :             {
    5820           27 :               if (!(TREE_CODE (first_arg) == PARM_DECL
    5821           21 :                     && DECL_ARRAY_PARAMETER_P (first_arg)
    5822            3 :                     && warn_sizeof_array_argument)
    5823           42 :                   && (complain & tf_warning))
    5824              :                 {
    5825           21 :                   auto_diagnostic_group d;
    5826           21 :                   if (warning_at (location, OPT_Wsizeof_pointer_div,
    5827              :                                   "division %<sizeof (%T) / sizeof (%T)%> does "
    5828              :                                   "not compute the number of array elements",
    5829              :                                   type0, type1))
    5830           18 :                     if (DECL_P (first_arg))
    5831           18 :                       inform (DECL_SOURCE_LOCATION (first_arg),
    5832              :                               "first %<sizeof%> operand was declared here");
    5833           21 :                 }
    5834              :             }
    5835       130131 :           else if (!dependent_type_p (type0)
    5836        30812 :                    && !dependent_type_p (type1)
    5837        30712 :                    && TREE_CODE (type0) == ARRAY_TYPE
    5838        21718 :                    && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0)))
    5839              :                    /* Set by finish_parenthesized_expr.  */
    5840        21067 :                    && !warning_suppressed_p (op1, OPT_Wsizeof_array_div)
    5841       151180 :                    && (complain & tf_warning))
    5842        21049 :             maybe_warn_sizeof_array_div (location, first_arg, type0,
    5843              :                                          op1, non_reference (type1));
    5844              :         }
    5845              : 
    5846     12489703 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5847              :            || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
    5848     12489685 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5849              :               || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
    5850              :         {
    5851     12489676 :           enum tree_code tcode0 = code0, tcode1 = code1;
    5852     12489676 :           doing_div_or_mod = true;
    5853     12489676 :           warn_for_div_by_zero (location, fold_for_warn (op1));
    5854              : 
    5855     12489676 :           if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
    5856        59164 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
    5857     12489676 :           if (tcode1 == COMPLEX_TYPE || tcode1 == VECTOR_TYPE)
    5858        30441 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
    5859              : 
    5860     12489679 :           if (!((tcode0 == INTEGER_TYPE
    5861      5450817 :                  || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
    5862              :                 && (tcode1 == INTEGER_TYPE
    5863        97886 :                     || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE))))
    5864              :             resultcode = RDIV_EXPR;
    5865              :           else
    5866              :             {
    5867              :               /* When dividing two signed integers, we have to promote to int.
    5868              :                  unless we divide by a constant != -1.  Note that default
    5869              :                  conversion will have been performed on the operands at this
    5870              :                  point, so we have to dig out the original type to find out if
    5871              :                  it was unsigned.  */
    5872      6940979 :               tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5873      6940979 :               shorten = may_shorten_divmod (op0, stripped_op1);
    5874              :             }
    5875              : 
    5876              :           common = 1;
    5877              :         }
    5878              :       break;
    5879              : 
    5880      2984499 :     case BIT_AND_EXPR:
    5881      2984499 :     case BIT_IOR_EXPR:
    5882      2984499 :     case BIT_XOR_EXPR:
    5883      2984499 :       if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5884      2984499 :           || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5885        21143 :               && !VECTOR_FLOAT_TYPE_P (type0)
    5886        21125 :               && !VECTOR_FLOAT_TYPE_P (type1)))
    5887              :         shorten = -1;
    5888              :       break;
    5889              : 
    5890      1590399 :     case TRUNC_MOD_EXPR:
    5891      1590399 :     case FLOOR_MOD_EXPR:
    5892      1590399 :       doing_div_or_mod = true;
    5893      1590399 :       warn_for_div_by_zero (location, fold_for_warn (op1));
    5894              : 
    5895      1590399 :       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5896           36 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5897      1590435 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    5898              :         common = 1;
    5899      1590363 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5900              :         {
    5901              :           /* Although it would be tempting to shorten always here, that loses
    5902              :              on some targets, since the modulo instruction is undefined if the
    5903              :              quotient can't be represented in the computation mode.  We shorten
    5904              :              only if unsigned or if dividing by something we know != -1.  */
    5905      1590339 :           tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5906      1590339 :           shorten = may_shorten_divmod (op0, stripped_op1);
    5907      1590339 :           common = 1;
    5908              :         }
    5909              :       break;
    5910              : 
    5911     18452726 :     case TRUTH_ANDIF_EXPR:
    5912     18452726 :     case TRUTH_ORIF_EXPR:
    5913     18452726 :     case TRUTH_AND_EXPR:
    5914     18452726 :     case TRUTH_OR_EXPR:
    5915     18452726 :       if (!VECTOR_TYPE_P (type0) && gnu_vector_type_p (type1))
    5916              :         {
    5917            3 :           if (!COMPARISON_CLASS_P (op1))
    5918            3 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5919              :                                       build_zero_cst (type1), complain);
    5920            3 :           if (code == TRUTH_ANDIF_EXPR)
    5921              :             {
    5922            0 :               tree z = build_zero_cst (TREE_TYPE (op1));
    5923            0 :               return build_conditional_expr (location, op0, op1, z, complain);
    5924              :             }
    5925            3 :           else if (code == TRUTH_ORIF_EXPR)
    5926              :             {
    5927            3 :               tree m1 = build_all_ones_cst (TREE_TYPE (op1));
    5928            3 :               return build_conditional_expr (location, op0, m1, op1, complain);
    5929              :             }
    5930              :           else
    5931            0 :             gcc_unreachable ();
    5932              :         }
    5933     18452723 :       if (gnu_vector_type_p (type0)
    5934     18452723 :           && (!VECTOR_TYPE_P (type1) || gnu_vector_type_p (type1)))
    5935              :         {
    5936           24 :           if (!COMPARISON_CLASS_P (op0))
    5937           24 :             op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0,
    5938              :                                       build_zero_cst (type0), complain);
    5939           24 :           if (!VECTOR_TYPE_P (type1))
    5940              :             {
    5941            9 :               tree m1 = build_all_ones_cst (TREE_TYPE (op0));
    5942            9 :               tree z = build_zero_cst (TREE_TYPE (op0));
    5943            9 :               op1 = build_conditional_expr (location, op1, m1, z, complain);
    5944              :             }
    5945           15 :           else if (!COMPARISON_CLASS_P (op1))
    5946           15 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5947              :                                       build_zero_cst (type1), complain);
    5948              : 
    5949           24 :           if (code == TRUTH_ANDIF_EXPR)
    5950              :             code = BIT_AND_EXPR;
    5951            9 :           else if (code == TRUTH_ORIF_EXPR)
    5952              :             code = BIT_IOR_EXPR;
    5953              :           else
    5954            0 :             gcc_unreachable ();
    5955              : 
    5956           24 :           return cp_build_binary_op (location, code, op0, op1, complain);
    5957              :         }
    5958              : 
    5959     18452699 :       if (warn_constant_logical_operand
    5960       131868 :           && (complain & tf_warning)
    5961       129435 :           && (code0 == INTEGER_TYPE || code0 == ENUMERAL_TYPE)
    5962        11360 :           && (code1 == INTEGER_TYPE || code1 == ENUMERAL_TYPE))
    5963              :         {
    5964         5029 :           tree cop0 = fold_for_warn (op0), cop1 = fold_for_warn (op1);
    5965         5029 :           const char *name
    5966              :             = ((code == TRUTH_ANDIF_EXPR || code == TRUTH_AND_EXPR)
    5967              :                ? "&&" : "||");
    5968         5114 :           auto enum_other_than_0_1 = [] (tree type) {
    5969           85 :             if (TREE_CODE (type) != ENUMERAL_TYPE)
    5970              :               return false;
    5971          154 :             for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
    5972              :               {
    5973          125 :                 tree v = DECL_INITIAL (TREE_VALUE (l));
    5974          125 :                 if (!integer_zerop (v) && !integer_onep (v))
    5975              :                   return true;
    5976              :               }
    5977              :             return false;
    5978              :           };
    5979        15039 :           auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
    5980        10010 :             if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
    5981              :               return false;
    5982          157 :             if (integer_onep (val) && !enum_other_than_0_1 (type))
    5983              :               return false;
    5984           96 :             gcc_rich_location richloc (location);
    5985           96 :             richloc.add_fixit_replace (name + 1);
    5986           96 :             auto_diagnostic_group d;
    5987           96 :             if (warning_at (location, OPT_Wconstant_logical_operand,
    5988              :                             "use of logical %qs with constant operand %qE",
    5989              :                             name, val))
    5990           96 :               inform (&richloc, "use %qs for bitwise operation", name + 1);
    5991           96 :             return true;
    5992           96 :           };
    5993         5029 :           if (!diagnose_constant_logical_operand (cop1, orig_type1))
    5994         4981 :             diagnose_constant_logical_operand (cop0, orig_type0);
    5995              :         }
    5996              : 
    5997     18452699 :       result_type = boolean_type_node;
    5998     18452699 :       break;
    5999              : 
    6000              :       /* Shift operations: result has same type as first operand;
    6001              :          always convert second operand to int.
    6002              :          Also set SHORT_SHIFT if shifting rightward.  */
    6003              : 
    6004      1197298 :     case RSHIFT_EXPR:
    6005      1197298 :       if (gnu_vector_type_p (type0)
    6006          202 :           && code1 == INTEGER_TYPE
    6007      1197363 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    6008              :         {
    6009              :           result_type = type0;
    6010              :           converted = 1;
    6011              :         }
    6012      1197233 :       else if (gnu_vector_type_p (type0)
    6013          137 :                && gnu_vector_type_p (type1)
    6014          137 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    6015          134 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    6016      1197367 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    6017              :                             TYPE_VECTOR_SUBPARTS (type1)))
    6018              :         {
    6019              :           result_type = type0;
    6020              :           converted = 1;
    6021              :         }
    6022      1197099 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    6023              :         {
    6024      1197072 :           tree const_op1 = fold_for_warn (op1);
    6025      1197072 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    6026       153395 :             const_op1 = op1;
    6027      1197072 :           result_type = type0;
    6028      1197072 :           doing_shift = true;
    6029      1197072 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    6030              :             {
    6031      1043677 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    6032              :                 {
    6033           48 :                   if ((complain & tf_warning)
    6034           48 :                       && c_inhibit_evaluation_warnings == 0)
    6035           36 :                     warning_at (location, OPT_Wshift_count_negative,
    6036              :                                 "right shift count is negative");
    6037              :                 }
    6038              :               else
    6039              :                 {
    6040      1043629 :                   if (!integer_zerop (const_op1))
    6041      1043326 :                     short_shift = 1;
    6042              : 
    6043      1043629 :                   if (compare_tree_int (const_op1, TYPE_PRECISION (type0)) >= 0
    6044           46 :                       && (complain & tf_warning)
    6045      1043675 :                       && c_inhibit_evaluation_warnings == 0)
    6046           34 :                     warning_at (location, OPT_Wshift_count_overflow,
    6047              :                                 "right shift count >= width of type");
    6048              :                 }
    6049              :             }
    6050              :           /* Avoid converting op1 to result_type later.  */
    6051              :           converted = 1;
    6052              :         }
    6053              :       break;
    6054              : 
    6055      3317960 :     case LSHIFT_EXPR:
    6056      3317960 :       if (gnu_vector_type_p (type0)
    6057          271 :           && code1 == INTEGER_TYPE
    6058      3318011 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    6059              :         {
    6060              :           result_type = type0;
    6061              :           converted = 1;
    6062              :         }
    6063      3317909 :       else if (gnu_vector_type_p (type0)
    6064          220 :                && gnu_vector_type_p (type1)
    6065          220 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    6066          217 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    6067      3318123 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    6068              :                             TYPE_VECTOR_SUBPARTS (type1)))
    6069              :         {
    6070              :           result_type = type0;
    6071              :           converted = 1;
    6072              :         }
    6073      3317695 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    6074              :         {
    6075      3317595 :           tree const_op0 = fold_for_warn (op0);
    6076      3317595 :           if (TREE_CODE (const_op0) != INTEGER_CST)
    6077       310713 :             const_op0 = op0;
    6078      3317595 :           tree const_op1 = fold_for_warn (op1);
    6079      3317595 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    6080       279599 :             const_op1 = op1;
    6081      3317595 :           result_type = type0;
    6082      3317595 :           doing_shift = true;
    6083      3317595 :           if (TREE_CODE (const_op0) == INTEGER_CST
    6084      3006882 :               && tree_int_cst_sgn (const_op0) < 0
    6085          280 :               && !TYPE_OVERFLOW_WRAPS (type0)
    6086          196 :               && (complain & tf_warning)
    6087      3317791 :               && c_inhibit_evaluation_warnings == 0)
    6088          196 :             warning_at (location, OPT_Wshift_negative_value,
    6089              :                         "left shift of negative value");
    6090      3317595 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    6091              :             {
    6092      3037996 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    6093              :                 {
    6094           57 :                   if ((complain & tf_warning)
    6095           57 :                       && c_inhibit_evaluation_warnings == 0)
    6096           39 :                     warning_at (location, OPT_Wshift_count_negative,
    6097              :                                 "left shift count is negative");
    6098              :                 }
    6099      3037939 :               else if (compare_tree_int (const_op1,
    6100      3037939 :                                          TYPE_PRECISION (type0)) >= 0)
    6101              :                 {
    6102           83 :                   if ((complain & tf_warning)
    6103           61 :                       && c_inhibit_evaluation_warnings == 0)
    6104           45 :                     warning_at (location, OPT_Wshift_count_overflow,
    6105              :                                 "left shift count >= width of type");
    6106              :                 }
    6107      3037856 :               else if (TREE_CODE (const_op0) == INTEGER_CST
    6108      2795431 :                        && (complain & tf_warning))
    6109      2681960 :                 maybe_warn_shift_overflow (location, const_op0, const_op1);
    6110              :             }
    6111              :           /* Avoid converting op1 to result_type later.  */
    6112              :           converted = 1;
    6113              :         }
    6114              :       break;
    6115              : 
    6116     27445283 :     case EQ_EXPR:
    6117     27445283 :     case NE_EXPR:
    6118     27445283 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6119         3336 :         goto vector_compare;
    6120     27441947 :       if ((complain & tf_warning)
    6121     24396853 :           && c_inhibit_evaluation_warnings == 0
    6122     50673749 :           && (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)))
    6123       804845 :         warning_at (location, OPT_Wfloat_equal,
    6124              :                     "comparing floating-point with %<==%> "
    6125              :                     "or %<!=%> is unsafe");
    6126     27441947 :       {
    6127     27441947 :         tree stripped_orig_op0 = tree_strip_any_location_wrapper (orig_op0);
    6128     27441947 :         tree stripped_orig_op1 = tree_strip_any_location_wrapper (orig_op1);
    6129     27441947 :         if ((complain & tf_warning_or_error)
    6130     27441947 :             && ((TREE_CODE (stripped_orig_op0) == STRING_CST
    6131           39 :                  && !integer_zerop (cp_fully_fold (op1)))
    6132     24894213 :                 || (TREE_CODE (stripped_orig_op1) == STRING_CST
    6133           68 :                     && !integer_zerop (cp_fully_fold (op0)))))
    6134           47 :           warning_at (location, OPT_Waddress,
    6135              :                       "comparison with string literal results in "
    6136              :                       "unspecified behavior");
    6137     27441900 :         else if (TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6138     27441900 :                  && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE)
    6139              :           {
    6140              :             /* P2865R5 made array comparisons ill-formed in C++26.  */
    6141           68 :             if (complain & tf_warning_or_error)
    6142           45 :               do_warn_array_compare (location, code, stripped_orig_op0,
    6143              :                                      stripped_orig_op1);
    6144           23 :             else if (cxx_dialect >= cxx26)
    6145            1 :               return error_mark_node;
    6146              :           }
    6147              :       }
    6148              : 
    6149     27441946 :       build_type = boolean_type_node;
    6150     27441946 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6151              :            || code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
    6152     23132360 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6153              :               || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
    6154              :         short_compare = 1;
    6155        45722 :       else if (((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0))
    6156      4304466 :                 && null_ptr_cst_p (orig_op1))
    6157              :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    6158      6861326 :                || (code0 == POINTER_TYPE
    6159      2466794 :                    && TYPE_PTR_P (type1) && integer_zerop (op1)))
    6160              :         {
    6161      1856607 :           if (TYPE_PTR_P (type1))
    6162        19343 :             result_type = composite_pointer_type (location,
    6163              :                                                   type0, type1, op0, op1,
    6164              :                                                   CPO_COMPARISON, complain);
    6165              :           else
    6166              :             result_type = type0;
    6167              : 
    6168      1856607 :           if (char_type_p (TREE_TYPE (orig_op1)))
    6169              :             {
    6170           10 :               auto_diagnostic_group d;
    6171           10 :               if (warning_at (location, OPT_Wpointer_compare,
    6172              :                               "comparison between pointer and zero character "
    6173              :                               "constant"))
    6174           10 :                 inform (location,
    6175              :                         "did you mean to dereference the pointer?");
    6176           10 :             }
    6177      1856607 :           warn_for_null_address (location, op0, complain);
    6178              :         }
    6179         5598 :       else if (((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1))
    6180      2487522 :                 && null_ptr_cst_p (orig_op0))
    6181              :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    6182      4984483 :                || (code1 == POINTER_TYPE
    6183      2486221 :                    && TYPE_PTR_P (type0) && integer_zerop (op0)))
    6184              :         {
    6185          961 :           if (TYPE_PTR_P (type0))
    6186           68 :             result_type = composite_pointer_type (location,
    6187              :                                                   type0, type1, op0, op1,
    6188              :                                                   CPO_COMPARISON, complain);
    6189              :           else
    6190              :             result_type = type1;
    6191              : 
    6192          961 :           if (char_type_p (TREE_TYPE (orig_op0)))
    6193              :             {
    6194           10 :               auto_diagnostic_group d;
    6195           10 :               if (warning_at (location, OPT_Wpointer_compare,
    6196              :                              "comparison between pointer and zero character "
    6197              :                              "constant"))
    6198           10 :                 inform (location,
    6199              :                         "did you mean to dereference the pointer?");
    6200           10 :             }
    6201          961 :           warn_for_null_address (location, op1, complain);
    6202              :         }
    6203      2491727 :       else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6204        44402 :                || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1)))
    6205      2447733 :         result_type = composite_pointer_type (location,
    6206              :                                               type0, type1, op0, op1,
    6207              :                                               CPO_COMPARISON, complain);
    6208        43994 :       else if (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1))
    6209              :         /* One of the operands must be of nullptr_t type.  */
    6210           69 :         result_type = TREE_TYPE (nullptr_node);
    6211        43925 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6212              :         {
    6213           58 :           result_type = type0;
    6214           58 :           if (complain & tf_error)
    6215           56 :             permerror (location, "ISO C++ forbids comparison between "
    6216              :                        "pointer and integer");
    6217              :           else
    6218            2 :             return error_mark_node;
    6219              :         }
    6220        43867 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6221              :         {
    6222        38828 :           result_type = type1;
    6223        38828 :           if (complain & tf_error)
    6224           69 :             permerror (location, "ISO C++ forbids comparison between "
    6225              :                        "pointer and integer");
    6226              :           else
    6227        38759 :             return error_mark_node;
    6228              :         }
    6229         5039 :       else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (orig_op1))
    6230              :         {
    6231          240 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    6232              :               == ptrmemfunc_vbit_in_delta)
    6233              :             {
    6234              :               tree pfn0, delta0, e1, e2;
    6235              : 
    6236              :               if (TREE_SIDE_EFFECTS (op0))
    6237              :                 op0 = cp_save_expr (op0);
    6238              : 
    6239              :               pfn0 = pfn_from_ptrmemfunc (op0);
    6240              :               delta0 = delta_from_ptrmemfunc (op0);
    6241              :               {
    6242              :                 /* If we will warn below about a null-address compare
    6243              :                    involving the orig_op0 ptrmemfunc, we'd likely also
    6244              :                    warn about the pfn0's null-address compare, and
    6245              :                    that would be redundant, so suppress it.  */
    6246              :                 warning_sentinel ws (warn_address);
    6247              :                 e1 = cp_build_binary_op (location,
    6248              :                                          EQ_EXPR,
    6249              :                                          pfn0,
    6250              :                                          build_zero_cst (TREE_TYPE (pfn0)),
    6251              :                                          complain);
    6252              :               }
    6253              :               e2 = cp_build_binary_op (location,
    6254              :                                        BIT_AND_EXPR,
    6255              :                                        delta0,
    6256              :                                        integer_one_node,
    6257              :                                        complain);
    6258              : 
    6259              :               if (complain & tf_warning)
    6260              :                 maybe_warn_zero_as_null_pointer_constant (op1, input_location);
    6261              : 
    6262              :               e2 = cp_build_binary_op (location,
    6263              :                                        EQ_EXPR, e2, integer_zero_node,
    6264              :                                        complain);
    6265              :               op0 = cp_build_binary_op (location,
    6266              :                                         TRUTH_ANDIF_EXPR, e1, e2,
    6267              :                                         complain);
    6268              :               op1 = cp_convert (TREE_TYPE (op0), integer_one_node, complain);
    6269              :             }
    6270              :           else
    6271              :             {
    6272          240 :               op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
    6273          240 :               op1 = cp_convert (TREE_TYPE (op0), op1, complain);
    6274              :             }
    6275          240 :           result_type = TREE_TYPE (op0);
    6276              : 
    6277          240 :           warn_for_null_address (location, orig_op0, complain);
    6278              :         }
    6279         4799 :       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (orig_op0))
    6280           36 :         return cp_build_binary_op (location, code, op1, op0, complain);
    6281         4763 :       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
    6282              :         {
    6283          145 :           tree type;
    6284              :           /* E will be the final comparison.  */
    6285          145 :           tree e;
    6286              :           /* E1 and E2 are for scratch.  */
    6287          145 :           tree e1;
    6288          145 :           tree e2;
    6289          145 :           tree pfn0;
    6290          145 :           tree pfn1;
    6291          145 :           tree delta0;
    6292          145 :           tree delta1;
    6293              : 
    6294          145 :           type = composite_pointer_type (location, type0, type1, op0, op1,
    6295              :                                          CPO_COMPARISON, complain);
    6296              : 
    6297          145 :           if (!same_type_p (TREE_TYPE (op0), type))
    6298            6 :             op0 = cp_convert_and_check (type, op0, complain);
    6299          145 :           if (!same_type_p (TREE_TYPE (op1), type))
    6300            9 :             op1 = cp_convert_and_check (type, op1, complain);
    6301              : 
    6302          145 :           if (op0 == error_mark_node || op1 == error_mark_node)
    6303              :             return error_mark_node;
    6304              : 
    6305          142 :           if (TREE_SIDE_EFFECTS (op0))
    6306           79 :             op0 = cp_save_expr (op0);
    6307          142 :           if (TREE_SIDE_EFFECTS (op1))
    6308            3 :             op1 = cp_save_expr (op1);
    6309              : 
    6310          142 :           pfn0 = pfn_from_ptrmemfunc (op0);
    6311          142 :           pfn0 = cp_fully_fold (pfn0);
    6312              :           /* Avoid -Waddress warnings (c++/64877).  */
    6313          142 :           if (TREE_CODE (pfn0) == ADDR_EXPR)
    6314           20 :             suppress_warning (pfn0, OPT_Waddress);
    6315          142 :           pfn1 = pfn_from_ptrmemfunc (op1);
    6316          142 :           pfn1 = cp_fully_fold (pfn1);
    6317          142 :           delta0 = delta_from_ptrmemfunc (op0);
    6318          142 :           delta1 = delta_from_ptrmemfunc (op1);
    6319          142 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    6320              :               == ptrmemfunc_vbit_in_delta)
    6321              :             {
    6322              :               /* We generate:
    6323              : 
    6324              :                  (op0.pfn == op1.pfn
    6325              :                   && ((op0.delta == op1.delta)
    6326              :                        || (!op0.pfn && op0.delta & 1 == 0
    6327              :                            && op1.delta & 1 == 0))
    6328              : 
    6329              :                  The reason for the `!op0.pfn' bit is that a NULL
    6330              :                  pointer-to-member is any member with a zero PFN and
    6331              :                  LSB of the DELTA field is 0.  */
    6332              : 
    6333              :               e1 = cp_build_binary_op (location, BIT_AND_EXPR,
    6334              :                                        delta0,
    6335              :                                        integer_one_node,
    6336              :                                        complain);
    6337              :               e1 = cp_build_binary_op (location,
    6338              :                                        EQ_EXPR, e1, integer_zero_node,
    6339              :                                        complain);
    6340              :               e2 = cp_build_binary_op (location, BIT_AND_EXPR,
    6341              :                                        delta1,
    6342              :                                        integer_one_node,
    6343              :                                        complain);
    6344              :               e2 = cp_build_binary_op (location,
    6345              :                                        EQ_EXPR, e2, integer_zero_node,
    6346              :                                        complain);
    6347              :               e1 = cp_build_binary_op (location,
    6348              :                                        TRUTH_ANDIF_EXPR, e2, e1,
    6349              :                                        complain);
    6350              :               e2 = cp_build_binary_op (location, EQ_EXPR,
    6351              :                                        pfn0,
    6352              :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6353              :                                        complain);
    6354              :               e2 = cp_build_binary_op (location,
    6355              :                                        TRUTH_ANDIF_EXPR, e2, e1, complain);
    6356              :               e1 = cp_build_binary_op (location,
    6357              :                                        EQ_EXPR, delta0, delta1, complain);
    6358              :               e1 = cp_build_binary_op (location,
    6359              :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6360              :             }
    6361              :           else
    6362              :             {
    6363              :               /* We generate:
    6364              : 
    6365              :                  (op0.pfn == op1.pfn
    6366              :                  && (!op0.pfn || op0.delta == op1.delta))
    6367              : 
    6368              :                  The reason for the `!op0.pfn' bit is that a NULL
    6369              :                  pointer-to-member is any member with a zero PFN; the
    6370              :                  DELTA field is unspecified.  */
    6371              : 
    6372          142 :               e1 = cp_build_binary_op (location,
    6373              :                                        EQ_EXPR, delta0, delta1, complain);
    6374          142 :               e2 = cp_build_binary_op (location,
    6375              :                                        EQ_EXPR,
    6376              :                                        pfn0,
    6377          142 :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6378              :                                        complain);
    6379          142 :               e1 = cp_build_binary_op (location,
    6380              :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6381              :             }
    6382          142 :           e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
    6383          142 :           e = cp_build_binary_op (location,
    6384              :                                   TRUTH_ANDIF_EXPR, e2, e1, complain);
    6385          142 :           if (code == EQ_EXPR)
    6386              :             return e;
    6387           34 :           return cp_build_binary_op (location,
    6388           34 :                                      EQ_EXPR, e, integer_zero_node, complain);
    6389              :         }
    6390              :       /* [expr.eq]: "If both operands are of type std::meta::info,
    6391              :          comparison is defined as follows..."  */
    6392         4618 :       else if (code0 == META_TYPE && code1 == META_TYPE)
    6393              :         result_type = type0;
    6394              :       else
    6395              :         {
    6396           28 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type0)
    6397              :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0),
    6398              :                                        type1));
    6399           28 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type1)
    6400              :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1),
    6401              :                                        type0));
    6402              :         }
    6403              : 
    6404              :       break;
    6405              : 
    6406          241 :     case MAX_EXPR:
    6407          241 :     case MIN_EXPR:
    6408          241 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
    6409          241 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
    6410              :         shorten = 1;
    6411            0 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6412            0 :         result_type = composite_pointer_type (location,
    6413              :                                               type0, type1, op0, op1,
    6414              :                                               CPO_COMPARISON, complain);
    6415              :       break;
    6416              : 
    6417     27078907 :     case LE_EXPR:
    6418     27078907 :     case GE_EXPR:
    6419     27078907 :     case LT_EXPR:
    6420     27078907 :     case GT_EXPR:
    6421     27078907 :     case SPACESHIP_EXPR:
    6422     27078907 :       if (TREE_CODE (orig_op0) == STRING_CST
    6423     27078907 :           || TREE_CODE (orig_op1) == STRING_CST)
    6424              :         {
    6425            0 :           if (complain & tf_warning)
    6426            0 :             warning_at (location, OPT_Waddress,
    6427              :                         "comparison with string literal results "
    6428              :                         "in unspecified behavior");
    6429              :         }
    6430     27078907 :       else if (TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6431          224 :                && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE
    6432     27079022 :                && code != SPACESHIP_EXPR)
    6433              :         {
    6434           96 :           if (complain & tf_warning_or_error)
    6435           51 :             do_warn_array_compare (location, code,
    6436              :                                    tree_strip_any_location_wrapper (orig_op0),
    6437              :                                    tree_strip_any_location_wrapper (orig_op1));
    6438           45 :           else if (cxx_dialect >= cxx26)
    6439            1 :             return error_mark_node;
    6440              :         }
    6441              : 
    6442     27078906 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6443              :         {
    6444         8238 :         vector_compare:
    6445         8238 :           tree intt;
    6446         8238 :           if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    6447         8238 :                                                           TREE_TYPE (type1))
    6448         8238 :               && !vector_types_compatible_elements_p (type0, type1))
    6449              :             {
    6450            3 :               if (complain & tf_error)
    6451              :                 {
    6452            3 :                   auto_diagnostic_group d;
    6453            3 :                   error_at (location, "comparing vectors with different "
    6454              :                                       "element types");
    6455            3 :                   inform (location, "operand types are %qT and %qT",
    6456              :                           type0, type1);
    6457            3 :                 }
    6458            3 :               return error_mark_node;
    6459              :             }
    6460              : 
    6461         8235 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
    6462        16470 :                         TYPE_VECTOR_SUBPARTS (type1)))
    6463              :             {
    6464            3 :               if (complain & tf_error)
    6465              :                 {
    6466            3 :                   auto_diagnostic_group d;
    6467            3 :                   error_at (location, "comparing vectors with different "
    6468              :                                       "number of elements");
    6469            3 :                   inform (location, "operand types are %qT and %qT",
    6470              :                           type0, type1);
    6471            3 :                 }
    6472            3 :               return error_mark_node;
    6473              :             }
    6474              : 
    6475              :           /* It's not precisely specified how the usual arithmetic
    6476              :              conversions apply to the vector types.  Here, we use
    6477              :              the unsigned type if one of the operands is signed and
    6478              :              the other one is unsigned.  */
    6479         8232 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
    6480              :             {
    6481           36 :               if (!TYPE_UNSIGNED (type0))
    6482           36 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
    6483              :               else
    6484            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
    6485           36 :               warning_at (location, OPT_Wsign_compare, "comparison between "
    6486              :                           "types %qT and %qT", type0, type1);
    6487              :             }
    6488              : 
    6489         8232 :           if (resultcode == SPACESHIP_EXPR)
    6490              :             {
    6491            3 :               if (complain & tf_error)
    6492            3 :                 sorry_at (location, "three-way comparison of vectors");
    6493            3 :               return error_mark_node;
    6494              :             }
    6495              : 
    6496         8229 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
    6497              :             result_type = type0;
    6498              :           else
    6499              :             {
    6500              :               /* Always construct signed integer vector type.  */
    6501         8229 :               auto intmode = SCALAR_TYPE_MODE (TREE_TYPE (type0));
    6502         8229 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
    6503              : 
    6504        16458 :               intt = c_common_type_for_size (GET_MODE_BITSIZE (intmode), 0);
    6505         8229 :               if (!intt)
    6506              :                 {
    6507            0 :                   if (complain & tf_error)
    6508            0 :                     error_at (location, "could not find an integer type "
    6509            0 :                                 "of the same size as %qT", TREE_TYPE (type0));
    6510            0 :                   return error_mark_node;
    6511              :                 }
    6512         8229 :               result_type = build_opaque_vector_type (intt, nelts);
    6513              :             }
    6514         8229 :           return build_vec_cmp (resultcode, result_type, op0, op1);
    6515              :         }
    6516     27074004 :       build_type = boolean_type_node;
    6517     27074004 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6518              :            || code0 == ENUMERAL_TYPE)
    6519     24339147 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6520              :                || code1 == ENUMERAL_TYPE))
    6521              :         short_compare = 1;
    6522      2734960 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6523      2734680 :         result_type = composite_pointer_type (location,
    6524              :                                               type0, type1, op0, op1,
    6525              :                                               CPO_COMPARISON, complain);
    6526           73 :       else if ((code0 == POINTER_TYPE && null_ptr_cst_p (orig_op1))
    6527          208 :                || (code1 == POINTER_TYPE && null_ptr_cst_p (orig_op0))
    6528          434 :                || (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)))
    6529              :         {
    6530              :           /* Core Issue 1512 made this ill-formed.  */
    6531          190 :           if (complain & tf_error)
    6532          186 :             error_at (location, "ordered comparison of pointer with "
    6533              :                       "integer zero (%qT and %qT)", type0, type1);
    6534          190 :           return error_mark_node;
    6535              :         }
    6536           90 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6537              :         {
    6538            0 :           result_type = type0;
    6539            0 :           if (complain & tf_error)
    6540            0 :             permerror (location, "ISO C++ forbids comparison between "
    6541              :                        "pointer and integer");
    6542              :           else
    6543            0 :             return error_mark_node;
    6544              :         }
    6545           90 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6546              :         {
    6547           24 :           result_type = type1;
    6548           24 :           if (complain & tf_error)
    6549           24 :             permerror (location, "ISO C++ forbids comparison between "
    6550              :                        "pointer and integer");
    6551              :           else
    6552            0 :             return error_mark_node;
    6553              :         }
    6554              : 
    6555     27073814 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    6556      2734705 :           && !processing_template_decl
    6557     29586463 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
    6558              :         {
    6559           49 :           op0 = cp_save_expr (op0);
    6560           49 :           op1 = cp_save_expr (op1);
    6561              : 
    6562           49 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
    6563           49 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
    6564              :         }
    6565              : 
    6566              :       break;
    6567              : 
    6568            0 :     case UNORDERED_EXPR:
    6569            0 :     case ORDERED_EXPR:
    6570            0 :     case UNLT_EXPR:
    6571            0 :     case UNLE_EXPR:
    6572            0 :     case UNGT_EXPR:
    6573            0 :     case UNGE_EXPR:
    6574            0 :     case UNEQ_EXPR:
    6575            0 :       build_type = integer_type_node;
    6576            0 :       if (code0 != REAL_TYPE || code1 != REAL_TYPE)
    6577              :         {
    6578            0 :           if (complain & tf_error)
    6579            0 :             error ("unordered comparison on non-floating-point argument");
    6580            0 :           return error_mark_node;
    6581              :         }
    6582              :       common = 1;
    6583              :       break;
    6584              : 
    6585              :     default:
    6586              :       break;
    6587              :     }
    6588              : 
    6589    146482312 :   if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
    6590              :         || code0 == ENUMERAL_TYPE)
    6591    119205785 :        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6592              :            || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
    6593              :     arithmetic_types_p = 1;
    6594              :   else
    6595              :     {
    6596     27679949 :       arithmetic_types_p = 0;
    6597              :       /* Vector arithmetic is only allowed when both sides are vectors.  */
    6598     27679949 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6599              :         {
    6600        60242 :           if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
    6601        60242 :               || !vector_types_compatible_elements_p (type0, type1))
    6602              :             {
    6603           18 :               if (complain & tf_error)
    6604              :                 {
    6605              :                   /* "location" already embeds the locations of the
    6606              :                      operands, so we don't need to add them separately
    6607              :                      to richloc.  */
    6608           18 :                   rich_location richloc (line_table, location);
    6609           18 :                   binary_op_error (&richloc, code, type0, type1);
    6610           18 :                 }
    6611           18 :               return error_mark_node;
    6612              :             }
    6613              :           arithmetic_types_p = 1;
    6614              :         }
    6615              :     }
    6616              :   /* Determine the RESULT_TYPE, if it is not already known.  */
    6617    146482294 :   if (!result_type
    6618    146482294 :       && arithmetic_types_p
    6619    114183500 :       && (shorten || common || short_compare))
    6620              :     {
    6621    114183353 :       result_type = cp_common_type (type0, type1);
    6622    114183353 :       if (result_type == error_mark_node)
    6623              :         {
    6624            6 :           tree t1 = type0;
    6625            6 :           tree t2 = type1;
    6626            6 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6627            0 :             t1 = TREE_TYPE (t1);
    6628            6 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6629            0 :             t2 = TREE_TYPE (t2);
    6630            6 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6631              :                                && TREE_CODE (t2) == REAL_TYPE
    6632              :                                && (extended_float_type_p (t1)
    6633              :                                    || extended_float_type_p (t2))
    6634              :                                && cp_compare_floating_point_conversion_ranks
    6635              :                                     (t1, t2) == 3);
    6636            6 :           if (complain & tf_error)
    6637              :             {
    6638            6 :               rich_location richloc (line_table, location);
    6639            6 :               binary_op_error (&richloc, code, type0, type1);
    6640            6 :             }
    6641            6 :           return error_mark_node;
    6642              :         }
    6643    114183347 :       if (complain & tf_warning)
    6644    104020384 :         do_warn_double_promotion (result_type, type0, type1,
    6645              :                                   "implicit conversion from %qH to %qI "
    6646              :                                   "to match other operand of binary "
    6647              :                                   "expression", location);
    6648    114183347 :       if (do_warn_enum_conversions (location, code, TREE_TYPE (orig_op0),
    6649    114183347 :                                     TREE_TYPE (orig_op1), complain))
    6650           12 :         return error_mark_node;
    6651              :     }
    6652    146482276 :   if (may_need_excess_precision
    6653    107757091 :       && (orig_type0 != type0 || orig_type1 != type1)
    6654        56992 :       && build_type == NULL_TREE
    6655        56992 :       && result_type)
    6656              :     {
    6657        43312 :       gcc_assert (common);
    6658        43312 :       semantic_result_type = cp_common_type (orig_type0, orig_type1);
    6659        43312 :       if (semantic_result_type == error_mark_node)
    6660              :         {
    6661            0 :           tree t1 = orig_type0;
    6662            0 :           tree t2 = orig_type1;
    6663            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6664            0 :             t1 = TREE_TYPE (t1);
    6665            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6666            0 :             t2 = TREE_TYPE (t2);
    6667            0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6668              :                                && TREE_CODE (t2) == REAL_TYPE
    6669              :                                && (extended_float_type_p (t1)
    6670              :                                    || extended_float_type_p (t2))
    6671              :                                && cp_compare_floating_point_conversion_ranks
    6672              :                                     (t1, t2) == 3);
    6673            0 :           if (complain & tf_error)
    6674              :             {
    6675            0 :               rich_location richloc (line_table, location);
    6676            0 :               binary_op_error (&richloc, code, type0, type1);
    6677            0 :             }
    6678            0 :           return error_mark_node;
    6679              :         }
    6680              :     }
    6681              : 
    6682    146482276 :   if (code == SPACESHIP_EXPR)
    6683              :     {
    6684       625674 :       iloc_sentinel s (location);
    6685              : 
    6686       625674 :       tree orig_type0 = TREE_TYPE (orig_op0);
    6687       625674 :       tree_code orig_code0 = TREE_CODE (orig_type0);
    6688       625674 :       tree orig_type1 = TREE_TYPE (orig_op1);
    6689       625674 :       tree_code orig_code1 = TREE_CODE (orig_type1);
    6690       625674 :       if (!result_type || result_type == error_mark_node)
    6691              :         /* Nope.  */
    6692              :         result_type = NULL_TREE;
    6693       625653 :       else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE))
    6694              :         /* "If one of the operands is of type bool and the other is not, the
    6695              :            program is ill-formed."  */
    6696              :         result_type = NULL_TREE;
    6697       625650 :       else if (code0 == POINTER_TYPE && orig_code0 != POINTER_TYPE
    6698           19 :                && code1 == POINTER_TYPE && orig_code1 != POINTER_TYPE)
    6699              :         /* We only do array/function-to-pointer conversion if "at least one of
    6700              :            the operands is of pointer type".  */
    6701              :         result_type = NULL_TREE;
    6702       625631 :       else if (TYPE_PTRFN_P (result_type) || NULLPTR_TYPE_P (result_type))
    6703              :         /* <=> no longer supports equality relations.  */
    6704              :         result_type = NULL_TREE;
    6705       625628 :       else if (orig_code0 == ENUMERAL_TYPE && orig_code1 == ENUMERAL_TYPE
    6706       625658 :                && !(same_type_ignoring_top_level_qualifiers_p
    6707           30 :                     (orig_type0, orig_type1)))
    6708              :         /* "If both operands have arithmetic types, or one operand has integral
    6709              :            type and the other operand has unscoped enumeration type, the usual
    6710              :            arithmetic conversions are applied to the operands."  So we don't do
    6711              :            arithmetic conversions if the operands both have enumeral type.  */
    6712              :         result_type = NULL_TREE;
    6713       625613 :       else if ((orig_code0 == ENUMERAL_TYPE && orig_code1 == REAL_TYPE)
    6714       625607 :                || (orig_code0 == REAL_TYPE && orig_code1 == ENUMERAL_TYPE))
    6715              :         /* [depr.arith.conv.enum]: Three-way comparisons between such operands
    6716              :            [where one is of enumeration type and the other is of a different
    6717              :            enumeration type or a floating-point type] are ill-formed.  */
    6718              :         result_type = NULL_TREE;
    6719              : 
    6720       625601 :       if (result_type)
    6721              :         {
    6722       625601 :           build_type = spaceship_type (result_type, complain);
    6723       625601 :           if (build_type == error_mark_node)
    6724              :             return error_mark_node;
    6725              :         }
    6726              : 
    6727       625659 :       if (result_type && arithmetic_types_p)
    6728              :         {
    6729              :           /* If a narrowing conversion is required, other than from an integral
    6730              :              type to a floating point type, the program is ill-formed.  */
    6731       292682 :           bool ok = true;
    6732       292682 :           if (TREE_CODE (result_type) == REAL_TYPE
    6733          615 :               && CP_INTEGRAL_TYPE_P (orig_type0))
    6734              :             /* OK */;
    6735       292675 :           else if (!check_narrowing (result_type, orig_op0, complain))
    6736       292682 :             ok = false;
    6737       292682 :           if (TREE_CODE (result_type) == REAL_TYPE
    6738          615 :               && CP_INTEGRAL_TYPE_P (orig_type1))
    6739              :             /* OK */;
    6740       292675 :           else if (!check_narrowing (result_type, orig_op1, complain))
    6741              :             ok = false;
    6742       292682 :           if (!ok && !(complain & tf_error))
    6743            2 :             return error_mark_node;
    6744              :         }
    6745       625674 :     }
    6746              : 
    6747    146482259 :   if (!result_type)
    6748              :     {
    6749          606 :       if (complain & tf_error)
    6750              :         {
    6751          221 :           binary_op_rich_location richloc (location,
    6752          221 :                                            orig_op0, orig_op1, true);
    6753          221 :           error_at (&richloc,
    6754              :                     "invalid operands of types %qT and %qT to binary %qO",
    6755          221 :                     TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code);
    6756          221 :         }
    6757          606 :       return error_mark_node;
    6758              :     }
    6759              : 
    6760              :   /* If we're in a template, the only thing we need to know is the
    6761              :      RESULT_TYPE.  */
    6762    146481653 :   if (processing_template_decl)
    6763              :     {
    6764              :       /* Since the middle-end checks the type when doing a build2, we
    6765              :          need to build the tree in pieces.  This built tree will never
    6766              :          get out of the front-end as we replace it when instantiating
    6767              :          the template.  */
    6768     68077800 :       tree tmp = build2 (resultcode,
    6769              :                          build_type ? build_type : result_type,
    6770              :                          NULL_TREE, op1);
    6771     42497793 :       TREE_OPERAND (tmp, 0) = op0;
    6772     42497793 :       if (semantic_result_type)
    6773           72 :         tmp = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, tmp);
    6774              :       return tmp;
    6775              :     }
    6776              : 
    6777              :   /* Remember the original type; RESULT_TYPE might be changed later on
    6778              :      by shorten_binary_op.  */
    6779    103983860 :   tree orig_type = result_type;
    6780              : 
    6781    103983860 :   if (arithmetic_types_p)
    6782              :     {
    6783     89118352 :       bool first_complex = (code0 == COMPLEX_TYPE);
    6784     89118352 :       bool second_complex = (code1 == COMPLEX_TYPE);
    6785     89118352 :       int none_complex = (!first_complex && !second_complex);
    6786              : 
    6787              :       /* Adapted from patch for c/24581.  */
    6788     89118352 :       if (first_complex != second_complex
    6789       161667 :           && (code == PLUS_EXPR
    6790              :               || code == MINUS_EXPR
    6791       161667 :               || code == MULT_EXPR
    6792        42236 :               || (code == TRUNC_DIV_EXPR && first_complex))
    6793       148160 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
    6794     89266351 :           && flag_signed_zeros)
    6795              :         {
    6796              :           /* An operation on mixed real/complex operands must be
    6797              :              handled specially, but the language-independent code can
    6798              :              more easily optimize the plain complex arithmetic if
    6799              :              -fno-signed-zeros.  */
    6800       147999 :           tree real_type = TREE_TYPE (result_type);
    6801       147999 :           tree real, imag;
    6802       147999 :           if (first_complex)
    6803              :             {
    6804       114951 :               if (TREE_TYPE (op0) != result_type)
    6805            6 :                 op0 = cp_convert_and_check (result_type, op0, complain);
    6806       114951 :               if (TREE_TYPE (op1) != real_type)
    6807           26 :                 op1 = cp_convert_and_check (real_type, op1, complain);
    6808              :             }
    6809              :           else
    6810              :             {
    6811        33048 :               if (TREE_TYPE (op0) != real_type)
    6812           31 :                 op0 = cp_convert_and_check (real_type, op0, complain);
    6813        33048 :               if (TREE_TYPE (op1) != result_type)
    6814           32 :                 op1 = cp_convert_and_check (result_type, op1, complain);
    6815              :             }
    6816       147999 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
    6817            0 :             return error_mark_node;
    6818       147999 :           if (first_complex)
    6819              :             {
    6820       114951 :               op0 = cp_save_expr (op0);
    6821       114951 :               real = cp_build_unary_op (REALPART_EXPR, op0, true, complain);
    6822       114951 :               imag = cp_build_unary_op (IMAGPART_EXPR, op0, true, complain);
    6823       114951 :               switch (code)
    6824              :                 {
    6825        57453 :                 case MULT_EXPR:
    6826        57453 :                 case TRUNC_DIV_EXPR:
    6827        57453 :                   op1 = cp_save_expr (op1);
    6828        57453 :                   imag = build2 (resultcode, real_type, imag, op1);
    6829              :                   /* Fall through.  */
    6830       114951 :                 case PLUS_EXPR:
    6831       114951 :                 case MINUS_EXPR:
    6832       114951 :                   real = build2 (resultcode, real_type, real, op1);
    6833       114951 :                   break;
    6834              :                 default:
    6835              :                   gcc_unreachable();
    6836              :                 }
    6837              :             }
    6838              :           else
    6839              :             {
    6840        33048 :               op1 = cp_save_expr (op1);
    6841        33048 :               real = cp_build_unary_op (REALPART_EXPR, op1, true, complain);
    6842        33048 :               imag = cp_build_unary_op (IMAGPART_EXPR, op1, true, complain);
    6843        33048 :               switch (code)
    6844              :                 {
    6845          638 :                 case MULT_EXPR:
    6846          638 :                   op0 = cp_save_expr (op0);
    6847          638 :                   imag = build2 (resultcode, real_type, op0, imag);
    6848              :                   /* Fall through.  */
    6849        17301 :                 case PLUS_EXPR:
    6850        17301 :                   real = build2 (resultcode, real_type, op0, real);
    6851        17301 :                   break;
    6852        15747 :                 case MINUS_EXPR:
    6853        15747 :                   real = build2 (resultcode, real_type, op0, real);
    6854        15747 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
    6855        15747 :                   break;
    6856            0 :                 default:
    6857            0 :                   gcc_unreachable();
    6858              :                 }
    6859              :             }
    6860       147999 :           result = build2 (COMPLEX_EXPR, result_type, real, imag);
    6861       147999 :           if (semantic_result_type)
    6862           26 :             result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6863              :                              result);
    6864              :           return result;
    6865              :         }
    6866              : 
    6867              :       /* For certain operations (which identify themselves by shorten != 0)
    6868              :          if both args were extended from the same smaller type,
    6869              :          do the arithmetic in that type and then extend.
    6870              : 
    6871              :          shorten !=0 and !=1 indicates a bitwise operation.
    6872              :          For them, this optimization is safe only if
    6873              :          both args are zero-extended or both are sign-extended.
    6874              :          Otherwise, we might change the result.
    6875              :          E.g., (short)-1 | (unsigned short)-1 is (int)-1
    6876              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
    6877              : 
    6878     88970353 :       if (shorten && none_complex)
    6879              :         {
    6880      7014228 :           final_type = result_type;
    6881      7014228 :           result_type = shorten_binary_op (result_type, op0, op1,
    6882              :                                            shorten == -1);
    6883              :         }
    6884              : 
    6885              :       /* Shifts can be shortened if shifting right.  */
    6886              : 
    6887     88970353 :       if (short_shift)
    6888              :         {
    6889       865989 :           int unsigned_arg;
    6890       865989 :           tree arg0 = get_narrower (op0, &unsigned_arg);
    6891              :           /* We're not really warning here but when we set short_shift we
    6892              :              used fold_for_warn to fold the operand.  */
    6893       865989 :           tree const_op1 = fold_for_warn (op1);
    6894              : 
    6895       865989 :           final_type = result_type;
    6896              : 
    6897       865989 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
    6898       786847 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
    6899              : 
    6900       865989 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
    6901         1342 :               && tree_int_cst_sgn (const_op1) > 0
    6902              :               /* We can shorten only if the shift count is less than the
    6903              :                  number of bits in the smaller type size.  */
    6904         1342 :               && compare_tree_int (const_op1,
    6905         1342 :                                    TYPE_PRECISION (TREE_TYPE (arg0))) < 0
    6906              :               /* We cannot drop an unsigned shift after sign-extension.  */
    6907       867291 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
    6908              :             {
    6909              :               /* Do an unsigned shift if the operand was zero-extended.  */
    6910         1295 :               result_type
    6911         1295 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
    6912         1295 :                                                     TREE_TYPE (arg0));
    6913              :               /* Convert value-to-be-shifted to that type.  */
    6914         1295 :               if (TREE_TYPE (op0) != result_type)
    6915         1295 :                 op0 = convert (result_type, op0);
    6916              :               converted = 1;
    6917              :             }
    6918              :         }
    6919              : 
    6920              :       /* Comparison operations are shortened too but differently.
    6921              :          They identify themselves by setting short_compare = 1.  */
    6922              : 
    6923     88970353 :       if (short_compare)
    6924              :         {
    6925              :           /* We call shorten_compare only for diagnostics.  */
    6926     30961486 :           tree xop0 = fold_simple (op0);
    6927     30961486 :           tree xop1 = fold_simple (op1);
    6928     30961486 :           tree xresult_type = result_type;
    6929     30961486 :           enum tree_code xresultcode = resultcode;
    6930     30961486 :           shorten_compare (location, &xop0, &xop1, &xresult_type,
    6931              :                            &xresultcode);
    6932              :         }
    6933              : 
    6934     58008780 :       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
    6935     30961675 :           && warn_sign_compare
    6936              :           /* Do not warn until the template is instantiated; we cannot
    6937              :              bound the ranges of the arguments until that point.  */
    6938       345739 :           && !processing_template_decl
    6939       345739 :           && (complain & tf_warning)
    6940       337760 :           && c_inhibit_evaluation_warnings == 0
    6941              :           /* Even unsigned enum types promote to signed int.  We don't
    6942              :              want to issue -Wsign-compare warnings for this case.  */
    6943       321329 :           && !enum_cast_to_int (orig_op0)
    6944     89291682 :           && !enum_cast_to_int (orig_op1))
    6945              :         {
    6946       321322 :           warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
    6947              :                                  result_type, resultcode);
    6948              :         }
    6949              :     }
    6950              : 
    6951              :   /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
    6952              :      Then the expression will be built.
    6953              :      It will be given type FINAL_TYPE if that is nonzero;
    6954              :      otherwise, it will be given type RESULT_TYPE.  */
    6955    103835861 :   if (! converted)
    6956              :     {
    6957    100001876 :       warning_sentinel w (warn_sign_conversion, short_compare);
    6958    100001876 :       if (!same_type_p (TREE_TYPE (op0), result_type))
    6959      4466650 :         op0 = cp_convert_and_check (result_type, op0, complain);
    6960    100001876 :       if (!same_type_p (TREE_TYPE (op1), result_type))
    6961     19492152 :         op1 = cp_convert_and_check (result_type, op1, complain);
    6962              : 
    6963    100001876 :       if (op0 == error_mark_node || op1 == error_mark_node)
    6964           58 :         return error_mark_node;
    6965    100001876 :     }
    6966              : 
    6967    103835803 :   if (build_type == NULL_TREE)
    6968     66276987 :     build_type = result_type;
    6969              : 
    6970    103835803 :   if (doing_shift
    6971      3833248 :       && flag_strong_eval_order == 2
    6972      3733636 :       && TREE_SIDE_EFFECTS (op1)
    6973    103858681 :       && !processing_template_decl)
    6974              :     {
    6975              :       /* In C++17, in both op0 << op1 and op0 >> op1 op0 is sequenced before
    6976              :          op1, so if op1 has side-effects, use SAVE_EXPR around op0.  */
    6977        22878 :       op0 = cp_save_expr (op0);
    6978        22878 :       instrument_expr = op0;
    6979              :     }
    6980              : 
    6981    103835803 :   if (sanitize_flags_p ((SANITIZE_SHIFT
    6982              :                          | SANITIZE_DIVIDE
    6983              :                          | SANITIZE_FLOAT_DIVIDE
    6984              :                          | SANITIZE_SI_OVERFLOW))
    6985        13786 :       && current_function_decl != NULL_TREE
    6986        11389 :       && !processing_template_decl
    6987    103847192 :       && (doing_div_or_mod || doing_shift))
    6988              :     {
    6989              :       /* OP0 and/or OP1 might have side-effects.  */
    6990          939 :       op0 = cp_save_expr (op0);
    6991          939 :       op1 = cp_save_expr (op1);
    6992          939 :       op0 = fold_non_dependent_expr (op0, complain);
    6993          939 :       op1 = fold_non_dependent_expr (op1, complain);
    6994          939 :       tree instrument_expr1 = NULL_TREE;
    6995          939 :       if (doing_div_or_mod
    6996          939 :           && sanitize_flags_p (SANITIZE_DIVIDE
    6997              :                                | SANITIZE_FLOAT_DIVIDE
    6998              :                                | SANITIZE_SI_OVERFLOW))
    6999              :         {
    7000              :           /* For diagnostics we want to use the promoted types without
    7001              :              shorten_binary_op.  So convert the arguments to the
    7002              :              original result_type.  */
    7003          475 :           tree cop0 = op0;
    7004          475 :           tree cop1 = op1;
    7005          475 :           if (TREE_TYPE (cop0) != orig_type)
    7006            6 :             cop0 = cp_convert (orig_type, op0, complain);
    7007          475 :           if (TREE_TYPE (cop1) != orig_type)
    7008           39 :             cop1 = cp_convert (orig_type, op1, complain);
    7009          475 :           instrument_expr1 = ubsan_instrument_division (location, cop0, cop1);
    7010              :         }
    7011          464 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
    7012          383 :         instrument_expr1 = ubsan_instrument_shift (location, code, op0, op1);
    7013          939 :       if (instrument_expr != NULL)
    7014           18 :         instrument_expr = add_stmt_to_compound (instrument_expr,
    7015              :                                                 instrument_expr1);
    7016              :       else
    7017          921 :         instrument_expr = instrument_expr1;
    7018              :     }
    7019              : 
    7020    103835803 :   result = build2_loc (location, resultcode, build_type, op0, op1);
    7021    103835803 :   if (final_type != 0)
    7022      7880217 :     result = cp_convert (final_type, result, complain);
    7023              : 
    7024    103835803 :   if (instrument_expr != NULL)
    7025        23376 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    7026              :                      instrument_expr, result);
    7027              : 
    7028    103835803 :   if (resultcode == SPACESHIP_EXPR && !processing_template_decl)
    7029       525382 :     result = get_target_expr (result, complain);
    7030              : 
    7031    103835803 :   if (semantic_result_type)
    7032        43214 :     result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, result);
    7033              : 
    7034    103835803 :   if (!c_inhibit_evaluation_warnings)
    7035              :     {
    7036     88181561 :       if (!processing_template_decl)
    7037              :         {
    7038     88181561 :           op0 = cp_fully_fold (op0);
    7039              :           /* Only consider the second argument if the first isn't overflowed.  */
    7040     88181561 :           if (!CONSTANT_CLASS_P (op0) || TREE_OVERFLOW_P (op0))
    7041              :             return result;
    7042     24836053 :           op1 = cp_fully_fold (op1);
    7043     24836053 :           if (!CONSTANT_CLASS_P (op1) || TREE_OVERFLOW_P (op1))
    7044              :             return result;
    7045              :         }
    7046            0 :       else if (!CONSTANT_CLASS_P (op0) || !CONSTANT_CLASS_P (op1)
    7047            0 :                || TREE_OVERFLOW_P (op0) || TREE_OVERFLOW_P (op1))
    7048              :         return result;
    7049              : 
    7050     19261971 :       tree result_ovl = fold_build2 (resultcode, build_type, op0, op1);
    7051     19261971 :       if (TREE_OVERFLOW_P (result_ovl))
    7052          190 :         overflow_warning (location, result_ovl);
    7053              :     }
    7054              : 
    7055              :   return result;
    7056              : }
    7057              : 
    7058              : /* Build a VEC_PERM_EXPR.
    7059              :    This is a simple wrapper for c_build_vec_perm_expr.  */
    7060              : tree
    7061        17402 : build_x_vec_perm_expr (location_t loc,
    7062              :                         tree arg0, tree arg1, tree arg2,
    7063              :                         tsubst_flags_t complain)
    7064              : {
    7065        17402 :   tree orig_arg0 = arg0;
    7066        17402 :   tree orig_arg1 = arg1;
    7067        17402 :   tree orig_arg2 = arg2;
    7068        17402 :   if (processing_template_decl)
    7069              :     {
    7070           19 :       if (type_dependent_expression_p (arg0)
    7071           13 :           || type_dependent_expression_p (arg1)
    7072           32 :           || type_dependent_expression_p (arg2))
    7073            6 :         return build_min_nt_loc (loc, VEC_PERM_EXPR, arg0, arg1, arg2);
    7074              :     }
    7075        17396 :   tree exp = c_build_vec_perm_expr (loc, arg0, arg1, arg2, complain & tf_error);
    7076        17396 :   if (processing_template_decl && exp != error_mark_node)
    7077           13 :     return build_min_non_dep (VEC_PERM_EXPR, exp, orig_arg0,
    7078           13 :                               orig_arg1, orig_arg2);
    7079              :   return exp;
    7080              : }
    7081              : 
    7082              : /* Build a VEC_PERM_EXPR.
    7083              :    This is a simple wrapper for c_build_shufflevector.  */
    7084              : tree
    7085        42181 : build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
    7086              :                        tsubst_flags_t complain)
    7087              : {
    7088        42181 :   tree arg0 = (*args)[0];
    7089        42181 :   tree arg1 = (*args)[1];
    7090        42181 :   if (processing_template_decl)
    7091              :     {
    7092          743 :       for (unsigned i = 0; i < args->length (); ++i)
    7093          712 :         if (i <= 1
    7094          712 :             ? type_dependent_expression_p ((*args)[i])
    7095          121 :             : instantiation_dependent_expression_p ((*args)[i]))
    7096              :           {
    7097          526 :             tree exp = build_min_nt_call_vec (NULL, args);
    7098          526 :             CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    7099          526 :             return exp;
    7100              :           }
    7101              :     }
    7102        41655 :   auto_vec<tree, 16> mask;
    7103       561159 :   for (unsigned i = 2; i < args->length (); ++i)
    7104              :     {
    7105       519504 :       tree idx = fold_non_dependent_expr ((*args)[i], complain);
    7106       519504 :       mask.safe_push (idx);
    7107              :     }
    7108        41655 :   tree exp = c_build_shufflevector (loc, arg0, arg1, mask, complain & tf_error);
    7109        41655 :   if (processing_template_decl && exp != error_mark_node)
    7110              :     {
    7111           31 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7112           31 :       CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    7113              :     }
    7114        41655 :   return exp;
    7115        41655 : }
    7116              : 
    7117              : /* Build __builtin_bswapg (ARG) or __builtin_bitreverseg (ARG).  */
    7118              : tree
    7119          162 : build_x_bswapg_bitreverseg (location_t loc, internal_fn ifn,
    7120              :                             vec<tree, va_gc> *args, tsubst_flags_t complain)
    7121              : {
    7122           81 :   const char *name
    7123          162 :     = ifn == IFN_BSWAP ? "__builtin_bswapg" : "__builtin_bitreverseg";
    7124          162 :   if (args->length () != 1)
    7125              :     {
    7126           18 :       if (complain & tf_error)
    7127           18 :         error_at (loc, "wrong number of arguments to %qs", name);
    7128           18 :       return error_mark_node;
    7129              :     }
    7130          144 :   tree arg = (*args)[0];
    7131          144 :   if (error_operand_p (arg))
    7132            6 :     return error_mark_node;
    7133          138 :   if (type_dependent_expression_p (arg))
    7134              :     {
    7135            0 :       tree exp = build_min_nt_call_vec (NULL, args);
    7136            0 :       CALL_EXPR_IFN (exp) = ifn;
    7137            0 :       return exp;
    7138              :     }
    7139          138 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
    7140          138 :   if (!INTEGRAL_TYPE_P (type))
    7141              :     {
    7142           24 :       if (complain & tf_error)
    7143           24 :         error_at (loc, "%qs operand not an integral type", name);
    7144           24 :       return error_mark_node;
    7145              :     }
    7146          114 :   if (TREE_CODE (type) == ENUMERAL_TYPE)
    7147              :     {
    7148           30 :       if (complain & tf_error)
    7149           30 :         error_at (loc, "argument %u in call to function "
    7150              :                        "%qs has enumerated type", 1, name);
    7151           30 :       return error_mark_node;
    7152              :     }
    7153           84 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
    7154              :     {
    7155            6 :       if (complain & tf_error)
    7156            6 :         error_at (loc, "argument %u in call to function "
    7157              :                        "%qs has boolean type", 1, name);
    7158            6 :       return error_mark_node;
    7159              :     }
    7160           78 :   if (!TYPE_UNSIGNED (type))
    7161              :     {
    7162           12 :       if (complain & tf_error)
    7163           12 :         error_at (loc, "argument 1 in call to function "
    7164              :                        "%qs has signed type", name);
    7165           12 :       return error_mark_node;
    7166              :     }
    7167           66 :   if (ifn == IFN_BSWAP && (TYPE_PRECISION (type) % 8) != 0)
    7168              :     {
    7169            0 :       if (complain & tf_error)
    7170            0 :         error_at (loc, "precision %d of argument 1 to function "
    7171              :                        "%qs is not a multiple of 8",
    7172            0 :                   TYPE_PRECISION (type), name);
    7173            0 :       return error_mark_node;
    7174              :     }
    7175           66 :   tree exp = build_call_expr_internal_loc (loc, ifn, type, 1, arg);
    7176           66 :   if (processing_template_decl)
    7177              :     {
    7178            0 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7179            0 :       CALL_EXPR_IFN (exp) = ifn;
    7180              :     }
    7181              :   return exp;
    7182              : }
    7183              : 
    7184              : /* Return a tree for the sum or difference (RESULTCODE says which)
    7185              :    of pointer PTROP and integer INTOP.  */
    7186              : 
    7187              : static tree
    7188      5911057 : cp_pointer_int_sum (location_t loc, enum tree_code resultcode, tree ptrop,
    7189              :                     tree intop, tsubst_flags_t complain)
    7190              : {
    7191      5911057 :   tree res_type = TREE_TYPE (ptrop);
    7192              : 
    7193              :   /* pointer_int_sum() uses size_in_bytes() on the TREE_TYPE(res_type)
    7194              :      in certain circumstance (when it's valid to do so).  So we need
    7195              :      to make sure it's complete.  We don't need to check here, if we
    7196              :      can actually complete it at all, as those checks will be done in
    7197              :      pointer_int_sum() anyway.  */
    7198      5911057 :   complete_type (TREE_TYPE (res_type));
    7199              : 
    7200      5911057 :   return pointer_int_sum (loc, resultcode, ptrop,
    7201      5911057 :                           intop, complain & tf_warning_or_error);
    7202              : }
    7203              : 
    7204              : /* Return a tree for the difference of pointers OP0 and OP1.
    7205              :    The resulting tree has type int.  If POINTER_SUBTRACT sanitization is
    7206              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    7207              : 
    7208              : static tree
    7209      1577256 : pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
    7210              :               tsubst_flags_t complain, tree *instrument_expr)
    7211              : {
    7212      1577256 :   tree result, inttype;
    7213      1577256 :   tree restype = ptrdiff_type_node;
    7214      1577256 :   tree target_type = TREE_TYPE (ptrtype);
    7215              : 
    7216      1577256 :   if (!complete_type_or_maybe_complain (target_type, NULL_TREE, complain))
    7217            9 :     return error_mark_node;
    7218              : 
    7219      1577247 :   if (VOID_TYPE_P (target_type))
    7220              :     {
    7221            0 :       if (complain & tf_error)
    7222            0 :         permerror (loc, "ISO C++ forbids using pointer of "
    7223              :                    "type %<void *%> in subtraction");
    7224              :       else
    7225            0 :         return error_mark_node;
    7226              :     }
    7227      1577247 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    7228              :     {
    7229            9 :       if (complain & tf_error)
    7230            3 :         permerror (loc, "ISO C++ forbids using pointer to "
    7231              :                    "a function in subtraction");
    7232              :       else
    7233            6 :         return error_mark_node;
    7234              :     }
    7235      1577241 :   if (TREE_CODE (target_type) == METHOD_TYPE)
    7236              :     {
    7237            0 :       if (complain & tf_error)
    7238            0 :         permerror (loc, "ISO C++ forbids using pointer to "
    7239              :                    "a method in subtraction");
    7240              :       else
    7241            0 :         return error_mark_node;
    7242              :     }
    7243      3154482 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    7244      1577241 :                                  TREE_TYPE (TREE_TYPE (op0)),
    7245      1577241 :                                  !(complain & tf_error))
    7246      3154482 :            || !verify_type_context (loc, TCTX_POINTER_ARITH,
    7247      1577241 :                                     TREE_TYPE (TREE_TYPE (op1)),
    7248              :                                     !(complain & tf_error)))
    7249            0 :     return error_mark_node;
    7250              : 
    7251              :   /* Determine integer type result of the subtraction.  This will usually
    7252              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    7253              :      type if pointers for the address space are wider than ptrdiff_t.  */
    7254      1577241 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    7255            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    7256              :   else
    7257              :     inttype = restype;
    7258              : 
    7259      1577241 :   if (!processing_template_decl
    7260      1577241 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    7261              :     {
    7262           84 :       op0 = save_expr (op0);
    7263           84 :       op1 = save_expr (op1);
    7264              : 
    7265           84 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    7266           84 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    7267              :     }
    7268              : 
    7269              :   /* First do the subtraction, then build the divide operator
    7270              :      and only convert at the very end.
    7271              :      Do not do default conversions in case restype is a short type.  */
    7272              : 
    7273              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    7274              :      pointers.  If some platform cannot provide that, or has a larger
    7275              :      ptrdiff_type to support differences larger than half the address
    7276              :      space, cast the pointers to some larger integer type and do the
    7277              :      computations in that type.  */
    7278      1577241 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    7279            0 :     op0 = cp_build_binary_op (loc,
    7280              :                               MINUS_EXPR,
    7281              :                               cp_convert (inttype, op0, complain),
    7282              :                               cp_convert (inttype, op1, complain),
    7283              :                               complain);
    7284              :   else
    7285      1577241 :     op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    7286              : 
    7287              :   /* This generates an error if op1 is a pointer to an incomplete type.  */
    7288      1577241 :   if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
    7289              :     {
    7290            0 :       if (complain & tf_error)
    7291            0 :         error_at (loc, "invalid use of a pointer to an incomplete type in "
    7292              :                   "pointer arithmetic");
    7293              :       else
    7294            0 :         return error_mark_node;
    7295              :     }
    7296              : 
    7297      1577241 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (op1)))
    7298              :     {
    7299           15 :       if (complain & tf_error)
    7300           15 :         error_at (loc, "arithmetic on pointer to an empty aggregate");
    7301              :       else
    7302            0 :         return error_mark_node;
    7303              :     }
    7304              : 
    7305      3154479 :   op1 = (TYPE_PTROB_P (ptrtype)
    7306      3154479 :          ? size_in_bytes_loc (loc, target_type)
    7307              :          : integer_one_node);
    7308              : 
    7309              :   /* Do the division.  */
    7310              : 
    7311      1577241 :   result = build2_loc (loc, EXACT_DIV_EXPR, inttype, op0,
    7312              :                        cp_convert (inttype, op1, complain));
    7313      1577241 :   return cp_convert (restype, result, complain);
    7314              : }
    7315              : 
    7316              : /* Construct and perhaps optimize a tree representation
    7317              :    for a unary operation.  CODE, a tree_code, specifies the operation
    7318              :    and XARG is the operand.  */
    7319              : 
    7320              : tree
    7321     66255641 : build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg,
    7322              :                   tree lookups, tsubst_flags_t complain)
    7323              : {
    7324     66255641 :   tree orig_expr = xarg;
    7325     66255641 :   tree exp;
    7326     66255641 :   int ptrmem = 0;
    7327     66255641 :   tree overload = NULL_TREE;
    7328              : 
    7329     66255641 :   if (processing_template_decl)
    7330              :     {
    7331     45132538 :       if (type_dependent_expression_p (xarg))
    7332              :         {
    7333     29500050 :           tree e = build_min_nt_loc (loc, code, xarg.get_value (), NULL_TREE);
    7334     29500050 :           TREE_TYPE (e) = build_dependent_operator_type (lookups, code, false);
    7335     29500050 :           return e;
    7336              :         }
    7337              :     }
    7338              : 
    7339     36755591 :   exp = NULL_TREE;
    7340              : 
    7341              :   /* [expr.unary.op] says:
    7342              : 
    7343              :        The address of an object of incomplete type can be taken.
    7344              : 
    7345              :      (And is just the ordinary address operator, not an overloaded
    7346              :      "operator &".)  However, if the type is a template
    7347              :      specialization, we must complete the type at this point so that
    7348              :      an overloaded "operator &" will be available if required.  */
    7349     36755591 :   if (code == ADDR_EXPR
    7350      4254613 :       && TREE_CODE (xarg) != TEMPLATE_ID_EXPR
    7351     41009788 :       && ((CLASS_TYPE_P (TREE_TYPE (xarg))
    7352      1860895 :            && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (xarg))))
    7353      4244762 :           || (TREE_CODE (xarg) == OFFSET_REF)))
    7354              :     /* Don't look for a function.  */;
    7355              :   else
    7356     36681910 :     exp = build_new_op (loc, code, LOOKUP_NORMAL, xarg, NULL_TREE,
    7357              :                         NULL_TREE, lookups, &overload, complain);
    7358              : 
    7359     36755591 :   if (!exp && code == ADDR_EXPR)
    7360              :     {
    7361      4254200 :       if (is_overloaded_fn (xarg))
    7362              :         {
    7363       393581 :           tree fn = get_first_fn (xarg);
    7364       787162 :           if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
    7365              :             {
    7366           12 :               if (complain & tf_error)
    7367           21 :                 error_at (loc, DECL_CONSTRUCTOR_P (fn)
    7368              :                           ? G_("taking address of constructor %qD")
    7369              :                           : G_("taking address of destructor %qD"),
    7370              :                           fn);
    7371           12 :               return error_mark_node;
    7372              :             }
    7373              :         }
    7374              : 
    7375              :       /* A pointer to member-function can be formed only by saying
    7376              :          &X::mf.  */
    7377      4254182 :       if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
    7378      4314623 :           && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
    7379              :         {
    7380            9 :           if (TREE_CODE (xarg) != OFFSET_REF
    7381            9 :               || !TYPE_P (TREE_OPERAND (xarg, 0)))
    7382              :             {
    7383            9 :               if (complain & tf_error)
    7384              :                 {
    7385            9 :                   auto_diagnostic_group d;
    7386            9 :                   error_at (loc, "invalid use of %qE to form a "
    7387              :                             "pointer-to-member-function", xarg.get_value ());
    7388            9 :                   if (TREE_CODE (xarg) != OFFSET_REF)
    7389            6 :                     inform (loc, "  a qualified-id is required");
    7390            9 :                 }
    7391            9 :               return error_mark_node;
    7392              :             }
    7393              :           else
    7394              :             {
    7395            0 :               if (complain & tf_error)
    7396            0 :                 error_at (loc, "parentheses around %qE cannot be used to "
    7397              :                           "form a pointer-to-member-function",
    7398              :                           xarg.get_value ());
    7399              :               else
    7400            0 :                 return error_mark_node;
    7401            0 :               PTRMEM_OK_P (xarg) = 1;
    7402              :             }
    7403              :         }
    7404              : 
    7405      4254179 :       if (TREE_CODE (xarg) == OFFSET_REF)
    7406              :         {
    7407        64231 :           ptrmem = PTRMEM_OK_P (xarg);
    7408              : 
    7409            0 :           if (!ptrmem && !flag_ms_extensions
    7410        64231 :               && TREE_CODE (TREE_TYPE (TREE_OPERAND (xarg, 1))) == METHOD_TYPE)
    7411              :             {
    7412              :               /* A single non-static member, make sure we don't allow a
    7413              :                  pointer-to-member.  */
    7414            0 :               xarg = build2 (OFFSET_REF, TREE_TYPE (xarg),
    7415            0 :                              TREE_OPERAND (xarg, 0),
    7416            0 :                              ovl_make (TREE_OPERAND (xarg, 1)));
    7417            0 :               PTRMEM_OK_P (xarg) = ptrmem;
    7418              :             }
    7419              :         }
    7420              : 
    7421      8508358 :       exp = cp_build_addr_expr_strict (xarg, complain);
    7422              : 
    7423      4254179 :       if (TREE_CODE (exp) == PTRMEM_CST)
    7424        63098 :         PTRMEM_CST_LOCATION (exp) = loc;
    7425              :       else
    7426      4191081 :         protected_set_expr_location (exp, loc);
    7427              :     }
    7428              : 
    7429     36755570 :   if (processing_template_decl && exp != error_mark_node)
    7430              :     {
    7431     15632327 :       if (overload != NULL_TREE)
    7432       195944 :         return (build_min_non_dep_op_overload
    7433       195944 :                 (code, exp, overload, orig_expr, integer_zero_node));
    7434              : 
    7435     15436383 :       exp = build_min_non_dep (code, exp, orig_expr,
    7436              :                                /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
    7437              :     }
    7438     36559626 :   if (TREE_CODE (exp) == ADDR_EXPR)
    7439      3421662 :     PTRMEM_OK_P (exp) = ptrmem;
    7440              :   return exp;
    7441              : }
    7442              : 
    7443              : /* Construct and perhaps optimize a tree representation
    7444              :    for __builtin_addressof operation.  ARG specifies the operand.  */
    7445              : 
    7446              : tree
    7447       709449 : cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain)
    7448              : {
    7449       709449 :   tree orig_expr = arg;
    7450              : 
    7451       709449 :   if (processing_template_decl)
    7452              :     {
    7453       188263 :       if (type_dependent_expression_p (arg))
    7454       188263 :         return build_min_nt_loc (loc, ADDRESSOF_EXPR, arg, NULL_TREE);
    7455              :     }
    7456              : 
    7457      1042372 :   tree exp = cp_build_addr_expr_strict (arg, complain);
    7458              : 
    7459       521186 :   if (processing_template_decl && exp != error_mark_node)
    7460            0 :     exp = build_min_non_dep (ADDRESSOF_EXPR, exp, orig_expr, NULL_TREE);
    7461              :   return exp;
    7462              : }
    7463              : 
    7464              : /* Like c_common_truthvalue_conversion, but handle pointer-to-member
    7465              :    constants, where a null value is represented by an INTEGER_CST of
    7466              :    -1.  */
    7467              : 
    7468              : tree
    7469      8679316 : cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
    7470              : {
    7471      8679316 :   tree type = TREE_TYPE (expr);
    7472      8679316 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    7473      7365133 :   if (TYPE_PTR_OR_PTRMEM_P (type)
    7474              :       /* Avoid ICE on invalid use of non-static member function.  */
    7475     16044161 :       || TREE_CODE (expr) == FUNCTION_DECL)
    7476      1314471 :     return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain);
    7477              :   else
    7478      7364845 :     return c_common_truthvalue_conversion (loc, expr);
    7479              : }
    7480              : 
    7481              : /* Returns EXPR contextually converted to bool.  */
    7482              : 
    7483              : tree
    7484     80309539 : contextual_conv_bool (tree expr, tsubst_flags_t complain)
    7485              : {
    7486     80309539 :   return perform_implicit_conversion_flags (boolean_type_node, expr,
    7487     80309539 :                                             complain, LOOKUP_NORMAL);
    7488              : }
    7489              : 
    7490              : /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  This
    7491              :    is a low-level function; most callers should use maybe_convert_cond.  */
    7492              : 
    7493              : tree
    7494     54772811 : condition_conversion (tree expr)
    7495              : {
    7496     54772811 :   tree t = contextual_conv_bool (expr, tf_warning_or_error);
    7497     54772811 :   if (!processing_template_decl)
    7498     27327241 :     t = fold_build_cleanup_point_expr (boolean_type_node, t);
    7499     54772811 :   return t;
    7500              : }
    7501              : 
    7502              : /* Returns the address of T.  This function will fold away
    7503              :    ADDR_EXPR of INDIRECT_REF.  This is only for low-level usage;
    7504              :    most places should use cp_build_addr_expr instead.  */
    7505              : 
    7506              : tree
    7507    363757782 : build_address (tree t)
    7508              : {
    7509    363757782 :   if (error_operand_p (t) || !cxx_mark_addressable (t))
    7510           24 :     return error_mark_node;
    7511    363757758 :   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR
    7512              :                        || processing_template_decl);
    7513    363757758 :   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
    7514    363757758 :   if (TREE_CODE (t) != ADDR_EXPR)
    7515     62543777 :     t = rvalue (t);
    7516              :   return t;
    7517              : }
    7518              : 
    7519              : /* Return a NOP_EXPR converting EXPR to TYPE.  */
    7520              : 
    7521              : tree
    7522    596751356 : build_nop (tree type, tree expr MEM_STAT_DECL)
    7523              : {
    7524    596751356 :   if (type == error_mark_node || error_operand_p (expr))
    7525              :     return expr;
    7526    596751282 :   return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr PASS_MEM_STAT);
    7527              : }
    7528              : 
    7529              : /* Take the address of ARG, whatever that means under C++ semantics.
    7530              :    If STRICT_LVALUE is true, require an lvalue; otherwise, allow xvalues
    7531              :    and class rvalues as well.
    7532              : 
    7533              :    Nothing should call this function directly; instead, callers should use
    7534              :    cp_build_addr_expr or cp_build_addr_expr_strict.  */
    7535              : 
    7536              : static tree
    7537    286842430 : cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
    7538              : {
    7539    286842430 :   tree argtype;
    7540    286842430 :   tree val;
    7541              : 
    7542    286842430 :   if (!arg || error_operand_p (arg))
    7543           12 :     return error_mark_node;
    7544              : 
    7545    286842418 :   arg = mark_lvalue_use (arg);
    7546    286842418 :   if (error_operand_p (arg))
    7547            3 :     return error_mark_node;
    7548              : 
    7549    286842415 :   argtype = lvalue_type (arg);
    7550    286842415 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    7551              : 
    7552    286842415 :   gcc_assert (!(identifier_p (arg) && IDENTIFIER_ANY_OP_P (arg)));
    7553              : 
    7554     16313169 :   if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
    7555    286842643 :       && !really_overloaded_fn (arg))
    7556              :     {
    7557              :       /* They're trying to take the address of a unique non-static
    7558              :          member function.  This is ill-formed (except in MS-land),
    7559              :          but let's try to DTRT.
    7560              :          Note: We only handle unique functions here because we don't
    7561              :          want to complain if there's a static overload; non-unique
    7562              :          cases will be handled by instantiate_type.  But we need to
    7563              :          handle this case here to allow casts on the resulting PMF.
    7564              :          We could defer this in non-MS mode, but it's easier to give
    7565              :          a useful error here.  */
    7566              : 
    7567              :       /* Inside constant member functions, the `this' pointer
    7568              :          contains an extra const qualifier.  TYPE_MAIN_VARIANT
    7569              :          is used here to remove this const from the diagnostics
    7570              :          and the created OFFSET_REF.  */
    7571           87 :       tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
    7572           87 :       tree fn = get_first_fn (TREE_OPERAND (arg, 1));
    7573           87 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7574            0 :         return error_mark_node;
    7575              :       /* Until microsoft headers are known to incorrectly take the address of
    7576              :          unqualified xobj member functions we should not support this
    7577              :          extension.
    7578              :          See comment in class.cc:resolve_address_of_overloaded_function for
    7579              :          the extended reasoning.  */
    7580           87 :       if (!flag_ms_extensions || DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7581              :         {
    7582           81 :           auto_diagnostic_group d;
    7583           81 :           tree name = DECL_NAME (fn);
    7584           81 :           if (!(complain & tf_error))
    7585            0 :             return error_mark_node;
    7586           81 :           else if (current_class_type
    7587           81 :                    && TREE_OPERAND (arg, 0) == current_class_ref)
    7588              :             /* An expression like &memfn.  */
    7589           36 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7590           21 :               permerror (loc,
    7591              :                          "ISO C++ forbids taking the address of an unqualified"
    7592              :                          " or parenthesized non-static member function to form"
    7593              :                          " a pointer to member function.  Say %<&%T::%D%>",
    7594              :                          base, name);
    7595              :             else
    7596           15 :               error_at (loc,
    7597              :                         "ISO C++ forbids taking the address of an unqualified"
    7598              :                         " or parenthesized non-static member function to form"
    7599              :                         " a pointer to explicit object member function");
    7600              :           else
    7601           45 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7602            9 :               permerror (loc,
    7603              :                          "ISO C++ forbids taking the address of a bound member"
    7604              :                          " function to form a pointer to member function."
    7605              :                          "  Say %<&%T::%D%>",
    7606              :                          base, name);
    7607              :             else
    7608           36 :               error_at (loc,
    7609              :                         "ISO C++ forbids taking the address of a bound member"
    7610              :                         " function to form a pointer to explicit object member"
    7611              :                         " function");
    7612           81 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7613           51 :             inform (loc,
    7614              :                     "a pointer to explicit object member function can only be "
    7615              :                     "formed with %<&%T::%D%>", base, name);
    7616           81 :         }
    7617           87 :       arg = build_offset_ref (base, fn, /*address_p=*/true, complain);
    7618              :     }
    7619              : 
    7620              :   /* Uninstantiated types are all functions.  Taking the
    7621              :      address of a function is a no-op, so just return the
    7622              :      argument.  */
    7623    286842415 :   if (type_unknown_p (arg))
    7624         3310 :     return build1 (ADDR_EXPR, unknown_type_node, arg);
    7625              : 
    7626    286839105 :   if (TREE_CODE (arg) == OFFSET_REF)
    7627              :     /* We want a pointer to member; bypass all the code for actually taking
    7628              :        the address of something.  */
    7629        63315 :     goto offset_ref;
    7630              : 
    7631              :   /* Anything not already handled and not a true memory reference
    7632              :      is an error.  */
    7633    286775790 :   if (!FUNC_OR_METHOD_TYPE_P (argtype))
    7634              :     {
    7635    151063580 :       cp_lvalue_kind kind = lvalue_kind (arg);
    7636    151063580 :       if (kind == clk_none)
    7637              :         {
    7638           25 :           if (complain & tf_error)
    7639           25 :             lvalue_error (loc, lv_addressof);
    7640           25 :           return error_mark_node;
    7641              :         }
    7642    151063555 :       if (strict_lvalue && (kind & (clk_rvalueref|clk_class)))
    7643              :         {
    7644           39 :           if (!(complain & tf_error))
    7645           12 :             return error_mark_node;
    7646              :           /* Make this a permerror because we used to accept it.  */
    7647           27 :           permerror (loc, "taking address of rvalue");
    7648              :         }
    7649              :     }
    7650              : 
    7651    286775753 :   if (TYPE_REF_P (argtype))
    7652              :     {
    7653          244 :       tree type = build_pointer_type (TREE_TYPE (argtype));
    7654          244 :       arg = build1 (CONVERT_EXPR, type, arg);
    7655          244 :       return arg;
    7656              :     }
    7657    286775509 :   else if (pedantic && DECL_MAIN_P (tree_strip_any_location_wrapper (arg)))
    7658              :     {
    7659              :       /* ARM $3.4 */
    7660              :       /* Apparently a lot of autoconf scripts for C++ packages do this,
    7661              :          so only complain if -Wpedantic.  */
    7662            9 :       if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
    7663            9 :         pedwarn (loc, OPT_Wpedantic,
    7664              :                  "ISO C++ forbids taking address of function %<::main%>");
    7665            0 :       else if (flag_pedantic_errors)
    7666            0 :         return error_mark_node;
    7667              :     }
    7668              : 
    7669              :   /* Let &* cancel out to simplify resulting code.  */
    7670    286775509 :   if (INDIRECT_REF_P (arg))
    7671              :     {
    7672    103156687 :       arg = TREE_OPERAND (arg, 0);
    7673    103156687 :       if (TYPE_REF_P (TREE_TYPE (arg)))
    7674              :         {
    7675     63274417 :           tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
    7676     63274417 :           arg = build1 (CONVERT_EXPR, type, arg);
    7677              :         }
    7678              :       else
    7679              :         /* Don't let this be an lvalue.  */
    7680     39882270 :         arg = rvalue (arg);
    7681              :       return arg;
    7682              :     }
    7683              : 
    7684              :   /* Handle complex lvalues (when permitted)
    7685              :      by reduction to simpler cases.  */
    7686    183618822 :   val = unary_complex_lvalue (ADDR_EXPR, arg);
    7687    183618822 :   if (val != 0)
    7688              :     return val;
    7689              : 
    7690    183115455 :   switch (TREE_CODE (arg))
    7691              :     {
    7692            0 :     CASE_CONVERT:
    7693            0 :     case FLOAT_EXPR:
    7694            0 :     case FIX_TRUNC_EXPR:
    7695              :       /* We should have handled this above in the lvalue_kind check.  */
    7696            0 :       gcc_unreachable ();
    7697        82081 :       break;
    7698              : 
    7699        82081 :     case BASELINK:
    7700        82081 :       arg = BASELINK_FUNCTIONS (arg);
    7701              :       /* Fall through.  */
    7702              : 
    7703        82081 :     case OVERLOAD:
    7704        82081 :       arg = OVL_FIRST (arg);
    7705              :       break;
    7706              : 
    7707        63315 :     case OFFSET_REF:
    7708        63315 :     offset_ref:
    7709              :       /* Turn a reference to a non-static data member into a
    7710              :          pointer-to-member.  */
    7711        63315 :       {
    7712        63315 :         tree type;
    7713        63315 :         tree t;
    7714              : 
    7715        63315 :         gcc_assert (PTRMEM_OK_P (arg));
    7716              : 
    7717        63315 :         t = TREE_OPERAND (arg, 1);
    7718        63315 :         if (TYPE_REF_P (TREE_TYPE (t)))
    7719              :           {
    7720           15 :             if (complain & tf_error)
    7721           15 :               error_at (loc,
    7722              :                         "cannot create pointer to reference member %qD", t);
    7723           15 :             return error_mark_node;
    7724              :           }
    7725              : 
    7726              :         /* Forming a pointer-to-member is a use of non-pure-virtual fns.  */
    7727        63300 :         if (TREE_CODE (t) == FUNCTION_DECL
    7728        60643 :             && !DECL_PURE_VIRTUAL_P (t)
    7729       123920 :             && !mark_used (t, complain) && !(complain & tf_error))
    7730            3 :           return error_mark_node;
    7731              : 
    7732              :         /* Pull out the function_decl for a single xobj member function, and
    7733              :            let the rest of this function handle it.  This is similar to how
    7734              :            static member functions are handled in the BASELINK case above.  */
    7735        63297 :         if (DECL_XOBJ_MEMBER_FUNCTION_P (t))
    7736              :           {
    7737              :             arg = t;
    7738              :             break;
    7739              :           }
    7740              : 
    7741        63201 :         type = build_ptrmem_type (context_for_name_lookup (t),
    7742        63201 :                                   TREE_TYPE (t));
    7743        63201 :         t = make_ptrmem_cst (type, t);
    7744        63201 :         return t;
    7745              :       }
    7746              : 
    7747              :     default:
    7748              :       break;
    7749              :     }
    7750              : 
    7751    183115551 :   if (argtype != error_mark_node)
    7752    183115551 :     argtype = build_pointer_type (argtype);
    7753              : 
    7754    183115551 :   if (bitfield_p (arg))
    7755              :     {
    7756           33 :       if (complain & tf_error)
    7757           33 :         error_at (loc, "attempt to take address of bit-field");
    7758           33 :       return error_mark_node;
    7759              :     }
    7760              : 
    7761              :   /* In a template, we are processing a non-dependent expression
    7762              :      so we can just form an ADDR_EXPR with the correct type.  */
    7763    183115518 :   if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
    7764              :     {
    7765    167289522 :       if (!mark_single_function (arg, complain))
    7766            3 :         return error_mark_node;
    7767    167289519 :       val = build_address (arg);
    7768    167289519 :       if (TREE_CODE (arg) == OFFSET_REF)
    7769            0 :         PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
    7770              :     }
    7771     15825996 :   else if (BASELINK_P (TREE_OPERAND (arg, 1)))
    7772              :     {
    7773           27 :       tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
    7774              : 
    7775           27 :       if (TREE_CODE (fn) == OVERLOAD && OVL_SINGLE_P (fn))
    7776           27 :         fn = OVL_FIRST (fn);
    7777              : 
    7778              :       /* We can only get here with a single static member
    7779              :          function.  */
    7780           27 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    7781              :                   && DECL_STATIC_FUNCTION_P (fn));
    7782           27 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7783            0 :         return error_mark_node;
    7784           27 :       val = build_address (fn);
    7785           27 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
    7786              :         /* Do not lose object's side effects.  */
    7787           12 :         val = build2 (COMPOUND_EXPR, TREE_TYPE (val),
    7788           12 :                       TREE_OPERAND (arg, 0), val);
    7789              :     }
    7790              :   else
    7791              :     {
    7792     15825969 :       tree object = TREE_OPERAND (arg, 0);
    7793     15825969 :       tree field = TREE_OPERAND (arg, 1);
    7794     15825969 :       gcc_assert (same_type_ignoring_top_level_qualifiers_p
    7795              :                   (TREE_TYPE (object), decl_type_context (field)));
    7796     15825969 :       val = build_address (arg);
    7797              :     }
    7798              : 
    7799    183115515 :   if (TYPE_PTR_P (argtype)
    7800    183115515 :       && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
    7801              :     {
    7802         1132 :       build_ptrmemfunc_type (argtype);
    7803         1132 :       val = build_ptrmemfunc (argtype, val, 0,
    7804              :                               /*c_cast_p=*/false,
    7805              :                               complain);
    7806              :     }
    7807              : 
    7808              :   /* Ensure we have EXPR_LOCATION set for possible later diagnostics.  */
    7809    183115515 :   if (TREE_CODE (val) == ADDR_EXPR
    7810    183115515 :       && TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
    7811    130033920 :     SET_EXPR_LOCATION (val, input_location);
    7812              : 
    7813              :   return val;
    7814              : }
    7815              : 
    7816              : /* Take the address of ARG if it has one, even if it's an rvalue.  */
    7817              : 
    7818              : tree
    7819    282067065 : cp_build_addr_expr (tree arg, tsubst_flags_t complain)
    7820              : {
    7821    282067065 :   return cp_build_addr_expr_1 (arg, 0, complain);
    7822              : }
    7823              : 
    7824              : /* Take the address of ARG, but only if it's an lvalue.  */
    7825              : 
    7826              : static tree
    7827      4775365 : cp_build_addr_expr_strict (tree arg, tsubst_flags_t complain)
    7828              : {
    7829      4775365 :   return cp_build_addr_expr_1 (arg, 1, complain);
    7830              : }
    7831              : 
    7832              : /* C++: Must handle pointers to members.
    7833              : 
    7834              :    Perhaps type instantiation should be extended to handle conversion
    7835              :    from aggregates to types we don't yet know we want?  (Or are those
    7836              :    cases typically errors which should be reported?)
    7837              : 
    7838              :    NOCONVERT suppresses the default promotions (such as from short to int).  */
    7839              : 
    7840              : tree
    7841     32172611 : cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
    7842              :                    tsubst_flags_t complain)
    7843              : {
    7844              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    7845     32172611 :   tree arg = xarg;
    7846     32172611 :   location_t location = cp_expr_loc_or_input_loc (arg);
    7847     32172611 :   tree argtype = 0;
    7848     32172611 :   tree eptype = NULL_TREE;
    7849     32172611 :   const char *errstring = NULL;
    7850     32172611 :   tree val;
    7851     32172611 :   const char *invalid_op_diag;
    7852              : 
    7853     32172611 :   if (!arg || error_operand_p (arg))
    7854            0 :     return error_mark_node;
    7855              : 
    7856     32172611 :   arg = resolve_nondeduced_context (arg, complain);
    7857              : 
    7858     64345222 :   if ((invalid_op_diag
    7859     32172611 :        = targetm.invalid_unary_op ((code == UNARY_PLUS_EXPR
    7860              :                                     ? CONVERT_EXPR
    7861              :                                     : code),
    7862     32172611 :                                    TREE_TYPE (arg))))
    7863              :     {
    7864            0 :       if (complain & tf_error)
    7865            0 :         error (invalid_op_diag);
    7866            0 :       return error_mark_node;
    7867              :     }
    7868              : 
    7869     32172611 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    7870              :     {
    7871         9460 :       eptype = TREE_TYPE (arg);
    7872         9460 :       arg = TREE_OPERAND (arg, 0);
    7873              :     }
    7874              : 
    7875     32172611 :   switch (code)
    7876              :     {
    7877      2450181 :     case UNARY_PLUS_EXPR:
    7878      2450181 :     case NEGATE_EXPR:
    7879      2450181 :       {
    7880      2450181 :         int flags = WANT_ARITH | WANT_ENUM;
    7881              :         /* Unary plus (but not unary minus) is allowed on pointers.  */
    7882      2450181 :         if (code == UNARY_PLUS_EXPR)
    7883       164814 :           flags |= WANT_POINTER;
    7884      2450181 :         arg = build_expr_type_conversion (flags, arg, true);
    7885      2450181 :         if (!arg)
    7886           35 :           errstring = (code == NEGATE_EXPR
    7887           27 :                        ? _("wrong type argument to unary minus")
    7888            8 :                        : _("wrong type argument to unary plus"));
    7889              :         else
    7890              :           {
    7891      2450146 :             if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    7892       694945 :               arg = cp_perform_integral_promotions (arg, complain);
    7893              : 
    7894              :             /* Make sure the result is not an lvalue: a unary plus or minus
    7895              :                expression is always a rvalue.  */
    7896      2450146 :             arg = rvalue (arg);
    7897              :           }
    7898              :       }
    7899              :       break;
    7900              : 
    7901       976708 :     case BIT_NOT_EXPR:
    7902       976708 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    7903              :         {
    7904           15 :           code = CONJ_EXPR;
    7905           15 :           if (!noconvert)
    7906              :             {
    7907           15 :               arg = cp_default_conversion (arg, complain);
    7908           15 :               if (arg == error_mark_node)
    7909              :                 return error_mark_node;
    7910              :             }
    7911              :         }
    7912       976693 :       else if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM
    7913              :                                                    | WANT_VECTOR_OR_COMPLEX,
    7914              :                                                    arg, true)))
    7915           20 :         errstring = _("wrong type argument to bit-complement");
    7916       976673 :       else if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    7917              :         {
    7918              :           /* Warn if the expression has boolean value.  */
    7919       976172 :           if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
    7920       976172 :               && (complain & tf_warning))
    7921              :             {
    7922           61 :               auto_diagnostic_group d;
    7923           61 :               if (warning_at (location, OPT_Wbool_operation,
    7924              :                               "%<~%> on an expression of type %<bool%>"))
    7925           42 :                 inform (location, "did you mean to use logical not (%<!%>)?");
    7926           61 :             }
    7927       976172 :           arg = cp_perform_integral_promotions (arg, complain);
    7928              :         }
    7929          501 :       else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
    7930          501 :         arg = mark_rvalue_use (arg);
    7931              :       break;
    7932              : 
    7933            0 :     case ABS_EXPR:
    7934            0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    7935            0 :         errstring = _("wrong type argument to abs");
    7936            0 :       else if (!noconvert)
    7937              :         {
    7938            0 :           arg = cp_default_conversion (arg, complain);
    7939            0 :           if (arg == error_mark_node)
    7940              :             return error_mark_node;
    7941              :         }
    7942              :       break;
    7943              : 
    7944            0 :     case CONJ_EXPR:
    7945              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    7946            0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    7947            0 :         errstring = _("wrong type argument to conjugation");
    7948            0 :       else if (!noconvert)
    7949              :         {
    7950            0 :           arg = cp_default_conversion (arg, complain);
    7951            0 :           if (arg == error_mark_node)
    7952              :             return error_mark_node;
    7953              :         }
    7954              :       break;
    7955              : 
    7956     18843338 :     case TRUTH_NOT_EXPR:
    7957     18843338 :       if (gnu_vector_type_p (TREE_TYPE (arg)))
    7958           60 :         return cp_build_binary_op (input_location, EQ_EXPR, arg,
    7959           60 :                                    build_zero_cst (TREE_TYPE (arg)), complain);
    7960     18843278 :       arg = contextual_conv_bool (arg, complain);
    7961     18843278 :       if (arg != error_mark_node)
    7962              :         {
    7963     18843268 :           if (processing_template_decl)
    7964      8813833 :             return build1_loc (location, TRUTH_NOT_EXPR, boolean_type_node, arg);
    7965     10029435 :           val = invert_truthvalue_loc (location, arg);
    7966     10029435 :           if (obvalue_p (val))
    7967        12345 :             val = non_lvalue_loc (location, val);
    7968              :           return val;
    7969              :         }
    7970           10 :       errstring = _("in argument to unary !");
    7971           10 :       break;
    7972              : 
    7973              :     case NOP_EXPR:
    7974              :       break;
    7975              : 
    7976       456404 :     case REALPART_EXPR:
    7977       456404 :     case IMAGPART_EXPR:
    7978       456404 :       val = build_real_imag_expr (input_location, code, arg);
    7979       456404 :       if (eptype && TREE_CODE (eptype) == COMPLEX_EXPR)
    7980            0 :         val = build1_loc (input_location, EXCESS_PRECISION_EXPR,
    7981            0 :                           TREE_TYPE (eptype), val);
    7982              :       return val;
    7983              : 
    7984      8850662 :     case PREINCREMENT_EXPR:
    7985      8850662 :     case POSTINCREMENT_EXPR:
    7986      8850662 :     case PREDECREMENT_EXPR:
    7987      8850662 :     case POSTDECREMENT_EXPR:
    7988              :       /* Handle complex lvalues (when permitted)
    7989              :          by reduction to simpler cases.  */
    7990              : 
    7991      8850662 :       val = unary_complex_lvalue (code, arg);
    7992      8850662 :       if (val != 0)
    7993           38 :         goto return_build_unary_op;
    7994              : 
    7995      8850624 :       tree stripped_arg;
    7996      8850624 :       stripped_arg = tree_strip_any_location_wrapper (arg);
    7997      2217763 :       if ((VAR_P (stripped_arg) || TREE_CODE (stripped_arg) == PARM_DECL)
    7998      8199992 :           && !DECL_READ_P (stripped_arg)
    7999     10011490 :           && (VAR_P (stripped_arg) ? warn_unused_but_set_variable
    8000              :                                    : warn_unused_but_set_parameter) > 1)
    8001              :         {
    8002         9810 :           arg = mark_lvalue_use (arg);
    8003         9810 :           DECL_READ_P (stripped_arg) = 0;
    8004              :         }
    8005              :       else
    8006      8840814 :         arg = mark_lvalue_use (arg);
    8007              : 
    8008              :       /* Increment or decrement the real part of the value,
    8009              :          and don't change the imaginary part.  */
    8010      8850624 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    8011              :         {
    8012           18 :           tree real, imag;
    8013              : 
    8014           18 :           arg = cp_stabilize_reference (arg);
    8015           18 :           real = cp_build_unary_op (REALPART_EXPR, arg, true, complain);
    8016           18 :           imag = cp_build_unary_op (IMAGPART_EXPR, arg, true, complain);
    8017           18 :           real = cp_build_unary_op (code, real, true, complain);
    8018           18 :           if (real == error_mark_node || imag == error_mark_node)
    8019              :             return error_mark_node;
    8020           15 :           val = build2 (COMPLEX_EXPR, TREE_TYPE (arg), real, imag);
    8021           15 :           goto return_build_unary_op;
    8022              :         }
    8023              : 
    8024              :       /* Report invalid types.  */
    8025              : 
    8026      8850606 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
    8027              :                                               arg, true)))
    8028              :         {
    8029           36 :           if (code == PREINCREMENT_EXPR)
    8030            9 :             errstring = _("no pre-increment operator for type");
    8031           27 :           else if (code == POSTINCREMENT_EXPR)
    8032            9 :             errstring = _("no post-increment operator for type");
    8033           18 :           else if (code == PREDECREMENT_EXPR)
    8034            9 :             errstring = _("no pre-decrement operator for type");
    8035              :           else
    8036            9 :             errstring = _("no post-decrement operator for type");
    8037              :           break;
    8038              :         }
    8039      8850570 :       else if (arg == error_mark_node)
    8040              :         return error_mark_node;
    8041              : 
    8042              :       /* Report something read-only.  */
    8043              : 
    8044      8850567 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg))
    8045      8850567 :           || TREE_READONLY (arg))
    8046              :         {
    8047          164 :           if (complain & tf_error)
    8048          164 :             cxx_readonly_error (location, arg,
    8049          164 :                                 ((code == PREINCREMENT_EXPR
    8050          164 :                                   || code == POSTINCREMENT_EXPR)
    8051              :                                  ? lv_increment : lv_decrement));
    8052              :           else
    8053            0 :             return error_mark_node;
    8054              :         }
    8055              : 
    8056      8850567 :       {
    8057      8850567 :         tree inc;
    8058      8850567 :         tree declared_type = unlowered_expr_type (arg);
    8059              : 
    8060      8850567 :         argtype = TREE_TYPE (arg);
    8061              : 
    8062              :         /* ARM $5.2.5 last annotation says this should be forbidden.  */
    8063      8850567 :         if (TREE_CODE (argtype) == ENUMERAL_TYPE)
    8064              :           {
    8065            0 :             if (complain & tf_error)
    8066            0 :               permerror (location, (code == PREINCREMENT_EXPR
    8067            0 :                                     || code == POSTINCREMENT_EXPR)
    8068              :                          ? G_("ISO C++ forbids incrementing an enum")
    8069              :                          : G_("ISO C++ forbids decrementing an enum"));
    8070              :             else
    8071            0 :               return error_mark_node;
    8072              :           }
    8073              : 
    8074              :         /* Compute the increment.  */
    8075              : 
    8076      8850567 :         if (TYPE_PTR_P (argtype))
    8077              :           {
    8078      2842548 :             tree type = complete_type (TREE_TYPE (argtype));
    8079              : 
    8080      2842548 :             if (!COMPLETE_OR_VOID_TYPE_P (type))
    8081              :               {
    8082           10 :                 if (complain & tf_error)
    8083            9 :                   error_at (location, ((code == PREINCREMENT_EXPR
    8084            9 :                                         || code == POSTINCREMENT_EXPR))
    8085              :                             ? G_("cannot increment a pointer to incomplete "
    8086              :                                  "type %qT")
    8087              :                             : G_("cannot decrement a pointer to incomplete "
    8088              :                                  "type %qT"),
    8089            9 :                             TREE_TYPE (argtype));
    8090              :                 else
    8091            1 :                   return error_mark_node;
    8092              :               }
    8093      2842538 :             else if (!TYPE_PTROB_P (argtype))
    8094              :               {
    8095           69 :                 if (complain & tf_error)
    8096           63 :                   pedwarn (location, OPT_Wpointer_arith,
    8097           63 :                            (code == PREINCREMENT_EXPR
    8098           63 :                               || code == POSTINCREMENT_EXPR)
    8099              :                            ? G_("ISO C++ forbids incrementing a pointer "
    8100              :                                 "of type %qT")
    8101              :                            : G_("ISO C++ forbids decrementing a pointer "
    8102              :                                 "of type %qT"),
    8103              :                            argtype);
    8104              :                 else
    8105            6 :                   return error_mark_node;
    8106              :               }
    8107      2842469 :             else if (!verify_type_context (location, TCTX_POINTER_ARITH,
    8108      2842469 :                                            TREE_TYPE (argtype),
    8109      2842469 :                                            !(complain & tf_error)))
    8110            0 :               return error_mark_node;
    8111              : 
    8112      2842541 :             inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
    8113              :           }
    8114              :         else
    8115      6007876 :           inc = VECTOR_TYPE_P (argtype)
    8116      6008019 :             ? build_one_cst (argtype)
    8117              :             : integer_one_node;
    8118              : 
    8119      8850560 :         inc = cp_convert (argtype, inc, complain);
    8120              : 
    8121              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    8122              :            need to ask Objective-C to build the increment or decrement
    8123              :            expression for it.  */
    8124      8850560 :         if (objc_is_property_ref (arg))
    8125            0 :           return objc_build_incr_expr_for_property_ref (input_location, code,
    8126            0 :                                                         arg, inc);
    8127              : 
    8128              :         /* Complain about anything else that is not a true lvalue.  */
    8129      8850560 :         if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
    8130      8850560 :                                     || code == POSTINCREMENT_EXPR)
    8131              :                                    ? lv_increment : lv_decrement),
    8132              :                              complain))
    8133           38 :           return error_mark_node;
    8134              : 
    8135              :         /* [depr.volatile.type] "Postfix ++ and -- expressions and
    8136              :            prefix ++ and -- expressions of volatile-qualified arithmetic
    8137              :            and pointer types are deprecated."  */
    8138      8850237 :         if ((TREE_THIS_VOLATILE (arg) || CP_TYPE_VOLATILE_P (TREE_TYPE (arg)))
    8139      8850522 :             && (complain & tf_warning))
    8140          398 :           warning_at (location, OPT_Wvolatile,
    8141              :                       "%qs expression of %<volatile%>-qualified type is "
    8142              :                       "deprecated",
    8143              :                       ((code == PREINCREMENT_EXPR
    8144              :                         || code == POSTINCREMENT_EXPR)
    8145              :                        ? "++" : "--"));
    8146              : 
    8147              :         /* Forbid using -- or ++ in C++17 on `bool'.  */
    8148      8850522 :         if (TREE_CODE (declared_type) == BOOLEAN_TYPE)
    8149              :           {
    8150           95 :             if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
    8151              :               {
    8152           33 :                 if (complain & tf_error)
    8153           33 :                   error_at (location,
    8154              :                             "use of an operand of type %qT in %<operator--%> "
    8155              :                             "is forbidden", boolean_type_node);
    8156           33 :                 return error_mark_node;
    8157              :               }
    8158              :             else
    8159              :               {
    8160           62 :                 if (cxx_dialect >= cxx17)
    8161              :                   {
    8162           33 :                     if (complain & tf_error)
    8163           32 :                       error_at (location,
    8164              :                                 "use of an operand of type %qT in "
    8165              :                                 "%<operator++%> is forbidden in C++17",
    8166              :                                 boolean_type_node);
    8167           33 :                     return error_mark_node;
    8168              :                   }
    8169              :                 /* Otherwise, [depr.incr.bool] says this is deprecated.  */
    8170           29 :                 else if (complain & tf_warning)
    8171           25 :                   warning_at (location, OPT_Wdeprecated,
    8172              :                               "use of an operand of type %qT "
    8173              :                               "in %<operator++%> is deprecated",
    8174              :                               boolean_type_node);
    8175              :               }
    8176           29 :             val = boolean_increment (code, arg);
    8177              :           }
    8178      8850427 :         else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    8179              :           /* An rvalue has no cv-qualifiers.  */
    8180      1435406 :           val = build2 (code, cv_unqualified (TREE_TYPE (arg)), arg, inc);
    8181              :         else
    8182      7415021 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    8183              : 
    8184      8850456 :         TREE_SIDE_EFFECTS (val) = 1;
    8185      8850456 :         goto return_build_unary_op;
    8186              :       }
    8187              : 
    8188       595318 :     case ADDR_EXPR:
    8189              :       /* Note that this operation never does default_conversion
    8190              :          regardless of NOCONVERT.  */
    8191       595318 :       return cp_build_addr_expr (arg, complain);
    8192              : 
    8193              :     default:
    8194              :       break;
    8195              :     }
    8196              : 
    8197      3426920 :   if (!errstring)
    8198              :     {
    8199      3426834 :       if (argtype == 0)
    8200      3426834 :         argtype = TREE_TYPE (arg);
    8201      3426834 :       val = build1 (code, argtype, arg);
    8202     12277343 :     return_build_unary_op:
    8203     12277343 :       if (eptype)
    8204         9451 :         val = build1 (EXCESS_PRECISION_EXPR, eptype, val);
    8205              :       return val;
    8206              :     }
    8207              : 
    8208          101 :   if (complain & tf_error)
    8209           54 :     error_at (location, "%s", errstring);
    8210          101 :   return error_mark_node;
    8211              : }
    8212              : 
    8213              : /* Hook for the c-common bits that build a unary op.  */
    8214              : tree
    8215         4139 : build_unary_op (location_t /*location*/,
    8216              :                 enum tree_code code, tree xarg, bool noconvert)
    8217              : {
    8218         4139 :   return cp_build_unary_op (code, xarg, noconvert, tf_warning_or_error);
    8219              : }
    8220              : 
    8221              : /* Adjust LVALUE, an MODIFY_EXPR, PREINCREMENT_EXPR or PREDECREMENT_EXPR,
    8222              :    so that it is a valid lvalue even for GENERIC by replacing
    8223              :    (lhs = rhs) with ((lhs = rhs), lhs)
    8224              :    (--lhs) with ((--lhs), lhs)
    8225              :    (++lhs) with ((++lhs), lhs)
    8226              :    and if lhs has side-effects, calling cp_stabilize_reference on it, so
    8227              :    that it can be evaluated multiple times.  */
    8228              : 
    8229              : tree
    8230       413859 : genericize_compound_lvalue (tree lvalue)
    8231              : {
    8232       413859 :   if (TREE_SIDE_EFFECTS (TREE_OPERAND (lvalue, 0)))
    8233          199 :     lvalue = build2 (TREE_CODE (lvalue), TREE_TYPE (lvalue),
    8234          199 :                      cp_stabilize_reference (TREE_OPERAND (lvalue, 0)),
    8235          199 :                      TREE_OPERAND (lvalue, 1));
    8236       413859 :   return build2 (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (lvalue, 0)),
    8237       413859 :                  lvalue, TREE_OPERAND (lvalue, 0));
    8238              : }
    8239              : 
    8240              : /* Apply unary lvalue-demanding operator CODE to the expression ARG
    8241              :    for certain kinds of expressions which are not really lvalues
    8242              :    but which we can accept as lvalues.
    8243              : 
    8244              :    If ARG is not a kind of expression we can handle, return
    8245              :    NULL_TREE.  */
    8246              : 
    8247              : tree
    8248    326503579 : unary_complex_lvalue (enum tree_code code, tree arg)
    8249              : {
    8250              :   /* Inside a template, making these kinds of adjustments is
    8251              :      pointless; we are only concerned with the type of the
    8252              :      expression.  */
    8253    326917208 :   if (processing_template_decl)
    8254              :     return NULL_TREE;
    8255              : 
    8256              :   /* Handle (a, b) used as an "lvalue".  */
    8257    235555739 :   if (TREE_CODE (arg) == COMPOUND_EXPR)
    8258              :     {
    8259       415306 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 1), false,
    8260              :                                             tf_warning_or_error);
    8261       415306 :       return build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    8262       830612 :                      TREE_OPERAND (arg, 0), real_result);
    8263              :     }
    8264              : 
    8265              :   /* Handle (a ? b : c) used as an "lvalue".  */
    8266    235140433 :   if (TREE_CODE (arg) == COND_EXPR
    8267    235052316 :       || TREE_CODE (arg) == MIN_EXPR || TREE_CODE (arg) == MAX_EXPR)
    8268        88117 :     return rationalize_conditional_expr (code, arg, tf_warning_or_error);
    8269              : 
    8270              :   /* Handle (a = b), (++a), and (--a) used as an "lvalue".  */
    8271    235052316 :   if (TREE_CODE (arg) == MODIFY_EXPR
    8272    234638813 :       || TREE_CODE (arg) == PREINCREMENT_EXPR
    8273    234638750 :       || TREE_CODE (arg) == PREDECREMENT_EXPR)
    8274       413629 :     return unary_complex_lvalue (code, genericize_compound_lvalue (arg));
    8275              : 
    8276    234638687 :   if (code != ADDR_EXPR)
    8277              :     return NULL_TREE;
    8278              : 
    8279              :   /* Handle (a = b) used as an "lvalue" for `&'.  */
    8280    230616588 :   if (TREE_CODE (arg) == MODIFY_EXPR
    8281    230616588 :       || TREE_CODE (arg) == INIT_EXPR)
    8282              :     {
    8283            0 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 0), false,
    8284              :                                             tf_warning_or_error);
    8285            0 :       arg = build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    8286              :                     arg, real_result);
    8287            0 :       suppress_warning (arg /* What warning? */);
    8288            0 :       return arg;
    8289              :     }
    8290              : 
    8291    353588361 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (arg))
    8292    353587250 :       || TREE_CODE (arg) == OFFSET_REF)
    8293              :     return NULL_TREE;
    8294              : 
    8295              :   /* We permit compiler to make function calls returning
    8296              :      objects of aggregate type look like lvalues.  */
    8297    122970662 :   {
    8298    122970662 :     tree targ = arg;
    8299              : 
    8300    122970662 :     if (TREE_CODE (targ) == SAVE_EXPR)
    8301            0 :       targ = TREE_OPERAND (targ, 0);
    8302              : 
    8303    122970662 :     if (TREE_CODE (targ) == CALL_EXPR && MAYBE_CLASS_TYPE_P (TREE_TYPE (targ)))
    8304              :       {
    8305           26 :         if (TREE_CODE (arg) == SAVE_EXPR)
    8306              :           targ = arg;
    8307              :         else
    8308           26 :           targ = build_cplus_new (TREE_TYPE (arg), arg, tf_warning_or_error);
    8309           26 :         return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
    8310              :       }
    8311              : 
    8312    122970636 :     if (TREE_CODE (arg) == SAVE_EXPR && INDIRECT_REF_P (targ))
    8313            0 :       return build3 (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
    8314            0 :                      TREE_OPERAND (targ, 0), current_function_decl, NULL);
    8315              :   }
    8316              : 
    8317              :   /* Don't let anything else be handled specially.  */
    8318              :   return NULL_TREE;
    8319              : }
    8320              : 
    8321              : /* Mark EXP saying that we need to be able to take the
    8322              :    address of it; it should not be allocated in a register.
    8323              :    Value is true if successful.  ARRAY_REF_P is true if this
    8324              :    is for ARRAY_REF construction - in that case we don't want
    8325              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    8326              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    8327              :    register variables.
    8328              : 
    8329              :    C++: we do not allow `current_class_ptr' to be addressable.  */
    8330              : 
    8331              : bool
    8332    384178802 : cxx_mark_addressable (tree exp, bool array_ref_p)
    8333              : {
    8334    384178802 :   tree x = exp;
    8335              : 
    8336    448972657 :   while (1)
    8337    448972657 :     switch (TREE_CODE (x))
    8338              :       {
    8339     32729666 :       case VIEW_CONVERT_EXPR:
    8340     32729666 :         if (array_ref_p
    8341       815217 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    8342     33348694 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    8343              :           return true;
    8344     32726399 :         x = TREE_OPERAND (x, 0);
    8345     32726399 :         break;
    8346              : 
    8347     31596260 :       case COMPONENT_REF:
    8348     31596260 :         if (bitfield_p (x))
    8349            9 :           error ("attempt to take address of bit-field");
    8350              :         /* FALLTHRU */
    8351     32067456 :       case ADDR_EXPR:
    8352     32067456 :       case ARRAY_REF:
    8353     32067456 :       case REALPART_EXPR:
    8354     32067456 :       case IMAGPART_EXPR:
    8355     32067456 :         x = TREE_OPERAND (x, 0);
    8356     32067456 :         break;
    8357              : 
    8358      8467646 :       case PARM_DECL:
    8359      8467646 :         if (x == current_class_ptr)
    8360              :           {
    8361           18 :             error ("cannot take the address of %<this%>, which is an rvalue expression");
    8362           18 :             TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later.  */
    8363           18 :             return true;
    8364              :           }
    8365              :         /* Fall through.  */
    8366              : 
    8367     78554500 :       case VAR_DECL:
    8368              :         /* Caller should not be trying to mark initialized
    8369              :            constant fields addressable.  */
    8370     78554500 :         gcc_assert (DECL_LANG_SPECIFIC (x) == 0
    8371              :                     || DECL_IN_AGGR_P (x) == 0
    8372              :                     || TREE_STATIC (x)
    8373              :                     || DECL_EXTERNAL (x));
    8374     78554500 :         if (VAR_P (x)
    8375     70086872 :             && DECL_ANON_UNION_VAR_P (x)
    8376     78554583 :             && !TREE_ADDRESSABLE (x))
    8377           39 :           cxx_mark_addressable (DECL_VALUE_EXPR (x));
    8378              :         /* Fall through.  */
    8379              : 
    8380     79440841 :       case RESULT_DECL:
    8381     79440971 :         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
    8382     79440962 :             && !DECL_ARTIFICIAL (x))
    8383              :           {
    8384           31 :             if (VAR_P (x) && DECL_HARD_REGISTER (x))
    8385              :               {
    8386           15 :                 error
    8387           15 :                   ("address of explicit register variable %qD requested", x);
    8388           15 :                 return false;
    8389              :               }
    8390           16 :             else if (extra_warnings)
    8391            3 :               warning
    8392            3 :                 (OPT_Wextra, "address requested for %qD, which is declared %<register%>", x);
    8393              :           }
    8394     79440826 :         TREE_ADDRESSABLE (x) = 1;
    8395     79440826 :         return true;
    8396              : 
    8397    188180314 :       case CONST_DECL:
    8398    188180314 :       case FUNCTION_DECL:
    8399    188180314 :         TREE_ADDRESSABLE (x) = 1;
    8400    188180314 :         return true;
    8401              : 
    8402        57142 :       case CONSTRUCTOR:
    8403        57142 :         TREE_ADDRESSABLE (x) = 1;
    8404        57142 :         return true;
    8405              : 
    8406     17634195 :       case TARGET_EXPR:
    8407     17634195 :         TREE_ADDRESSABLE (x) = 1;
    8408     17634195 :         cxx_mark_addressable (TARGET_EXPR_SLOT (x));
    8409     17634195 :         return true;
    8410              : 
    8411              :       default:
    8412              :         return true;
    8413              :     }
    8414              : }
    8415              : 
    8416              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
    8417              : 
    8418              : tree
    8419      9910932 : build_x_conditional_expr (location_t loc, tree ifexp, tree op1, tree op2,
    8420              :                           tsubst_flags_t complain)
    8421              : {
    8422      9910932 :   tree orig_ifexp = ifexp;
    8423      9910932 :   tree orig_op1 = op1;
    8424      9910932 :   tree orig_op2 = op2;
    8425      9910932 :   tree expr;
    8426              : 
    8427      9910932 :   if (processing_template_decl)
    8428              :     {
    8429              :       /* The standard says that the expression is type-dependent if
    8430              :          IFEXP is type-dependent, even though the eventual type of the
    8431              :          expression doesn't dependent on IFEXP.  */
    8432      3507339 :       if (type_dependent_expression_p (ifexp)
    8433              :           /* As a GNU extension, the middle operand may be omitted.  */
    8434      1918349 :           || (op1 && type_dependent_expression_p (op1))
    8435      4918854 :           || type_dependent_expression_p (op2))
    8436      2125658 :         return build_min_nt_loc (loc, COND_EXPR, ifexp, op1, op2);
    8437              :     }
    8438              : 
    8439      7785274 :   expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
    8440      7785274 :   if (processing_template_decl && expr != error_mark_node)
    8441              :     {
    8442      1381675 :       tree min = build_min_non_dep (COND_EXPR, expr,
    8443              :                                     orig_ifexp, orig_op1, orig_op2);
    8444      1381675 :       expr = convert_from_reference (min);
    8445              :     }
    8446              :   return expr;
    8447              : }
    8448              : 
    8449              : /* Given a list of expressions, return a compound expression
    8450              :    that performs them all and returns the value of the last of them.  */
    8451              : 
    8452              : tree
    8453     32870224 : build_x_compound_expr_from_list (tree list, expr_list_kind exp,
    8454              :                                  tsubst_flags_t complain)
    8455              : {
    8456     32870224 :   tree expr = TREE_VALUE (list);
    8457              : 
    8458       493348 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8459     33363560 :       && !CONSTRUCTOR_IS_DIRECT_INIT (expr))
    8460              :     {
    8461           14 :       if (complain & tf_error)
    8462           28 :         pedwarn (cp_expr_loc_or_input_loc (expr), 0,
    8463              :                  "list-initializer for non-class type must not "
    8464              :                  "be parenthesized");
    8465              :       else
    8466            0 :         return error_mark_node;
    8467              :     }
    8468              : 
    8469     32870224 :   if (TREE_CHAIN (list))
    8470              :     {
    8471           23 :       if (complain & tf_error)
    8472           14 :         switch (exp)
    8473              :           {
    8474           12 :           case ELK_INIT:
    8475           12 :             permerror (input_location, "expression list treated as compound "
    8476              :                                        "expression in initializer");
    8477           12 :             break;
    8478            1 :           case ELK_MEM_INIT:
    8479            1 :             permerror (input_location, "expression list treated as compound "
    8480              :                                        "expression in mem-initializer");
    8481            1 :             break;
    8482            1 :           case ELK_FUNC_CAST:
    8483            1 :             permerror (input_location, "expression list treated as compound "
    8484              :                                        "expression in functional cast");
    8485            1 :             break;
    8486            0 :           default:
    8487            0 :             gcc_unreachable ();
    8488              :           }
    8489              :       else
    8490            9 :         return error_mark_node;
    8491              : 
    8492           28 :       for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
    8493           28 :         expr = build_x_compound_expr (EXPR_LOCATION (TREE_VALUE (list)),
    8494           14 :                                       expr, TREE_VALUE (list), NULL_TREE,
    8495              :                                       complain);
    8496              :     }
    8497              : 
    8498              :   return expr;
    8499              : }
    8500              : 
    8501              : /* Like build_x_compound_expr_from_list, but using a VEC.  */
    8502              : 
    8503              : tree
    8504       422523 : build_x_compound_expr_from_vec (vec<tree, va_gc> *vec, const char *msg,
    8505              :                                 tsubst_flags_t complain)
    8506              : {
    8507       422523 :   if (vec_safe_is_empty (vec))
    8508              :     return NULL_TREE;
    8509       422523 :   else if (vec->length () == 1)
    8510       422459 :     return (*vec)[0];
    8511              :   else
    8512              :     {
    8513           64 :       tree expr;
    8514           64 :       unsigned int ix;
    8515           64 :       tree t;
    8516              : 
    8517           64 :       if (msg != NULL)
    8518              :         {
    8519            4 :           if (complain & tf_error)
    8520            0 :             permerror (input_location,
    8521              :                        "%s expression list treated as compound expression",
    8522              :                        msg);
    8523              :           else
    8524            4 :             return error_mark_node;
    8525              :         }
    8526              : 
    8527           60 :       expr = (*vec)[0];
    8528          134 :       for (ix = 1; vec->iterate (ix, &t); ++ix)
    8529           74 :         expr = build_x_compound_expr (EXPR_LOCATION (t), expr,
    8530              :                                       t, NULL_TREE, complain);
    8531              : 
    8532              :       return expr;
    8533              :     }
    8534              : }
    8535              : 
    8536              : /* Handle overloading of the ',' operator when needed.  */
    8537              : 
    8538              : tree
    8539      3213623 : build_x_compound_expr (location_t loc, tree op1, tree op2,
    8540              :                        tree lookups, tsubst_flags_t complain)
    8541              : {
    8542      3213623 :   tree result;
    8543      3213623 :   tree orig_op1 = op1;
    8544      3213623 :   tree orig_op2 = op2;
    8545      3213623 :   tree overload = NULL_TREE;
    8546              : 
    8547      3213623 :   if (processing_template_decl)
    8548              :     {
    8549      2951038 :       if (type_dependent_expression_p (op1)
    8550      2951038 :           || type_dependent_expression_p (op2))
    8551              :         {
    8552      2676831 :           result = build_min_nt_loc (loc, COMPOUND_EXPR, op1, op2);
    8553      2676831 :           TREE_TYPE (result)
    8554      2676831 :             = build_dependent_operator_type (lookups, COMPOUND_EXPR, false);
    8555      2676831 :           return result;
    8556              :         }
    8557              :     }
    8558              : 
    8559       536792 :   result = build_new_op (loc, COMPOUND_EXPR, LOOKUP_NORMAL, op1, op2,
    8560              :                          NULL_TREE, lookups, &overload, complain);
    8561       536792 :   if (!result)
    8562       528171 :     result = cp_build_compound_expr (op1, op2, complain);
    8563              : 
    8564       536792 :   if (processing_template_decl && result != error_mark_node)
    8565              :     {
    8566       272386 :       if (overload != NULL_TREE)
    8567           72 :         return (build_min_non_dep_op_overload
    8568           72 :                 (COMPOUND_EXPR, result, overload, orig_op1, orig_op2));
    8569              : 
    8570       272314 :       return build_min_non_dep (COMPOUND_EXPR, result, orig_op1, orig_op2);
    8571              :     }
    8572              : 
    8573              :   return result;
    8574              : }
    8575              : 
    8576              : /* Like cp_build_compound_expr, but for the c-common bits.  */
    8577              : 
    8578              : tree
    8579        21474 : build_compound_expr (location_t /*loc*/, tree lhs, tree rhs)
    8580              : {
    8581        21474 :   return cp_build_compound_expr (lhs, rhs, tf_warning_or_error);
    8582              : }
    8583              : 
    8584              : /* Build a compound expression.  */
    8585              : 
    8586              : tree
    8587       693395 : cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
    8588              : {
    8589       693395 :   lhs = convert_to_void (lhs, ICV_LEFT_OF_COMMA, complain);
    8590              : 
    8591       693395 :   if (lhs == error_mark_node || rhs == error_mark_node)
    8592              :     return error_mark_node;
    8593              : 
    8594       693392 :   if (TREE_CODE (lhs) == EXCESS_PRECISION_EXPR)
    8595            0 :     lhs = TREE_OPERAND (lhs, 0);
    8596       693392 :   tree eptype = NULL_TREE;
    8597       693392 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8598              :     {
    8599            3 :       eptype = TREE_TYPE (rhs);
    8600            3 :       rhs = TREE_OPERAND (rhs, 0);
    8601              :     }
    8602              : 
    8603       693392 :   if (TREE_CODE (rhs) == TARGET_EXPR)
    8604              :     {
    8605              :       /* If the rhs is a TARGET_EXPR, then build the compound
    8606              :          expression inside the target_expr's initializer. This
    8607              :          helps the compiler to eliminate unnecessary temporaries.  */
    8608        31923 :       tree init = TARGET_EXPR_INITIAL (rhs);
    8609              : 
    8610        31923 :       init = build2 (COMPOUND_EXPR, TREE_TYPE (init), lhs, init);
    8611        31923 :       TARGET_EXPR_INITIAL (rhs) = init;
    8612              : 
    8613        31923 :       if (eptype)
    8614            0 :         rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    8615              :       return rhs;
    8616              :     }
    8617              : 
    8618       661469 :   rhs = resolve_nondeduced_context (rhs, complain);
    8619              : 
    8620       661469 :   if (type_unknown_p (rhs))
    8621              :     {
    8622           33 :       if (complain & tf_error)
    8623           51 :         error_at (cp_expr_loc_or_input_loc (rhs),
    8624              :                   "no context to resolve type of %qE", rhs);
    8625           33 :       return error_mark_node;
    8626              :     }
    8627              : 
    8628       661436 :   tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
    8629       661436 :   if (eptype)
    8630            3 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    8631              :   return ret;
    8632              : }
    8633              : 
    8634              : /* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
    8635              :    casts away constness.  CAST gives the type of cast.  Returns true
    8636              :    if the cast is ill-formed, false if it is well-formed.
    8637              : 
    8638              :    ??? This function warns for casting away any qualifier not just
    8639              :    const.  We would like to specify exactly what qualifiers are casted
    8640              :    away.
    8641              : */
    8642              : 
    8643              : static bool
    8644       883311 : check_for_casting_away_constness (location_t loc, tree src_type,
    8645              :                                   tree dest_type, enum tree_code cast,
    8646              :                                   tsubst_flags_t complain)
    8647              : {
    8648              :   /* C-style casts are allowed to cast away constness.  With
    8649              :      WARN_CAST_QUAL, we still want to issue a warning.  */
    8650       883311 :   if (cast == CAST_EXPR && !warn_cast_qual)
    8651              :     return false;
    8652              : 
    8653       667822 :   if (!casts_away_constness (src_type, dest_type, complain))
    8654              :     return false;
    8655              : 
    8656          400 :   switch (cast)
    8657              :     {
    8658          343 :     case CAST_EXPR:
    8659          343 :       if (complain & tf_warning)
    8660          343 :         warning_at (loc, OPT_Wcast_qual,
    8661              :                     "cast from type %qT to type %qT casts away qualifiers",
    8662              :                     src_type, dest_type);
    8663              :       return false;
    8664              : 
    8665           36 :     case STATIC_CAST_EXPR:
    8666           36 :       if (complain & tf_error)
    8667           24 :         error_at (loc, "%<static_cast%> from type %qT to type %qT casts "
    8668              :                   "away qualifiers",
    8669              :                   src_type, dest_type);
    8670              :       return true;
    8671              : 
    8672           21 :     case REINTERPRET_CAST_EXPR:
    8673           21 :       if (complain & tf_error)
    8674           15 :         error_at (loc, "%<reinterpret_cast%> from type %qT to type %qT "
    8675              :                   "casts away qualifiers",
    8676              :                   src_type, dest_type);
    8677              :       return true;
    8678              : 
    8679            0 :     default:
    8680            0 :       gcc_unreachable();
    8681              :     }
    8682              : }
    8683              : 
    8684              : /* Warns if the cast from expression EXPR to type TYPE is useless.  */
    8685              : void
    8686     52461422 : maybe_warn_about_useless_cast (location_t loc, tree type, tree expr,
    8687              :                                tsubst_flags_t complain)
    8688              : {
    8689     52461422 :   if (warn_useless_cast
    8690          152 :       && complain & tf_warning)
    8691              :     {
    8692          152 :       if (TYPE_REF_P (type)
    8693          152 :           ? ((TYPE_REF_IS_RVALUE (type)
    8694           86 :               ? xvalue_p (expr) : lvalue_p (expr))
    8695          172 :              && same_type_p (TREE_TYPE (expr), TREE_TYPE (type)))
    8696              :           /* Don't warn when converting a class object to a non-reference type,
    8697              :              because that's a common way to create a temporary.  */
    8698           66 :           : (!glvalue_p (expr) && same_type_p (TREE_TYPE (expr), type)))
    8699           96 :         warning_at (loc, OPT_Wuseless_cast,
    8700              :                     "useless cast to type %q#T", type);
    8701              :     }
    8702     52461422 : }
    8703              : 
    8704              : /* Warns if the cast ignores cv-qualifiers on TYPE.  */
    8705              : static void
    8706     52454315 : maybe_warn_about_cast_ignoring_quals (location_t loc, tree type,
    8707              :                                       tsubst_flags_t complain)
    8708              : {
    8709     52454315 :   if (warn_ignored_qualifiers
    8710       276338 :       && complain & tf_warning
    8711       275838 :       && !CLASS_TYPE_P (type)
    8712     52724816 :       && (cp_type_quals (type) & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)))
    8713           63 :     warning_at (loc, OPT_Wignored_qualifiers,
    8714              :                 "type qualifiers ignored on cast result type");
    8715     52454315 : }
    8716              : 
    8717              : /* Convert EXPR (an expression with pointer-to-member type) to TYPE
    8718              :    (another pointer-to-member type in the same hierarchy) and return
    8719              :    the converted expression.  If ALLOW_INVERSE_P is permitted, a
    8720              :    pointer-to-derived may be converted to pointer-to-base; otherwise,
    8721              :    only the other direction is permitted.  If C_CAST_P is true, this
    8722              :    conversion is taking place as part of a C-style cast.  */
    8723              : 
    8724              : tree
    8725        29151 : convert_ptrmem (tree type, tree expr, bool allow_inverse_p,
    8726              :                 bool c_cast_p, tsubst_flags_t complain)
    8727              : {
    8728        29151 :   if (same_type_p (type, TREE_TYPE (expr)))
    8729              :     return expr;
    8730              : 
    8731        29151 :   if (TYPE_PTRDATAMEM_P (type))
    8732              :     {
    8733          418 :       tree obase = TYPE_PTRMEM_CLASS_TYPE (TREE_TYPE (expr));
    8734          418 :       tree nbase = TYPE_PTRMEM_CLASS_TYPE (type);
    8735          418 :       tree delta = (get_delta_difference
    8736          418 :                     (obase, nbase,
    8737              :                      allow_inverse_p, c_cast_p, complain));
    8738              : 
    8739          418 :       if (delta == error_mark_node)
    8740              :         return error_mark_node;
    8741              : 
    8742          412 :       if (!same_type_p (obase, nbase))
    8743              :         {
    8744          299 :           if (TREE_CODE (expr) == PTRMEM_CST)
    8745          157 :             expr = cplus_expand_constant (expr);
    8746              : 
    8747          299 :           tree cond = cp_build_binary_op (input_location, EQ_EXPR, expr,
    8748          299 :                                           build_int_cst (TREE_TYPE (expr), -1),
    8749              :                                           complain);
    8750          299 :           tree op1 = build_nop (ptrdiff_type_node, expr);
    8751          299 :           tree op2 = cp_build_binary_op (input_location, PLUS_EXPR, op1, delta,
    8752              :                                          complain);
    8753              : 
    8754          299 :           expr = fold_build3_loc (input_location,
    8755              :                                   COND_EXPR, ptrdiff_type_node, cond, op1, op2);
    8756              :         }
    8757              : 
    8758          412 :       return build_nop (type, expr);
    8759              :     }
    8760              :   else
    8761        28733 :     return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr,
    8762        28733 :                              allow_inverse_p, c_cast_p, complain);
    8763              : }
    8764              : 
    8765              : /* Perform a static_cast from EXPR to TYPE.  When C_CAST_P is true,
    8766              :    this static_cast is being attempted as one of the possible casts
    8767              :    allowed by a C-style cast.  (In that case, accessibility of base
    8768              :    classes is not considered, and it is OK to cast away
    8769              :    constness.)  Return the result of the cast.  *VALID_P is set to
    8770              :    indicate whether or not the cast was valid.  */
    8771              : 
    8772              : static tree
    8773     51908824 : build_static_cast_1 (location_t loc, tree type, tree expr, bool c_cast_p,
    8774              :                      bool *valid_p, tsubst_flags_t complain)
    8775              : {
    8776     51908824 :   tree intype;
    8777     51908824 :   tree result;
    8778     51908824 :   cp_lvalue_kind clk;
    8779              : 
    8780              :   /* Assume the cast is valid.  */
    8781     51908824 :   *valid_p = true;
    8782              : 
    8783     51908824 :   intype = unlowered_expr_type (expr);
    8784              : 
    8785              :   /* Save casted types in the function's used types hash table.  */
    8786     51908824 :   used_types_insert (type);
    8787              : 
    8788              :   /* A prvalue of non-class type is cv-unqualified.  */
    8789     51908824 :   if (!CLASS_TYPE_P (type))
    8790     48673163 :     type = cv_unqualified (type);
    8791              : 
    8792              :   /* [expr.static.cast]
    8793              : 
    8794              :      An lvalue of type "cv1 B", where B is a class type, can be cast
    8795              :      to type "reference to cv2 D", where D is a class derived (clause
    8796              :      _class.derived_) from B, if a valid standard conversion from
    8797              :      "pointer to D" to "pointer to B" exists (_conv.ptr_), cv2 is the
    8798              :      same cv-qualification as, or greater cv-qualification than, cv1,
    8799              :      and B is not a virtual base class of D.  */
    8800              :   /* We check this case before checking the validity of "TYPE t =
    8801              :      EXPR;" below because for this case:
    8802              : 
    8803              :        struct B {};
    8804              :        struct D : public B { D(const B&); };
    8805              :        extern B& b;
    8806              :        void f() { static_cast<const D&>(b); }
    8807              : 
    8808              :      we want to avoid constructing a new D.  The standard is not
    8809              :      completely clear about this issue, but our interpretation is
    8810              :      consistent with other compilers.  */
    8811     51908824 :   if (TYPE_REF_P (type)
    8812      5844976 :       && CLASS_TYPE_P (TREE_TYPE (type))
    8813      3824613 :       && CLASS_TYPE_P (intype)
    8814      3824596 :       && (TYPE_REF_IS_RVALUE (type) || lvalue_p (expr))
    8815      3811398 :       && DERIVED_FROM_P (intype, TREE_TYPE (type))
    8816      3788999 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT (intype)),
    8817      3788999 :                       build_pointer_type (TYPE_MAIN_VARIANT
    8818              :                                           (TREE_TYPE (type))),
    8819              :                       complain)
    8820     55697823 :       && (c_cast_p
    8821      3788975 :           || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    8822              :     {
    8823      3788999 :       tree base;
    8824              : 
    8825      3788999 :       if (processing_template_decl)
    8826              :         return expr;
    8827              : 
    8828              :       /* There is a standard conversion from "D*" to "B*" even if "B"
    8829              :          is ambiguous or inaccessible.  If this is really a
    8830              :          static_cast, then we check both for inaccessibility and
    8831              :          ambiguity.  However, if this is a static_cast being performed
    8832              :          because the user wrote a C-style cast, then accessibility is
    8833              :          not considered.  */
    8834      7096094 :       base = lookup_base (TREE_TYPE (type), intype,
    8835              :                           c_cast_p ? ba_unique : ba_check,
    8836              :                           NULL, complain);
    8837      3548059 :       expr = cp_build_addr_expr (expr, complain);
    8838              : 
    8839      3548059 :       if (sanitize_flags_p (SANITIZE_VPTR))
    8840              :         {
    8841          496 :           tree ubsan_check
    8842          496 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    8843              :                                                   intype, expr);
    8844          496 :           if (ubsan_check)
    8845      3548059 :             expr = ubsan_check;
    8846              :         }
    8847              : 
    8848              :       /* Convert from "B*" to "D*".  This function will check that "B"
    8849              :          is not a virtual base of "D".  Even if we don't have a guarantee
    8850              :          that expr is NULL, if the static_cast is to a reference type,
    8851              :          it is UB if it would be NULL, so omit the non-NULL check.  */
    8852      3548059 :       expr = build_base_path (MINUS_EXPR, expr, base,
    8853              :                               /*nonnull=*/flag_delete_null_pointer_checks,
    8854              :                               complain);
    8855              : 
    8856              :       /* Convert the pointer to a reference -- but then remember that
    8857              :          there are no expressions with reference type in C++.
    8858              : 
    8859              :          We call rvalue so that there's an actual tree code
    8860              :          (NON_LVALUE_EXPR) for the static_cast; otherwise, if the operand
    8861              :          is a variable with the same type, the conversion would get folded
    8862              :          away, leaving just the variable and causing lvalue_kind to give
    8863              :          the wrong answer.  */
    8864      3548059 :       expr = cp_fold_convert (type, expr);
    8865              : 
    8866              :       /* When -fsanitize=null, make sure to diagnose reference binding to
    8867              :          NULL even when the reference is converted to pointer later on.  */
    8868      3548059 :       if (sanitize_flags_p (SANITIZE_NULL)
    8869          502 :           && TREE_CODE (expr) == COND_EXPR
    8870            6 :           && TREE_OPERAND (expr, 2)
    8871            6 :           && TREE_CODE (TREE_OPERAND (expr, 2)) == INTEGER_CST
    8872      3548065 :           && TREE_TYPE (TREE_OPERAND (expr, 2)) == type)
    8873            6 :         ubsan_maybe_instrument_reference (&TREE_OPERAND (expr, 2));
    8874              : 
    8875      3548059 :       return convert_from_reference (rvalue (expr));
    8876              :     }
    8877              : 
    8878              :   /* "A glvalue of type cv1 T1 can be cast to type rvalue reference to
    8879              :      cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)."  */
    8880     48119825 :   if (TYPE_REF_P (type)
    8881      2055977 :       && TYPE_REF_IS_RVALUE (type)
    8882       867870 :       && (clk = real_lvalue_p (expr))
    8883       855787 :       && reference_compatible_p (TREE_TYPE (type), intype)
    8884     48975605 :       && (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    8885              :     {
    8886       855780 :       if (processing_template_decl)
    8887              :         return expr;
    8888       855015 :       if (clk == clk_ordinary)
    8889              :         {
    8890              :           /* Handle the (non-bit-field) lvalue case here by casting to
    8891              :              lvalue reference and then changing it to an rvalue reference.
    8892              :              Casting an xvalue to rvalue reference will be handled by the
    8893              :              main code path.  */
    8894       855012 :           tree lref = cp_build_reference_type (TREE_TYPE (type), false);
    8895       855012 :           result = (perform_direct_initialization_if_possible
    8896       855012 :                     (lref, expr, c_cast_p, complain));
    8897       855012 :           result = build1 (NON_LVALUE_EXPR, type, result);
    8898       855012 :           return convert_from_reference (result);
    8899              :         }
    8900              :       else
    8901              :         /* For a bit-field or packed field, bind to a temporary.  */
    8902            3 :         expr = rvalue (expr);
    8903              :     }
    8904              : 
    8905              :   /* Resolve overloaded address here rather than once in
    8906              :      implicit_conversion and again in the inverse code below.  */
    8907     47264048 :   if (TYPE_PTRMEMFUNC_P (type) && type_unknown_p (expr))
    8908              :     {
    8909           21 :       expr = instantiate_type (type, expr, complain);
    8910           21 :       intype = TREE_TYPE (expr);
    8911              :     }
    8912              : 
    8913              :   /* [expr.static.cast]
    8914              : 
    8915              :      Any expression can be explicitly converted to type cv void.  */
    8916     47264048 :   if (VOID_TYPE_P (type))
    8917              :     {
    8918       602758 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    8919            0 :         expr = TREE_OPERAND (expr, 0);
    8920       602758 :       return convert_to_void (expr, ICV_CAST, complain);
    8921              :     }
    8922              : 
    8923              :   /* [class.abstract]
    8924              :      An abstract class shall not be used ... as the type of an explicit
    8925              :      conversion.  */
    8926     46661290 :   if (abstract_virtuals_error (ACU_CAST, type, complain))
    8927            6 :     return error_mark_node;
    8928              : 
    8929              :   /* [expr.static.cast]
    8930              : 
    8931              :      An expression e can be explicitly converted to a type T using a
    8932              :      static_cast of the form static_cast<T>(e) if the declaration T
    8933              :      t(e);" is well-formed, for some invented temporary variable
    8934              :      t.  */
    8935     46661284 :   result = perform_direct_initialization_if_possible (type, expr,
    8936              :                                                       c_cast_p, complain);
    8937              :   /* P1975 allows static_cast<Aggr>(42), as well as static_cast<T[5]>(42),
    8938              :      which initialize the first element of the aggregate.  We need to handle
    8939              :      the array case specifically.  */
    8940     46661284 :   if (result == NULL_TREE
    8941      4787573 :       && cxx_dialect >= cxx20
    8942      3412936 :       && TREE_CODE (type) == ARRAY_TYPE)
    8943              :     {
    8944              :       /* Create { EXPR } and perform direct-initialization from it.  */
    8945           15 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
    8946           15 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
    8947           15 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
    8948           15 :       result = perform_direct_initialization_if_possible (type, e, c_cast_p,
    8949              :                                                           complain);
    8950              :     }
    8951      4787573 :   if (result)
    8952              :     {
    8953     41873726 :       if (processing_template_decl)
    8954              :         return expr;
    8955              : 
    8956     41153468 :       result = convert_from_reference (result);
    8957              : 
    8958              :       /* [expr.static.cast]
    8959              : 
    8960              :          If T is a reference type, the result is an lvalue; otherwise,
    8961              :          the result is an rvalue.  */
    8962     41153468 :       if (!TYPE_REF_P (type))
    8963              :         {
    8964     39953365 :           result = rvalue (result);
    8965              : 
    8966     39953365 :           if (result == expr && SCALAR_TYPE_P (type))
    8967              :             /* Leave some record of the cast.  */
    8968      2465714 :             result = build_nop (type, expr);
    8969              :         }
    8970              :       return result;
    8971              :     }
    8972              : 
    8973              :   /* [expr.static.cast]
    8974              : 
    8975              :      The inverse of any standard conversion sequence (clause _conv_),
    8976              :      other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer
    8977              :      (_conv.array_), function-to-pointer (_conv.func_), and boolean
    8978              :      (_conv.bool_) conversions, can be performed explicitly using
    8979              :      static_cast subject to the restriction that the explicit
    8980              :      conversion does not cast away constness (_expr.const.cast_), and
    8981              :      the following additional rules for specific cases:  */
    8982              :   /* For reference, the conversions not excluded are: integral
    8983              :      promotions, floating-point promotion, integral conversions,
    8984              :      floating-point conversions, floating-integral conversions,
    8985              :      pointer conversions, and pointer to member conversions.  */
    8986              :   /* DR 128
    8987              : 
    8988              :      A value of integral _or enumeration_ type can be explicitly
    8989              :      converted to an enumeration type.  */
    8990              :   /* The effect of all that is that any conversion between any two
    8991              :      types which are integral, floating, or enumeration types can be
    8992              :      performed.  */
    8993      4787558 :   if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    8994      2643814 :        || SCALAR_FLOAT_TYPE_P (type))
    8995      2262204 :       && (INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
    8996       220138 :           || SCALAR_FLOAT_TYPE_P (intype)))
    8997              :     {
    8998      2160431 :       if (processing_template_decl)
    8999              :         return expr;
    9000      2066578 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9001            0 :         expr = TREE_OPERAND (expr, 0);
    9002              :       /* [expr.static.cast]: "If the value is not a bit-field, the result
    9003              :          refers to the object or the specified base class subobject thereof;
    9004              :          otherwise, the lvalue-to-rvalue conversion is applied to the
    9005              :          bit-field and the resulting prvalue is used as the operand of the
    9006              :          static_cast."  There are no prvalue bit-fields; the l-to-r conversion
    9007              :          will give us an object of the underlying type of the bit-field.  */
    9008      2066578 :       expr = decay_conversion (expr, complain);
    9009      2066578 :       return ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL, complain);
    9010              :     }
    9011              : 
    9012       824001 :   if (TYPE_PTR_P (type) && TYPE_PTR_P (intype)
    9013       819493 :       && CLASS_TYPE_P (TREE_TYPE (type))
    9014       190519 :       && CLASS_TYPE_P (TREE_TYPE (intype))
    9015      2662164 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT
    9016              :                                           (TREE_TYPE (intype))),
    9017        35037 :                       build_pointer_type (TYPE_MAIN_VARIANT
    9018              :                                           (TREE_TYPE (type))),
    9019              :                       complain))
    9020              :     {
    9021        34697 :       tree base;
    9022              : 
    9023        34697 :       if (processing_template_decl)
    9024              :         return expr;
    9025              : 
    9026        34679 :       if (!c_cast_p
    9027        34679 :           && check_for_casting_away_constness (loc, intype, type,
    9028              :                                                STATIC_CAST_EXPR,
    9029              :                                                complain))
    9030            6 :         return error_mark_node;
    9031        68804 :       base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
    9032              :                           c_cast_p ? ba_unique : ba_check,
    9033              :                           NULL, complain);
    9034        34673 :       expr = build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false,
    9035              :                               complain);
    9036              : 
    9037        34673 :       if (sanitize_flags_p (SANITIZE_VPTR))
    9038              :         {
    9039           43 :           tree ubsan_check
    9040           43 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    9041              :                                                   intype, expr);
    9042           43 :           if (ubsan_check)
    9043        34673 :             expr = ubsan_check;
    9044              :         }
    9045              : 
    9046        34673 :       return cp_fold_convert (type, expr);
    9047              :     }
    9048              : 
    9049           89 :   if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    9050      2592430 :       || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
    9051              :     {
    9052          232 :       tree c1;
    9053          232 :       tree c2;
    9054          232 :       tree t1;
    9055          232 :       tree t2;
    9056              : 
    9057          232 :       c1 = TYPE_PTRMEM_CLASS_TYPE (intype);
    9058          232 :       c2 = TYPE_PTRMEM_CLASS_TYPE (type);
    9059              : 
    9060          232 :       if (TYPE_PTRDATAMEM_P (type))
    9061              :         {
    9062           89 :           t1 = (build_ptrmem_type
    9063           89 :                 (c1,
    9064           89 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (intype))));
    9065           89 :           t2 = (build_ptrmem_type
    9066           89 :                 (c2,
    9067           89 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (type))));
    9068              :         }
    9069              :       else
    9070              :         {
    9071              :           t1 = intype;
    9072              :           t2 = type;
    9073              :         }
    9074          232 :       if (can_convert (t1, t2, complain) || can_convert (t2, t1, complain))
    9075              :         {
    9076          154 :           if (!c_cast_p
    9077          154 :               && check_for_casting_away_constness (loc, intype, type,
    9078              :                                                    STATIC_CAST_EXPR,
    9079              :                                                    complain))
    9080            9 :             return error_mark_node;
    9081          145 :           if (processing_template_decl)
    9082              :             return expr;
    9083          145 :           return convert_ptrmem (type, expr, /*allow_inverse_p=*/1,
    9084          145 :                                  c_cast_p, complain);
    9085              :         }
    9086              :     }
    9087              : 
    9088              :   /* [expr.static.cast]
    9089              : 
    9090              :      An rvalue of type "pointer to cv void" can be explicitly
    9091              :      converted to a pointer to object type.  A value of type pointer
    9092              :      to object converted to "pointer to cv void" and back to the
    9093              :      original pointer type will have its original value.  */
    9094      2592276 :   if (TYPE_PTR_P (intype)
    9095       884311 :       && VOID_TYPE_P (TREE_TYPE (intype))
    9096      3338718 :       && TYPE_PTROB_P (type))
    9097              :     {
    9098       714182 :       if (!c_cast_p
    9099       714182 :           && check_for_casting_away_constness (loc, intype, type,
    9100              :                                                STATIC_CAST_EXPR,
    9101              :                                                complain))
    9102           21 :         return error_mark_node;
    9103       714161 :       if (processing_template_decl)
    9104              :         return expr;
    9105       627250 :       return build_nop (type, expr);
    9106              :     }
    9107              : 
    9108      1878094 :   *valid_p = false;
    9109      1878094 :   return error_mark_node;
    9110              : }
    9111              : 
    9112              : /* Return an expression representing static_cast<TYPE>(EXPR).  */
    9113              : 
    9114              : tree
    9115     17837358 : build_static_cast (location_t loc, tree type, tree oexpr,
    9116              :                    tsubst_flags_t complain)
    9117              : {
    9118     17837358 :   tree expr = oexpr;
    9119     17837358 :   tree result;
    9120     17837358 :   bool valid_p;
    9121              : 
    9122     17837358 :   if (type == error_mark_node || expr == error_mark_node)
    9123              :     return error_mark_node;
    9124              : 
    9125     17837102 :   bool dependent = (dependent_type_p (type)
    9126     17837102 :                     || type_dependent_expression_p (expr));
    9127     12437245 :   if (dependent)
    9128              :     {
    9129      6542639 :     tmpl:
    9130      6542639 :       expr = build_min (STATIC_CAST_EXPR, type, oexpr);
    9131              :       /* We don't know if it will or will not have side effects.  */
    9132      6542639 :       TREE_SIDE_EFFECTS (expr) = 1;
    9133      6542639 :       result = convert_from_reference (expr);
    9134      6542639 :       protected_set_expr_location (result, loc);
    9135      6542639 :       return result;
    9136              :     }
    9137              : 
    9138              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9139              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9140     12437245 :   if (!TYPE_REF_P (type)
    9141      6593608 :       && TREE_CODE (expr) == NOP_EXPR
    9142     12549662 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9143           86 :     expr = TREE_OPERAND (expr, 0);
    9144              : 
    9145     12437245 :   result = build_static_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    9146              :                                 &valid_p, complain);
    9147     12437245 :   if (valid_p)
    9148              :     {
    9149     12436951 :       if (result != error_mark_node)
    9150              :         {
    9151     12436846 :           maybe_warn_about_useless_cast (loc, type, expr, complain);
    9152     12436846 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9153              :         }
    9154     12436951 :       if (processing_template_decl)
    9155      1142782 :         goto tmpl;
    9156     11294169 :       protected_set_expr_location (result, loc);
    9157     11294169 :       return result;
    9158              :     }
    9159              : 
    9160          294 :   if (complain & tf_error)
    9161              :     {
    9162          163 :       auto_diagnostic_group d;
    9163          163 :       error_at (loc, "invalid %<static_cast%> from type %qT to type %qT",
    9164          163 :                 TREE_TYPE (expr), type);
    9165          163 :       if ((TYPE_PTR_P (type) || TYPE_REF_P (type))
    9166          121 :           && CLASS_TYPE_P (TREE_TYPE (type))
    9167          192 :             && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    9168           17 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (TREE_TYPE (type))),
    9169           17 :                 "class type %qT is incomplete", TREE_TYPE (type));
    9170          163 :       tree expr_type = TREE_TYPE (expr);
    9171          163 :       if (TYPE_PTR_P (expr_type))
    9172           35 :         expr_type = TREE_TYPE (expr_type);
    9173          163 :       if (CLASS_TYPE_P (expr_type) && !COMPLETE_TYPE_P (expr_type))
    9174           12 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (expr_type)),
    9175              :                 "class type %qT is incomplete", expr_type);
    9176          163 :     }
    9177          294 :   return error_mark_node;
    9178              : }
    9179              : 
    9180              : /* EXPR is an expression with member function or pointer-to-member
    9181              :    function type.  TYPE is a pointer type.  Converting EXPR to TYPE is
    9182              :    not permitted by ISO C++, but we accept it in some modes.  If we
    9183              :    are not in one of those modes, issue a diagnostic.  Return the
    9184              :    converted expression.  */
    9185              : 
    9186              : tree
    9187          167 : convert_member_func_to_ptr (tree type, tree expr, tsubst_flags_t complain)
    9188              : {
    9189          167 :   tree intype;
    9190          167 :   tree decl;
    9191              : 
    9192          167 :   intype = TREE_TYPE (expr);
    9193          167 :   gcc_assert (TYPE_PTRMEMFUNC_P (intype)
    9194              :               || TREE_CODE (intype) == METHOD_TYPE);
    9195              : 
    9196          167 :   if (!(complain & tf_warning_or_error))
    9197            0 :     return error_mark_node;
    9198              : 
    9199          167 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    9200              : 
    9201          167 :   if (pedantic || warn_pmf2ptr)
    9202          211 :     pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpmf_conversions,
    9203              :              "converting from %qH to %qI", intype, type);
    9204              : 
    9205          167 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    9206              : 
    9207          167 :   if (TREE_CODE (intype) == METHOD_TYPE)
    9208           73 :     expr = build_addr_func (expr, complain);
    9209           94 :   else if (TREE_CODE (expr) == PTRMEM_CST)
    9210           76 :     expr = build_address (PTRMEM_CST_MEMBER (expr));
    9211              :   else
    9212              :     {
    9213           18 :       decl = maybe_dummy_object (TYPE_PTRMEM_CLASS_TYPE (intype), 0);
    9214           18 :       decl = build_address (decl);
    9215           18 :       expr = get_member_function_from_ptrfunc (&decl, expr, complain);
    9216              :     }
    9217              : 
    9218          167 :   if (expr == error_mark_node)
    9219              :     return error_mark_node;
    9220              : 
    9221          167 :   expr = build_nop (type, expr);
    9222          167 :   SET_EXPR_LOCATION (expr, loc);
    9223          167 :   return expr;
    9224              : }
    9225              : 
    9226              : /* Build a NOP_EXPR to TYPE, but mark it as a reinterpret_cast so that
    9227              :    constexpr evaluation knows to reject it.  */
    9228              : 
    9229              : static tree
    9230       116714 : build_nop_reinterpret (tree type, tree expr)
    9231              : {
    9232       116714 :   tree ret = build_nop (type, expr);
    9233       116714 :   if (ret != expr)
    9234       116714 :     REINTERPRET_CAST_P (ret) = true;
    9235       116714 :   return ret;
    9236              : }
    9237              : 
    9238              : /* Return a representation for a reinterpret_cast from EXPR to TYPE.
    9239              :    If C_CAST_P is true, this reinterpret cast is being done as part of
    9240              :    a C-style cast.  If VALID_P is non-NULL, *VALID_P is set to
    9241              :    indicate whether or not reinterpret_cast was valid.  */
    9242              : 
    9243              : static tree
    9244      2033872 : build_reinterpret_cast_1 (location_t loc, tree type, tree expr,
    9245              :                           bool c_cast_p, bool *valid_p,
    9246              :                           tsubst_flags_t complain)
    9247              : {
    9248      2033872 :   tree intype;
    9249              : 
    9250              :   /* Assume the cast is invalid.  */
    9251      2033872 :   if (valid_p)
    9252      1877856 :     *valid_p = true;
    9253              : 
    9254      2033872 :   if (type == error_mark_node || error_operand_p (expr))
    9255              :     return error_mark_node;
    9256              : 
    9257      2033872 :   intype = TREE_TYPE (expr);
    9258              : 
    9259              :   /* Save casted types in the function's used types hash table.  */
    9260      2033872 :   used_types_insert (type);
    9261              : 
    9262              :   /* A prvalue of non-class type is cv-unqualified.  */
    9263      2033872 :   if (!CLASS_TYPE_P (type))
    9264      2033863 :     type = cv_unqualified (type);
    9265              : 
    9266              :   /* [expr.reinterpret.cast]
    9267              :      A glvalue of type T1, designating an object x, can be cast to the type
    9268              :      "reference to T2" if an expression of type "pointer to T1" can be
    9269              :      explicitly converted to the type "pointer to T2" using a reinterpret_cast.
    9270              :      The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x
    9271              :      of type "pointer to T1". No temporary is created, no copy is made, and no
    9272              :      constructors (11.4.4) or conversion functions (11.4.7) are called.  */
    9273      2033872 :   if (TYPE_REF_P (type))
    9274              :     {
    9275         9870 :       if (!glvalue_p (expr))
    9276              :         {
    9277            9 :           if (complain & tf_error)
    9278            9 :             error_at (loc, "invalid cast of a prvalue expression of type "
    9279              :                       "%qT to type %qT",
    9280              :                       intype, type);
    9281            9 :           return error_mark_node;
    9282              :         }
    9283              : 
    9284              :       /* Warn about a reinterpret_cast from "A*" to "B&" if "A" and
    9285              :          "B" are related class types; the reinterpret_cast does not
    9286              :          adjust the pointer.  */
    9287         9861 :       if (TYPE_PTR_P (intype)
    9288            3 :           && (complain & tf_warning)
    9289         9864 :           && (comptypes (TREE_TYPE (intype), TREE_TYPE (type),
    9290              :                          COMPARE_BASE | COMPARE_DERIVED)))
    9291            3 :         warning_at (loc, 0, "casting %qT to %qT does not dereference pointer",
    9292              :                     intype, type);
    9293              : 
    9294         9861 :       expr = cp_build_addr_expr (expr, complain);
    9295              : 
    9296         9861 :       if (warn_strict_aliasing > 2)
    9297           72 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    9298              : 
    9299         9861 :       if (expr != error_mark_node)
    9300         9861 :         expr = build_reinterpret_cast_1
    9301         9861 :           (loc, build_pointer_type (TREE_TYPE (type)), expr, c_cast_p,
    9302              :            valid_p, complain);
    9303         9861 :       if (expr != error_mark_node)
    9304              :         /* cp_build_indirect_ref isn't right for rvalue refs.  */
    9305         9858 :         expr = convert_from_reference (fold_convert (type, expr));
    9306              :       return expr;
    9307              :     }
    9308              : 
    9309              :   /* As a G++ extension, we consider conversions from member
    9310              :      functions, and pointers to member functions to
    9311              :      pointer-to-function and pointer-to-void types.  If
    9312              :      -Wno-pmf-conversions has not been specified,
    9313              :      convert_member_func_to_ptr will issue an error message.  */
    9314          251 :   if ((TYPE_PTRMEMFUNC_P (intype)
    9315      2023829 :        || TREE_CODE (intype) == METHOD_TYPE)
    9316          246 :       && TYPE_PTR_P (type)
    9317      2024169 :       && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    9318          125 :           || VOID_TYPE_P (TREE_TYPE (type))))
    9319          158 :     return convert_member_func_to_ptr (type, expr, complain);
    9320              : 
    9321              :   /* If the cast is not to a reference type, the lvalue-to-rvalue,
    9322              :      array-to-pointer, and function-to-pointer conversions are
    9323              :      performed.  */
    9324      2023844 :   expr = decay_conversion (expr, complain);
    9325              : 
    9326              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9327              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9328      2023844 :   if (TREE_CODE (expr) == NOP_EXPR
    9329      2023844 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9330          388 :     expr = TREE_OPERAND (expr, 0);
    9331              : 
    9332      2023844 :   if (error_operand_p (expr))
    9333           30 :     return error_mark_node;
    9334              : 
    9335      2023814 :   intype = TREE_TYPE (expr);
    9336              : 
    9337              :   /* [expr.reinterpret.cast]
    9338              :      A pointer can be converted to any integral type large enough to
    9339              :      hold it. ... A value of type std::nullptr_t can be converted to
    9340              :      an integral type; the conversion has the same meaning and
    9341              :      validity as a conversion of (void*)0 to the integral type.  */
    9342      2023814 :   if (CP_INTEGRAL_TYPE_P (type)
    9343       169517 :       && (TYPE_PTR_P (intype) || NULLPTR_TYPE_P (intype)))
    9344              :     {
    9345       167610 :       if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))
    9346              :         {
    9347           21 :           if (complain & tf_error)
    9348           15 :             permerror (loc, "cast from %qH to %qI loses precision",
    9349              :                        intype, type);
    9350              :           else
    9351            6 :             return error_mark_node;
    9352              :         }
    9353       167604 :       if (NULLPTR_TYPE_P (intype))
    9354           98 :         return build_int_cst (type, 0);
    9355              :     }
    9356              :   /* [expr.reinterpret.cast]
    9357              :      A value of integral or enumeration type can be explicitly
    9358              :      converted to a pointer.  */
    9359      1856204 :   else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype))
    9360              :     /* OK */
    9361              :     ;
    9362      1821093 :   else if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    9363      1819171 :             || TYPE_PTR_OR_PTRMEM_P (type))
    9364      1938368 :            && same_type_p (type, intype))
    9365              :     /* DR 799 */
    9366          529 :     return rvalue (expr);
    9367      1820564 :   else if (TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
    9368              :     {
    9369          282 :       if ((complain & tf_warning)
    9370          564 :           && !cxx_safe_function_type_cast_p (TREE_TYPE (type),
    9371          282 :                                              TREE_TYPE (intype)))
    9372          145 :         warning_at (loc, OPT_Wcast_function_type,
    9373              :                     "cast between incompatible function types"
    9374              :                     " from %qH to %qI", intype, type);
    9375          282 :       return build_nop_reinterpret (type, expr);
    9376              :     }
    9377      1820282 :   else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype))
    9378              :     {
    9379           79 :       if ((complain & tf_warning)
    9380          158 :           && !cxx_safe_function_type_cast_p
    9381           79 :                 (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (type)),
    9382           79 :                  TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (intype))))
    9383           52 :         warning_at (loc, OPT_Wcast_function_type,
    9384              :                     "cast between incompatible pointer to member types"
    9385              :                     " from %qH to %qI", intype, type);
    9386           79 :       return build_nop_reinterpret (type, expr);
    9387              :     }
    9388           21 :   else if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    9389      1820203 :            || (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype)))
    9390              :     {
    9391       116098 :       if (!c_cast_p
    9392       116098 :           && check_for_casting_away_constness (loc, intype, type,
    9393              :                                                REINTERPRET_CAST_EXPR,
    9394              :                                                complain))
    9395           21 :         return error_mark_node;
    9396              :       /* Warn about possible alignment problems.  */
    9397       116077 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    9398           24 :           && (complain & tf_warning)
    9399           24 :           && !VOID_TYPE_P (type)
    9400           24 :           && TREE_CODE (TREE_TYPE (intype)) != FUNCTION_TYPE
    9401           24 :           && COMPLETE_TYPE_P (TREE_TYPE (type))
    9402           24 :           && COMPLETE_TYPE_P (TREE_TYPE (intype))
    9403       116125 :           && min_align_of_type (TREE_TYPE (type))
    9404           24 :              > min_align_of_type (TREE_TYPE (intype)))
    9405           18 :         warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    9406              :                     "increases required alignment of target type",
    9407              :                     intype, type);
    9408              : 
    9409       116077 :       if (warn_strict_aliasing <= 2)
    9410              :         /* strict_aliasing_warning STRIP_NOPs its expr.  */
    9411       104242 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    9412              : 
    9413       116077 :       return build_nop_reinterpret (type, expr);
    9414              :     }
    9415          297 :   else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
    9416      1704265 :            || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
    9417              :     {
    9418          276 :       if (complain & tf_warning)
    9419              :         /* C++11 5.2.10 p8 says that "Converting a function pointer to an
    9420              :            object pointer type or vice versa is conditionally-supported."  */
    9421          276 :         warning_at (loc, OPT_Wconditionally_supported,
    9422              :                     "casting between pointer-to-function and "
    9423              :                     "pointer-to-object is conditionally-supported");
    9424          276 :       return build_nop_reinterpret (type, expr);
    9425              :     }
    9426      1703829 :   else if (gnu_vector_type_p (type) && scalarish_type_p (intype))
    9427      1701872 :     return convert_to_vector (type, rvalue (expr));
    9428         1957 :   else if (gnu_vector_type_p (intype)
    9429         1957 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    9430         1855 :     return convert_to_integer_nofold (type, expr);
    9431              :   else
    9432              :     {
    9433          102 :       if (valid_p)
    9434           84 :         *valid_p = false;
    9435          102 :       if (complain & tf_error)
    9436           93 :         error_at (loc, "invalid cast from type %qT to type %qT",
    9437              :                   intype, type);
    9438          102 :       return error_mark_node;
    9439              :     }
    9440              : 
    9441       202617 :   expr = cp_convert (type, expr, complain);
    9442       202617 :   if (TREE_CODE (expr) == NOP_EXPR)
    9443              :     /* Mark any nop_expr that created as a reintepret_cast.  */
    9444            0 :     REINTERPRET_CAST_P (expr) = true;
    9445              :   return expr;
    9446              : }
    9447              : 
    9448              : tree
    9449       778394 : build_reinterpret_cast (location_t loc, tree type, tree expr,
    9450              :                         tsubst_flags_t complain)
    9451              : {
    9452       778394 :   tree r;
    9453              : 
    9454       778394 :   if (type == error_mark_node || expr == error_mark_node)
    9455              :     return error_mark_node;
    9456              : 
    9457       778387 :   if (processing_template_decl)
    9458              :     {
    9459       632176 :       tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
    9460              : 
    9461       632176 :       if (!TREE_SIDE_EFFECTS (t)
    9462       632176 :           && type_dependent_expression_p (expr))
    9463              :         /* There might turn out to be side effects inside expr.  */
    9464       296837 :         TREE_SIDE_EFFECTS (t) = 1;
    9465       632176 :       r = convert_from_reference (t);
    9466       632176 :       protected_set_expr_location (r, loc);
    9467       632176 :       return r;
    9468              :     }
    9469              : 
    9470       146211 :   r = build_reinterpret_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    9471              :                                 /*valid_p=*/NULL, complain);
    9472       146211 :   if (r != error_mark_node)
    9473              :     {
    9474       146148 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9475       146148 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9476              :     }
    9477       146211 :   protected_set_expr_location (r, loc);
    9478       146211 :   return r;
    9479              : }
    9480              : 
    9481              : /* Perform a const_cast from EXPR to TYPE.  If the cast is valid,
    9482              :    return an appropriate expression.  Otherwise, return
    9483              :    error_mark_node.  If the cast is not valid, and COMPLAIN is true,
    9484              :    then a diagnostic will be issued.  If VALID_P is non-NULL, we are
    9485              :    performing a C-style cast, its value upon return will indicate
    9486              :    whether or not the conversion succeeded.  */
    9487              : 
    9488              : static tree
    9489     39871839 : build_const_cast_1 (location_t loc, tree dst_type, tree expr,
    9490              :                     tsubst_flags_t complain, bool *valid_p)
    9491              : {
    9492     39871839 :   tree src_type;
    9493     39871839 :   tree reference_type;
    9494              : 
    9495              :   /* Callers are responsible for handling error_mark_node as a
    9496              :      destination type.  */
    9497     39871839 :   gcc_assert (dst_type != error_mark_node);
    9498              :   /* In a template, callers should be building syntactic
    9499              :      representations of casts, not using this machinery.  */
    9500     39871839 :   gcc_assert (!processing_template_decl);
    9501              : 
    9502              :   /* Assume the conversion is invalid.  */
    9503     39871839 :   if (valid_p)
    9504     39673105 :     *valid_p = false;
    9505              : 
    9506     39871839 :   if (!INDIRECT_TYPE_P (dst_type) && !TYPE_PTRDATAMEM_P (dst_type))
    9507              :     {
    9508     38778512 :       if (complain & tf_error)
    9509            9 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9510              :                   "which is not a pointer, reference, "
    9511              :                   "nor a pointer-to-data-member type", dst_type);
    9512     38778512 :       return error_mark_node;
    9513              :     }
    9514              : 
    9515      1093327 :   if (TREE_CODE (TREE_TYPE (dst_type)) == FUNCTION_TYPE)
    9516              :     {
    9517         4175 :       if (complain & tf_error)
    9518            6 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9519              :                   "which is a pointer or reference to a function type",
    9520              :                   dst_type);
    9521         4175 :        return error_mark_node;
    9522              :     }
    9523              : 
    9524              :   /* A prvalue of non-class type is cv-unqualified.  */
    9525      1089152 :   dst_type = cv_unqualified (dst_type);
    9526              : 
    9527              :   /* Save casted types in the function's used types hash table.  */
    9528      1089152 :   used_types_insert (dst_type);
    9529              : 
    9530      1089152 :   src_type = TREE_TYPE (expr);
    9531              :   /* Expressions do not really have reference types.  */
    9532      1089152 :   if (TYPE_REF_P (src_type))
    9533            0 :     src_type = TREE_TYPE (src_type);
    9534              : 
    9535              :   /* [expr.const.cast]
    9536              : 
    9537              :      For two object types T1 and T2, if a pointer to T1 can be explicitly
    9538              :      converted to the type "pointer to T2" using a const_cast, then the
    9539              :      following conversions can also be made:
    9540              : 
    9541              :      -- an lvalue of type T1 can be explicitly converted to an lvalue of
    9542              :      type T2 using the cast const_cast<T2&>;
    9543              : 
    9544              :      -- a glvalue of type T1 can be explicitly converted to an xvalue of
    9545              :      type T2 using the cast const_cast<T2&&>; and
    9546              : 
    9547              :      -- if T1 is a class type, a prvalue of type T1 can be explicitly
    9548              :      converted to an xvalue of type T2 using the cast const_cast<T2&&>.  */
    9549              : 
    9550      1089152 :   if (TYPE_REF_P (dst_type))
    9551              :     {
    9552       125307 :       reference_type = dst_type;
    9553       125307 :       if (!TYPE_REF_IS_RVALUE (dst_type)
    9554       125307 :           ? lvalue_p (expr)
    9555         1562 :           : obvalue_p (expr))
    9556              :         /* OK.  */;
    9557              :       else
    9558              :         {
    9559           35 :           if (complain & tf_error)
    9560            9 :             error_at (loc, "invalid %<const_cast%> of an rvalue of type %qT "
    9561              :                       "to type %qT",
    9562              :                       src_type, dst_type);
    9563           35 :           return error_mark_node;
    9564              :         }
    9565       125272 :       dst_type = build_pointer_type (TREE_TYPE (dst_type));
    9566       125272 :       src_type = build_pointer_type (src_type);
    9567              :     }
    9568              :   else
    9569              :     {
    9570       963845 :       reference_type = NULL_TREE;
    9571              :       /* If the destination type is not a reference type, the
    9572              :          lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9573              :          conversions are performed.  */
    9574       963845 :       src_type = type_decays_to (src_type);
    9575       963845 :       if (src_type == error_mark_node)
    9576              :         return error_mark_node;
    9577              :     }
    9578              : 
    9579      1089117 :   if (TYPE_PTR_P (src_type) || TYPE_PTRDATAMEM_P (src_type))
    9580              :     {
    9581       644777 :       if (comp_ptr_ttypes_const (dst_type, src_type, bounds_none))
    9582              :         {
    9583       400182 :           if (valid_p)
    9584              :             {
    9585       201526 :               *valid_p = true;
    9586              :               /* This cast is actually a C-style cast.  Issue a warning if
    9587              :                  the user is making a potentially unsafe cast.  */
    9588       201526 :               check_for_casting_away_constness (loc, src_type, dst_type,
    9589              :                                                 CAST_EXPR, complain);
    9590              :               /* ??? comp_ptr_ttypes_const ignores TYPE_ALIGN.  */
    9591       201526 :               if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    9592            3 :                   && (complain & tf_warning)
    9593       201532 :                   && min_align_of_type (TREE_TYPE (dst_type))
    9594            3 :                      > min_align_of_type (TREE_TYPE (src_type)))
    9595            3 :                 warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    9596              :                             "increases required alignment of target type",
    9597              :                             src_type, dst_type);
    9598              :             }
    9599       400182 :           if (reference_type)
    9600              :             {
    9601       123961 :               expr = cp_build_addr_expr (expr, complain);
    9602       123961 :               if (expr == error_mark_node)
    9603              :                 return error_mark_node;
    9604       123943 :               expr = build_nop (reference_type, expr);
    9605       123943 :               return convert_from_reference (expr);
    9606              :             }
    9607              :           else
    9608              :             {
    9609       276221 :               expr = decay_conversion (expr, complain);
    9610       276221 :               if (expr == error_mark_node)
    9611              :                 return error_mark_node;
    9612              : 
    9613              :               /* build_c_cast puts on a NOP_EXPR to make the result not an
    9614              :                  lvalue.  Strip such NOP_EXPRs if VALUE is being used in
    9615              :                  non-lvalue context.  */
    9616       276221 :               if (TREE_CODE (expr) == NOP_EXPR
    9617       276221 :                   && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9618            3 :                 expr = TREE_OPERAND (expr, 0);
    9619       276221 :               return build_nop (dst_type, expr);
    9620              :             }
    9621              :         }
    9622       244595 :       else if (valid_p
    9623       489142 :                && !at_least_as_qualified_p (TREE_TYPE (dst_type),
    9624       244547 :                                             TREE_TYPE (src_type)))
    9625        14976 :         check_for_casting_away_constness (loc, src_type, dst_type,
    9626              :                                           CAST_EXPR, complain);
    9627              :     }
    9628              : 
    9629       688935 :   if (complain & tf_error)
    9630           30 :     error_at (loc, "invalid %<const_cast%> from type %qT to type %qT",
    9631              :               src_type, dst_type);
    9632       688935 :   return error_mark_node;
    9633              : }
    9634              : 
    9635              : tree
    9636       699517 : build_const_cast (location_t loc, tree type, tree expr,
    9637              :                   tsubst_flags_t complain)
    9638              : {
    9639       699517 :   tree r;
    9640              : 
    9641       699517 :   if (type == error_mark_node || error_operand_p (expr))
    9642              :     return error_mark_node;
    9643              : 
    9644       699509 :   if (processing_template_decl)
    9645              :     {
    9646       500775 :       tree t = build_min (CONST_CAST_EXPR, type, expr);
    9647              : 
    9648       500775 :       if (!TREE_SIDE_EFFECTS (t)
    9649       500775 :           && type_dependent_expression_p (expr))
    9650              :         /* There might turn out to be side effects inside expr.  */
    9651       384089 :         TREE_SIDE_EFFECTS (t) = 1;
    9652       500775 :       r = convert_from_reference (t);
    9653       500775 :       protected_set_expr_location (r, loc);
    9654       500775 :       return r;
    9655              :     }
    9656              : 
    9657       198734 :   r = build_const_cast_1 (loc, type, expr, complain, /*valid_p=*/NULL);
    9658       198734 :   if (r != error_mark_node)
    9659              :     {
    9660       198656 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9661       198656 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9662              :     }
    9663       198734 :   protected_set_expr_location (r, loc);
    9664       198734 :   return r;
    9665              : }
    9666              : 
    9667              : /* Like cp_build_c_cast, but for the c-common bits.  */
    9668              : 
    9669              : tree
    9670            0 : build_c_cast (location_t loc, tree type, tree expr)
    9671              : {
    9672            0 :   return cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9673              : }
    9674              : 
    9675              : /* Like the "build_c_cast" used for c-common, but using cp_expr to
    9676              :    preserve location information even for tree nodes that don't
    9677              :    support it.  */
    9678              : 
    9679              : cp_expr
    9680     10800647 : build_c_cast (location_t loc, tree type, cp_expr expr)
    9681              : {
    9682     10800647 :   cp_expr result = cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9683     10800647 :   result.set_location (loc);
    9684     10800647 :   return result;
    9685              : }
    9686              : 
    9687              : /* Build an expression representing an explicit C-style cast to type
    9688              :    TYPE of expression EXPR.  */
    9689              : 
    9690              : tree
    9691     42516032 : cp_build_c_cast (location_t loc, tree type, tree expr,
    9692              :                  tsubst_flags_t complain)
    9693              : {
    9694     42516032 :   tree value = expr;
    9695     42516032 :   tree result;
    9696     42516032 :   bool valid_p;
    9697              : 
    9698     42516032 :   if (type == error_mark_node || error_operand_p (expr))
    9699              :     return error_mark_node;
    9700              : 
    9701     42515855 :   if (processing_template_decl)
    9702              :     {
    9703      2842741 :       tree t = build_min (CAST_EXPR, type,
    9704              :                           tree_cons (NULL_TREE, value, NULL_TREE));
    9705              :       /* We don't know if it will or will not have side effects.  */
    9706      2842741 :       TREE_SIDE_EFFECTS (t) = 1;
    9707      2842741 :       return convert_from_reference (t);
    9708              :     }
    9709              : 
    9710              :   /* Casts to a (pointer to a) specific ObjC class (or 'id' or
    9711              :      'Class') should always be retained, because this information aids
    9712              :      in method lookup.  */
    9713     39673114 :   if (objc_is_object_ptr (type)
    9714     39673114 :       && objc_is_object_ptr (TREE_TYPE (expr)))
    9715            0 :     return build_nop (type, expr);
    9716              : 
    9717              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9718              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9719     39673114 :   if (!TYPE_REF_P (type)
    9720     39670366 :       && TREE_CODE (value) == NOP_EXPR
    9721     40152022 :       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
    9722       243036 :     value = TREE_OPERAND (value, 0);
    9723              : 
    9724     39673114 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9725              :     {
    9726              :       /* Allow casting from T1* to T2[] because Cfront allows it.
    9727              :          NIHCL uses it. It is not valid ISO C++ however.  */
    9728            3 :       if (TYPE_PTR_P (TREE_TYPE (expr)))
    9729              :         {
    9730            0 :           if (complain & tf_error)
    9731            0 :             permerror (loc, "ISO C++ forbids casting to an array type %qT",
    9732              :                        type);
    9733              :           else
    9734            0 :             return error_mark_node;
    9735            0 :           type = build_pointer_type (TREE_TYPE (type));
    9736              :         }
    9737              :       else
    9738              :         {
    9739            3 :           if (complain & tf_error)
    9740            3 :             error_at (loc, "ISO C++ forbids casting to an array type %qT",
    9741              :                       type);
    9742            3 :           return error_mark_node;
    9743              :         }
    9744              :     }
    9745              : 
    9746     39673111 :   if (FUNC_OR_METHOD_TYPE_P (type))
    9747              :     {
    9748           15 :       if (complain & tf_error)
    9749           15 :         error_at (loc, "invalid cast to function type %qT", type);
    9750           15 :       return error_mark_node;
    9751              :     }
    9752              : 
    9753     39673096 :   if (TYPE_PTR_P (type)
    9754       891708 :       && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
    9755              :       /* Casting to an integer of smaller size is an error detected elsewhere.  */
    9756       442896 :       && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (value))
    9757              :       /* Don't warn about converting any constant.  */
    9758     40058994 :       && !TREE_CONSTANT (value))
    9759           47 :     warning_at (loc, OPT_Wint_to_pointer_cast,
    9760              :                 "cast to pointer from integer of different size");
    9761              : 
    9762              :   /* A C-style cast can be a const_cast.  */
    9763     39673096 :   result = build_const_cast_1 (loc, type, value, complain & tf_warning,
    9764              :                                &valid_p);
    9765     39673096 :   if (valid_p)
    9766              :     {
    9767       201517 :       if (result != error_mark_node)
    9768              :         {
    9769       201508 :           maybe_warn_about_useless_cast (loc, type, value, complain);
    9770       201508 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9771              :         }
    9772            9 :       else if (complain & tf_error)
    9773            9 :         build_const_cast_1 (loc, type, value, tf_error, &valid_p);
    9774              :       return result;
    9775              :     }
    9776              : 
    9777              :   /* Or a static cast.  */
    9778     39471579 :   result = build_static_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9779              :                                 &valid_p, complain);
    9780              :   /* Or a reinterpret_cast.  */
    9781     39471579 :   if (!valid_p)
    9782      1877800 :     result = build_reinterpret_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9783              :                                        &valid_p, complain);
    9784              :   /* The static_cast or reinterpret_cast may be followed by a
    9785              :      const_cast.  */
    9786     39471579 :   if (valid_p
    9787              :       /* A valid cast may result in errors if, for example, a
    9788              :          conversion to an ambiguous base class is required.  */
    9789     39471579 :       && !error_operand_p (result))
    9790              :     {
    9791     39471157 :       tree result_type;
    9792              : 
    9793     39471157 :       maybe_warn_about_useless_cast (loc, type, value, complain);
    9794     39471157 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9795              : 
    9796              :       /* Non-class rvalues always have cv-unqualified type.  */
    9797     39471157 :       if (!CLASS_TYPE_P (type))
    9798     36632457 :         type = TYPE_MAIN_VARIANT (type);
    9799     39471157 :       result_type = TREE_TYPE (result);
    9800     39471157 :       if (!CLASS_TYPE_P (result_type) && !TYPE_REF_P (type))
    9801     36631124 :         result_type = TYPE_MAIN_VARIANT (result_type);
    9802              :       /* If the type of RESULT does not match TYPE, perform a
    9803              :          const_cast to make it match.  If the static_cast or
    9804              :          reinterpret_cast succeeded, we will differ by at most
    9805              :          cv-qualification, so the follow-on const_cast is guaranteed
    9806              :          to succeed.  */
    9807     39471157 :       if (!same_type_p (non_reference (type), non_reference (result_type)))
    9808              :         {
    9809            0 :           result = build_const_cast_1 (loc, type, result, tf_none, &valid_p);
    9810            0 :           gcc_assert (valid_p);
    9811              :         }
    9812              :       return result;
    9813              :     }
    9814              : 
    9815          422 :   return error_mark_node;
    9816              : }
    9817              : 
    9818              : /* Warn when a value is moved to itself with std::move.  LHS is the target,
    9819              :    RHS may be the std::move call, and LOC is the location of the whole
    9820              :    assignment.  Return true if we warned.  */
    9821              : 
    9822              : bool
    9823     29582452 : maybe_warn_self_move (location_t loc, tree lhs, tree rhs)
    9824              : {
    9825     29582452 :   if (!warn_self_move)
    9826              :     return false;
    9827              : 
    9828              :   /* C++98 doesn't know move.  */
    9829       368856 :   if (cxx_dialect < cxx11)
    9830              :     return false;
    9831              : 
    9832       348966 :   if (processing_template_decl)
    9833              :     return false;
    9834              : 
    9835        26723 :   if (!REFERENCE_REF_P (rhs)
    9836       304905 :       || TREE_CODE (TREE_OPERAND (rhs, 0)) != CALL_EXPR)
    9837              :     return false;
    9838         4901 :   tree fn = TREE_OPERAND (rhs, 0);
    9839         4901 :   if (!is_std_move_p (fn))
    9840              :     return false;
    9841              : 
    9842              :   /* Just a little helper to strip * and various NOPs.  */
    9843         6693 :   auto extract_op = [] (tree &op) {
    9844         4462 :     STRIP_NOPS (op);
    9845         5683 :     while (INDIRECT_REF_P (op))
    9846         1221 :       op = TREE_OPERAND (op, 0);
    9847         4462 :     op = maybe_undo_parenthesized_ref (op);
    9848         4462 :     STRIP_ANY_LOCATION_WRAPPER (op);
    9849         4462 :   };
    9850              : 
    9851         2231 :   tree arg = CALL_EXPR_ARG (fn, 0);
    9852         2231 :   extract_op (arg);
    9853         2231 :   if (TREE_CODE (arg) == ADDR_EXPR)
    9854         1555 :     arg = TREE_OPERAND (arg, 0);
    9855         2231 :   tree type = TREE_TYPE (lhs);
    9856         2231 :   tree orig_lhs = lhs;
    9857         2231 :   extract_op (lhs);
    9858         2231 :   if (cp_tree_equal (lhs, arg)
    9859              :       /* Also warn in a member-initializer-list, as in : i(std::move(i)).  */
    9860         2231 :       || (TREE_CODE (lhs) == FIELD_DECL
    9861          642 :           && TREE_CODE (arg) == COMPONENT_REF
    9862          305 :           && cp_tree_equal (TREE_OPERAND (arg, 0), current_class_ref)
    9863            6 :           && TREE_OPERAND (arg, 1) == lhs))
    9864          117 :     if (warning_at (loc, OPT_Wself_move,
    9865              :                     "moving %qE of type %qT to itself", orig_lhs, type))
    9866              :       return true;
    9867              : 
    9868              :   return false;
    9869              : }
    9870              : 
    9871              : /* For use from the C common bits.  */
    9872              : tree
    9873         4772 : build_modify_expr (location_t location,
    9874              :                    tree lhs, tree /*lhs_origtype*/,
    9875              :                    enum tree_code modifycode,
    9876              :                    location_t /*rhs_location*/, tree rhs,
    9877              :                    tree /*rhs_origtype*/)
    9878              : {
    9879         4772 :   return cp_build_modify_expr (location, lhs, modifycode, rhs,
    9880         4772 :                                tf_warning_or_error);
    9881              : }
    9882              : 
    9883              : /* Build an assignment expression of lvalue LHS from value RHS.
    9884              :    MODIFYCODE is the code for a binary operator that we use
    9885              :    to combine the old value of LHS with RHS to get the new value.
    9886              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
    9887              : 
    9888              :    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.  */
    9889              : 
    9890              : tree
    9891     38716422 : cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
    9892              :                       tree rhs, tsubst_flags_t complain)
    9893              : {
    9894     38716422 :   lhs = mark_lvalue_use_nonread (lhs);
    9895              : 
    9896     38716422 :   tree result = NULL_TREE;
    9897     38716422 :   tree newrhs = rhs;
    9898     38716422 :   tree lhstype = TREE_TYPE (lhs);
    9899     38716422 :   tree olhs = lhs;
    9900     38716422 :   tree olhstype = lhstype;
    9901     38716422 :   bool plain_assign = (modifycode == NOP_EXPR);
    9902     38716422 :   bool compound_side_effects_p = false;
    9903     38716422 :   tree preeval = NULL_TREE;
    9904              : 
    9905              :   /* Avoid duplicate error messages from operands that had errors.  */
    9906     38716422 :   if (error_operand_p (lhs) || error_operand_p (rhs))
    9907           19 :     return error_mark_node;
    9908              : 
    9909     38716485 :   while (TREE_CODE (lhs) == COMPOUND_EXPR)
    9910              :     {
    9911           82 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
    9912           70 :         compound_side_effects_p = true;
    9913           82 :       lhs = TREE_OPERAND (lhs, 1);
    9914              :     }
    9915              : 
    9916              :   /* Handle control structure constructs used as "lvalues".  Note that we
    9917              :      leave COMPOUND_EXPR on the LHS because it is sequenced after the RHS.  */
    9918     38716403 :   switch (TREE_CODE (lhs))
    9919              :     {
    9920              :       /* Handle --foo = 5; as these are valid constructs in C++.  */
    9921           27 :     case PREDECREMENT_EXPR:
    9922           27 :     case PREINCREMENT_EXPR:
    9923           27 :       if (compound_side_effects_p)
    9924            9 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
    9925           27 :       lhs = genericize_compound_lvalue (lhs);
    9926          173 :     maybe_add_compound:
    9927              :       /* If we had (bar, --foo) = 5; or (bar, (baz, --foo)) = 5;
    9928              :          and looked through the COMPOUND_EXPRs, readd them now around
    9929              :          the resulting lhs.  */
    9930          173 :       if (TREE_CODE (olhs) == COMPOUND_EXPR)
    9931              :         {
    9932            9 :           lhs = build2 (COMPOUND_EXPR, lhstype, TREE_OPERAND (olhs, 0), lhs);
    9933            9 :           tree *ptr = &TREE_OPERAND (lhs, 1);
    9934            9 :           for (olhs = TREE_OPERAND (olhs, 1);
    9935           12 :                TREE_CODE (olhs) == COMPOUND_EXPR;
    9936            3 :                olhs = TREE_OPERAND (olhs, 1))
    9937              :             {
    9938            3 :               *ptr = build2 (COMPOUND_EXPR, lhstype,
    9939            3 :                              TREE_OPERAND (olhs, 0), *ptr);
    9940            3 :               ptr = &TREE_OPERAND (*ptr, 1);
    9941              :             }
    9942              :         }
    9943              :       break;
    9944              : 
    9945          146 :     case MODIFY_EXPR:
    9946          146 :       if (compound_side_effects_p)
    9947            0 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
    9948          146 :       lhs = genericize_compound_lvalue (lhs);
    9949          146 :       goto maybe_add_compound;
    9950              : 
    9951            0 :     case MIN_EXPR:
    9952            0 :     case MAX_EXPR:
    9953              :       /* MIN_EXPR and MAX_EXPR are currently only permitted as lvalues,
    9954              :          when neither operand has side-effects.  */
    9955            0 :       if (!lvalue_or_else (lhs, lv_assign, complain))
    9956            0 :         return error_mark_node;
    9957              : 
    9958            0 :       gcc_assert (!TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0))
    9959              :                   && !TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 1)));
    9960              : 
    9961            0 :       lhs = build3 (COND_EXPR, TREE_TYPE (lhs),
    9962            0 :                     build2 (TREE_CODE (lhs) == MIN_EXPR ? LE_EXPR : GE_EXPR,
    9963              :                             boolean_type_node,
    9964            0 :                             TREE_OPERAND (lhs, 0),
    9965            0 :                             TREE_OPERAND (lhs, 1)),
    9966            0 :                     TREE_OPERAND (lhs, 0),
    9967            0 :                     TREE_OPERAND (lhs, 1));
    9968          212 :       gcc_fallthrough ();
    9969              : 
    9970              :       /* Handle (a ? b : c) used as an "lvalue".  */
    9971          212 :     case COND_EXPR:
    9972          212 :       {
    9973              :         /* Produce (a ? (b = rhs) : (c = rhs))
    9974              :            except that the RHS goes through a save-expr
    9975              :            so the code to compute it is only emitted once.  */
    9976          212 :         if (VOID_TYPE_P (TREE_TYPE (rhs)))
    9977              :           {
    9978           18 :             if (complain & tf_error)
    9979           24 :               error_at (cp_expr_loc_or_loc (rhs, loc),
    9980              :                         "void value not ignored as it ought to be");
    9981           18 :             return error_mark_node;
    9982              :           }
    9983              : 
    9984          194 :         rhs = stabilize_expr (rhs, &preeval);
    9985              : 
    9986              :         /* Check this here to avoid odd errors when trying to convert
    9987              :            a throw to the type of the COND_EXPR.  */
    9988          194 :         if (!lvalue_or_else (lhs, lv_assign, complain))
    9989            6 :           return error_mark_node;
    9990              : 
    9991          188 :         tree op1 = TREE_OPERAND (lhs, 1);
    9992          188 :         if (TREE_CODE (op1) != THROW_EXPR)
    9993          182 :           op1 = cp_build_modify_expr (loc, op1, modifycode, rhs, complain);
    9994              :         /* When sanitizing undefined behavior, even when rhs doesn't need
    9995              :            stabilization at this point, the sanitization might add extra
    9996              :            SAVE_EXPRs in there and so make sure there is no tree sharing
    9997              :            in the rhs, otherwise those SAVE_EXPRs will have initialization
    9998              :            only in one of the two branches.  */
    9999          188 :         if (sanitize_flags_p (SANITIZE_UNDEFINED
   10000              :                               | SANITIZE_UNDEFINED_NONDEFAULT))
   10001            3 :           rhs = unshare_expr (rhs);
   10002          188 :         tree op2 = TREE_OPERAND (lhs, 2);
   10003          188 :         if (TREE_CODE (op2) != THROW_EXPR)
   10004          182 :           op2 = cp_build_modify_expr (loc, op2, modifycode, rhs, complain);
   10005          188 :         tree cond = build_conditional_expr (input_location,
   10006          188 :                                             TREE_OPERAND (lhs, 0), op1, op2,
   10007              :                                             complain);
   10008              : 
   10009          188 :         if (cond == error_mark_node)
   10010              :           return cond;
   10011              :         /* If we had (e, (a ? b : c)) = d; or (e, (f, (a ? b : c))) = d;
   10012              :            and looked through the COMPOUND_EXPRs, readd them now around
   10013              :            the resulting cond before adding the preevaluated rhs.  */
   10014          185 :         if (TREE_CODE (olhs) == COMPOUND_EXPR)
   10015              :           {
   10016           18 :             cond = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
   10017           18 :                            TREE_OPERAND (olhs, 0), cond);
   10018           18 :             tree *ptr = &TREE_OPERAND (cond, 1);
   10019           18 :             for (olhs = TREE_OPERAND (olhs, 1);
   10020           21 :                  TREE_CODE (olhs) == COMPOUND_EXPR;
   10021            3 :                  olhs = TREE_OPERAND (olhs, 1))
   10022              :               {
   10023            3 :                 *ptr = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
   10024            3 :                                TREE_OPERAND (olhs, 0), *ptr);
   10025            3 :                 ptr = &TREE_OPERAND (*ptr, 1);
   10026              :               }
   10027              :           }
   10028              :         /* Make sure the code to compute the rhs comes out
   10029              :            before the split.  */
   10030          185 :         result = cond;
   10031          185 :         goto ret;
   10032              :       }
   10033              : 
   10034              :     default:
   10035              :       lhs = olhs;
   10036              :       break;
   10037              :     }
   10038              : 
   10039     38716191 :   if (modifycode == INIT_EXPR)
   10040              :     {
   10041      4366059 :       if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
   10042              :         /* Do the default thing.  */;
   10043      4157203 :       else if (TREE_CODE (rhs) == CONSTRUCTOR)
   10044              :         {
   10045              :           /* Compound literal.  */
   10046           98 :           if (! same_type_p (TREE_TYPE (rhs), lhstype))
   10047              :             /* Call convert to generate an error; see PR 11063.  */
   10048            0 :             rhs = convert (lhstype, rhs);
   10049           98 :           result = cp_build_init_expr (lhs, rhs);
   10050           98 :           TREE_SIDE_EFFECTS (result) = 1;
   10051           98 :           goto ret;
   10052              :         }
   10053      4157105 :       else if (! MAYBE_CLASS_TYPE_P (lhstype))
   10054              :         /* Do the default thing.  */;
   10055              :       else
   10056              :         {
   10057        41718 :           releasing_vec rhs_vec = make_tree_vector_single (rhs);
   10058        41718 :           result = build_special_member_call (lhs, complete_ctor_identifier,
   10059              :                                               &rhs_vec, lhstype, LOOKUP_NORMAL,
   10060              :                                               complain);
   10061        41718 :           if (result == NULL_TREE)
   10062            0 :             return error_mark_node;
   10063        41718 :           goto ret;
   10064        41718 :         }
   10065              :     }
   10066              :   else
   10067              :     {
   10068     34350132 :       lhs = require_complete_type (lhs, complain);
   10069     34350132 :       if (lhs == error_mark_node)
   10070              :         return error_mark_node;
   10071              : 
   10072     34349966 :       if (modifycode == NOP_EXPR)
   10073              :         {
   10074     29533283 :           maybe_warn_self_move (loc, lhs, rhs);
   10075              : 
   10076     29533283 :           if (c_dialect_objc ())
   10077              :             {
   10078            0 :               result = objc_maybe_build_modify_expr (lhs, rhs);
   10079            0 :               if (result)
   10080            0 :                 goto ret;
   10081              :             }
   10082              : 
   10083              :           /* `operator=' is not an inheritable operator.  */
   10084     29533283 :           if (! MAYBE_CLASS_TYPE_P (lhstype))
   10085              :             /* Do the default thing.  */;
   10086              :           else
   10087              :             {
   10088      3576067 :               result = build_new_op (input_location, MODIFY_EXPR,
   10089              :                                      LOOKUP_NORMAL, lhs, rhs,
   10090              :                                      make_node (NOP_EXPR), NULL_TREE,
   10091              :                                      /*overload=*/NULL, complain);
   10092      3576067 :               if (result == NULL_TREE)
   10093            0 :                 return error_mark_node;
   10094      3576067 :               goto ret;
   10095              :             }
   10096              :           lhstype = olhstype;
   10097              :         }
   10098              :       else
   10099              :         {
   10100      4816683 :           tree init = NULL_TREE;
   10101              : 
   10102              :           /* A binary op has been requested.  Combine the old LHS
   10103              :              value with the RHS producing the value we should actually
   10104              :              store into the LHS.  */
   10105      4816683 :           gcc_assert (!((TYPE_REF_P (lhstype)
   10106              :                          && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype)))
   10107              :                         || MAYBE_CLASS_TYPE_P (lhstype)));
   10108              : 
   10109              :           /* Preevaluate the RHS to make sure its evaluation is complete
   10110              :              before the lvalue-to-rvalue conversion of the LHS:
   10111              : 
   10112              :              [expr.ass] With respect to an indeterminately-sequenced
   10113              :              function call, the operation of a compound assignment is a
   10114              :              single evaluation. [ Note: Therefore, a function call shall
   10115              :              not intervene between the lvalue-to-rvalue conversion and the
   10116              :              side effect associated with any single compound assignment
   10117              :              operator. -- end note ]  */
   10118      4816683 :           lhs = cp_stabilize_reference (lhs);
   10119      4816683 :           rhs = decay_conversion (rhs, complain);
   10120      4816683 :           if (rhs == error_mark_node)
   10121          123 :             return error_mark_node;
   10122              : 
   10123      4816680 :           {
   10124      4816680 :             auto_diagnostic_group d;
   10125      4816680 :             rhs = stabilize_expr (rhs, &init);
   10126      4816680 :             bool clear_decl_read = false;
   10127      4816680 :             tree stripped_lhs = tree_strip_any_location_wrapper (lhs);
   10128      1440579 :             if ((VAR_P (stripped_lhs) || TREE_CODE (stripped_lhs) == PARM_DECL)
   10129      4072140 :                 && !DECL_READ_P (stripped_lhs)
   10130      1057365 :                 && (VAR_P (stripped_lhs) ? warn_unused_but_set_variable
   10131              :                                          : warn_unused_but_set_parameter) > 2
   10132         7107 :                 && !CLASS_TYPE_P (TREE_TYPE (lhs))
   10133      4823787 :                 && !CLASS_TYPE_P (TREE_TYPE (rhs)))
   10134              :               {
   10135         7107 :                 mark_exp_read (rhs);
   10136         7107 :                 if (!DECL_READ_P (stripped_lhs))
   10137      4816680 :                   clear_decl_read = true;
   10138              :               }
   10139      4816680 :             newrhs = cp_build_binary_op (loc, modifycode, lhs, rhs, complain);
   10140      4816680 :             if (clear_decl_read)
   10141         7107 :               DECL_READ_P (stripped_lhs) = 0;
   10142      4816680 :             if (newrhs == error_mark_node)
   10143              :               {
   10144          120 :                 if (complain & tf_error)
   10145           24 :                   inform (loc, "  in evaluation of %<%Q(%#T, %#T)%>",
   10146           24 :                           modifycode, TREE_TYPE (lhs), TREE_TYPE (rhs));
   10147          120 :                 return error_mark_node;
   10148              :               }
   10149      4816680 :           }
   10150              : 
   10151      4816560 :           if (init)
   10152       295838 :             newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), init, newrhs);
   10153              : 
   10154              :           /* Now it looks like a plain assignment.  */
   10155      4816560 :           modifycode = NOP_EXPR;
   10156      4816560 :           if (c_dialect_objc ())
   10157              :             {
   10158            0 :               result = objc_maybe_build_modify_expr (lhs, newrhs);
   10159            0 :               if (result)
   10160            0 :                 goto ret;
   10161              :             }
   10162              :         }
   10163     30773776 :       gcc_assert (!TYPE_REF_P (lhstype));
   10164     30773776 :       gcc_assert (!TYPE_REF_P (TREE_TYPE (newrhs)));
   10165              :     }
   10166              : 
   10167              :   /* The left-hand side must be an lvalue.  */
   10168     35098019 :   if (!lvalue_or_else (lhs, lv_assign, complain))
   10169          839 :     return error_mark_node;
   10170              : 
   10171              :   /* Warn about modifying something that is `const'.  Don't warn if
   10172              :      this is initialization.  */
   10173     35097180 :   if (modifycode != INIT_EXPR
   10174     35097180 :       && (TREE_READONLY (lhs) || CP_TYPE_CONST_P (lhstype)
   10175              :           /* Functions are not modifiable, even though they are
   10176              :              lvalues.  */
   10177     30730799 :           || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (lhs))
   10178              :           /* If it's an aggregate and any field is const, then it is
   10179              :              effectively const.  */
   10180     30730721 :           || (CLASS_TYPE_P (lhstype)
   10181            0 :               && C_TYPE_FIELDS_READONLY (lhstype))))
   10182              :     {
   10183        42216 :       if (complain & tf_error)
   10184           89 :         cxx_readonly_error (loc, lhs, lv_assign);
   10185        42216 :       return error_mark_node;
   10186              :     }
   10187              : 
   10188              :   /* If storing into a structure or union member, it may have been given a
   10189              :      lowered bitfield type.  We need to convert to the declared type first,
   10190              :      so retrieve it now.  */
   10191              : 
   10192     35054964 :   olhstype = unlowered_expr_type (lhs);
   10193              : 
   10194              :   /* Convert new value to destination type.  */
   10195              : 
   10196     35054964 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
   10197              :     {
   10198          222 :       int from_array;
   10199              : 
   10200          222 :       if (BRACE_ENCLOSED_INITIALIZER_P (newrhs))
   10201              :         {
   10202           12 :           if (modifycode != INIT_EXPR)
   10203              :             {
   10204           12 :               if (complain & tf_error)
   10205           12 :                 error_at (loc,
   10206              :                           "assigning to an array from an initializer list");
   10207           12 :               return error_mark_node;
   10208              :             }
   10209            0 :           if (check_array_initializer (lhs, lhstype, newrhs))
   10210            0 :             return error_mark_node;
   10211            0 :           newrhs = digest_init (lhstype, newrhs, complain);
   10212            0 :           if (newrhs == error_mark_node)
   10213              :             return error_mark_node;
   10214              :         }
   10215              : 
   10216              :       /* C++11 8.5/17: "If the destination type is an array of characters,
   10217              :          an array of char16_t, an array of char32_t, or an array of wchar_t,
   10218              :          and the initializer is a string literal...".  */
   10219          210 :       else if ((TREE_CODE (tree_strip_any_location_wrapper (newrhs))
   10220              :                 == STRING_CST)
   10221           43 :                && char_type_p (TREE_TYPE (TYPE_MAIN_VARIANT (lhstype)))
   10222          253 :                && modifycode == INIT_EXPR)
   10223              :         {
   10224           28 :           newrhs = digest_init (lhstype, newrhs, complain);
   10225           28 :           if (newrhs == error_mark_node)
   10226              :             return error_mark_node;
   10227              :         }
   10228              : 
   10229          182 :       else if (!same_or_base_type_p (TYPE_MAIN_VARIANT (lhstype),
   10230              :                                      TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))))
   10231              :         {
   10232           27 :           if (complain & tf_error)
   10233           12 :             error_at (loc, "incompatible types in assignment of %qT to %qT",
   10234           12 :                       TREE_TYPE (rhs), lhstype);
   10235           27 :           return error_mark_node;
   10236              :         }
   10237              : 
   10238              :       /* Allow array assignment in compiler-generated code.  */
   10239          155 :       else if (DECL_P (lhs) && DECL_ARTIFICIAL (lhs))
   10240              :         /* OK, used by coroutines (co-await-initlist1.C).  */;
   10241          149 :       else if (!current_function_decl
   10242          149 :                || !DECL_DEFAULTED_FN (current_function_decl))
   10243              :         {
   10244              :           /* This routine is used for both initialization and assignment.
   10245              :              Make sure the diagnostic message differentiates the context.  */
   10246           99 :           if (complain & tf_error)
   10247              :             {
   10248           30 :               if (modifycode == INIT_EXPR)
   10249            9 :                 error_at (loc, "array used as initializer");
   10250              :               else
   10251           21 :                 error_at (loc, "invalid array assignment");
   10252              :             }
   10253           99 :           return error_mark_node;
   10254              :         }
   10255              : 
   10256          131 :       from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
   10257           84 :                    ? 1 + (modifycode != INIT_EXPR) : 0;
   10258           84 :       result = build_vec_init (lhs, NULL_TREE, newrhs,
   10259              :                                /*explicit_value_init_p=*/false,
   10260              :                                from_array, complain);
   10261           84 :       goto ret;
   10262              :     }
   10263              : 
   10264     35054742 :   if (modifycode == INIT_EXPR)
   10265              :     /* Calls with INIT_EXPR are all direct-initialization, so don't set
   10266              :        LOOKUP_ONLYCONVERTING.  */
   10267      4324184 :     newrhs = convert_for_initialization (lhs, olhstype, newrhs, LOOKUP_NORMAL,
   10268              :                                          ICR_INIT, NULL_TREE, 0,
   10269              :                                          complain | tf_no_cleanup);
   10270              :   else
   10271     30730558 :     newrhs = convert_for_assignment (olhstype, newrhs, ICR_ASSIGN,
   10272              :                                      NULL_TREE, 0, complain, LOOKUP_IMPLICIT);
   10273              : 
   10274     35054742 :   if (!same_type_p (lhstype, olhstype))
   10275       408118 :     newrhs = cp_convert_and_check (lhstype, newrhs, complain);
   10276              : 
   10277     35054742 :   if (modifycode != INIT_EXPR)
   10278              :     {
   10279     30730558 :       if (TREE_CODE (newrhs) == CALL_EXPR
   10280     30730558 :           && TYPE_NEEDS_CONSTRUCTING (lhstype))
   10281            0 :         newrhs = build_cplus_new (lhstype, newrhs, complain);
   10282              : 
   10283              :       /* Can't initialize directly from a TARGET_EXPR, since that would
   10284              :          cause the lhs to be constructed twice, and possibly result in
   10285              :          accidental self-initialization.  So we force the TARGET_EXPR to be
   10286              :          expanded without a target.  */
   10287     30730558 :       if (TREE_CODE (newrhs) == TARGET_EXPR)
   10288          118 :         newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), newrhs,
   10289          118 :                          TARGET_EXPR_SLOT (newrhs));
   10290              :     }
   10291              : 
   10292     35054742 :   if (newrhs == error_mark_node)
   10293              :     return error_mark_node;
   10294              : 
   10295     35054040 :   if (c_dialect_objc () && flag_objc_gc)
   10296              :     {
   10297            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
   10298              : 
   10299            0 :       if (result)
   10300            0 :         goto ret;
   10301              :     }
   10302              : 
   10303     39378175 :   result = build2_loc (loc, modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
   10304              :                        lhstype, lhs, newrhs);
   10305     35054040 :   if (modifycode == INIT_EXPR)
   10306      4324135 :     set_target_expr_eliding (newrhs);
   10307              : 
   10308     35054040 :   TREE_SIDE_EFFECTS (result) = 1;
   10309     35054040 :   if (!plain_assign)
   10310      9140665 :     suppress_warning (result, OPT_Wparentheses);
   10311              : 
   10312     25913375 :  ret:
   10313     38672192 :   if (preeval)
   10314           39 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), preeval, result);
   10315              :   return result;
   10316              : }
   10317              : 
   10318              : cp_expr
   10319     72175399 : build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
   10320              :                      tree rhs, tree lookups, tsubst_flags_t complain)
   10321              : {
   10322     72175399 :   tree orig_lhs = lhs;
   10323     72175399 :   tree orig_rhs = rhs;
   10324     72175399 :   tree overload = NULL_TREE;
   10325              : 
   10326     72175399 :   if (lhs == error_mark_node || rhs == error_mark_node)
   10327         2173 :     return cp_expr (error_mark_node, loc);
   10328              : 
   10329     72173226 :   tree op = build_min (modifycode, void_type_node, NULL_TREE, NULL_TREE);
   10330              : 
   10331     72173226 :   if (processing_template_decl)
   10332              :     {
   10333     50328706 :       if (type_dependent_expression_p (lhs)
   10334     50328706 :           || type_dependent_expression_p (rhs))
   10335              :         {
   10336     37653916 :           tree rval = build_min_nt_loc (loc, MODOP_EXPR, lhs, op, rhs);
   10337     37653916 :           if (modifycode != NOP_EXPR)
   10338      6370430 :             TREE_TYPE (rval)
   10339     12740860 :               = build_dependent_operator_type (lookups, modifycode, true);
   10340     37653916 :           return rval;
   10341              :         }
   10342              :     }
   10343              : 
   10344     34519310 :   tree rval;
   10345     34519310 :   if (modifycode == NOP_EXPR)
   10346     26748497 :     rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, complain);
   10347              :   else
   10348      7770813 :     rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
   10349              :                          lhs, rhs, op, lookups, &overload, complain);
   10350     34519310 :   if (rval == error_mark_node)
   10351         7257 :     return error_mark_node;
   10352     34512053 :   if (processing_template_decl)
   10353              :     {
   10354     12674769 :       if (overload != NULL_TREE)
   10355      1986623 :         return (build_min_non_dep_op_overload
   10356      1986623 :                 (MODIFY_EXPR, rval, overload, orig_lhs, orig_rhs));
   10357              : 
   10358     10688146 :       return (build_min_non_dep
   10359     10688146 :               (MODOP_EXPR, rval, orig_lhs, op, orig_rhs));
   10360              :     }
   10361     21837284 :   return rval;
   10362              : }
   10363              : 
   10364              : /* Helper function for get_delta_difference which assumes FROM is a base
   10365              :    class of TO.  Returns a delta for the conversion of pointer-to-member
   10366              :    of FROM to pointer-to-member of TO.  If the conversion is invalid and
   10367              :    tf_error is not set in COMPLAIN returns error_mark_node, otherwise
   10368              :    returns zero.  If FROM is not a base class of TO, returns NULL_TREE.
   10369              :    If C_CAST_P is true, this conversion is taking place as part of a
   10370              :    C-style cast.  */
   10371              : 
   10372              : static tree
   10373        29166 : get_delta_difference_1 (tree from, tree to, bool c_cast_p,
   10374              :                         tsubst_flags_t complain)
   10375              : {
   10376        29166 :   tree binfo;
   10377        29166 :   base_kind kind;
   10378              : 
   10379        58082 :   binfo = lookup_base (to, from, c_cast_p ? ba_unique : ba_check,
   10380              :                        &kind, complain);
   10381              : 
   10382        29166 :   if (binfo == error_mark_node)
   10383              :     {
   10384           51 :       if (!(complain & tf_error))
   10385              :         return error_mark_node;
   10386              : 
   10387           51 :       inform (input_location, "   in pointer to member function conversion");
   10388           51 :       return size_zero_node;
   10389              :     }
   10390        29115 :   else if (binfo)
   10391              :     {
   10392        28967 :       if (kind != bk_via_virtual)
   10393        28874 :         return BINFO_OFFSET (binfo);
   10394              :       else
   10395              :         /* FROM is a virtual base class of TO.  Issue an error or warning
   10396              :            depending on whether or not this is a reinterpret cast.  */
   10397              :         {
   10398           93 :           if (!(complain & tf_error))
   10399              :             return error_mark_node;
   10400              : 
   10401           78 :           error ("pointer to member conversion via virtual base %qT",
   10402           78 :                  BINFO_TYPE (binfo_from_vbase (binfo)));
   10403              : 
   10404           78 :           return size_zero_node;
   10405              :         }
   10406              :       }
   10407              :   else
   10408              :     return NULL_TREE;
   10409              : }
   10410              : 
   10411              : /* Get difference in deltas for different pointer to member function
   10412              :    types.  If the conversion is invalid and tf_error is not set in
   10413              :    COMPLAIN, returns error_mark_node, otherwise returns an integer
   10414              :    constant of type PTRDIFF_TYPE_NODE and its value is zero if the
   10415              :    conversion is invalid.  If ALLOW_INVERSE_P is true, then allow reverse
   10416              :    conversions as well.  If C_CAST_P is true this conversion is taking
   10417              :    place as part of a C-style cast.
   10418              : 
   10419              :    Note that the naming of FROM and TO is kind of backwards; the return
   10420              :    value is what we add to a TO in order to get a FROM.  They are named
   10421              :    this way because we call this function to find out how to convert from
   10422              :    a pointer to member of FROM to a pointer to member of TO.  */
   10423              : 
   10424              : static tree
   10425        91124 : get_delta_difference (tree from, tree to,
   10426              :                       bool allow_inverse_p,
   10427              :                       bool c_cast_p, tsubst_flags_t complain)
   10428              : {
   10429        91124 :   auto_diagnostic_group d;
   10430        91124 :   tree result;
   10431              : 
   10432        91124 :   if (same_type_ignoring_top_level_qualifiers_p (from, to))
   10433              :     /* Pointer to member of incomplete class is permitted*/
   10434        62106 :     result = size_zero_node;
   10435              :   else
   10436        29018 :     result = get_delta_difference_1 (from, to, c_cast_p, complain);
   10437              : 
   10438        91124 :   if (result == error_mark_node)
   10439              :     return error_mark_node;
   10440              : 
   10441        91109 :   if (!result)
   10442              :   {
   10443          148 :     if (!allow_inverse_p)
   10444              :       {
   10445            0 :         if (!(complain & tf_error))
   10446              :           return error_mark_node;
   10447              : 
   10448            0 :         error_not_base_type (from, to);
   10449            0 :         inform (input_location, "   in pointer to member conversion");
   10450            0 :         result = size_zero_node;
   10451              :       }
   10452              :     else
   10453              :       {
   10454          148 :         result = get_delta_difference_1 (to, from, c_cast_p, complain);
   10455              : 
   10456          148 :         if (result == error_mark_node)
   10457              :           return error_mark_node;
   10458              : 
   10459          148 :         if (result)
   10460          148 :           result = size_diffop_loc (input_location,
   10461              :                                     size_zero_node, result);
   10462              :         else
   10463              :           {
   10464            0 :             if (!(complain & tf_error))
   10465              :               return error_mark_node;
   10466              : 
   10467            0 :             error_not_base_type (from, to);
   10468            0 :             inform (input_location, "   in pointer to member conversion");
   10469            0 :             result = size_zero_node;
   10470              :           }
   10471              :       }
   10472              :   }
   10473              : 
   10474        91109 :   return convert_to_integer (ptrdiff_type_node, result);
   10475        91124 : }
   10476              : 
   10477              : /* Return a constructor for the pointer-to-member-function TYPE using
   10478              :    the other components as specified.  */
   10479              : 
   10480              : tree
   10481        62357 : build_ptrmemfunc1 (tree type, tree delta, tree pfn)
   10482              : {
   10483        62357 :   tree u = NULL_TREE;
   10484        62357 :   tree delta_field;
   10485        62357 :   tree pfn_field;
   10486        62357 :   vec<constructor_elt, va_gc> *v;
   10487              : 
   10488              :   /* Pull the FIELD_DECLs out of the type.  */
   10489        62357 :   pfn_field = TYPE_FIELDS (type);
   10490        62357 :   delta_field = DECL_CHAIN (pfn_field);
   10491              : 
   10492              :   /* Make sure DELTA has the type we want.  */
   10493        62357 :   delta = convert_and_check (input_location, delta_type_node, delta);
   10494              : 
   10495              :   /* Convert to the correct target type if necessary.  */
   10496        62357 :   pfn = fold_convert (TREE_TYPE (pfn_field), pfn);
   10497              : 
   10498              :   /* Finish creating the initializer.  */
   10499        62357 :   vec_alloc (v, 2);
   10500        62357 :   CONSTRUCTOR_APPEND_ELT(v, pfn_field, pfn);
   10501        62357 :   CONSTRUCTOR_APPEND_ELT(v, delta_field, delta);
   10502        62357 :   u = build_constructor (type, v);
   10503        62357 :   TREE_CONSTANT (u) = TREE_CONSTANT (pfn) & TREE_CONSTANT (delta);
   10504        62357 :   TREE_STATIC (u) = (TREE_CONSTANT (u)
   10505        62219 :                      && (initializer_constant_valid_p (pfn, TREE_TYPE (pfn))
   10506              :                          != NULL_TREE)
   10507       124576 :                      && (initializer_constant_valid_p (delta, TREE_TYPE (delta))
   10508              :                          != NULL_TREE));
   10509        62357 :   return u;
   10510              : }
   10511              : 
   10512              : /* Build a constructor for a pointer to member function.  It can be
   10513              :    used to initialize global variables, local variable, or used
   10514              :    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
   10515              :    want to be.
   10516              : 
   10517              :    If FORCE is nonzero, then force this conversion, even if
   10518              :    we would rather not do it.  Usually set when using an explicit
   10519              :    cast.  A C-style cast is being processed iff C_CAST_P is true.
   10520              : 
   10521              :    Return error_mark_node, if something goes wrong.  */
   10522              : 
   10523              : tree
   10524        30539 : build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p,
   10525              :                   tsubst_flags_t complain)
   10526              : {
   10527        30539 :   tree fn;
   10528        30539 :   tree pfn_type;
   10529        30539 :   tree to_type;
   10530              : 
   10531        30539 :   if (error_operand_p (pfn))
   10532            0 :     return error_mark_node;
   10533              : 
   10534        30539 :   pfn_type = TREE_TYPE (pfn);
   10535        30539 :   to_type = build_ptrmemfunc_type (type);
   10536              : 
   10537              :   /* Handle multiple conversions of pointer to member functions.  */
   10538        30539 :   if (TYPE_PTRMEMFUNC_P (pfn_type))
   10539              :     {
   10540        28733 :       tree delta = NULL_TREE;
   10541        28733 :       tree npfn = NULL_TREE;
   10542        28733 :       tree n;
   10543              : 
   10544        28733 :       if (!force
   10545        28733 :           && !can_convert_arg (to_type, TREE_TYPE (pfn), pfn,
   10546              :                                LOOKUP_NORMAL, complain))
   10547              :         {
   10548            0 :           if (complain & tf_error)
   10549            0 :             error ("invalid conversion to type %qT from type %qT",
   10550              :                    to_type, pfn_type);
   10551              :           else
   10552            0 :             return error_mark_node;
   10553              :         }
   10554              : 
   10555        28733 :       n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
   10556        28733 :                                 TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
   10557              :                                 force,
   10558              :                                 c_cast_p, complain);
   10559        28733 :       if (n == error_mark_node)
   10560              :         return error_mark_node;
   10561              : 
   10562        28724 :       STRIP_ANY_LOCATION_WRAPPER (pfn);
   10563              : 
   10564              :       /* We don't have to do any conversion to convert a
   10565              :          pointer-to-member to its own type.  But, we don't want to
   10566              :          just return a PTRMEM_CST if there's an explicit cast; that
   10567              :          cast should make the expression an invalid template argument.  */
   10568        28724 :       if (TREE_CODE (pfn) != PTRMEM_CST
   10569        28724 :           && same_type_p (to_type, pfn_type))
   10570              :         return pfn;
   10571              : 
   10572        28724 :       if (TREE_SIDE_EFFECTS (pfn))
   10573           18 :         pfn = save_expr (pfn);
   10574              : 
   10575              :       /* Obtain the function pointer and the current DELTA.  */
   10576        28724 :       if (TREE_CODE (pfn) == PTRMEM_CST)
   10577        28610 :         expand_ptrmemfunc_cst (pfn, &delta, &npfn);
   10578              :       else
   10579              :         {
   10580          114 :           npfn = build_ptrmemfunc_access_expr (pfn, pfn_identifier);
   10581          114 :           delta = build_ptrmemfunc_access_expr (pfn, delta_identifier);
   10582              :         }
   10583              : 
   10584              :       /* Just adjust the DELTA field.  */
   10585        28724 :       gcc_assert  (same_type_ignoring_top_level_qualifiers_p
   10586              :                    (TREE_TYPE (delta), ptrdiff_type_node));
   10587        28724 :       if (!integer_zerop (n))
   10588              :         {
   10589           56 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
   10590              :             n = cp_build_binary_op (input_location,
   10591              :                                     LSHIFT_EXPR, n, integer_one_node,
   10592              :                                     complain);
   10593           56 :           delta = cp_build_binary_op (input_location,
   10594              :                                       PLUS_EXPR, delta, n, complain);
   10595              :         }
   10596        28724 :       return build_ptrmemfunc1 (to_type, delta, npfn);
   10597              :     }
   10598              : 
   10599              :   /* Handle null pointer to member function conversions.  */
   10600         1806 :   if (null_ptr_cst_p (pfn))
   10601              :     {
   10602          674 :       pfn = cp_build_c_cast (input_location,
   10603          674 :                              TYPE_PTRMEMFUNC_FN_TYPE_RAW (to_type),
   10604              :                              pfn, complain);
   10605          674 :       return build_ptrmemfunc1 (to_type,
   10606              :                                 integer_zero_node,
   10607          674 :                                 pfn);
   10608              :     }
   10609              : 
   10610         1132 :   if (type_unknown_p (pfn))
   10611            0 :     return instantiate_type (type, pfn, complain);
   10612              : 
   10613         1132 :   fn = TREE_OPERAND (pfn, 0);
   10614         1132 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
   10615              :               /* In a template, we will have preserved the
   10616              :                  OFFSET_REF.  */
   10617              :               || (processing_template_decl && TREE_CODE (fn) == OFFSET_REF));
   10618         1132 :   return make_ptrmem_cst (to_type, fn);
   10619              : }
   10620              : 
   10621              : /* Return the DELTA, IDX, PFN, and DELTA2 values for the PTRMEM_CST
   10622              :    given by CST.
   10623              : 
   10624              :    ??? There is no consistency as to the types returned for the above
   10625              :    values.  Some code acts as if it were a sizetype and some as if it were
   10626              :    integer_type_node.  */
   10627              : 
   10628              : void
   10629        61973 : expand_ptrmemfunc_cst (tree cst, tree *delta, tree *pfn)
   10630              : {
   10631        61973 :   tree type = TREE_TYPE (cst);
   10632        61973 :   tree fn = PTRMEM_CST_MEMBER (cst);
   10633        61973 :   tree ptr_class, fn_class;
   10634              : 
   10635        61973 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
   10636              : 
   10637              :   /* The class that the function belongs to.  */
   10638        61973 :   fn_class = DECL_CONTEXT (fn);
   10639              : 
   10640              :   /* The class that we're creating a pointer to member of.  */
   10641        61973 :   ptr_class = TYPE_PTRMEMFUNC_OBJECT_TYPE (type);
   10642              : 
   10643              :   /* First, calculate the adjustment to the function's class.  */
   10644        61973 :   *delta = get_delta_difference (fn_class, ptr_class, /*force=*/0,
   10645              :                                  /*c_cast_p=*/0, tf_warning_or_error);
   10646              : 
   10647        61973 :   if (!DECL_VIRTUAL_P (fn))
   10648              :     {
   10649        60858 :       tree t = build_addr_func (fn, tf_warning_or_error);
   10650        60858 :       if (TREE_CODE (t) == ADDR_EXPR)
   10651        60858 :         SET_EXPR_LOCATION (t, PTRMEM_CST_LOCATION (cst));
   10652        60858 :       *pfn = convert (TYPE_PTRMEMFUNC_FN_TYPE (type), t);
   10653              :     }
   10654              :   else
   10655              :     {
   10656              :       /* If we're dealing with a virtual function, we have to adjust 'this'
   10657              :          again, to point to the base which provides the vtable entry for
   10658              :          fn; the call will do the opposite adjustment.  */
   10659         1115 :       tree orig_class = DECL_CONTEXT (fn);
   10660         1115 :       tree binfo = binfo_or_else (orig_class, fn_class);
   10661         1115 :       *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10662              :                             *delta, BINFO_OFFSET (binfo));
   10663              : 
   10664              :       /* We set PFN to the vtable offset at which the function can be
   10665              :          found, plus one (unless ptrmemfunc_vbit_in_delta, in which
   10666              :          case delta is shifted left, and then incremented).  */
   10667         1115 :       *pfn = DECL_VINDEX (fn);
   10668         1115 :       *pfn = fold_build2 (MULT_EXPR, integer_type_node, *pfn,
   10669              :                           TYPE_SIZE_UNIT (vtable_entry_type));
   10670              : 
   10671         1115 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
   10672              :         {
   10673         1115 :         case ptrmemfunc_vbit_in_pfn:
   10674         1115 :           *pfn = fold_build2 (PLUS_EXPR, integer_type_node, *pfn,
   10675              :                               integer_one_node);
   10676         1115 :           break;
   10677              : 
   10678              :         case ptrmemfunc_vbit_in_delta:
   10679              :           *delta = fold_build2 (LSHIFT_EXPR, TREE_TYPE (*delta),
   10680              :                                 *delta, integer_one_node);
   10681              :           *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10682              :                                 *delta, integer_one_node);
   10683              :           break;
   10684              : 
   10685              :         default:
   10686              :           gcc_unreachable ();
   10687              :         }
   10688              : 
   10689         1115 :       *pfn = fold_convert (TYPE_PTRMEMFUNC_FN_TYPE (type), *pfn);
   10690              :     }
   10691        61973 : }
   10692              : 
   10693              : /* Return an expression for PFN from the pointer-to-member function
   10694              :    given by T.  */
   10695              : 
   10696              : static tree
   10697        87375 : pfn_from_ptrmemfunc (tree t)
   10698              : {
   10699        87375 :   if (TREE_CODE (t) == PTRMEM_CST)
   10700              :     {
   10701          202 :       tree delta;
   10702          202 :       tree pfn;
   10703              : 
   10704          202 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10705          202 :       if (pfn)
   10706          202 :         return pfn;
   10707              :     }
   10708              : 
   10709        87173 :   return build_ptrmemfunc_access_expr (t, pfn_identifier);
   10710              : }
   10711              : 
   10712              : /* Return an expression for DELTA from the pointer-to-member function
   10713              :    given by T.  */
   10714              : 
   10715              : static tree
   10716        87375 : delta_from_ptrmemfunc (tree t)
   10717              : {
   10718        87375 :   if (TREE_CODE (t) == PTRMEM_CST)
   10719              :     {
   10720          202 :       tree delta;
   10721          202 :       tree pfn;
   10722              : 
   10723          202 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10724          202 :       if (delta)
   10725          202 :         return delta;
   10726              :     }
   10727              : 
   10728        87173 :   return build_ptrmemfunc_access_expr (t, delta_identifier);
   10729              : }
   10730              : 
   10731              : /* Convert value RHS to type TYPE as preparation for an assignment to
   10732              :    an lvalue of type TYPE.  ERRTYPE indicates what kind of error the
   10733              :    implicit conversion is.  If FNDECL is non-NULL, we are doing the
   10734              :    conversion in order to pass the PARMNUMth argument of FNDECL.
   10735              :    If FNDECL is NULL, we are doing the conversion in function pointer
   10736              :    argument passing, conversion in initialization, etc. */
   10737              : 
   10738              : static tree
   10739    185718576 : convert_for_assignment (tree type, tree rhs,
   10740              :                         impl_conv_rhs errtype, tree fndecl, int parmnum,
   10741              :                         tsubst_flags_t complain, int flags)
   10742              : {
   10743    185718576 :   tree rhstype;
   10744    185718576 :   enum tree_code coder;
   10745              : 
   10746    185718576 :   location_t rhs_loc = cp_expr_loc_or_input_loc (rhs);
   10747    185718576 :   bool has_loc = EXPR_LOCATION (rhs) != UNKNOWN_LOCATION;
   10748              :   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue,
   10749              :      but preserve location wrappers.  */
   10750    185718576 :   if (TREE_CODE (rhs) == NON_LVALUE_EXPR
   10751    185718576 :       && !location_wrapper_p (rhs))
   10752         8536 :     rhs = TREE_OPERAND (rhs, 0);
   10753              : 
   10754              :   /* Handle [dcl.init.list] direct-list-initialization from
   10755              :      single element of enumeration with a fixed underlying type.  */
   10756    185718576 :   if (is_direct_enum_init (type, rhs))
   10757              :     {
   10758           20 :       tree elt = CONSTRUCTOR_ELT (rhs, 0)->value;
   10759           20 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
   10760              :         {
   10761           11 :           warning_sentinel w (warn_useless_cast);
   10762           11 :           warning_sentinel w2 (warn_ignored_qualifiers);
   10763           11 :           rhs = cp_build_c_cast (rhs_loc, type, elt, complain);
   10764           11 :         }
   10765              :       else
   10766            9 :         rhs = error_mark_node;
   10767              :     }
   10768              : 
   10769    185718576 :   rhstype = TREE_TYPE (rhs);
   10770    185718576 :   coder = TREE_CODE (rhstype);
   10771              : 
   10772      1381154 :   if (VECTOR_TYPE_P (type) && coder == VECTOR_TYPE
   10773    187099624 :       && vector_types_convertible_p (type, rhstype, true))
   10774              :     {
   10775      1381039 :       rhs = mark_rvalue_use (rhs);
   10776      1381039 :       return convert (type, rhs);
   10777              :     }
   10778              : 
   10779    184337537 :   if (rhs == error_mark_node || rhstype == error_mark_node)
   10780              :     return error_mark_node;
   10781    184337528 :   if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
   10782              :     return error_mark_node;
   10783              : 
   10784              :   /* The RHS of an assignment cannot have void type.  */
   10785    184337528 :   if (coder == VOID_TYPE)
   10786              :     {
   10787           50 :       if (complain & tf_error)
   10788           30 :         error_at (rhs_loc, "void value not ignored as it ought to be");
   10789           50 :       return error_mark_node;
   10790              :     }
   10791              : 
   10792    184337478 :   if (c_dialect_objc ())
   10793              :     {
   10794            0 :       int parmno;
   10795            0 :       tree selector;
   10796            0 :       tree rname = fndecl;
   10797              : 
   10798            0 :       switch (errtype)
   10799              :         {
   10800              :           case ICR_ASSIGN:
   10801              :             parmno = -1;
   10802              :             break;
   10803            0 :           case ICR_INIT:
   10804            0 :             parmno = -2;
   10805            0 :             break;
   10806            0 :           default:
   10807            0 :             selector = objc_message_selector ();
   10808            0 :             parmno = parmnum;
   10809            0 :             if (selector && parmno > 1)
   10810              :               {
   10811            0 :                 rname = selector;
   10812            0 :                 parmno -= 1;
   10813              :               }
   10814              :         }
   10815              : 
   10816            0 :       if (objc_compare_types (type, rhstype, parmno, rname))
   10817              :         {
   10818            0 :           rhs = mark_rvalue_use (rhs);
   10819            0 :           return convert (type, rhs);
   10820              :         }
   10821              :     }
   10822              : 
   10823              :   /* [expr.ass]
   10824              : 
   10825              :      The expression is implicitly converted (clause _conv_) to the
   10826              :      cv-unqualified type of the left operand.
   10827              : 
   10828              :      We allow bad conversions here because by the time we get to this point
   10829              :      we are committed to doing the conversion.  If we end up doing a bad
   10830              :      conversion, convert_like will complain.  */
   10831    184337478 :   if (!can_convert_arg_bad (type, rhstype, rhs, flags, complain))
   10832              :     {
   10833              :       /* When -Wno-pmf-conversions is use, we just silently allow
   10834              :          conversions from pointers-to-members to plain pointers.  If
   10835              :          the conversion doesn't work, cp_convert will complain.  */
   10836         1640 :       if (!warn_pmf2ptr
   10837            9 :           && TYPE_PTR_P (type)
   10838         1649 :           && TYPE_PTRMEMFUNC_P (rhstype))
   10839            9 :         rhs = cp_convert (strip_top_quals (type), rhs, complain);
   10840              :       else
   10841              :         {
   10842         1631 :           if (complain & tf_error)
   10843              :             {
   10844         1316 :               auto_diagnostic_group d;
   10845              : 
   10846              :               /* If the right-hand side has unknown type, then it is an
   10847              :                  overloaded function.  Call instantiate_type to get error
   10848              :                  messages.  */
   10849         1316 :               if (rhstype == unknown_type_node)
   10850              :                 {
   10851          225 :                   tree r = instantiate_type (type, rhs, tf_warning_or_error);
   10852              :                   /* -fpermissive might allow this; recurse.  */
   10853          225 :                   if (!seen_error ())
   10854           15 :                     return convert_for_assignment (type, r, errtype, fndecl,
   10855              :                                                    parmnum, complain, flags);
   10856              :                 }
   10857         1091 :               else if (fndecl)
   10858           92 :                 complain_about_bad_argument (rhs_loc,
   10859              :                                              rhstype, type,
   10860              :                                              fndecl, parmnum);
   10861              :               else
   10862              :                 {
   10863          999 :                   range_label_for_type_mismatch label (rhstype, type);
   10864          999 :                   gcc_rich_location richloc
   10865              :                     (rhs_loc,
   10866              :                      has_loc ? &label : NULL,
   10867          999 :                      has_loc ? highlight_colors::percent_h : NULL);
   10868              : 
   10869          999 :                   switch (errtype)
   10870              :                     {
   10871            0 :                     case ICR_DEFAULT_ARGUMENT:
   10872            0 :                       error_at (&richloc,
   10873              :                                 "cannot convert %qH to %qI in default argument",
   10874              :                                 rhstype, type);
   10875            0 :                       break;
   10876            6 :                     case ICR_ARGPASS:
   10877            6 :                       error_at (&richloc,
   10878              :                                 "cannot convert %qH to %qI in argument passing",
   10879              :                                 rhstype, type);
   10880            6 :                       break;
   10881            0 :                     case ICR_CONVERTING:
   10882            0 :                       error_at (&richloc, "cannot convert %qH to %qI",
   10883              :                                 rhstype, type);
   10884            0 :                       break;
   10885          561 :                     case ICR_INIT:
   10886          561 :                       error_at (&richloc,
   10887              :                                 "cannot convert %qH to %qI in initialization",
   10888              :                                 rhstype, type);
   10889          561 :                       break;
   10890           18 :                     case ICR_RETURN:
   10891           18 :                       error_at (&richloc, "cannot convert %qH to %qI in return",
   10892              :                                 rhstype, type);
   10893           18 :                       break;
   10894          414 :                     case ICR_ASSIGN:
   10895          414 :                       error_at (&richloc,
   10896              :                                 "cannot convert %qH to %qI in assignment",
   10897              :                                 rhstype, type);
   10898          414 :                       break;
   10899            0 :                     default:
   10900            0 :                       gcc_unreachable();
   10901              :                   }
   10902          999 :                 }
   10903              : 
   10904              :               /* See if we can be more helpful.  */
   10905         1301 :               maybe_show_nonconverting_candidate (type, rhstype, rhs, flags);
   10906              : 
   10907         1301 :               if (TYPE_PTR_P (rhstype)
   10908          413 :                   && TYPE_PTR_P (type)
   10909          398 :                   && CLASS_TYPE_P (TREE_TYPE (rhstype))
   10910          280 :                   && CLASS_TYPE_P (TREE_TYPE (type))
   10911         1365 :                   && !COMPLETE_TYPE_P (TREE_TYPE (rhstype)))
   10912            3 :                 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL
   10913              :                                               (TREE_TYPE (rhstype))),
   10914            3 :                         "class type %qT is incomplete", TREE_TYPE (rhstype));
   10915         1316 :             }
   10916         1616 :           return error_mark_node;
   10917              :         }
   10918              :     }
   10919    184335847 :   if (warn_suggest_attribute_format)
   10920              :     {
   10921         2383 :       const enum tree_code codel = TREE_CODE (type);
   10922         2383 :       if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
   10923          596 :           && coder == codel
   10924          508 :           && check_missing_format_attribute (type, rhstype)
   10925         2401 :           && (complain & tf_warning))
   10926           18 :         switch (errtype)
   10927              :           {
   10928            0 :             case ICR_ARGPASS:
   10929            0 :             case ICR_DEFAULT_ARGUMENT:
   10930            0 :               if (fndecl)
   10931            0 :                 warning (OPT_Wsuggest_attribute_format,
   10932              :                          "parameter %qP of %qD might be a candidate "
   10933              :                          "for a format attribute", parmnum, fndecl);
   10934              :               else
   10935            0 :                 warning (OPT_Wsuggest_attribute_format,
   10936              :                          "parameter might be a candidate "
   10937              :                          "for a format attribute");
   10938              :               break;
   10939            0 :             case ICR_CONVERTING:
   10940            0 :               warning (OPT_Wsuggest_attribute_format,
   10941              :                        "target of conversion might be a candidate "
   10942              :                        "for a format attribute");
   10943            0 :               break;
   10944            6 :             case ICR_INIT:
   10945            6 :               warning (OPT_Wsuggest_attribute_format,
   10946              :                        "target of initialization might be a candidate "
   10947              :                        "for a format attribute");
   10948            6 :               break;
   10949            6 :             case ICR_RETURN:
   10950            6 :               warning (OPT_Wsuggest_attribute_format,
   10951              :                        "return type might be a candidate "
   10952              :                        "for a format attribute");
   10953            6 :               break;
   10954            6 :             case ICR_ASSIGN:
   10955            6 :               warning (OPT_Wsuggest_attribute_format,
   10956              :                        "left-hand side of assignment might be a candidate "
   10957              :                        "for a format attribute");
   10958            6 :               break;
   10959            0 :             default:
   10960            0 :               gcc_unreachable();
   10961              :           }
   10962              :     }
   10963              : 
   10964    184335847 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
   10965     38000522 :     maybe_warn_unparenthesized_assignment (rhs, /*nested_p=*/true, complain);
   10966              : 
   10967    184335847 :   if (complain & tf_warning)
   10968    181728982 :     warn_for_address_of_packed_member (type, rhs);
   10969              : 
   10970    184335847 :   return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
   10971    184335847 :                                             complain, flags);
   10972              : }
   10973              : 
   10974              : /* Convert RHS to be of type TYPE.
   10975              :    If EXP is nonzero, it is the target of the initialization.
   10976              :    ERRTYPE indicates what kind of error the implicit conversion is.
   10977              : 
   10978              :    Two major differences between the behavior of
   10979              :    `convert_for_assignment' and `convert_for_initialization'
   10980              :    are that references are bashed in the former, while
   10981              :    copied in the latter, and aggregates are assigned in
   10982              :    the former (operator=) while initialized in the
   10983              :    latter (X(X&)).
   10984              : 
   10985              :    If using constructor make sure no conversion operator exists, if one does
   10986              :    exist, an ambiguity exists.  */
   10987              : 
   10988              : tree
   10989    171544045 : convert_for_initialization (tree exp, tree type, tree rhs, int flags,
   10990              :                             impl_conv_rhs errtype, tree fndecl, int parmnum,
   10991              :                             tsubst_flags_t complain)
   10992              : {
   10993    171544045 :   enum tree_code codel = TREE_CODE (type);
   10994    171544045 :   tree rhstype;
   10995    171544045 :   enum tree_code coder;
   10996              : 
   10997              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
   10998              :      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
   10999    171544045 :   if (TREE_CODE (rhs) == NOP_EXPR
   11000      6015444 :       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
   11001    172041954 :       && codel != REFERENCE_TYPE)
   11002       497909 :     rhs = TREE_OPERAND (rhs, 0);
   11003              : 
   11004    171544045 :   if (type == error_mark_node
   11005    171544002 :       || rhs == error_mark_node
   11006    343087978 :       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
   11007              :     return error_mark_node;
   11008              : 
   11009    171543933 :   if (MAYBE_CLASS_TYPE_P (non_reference (type)))
   11010              :     ;
   11011    156976053 :   else if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
   11012      2378078 :             && TREE_CODE (type) != ARRAY_TYPE
   11013      2378078 :             && (!TYPE_REF_P (type)
   11014         1167 :                 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
   11015    154599139 :            || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
   11016        26296 :                && !TYPE_REFFN_P (type))
   11017    311550109 :            || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
   11018      2402003 :     rhs = decay_conversion (rhs, complain);
   11019              : 
   11020    171543933 :   rhstype = TREE_TYPE (rhs);
   11021    171543933 :   coder = TREE_CODE (rhstype);
   11022              : 
   11023    171543933 :   if (coder == ERROR_MARK)
   11024            9 :     return error_mark_node;
   11025              : 
   11026              :   /* We accept references to incomplete types, so we can
   11027              :      return here before checking if RHS is of complete type.  */
   11028              : 
   11029    171543924 :   if (codel == REFERENCE_TYPE)
   11030              :     {
   11031      6117721 :       auto_diagnostic_group d;
   11032              :       /* This should eventually happen in convert_arguments.  */
   11033      6117721 :       int savew = 0, savee = 0;
   11034              : 
   11035      6117721 :       if (fndecl)
   11036       300710 :         savew = warningcount + werrorcount, savee = errorcount;
   11037      6117721 :       rhs = initialize_reference (type, rhs, flags, complain);
   11038              : 
   11039      6117721 :       if (fndecl
   11040      6117721 :           && (warningcount + werrorcount > savew || errorcount > savee))
   11041           36 :         inform (get_fndecl_argument_location (fndecl, parmnum),
   11042              :                 "in passing argument %P of %qD", parmnum, fndecl);
   11043      6117721 :       return rhs;
   11044      6117721 :     }
   11045              : 
   11046    165426203 :   if (exp != 0)
   11047      4324184 :     exp = require_complete_type (exp, complain);
   11048    165426203 :   if (exp == error_mark_node)
   11049              :     return error_mark_node;
   11050              : 
   11051    165426203 :   type = complete_type (type);
   11052              : 
   11053    165426203 :   if (DIRECT_INIT_EXPR_P (type, rhs))
   11054              :     /* Don't try to do copy-initialization if we already have
   11055              :        direct-initialization.  */
   11056              :     return rhs;
   11057              : 
   11058    165424776 :   if (MAYBE_CLASS_TYPE_P (type))
   11059     10436773 :     return perform_implicit_conversion_flags (type, rhs, complain, flags);
   11060              : 
   11061    154988003 :   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum,
   11062    154988003 :                                  complain, flags);
   11063              : }
   11064              : 
   11065              : /* If RETVAL is the address of, or a reference to, a local variable or
   11066              :    temporary give an appropriate warning and return true.  */
   11067              : 
   11068              : static bool
   11069     44237707 : maybe_warn_about_returning_address_of_local (tree retval, location_t loc)
   11070              : {
   11071     44238734 :   tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
   11072     44238734 :   tree whats_returned = fold_for_warn (retval);
   11073     44238734 :   if (!loc)
   11074     44238734 :     loc = cp_expr_loc_or_input_loc (retval);
   11075              : 
   11076     53902309 :   for (;;)
   11077              :     {
   11078     53902309 :       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
   11079       790650 :         whats_returned = TREE_OPERAND (whats_returned, 1);
   11080     53111659 :       else if (CONVERT_EXPR_P (whats_returned)
   11081     44256653 :                || TREE_CODE (whats_returned) == NON_LVALUE_EXPR)
   11082      8872925 :         whats_returned = TREE_OPERAND (whats_returned, 0);
   11083              :       else
   11084              :         break;
   11085              :     }
   11086              : 
   11087     44238734 :   if (TREE_CODE (whats_returned) == TARGET_EXPR
   11088     44238734 :       && is_std_init_list (TREE_TYPE (whats_returned)))
   11089              :     {
   11090           16 :       tree init = TARGET_EXPR_INITIAL (whats_returned);
   11091           16 :       if (TREE_CODE (init) == CONSTRUCTOR)
   11092              :         /* Pull out the array address.  */
   11093            7 :         whats_returned = CONSTRUCTOR_ELT (init, 0)->value;
   11094            9 :       else if (TREE_CODE (init) == INDIRECT_REF)
   11095              :         /* The source of a trivial copy looks like *(T*)&var.  */
   11096            6 :         whats_returned = TREE_OPERAND (init, 0);
   11097              :       else
   11098              :         return false;
   11099           13 :       STRIP_NOPS (whats_returned);
   11100              :     }
   11101              : 
   11102              :   /* As a special case, we handle a call to std::move or std::forward.  */
   11103     44238731 :   if (TREE_CODE (whats_returned) == CALL_EXPR
   11104     44238731 :       && (is_std_move_p (whats_returned)
   11105     10526806 :           || is_std_forward_p (whats_returned)))
   11106              :     {
   11107         1015 :       tree arg = CALL_EXPR_ARG (whats_returned, 0);
   11108         1015 :       return maybe_warn_about_returning_address_of_local (arg, loc);
   11109              :     }
   11110              : 
   11111     44237716 :   if (TREE_CODE (whats_returned) != ADDR_EXPR)
   11112              :     return false;
   11113       929605 :   whats_returned = TREE_OPERAND (whats_returned, 0);
   11114              : 
   11115       929605 :   while (TREE_CODE (whats_returned) == COMPONENT_REF
   11116      1805415 :          || TREE_CODE (whats_returned) == ARRAY_REF)
   11117       875810 :     whats_returned = TREE_OPERAND (whats_returned, 0);
   11118              : 
   11119       929605 :   if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR
   11120       929605 :       || TREE_CODE (whats_returned) == TARGET_EXPR)
   11121              :     {
   11122           50 :       if (TYPE_REF_P (valtype))
   11123              :         /* P2748 made this an error in C++26.  */
   11124           72 :         emit_diagnostic ((cxx_dialect >= cxx26
   11125              :                           ? diagnostics::kind::permerror
   11126              :                           : diagnostics::kind::warning),
   11127           41 :                          loc, OPT_Wreturn_local_addr,
   11128              :                          "returning reference to temporary");
   11129            9 :       else if (TYPE_PTR_P (valtype))
   11130            3 :         warning_at (loc, OPT_Wreturn_local_addr,
   11131              :                     "returning pointer to temporary");
   11132            6 :       else if (is_std_init_list (valtype))
   11133            6 :         warning_at (loc, OPT_Winit_list_lifetime,
   11134              :                     "returning temporary %<initializer_list%> does not extend "
   11135              :                     "the lifetime of the underlying array");
   11136              :       return true;
   11137              :     }
   11138              : 
   11139       929555 :   STRIP_ANY_LOCATION_WRAPPER (whats_returned);
   11140              : 
   11141       929555 :   if (DECL_P (whats_returned)
   11142       120146 :       && DECL_NAME (whats_returned)
   11143       120146 :       && DECL_FUNCTION_SCOPE_P (whats_returned)
   11144        12490 :       && !is_capture_proxy (whats_returned)
   11145       942015 :       && !(TREE_STATIC (whats_returned)
   11146          155 :            || TREE_PUBLIC (whats_returned)))
   11147              :     {
   11148          108 :       if (DECL_DECOMPOSITION_P (whats_returned)
   11149           39 :           && !DECL_DECOMP_IS_BASE (whats_returned)
   11150          194 :           && DECL_HAS_VALUE_EXPR_P (whats_returned))
   11151              :         {
   11152              :           /* When returning address of a structured binding, if the structured
   11153              :              binding is not a reference, continue normally, if it is a
   11154              :              reference, recurse on the initializer of the structured
   11155              :              binding.  */
   11156           39 :           tree base = DECL_DECOMP_BASE (whats_returned);
   11157           39 :           if (TYPE_REF_P (TREE_TYPE (base)))
   11158              :             {
   11159           15 :               if (tree init = DECL_INITIAL (base))
   11160              :                 return maybe_warn_about_returning_address_of_local (init, loc);
   11161              :               else
   11162              :                 return false;
   11163              :             }
   11164              :         }
   11165          140 :       bool w = false;
   11166          140 :       auto_diagnostic_group d;
   11167          140 :       if (TYPE_REF_P (valtype))
   11168           89 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11169              :                         "reference to local variable %qD returned",
   11170              :                         whats_returned);
   11171           51 :       else if (is_std_init_list (valtype))
   11172            3 :         w = warning_at (loc, OPT_Winit_list_lifetime,
   11173              :                         "returning local %<initializer_list%> variable %qD "
   11174              :                         "does not extend the lifetime of the underlying array",
   11175              :                         whats_returned);
   11176           48 :       else if (POINTER_TYPE_P (valtype)
   11177           42 :                && TREE_CODE (whats_returned) == LABEL_DECL)
   11178            6 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11179              :                         "address of label %qD returned",
   11180              :                         whats_returned);
   11181           42 :       else if (POINTER_TYPE_P (valtype))
   11182           36 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11183              :                         "address of local variable %qD returned",
   11184              :                         whats_returned);
   11185          134 :       if (w)
   11186          111 :         inform (DECL_SOURCE_LOCATION (whats_returned),
   11187              :                 "declared here");
   11188          140 :       return true;
   11189          140 :     }
   11190              : 
   11191              :   return false;
   11192              : }
   11193              : 
   11194              : /* Returns true if DECL is in the std namespace.  */
   11195              : 
   11196              : bool
   11197     89128708 : decl_in_std_namespace_p (tree decl)
   11198              : {
   11199    103526468 :   while (decl)
   11200              :     {
   11201    103104132 :       decl = decl_namespace_context (decl);
   11202    103104132 :       if (DECL_NAMESPACE_STD_P (decl))
   11203              :         return true;
   11204              :       /* Allow inline namespaces inside of std namespace, e.g. with
   11205              :          --enable-symvers=gnu-versioned-namespace std::forward would be
   11206              :          actually std::_8::forward.  */
   11207     49041265 :       if (!DECL_NAMESPACE_INLINE_P (decl))
   11208              :         return false;
   11209     14397760 :       decl = CP_DECL_CONTEXT (decl);
   11210              :     }
   11211              :   return false;
   11212              : }
   11213              : 
   11214              : /* Returns true if FN, a CALL_EXPR, is a call to std::forward.  */
   11215              : 
   11216              : static bool
   11217     10526806 : is_std_forward_p (tree fn)
   11218              : {
   11219              :   /* std::forward only takes one argument.  */
   11220     10526806 :   if (call_expr_nargs (fn) != 1)
   11221              :     return false;
   11222              : 
   11223      4879260 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   11224      4879260 :   if (!decl_in_std_namespace_p (fndecl))
   11225              :     return false;
   11226              : 
   11227      1835413 :   tree name = DECL_NAME (fndecl);
   11228      1835413 :   return name && id_equal (name, "forward");
   11229              : }
   11230              : 
   11231              : /* Returns true if FN, a CALL_EXPR, is a call to std::move.  */
   11232              : 
   11233              : static bool
   11234     10534454 : is_std_move_p (tree fn)
   11235              : {
   11236              :   /* std::move only takes one argument.  */
   11237     10534454 :   if (call_expr_nargs (fn) != 1)
   11238              :     return false;
   11239              : 
   11240      4886129 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   11241      4886129 :   if (!decl_in_std_namespace_p (fndecl))
   11242              :     return false;
   11243              : 
   11244      1841798 :   tree name = DECL_NAME (fndecl);
   11245      1841798 :   return name && id_equal (name, "move");
   11246              : }
   11247              : 
   11248              : /* Returns true if RETVAL is a good candidate for the NRVO as per
   11249              :    [class.copy.elision].  FUNCTYPE is the type the function is declared
   11250              :    to return.  */
   11251              : 
   11252              : static bool
   11253     57215723 : can_do_nrvo_p (tree retval, tree functype)
   11254              : {
   11255     57215723 :   if (functype == error_mark_node)
   11256              :     return false;
   11257     57215677 :   if (retval)
   11258     55500219 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   11259     57215677 :   tree result = DECL_RESULT (current_function_decl);
   11260     57215677 :   return (retval != NULL_TREE
   11261     55500219 :           && !processing_template_decl
   11262              :           /* Must be a local, automatic variable.  */
   11263     45749298 :           && VAR_P (retval)
   11264      4010408 :           && DECL_CONTEXT (retval) == current_function_decl
   11265      2932191 :           && !TREE_STATIC (retval)
   11266              :           /* And not a lambda or anonymous union proxy.  */
   11267      2929250 :           && !DECL_HAS_VALUE_EXPR_P (retval)
   11268      2928984 :           && (DECL_ALIGN (retval) <= DECL_ALIGN (result))
   11269              :           /* The cv-unqualified type of the returned value must be the
   11270              :              same as the cv-unqualified return type of the
   11271              :              function.  */
   11272      2928861 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   11273              :                           TYPE_MAIN_VARIANT (functype))
   11274              :           /* And the returned value must be non-volatile.  */
   11275     60120829 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   11276              : }
   11277              : 
   11278              : /* True if we would like to perform NRVO, i.e. can_do_nrvo_p is true and we
   11279              :    would otherwise return in memory.  */
   11280              : 
   11281              : static bool
   11282     57215353 : want_nrvo_p (tree retval, tree functype)
   11283              : {
   11284     57215353 :   return (can_do_nrvo_p (retval, functype)
   11285     57215353 :           && aggregate_value_p (functype, current_function_decl));
   11286              : }
   11287              : 
   11288              : /* Like can_do_nrvo_p, but we check if we're trying to move a class
   11289              :    prvalue.  */
   11290              : 
   11291              : static bool
   11292         1441 : can_elide_copy_prvalue_p (tree retval, tree functype)
   11293              : {
   11294         1441 :   if (functype == error_mark_node)
   11295              :     return false;
   11296         1441 :   if (retval)
   11297         1441 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   11298         1441 :   return (retval != NULL_TREE
   11299         1441 :           && !glvalue_p (retval)
   11300          135 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   11301              :                           TYPE_MAIN_VARIANT (functype))
   11302         1549 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   11303              : }
   11304              : 
   11305              : /* If we should treat RETVAL, an expression being returned, as if it were
   11306              :    designated by an rvalue, returns it adjusted accordingly; otherwise, returns
   11307              :    NULL_TREE.  See [class.copy.elision].  RETURN_P is true if this is a return
   11308              :    context (rather than throw).  */
   11309              : 
   11310              : tree
   11311     11638149 : treat_lvalue_as_rvalue_p (tree expr, bool return_p)
   11312              : {
   11313     11638149 :   if (cxx_dialect == cxx98)
   11314              :     return NULL_TREE;
   11315              : 
   11316     11628696 :   tree retval = expr;
   11317     11628696 :   STRIP_ANY_LOCATION_WRAPPER (retval);
   11318     11628696 :   if (REFERENCE_REF_P (retval))
   11319       582150 :     retval = TREE_OPERAND (retval, 0);
   11320              : 
   11321              :   /* An implicitly movable entity is a variable of automatic storage duration
   11322              :      that is either a non-volatile object or (C++20) an rvalue reference to a
   11323              :      non-volatile object type.  */
   11324     11628696 :   if (!(((VAR_P (retval) && !DECL_HAS_VALUE_EXPR_P (retval))
   11325     10341774 :          || TREE_CODE (retval) == PARM_DECL)
   11326      1859968 :         && !TREE_STATIC (retval)
   11327      1764996 :         && !CP_TYPE_VOLATILE_P (non_reference (TREE_TYPE (retval)))
   11328      1764991 :         && (TREE_CODE (TREE_TYPE (retval)) != REFERENCE_TYPE
   11329       128552 :             || (cxx_dialect >= cxx20
   11330       128004 :                 && TYPE_REF_IS_RVALUE (TREE_TYPE (retval))))))
   11331              :     return NULL_TREE;
   11332              : 
   11333              :   /* If the expression in a return or co_return statement is a (possibly
   11334              :      parenthesized) id-expression that names an implicitly movable entity
   11335              :      declared in the body or parameter-declaration-clause of the innermost
   11336              :      enclosing function or lambda-expression, */
   11337      1637286 :   if (return_p)
   11338              :     {
   11339      1627780 :       if (DECL_CONTEXT (retval) != current_function_decl)
   11340              :         return NULL_TREE;
   11341      1627713 :       expr = move (expr);
   11342      1627713 :       if (expr == error_mark_node)
   11343              :         return NULL_TREE;
   11344      1627711 :       return set_implicit_rvalue_p (expr);
   11345              :     }
   11346              : 
   11347              :   /* if the id-expression (possibly parenthesized) is the operand of
   11348              :      a throw-expression, and names an implicitly movable entity that belongs
   11349              :      to a scope that does not contain the compound-statement of the innermost
   11350              :      lambda-expression, try-block, or function-try-block (if any) whose
   11351              :      compound-statement or ctor-initializer contains the throw-expression.  */
   11352              : 
   11353              :   /* C++20 added move on throw of parms.  */
   11354         9506 :   if (TREE_CODE (retval) == PARM_DECL && cxx_dialect < cxx20)
   11355              :     return NULL_TREE;
   11356              : 
   11357              :   /* We don't check for lambda-expression here, because we should not get past
   11358              :      the DECL_HAS_VALUE_EXPR_P check above.  */
   11359         9490 :   for (cp_binding_level *b = current_binding_level;
   11360         9586 :        b->kind != sk_namespace; b = b->level_chain)
   11361              :     {
   11362         9584 :       for (tree decl = b->names; decl; decl = TREE_CHAIN (decl))
   11363          103 :         if (decl == retval)
   11364           91 :           return set_implicit_rvalue_p (move (expr));
   11365         9481 :       if (b->kind == sk_try)
   11366              :         return NULL_TREE;
   11367              :     }
   11368              : 
   11369           14 :   return set_implicit_rvalue_p (move (expr));
   11370              : }
   11371              : 
   11372              : /* Warn about dubious usage of std::move (in a return statement, if RETURN_P
   11373              :    is true).  EXPR is the std::move expression; TYPE is the type of the object
   11374              :    being initialized.  */
   11375              : 
   11376              : void
   11377    157704556 : maybe_warn_pessimizing_move (tree expr, tree type, bool return_p)
   11378              : {
   11379    157704556 :   if (!(warn_pessimizing_move || warn_redundant_move))
   11380              :     return;
   11381              : 
   11382      4624931 :   const location_t loc = cp_expr_loc_or_input_loc (expr);
   11383              : 
   11384              :   /* C++98 doesn't know move.  */
   11385      4624931 :   if (cxx_dialect < cxx11)
   11386              :     return;
   11387              : 
   11388              :   /* Wait until instantiation time, since we can't gauge if we should do
   11389              :      the NRVO until then.  */
   11390      4562270 :   if (processing_template_decl)
   11391              :     return;
   11392              : 
   11393              :   /* This is only interesting for class types.  */
   11394      4473353 :   if (!CLASS_TYPE_P (type))
   11395              :     return;
   11396              : 
   11397       112321 :   bool wrapped_p = false;
   11398              :   /* A a = std::move (A());  */
   11399       112321 :   if (TREE_CODE (expr) == TREE_LIST)
   11400              :     {
   11401         8960 :       if (list_length (expr) == 1)
   11402              :         {
   11403         5979 :           expr = TREE_VALUE (expr);
   11404         5979 :           wrapped_p = true;
   11405              :         }
   11406              :       else
   11407              :         return;
   11408              :     }
   11409              :   /* A a = {std::move (A())};
   11410              :      A a{std::move (A())};  */
   11411       103361 :   else if (TREE_CODE (expr) == CONSTRUCTOR)
   11412              :     {
   11413         7935 :       if (CONSTRUCTOR_NELTS (expr) == 1)
   11414              :         {
   11415          887 :           expr = CONSTRUCTOR_ELT (expr, 0)->value;
   11416          887 :           wrapped_p = true;
   11417              :         }
   11418              :       else
   11419              :         return;
   11420              :     }
   11421              : 
   11422              :   /* First, check if this is a call to std::move.  */
   11423         6827 :   if (!REFERENCE_REF_P (expr)
   11424       107098 :       || TREE_CODE (TREE_OPERAND (expr, 0)) != CALL_EXPR)
   11425              :     return;
   11426         2710 :   tree fn = TREE_OPERAND (expr, 0);
   11427         2710 :   if (!is_std_move_p (fn))
   11428              :     return;
   11429         2084 :   tree arg = CALL_EXPR_ARG (fn, 0);
   11430         2084 :   if (TREE_CODE (arg) != NOP_EXPR)
   11431              :     return;
   11432              :   /* If we're looking at *std::move<T&> ((T &) &arg), do the pessimizing N/RVO
   11433              :      and implicitly-movable warnings.  */
   11434         2084 :   if (TREE_CODE (TREE_OPERAND (arg, 0)) == ADDR_EXPR)
   11435              :     {
   11436         1441 :       arg = TREE_OPERAND (arg, 0);
   11437         1441 :       arg = TREE_OPERAND (arg, 0);
   11438         1441 :       arg = convert_from_reference (arg);
   11439         1441 :       if (can_elide_copy_prvalue_p (arg, type))
   11440              :         {
   11441          108 :           auto_diagnostic_group d;
   11442          108 :           if (warning_at (loc, OPT_Wpessimizing_move,
   11443              :                           "moving a temporary object prevents copy elision"))
   11444          108 :             inform (loc, "remove %<std::move%> call");
   11445          108 :         }
   11446              :       /* The rest of the warnings is only relevant for when we are returning
   11447              :          from a function.  */
   11448         1441 :       if (!return_p)
   11449              :         return;
   11450              : 
   11451          370 :       tree moved;
   11452              :       /* Warn if we could do copy elision were it not for the move.  */
   11453          370 :       if (can_do_nrvo_p (arg, type))
   11454              :         {
   11455           48 :           auto_diagnostic_group d;
   11456           48 :           if (!warning_suppressed_p (expr, OPT_Wpessimizing_move)
   11457           48 :               && warning_at (loc, OPT_Wpessimizing_move,
   11458              :                              "moving a local object in a return statement "
   11459              :                              "prevents copy elision"))
   11460           42 :             inform (loc, "remove %<std::move%> call");
   11461           48 :         }
   11462              :       /* Warn if the move is redundant.  It is redundant when we would
   11463              :          do maybe-rvalue overload resolution even without std::move.  */
   11464          322 :       else if (warn_redundant_move
   11465              :                /* This doesn't apply for return {std::move (t)};.  */
   11466          224 :                && !wrapped_p
   11467          221 :                && !warning_suppressed_p (expr, OPT_Wredundant_move)
   11468          418 :                && (moved = treat_lvalue_as_rvalue_p (arg, /*return*/true)))
   11469              :         {
   11470              :           /* Make sure that overload resolution would actually succeed
   11471              :              if we removed the std::move call.  */
   11472           54 :           tree t = convert_for_initialization (NULL_TREE, type,
   11473              :                                                moved,
   11474              :                                                (LOOKUP_NORMAL
   11475              :                                                 | LOOKUP_ONLYCONVERTING),
   11476              :                                                ICR_RETURN, NULL_TREE, 0,
   11477              :                                                tf_none);
   11478              :           /* If this worked, implicit rvalue would work, so the call to
   11479              :              std::move is redundant.  */
   11480           54 :           if (t != error_mark_node)
   11481              :             {
   11482           54 :               auto_diagnostic_group d;
   11483           54 :               if (warning_at (loc, OPT_Wredundant_move,
   11484              :                               "redundant move in return statement"))
   11485           54 :                 inform (loc, "remove %<std::move%> call");
   11486           54 :             }
   11487              :         }
   11488              :      }
   11489              :   /* Also try to warn about redundant std::move in code such as
   11490              :       T f (const T& t)
   11491              :       {
   11492              :         return std::move(t);
   11493              :       }
   11494              :     for which EXPR will be something like
   11495              :       *std::move<const T&> ((const struct T &) (const struct T *) t)
   11496              :      and where the std::move does nothing if T does not have a T(const T&&)
   11497              :      constructor, because the argument is const.  It will not use T(T&&)
   11498              :      because that would mean losing the const.  */
   11499          643 :   else if (warn_redundant_move
   11500          521 :            && !warning_suppressed_p (expr, OPT_Wredundant_move)
   11501           66 :            && TYPE_REF_P (TREE_TYPE (arg))
   11502          709 :            && CP_TYPE_CONST_P (TREE_TYPE (TREE_TYPE (arg))))
   11503              :     {
   11504           18 :       tree rtype = TREE_TYPE (TREE_TYPE (arg));
   11505           18 :       if (!same_type_ignoring_top_level_qualifiers_p (rtype, type))
   11506            9 :         return;
   11507              :       /* Check for the unlikely case there's T(const T&&) (we don't care if
   11508              :          it's deleted).  */
   11509           54 :       for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (rtype)))
   11510           30 :         if (move_fn_p (fn))
   11511              :           {
   11512           15 :             tree t = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (fn));
   11513           15 :             if (UNLIKELY (CP_TYPE_CONST_P (TREE_TYPE (t))))
   11514            6 :               return;
   11515              :           }
   11516            9 :       auto_diagnostic_group d;
   11517           18 :       if (return_p
   11518            9 :           ? warning_at (loc, OPT_Wredundant_move,
   11519              :                         "redundant move in return statement")
   11520            9 :           : warning_at (loc, OPT_Wredundant_move,
   11521              :                         "redundant move in initialization"))
   11522            9 :         inform (loc, "remove %<std::move%> call");
   11523            9 :     }
   11524              : }
   11525              : 
   11526              : /* Check that returning RETVAL from the current function is valid.
   11527              :    Return an expression explicitly showing all conversions required to
   11528              :    change RETVAL into the function return type, and to assign it to
   11529              :    the DECL_RESULT for the function.  Set *NO_WARNING to true if
   11530              :    code reaches end of non-void function warning shouldn't be issued
   11531              :    on this RETURN_EXPR.  Set *DANGLING to true if code returns the
   11532              :    address of a local variable.  */
   11533              : 
   11534              : tree
   11535    132364709 : check_return_expr (tree retval, bool *no_warning, bool *dangling)
   11536              : {
   11537    132364709 :   tree result;
   11538              :   /* The type actually returned by the function.  */
   11539    132364709 :   tree valtype;
   11540              :   /* The type the function is declared to return, or void if
   11541              :      the declared type is incomplete.  */
   11542    132364709 :   tree functype;
   11543    132364709 :   int fn_returns_value_p;
   11544    132364709 :   location_t loc = cp_expr_loc_or_input_loc (retval);
   11545              : 
   11546    132364709 :   *no_warning = false;
   11547    132364709 :   *dangling = false;
   11548              : 
   11549              :   /* A `volatile' function is one that isn't supposed to return, ever.
   11550              :      (This is a G++ extension, used to get better code for functions
   11551              :      that call the `volatile' function.)  */
   11552    132364709 :   if (TREE_THIS_VOLATILE (current_function_decl))
   11553           12 :     warning (0, "function declared %<noreturn%> has a %<return%> statement");
   11554              : 
   11555              :   /* Check for various simple errors.  */
   11556    264729418 :   if (DECL_DESTRUCTOR_P (current_function_decl))
   11557              :     {
   11558         3359 :       if (retval)
   11559            3 :         error_at (loc, "returning a value from a destructor");
   11560              : 
   11561         3359 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11562            0 :         retval = current_class_ptr;
   11563              :       else
   11564              :         return NULL_TREE;
   11565              :     }
   11566    132361350 :   else if (DECL_CONSTRUCTOR_P (current_function_decl))
   11567              :     {
   11568       163793 :       if (in_function_try_handler)
   11569              :         /* If a return statement appears in a handler of the
   11570              :            function-try-block of a constructor, the program is ill-formed.  */
   11571            0 :         error ("cannot return from a handler of a function-try-block of a constructor");
   11572       163793 :       else if (retval)
   11573              :         /* You can't return a value from a constructor.  */
   11574            3 :         error_at (loc, "returning a value from a constructor");
   11575              : 
   11576       163793 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11577            0 :         retval = current_class_ptr;
   11578              :       else
   11579              :         return NULL_TREE;
   11580              :     }
   11581              : 
   11582    132197557 :   const tree saved_retval = retval;
   11583              : 
   11584    132197557 :   if (processing_template_decl)
   11585              :     {
   11586              :       /* If in expansion statement body, we don't know if the body
   11587              :          will be instantiated at all.  */
   11588     85744657 :       if (in_expansion_stmt)
   11589           46 :         goto dependent;
   11590              : 
   11591     85744611 :       current_function_returns_value = 1;
   11592              : 
   11593     85744611 :       if (check_for_bare_parameter_packs (retval))
   11594           14 :         return error_mark_node;
   11595              : 
   11596              :       /* If one of the types might be void, we can't tell whether we're
   11597              :          returning a value.  */
   11598     85744597 :       if ((WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
   11599     36130003 :            && !FNDECL_USED_AUTO (current_function_decl))
   11600     49614594 :           || (retval != NULL_TREE
   11601     48434798 :               && (TREE_TYPE (retval) == NULL_TREE
   11602     33438771 :                   || WILDCARD_TYPE_P (TREE_TYPE (retval)))))
   11603     58345555 :         goto dependent;
   11604              :     }
   11605              : 
   11606     73851942 :   functype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11607              : 
   11608              :   /* Deduce auto return type from a return statement.  */
   11609     73851942 :   if (FNDECL_USED_AUTO (current_function_decl))
   11610              :     {
   11611      1156788 :       tree pattern = DECL_SAVED_AUTO_RETURN_TYPE (current_function_decl);
   11612      1156788 :       tree auto_node;
   11613      1156788 :       tree type;
   11614              : 
   11615      1156788 :       if (!retval && !is_auto (pattern))
   11616              :         {
   11617              :           /* Give a helpful error message.  */
   11618            3 :           auto_diagnostic_group d;
   11619            3 :           error ("return-statement with no value, in function returning %qT",
   11620              :                  pattern);
   11621            3 :           inform (input_location, "only plain %<auto%> return type can be "
   11622              :                   "deduced to %<void%>");
   11623            3 :           type = error_mark_node;
   11624            3 :         }
   11625      1156785 :       else if (retval && BRACE_ENCLOSED_INITIALIZER_P (retval))
   11626              :         {
   11627            6 :           error ("returning initializer list");
   11628            6 :           type = error_mark_node;
   11629              :         }
   11630              :       else
   11631              :         {
   11632      1156779 :           if (!retval)
   11633         2558 :             retval = void_node;
   11634      1156779 :           auto_node = type_uses_auto (pattern);
   11635      1156779 :           type = do_auto_deduction (pattern, retval, auto_node,
   11636              :                                     tf_warning_or_error, adc_return_type);
   11637              :         }
   11638              : 
   11639      1156788 :       if (type == error_mark_node)
   11640              :         /* Leave it.  */;
   11641      1156546 :       else if (functype == pattern)
   11642       920809 :         apply_deduced_return_type (current_function_decl, type);
   11643       235737 :       else if (!same_type_p (type, functype))
   11644              :         {
   11645           24 :           if (LAMBDA_FUNCTION_P (current_function_decl))
   11646            6 :             error_at (loc, "inconsistent types %qT and %qT deduced for "
   11647              :                       "lambda return type", functype, type);
   11648              :           else
   11649           12 :             error_at (loc, "inconsistent deduction for auto return type: "
   11650              :                       "%qT and then %qT", functype, type);
   11651              :         }
   11652              :       functype = type;
   11653              :     }
   11654              : 
   11655     73851942 :   result = DECL_RESULT (current_function_decl);
   11656     73851942 :   valtype = TREE_TYPE (result);
   11657     73851942 :   gcc_assert (valtype != NULL_TREE);
   11658     73851942 :   fn_returns_value_p = !VOID_TYPE_P (valtype);
   11659              : 
   11660              :   /* Check for a return statement with no return value in a function
   11661              :      that's supposed to return a value.  */
   11662     73851942 :   if (!retval && fn_returns_value_p)
   11663              :     {
   11664           33 :       if (functype != error_mark_node)
   11665           30 :         permerror (input_location, "return-statement with no value, in "
   11666              :                    "function returning %qT", valtype);
   11667              :       /* Remember that this function did return.  */
   11668           33 :       current_function_returns_value = 1;
   11669              :       /* But suppress NRV  .*/
   11670           33 :       current_function_return_value = error_mark_node;
   11671              :       /* And signal caller that TREE_NO_WARNING should be set on the
   11672              :          RETURN_EXPR to avoid control reaches end of non-void function
   11673              :          warnings in tree-cfg.cc.  */
   11674           33 :       *no_warning = true;
   11675              :     }
   11676              :   /* Check for a return statement with a value in a function that
   11677              :      isn't supposed to return a value.  */
   11678     73851909 :   else if (retval && !fn_returns_value_p)
   11679              :     {
   11680       176990 :       if (VOID_TYPE_P (TREE_TYPE (retval)))
   11681              :         /* You can return a `void' value from a function of `void'
   11682              :            type.  In that case, we have to evaluate the expression for
   11683              :            its side-effects.  */
   11684       176951 :         finish_expr_stmt (retval);
   11685           39 :       else if (retval != error_mark_node)
   11686           36 :         permerror (loc, "return-statement with a value, in function "
   11687              :                    "returning %qT", valtype);
   11688       176990 :       current_function_returns_null = 1;
   11689              : 
   11690              :       /* There's really no value to return, after all.  */
   11691       176990 :       return NULL_TREE;
   11692              :     }
   11693     73674919 :   else if (!retval)
   11694              :     /* Remember that this function can sometimes return without a
   11695              :        value.  */
   11696      1715443 :     current_function_returns_null = 1;
   11697              :   else
   11698              :     /* Remember that this function did return a value.  */
   11699     71959476 :     current_function_returns_value = 1;
   11700              : 
   11701              :   /* Check for erroneous operands -- but after giving ourselves a
   11702              :      chance to provide an error about returning a value from a void
   11703              :      function.  */
   11704     73674952 :   if (error_operand_p (retval))
   11705              :     {
   11706         1076 :       current_function_return_value = error_mark_node;
   11707         1076 :       return error_mark_node;
   11708              :     }
   11709              : 
   11710              :   /* Only operator new(...) throw(), can return NULL [expr.new/13].  */
   11711    147347752 :   if (IDENTIFIER_NEW_OP_P (DECL_NAME (current_function_decl))
   11712        32881 :       && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
   11713         2618 :       && ! flag_check_new
   11714     73676485 :       && retval && null_ptr_cst_p (retval))
   11715           24 :     warning (0, "%<operator new%> must not return NULL unless it is "
   11716              :              "declared %<throw()%> (or %<-fcheck-new%> is in effect)");
   11717              : 
   11718              :   /* Effective C++ rule 15.  See also start_function.  */
   11719     73673876 :   if (warn_ecpp
   11720           42 :       && DECL_NAME (current_function_decl) == assign_op_identifier
   11721     73673906 :       && !type_dependent_expression_p (retval))
   11722              :     {
   11723           27 :       bool warn = true;
   11724              : 
   11725              :       /* The function return type must be a reference to the current
   11726              :         class.  */
   11727           27 :       if (TYPE_REF_P (valtype)
   11728           45 :           && same_type_ignoring_top_level_qualifiers_p
   11729           18 :               (TREE_TYPE (valtype), TREE_TYPE (current_class_ref)))
   11730              :         {
   11731              :           /* Returning '*this' is obviously OK.  */
   11732           18 :           if (retval == current_class_ref)
   11733              :             warn = false;
   11734              :           /* If we are calling a function whose return type is the same of
   11735              :              the current class reference, it is ok.  */
   11736            6 :           else if (INDIRECT_REF_P (retval)
   11737            6 :                    && TREE_CODE (TREE_OPERAND (retval, 0)) == CALL_EXPR)
   11738              :             warn = false;
   11739              :         }
   11740              : 
   11741              :       if (warn)
   11742            9 :         warning_at (loc, OPT_Weffc__,
   11743              :                     "%<operator=%> should return a reference to %<*this%>");
   11744              :     }
   11745              : 
   11746     73673876 :   if (dependent_type_p (functype)
   11747     73673876 :       || type_dependent_expression_p (retval))
   11748              :     {
   11749     74804124 :     dependent:
   11750              :       /* We should not have changed the return value.  */
   11751     74804124 :       gcc_assert (retval == saved_retval);
   11752              :       /* We don't know if this is an lvalue or rvalue use, but
   11753              :          either way we can mark it as read.  */
   11754     74804124 :       mark_exp_read (retval);
   11755     74804124 :       return retval;
   11756              :     }
   11757              : 
   11758              :   /* The fabled Named Return Value optimization, as per [class.copy]/15:
   11759              : 
   11760              :      [...]      For  a function with a class return type, if the expression
   11761              :      in the return statement is the name of a local  object,  and  the  cv-
   11762              :      unqualified  type  of  the  local  object  is the same as the function
   11763              :      return type, an implementation is permitted to omit creating the  tem-
   11764              :      porary  object  to  hold  the function return value [...]
   11765              : 
   11766              :      So, if this is a value-returning function that always returns the same
   11767              :      local variable, remember it.
   11768              : 
   11769              :      We choose the first suitable variable even if the function sometimes
   11770              :      returns something else, but only if the variable is out of scope at the
   11771              :      other return sites, or else we run the risk of clobbering the variable we
   11772              :      chose if the other returned expression uses the chosen variable somehow.
   11773              : 
   11774              :      We don't currently do this if the first return is a non-variable, as it
   11775              :      would be complicated to determine whether an NRV selected later was in
   11776              :      scope at the point of the earlier return.  We also don't currently support
   11777              :      multiple variables with non-overlapping scopes (53637).
   11778              : 
   11779              :      See finish_function and finalize_nrv for the rest of this optimization.  */
   11780     57215353 :   tree bare_retval = NULL_TREE;
   11781     57215353 :   if (retval)
   11782              :     {
   11783     55499892 :       retval = maybe_undo_parenthesized_ref (retval);
   11784     55499892 :       bare_retval = tree_strip_any_location_wrapper (retval);
   11785              :     }
   11786              : 
   11787     57215353 :   bool named_return_value_okay_p = want_nrvo_p (bare_retval, functype);
   11788     57215353 :   if (fn_returns_value_p && flag_elide_constructors
   11789     55499869 :       && current_function_return_value != bare_retval)
   11790              :     {
   11791     55493826 :       if (named_return_value_okay_p
   11792       275075 :           && current_function_return_value == NULL_TREE)
   11793       233889 :         current_function_return_value = bare_retval;
   11794     55259937 :       else if (current_function_return_value
   11795     11159372 :                && VAR_P (current_function_return_value)
   11796          209 :                && DECL_NAME (current_function_return_value)
   11797     55260146 :                && !decl_in_scope_p (current_function_return_value))
   11798              :         {
   11799              :           /* The earlier NRV is out of scope at this point, so it's safe to
   11800          145 :              leave it alone; the current return can't refer to it.  */;
   11801          145 :           if (named_return_value_okay_p
   11802          145 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11803              :             {
   11804           12 :               warning (OPT_Wnrvo, "not eliding copy on return from %qD",
   11805              :                        bare_retval);
   11806           12 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   11807              :             }
   11808              :         }
   11809              :       else
   11810              :         {
   11811     55259792 :           if ((named_return_value_okay_p
   11812     55218620 :                || (current_function_return_value
   11813     11118055 :                    && current_function_return_value != error_mark_node))
   11814     55259834 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11815              :             {
   11816        41137 :               warning (OPT_Wnrvo, "not eliding copy on return in %qD",
   11817              :                        current_function_decl);
   11818        41137 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   11819              :             }
   11820     55259792 :           current_function_return_value = error_mark_node;
   11821              :         }
   11822              :     }
   11823              : 
   11824              :   /* We don't need to do any conversions when there's nothing being
   11825              :      returned.  */
   11826     57215353 :   if (!retval)
   11827              :     return NULL_TREE;
   11828              : 
   11829     55499892 :   if (!named_return_value_okay_p)
   11830     55218774 :     maybe_warn_pessimizing_move (retval, functype, /*return_p*/true);
   11831              : 
   11832              :   /* Do any required conversions.  */
   11833    110999784 :   if (bare_retval == result || DECL_CONSTRUCTOR_P (current_function_decl))
   11834              :     /* No conversions are required.  */
   11835              :     ;
   11836              :   else
   11837              :     {
   11838     55499892 :       int flags = LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING;
   11839              : 
   11840              :       /* The functype's return type will have been set to void, if it
   11841              :          was an incomplete type.  Just treat this as 'return;' */
   11842     55499892 :       if (VOID_TYPE_P (functype))
   11843            6 :         return error_mark_node;
   11844              : 
   11845              :       /* Under C++11 [12.8/32 class.copy], a returned lvalue is sometimes
   11846              :          treated as an rvalue for the purposes of overload resolution to
   11847              :          favor move constructors over copy constructors.
   11848              : 
   11849              :          Note that these conditions are similar to, but not as strict as,
   11850              :          the conditions for the named return value optimization.  */
   11851     55499886 :       bool converted = false;
   11852     55499886 :       tree moved;
   11853              :       /* Until C++23, this was only interesting for class type, but in C++23,
   11854              :          we should do the below when we're converting from/to a class/reference
   11855              :          (a non-scalar type).  */
   11856     55499886 :         if ((cxx_dialect < cxx23
   11857      7828192 :              ? CLASS_TYPE_P (functype)
   11858      9813630 :              : !SCALAR_TYPE_P (functype) || !SCALAR_TYPE_P (TREE_TYPE (retval)))
   11859     66330140 :             && (moved = treat_lvalue_as_rvalue_p (retval, /*return*/true)))
   11860              :           /* In C++20 and earlier we treat the return value as an rvalue
   11861              :              that can bind to lvalue refs.  In C++23, such an expression is just
   11862              :              an xvalue (see reference_binding).  */
   11863              :           retval = moved;
   11864              : 
   11865              :       /* The call in a (lambda) thunk needs no conversions.  */
   11866     55499886 :       if (TREE_CODE (retval) == CALL_EXPR
   11867     55499886 :           && call_from_lambda_thunk_p (retval))
   11868              :         converted = true;
   11869              : 
   11870              :       /* Don't check copy-initialization for NRV in a coroutine ramp; we
   11871              :          implement this case as NRV, but it's specified as directly
   11872              :          initializing the return value from get_return_object().  */
   11873     55499886 :       if (DECL_RAMP_P (current_function_decl) && named_return_value_okay_p)
   11874              :         converted = true;
   11875              : 
   11876              :       /* First convert the value to the function's return type, then
   11877              :          to the type of return value's location to handle the
   11878              :          case that functype is smaller than the valtype.  */
   11879     55499624 :       if (!converted)
   11880     55443263 :         retval = convert_for_initialization
   11881     55443263 :           (NULL_TREE, functype, retval, flags, ICR_RETURN, NULL_TREE, 0,
   11882              :            tf_warning_or_error);
   11883     55499886 :       retval = convert (valtype, retval);
   11884              : 
   11885              :       /* If the conversion failed, treat this just like `return;'.  */
   11886     55499886 :       if (retval == error_mark_node)
   11887              :         {
   11888              :           /* And suppress NRV.  */
   11889          213 :           current_function_return_value = error_mark_node;
   11890          213 :           return retval;
   11891              :         }
   11892              :       /* We can't initialize a register from a AGGR_INIT_EXPR.  */
   11893     55499673 :       else if (! cfun->returns_struct
   11894     53319120 :                && TREE_CODE (retval) == TARGET_EXPR
   11895     62245989 :                && TREE_CODE (TARGET_EXPR_INITIAL (retval)) == AGGR_INIT_EXPR)
   11896      1511057 :         retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval,
   11897      1511057 :                          TARGET_EXPR_SLOT (retval));
   11898     53988616 :       else if (!processing_template_decl
   11899     44237707 :                && maybe_warn_about_returning_address_of_local (retval, loc)
   11900     53988806 :                && INDIRECT_TYPE_P (valtype))
   11901          175 :         *dangling = true;
   11902              :     }
   11903              : 
   11904     55499673 :   if (check_out_of_consteval_use (retval))
   11905              :     {
   11906           12 :       current_function_return_value = error_mark_node;
   11907           12 :       return error_mark_node;
   11908              :     }
   11909              : 
   11910              :   /* A naive attempt to reduce the number of -Wdangling-reference false
   11911              :      positives: if we know that this function can return a variable with
   11912              :      static storage duration rather than one of its parameters, suppress
   11913              :      the warning.  */
   11914     55499661 :   if (warn_dangling_reference
   11915       414416 :       && TYPE_REF_P (functype)
   11916        27618 :       && bare_retval
   11917        27618 :       && VAR_P (bare_retval)
   11918           50 :       && TREE_STATIC (bare_retval))
   11919           50 :     suppress_warning (current_function_decl, OPT_Wdangling_reference);
   11920              : 
   11921     55499661 :   if (processing_template_decl)
   11922              :     return saved_retval;
   11923              : 
   11924              :   /* Actually copy the value returned into the appropriate location.  */
   11925     45748754 :   if (retval && retval != result)
   11926     45748754 :     retval = cp_build_init_expr (result, retval);
   11927              : 
   11928     45748754 :   if (current_function_return_value == bare_retval)
   11929       239926 :     INIT_EXPR_NRV_P (retval) = true;
   11930              : 
   11931     45748754 :   if (tree set = maybe_set_retval_sentinel ())
   11932       135822 :     retval = build2 (COMPOUND_EXPR, void_type_node, retval, set);
   11933              : 
   11934              :   return retval;
   11935              : }
   11936              : 
   11937              : 
   11938              : /* Returns nonzero if the pointer-type FROM can be converted to the
   11939              :    pointer-type TO via a qualification conversion.  If CONSTP is -1,
   11940              :    then we return nonzero if the pointers are similar, and the
   11941              :    cv-qualification signature of FROM is a proper subset of that of TO.
   11942              : 
   11943              :    If CONSTP is positive, then all outer pointers have been
   11944              :    const-qualified.  */
   11945              : 
   11946              : static bool
   11947    194363923 : comp_ptr_ttypes_real (tree to, tree from, int constp)
   11948              : {
   11949    194363923 :   bool to_more_cv_qualified = false;
   11950    194363923 :   bool is_opaque_pointer = false;
   11951              : 
   11952       670726 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   11953              :     {
   11954    195034649 :       if (TREE_CODE (to) != TREE_CODE (from))
   11955              :         return false;
   11956              : 
   11957    130112793 :       if (TREE_CODE (from) == OFFSET_TYPE
   11958    130112793 :           && !same_type_p (TYPE_OFFSET_BASETYPE (from),
   11959              :                            TYPE_OFFSET_BASETYPE (to)))
   11960              :         return false;
   11961              : 
   11962              :       /* Const and volatile mean something different for function and
   11963              :          array types, so the usual checks are not appropriate.  We'll
   11964              :          check the array type elements in further iterations.  */
   11965    130112793 :       if (!FUNC_OR_METHOD_TYPE_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   11966              :         {
   11967    129854880 :           if (!at_least_as_qualified_p (to, from))
   11968              :             return false;
   11969              : 
   11970    115627505 :           if (!at_least_as_qualified_p (from, to))
   11971              :             {
   11972     78467324 :               if (constp == 0)
   11973              :                 return false;
   11974              :               to_more_cv_qualified = true;
   11975              :             }
   11976              : 
   11977    115627240 :           if (constp > 0)
   11978    115622967 :             constp &= TYPE_READONLY (to);
   11979              :         }
   11980              : 
   11981    115885153 :       if (VECTOR_TYPE_P (to))
   11982        10121 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   11983              : 
   11984              :       /* P0388R4 allows a conversion from int[N] to int[] but not the
   11985              :          other way round.  When both arrays have bounds but they do
   11986              :          not match, then no conversion is possible.  */
   11987    115885153 :       if (TREE_CODE (to) == ARRAY_TYPE
   11988    115885153 :           && !comp_array_types (to, from, bounds_first, /*strict=*/false))
   11989              :         return false;
   11990              : 
   11991    115884315 :       if (!TYPE_PTR_P (to)
   11992              :           && !TYPE_PTRDATAMEM_P (to)
   11993              :           /* CWG 330 says we need to look through arrays.  */
   11994              :           && TREE_CODE (to) != ARRAY_TYPE)
   11995    115213589 :         return ((constp >= 0 || to_more_cv_qualified)
   11996    115213589 :                 && (is_opaque_pointer
   11997    115213051 :                     || same_type_ignoring_top_level_qualifiers_p (to, from)));
   11998              :     }
   11999              : }
   12000              : 
   12001              : /* When comparing, say, char ** to char const **, this function takes
   12002              :    the 'char *' and 'char const *'.  Do not pass non-pointer/reference
   12003              :    types to this function.  */
   12004              : 
   12005              : int
   12006    194363287 : comp_ptr_ttypes (tree to, tree from)
   12007              : {
   12008    194363287 :   return comp_ptr_ttypes_real (to, from, 1);
   12009              : }
   12010              : 
   12011              : /* Returns true iff FNTYPE is a non-class type that involves
   12012              :    error_mark_node.  We can get FUNCTION_TYPE with buried error_mark_node
   12013              :    if a parameter type is ill-formed.  */
   12014              : 
   12015              : bool
   12016       729908 : error_type_p (const_tree type)
   12017              : {
   12018       770897 :   tree t;
   12019              : 
   12020       770897 :   switch (TREE_CODE (type))
   12021              :     {
   12022              :     case ERROR_MARK:
   12023              :       return true;
   12024              : 
   12025        40900 :     case POINTER_TYPE:
   12026        40900 :     case REFERENCE_TYPE:
   12027        40900 :     case OFFSET_TYPE:
   12028        40900 :       return error_type_p (TREE_TYPE (type));
   12029              : 
   12030         3260 :     case FUNCTION_TYPE:
   12031         3260 :     case METHOD_TYPE:
   12032         3260 :       if (error_type_p (TREE_TYPE (type)))
   12033              :         return true;
   12034         8810 :       for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
   12035         5556 :         if (error_type_p (TREE_VALUE (t)))
   12036              :           return true;
   12037              :       return false;
   12038              : 
   12039       192058 :     case RECORD_TYPE:
   12040       192058 :       if (TYPE_PTRMEMFUNC_P (type))
   12041           89 :         return error_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type));
   12042              :       return false;
   12043              : 
   12044              :     default:
   12045              :       return false;
   12046              :     }
   12047              : }
   12048              : 
   12049              : /* Returns true if to and from are (possibly multi-level) pointers to the same
   12050              :    type or inheritance-related types, regardless of cv-quals.  */
   12051              : 
   12052              : bool
   12053    139447222 : ptr_reasonably_similar (const_tree to, const_tree from)
   12054              : {
   12055         1531 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   12056              :     {
   12057              :       /* Any target type is similar enough to void.  */
   12058    139448753 :       if (VOID_TYPE_P (to))
   12059         2095 :         return !error_type_p (from);
   12060    139446658 :       if (VOID_TYPE_P (from))
   12061       716707 :         return !error_type_p (to);
   12062              : 
   12063    138729951 :       if (TREE_CODE (to) != TREE_CODE (from))
   12064              :         return false;
   12065              : 
   12066     74383676 :       if (TREE_CODE (from) == OFFSET_TYPE
   12067     74383676 :           && comptypes (TYPE_OFFSET_BASETYPE (to),
   12068            3 :                         TYPE_OFFSET_BASETYPE (from),
   12069              :                         COMPARE_BASE | COMPARE_DERIVED))
   12070            3 :         continue;
   12071              : 
   12072     74383670 :       if (VECTOR_TYPE_P (to)
   12073     74383670 :           && vector_types_convertible_p (to, from, false))
   12074              :         return true;
   12075              : 
   12076     74383586 :       if (TREE_CODE (to) == INTEGER_TYPE
   12077     74383586 :           && TYPE_PRECISION (to) == TYPE_PRECISION (from))
   12078              :         return true;
   12079              : 
   12080     74188094 :       if (TREE_CODE (to) == FUNCTION_TYPE)
   12081         1145 :         return !error_type_p (to) && !error_type_p (from);
   12082              : 
   12083     74186949 :       if (!TYPE_PTR_P (to))
   12084              :         {
   12085              :           /* When either type is incomplete avoid DERIVED_FROM_P,
   12086              :              which may call complete_type (c++/57942).  */
   12087     74185421 :           bool b = !COMPLETE_TYPE_P (to) || !COMPLETE_TYPE_P (from);
   12088              :           return comptypes
   12089     74185421 :             (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from),
   12090     74185421 :              b ? COMPARE_STRICT : COMPARE_BASE | COMPARE_DERIVED);
   12091              :         }
   12092         1531 :     }
   12093              : }
   12094              : 
   12095              : /* Return true if TO and FROM (both of which are POINTER_TYPEs or
   12096              :    pointer-to-member types) are the same, ignoring cv-qualification at
   12097              :    all levels.  CB says how we should behave when comparing array bounds.  */
   12098              : 
   12099              : bool
   12100      1123940 : comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
   12101              : {
   12102      1123940 :   bool is_opaque_pointer = false;
   12103              : 
   12104      1126007 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   12105              :     {
   12106      2249947 :       if (TREE_CODE (to) != TREE_CODE (from))
   12107              :         return false;
   12108              : 
   12109      1914980 :       if (TREE_CODE (from) == OFFSET_TYPE
   12110      1913008 :           && same_type_p (TYPE_OFFSET_BASETYPE (from),
   12111              :                           TYPE_OFFSET_BASETYPE (to)))
   12112         1972 :           continue;
   12113              : 
   12114      1911036 :       if (VECTOR_TYPE_P (to))
   12115         8632 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   12116              : 
   12117      1911036 :       if (TREE_CODE (to) == ARRAY_TYPE
   12118              :           /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
   12119              :              we must fail.  */
   12120      1911036 :           && !comp_array_types (to, from, cb, /*strict=*/false))
   12121              :         return false;
   12122              : 
   12123              :       /* CWG 330 says we need to look through arrays.  */
   12124      1907766 :       if (!TYPE_PTR_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   12125       783731 :         return (is_opaque_pointer
   12126       783731 :                 || same_type_ignoring_top_level_qualifiers_p (to, from));
   12127              :     }
   12128              : }
   12129              : 
   12130              : /* Returns the type qualifiers for this type, including the qualifiers on the
   12131              :    elements for an array type.  */
   12132              : 
   12133              : int
   12134  65425315374 : cp_type_quals (const_tree type)
   12135              : {
   12136  65425315374 :   int quals;
   12137              :   /* This CONST_CAST is okay because strip_array_types returns its
   12138              :      argument unmodified and we assign it to a const_tree.  */
   12139  65425315374 :   type = strip_array_types (const_cast<tree> (type));
   12140  65425315374 :   if (type == error_mark_node
   12141              :       /* Quals on a FUNCTION_TYPE are memfn quals.  */
   12142  65388895799 :       || TREE_CODE (type) == FUNCTION_TYPE)
   12143              :     return TYPE_UNQUALIFIED;
   12144  65317087492 :   quals = TYPE_QUALS (type);
   12145              :   /* METHOD and REFERENCE_TYPEs should never have quals.  */
   12146  65317087492 :   gcc_assert ((TREE_CODE (type) != METHOD_TYPE
   12147              :                && !TYPE_REF_P (type))
   12148              :               || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
   12149              :                   == TYPE_UNQUALIFIED));
   12150              :   return quals;
   12151              : }
   12152              : 
   12153              : /* Returns the function-ref-qualifier for TYPE */
   12154              : 
   12155              : cp_ref_qualifier
   12156   3509951035 : type_memfn_rqual (const_tree type)
   12157              : {
   12158   3509951035 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
   12159              : 
   12160   3509951035 :   if (!FUNCTION_REF_QUALIFIED (type))
   12161              :     return REF_QUAL_NONE;
   12162     32473399 :   else if (FUNCTION_RVALUE_QUALIFIED (type))
   12163              :     return REF_QUAL_RVALUE;
   12164              :   else
   12165     16132307 :     return REF_QUAL_LVALUE;
   12166              : }
   12167              : 
   12168              : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
   12169              :    METHOD_TYPE.  */
   12170              : 
   12171              : int
   12172   1153227517 : type_memfn_quals (const_tree type)
   12173              : {
   12174   1153227517 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12175    114668968 :     return TYPE_QUALS (type);
   12176   1038558549 :   else if (TREE_CODE (type) == METHOD_TYPE)
   12177   1038558549 :     return cp_type_quals (class_of_this_parm (type));
   12178              :   else
   12179            0 :     gcc_unreachable ();
   12180              : }
   12181              : 
   12182              : /* Returns the FUNCTION_TYPE TYPE with its function-cv-quals changed to
   12183              :    MEMFN_QUALS and its ref-qualifier to RQUAL. */
   12184              : 
   12185              : tree
   12186     76298826 : apply_memfn_quals (tree type, cp_cv_quals memfn_quals, cp_ref_qualifier rqual)
   12187              : {
   12188              :   /* Could handle METHOD_TYPE here if necessary.  */
   12189     76298826 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
   12190     76298826 :   if (TYPE_QUALS (type) == memfn_quals
   12191     76298826 :       && type_memfn_rqual (type) == rqual)
   12192              :     return type;
   12193              : 
   12194              :   /* This should really have a different TYPE_MAIN_VARIANT, but that gets
   12195              :      complex.  */
   12196       706239 :   tree result = build_qualified_type (type, memfn_quals);
   12197       706239 :   return build_ref_qualified_type (result, rqual);
   12198              : }
   12199              : 
   12200              : /* Returns nonzero if TYPE is const or volatile.  */
   12201              : 
   12202              : bool
   12203   1265567484 : cv_qualified_p (const_tree type)
   12204              : {
   12205   1265567484 :   int quals = cp_type_quals (type);
   12206   1265567484 :   return (quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)) != 0;
   12207              : }
   12208              : 
   12209              : /* Returns nonzero if the TYPE contains a mutable member.  */
   12210              : 
   12211              : bool
   12212    976492435 : cp_has_mutable_p (const_tree type)
   12213              : {
   12214              :   /* This CONST_CAST is okay because strip_array_types returns its
   12215              :      argument unmodified and we assign it to a const_tree.  */
   12216    976492435 :   type = strip_array_types (const_cast<tree> (type));
   12217              : 
   12218    976492435 :   return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
   12219              : }
   12220              : 
   12221              : /* Set TREE_READONLY and TREE_VOLATILE on DECL as indicated by the
   12222              :    TYPE_QUALS.  For a VAR_DECL, this may be an optimistic
   12223              :    approximation.  In particular, consider:
   12224              : 
   12225              :      int f();
   12226              :      struct S { int i; };
   12227              :      const S s = { f(); }
   12228              : 
   12229              :    Here, we will make "s" as TREE_READONLY (because it is declared
   12230              :    "const") -- only to reverse ourselves upon seeing that the
   12231              :    initializer is non-constant.  */
   12232              : 
   12233              : void
   12234   1053439054 : cp_apply_type_quals_to_decl (int type_quals, tree decl)
   12235              : {
   12236   1053439054 :   tree type = TREE_TYPE (decl);
   12237              : 
   12238   1053439054 :   if (type == error_mark_node)
   12239              :     return;
   12240              : 
   12241   1053438348 :   if (TREE_CODE (decl) == TYPE_DECL)
   12242              :     return;
   12243              : 
   12244    928901966 :   gcc_assert (!(TREE_CODE (type) == FUNCTION_TYPE
   12245              :                 && type_quals != TYPE_UNQUALIFIED));
   12246              : 
   12247              :   /* Avoid setting TREE_READONLY incorrectly.  */
   12248              :   /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
   12249              :      constructor can produce constant init, so rely on cp_finish_decl to
   12250              :      clear TREE_READONLY if the variable has non-constant init.  */
   12251              : 
   12252              :   /* If the type has (or might have) a mutable component, that component
   12253              :      might be modified.  */
   12254    928901966 :   if (TYPE_HAS_MUTABLE_P (type) || !COMPLETE_TYPE_P (type))
   12255     85795923 :     type_quals &= ~TYPE_QUAL_CONST;
   12256              : 
   12257    928901966 :   c_apply_type_quals_to_decl (type_quals, decl);
   12258              : }
   12259              : 
   12260              : /* Subroutine of casts_away_constness.  Make T1 and T2 point at
   12261              :    exemplar types such that casting T1 to T2 is casting away constness
   12262              :    if and only if there is no implicit conversion from T1 to T2.  */
   12263              : 
   12264              : static void
   12265      1335941 : casts_away_constness_r (tree *t1, tree *t2, tsubst_flags_t complain)
   12266              : {
   12267      1335941 :   int quals1;
   12268      1335941 :   int quals2;
   12269              : 
   12270              :   /* [expr.const.cast]
   12271              : 
   12272              :      For multi-level pointer to members and multi-level mixed pointers
   12273              :      and pointers to members (conv.qual), the "member" aspect of a
   12274              :      pointer to member level is ignored when determining if a const
   12275              :      cv-qualifier has been cast away.  */
   12276              :   /* [expr.const.cast]
   12277              : 
   12278              :      For  two  pointer types:
   12279              : 
   12280              :             X1 is T1cv1,1 * ... cv1,N *   where T1 is not a pointer type
   12281              :             X2 is T2cv2,1 * ... cv2,M *   where T2 is not a pointer type
   12282              :             K is min(N,M)
   12283              : 
   12284              :      casting from X1 to X2 casts away constness if, for a non-pointer
   12285              :      type T there does not exist an implicit conversion (clause
   12286              :      _conv_) from:
   12287              : 
   12288              :             Tcv1,(N-K+1) * cv1,(N-K+2) * ... cv1,N *
   12289              : 
   12290              :      to
   12291              : 
   12292              :             Tcv2,(M-K+1) * cv2,(M-K+2) * ... cv2,M *.  */
   12293      1335941 :   if ((!TYPE_PTR_P (*t1) && !TYPE_PTRDATAMEM_P (*t1))
   12294       668323 :       || (!TYPE_PTR_P (*t2) && !TYPE_PTRDATAMEM_P (*t2)))
   12295              :     {
   12296       667798 :       *t1 = cp_build_qualified_type (void_type_node,
   12297              :                                      cp_type_quals (*t1));
   12298       667798 :       *t2 = cp_build_qualified_type (void_type_node,
   12299              :                                      cp_type_quals (*t2));
   12300       667798 :       return;
   12301              :     }
   12302              : 
   12303       668143 :   quals1 = cp_type_quals (*t1);
   12304       668143 :   quals2 = cp_type_quals (*t2);
   12305              : 
   12306       668143 :   if (TYPE_PTRDATAMEM_P (*t1))
   12307            0 :     *t1 = TYPE_PTRMEM_POINTED_TO_TYPE (*t1);
   12308              :   else
   12309       668143 :     *t1 = TREE_TYPE (*t1);
   12310       668143 :   if (TYPE_PTRDATAMEM_P (*t2))
   12311            0 :     *t2 = TYPE_PTRMEM_POINTED_TO_TYPE (*t2);
   12312              :   else
   12313       668143 :     *t2 = TREE_TYPE (*t2);
   12314              : 
   12315       668143 :   casts_away_constness_r (t1, t2, complain);
   12316       668143 :   *t1 = build_pointer_type (*t1);
   12317       668143 :   *t2 = build_pointer_type (*t2);
   12318       668143 :   *t1 = cp_build_qualified_type (*t1, quals1);
   12319       668143 :   *t2 = cp_build_qualified_type (*t2, quals2);
   12320              : }
   12321              : 
   12322              : /* Returns nonzero if casting from TYPE1 to TYPE2 casts away
   12323              :    constness.
   12324              : 
   12325              :    ??? This function returns non-zero if casting away qualifiers not
   12326              :    just const.  We would like to return to the caller exactly which
   12327              :    qualifiers are casted away to give more accurate diagnostics.
   12328              : */
   12329              : 
   12330              : static bool
   12331       667870 : casts_away_constness (tree t1, tree t2, tsubst_flags_t complain)
   12332              : {
   12333       667870 :   if (TYPE_REF_P (t2))
   12334              :     {
   12335              :       /* [expr.const.cast]
   12336              : 
   12337              :          Casting from an lvalue of type T1 to an lvalue of type T2
   12338              :          using a reference cast casts away constness if a cast from an
   12339              :          rvalue of type "pointer to T1" to the type "pointer to T2"
   12340              :          casts away constness.  */
   12341            0 :       t1 = (TYPE_REF_P (t1) ? TREE_TYPE (t1) : t1);
   12342            0 :       return casts_away_constness (build_pointer_type (t1),
   12343            0 :                                    build_pointer_type (TREE_TYPE (t2)),
   12344            0 :                                    complain);
   12345              :     }
   12346              : 
   12347       667870 :   if (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
   12348              :     /* [expr.const.cast]
   12349              : 
   12350              :        Casting from an rvalue of type "pointer to data member of X
   12351              :        of type T1" to the type "pointer to data member of Y of type
   12352              :        T2" casts away constness if a cast from an rvalue of type
   12353              :        "pointer to T1" to the type "pointer to T2" casts away
   12354              :        constness.  */
   12355           48 :     return casts_away_constness
   12356           48 :       (build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t1)),
   12357           48 :        build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t2)),
   12358           48 :        complain);
   12359              : 
   12360              :   /* Casting away constness is only something that makes sense for
   12361              :      pointer or reference types.  */
   12362       667822 :   if (!TYPE_PTR_P (t1) || !TYPE_PTR_P (t2))
   12363              :     return false;
   12364              : 
   12365              :   /* Top-level qualifiers don't matter.  */
   12366       667798 :   t1 = TYPE_MAIN_VARIANT (t1);
   12367       667798 :   t2 = TYPE_MAIN_VARIANT (t2);
   12368       667798 :   casts_away_constness_r (&t1, &t2, complain);
   12369       667798 :   if (!can_convert (t2, t1, complain))
   12370          400 :     return true;
   12371              : 
   12372              :   return false;
   12373              : }
   12374              : 
   12375              : /* If T is a REFERENCE_TYPE return the type to which T refers.
   12376              :    Otherwise, return T itself.  */
   12377              : 
   12378              : tree
   12379   4511417914 : non_reference (tree t)
   12380              : {
   12381   4511417914 :   if (t && TYPE_REF_P (t))
   12382    406329489 :     t = TREE_TYPE (t);
   12383   4511417914 :   return t;
   12384              : }
   12385              : 
   12386              : 
   12387              : /* Return nonzero if REF is an lvalue valid for this language;
   12388              :    otherwise, print an error message and return zero.  USE says
   12389              :    how the lvalue is being used and so selects the error message.  */
   12390              : 
   12391              : int
   12392     43967979 : lvalue_or_else (tree ref, enum lvalue_use use, tsubst_flags_t complain)
   12393              : {
   12394     43967979 :   cp_lvalue_kind kind = lvalue_kind (ref);
   12395              : 
   12396     43967979 :   if (kind == clk_none)
   12397              :     {
   12398          690 :       if (complain & tf_error)
   12399          126 :         lvalue_error (cp_expr_loc_or_input_loc (ref), use);
   12400              :       return 0;
   12401              :     }
   12402     43967289 :   else if (kind & (clk_rvalueref|clk_class))
   12403              :     {
   12404          220 :       if (!(complain & tf_error))
   12405              :         return 0;
   12406              :       /* Make this a permerror because we used to accept it.  */
   12407           18 :       permerror (cp_expr_loc_or_input_loc (ref),
   12408              :                  "using rvalue as lvalue");
   12409              :     }
   12410              :   return 1;
   12411              : }
   12412              : 
   12413              : /* Return true if a user-defined literal operator is a raw operator.  */
   12414              : 
   12415              : bool
   12416       116566 : check_raw_literal_operator (const_tree decl)
   12417              : {
   12418       116566 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   12419       116566 :   tree argtype;
   12420       116566 :   int arity;
   12421       116566 :   bool maybe_raw_p = false;
   12422              : 
   12423              :   /* Count the number and type of arguments and check for ellipsis.  */
   12424       116566 :   for (argtype = argtypes, arity = 0;
   12425       174866 :        argtype && argtype != void_list_node;
   12426        58300 :        ++arity, argtype = TREE_CHAIN (argtype))
   12427              :     {
   12428        58300 :       tree t = TREE_VALUE (argtype);
   12429              : 
   12430        58300 :       if (same_type_p (t, const_string_type_node))
   12431            9 :         maybe_raw_p = true;
   12432              :     }
   12433       116566 :   if (!argtype)
   12434              :     return false; /* Found ellipsis.  */
   12435              : 
   12436       116566 :   if (!maybe_raw_p || arity != 1)
   12437       116560 :     return false;
   12438              : 
   12439              :   return true;
   12440              : }
   12441              : 
   12442              : 
   12443              : /* Return true if a user-defined literal operator has one of the allowed
   12444              :    argument types.  */
   12445              : 
   12446              : bool
   12447       319409 : check_literal_operator_args (const_tree decl,
   12448              :                              bool *long_long_unsigned_p, bool *long_double_p)
   12449              : {
   12450       319409 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   12451              : 
   12452       319409 :   *long_long_unsigned_p = false;
   12453       319409 :   *long_double_p = false;
   12454       319409 :   if (processing_template_decl || processing_specialization)
   12455        58428 :     return argtypes == void_list_node;
   12456              :   else
   12457              :     {
   12458              :       tree argtype;
   12459              :       int arity;
   12460              :       int max_arity = 2;
   12461              : 
   12462              :       /* Count the number and type of arguments and check for ellipsis.  */
   12463       260853 :       for (argtype = argtypes, arity = 0;
   12464       521834 :            argtype && argtype != void_list_node;
   12465       260853 :            argtype = TREE_CHAIN (argtype))
   12466              :         {
   12467       260987 :           tree t = TREE_VALUE (argtype);
   12468       260987 :           ++arity;
   12469              : 
   12470       260987 :           if (TYPE_PTR_P (t))
   12471              :             {
   12472       126911 :               bool maybe_raw_p = false;
   12473       126911 :               t = TREE_TYPE (t);
   12474       126911 :               if (cp_type_quals (t) != TYPE_QUAL_CONST)
   12475              :                 return false;
   12476       126908 :               t = TYPE_MAIN_VARIANT (t);
   12477       126908 :               if ((maybe_raw_p = same_type_p (t, char_type_node))
   12478       101336 :                   || same_type_p (t, wchar_type_node)
   12479        75950 :                   || same_type_p (t, char8_type_node)
   12480        50784 :                   || same_type_p (t, char16_type_node)
   12481       152300 :                   || same_type_p (t, char32_type_node))
   12482              :                 {
   12483       126905 :                   argtype = TREE_CHAIN (argtype);
   12484       126905 :                   if (!argtype)
   12485              :                     return false;
   12486       126905 :                   t = TREE_VALUE (argtype);
   12487       126905 :                   if (maybe_raw_p && argtype == void_list_node)
   12488              :                     return true;
   12489       126798 :                   else if (same_type_p (t, size_type_node))
   12490              :                     {
   12491       126792 :                       ++arity;
   12492       126792 :                       continue;
   12493              :                     }
   12494              :                   else
   12495              :                     return false;
   12496              :                 }
   12497              :             }
   12498       134076 :           else if (same_type_p (t, long_long_unsigned_type_node))
   12499              :             {
   12500        47217 :               max_arity = 1;
   12501        47217 :               *long_long_unsigned_p = true;
   12502              :             }
   12503        86859 :           else if (same_type_p (t, long_double_type_node))
   12504              :             {
   12505        86759 :               max_arity = 1;
   12506        86759 :               *long_double_p = true;
   12507              :             }
   12508          100 :           else if (same_type_p (t, char_type_node))
   12509              :             max_arity = 1;
   12510           56 :           else if (same_type_p (t, wchar_type_node))
   12511              :             max_arity = 1;
   12512           45 :           else if (same_type_p (t, char8_type_node))
   12513              :             max_arity = 1;
   12514           40 :           else if (same_type_p (t, char16_type_node))
   12515              :             max_arity = 1;
   12516           29 :           else if (same_type_p (t, char32_type_node))
   12517              :             max_arity = 1;
   12518              :           else
   12519              :             return false;
   12520              :         }
   12521       260847 :       if (!argtype)
   12522              :         return false; /* Found ellipsis.  */
   12523              : 
   12524       260844 :       if (arity != max_arity)
   12525              :         return false;
   12526              : 
   12527       260838 :       return true;
   12528              :     }
   12529              : }
   12530              : 
   12531              : /* Always returns false since unlike C90, C++ has no concept of implicit
   12532              :    function declarations.  */
   12533              : 
   12534              : bool
   12535          395 : c_decl_implicit (const_tree)
   12536              : {
   12537          395 :   return false;
   12538              : }
        

Generated by: LCOV version 2.4-beta

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