LCOV - code coverage report
Current view: top level - gcc/cp - typeck.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.2 % 5667 5224
Test Date: 2026-12-05 16:10:02 Functions: 97.8 % 180 176
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    150923592 : require_complete_type (tree value,
      75              :                        tsubst_flags_t complain /* = tf_warning_or_error */)
      76              : {
      77    150923592 :   tree type;
      78              : 
      79    150923592 :   if (processing_template_decl || value == error_mark_node)
      80              :     return value;
      81              : 
      82    140280106 :   if (TREE_CODE (value) == OVERLOAD)
      83            0 :     type = unknown_type_node;
      84              :   else
      85    140280106 :     type = TREE_TYPE (value);
      86              : 
      87    140280106 :   if (type == error_mark_node)
      88              :     return error_mark_node;
      89              : 
      90              :   /* First, detect a valid value with a complete type.  */
      91    140280094 :   if (COMPLETE_TYPE_P (type))
      92              :     return value;
      93              : 
      94       135311 :   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  15873350148 : complete_type (tree type)
     107              : {
     108  15873350148 :   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  15873350148 :   if (type == error_mark_node || COMPLETE_TYPE_P (type))
     114              :     ;
     115   5167671958 :   else if (TREE_CODE (type) == ARRAY_TYPE)
     116              :     {
     117       799658 :       tree t = complete_type (TREE_TYPE (type));
     118       799658 :       unsigned int needs_constructing, has_nontrivial_dtor;
     119       799658 :       if (COMPLETE_TYPE_P (t) && !dependent_type_p (type))
     120       780764 :         layout_type (type);
     121       799658 :       needs_constructing
     122       799658 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (t));
     123       799658 :       has_nontrivial_dtor
     124       799658 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (t));
     125      2658566 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
     126              :         {
     127      1858908 :           TYPE_NEEDS_CONSTRUCTING (t) = needs_constructing;
     128      1858908 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = has_nontrivial_dtor;
     129              :         }
     130              :     }
     131   5166872300 :   else if (CLASS_TYPE_P (type))
     132              :     {
     133   5071268896 :       if (modules_p ())
     134              :         /* TYPE could be a class member we've not loaded the definition of.  */
     135     20648500 :         lazy_load_pendings (TYPE_NAME (TYPE_MAIN_VARIANT (type)));
     136              : 
     137   5071268896 :       if (CLASSTYPE_TEMPLATE_INSTANTIATION (type))
     138    966167808 :         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   1715714574 : complete_type_or_maybe_complain (tree type, tree value, tsubst_flags_t complain)
     150              : {
     151   1715714574 :   type = complete_type (type);
     152   1715714571 :   if (type == error_mark_node)
     153              :     /* We already issued an error.  */
     154              :     return NULL_TREE;
     155   1715714413 :   else if (!COMPLETE_TYPE_P (type))
     156              :     {
     157         3968 :       if (complain & tf_error)
     158          478 :         cxx_incomplete_type_diagnostic (value, type, diagnostics::kind::error);
     159         3968 :       note_failed_type_completion (type, complain);
     160         3968 :       return NULL_TREE;
     161              :     }
     162              :   else
     163              :     return type;
     164              : }
     165              : 
     166              : tree
     167    171092263 : complete_type_or_else (tree type, tree value)
     168              : {
     169    171092263 :   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      4295828 : commonparms (tree p1, tree p2)
     182              : {
     183      4295828 :   tree oldargs = p1, newargs, n;
     184      4295828 :   int i, len;
     185      4295828 :   int any_change = 0;
     186              : 
     187      4295828 :   len = list_length (p1);
     188      4295828 :   newargs = tree_last (p1);
     189              : 
     190      4295828 :   if (newargs == void_list_node)
     191      4295828 :     i = 1;
     192              :   else
     193              :     {
     194        40839 :       i = 0;
     195        40839 :       newargs = 0;
     196              :     }
     197              : 
     198     14188698 :   for (; i < len; i++)
     199      9892870 :     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
     200              : 
     201              :   n = newargs;
     202              : 
     203     18443687 :   for (i = 0; p1;
     204     14147859 :        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
     205              :     {
     206     14148068 :       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
     207              :         {
     208          174 :           TREE_PURPOSE (n) = TREE_PURPOSE (p1);
     209          174 :           any_change = 1;
     210              :         }
     211     14147685 :       else if (! TREE_PURPOSE (p1))
     212              :         {
     213     14147650 :           if (TREE_PURPOSE (p2))
     214              :             {
     215       428215 :               TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     216       428215 :               any_change = 1;
     217              :             }
     218              :         }
     219              :       else
     220              :         {
     221           35 :           if (simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)) != 1)
     222           35 :             any_change = 1;
     223           35 :           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
     224              :         }
     225     14147859 :       if (TREE_VALUE (p1) != TREE_VALUE (p2))
     226              :         {
     227      3960267 :           any_change = 1;
     228      3960267 :           TREE_VALUE (n) = merge_types (TREE_VALUE (p1), TREE_VALUE (p2));
     229              :         }
     230              :       else
     231     10187592 :         TREE_VALUE (n) = TREE_VALUE (p1);
     232              :     }
     233      4295828 :   if (! any_change)
     234      1429340 :     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     33669840 : original_type (tree t)
     243              : {
     244     33669840 :   auto quals = cp_type_quals (t);
     245     33669840 :   while (t != error_mark_node
     246     34839958 :          && TYPE_NAME (t) != NULL_TREE)
     247              :     {
     248     11738918 :       tree x = TYPE_NAME (t);
     249     11738918 :       if (TREE_CODE (x) != TYPE_DECL)
     250              :         break;
     251     11738918 :       x = DECL_ORIGINAL_TYPE (x);
     252     11738918 :       if (x == NULL_TREE)
     253              :         break;
     254              :       t = x;
     255              :     }
     256     33669840 :   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      7533765 : cp_compare_floating_point_conversion_ranks (tree t1, tree t2)
     280              : {
     281      7533765 :   tree mv1 = TYPE_MAIN_VARIANT (t1);
     282      7533765 :   tree mv2 = TYPE_MAIN_VARIANT (t2);
     283      7533765 :   int extended1 = 0;
     284      7533765 :   int extended2 = 0;
     285              : 
     286      7533765 :   if (mv1 == mv2)
     287              :     return 0;
     288              : 
     289     60248872 :   for (int i = 0; i < NUM_FLOATN_NX_TYPES; ++i)
     290              :     {
     291     52717763 :       if (mv1 == FLOATN_NX_TYPE_NODE (i))
     292      3386900 :         extended1 = i + 1;
     293     52717763 :       if (mv2 == FLOATN_NX_TYPE_NODE (i))
     294      2863611 :         extended2 = i + 1;
     295              :     }
     296      7531109 :   if (mv1 == bfloat16_type_node)
     297       822902 :     extended1 = true;
     298      7531109 :   if (mv2 == bfloat16_type_node)
     299       629633 :     extended2 = true;
     300      7531109 :   if (extended2 && !extended1)
     301              :     {
     302      3279408 :       int ret = cp_compare_floating_point_conversion_ranks (t2, t1);
     303      3279408 :       return ret == 3 ? 3 : -ret;
     304              :     }
     305              : 
     306      4251701 :   const struct real_format *fmt1 = REAL_MODE_FORMAT (TYPE_MODE (t1));
     307      4251701 :   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      4251701 :   gcc_assert (fmt1->b == 2);
     313      4251701 :   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      4251668 :   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     34013344 :   int p1 = (MODE_COMPOSITE_P (TYPE_MODE (t1))
     338      8503336 :             ? fmt1->emax - fmt1->emin + fmt1->p - 1 : fmt1->p);
     339     34013344 :   int p2 = (MODE_COMPOSITE_P (TYPE_MODE (t2))
     340      8503336 :             ? 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      4251668 :   if ((p1 > p2 && fmt1->emax >= fmt2->emax)
     345      3333000 :        || (p1 == p2 && fmt1->emax > fmt2->emax))
     346              :     return 2;
     347      3333000 :   if ((p1 < p2 && fmt1->emax <= fmt2->emax)
     348      1094049 :        || (p1 == p2 && fmt1->emax < fmt2->emax))
     349              :     return -2;
     350      1094049 :   if ((p1 > p2 && fmt1->emax < fmt2->emax)
     351      1080640 :        || (p1 < p2 && fmt1->emax > fmt2->emax))
     352              :     return 3;
     353      1067333 :   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      1067333 :   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      4269308 :   for (p = &float_type_node; p <= &long_double_type_node; ++p)
     398              :     {
     399      3201981 :       const struct real_format *fmt3 = REAL_MODE_FORMAT (TYPE_MODE (*p));
     400      3201981 :       gcc_assert (fmt3->b == 2);
     401     25615848 :       int p3 = (MODE_COMPOSITE_P (TYPE_MODE (*p))
     402      6403962 :                 ? fmt3->emax - fmt3->emin + fmt3->p - 1 : fmt3->p);
     403      3201981 :       if (p1 == p3 && fmt1->emax == fmt3->emax)
     404       949652 :         ++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      1067327 :   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    115932416 : cp_common_type (tree t1, tree t2)
     436              : {
     437    115932416 :   enum tree_code code1 = TREE_CODE (t1);
     438    115932416 :   enum tree_code code2 = TREE_CODE (t2);
     439    115932416 :   tree attributes;
     440    115932416 :   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    115932416 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     447              : 
     448    115932416 :   if (SCOPED_ENUM_P (t1) || SCOPED_ENUM_P (t2))
     449              :     {
     450      2308957 :       if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     451      2308957 :         return build_type_attribute_variant (t1, attributes);
     452              :       else
     453              :         return NULL_TREE;
     454              :     }
     455              : 
     456              :   /* FIXME: Attributes.  */
     457    113623459 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     458              :               || VECTOR_TYPE_P (t1)
     459              :               || UNSCOPED_ENUM_P (t1));
     460    113623459 :   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    113623459 :   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
     468              :     {
     469       222158 :       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
     470       222158 :       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
     471       222158 :       tree subtype
     472       222158 :         = type_after_usual_arithmetic_conversions (subtype1, subtype2);
     473              : 
     474       222158 :       if (subtype == error_mark_node)
     475              :         return subtype;
     476       222158 :       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
     477       188746 :         return build_type_attribute_variant (t1, attributes);
     478        33412 :       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
     479        33352 :         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    113401301 :   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    113341440 :   if (code1 == REAL_TYPE && code2 != REAL_TYPE)
     497      1160990 :     return build_type_attribute_variant (t1, attributes);
     498    112180450 :   if (code2 == REAL_TYPE && code1 != REAL_TYPE)
     499      1038723 :     return build_type_attribute_variant (t2, attributes);
     500              : 
     501    111141727 :   if (code1 == REAL_TYPE
     502    111141727 :       && (extended_float_type_p (t1) || extended_float_type_p (t2)))
     503              :     {
     504       141071 :       tree mv1 = TYPE_MAIN_VARIANT (t1);
     505       141071 :       tree mv2 = TYPE_MAIN_VARIANT (t2);
     506       141071 :       if (mv1 == mv2)
     507       138030 :         return build_type_attribute_variant (t1, attributes);
     508              : 
     509         3041 :       int cmpret = cp_compare_floating_point_conversion_ranks (mv1, mv2);
     510         3041 :       if (cmpret == 3)
     511            6 :         return error_mark_node;
     512         3035 :       else if (cmpret >= 0)
     513         2660 :         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    111000656 :   if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
     520     17593962 :     return build_type_attribute_variant (t1, attributes);
     521     93406694 :   else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
     522      2492361 :     return build_type_attribute_variant (t2, attributes);
     523              : 
     524              :   /* The types are the same; no need to do anything fancy.  */
     525     90914333 :   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
     526     83433568 :     return build_type_attribute_variant (t1, attributes);
     527              : 
     528      7480765 :   if (code1 != REAL_TYPE)
     529              :     {
     530              :       /* If one is unsigned long long, then convert the other to unsigned
     531              :          long long.  */
     532      7480762 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node)
     533      7480762 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_unsigned_type_node))
     534       156834 :         return build_type_attribute_variant (long_long_unsigned_type_node,
     535       156834 :                                              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      7323928 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_integer_type_node)
     547      7323928 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_integer_type_node))
     548              :         {
     549         1424 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     550          718 :                     ? long_long_unsigned_type_node
     551          718 :                     : long_long_integer_type_node);
     552          718 :           return build_type_attribute_variant (t, attributes);
     553              :         }
     554              : 
     555              :       /* Go through the same procedure, but for longs.  */
     556      7323210 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_unsigned_type_node)
     557      7323210 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_unsigned_type_node))
     558       923834 :         return build_type_attribute_variant (long_unsigned_type_node,
     559       923834 :                                              attributes);
     560      6399376 :       if (same_type_p (TYPE_MAIN_VARIANT (t1), long_integer_type_node)
     561      6399376 :           || same_type_p (TYPE_MAIN_VARIANT (t2), long_integer_type_node))
     562              :         {
     563        75959 :           tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2))
     564        75959 :                     ? long_unsigned_type_node : long_integer_type_node);
     565        38454 :           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     12721812 :       for (i = 0; i < NUM_INT_N_ENTS; i ++)
     573              :         {
     574      6360922 :           if (int_n_enabled_p [i]
     575      6360922 :               && (same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].signed_type)
     576      6270974 :                   || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].signed_type)
     577      6270970 :                   || same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].unsigned_type)
     578      6270970 :                   || 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      6360890 :       if (TYPE_UNSIGNED (t1))
     589      5134858 :         return build_type_attribute_variant (t1, attributes);
     590              :       else
     591      1226032 :         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      1243209 : type_after_usual_arithmetic_conversions (tree t1, tree t2)
     623              : {
     624      1243209 :   gcc_assert (ARITHMETIC_TYPE_P (t1)
     625              :               || VECTOR_TYPE_P (t1)
     626              :               || UNSCOPED_ENUM_P (t1));
     627      1243209 :   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      1243209 :   if (INTEGRAL_OR_ENUMERATION_TYPE_P (t1)
     633      1020511 :       && INTEGRAL_OR_ENUMERATION_TYPE_P (t2))
     634              :     {
     635      1020188 :       t1 = type_promotes_to (t1);
     636      1020188 :       t2 = type_promotes_to (t2);
     637              :     }
     638              : 
     639      1243209 :   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      6264874 : 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      6264874 :   tree pointee1;
     683      6264874 :   tree pointee2;
     684      6264874 :   tree result_type;
     685      6264874 :   tree attributes;
     686              : 
     687              :   /* Determine the types pointed to by T1 and T2.  */
     688      6264874 :   if (TYPE_PTR_P (t1))
     689              :     {
     690      6264283 :       pointee1 = TREE_TYPE (t1);
     691      6264283 :       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      6264874 :   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      6264797 :   const auto q1 = cp_type_quals (pointee1);
     723      6264797 :   const auto q2 = cp_type_quals (pointee2);
     724      6264797 :   const auto quals = q1 | q2;
     725      6264797 :   result_type = cp_build_qualified_type (result_type,
     726      6264797 :                                          (quals | (*add_const
     727              :                                                    ? 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      6264797 :   if (quals != q1 || quals != q2)
     733       743963 :     *add_const = true;
     734              :   /* If the original types were pointers to members, so is the
     735              :      result.  */
     736      6264797 :   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      6264220 :     result_type = build_pointer_type (result_type);
     752              : 
     753              :   /* Merge the attributes.  */
     754      6264797 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     755      6264797 :   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      6734812 : 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      6734812 :   tree class1;
     773      6734812 :   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      6734812 :   if (null_ptr_cst_p (arg1))
     780              :     return t2;
     781      6734588 :   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      6713158 :   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      6713158 :   if (TYPE_PTR_P (t1) && VOID_TYPE_P (TREE_TYPE (t1)))
     799              :     {
     800       448212 :       tree attributes;
     801       448212 :       tree result_type;
     802              : 
     803       448212 :       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       448210 :       result_type
     833       448210 :         = cp_build_qualified_type (void_type_node,
     834       448210 :                                    (cp_type_quals (TREE_TYPE (t1))
     835       448210 :                                     | cp_type_quals (TREE_TYPE (t2))));
     836       448210 :       result_type = build_pointer_type (result_type);
     837              :       /* Merge the attributes.  */
     838       448210 :       attributes = (*targetm.merge_type_attributes) (t1, t2);
     839       448210 :       return build_type_attribute_variant (result_type, attributes);
     840              :     }
     841              : 
     842      6264946 :   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      6264946 :   if (fnptr_conv_p (t1, t2))
     853              :     return t1;
     854      6264911 :   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      6264268 :   if (TYPE_PTR_P (t1) && TYPE_PTR_P (t2)
     860      6264268 :       && CLASS_TYPE_P (TREE_TYPE (t1))
     861       956143 :       && CLASS_TYPE_P (TREE_TYPE (t2))
     862      7221020 :       && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (t1),
     863       956140 :                                                      TREE_TYPE (t2)))
     864              :     {
     865        30150 :       class1 = TREE_TYPE (t1);
     866        30150 :       class2 = TREE_TYPE (t2);
     867              : 
     868        30150 :       if (DERIVED_FROM_P (class1, class2))
     869         3256 :         t2 = (build_pointer_type
     870         1628 :               (cp_build_qualified_type (class1, cp_type_quals (class2))));
     871        28522 :       else if (DERIVED_FROM_P (class2, class1))
     872        57008 :         t1 = (build_pointer_type
     873        28504 :               (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      6234281 :   else if (TYPE_PTRMEM_P (t1)
     885      6234893 :            && !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      6264841 :   bool add_const = false;
     923      6264841 :   return composite_pointer_type_r (location, t1, t2, &add_const, operation,
     924      6264841 :                                    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     30871051 : merge_types (tree t1, tree t2)
     936              : {
     937     30871051 :   enum tree_code code1;
     938     30871051 :   enum tree_code code2;
     939     30871051 :   tree attributes;
     940              : 
     941              :   /* Save time if the two types are the same.  */
     942     30871051 :   if (t1 == t2)
     943              :     return t1;
     944     16834920 :   if (original_type (t1) == original_type (t2))
     945              :     return t1;
     946              : 
     947              :   /* If one type is nonsense, use the other.  */
     948     16698132 :   if (t1 == error_mark_node)
     949              :     return t2;
     950     16698132 :   if (t2 == error_mark_node)
     951              :     return t1;
     952              : 
     953              :   /* Handle merging an auto redeclaration with a previous deduced
     954              :      return type.  */
     955     16698132 :   if (is_auto (t1))
     956              :     return t2;
     957              : 
     958              :   /* Merge the attributes.  */
     959     16683191 :   attributes = (*targetm.merge_type_attributes) (t1, t2);
     960              : 
     961     16683191 :   if (TYPE_PTRMEMFUNC_P (t1))
     962           15 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
     963     16683191 :   if (TYPE_PTRMEMFUNC_P (t2))
     964           15 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
     965              : 
     966     16683191 :   code1 = TREE_CODE (t1);
     967     16683191 :   code2 = TREE_CODE (t2);
     968     16683191 :   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     16683191 :   switch (code1)
     984              :     {
     985      2839679 :     case POINTER_TYPE:
     986      2839679 :     case REFERENCE_TYPE:
     987              :       /* For two pointers, do this recursively on the target type.  */
     988      2839679 :       {
     989      2839679 :         tree target = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
     990      2839679 :         auto quals = cp_type_quals (t1);
     991              : 
     992      2839679 :         if (code1 == POINTER_TYPE)
     993              :           {
     994       756453 :             t1 = build_pointer_type (target);
     995       756453 :             if (TREE_CODE (target) == METHOD_TYPE)
     996           15 :               t1 = build_ptrmemfunc_type (t1);
     997              :           }
     998              :         else
     999      2083226 :           t1 = cp_build_reference_type (target, TYPE_REF_IS_RVALUE (t1));
    1000      2839679 :         t1 = build_type_attribute_variant (t1, attributes);
    1001      2839679 :         t1 = cp_build_qualified_type (t1, quals);
    1002              : 
    1003      2839679 :         return t1;
    1004              :       }
    1005              : 
    1006           12 :     case OFFSET_TYPE:
    1007           12 :       {
    1008           12 :         tree pointee;
    1009           12 :         auto quals = cp_type_quals (t1);
    1010           12 :         pointee = merge_types (TYPE_PTRMEM_POINTED_TO_TYPE (t1),
    1011           12 :                                TYPE_PTRMEM_POINTED_TO_TYPE (t2));
    1012           12 :         t1 = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1),
    1013              :                                 pointee);
    1014           12 :         t1 = cp_build_qualified_type (t1, quals);
    1015           12 :         break;
    1016              :       }
    1017              : 
    1018        10476 :     case ARRAY_TYPE:
    1019        10476 :       {
    1020        10476 :         tree elt = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1021              :         /* Save space: see if the result is identical to one of the args.  */
    1022        20952 :         if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
    1023        10445 :           return build_type_attribute_variant (t1, attributes);
    1024           53 :         if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
    1025           22 :           return build_type_attribute_variant (t2, attributes);
    1026              :         /* Merge the element types, and have a size if either arg has one.  */
    1027            9 :         t1 = build_cplus_array_type
    1028            9 :           (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
    1029            9 :         break;
    1030              :       }
    1031              : 
    1032      4462636 :     case FUNCTION_TYPE:
    1033              :       /* Function types: prefer the one that specified arg types.
    1034              :          If both do, merge the arg types.  Also merge the return types.  */
    1035      4462636 :       {
    1036      4462636 :         tree valtype = merge_types (TREE_TYPE (t1), TREE_TYPE (t2));
    1037      4462636 :         tree p1 = TYPE_ARG_TYPES (t1);
    1038      4462636 :         tree p2 = TYPE_ARG_TYPES (t2);
    1039      4462636 :         tree parms;
    1040              : 
    1041              :         /* Save space: see if the result is identical to one of the args.  */
    1042      4462636 :         if (valtype == TREE_TYPE (t1) && ! p2)
    1043            0 :           return cp_build_type_attribute_variant (t1, attributes);
    1044      4462636 :         if (valtype == TREE_TYPE (t2) && ! p1)
    1045            0 :           return cp_build_type_attribute_variant (t2, attributes);
    1046              : 
    1047              :         /* Simple way if one arg fails to specify argument types.  */
    1048      8925272 :         if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
    1049              :           parms = p2;
    1050      8591656 :         else if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
    1051              :           parms = p1;
    1052              :         else
    1053      4295828 :           parms = commonparms (p1, p2);
    1054              : 
    1055      4462636 :         cp_cv_quals quals = type_memfn_quals (t1);
    1056      4462636 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1057      4462636 :         gcc_assert (quals == type_memfn_quals (t2));
    1058      4462636 :         gcc_assert (rqual == type_memfn_rqual (t2));
    1059              : 
    1060      4462636 :         tree rval = cp_build_function_type (valtype, parms);
    1061      4462636 :         rval = apply_memfn_quals (rval, quals);
    1062      4462636 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1063      4462636 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1064      4462636 :         bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1065      4462636 :         t1 = build_cp_fntype_variant (rval, rqual, raises, late_return_type_p);
    1066      4462636 :         break;
    1067              :       }
    1068              : 
    1069      4051079 :     case METHOD_TYPE:
    1070      4051079 :       {
    1071              :         /* Get this value the long way, since TYPE_METHOD_BASETYPE
    1072              :            is just the main variant of this.  */
    1073      4051079 :         tree basetype = class_of_this_parm (t2);
    1074      4051079 :         tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
    1075      4051079 :                                                   TYPE_RAISES_EXCEPTIONS (t2));
    1076      4051079 :         cp_ref_qualifier rqual = type_memfn_rqual (t1);
    1077      4051079 :         tree t3;
    1078      4051079 :         bool late_return_type_1_p = TYPE_HAS_LATE_RETURN_TYPE (t1);
    1079              : 
    1080              :         /* If this was a member function type, get back to the
    1081              :            original type of type member function (i.e., without
    1082              :            the class instance variable up front.  */
    1083      4051079 :         t1 = cp_build_function_type (TREE_TYPE (t1),
    1084      4051079 :                                      TREE_CHAIN (TYPE_ARG_TYPES (t1)));
    1085      4051079 :         t2 = cp_build_function_type (TREE_TYPE (t2),
    1086      4051079 :                                      TREE_CHAIN (TYPE_ARG_TYPES (t2)));
    1087      4051079 :         t3 = merge_types (t1, t2);
    1088      4051079 :         t3 = build_method_type_directly (basetype, TREE_TYPE (t3),
    1089      4051079 :                                          TYPE_ARG_TYPES (t3));
    1090      4051079 :         t1 = build_cp_fntype_variant (t3, rqual, raises, late_return_type_1_p);
    1091      4051079 :         break;
    1092              :       }
    1093              : 
    1094              :     case TYPENAME_TYPE:
    1095              :       /* There is no need to merge attributes into a TYPENAME_TYPE.
    1096              :          When the type is instantiated it will have whatever
    1097              :          attributes result from the instantiation.  */
    1098              :       return t1;
    1099              : 
    1100      5309045 :     default:;
    1101      5309045 :       if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
    1102              :         return t1;
    1103           16 :       else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
    1104              :         return t2;
    1105              :       break;
    1106              :     }
    1107              : 
    1108      8513736 :   return cp_build_type_attribute_variant (t1, attributes);
    1109              : }
    1110              : 
    1111              : /* Return the ARRAY_TYPE type without its domain.  */
    1112              : 
    1113              : tree
    1114          391 : strip_array_domain (tree type)
    1115              : {
    1116          391 :   tree t2;
    1117          391 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    1118          391 :   if (TYPE_DOMAIN (type) == NULL_TREE)
    1119              :     return type;
    1120          226 :   t2 = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
    1121          226 :   return cp_build_type_attribute_variant (t2, TYPE_ATTRIBUTES (type));
    1122              : }
    1123              : 
    1124              : /* Wrapper around cp_common_type that is used by c-common.cc and other
    1125              :    front end optimizations that remove promotions.
    1126              : 
    1127              :    Return the common type for two arithmetic types T1 and T2 under the
    1128              :    usual arithmetic conversions.  The default conversions have already
    1129              :    been applied, and enumerated types converted to their compatible
    1130              :    integer types.  */
    1131              : 
    1132              : tree
    1133       648262 : common_type (tree t1, tree t2)
    1134              : {
    1135              :   /* If one type is nonsense, use the other  */
    1136       648262 :   if (t1 == error_mark_node)
    1137              :     return t2;
    1138       648262 :   if (t2 == error_mark_node)
    1139              :     return t1;
    1140              : 
    1141       648262 :   return cp_common_type (t1, t2);
    1142              : }
    1143              : 
    1144              : /* Return the common type of two pointer types T1 and T2.  This is the
    1145              :    type for the result of most arithmetic operations if the operands
    1146              :    have the given two types.
    1147              : 
    1148              :    We assume that comp_target_types has already been done and returned
    1149              :    nonzero; if that isn't so, this may crash.  */
    1150              : 
    1151              : tree
    1152      1553890 : common_pointer_type (tree t1, tree t2)
    1153              : {
    1154      1553890 :   gcc_assert ((TYPE_PTR_P (t1) && TYPE_PTR_P (t2))
    1155              :               || (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
    1156              :               || (TYPE_PTRMEMFUNC_P (t1) && TYPE_PTRMEMFUNC_P (t2)));
    1157              : 
    1158      1553890 :   return composite_pointer_type (input_location, t1, t2,
    1159              :                                  error_mark_node, error_mark_node,
    1160      1553890 :                                  CPO_CONVERSION, tf_warning_or_error);
    1161              : }
    1162              : 
    1163              : /* Compare two exception specifier types for exactness or subsetness, if
    1164              :    allowed. Returns false for mismatch, true for match (same, or
    1165              :    derived and !exact).
    1166              : 
    1167              :    [except.spec] "If a class X ... objects of class X or any class publicly
    1168              :    and unambiguously derived from X. Similarly, if a pointer type Y * ...
    1169              :    exceptions of type Y * or that are pointers to any type publicly and
    1170              :    unambiguously derived from Y. Otherwise a function only allows exceptions
    1171              :    that have the same type ..."
    1172              :    This does not mention cv qualifiers and is different to what throw
    1173              :    [except.throw] and catch [except.catch] will do. They will ignore the
    1174              :    top level cv qualifiers, and allow qualifiers in the pointer to class
    1175              :    example.
    1176              : 
    1177              :    We implement the letter of the standard.  */
    1178              : 
    1179              : static bool
    1180         1684 : comp_except_types (tree a, tree b, bool exact)
    1181              : {
    1182         1684 :   if (same_type_p (a, b))
    1183              :     return true;
    1184          506 :   else if (!exact)
    1185              :     {
    1186           11 :       if (cp_type_quals (a) || cp_type_quals (b))
    1187              :         return false;
    1188              : 
    1189           11 :       if (TYPE_PTR_P (a) && TYPE_PTR_P (b))
    1190              :         {
    1191            7 :           a = TREE_TYPE (a);
    1192            7 :           b = TREE_TYPE (b);
    1193            7 :           if (cp_type_quals (a) || cp_type_quals (b))
    1194              :             return false;
    1195              :         }
    1196              : 
    1197           10 :       if (TREE_CODE (a) != RECORD_TYPE
    1198           10 :           || TREE_CODE (b) != RECORD_TYPE)
    1199              :         return false;
    1200              : 
    1201            9 :       if (publicly_uniquely_derived_p (a, b))
    1202              :         return true;
    1203              :     }
    1204              :   return false;
    1205              : }
    1206              : 
    1207              : /* Return true if TYPE1 and TYPE2 are equivalent exception specifiers.
    1208              :    If EXACT is ce_derived, T2 can be stricter than T1 (according to 15.4/5).
    1209              :    If EXACT is ce_type, the C++17 type compatibility rules apply.
    1210              :    If EXACT is ce_normal, the compatibility rules in 15.4/3 apply.
    1211              :    If EXACT is ce_exact, the specs must be exactly the same. Exception lists
    1212              :    are unordered, but we've already filtered out duplicates. Most lists will
    1213              :    be in order, we should try to make use of that.  */
    1214              : 
    1215              : bool
    1216   1670820376 : comp_except_specs (const_tree t1, const_tree t2, int exact)
    1217              : {
    1218   1670820376 :   const_tree probe;
    1219   1670820376 :   const_tree base;
    1220   1670820376 :   int  length = 0;
    1221              : 
    1222   1670820376 :   if (t1 == t2)
    1223              :     return true;
    1224              : 
    1225              :   /* First handle noexcept.  */
    1226    679446066 :   if (exact < ce_exact)
    1227              :     {
    1228      4992608 :       if (exact == ce_type
    1229      9940862 :           && (canonical_eh_spec (const_cast<tree> (t1))
    1230      4948254 :               == canonical_eh_spec (const_cast<tree> (t2))))
    1231              :         return true;
    1232              : 
    1233              :       /* noexcept(false) is compatible with no exception-specification,
    1234              :          and less strict than any spec.  */
    1235      4961909 :       if (t1 == noexcept_false_spec)
    1236          236 :         return t2 == NULL_TREE || exact == ce_derived;
    1237              :       /* Even a derived noexcept(false) is compatible with no
    1238              :          exception-specification.  */
    1239      4961673 :       if (t2 == noexcept_false_spec)
    1240         1393 :         return t1 == NULL_TREE;
    1241              : 
    1242              :       /* Otherwise, if we aren't looking for an exact match, noexcept is
    1243              :          equivalent to throw().  */
    1244      4960280 :       if (t1 == noexcept_true_spec)
    1245       722359 :         t1 = empty_except_spec;
    1246      4960280 :       if (t2 == noexcept_true_spec)
    1247      4044809 :         t2 = empty_except_spec;
    1248              :     }
    1249              : 
    1250              :   /* If any noexcept is left, it is only comparable to itself;
    1251              :      either we're looking for an exact match or we're redeclaring a
    1252              :      template with dependent noexcept.  */
    1253    658703177 :   if ((t1 && TREE_PURPOSE (t1))
    1254    702986623 :       || (t2 && TREE_PURPOSE (t2)))
    1255    672350072 :     return (t1 && t2
    1256    672350072 :             && (exact == ce_exact
    1257     83990681 :                 ? TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
    1258       192817 :                 : cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))));
    1259              : 
    1260      7063666 :   if (t1 == NULL_TREE)                     /* T1 is ...  */
    1261      4265724 :     return t2 == NULL_TREE || exact == ce_derived;
    1262      2797942 :   if (!TREE_VALUE (t1))                    /* t1 is EMPTY */
    1263      2764250 :     return t2 != NULL_TREE && !TREE_VALUE (t2);
    1264        35110 :   if (t2 == NULL_TREE)                     /* T2 is ...  */
    1265              :     return false;
    1266         1562 :   if (TREE_VALUE (t1) && !TREE_VALUE (t2)) /* T2 is EMPTY, T1 is not */
    1267           76 :     return exact == ce_derived;
    1268              : 
    1269              :   /* Neither set is ... or EMPTY, make sure each part of T2 is in T1.
    1270              :      Count how many we find, to determine exactness. For exact matching and
    1271              :      ordered T1, T2, this is an O(n) operation, otherwise its worst case is
    1272              :      O(nm).  */
    1273         2667 :   for (base = t1; t2 != NULL_TREE; t2 = TREE_CHAIN (t2))
    1274              :     {
    1275         2080 :       for (probe = base; probe != NULL_TREE; probe = TREE_CHAIN (probe))
    1276              :         {
    1277         1684 :           tree a = TREE_VALUE (probe);
    1278         1684 :           tree b = TREE_VALUE (t2);
    1279              : 
    1280         1684 :           if (comp_except_types (a, b, exact))
    1281              :             {
    1282         1181 :               if (probe == base && exact > ce_derived)
    1283         1146 :                 base = TREE_CHAIN (probe);
    1284         1181 :               length++;
    1285         1181 :               break;
    1286              :             }
    1287              :         }
    1288         1181 :       if (probe == NULL_TREE)
    1289              :         return false;
    1290              :     }
    1291         1090 :   return exact == ce_derived || base == NULL_TREE || length == list_length (t1);
    1292              : }
    1293              : 
    1294              : /* Compare the array types T1 and T2.  CB says how we should behave when
    1295              :    comparing array bounds: bounds_none doesn't allow dimensionless arrays,
    1296              :    bounds_either says than any array can be [], bounds_first means that
    1297              :    onlt T1 can be an array with unknown bounds.  STRICT is true if
    1298              :    qualifiers must match when comparing the types of the array elements.  */
    1299              : 
    1300              : static bool
    1301      1939772 : comp_array_types (const_tree t1, const_tree t2, compare_bounds_t cb,
    1302              :                   bool strict)
    1303              : {
    1304      1939772 :   tree d1;
    1305      1939772 :   tree d2;
    1306      1939772 :   tree max1, max2;
    1307              : 
    1308      1939772 :   if (t1 == t2)
    1309              :     return true;
    1310              : 
    1311              :   /* The type of the array elements must be the same.  */
    1312      1938882 :   if (strict
    1313      1938882 :       ? !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    1314        14274 :       : !similar_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1315              :     return false;
    1316              : 
    1317      1242929 :   d1 = TYPE_DOMAIN (t1);
    1318      1242929 :   d2 = TYPE_DOMAIN (t2);
    1319              : 
    1320      1242929 :   if (d1 == d2)
    1321              :     return true;
    1322              : 
    1323              :   /* If one of the arrays is dimensionless, and the other has a
    1324              :      dimension, they are of different types.  However, it is valid to
    1325              :      write:
    1326              : 
    1327              :        extern int a[];
    1328              :        int a[3];
    1329              : 
    1330              :      by [basic.link]:
    1331              : 
    1332              :        declarations for an array object can specify
    1333              :        array types that differ by the presence or absence of a major
    1334              :        array bound (_dcl.array_).  */
    1335       684302 :   if (!d1 && d2)
    1336         7905 :     return cb >= bounds_either;
    1337       676397 :   else if (d1 && !d2)
    1338        17397 :     return cb == bounds_either;
    1339              : 
    1340              :   /* Check that the dimensions are the same.  */
    1341              : 
    1342       659000 :   if (!cp_tree_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2)))
    1343              :     return false;
    1344       658979 :   max1 = TYPE_MAX_VALUE (d1);
    1345       658979 :   max2 = TYPE_MAX_VALUE (d2);
    1346              : 
    1347       658979 :   if (!cp_tree_equal (max1, max2))
    1348              :     return false;
    1349              : 
    1350              :   return true;
    1351              : }
    1352              : 
    1353              : /* Compare the relative position of T1 and T2 into their respective
    1354              :    template parameter list.
    1355              :    T1 and T2 must be template parameter types.
    1356              :    Return TRUE if T1 and T2 have the same position, FALSE otherwise.  */
    1357              : 
    1358              : static bool
    1359   1758218345 : comp_template_parms_position (tree t1, tree t2)
    1360              : {
    1361   1758218345 :   tree index1, index2;
    1362   1758218345 :   gcc_assert (t1 && t2
    1363              :               && TREE_CODE (t1) == TREE_CODE (t2)
    1364              :               && (TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM
    1365              :                   || TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM
    1366              :                   || TREE_CODE (t1) == TEMPLATE_TYPE_PARM));
    1367              : 
    1368   1758218345 :   index1 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t1));
    1369   1758218345 :   index2 = TEMPLATE_TYPE_PARM_INDEX (TYPE_MAIN_VARIANT (t2));
    1370              : 
    1371              :   /* Then compare their relative position.  */
    1372   1758218345 :   if (TEMPLATE_PARM_IDX (index1) != TEMPLATE_PARM_IDX (index2)
    1373   1189313838 :       || TEMPLATE_PARM_LEVEL (index1) != TEMPLATE_PARM_LEVEL (index2)
    1374   2649967056 :       || (TEMPLATE_PARM_PARAMETER_PACK (index1)
    1375    891748711 :           != TEMPLATE_PARM_PARAMETER_PACK (index2)))
    1376              :     return false;
    1377              : 
    1378              :   /* In C++14 we can end up comparing 'auto' to a normal template
    1379              :      parameter.  Don't confuse them.  */
    1380    789759941 :   if (cxx_dialect >= cxx14 && (is_auto (t1) || is_auto (t2)))
    1381    205645936 :     return TYPE_IDENTIFIER (t1) == TYPE_IDENTIFIER (t2);
    1382              : 
    1383              :   return true;
    1384              : }
    1385              : 
    1386              : /* Heuristic check if two parameter types can be considered ABI-equivalent.  */
    1387              : 
    1388              : static bool
    1389          512 : cxx_safe_arg_type_equiv_p (tree t1, tree t2)
    1390              : {
    1391          512 :   t1 = TYPE_MAIN_VARIANT (t1);
    1392          512 :   t2 = TYPE_MAIN_VARIANT (t2);
    1393              : 
    1394          512 :   if (TYPE_PTR_P (t1)
    1395          141 :       && TYPE_PTR_P (t2))
    1396              :     return true;
    1397              : 
    1398              :   /* Only the precision of the parameter matters.  This check should
    1399              :      make sure that the callee does not see undefined values in argument
    1400              :      registers.  */
    1401          377 :   if (INTEGRAL_TYPE_P (t1)
    1402           68 :       && INTEGRAL_TYPE_P (t2)
    1403          424 :       && TYPE_PRECISION (t1) == TYPE_PRECISION (t2))
    1404              :     return true;
    1405              : 
    1406          333 :   return same_type_p (t1, t2);
    1407              : }
    1408              : 
    1409              : /* Check if a type cast between two function types can be considered safe.  */
    1410              : 
    1411              : static bool
    1412          361 : cxx_safe_function_type_cast_p (tree t1, tree t2)
    1413              : {
    1414          361 :   if (TREE_TYPE (t1) == void_type_node &&
    1415          280 :       TYPE_ARG_TYPES (t1) == void_list_node)
    1416              :     return true;
    1417              : 
    1418          309 :   if (TREE_TYPE (t2) == void_type_node &&
    1419          103 :       TYPE_ARG_TYPES (t2) == void_list_node)
    1420              :     return true;
    1421              : 
    1422          273 :   if (!cxx_safe_arg_type_equiv_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1423              :     return false;
    1424              : 
    1425          112 :   for (t1 = TYPE_ARG_TYPES (t1), t2 = TYPE_ARG_TYPES (t2);
    1426          315 :        t1 && t2;
    1427          203 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1428          239 :     if (!cxx_safe_arg_type_equiv_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1429              :       return false;
    1430              : 
    1431              :   return true;
    1432              : }
    1433              : 
    1434              : /* Subroutine in comptypes.  */
    1435              : 
    1436              : static bool
    1437  16991779744 : structural_comptypes (tree t1, tree t2, int strict)
    1438              : {
    1439              :   /* Both should be types that are not obviously the same.  */
    1440  16991779744 :   gcc_checking_assert (t1 != t2 && TYPE_P (t1) && TYPE_P (t2));
    1441              : 
    1442              :   /* Suppress typename resolution under spec_hasher::equal in place of calling
    1443              :      push_to_top_level there.  */
    1444  16991779744 :   if (!comparing_specializations)
    1445              :     {
    1446              :       /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
    1447              :          current instantiation.  */
    1448  13580050049 :       if (TREE_CODE (t1) == TYPENAME_TYPE)
    1449    107035140 :         t1 = resolve_typename_type (t1, /*only_current_p=*/true);
    1450              : 
    1451  13580050049 :       if (TREE_CODE (t2) == TYPENAME_TYPE)
    1452    139145170 :         t2 = resolve_typename_type (t2, /*only_current_p=*/true);
    1453              :     }
    1454              : 
    1455  16991779744 :   if (TYPE_PTRMEMFUNC_P (t1))
    1456     26195409 :     t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
    1457  16991779744 :   if (TYPE_PTRMEMFUNC_P (t2))
    1458     29468556 :     t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
    1459              : 
    1460              :   /* Different classes of types can't be compatible.  */
    1461  16991779744 :   if (TREE_CODE (t1) != TREE_CODE (t2))
    1462              :     return false;
    1463              : 
    1464              :   /* Qualifiers must match.  For array types, we will check when we
    1465              :      recur on the array element types.  */
    1466  11145073098 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1467  11145073098 :       && cp_type_quals (t1) != cp_type_quals (t2))
    1468              :     return false;
    1469  10439850711 :   if (TREE_CODE (t1) == FUNCTION_TYPE
    1470  10439850711 :       && type_memfn_quals (t1) != type_memfn_quals (t2))
    1471              :     return false;
    1472              :   /* Need to check this before TYPE_MAIN_VARIANT.
    1473              :      FIXME function qualifiers should really change the main variant.  */
    1474  10439767372 :   if (FUNC_OR_METHOD_TYPE_P (t1))
    1475              :     {
    1476     29849126 :       if (type_memfn_rqual (t1) != type_memfn_rqual (t2))
    1477              :         return false;
    1478     14500952 :       if (flag_noexcept_type
    1479     28931348 :           && !comp_except_specs (TYPE_RAISES_EXCEPTIONS (t1),
    1480     14430396 :                                  TYPE_RAISES_EXCEPTIONS (t2),
    1481              :                                  ce_type))
    1482              :         return false;
    1483              :     }
    1484              : 
    1485              :   /* Allow for two different type nodes which have essentially the same
    1486              :      definition.  Note that we already checked for equality of the type
    1487              :      qualifiers (just above).  */
    1488  10419654586 :   if (TREE_CODE (t1) != ARRAY_TYPE
    1489  10419654586 :       && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    1490    533038098 :     goto check_alias;
    1491              : 
    1492              :   /* Compare the types.  Return false on known not-same. Break on not
    1493              :      known.   Never return true from this switch -- you'll break
    1494              :      specialization comparison.    */
    1495   9886616488 :   switch (TREE_CODE (t1))
    1496              :     {
    1497              :     case VOID_TYPE:
    1498              :     case BOOLEAN_TYPE:
    1499              :       /* All void and bool types are the same.  */
    1500              :       break;
    1501              : 
    1502    821759636 :     case OPAQUE_TYPE:
    1503    821759636 :     case INTEGER_TYPE:
    1504    821759636 :     case FIXED_POINT_TYPE:
    1505    821759636 :     case REAL_TYPE:
    1506              :       /* With these nodes, we can't determine type equivalence by
    1507              :          looking at what is stored in the nodes themselves, because
    1508              :          two nodes might have different TYPE_MAIN_VARIANTs but still
    1509              :          represent the same type.  For example, wchar_t and int could
    1510              :          have the same properties (TYPE_PRECISION, TYPE_MIN_VALUE,
    1511              :          TYPE_MAX_VALUE, etc.), but have different TYPE_MAIN_VARIANTs
    1512              :          and are distinct types. On the other hand, int and the
    1513              :          following typedef
    1514              : 
    1515              :            typedef int INT __attribute((may_alias));
    1516              : 
    1517              :          have identical properties, different TYPE_MAIN_VARIANTs, but
    1518              :          represent the same type.  The canonical type system keeps
    1519              :          track of equivalence in this case, so we fall back on it.  */
    1520    821759636 :       if (TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1521              :         return false;
    1522              : 
    1523              :       /* We don't need or want the attribute comparison.  */
    1524         9817 :       goto check_alias;
    1525              : 
    1526      3653745 :     case TEMPLATE_TEMPLATE_PARM:
    1527      3653745 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    1528      3653745 :       if (!comp_template_parms_position (t1, t2))
    1529              :         return false;
    1530      2579626 :       if (!comp_template_parms
    1531      5159252 :           (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
    1532      7245788 :            DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
    1533              :         return false;
    1534      1929752 :       if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
    1535              :         break;
    1536              :       /* Don't check inheritance.  */
    1537              :       strict = COMPARE_STRICT;
    1538              :       /* Fall through.  */
    1539              : 
    1540   4658856502 :     case RECORD_TYPE:
    1541   4658856502 :     case UNION_TYPE:
    1542   8205384083 :       if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
    1543   2957226742 :           && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
    1544   2086179254 :               || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
    1545   5530144152 :           && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
    1546              :         break;
    1547              : 
    1548   4593952584 :       if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
    1549              :         break;
    1550   4593952550 :       else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
    1551              :         break;
    1552              : 
    1553              :       return false;
    1554              : 
    1555        60386 :     case OFFSET_TYPE:
    1556        60386 :       if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
    1557              :                       strict & ~COMPARE_REDECLARATION))
    1558              :         return false;
    1559        58539 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1560              :         return false;
    1561              :       break;
    1562              : 
    1563   1489667044 :     case REFERENCE_TYPE:
    1564   1489667044 :       if (TYPE_REF_IS_RVALUE (t1) != TYPE_REF_IS_RVALUE (t2))
    1565              :         return false;
    1566              :       /* fall through to checks for pointer types */
    1567   1849789482 :       gcc_fallthrough ();
    1568              : 
    1569   1849789482 :     case POINTER_TYPE:
    1570   1849789482 :       if (TYPE_MODE (t1) != TYPE_MODE (t2)
    1571   1849789482 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1572              :         return false;
    1573              :       break;
    1574              : 
    1575      2018349 :     case FUNCTION_TYPE:
    1576      2018349 :       if (TYPE_NO_NAMED_ARGS_STDARG_P (t1) != TYPE_NO_NAMED_ARGS_STDARG_P (t2))
    1577              :         return false;
    1578              :       /* FALLTHRU */
    1579      9427201 :     case METHOD_TYPE:
    1580              :       /* Exception specs and memfn_rquals were checked above.  */
    1581      9427201 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1582              :         return false;
    1583      8699811 :       if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
    1584              :         return false;
    1585              :       break;
    1586              : 
    1587      1924608 :     case ARRAY_TYPE:
    1588              :       /* Target types must match incl. qualifiers.  */
    1589      1924608 :       if (!comp_array_types (t1, t2, ((strict & COMPARE_REDECLARATION)
    1590      1924608 :                                       ? bounds_either : bounds_none),
    1591              :                              /*strict=*/true))
    1592              :         return false;
    1593              :       break;
    1594              : 
    1595   1754564600 :     case TEMPLATE_TYPE_PARM:
    1596              :       /* If T1 and T2 don't have the same relative position in their
    1597              :          template parameters set, they can't be equal.  */
    1598   1754564600 :       if (!comp_template_parms_position (t1, t2))
    1599              :         return false;
    1600              :       /* If T1 and T2 don't represent the same class template deduction,
    1601              :          they aren't equal.  */
    1602   1259899722 :       if (!cp_tree_equal (CLASS_PLACEHOLDER_TEMPLATE (t1),
    1603    629949861 :                           CLASS_PLACEHOLDER_TEMPLATE (t2)))
    1604              :         return false;
    1605              :       /* Constrained 'auto's are distinct from parms that don't have the same
    1606              :          constraints.  */
    1607    618906134 :       if (!equivalent_placeholder_constraints (t1, t2))
    1608              :         return false;
    1609              :       break;
    1610              : 
    1611    308276606 :     case TYPENAME_TYPE:
    1612    616553212 :       if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
    1613    308276606 :                           TYPENAME_TYPE_FULLNAME (t2)))
    1614              :         return false;
    1615              :       /* Qualifiers don't matter on scopes.  */
    1616    270217925 :       if (!same_type_ignoring_top_level_qualifiers_p (TYPE_CONTEXT (t1),
    1617    270217925 :                                                       TYPE_CONTEXT (t2)))
    1618              :         return false;
    1619              :       break;
    1620              : 
    1621        28281 :     case UNBOUND_CLASS_TEMPLATE:
    1622        28281 :       if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
    1623              :         return false;
    1624        28141 :       if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
    1625              :         return false;
    1626              :       break;
    1627              : 
    1628      2568560 :     case COMPLEX_TYPE:
    1629      2568560 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1630              :         return false;
    1631              :       break;
    1632              : 
    1633     12848269 :     case VECTOR_TYPE:
    1634     12848269 :       if (gnu_vector_type_p (t1) != gnu_vector_type_p (t2)
    1635     23994080 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2))
    1636     23994080 :           || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    1637              :         return false;
    1638              :       break;
    1639              : 
    1640      7832190 :     case TYPE_PACK_EXPANSION:
    1641      7832190 :       return (same_type_p (PACK_EXPANSION_PATTERN (t1),
    1642              :                            PACK_EXPANSION_PATTERN (t2))
    1643     15484234 :               && comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    1644      7652044 :                                      PACK_EXPANSION_EXTRA_ARGS (t2)));
    1645              : 
    1646           34 :     case PACK_INDEX_TYPE:
    1647           34 :       return (cp_tree_equal (PACK_INDEX_PACK (t1),
    1648           34 :                              PACK_INDEX_PACK (t2))
    1649           40 :               && cp_tree_equal (PACK_INDEX_INDEX (t1),
    1650            6 :                                 PACK_INDEX_INDEX (t2)));
    1651              : 
    1652     33336780 :     case DECLTYPE_TYPE:
    1653     66673560 :       if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t1)
    1654     33336780 :           != DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t2))
    1655              :         return false;
    1656     33308588 :       if (DECLTYPE_FOR_LAMBDA_CAPTURE (t1) != DECLTYPE_FOR_LAMBDA_CAPTURE (t2))
    1657              :         return false;
    1658     33308588 :       if (DECLTYPE_FOR_LAMBDA_PROXY (t1) != DECLTYPE_FOR_LAMBDA_PROXY (t2))
    1659              :         return false;
    1660     33308588 :       if (!cp_tree_equal (DECLTYPE_TYPE_EXPR (t1), DECLTYPE_TYPE_EXPR (t2)))
    1661              :         return false;
    1662              :       break;
    1663              : 
    1664       748613 :     case TRAIT_TYPE:
    1665       748613 :       if (TRAIT_TYPE_KIND (t1) != TRAIT_TYPE_KIND (t2))
    1666              :         return false;
    1667         1377 :       if (!cp_tree_equal (TRAIT_TYPE_TYPE1 (t1), TRAIT_TYPE_TYPE1 (t2))
    1668         2754 :           || !cp_tree_equal (TRAIT_TYPE_TYPE2 (t1), TRAIT_TYPE_TYPE2 (t2)))
    1669              :         return false;
    1670              :       break;
    1671              : 
    1672            3 :     case TYPEOF_TYPE:
    1673            3 :       if (!cp_tree_equal (TYPEOF_TYPE_EXPR (t1), TYPEOF_TYPE_EXPR (t2)))
    1674              :         return false;
    1675              :       break;
    1676              : 
    1677           34 :     case SPLICE_SCOPE:
    1678           34 :       if (SPLICE_SCOPE_TYPE_P (t1) != SPLICE_SCOPE_TYPE_P (t2))
    1679              :         return false;
    1680           34 :       if (!cp_tree_equal (SPLICE_SCOPE_EXPR (t1), SPLICE_SCOPE_EXPR (t2)))
    1681              :         return false;
    1682              :       break;
    1683              : 
    1684              :     default:
    1685              :       return false;
    1686              :     }
    1687              : 
    1688              :   /* If we get here, we know that from a target independent POV the
    1689              :      types are the same.  Make sure the target attributes are also
    1690              :      the same.  */
    1691    871927560 :   if (!comp_type_attributes (t1, t2))
    1692              :     return false;
    1693              : 
    1694    871926431 :  check_alias:
    1695   1404974346 :   if (comparing_dependent_aliases
    1696   1404974346 :       && (typedef_variant_p (t1) || typedef_variant_p (t2)))
    1697              :     {
    1698      5209070 :       tree dep1 = dependent_opaque_alias_p (t1) ? t1 : NULL_TREE;
    1699      5209070 :       tree dep2 = dependent_opaque_alias_p (t2) ? t2 : NULL_TREE;
    1700      5209070 :       if ((dep1 || dep2)
    1701      5209070 :           && (!(dep1 && dep2)
    1702            0 :               || !comp_type_attributes (DECL_ATTRIBUTES (TYPE_NAME (dep1)),
    1703            0 :                                         DECL_ATTRIBUTES (TYPE_NAME (dep2)))))
    1704              :         return false;
    1705              : 
    1706              :       /* Don't treat an alias template specialization with dependent
    1707              :          arguments as equivalent to its underlying type when used as a
    1708              :          template argument; we need them to be distinct so that we
    1709              :          substitute into the specialization arguments at instantiation
    1710              :          time.  And aliases can't be equivalent without being ==, so
    1711              :          we don't need to look any deeper.  */
    1712      5209005 :       ++processing_template_decl;
    1713      5209005 :       dep1 = dependent_alias_template_spec_p (t1, nt_transparent);
    1714      5209005 :       dep2 = dependent_alias_template_spec_p (t2, nt_transparent);
    1715      5209005 :       --processing_template_decl;
    1716      5209005 :       if ((dep1 || dep2) && dep1 != dep2)
    1717              :         return false;
    1718              :     }
    1719              : 
    1720              :   return true;
    1721              : }
    1722              : 
    1723              : /* C++ implementation of compatible_types_for_indirection_note_p.  */
    1724              : 
    1725              : bool
    1726         1611 : compatible_types_for_indirection_note_p (tree type1, tree type2)
    1727              : {
    1728         1611 :   return same_type_p (type1, type2);
    1729              : }
    1730              : 
    1731              : /* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
    1732              :    is a bitwise-or of the COMPARE_* flags.  */
    1733              : 
    1734              : bool
    1735  25651288800 : comptypes (tree t1, tree t2, int strict)
    1736              : {
    1737  25651288800 :   gcc_checking_assert (t1 && t2);
    1738              : 
    1739              :   /* TYPE_ARGUMENT_PACKS are not really types.  */
    1740  25651288800 :   gcc_checking_assert (TREE_CODE (t1) != TYPE_ARGUMENT_PACK
    1741              :                        && TREE_CODE (t2) != TYPE_ARGUMENT_PACK);
    1742              : 
    1743  25651288800 :   if (t1 == t2)
    1744              :     return true;
    1745              : 
    1746              :   /* Suppress errors caused by previously reported errors.  */
    1747  16991780912 :   if (t1 == error_mark_node || t2 == error_mark_node)
    1748              :     return false;
    1749              : 
    1750  16991780747 :   if (strict == COMPARE_STRICT)
    1751              :     {
    1752  15446721077 :       if (TYPE_STRUCTURAL_EQUALITY_P (t1) || TYPE_STRUCTURAL_EQUALITY_P (t2))
    1753              :         /* At least one of the types requires structural equality, so
    1754              :            perform a deep check. */
    1755   1807415038 :         return structural_comptypes (t1, t2, strict);
    1756              : 
    1757  13639306039 :       if (flag_checking && param_use_canonical_types)
    1758              :         {
    1759  13639305036 :           bool result = structural_comptypes (t1, t2, strict);
    1760              : 
    1761  13639305036 :           if (result && TYPE_CANONICAL (t1) != TYPE_CANONICAL (t2))
    1762              :             /* The two types are structurally equivalent, but their
    1763              :                canonical types were different. This is a failure of the
    1764              :                canonical type propagation code.*/
    1765            0 :             internal_error
    1766            0 :               ("canonical types differ for identical types %qT and %qT",
    1767              :                t1, t2);
    1768  13639305036 :           else if (!result && TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2))
    1769              :             /* Two types are structurally different, but the canonical
    1770              :                types are the same. This means we were over-eager in
    1771              :                assigning canonical types. */
    1772            0 :             internal_error
    1773            0 :               ("same canonical type node for different types %qT and %qT",
    1774              :                t1, t2);
    1775              : 
    1776              :           return result;
    1777              :         }
    1778         1003 :       if (!flag_checking && param_use_canonical_types)
    1779         1003 :         return TYPE_CANONICAL (t1) == TYPE_CANONICAL (t2);
    1780              :       else
    1781            0 :         return structural_comptypes (t1, t2, strict);
    1782              :     }
    1783   1545059670 :   else if (strict == COMPARE_STRUCTURAL)
    1784   1478372587 :     return structural_comptypes (t1, t2, COMPARE_STRICT);
    1785              :   else
    1786     66687083 :     return structural_comptypes (t1, t2, strict);
    1787              : }
    1788              : 
    1789              : /* Returns nonzero iff TYPE1 and TYPE2 are the same type, ignoring
    1790              :    top-level qualifiers.  */
    1791              : 
    1792              : bool
    1793   4559499287 : same_type_ignoring_top_level_qualifiers_p (tree type1, tree type2)
    1794              : {
    1795   4559499287 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1796              :     return false;
    1797   4559499276 :   if (type1 == type2)
    1798              :     return true;
    1799              : 
    1800   2531248700 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1801   2531248700 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1802   2531248700 :   return same_type_p (type1, type2);
    1803              : }
    1804              : 
    1805              : /* Returns nonzero iff TYPE1 and TYPE2 are similar, as per [conv.qual].  */
    1806              : 
    1807              : bool
    1808    391047511 : similar_type_p (tree type1, tree type2)
    1809              : {
    1810    391047511 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1811              :     return false;
    1812              : 
    1813              :   /* Informally, two types are similar if, ignoring top-level cv-qualification:
    1814              :      * they are the same type; or
    1815              :      * they are both pointers, and the pointed-to types are similar; or
    1816              :      * they are both pointers to member of the same class, and the types of
    1817              :        the pointed-to members are similar; or
    1818              :      * they are both arrays of the same size or both arrays of unknown bound,
    1819              :        and the array element types are similar.  */
    1820              : 
    1821    391047511 :   if (same_type_ignoring_top_level_qualifiers_p (type1, type2))
    1822              :     return true;
    1823              : 
    1824    161426778 :   if ((TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
    1825    161158225 :       || (TYPE_PTRDATAMEM_P (type1) && TYPE_PTRDATAMEM_P (type2))
    1826    161156359 :       || (TREE_CODE (type1) == ARRAY_TYPE && TREE_CODE (type2) == ARRAY_TYPE))
    1827       273301 :     return comp_ptr_ttypes_const (type1, type2, bounds_either);
    1828              : 
    1829              :   return false;
    1830              : }
    1831              : 
    1832              : /* Helper function for layout_compatible_type_p and
    1833              :    is_corresponding_member_aggr.  Advance to next members (NULL if
    1834              :    no further ones) and return true if those members are still part of
    1835              :    the common initial sequence.  */
    1836              : 
    1837              : bool
    1838         2210 : next_common_initial_sequence (tree &memb1, tree &memb2)
    1839              : {
    1840         2733 :   while (memb1)
    1841              :     {
    1842         2772 :       if (TREE_CODE (memb1) != FIELD_DECL
    1843         2313 :           || (DECL_FIELD_IS_BASE (memb1) && is_empty_field (memb1)))
    1844              :         {
    1845          459 :           memb1 = DECL_CHAIN (memb1);
    1846          459 :           continue;
    1847              :         }
    1848         1854 :       if (DECL_FIELD_IS_BASE (memb1))
    1849              :         {
    1850           64 :           memb1 = TYPE_FIELDS (TREE_TYPE (memb1));
    1851           64 :           continue;
    1852              :         }
    1853              :       break;
    1854              :     }
    1855         2694 :   while (memb2)
    1856              :     {
    1857         2730 :       if (TREE_CODE (memb2) != FIELD_DECL
    1858         2274 :           || (DECL_FIELD_IS_BASE (memb2) && is_empty_field (memb2)))
    1859              :         {
    1860          456 :           memb2 = DECL_CHAIN (memb2);
    1861          456 :           continue;
    1862              :         }
    1863         1818 :       if (DECL_FIELD_IS_BASE (memb2))
    1864              :         {
    1865           28 :           memb2 = TYPE_FIELDS (TREE_TYPE (memb2));
    1866           28 :           continue;
    1867              :         }
    1868              :       break;
    1869              :     }
    1870         2210 :   if (memb1 == NULL_TREE && memb2 == NULL_TREE)
    1871              :     return true;
    1872         1790 :   if (memb1 == NULL_TREE || memb2 == NULL_TREE)
    1873              :     return false;
    1874         1790 :   if (DECL_BIT_FIELD_TYPE (memb1))
    1875              :     {
    1876          165 :       if (!DECL_BIT_FIELD_TYPE (memb2))
    1877              :         return false;
    1878           66 :       if (!layout_compatible_type_p (DECL_BIT_FIELD_TYPE (memb1),
    1879           66 :                                      DECL_BIT_FIELD_TYPE (memb2)))
    1880              :         return false;
    1881           66 :       if (TYPE_PRECISION (TREE_TYPE (memb1))
    1882           66 :           != TYPE_PRECISION (TREE_TYPE (memb2)))
    1883              :         return false;
    1884              :     }
    1885         1625 :   else if (DECL_BIT_FIELD_TYPE (memb2))
    1886              :     return false;
    1887         1598 :   else if (!layout_compatible_type_p (TREE_TYPE (memb1), TREE_TYPE (memb2)))
    1888              :     return false;
    1889         1598 :   if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1)))
    1890         1598 :       != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2)))
    1891              :     return false;
    1892         1571 :   if (DECL_ALIGN (memb1) != DECL_ALIGN (memb2))
    1893              :     return false;
    1894         1512 :   if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2)))
    1895              :     return false;
    1896              :   return true;
    1897              : }
    1898              : 
    1899              : /* Return true if TYPE1 and TYPE2 are layout-compatible types.  */
    1900              : 
    1901              : bool
    1902         2773 : layout_compatible_type_p (tree type1, tree type2, bool explain/*=false*/)
    1903              : {
    1904         2773 :   if (type1 == error_mark_node || type2 == error_mark_node)
    1905              :     return false;
    1906         2773 :   if (type1 == type2)
    1907              :     return true;
    1908              : 
    1909         1359 :   type1 = cp_build_qualified_type (type1, TYPE_UNQUALIFIED);
    1910         1359 :   type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED);
    1911         1359 :   if (same_type_p (type1, type2))
    1912              :     return true;
    1913              : 
    1914          654 :   if (TREE_CODE (type1) != TREE_CODE (type2)
    1915          602 :       || (TREE_CODE (type1) != ENUMERAL_TYPE
    1916          564 :           && !CLASS_TYPE_P (type1))
    1917         1107 :       || (TREE_CODE (type2) != ENUMERAL_TYPE
    1918          415 :           && !CLASS_TYPE_P (type2)))
    1919              :     {
    1920          201 :       if (explain)
    1921            6 :         inform (input_location, "%q#T and %q#T are not both the same type, "
    1922              :                 "layout-compatible enumerations, or "
    1923              :                 "layout-compatible standard-layout class types",
    1924              :                 type1, type2);
    1925              :       return false;
    1926              :     }
    1927              : 
    1928          453 :   if (!std_layout_type_p (type1))
    1929              :     {
    1930           16 :       if (explain)
    1931            3 :         inform (location_of (type1),
    1932              :                 "%qT is not a standard-layout type", type1);
    1933              :       return false;
    1934              :     }
    1935          437 :   if (!std_layout_type_p (type2))
    1936              :     {
    1937            0 :       if (explain)
    1938            0 :         inform (location_of (type2),
    1939              :                 "%qT is not a standard-layout type", type2);
    1940              :       return false;
    1941              :     }
    1942              : 
    1943          437 :   if (TREE_CODE (type1) == ENUMERAL_TYPE)
    1944              :     {
    1945           38 :       tree underlying1 = finish_underlying_type (type1);
    1946           38 :       tree underlying2 = finish_underlying_type (type2);
    1947           38 :       if (!same_type_p (underlying1, underlying2))
    1948              :         {
    1949           25 :           if (explain)
    1950              :             {
    1951            3 :               inform (location_of (type1),
    1952              :                       "the underlying type of %qT is %qT, but",
    1953              :                       type1, underlying1);
    1954            3 :               inform (location_of (type2),
    1955              :                       "the underlying type of %qT is %qT",
    1956              :                       type2, underlying2);
    1957              :             }
    1958              :           return false;
    1959              :         }
    1960              :     }
    1961          399 :   else if (TREE_CODE (type1) == RECORD_TYPE)
    1962              :     {
    1963          315 :       tree field1 = TYPE_FIELDS (type1);
    1964          315 :       tree field2 = TYPE_FIELDS (type2);
    1965         1179 :       while (1)
    1966              :         {
    1967          747 :           if (!next_common_initial_sequence (field1, field2))
    1968              :             {
    1969           27 :               if (explain)
    1970              :                 {
    1971            6 :                   if (field1 && field2)
    1972              :                     {
    1973            6 :                       inform (DECL_SOURCE_LOCATION (field1),
    1974              :                               "%qD and %qD do not correspond",
    1975              :                               field1, field2);
    1976            6 :                       inform (DECL_SOURCE_LOCATION (field2),
    1977              :                               "%qD declared here", field2);
    1978              :                     }
    1979            0 :                   else if (field1)
    1980            0 :                     inform (DECL_SOURCE_LOCATION (field1),
    1981              :                             "%qT has no member corresponding to %qD",
    1982              :                             type2, field1);
    1983            0 :                   else if (field2)
    1984            0 :                     inform (DECL_SOURCE_LOCATION (field2),
    1985              :                             "%qT has no member corresponding to %qD",
    1986              :                             type1, field2);
    1987              :                 }
    1988           27 :               return false;
    1989              :             }
    1990          720 :           if (field1 == NULL_TREE)
    1991              :             break;
    1992          432 :           field1 = DECL_CHAIN (field1);
    1993          432 :           field2 = DECL_CHAIN (field2);
    1994              :         }
    1995              :     }
    1996           84 :   else if (TREE_CODE (type1) == UNION_TYPE)
    1997              :     {
    1998              :       /* The standard says:
    1999              :          "Two standard-layout unions are layout-compatible if they have
    2000              :          the same number of non-static data members and corresponding
    2001              :          non-static data members (in any order) have layout-compatible
    2002              :          types."
    2003              :          but the code anticipates that bitfield vs. non-bitfield,
    2004              :          different bitfield widths or presence/absence of
    2005              :          [[no_unique_address]] should be checked as well.  */
    2006           84 :       tree field1 = TYPE_FIELDS (type1);
    2007           84 :       tree field2 = TYPE_FIELDS (type2);
    2008           84 :       auto_vec<tree, 16> vec;
    2009           84 :       unsigned int count = 0;
    2010          378 :       for (; field1; field1 = DECL_CHAIN (field1))
    2011          294 :         if (TREE_CODE (field1) == FIELD_DECL)
    2012          195 :           count++;
    2013          372 :       for (; field2; field2 = DECL_CHAIN (field2))
    2014          288 :         if (TREE_CODE (field2) == FIELD_DECL)
    2015          189 :           vec.safe_push (field2);
    2016              : 
    2017              :       /* Discussions on core lean towards treating multiple union fields
    2018              :          of the same type as the same field, so this might need changing
    2019              :          in the future.  */
    2020          168 :       if (count != vec.length ())
    2021              :         {
    2022            6 :           if (explain)
    2023              :             {
    2024            3 :               inform_n (location_of (type1), count,
    2025              :                         "%qT has %u field, but",
    2026              :                         "%qT has %u fields, but",
    2027              :                         type1, count);
    2028            6 :               inform_n (location_of (type2), vec.length (),
    2029              :                         "%qT has %u field",
    2030              :                         "%qT has %u fields",
    2031              :                         type2, vec.length ());
    2032              :             }
    2033              :           return false;
    2034              :         }
    2035              : 
    2036          324 :       for (field1 = TYPE_FIELDS (type1); field1; field1 = DECL_CHAIN (field1))
    2037              :         {
    2038          258 :           if (TREE_CODE (field1) != FIELD_DECL)
    2039           81 :             continue;
    2040          177 :           unsigned int j;
    2041          177 :           tree t1 = DECL_BIT_FIELD_TYPE (field1);
    2042          177 :           if (t1 == NULL_TREE)
    2043          174 :             t1 = TREE_TYPE (field1);
    2044          474 :           FOR_EACH_VEC_ELT (vec, j, field2)
    2045              :             {
    2046          285 :               tree t2 = DECL_BIT_FIELD_TYPE (field2);
    2047          285 :               if (t2 == NULL_TREE)
    2048          273 :                 t2 = TREE_TYPE (field2);
    2049          285 :               if (DECL_BIT_FIELD_TYPE (field1))
    2050              :                 {
    2051            6 :                   if (!DECL_BIT_FIELD_TYPE (field2))
    2052            0 :                     continue;
    2053            6 :                   if (TYPE_PRECISION (TREE_TYPE (field1))
    2054            6 :                       != TYPE_PRECISION (TREE_TYPE (field2)))
    2055            6 :                     continue;
    2056              :                 }
    2057          279 :               else if (DECL_BIT_FIELD_TYPE (field2))
    2058            6 :                 continue;
    2059          273 :               if (!layout_compatible_type_p (t1, t2))
    2060          108 :                 continue;
    2061          165 :               if ((!lookup_attribute ("no_unique_address",
    2062          165 :                                       DECL_ATTRIBUTES (field1)))
    2063          165 :                   != !lookup_attribute ("no_unique_address",
    2064          165 :                                         DECL_ATTRIBUTES (field2)))
    2065            0 :                 continue;
    2066              :               break;
    2067              :             }
    2068          354 :           if (j == vec.length ())
    2069              :             {
    2070           12 :               if (explain)
    2071              :                 {
    2072            3 :                   inform (DECL_SOURCE_LOCATION (field1),
    2073              :                           "%qT has no member corresponding to %qD",
    2074              :                           type2, field1);
    2075            3 :                   inform (location_of (type2), "%qT declared here", type2);
    2076              :                 }
    2077              :               return false;
    2078              :             }
    2079          165 :           vec.unordered_remove (j);
    2080              :         }
    2081           84 :     }
    2082              :   else
    2083            0 :     gcc_unreachable ();
    2084              : 
    2085              :   return true;
    2086              : }
    2087              : 
    2088              : /* Returns 1 if TYPE1 is at least as qualified as TYPE2.  */
    2089              : 
    2090              : bool
    2091    252964988 : at_least_as_qualified_p (const_tree type1, const_tree type2)
    2092              : {
    2093    252964988 :   int q1 = cp_type_quals (type1);
    2094    252964988 :   int q2 = cp_type_quals (type2);
    2095              : 
    2096              :   /* All qualifiers for TYPE2 must also appear in TYPE1.  */
    2097    252964988 :   return (q1 & q2) == q2;
    2098              : }
    2099              : 
    2100              : /* Returns 1 if TYPE1 is more cv-qualified than TYPE2, -1 if TYPE2 is
    2101              :    more cv-qualified that TYPE1, and 0 otherwise.  */
    2102              : 
    2103              : int
    2104     15236462 : comp_cv_qualification (int q1, int q2)
    2105              : {
    2106     15236462 :   if (q1 == q2)
    2107              :     return 0;
    2108              : 
    2109      3429176 :   if ((q1 & q2) == q2)
    2110              :     return 1;
    2111       364790 :   else if ((q1 & q2) == q1)
    2112       364205 :     return -1;
    2113              : 
    2114              :   return 0;
    2115              : }
    2116              : 
    2117              : int
    2118            0 : comp_cv_qualification (const_tree type1, const_tree type2)
    2119              : {
    2120            0 :   int q1 = cp_type_quals (type1);
    2121            0 :   int q2 = cp_type_quals (type2);
    2122            0 :   return comp_cv_qualification (q1, q2);
    2123              : }
    2124              : 
    2125              : /* Returns 1 if the cv-qualification signature of TYPE1 is a proper
    2126              :    subset of the cv-qualification signature of TYPE2, and the types
    2127              :    are similar.  Returns -1 if the other way 'round, and 0 otherwise.  */
    2128              : 
    2129              : int
    2130          385 : comp_cv_qual_signature (tree type1, tree type2)
    2131              : {
    2132          385 :   if (comp_ptr_ttypes_real (type2, type1, -1))
    2133              :     return 1;
    2134          311 :   else if (comp_ptr_ttypes_real (type1, type2, -1))
    2135              :     return -1;
    2136              :   else
    2137          299 :     return 0;
    2138              : }
    2139              : 
    2140              : /* Subroutines of `comptypes'.  */
    2141              : 
    2142              : /* Return true if two parameter type lists PARMS1 and PARMS2 are
    2143              :    equivalent in the sense that functions with those parameter types
    2144              :    can have equivalent types.  The two lists must be equivalent,
    2145              :    element by element.  */
    2146              : 
    2147              : bool
    2148   1126572678 : compparms (const_tree parms1, const_tree parms2)
    2149              : {
    2150   1126572678 :   const_tree t1, t2;
    2151              : 
    2152              :   /* An unspecified parmlist matches any specified parmlist
    2153              :      whose argument types don't need default promotions.  */
    2154              : 
    2155   1126572678 :   for (t1 = parms1, t2 = parms2;
    2156   1786271872 :        t1 || t2;
    2157    659699194 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2158              :     {
    2159              :       /* If one parmlist is shorter than the other,
    2160              :          they fail to match.  */
    2161   1670347451 :       if (!t1 || !t2)
    2162              :         return false;
    2163   1669753460 :       if (!same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2164              :         return false;
    2165              :     }
    2166              :   return true;
    2167              : }
    2168              : 
    2169              : 
    2170              : /* Process a sizeof or alignof expression where the operand is a type.
    2171              :    STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
    2172              :    or GNU (preferred alignment) semantics; it is ignored if OP is
    2173              :    SIZEOF_EXPR.  */
    2174              : 
    2175              : tree
    2176     30408142 : cxx_sizeof_or_alignof_type (location_t loc, tree type, enum tree_code op,
    2177              :                             bool std_alignof, bool complain)
    2178              : {
    2179     30408142 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2180     30408142 :   if (type == error_mark_node)
    2181              :     return error_mark_node;
    2182              : 
    2183     30408140 :   type = non_reference (type);
    2184     30408140 :   if (TREE_CODE (type) == METHOD_TYPE)
    2185              :     {
    2186            0 :       if (complain)
    2187              :         {
    2188            0 :           pedwarn (loc, OPT_Wpointer_arith,
    2189              :                    "invalid application of %qs to a member function",
    2190            0 :                    OVL_OP_INFO (false, op)->name);
    2191            0 :           return size_one_node;
    2192              :         }
    2193              :       else
    2194            0 :         return error_mark_node;
    2195              :     }
    2196     30408140 :   else if (VOID_TYPE_P (type) && std_alignof)
    2197              :     {
    2198           12 :       if (complain)
    2199           12 :         error_at (loc, "invalid application of %qs to a void type",
    2200           12 :                   OVL_OP_INFO (false, op)->name);
    2201           12 :       return error_mark_node;
    2202              :     }
    2203              : 
    2204     30408128 :   bool dependent_p = dependent_type_p (type);
    2205     30408128 :   if (!dependent_p)
    2206              :     {
    2207     25297459 :       complete_type (type);
    2208     25297459 :       if (!COMPLETE_TYPE_P (type))
    2209              :         /* Call this here because the incompleteness diagnostic comes from
    2210              :            c_sizeof_or_alignof_type instead of
    2211              :            complete_type_or_maybe_complain.  */
    2212          288 :         note_failed_type_completion (type, complain);
    2213              :     }
    2214     25297459 :   if (dependent_p
    2215              :       /* VLA types will have a non-constant size.  In the body of an
    2216              :          uninstantiated template, we don't need to try to compute the
    2217              :          value, because the sizeof expression is not an integral
    2218              :          constant expression in that case.  And, if we do try to
    2219              :          compute the value, we'll likely end up with SAVE_EXPRs, which
    2220              :          the template substitution machinery does not expect to see.  */
    2221     25297459 :       || (processing_template_decl
    2222      2328284 :           && COMPLETE_TYPE_P (type)
    2223      2328278 :           && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
    2224              :     {
    2225      5110669 :       tree value = build_min (op, size_type_node, type);
    2226      5110669 :       TREE_READONLY (value) = 1;
    2227      5110669 :       if (op == ALIGNOF_EXPR && std_alignof)
    2228       582823 :         ALIGNOF_EXPR_STD_P (value) = true;
    2229      5110669 :       SET_EXPR_LOCATION (value, loc);
    2230      5110669 :       return value;
    2231              :     }
    2232              : 
    2233     25297459 :   return c_sizeof_or_alignof_type (loc, complete_type (type),
    2234              :                                    op == SIZEOF_EXPR, std_alignof,
    2235     25297459 :                                    complain & (tf_warning_or_error));
    2236              : }
    2237              : 
    2238              : /* Return the size of the type, without producing any warnings for
    2239              :    types whose size cannot be taken.  This routine should be used only
    2240              :    in some other routine that has already produced a diagnostic about
    2241              :    using the size of such a type.  */
    2242              : tree
    2243      2870197 : cxx_sizeof_nowarn (tree type)
    2244              : {
    2245      2870197 :   if (TREE_CODE (type) == FUNCTION_TYPE
    2246      2870197 :       || VOID_TYPE_P (type)
    2247      2870115 :       || TREE_CODE (type) == ERROR_MARK)
    2248           82 :     return size_one_node;
    2249      2870115 :   else if (!COMPLETE_TYPE_P (type))
    2250           25 :     return size_zero_node;
    2251              :   else
    2252      2870090 :     return cxx_sizeof_or_alignof_type (input_location, type,
    2253      2870090 :                                        SIZEOF_EXPR, false, false);
    2254              : }
    2255              : 
    2256              : /* Process a sizeof expression where the operand is an expression.  */
    2257              : 
    2258              : static tree
    2259      1335427 : cxx_sizeof_expr (location_t loc, tree e, tsubst_flags_t complain)
    2260              : {
    2261      1335427 :   if (e == error_mark_node)
    2262              :     return error_mark_node;
    2263              : 
    2264      1334692 :   if (instantiation_dependent_uneval_expression_p (e))
    2265              :     {
    2266       365992 :       e = build_min (SIZEOF_EXPR, size_type_node, e);
    2267       365992 :       TREE_SIDE_EFFECTS (e) = 0;
    2268       365992 :       TREE_READONLY (e) = 1;
    2269       365992 :       SET_EXPR_LOCATION (e, loc);
    2270              : 
    2271       365992 :       return e;
    2272              :     }
    2273              : 
    2274       968700 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2275       968700 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2276              : 
    2277       968700 :   if (TREE_CODE (e) == PARM_DECL
    2278        36537 :       && DECL_ARRAY_PARAMETER_P (e)
    2279       969077 :       && (complain & tf_warning))
    2280              :     {
    2281          120 :       auto_diagnostic_group d;
    2282          120 :       if (warning_at (e_loc, OPT_Wsizeof_array_argument,
    2283              :                       "%<sizeof%> on array function parameter %qE "
    2284          120 :                       "will return size of %qT", e, TREE_TYPE (e)))
    2285           24 :         inform (DECL_SOURCE_LOCATION (e), "declared here");
    2286          120 :     }
    2287              : 
    2288       968700 :   e = mark_type_use (e);
    2289              : 
    2290       968700 :   if (bitfield_p (e))
    2291              :     {
    2292           15 :       if (complain & tf_error)
    2293            6 :         error_at (e_loc,
    2294              :                   "invalid application of %<sizeof%> to a bit-field");
    2295              :       else
    2296            9 :         return error_mark_node;
    2297            6 :       e = char_type_node;
    2298              :     }
    2299       968685 :   else if (is_overloaded_fn (e))
    2300              :     {
    2301           36 :       if (complain & tf_error)
    2302           12 :         permerror (e_loc, "ISO C++ forbids applying %<sizeof%> to "
    2303              :                    "an expression of function type");
    2304              :       else
    2305           24 :         return error_mark_node;
    2306           12 :       e = char_type_node;
    2307              :     }
    2308       968649 :   else if (type_unknown_p (e))
    2309              :     {
    2310            0 :       if (complain & tf_error)
    2311            0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2312              :       else
    2313            0 :         return error_mark_node;
    2314            0 :       e = char_type_node;
    2315              :     }
    2316              :   else
    2317       968649 :     e = TREE_TYPE (e);
    2318              : 
    2319       968667 :   return cxx_sizeof_or_alignof_type (loc, e, SIZEOF_EXPR, false,
    2320       968667 :                                      complain & tf_error);
    2321              : }
    2322              : 
    2323              : /* Implement the __alignof keyword: Return the minimum required
    2324              :    alignment of E, measured in bytes.  For VAR_DECL's and
    2325              :    FIELD_DECL's return DECL_ALIGN (which can be set from an
    2326              :    "aligned" __attribute__ specification).  STD_ALIGNOF acts
    2327              :    like in cxx_sizeof_or_alignof_type.  */
    2328              : 
    2329              : static tree
    2330       101101 : cxx_alignof_expr (location_t loc, tree e, bool std_alignof,
    2331              :                   tsubst_flags_t complain)
    2332              : {
    2333       101101 :   tree t;
    2334              : 
    2335       101101 :   if (e == error_mark_node)
    2336              :     return error_mark_node;
    2337              : 
    2338       101093 :   if (processing_template_decl)
    2339              :     {
    2340        19266 :       e = build_min (ALIGNOF_EXPR, size_type_node, e);
    2341        19266 :       TREE_SIDE_EFFECTS (e) = 0;
    2342        19266 :       TREE_READONLY (e) = 1;
    2343        19266 :       SET_EXPR_LOCATION (e, loc);
    2344        19266 :       ALIGNOF_EXPR_STD_P (e) = std_alignof;
    2345              : 
    2346        19266 :       return e;
    2347              :     }
    2348              : 
    2349        81827 :   location_t e_loc = cp_expr_loc_or_loc (e, loc);
    2350        81827 :   STRIP_ANY_LOCATION_WRAPPER (e);
    2351              : 
    2352        81827 :   e = mark_type_use (e);
    2353              : 
    2354        81827 :   if (!verify_type_context (loc, TCTX_ALIGNOF, TREE_TYPE (e),
    2355        81827 :                             !(complain & tf_error)))
    2356              :     {
    2357            0 :       if (!(complain & tf_error))
    2358            0 :         return error_mark_node;
    2359            0 :       t = size_one_node;
    2360              :     }
    2361        81827 :   else if (VAR_P (e))
    2362        12390 :     t = size_int (DECL_ALIGN_UNIT (e));
    2363        69437 :   else if (bitfield_p (e))
    2364              :     {
    2365            6 :       if (complain & tf_error)
    2366            6 :         error_at (e_loc,
    2367              :                   "invalid application of %<__alignof%> to a bit-field");
    2368              :       else
    2369            0 :         return error_mark_node;
    2370            6 :       t = size_one_node;
    2371              :     }
    2372        69431 :   else if (TREE_CODE (e) == COMPONENT_REF
    2373        69431 :            && TREE_CODE (TREE_OPERAND (e, 1)) == FIELD_DECL)
    2374        37792 :     t = size_int (DECL_ALIGN_UNIT (TREE_OPERAND (e, 1)));
    2375        31639 :   else if (is_overloaded_fn (e))
    2376              :     {
    2377            6 :       if (complain & tf_error)
    2378            6 :         permerror (e_loc, "ISO C++ forbids applying %<__alignof%> to "
    2379              :                    "an expression of function type");
    2380              :       else
    2381            0 :         return error_mark_node;
    2382            6 :       if (TREE_CODE (e) == FUNCTION_DECL)
    2383            3 :         t = size_int (DECL_ALIGN_UNIT (e));
    2384              :       else
    2385            3 :         t = size_one_node;
    2386              :     }
    2387        31633 :   else if (type_unknown_p (e))
    2388              :     {
    2389            0 :       if (complain & tf_error)
    2390            0 :         cxx_incomplete_type_error (e_loc, e, TREE_TYPE (e));
    2391              :       else
    2392            0 :         return error_mark_node;
    2393            0 :       t = size_one_node;
    2394              :     }
    2395              :   else
    2396        31633 :     return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
    2397              :                                        ALIGNOF_EXPR, std_alignof,
    2398        31633 :                                        complain & tf_error);
    2399              : 
    2400        50194 :   return fold_convert_loc (loc, size_type_node, t);
    2401              : }
    2402              : 
    2403              : /* Process a sizeof or alignof expression E with code OP where the operand
    2404              :    is an expression. STD_ALIGNOF acts like in cxx_sizeof_or_alignof_type.  */
    2405              : 
    2406              : tree
    2407      1436528 : cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
    2408              :                             bool std_alignof, bool complain)
    2409              : {
    2410      1436528 :   gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
    2411      1436528 :   if (op == SIZEOF_EXPR)
    2412      1955768 :     return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
    2413              :   else
    2414       101128 :     return cxx_alignof_expr (loc, e, std_alignof,
    2415       101101 :                              complain? tf_warning_or_error : tf_none);
    2416              : }
    2417              : 
    2418              : /*  Build a representation of an expression 'alignas(E).'  Return the
    2419              :     folded integer value of E if it is an integral constant expression
    2420              :     that resolves to a valid alignment.  If E depends on a template
    2421              :     parameter, return a syntactic representation tree of kind
    2422              :     ALIGNOF_EXPR.  Otherwise, return an error_mark_node if the
    2423              :     expression is ill formed, or NULL_TREE if E is NULL_TREE.  */
    2424              : 
    2425              : tree
    2426       277239 : cxx_alignas_expr (tree e)
    2427              : {
    2428       277239 :   if (e == NULL_TREE || e == error_mark_node
    2429       554478 :       || (!TYPE_P (e) && !require_potential_rvalue_constant_expression (e)))
    2430              :     return e;
    2431              : 
    2432       277239 :   if (TYPE_P (e))
    2433              :     /* [dcl.align]/3:
    2434              : 
    2435              :            When the alignment-specifier is of the form
    2436              :            alignas(type-id), it shall have the same effect as
    2437              :            alignas(alignof(type-id)).  */
    2438              : 
    2439       145702 :     return cxx_sizeof_or_alignof_type (input_location,
    2440              :                                        e, ALIGNOF_EXPR,
    2441              :                                        /*std_alignof=*/true,
    2442       145702 :                                        /*complain=*/true);
    2443              : 
    2444              :   /* If we reach this point, it means the alignas expression if of
    2445              :      the form "alignas(assignment-expression)", so we should follow
    2446              :      what is stated by [dcl.align]/2.  */
    2447              : 
    2448       131537 :   if (value_dependent_expression_p (e))
    2449              :     /* Leave value-dependent expression alone for now. */
    2450              :     return e;
    2451              : 
    2452        67890 :   e = instantiate_non_dependent_expr (e);
    2453        67890 :   e = mark_rvalue_use (e);
    2454              : 
    2455              :   /* [dcl.align]/2 says:
    2456              : 
    2457              :          the assignment-expression shall be an integral constant
    2458              :          expression.  */
    2459              : 
    2460        67890 :   if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (e)))
    2461              :     {
    2462           18 :       error ("%<alignas%> argument has non-integral type %qT", TREE_TYPE (e));
    2463           18 :       return error_mark_node;
    2464              :     }
    2465              : 
    2466        67872 :   return cxx_constant_value (e);
    2467              : }
    2468              : 
    2469              : 
    2470              : /* EXPR is being used in a context that is not a function call.
    2471              :    Enforce:
    2472              : 
    2473              :      [expr.ref]
    2474              : 
    2475              :      The expression can be used only as the left-hand operand of a
    2476              :      member function call.
    2477              : 
    2478              :      [expr.mptr.operator]
    2479              : 
    2480              :      If the result of .* or ->* is a function, then that result can be
    2481              :      used only as the operand for the function call operator ().
    2482              : 
    2483              :    by issuing an error message if appropriate.  Returns true iff EXPR
    2484              :    violates these rules.  */
    2485              : 
    2486              : bool
    2487   1549237891 : invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
    2488              : {
    2489   1549237891 :   if (expr == NULL_TREE)
    2490              :     return false;
    2491              :   /* Don't enforce this in MS mode.  */
    2492   1549236441 :   if (flag_ms_extensions)
    2493              :     return false;
    2494   1549228380 :   if (is_overloaded_fn (expr) && !really_overloaded_fn (expr))
    2495    129296492 :     expr = get_first_fn (expr);
    2496   1549228380 :   if (TREE_TYPE (expr)
    2497   1549228380 :       && DECL_IOBJ_MEMBER_FUNCTION_P (expr))
    2498              :     {
    2499           96 :       if (complain & tf_error)
    2500              :         {
    2501           88 :           if (DECL_P (expr))
    2502              :             {
    2503           70 :               auto_diagnostic_group d;
    2504           70 :               error_at (loc, "invalid use of non-static member function %qD",
    2505              :                         expr);
    2506           70 :               inform (DECL_SOURCE_LOCATION (expr), "declared here");
    2507           70 :             }
    2508              :           else
    2509           18 :             error_at (loc, "invalid use of non-static member function of "
    2510           18 :                       "type %qT", TREE_TYPE (expr));
    2511              :         }
    2512              :       return true;
    2513              :     }
    2514              :   return false;
    2515              : }
    2516              : 
    2517              : /* If EXP is a reference to a bit-field, and the type of EXP does not
    2518              :    match the declared type of the bit-field, return the declared type
    2519              :    of the bit-field.  Otherwise, return NULL_TREE.  */
    2520              : 
    2521              : tree
    2522   3722905130 : is_bitfield_expr_with_lowered_type (const_tree exp)
    2523              : {
    2524   5077135713 :   switch (TREE_CODE (exp))
    2525              :     {
    2526      9724762 :     case COND_EXPR:
    2527     19449524 :       if (!is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1)
    2528      9724736 :                                                ? TREE_OPERAND (exp, 1)
    2529           26 :                                                : TREE_OPERAND (exp, 0)))
    2530              :         return NULL_TREE;
    2531          150 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 2));
    2532              : 
    2533      1091503 :     case COMPOUND_EXPR:
    2534      1091503 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 1));
    2535              : 
    2536    444552990 :     case MODIFY_EXPR:
    2537    444552990 :     case SAVE_EXPR:
    2538    444552990 :     case UNARY_PLUS_EXPR:
    2539    444552990 :     case PREDECREMENT_EXPR:
    2540    444552990 :     case PREINCREMENT_EXPR:
    2541    444552990 :     case POSTDECREMENT_EXPR:
    2542    444552990 :     case POSTINCREMENT_EXPR:
    2543    444552990 :     case NEGATE_EXPR:
    2544    444552990 :     case NON_LVALUE_EXPR:
    2545    444552990 :     case BIT_NOT_EXPR:
    2546    444552990 :     case CLEANUP_POINT_EXPR:
    2547    444552990 :       return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2548              : 
    2549    270002329 :     case COMPONENT_REF:
    2550    270002329 :       {
    2551    270002329 :         tree field;
    2552              : 
    2553    270002329 :         field = TREE_OPERAND (exp, 1);
    2554    270002329 :         if (TREE_CODE (field) != FIELD_DECL || !DECL_BIT_FIELD_TYPE (field))
    2555              :           return NULL_TREE;
    2556     22639746 :         if (same_type_ignoring_top_level_qualifiers_p
    2557     22639746 :             (TREE_TYPE (exp), DECL_BIT_FIELD_TYPE (field)))
    2558              :           return NULL_TREE;
    2559     22471796 :         return DECL_BIT_FIELD_TYPE (field);
    2560              :       }
    2561              : 
    2562    688258537 :     case VAR_DECL:
    2563    688258537 :       if (DECL_HAS_VALUE_EXPR_P (exp))
    2564      1387572 :         return is_bitfield_expr_with_lowered_type (DECL_VALUE_EXPR
    2565      1387572 :                                                    (const_cast<tree> (exp)));
    2566              :       return NULL_TREE;
    2567              : 
    2568    914290564 :     case VIEW_CONVERT_EXPR:
    2569    914290564 :       if (location_wrapper_p (exp))
    2570    907198368 :         return is_bitfield_expr_with_lowered_type (TREE_OPERAND (exp, 0));
    2571              :       else
    2572              :         return NULL_TREE;
    2573              : 
    2574              :     default:
    2575              :       return NULL_TREE;
    2576              :     }
    2577              : }
    2578              : 
    2579              : /* Like is_bitfield_with_lowered_type, except that if EXP is not a
    2580              :    bitfield with a lowered type, the type of EXP is returned, rather
    2581              :    than NULL_TREE.  */
    2582              : 
    2583              : tree
    2584   1780073951 : unlowered_expr_type (const_tree exp)
    2585              : {
    2586   1780073951 :   tree type;
    2587   1780073951 :   tree etype = TREE_TYPE (exp);
    2588              : 
    2589   1780073951 :   type = is_bitfield_expr_with_lowered_type (exp);
    2590   1780073951 :   if (type)
    2591     18049279 :     type = cp_build_qualified_type (type, cp_type_quals (etype));
    2592              :   else
    2593              :     type = etype;
    2594              : 
    2595   1780073951 :   return type;
    2596              : }
    2597              : 
    2598              : /* Perform the conversions in [expr] that apply when an lvalue appears
    2599              :    in an rvalue context: the lvalue-to-rvalue, array-to-pointer, and
    2600              :    function-to-pointer conversions.  In addition, bitfield references are
    2601              :    converted to their declared types. Note that this function does not perform
    2602              :    the lvalue-to-rvalue conversion for class types. If you need that conversion
    2603              :    for class types, then you probably need to use force_rvalue.
    2604              : 
    2605              :    Although the returned value is being used as an rvalue, this
    2606              :    function does not wrap the returned expression in a
    2607              :    NON_LVALUE_EXPR; the caller is expected to be mindful of the fact
    2608              :    that the return value is no longer an lvalue.  */
    2609              : 
    2610              : tree
    2611   1227201127 : decay_conversion (tree exp,
    2612              :                   tsubst_flags_t complain,
    2613              :                   bool reject_builtin /* = true */)
    2614              : {
    2615   1227201127 :   tree type;
    2616   1227201127 :   enum tree_code code;
    2617   1227201127 :   location_t loc = cp_expr_loc_or_input_loc (exp);
    2618              : 
    2619   1227201127 :   type = TREE_TYPE (exp);
    2620   1227201127 :   if (type == error_mark_node)
    2621              :     return error_mark_node;
    2622              : 
    2623   1227200913 :   exp = resolve_nondeduced_context_or_error (exp, complain);
    2624              : 
    2625   1227200913 :   code = TREE_CODE (type);
    2626              : 
    2627   1227200913 :   if (error_operand_p (exp))
    2628           90 :     return error_mark_node;
    2629              : 
    2630   1227200823 :   if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp))
    2631              :     {
    2632      1772741 :       mark_rvalue_use (exp, loc, reject_builtin);
    2633      1772741 :       return nullptr_node;
    2634              :     }
    2635              : 
    2636              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    2637              :      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
    2638   1225428082 :   if (code == VOID_TYPE)
    2639              :     {
    2640         5810 :       if (complain & tf_error)
    2641            3 :         error_at (loc, "void value not ignored as it ought to be");
    2642         5810 :       return error_mark_node;
    2643              :     }
    2644   1225422272 :   if (invalid_nonstatic_memfn_p (loc, exp, complain))
    2645            6 :     return error_mark_node;
    2646   1225422266 :   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
    2647              :     {
    2648    134908190 :       exp = mark_lvalue_use (exp);
    2649    134908190 :       if (reject_builtin && reject_gcc_builtin (exp, loc))
    2650          109 :         return error_mark_node;
    2651    134908081 :       return cp_build_addr_expr (exp, complain);
    2652              :     }
    2653   1090514076 :   if (code == ARRAY_TYPE)
    2654              :     {
    2655      6863916 :       tree adr;
    2656      6863916 :       tree ptrtype;
    2657              : 
    2658      6863916 :       exp = mark_lvalue_use (exp);
    2659              : 
    2660      6863916 :       if (INDIRECT_REF_P (exp))
    2661       165819 :         return build_nop (build_pointer_type (TREE_TYPE (type)),
    2662       331638 :                           TREE_OPERAND (exp, 0));
    2663              : 
    2664      6698097 :       if (TREE_CODE (exp) == COMPOUND_EXPR)
    2665              :         {
    2666            3 :           tree op1 = decay_conversion (TREE_OPERAND (exp, 1), complain);
    2667            3 :           if (op1 == error_mark_node)
    2668              :             return error_mark_node;
    2669            3 :           return build2 (COMPOUND_EXPR, TREE_TYPE (op1),
    2670            6 :                          TREE_OPERAND (exp, 0), op1);
    2671              :         }
    2672              : 
    2673      6698094 :       if (!obvalue_p (exp)
    2674      6698094 :           && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
    2675              :         {
    2676            0 :           if (complain & tf_error)
    2677            0 :             error_at (loc, "invalid use of non-lvalue array");
    2678            0 :           return error_mark_node;
    2679              :         }
    2680              : 
    2681      6698094 :       ptrtype = build_pointer_type (TREE_TYPE (type));
    2682              : 
    2683      6698094 :       if (VAR_P (exp))
    2684              :         {
    2685       577761 :           if (!cxx_mark_addressable (exp))
    2686            0 :             return error_mark_node;
    2687       577761 :           adr = build_nop (ptrtype, build_address (exp));
    2688       577761 :           return adr;
    2689              :         }
    2690              :       /* This way is better for a COMPONENT_REF since it can
    2691              :          simplify the offset for a component.  */
    2692      6120333 :       adr = cp_build_addr_expr (exp, complain);
    2693      6120333 :       return cp_convert (ptrtype, adr, complain);
    2694              :     }
    2695              : 
    2696              :   /* Otherwise, it's the lvalue-to-rvalue conversion.  */
    2697   1083650160 :   exp = mark_rvalue_use (exp, loc, reject_builtin);
    2698              : 
    2699              :   /* If a bitfield is used in a context where integral promotion
    2700              :      applies, then the caller is expected to have used
    2701              :      default_conversion.  That function promotes bitfields correctly
    2702              :      before calling this function.  At this point, if we have a
    2703              :      bitfield referenced, we may assume that is not subject to
    2704              :      promotion, and that, therefore, the type of the resulting rvalue
    2705              :      is the declared type of the bitfield.  */
    2706   1083650160 :   exp = convert_bitfield_to_declared_type (exp);
    2707              : 
    2708              :   /* We do not call rvalue() here because we do not want to wrap EXP
    2709              :      in a NON_LVALUE_EXPR.  */
    2710              : 
    2711              :   /* [basic.lval]
    2712              : 
    2713              :      Non-class rvalues always have cv-unqualified types.  */
    2714   1083650160 :   type = TREE_TYPE (exp);
    2715   1083650160 :   if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    2716    332676960 :     exp = build_nop (cv_unqualified (type), exp);
    2717              : 
    2718   1083650160 :   if (!complete_type_or_maybe_complain (type, exp, complain))
    2719           42 :     return error_mark_node;
    2720              : 
    2721              :   return exp;
    2722              : }
    2723              : 
    2724              : /* Perform preparatory conversions, as part of the "usual arithmetic
    2725              :    conversions".  In particular, as per [expr]:
    2726              : 
    2727              :      Whenever an lvalue expression appears as an operand of an
    2728              :      operator that expects the rvalue for that operand, the
    2729              :      lvalue-to-rvalue, array-to-pointer, or function-to-pointer
    2730              :      standard conversions are applied to convert the expression to an
    2731              :      rvalue.
    2732              : 
    2733              :    In addition, we perform integral promotions here, as those are
    2734              :    applied to both operands to a binary operator before determining
    2735              :    what additional conversions should apply.  */
    2736              : 
    2737              : static tree
    2738    321145306 : cp_default_conversion (tree exp, tsubst_flags_t complain)
    2739              : {
    2740              :   /* Check for target-specific promotions.  */
    2741    321145306 :   tree promoted_type = targetm.promoted_type (TREE_TYPE (exp));
    2742    321145306 :   if (promoted_type)
    2743            0 :     exp = cp_convert (promoted_type, exp, complain);
    2744              :   /* Perform the integral promotions first so that bitfield
    2745              :      expressions (which may promote to "int", even if the bitfield is
    2746              :      declared "unsigned") are promoted correctly.  */
    2747    321145306 :   else if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)))
    2748    223766067 :     exp = cp_perform_integral_promotions (exp, complain);
    2749              :   /* Perform the other conversions.  */
    2750    321145306 :   exp = decay_conversion (exp, complain);
    2751              : 
    2752    321145306 :   return exp;
    2753              : }
    2754              : 
    2755              : /* C version.  */
    2756              : 
    2757              : tree
    2758     42515213 : default_conversion (tree exp)
    2759              : {
    2760     42515213 :   return cp_default_conversion (exp, tf_warning_or_error);
    2761              : }
    2762              : 
    2763              : /* EXPR is an expression with an integral or enumeration type.
    2764              :    Perform the integral promotions in [conv.prom], and return the
    2765              :    converted value.  */
    2766              : 
    2767              : tree
    2768    230142195 : cp_perform_integral_promotions (tree expr, tsubst_flags_t complain)
    2769              : {
    2770    230142195 :   tree type;
    2771    230142195 :   tree promoted_type;
    2772              : 
    2773    230142195 :   expr = mark_rvalue_use (expr);
    2774    230142195 :   if (error_operand_p (expr))
    2775            6 :     return error_mark_node;
    2776              : 
    2777    230142189 :   type = TREE_TYPE (expr);
    2778              : 
    2779              :   /* [conv.prom]
    2780              : 
    2781              :      A prvalue for an integral bit-field (11.3.9) can be converted to a prvalue
    2782              :      of type int if int can represent all the values of the bit-field;
    2783              :      otherwise, it can be converted to unsigned int if unsigned int can
    2784              :      represent all the values of the bit-field. If the bit-field is larger yet,
    2785              :      no integral promotion applies to it. If the bit-field has an enumerated
    2786              :      type, it is treated as any other value of that type for promotion
    2787              :      purposes.  */
    2788    230142189 :   tree bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    2789    230142189 :   if (bitfield_type
    2790    230142189 :       && (TREE_CODE (bitfield_type) == ENUMERAL_TYPE
    2791       553497 :           || TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)))
    2792              :     type = bitfield_type;
    2793              : 
    2794    230142189 :   gcc_assert (INTEGRAL_OR_ENUMERATION_TYPE_P (type));
    2795              :   /* Scoped enums don't promote.  */
    2796    230142189 :   if (SCOPED_ENUM_P (type))
    2797              :     return expr;
    2798    229496745 :   promoted_type = type_promotes_to (type);
    2799    229496745 :   if (type != promoted_type)
    2800     69174320 :     expr = cp_convert (promoted_type, expr, complain);
    2801    160322425 :   else if (bitfield_type && bitfield_type != type)
    2802              :     /* Prevent decay_conversion from converting to bitfield_type.  */
    2803          159 :     expr = build_nop (type, expr);
    2804              :   return expr;
    2805              : }
    2806              : 
    2807              : /* C version.  */
    2808              : 
    2809              : tree
    2810      1876058 : perform_integral_promotions (tree expr)
    2811              : {
    2812      1876058 :   return cp_perform_integral_promotions (expr, tf_warning_or_error);
    2813              : }
    2814              : 
    2815              : /* Returns nonzero iff exp is a STRING_CST or the result of applying
    2816              :    decay_conversion to one.  */
    2817              : 
    2818              : int
    2819      3882484 : string_conv_p (const_tree totype, const_tree exp, int warn)
    2820              : {
    2821      3882484 :   tree t;
    2822              : 
    2823      3882484 :   if (!TYPE_PTR_P (totype))
    2824              :     return 0;
    2825              : 
    2826      3881593 :   t = TREE_TYPE (totype);
    2827      3881593 :   if (!same_type_p (t, char_type_node)
    2828      3732408 :       && !same_type_p (t, char8_type_node)
    2829      3669169 :       && !same_type_p (t, char16_type_node)
    2830      3617503 :       && !same_type_p (t, char32_type_node)
    2831      7447431 :       && !same_type_p (t, wchar_type_node))
    2832              :     return 0;
    2833              : 
    2834       356940 :   location_t loc = EXPR_LOC_OR_LOC (exp, input_location);
    2835              : 
    2836       356940 :   STRIP_ANY_LOCATION_WRAPPER (exp);
    2837              : 
    2838       356940 :   if (TREE_CODE (exp) == STRING_CST)
    2839              :     {
    2840              :       /* Make sure that we don't try to convert between char and wide chars.  */
    2841          108 :       if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t))
    2842              :         return 0;
    2843              :     }
    2844              :   else
    2845              :     {
    2846              :       /* Is this a string constant which has decayed to 'const char *'?  */
    2847       356832 :       t = build_pointer_type (cp_build_qualified_type (t, TYPE_QUAL_CONST));
    2848       356832 :       if (!same_type_p (TREE_TYPE (exp), t))
    2849              :         return 0;
    2850        14418 :       STRIP_NOPS (exp);
    2851        14418 :       if (TREE_CODE (exp) != ADDR_EXPR
    2852        14418 :           || TREE_CODE (TREE_OPERAND (exp, 0)) != STRING_CST)
    2853              :         return 0;
    2854              :     }
    2855          306 :   if (warn)
    2856              :     {
    2857          102 :       if (cxx_dialect >= cxx11)
    2858           87 :         pedwarn (loc, OPT_Wwrite_strings,
    2859              :                  "ISO C++ forbids converting a string constant to %qT",
    2860              :                  totype);
    2861              :       else
    2862           15 :         warning_at (loc, OPT_Wwrite_strings,
    2863              :                     "deprecated conversion from string constant to %qT",
    2864              :                     totype);
    2865              :     }
    2866              : 
    2867              :   return 1;
    2868              : }
    2869              : 
    2870              : /* Given a COND_EXPR, MIN_EXPR, or MAX_EXPR in T, return it in a form that we
    2871              :    can, for example, use as an lvalue.  This code used to be in
    2872              :    unary_complex_lvalue, but we needed it to deal with `a = (d == c) ? b : c'
    2873              :    expressions, where we're dealing with aggregates.  But now it's again only
    2874              :    called from unary_complex_lvalue.  The case (in particular) that led to
    2875              :    this was with CODE == ADDR_EXPR, since it's not an lvalue when we'd
    2876              :    get it there.  */
    2877              : 
    2878              : static tree
    2879        87219 : rationalize_conditional_expr (enum tree_code code, tree t,
    2880              :                               tsubst_flags_t complain)
    2881              : {
    2882        87219 :   location_t loc = cp_expr_loc_or_input_loc (t);
    2883              : 
    2884              :   /* For MIN_EXPR or MAX_EXPR, fold-const.cc has arranged things so that
    2885              :      the first operand is always the one to be used if both operands
    2886              :      are equal, so we know what conditional expression this used to be.  */
    2887        87219 :   if (TREE_CODE (t) == MIN_EXPR || TREE_CODE (t) == MAX_EXPR)
    2888              :     {
    2889            0 :       tree op0 = TREE_OPERAND (t, 0);
    2890            0 :       tree op1 = TREE_OPERAND (t, 1);
    2891              : 
    2892              :       /* The following code is incorrect if either operand side-effects.  */
    2893            0 :       gcc_assert (!TREE_SIDE_EFFECTS (op0)
    2894              :                   && !TREE_SIDE_EFFECTS (op1));
    2895            0 :       return
    2896            0 :         build_conditional_expr (loc,
    2897            0 :                                 build_x_binary_op (loc,
    2898            0 :                                                    (TREE_CODE (t) == MIN_EXPR
    2899              :                                                     ? LE_EXPR : GE_EXPR),
    2900            0 :                                                    op0, TREE_CODE (op0),
    2901            0 :                                                    op1, TREE_CODE (op1),
    2902              :                                                    NULL_TREE,
    2903              :                                                    /*overload=*/NULL,
    2904              :                                                    complain),
    2905              :                                 cp_build_unary_op (code, op0, false, complain),
    2906              :                                 cp_build_unary_op (code, op1, false, complain),
    2907              :                                 complain);
    2908              :     }
    2909              : 
    2910        87219 :   tree op1 = TREE_OPERAND (t, 1);
    2911        87219 :   if (TREE_CODE (op1) != THROW_EXPR)
    2912        87216 :     op1 = cp_build_unary_op (code, op1, false, complain);
    2913        87219 :   tree op2 = TREE_OPERAND (t, 2);
    2914        87219 :   if (TREE_CODE (op2) != THROW_EXPR)
    2915        87213 :     op2 = cp_build_unary_op (code, op2, false, complain);
    2916              : 
    2917        87219 :   return
    2918        87219 :     build_conditional_expr (loc, TREE_OPERAND (t, 0), op1, op2, complain);
    2919              : }
    2920              : 
    2921              : /* Given the TYPE of an anonymous union field inside T, return the
    2922              :    FIELD_DECL for the field.  If not found return NULL_TREE.  Because
    2923              :    anonymous unions can nest, we must also search all anonymous unions
    2924              :    that are directly reachable.  */
    2925              : 
    2926              : tree
    2927      1523595 : lookup_anon_field (tree, tree type)
    2928              : {
    2929      1523595 :   tree field;
    2930              : 
    2931      1523595 :   type = TYPE_MAIN_VARIANT (type);
    2932      1523595 :   field = ANON_AGGR_TYPE_FIELD (type);
    2933      1523595 :   gcc_assert (field);
    2934      1523595 :   return field;
    2935              : }
    2936              : 
    2937              : /* Build an expression representing OBJECT.MEMBER.  OBJECT is an
    2938              :    expression; MEMBER is a DECL or baselink.  If ACCESS_PATH is
    2939              :    non-NULL, it indicates the path to the base used to name MEMBER.
    2940              :    If PRESERVE_REFERENCE is true, the expression returned will have
    2941              :    REFERENCE_TYPE if the MEMBER does.  Otherwise, the expression
    2942              :    returned will have the type referred to by the reference.
    2943              : 
    2944              :    This function does not perform access control; that is either done
    2945              :    earlier by the parser when the name of MEMBER is resolved to MEMBER
    2946              :    itself, or later when overload resolution selects one of the
    2947              :    functions indicated by MEMBER.  */
    2948              : 
    2949              : tree
    2950    124210228 : build_class_member_access_expr (cp_expr object, tree member,
    2951              :                                 tree access_path, bool preserve_reference,
    2952              :                                 tsubst_flags_t complain)
    2953              : {
    2954    124210228 :   tree object_type;
    2955    124210228 :   tree member_scope;
    2956    124210228 :   tree result = NULL_TREE;
    2957    124210228 :   tree using_decl = NULL_TREE;
    2958              : 
    2959    124210228 :   if (error_operand_p (object) || error_operand_p (member))
    2960           59 :     return error_mark_node;
    2961              : 
    2962    124210169 :   gcc_assert (DECL_P (member) || BASELINK_P (member));
    2963              : 
    2964              :   /* [expr.ref]
    2965              : 
    2966              :      The type of the first expression shall be "class object" (of a
    2967              :      complete type).  */
    2968    124210169 :   object_type = TREE_TYPE (object);
    2969    124210169 :   if (!currently_open_class (object_type)
    2970    124210169 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    2971            0 :     return error_mark_node;
    2972    124210169 :   if (!CLASS_TYPE_P (object_type))
    2973              :     {
    2974            0 :       if (complain & tf_error)
    2975              :         {
    2976            0 :           if (INDIRECT_TYPE_P (object_type)
    2977            0 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    2978            0 :             error ("request for member %qD in %qE, which is of pointer "
    2979              :                    "type %qT (maybe you meant to use %<->%> ?)",
    2980              :                    member, object.get_value (), object_type);
    2981              :           else
    2982            0 :             error ("request for member %qD in %qE, which is of non-class "
    2983              :                    "type %qT", member, object.get_value (), object_type);
    2984              :         }
    2985            0 :       return error_mark_node;
    2986              :     }
    2987              : 
    2988              :   /* The standard does not seem to actually say that MEMBER must be a
    2989              :      member of OBJECT_TYPE.  However, that is clearly what is
    2990              :      intended.  */
    2991    124210169 :   if (DECL_P (member))
    2992              :     {
    2993     54203018 :       member_scope = DECL_CLASS_CONTEXT (member);
    2994     54203018 :       if (!mark_used (member, complain) && !(complain & tf_error))
    2995            0 :         return error_mark_node;
    2996              : 
    2997     54203018 :       if (TREE_UNAVAILABLE (member))
    2998           30 :         error_unavailable_use (member, NULL_TREE);
    2999     54202988 :       else if (TREE_DEPRECATED (member))
    3000           30 :         warn_deprecated_use (member, NULL_TREE);
    3001              :     }
    3002              :   else
    3003     70007151 :     member_scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (member));
    3004              :   /* If MEMBER is from an anonymous aggregate, MEMBER_SCOPE will
    3005              :      presently be the anonymous union.  Go outwards until we find a
    3006              :      type related to OBJECT_TYPE.  */
    3007    125738055 :   while ((ANON_AGGR_TYPE_P (member_scope) || UNSCOPED_ENUM_P (member_scope))
    3008    127266517 :          && !same_type_ignoring_top_level_qualifiers_p (member_scope,
    3009              :                                                         object_type))
    3010      1527886 :     member_scope = TYPE_CONTEXT (member_scope);
    3011    124210169 :   if (!member_scope || !DERIVED_FROM_P (member_scope, object_type))
    3012              :     {
    3013           15 :       if (complain & tf_error)
    3014              :         {
    3015           15 :           if (TREE_CODE (member) == FIELD_DECL)
    3016            0 :             error ("invalid use of non-static data member %qE", member);
    3017              :           else
    3018           15 :             error ("%qD is not a member of %qT", member, object_type);
    3019              :         }
    3020           15 :       return error_mark_node;
    3021              :     }
    3022              : 
    3023              :   /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x' into
    3024              :      `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only an lvalue
    3025              :      in the front end; only _DECLs and _REFs are lvalues in the back end.  */
    3026    124210154 :   if (tree temp = unary_complex_lvalue (ADDR_EXPR, object))
    3027              :     {
    3028           44 :       temp = cp_build_fold_indirect_ref (temp);
    3029           44 :       if (!lvalue_p (object) && lvalue_p (temp))
    3030              :         /* Preserve rvalueness.  */
    3031            6 :         temp = move (temp);
    3032           44 :       object = temp;
    3033              :     }
    3034              : 
    3035              :   /* In [expr.ref], there is an explicit list of the valid choices for
    3036              :      MEMBER.  We check for each of those cases here.  */
    3037    124210154 :   if (VAR_P (member))
    3038              :     {
    3039              :       /* A static data member.  */
    3040       121498 :       result = member;
    3041       121498 :       mark_exp_read (object);
    3042              : 
    3043       121498 :       if (tree wrap = maybe_get_tls_wrapper_call (result))
    3044              :         /* Replace an evaluated use of the thread_local variable with
    3045              :            a call to its wrapper.  */
    3046          102 :         result = wrap;
    3047              : 
    3048              :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3049       121498 :       if (TREE_SIDE_EFFECTS (object))
    3050         4827 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result), object, result);
    3051              :     }
    3052    124088656 :   else if (TREE_CODE (member) == FIELD_DECL)
    3053              :     {
    3054              :       /* A non-static data member.  */
    3055     54081293 :       bool null_object_p;
    3056     54081293 :       cv_qualifier type_quals;
    3057     54081293 :       tree member_type;
    3058              : 
    3059     54081293 :       if (INDIRECT_REF_P (object))
    3060     40651228 :         null_object_p =
    3061     40651228 :           integer_zerop (tree_strip_nop_conversions (TREE_OPERAND (object, 0)));
    3062              :       else
    3063              :         null_object_p = false;
    3064              : 
    3065              :       /* Convert OBJECT to the type of MEMBER.  */
    3066     54081293 :       if (!same_type_p (TYPE_MAIN_VARIANT (object_type),
    3067              :                         TYPE_MAIN_VARIANT (member_scope)))
    3068              :         {
    3069      2051789 :           tree binfo;
    3070      2051789 :           base_kind kind;
    3071              : 
    3072              :           /* We didn't complain above about a currently open class, but now we
    3073              :              must: we don't know how to refer to a base member before layout is
    3074              :              complete.  But still don't complain in a template.  */
    3075      2051789 :           if (!cp_unevaluated_operand
    3076      2051264 :               && !dependent_type_p (object_type)
    3077      3813840 :               && !complete_type_or_maybe_complain (object_type, object,
    3078              :                                                    complain))
    3079            9 :             return error_mark_node;
    3080              : 
    3081      2777076 :           binfo = lookup_base (access_path ? access_path : object_type,
    3082              :                                member_scope, ba_unique, &kind, complain);
    3083      2051786 :           if (binfo == error_mark_node)
    3084              :             return error_mark_node;
    3085              : 
    3086              :           /* It is invalid to try to get to a virtual base of a
    3087              :              NULL object.  The most common cause is invalid use of
    3088              :              offsetof macro.  */
    3089      2051786 :           if (null_object_p && kind == bk_via_virtual)
    3090              :             {
    3091            6 :               if (complain & tf_error)
    3092              :                 {
    3093            6 :                   error ("invalid access to non-static data member %qD in "
    3094              :                          "virtual base of NULL object", member);
    3095              :                 }
    3096            6 :               return error_mark_node;
    3097              :             }
    3098              : 
    3099              :           /* Convert to the base.  */
    3100      2051780 :           object = build_base_path (PLUS_EXPR, object, binfo,
    3101              :                                     /*nonnull=*/1, complain);
    3102              :           /* If we found the base successfully then we should be able
    3103              :              to convert to it successfully.  */
    3104      2051780 :           gcc_assert (object != error_mark_node || seen_error ());
    3105              :         }
    3106              : 
    3107              :       /* If MEMBER is from an anonymous aggregate, we have converted
    3108              :          OBJECT so that it refers to the class containing the
    3109              :          anonymous union.  Generate a reference to the anonymous union
    3110              :          itself, and recur to find MEMBER.  */
    3111    108162568 :       if (ANON_AGGR_TYPE_P (DECL_CONTEXT (member))
    3112              :           /* When this code is called from build_field_call, the
    3113              :              object already has the type of the anonymous union.
    3114              :              That is because the COMPONENT_REF was already
    3115              :              constructed, and was then disassembled before calling
    3116              :              build_field_call.  After the function-call code is
    3117              :              cleaned up, this waste can be eliminated.  */
    3118     55605309 :           && (!same_type_ignoring_top_level_qualifiers_p
    3119      1524025 :               (TREE_TYPE (object), DECL_CONTEXT (member))))
    3120              :         {
    3121      1523455 :           tree anonymous_union;
    3122              : 
    3123      1523455 :           anonymous_union = lookup_anon_field (TREE_TYPE (object),
    3124      1523455 :                                                DECL_CONTEXT (member));
    3125      1523455 :           object = build_class_member_access_expr (object,
    3126              :                                                    anonymous_union,
    3127              :                                                    /*access_path=*/NULL_TREE,
    3128              :                                                    preserve_reference,
    3129              :                                                    complain);
    3130              :         }
    3131              : 
    3132              :       /* Compute the type of the field, as described in [expr.ref].  */
    3133     54081284 :       type_quals = TYPE_UNQUALIFIED;
    3134     54081284 :       member_type = TREE_TYPE (member);
    3135     54081284 :       if (!TYPE_REF_P (member_type))
    3136              :         {
    3137    106093882 :           type_quals = (cp_type_quals (member_type)
    3138     53046941 :                         | cp_type_quals (object_type));
    3139              : 
    3140              :           /* A field is const (volatile) if the enclosing object, or the
    3141              :              field itself, is const (volatile).  But, a mutable field is
    3142              :              not const, even within a const object.  */
    3143     53046941 :           if (DECL_MUTABLE_P (member))
    3144       321462 :             type_quals &= ~TYPE_QUAL_CONST;
    3145     53046941 :           member_type = cp_build_qualified_type (member_type, type_quals);
    3146              :         }
    3147              : 
    3148     54081284 :       result = build3_loc (input_location, COMPONENT_REF, member_type,
    3149              :                            object, member, NULL_TREE);
    3150              : 
    3151              :       /* Mark the expression const or volatile, as appropriate.  Even
    3152              :          though we've dealt with the type above, we still have to mark the
    3153              :          expression itself.  */
    3154     54081284 :       if (type_quals & TYPE_QUAL_CONST)
    3155     16825601 :         TREE_READONLY (result) = 1;
    3156     54081284 :       if (type_quals & TYPE_QUAL_VOLATILE)
    3157       186282 :         TREE_THIS_VOLATILE (result) = 1;
    3158              :     }
    3159     70007363 :   else if (BASELINK_P (member))
    3160              :     {
    3161              :       /* The member is a (possibly overloaded) member function.  */
    3162     70007136 :       tree functions;
    3163     70007136 :       tree type;
    3164              : 
    3165              :       /* If the MEMBER is exactly one static member function, then we
    3166              :          know the type of the expression.  Otherwise, we must wait
    3167              :          until overload resolution has been performed.  */
    3168     70007136 :       functions = BASELINK_FUNCTIONS (member);
    3169     70007136 :       if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
    3170     70007136 :         functions = OVL_FIRST (functions);
    3171     70007136 :       if (TREE_CODE (functions) == FUNCTION_DECL
    3172     70007136 :           && DECL_STATIC_FUNCTION_P (functions))
    3173       624601 :         type = TREE_TYPE (functions);
    3174              :       else
    3175     69382535 :         type = unknown_type_node;
    3176              :       /* Note that we do not convert OBJECT to the BASELINK_BINFO
    3177              :          base.  That will happen when the function is called.  */
    3178     70007136 :       result = build3_loc (input_location, COMPONENT_REF, type, object, member,
    3179              :                            NULL_TREE);
    3180              :     }
    3181          227 :   else if (TREE_CODE (member) == CONST_DECL)
    3182              :     {
    3183              :       /* The member is an enumerator.  */
    3184          215 :       result = member;
    3185              :       /* If OBJECT has side-effects, they are supposed to occur.  */
    3186          215 :       if (TREE_SIDE_EFFECTS (object))
    3187            6 :         result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    3188              :                          object, result);
    3189              :     }
    3190           12 :   else if ((using_decl = strip_using_decl (member)) != member)
    3191            0 :     result = build_class_member_access_expr (object,
    3192              :                                              using_decl,
    3193              :                                              access_path, preserve_reference,
    3194              :                                              complain);
    3195              :   else
    3196              :     {
    3197           12 :       if (complain & tf_error)
    3198           12 :         error ("invalid use of %qD", member);
    3199           12 :       return error_mark_node;
    3200              :     }
    3201              : 
    3202    124210133 :   if (!preserve_reference)
    3203              :     /* [expr.ref]
    3204              : 
    3205              :        If E2 is declared to have type "reference to T", then ... the
    3206              :        type of E1.E2 is T.  */
    3207    117307928 :     result = convert_from_reference (result);
    3208              : 
    3209              :   return result;
    3210              : }
    3211              : 
    3212              : /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
    3213              :    SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type.  */
    3214              : 
    3215              : tree
    3216       221567 : lookup_destructor (tree object, tree scope, tree dtor_name,
    3217              :                    tsubst_flags_t complain)
    3218              : {
    3219       221567 :   tree object_type = TREE_TYPE (object);
    3220       221567 :   tree dtor_type = TREE_OPERAND (dtor_name, 0);
    3221       221567 :   tree expr;
    3222              : 
    3223              :   /* We've already complained about this destructor.  */
    3224       221567 :   if (dtor_type == error_mark_node)
    3225              :     return error_mark_node;
    3226              : 
    3227       221561 :   if (scope && !check_dtor_name (scope, dtor_type))
    3228              :     {
    3229            3 :       if (complain & tf_error)
    3230            3 :         error ("qualified type %qT does not match destructor name ~%qT",
    3231              :                scope, dtor_type);
    3232            3 :       return error_mark_node;
    3233              :     }
    3234       221558 :   if (is_auto (dtor_type))
    3235              :     dtor_type = object_type;
    3236       221555 :   else if (identifier_p (dtor_type))
    3237              :     {
    3238              :       /* In a template, names we can't find a match for are still accepted
    3239              :          destructor names, and we check them here.  */
    3240           23 :       if (check_dtor_name (object_type, dtor_type))
    3241              :         dtor_type = object_type;
    3242              :       else
    3243              :         {
    3244            3 :           if (complain & tf_error)
    3245            3 :             error ("object type %qT does not match destructor name ~%qT",
    3246              :                    object_type, dtor_type);
    3247            3 :           return error_mark_node;
    3248              :         }
    3249              : 
    3250              :     }
    3251       221532 :   else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
    3252              :     {
    3253            8 :       if (complain & tf_error)
    3254            8 :         error ("the type being destroyed is %qT, but the destructor "
    3255            8 :                "refers to %qT", TYPE_MAIN_VARIANT (object_type), dtor_type);
    3256            8 :       return error_mark_node;
    3257              :     }
    3258       221547 :   expr = lookup_member (dtor_type, complete_dtor_identifier,
    3259              :                         /*protect=*/1, /*want_type=*/false,
    3260              :                         complain);
    3261       221547 :   if (expr == error_mark_node)
    3262              :     return error_mark_node;
    3263       221547 :   if (!expr)
    3264              :     {
    3265            6 :       if (complain & tf_error)
    3266            6 :         cxx_incomplete_type_error (dtor_name, dtor_type);
    3267            6 :       return error_mark_node;
    3268              :     }
    3269       221541 :   expr = (adjust_result_of_qualified_name_lookup
    3270       221541 :           (expr, dtor_type, object_type));
    3271       221541 :   if (scope == NULL_TREE)
    3272              :     /* We need to call adjust_result_of_qualified_name_lookup in case the
    3273              :        destructor names a base class, but we unset BASELINK_QUALIFIED_P so
    3274              :        that we still get virtual function binding.  */
    3275       221398 :     BASELINK_QUALIFIED_P (expr) = false;
    3276              :   return expr;
    3277              : }
    3278              : 
    3279              : /* An expression of the form "A::template B" has been resolved to
    3280              :    DECL.  Issue a diagnostic if B is not a template or template
    3281              :    specialization.  */
    3282              : 
    3283              : void
    3284       273016 : check_template_keyword (tree decl)
    3285              : {
    3286              :   /* The standard says:
    3287              : 
    3288              :       [temp.names]
    3289              : 
    3290              :       If a name prefixed by the keyword template is not a member
    3291              :       template, the program is ill-formed.
    3292              : 
    3293              :      DR 228 removed the restriction that the template be a member
    3294              :      template.
    3295              : 
    3296              :      DR 96, if accepted would add the further restriction that explicit
    3297              :      template arguments must be provided if the template keyword is
    3298              :      used, but, as of 2005-10-16, that DR is still in "drafting".  If
    3299              :      this DR is accepted, then the semantic checks here can be
    3300              :      simplified, as the entity named must in fact be a template
    3301              :      specialization, rather than, as at present, a set of overloaded
    3302              :      functions containing at least one template function.  */
    3303       273016 :   if (TREE_CODE (decl) != TEMPLATE_DECL
    3304       273016 :       && TREE_CODE (decl) != TEMPLATE_ID_EXPR)
    3305              :     {
    3306        60766 :       if (VAR_P (decl))
    3307              :         {
    3308         9729 :           if (DECL_USE_TEMPLATE (decl)
    3309         9729 :               && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
    3310              :             ;
    3311              :           else
    3312            0 :             permerror (input_location, "%qD is not a template", decl);
    3313              :         }
    3314        51037 :       else if (!is_overloaded_fn (decl))
    3315            0 :         permerror (input_location, "%qD is not a template", decl);
    3316              :       else
    3317              :         {
    3318        51037 :           bool found = false;
    3319              : 
    3320       102074 :           for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (decl));
    3321       102076 :                !found && iter; ++iter)
    3322              :             {
    3323        51039 :               tree fn = *iter;
    3324        51039 :               if (TREE_CODE (fn) == TEMPLATE_DECL
    3325        50643 :                   || TREE_CODE (fn) == TEMPLATE_ID_EXPR
    3326        51053 :                   || (TREE_CODE (fn) == FUNCTION_DECL
    3327           14 :                       && DECL_USE_TEMPLATE (fn)
    3328            6 :                       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (fn))))
    3329              :                 found = true;
    3330              :             }
    3331        51037 :           if (!found)
    3332           12 :             permerror (input_location, "%qD is not a template", decl);
    3333              :         }
    3334              :     }
    3335       273016 : }
    3336              : 
    3337              : /* Record that an access failure occurred on BASETYPE_PATH attempting
    3338              :    to access DECL, where DIAG_DECL should be used for diagnostics.  */
    3339              : 
    3340              : void
    3341          412 : access_failure_info::record_access_failure (tree basetype_path,
    3342              :                                             tree decl, tree diag_decl)
    3343              : {
    3344          412 :   m_was_inaccessible = true;
    3345          412 :   m_basetype_path = basetype_path;
    3346          412 :   m_decl = decl;
    3347          412 :   m_diag_decl = diag_decl;
    3348          412 : }
    3349              : 
    3350              : /* If an access failure was recorded, then attempt to locate an
    3351              :    accessor function for the pertinent field.
    3352              :    Otherwise, return NULL_TREE.  */
    3353              : 
    3354              : tree
    3355     99387734 : access_failure_info::get_any_accessor (bool const_p) const
    3356              : {
    3357     99387734 :   if (!was_inaccessible_p ())
    3358              :     return NULL_TREE;
    3359              : 
    3360          412 :   tree accessor
    3361          412 :     = locate_field_accessor (m_basetype_path, m_diag_decl, const_p);
    3362          412 :   if (!accessor)
    3363              :     return NULL_TREE;
    3364              : 
    3365              :   /* The accessor must itself be accessible for it to be a reasonable
    3366              :      suggestion.  */
    3367          161 :   if (!accessible_p (m_basetype_path, accessor, true))
    3368           21 :     return NULL_TREE;
    3369              : 
    3370              :   return accessor;
    3371              : }
    3372              : 
    3373              : /* Add a fix-it hint to RICHLOC suggesting the use of ACCESSOR_DECL, by
    3374              :    replacing the primary location in RICHLOC with "accessor()".  */
    3375              : 
    3376              : void
    3377          140 : access_failure_info::add_fixit_hint (rich_location *richloc,
    3378              :                                      tree accessor_decl)
    3379              : {
    3380          140 :   pretty_printer pp;
    3381          140 :   pp_string (&pp, IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
    3382          140 :   pp_string (&pp, "()");
    3383          140 :   richloc->add_fixit_replace (pp_formatted_text (&pp));
    3384          140 : }
    3385              : 
    3386              : /* If an access failure was recorded, then attempt to locate an
    3387              :    accessor function for the pertinent field, and if one is
    3388              :    available, add a note and fix-it hint suggesting using it.  */
    3389              : 
    3390              : void
    3391     99387664 : access_failure_info::maybe_suggest_accessor (bool const_p) const
    3392              : {
    3393     99387664 :   tree accessor = get_any_accessor (const_p);
    3394     99387664 :   if (accessor == NULL_TREE)
    3395              :     return;
    3396           98 :   rich_location richloc (line_table, input_location);
    3397           98 :   add_fixit_hint (&richloc, accessor);
    3398           98 :   inform (&richloc, "field %q#D can be accessed via %q#D",
    3399           98 :           m_diag_decl, accessor);
    3400           98 : }
    3401              : 
    3402              : /* Subroutine of finish_class_member_access_expr.
    3403              :    Issue an error about NAME not being a member of ACCESS_PATH (or
    3404              :    OBJECT_TYPE), potentially providing a fix-it hint for misspelled
    3405              :    names.  */
    3406              : 
    3407              : static void
    3408          339 : complain_about_unrecognized_member (tree access_path, tree name,
    3409              :                                     tree object_type)
    3410              : {
    3411              :   /* Attempt to provide a hint about misspelled names.  */
    3412          339 :   tree guessed_id = lookup_member_fuzzy (access_path, name,
    3413              :                                          /*want_type=*/false);
    3414          339 :   if (guessed_id == NULL_TREE)
    3415              :     {
    3416              :       /* No hint.  */
    3417          223 :       error ("%q#T has no member named %qE",
    3418          223 :              TREE_CODE (access_path) == TREE_BINFO
    3419            6 :              ? TREE_TYPE (access_path) : object_type, name);
    3420          223 :       return;
    3421              :     }
    3422              : 
    3423          116 :   location_t bogus_component_loc = input_location;
    3424          116 :   gcc_rich_location rich_loc (bogus_component_loc);
    3425              : 
    3426              :   /* Check that the guessed name is accessible along access_path.  */
    3427          116 :   access_failure_info afi;
    3428          116 :   lookup_member (access_path, guessed_id, /*protect=*/1,
    3429              :                  /*want_type=*/false, /*complain=*/false,
    3430              :                  &afi);
    3431          116 :   if (afi.was_inaccessible_p ())
    3432              :     {
    3433           70 :       tree accessor = afi.get_any_accessor (TYPE_READONLY (object_type));
    3434           70 :       if (accessor)
    3435              :         {
    3436              :           /* The guessed name isn't directly accessible, but can be accessed
    3437              :              via an accessor member function.  */
    3438           42 :           afi.add_fixit_hint (&rich_loc, accessor);
    3439           42 :           error_at (&rich_loc,
    3440              :                     "%q#T has no member named %qE;"
    3441              :                     " did you mean %q#D? (accessible via %q#D)",
    3442           42 :                     TREE_CODE (access_path) == TREE_BINFO
    3443            0 :                     ? TREE_TYPE (access_path) : object_type,
    3444              :                     name, afi.get_diag_decl (), accessor);
    3445              :         }
    3446              :       else
    3447              :         {
    3448              :           /* The guessed name isn't directly accessible, and no accessor
    3449              :              member function could be found.  */
    3450           28 :           auto_diagnostic_group d;
    3451           28 :           error_at (&rich_loc,
    3452              :                     "%q#T has no member named %qE;"
    3453              :                     " did you mean %q#D? (not accessible from this context)",
    3454           28 :                     TREE_CODE (access_path) == TREE_BINFO
    3455            0 :                     ? TREE_TYPE (access_path) : object_type,
    3456              :                     name, afi.get_diag_decl ());
    3457           28 :           complain_about_access (afi.get_decl (), afi.get_diag_decl (),
    3458              :                                  afi.get_diag_decl (), false, ak_none);
    3459           28 :         }
    3460              :     }
    3461              :   else
    3462              :     {
    3463              :       /* The guessed name is directly accessible; suggest it.  */
    3464           46 :       rich_loc.add_fixit_misspelled_id (bogus_component_loc,
    3465              :                                         guessed_id);
    3466           46 :       error_at (&rich_loc,
    3467              :                 "%q#T has no member named %qE;"
    3468              :                 " did you mean %qE?",
    3469           46 :                 TREE_CODE (access_path) == TREE_BINFO
    3470            0 :                 ? TREE_TYPE (access_path) : object_type,
    3471              :                 name, guessed_id);
    3472              :     }
    3473          116 : }
    3474              : 
    3475              : /* This function is called by the parser to process a class member
    3476              :    access expression of the form OBJECT.NAME.  NAME is a node used by
    3477              :    the parser to represent a name; it is not yet a DECL, except when
    3478              :    SPLICE_P.  It may, however, be a BASELINK where the BASELINK_FUNCTIONS
    3479              :    is a TEMPLATE_ID_EXPR.  Templates must be looked up by the parser, and
    3480              :    there is no reason to do the lookup twice, so the parser keeps the
    3481              :    BASELINK.  TEMPLATE_P is true iff NAME was explicitly declared to
    3482              :    be a template via the use of the "A::template B" syntax.  SPLICE_P
    3483              :    is true if NAME was designated by a splice-expression.  */
    3484              : 
    3485              : tree
    3486    198728215 : finish_class_member_access_expr (cp_expr object, tree name, bool template_p,
    3487              :                                  tsubst_flags_t complain,
    3488              :                                  bool splice_p/*=false*/)
    3489              : {
    3490    198728215 :   tree expr;
    3491    198728215 :   tree object_type;
    3492    198728215 :   tree member;
    3493    198728215 :   tree access_path = NULL_TREE;
    3494    198728215 :   tree orig_object = object;
    3495    198728215 :   tree orig_name = name;
    3496              : 
    3497    198728215 :   if (object == error_mark_node || name == error_mark_node)
    3498              :     return error_mark_node;
    3499              : 
    3500              :   /* If OBJECT is an ObjC class instance, we must obey ObjC access rules.  */
    3501    198727668 :   if (!objc_is_public (object, name))
    3502            0 :     return error_mark_node;
    3503              : 
    3504    198727668 :   object_type = TREE_TYPE (object);
    3505              : 
    3506    198727668 :   if (processing_template_decl)
    3507              :     {
    3508    163968779 :       if (/* If OBJECT is dependent, so is OBJECT.NAME.  */
    3509    163968779 :           type_dependent_object_expression_p (object)
    3510              :           /* If NAME is "f<args>", where either 'f' or 'args' is
    3511              :              dependent, then the expression is dependent.  */
    3512     77070293 :           || (TREE_CODE (name) == TEMPLATE_ID_EXPR
    3513       695663 :               && dependent_template_id_p (TREE_OPERAND (name, 0),
    3514       695663 :                                           TREE_OPERAND (name, 1)))
    3515              :           /* If NAME is "T::X" where "T" is dependent, then the
    3516              :              expression is dependent.  */
    3517     76695035 :           || (TREE_CODE (name) == SCOPE_REF
    3518       106996 :               && TYPE_P (TREE_OPERAND (name, 0))
    3519       106996 :               && dependent_scope_p (TREE_OPERAND (name, 0)))
    3520              :           /* If NAME is operator T where "T" is dependent, we can't
    3521              :              lookup until we instantiate the T.  */
    3522     76588302 :           || (TREE_CODE (name) == IDENTIFIER_NODE
    3523     75930414 :               && IDENTIFIER_CONV_OP_P (name)
    3524          100 :               && dependent_type_p (TREE_TYPE (name)))
    3525              :           /* This is OBJECT.[:R:], which is dependent.  */
    3526     76588208 :           || dependent_splice_p (name)
    3527              :           /* This is OBJECT.[:T::R:], which is dependent.  */
    3528    240556563 :           || (TREE_CODE (name) == SCOPE_REF
    3529          263 :               && dependent_splice_p (TREE_OPERAND (name, 1))))
    3530              :         {
    3531    102258739 :         dependent:
    3532    102258739 :           expr = build_min_nt_loc (UNKNOWN_LOCATION, COMPONENT_REF,
    3533              :                                    orig_object, orig_name, NULL_TREE);
    3534    102258739 :           COMPONENT_REF_SPLICE_P (expr) = splice_p;
    3535    102258739 :           return expr;
    3536              :         }
    3537              :     }
    3538     34758889 :   else if (c_dialect_objc ()
    3539    111346673 :            && identifier_p (name)
    3540     34758889 :            && (expr = objc_maybe_build_component_ref (object, name)))
    3541              :     return expr;
    3542              : 
    3543              :   /* [expr.ref]
    3544              : 
    3545              :      The type of the first expression shall be "class object" (of a
    3546              :      complete type).  */
    3547    111346673 :   if (!currently_open_class (object_type)
    3548    111346673 :       && !complete_type_or_maybe_complain (object_type, object, complain))
    3549           76 :     return error_mark_node;
    3550    111346597 :   if (!CLASS_TYPE_P (object_type))
    3551              :     {
    3552       287713 :       if (complain & tf_error)
    3553              :         {
    3554          135 :           if (INDIRECT_TYPE_P (object_type)
    3555          135 :               && CLASS_TYPE_P (TREE_TYPE (object_type)))
    3556           23 :             error ("request for member %qD in %qE, which is of pointer "
    3557              :                    "type %qT (maybe you meant to use %<->%> ?)",
    3558              :                    name, object.get_value (), object_type);
    3559              :           else
    3560          112 :             error ("request for member %qD in %qE, which is of non-class "
    3561              :                    "type %qT", name, object.get_value (), object_type);
    3562              :         }
    3563       287713 :       return error_mark_node;
    3564              :     }
    3565              : 
    3566    111058884 :   if (BASELINK_P (name))
    3567              :     /* A member function that has already been looked up.  */
    3568              :     member = name;
    3569     99657784 :   else if (TREE_CODE (name) == TREE_BINFO)
    3570              :     {
    3571              :       /* Splicing a base class subobject.  We can only get here via
    3572              :          e1.[:e2:].  */
    3573           94 :       expr = build_base_path (PLUS_EXPR, object, name, /*nonnull=*/true,
    3574              :                               complain);
    3575           94 :       if (expr == error_mark_node && (complain & tf_error))
    3576            4 :         error_not_base_type (BINFO_TYPE (name), object_type);
    3577              :       return expr;
    3578              :     }
    3579              :   else
    3580              :     {
    3581     99657690 :       bool is_template_id = false;
    3582     99657690 :       tree template_args = NULL_TREE;
    3583     99657690 :       tree scope = NULL_TREE;
    3584              : 
    3585     99657690 :       access_path = object_type;
    3586              : 
    3587     99657690 :       if (TREE_CODE (name) == SCOPE_REF)
    3588              :         {
    3589              :           /* A qualified name.  The qualifying class or namespace `S'
    3590              :              has already been looked up; it is either a TYPE or a
    3591              :              NAMESPACE_DECL.  */
    3592         1854 :           scope = TREE_OPERAND (name, 0);
    3593         1854 :           name = TREE_OPERAND (name, 1);
    3594              : 
    3595              :           /* If SCOPE is a namespace, then the qualified name does not
    3596              :              name a member of OBJECT_TYPE.  */
    3597         1854 :           if (TREE_CODE (scope) == NAMESPACE_DECL)
    3598              :             {
    3599            0 :               if (complain & tf_error)
    3600            0 :                 error ("%<%D::%D%> is not a member of %qT",
    3601              :                        scope, name, object_type);
    3602            0 :               return error_mark_node;
    3603              :             }
    3604              :         }
    3605     99655836 :       else if (splice_p && valid_splice_for_member_access_p (name))
    3606              :         {
    3607          486 :           scope = context_for_name_lookup (OVL_FIRST (name));
    3608          486 :           if (!CLASS_TYPE_P (scope))
    3609              :             {
    3610            8 :               if (complain & tf_error)
    3611              :                 {
    3612            8 :                   auto_diagnostic_group d;
    3613            8 :                   error ("%q#D is not a member of %qT", name, object_type);
    3614           16 :                   inform (DECL_SOURCE_LOCATION (OVL_FIRST (name)), "declared here");
    3615            8 :                 }
    3616            8 :               return error_mark_node;
    3617              :             }
    3618              :         }
    3619              : 
    3620     99657682 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    3621              :         {
    3622       485935 :           is_template_id = true;
    3623       485935 :           template_args = TREE_OPERAND (name, 1);
    3624       485935 :           name = TREE_OPERAND (name, 0);
    3625              : 
    3626       485935 :           if (splice_p
    3627       486421 :               && (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (name))
    3628          162 :                   || variable_template_p (name)))
    3629          162 :             scope = DECL_CONTEXT (OVL_FIRST (name));
    3630       942198 :           else if (!identifier_p (name))
    3631       456495 :             name = OVL_NAME (name);
    3632              :         }
    3633              : 
    3634     99657682 :       if (scope)
    3635              :         {
    3636         2494 :           if (TREE_CODE (scope) == ENUMERAL_TYPE)
    3637              :             {
    3638           12 :               gcc_assert (!is_template_id);
    3639              :               /* Looking up a member enumerator (c++/56793).  */
    3640           24 :               if (!TYPE_CLASS_SCOPE_P (scope)
    3641           21 :                   || !DERIVED_FROM_P (TYPE_CONTEXT (scope), object_type))
    3642              :                 {
    3643            3 :                   if (complain & tf_error)
    3644            3 :                     error ("%<%D::%D%> is not a member of %qT",
    3645              :                            scope, name, object_type);
    3646            3 :                   return error_mark_node;
    3647              :                 }
    3648            9 :               tree val;
    3649            9 :               if (splice_p && TREE_CODE (name) == CONST_DECL)
    3650              :                 val = name;
    3651              :               else
    3652            9 :                 val = lookup_enumerator (scope, name);
    3653            9 :               if (!val)
    3654              :                 {
    3655            6 :                   if (complain & tf_error)
    3656            6 :                     error ("%qD is not a member of %qD",
    3657              :                            name, scope);
    3658            6 :                   return error_mark_node;
    3659              :                 }
    3660              : 
    3661            3 :               if (TREE_SIDE_EFFECTS (object))
    3662            0 :                 val = build2 (COMPOUND_EXPR, TREE_TYPE (val), object, val);
    3663              :               return val;
    3664              :             }
    3665              : 
    3666         2482 :           gcc_assert (CLASS_TYPE_P (scope));
    3667         2482 :           gcc_assert (identifier_p (name)
    3668              :                       || TREE_CODE (name) == BIT_NOT_EXPR
    3669              :                       || (splice_p && valid_splice_for_member_access_p (name)));
    3670              : 
    3671         2482 :           if (constructor_name_p (name, scope))
    3672              :             {
    3673            3 :               if (complain & tf_error)
    3674            3 :                 error ("cannot call constructor %<%T::%D%> directly",
    3675              :                        scope, name);
    3676            3 :               return error_mark_node;
    3677              :             }
    3678              : 
    3679              :           /* NAME may refer to a static data member, in which case there is
    3680              :              one copy of the data member that is shared by all the objects of
    3681              :              the class.  So NAME can be unambiguously referred to even if
    3682              :              there are multiple indirect base classes containing NAME.  */
    3683         7437 :           const base_access ba = [scope, name, splice_p] ()
    3684              :             {
    3685              :               /* [class.access.base]/5: A member m is accessible at the
    3686              :                  point R when designated in class N if
    3687              :                  -- m is designated by a splice-expression  */
    3688         2479 :               if (splice_p)
    3689              :                 return ba_unique;
    3690         1839 :               if (identifier_p (name))
    3691              :                 {
    3692         1702 :                   tree m = lookup_member (scope, name, /*protect=*/0,
    3693              :                                           /*want_type=*/false, tf_none);
    3694         1702 :                   if (!m || shared_member_p (m))
    3695           38 :                     return ba_any;
    3696              :                 }
    3697              :               return ba_check;
    3698         2479 :             } ();
    3699              : 
    3700              :           /* Find the base of OBJECT_TYPE corresponding to SCOPE.  */
    3701         2479 :           access_path = lookup_base (object_type, scope, ba, NULL, complain);
    3702         2479 :           if (access_path == error_mark_node)
    3703              :             return error_mark_node;
    3704         2441 :           if (!access_path)
    3705              :             {
    3706           40 :               if (any_dependent_bases_p (object_type))
    3707            6 :                 goto dependent;
    3708           34 :               if (complain & tf_error)
    3709           34 :                 error ("%qT is not a base of %qT", scope, object_type);
    3710           34 :               return error_mark_node;
    3711              :             }
    3712              :         }
    3713              : 
    3714     99657589 :       if (TREE_CODE (name) == BIT_NOT_EXPR)
    3715              :         {
    3716       269339 :           if (dependent_type_p (object_type))
    3717              :             /* The destructor isn't declared yet.  */
    3718        47787 :             goto dependent;
    3719       221552 :           member = lookup_destructor (object, scope, name, complain);
    3720              :         }
    3721     99388250 :       else if (splice_p && valid_splice_for_member_access_p (name))
    3722              :         {
    3723          586 :           member = name;
    3724          586 :           name = OVL_FIRST (name);
    3725          586 :           if (any_dependent_type_attributes_p (DECL_ATTRIBUTES (name)))
    3726              :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3727              :                wrong, so don't use it.  */
    3728            0 :             goto dependent;
    3729          586 :           if (is_overloaded_fn (name))
    3730            0 :             member
    3731            0 :               = build_baselink (access_path, TYPE_BINFO (object_type), member,
    3732            0 :                                 IDENTIFIER_CONV_OP_P (DECL_NAME (name))
    3733            0 :                                 ? TREE_TYPE (DECL_NAME (name)) : NULL_TREE);
    3734              :         }
    3735              :       else
    3736              :         {
    3737              :           /* Look up the member.  */
    3738     99387664 :           {
    3739     99387664 :             auto_diagnostic_group d;
    3740     99387664 :             access_failure_info afi;
    3741     99387664 :             if (processing_template_decl)
    3742              :               /* Even though this class member access expression is at this
    3743              :                  point not dependent, the member itself may be dependent, and
    3744              :                  we must not potentially push a access check for a dependent
    3745              :                  member onto TI_DEFERRED_ACCESS_CHECKS.  So don't check access
    3746              :                  ahead of time here; we're going to redo this member lookup at
    3747              :                  instantiation time anyway.  */
    3748     76250806 :               push_deferring_access_checks (dk_no_check);
    3749     99387664 :             member = lookup_member (access_path, name, /*protect=*/1,
    3750              :                                     /*want_type=*/false, complain,
    3751              :                                     &afi);
    3752     99387664 :             if (processing_template_decl)
    3753     76250806 :               pop_deferring_access_checks ();
    3754     99387664 :             afi.maybe_suggest_accessor (TYPE_READONLY (object_type));
    3755     99387664 :           }
    3756     99387664 :           if (member == NULL_TREE)
    3757              :             {
    3758      9518626 :               if (dependentish_scope_p (object_type))
    3759              :                 /* Try again at instantiation time.  */
    3760      9494497 :                 goto dependent;
    3761        24129 :               if (complain & tf_error)
    3762          339 :                 complain_about_unrecognized_member (access_path, name,
    3763              :                                                     object_type);
    3764        24129 :               return error_mark_node;
    3765              :             }
    3766     89869038 :           if (member == error_mark_node)
    3767              :             return error_mark_node;
    3768     89868992 :           if (DECL_P (member)
    3769     89868992 :               && any_dependent_type_attributes_p (DECL_ATTRIBUTES (member)))
    3770              :             /* Dependent type attributes on the decl mean that the TREE_TYPE is
    3771              :                wrong, so don't use it.  */
    3772            6 :             goto dependent;
    3773     89868986 :           if (TREE_CODE (member) == USING_DECL && DECL_DEPENDENT_P (member))
    3774      5335448 :             goto dependent;
    3775              :         }
    3776              : 
    3777     84755676 :       if (is_template_id)
    3778              :         {
    3779       485645 :           tree templ = member;
    3780              : 
    3781       485645 :           if (BASELINK_P (templ))
    3782       485391 :             member = lookup_template_function (templ, template_args);
    3783          254 :           else if (variable_template_p (templ))
    3784          254 :             member = (lookup_and_finish_template_variable
    3785          254 :                       (templ, template_args, complain));
    3786              :           else
    3787              :             {
    3788            0 :               if (complain & tf_error)
    3789            0 :                 error ("%qD is not a member template function", name);
    3790            0 :               return error_mark_node;
    3791              :             }
    3792              :         }
    3793              :     }
    3794              : 
    3795     96156776 :   if (TREE_UNAVAILABLE (member))
    3796           30 :     error_unavailable_use (member, NULL_TREE);
    3797     96156746 :   else if (TREE_DEPRECATED (member))
    3798           30 :     warn_deprecated_use (member, NULL_TREE);
    3799              : 
    3800     96156776 :   if (template_p)
    3801         9705 :     check_template_keyword (member);
    3802              : 
    3803     96156776 :   expr = build_class_member_access_expr (object, member, access_path,
    3804              :                                          /*preserve_reference=*/false,
    3805              :                                          complain);
    3806     96156776 :   if (processing_template_decl && expr != error_mark_node)
    3807              :     {
    3808     61709943 :       if (BASELINK_P (member))
    3809              :         {
    3810     45761244 :           if (TREE_CODE (orig_name) == SCOPE_REF)
    3811          215 :             BASELINK_QUALIFIED_P (member) = 1;
    3812              :           orig_name = member;
    3813              :         }
    3814     61709943 :       expr = build_min_non_dep (COMPONENT_REF, expr,
    3815              :                                 orig_object, orig_name,
    3816              :                                 NULL_TREE);
    3817    123419886 :       COMPONENT_REF_SPLICE_P (STRIP_REFERENCE_REF (expr)) = splice_p;
    3818              :     }
    3819              : 
    3820              :   return expr;
    3821              : }
    3822              : 
    3823              : /* Build a COMPONENT_REF of OBJECT and MEMBER with the appropriate
    3824              :    type.  */
    3825              : 
    3826              : tree
    3827       174484 : build_simple_component_ref (tree object, tree member)
    3828              : {
    3829       174484 :   tree type = cp_build_qualified_type (TREE_TYPE (member),
    3830       174484 :                                        cp_type_quals (TREE_TYPE (object)));
    3831       174484 :   return build3_loc (input_location,
    3832              :                      COMPONENT_REF, type,
    3833       174484 :                      object, member, NULL_TREE);
    3834              : }
    3835              : 
    3836              : /* Return an expression for the MEMBER_NAME field in the internal
    3837              :    representation of PTRMEM, a pointer-to-member function.  (Each
    3838              :    pointer-to-member function type gets its own RECORD_TYPE so it is
    3839              :    more convenient to access the fields by name than by FIELD_DECL.)
    3840              :    This routine converts the NAME to a FIELD_DECL and then creates the
    3841              :    node for the complete expression.  */
    3842              : 
    3843              : tree
    3844       174400 : build_ptrmemfunc_access_expr (tree ptrmem, tree member_name)
    3845              : {
    3846       174400 :   tree ptrmem_type;
    3847       174400 :   tree member;
    3848              : 
    3849       174400 :   if (TREE_CODE (ptrmem) == CONSTRUCTOR)
    3850              :     {
    3851          234 :       for (auto &e: CONSTRUCTOR_ELTS (ptrmem))
    3852           90 :         if (e.index && DECL_P (e.index) && DECL_NAME (e.index) == member_name)
    3853           72 :           return e.value;
    3854            0 :       gcc_unreachable ();
    3855              :     }
    3856              : 
    3857              :   /* This code is a stripped down version of
    3858              :      build_class_member_access_expr.  It does not work to use that
    3859              :      routine directly because it expects the object to be of class
    3860              :      type.  */
    3861       174328 :   ptrmem_type = TREE_TYPE (ptrmem);
    3862       174328 :   gcc_assert (TYPE_PTRMEMFUNC_P (ptrmem_type));
    3863       261375 :   for (member = TYPE_FIELDS (ptrmem_type); member;
    3864        87047 :        member = DECL_CHAIN (member))
    3865       261375 :     if (DECL_NAME (member) == member_name)
    3866              :       break;
    3867       174328 :   return build_simple_component_ref (ptrmem, member);
    3868              : }
    3869              : 
    3870              : /* Return a TREE_LIST of namespace-scope overloads for the given operator,
    3871              :    and for any other relevant operator.  */
    3872              : 
    3873              : static tree
    3874    143599850 : op_unqualified_lookup (tree_code code, bool is_assign)
    3875              : {
    3876    143599850 :   tree lookups = NULL_TREE;
    3877              : 
    3878    143599850 :   if (cxx_dialect >= cxx20 && !is_assign)
    3879              :     {
    3880    135747633 :       if (code == NE_EXPR)
    3881              :         {
    3882              :           /* != can get rewritten in terms of ==.  */
    3883      8754312 :           tree fnname = ovl_op_identifier (false, EQ_EXPR);
    3884      8754312 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3885      8646478 :             lookups = tree_cons (fnname, fns, lookups);
    3886              :         }
    3887    126993321 :       else if (code == GT_EXPR || code == LE_EXPR
    3888    126993321 :                || code == LT_EXPR || code == GE_EXPR)
    3889              :         {
    3890              :           /* These can get rewritten in terms of <=>.  */
    3891     11994713 :           tree fnname = ovl_op_identifier (false, SPACESHIP_EXPR);
    3892     11994713 :           if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3893     11359627 :             lookups = tree_cons (fnname, fns, lookups);
    3894              :         }
    3895              :     }
    3896              : 
    3897    143599850 :   tree fnname = ovl_op_identifier (is_assign, code);
    3898    143599850 :   if (tree fns = lookup_name (fnname, LOOK_where::BLOCK_NAMESPACE))
    3899     77900393 :     lookups = tree_cons (fnname, fns, lookups);
    3900              : 
    3901    143599850 :   if (lookups)
    3902              :     return lookups;
    3903              :   else
    3904     65468278 :     return build_tree_list (NULL_TREE, NULL_TREE);
    3905              : }
    3906              : 
    3907              : /* Create a DEPENDENT_OPERATOR_TYPE for a dependent operator expression of
    3908              :    the given operator.  LOOKUPS, if non-NULL, is the result of phase 1
    3909              :    name lookup for the given operator.  */
    3910              : 
    3911              : tree
    3912    149986538 : build_dependent_operator_type (tree lookups, tree_code code, bool is_assign)
    3913              : {
    3914    149986538 :   if (lookups)
    3915              :     /* We're partially instantiating a dependent operator expression, and
    3916              :        LOOKUPS is the result of phase 1 name lookup that we performed
    3917              :        earlier at template definition time, so just reuse the corresponding
    3918              :        DEPENDENT_OPERATOR_TYPE.  */
    3919      6386688 :     return TREE_TYPE (lookups);
    3920              : 
    3921              :   /* Otherwise we're processing a dependent operator expression at template
    3922              :      definition time, so perform phase 1 name lookup now.  */
    3923    143599850 :   lookups = op_unqualified_lookup (code, is_assign);
    3924              : 
    3925    143599850 :   tree type = cxx_make_type (DEPENDENT_OPERATOR_TYPE);
    3926    143599850 :   DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (type) = lookups;
    3927    143599850 :   TREE_TYPE (lookups) = type;
    3928    143599850 :   return type;
    3929              : }
    3930              : 
    3931              : /* Given an expression PTR for a pointer, return an expression
    3932              :    for the value pointed to.
    3933              :    ERRORSTRING is the name of the operator to appear in error messages.
    3934              : 
    3935              :    This function may need to overload OPERATOR_FNNAME.
    3936              :    Must also handle REFERENCE_TYPEs for C++.  */
    3937              : 
    3938              : tree
    3939     51957131 : build_x_indirect_ref (location_t loc, tree expr, ref_operator errorstring,
    3940              :                       tree lookups, tsubst_flags_t complain)
    3941              : {
    3942     51957131 :   tree orig_expr = expr;
    3943     51957131 :   tree rval;
    3944     51957131 :   tree overload = NULL_TREE;
    3945              : 
    3946     51957131 :   if (processing_template_decl)
    3947              :     {
    3948              :       /* Retain the type if we know the operand is a pointer.  */
    3949     30108382 :       if (TREE_TYPE (expr) && INDIRECT_TYPE_P (TREE_TYPE (expr)))
    3950              :         {
    3951     14834185 :           if (expr == current_class_ptr
    3952     14834185 :               || (TREE_CODE (expr) == NOP_EXPR
    3953      9851756 :                   && TREE_OPERAND (expr, 0) == current_class_ptr
    3954      9738003 :                   && (same_type_ignoring_top_level_qualifiers_p
    3955      9738003 :                         (TREE_TYPE (expr), TREE_TYPE (current_class_ptr)))))
    3956      9738002 :             return current_class_ref;
    3957      5096183 :           return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
    3958              :         }
    3959     15274197 :       if (type_dependent_expression_p (expr))
    3960              :         {
    3961     15132341 :           expr = build_min_nt_loc (loc, INDIRECT_REF, expr);
    3962     15132341 :           TREE_TYPE (expr)
    3963     15132341 :             = build_dependent_operator_type (lookups, INDIRECT_REF, false);
    3964     15132341 :           return expr;
    3965              :         }
    3966              :     }
    3967              : 
    3968     21990605 :   rval = build_new_op (loc, INDIRECT_REF, LOOKUP_NORMAL, expr,
    3969              :                        NULL_TREE, NULL_TREE, lookups,
    3970              :                        &overload, complain);
    3971     21990605 :   if (!rval)
    3972            0 :     rval = cp_build_indirect_ref (loc, expr, errorstring, complain);
    3973              : 
    3974     21990605 :   if (processing_template_decl && rval != error_mark_node)
    3975              :     {
    3976       140023 :       if (overload != NULL_TREE)
    3977       139992 :         return (build_min_non_dep_op_overload
    3978       139992 :                 (INDIRECT_REF, rval, overload, orig_expr));
    3979              : 
    3980           31 :       return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
    3981              :     }
    3982              :   else
    3983              :     return rval;
    3984              : }
    3985              : 
    3986              : /* Like c-family strict_aliasing_warning, but don't warn for dependent
    3987              :    types or expressions.  */
    3988              : 
    3989              : static bool
    3990       657836 : cp_strict_aliasing_warning (location_t loc, tree type, tree expr)
    3991              : {
    3992       657836 :   if (processing_template_decl)
    3993              :     {
    3994        45714 :       tree e = expr;
    3995        45714 :       STRIP_NOPS (e);
    3996        45714 :       if (dependent_type_p (type) || type_dependent_expression_p (e))
    3997              :         return false;
    3998              :     }
    3999       650400 :   return strict_aliasing_warning (loc, type, expr);
    4000              : }
    4001              : 
    4002              : /* The implementation of the above, and of indirection implied by other
    4003              :    constructs.  If DO_FOLD is true, fold away INDIRECT_REF of ADDR_EXPR.  */
    4004              : 
    4005              : static tree
    4006    368511446 : cp_build_indirect_ref_1 (location_t loc, tree ptr, ref_operator errorstring,
    4007              :                          tsubst_flags_t complain, bool do_fold)
    4008              : {
    4009    368511446 :   tree pointer, type;
    4010              : 
    4011              :   /* RO_NULL should only be used with the folding entry points below, not
    4012              :      cp_build_indirect_ref.  */
    4013    368511446 :   gcc_checking_assert (errorstring != RO_NULL || do_fold);
    4014              : 
    4015    368511446 :   if (ptr == current_class_ptr
    4016    368511446 :       || (TREE_CODE (ptr) == NOP_EXPR
    4017     39607688 :           && TREE_OPERAND (ptr, 0) == current_class_ptr
    4018     21038912 :           && (same_type_ignoring_top_level_qualifiers_p
    4019     21038912 :               (TREE_TYPE (ptr), TREE_TYPE (current_class_ptr)))))
    4020     22574577 :     return current_class_ref;
    4021              : 
    4022    345936869 :   pointer = (TYPE_REF_P (TREE_TYPE (ptr))
    4023    345936869 :              ? ptr : decay_conversion (ptr, complain));
    4024    345936869 :   if (pointer == error_mark_node)
    4025              :     return error_mark_node;
    4026              : 
    4027    345930998 :   type = TREE_TYPE (pointer);
    4028              : 
    4029    345930998 :   if (INDIRECT_TYPE_P (type))
    4030              :     {
    4031              :       /* [expr.unary.op]
    4032              : 
    4033              :          If the type of the expression is "pointer to T," the type
    4034              :          of  the  result  is  "T."  */
    4035    345930398 :       tree t = TREE_TYPE (type);
    4036              : 
    4037    326035811 :       if ((CONVERT_EXPR_P (ptr)
    4038    236872757 :            || TREE_CODE (ptr) == VIEW_CONVERT_EXPR)
    4039    437523409 :           && (!CLASS_TYPE_P (t) || !CLASSTYPE_EMPTY_P (t)))
    4040              :         {
    4041              :           /* If a warning is issued, mark it to avoid duplicates from
    4042              :              the backend.  This only needs to be done at
    4043              :              warn_strict_aliasing > 2.  */
    4044     87385659 :           if (warn_strict_aliasing > 2
    4045     87941336 :               && cp_strict_aliasing_warning (EXPR_LOCATION (ptr),
    4046       555677 :                                              type, TREE_OPERAND (ptr, 0)))
    4047            9 :             suppress_warning (ptr, OPT_Wstrict_aliasing);
    4048              :         }
    4049              : 
    4050    345930398 :       if (VOID_TYPE_P (t))
    4051              :         {
    4052              :           /* A pointer to incomplete type (other than cv void) can be
    4053              :              dereferenced [expr.unary.op]/1  */
    4054           48 :           if (complain & tf_error)
    4055           19 :             error_at (loc, "%qT is not a pointer-to-object type", type);
    4056           48 :           return error_mark_node;
    4057              :         }
    4058    334854935 :       else if (do_fold && TREE_CODE (pointer) == ADDR_EXPR
    4059    353550567 :                && same_type_p (t, TREE_TYPE (TREE_OPERAND (pointer, 0))))
    4060              :         /* The POINTER was something like `&x'.  We simplify `*&x' to
    4061              :            `x'.  This can change the value category: '*&TARGET_EXPR'
    4062              :            is an lvalue and folding it into 'TARGET_EXPR' turns it into
    4063              :            a prvalue of class type.  */
    4064      7620139 :         return TREE_OPERAND (pointer, 0);
    4065              :       else
    4066              :         {
    4067    338310211 :           tree ref = build1 (INDIRECT_REF, t, pointer);
    4068              : 
    4069              :           /* We *must* set TREE_READONLY when dereferencing a pointer to const,
    4070              :              so that we get the proper error message if the result is used
    4071              :              to assign to.  Also, &* is supposed to be a no-op.  */
    4072    338310211 :           TREE_READONLY (ref) = CP_TYPE_CONST_P (t);
    4073    338310211 :           TREE_THIS_VOLATILE (ref) = CP_TYPE_VOLATILE_P (t);
    4074    338310211 :           TREE_SIDE_EFFECTS (ref)
    4075    338310211 :             = (TREE_THIS_VOLATILE (ref) || TREE_SIDE_EFFECTS (pointer));
    4076    338310211 :           return ref;
    4077              :         }
    4078              :     }
    4079          600 :   else if (!(complain & tf_error))
    4080              :     /* Don't emit any errors; we'll just return ERROR_MARK_NODE later.  */
    4081              :     ;
    4082              :   /* `pointer' won't be an error_mark_node if we were given a
    4083              :      pointer to member, so it's cool to check for this here.  */
    4084           41 :   else if (TYPE_PTRMEM_P (type))
    4085           15 :     switch (errorstring)
    4086              :       {
    4087            0 :          case RO_ARRAY_INDEXING:
    4088            0 :            error_at (loc,
    4089              :                      "invalid use of array indexing on pointer to member");
    4090            0 :            break;
    4091           12 :          case RO_UNARY_STAR:
    4092           12 :            error_at (loc, "invalid use of unary %<*%> on pointer to member");
    4093           12 :            break;
    4094            0 :          case RO_IMPLICIT_CONVERSION:
    4095            0 :            error_at (loc, "invalid use of implicit conversion on pointer "
    4096              :                      "to member");
    4097            0 :            break;
    4098            3 :          case RO_ARROW_STAR:
    4099            3 :            error_at (loc, "left hand operand of %<->*%> must be a pointer to "
    4100              :                      "class, but is a pointer to member of type %qT", type);
    4101            3 :            break;
    4102            0 :          default:
    4103            0 :            gcc_unreachable ();
    4104              :       }
    4105           26 :   else if (pointer != error_mark_node)
    4106           26 :     invalid_indirection_error (loc, type, errorstring);
    4107              : 
    4108          600 :   return error_mark_node;
    4109              : }
    4110              : 
    4111              : /* Entry point used by c-common, which expects folding.  */
    4112              : 
    4113              : tree
    4114        69879 : build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring)
    4115              : {
    4116        69879 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring,
    4117        69879 :                                   tf_warning_or_error, true);
    4118              : }
    4119              : 
    4120              : /* Entry point used by internal indirection needs that don't correspond to any
    4121              :    syntactic construct.  */
    4122              : 
    4123              : tree
    4124    338666509 : cp_build_fold_indirect_ref (tree pointer)
    4125              : {
    4126    338666509 :   return cp_build_indirect_ref_1 (input_location, pointer, RO_NULL,
    4127    338666509 :                                   tf_warning_or_error, true);
    4128              : }
    4129              : 
    4130              : /* Entry point used by indirection needs that correspond to some syntactic
    4131              :    construct.  */
    4132              : 
    4133              : tree
    4134     29775058 : cp_build_indirect_ref (location_t loc, tree ptr, ref_operator errorstring,
    4135              :                        tsubst_flags_t complain)
    4136              : {
    4137     29775058 :   return cp_build_indirect_ref_1 (loc, ptr, errorstring, complain, false);
    4138              : }
    4139              : 
    4140              : /* This handles expressions of the form "a[i]", which denotes
    4141              :    an array reference.
    4142              : 
    4143              :    This is logically equivalent in C to *(a+i), but we may do it differently.
    4144              :    If A is a variable or a member, we generate a primitive ARRAY_REF.
    4145              :    This avoids forcing the array out of registers, and can work on
    4146              :    arrays that are not lvalues (for example, members of structures returned
    4147              :    by functions).
    4148              : 
    4149              :    If INDEX is of some user-defined type, it must be converted to
    4150              :    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
    4151              :    will inherit the type of the array, which will be some pointer type.
    4152              : 
    4153              :    LOC is the location to use in building the array reference.  */
    4154              : 
    4155              : tree
    4156      6196123 : cp_build_array_ref (location_t loc, tree array, tree idx,
    4157              :                     tsubst_flags_t complain)
    4158              : {
    4159      6196123 :   tree ret;
    4160              : 
    4161      6196123 :   if (idx == 0)
    4162              :     {
    4163            0 :       if (complain & tf_error)
    4164            0 :         error_at (loc, "subscript missing in array reference");
    4165            0 :       return error_mark_node;
    4166              :     }
    4167              : 
    4168      6196123 :   if (TREE_TYPE (array) == error_mark_node
    4169      6196123 :       || TREE_TYPE (idx) == error_mark_node)
    4170              :     return error_mark_node;
    4171              : 
    4172              :   /* 0[array] */
    4173      6196123 :   if (TREE_CODE (TREE_TYPE (idx)) == ARRAY_TYPE
    4174      6196123 :       && TREE_CODE (TREE_TYPE (array)) != ARRAY_TYPE)
    4175              :     {
    4176           10 :       std::swap (array, idx);
    4177              : 
    4178           10 :       tree first = NULL_TREE;
    4179           10 :       if (flag_strong_eval_order == 2 && TREE_SIDE_EFFECTS (array))
    4180            9 :         idx = first = save_expr (idx);
    4181           10 :       ret = cp_build_array_ref (loc, array, idx, complain);
    4182              : 
    4183           10 :       if (first)
    4184            9 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4185              :       return ret;
    4186              :     }
    4187              : 
    4188              :   /* If ARRAY is a COMPOUND_EXPR or COND_EXPR, move our reference
    4189              :      inside it.  */
    4190      6196113 :   switch (TREE_CODE (array))
    4191              :     {
    4192           28 :     case COMPOUND_EXPR:
    4193           28 :       {
    4194           28 :         tree value = cp_build_array_ref (loc, TREE_OPERAND (array, 1), idx,
    4195              :                                          complain);
    4196           28 :         ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
    4197           28 :                       TREE_OPERAND (array, 0), value);
    4198           28 :         SET_EXPR_LOCATION (ret, loc);
    4199           28 :         return ret;
    4200              :       }
    4201              : 
    4202           73 :     case COND_EXPR:
    4203           73 :       tree op0, op1, op2;
    4204           73 :       op0 = TREE_OPERAND (array, 0);
    4205           73 :       op1 = TREE_OPERAND (array, 1);
    4206           73 :       op2 = TREE_OPERAND (array, 2);
    4207           73 :       if (TREE_SIDE_EFFECTS (idx) || !tree_invariant_p (idx))
    4208              :         {
    4209              :           /* If idx could possibly have some SAVE_EXPRs, turning
    4210              :              (op0 ? op1 : op2)[idx] into
    4211              :              op0 ? op1[idx] : op2[idx] can lead into temporaries
    4212              :              initialized in one conditional path and uninitialized
    4213              :              uses of them in the other path.
    4214              :              And if idx is a really large expression, evaluating it
    4215              :              twice is also not optimal.
    4216              :              On the other side, op0 must be sequenced before evaluation
    4217              :              of op1 and op2 and for C++17 op0, op1 and op2 must be
    4218              :              sequenced before idx.
    4219              :              If idx is INTEGER_CST, we can just do the optimization
    4220              :              without any SAVE_EXPRs, if op1 and op2 are both ARRAY_TYPE
    4221              :              VAR_DECLs or COMPONENT_REFs thereof (so their address
    4222              :              is constant or relative to frame), optimize into
    4223              :              (SAVE_EXPR <op0>, SAVE_EXPR <idx>, SAVE_EXPR <op0>)
    4224              :              ? op1[SAVE_EXPR <idx>] : op2[SAVE_EXPR <idx>]
    4225              :              Otherwise avoid this optimization.  */
    4226           58 :           if (flag_strong_eval_order == 2)
    4227              :             {
    4228           39 :               if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    4229              :                 {
    4230           30 :                   if (!address_invariant_p (op1) || !address_invariant_p (op2))
    4231              :                     {
    4232              :                       /* Force default conversion on array if
    4233              :                          we can't optimize this and array is ARRAY_TYPE
    4234              :                          COND_EXPR, we can't leave COND_EXPRs with
    4235              :                          ARRAY_TYPE in the IL.  */
    4236            8 :                       array = cp_default_conversion (array, complain);
    4237            8 :                       if (error_operand_p (array))
    4238            0 :                         return error_mark_node;
    4239              :                       break;
    4240              :                     }
    4241              :                 }
    4242           16 :               else if (!POINTER_TYPE_P (TREE_TYPE (array))
    4243            2 :                        || !tree_invariant_p (op1)
    4244           11 :                        || !tree_invariant_p (op2))
    4245              :                 break;
    4246              :             }
    4247           43 :           if (TREE_SIDE_EFFECTS (idx))
    4248              :             {
    4249           18 :               idx = save_expr (idx);
    4250           18 :               op0 = save_expr (op0);
    4251           18 :               warning_sentinel w (warn_unused_value);
    4252           18 :               tree tem = build_compound_expr (loc, op0, idx);
    4253           18 :               op0 = build_compound_expr (loc, tem, op0);
    4254           18 :             }
    4255              :         }
    4256           58 :       op1 = cp_build_array_ref (loc, op1, idx, complain);
    4257           58 :       op2 = cp_build_array_ref (loc, op2, idx, complain);
    4258           58 :       ret = build_conditional_expr (loc, op0, op1, op2, complain);
    4259           58 :       protected_set_expr_location (ret, loc);
    4260           58 :       return ret;
    4261              : 
    4262              :     default:
    4263              :       break;
    4264              :     }
    4265              : 
    4266      6196027 :   bool non_lvalue = convert_vector_to_array_for_subscript (loc, &array, idx);
    4267              : 
    4268      6196027 :   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE)
    4269              :     {
    4270      1921282 :       tree rval, type;
    4271              : 
    4272      1921282 :       warn_array_subscript_with_type_char (loc, idx);
    4273              : 
    4274      1921282 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
    4275              :         {
    4276            6 :           if (complain & tf_error)
    4277            6 :             error_at (loc, "array subscript is not an integer");
    4278            6 :           return error_mark_node;
    4279              :         }
    4280              : 
    4281              :       /* Apply integral promotions *after* noticing character types.
    4282              :          (It is unclear why we do these promotions -- the standard
    4283              :          does not say that we should.  In fact, the natural thing would
    4284              :          seem to be to convert IDX to ptrdiff_t; we're performing
    4285              :          pointer arithmetic.)  */
    4286      1921276 :       idx = cp_perform_integral_promotions (idx, complain);
    4287              : 
    4288      1921276 :       idx = maybe_fold_non_dependent_expr (idx, complain);
    4289              : 
    4290              :       /* An array that is indexed by a non-constant
    4291              :          cannot be stored in a register; we must be able to do
    4292              :          address arithmetic on its address.
    4293              :          Likewise an array of elements of variable size.  */
    4294      1921276 :       if (TREE_CODE (idx) != INTEGER_CST
    4295      1921276 :           || (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (array)))
    4296       932088 :               && (TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))))
    4297              :                   != INTEGER_CST)))
    4298              :         {
    4299       990448 :           if (!cxx_mark_addressable (array, true))
    4300            0 :             return error_mark_node;
    4301              :         }
    4302              : 
    4303              :       /* An array that is indexed by a constant value which is not within
    4304              :          the array bounds cannot be stored in a register either; because we
    4305              :          would get a crash in store_bit_field/extract_bit_field when trying
    4306              :          to access a non-existent part of the register.  */
    4307      1921276 :       if (TREE_CODE (idx) == INTEGER_CST
    4308       932091 :           && TYPE_DOMAIN (TREE_TYPE (array))
    4309      2851969 :           && ! int_fits_type_p (idx, TYPE_DOMAIN (TREE_TYPE (array))))
    4310              :         {
    4311         3124 :           if (!cxx_mark_addressable (array))
    4312            0 :             return error_mark_node;
    4313              :         }
    4314              : 
    4315              :       /* Note in C++ it is valid to subscript a `register' array, since
    4316              :          it is valid to take the address of something with that
    4317              :          storage specification.  */
    4318      1921276 :       if (extra_warnings)
    4319              :         {
    4320        38852 :           tree foo = array;
    4321        59542 :           while (TREE_CODE (foo) == COMPONENT_REF)
    4322        20690 :             foo = TREE_OPERAND (foo, 0);
    4323            8 :           if (VAR_P (foo) && DECL_REGISTER (foo)
    4324        38852 :               && (complain & tf_warning))
    4325            0 :             warning_at (loc, OPT_Wextra,
    4326              :                         "subscripting array declared %<register%>");
    4327              :         }
    4328              : 
    4329      1921276 :       type = TREE_TYPE (TREE_TYPE (array));
    4330      1921276 :       rval = build4 (ARRAY_REF, type, array, idx, NULL_TREE, NULL_TREE);
    4331              :       /* Array ref is const/volatile if the array elements are
    4332              :          or if the array is..  */
    4333      5763828 :       TREE_READONLY (rval)
    4334      1921276 :         |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
    4335      5763828 :       TREE_SIDE_EFFECTS (rval)
    4336      1921276 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
    4337      3842552 :       TREE_THIS_VOLATILE (rval)
    4338      1921276 :         |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
    4339      1921276 :       ret = require_complete_type (rval, complain);
    4340      1921276 :       protected_set_expr_location (ret, loc);
    4341      1921276 :       if (non_lvalue)
    4342        38431 :         ret = non_lvalue_loc (loc, ret);
    4343              :       return ret;
    4344              :     }
    4345              : 
    4346      4274745 :   {
    4347      4274745 :     tree ar = cp_default_conversion (array, complain);
    4348      4274745 :     tree ind = cp_default_conversion (idx, complain);
    4349      4274745 :     tree first = NULL_TREE;
    4350              : 
    4351      2772988 :     if (!processing_template_decl && flag_strong_eval_order == 2
    4352      7007438 :         && TREE_SIDE_EFFECTS (ind))
    4353        94085 :       ar = first = save_expr (ar);
    4354              : 
    4355              :     /* Put the integer in IND to simplify error checking.  */
    4356      4274745 :     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
    4357           57 :       std::swap (ar, ind);
    4358              : 
    4359      4274745 :     if (ar == error_mark_node || ind == error_mark_node)
    4360              :       return error_mark_node;
    4361              : 
    4362      4274745 :     if (!TYPE_PTR_P (TREE_TYPE (ar)))
    4363              :       {
    4364           74 :         if (complain & tf_error)
    4365            3 :           error_at (loc, "subscripted value is neither array nor pointer");
    4366           74 :         return error_mark_node;
    4367              :       }
    4368      4274671 :     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
    4369              :       {
    4370            0 :         if (complain & tf_error)
    4371            0 :           error_at (loc, "array subscript is not an integer");
    4372            0 :         return error_mark_node;
    4373              :       }
    4374              : 
    4375      4274671 :     warn_array_subscript_with_type_char (loc, idx);
    4376              : 
    4377      4274671 :     ret = cp_build_binary_op (input_location, PLUS_EXPR, ar, ind, complain);
    4378      4274671 :     if (first)
    4379        94085 :       ret = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (ret), first, ret);
    4380      4274671 :     ret = cp_build_indirect_ref (loc, ret, RO_ARRAY_INDEXING, complain);
    4381      4274671 :     protected_set_expr_location (ret, loc);
    4382      4274671 :     if (non_lvalue)
    4383            0 :       ret = non_lvalue_loc (loc, ret);
    4384              :     return ret;
    4385              :   }
    4386              : }
    4387              : 
    4388              : /* Entry point for Obj-C++.  */
    4389              : 
    4390              : tree
    4391      3731370 : build_array_ref (location_t loc, tree array, tree idx)
    4392              : {
    4393      3731370 :   return cp_build_array_ref (loc, array, idx, tf_warning_or_error);
    4394              : }
    4395              : 
    4396              : /* Resolve a pointer to member function.  INSTANCE is the object
    4397              :    instance to use, if the member points to a virtual member.
    4398              : 
    4399              :    This used to avoid checking for virtual functions if basetype
    4400              :    has no virtual functions, according to an earlier ANSI draft.
    4401              :    With the final ISO C++ rules, such an optimization is
    4402              :    incorrect: A pointer to a derived member can be static_cast
    4403              :    to pointer-to-base-member, as long as the dynamic object
    4404              :    later has the right member.  So now we only do this optimization
    4405              :    when we know the dynamic type of the object.  */
    4406              : 
    4407              : tree
    4408        86870 : get_member_function_from_ptrfunc (tree *instance_ptrptr, tree function,
    4409              :                                   tsubst_flags_t complain)
    4410              : {
    4411        86870 :   if (TREE_CODE (function) == OFFSET_REF)
    4412            0 :     function = TREE_OPERAND (function, 1);
    4413              : 
    4414        86870 :   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
    4415              :     {
    4416        86870 :       tree idx, delta, e1, e2, e3, vtbl;
    4417        86870 :       bool nonvirtual;
    4418        86870 :       tree fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
    4419        86870 :       tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (fntype));
    4420              : 
    4421        86870 :       tree instance_ptr = *instance_ptrptr;
    4422        86870 :       tree instance_save_expr = 0;
    4423        86870 :       if (instance_ptr == error_mark_node)
    4424              :         {
    4425            0 :           if (TREE_CODE (function) == PTRMEM_CST)
    4426              :             {
    4427              :               /* Extracting the function address from a pmf is only
    4428              :                  allowed with -Wno-pmf-conversions. It only works for
    4429              :                  pmf constants.  */
    4430            0 :               e1 = build_addr_func (PTRMEM_CST_MEMBER (function), complain);
    4431            0 :               e1 = convert (fntype, e1);
    4432            0 :               return e1;
    4433              :             }
    4434              :           else
    4435              :             {
    4436            0 :               if (complain & tf_error)
    4437            0 :                 error ("object missing in use of %qE", function);
    4438            0 :               return error_mark_node;
    4439              :             }
    4440              :         }
    4441              : 
    4442              :       /* True if we know that the dynamic type of the object doesn't have
    4443              :          virtual functions, so we can assume the PFN field is a pointer.  */
    4444        86870 :       nonvirtual = (COMPLETE_TYPE_P (basetype)
    4445        86834 :                     && !TYPE_POLYMORPHIC_P (basetype)
    4446       117054 :                     && resolves_to_fixed_type_p (instance_ptr, 0));
    4447              : 
    4448              :       /* If we don't really have an object (i.e. in an ill-formed
    4449              :          conversion from PMF to pointer), we can't resolve virtual
    4450              :          functions anyway.  */
    4451        86610 :       if (!nonvirtual && is_dummy_object (instance_ptr))
    4452              :         nonvirtual = true;
    4453              : 
    4454              :       /* Use force_target_expr even when instance_ptr doesn't have
    4455              :          side-effects, unless it is a simple decl or constant, so
    4456              :          that we don't ubsan instrument the expression multiple times.
    4457              :          Don't use save_expr, as save_expr can avoid building a SAVE_EXPR
    4458              :          and building a SAVE_EXPR manually can be optimized away during
    4459              :          cp_fold.  See PR116449 and PR117259.  */
    4460        86870 :       if (TREE_SIDE_EFFECTS (instance_ptr)
    4461        86870 :           || (!nonvirtual
    4462        48512 :               && !DECL_P (instance_ptr)
    4463        48512 :               && !TREE_CONSTANT (instance_ptr)))
    4464        86027 :         instance_ptr = instance_save_expr
    4465        86027 :           = get_internal_target_expr (instance_ptr);
    4466              : 
    4467              :       /* See above comment.  */
    4468        86870 :       if (TREE_SIDE_EFFECTS (function)
    4469        86870 :           || (!nonvirtual
    4470        67332 :               && !DECL_P (function)
    4471        67320 :               && !TREE_CONSTANT (function)))
    4472        86408 :         function = get_internal_target_expr (function);
    4473              : 
    4474              :       /* Start by extracting all the information from the PMF itself.  */
    4475        86870 :       e3 = pfn_from_ptrmemfunc (function);
    4476        86870 :       delta = delta_from_ptrmemfunc (function);
    4477        86870 :       idx = build1 (NOP_EXPR, vtable_index_type, e3);
    4478        86870 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
    4479              :         {
    4480        86870 :           sanitize_code_type flag_sanitize_save;
    4481        86870 :         case ptrmemfunc_vbit_in_pfn:
    4482        86870 :           e1 = cp_build_binary_op (input_location,
    4483              :                                    BIT_AND_EXPR, idx, integer_one_node,
    4484              :                                    complain);
    4485        86870 :           idx = cp_build_binary_op (input_location,
    4486              :                                     MINUS_EXPR, idx, integer_one_node,
    4487              :                                     complain);
    4488        86870 :           if (idx == error_mark_node)
    4489              :             return error_mark_node;
    4490        86870 :           break;
    4491              : 
    4492              :         case ptrmemfunc_vbit_in_delta:
    4493              :           e1 = cp_build_binary_op (input_location,
    4494              :                                    BIT_AND_EXPR, delta, integer_one_node,
    4495              :                                    complain);
    4496              :           /* Don't instrument the RSHIFT_EXPR we're about to create because
    4497              :              we're going to use DELTA number of times, and that wouldn't play
    4498              :              well with SAVE_EXPRs therein.  */
    4499              :           flag_sanitize_save = flag_sanitize;
    4500              :           flag_sanitize = 0;
    4501              :           delta = cp_build_binary_op (input_location,
    4502              :                                       RSHIFT_EXPR, delta, integer_one_node,
    4503              :                                       complain);
    4504              :           flag_sanitize = flag_sanitize_save;
    4505              :           if (delta == error_mark_node)
    4506              :             return error_mark_node;
    4507              :           break;
    4508              : 
    4509              :         default:
    4510              :           gcc_unreachable ();
    4511              :         }
    4512              : 
    4513        86870 :       if (e1 == error_mark_node)
    4514              :         return error_mark_node;
    4515              : 
    4516              :       /* Convert down to the right base before using the instance.  A
    4517              :          special case is that in a pointer to member of class C, C may
    4518              :          be incomplete.  In that case, the function will of course be
    4519              :          a member of C, and no conversion is required.  In fact,
    4520              :          lookup_base will fail in that case, because incomplete
    4521              :          classes do not have BINFOs.  */
    4522        86870 :       if (!same_type_ignoring_top_level_qualifiers_p
    4523        86870 :           (basetype, TREE_TYPE (TREE_TYPE (instance_ptr))))
    4524              :         {
    4525           99 :           basetype = lookup_base (TREE_TYPE (TREE_TYPE (instance_ptr)),
    4526              :                                   basetype, ba_check, NULL, complain);
    4527           99 :           instance_ptr = build_base_path (PLUS_EXPR, instance_ptr, basetype,
    4528              :                                           1, complain);
    4529           99 :           if (instance_ptr == error_mark_node)
    4530              :             return error_mark_node;
    4531              :         }
    4532              :       /* ...and then the delta in the PMF.  */
    4533        86870 :       instance_ptr = fold_build_pointer_plus (instance_ptr, delta);
    4534              : 
    4535              :       /* Hand back the adjusted 'this' argument to our caller.  */
    4536        86870 :       *instance_ptrptr = instance_ptr;
    4537              : 
    4538        86870 :       if (nonvirtual)
    4539              :         /* Now just return the pointer.  */
    4540              :         return e3;
    4541              : 
    4542              :       /* Next extract the vtable pointer from the object.  */
    4543        86592 :       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
    4544              :                      instance_ptr);
    4545        86592 :       vtbl = cp_build_fold_indirect_ref (vtbl);
    4546        86592 :       if (vtbl == error_mark_node)
    4547              :         return error_mark_node;
    4548              : 
    4549              :       /* Finally, extract the function pointer from the vtable.  */
    4550        86592 :       e2 = fold_build_pointer_plus_loc (input_location, vtbl, idx);
    4551        86592 :       e2 = cp_build_fold_indirect_ref (e2);
    4552        86592 :       if (e2 == error_mark_node)
    4553              :         return error_mark_node;
    4554        86592 :       TREE_CONSTANT (e2) = 1;
    4555              : 
    4556              :       /* When using function descriptors, the address of the
    4557              :          vtable entry is treated as a function pointer.  */
    4558        86592 :       if (TARGET_VTABLE_USES_DESCRIPTORS)
    4559              :         e2 = build1 (NOP_EXPR, TREE_TYPE (e2),
    4560              :                      cp_build_addr_expr (e2, complain));
    4561              : 
    4562        86592 :       e2 = fold_convert (TREE_TYPE (e3), e2);
    4563        86592 :       e1 = build_conditional_expr (input_location, e1, e2, e3, complain);
    4564        86592 :       if (e1 == error_mark_node)
    4565              :         return error_mark_node;
    4566              : 
    4567              :       /* Make sure this doesn't get evaluated first inside one of the
    4568              :          branches of the COND_EXPR.  */
    4569        86592 :       if (instance_save_expr)
    4570        85979 :         e1 = build2 (COMPOUND_EXPR, TREE_TYPE (e1),
    4571              :                      instance_save_expr, e1);
    4572              : 
    4573              :       function = e1;
    4574              :     }
    4575              :   return function;
    4576              : }
    4577              : 
    4578              : /* Used by the C-common bits.  */
    4579              : tree
    4580            0 : build_function_call (location_t /*loc*/,
    4581              :                      tree function, tree params)
    4582              : {
    4583            0 :   return cp_build_function_call (function, params, tf_warning_or_error);
    4584              : }
    4585              : 
    4586              : /* Used by the C-common bits.  */
    4587              : tree
    4588       340461 : build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
    4589              :                          tree function, vec<tree, va_gc> *params,
    4590              :                          vec<tree, va_gc> * /*origtypes*/, tree orig_function)
    4591              : {
    4592       340461 :   vec<tree, va_gc> *orig_params = params;
    4593       340461 :   tree ret = cp_build_function_call_vec (function, &params,
    4594              :                                          tf_warning_or_error, orig_function);
    4595              : 
    4596              :   /* cp_build_function_call_vec can reallocate PARAMS by adding
    4597              :      default arguments.  That should never happen here.  Verify
    4598              :      that.  */
    4599       340461 :   gcc_assert (params == orig_params);
    4600              : 
    4601       340461 :   return ret;
    4602              : }
    4603              : 
    4604              : /* Build a function call using a tree list of arguments.  */
    4605              : 
    4606              : static tree
    4607            0 : cp_build_function_call (tree function, tree params, tsubst_flags_t complain)
    4608              : {
    4609            0 :   tree ret;
    4610              : 
    4611            0 :   releasing_vec vec;
    4612            0 :   for (; params != NULL_TREE; params = TREE_CHAIN (params))
    4613            0 :     vec_safe_push (vec, TREE_VALUE (params));
    4614            0 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4615            0 :   return ret;
    4616            0 : }
    4617              : 
    4618              : /* Build a function call using varargs.  */
    4619              : 
    4620              : tree
    4621       615676 : cp_build_function_call_nary (tree function, tsubst_flags_t complain, ...)
    4622              : {
    4623       615676 :   va_list args;
    4624       615676 :   tree ret, t;
    4625              : 
    4626       615676 :   releasing_vec vec;
    4627       615676 :   va_start (args, complain);
    4628      1539055 :   for (t = va_arg (args, tree); t != NULL_TREE; t = va_arg (args, tree))
    4629       923379 :     vec_safe_push (vec, t);
    4630       615676 :   va_end (args);
    4631       615676 :   ret = cp_build_function_call_vec (function, &vec, complain);
    4632       615676 :   return ret;
    4633       615676 : }
    4634              : 
    4635              : /* C++ implementation of callback for use when checking param types.  */
    4636              : 
    4637              : bool
    4638           18 : cp_comp_parm_types (tree wanted_type, tree actual_type)
    4639              : {
    4640           18 :   if (TREE_CODE (wanted_type) == POINTER_TYPE
    4641           18 :       && TREE_CODE (actual_type) == POINTER_TYPE)
    4642           15 :     return same_or_base_type_p (TREE_TYPE (wanted_type),
    4643              :                                 TREE_TYPE (actual_type));
    4644              :   return false;
    4645              : }
    4646              : 
    4647              : /* Build a function call using a vector of arguments.
    4648              :    If FUNCTION is the result of resolving an overloaded target built-in,
    4649              :    ORIG_FNDECL is the original function decl, otherwise it is null.
    4650              :    PARAMS may be NULL if there are no parameters.  This changes the
    4651              :    contents of PARAMS.  */
    4652              : 
    4653              : tree
    4654      7803992 : cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
    4655              :                             tsubst_flags_t complain, tree orig_fndecl)
    4656              : {
    4657      7803992 :   tree fntype, fndecl;
    4658      7803992 :   int is_method;
    4659      7803992 :   tree original = function;
    4660      7803992 :   int nargs;
    4661      7803992 :   tree *argarray;
    4662      7803992 :   tree parm_types;
    4663      7803992 :   vec<tree, va_gc> *allocated = NULL;
    4664      7803992 :   tree ret;
    4665              : 
    4666              :   /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
    4667              :      expressions, like those used for ObjC messenger dispatches.  */
    4668      7803992 :   if (params != NULL && !vec_safe_is_empty (*params))
    4669      2229136 :     function = objc_rewrite_function_call (function, (**params)[0]);
    4670              : 
    4671              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4672              :      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
    4673      7803992 :   if (TREE_CODE (function) == NOP_EXPR
    4674      7803992 :       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
    4675           19 :     function = TREE_OPERAND (function, 0);
    4676              : 
    4677      7803992 :   if (TREE_CODE (function) == FUNCTION_DECL)
    4678              :     {
    4679      1687780 :       if (!mark_used (function, complain))
    4680           24 :         return error_mark_node;
    4681      1687756 :       fndecl = function;
    4682              : 
    4683              :       /* For target_version semantics, the function set cannot be called
    4684              :          if there is no default version in scope.  */
    4685      1687756 :       if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    4686              :            && !is_function_default_version (fndecl))
    4687              :          {
    4688              :            if (complain & tf_error)
    4689              :             error ("no default version in scope");
    4690              :            return error_mark_node;
    4691              :          }
    4692              : 
    4693              :       /* Convert anything with function type to a pointer-to-function.  */
    4694      1687756 :       if (DECL_MAIN_P (function))
    4695              :         {
    4696            0 :           if (complain & tf_error)
    4697            0 :             pedwarn (input_location, OPT_Wpedantic,
    4698              :                      "ISO C++ forbids calling %<::main%> from within program");
    4699              :           else
    4700            0 :             return error_mark_node;
    4701              :         }
    4702      1687756 :       function = build_addr_func (function, complain);
    4703              :     }
    4704              :   else
    4705              :     {
    4706      6116212 :       fndecl = NULL_TREE;
    4707              : 
    4708      6116212 :       function = build_addr_func (function, complain);
    4709              :     }
    4710              : 
    4711      7803968 :   if (function == error_mark_node)
    4712              :     return error_mark_node;
    4713              : 
    4714      7803866 :   fntype = TREE_TYPE (function);
    4715              : 
    4716      7803866 :   if (TYPE_PTRMEMFUNC_P (fntype))
    4717              :     {
    4718           15 :       if (complain & tf_error)
    4719           15 :         error ("must use %<.*%> or %<->*%> to call pointer-to-member "
    4720              :                "function in %<%E (...)%>, e.g. %<(... ->* %E) (...)%>",
    4721              :                original, original);
    4722           15 :       return error_mark_node;
    4723              :     }
    4724              : 
    4725     15607702 :   is_method = (TYPE_PTR_P (fntype)
    4726      7803851 :                && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
    4727              : 
    4728      7803851 :   if (!(TYPE_PTRFN_P (fntype)
    4729        89080 :         || is_method
    4730         2269 :         || TREE_CODE (function) == TEMPLATE_ID_EXPR))
    4731              :     {
    4732         2269 :       if (complain & tf_error)
    4733              :         {
    4734          178 :           if (is_stub_object (original))
    4735            3 :             error_at (input_location,
    4736              :                       "%qT cannot be used as a function",
    4737            3 :                       TREE_TYPE (original));
    4738          175 :           else if (!flag_diagnostics_show_caret)
    4739          175 :             error_at (input_location,
    4740              :                       "%qE cannot be used as a function", original);
    4741            0 :           else if (DECL_P (original))
    4742            0 :             error_at (input_location,
    4743              :                       "%qD cannot be used as a function", original);
    4744              :           else
    4745            0 :             error_at (input_location,
    4746              :                       "expression cannot be used as a function");
    4747              :         }
    4748              : 
    4749         2269 :       return error_mark_node;
    4750              :     }
    4751              : 
    4752              :   /* fntype now gets the type of function pointed to.  */
    4753      7801582 :   fntype = TREE_TYPE (fntype);
    4754      7801582 :   parm_types = TYPE_ARG_TYPES (fntype);
    4755              : 
    4756      7801582 :   if (params == NULL)
    4757              :     {
    4758       160430 :       allocated = make_tree_vector ();
    4759       160430 :       params = &allocated;
    4760              :     }
    4761              : 
    4762      7801582 :     nargs = convert_arguments (parm_types, params, fndecl, LOOKUP_NORMAL,
    4763              :                                complain);
    4764      7801582 :   if (nargs < 0)
    4765         2242 :     return error_mark_node;
    4766              : 
    4767      7799340 :   argarray = (*params)->address ();
    4768              : 
    4769              :   /* Check for errors in format strings and inappropriately
    4770              :      null parameters.  */
    4771      7799340 :   bool warned_p
    4772      7799340 :     = ((complain & tf_warning)
    4773      7799340 :        && check_function_arguments (input_location, fndecl, fntype,
    4774              :                                     nargs, argarray, NULL,
    4775      7799340 :                                     cp_comp_parm_types));
    4776              : 
    4777      7799340 :   ret = build_cxx_call (function, nargs, argarray, complain, orig_fndecl);
    4778              : 
    4779      7799340 :   if (warned_p)
    4780              :     {
    4781           27 :       tree c = extract_call_expr (ret);
    4782           27 :       if (TREE_CODE (c) == CALL_EXPR)
    4783           27 :         suppress_warning (c, OPT_Wnonnull);
    4784              :     }
    4785              : 
    4786      7799340 :   if (allocated != NULL)
    4787       160430 :     release_tree_vector (allocated);
    4788              : 
    4789              :   return ret;
    4790              : }
    4791              : 
    4792              : /* Subroutine of convert_arguments.
    4793              :    Print an error message about a wrong number of arguments.  */
    4794              : 
    4795              : static void
    4796          162 : error_args_num (location_t loc, tree fndecl, bool too_many_p)
    4797              : {
    4798          162 :   if (fndecl)
    4799              :     {
    4800          126 :       auto_diagnostic_group d;
    4801          126 :       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
    4802              :         {
    4803            0 :           if (DECL_NAME (fndecl) == NULL_TREE
    4804            0 :               || (DECL_NAME (fndecl)
    4805            0 :                   == DECL_NAME (TYPE_NAME (DECL_CONTEXT (fndecl)))))
    4806            0 :             error_at (loc,
    4807              :                       too_many_p
    4808              :                       ? G_("too many arguments to constructor %q#D")
    4809              :                       : G_("too few arguments to constructor %q#D"),
    4810              :                       fndecl);
    4811              :           else
    4812            0 :             error_at (loc,
    4813              :                       too_many_p
    4814              :                       ? G_("too many arguments to member function %q#D")
    4815              :                       : G_("too few arguments to member function %q#D"),
    4816              :                       fndecl);
    4817              :         }
    4818              :       else
    4819          189 :         error_at (loc,
    4820              :                   too_many_p
    4821              :                   ? G_("too many arguments to function %q#D")
    4822              :                   : G_("too few arguments to function %q#D"),
    4823              :                   fndecl);
    4824          126 :       if (!DECL_IS_UNDECLARED_BUILTIN (fndecl))
    4825           87 :         inform (DECL_SOURCE_LOCATION (fndecl), "declared here");
    4826          126 :     }
    4827              :   else
    4828              :     {
    4829           36 :       if (c_dialect_objc ()  &&  objc_message_selector ())
    4830            0 :         error_at (loc,
    4831              :                   too_many_p
    4832              :                   ? G_("too many arguments to method %q#D")
    4833              :                   : G_("too few arguments to method %q#D"),
    4834              :                   objc_message_selector ());
    4835              :       else
    4836           57 :         error_at (loc, too_many_p ? G_("too many arguments to function")
    4837              :                                   : G_("too few arguments to function"));
    4838              :     }
    4839          162 : }
    4840              : 
    4841              : /* Convert the actual parameter expressions in the list VALUES to the
    4842              :    types in the list TYPELIST.  The converted expressions are stored
    4843              :    back in the VALUES vector.
    4844              :    If parmdecls is exhausted, or when an element has NULL as its type,
    4845              :    perform the default conversions.
    4846              : 
    4847              :    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
    4848              : 
    4849              :    This is also where warnings about wrong number of args are generated.
    4850              : 
    4851              :    Returns the actual number of arguments processed (which might be less
    4852              :    than the length of the vector), or -1 on error.
    4853              : 
    4854              :    In C++, unspecified trailing parameters can be filled in with their
    4855              :    default arguments, if such were specified.  Do so here.  */
    4856              : 
    4857              : static int
    4858      7801582 : convert_arguments (tree typelist, vec<tree, va_gc> **values, tree fndecl,
    4859              :                    int flags, tsubst_flags_t complain)
    4860              : {
    4861      7801582 :   tree typetail;
    4862      7801582 :   unsigned int i;
    4863              : 
    4864              :   /* Argument passing is always copy-initialization.  */
    4865      7801582 :   flags |= LOOKUP_ONLYCONVERTING;
    4866              : 
    4867     12636326 :   for (i = 0, typetail = typelist;
    4868     12636326 :        i < vec_safe_length (*values);
    4869              :        i++)
    4870              :     {
    4871      9673126 :       tree type = typetail ? TREE_VALUE (typetail) : 0;
    4872      4836786 :       tree val = (**values)[i];
    4873              : 
    4874      4836786 :       if (val == error_mark_node || type == error_mark_node)
    4875              :         return -1;
    4876              : 
    4877      4836780 :       if (type == void_type_node)
    4878              :         {
    4879          232 :           if (complain & tf_error)
    4880           78 :             error_args_num (input_location, fndecl, /*too_many_p=*/true);
    4881              :           return -1;
    4882              :         }
    4883              : 
    4884              :       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    4885              :          Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
    4886      4836548 :       if (TREE_CODE (val) == NOP_EXPR
    4887      1264419 :           && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
    4888      4836566 :           && (type == 0 || !TYPE_REF_P (type)))
    4889           18 :         val = TREE_OPERAND (val, 0);
    4890              : 
    4891      4836548 :       if (type == 0 || !TYPE_REF_P (type))
    4892              :         {
    4893      4630730 :           if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
    4894      4630730 :               || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (val)))
    4895        11052 :             val = decay_conversion (val, complain);
    4896              :         }
    4897              : 
    4898      4836548 :       if (val == error_mark_node)
    4899              :         return -1;
    4900              : 
    4901      4836548 :       if (type != 0)
    4902              :         {
    4903              :           /* Formal parm type is specified by a function prototype.  */
    4904      4836102 :           tree parmval;
    4905              : 
    4906      4836102 :           if (!COMPLETE_TYPE_P (complete_type (type)))
    4907              :             {
    4908           18 :               if (complain & tf_error)
    4909              :                 {
    4910           12 :                   location_t loc = EXPR_LOC_OR_LOC (val, input_location);
    4911           12 :                   if (fndecl)
    4912              :                     {
    4913           12 :                       auto_diagnostic_group d;
    4914           12 :                       error_at (loc,
    4915              :                                 "parameter %P of %qD has incomplete type %qT",
    4916              :                                 i, fndecl, type);
    4917           12 :                       inform (get_fndecl_argument_location (fndecl, i),
    4918              :                               "  declared here");
    4919           12 :                     }
    4920              :                   else
    4921            0 :                     error_at (loc, "parameter %P has incomplete type %qT", i,
    4922              :                               type);
    4923              :                 }
    4924           18 :               parmval = error_mark_node;
    4925              :             }
    4926              :           else
    4927              :             {
    4928      4836084 :               parmval = convert_for_initialization
    4929      4836084 :                 (NULL_TREE, type, val, flags,
    4930              :                  ICR_ARGPASS, fndecl, i, complain);
    4931      4836084 :               parmval = convert_for_arg_passing (type, parmval, complain);
    4932              :             }
    4933              : 
    4934      4836102 :           if (parmval == error_mark_node)
    4935              :             return -1;
    4936              : 
    4937      4834298 :           (**values)[i] = parmval;
    4938              :         }
    4939              :       else
    4940              :         {
    4941          446 :           int magic = fndecl ? magic_varargs_p (fndecl) : 0;
    4942           21 :           if (magic)
    4943              :             {
    4944              :               /* Don't truncate excess precision to the semantic type.  */
    4945            0 :               if (magic == 1 && TREE_CODE (val) == EXCESS_PRECISION_EXPR)
    4946            0 :                 val = TREE_OPERAND (val, 0);
    4947              :               /* Don't do ellipsis conversion for __built_in_constant_p
    4948              :                  as this will result in spurious errors for non-trivial
    4949              :                  types.  */
    4950            0 :               val = require_complete_type (val, complain);
    4951              :             }
    4952              :           else
    4953          446 :             val = convert_arg_to_ellipsis (val, complain);
    4954              : 
    4955          446 :           (**values)[i] = val;
    4956              :         }
    4957              : 
    4958      4834744 :       if (typetail)
    4959      4834298 :         typetail = TREE_CHAIN (typetail);
    4960              :     }
    4961              : 
    4962      7799540 :   if (typetail != 0 && typetail != void_list_node)
    4963              :     {
    4964              :       /* See if there are default arguments that can be used.  Because
    4965              :          we hold default arguments in the FUNCTION_TYPE (which is so
    4966              :          wrong), we can see default parameters here from deduced
    4967              :          contexts (and via typeof) for indirect function calls.
    4968              :          Fortunately we know whether we have a function decl to
    4969              :          provide default arguments in a language conformant
    4970              :          manner.  */
    4971           63 :       if (fndecl && TREE_PURPOSE (typetail)
    4972          203 :           && TREE_CODE (TREE_PURPOSE (typetail)) != DEFERRED_PARSE)
    4973              :         {
    4974            6 :           for (; typetail != void_list_node; ++i)
    4975              :             {
    4976              :               /* After DR777, with explicit template args we can end up with a
    4977              :                  default argument followed by no default argument.  */
    4978            6 :               if (!TREE_PURPOSE (typetail))
    4979              :                 break;
    4980            3 :               tree parmval
    4981            3 :                 = convert_default_arg (TREE_VALUE (typetail),
    4982            3 :                                        TREE_PURPOSE (typetail),
    4983            3 :                                        fndecl, i, complain);
    4984              : 
    4985            3 :               if (parmval == error_mark_node)
    4986            0 :                 return -1;
    4987              : 
    4988            3 :               vec_safe_push (*values, parmval);
    4989            3 :               typetail = TREE_CHAIN (typetail);
    4990              :               /* ends with `...'.  */
    4991            3 :               if (typetail == NULL_TREE)
    4992              :                 break;
    4993              :             }
    4994              :         }
    4995              : 
    4996          200 :       if (typetail && typetail != void_list_node)
    4997              :         {
    4998          200 :           if (complain & tf_error)
    4999           84 :             error_args_num (input_location, fndecl, /*too_many_p=*/false);
    5000              :           return -1;
    5001              :         }
    5002              :     }
    5003              : 
    5004      7799340 :   return (int) i;
    5005              : }
    5006              : 
    5007              : /* Build a binary-operation expression, after performing default
    5008              :    conversions on the operands.  CODE is the kind of expression to
    5009              :    build.  ARG1 and ARG2 are the arguments.  ARG1_CODE and ARG2_CODE
    5010              :    are the tree codes which correspond to ARG1 and ARG2 when issuing
    5011              :    warnings about possibly misplaced parentheses.  They may differ
    5012              :    from the TREE_CODE of ARG1 and ARG2 if the parser has done constant
    5013              :    folding (e.g., if the parser sees "a | 1 + 1", it may call this
    5014              :    routine with ARG2 being an INTEGER_CST and ARG2_CODE == PLUS_EXPR).
    5015              :    To avoid issuing any parentheses warnings, pass ARG1_CODE and/or
    5016              :    ARG2_CODE as ERROR_MARK.  */
    5017              : 
    5018              : tree
    5019    238931931 : build_x_binary_op (const op_location_t &loc, enum tree_code code, tree arg1,
    5020              :                    enum tree_code arg1_code, tree arg2,
    5021              :                    enum tree_code arg2_code, tree lookups,
    5022              :                    tree *overload_p, tsubst_flags_t complain)
    5023              : {
    5024    238931931 :   tree orig_arg1;
    5025    238931931 :   tree orig_arg2;
    5026    238931931 :   tree expr;
    5027    238931931 :   tree overload = NULL_TREE;
    5028              : 
    5029    238931931 :   orig_arg1 = arg1;
    5030    238931931 :   orig_arg2 = arg2;
    5031              : 
    5032    238931931 :   if (processing_template_decl)
    5033              :     {
    5034    140206356 :       if (type_dependent_expression_p (arg1)
    5035    140206356 :           || type_dependent_expression_p (arg2))
    5036              :         {
    5037     95536780 :           expr = build_min_nt_loc (loc, code, arg1, arg2);
    5038     95536780 :           TREE_TYPE (expr)
    5039     95536780 :             = build_dependent_operator_type (lookups, code, false);
    5040     95536780 :           return expr;
    5041              :         }
    5042              :     }
    5043              : 
    5044    143395151 :   if (code == DOTSTAR_EXPR)
    5045        86930 :     expr = build_m_component_ref (arg1, arg2, complain);
    5046              :   else
    5047    143308221 :     expr = build_new_op (loc, code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
    5048              :                          lookups, &overload, complain);
    5049              : 
    5050    143395118 :   if (overload_p != NULL)
    5051     63302889 :     *overload_p = overload;
    5052              : 
    5053              :   /* Check for cases such as x+y<<z which users are likely to
    5054              :      misinterpret.  But don't warn about obj << x + y, since that is a
    5055              :      common idiom for I/O.  */
    5056    143395118 :   if (warn_parentheses
    5057      1262370 :       && (complain & tf_warning)
    5058      1204313 :       && !processing_template_decl
    5059       821880 :       && !error_operand_p (arg1)
    5060       821874 :       && !error_operand_p (arg2)
    5061    144216980 :       && (code != LSHIFT_EXPR
    5062        71195 :           || !CLASS_TYPE_P (TREE_TYPE (arg1))))
    5063       820815 :     warn_about_parentheses (loc, code, arg1_code, orig_arg1,
    5064              :                             arg2_code, orig_arg2);
    5065              : 
    5066    143395118 :   if (processing_template_decl && expr != error_mark_node)
    5067              :     {
    5068     44669329 :       if (overload != NULL_TREE)
    5069      3920715 :         return (build_min_non_dep_op_overload
    5070      3920715 :                 (code, expr, overload, orig_arg1, orig_arg2));
    5071              : 
    5072     40748614 :       return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
    5073              :     }
    5074              : 
    5075              :   return expr;
    5076              : }
    5077              : 
    5078              : /* Build and return an ARRAY_REF expression.  */
    5079              : 
    5080              : tree
    5081      2622624 : build_x_array_ref (location_t loc, tree arg1, tree arg2,
    5082              :                    tsubst_flags_t complain)
    5083              : {
    5084      2622624 :   tree orig_arg1 = arg1;
    5085      2622624 :   tree orig_arg2 = arg2;
    5086      2622624 :   tree expr;
    5087      2622624 :   tree overload = NULL_TREE;
    5088              : 
    5089      2622624 :   if (processing_template_decl)
    5090              :     {
    5091         9499 :       if (type_dependent_expression_p (arg1)
    5092         9499 :           || type_dependent_expression_p (arg2))
    5093         4551 :         return build_min_nt_loc (loc, ARRAY_REF, arg1, arg2,
    5094         4551 :                                  NULL_TREE, NULL_TREE);
    5095              :     }
    5096              : 
    5097      2618073 :   expr = build_new_op (loc, ARRAY_REF, LOOKUP_NORMAL, arg1, arg2,
    5098              :                        NULL_TREE, NULL_TREE, &overload, complain);
    5099              : 
    5100      2618073 :   if (processing_template_decl && expr != error_mark_node)
    5101              :     {
    5102         4945 :       if (overload != NULL_TREE)
    5103         4936 :         return (build_min_non_dep_op_overload
    5104         4936 :                 (ARRAY_REF, expr, overload, orig_arg1, orig_arg2));
    5105              : 
    5106            9 :       return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
    5107            9 :                                 NULL_TREE, NULL_TREE);
    5108              :     }
    5109              :   return expr;
    5110              : }
    5111              : 
    5112              : /* Build an OpenMP array section reference, creating an exact type for the
    5113              :    resulting expression based on the element type and bounds if possible.  If
    5114              :    we have variable bounds, create an incomplete array type for the result
    5115              :    instead.  */
    5116              : 
    5117              : tree
    5118        11138 : build_omp_array_section (location_t loc, tree array_expr, tree index,
    5119              :                          tree length)
    5120              : {
    5121        11138 :   if (TREE_CODE (array_expr) == TYPE_DECL
    5122        11138 :       || type_dependent_expression_p (array_expr))
    5123          274 :     return build3_loc (loc, OMP_ARRAY_SECTION, NULL_TREE, array_expr, index,
    5124          274 :                        length);
    5125              : 
    5126        10864 :   tree type = TREE_TYPE (array_expr);
    5127        10864 :   gcc_assert (type);
    5128        10864 :   type = non_reference (type);
    5129              : 
    5130        10864 :   tree sectype, eltype = TREE_TYPE (type);
    5131              : 
    5132              :   /* It's not an array or pointer type.  Just reuse the type of the
    5133              :      original expression as the type of the array section (an error will be
    5134              :      raised anyway, later).  */
    5135        10864 :   if (eltype == NULL_TREE)
    5136           42 :     sectype = TREE_TYPE (array_expr);
    5137              :   else
    5138              :     {
    5139        10822 :       tree idxtype = NULL_TREE;
    5140              : 
    5141              :       /* If we know the integer bounds, create an index type with exact
    5142              :          low/high (or zero/length) bounds.  Otherwise, create an incomplete
    5143              :          array type.  (This mostly only affects diagnostics.)  */
    5144        10822 :       if (index != NULL_TREE
    5145        10822 :           && length != NULL_TREE
    5146         7695 :           && TREE_CODE (index) == INTEGER_CST
    5147         6878 :           && TREE_CODE (length) == INTEGER_CST)
    5148              :         {
    5149         5375 :           tree low = fold_convert (sizetype, index);
    5150         5375 :           tree high = fold_convert (sizetype, length);
    5151         5375 :           high = size_binop (PLUS_EXPR, low, high);
    5152         5375 :           high = size_binop (MINUS_EXPR, high, size_one_node);
    5153         5375 :           idxtype = build_range_type (sizetype, low, high);
    5154         5375 :         }
    5155         3007 :       else if ((index == NULL_TREE || integer_zerop (index))
    5156         3764 :                && length != NULL_TREE
    5157         7707 :                && TREE_CODE (length) == INTEGER_CST)
    5158         1546 :         idxtype = build_index_type (length);
    5159              : 
    5160        10822 :       sectype = build_array_type (eltype, idxtype);
    5161              :     }
    5162              : 
    5163        10864 :   return build3_loc (loc, OMP_ARRAY_SECTION, sectype, array_expr, index,
    5164        10864 :                      length);
    5165              : }
    5166              : 
    5167              : /* Return whether OP is an expression of enum type cast to integer
    5168              :    type.  In C++ even unsigned enum types are cast to signed integer
    5169              :    types.  We do not want to issue warnings about comparisons between
    5170              :    signed and unsigned types when one of the types is an enum type.
    5171              :    Those warnings are always false positives in practice.  */
    5172              : 
    5173              : static bool
    5174       645146 : enum_cast_to_int (tree op)
    5175              : {
    5176       632123 :   if (CONVERT_EXPR_P (op)
    5177        14050 :       && TREE_TYPE (op) == integer_type_node
    5178          910 :       && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == ENUMERAL_TYPE
    5179       645161 :       && TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 0))))
    5180              :     return true;
    5181              : 
    5182              :   /* The cast may have been pushed into a COND_EXPR.  */
    5183       645139 :   if (TREE_CODE (op) == COND_EXPR)
    5184          765 :     return (enum_cast_to_int (TREE_OPERAND (op, 1))
    5185          765 :             || enum_cast_to_int (TREE_OPERAND (op, 2)));
    5186              : 
    5187              :   return false;
    5188              : }
    5189              : 
    5190              : /* For the c-common bits.  */
    5191              : tree
    5192      5102496 : build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
    5193              :                  bool /*convert_p*/)
    5194              : {
    5195      5102496 :   return cp_build_binary_op (location, code, op0, op1, tf_warning_or_error);
    5196              : }
    5197              : 
    5198              : /* Build a vector comparison of ARG0 and ARG1 using CODE opcode
    5199              :    into a value of TYPE type.  Comparison is done via VEC_COND_EXPR.  */
    5200              : 
    5201              : static tree
    5202         8292 : build_vec_cmp (tree_code code, tree type,
    5203              :                tree arg0, tree arg1)
    5204              : {
    5205         8292 :   tree zero_vec = build_zero_cst (type);
    5206         8292 :   tree minus_one_vec = build_minus_one_cst (type);
    5207         8292 :   tree cmp_type = truth_type_for (TREE_TYPE (arg0));
    5208         8292 :   tree cmp = build2 (code, cmp_type, arg0, arg1);
    5209         8292 :   return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
    5210              : }
    5211              : 
    5212              : /* Possibly warn about an address never being NULL.  */
    5213              : 
    5214              : static void
    5215      1826856 : warn_for_null_address (location_t location, tree op, tsubst_flags_t complain)
    5216              : {
    5217              :   /* Prevent warnings issued for macro expansion.  */
    5218      1826856 :   if (!warn_address
    5219        41700 :       || (complain & tf_warning) == 0
    5220        24943 :       || c_inhibit_evaluation_warnings != 0
    5221        24926 :       || from_macro_expansion_at (location)
    5222      1845049 :       || warning_suppressed_p (op, OPT_Waddress))
    5223      1808986 :     return;
    5224              : 
    5225        18160 :   tree cop = fold_for_warn (op);
    5226              : 
    5227        18160 :   if (TREE_CODE (cop) == NON_LVALUE_EXPR)
    5228              :     /* Unwrap the expression for C++ 98.  */
    5229            1 :     cop = TREE_OPERAND (cop, 0);
    5230              : 
    5231        18160 :   if (TREE_CODE (cop) == PTRMEM_CST)
    5232              :     {
    5233              :       /* The address of a nonstatic data member is never null.  */
    5234           30 :       warning_at (location, OPT_Waddress,
    5235              :                   "the address %qE will never be NULL",
    5236              :                   cop);
    5237           30 :       return;
    5238              :     }
    5239              : 
    5240        18130 :   if (TREE_CODE (cop) == NOP_EXPR)
    5241              :     {
    5242              :       /* Allow casts to intptr_t to suppress the warning.  */
    5243         1248 :       tree type = TREE_TYPE (cop);
    5244         1248 :       if (TREE_CODE (type) == INTEGER_TYPE)
    5245              :         return;
    5246              : 
    5247         1248 :       STRIP_NOPS (cop);
    5248              :     }
    5249              : 
    5250        18130 :   auto_diagnostic_group d;
    5251        18130 :   bool warned = false;
    5252        18130 :   if (TREE_CODE (cop) == ADDR_EXPR)
    5253              :     {
    5254          789 :       cop = TREE_OPERAND (cop, 0);
    5255              : 
    5256              :       /* Set to true in the loop below if OP dereferences its operand.
    5257              :          In such a case the ultimate target need not be a decl for
    5258              :          the null [in]equality test to be necessarily constant.  */
    5259          789 :       bool deref = false;
    5260              : 
    5261              :       /* Get the outermost array or object, or member.  */
    5262          960 :       while (handled_component_p (cop))
    5263              :         {
    5264          270 :           if (TREE_CODE (cop) == COMPONENT_REF)
    5265              :             {
    5266              :               /* Get the member (its address is never null).  */
    5267           99 :               cop = TREE_OPERAND (cop, 1);
    5268           99 :               break;
    5269              :             }
    5270              : 
    5271              :           /* Get the outer array/object to refer to in the warning.  */
    5272          171 :           cop = TREE_OPERAND (cop, 0);
    5273          171 :           deref = true;
    5274              :         }
    5275              : 
    5276          639 :       if ((!deref && !decl_with_nonnull_addr_p (cop))
    5277          631 :           || from_macro_expansion_at (location)
    5278         1420 :           || warning_suppressed_p (cop, OPT_Waddress))
    5279              :         return;
    5280              : 
    5281          631 :       warned = warning_at (location, OPT_Waddress,
    5282              :                            "the address of %qD will never be NULL", cop);
    5283          631 :       op = cop;
    5284              :     }
    5285        17341 :   else if (TREE_CODE (cop) == POINTER_PLUS_EXPR)
    5286              :     {
    5287              :       /* Adding zero to the null pointer is well-defined in C++.  When
    5288              :          the offset is unknown (i.e., not a constant) warn anyway since
    5289              :          it's less likely that the pointer operand is null than not.  */
    5290          102 :       tree off = TREE_OPERAND (cop, 1);
    5291          102 :       if (!integer_zerop (off)
    5292          102 :           && !warning_suppressed_p (cop, OPT_Waddress))
    5293              :         {
    5294          102 :           tree base = TREE_OPERAND (cop, 0);
    5295          102 :           STRIP_NOPS (base);
    5296          102 :           if (TYPE_REF_P (TREE_TYPE (base)))
    5297           12 :             warning_at (location, OPT_Waddress, "the compiler can assume that "
    5298              :                         "the address of %qE will never be NULL", base);
    5299              :           else
    5300           90 :             warning_at (location, OPT_Waddress, "comparing the result of "
    5301              :                         "pointer addition %qE and NULL", cop);
    5302              :         }
    5303              :       return;
    5304              :     }
    5305        16272 :   else if (CONVERT_EXPR_P (op)
    5306        17301 :            && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0))))
    5307              :     {
    5308           62 :       STRIP_NOPS (op);
    5309              : 
    5310           62 :       if (TREE_CODE (op) == COMPONENT_REF)
    5311           24 :         op = TREE_OPERAND (op, 1);
    5312              : 
    5313           62 :       if (DECL_P (op))
    5314           62 :         warned = warning_at (location, OPT_Waddress,
    5315              :                              "the compiler can assume that the address of "
    5316              :                              "%qD will never be NULL", op);
    5317              :     }
    5318              : 
    5319          693 :   if (warned && DECL_P (op))
    5320          657 :     inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op);
    5321        18130 : }
    5322              : 
    5323              : /* Warn about [expr.arith.conv]/2: If one operand is of enumeration type and
    5324              :    the other operand is of a different enumeration type or a floating-point
    5325              :    type, this behavior is deprecated ([depr.arith.conv.enum]).  CODE is the
    5326              :    code of the binary operation, TYPE0 and TYPE1 are the types of the operands,
    5327              :    and LOC is the location for the whole binary expression.
    5328              :    For C++26 this is ill-formed rather than deprecated.
    5329              :    Return true for SFINAE errors.
    5330              :    TODO: Consider combining this with -Wenum-compare in build_new_op_1.  */
    5331              : 
    5332              : static bool
    5333    113996667 : do_warn_enum_conversions (location_t loc, enum tree_code code, tree type0,
    5334              :                           tree type1, tsubst_flags_t complain)
    5335              : {
    5336    113996667 :   if (TREE_CODE (type0) == ENUMERAL_TYPE
    5337      3486871 :       && TREE_CODE (type1) == ENUMERAL_TYPE
    5338    116954003 :       && TYPE_MAIN_VARIANT (type0) != TYPE_MAIN_VARIANT (type1))
    5339              :     {
    5340          200 :       if (cxx_dialect >= cxx26)
    5341              :         {
    5342           65 :           if ((complain & tf_warning_or_error) == 0)
    5343              :             return true;
    5344              :         }
    5345          135 :       else if ((complain & tf_warning) == 0)
    5346              :         return false;
    5347              :       /* In C++20, -Wdeprecated-enum-enum-conversion is on by default.
    5348              :          Otherwise, warn if -Wenum-conversion is on.  */
    5349          193 :       enum opt_code opt;
    5350          193 :       if (warn_deprecated_enum_enum_conv)
    5351              :         opt = OPT_Wdeprecated_enum_enum_conversion;
    5352           93 :       else if (warn_enum_conversion)
    5353              :         opt = OPT_Wenum_conversion;
    5354              :       else
    5355              :         return false;
    5356              : 
    5357          122 :       switch (code)
    5358              :         {
    5359              :         case GT_EXPR:
    5360              :         case LT_EXPR:
    5361              :         case GE_EXPR:
    5362              :         case LE_EXPR:
    5363              :         case EQ_EXPR:
    5364              :         case NE_EXPR:
    5365              :           /* Comparisons are handled by -Wenum-compare.  */
    5366              :           return false;
    5367              :         case SPACESHIP_EXPR:
    5368              :           /* This is invalid, don't warn.  */
    5369              :           return false;
    5370           18 :         case BIT_AND_EXPR:
    5371           18 :         case BIT_IOR_EXPR:
    5372           18 :         case BIT_XOR_EXPR:
    5373           18 :           if (cxx_dialect >= cxx26)
    5374            6 :             pedwarn (loc, opt, "bitwise operation between different "
    5375              :                      "enumeration types %qT and %qT", type0, type1);
    5376              :           else
    5377           12 :             warning_at (loc, opt, "bitwise operation between different "
    5378              :                         "enumeration types %qT and %qT is deprecated",
    5379              :                         type0, type1);
    5380              :           return false;
    5381           42 :         default:
    5382           42 :           if (cxx_dialect >= cxx26)
    5383           13 :             pedwarn (loc, opt, "arithmetic between different enumeration "
    5384              :                      "types %qT and %qT", type0, type1);
    5385              :           else
    5386           29 :             warning_at (loc, opt, "arithmetic between different enumeration "
    5387              :                         "types %qT and %qT is deprecated", type0, type1);
    5388              :           return false;
    5389              :         }
    5390              :     }
    5391    113996467 :   else if ((TREE_CODE (type0) == ENUMERAL_TYPE
    5392      3486671 :             && SCALAR_FLOAT_TYPE_P (type1))
    5393    113996395 :            || (SCALAR_FLOAT_TYPE_P (type0)
    5394     31604352 :                && TREE_CODE (type1) == ENUMERAL_TYPE))
    5395              :     {
    5396          151 :       if (cxx_dialect >= cxx26)
    5397              :         {
    5398           54 :           if ((complain & tf_warning_or_error) == 0)
    5399              :             return true;
    5400              :         }
    5401           97 :       else if ((complain & tf_warning) == 0)
    5402              :         return false;
    5403          139 :       const bool enum_first_p = TREE_CODE (type0) == ENUMERAL_TYPE;
    5404              :       /* In C++20, -Wdeprecated-enum-float-conversion is on by default.
    5405              :          Otherwise, warn if -Wenum-conversion is on.  */
    5406          139 :       enum opt_code opt;
    5407          139 :       if (warn_deprecated_enum_float_conv)
    5408              :         opt = OPT_Wdeprecated_enum_float_conversion;
    5409           68 :       else if (warn_enum_conversion)
    5410              :         opt = OPT_Wenum_conversion;
    5411              :       else
    5412              :         return false;
    5413              : 
    5414           88 :       switch (code)
    5415              :         {
    5416           36 :         case GT_EXPR:
    5417           36 :         case LT_EXPR:
    5418           36 :         case GE_EXPR:
    5419           36 :         case LE_EXPR:
    5420           36 :         case EQ_EXPR:
    5421           36 :         case NE_EXPR:
    5422           36 :           if (enum_first_p && cxx_dialect >= cxx26)
    5423            6 :             pedwarn (loc, opt, "comparison of enumeration type %qT with "
    5424              :                      "floating-point type %qT", type0, type1);
    5425           30 :           else if (cxx_dialect >= cxx26)
    5426            6 :             pedwarn (loc, opt, "comparison of floating-point type %qT "
    5427              :                       "with enumeration type %qT", type0, type1);
    5428           24 :           else if (enum_first_p)
    5429           12 :             warning_at (loc, opt, "comparison of enumeration type %qT with "
    5430              :                         "floating-point type %qT is deprecated",
    5431              :                         type0, type1);
    5432              :           else
    5433           12 :             warning_at (loc, opt, "comparison of floating-point type %qT "
    5434              :                         "with enumeration type %qT is deprecated",
    5435              :                         type0, type1);
    5436              :           return false;
    5437              :         case SPACESHIP_EXPR:
    5438              :           /* This is invalid, don't warn.  */
    5439              :           return false;
    5440           40 :         default:
    5441           40 :           if (enum_first_p && cxx_dialect >= cxx26)
    5442            6 :             pedwarn (loc, opt, "arithmetic between enumeration type %qT "
    5443              :                      "and floating-point type %qT", type0, type1);
    5444           34 :           else if (cxx_dialect >= cxx26)
    5445            7 :             pedwarn (loc, opt, "arithmetic between floating-point type %qT "
    5446              :                      "and enumeration type %qT", type0, type1);
    5447           27 :           else if (enum_first_p)
    5448           12 :             warning_at (loc, opt, "arithmetic between enumeration type %qT "
    5449              :                         "and floating-point type %qT is deprecated",
    5450              :                         type0, type1);
    5451              :           else
    5452           15 :             warning_at (loc, opt, "arithmetic between floating-point type %qT "
    5453              :                         "and enumeration type %qT is deprecated",
    5454              :                         type0, type1);
    5455              :           return false;
    5456              :         }
    5457              :     }
    5458              :   return false;
    5459              : }
    5460              : 
    5461              : /* Build a binary-operation expression without default conversions.
    5462              :    CODE is the kind of expression to build.
    5463              :    LOCATION is the location_t of the operator in the source code.
    5464              :    This function differs from `build' in several ways:
    5465              :    the data type of the result is computed and recorded in it,
    5466              :    warnings are generated if arg data types are invalid,
    5467              :    special handling for addition and subtraction of pointers is known,
    5468              :    and some optimization is done (operations on narrow ints
    5469              :    are done in the narrower type when that gives the same result).
    5470              :    Constant folding is also done before the result is returned.
    5471              : 
    5472              :    Note that the operands will never have enumeral types
    5473              :    because either they have just had the default conversions performed
    5474              :    or they have both just been converted to some other type in which
    5475              :    the arithmetic is to be done.
    5476              : 
    5477              :    C++: must do special pointer arithmetic when implementing
    5478              :    multiple inheritance, and deal with pointer to member functions.  */
    5479              : 
    5480              : tree
    5481    153308954 : cp_build_binary_op (const op_location_t &location,
    5482              :                     enum tree_code code, tree orig_op0, tree orig_op1,
    5483              :                     tsubst_flags_t complain)
    5484              : {
    5485    153308954 :   tree op0, op1;
    5486    153308954 :   enum tree_code code0, code1;
    5487    153308954 :   tree type0, type1, orig_type0, orig_type1;
    5488    153308954 :   const char *invalid_op_diag;
    5489              : 
    5490              :   /* Expression code to give to the expression when it is built.
    5491              :      Normally this is CODE, which is what the caller asked for,
    5492              :      but in some special cases we change it.  */
    5493    153308954 :   enum tree_code resultcode = code;
    5494              : 
    5495              :   /* Data type in which the computation is to be performed.
    5496              :      In the simplest cases this is the common type of the arguments.  */
    5497    153308954 :   tree result_type = NULL_TREE;
    5498              : 
    5499              :   /* When the computation is in excess precision, the type of the
    5500              :      final EXCESS_PRECISION_EXPR.  */
    5501    153308954 :   tree semantic_result_type = NULL;
    5502              : 
    5503              :   /* Nonzero means operands have already been type-converted
    5504              :      in whatever way is necessary.
    5505              :      Zero means they need to be converted to RESULT_TYPE.  */
    5506    153308954 :   int converted = 0;
    5507              : 
    5508              :   /* Nonzero means create the expression with this type, rather than
    5509              :      RESULT_TYPE.  */
    5510    153308954 :   tree build_type = 0;
    5511              : 
    5512              :   /* Nonzero means after finally constructing the expression
    5513              :      convert it to this type.  */
    5514    153308954 :   tree final_type = 0;
    5515              : 
    5516    153308954 :   tree result;
    5517              : 
    5518              :   /* Nonzero if this is an operation like MIN or MAX which can
    5519              :      safely be computed in short if both args are promoted shorts.
    5520              :      Also implies COMMON.
    5521              :      -1 indicates a bitwise operation; this makes a difference
    5522              :      in the exact conditions for when it is safe to do the operation
    5523              :      in a narrower mode.  */
    5524    153308954 :   int shorten = 0;
    5525              : 
    5526              :   /* Nonzero if this is a comparison operation;
    5527              :      if both args are promoted shorts, compare the original shorts.
    5528              :      Also implies COMMON.  */
    5529    153308954 :   int short_compare = 0;
    5530              : 
    5531              :   /* Nonzero if this is a right-shift operation, which can be computed on the
    5532              :      original short and then promoted if the operand is a promoted short.  */
    5533    153308954 :   int short_shift = 0;
    5534              : 
    5535              :   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
    5536    153308954 :   int common = 0;
    5537              : 
    5538              :   /* True if both operands have arithmetic type.  */
    5539    153308954 :   bool arithmetic_types_p;
    5540              : 
    5541              :   /* Remember whether we're doing / or %.  */
    5542    153308954 :   bool doing_div_or_mod = false;
    5543              : 
    5544              :   /* Remember whether we're doing << or >>.  */
    5545    153308954 :   bool doing_shift = false;
    5546              : 
    5547              :   /* Tree holding instrumentation expression.  */
    5548    153308954 :   tree instrument_expr = NULL_TREE;
    5549              : 
    5550              :   /* True means this is an arithmetic operation that may need excess
    5551              :      precision.  */
    5552    153308954 :   bool may_need_excess_precision;
    5553              : 
    5554              :   /* Apply default conversions.  */
    5555    153308954 :   op0 = resolve_nondeduced_context (orig_op0, complain);
    5556    153308954 :   op1 = resolve_nondeduced_context (orig_op1, complain);
    5557              : 
    5558    153308954 :   if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
    5559    138679747 :       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
    5560    135040324 :       || code == TRUTH_XOR_EXPR)
    5561              :     {
    5562     18268630 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5563     18268612 :         op0 = decay_conversion (op0, complain);
    5564     18268630 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5565     18268630 :         op1 = decay_conversion (op1, complain);
    5566              :     }
    5567              :   else
    5568              :     {
    5569    135040324 :       if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
    5570    135040275 :         op0 = cp_default_conversion (op0, complain);
    5571    135040324 :       if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
    5572    135040305 :         op1 = cp_default_conversion (op1, complain);
    5573              :     }
    5574              : 
    5575              :   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
    5576    162014895 :   STRIP_TYPE_NOPS (op0);
    5577    188095325 :   STRIP_TYPE_NOPS (op1);
    5578              : 
    5579              :   /* DTRT if one side is an overloaded function, but complain about it.  */
    5580    153308954 :   if (type_unknown_p (op0))
    5581              :     {
    5582            9 :       tree t = instantiate_type (TREE_TYPE (op1), op0, tf_none);
    5583            9 :       if (t != error_mark_node)
    5584              :         {
    5585            0 :           if (complain & tf_error)
    5586            0 :             permerror (location,
    5587              :                        "assuming cast to type %qT from overloaded function",
    5588            0 :                        TREE_TYPE (t));
    5589              :           op0 = t;
    5590              :         }
    5591              :     }
    5592    153308954 :   if (type_unknown_p (op1))
    5593              :     {
    5594            3 :       tree t = instantiate_type (TREE_TYPE (op0), op1, tf_none);
    5595            3 :       if (t != error_mark_node)
    5596              :         {
    5597            3 :           if (complain & tf_error)
    5598            3 :             permerror (location,
    5599              :                        "assuming cast to type %qT from overloaded function",
    5600            3 :                        TREE_TYPE (t));
    5601              :           op1 = t;
    5602              :         }
    5603              :     }
    5604              : 
    5605    153308954 :   orig_type0 = type0 = TREE_TYPE (op0);
    5606    153308954 :   orig_type1 = type1 = TREE_TYPE (op1);
    5607    153308954 :   tree non_ep_op0 = op0;
    5608    153308954 :   tree non_ep_op1 = op1;
    5609              : 
    5610              :   /* The expression codes of the data types of the arguments tell us
    5611              :      whether the arguments are integers, floating, pointers, etc.  */
    5612    153308954 :   code0 = TREE_CODE (type0);
    5613    153308954 :   code1 = TREE_CODE (type1);
    5614              : 
    5615              :   /* If an error was already reported for one of the arguments,
    5616              :      avoid reporting another error.  */
    5617    153308954 :   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
    5618          101 :     return error_mark_node;
    5619              : 
    5620    306617706 :   if ((invalid_op_diag
    5621    153308853 :        = targetm.invalid_binary_op (code, type0, type1)))
    5622              :     {
    5623            0 :       if (complain & tf_error)
    5624              :         {
    5625            0 :           if (code0 == REAL_TYPE
    5626            0 :               && code1 == REAL_TYPE
    5627            0 :               && (extended_float_type_p (type0)
    5628            0 :                   || extended_float_type_p (type1))
    5629            0 :               && cp_compare_floating_point_conversion_ranks (type0,
    5630              :                                                              type1) == 3)
    5631              :             {
    5632            0 :               rich_location richloc (line_table, location);
    5633            0 :               binary_op_error (&richloc, code, type0, type1);
    5634            0 :             }
    5635              :           else
    5636            0 :             error (invalid_op_diag);
    5637              :         }
    5638            0 :       return error_mark_node;
    5639              :     }
    5640              : 
    5641    153308853 :   switch (code)
    5642              :     {
    5643              :     case PLUS_EXPR:
    5644              :     case MINUS_EXPR:
    5645              :     case MULT_EXPR:
    5646              :     case TRUNC_DIV_EXPR:
    5647              :     case CEIL_DIV_EXPR:
    5648              :     case FLOOR_DIV_EXPR:
    5649              :     case ROUND_DIV_EXPR:
    5650              :     case EXACT_DIV_EXPR:
    5651              :       may_need_excess_precision = true;
    5652              :       break;
    5653     54462140 :     case EQ_EXPR:
    5654     54462140 :     case NE_EXPR:
    5655     54462140 :     case LE_EXPR:
    5656     54462140 :     case GE_EXPR:
    5657     54462140 :     case LT_EXPR:
    5658     54462140 :     case GT_EXPR:
    5659     54462140 :     case SPACESHIP_EXPR:
    5660              :       /* Excess precision for implicit conversions of integers to
    5661              :          floating point.  */
    5662     11563979 :       may_need_excess_precision = (ANY_INTEGRAL_TYPE_P (type0)
    5663     66018565 :                                    || ANY_INTEGRAL_TYPE_P (type1));
    5664              :       break;
    5665              :     default:
    5666    153308853 :       may_need_excess_precision = false;
    5667              :       break;
    5668              :     }
    5669    153308853 :   if (TREE_CODE (op0) == EXCESS_PRECISION_EXPR)
    5670              :     {
    5671        15269 :       op0 = TREE_OPERAND (op0, 0);
    5672        15269 :       type0 = TREE_TYPE (op0);
    5673              :     }
    5674    153293584 :   else if (may_need_excess_precision
    5675    115006772 :            && (code0 == REAL_TYPE || code0 == COMPLEX_TYPE))
    5676     27554245 :     if (tree eptype = excess_precision_type (type0))
    5677              :       {
    5678        40908 :         type0 = eptype;
    5679        40908 :         op0 = convert (eptype, op0);
    5680              :       }
    5681    153308853 :   if (TREE_CODE (op1) == EXCESS_PRECISION_EXPR)
    5682              :     {
    5683        19301 :       op1 = TREE_OPERAND (op1, 0);
    5684        19301 :       type1 = TREE_TYPE (op1);
    5685              :     }
    5686    153289552 :   else if (may_need_excess_precision
    5687    115004994 :            && (code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
    5688     27428746 :     if (tree eptype = excess_precision_type (type1))
    5689              :       {
    5690        27214 :         type1 = eptype;
    5691        27214 :         op1 = convert (eptype, op1);
    5692              :       }
    5693              : 
    5694              :   /* Issue warnings about peculiar, but valid, uses of NULL.  */
    5695    306617621 :   if ((null_node_p (orig_op0) || null_node_p (orig_op1))
    5696              :       /* It's reasonable to use pointer values as operands of &&
    5697              :          and ||, so NULL is no exception.  */
    5698        12193 :       && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR
    5699        12178 :       && ( /* Both are NULL (or 0) and the operation was not a
    5700              :               comparison or a pointer subtraction.  */
    5701        12251 :           (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)
    5702           27 :            && code != EQ_EXPR && code != NE_EXPR && code != MINUS_EXPR)
    5703              :           /* Or if one of OP0 or OP1 is neither a pointer nor NULL.  */
    5704        12166 :           || (!null_ptr_cst_p (orig_op0)
    5705        12105 :               && !TYPE_PTR_OR_PTRMEM_P (type0))
    5706        12154 :           || (!null_ptr_cst_p (orig_op1)
    5707           46 :               && !TYPE_PTR_OR_PTRMEM_P (type1)))
    5708    153308892 :       && (complain & tf_warning))
    5709              :     {
    5710           39 :       location_t loc =
    5711           39 :         expansion_point_location_if_in_system_header (input_location);
    5712              : 
    5713           39 :       warning_at (loc, OPT_Wpointer_arith, "NULL used in arithmetic");
    5714              :     }
    5715              : 
    5716              :   /* In case when one of the operands of the binary operation is
    5717              :      a vector and another is a scalar -- convert scalar to vector.  */
    5718    153377484 :   if ((gnu_vector_type_p (type0) && code1 != VECTOR_TYPE)
    5719    153376346 :       || (gnu_vector_type_p (type1) && code0 != VECTOR_TYPE))
    5720              :     {
    5721         1223 :       enum stv_conv convert_flag
    5722         1223 :         = scalar_to_vector (location, code, non_ep_op0, non_ep_op1,
    5723              :                             complain & tf_error);
    5724              : 
    5725         1223 :       switch (convert_flag)
    5726              :         {
    5727           21 :           case stv_error:
    5728           21 :             return error_mark_node;
    5729           55 :           case stv_firstarg:
    5730           55 :             {
    5731           55 :               op0 = convert (TREE_TYPE (type1), op0);
    5732           55 :               op0 = cp_save_expr (op0);
    5733           55 :               op0 = build_vector_from_val (type1, op0);
    5734           55 :               orig_type0 = type0 = TREE_TYPE (op0);
    5735           55 :               code0 = TREE_CODE (type0);
    5736           55 :               converted = 1;
    5737           55 :               break;
    5738              :             }
    5739         1010 :           case stv_secondarg:
    5740         1010 :             {
    5741         1010 :               op1 = convert (TREE_TYPE (type0), op1);
    5742         1010 :               op1 = cp_save_expr (op1);
    5743         1010 :               op1 = build_vector_from_val (type0, op1);
    5744         1010 :               orig_type1 = type1 = TREE_TYPE (op1);
    5745         1010 :               code1 = TREE_CODE (type1);
    5746         1010 :               converted = 1;
    5747         1010 :               break;
    5748              :             }
    5749              :           default:
    5750              :             break;
    5751              :         }
    5752              :     }
    5753              : 
    5754    153308832 :   switch (code)
    5755              :     {
    5756     16697440 :     case MINUS_EXPR:
    5757              :       /* Subtraction of two similar pointers.
    5758              :          We must subtract them as integers, then divide by object size.  */
    5759     16697440 :       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
    5760     18251333 :           && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    5761      1553893 :                                                         TREE_TYPE (type1)))
    5762              :         {
    5763      1553890 :           result = pointer_diff (location, op0, op1,
    5764              :                                  common_pointer_type (type0, type1), complain,
    5765              :                                  &instrument_expr);
    5766      1553890 :           if (instrument_expr != NULL)
    5767           84 :             result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    5768              :                              instrument_expr, result);
    5769              : 
    5770              :           return result;
    5771              :         }
    5772              :       /* In all other cases except pointer - int, the usual arithmetic
    5773              :          rules apply.  */
    5774     15143550 :       else if (!(code0 == POINTER_TYPE && code1 == INTEGER_TYPE))
    5775              :         {
    5776              :           common = 1;
    5777              :           break;
    5778              :         }
    5779              :       /* The pointer - int case is just like pointer + int; fall
    5780              :          through.  */
    5781     22368964 :       gcc_fallthrough ();
    5782     22368964 :     case PLUS_EXPR:
    5783     22368964 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    5784      8060414 :           && (code0 == INTEGER_TYPE || code1 == INTEGER_TYPE))
    5785              :         {
    5786      8060405 :           tree ptr_operand;
    5787      8060405 :           tree int_operand;
    5788      8060405 :           ptr_operand = ((code0 == POINTER_TYPE) ? op0 : op1);
    5789       128607 :           int_operand = ((code0 == INTEGER_TYPE) ? op0 : op1);
    5790      8060405 :           if (processing_template_decl)
    5791              :             {
    5792      2239122 :               result_type = TREE_TYPE (ptr_operand);
    5793      2239122 :               break;
    5794              :             }
    5795      5821283 :           return cp_pointer_int_sum (location, code,
    5796              :                                      ptr_operand,
    5797              :                                      int_operand,
    5798      5821283 :                                      complain);
    5799              :         }
    5800              :       common = 1;
    5801              :       break;
    5802              : 
    5803              :     case MULT_EXPR:
    5804    145886214 :       common = 1;
    5805              :       break;
    5806              : 
    5807     12377491 :     case TRUNC_DIV_EXPR:
    5808     12377491 :     case CEIL_DIV_EXPR:
    5809     12377491 :     case FLOOR_DIV_EXPR:
    5810     12377491 :     case ROUND_DIV_EXPR:
    5811     12377491 :     case EXACT_DIV_EXPR:
    5812     12377491 :       if (TREE_CODE (op0) == SIZEOF_EXPR && TREE_CODE (op1) == SIZEOF_EXPR)
    5813              :         {
    5814       128334 :           tree type0 = TREE_OPERAND (op0, 0);
    5815       128334 :           tree type1 = TREE_OPERAND (op1, 0);
    5816       128334 :           tree first_arg = tree_strip_any_location_wrapper (type0);
    5817       128334 :           if (!TYPE_P (type0))
    5818        86002 :             type0 = TREE_TYPE (type0);
    5819       128334 :           if (!TYPE_P (type1))
    5820        50217 :             type1 = TREE_TYPE (type1);
    5821       128334 :           if (type0
    5822       128334 :               && type1
    5823       108767 :               && INDIRECT_TYPE_P (type0)
    5824       128409 :               && same_type_p (TREE_TYPE (type0), type1))
    5825              :             {
    5826           27 :               if (!(TREE_CODE (first_arg) == PARM_DECL
    5827           21 :                     && DECL_ARRAY_PARAMETER_P (first_arg)
    5828            3 :                     && warn_sizeof_array_argument)
    5829           42 :                   && (complain & tf_warning))
    5830              :                 {
    5831           21 :                   auto_diagnostic_group d;
    5832           21 :                   if (warning_at (location, OPT_Wsizeof_pointer_div,
    5833              :                                   "division %<sizeof (%T) / sizeof (%T)%> does "
    5834              :                                   "not compute the number of array elements",
    5835              :                                   type0, type1))
    5836           18 :                     if (DECL_P (first_arg))
    5837           18 :                       inform (DECL_SOURCE_LOCATION (first_arg),
    5838              :                               "first %<sizeof%> operand was declared here");
    5839           21 :                 }
    5840              :             }
    5841       128310 :           else if (!dependent_type_p (type0)
    5842        30753 :                    && !dependent_type_p (type1)
    5843        30653 :                    && TREE_CODE (type0) == ARRAY_TYPE
    5844        21625 :                    && !char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type0)))
    5845              :                    /* Set by finish_parenthesized_expr.  */
    5846        20974 :                    && !warning_suppressed_p (op1, OPT_Wsizeof_array_div)
    5847       149266 :                    && (complain & tf_warning))
    5848        20956 :             maybe_warn_sizeof_array_div (location, first_arg, type0,
    5849              :                                          op1, non_reference (type1));
    5850              :         }
    5851              : 
    5852     12377491 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    5853              :            || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
    5854     12377473 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    5855              :               || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE))
    5856              :         {
    5857     12377464 :           enum tree_code tcode0 = code0, tcode1 = code1;
    5858     12377464 :           doing_div_or_mod = true;
    5859     12377464 :           warn_for_div_by_zero (location, fold_for_warn (op1));
    5860              : 
    5861     12377464 :           if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
    5862        58774 :             tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
    5863     12377464 :           if (tcode1 == COMPLEX_TYPE || tcode1 == VECTOR_TYPE)
    5864        30246 :             tcode1 = TREE_CODE (TREE_TYPE (TREE_TYPE (op1)));
    5865              : 
    5866     12377467 :           if (!((tcode0 == INTEGER_TYPE
    5867      5414593 :                  || (tcode0 == ENUMERAL_TYPE && code0 == VECTOR_TYPE))
    5868              :                 && (tcode1 == INTEGER_TYPE
    5869        96922 :                     || (tcode1 == ENUMERAL_TYPE && code1 == VECTOR_TYPE))))
    5870              :             resultcode = RDIV_EXPR;
    5871              :           else
    5872              :             {
    5873              :               /* When dividing two signed integers, we have to promote to int.
    5874              :                  unless we divide by a constant != -1.  Note that default
    5875              :                  conversion will have been performed on the operands at this
    5876              :                  point, so we have to dig out the original type to find out if
    5877              :                  it was unsigned.  */
    5878      6865955 :               tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5879      6865955 :               shorten = may_shorten_divmod (op0, stripped_op1);
    5880              :             }
    5881              : 
    5882              :           common = 1;
    5883              :         }
    5884              :       break;
    5885              : 
    5886      2950937 :     case BIT_AND_EXPR:
    5887      2950937 :     case BIT_IOR_EXPR:
    5888      2950937 :     case BIT_XOR_EXPR:
    5889      2950937 :       if ((code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5890      2950937 :           || (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5891        21143 :               && !VECTOR_FLOAT_TYPE_P (type0)
    5892        21125 :               && !VECTOR_FLOAT_TYPE_P (type1)))
    5893              :         shorten = -1;
    5894              :       break;
    5895              : 
    5896      1575443 :     case TRUNC_MOD_EXPR:
    5897      1575443 :     case FLOOR_MOD_EXPR:
    5898      1575443 :       doing_div_or_mod = true;
    5899      1575443 :       warn_for_div_by_zero (location, fold_for_warn (op1));
    5900              : 
    5901      1575443 :       if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
    5902           36 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    5903      1575479 :           && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
    5904              :         common = 1;
    5905      1575407 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    5906              :         {
    5907              :           /* Although it would be tempting to shorten always here, that loses
    5908              :              on some targets, since the modulo instruction is undefined if the
    5909              :              quotient can't be represented in the computation mode.  We shorten
    5910              :              only if unsigned or if dividing by something we know != -1.  */
    5911      1575383 :           tree stripped_op1 = tree_strip_any_location_wrapper (op1);
    5912      1575383 :           shorten = may_shorten_divmod (op0, stripped_op1);
    5913      1575383 :           common = 1;
    5914              :         }
    5915              :       break;
    5916              : 
    5917     18268615 :     case TRUTH_ANDIF_EXPR:
    5918     18268615 :     case TRUTH_ORIF_EXPR:
    5919     18268615 :     case TRUTH_AND_EXPR:
    5920     18268615 :     case TRUTH_OR_EXPR:
    5921     18268615 :       if (!VECTOR_TYPE_P (type0) && gnu_vector_type_p (type1))
    5922              :         {
    5923            3 :           if (!COMPARISON_CLASS_P (op1))
    5924            3 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5925              :                                       build_zero_cst (type1), complain);
    5926            3 :           if (code == TRUTH_ANDIF_EXPR)
    5927              :             {
    5928            0 :               tree z = build_zero_cst (TREE_TYPE (op1));
    5929            0 :               return build_conditional_expr (location, op0, op1, z, complain);
    5930              :             }
    5931            3 :           else if (code == TRUTH_ORIF_EXPR)
    5932              :             {
    5933            3 :               tree m1 = build_all_ones_cst (TREE_TYPE (op1));
    5934            3 :               return build_conditional_expr (location, op0, m1, op1, complain);
    5935              :             }
    5936              :           else
    5937            0 :             gcc_unreachable ();
    5938              :         }
    5939     18268612 :       if (gnu_vector_type_p (type0)
    5940     18268612 :           && (!VECTOR_TYPE_P (type1) || gnu_vector_type_p (type1)))
    5941              :         {
    5942           24 :           if (!COMPARISON_CLASS_P (op0))
    5943           24 :             op0 = cp_build_binary_op (EXPR_LOCATION (op0), NE_EXPR, op0,
    5944              :                                       build_zero_cst (type0), complain);
    5945           24 :           if (!VECTOR_TYPE_P (type1))
    5946              :             {
    5947            9 :               tree m1 = build_all_ones_cst (TREE_TYPE (op0));
    5948            9 :               tree z = build_zero_cst (TREE_TYPE (op0));
    5949            9 :               op1 = build_conditional_expr (location, op1, m1, z, complain);
    5950              :             }
    5951           15 :           else if (!COMPARISON_CLASS_P (op1))
    5952           15 :             op1 = cp_build_binary_op (EXPR_LOCATION (op1), NE_EXPR, op1,
    5953              :                                       build_zero_cst (type1), complain);
    5954              : 
    5955           24 :           if (code == TRUTH_ANDIF_EXPR)
    5956              :             code = BIT_AND_EXPR;
    5957            9 :           else if (code == TRUTH_ORIF_EXPR)
    5958              :             code = BIT_IOR_EXPR;
    5959              :           else
    5960            0 :             gcc_unreachable ();
    5961              : 
    5962           24 :           return cp_build_binary_op (location, code, op0, op1, complain);
    5963              :         }
    5964              : 
    5965     18268588 :       if (warn_constant_logical_operand
    5966       135698 :           && (complain & tf_warning)
    5967       133232 :           && (code0 == INTEGER_TYPE || code0 == ENUMERAL_TYPE)
    5968        11363 :           && (code1 == INTEGER_TYPE || code1 == ENUMERAL_TYPE))
    5969              :         {
    5970         5030 :           tree cop0 = fold_for_warn (op0), cop1 = fold_for_warn (op1);
    5971         5030 :           const char *name
    5972              :             = ((code == TRUTH_ANDIF_EXPR || code == TRUTH_AND_EXPR)
    5973              :                ? "&&" : "||");
    5974         5115 :           auto enum_other_than_0_1 = [] (tree type) {
    5975           85 :             if (TREE_CODE (type) != ENUMERAL_TYPE)
    5976              :               return false;
    5977          154 :             for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l))
    5978              :               {
    5979          125 :                 tree v = DECL_INITIAL (TREE_VALUE (l));
    5980          125 :                 if (!integer_zerop (v) && !integer_onep (v))
    5981              :                   return true;
    5982              :               }
    5983              :             return false;
    5984              :           };
    5985        15042 :           auto diagnose_constant_logical_operand = [=] (tree val, tree type) {
    5986        10012 :             if (TREE_CODE (val) != INTEGER_CST || integer_zerop (val))
    5987              :               return false;
    5988          157 :             if (integer_onep (val) && !enum_other_than_0_1 (type))
    5989              :               return false;
    5990           96 :             gcc_rich_location richloc (location);
    5991           96 :             richloc.add_fixit_replace (name + 1);
    5992           96 :             auto_diagnostic_group d;
    5993           96 :             if (warning_at (location, OPT_Wconstant_logical_operand,
    5994              :                             "use of logical %qs with constant operand %qE",
    5995              :                             name, val))
    5996           96 :               inform (&richloc, "use %qs for bitwise operation", name + 1);
    5997           96 :             return true;
    5998           96 :           };
    5999         5030 :           if (!diagnose_constant_logical_operand (cop1, orig_type1))
    6000         4982 :             diagnose_constant_logical_operand (cop0, orig_type0);
    6001              :         }
    6002              : 
    6003     18268588 :       result_type = boolean_type_node;
    6004     18268588 :       break;
    6005              : 
    6006              :       /* Shift operations: result has same type as first operand;
    6007              :          always convert second operand to int.
    6008              :          Also set SHORT_SHIFT if shifting rightward.  */
    6009              : 
    6010      1176828 :     case RSHIFT_EXPR:
    6011      1176828 :       if (gnu_vector_type_p (type0)
    6012          202 :           && code1 == INTEGER_TYPE
    6013      1176893 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    6014              :         {
    6015              :           result_type = type0;
    6016              :           converted = 1;
    6017              :         }
    6018      1176763 :       else if (gnu_vector_type_p (type0)
    6019          137 :                && gnu_vector_type_p (type1)
    6020          137 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    6021          134 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    6022      1176897 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    6023              :                             TYPE_VECTOR_SUBPARTS (type1)))
    6024              :         {
    6025              :           result_type = type0;
    6026              :           converted = 1;
    6027              :         }
    6028      1176629 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    6029              :         {
    6030      1176602 :           tree const_op1 = fold_for_warn (op1);
    6031      1176602 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    6032       151966 :             const_op1 = op1;
    6033      1176602 :           result_type = type0;
    6034      1176602 :           doing_shift = true;
    6035      1176602 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    6036              :             {
    6037      1024636 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    6038              :                 {
    6039           48 :                   if ((complain & tf_warning)
    6040           48 :                       && c_inhibit_evaluation_warnings == 0)
    6041           36 :                     warning_at (location, OPT_Wshift_count_negative,
    6042              :                                 "right shift count is negative");
    6043              :                 }
    6044              :               else
    6045              :                 {
    6046      1024588 :                   if (!integer_zerop (const_op1))
    6047      1024202 :                     short_shift = 1;
    6048              : 
    6049      1024588 :                   if (compare_tree_int (const_op1, TYPE_PRECISION (type0)) >= 0
    6050           70 :                       && (complain & tf_warning)
    6051      1024658 :                       && c_inhibit_evaluation_warnings == 0)
    6052           34 :                     warning_at (location, OPT_Wshift_count_overflow,
    6053              :                                 "right shift count >= width of type");
    6054              :                 }
    6055              :             }
    6056              :           /* Avoid converting op1 to result_type later.  */
    6057              :           converted = 1;
    6058              :         }
    6059              :       break;
    6060              : 
    6061      3234011 :     case LSHIFT_EXPR:
    6062      3234011 :       if (gnu_vector_type_p (type0)
    6063          271 :           && code1 == INTEGER_TYPE
    6064      3234062 :           && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE)
    6065              :         {
    6066              :           result_type = type0;
    6067              :           converted = 1;
    6068              :         }
    6069      3233960 :       else if (gnu_vector_type_p (type0)
    6070          220 :                && gnu_vector_type_p (type1)
    6071          220 :                && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
    6072          217 :                && TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE
    6073      3234174 :                && known_eq (TYPE_VECTOR_SUBPARTS (type0),
    6074              :                             TYPE_VECTOR_SUBPARTS (type1)))
    6075              :         {
    6076              :           result_type = type0;
    6077              :           converted = 1;
    6078              :         }
    6079      3233746 :       else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
    6080              :         {
    6081      3233646 :           tree const_op0 = fold_for_warn (op0);
    6082      3233646 :           if (TREE_CODE (const_op0) != INTEGER_CST)
    6083       309177 :             const_op0 = op0;
    6084      3233646 :           tree const_op1 = fold_for_warn (op1);
    6085      3233646 :           if (TREE_CODE (const_op1) != INTEGER_CST)
    6086       277048 :             const_op1 = op1;
    6087      3233646 :           result_type = type0;
    6088      3233646 :           doing_shift = true;
    6089      3233646 :           if (TREE_CODE (const_op0) == INTEGER_CST
    6090      2924469 :               && tree_int_cst_sgn (const_op0) < 0
    6091          352 :               && !TYPE_OVERFLOW_WRAPS (type0)
    6092          268 :               && (complain & tf_warning)
    6093      3233914 :               && c_inhibit_evaluation_warnings == 0)
    6094          196 :             warning_at (location, OPT_Wshift_negative_value,
    6095              :                         "left shift of negative value");
    6096      3233646 :           if (TREE_CODE (const_op1) == INTEGER_CST)
    6097              :             {
    6098      2956598 :               if (tree_int_cst_lt (const_op1, integer_zero_node))
    6099              :                 {
    6100           57 :                   if ((complain & tf_warning)
    6101           57 :                       && c_inhibit_evaluation_warnings == 0)
    6102           39 :                     warning_at (location, OPT_Wshift_count_negative,
    6103              :                                 "left shift count is negative");
    6104              :                 }
    6105      2956541 :               else if (compare_tree_int (const_op1,
    6106      2956541 :                                          TYPE_PRECISION (type0)) >= 0)
    6107              :                 {
    6108          178 :                   if ((complain & tf_warning)
    6109          156 :                       && c_inhibit_evaluation_warnings == 0)
    6110           45 :                     warning_at (location, OPT_Wshift_count_overflow,
    6111              :                                 "left shift count >= width of type");
    6112              :                 }
    6113      2956363 :               else if (TREE_CODE (const_op0) == INTEGER_CST
    6114      2714897 :                        && (complain & tf_warning))
    6115      2604640 :                 maybe_warn_shift_overflow (location, const_op0, const_op1);
    6116              :             }
    6117              :           /* Avoid converting op1 to result_type later.  */
    6118              :           converted = 1;
    6119              :         }
    6120              :       break;
    6121              : 
    6122     27373517 :     case EQ_EXPR:
    6123     27373517 :     case NE_EXPR:
    6124     27373517 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6125         3339 :         goto vector_compare;
    6126     27370178 :       if ((complain & tf_warning)
    6127     24340453 :           && c_inhibit_evaluation_warnings == 0
    6128     50546635 :           && (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)))
    6129       800188 :         warning_at (location, OPT_Wfloat_equal,
    6130              :                     "comparing floating-point with %<==%> "
    6131              :                     "or %<!=%> is unsafe");
    6132     27370178 :       {
    6133     27370178 :         tree stripped_orig_op0 = tree_strip_any_location_wrapper (orig_op0);
    6134     27370178 :         tree stripped_orig_op1 = tree_strip_any_location_wrapper (orig_op1);
    6135     27370178 :         if ((complain & tf_warning_or_error)
    6136     27370178 :             && ((TREE_CODE (stripped_orig_op0) == STRING_CST
    6137           39 :                  && !integer_zerop (cp_fully_fold (op1)))
    6138     24843752 :                 || (TREE_CODE (stripped_orig_op1) == STRING_CST
    6139           68 :                     && !integer_zerop (cp_fully_fold (op0)))))
    6140           47 :           warning_at (location, OPT_Waddress,
    6141              :                       "comparison with string literal results in "
    6142              :                       "unspecified behavior");
    6143     27370131 :         else if (TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6144     27370131 :                  && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE)
    6145              :           {
    6146              :             /* P2865R5 made array comparisons ill-formed in C++26.  */
    6147           68 :             if (complain & tf_warning_or_error)
    6148           45 :               do_warn_array_compare (location, code, stripped_orig_op0,
    6149              :                                      stripped_orig_op1);
    6150           23 :             else if (cxx_dialect >= cxx26)
    6151            1 :               return error_mark_node;
    6152              :           }
    6153              :       }
    6154              : 
    6155     27370177 :       build_type = boolean_type_node;
    6156     27370177 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6157              :            || code0 == COMPLEX_TYPE || code0 == ENUMERAL_TYPE)
    6158     23111736 :           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6159              :               || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE))
    6160              :         short_compare = 1;
    6161        45825 :       else if (((code0 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type0))
    6162      4253213 :                 && null_ptr_cst_p (orig_op1))
    6163              :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    6164      6789832 :                || (code0 == POINTER_TYPE
    6165      2446371 :                    && TYPE_PTR_P (type1) && integer_zerop (op1)))
    6166              :         {
    6167      1825646 :           if (TYPE_PTR_P (type1))
    6168        19212 :             result_type = composite_pointer_type (location,
    6169              :                                                   type0, type1, op0, op1,
    6170              :                                                   CPO_COMPARISON, complain);
    6171              :           else
    6172              :             result_type = type0;
    6173              : 
    6174      1825646 :           if (char_type_p (TREE_TYPE (orig_op1)))
    6175              :             {
    6176           10 :               auto_diagnostic_group d;
    6177           10 :               if (warning_at (location, OPT_Wpointer_compare,
    6178              :                               "comparison between pointer and zero character "
    6179              :                               "constant"))
    6180           10 :                 inform (location,
    6181              :                         "did you mean to dereference the pointer?");
    6182           10 :             }
    6183      1825646 :           warn_for_null_address (location, op0, complain);
    6184              :         }
    6185         5706 :       else if (((code1 == POINTER_TYPE || TYPE_PTRDATAMEM_P (type1))
    6186      2467213 :                 && null_ptr_cst_p (orig_op0))
    6187              :                /* Handle, eg, (void*)0 (c++/43906), and more.  */
    6188      4944081 :                || (code1 == POINTER_TYPE
    6189      2465912 :                    && TYPE_PTR_P (type0) && integer_zerop (op0)))
    6190              :         {
    6191          961 :           if (TYPE_PTR_P (type0))
    6192           68 :             result_type = composite_pointer_type (location,
    6193              :                                                   type0, type1, op0, op1,
    6194              :                                                   CPO_COMPARISON, complain);
    6195              :           else
    6196              :             result_type = type1;
    6197              : 
    6198          961 :           if (char_type_p (TREE_TYPE (orig_op0)))
    6199              :             {
    6200           10 :               auto_diagnostic_group d;
    6201           10 :               if (warning_at (location, OPT_Wpointer_compare,
    6202              :                              "comparison between pointer and zero character "
    6203              :                              "constant"))
    6204           10 :                 inform (location,
    6205              :                         "did you mean to dereference the pointer?");
    6206           10 :             }
    6207          961 :           warn_for_null_address (location, op1, complain);
    6208              :         }
    6209      2471526 :       else if ((code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6210        44493 :                || (TYPE_PTRDATAMEM_P (type0) && TYPE_PTRDATAMEM_P (type1)))
    6211      2427441 :         result_type = composite_pointer_type (location,
    6212              :                                               type0, type1, op0, op1,
    6213              :                                               CPO_COMPARISON, complain);
    6214        44085 :       else if (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1))
    6215              :         /* One of the operands must be of nullptr_t type.  */
    6216           69 :         result_type = TREE_TYPE (nullptr_node);
    6217        44016 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6218              :         {
    6219           58 :           result_type = type0;
    6220           58 :           if (complain & tf_error)
    6221           56 :             permerror (location, "ISO C++ forbids comparison between "
    6222              :                        "pointer and integer");
    6223              :           else
    6224            2 :             return error_mark_node;
    6225              :         }
    6226        43958 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6227              :         {
    6228        38811 :           result_type = type1;
    6229        38811 :           if (complain & tf_error)
    6230           69 :             permerror (location, "ISO C++ forbids comparison between "
    6231              :                        "pointer and integer");
    6232              :           else
    6233        38742 :             return error_mark_node;
    6234              :         }
    6235         5147 :       else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (orig_op1))
    6236              :         {
    6237          249 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    6238              :               == ptrmemfunc_vbit_in_delta)
    6239              :             {
    6240              :               tree pfn0, delta0, e1, e2;
    6241              : 
    6242              :               if (TREE_SIDE_EFFECTS (op0))
    6243              :                 op0 = cp_save_expr (op0);
    6244              : 
    6245              :               pfn0 = pfn_from_ptrmemfunc (op0);
    6246              :               delta0 = delta_from_ptrmemfunc (op0);
    6247              :               {
    6248              :                 /* If we will warn below about a null-address compare
    6249              :                    involving the orig_op0 ptrmemfunc, we'd likely also
    6250              :                    warn about the pfn0's null-address compare, and
    6251              :                    that would be redundant, so suppress it.  */
    6252              :                 warning_sentinel ws (warn_address);
    6253              :                 e1 = cp_build_binary_op (location,
    6254              :                                          EQ_EXPR,
    6255              :                                          pfn0,
    6256              :                                          build_zero_cst (TREE_TYPE (pfn0)),
    6257              :                                          complain);
    6258              :               }
    6259              :               e2 = cp_build_binary_op (location,
    6260              :                                        BIT_AND_EXPR,
    6261              :                                        delta0,
    6262              :                                        integer_one_node,
    6263              :                                        complain);
    6264              : 
    6265              :               if (complain & tf_warning)
    6266              :                 maybe_warn_zero_as_null_pointer_constant (op1, input_location);
    6267              : 
    6268              :               e2 = cp_build_binary_op (location,
    6269              :                                        EQ_EXPR, e2, integer_zero_node,
    6270              :                                        complain);
    6271              :               op0 = cp_build_binary_op (location,
    6272              :                                         TRUTH_ANDIF_EXPR, e1, e2,
    6273              :                                         complain);
    6274              :               op1 = cp_convert (TREE_TYPE (op0), integer_one_node, complain);
    6275              :             }
    6276              :           else
    6277              :             {
    6278          249 :               op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
    6279          249 :               op1 = cp_convert (TREE_TYPE (op0), op1, complain);
    6280              :             }
    6281          249 :           result_type = TREE_TYPE (op0);
    6282              : 
    6283          249 :           warn_for_null_address (location, orig_op0, complain);
    6284              :         }
    6285         4898 :       else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (orig_op0))
    6286           36 :         return cp_build_binary_op (location, code, op1, op0, complain);
    6287         4862 :       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1))
    6288              :         {
    6289          145 :           tree type;
    6290              :           /* E will be the final comparison.  */
    6291          145 :           tree e;
    6292              :           /* E1 and E2 are for scratch.  */
    6293          145 :           tree e1;
    6294          145 :           tree e2;
    6295          145 :           tree pfn0;
    6296          145 :           tree pfn1;
    6297          145 :           tree delta0;
    6298          145 :           tree delta1;
    6299              : 
    6300          145 :           type = composite_pointer_type (location, type0, type1, op0, op1,
    6301              :                                          CPO_COMPARISON, complain);
    6302              : 
    6303          145 :           if (!same_type_p (TREE_TYPE (op0), type))
    6304            6 :             op0 = cp_convert_and_check (type, op0, complain);
    6305          145 :           if (!same_type_p (TREE_TYPE (op1), type))
    6306            9 :             op1 = cp_convert_and_check (type, op1, complain);
    6307              : 
    6308          145 :           if (op0 == error_mark_node || op1 == error_mark_node)
    6309              :             return error_mark_node;
    6310              : 
    6311          142 :           if (TREE_SIDE_EFFECTS (op0))
    6312           79 :             op0 = cp_save_expr (op0);
    6313          142 :           if (TREE_SIDE_EFFECTS (op1))
    6314            3 :             op1 = cp_save_expr (op1);
    6315              : 
    6316          142 :           pfn0 = pfn_from_ptrmemfunc (op0);
    6317          142 :           pfn0 = cp_fully_fold (pfn0);
    6318              :           /* Avoid -Waddress warnings (c++/64877).  */
    6319          142 :           if (TREE_CODE (pfn0) == ADDR_EXPR)
    6320           20 :             suppress_warning (pfn0, OPT_Waddress);
    6321          142 :           pfn1 = pfn_from_ptrmemfunc (op1);
    6322          142 :           pfn1 = cp_fully_fold (pfn1);
    6323          142 :           delta0 = delta_from_ptrmemfunc (op0);
    6324          142 :           delta1 = delta_from_ptrmemfunc (op1);
    6325          142 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION
    6326              :               == ptrmemfunc_vbit_in_delta)
    6327              :             {
    6328              :               /* We generate:
    6329              : 
    6330              :                  (op0.pfn == op1.pfn
    6331              :                   && ((op0.delta == op1.delta)
    6332              :                        || (!op0.pfn && op0.delta & 1 == 0
    6333              :                            && op1.delta & 1 == 0))
    6334              : 
    6335              :                  The reason for the `!op0.pfn' bit is that a NULL
    6336              :                  pointer-to-member is any member with a zero PFN and
    6337              :                  LSB of the DELTA field is 0.  */
    6338              : 
    6339              :               e1 = cp_build_binary_op (location, BIT_AND_EXPR,
    6340              :                                        delta0,
    6341              :                                        integer_one_node,
    6342              :                                        complain);
    6343              :               e1 = cp_build_binary_op (location,
    6344              :                                        EQ_EXPR, e1, integer_zero_node,
    6345              :                                        complain);
    6346              :               e2 = cp_build_binary_op (location, BIT_AND_EXPR,
    6347              :                                        delta1,
    6348              :                                        integer_one_node,
    6349              :                                        complain);
    6350              :               e2 = cp_build_binary_op (location,
    6351              :                                        EQ_EXPR, e2, integer_zero_node,
    6352              :                                        complain);
    6353              :               e1 = cp_build_binary_op (location,
    6354              :                                        TRUTH_ANDIF_EXPR, e2, e1,
    6355              :                                        complain);
    6356              :               e2 = cp_build_binary_op (location, EQ_EXPR,
    6357              :                                        pfn0,
    6358              :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6359              :                                        complain);
    6360              :               e2 = cp_build_binary_op (location,
    6361              :                                        TRUTH_ANDIF_EXPR, e2, e1, complain);
    6362              :               e1 = cp_build_binary_op (location,
    6363              :                                        EQ_EXPR, delta0, delta1, complain);
    6364              :               e1 = cp_build_binary_op (location,
    6365              :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6366              :             }
    6367              :           else
    6368              :             {
    6369              :               /* We generate:
    6370              : 
    6371              :                  (op0.pfn == op1.pfn
    6372              :                  && (!op0.pfn || op0.delta == op1.delta))
    6373              : 
    6374              :                  The reason for the `!op0.pfn' bit is that a NULL
    6375              :                  pointer-to-member is any member with a zero PFN; the
    6376              :                  DELTA field is unspecified.  */
    6377              : 
    6378          142 :               e1 = cp_build_binary_op (location,
    6379              :                                        EQ_EXPR, delta0, delta1, complain);
    6380          142 :               e2 = cp_build_binary_op (location,
    6381              :                                        EQ_EXPR,
    6382              :                                        pfn0,
    6383          142 :                                        build_zero_cst (TREE_TYPE (pfn0)),
    6384              :                                        complain);
    6385          142 :               e1 = cp_build_binary_op (location,
    6386              :                                        TRUTH_ORIF_EXPR, e1, e2, complain);
    6387              :             }
    6388          142 :           e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
    6389          142 :           e = cp_build_binary_op (location,
    6390              :                                   TRUTH_ANDIF_EXPR, e2, e1, complain);
    6391          142 :           if (code == EQ_EXPR)
    6392              :             return e;
    6393           34 :           return cp_build_binary_op (location,
    6394           34 :                                      EQ_EXPR, e, integer_zero_node, complain);
    6395              :         }
    6396              :       /* [expr.eq]: "If both operands are of type std::meta::info,
    6397              :          comparison is defined as follows..."  */
    6398         4717 :       else if (REFLECTION_TYPE_P (type0) && REFLECTION_TYPE_P (type1))
    6399              :         result_type = type0;
    6400              :       else
    6401              :         {
    6402           28 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type0)
    6403              :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type0),
    6404              :                                        type1));
    6405           28 :           gcc_assert (!TYPE_PTRMEMFUNC_P (type1)
    6406              :                       || !same_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type1),
    6407              :                                        type0));
    6408              :         }
    6409              : 
    6410              :       break;
    6411              : 
    6412          241 :     case MAX_EXPR:
    6413          241 :     case MIN_EXPR:
    6414          241 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
    6415          241 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
    6416              :         shorten = 1;
    6417            0 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6418            0 :         result_type = composite_pointer_type (location,
    6419              :                                               type0, type1, op0, op1,
    6420              :                                               CPO_COMPARISON, complain);
    6421              :       break;
    6422              : 
    6423     27088623 :     case LE_EXPR:
    6424     27088623 :     case GE_EXPR:
    6425     27088623 :     case LT_EXPR:
    6426     27088623 :     case GT_EXPR:
    6427     27088623 :     case SPACESHIP_EXPR:
    6428     27088623 :       if (TREE_CODE (orig_op0) == STRING_CST
    6429     27088623 :           || TREE_CODE (orig_op1) == STRING_CST)
    6430              :         {
    6431            0 :           if (complain & tf_warning)
    6432            0 :             warning_at (location, OPT_Waddress,
    6433              :                         "comparison with string literal results "
    6434              :                         "in unspecified behavior");
    6435              :         }
    6436     27088623 :       else if (TREE_CODE (TREE_TYPE (orig_op0)) == ARRAY_TYPE
    6437          224 :                && TREE_CODE (TREE_TYPE (orig_op1)) == ARRAY_TYPE
    6438     27088738 :                && code != SPACESHIP_EXPR)
    6439              :         {
    6440           96 :           if (complain & tf_warning_or_error)
    6441           51 :             do_warn_array_compare (location, code,
    6442              :                                    tree_strip_any_location_wrapper (orig_op0),
    6443              :                                    tree_strip_any_location_wrapper (orig_op1));
    6444           45 :           else if (cxx_dialect >= cxx26)
    6445            1 :             return error_mark_node;
    6446              :         }
    6447              : 
    6448     27088622 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6449              :         {
    6450         8301 :         vector_compare:
    6451         8301 :           tree intt;
    6452         8301 :           if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0),
    6453         8301 :                                                           TREE_TYPE (type1))
    6454         8301 :               && !vector_types_compatible_elements_p (type0, type1))
    6455              :             {
    6456            3 :               if (complain & tf_error)
    6457              :                 {
    6458            3 :                   auto_diagnostic_group d;
    6459            3 :                   error_at (location, "comparing vectors with different "
    6460              :                                       "element types");
    6461            3 :                   inform (location, "operand types are %qT and %qT",
    6462              :                           type0, type1);
    6463            3 :                 }
    6464            3 :               return error_mark_node;
    6465              :             }
    6466              : 
    6467         8298 :           if (maybe_ne (TYPE_VECTOR_SUBPARTS (type0),
    6468        16596 :                         TYPE_VECTOR_SUBPARTS (type1)))
    6469              :             {
    6470            3 :               if (complain & tf_error)
    6471              :                 {
    6472            3 :                   auto_diagnostic_group d;
    6473            3 :                   error_at (location, "comparing vectors with different "
    6474              :                                       "number of elements");
    6475            3 :                   inform (location, "operand types are %qT and %qT",
    6476              :                           type0, type1);
    6477            3 :                 }
    6478            3 :               return error_mark_node;
    6479              :             }
    6480              : 
    6481              :           /* It's not precisely specified how the usual arithmetic
    6482              :              conversions apply to the vector types.  Here, we use
    6483              :              the unsigned type if one of the operands is signed and
    6484              :              the other one is unsigned.  */
    6485         8295 :           if (TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1))
    6486              :             {
    6487           36 :               if (!TYPE_UNSIGNED (type0))
    6488           36 :                 op0 = build1 (VIEW_CONVERT_EXPR, type1, op0);
    6489              :               else
    6490            0 :                 op1 = build1 (VIEW_CONVERT_EXPR, type0, op1);
    6491           36 :               warning_at (location, OPT_Wsign_compare, "comparison between "
    6492              :                           "types %qT and %qT", type0, type1);
    6493              :             }
    6494              : 
    6495         8295 :           if (resultcode == SPACESHIP_EXPR)
    6496              :             {
    6497            3 :               if (complain & tf_error)
    6498            3 :                 sorry_at (location, "three-way comparison of vectors");
    6499            3 :               return error_mark_node;
    6500              :             }
    6501              : 
    6502         8292 :           if (VECTOR_BOOLEAN_TYPE_P (type0) && VECTOR_BOOLEAN_TYPE_P (type1))
    6503              :             result_type = type0;
    6504              :           else
    6505              :             {
    6506              :               /* Always construct signed integer vector type.  */
    6507         8292 :               auto intmode = SCALAR_TYPE_MODE (TREE_TYPE (type0));
    6508         8292 :               auto nelts = TYPE_VECTOR_SUBPARTS (type0);
    6509              : 
    6510        16584 :               intt = c_common_type_for_size (GET_MODE_BITSIZE (intmode), 0);
    6511         8292 :               if (!intt)
    6512              :                 {
    6513            0 :                   if (complain & tf_error)
    6514            0 :                     error_at (location, "could not find an integer type "
    6515            0 :                                 "of the same size as %qT", TREE_TYPE (type0));
    6516            0 :                   return error_mark_node;
    6517              :                 }
    6518         8292 :               result_type = build_opaque_vector_type (intt, nelts);
    6519              :             }
    6520         8292 :           return build_vec_cmp (resultcode, result_type, op0, op1);
    6521              :         }
    6522     27083660 :       build_type = boolean_type_node;
    6523     27083660 :       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
    6524              :            || code0 == ENUMERAL_TYPE)
    6525     24372125 :            && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6526              :                || code1 == ENUMERAL_TYPE))
    6527              :         short_compare = 1;
    6528      2711638 :       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
    6529      2711358 :         result_type = composite_pointer_type (location,
    6530              :                                               type0, type1, op0, op1,
    6531              :                                               CPO_COMPARISON, complain);
    6532           73 :       else if ((code0 == POINTER_TYPE && null_ptr_cst_p (orig_op1))
    6533          208 :                || (code1 == POINTER_TYPE && null_ptr_cst_p (orig_op0))
    6534          434 :                || (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)))
    6535              :         {
    6536              :           /* Core Issue 1512 made this ill-formed.  */
    6537          190 :           if (complain & tf_error)
    6538          186 :             error_at (location, "ordered comparison of pointer with "
    6539              :                       "integer zero (%qT and %qT)", type0, type1);
    6540          190 :           return error_mark_node;
    6541              :         }
    6542           90 :       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
    6543              :         {
    6544            0 :           result_type = type0;
    6545            0 :           if (complain & tf_error)
    6546            0 :             permerror (location, "ISO C++ forbids comparison between "
    6547              :                        "pointer and integer");
    6548              :           else
    6549            0 :             return error_mark_node;
    6550              :         }
    6551           90 :       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
    6552              :         {
    6553           24 :           result_type = type1;
    6554           24 :           if (complain & tf_error)
    6555           24 :             permerror (location, "ISO C++ forbids comparison between "
    6556              :                        "pointer and integer");
    6557              :           else
    6558            0 :             return error_mark_node;
    6559              :         }
    6560              : 
    6561     27083470 :       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
    6562      2711383 :           && !processing_template_decl
    6563     29574715 :           && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
    6564              :         {
    6565           49 :           op0 = cp_save_expr (op0);
    6566           49 :           op1 = cp_save_expr (op1);
    6567              : 
    6568           49 :           tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
    6569           49 :           instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
    6570              :         }
    6571              : 
    6572              :       break;
    6573              : 
    6574            0 :     case UNORDERED_EXPR:
    6575            0 :     case ORDERED_EXPR:
    6576            0 :     case UNLT_EXPR:
    6577            0 :     case UNLE_EXPR:
    6578            0 :     case UNGT_EXPR:
    6579            0 :     case UNGE_EXPR:
    6580            0 :     case UNEQ_EXPR:
    6581            0 :       build_type = integer_type_node;
    6582            0 :       if (code0 != REAL_TYPE || code1 != REAL_TYPE)
    6583              :         {
    6584            0 :           if (complain & tf_error)
    6585            0 :             error ("unordered comparison on non-floating-point argument");
    6586            0 :           return error_mark_node;
    6587              :         }
    6588              :       common = 1;
    6589              :       break;
    6590              : 
    6591              :     default:
    6592              :       break;
    6593              :     }
    6594              : 
    6595    145886214 :   if (((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE
    6596              :         || code0 == ENUMERAL_TYPE)
    6597    118906988 :        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
    6598              :            || code1 == COMPLEX_TYPE || code1 == ENUMERAL_TYPE)))
    6599              :     arithmetic_types_p = 1;
    6600              :   else
    6601              :     {
    6602     27375238 :       arithmetic_types_p = 0;
    6603              :       /* Vector arithmetic is only allowed when both sides are vectors.  */
    6604     27375238 :       if (gnu_vector_type_p (type0) && gnu_vector_type_p (type1))
    6605              :         {
    6606        60242 :           if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1))
    6607        60242 :               || !vector_types_compatible_elements_p (type0, type1))
    6608              :             {
    6609           18 :               if (complain & tf_error)
    6610              :                 {
    6611              :                   /* "location" already embeds the locations of the
    6612              :                      operands, so we don't need to add them separately
    6613              :                      to richloc.  */
    6614           18 :                   rich_location richloc (line_table, location);
    6615           18 :                   binary_op_error (&richloc, code, type0, type1);
    6616           18 :                 }
    6617           18 :               return error_mark_node;
    6618              :             }
    6619              :           arithmetic_types_p = 1;
    6620              :         }
    6621              :     }
    6622              :   /* Determine the RESULT_TYPE, if it is not already known.  */
    6623    145886196 :   if (!result_type
    6624    145886196 :       && arithmetic_types_p
    6625    113996820 :       && (shorten || common || short_compare))
    6626              :     {
    6627    113996673 :       result_type = cp_common_type (type0, type1);
    6628    113996673 :       if (result_type == error_mark_node)
    6629              :         {
    6630            6 :           tree t1 = type0;
    6631            6 :           tree t2 = type1;
    6632            6 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6633            0 :             t1 = TREE_TYPE (t1);
    6634            6 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6635            0 :             t2 = TREE_TYPE (t2);
    6636            6 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6637              :                                && TREE_CODE (t2) == REAL_TYPE
    6638              :                                && (extended_float_type_p (t1)
    6639              :                                    || extended_float_type_p (t2))
    6640              :                                && cp_compare_floating_point_conversion_ranks
    6641              :                                     (t1, t2) == 3);
    6642            6 :           if (complain & tf_error)
    6643              :             {
    6644            6 :               rich_location richloc (line_table, location);
    6645            6 :               binary_op_error (&richloc, code, type0, type1);
    6646            6 :             }
    6647            6 :           return error_mark_node;
    6648              :         }
    6649    113996667 :       if (complain & tf_warning)
    6650    103919665 :         do_warn_double_promotion (result_type, type0, type1,
    6651              :                                   "implicit conversion from %qH to %qI "
    6652              :                                   "to match other operand of binary "
    6653              :                                   "expression", location);
    6654    113996667 :       if (do_warn_enum_conversions (location, code, TREE_TYPE (orig_op0),
    6655    113996667 :                                     TREE_TYPE (orig_op1), complain))
    6656           12 :         return error_mark_node;
    6657              :     }
    6658    145886178 :   if (may_need_excess_precision
    6659    107600173 :       && (orig_type0 != type0 || orig_type1 != type1)
    6660        58291 :       && build_type == NULL_TREE
    6661        58291 :       && result_type)
    6662              :     {
    6663        44272 :       gcc_assert (common);
    6664        44272 :       semantic_result_type = cp_common_type (orig_type0, orig_type1);
    6665        44272 :       if (semantic_result_type == error_mark_node)
    6666              :         {
    6667            0 :           tree t1 = orig_type0;
    6668            0 :           tree t2 = orig_type1;
    6669            0 :           if (TREE_CODE (t1) == COMPLEX_TYPE)
    6670            0 :             t1 = TREE_TYPE (t1);
    6671            0 :           if (TREE_CODE (t2) == COMPLEX_TYPE)
    6672            0 :             t2 = TREE_TYPE (t2);
    6673            0 :           gcc_checking_assert (TREE_CODE (t1) == REAL_TYPE
    6674              :                                && TREE_CODE (t2) == REAL_TYPE
    6675              :                                && (extended_float_type_p (t1)
    6676              :                                    || extended_float_type_p (t2))
    6677              :                                && cp_compare_floating_point_conversion_ranks
    6678              :                                     (t1, t2) == 3);
    6679            0 :           if (complain & tf_error)
    6680              :             {
    6681            0 :               rich_location richloc (line_table, location);
    6682            0 :               binary_op_error (&richloc, code, type0, type1);
    6683            0 :             }
    6684            0 :           return error_mark_node;
    6685              :         }
    6686              :     }
    6687              : 
    6688    145886178 :   if (code == SPACESHIP_EXPR)
    6689              :     {
    6690       623012 :       iloc_sentinel s (location);
    6691              : 
    6692       623012 :       tree orig_type0 = TREE_TYPE (orig_op0);
    6693       623012 :       tree_code orig_code0 = TREE_CODE (orig_type0);
    6694       623012 :       tree orig_type1 = TREE_TYPE (orig_op1);
    6695       623012 :       tree_code orig_code1 = TREE_CODE (orig_type1);
    6696       623012 :       if (!result_type || result_type == error_mark_node)
    6697              :         /* Nope.  */
    6698              :         result_type = NULL_TREE;
    6699       622991 :       else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE))
    6700              :         /* "If one of the operands is of type bool and the other is not, the
    6701              :            program is ill-formed."  */
    6702              :         result_type = NULL_TREE;
    6703       622988 :       else if (code0 == POINTER_TYPE && orig_code0 != POINTER_TYPE
    6704           19 :                && code1 == POINTER_TYPE && orig_code1 != POINTER_TYPE)
    6705              :         /* We only do array/function-to-pointer conversion if "at least one of
    6706              :            the operands is of pointer type".  */
    6707              :         result_type = NULL_TREE;
    6708       622969 :       else if (TYPE_PTRFN_P (result_type) || NULLPTR_TYPE_P (result_type))
    6709              :         /* <=> no longer supports equality relations.  */
    6710              :         result_type = NULL_TREE;
    6711       622966 :       else if (orig_code0 == ENUMERAL_TYPE && orig_code1 == ENUMERAL_TYPE
    6712       622996 :                && !(same_type_ignoring_top_level_qualifiers_p
    6713           30 :                     (orig_type0, orig_type1)))
    6714              :         /* "If both operands have arithmetic types, or one operand has integral
    6715              :            type and the other operand has unscoped enumeration type, the usual
    6716              :            arithmetic conversions are applied to the operands."  So we don't do
    6717              :            arithmetic conversions if the operands both have enumeral type.  */
    6718              :         result_type = NULL_TREE;
    6719       622951 :       else if ((orig_code0 == ENUMERAL_TYPE && orig_code1 == REAL_TYPE)
    6720       622945 :                || (orig_code0 == REAL_TYPE && orig_code1 == ENUMERAL_TYPE))
    6721              :         /* [depr.arith.conv.enum]: Three-way comparisons between such operands
    6722              :            [where one is of enumeration type and the other is of a different
    6723              :            enumeration type or a floating-point type] are ill-formed.  */
    6724              :         result_type = NULL_TREE;
    6725              : 
    6726       622939 :       if (result_type)
    6727              :         {
    6728       622939 :           build_type = spaceship_type (result_type, complain);
    6729       622939 :           if (build_type == error_mark_node)
    6730              :             return error_mark_node;
    6731              :         }
    6732              : 
    6733       622997 :       if (result_type && arithmetic_types_p)
    6734              :         {
    6735              :           /* If a narrowing conversion is required, other than from an integral
    6736              :              type to a floating point type, the program is ill-formed.  */
    6737       288230 :           bool ok = true;
    6738       288230 :           if (TREE_CODE (result_type) == REAL_TYPE
    6739          614 :               && CP_INTEGRAL_TYPE_P (orig_type0))
    6740              :             /* OK */;
    6741       288223 :           else if (!check_narrowing (result_type, orig_op0, complain))
    6742       288230 :             ok = false;
    6743       288230 :           if (TREE_CODE (result_type) == REAL_TYPE
    6744          614 :               && CP_INTEGRAL_TYPE_P (orig_type1))
    6745              :             /* OK */;
    6746       288223 :           else if (!check_narrowing (result_type, orig_op1, complain))
    6747              :             ok = false;
    6748       288230 :           if (!ok && !(complain & tf_error))
    6749            2 :             return error_mark_node;
    6750              :         }
    6751       623012 :     }
    6752              : 
    6753    145886161 :   if (!result_type)
    6754              :     {
    6755          606 :       if (complain & tf_error)
    6756              :         {
    6757          221 :           binary_op_rich_location richloc (location,
    6758          221 :                                            orig_op0, orig_op1, true);
    6759          221 :           error_at (&richloc,
    6760              :                     "invalid operands of types %qT and %qT to binary %qO",
    6761          221 :                     TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), code);
    6762          221 :         }
    6763          606 :       return error_mark_node;
    6764              :     }
    6765              : 
    6766              :   /* If we're in a template, the only thing we need to know is the
    6767              :      RESULT_TYPE.  */
    6768    145885555 :   if (processing_template_decl)
    6769              :     {
    6770              :       /* Since the middle-end checks the type when doing a build2, we
    6771              :          need to build the tree in pieces.  This built tree will never
    6772              :          get out of the front-end as we replace it when instantiating
    6773              :          the template.  */
    6774     68578271 :       tree tmp = build2 (resultcode,
    6775              :                          build_type ? build_type : result_type,
    6776              :                          NULL_TREE, op1);
    6777     42896146 :       TREE_OPERAND (tmp, 0) = op0;
    6778     42896146 :       if (semantic_result_type)
    6779           72 :         tmp = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, tmp);
    6780              :       return tmp;
    6781              :     }
    6782              : 
    6783              :   /* Remember the original type; RESULT_TYPE might be changed later on
    6784              :      by shorten_binary_op.  */
    6785    102989409 :   tree orig_type = result_type;
    6786              : 
    6787    102989409 :   if (arithmetic_types_p)
    6788              :     {
    6789     88271569 :       bool first_complex = (code0 == COMPLEX_TYPE);
    6790     88271569 :       bool second_complex = (code1 == COMPLEX_TYPE);
    6791     88271569 :       int none_complex = (!first_complex && !second_complex);
    6792              : 
    6793              :       /* Adapted from patch for c/24581.  */
    6794     88271569 :       if (first_complex != second_complex
    6795       160895 :           && (code == PLUS_EXPR
    6796              :               || code == MINUS_EXPR
    6797       160895 :               || code == MULT_EXPR
    6798        42041 :               || (code == TRUNC_DIV_EXPR && first_complex))
    6799       147388 :           && TREE_CODE (TREE_TYPE (result_type)) == REAL_TYPE
    6800     88418796 :           && flag_signed_zeros)
    6801              :         {
    6802              :           /* An operation on mixed real/complex operands must be
    6803              :              handled specially, but the language-independent code can
    6804              :              more easily optimize the plain complex arithmetic if
    6805              :              -fno-signed-zeros.  */
    6806       147227 :           tree real_type = TREE_TYPE (result_type);
    6807       147227 :           tree real, imag;
    6808       147227 :           if (first_complex)
    6809              :             {
    6810       114175 :               if (TREE_TYPE (op0) != result_type)
    6811            6 :                 op0 = cp_convert_and_check (result_type, op0, complain);
    6812       114175 :               if (TREE_TYPE (op1) != real_type)
    6813           30 :                 op1 = cp_convert_and_check (real_type, op1, complain);
    6814              :             }
    6815              :           else
    6816              :             {
    6817        33052 :               if (TREE_TYPE (op0) != real_type)
    6818           35 :                 op0 = cp_convert_and_check (real_type, op0, complain);
    6819        33052 :               if (TREE_TYPE (op1) != result_type)
    6820           32 :                 op1 = cp_convert_and_check (result_type, op1, complain);
    6821              :             }
    6822       147227 :           if (TREE_CODE (op0) == ERROR_MARK || TREE_CODE (op1) == ERROR_MARK)
    6823            0 :             return error_mark_node;
    6824       147227 :           if (first_complex)
    6825              :             {
    6826       114175 :               op0 = cp_save_expr (op0);
    6827       114175 :               real = cp_build_unary_op (REALPART_EXPR, op0, true, complain);
    6828       114175 :               imag = cp_build_unary_op (IMAGPART_EXPR, op0, true, complain);
    6829       114175 :               switch (code)
    6830              :                 {
    6831        57067 :                 case MULT_EXPR:
    6832        57067 :                 case TRUNC_DIV_EXPR:
    6833        57067 :                   op1 = cp_save_expr (op1);
    6834        57067 :                   imag = build2 (resultcode, real_type, imag, op1);
    6835              :                   /* Fall through.  */
    6836       114175 :                 case PLUS_EXPR:
    6837       114175 :                 case MINUS_EXPR:
    6838       114175 :                   real = build2 (resultcode, real_type, real, op1);
    6839       114175 :                   break;
    6840              :                 default:
    6841              :                   gcc_unreachable();
    6842              :                 }
    6843              :             }
    6844              :           else
    6845              :             {
    6846        33052 :               op1 = cp_save_expr (op1);
    6847        33052 :               real = cp_build_unary_op (REALPART_EXPR, op1, true, complain);
    6848        33052 :               imag = cp_build_unary_op (IMAGPART_EXPR, op1, true, complain);
    6849        33052 :               switch (code)
    6850              :                 {
    6851          638 :                 case MULT_EXPR:
    6852          638 :                   op0 = cp_save_expr (op0);
    6853          638 :                   imag = build2 (resultcode, real_type, op0, imag);
    6854              :                   /* Fall through.  */
    6855        17305 :                 case PLUS_EXPR:
    6856        17305 :                   real = build2 (resultcode, real_type, op0, real);
    6857        17305 :                   break;
    6858        15747 :                 case MINUS_EXPR:
    6859        15747 :                   real = build2 (resultcode, real_type, op0, real);
    6860        15747 :                   imag = build1 (NEGATE_EXPR, real_type, imag);
    6861        15747 :                   break;
    6862            0 :                 default:
    6863            0 :                   gcc_unreachable();
    6864              :                 }
    6865              :             }
    6866       147227 :           result = build2 (COMPLEX_EXPR, result_type, real, imag);
    6867       147227 :           if (semantic_result_type)
    6868           26 :             result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type,
    6869              :                              result);
    6870              :           return result;
    6871              :         }
    6872              : 
    6873              :       /* For certain operations (which identify themselves by shorten != 0)
    6874              :          if both args were extended from the same smaller type,
    6875              :          do the arithmetic in that type and then extend.
    6876              : 
    6877              :          shorten !=0 and !=1 indicates a bitwise operation.
    6878              :          For them, this optimization is safe only if
    6879              :          both args are zero-extended or both are sign-extended.
    6880              :          Otherwise, we might change the result.
    6881              :          E.g., (short)-1 | (unsigned short)-1 is (int)-1
    6882              :          but calculated in (unsigned short) it would be (unsigned short)-1.  */
    6883              : 
    6884     88124342 :       if (shorten && none_complex)
    6885              :         {
    6886      6940366 :           final_type = result_type;
    6887      6940366 :           result_type = shorten_binary_op (result_type, op0, op1,
    6888              :                                            shorten == -1);
    6889              :         }
    6890              : 
    6891              :       /* Shifts can be shortened if shifting right.  */
    6892              : 
    6893     88124342 :       if (short_shift)
    6894              :         {
    6895       848584 :           int unsigned_arg;
    6896       848584 :           tree arg0 = get_narrower (op0, &unsigned_arg);
    6897              :           /* We're not really warning here but when we set short_shift we
    6898              :              used fold_for_warn to fold the operand.  */
    6899       848584 :           tree const_op1 = fold_for_warn (op1);
    6900              : 
    6901       848584 :           final_type = result_type;
    6902              : 
    6903       848584 :           if (arg0 == op0 && final_type == TREE_TYPE (op0))
    6904       770281 :             unsigned_arg = TYPE_UNSIGNED (TREE_TYPE (op0));
    6905              : 
    6906       848584 :           if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
    6907         1108 :               && tree_int_cst_sgn (const_op1) > 0
    6908              :               /* We can shorten only if the shift count is less than the
    6909              :                  number of bits in the smaller type size.  */
    6910         1108 :               && compare_tree_int (const_op1,
    6911         1108 :                                    TYPE_PRECISION (TREE_TYPE (arg0))) < 0
    6912              :               /* We cannot drop an unsigned shift after sign-extension.  */
    6913       849652 :               && (!TYPE_UNSIGNED (final_type) || unsigned_arg))
    6914              :             {
    6915              :               /* Do an unsigned shift if the operand was zero-extended.  */
    6916         1061 :               result_type
    6917         1061 :                 = c_common_signed_or_unsigned_type (unsigned_arg,
    6918         1061 :                                                     TREE_TYPE (arg0));
    6919              :               /* Convert value-to-be-shifted to that type.  */
    6920         1061 :               if (TREE_TYPE (op0) != result_type)
    6921         1061 :                 op0 = convert (result_type, op0);
    6922              :               converted = 1;
    6923              :             }
    6924              :         }
    6925              : 
    6926              :       /* Comparison operations are shortened too but differently.
    6927              :          They identify themselves by setting short_compare = 1.  */
    6928              : 
    6929     88124342 :       if (short_compare)
    6930              :         {
    6931              :           /* We call shorten_compare only for diagnostics.  */
    6932     30673009 :           tree xop0 = fold_simple (op0);
    6933     30673009 :           tree xop1 = fold_simple (op1);
    6934     30673009 :           tree xresult_type = result_type;
    6935     30673009 :           enum tree_code xresultcode = resultcode;
    6936     30673009 :           shorten_compare (location, &xop0, &xop1, &xresult_type,
    6937              :                            &xresultcode);
    6938              :         }
    6939              : 
    6940     57451246 :       if ((short_compare || code == MIN_EXPR || code == MAX_EXPR)
    6941     30673198 :           && warn_sign_compare
    6942              :           /* Do not warn until the template is instantiated; we cannot
    6943              :              bound the ranges of the arguments until that point.  */
    6944       346093 :           && !processing_template_decl
    6945       346093 :           && (complain & tf_warning)
    6946       338228 :           && c_inhibit_evaluation_warnings == 0
    6947              :           /* Even unsigned enum types promote to signed int.  We don't
    6948              :              want to issue -Wsign-compare warnings for this case.  */
    6949       321808 :           && !enum_cast_to_int (orig_op0)
    6950     88446150 :           && !enum_cast_to_int (orig_op1))
    6951              :         {
    6952       321801 :           warn_for_sign_compare (location, orig_op0, orig_op1, op0, op1,
    6953              :                                  result_type, resultcode);
    6954              :         }
    6955              :     }
    6956              : 
    6957              :   /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
    6958              :      Then the expression will be built.
    6959              :      It will be given type FINAL_TYPE if that is nonzero;
    6960              :      otherwise, it will be given type RESULT_TYPE.  */
    6961    102842182 :   if (! converted)
    6962              :     {
    6963     99106697 :       warning_sentinel w (warn_sign_conversion, short_compare);
    6964     99106697 :       warning_sentinel w_attr (warn_conversion_attribute,
    6965     99106697 :                                (common || shorten == -1) && !short_compare);
    6966     99106697 :       if (!same_type_p (TREE_TYPE (op0), result_type))
    6967      4411231 :         op0 = cp_convert_and_check (result_type, op0, complain);
    6968     99106697 :       if (!same_type_p (TREE_TYPE (op1), result_type))
    6969     19237731 :         op1 = cp_convert_and_check (result_type, op1, complain);
    6970              : 
    6971     99106697 :       if (op0 == error_mark_node || op1 == error_mark_node)
    6972           58 :         return error_mark_node;
    6973     99106697 :     }
    6974              : 
    6975    102842124 :   if (build_type == NULL_TREE)
    6976     65641639 :     build_type = result_type;
    6977              : 
    6978    102842124 :   if (doing_shift
    6979      3734748 :       && flag_strong_eval_order == 2
    6980      3646526 :       && TREE_SIDE_EFFECTS (op1)
    6981    102864989 :       && !processing_template_decl)
    6982              :     {
    6983              :       /* In C++17, in both op0 << op1 and op0 >> op1 op0 is sequenced before
    6984              :          op1, so if op1 has side-effects, use SAVE_EXPR around op0.  */
    6985        22865 :       op0 = cp_save_expr (op0);
    6986        22865 :       instrument_expr = op0;
    6987              :     }
    6988              : 
    6989    102842124 :   if (sanitize_flags_p ((SANITIZE_SHIFT
    6990              :                          | SANITIZE_DIVIDE
    6991              :                          | SANITIZE_FLOAT_DIVIDE
    6992              :                          | SANITIZE_SI_OVERFLOW))
    6993        13874 :       && current_function_decl != NULL_TREE
    6994        11490 :       && !processing_template_decl
    6995    102853614 :       && (doing_div_or_mod || doing_shift))
    6996              :     {
    6997              :       /* OP0 and/or OP1 might have side-effects.  */
    6998          939 :       op0 = cp_save_expr (op0);
    6999          939 :       op1 = cp_save_expr (op1);
    7000          939 :       op0 = fold_non_dependent_expr (op0, complain);
    7001          939 :       op1 = fold_non_dependent_expr (op1, complain);
    7002          939 :       tree instrument_expr1 = NULL_TREE;
    7003          939 :       if (doing_div_or_mod
    7004          939 :           && sanitize_flags_p (SANITIZE_DIVIDE
    7005              :                                | SANITIZE_FLOAT_DIVIDE
    7006              :                                | SANITIZE_SI_OVERFLOW))
    7007              :         {
    7008              :           /* For diagnostics we want to use the promoted types without
    7009              :              shorten_binary_op.  So convert the arguments to the
    7010              :              original result_type.  */
    7011          475 :           tree cop0 = op0;
    7012          475 :           tree cop1 = op1;
    7013          475 :           if (TREE_TYPE (cop0) != orig_type)
    7014            6 :             cop0 = cp_convert (orig_type, op0, complain);
    7015          475 :           if (TREE_TYPE (cop1) != orig_type)
    7016           39 :             cop1 = cp_convert (orig_type, op1, complain);
    7017          475 :           instrument_expr1 = ubsan_instrument_division (location, cop0, cop1);
    7018              :         }
    7019          464 :       else if (doing_shift && sanitize_flags_p (SANITIZE_SHIFT))
    7020          383 :         instrument_expr1 = ubsan_instrument_shift (location, code, op0, op1);
    7021          939 :       if (instrument_expr != NULL)
    7022           18 :         instrument_expr = add_stmt_to_compound (instrument_expr,
    7023              :                                                 instrument_expr1);
    7024              :       else
    7025          921 :         instrument_expr = instrument_expr1;
    7026              :     }
    7027              : 
    7028    102842124 :   result = build2_loc (location, resultcode, build_type, op0, op1);
    7029    102842124 :   if (final_type != 0)
    7030      7788950 :     result = cp_convert (final_type, result, complain);
    7031              : 
    7032    102842124 :   if (instrument_expr != NULL)
    7033        23363 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result),
    7034              :                      instrument_expr, result);
    7035              : 
    7036    102842124 :   if (resultcode == SPACESHIP_EXPR && !processing_template_decl)
    7037       524960 :     result = get_target_expr (result, complain);
    7038              : 
    7039    102842124 :   if (semantic_result_type)
    7040        44174 :     result = build1 (EXCESS_PRECISION_EXPR, semantic_result_type, result);
    7041              : 
    7042    102842124 :   if (!c_inhibit_evaluation_warnings)
    7043              :     {
    7044     87398976 :       if (!processing_template_decl)
    7045              :         {
    7046     87398976 :           op0 = cp_fully_fold (op0);
    7047              :           /* Only consider the second argument if the first isn't overflowed.  */
    7048     87398976 :           if (!CONSTANT_CLASS_P (op0) || TREE_OVERFLOW_P (op0))
    7049              :             return result;
    7050     24635102 :           op1 = cp_fully_fold (op1);
    7051     24635102 :           if (!CONSTANT_CLASS_P (op1) || TREE_OVERFLOW_P (op1))
    7052              :             return result;
    7053              :         }
    7054            0 :       else if (!CONSTANT_CLASS_P (op0) || !CONSTANT_CLASS_P (op1)
    7055            0 :                || TREE_OVERFLOW_P (op0) || TREE_OVERFLOW_P (op1))
    7056              :         return result;
    7057              : 
    7058     19101959 :       tree result_ovl = fold_build2 (resultcode, build_type, op0, op1);
    7059     19101959 :       if (TREE_OVERFLOW_P (result_ovl))
    7060          190 :         overflow_warning (location, result_ovl);
    7061              :     }
    7062              : 
    7063              :   return result;
    7064              : }
    7065              : 
    7066              : /* Build a VEC_PERM_EXPR.
    7067              :    This is a simple wrapper for c_build_vec_perm_expr.  */
    7068              : tree
    7069        17402 : build_x_vec_perm_expr (location_t loc,
    7070              :                         tree arg0, tree arg1, tree arg2,
    7071              :                         tsubst_flags_t complain)
    7072              : {
    7073        17402 :   tree orig_arg0 = arg0;
    7074        17402 :   tree orig_arg1 = arg1;
    7075        17402 :   tree orig_arg2 = arg2;
    7076        17402 :   if (processing_template_decl)
    7077              :     {
    7078           19 :       if (type_dependent_expression_p (arg0)
    7079           13 :           || type_dependent_expression_p (arg1)
    7080           32 :           || type_dependent_expression_p (arg2))
    7081            6 :         return build_min_nt_loc (loc, VEC_PERM_EXPR, arg0, arg1, arg2);
    7082              :     }
    7083        17396 :   tree exp = c_build_vec_perm_expr (loc, arg0, arg1, arg2, complain & tf_error);
    7084        17396 :   if (processing_template_decl && exp != error_mark_node)
    7085           13 :     return build_min_non_dep (VEC_PERM_EXPR, exp, orig_arg0,
    7086           13 :                               orig_arg1, orig_arg2);
    7087              :   return exp;
    7088              : }
    7089              : 
    7090              : /* Build a VEC_PERM_EXPR.
    7091              :    This is a simple wrapper for c_build_shufflevector.  */
    7092              : tree
    7093        42187 : build_x_shufflevector (location_t loc, vec<tree, va_gc> *args,
    7094              :                        tsubst_flags_t complain)
    7095              : {
    7096        42187 :   tree arg0 = (*args)[0];
    7097        42187 :   tree arg1 = (*args)[1];
    7098        42187 :   if (processing_template_decl)
    7099              :     {
    7100          743 :       for (unsigned i = 0; i < args->length (); ++i)
    7101          712 :         if (i <= 1
    7102          712 :             ? type_dependent_expression_p ((*args)[i])
    7103          121 :             : instantiation_dependent_expression_p ((*args)[i]))
    7104              :           {
    7105          526 :             tree exp = build_min_nt_call_vec (NULL, args);
    7106          526 :             CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    7107          526 :             return exp;
    7108              :           }
    7109              :     }
    7110        41661 :   auto_vec<tree, 16> mask;
    7111       561177 :   for (unsigned i = 2; i < args->length (); ++i)
    7112              :     {
    7113       519516 :       tree idx = fold_non_dependent_expr ((*args)[i], complain);
    7114       519516 :       mask.safe_push (idx);
    7115              :     }
    7116        41661 :   tree exp = c_build_shufflevector (loc, arg0, arg1, mask, complain & tf_error);
    7117        41661 :   if (processing_template_decl && exp != error_mark_node)
    7118              :     {
    7119           31 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7120           31 :       CALL_EXPR_IFN (exp) = IFN_SHUFFLEVECTOR;
    7121              :     }
    7122        41661 :   return exp;
    7123        41661 : }
    7124              : 
    7125              : /* Build __builtin_bswapg (ARG) or __builtin_bitreverseg (ARG).  */
    7126              : tree
    7127         1546 : build_x_bswapg_bitreverseg (location_t loc, internal_fn ifn,
    7128              :                             vec<tree, va_gc> *args, tsubst_flags_t complain)
    7129              : {
    7130         1456 :   const char *name
    7131         1546 :     = ifn == IFN_BSWAP ? "__builtin_bswapg" : "__builtin_bitreverseg";
    7132         1546 :   if (args->length () != 1)
    7133              :     {
    7134           18 :       if (complain & tf_error)
    7135           18 :         error_at (loc, "wrong number of arguments to %qs", name);
    7136           18 :       return error_mark_node;
    7137              :     }
    7138         1528 :   tree arg = (*args)[0];
    7139         1528 :   if (error_operand_p (arg))
    7140            6 :     return error_mark_node;
    7141         1522 :   if (type_dependent_expression_p (arg))
    7142              :     {
    7143         1372 :       tree exp = build_min_nt_call_vec (NULL, args);
    7144         1372 :       CALL_EXPR_IFN (exp) = ifn;
    7145         1372 :       return exp;
    7146              :     }
    7147          150 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg));
    7148          150 :   if (!INTEGRAL_TYPE_P (type))
    7149              :     {
    7150           24 :       if (complain & tf_error)
    7151           24 :         error_at (loc, "%qs operand not an integral type", name);
    7152           24 :       return error_mark_node;
    7153              :     }
    7154          126 :   if (TREE_CODE (type) == ENUMERAL_TYPE)
    7155              :     {
    7156           30 :       if (complain & tf_error)
    7157           30 :         error_at (loc, "argument %u in call to function "
    7158              :                        "%qs has enumerated type", 1, name);
    7159           30 :       return error_mark_node;
    7160              :     }
    7161           96 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
    7162              :     {
    7163            6 :       if (complain & tf_error)
    7164            6 :         error_at (loc, "argument %u in call to function "
    7165              :                        "%qs has boolean type", 1, name);
    7166            6 :       return error_mark_node;
    7167              :     }
    7168           90 :   if (!TYPE_UNSIGNED (type))
    7169              :     {
    7170           12 :       if (complain & tf_error)
    7171           12 :         error_at (loc, "argument 1 in call to function "
    7172              :                        "%qs has signed type", name);
    7173           12 :       return error_mark_node;
    7174              :     }
    7175           78 :   if (ifn == IFN_BSWAP && (TYPE_PRECISION (type) % 8) != 0)
    7176              :     {
    7177            0 :       if (complain & tf_error)
    7178            0 :         error_at (loc, "precision %d of argument 1 to function "
    7179              :                        "%qs is not a multiple of 8",
    7180            0 :                   TYPE_PRECISION (type), name);
    7181            0 :       return error_mark_node;
    7182              :     }
    7183           78 :   tree exp = build_call_expr_internal_loc (loc, ifn, type, 1, arg);
    7184           78 :   if (processing_template_decl)
    7185              :     {
    7186            0 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7187            0 :       CALL_EXPR_IFN (exp) = ifn;
    7188              :     }
    7189              :   return exp;
    7190              : }
    7191              : 
    7192              : /* Build __builtin_clmulg (ARG1, ARG2) or
    7193              :    __builtin_clmulg (ARG1, ARG2, ARG3).  */
    7194              : tree
    7195         1363 : build_x_clmulg (location_t loc, vec<tree, va_gc> *args,
    7196              :                 tsubst_flags_t complain)
    7197              : {
    7198         1363 :   const char *name = "__builtin_clmulg";
    7199         1363 :   if (args->length () < 2 || args->length () > 3)
    7200              :     {
    7201            9 :       if (complain & tf_error)
    7202            9 :         error_at (loc, "wrong number of arguments to %qs", name);
    7203            9 :       return error_mark_node;
    7204              :     }
    7205         1354 :   tree arg1 = (*args)[0];
    7206         1354 :   tree arg2 = (*args)[1];
    7207         1354 :   tree arg3 = args->length () == 3 ? (*args)[2] : NULL_TREE;
    7208         1354 :   if (error_operand_p (arg1)
    7209         1354 :       || error_operand_p (arg2)
    7210         2708 :       || error_operand_p (arg3))
    7211            0 :     return error_mark_node;
    7212         1354 :   if (type_dependent_expression_p (arg1)
    7213          372 :       || type_dependent_expression_p (arg2)
    7214         1726 :       || type_dependent_expression_p (arg3))
    7215              :     {
    7216          982 :       tree exp = build_min_nt_call_vec (NULL, args);
    7217          982 :       CALL_EXPR_IFN (exp) = IFN_CLMUL;
    7218          982 :       return exp;
    7219              :     }
    7220          372 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg1));
    7221          372 :   if (!INTEGRAL_TYPE_P (type))
    7222              :     {
    7223           12 :       if (complain & tf_error)
    7224           12 :         error_at (loc, "%qs operand not an integral type", name);
    7225           12 :       return error_mark_node;
    7226              :     }
    7227          360 :   if (TREE_CODE (type) == ENUMERAL_TYPE)
    7228              :     {
    7229           15 :       if (complain & tf_error)
    7230           15 :         error_at (loc, "argument %u in call to function "
    7231              :                        "%qs has enumerated type", 1, name);
    7232           15 :       return error_mark_node;
    7233              :     }
    7234          345 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
    7235              :     {
    7236            6 :       if (complain & tf_error)
    7237            6 :         error_at (loc, "argument %u in call to function "
    7238              :                        "%qs has boolean type", 1, name);
    7239            6 :       return error_mark_node;
    7240              :     }
    7241          339 :   if (!TYPE_UNSIGNED (type))
    7242              :     {
    7243           12 :       if (complain & tf_error)
    7244           12 :         error_at (loc, "argument 1 in call to function "
    7245              :                        "%qs has signed type", name);
    7246           12 :       return error_mark_node;
    7247              :     }
    7248          327 :   if (!same_type_p (type, TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
    7249              :     {
    7250           24 :       if (complain & tf_error)
    7251           24 :         error_at (loc, "arguments 1 and 2 to function %qs "
    7252              :                        "have different types %qT and %qT",
    7253           24 :                   name, type, TYPE_MAIN_VARIANT (TREE_TYPE (arg2)));
    7254           24 :       return error_mark_node;
    7255              :     }
    7256          303 :   if (arg3)
    7257              :     {
    7258          117 :       if (!POINTER_TYPE_P (TREE_TYPE (arg3)))
    7259              :         {
    7260            3 :           if (complain & tf_error)
    7261            3 :             error_at (loc, "argument 3 to function %qs does not have "
    7262              :                            "pointer type", name);
    7263            3 :           return error_mark_node;
    7264              :         }
    7265          114 :       tree htype = TREE_TYPE (TREE_TYPE (arg3));
    7266          114 :       if (!same_type_p (type, TYPE_MAIN_VARIANT (htype)))
    7267              :         {
    7268            3 :           if (complain & tf_error)
    7269            3 :             error_at (loc, "arguments 1 and 3 to function %qs "
    7270              :                            "have incompatible types %qT and %qT",
    7271            3 :                       name, type, TREE_TYPE (arg3));
    7272            3 :           return error_mark_node;
    7273              :         }
    7274          111 :       if (TYPE_READONLY (htype))
    7275              :         {
    7276            3 :           if (complain & tf_error)
    7277            3 :             error_at (loc, "argument 3 to function %qs "
    7278              :                            "has pointer to %qs type %qT",
    7279            3 :                       name, "const", TREE_TYPE (arg3));
    7280            3 :           return error_mark_node;
    7281              :         }
    7282              :     }
    7283          294 :   tree exp = build_call_expr_internal_loc (loc, IFN_CLMUL, type,
    7284              :                                            arg3 ? 3 : 2, arg1, arg2, arg3);
    7285          294 :   if (processing_template_decl)
    7286              :     {
    7287            0 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7288            0 :       CALL_EXPR_IFN (exp) = IFN_CLMUL;
    7289              :     }
    7290              :   return exp;
    7291              : }
    7292              : 
    7293              : /* Build __builtin_bitcompressg (ARG1, ARG2) or
    7294              :    __builtin_bitexpandg (ARG1, ARG2).  */
    7295              : tree
    7296         3548 : build_x_bitcompressg_bitexpandg (location_t loc, internal_fn ifn,
    7297              :                                  vec<tree, va_gc> *args,
    7298              :                                  tsubst_flags_t complain)
    7299              : {
    7300         1780 :   const char *name
    7301              :     = (ifn == IFN_BITCOMPRESS
    7302         3548 :        ? "__builtin_bitcompressg" : "__builtin_bitexpandg");
    7303         3548 :   if (args->length () != 2)
    7304              :     {
    7305           24 :       if (complain & tf_error)
    7306           24 :         error_at (loc, "wrong number of arguments to %qs", name);
    7307           24 :       return error_mark_node;
    7308              :     }
    7309         3524 :   tree arg1 = (*args)[0];
    7310         3524 :   tree arg2 = (*args)[1];
    7311         3524 :   if (error_operand_p (arg1) || error_operand_p (arg2))
    7312            0 :     return error_mark_node;
    7313         3524 :   if (type_dependent_expression_p (arg1)
    7314         3524 :       || type_dependent_expression_p (arg2))
    7315              :     {
    7316         2720 :       tree exp = build_min_nt_call_vec (NULL, args);
    7317         2720 :       CALL_EXPR_IFN (exp) = ifn;
    7318         2720 :       return exp;
    7319              :     }
    7320          804 :   tree type = TYPE_MAIN_VARIANT (TREE_TYPE (arg1));
    7321          804 :   if (!INTEGRAL_TYPE_P (type))
    7322              :     {
    7323           24 :       if (complain & tf_error)
    7324           24 :         error_at (loc, "%qs operand not an integral type", name);
    7325           24 :       return error_mark_node;
    7326              :     }
    7327          780 :   if (TREE_CODE (type) == ENUMERAL_TYPE)
    7328              :     {
    7329           30 :       if (complain & tf_error)
    7330           30 :         error_at (loc, "argument %u in call to function "
    7331              :                        "%qs has enumerated type", 1, name);
    7332           30 :       return error_mark_node;
    7333              :     }
    7334          750 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
    7335              :     {
    7336            6 :       if (complain & tf_error)
    7337            6 :         error_at (loc, "argument %u in call to function "
    7338              :                        "%qs has boolean type", 1, name);
    7339            6 :       return error_mark_node;
    7340              :     }
    7341          744 :   if (!TYPE_UNSIGNED (type))
    7342              :     {
    7343           12 :       if (complain & tf_error)
    7344           12 :         error_at (loc, "argument 1 in call to function "
    7345              :                        "%qs has signed type", name);
    7346           12 :       return error_mark_node;
    7347              :     }
    7348          732 :   if (!same_type_p (type, TYPE_MAIN_VARIANT (TREE_TYPE (arg2))))
    7349              :     {
    7350           24 :       if (complain & tf_error)
    7351           24 :         error_at (loc, "arguments 1 and 2 to function %qs "
    7352              :                        "have different types %qT and %qT",
    7353           24 :                   name, type, TYPE_MAIN_VARIANT (TREE_TYPE (arg2)));
    7354           24 :       return error_mark_node;
    7355              :     }
    7356          708 :   tree exp = build_call_expr_internal_loc (loc, ifn, type, 2, arg1, arg2);
    7357          708 :   if (processing_template_decl)
    7358              :     {
    7359            0 :       exp = build_min_non_dep_call_vec (exp, NULL, args);
    7360            0 :       CALL_EXPR_IFN (exp) = ifn;
    7361              :     }
    7362              :   return exp;
    7363              : }
    7364              : 
    7365              : /* Return a tree for the sum or difference (RESULTCODE says which)
    7366              :    of pointer PTROP and integer INTOP.  */
    7367              : 
    7368              : static tree
    7369      5821283 : cp_pointer_int_sum (location_t loc, enum tree_code resultcode, tree ptrop,
    7370              :                     tree intop, tsubst_flags_t complain)
    7371              : {
    7372      5821283 :   tree res_type = TREE_TYPE (ptrop);
    7373              : 
    7374              :   /* pointer_int_sum() uses size_in_bytes() on the TREE_TYPE(res_type)
    7375              :      in certain circumstance (when it's valid to do so).  So we need
    7376              :      to make sure it's complete.  We don't need to check here, if we
    7377              :      can actually complete it at all, as those checks will be done in
    7378              :      pointer_int_sum() anyway.  */
    7379      5821283 :   complete_type (TREE_TYPE (res_type));
    7380              : 
    7381      5821283 :   return pointer_int_sum (loc, resultcode, ptrop,
    7382      5821283 :                           intop, complain & tf_warning_or_error);
    7383              : }
    7384              : 
    7385              : /* Return a tree for the difference of pointers OP0 and OP1.
    7386              :    The resulting tree has type int.  If POINTER_SUBTRACT sanitization is
    7387              :    enabled, assign to INSTRUMENT_EXPR call to libsanitizer.  */
    7388              : 
    7389              : static tree
    7390      1553890 : pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
    7391              :               tsubst_flags_t complain, tree *instrument_expr)
    7392              : {
    7393      1553890 :   tree result, inttype;
    7394      1553890 :   tree restype = ptrdiff_type_node;
    7395      1553890 :   tree target_type = TREE_TYPE (ptrtype);
    7396              : 
    7397      1553890 :   if (!complete_type_or_maybe_complain (target_type, NULL_TREE, complain))
    7398            9 :     return error_mark_node;
    7399              : 
    7400      1553881 :   if (VOID_TYPE_P (target_type))
    7401              :     {
    7402            0 :       if (complain & tf_error)
    7403            0 :         permerror (loc, "ISO C++ forbids using pointer of "
    7404              :                    "type %<void *%> in subtraction");
    7405              :       else
    7406            0 :         return error_mark_node;
    7407              :     }
    7408      1553881 :   if (TREE_CODE (target_type) == FUNCTION_TYPE)
    7409              :     {
    7410            9 :       if (complain & tf_error)
    7411            3 :         permerror (loc, "ISO C++ forbids using pointer to "
    7412              :                    "a function in subtraction");
    7413              :       else
    7414            6 :         return error_mark_node;
    7415              :     }
    7416      1553875 :   if (TREE_CODE (target_type) == METHOD_TYPE)
    7417              :     {
    7418            0 :       if (complain & tf_error)
    7419            0 :         permerror (loc, "ISO C++ forbids using pointer to "
    7420              :                    "a method in subtraction");
    7421              :       else
    7422            0 :         return error_mark_node;
    7423              :     }
    7424      3107750 :   else if (!verify_type_context (loc, TCTX_POINTER_ARITH,
    7425      1553875 :                                  TREE_TYPE (TREE_TYPE (op0)),
    7426      1553875 :                                  !(complain & tf_error))
    7427      3107750 :            || !verify_type_context (loc, TCTX_POINTER_ARITH,
    7428      1553875 :                                     TREE_TYPE (TREE_TYPE (op1)),
    7429              :                                     !(complain & tf_error)))
    7430            0 :     return error_mark_node;
    7431              : 
    7432              :   /* Determine integer type result of the subtraction.  This will usually
    7433              :      be the same as the result type (ptrdiff_t), but may need to be a wider
    7434              :      type if pointers for the address space are wider than ptrdiff_t.  */
    7435      1553875 :   if (TYPE_PRECISION (restype) < TYPE_PRECISION (TREE_TYPE (op0)))
    7436            0 :     inttype = c_common_type_for_size (TYPE_PRECISION (TREE_TYPE (op0)), 0);
    7437              :   else
    7438              :     inttype = restype;
    7439              : 
    7440      1553875 :   if (!processing_template_decl
    7441      1553875 :       && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
    7442              :     {
    7443           84 :       op0 = save_expr (op0);
    7444           84 :       op1 = save_expr (op1);
    7445              : 
    7446           84 :       tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
    7447           84 :       *instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
    7448              :     }
    7449              : 
    7450              :   /* First do the subtraction, then build the divide operator
    7451              :      and only convert at the very end.
    7452              :      Do not do default conversions in case restype is a short type.  */
    7453              : 
    7454              :   /* POINTER_DIFF_EXPR requires a signed integer type of the same size as
    7455              :      pointers.  If some platform cannot provide that, or has a larger
    7456              :      ptrdiff_type to support differences larger than half the address
    7457              :      space, cast the pointers to some larger integer type and do the
    7458              :      computations in that type.  */
    7459      1553875 :   if (TYPE_PRECISION (inttype) > TYPE_PRECISION (TREE_TYPE (op0)))
    7460            0 :     op0 = cp_build_binary_op (loc,
    7461              :                               MINUS_EXPR,
    7462              :                               cp_convert (inttype, op0, complain),
    7463              :                               cp_convert (inttype, op1, complain),
    7464              :                               complain);
    7465              :   else
    7466      1553875 :     op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1);
    7467              : 
    7468              :   /* This generates an error if op1 is a pointer to an incomplete type.  */
    7469      1553875 :   if (!COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (op1))))
    7470              :     {
    7471            0 :       if (complain & tf_error)
    7472            0 :         error_at (loc, "invalid use of a pointer to an incomplete type in "
    7473              :                   "pointer arithmetic");
    7474              :       else
    7475            0 :         return error_mark_node;
    7476              :     }
    7477              : 
    7478      1553875 :   if (pointer_to_zero_sized_aggr_p (TREE_TYPE (op1)))
    7479              :     {
    7480           15 :       if (complain & tf_error)
    7481           15 :         error_at (loc, "arithmetic on pointer to an empty aggregate");
    7482              :       else
    7483            0 :         return error_mark_node;
    7484              :     }
    7485              : 
    7486      3107747 :   op1 = (TYPE_PTROB_P (ptrtype)
    7487      3107747 :          ? size_in_bytes_loc (loc, target_type)
    7488              :          : integer_one_node);
    7489              : 
    7490              :   /* Do the division.  */
    7491              : 
    7492      1553875 :   result = build2_loc (loc, EXACT_DIV_EXPR, inttype, op0,
    7493              :                        cp_convert (inttype, op1, complain));
    7494      1553875 :   return cp_convert (restype, result, complain);
    7495              : }
    7496              : 
    7497              : /* Construct and perhaps optimize a tree representation
    7498              :    for a unary operation.  CODE, a tree_code, specifies the operation
    7499              :    and XARG is the operand.  */
    7500              : 
    7501              : tree
    7502     65785381 : build_x_unary_op (location_t loc, enum tree_code code, cp_expr xarg,
    7503              :                   tree lookups, tsubst_flags_t complain)
    7504              : {
    7505     65785381 :   tree orig_expr = xarg;
    7506     65785381 :   tree exp;
    7507     65785381 :   int ptrmem = 0;
    7508     65785381 :   tree overload = NULL_TREE;
    7509              : 
    7510     65785381 :   if (processing_template_decl)
    7511              :     {
    7512     44833748 :       if (type_dependent_expression_p (xarg))
    7513              :         {
    7514     29240372 :           tree e = build_min_nt_loc (loc, code, xarg.get_value (), NULL_TREE);
    7515     29240372 :           TREE_TYPE (e) = build_dependent_operator_type (lookups, code, false);
    7516     29240372 :           return e;
    7517              :         }
    7518              :     }
    7519              : 
    7520     36545009 :   exp = NULL_TREE;
    7521              : 
    7522              :   /* [expr.unary.op] says:
    7523              : 
    7524              :        The address of an object of incomplete type can be taken.
    7525              : 
    7526              :      (And is just the ordinary address operator, not an overloaded
    7527              :      "operator &".)  However, if the type is a template
    7528              :      specialization, we must complete the type at this point so that
    7529              :      an overloaded "operator &" will be available if required.  */
    7530     36545009 :   if (code == ADDR_EXPR
    7531      4208693 :       && TREE_CODE (xarg) != TEMPLATE_ID_EXPR
    7532     40752959 :       && ((CLASS_TYPE_P (TREE_TYPE (xarg))
    7533      1846611 :            && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (xarg))))
    7534      4198582 :           || (TREE_CODE (xarg) == OFFSET_REF)))
    7535              :     /* Don't look for a function.  */;
    7536              :   else
    7537     36471612 :     exp = build_new_op (loc, code, LOOKUP_NORMAL, xarg, NULL_TREE,
    7538              :                         NULL_TREE, lookups, &overload, complain);
    7539              : 
    7540     36545009 :   if (!exp && code == ADDR_EXPR)
    7541              :     {
    7542      4208278 :       if (is_overloaded_fn (xarg))
    7543              :         {
    7544       385587 :           tree fn = get_first_fn (xarg);
    7545       771174 :           if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn))
    7546              :             {
    7547           12 :               if (complain & tf_error)
    7548           21 :                 error_at (loc, DECL_CONSTRUCTOR_P (fn)
    7549              :                           ? G_("taking address of constructor %qD")
    7550              :                           : G_("taking address of destructor %qD"),
    7551              :                           fn);
    7552           12 :               return error_mark_node;
    7553              :             }
    7554              :         }
    7555              : 
    7556              :       /* A pointer to member-function can be formed only by saying
    7557              :          &X::mf.  */
    7558      4208260 :       if (!flag_ms_extensions && TREE_CODE (TREE_TYPE (xarg)) == METHOD_TYPE
    7559      4268525 :           && (TREE_CODE (xarg) != OFFSET_REF || !PTRMEM_OK_P (xarg)))
    7560              :         {
    7561            9 :           if (TREE_CODE (xarg) != OFFSET_REF
    7562            9 :               || !TYPE_P (TREE_OPERAND (xarg, 0)))
    7563              :             {
    7564            9 :               if (complain & tf_error)
    7565              :                 {
    7566            9 :                   auto_diagnostic_group d;
    7567            9 :                   error_at (loc, "invalid use of %qE to form a "
    7568              :                             "pointer-to-member-function", xarg.get_value ());
    7569            9 :                   if (TREE_CODE (xarg) != OFFSET_REF)
    7570            6 :                     inform (loc, "  a qualified-id is required");
    7571            9 :                 }
    7572            9 :               return error_mark_node;
    7573              :             }
    7574              :           else
    7575              :             {
    7576            0 :               if (complain & tf_error)
    7577            0 :                 error_at (loc, "parentheses around %qE cannot be used to "
    7578              :                           "form a pointer-to-member-function",
    7579              :                           xarg.get_value ());
    7580              :               else
    7581            0 :                 return error_mark_node;
    7582            0 :               PTRMEM_OK_P (xarg) = 1;
    7583              :             }
    7584              :         }
    7585              : 
    7586      4208257 :       if (TREE_CODE (xarg) == OFFSET_REF)
    7587              :         {
    7588        64014 :           ptrmem = PTRMEM_OK_P (xarg);
    7589              : 
    7590            0 :           if (!ptrmem && !flag_ms_extensions
    7591        64014 :               && TREE_CODE (TREE_TYPE (TREE_OPERAND (xarg, 1))) == METHOD_TYPE)
    7592              :             {
    7593              :               /* A single non-static member, make sure we don't allow a
    7594              :                  pointer-to-member.  */
    7595            0 :               xarg = build2 (OFFSET_REF, TREE_TYPE (xarg),
    7596            0 :                              TREE_OPERAND (xarg, 0),
    7597            0 :                              ovl_make (TREE_OPERAND (xarg, 1)));
    7598            0 :               PTRMEM_OK_P (xarg) = ptrmem;
    7599              :             }
    7600              :         }
    7601              : 
    7602      8416514 :       exp = cp_build_addr_expr_strict (xarg, complain);
    7603              : 
    7604      4208257 :       if (TREE_CODE (exp) == PTRMEM_CST)
    7605        62943 :         PTRMEM_CST_LOCATION (exp) = loc;
    7606              :       else
    7607      4145314 :         protected_set_expr_location (exp, loc);
    7608              :     }
    7609              : 
    7610     36544988 :   if (processing_template_decl && exp != error_mark_node)
    7611              :     {
    7612     15593215 :       if (overload != NULL_TREE)
    7613       192749 :         return (build_min_non_dep_op_overload
    7614       192749 :                 (code, exp, overload, orig_expr, integer_zero_node));
    7615              : 
    7616     15400466 :       exp = build_min_non_dep (code, exp, orig_expr,
    7617              :                                /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
    7618              :     }
    7619     36352239 :   if (TREE_CODE (exp) == ADDR_EXPR)
    7620      3385175 :     PTRMEM_OK_P (exp) = ptrmem;
    7621              :   return exp;
    7622              : }
    7623              : 
    7624              : /* Construct and perhaps optimize a tree representation
    7625              :    for __builtin_addressof operation.  ARG specifies the operand.  */
    7626              : 
    7627              : tree
    7628       697394 : cp_build_addressof (location_t loc, tree arg, tsubst_flags_t complain)
    7629              : {
    7630       697394 :   tree orig_expr = arg;
    7631              : 
    7632       697394 :   if (processing_template_decl)
    7633              :     {
    7634       187682 :       if (type_dependent_expression_p (arg))
    7635       187682 :         return build_min_nt_loc (loc, ADDRESSOF_EXPR, arg, NULL_TREE);
    7636              :     }
    7637              : 
    7638      1019424 :   tree exp = cp_build_addr_expr_strict (arg, complain);
    7639              : 
    7640       509712 :   if (processing_template_decl && exp != error_mark_node)
    7641            0 :     exp = build_min_non_dep (ADDRESSOF_EXPR, exp, orig_expr, NULL_TREE);
    7642              :   return exp;
    7643              : }
    7644              : 
    7645              : /* Like c_common_truthvalue_conversion, but handle pointer-to-member
    7646              :    constants, where a null value is represented by an INTEGER_CST of
    7647              :    -1.  */
    7648              : 
    7649              : tree
    7650      8579445 : cp_truthvalue_conversion (tree expr, tsubst_flags_t complain)
    7651              : {
    7652      8579445 :   tree type = TREE_TYPE (expr);
    7653      8579445 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    7654      7291012 :   if (TYPE_PTR_OR_PTRMEM_P (type)
    7655              :       /* Avoid ICE on invalid use of non-static member function.  */
    7656     15870151 :       || TREE_CODE (expr) == FUNCTION_DECL)
    7657      1288739 :     return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain);
    7658              :   else
    7659      7290706 :     return c_common_truthvalue_conversion (loc, expr);
    7660              : }
    7661              : 
    7662              : /* Returns EXPR contextually converted to bool.  */
    7663              : 
    7664              : tree
    7665     80130722 : contextual_conv_bool (tree expr, tsubst_flags_t complain)
    7666              : {
    7667     80130722 :   return perform_implicit_conversion_flags (boolean_type_node, expr,
    7668     80130722 :                                             complain, LOOKUP_NORMAL);
    7669              : }
    7670              : 
    7671              : /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  This
    7672              :    is a low-level function; most callers should use maybe_convert_cond.  */
    7673              : 
    7674              : tree
    7675     54723357 : condition_conversion (tree expr)
    7676              : {
    7677     54723357 :   tree t = contextual_conv_bool (expr, tf_warning_or_error);
    7678     54723357 :   if (!processing_template_decl)
    7679     27237653 :     t = fold_build_cleanup_point_expr (boolean_type_node, t);
    7680     54723357 :   return t;
    7681              : }
    7682              : 
    7683              : /* Returns the address of T.  This function will fold away
    7684              :    ADDR_EXPR of INDIRECT_REF.  This is only for low-level usage;
    7685              :    most places should use cp_build_addr_expr instead.  */
    7686              : 
    7687              : tree
    7688    361664396 : build_address (tree t)
    7689              : {
    7690    361664396 :   if (error_operand_p (t) || !cxx_mark_addressable (t))
    7691           24 :     return error_mark_node;
    7692    361664372 :   gcc_checking_assert (TREE_CODE (t) != CONSTRUCTOR
    7693              :                        || processing_template_decl);
    7694    361664372 :   t = build_fold_addr_expr_loc (EXPR_LOCATION (t), t);
    7695    361664372 :   if (TREE_CODE (t) != ADDR_EXPR)
    7696     62003102 :     t = rvalue (t);
    7697              :   return t;
    7698              : }
    7699              : 
    7700              : /* Return a NOP_EXPR converting EXPR to TYPE.  */
    7701              : 
    7702              : tree
    7703    592233303 : build_nop (tree type, tree expr MEM_STAT_DECL)
    7704              : {
    7705    592233303 :   if (type == error_mark_node || error_operand_p (expr))
    7706              :     return expr;
    7707    592233229 :   return build1_loc (EXPR_LOCATION (expr), NOP_EXPR, type, expr PASS_MEM_STAT);
    7708              : }
    7709              : 
    7710              : /* Take the address of ARG, whatever that means under C++ semantics.
    7711              :    If STRICT_LVALUE is true, require an lvalue; otherwise, allow xvalues
    7712              :    and class rvalues as well.
    7713              : 
    7714              :    Nothing should call this function directly; instead, callers should use
    7715              :    cp_build_addr_expr or cp_build_addr_expr_strict.  */
    7716              : 
    7717              : static tree
    7718    285612338 : cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
    7719              : {
    7720    285612338 :   tree argtype;
    7721    285612338 :   tree val;
    7722              : 
    7723    285612338 :   if (!arg || error_operand_p (arg))
    7724           12 :     return error_mark_node;
    7725              : 
    7726    285612326 :   arg = mark_lvalue_use (arg);
    7727    285612326 :   if (error_operand_p (arg))
    7728            3 :     return error_mark_node;
    7729              : 
    7730    285612323 :   argtype = lvalue_type (arg);
    7731    285612323 :   location_t loc = cp_expr_loc_or_input_loc (arg);
    7732              : 
    7733    285612323 :   gcc_assert (!(identifier_p (arg) && IDENTIFIER_ANY_OP_P (arg)));
    7734              : 
    7735     16188998 :   if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
    7736    285612551 :       && !really_overloaded_fn (arg))
    7737              :     {
    7738              :       /* They're trying to take the address of a unique non-static
    7739              :          member function.  This is ill-formed (except in MS-land),
    7740              :          but let's try to DTRT.
    7741              :          Note: We only handle unique functions here because we don't
    7742              :          want to complain if there's a static overload; non-unique
    7743              :          cases will be handled by instantiate_type.  But we need to
    7744              :          handle this case here to allow casts on the resulting PMF.
    7745              :          We could defer this in non-MS mode, but it's easier to give
    7746              :          a useful error here.  */
    7747              : 
    7748              :       /* Inside constant member functions, the `this' pointer
    7749              :          contains an extra const qualifier.  TYPE_MAIN_VARIANT
    7750              :          is used here to remove this const from the diagnostics
    7751              :          and the created OFFSET_REF.  */
    7752           87 :       tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
    7753           87 :       tree fn = get_first_fn (TREE_OPERAND (arg, 1));
    7754           87 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7755            0 :         return error_mark_node;
    7756              :       /* Until microsoft headers are known to incorrectly take the address of
    7757              :          unqualified xobj member functions we should not support this
    7758              :          extension.
    7759              :          See comment in class.cc:resolve_address_of_overloaded_function for
    7760              :          the extended reasoning.  */
    7761           87 :       if (!flag_ms_extensions || DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7762              :         {
    7763           81 :           auto_diagnostic_group d;
    7764           81 :           tree name = DECL_NAME (fn);
    7765           81 :           if (!(complain & tf_error))
    7766            0 :             return error_mark_node;
    7767           81 :           else if (current_class_type
    7768           81 :                    && TREE_OPERAND (arg, 0) == current_class_ref)
    7769              :             /* An expression like &memfn.  */
    7770           36 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7771           21 :               permerror (loc,
    7772              :                          "ISO C++ forbids taking the address of an unqualified"
    7773              :                          " or parenthesized non-static member function to form"
    7774              :                          " a pointer to member function.  Say %<&%T::%D%>",
    7775              :                          base, name);
    7776              :             else
    7777           15 :               error_at (loc,
    7778              :                         "ISO C++ forbids taking the address of an unqualified"
    7779              :                         " or parenthesized non-static member function to form"
    7780              :                         " a pointer to explicit object member function");
    7781              :           else
    7782           45 :             if (!DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7783            9 :               permerror (loc,
    7784              :                          "ISO C++ forbids taking the address of a bound member"
    7785              :                          " function to form a pointer to member function."
    7786              :                          "  Say %<&%T::%D%>",
    7787              :                          base, name);
    7788              :             else
    7789           36 :               error_at (loc,
    7790              :                         "ISO C++ forbids taking the address of a bound member"
    7791              :                         " function to form a pointer to explicit object member"
    7792              :                         " function");
    7793           81 :           if (DECL_XOBJ_MEMBER_FUNCTION_P (fn))
    7794           51 :             inform (loc,
    7795              :                     "a pointer to explicit object member function can only be "
    7796              :                     "formed with %<&%T::%D%>", base, name);
    7797           81 :         }
    7798           87 :       arg = build_offset_ref (base, fn, /*address_p=*/true, complain);
    7799              :     }
    7800              : 
    7801              :   /* Uninstantiated types are all functions.  Taking the
    7802              :      address of a function is a no-op, so just return the
    7803              :      argument.  */
    7804    285612323 :   if (type_unknown_p (arg))
    7805         3579 :     return build1 (ADDR_EXPR, unknown_type_node, arg);
    7806              : 
    7807    285608744 :   if (TREE_CODE (arg) == OFFSET_REF)
    7808              :     /* We want a pointer to member; bypass all the code for actually taking
    7809              :        the address of something.  */
    7810        63160 :     goto offset_ref;
    7811              : 
    7812              :   /* Anything not already handled and not a true memory reference
    7813              :      is an error.  */
    7814    285545584 :   if (!FUNC_OR_METHOD_TYPE_P (argtype))
    7815              :     {
    7816    150231383 :       cp_lvalue_kind kind = lvalue_kind (arg);
    7817    150231383 :       if (kind == clk_none)
    7818              :         {
    7819           25 :           if (complain & tf_error)
    7820           25 :             lvalue_error (loc, lv_addressof);
    7821           25 :           return error_mark_node;
    7822              :         }
    7823    150231358 :       if (strict_lvalue && (kind & (clk_rvalueref|clk_class)))
    7824              :         {
    7825           39 :           if (!(complain & tf_error))
    7826           12 :             return error_mark_node;
    7827              :           /* Make this a permerror because we used to accept it.  */
    7828           27 :           permerror (loc, "taking address of rvalue");
    7829              :         }
    7830              :     }
    7831              : 
    7832    285545547 :   if (TYPE_REF_P (argtype))
    7833              :     {
    7834          244 :       tree type = build_pointer_type (TREE_TYPE (argtype));
    7835          244 :       arg = build1 (CONVERT_EXPR, type, arg);
    7836          244 :       return arg;
    7837              :     }
    7838    285545303 :   else if (pedantic && DECL_MAIN_P (tree_strip_any_location_wrapper (arg)))
    7839              :     {
    7840              :       /* ARM $3.4 */
    7841              :       /* Apparently a lot of autoconf scripts for C++ packages do this,
    7842              :          so only complain if -Wpedantic.  */
    7843            9 :       if (complain & (flag_pedantic_errors ? tf_error : tf_warning))
    7844            9 :         pedwarn (loc, OPT_Wpedantic,
    7845              :                  "ISO C++ forbids taking address of function %<::main%>");
    7846            0 :       else if (flag_pedantic_errors)
    7847            0 :         return error_mark_node;
    7848              :     }
    7849              : 
    7850              :   /* Let &* cancel out to simplify resulting code.  */
    7851    285545303 :   if (INDIRECT_REF_P (arg))
    7852              :     {
    7853    102503831 :       arg = TREE_OPERAND (arg, 0);
    7854    102503831 :       if (TYPE_REF_P (TREE_TYPE (arg)))
    7855              :         {
    7856     63108727 :           tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
    7857     63108727 :           arg = build1 (CONVERT_EXPR, type, arg);
    7858              :         }
    7859              :       else
    7860              :         /* Don't let this be an lvalue.  */
    7861     39395104 :         arg = rvalue (arg);
    7862              :       return arg;
    7863              :     }
    7864              : 
    7865              :   /* Handle complex lvalues (when permitted)
    7866              :      by reduction to simpler cases.  */
    7867    183041472 :   val = unary_complex_lvalue (ADDR_EXPR, arg);
    7868    183041472 :   if (val != 0)
    7869              :     return val;
    7870              : 
    7871    182545638 :   switch (TREE_CODE (arg))
    7872              :     {
    7873            0 :     CASE_CONVERT:
    7874            0 :     case FLOAT_EXPR:
    7875            0 :     case FIX_TRUNC_EXPR:
    7876              :       /* We should have handled this above in the lvalue_kind check.  */
    7877            0 :       gcc_unreachable ();
    7878        81692 :       break;
    7879              : 
    7880        81692 :     case BASELINK:
    7881        81692 :       arg = BASELINK_FUNCTIONS (arg);
    7882              :       /* Fall through.  */
    7883              : 
    7884        81692 :     case OVERLOAD:
    7885        81692 :       arg = OVL_FIRST (arg);
    7886              :       break;
    7887              : 
    7888        63160 :     case OFFSET_REF:
    7889        63160 :     offset_ref:
    7890              :       /* Turn a reference to a non-static data member into a
    7891              :          pointer-to-member.  */
    7892        63160 :       {
    7893        63160 :         tree type;
    7894        63160 :         tree t;
    7895              : 
    7896        63160 :         gcc_assert (PTRMEM_OK_P (arg));
    7897              : 
    7898        63160 :         t = TREE_OPERAND (arg, 1);
    7899        63160 :         if (TYPE_REF_P (TREE_TYPE (t)))
    7900              :           {
    7901           15 :             if (complain & tf_error)
    7902           15 :               error_at (loc,
    7903              :                         "cannot create pointer to reference member %qD", t);
    7904           15 :             return error_mark_node;
    7905              :           }
    7906              : 
    7907              :         /* Forming a pointer-to-member is a use of non-pure-virtual fns.  */
    7908        63145 :         if (TREE_CODE (t) == FUNCTION_DECL
    7909        60467 :             && !DECL_PURE_VIRTUAL_P (t)
    7910       123589 :             && !mark_used (t, complain) && !(complain & tf_error))
    7911            3 :           return error_mark_node;
    7912              : 
    7913              :         /* Pull out the function_decl for a single xobj member function, and
    7914              :            let the rest of this function handle it.  This is similar to how
    7915              :            static member functions are handled in the BASELINK case above.  */
    7916        63142 :         if (DECL_XOBJ_MEMBER_FUNCTION_P (t))
    7917              :           {
    7918              :             arg = t;
    7919              :             break;
    7920              :           }
    7921              : 
    7922        63046 :         type = build_ptrmem_type (context_for_name_lookup (t),
    7923        63046 :                                   TREE_TYPE (t));
    7924        63046 :         t = make_ptrmem_cst (type, t);
    7925        63046 :         return t;
    7926              :       }
    7927              : 
    7928              :     default:
    7929              :       break;
    7930              :     }
    7931              : 
    7932    182545734 :   if (argtype != error_mark_node)
    7933    182545734 :     argtype = build_pointer_type (argtype);
    7934              : 
    7935    182545734 :   if (bitfield_p (arg))
    7936              :     {
    7937           33 :       if (complain & tf_error)
    7938           33 :         error_at (loc, "attempt to take address of bit-field");
    7939           33 :       return error_mark_node;
    7940              :     }
    7941              : 
    7942              :   /* In a template, we are processing a non-dependent expression
    7943              :      so we can just form an ADDR_EXPR with the correct type.  */
    7944    182545701 :   if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
    7945              :     {
    7946    166839414 :       if (!mark_single_function (arg, complain))
    7947            3 :         return error_mark_node;
    7948    166839411 :       val = build_address (arg);
    7949    166839411 :       if (TREE_CODE (arg) == OFFSET_REF)
    7950            0 :         PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
    7951              :     }
    7952     15706287 :   else if (BASELINK_P (TREE_OPERAND (arg, 1)))
    7953              :     {
    7954           27 :       tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
    7955              : 
    7956           27 :       if (TREE_CODE (fn) == OVERLOAD && OVL_SINGLE_P (fn))
    7957           27 :         fn = OVL_FIRST (fn);
    7958              : 
    7959              :       /* We can only get here with a single static member
    7960              :          function.  */
    7961           27 :       gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
    7962              :                   && DECL_STATIC_FUNCTION_P (fn));
    7963           27 :       if (!mark_used (fn, complain) && !(complain & tf_error))
    7964            0 :         return error_mark_node;
    7965           27 :       val = build_address (fn);
    7966           27 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
    7967              :         /* Do not lose object's side effects.  */
    7968           12 :         val = build2 (COMPOUND_EXPR, TREE_TYPE (val),
    7969           12 :                       TREE_OPERAND (arg, 0), val);
    7970              :     }
    7971              :   else
    7972              :     {
    7973     15706260 :       tree object = TREE_OPERAND (arg, 0);
    7974     15706260 :       tree field = TREE_OPERAND (arg, 1);
    7975     15706260 :       gcc_assert (same_type_ignoring_top_level_qualifiers_p
    7976              :                   (TREE_TYPE (object), decl_type_context (field)));
    7977     15706260 :       val = build_address (arg);
    7978              :     }
    7979              : 
    7980    182545698 :   if (TYPE_PTR_P (argtype)
    7981    182545698 :       && TREE_CODE (TREE_TYPE (argtype)) == METHOD_TYPE)
    7982              :     {
    7983         1132 :       build_ptrmemfunc_type (argtype);
    7984         1132 :       val = build_ptrmemfunc (argtype, val, 0,
    7985              :                               /*c_cast_p=*/false,
    7986              :                               complain);
    7987              :     }
    7988              : 
    7989              :   /* Ensure we have EXPR_LOCATION set for possible later diagnostics.  */
    7990    182545698 :   if (TREE_CODE (val) == ADDR_EXPR
    7991    182545698 :       && TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
    7992    129679853 :     SET_EXPR_LOCATION (val, input_location);
    7993              : 
    7994              :   return val;
    7995              : }
    7996              : 
    7997              : /* Take the address of ARG if it has one, even if it's an rvalue.  */
    7998              : 
    7999              : tree
    8000    280894369 : cp_build_addr_expr (tree arg, tsubst_flags_t complain)
    8001              : {
    8002    280894369 :   return cp_build_addr_expr_1 (arg, 0, complain);
    8003              : }
    8004              : 
    8005              : /* Take the address of ARG, but only if it's an lvalue.  */
    8006              : 
    8007              : static tree
    8008      4717969 : cp_build_addr_expr_strict (tree arg, tsubst_flags_t complain)
    8009              : {
    8010      4717969 :   return cp_build_addr_expr_1 (arg, 1, complain);
    8011              : }
    8012              : 
    8013              : /* C++: Must handle pointers to members.
    8014              : 
    8015              :    Perhaps type instantiation should be extended to handle conversion
    8016              :    from aggregates to types we don't yet know we want?  (Or are those
    8017              :    cases typically errors which should be reported?)
    8018              : 
    8019              :    NOCONVERT suppresses the default promotions (such as from short to int).  */
    8020              : 
    8021              : tree
    8022     31997742 : cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
    8023              :                    tsubst_flags_t complain)
    8024              : {
    8025              :   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
    8026     31997742 :   tree arg = xarg;
    8027     31997742 :   location_t location = cp_expr_loc_or_input_loc (arg);
    8028     31997742 :   tree argtype = 0;
    8029     31997742 :   tree eptype = NULL_TREE;
    8030     31997742 :   const char *errstring = NULL;
    8031     31997742 :   tree val;
    8032     31997742 :   const char *invalid_op_diag;
    8033              : 
    8034     31997742 :   if (!arg || error_operand_p (arg))
    8035            0 :     return error_mark_node;
    8036              : 
    8037     31997742 :   arg = resolve_nondeduced_context (arg, complain);
    8038              : 
    8039     63995484 :   if ((invalid_op_diag
    8040     31997742 :        = targetm.invalid_unary_op ((code == UNARY_PLUS_EXPR
    8041              :                                     ? CONVERT_EXPR
    8042              :                                     : code),
    8043     31997742 :                                    TREE_TYPE (arg))))
    8044              :     {
    8045            0 :       if (complain & tf_error)
    8046            0 :         error (invalid_op_diag);
    8047            0 :       return error_mark_node;
    8048              :     }
    8049              : 
    8050     31997742 :   if (TREE_CODE (arg) == EXCESS_PRECISION_EXPR)
    8051              :     {
    8052         9712 :       eptype = TREE_TYPE (arg);
    8053         9712 :       arg = TREE_OPERAND (arg, 0);
    8054              :     }
    8055              : 
    8056     31997742 :   switch (code)
    8057              :     {
    8058      2428586 :     case UNARY_PLUS_EXPR:
    8059      2428586 :     case NEGATE_EXPR:
    8060      2428586 :       {
    8061      2428586 :         int flags = WANT_ARITH | WANT_ENUM;
    8062              :         /* Unary plus (but not unary minus) is allowed on pointers.  */
    8063      2428586 :         if (code == UNARY_PLUS_EXPR)
    8064       163260 :           flags |= WANT_POINTER;
    8065      2428586 :         arg = build_expr_type_conversion (flags, arg, true);
    8066      2428586 :         if (!arg)
    8067           35 :           errstring = (code == NEGATE_EXPR
    8068           27 :                        ? _("wrong type argument to unary minus")
    8069            8 :                        : _("wrong type argument to unary plus"));
    8070              :         else
    8071              :           {
    8072      2428551 :             if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    8073       685007 :               arg = cp_perform_integral_promotions (arg, complain);
    8074              : 
    8075              :             /* Make sure the result is not an lvalue: a unary plus or minus
    8076              :                expression is always a rvalue.  */
    8077      2428551 :             arg = rvalue (arg);
    8078              :           }
    8079              :       }
    8080              :       break;
    8081              : 
    8082       963280 :     case BIT_NOT_EXPR:
    8083       963280 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    8084              :         {
    8085           15 :           code = CONJ_EXPR;
    8086           15 :           if (!noconvert)
    8087              :             {
    8088           15 :               arg = cp_default_conversion (arg, complain);
    8089           15 :               if (arg == error_mark_node)
    8090              :                 return error_mark_node;
    8091              :             }
    8092              :         }
    8093       963265 :       else if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM
    8094              :                                                    | WANT_VECTOR_OR_COMPLEX,
    8095              :                                                    arg, true)))
    8096           20 :         errstring = _("wrong type argument to bit-complement");
    8097       963245 :       else if (!noconvert && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
    8098              :         {
    8099              :           /* Warn if the expression has boolean value.  */
    8100       962744 :           if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
    8101       962744 :               && (complain & tf_warning))
    8102              :             {
    8103           61 :               auto_diagnostic_group d;
    8104           61 :               if (warning_at (location, OPT_Wbool_operation,
    8105              :                               "%<~%> on an expression of type %<bool%>"))
    8106           42 :                 inform (location, "did you mean to use logical not (%<!%>)?");
    8107           61 :             }
    8108       962744 :           arg = cp_perform_integral_promotions (arg, complain);
    8109              :         }
    8110          501 :       else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
    8111          501 :         arg = mark_rvalue_use (arg);
    8112              :       break;
    8113              : 
    8114            0 :     case ABS_EXPR:
    8115            0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    8116            0 :         errstring = _("wrong type argument to abs");
    8117            0 :       else if (!noconvert)
    8118              :         {
    8119            0 :           arg = cp_default_conversion (arg, complain);
    8120            0 :           if (arg == error_mark_node)
    8121              :             return error_mark_node;
    8122              :         }
    8123              :       break;
    8124              : 
    8125            0 :     case CONJ_EXPR:
    8126              :       /* Conjugating a real value is a no-op, but allow it anyway.  */
    8127            0 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, true)))
    8128            0 :         errstring = _("wrong type argument to conjugation");
    8129            0 :       else if (!noconvert)
    8130              :         {
    8131            0 :           arg = cp_default_conversion (arg, complain);
    8132            0 :           if (arg == error_mark_node)
    8133              :             return error_mark_node;
    8134              :         }
    8135              :       break;
    8136              : 
    8137     18794220 :     case TRUTH_NOT_EXPR:
    8138     18794220 :       if (gnu_vector_type_p (TREE_TYPE (arg)))
    8139           60 :         return cp_build_binary_op (input_location, EQ_EXPR, arg,
    8140           60 :                                    build_zero_cst (TREE_TYPE (arg)), complain);
    8141     18794160 :       arg = contextual_conv_bool (arg, complain);
    8142     18794160 :       if (arg != error_mark_node)
    8143              :         {
    8144     18794150 :           if (processing_template_decl)
    8145      8828783 :             return build1_loc (location, TRUTH_NOT_EXPR, boolean_type_node, arg);
    8146      9965367 :           val = invert_truthvalue_loc (location, arg);
    8147      9965367 :           if (obvalue_p (val))
    8148        12278 :             val = non_lvalue_loc (location, val);
    8149              :           return val;
    8150              :         }
    8151           10 :       errstring = _("in argument to unary !");
    8152           10 :       break;
    8153              : 
    8154              :     case NOP_EXPR:
    8155              :       break;
    8156              : 
    8157       453983 :     case REALPART_EXPR:
    8158       453983 :     case IMAGPART_EXPR:
    8159       453983 :       val = build_real_imag_expr (input_location, code, arg);
    8160       453983 :       if (eptype && TREE_CODE (eptype) == COMPLEX_EXPR)
    8161            0 :         val = build1_loc (input_location, EXCESS_PRECISION_EXPR,
    8162            0 :                           TREE_TYPE (eptype), val);
    8163              :       return val;
    8164              : 
    8165      8770782 :     case PREINCREMENT_EXPR:
    8166      8770782 :     case POSTINCREMENT_EXPR:
    8167      8770782 :     case PREDECREMENT_EXPR:
    8168      8770782 :     case POSTDECREMENT_EXPR:
    8169              :       /* Handle complex lvalues (when permitted)
    8170              :          by reduction to simpler cases.  */
    8171              : 
    8172      8770782 :       val = unary_complex_lvalue (code, arg);
    8173      8770782 :       if (val != 0)
    8174           42 :         goto return_build_unary_op;
    8175              : 
    8176      8770740 :       tree stripped_arg;
    8177      8770740 :       stripped_arg = tree_strip_any_location_wrapper (arg);
    8178      2184503 :       if ((VAR_P (stripped_arg) || TREE_CODE (stripped_arg) == PARM_DECL)
    8179      8127000 :           && !DECL_READ_P (stripped_arg)
    8180      9928841 :           && (VAR_P (stripped_arg) ? warn_unused_but_set_variable
    8181              :                                    : warn_unused_but_set_parameter) > 1)
    8182              :         {
    8183         9851 :           arg = mark_lvalue_use (arg);
    8184         9851 :           DECL_READ_P (stripped_arg) = 0;
    8185              :         }
    8186              :       else
    8187      8760889 :         arg = mark_lvalue_use (arg);
    8188              : 
    8189              :       /* Increment or decrement the real part of the value,
    8190              :          and don't change the imaginary part.  */
    8191      8770740 :       if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
    8192              :         {
    8193           18 :           tree real, imag;
    8194              : 
    8195           18 :           arg = cp_stabilize_reference (arg);
    8196           18 :           real = cp_build_unary_op (REALPART_EXPR, arg, true, complain);
    8197           18 :           imag = cp_build_unary_op (IMAGPART_EXPR, arg, true, complain);
    8198           18 :           real = cp_build_unary_op (code, real, true, complain);
    8199           18 :           if (real == error_mark_node || imag == error_mark_node)
    8200              :             return error_mark_node;
    8201           15 :           val = build2 (COMPLEX_EXPR, TREE_TYPE (arg), real, imag);
    8202           15 :           goto return_build_unary_op;
    8203              :         }
    8204              : 
    8205              :       /* Report invalid types.  */
    8206              : 
    8207      8770722 :       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
    8208              :                                               arg, true)))
    8209              :         {
    8210           36 :           if (code == PREINCREMENT_EXPR)
    8211            9 :             errstring = _("no pre-increment operator for type");
    8212           27 :           else if (code == POSTINCREMENT_EXPR)
    8213            9 :             errstring = _("no post-increment operator for type");
    8214           18 :           else if (code == PREDECREMENT_EXPR)
    8215            9 :             errstring = _("no pre-decrement operator for type");
    8216              :           else
    8217            9 :             errstring = _("no post-decrement operator for type");
    8218              :           break;
    8219              :         }
    8220      8770686 :       else if (arg == error_mark_node)
    8221              :         return error_mark_node;
    8222              : 
    8223              :       /* Report something read-only.  */
    8224              : 
    8225      8770683 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg))
    8226      8770683 :           || TREE_READONLY (arg))
    8227              :         {
    8228          176 :           if (complain & tf_error)
    8229          176 :             cxx_readonly_error (location, arg,
    8230          176 :                                 ((code == PREINCREMENT_EXPR
    8231          176 :                                   || code == POSTINCREMENT_EXPR)
    8232              :                                  ? lv_increment : lv_decrement));
    8233              :           else
    8234            0 :             return error_mark_node;
    8235              :         }
    8236              : 
    8237      8770683 :       {
    8238      8770683 :         tree inc;
    8239      8770683 :         tree declared_type = unlowered_expr_type (arg);
    8240              : 
    8241      8770683 :         argtype = TREE_TYPE (arg);
    8242              : 
    8243              :         /* ARM $5.2.5 last annotation says this should be forbidden.  */
    8244      8770683 :         if (TREE_CODE (argtype) == ENUMERAL_TYPE)
    8245              :           {
    8246            0 :             if (complain & tf_error)
    8247            0 :               permerror (location, (code == PREINCREMENT_EXPR
    8248            0 :                                     || code == POSTINCREMENT_EXPR)
    8249              :                          ? G_("ISO C++ forbids incrementing an enum")
    8250              :                          : G_("ISO C++ forbids decrementing an enum"));
    8251              :             else
    8252            0 :               return error_mark_node;
    8253              :           }
    8254              : 
    8255              :         /* Compute the increment.  */
    8256              : 
    8257      8770683 :         if (TYPE_PTR_P (argtype))
    8258              :           {
    8259      2811946 :             tree type = complete_type (TREE_TYPE (argtype));
    8260              : 
    8261      2811946 :             if (!COMPLETE_OR_VOID_TYPE_P (type))
    8262              :               {
    8263           10 :                 if (complain & tf_error)
    8264            9 :                   error_at (location, ((code == PREINCREMENT_EXPR
    8265            9 :                                         || code == POSTINCREMENT_EXPR))
    8266              :                             ? G_("cannot increment a pointer to incomplete "
    8267              :                                  "type %qT")
    8268              :                             : G_("cannot decrement a pointer to incomplete "
    8269              :                                  "type %qT"),
    8270            9 :                             TREE_TYPE (argtype));
    8271              :                 else
    8272            1 :                   return error_mark_node;
    8273              :               }
    8274      2811936 :             else if (!TYPE_PTROB_P (argtype))
    8275              :               {
    8276           69 :                 if (complain & tf_error)
    8277           63 :                   pedwarn (location, OPT_Wpointer_arith,
    8278           63 :                            (code == PREINCREMENT_EXPR
    8279           63 :                               || code == POSTINCREMENT_EXPR)
    8280              :                            ? G_("ISO C++ forbids incrementing a pointer "
    8281              :                                 "of type %qT")
    8282              :                            : G_("ISO C++ forbids decrementing a pointer "
    8283              :                                 "of type %qT"),
    8284              :                            argtype);
    8285              :                 else
    8286            6 :                   return error_mark_node;
    8287              :               }
    8288      2811867 :             else if (!verify_type_context (location, TCTX_POINTER_ARITH,
    8289      2811867 :                                            TREE_TYPE (argtype),
    8290      2811867 :                                            !(complain & tf_error)))
    8291            0 :               return error_mark_node;
    8292              : 
    8293      2811939 :             inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
    8294              :           }
    8295              :         else
    8296      5958594 :           inc = VECTOR_TYPE_P (argtype)
    8297      5958737 :             ? build_one_cst (argtype)
    8298              :             : integer_one_node;
    8299              : 
    8300      8770676 :         inc = cp_convert (argtype, inc, complain);
    8301              : 
    8302              :         /* If 'arg' is an Objective-C PROPERTY_REF expression, then we
    8303              :            need to ask Objective-C to build the increment or decrement
    8304              :            expression for it.  */
    8305      8770676 :         if (objc_is_property_ref (arg))
    8306            0 :           return objc_build_incr_expr_for_property_ref (input_location, code,
    8307            0 :                                                         arg, inc);
    8308              : 
    8309              :         /* Complain about anything else that is not a true lvalue.  */
    8310      8770676 :         if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
    8311      8770676 :                                     || code == POSTINCREMENT_EXPR)
    8312              :                                    ? lv_increment : lv_decrement),
    8313              :                              complain))
    8314           38 :           return error_mark_node;
    8315              : 
    8316              :         /* [depr.volatile.type] "Postfix ++ and -- expressions and
    8317              :            prefix ++ and -- expressions of volatile-qualified arithmetic
    8318              :            and pointer types are deprecated."  */
    8319      8770353 :         if ((TREE_THIS_VOLATILE (arg) || CP_TYPE_VOLATILE_P (TREE_TYPE (arg)))
    8320      8770638 :             && (complain & tf_warning))
    8321          398 :           warning_at (location, OPT_Wvolatile,
    8322              :                       "%qs expression of %<volatile%>-qualified type is "
    8323              :                       "deprecated",
    8324              :                       ((code == PREINCREMENT_EXPR
    8325              :                         || code == POSTINCREMENT_EXPR)
    8326              :                        ? "++" : "--"));
    8327              : 
    8328              :         /* Forbid using -- or ++ in C++17 on `bool'.  */
    8329      8770638 :         if (TREE_CODE (declared_type) == BOOLEAN_TYPE)
    8330              :           {
    8331           95 :             if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
    8332              :               {
    8333           33 :                 if (complain & tf_error)
    8334           33 :                   error_at (location,
    8335              :                             "use of an operand of type %qT in %<operator--%> "
    8336              :                             "is forbidden", boolean_type_node);
    8337           33 :                 return error_mark_node;
    8338              :               }
    8339              :             else
    8340              :               {
    8341           62 :                 if (cxx_dialect >= cxx17)
    8342              :                   {
    8343           33 :                     if (complain & tf_error)
    8344           32 :                       error_at (location,
    8345              :                                 "use of an operand of type %qT in "
    8346              :                                 "%<operator++%> is forbidden in C++17",
    8347              :                                 boolean_type_node);
    8348           33 :                     return error_mark_node;
    8349              :                   }
    8350              :                 /* Otherwise, [depr.incr.bool] says this is deprecated.  */
    8351           29 :                 else if (complain & tf_warning)
    8352           25 :                   warning_at (location, OPT_Wdeprecated,
    8353              :                               "use of an operand of type %qT "
    8354              :                               "in %<operator++%> is deprecated",
    8355              :                               boolean_type_node);
    8356              :               }
    8357           29 :             val = boolean_increment (code, arg);
    8358              :           }
    8359      8770543 :         else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
    8360              :           /* An rvalue has no cv-qualifiers.  */
    8361      1418251 :           val = build2 (code, cv_unqualified (TREE_TYPE (arg)), arg, inc);
    8362              :         else
    8363      7352292 :           val = build2 (code, TREE_TYPE (arg), arg, inc);
    8364              : 
    8365      8770572 :         TREE_SIDE_EFFECTS (val) = 1;
    8366      8770572 :         goto return_build_unary_op;
    8367              :       }
    8368              : 
    8369       586891 :     case ADDR_EXPR:
    8370              :       /* Note that this operation never does default_conversion
    8371              :          regardless of NOCONVERT.  */
    8372       586891 :       return cp_build_addr_expr (arg, complain);
    8373              : 
    8374              :     default:
    8375              :       break;
    8376              :     }
    8377              : 
    8378      3391897 :   if (!errstring)
    8379              :     {
    8380      3391811 :       if (argtype == 0)
    8381      3391811 :         argtype = TREE_TYPE (arg);
    8382      3391811 :       val = build1 (code, argtype, arg);
    8383     12162440 :     return_build_unary_op:
    8384     12162440 :       if (eptype)
    8385         9703 :         val = build1 (EXCESS_PRECISION_EXPR, eptype, val);
    8386              :       return val;
    8387              :     }
    8388              : 
    8389          101 :   if (complain & tf_error)
    8390           54 :     error_at (location, "%s", errstring);
    8391          101 :   return error_mark_node;
    8392              : }
    8393              : 
    8394              : /* Hook for the c-common bits that build a unary op.  */
    8395              : tree
    8396         4147 : build_unary_op (location_t /*location*/,
    8397              :                 enum tree_code code, tree xarg, bool noconvert)
    8398              : {
    8399         4147 :   return cp_build_unary_op (code, xarg, noconvert, tf_warning_or_error);
    8400              : }
    8401              : 
    8402              : /* Adjust LVALUE, an MODIFY_EXPR, PREINCREMENT_EXPR or PREDECREMENT_EXPR,
    8403              :    so that it is a valid lvalue even for GENERIC by replacing
    8404              :    (lhs = rhs) with ((lhs = rhs), lhs)
    8405              :    (--lhs) with ((--lhs), lhs)
    8406              :    (++lhs) with ((++lhs), lhs)
    8407              :    and if lhs has side-effects, calling cp_stabilize_reference on it, so
    8408              :    that it can be evaluated multiple times.  */
    8409              : 
    8410              : tree
    8411       407202 : genericize_compound_lvalue (tree lvalue)
    8412              : {
    8413       407202 :   if (TREE_SIDE_EFFECTS (TREE_OPERAND (lvalue, 0)))
    8414          203 :     lvalue = build2 (TREE_CODE (lvalue), TREE_TYPE (lvalue),
    8415          203 :                      cp_stabilize_reference (TREE_OPERAND (lvalue, 0)),
    8416          203 :                      TREE_OPERAND (lvalue, 1));
    8417       407202 :   return build2 (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (lvalue, 0)),
    8418       407202 :                  lvalue, TREE_OPERAND (lvalue, 0));
    8419              : }
    8420              : 
    8421              : /* Apply unary lvalue-demanding operator CODE to the expression ARG
    8422              :    for certain kinds of expressions which are not really lvalues
    8423              :    but which we can accept as lvalues.
    8424              : 
    8425              :    If ARG is not a kind of expression we can handle, return
    8426              :    NULL_TREE.  */
    8427              : 
    8428              : tree
    8429    324696050 : unary_complex_lvalue (enum tree_code code, tree arg)
    8430              : {
    8431              :   /* Inside a template, making these kinds of adjustments is
    8432              :      pointless; we are only concerned with the type of the
    8433              :      expression.  */
    8434    325103022 :   if (processing_template_decl)
    8435              :     return NULL_TREE;
    8436              : 
    8437              :   /* Handle (a, b) used as an "lvalue".  */
    8438    234513725 :   if (TREE_CODE (arg) == COMPOUND_EXPR)
    8439              :     {
    8440       408675 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 1), false,
    8441              :                                             tf_warning_or_error);
    8442       408675 :       return build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    8443       817350 :                      TREE_OPERAND (arg, 0), real_result);
    8444              :     }
    8445              : 
    8446              :   /* Handle (a ? b : c) used as an "lvalue".  */
    8447    234105050 :   if (TREE_CODE (arg) == COND_EXPR
    8448    234017831 :       || TREE_CODE (arg) == MIN_EXPR || TREE_CODE (arg) == MAX_EXPR)
    8449        87219 :     return rationalize_conditional_expr (code, arg, tf_warning_or_error);
    8450              : 
    8451              :   /* Handle (a = b), (++a), and (--a) used as an "lvalue".  */
    8452    234017831 :   if (TREE_CODE (arg) == MODIFY_EXPR
    8453    233610984 :       || TREE_CODE (arg) == PREINCREMENT_EXPR
    8454    233610920 :       || TREE_CODE (arg) == PREDECREMENT_EXPR)
    8455       406972 :     return unary_complex_lvalue (code, genericize_compound_lvalue (arg));
    8456              : 
    8457    233610859 :   if (code != ADDR_EXPR)
    8458              :     return NULL_TREE;
    8459              : 
    8460              :   /* Handle (a = b) used as an "lvalue" for `&'.  */
    8461    229633916 :   if (TREE_CODE (arg) == MODIFY_EXPR
    8462    229633916 :       || TREE_CODE (arg) == INIT_EXPR)
    8463              :     {
    8464            0 :       tree real_result = cp_build_unary_op (code, TREE_OPERAND (arg, 0), false,
    8465              :                                             tf_warning_or_error);
    8466            0 :       arg = build2 (COMPOUND_EXPR, TREE_TYPE (real_result),
    8467              :                     arg, real_result);
    8468            0 :       suppress_warning (arg /* What warning? */);
    8469            0 :       return arg;
    8470              :     }
    8471              : 
    8472    351785474 :   if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (arg))
    8473    351784363 :       || TREE_CODE (arg) == OFFSET_REF)
    8474              :     return NULL_TREE;
    8475              : 
    8476              :   /* We permit compiler to make function calls returning
    8477              :      objects of aggregate type look like lvalues.  */
    8478    122150447 :   {
    8479    122150447 :     tree targ = arg;
    8480              : 
    8481    122150447 :     if (TREE_CODE (targ) == SAVE_EXPR)
    8482            0 :       targ = TREE_OPERAND (targ, 0);
    8483              : 
    8484    122150447 :     if (TREE_CODE (targ) == CALL_EXPR && MAYBE_CLASS_TYPE_P (TREE_TYPE (targ)))
    8485              :       {
    8486           26 :         if (TREE_CODE (arg) == SAVE_EXPR)
    8487              :           targ = arg;
    8488              :         else
    8489           26 :           targ = build_cplus_new (TREE_TYPE (arg), arg, tf_warning_or_error);
    8490           26 :         return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
    8491              :       }
    8492              : 
    8493    122150421 :     if (TREE_CODE (arg) == SAVE_EXPR && INDIRECT_REF_P (targ))
    8494            0 :       return build3 (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
    8495            0 :                      TREE_OPERAND (targ, 0), current_function_decl, NULL);
    8496              :   }
    8497              : 
    8498              :   /* Don't let anything else be handled specially.  */
    8499              :   return NULL_TREE;
    8500              : }
    8501              : 
    8502              : /* Mark EXP saying that we need to be able to take the
    8503              :    address of it; it should not be allocated in a register.
    8504              :    Value is true if successful.  ARRAY_REF_P is true if this
    8505              :    is for ARRAY_REF construction - in that case we don't want
    8506              :    to look through VIEW_CONVERT_EXPR from VECTOR_TYPE to ARRAY_TYPE,
    8507              :    it is fine to use ARRAY_REFs for vector subscripts on vector
    8508              :    register variables.
    8509              : 
    8510              :    C++: we do not allow `current_class_ptr' to be addressable.  */
    8511              : 
    8512              : bool
    8513    381278625 : cxx_mark_addressable (tree exp, bool array_ref_p)
    8514              : {
    8515    381278625 :   tree x = exp;
    8516              : 
    8517    445855868 :   while (1)
    8518    445855868 :     switch (TREE_CODE (x))
    8519              :       {
    8520     32693316 :       case VIEW_CONVERT_EXPR:
    8521     32693316 :         if (array_ref_p
    8522       808590 :             && TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
    8523     33306415 :             && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))))
    8524              :           return true;
    8525     32690049 :         x = TREE_OPERAND (x, 0);
    8526     32690049 :         break;
    8527              : 
    8528     31412196 :       case COMPONENT_REF:
    8529     31412196 :         if (bitfield_p (x))
    8530            9 :           error ("attempt to take address of bit-field");
    8531              :         /* FALLTHRU */
    8532     31887194 :       case ADDR_EXPR:
    8533     31887194 :       case ARRAY_REF:
    8534     31887194 :       case REALPART_EXPR:
    8535     31887194 :       case IMAGPART_EXPR:
    8536     31887194 :         x = TREE_OPERAND (x, 0);
    8537     31887194 :         break;
    8538              : 
    8539      8451844 :       case PARM_DECL:
    8540      8451844 :         if (x == current_class_ptr)
    8541              :           {
    8542           18 :             error ("cannot take the address of %<this%>, which is an rvalue expression");
    8543           18 :             TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later.  */
    8544           18 :             return true;
    8545              :           }
    8546              :         /* Fall through.  */
    8547              : 
    8548     78204866 :       case VAR_DECL:
    8549              :         /* Caller should not be trying to mark initialized
    8550              :            constant fields addressable.  */
    8551     78204866 :         gcc_assert (DECL_LANG_SPECIFIC (x) == 0
    8552              :                     || DECL_IN_AGGR_P (x) == 0
    8553              :                     || TREE_STATIC (x)
    8554              :                     || DECL_EXTERNAL (x));
    8555     78204866 :         if (VAR_P (x)
    8556     69753040 :             && DECL_ANON_UNION_VAR_P (x)
    8557     78205015 :             && !TREE_ADDRESSABLE (x))
    8558           51 :           cxx_mark_addressable (DECL_VALUE_EXPR (x));
    8559              :         /* Fall through.  */
    8560              : 
    8561     79074600 :       case RESULT_DECL:
    8562     79074730 :         if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
    8563     79074721 :             && !DECL_ARTIFICIAL (x))
    8564              :           {
    8565           31 :             if (VAR_P (x) && DECL_HARD_REGISTER (x))
    8566              :               {
    8567           15 :                 error
    8568           15 :                   ("address of explicit register variable %qD requested", x);
    8569           15 :                 return false;
    8570              :               }
    8571           16 :             else if (extra_warnings)
    8572            3 :               warning
    8573            3 :                 (OPT_Wextra, "address requested for %qD, which is declared %<register%>", x);
    8574              :           }
    8575     79074585 :         TREE_ADDRESSABLE (x) = 1;
    8576     79074585 :         return true;
    8577              : 
    8578    186490440 :       case CONST_DECL:
    8579    186490440 :       case FUNCTION_DECL:
    8580    186490440 :         TREE_ADDRESSABLE (x) = 1;
    8581    186490440 :         return true;
    8582              : 
    8583        55659 :       case CONSTRUCTOR:
    8584        55659 :         TREE_ADDRESSABLE (x) = 1;
    8585        55659 :         return true;
    8586              : 
    8587     17513766 :       case TARGET_EXPR:
    8588     17513766 :         TREE_ADDRESSABLE (x) = 1;
    8589     17513766 :         cxx_mark_addressable (TARGET_EXPR_SLOT (x));
    8590     17513766 :         return true;
    8591              : 
    8592              :       default:
    8593              :         return true;
    8594              :     }
    8595              : }
    8596              : 
    8597              : /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
    8598              : 
    8599              : tree
    8600      9945464 : build_x_conditional_expr (location_t loc, tree ifexp, tree op1, tree op2,
    8601              :                           tsubst_flags_t complain)
    8602              : {
    8603      9945464 :   tree orig_ifexp = ifexp;
    8604      9945464 :   tree orig_op1 = op1;
    8605      9945464 :   tree orig_op2 = op2;
    8606      9945464 :   tree expr;
    8607              : 
    8608      9945464 :   if (processing_template_decl)
    8609              :     {
    8610              :       /* The standard says that the expression is type-dependent if
    8611              :          IFEXP is type-dependent, even though the eventual type of the
    8612              :          expression doesn't dependent on IFEXP.  */
    8613      3607153 :       if (type_dependent_expression_p (ifexp)
    8614              :           /* As a GNU extension, the middle operand may be omitted.  */
    8615      2009367 :           || (op1 && type_dependent_expression_p (op1))
    8616      5128373 :           || type_dependent_expression_p (op2))
    8617      2112809 :         return build_min_nt_loc (loc, COND_EXPR, ifexp, op1, op2);
    8618              :     }
    8619              : 
    8620      7832655 :   expr = build_conditional_expr (loc, ifexp, op1, op2, complain);
    8621      7832655 :   if (processing_template_decl && expr != error_mark_node)
    8622              :     {
    8623      1494338 :       tree min = build_min_non_dep (COND_EXPR, expr,
    8624              :                                     orig_ifexp, orig_op1, orig_op2);
    8625      1494338 :       expr = convert_from_reference (min);
    8626              :     }
    8627              :   return expr;
    8628              : }
    8629              : 
    8630              : /* Given a list of expressions, return a compound expression
    8631              :    that performs them all and returns the value of the last of them.  */
    8632              : 
    8633              : tree
    8634     32596577 : build_x_compound_expr_from_list (tree list, expr_list_kind exp,
    8635              :                                  tsubst_flags_t complain)
    8636              : {
    8637     32596577 :   tree expr = TREE_VALUE (list);
    8638              : 
    8639       487686 :   if (BRACE_ENCLOSED_INITIALIZER_P (expr)
    8640     33084251 :       && !CONSTRUCTOR_IS_DIRECT_INIT (expr))
    8641              :     {
    8642           14 :       if (complain & tf_error)
    8643           28 :         pedwarn (cp_expr_loc_or_input_loc (expr), 0,
    8644              :                  "list-initializer for non-class type must not "
    8645              :                  "be parenthesized");
    8646              :       else
    8647            0 :         return error_mark_node;
    8648              :     }
    8649              : 
    8650     32596577 :   if (TREE_CHAIN (list))
    8651              :     {
    8652           23 :       if (complain & tf_error)
    8653           14 :         switch (exp)
    8654              :           {
    8655           12 :           case ELK_INIT:
    8656           12 :             permerror (input_location, "expression list treated as compound "
    8657              :                                        "expression in initializer");
    8658           12 :             break;
    8659            1 :           case ELK_MEM_INIT:
    8660            1 :             permerror (input_location, "expression list treated as compound "
    8661              :                                        "expression in mem-initializer");
    8662            1 :             break;
    8663            1 :           case ELK_FUNC_CAST:
    8664            1 :             permerror (input_location, "expression list treated as compound "
    8665              :                                        "expression in functional cast");
    8666            1 :             break;
    8667            0 :           default:
    8668            0 :             gcc_unreachable ();
    8669              :           }
    8670              :       else
    8671            9 :         return error_mark_node;
    8672              : 
    8673           28 :       for (list = TREE_CHAIN (list); list; list = TREE_CHAIN (list))
    8674           28 :         expr = build_x_compound_expr (EXPR_LOCATION (TREE_VALUE (list)),
    8675           14 :                                       expr, TREE_VALUE (list), NULL_TREE,
    8676              :                                       complain);
    8677              :     }
    8678              : 
    8679              :   return expr;
    8680              : }
    8681              : 
    8682              : /* Like build_x_compound_expr_from_list, but using a VEC.  */
    8683              : 
    8684              : tree
    8685       409944 : build_x_compound_expr_from_vec (vec<tree, va_gc> *vec, const char *msg,
    8686              :                                 tsubst_flags_t complain)
    8687              : {
    8688       409944 :   if (vec_safe_is_empty (vec))
    8689              :     return NULL_TREE;
    8690       409944 :   else if (vec->length () == 1)
    8691       409880 :     return (*vec)[0];
    8692              :   else
    8693              :     {
    8694           64 :       tree expr;
    8695           64 :       unsigned int ix;
    8696           64 :       tree t;
    8697              : 
    8698           64 :       if (msg != NULL)
    8699              :         {
    8700            4 :           if (complain & tf_error)
    8701            0 :             permerror (input_location,
    8702              :                        "%s expression list treated as compound expression",
    8703              :                        msg);
    8704              :           else
    8705            4 :             return error_mark_node;
    8706              :         }
    8707              : 
    8708           60 :       expr = (*vec)[0];
    8709          134 :       for (ix = 1; vec->iterate (ix, &t); ++ix)
    8710           74 :         expr = build_x_compound_expr (EXPR_LOCATION (t), expr,
    8711              :                                       t, NULL_TREE, complain);
    8712              : 
    8713              :       return expr;
    8714              :     }
    8715              : }
    8716              : 
    8717              : /* Handle overloading of the ',' operator when needed.  */
    8718              : 
    8719              : tree
    8720      3218118 : build_x_compound_expr (location_t loc, tree op1, tree op2,
    8721              :                        tree lookups, tsubst_flags_t complain)
    8722              : {
    8723      3218118 :   tree result;
    8724      3218118 :   tree orig_op1 = op1;
    8725      3218118 :   tree orig_op2 = op2;
    8726      3218118 :   tree overload = NULL_TREE;
    8727              : 
    8728      3218118 :   if (processing_template_decl)
    8729              :     {
    8730      2947025 :       if (type_dependent_expression_p (op1)
    8731      2947025 :           || type_dependent_expression_p (op2))
    8732              :         {
    8733      2674878 :           result = build_min_nt_loc (loc, COMPOUND_EXPR, op1, op2);
    8734      2674878 :           TREE_TYPE (result)
    8735      2674878 :             = build_dependent_operator_type (lookups, COMPOUND_EXPR, false);
    8736      2674878 :           return result;
    8737              :         }
    8738              :     }
    8739              : 
    8740       543240 :   result = build_new_op (loc, COMPOUND_EXPR, LOOKUP_NORMAL, op1, op2,
    8741              :                          NULL_TREE, lookups, &overload, complain);
    8742       543240 :   if (!result)
    8743       534619 :     result = cp_build_compound_expr (op1, op2, complain);
    8744              : 
    8745       543240 :   if (processing_template_decl && result != error_mark_node)
    8746              :     {
    8747       270326 :       if (overload != NULL_TREE)
    8748           72 :         return (build_min_non_dep_op_overload
    8749           72 :                 (COMPOUND_EXPR, result, overload, orig_op1, orig_op2));
    8750              : 
    8751       270254 :       return build_min_non_dep (COMPOUND_EXPR, result, orig_op1, orig_op2);
    8752              :     }
    8753              : 
    8754              :   return result;
    8755              : }
    8756              : 
    8757              : /* Like cp_build_compound_expr, but for the c-common bits.  */
    8758              : 
    8759              : tree
    8760        22108 : build_compound_expr (location_t /*loc*/, tree lhs, tree rhs)
    8761              : {
    8762        22108 :   return cp_build_compound_expr (lhs, rhs, tf_warning_or_error);
    8763              : }
    8764              : 
    8765              : /* Build a compound expression.  */
    8766              : 
    8767              : tree
    8768       699016 : cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
    8769              : {
    8770       699016 :   lhs = convert_to_void (lhs, ICV_LEFT_OF_COMMA, complain);
    8771              : 
    8772       699016 :   if (lhs == error_mark_node || rhs == error_mark_node)
    8773              :     return error_mark_node;
    8774              : 
    8775       699013 :   if (TREE_CODE (lhs) == EXCESS_PRECISION_EXPR)
    8776            0 :     lhs = TREE_OPERAND (lhs, 0);
    8777       699013 :   tree eptype = NULL_TREE;
    8778       699013 :   if (TREE_CODE (rhs) == EXCESS_PRECISION_EXPR)
    8779              :     {
    8780            3 :       eptype = TREE_TYPE (rhs);
    8781            3 :       rhs = TREE_OPERAND (rhs, 0);
    8782              :     }
    8783              : 
    8784       699013 :   if (TREE_CODE (rhs) == TARGET_EXPR)
    8785              :     {
    8786              :       /* If the rhs is a TARGET_EXPR, then build the compound
    8787              :          expression inside the target_expr's initializer. This
    8788              :          helps the compiler to eliminate unnecessary temporaries.  */
    8789        31443 :       tree init = TARGET_EXPR_INITIAL (rhs);
    8790              : 
    8791        31443 :       init = build2 (COMPOUND_EXPR, TREE_TYPE (init), lhs, init);
    8792        31443 :       TARGET_EXPR_INITIAL (rhs) = init;
    8793              : 
    8794        31443 :       if (eptype)
    8795            0 :         rhs = build1 (EXCESS_PRECISION_EXPR, eptype, rhs);
    8796              :       return rhs;
    8797              :     }
    8798              : 
    8799       667570 :   rhs = resolve_nondeduced_context (rhs, complain);
    8800              : 
    8801       667570 :   if (type_unknown_p (rhs))
    8802              :     {
    8803           33 :       if (complain & tf_error)
    8804           51 :         error_at (cp_expr_loc_or_input_loc (rhs),
    8805              :                   "no context to resolve type of %qE", rhs);
    8806           33 :       return error_mark_node;
    8807              :     }
    8808              : 
    8809       667537 :   tree ret = build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
    8810       667537 :   if (eptype)
    8811            3 :     ret = build1 (EXCESS_PRECISION_EXPR, eptype, ret);
    8812              :   return ret;
    8813              : }
    8814              : 
    8815              : /* Issue a diagnostic message if casting from SRC_TYPE to DEST_TYPE
    8816              :    casts away constness.  CAST gives the type of cast.  Returns true
    8817              :    if the cast is ill-formed, false if it is well-formed.
    8818              : 
    8819              :    ??? This function warns for casting away any qualifier not just
    8820              :    const.  We would like to specify exactly what qualifiers are casted
    8821              :    away.
    8822              : */
    8823              : 
    8824              : static bool
    8825       869026 : check_for_casting_away_constness (location_t loc, tree src_type,
    8826              :                                   tree dest_type, enum tree_code cast,
    8827              :                                   tsubst_flags_t complain)
    8828              : {
    8829              :   /* C-style casts are allowed to cast away constness.  With
    8830              :      WARN_CAST_QUAL, we still want to issue a warning.  */
    8831       869026 :   if (cast == CAST_EXPR && !warn_cast_qual)
    8832              :     return false;
    8833              : 
    8834       654075 :   if (!casts_away_constness (src_type, dest_type, complain))
    8835              :     return false;
    8836              : 
    8837          402 :   switch (cast)
    8838              :     {
    8839          345 :     case CAST_EXPR:
    8840          345 :       if (complain & tf_warning)
    8841          345 :         warning_at (loc, OPT_Wcast_qual,
    8842              :                     "cast from type %qT to type %qT casts away qualifiers",
    8843              :                     src_type, dest_type);
    8844              :       return false;
    8845              : 
    8846           36 :     case STATIC_CAST_EXPR:
    8847           36 :       if (complain & tf_error)
    8848           24 :         error_at (loc, "%<static_cast%> from type %qT to type %qT casts "
    8849              :                   "away qualifiers",
    8850              :                   src_type, dest_type);
    8851              :       return true;
    8852              : 
    8853           21 :     case REINTERPRET_CAST_EXPR:
    8854           21 :       if (complain & tf_error)
    8855           15 :         error_at (loc, "%<reinterpret_cast%> from type %qT to type %qT "
    8856              :                   "casts away qualifiers",
    8857              :                   src_type, dest_type);
    8858              :       return true;
    8859              : 
    8860            0 :     default:
    8861            0 :       gcc_unreachable();
    8862              :     }
    8863              : }
    8864              : 
    8865              : /* Warns if the cast from expression EXPR to type TYPE is useless.  */
    8866              : void
    8867     52003053 : maybe_warn_about_useless_cast (location_t loc, tree type, tree expr,
    8868              :                                tsubst_flags_t complain)
    8869              : {
    8870     52003053 :   if (warn_useless_cast
    8871          152 :       && complain & tf_warning)
    8872              :     {
    8873          152 :       if (TYPE_REF_P (type)
    8874          152 :           ? ((TYPE_REF_IS_RVALUE (type)
    8875           86 :               ? xvalue_p (expr) : lvalue_p (expr))
    8876          172 :              && same_type_p (TREE_TYPE (expr), TREE_TYPE (type)))
    8877              :           /* Don't warn when converting a class object to a non-reference type,
    8878              :              because that's a common way to create a temporary.  */
    8879           66 :           : (!glvalue_p (expr) && same_type_p (TREE_TYPE (expr), type)))
    8880           96 :         warning_at (loc, OPT_Wuseless_cast,
    8881              :                     "useless cast to type %q#T", type);
    8882              :     }
    8883     52003053 : }
    8884              : 
    8885              : /* Warns if the cast ignores cv-qualifiers on TYPE.  */
    8886              : static void
    8887     51995962 : maybe_warn_about_cast_ignoring_quals (location_t loc, tree type,
    8888              :                                       tsubst_flags_t complain)
    8889              : {
    8890     51995962 :   if (warn_ignored_qualifiers
    8891       276779 :       && complain & tf_warning
    8892       276274 :       && !CLASS_TYPE_P (type)
    8893     52266882 :       && (cp_type_quals (type) & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)))
    8894           63 :     warning_at (loc, OPT_Wignored_qualifiers,
    8895              :                 "type qualifiers ignored on cast result type");
    8896     51995962 : }
    8897              : 
    8898              : /* Convert EXPR (an expression with pointer-to-member type) to TYPE
    8899              :    (another pointer-to-member type in the same hierarchy) and return
    8900              :    the converted expression.  If ALLOW_INVERSE_P is permitted, a
    8901              :    pointer-to-derived may be converted to pointer-to-base; otherwise,
    8902              :    only the other direction is permitted.  If C_CAST_P is true, this
    8903              :    conversion is taking place as part of a C-style cast.  */
    8904              : 
    8905              : tree
    8906        28950 : convert_ptrmem (tree type, tree expr, bool allow_inverse_p,
    8907              :                 bool c_cast_p, tsubst_flags_t complain)
    8908              : {
    8909        28950 :   if (same_type_p (type, TREE_TYPE (expr)))
    8910              :     return expr;
    8911              : 
    8912        28950 :   if (TYPE_PTRDATAMEM_P (type))
    8913              :     {
    8914          418 :       tree obase = TYPE_PTRMEM_CLASS_TYPE (TREE_TYPE (expr));
    8915          418 :       tree nbase = TYPE_PTRMEM_CLASS_TYPE (type);
    8916          418 :       tree delta = (get_delta_difference
    8917          418 :                     (obase, nbase,
    8918              :                      allow_inverse_p, c_cast_p, complain));
    8919              : 
    8920          418 :       if (delta == error_mark_node)
    8921              :         return error_mark_node;
    8922              : 
    8923          412 :       if (!same_type_p (obase, nbase))
    8924              :         {
    8925          299 :           if (TREE_CODE (expr) == PTRMEM_CST)
    8926          157 :             expr = cplus_expand_constant (expr);
    8927              : 
    8928          299 :           tree cond = cp_build_binary_op (input_location, EQ_EXPR, expr,
    8929          299 :                                           build_int_cst (TREE_TYPE (expr), -1),
    8930              :                                           complain);
    8931          299 :           tree op1 = build_nop (ptrdiff_type_node, expr);
    8932          299 :           tree op2 = cp_build_binary_op (input_location, PLUS_EXPR, op1, delta,
    8933              :                                          complain);
    8934              : 
    8935          299 :           expr = fold_build3_loc (input_location,
    8936              :                                   COND_EXPR, ptrdiff_type_node, cond, op1, op2);
    8937              :         }
    8938              : 
    8939          412 :       return build_nop (type, expr);
    8940              :     }
    8941              :   else
    8942        28532 :     return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr,
    8943        28532 :                              allow_inverse_p, c_cast_p, complain);
    8944              : }
    8945              : 
    8946              : /* Perform a static_cast from EXPR to TYPE.  When C_CAST_P is true,
    8947              :    this static_cast is being attempted as one of the possible casts
    8948              :    allowed by a C-style cast.  (In that case, accessibility of base
    8949              :    classes is not considered, and it is OK to cast away
    8950              :    constness.)  Return the result of the cast.  *VALID_P is set to
    8951              :    indicate whether or not the cast was valid.  */
    8952              : 
    8953              : static tree
    8954     51453394 : build_static_cast_1 (location_t loc, tree type, tree expr, bool c_cast_p,
    8955              :                      bool *valid_p, tsubst_flags_t complain)
    8956              : {
    8957     51453394 :   tree intype;
    8958     51453394 :   tree result;
    8959     51453394 :   cp_lvalue_kind clk;
    8960              : 
    8961              :   /* Assume the cast is valid.  */
    8962     51453394 :   *valid_p = true;
    8963              : 
    8964     51453394 :   intype = unlowered_expr_type (expr);
    8965              : 
    8966              :   /* Save casted types in the function's used types hash table.  */
    8967     51453394 :   used_types_insert (type);
    8968              : 
    8969              :   /* A prvalue of non-class type is cv-unqualified.  */
    8970     51453394 :   if (!CLASS_TYPE_P (type))
    8971     48230177 :     type = cv_unqualified (type);
    8972              : 
    8973              :   /* [expr.static.cast]
    8974              : 
    8975              :      An lvalue of type "cv1 B", where B is a class type, can be cast
    8976              :      to type "reference to cv2 D", where D is a class derived (clause
    8977              :      _class.derived_) from B, if a valid standard conversion from
    8978              :      "pointer to D" to "pointer to B" exists (_conv.ptr_), cv2 is the
    8979              :      same cv-qualification as, or greater cv-qualification than, cv1,
    8980              :      and B is not a virtual base class of D.  */
    8981              :   /* We check this case before checking the validity of "TYPE t =
    8982              :      EXPR;" below because for this case:
    8983              : 
    8984              :        struct B {};
    8985              :        struct D : public B { D(const B&); };
    8986              :        extern B& b;
    8987              :        void f() { static_cast<const D&>(b); }
    8988              : 
    8989              :      we want to avoid constructing a new D.  The standard is not
    8990              :      completely clear about this issue, but our interpretation is
    8991              :      consistent with other compilers.  */
    8992     51453394 :   if (TYPE_REF_P (type)
    8993      5798298 :       && CLASS_TYPE_P (TREE_TYPE (type))
    8994      3803844 :       && CLASS_TYPE_P (intype)
    8995      3803827 :       && (TYPE_REF_IS_RVALUE (type) || lvalue_p (expr))
    8996      3790691 :       && DERIVED_FROM_P (intype, TREE_TYPE (type))
    8997      3768258 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT (intype)),
    8998      3768258 :                       build_pointer_type (TYPE_MAIN_VARIANT
    8999              :                                           (TREE_TYPE (type))),
    9000              :                       complain)
    9001     55221652 :       && (c_cast_p
    9002      3768234 :           || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    9003              :     {
    9004      3768258 :       tree base;
    9005              : 
    9006      3768258 :       if (processing_template_decl)
    9007              :         return expr;
    9008              : 
    9009              :       /* There is a standard conversion from "D*" to "B*" even if "B"
    9010              :          is ambiguous or inaccessible.  If this is really a
    9011              :          static_cast, then we check both for inaccessibility and
    9012              :          ambiguity.  However, if this is a static_cast being performed
    9013              :          because the user wrote a C-style cast, then accessibility is
    9014              :          not considered.  */
    9015      7059000 :       base = lookup_base (TREE_TYPE (type), intype,
    9016              :                           c_cast_p ? ba_unique : ba_check,
    9017              :                           NULL, complain);
    9018      3529512 :       expr = cp_build_addr_expr (expr, complain);
    9019              : 
    9020      3529512 :       if (sanitize_flags_p (SANITIZE_VPTR))
    9021              :         {
    9022          507 :           tree ubsan_check
    9023          507 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    9024              :                                                   intype, expr);
    9025          507 :           if (ubsan_check)
    9026      3529512 :             expr = ubsan_check;
    9027              :         }
    9028              : 
    9029              :       /* Convert from "B*" to "D*".  This function will check that "B"
    9030              :          is not a virtual base of "D".  Even if we don't have a guarantee
    9031              :          that expr is NULL, if the static_cast is to a reference type,
    9032              :          it is UB if it would be NULL, so omit the non-NULL check.  */
    9033      3529512 :       expr = build_base_path (MINUS_EXPR, expr, base,
    9034              :                               /*nonnull=*/flag_delete_null_pointer_checks,
    9035              :                               complain);
    9036              : 
    9037              :       /* Convert the pointer to a reference -- but then remember that
    9038              :          there are no expressions with reference type in C++.
    9039              : 
    9040              :          We call rvalue so that there's an actual tree code
    9041              :          (NON_LVALUE_EXPR) for the static_cast; otherwise, if the operand
    9042              :          is a variable with the same type, the conversion would get folded
    9043              :          away, leaving just the variable and causing lvalue_kind to give
    9044              :          the wrong answer.  */
    9045      3529512 :       expr = cp_fold_convert (type, expr);
    9046              : 
    9047              :       /* When -fsanitize=null, make sure to diagnose reference binding to
    9048              :          NULL even when the reference is converted to pointer later on.  */
    9049      3529512 :       if (sanitize_flags_p (SANITIZE_NULL)
    9050          513 :           && TREE_CODE (expr) == COND_EXPR
    9051            6 :           && TREE_OPERAND (expr, 2)
    9052            6 :           && TREE_CODE (TREE_OPERAND (expr, 2)) == INTEGER_CST
    9053      3529518 :           && TREE_TYPE (TREE_OPERAND (expr, 2)) == type)
    9054            6 :         ubsan_maybe_instrument_reference (&TREE_OPERAND (expr, 2));
    9055              : 
    9056      3529512 :       return convert_from_reference (rvalue (expr));
    9057              :     }
    9058              : 
    9059              :   /* "A glvalue of type cv1 T1 can be cast to type rvalue reference to
    9060              :      cv2 T2 if cv2 T2 is reference-compatible with cv1 T1 (8.5.3)."  */
    9061     47685136 :   if (TYPE_REF_P (type)
    9062      2030040 :       && TYPE_REF_IS_RVALUE (type)
    9063       857774 :       && (clk = real_lvalue_p (expr))
    9064       845822 :       && reference_compatible_p (TREE_TYPE (type), intype)
    9065     48530951 :       && (c_cast_p || at_least_as_qualified_p (TREE_TYPE (type), intype)))
    9066              :     {
    9067       845815 :       if (processing_template_decl)
    9068              :         return expr;
    9069       845050 :       if (clk == clk_ordinary)
    9070              :         {
    9071              :           /* Handle the (non-bit-field) lvalue case here by casting to
    9072              :              lvalue reference and then changing it to an rvalue reference.
    9073              :              Casting an xvalue to rvalue reference will be handled by the
    9074              :              main code path.  */
    9075       845047 :           tree lref = cp_build_reference_type (TREE_TYPE (type), false);
    9076       845047 :           result = (perform_direct_initialization_if_possible
    9077       845047 :                     (lref, expr, c_cast_p, complain));
    9078       845047 :           result = build1 (NON_LVALUE_EXPR, type, result);
    9079       845047 :           return convert_from_reference (result);
    9080              :         }
    9081              :       else
    9082              :         /* For a bit-field or packed field, bind to a temporary.  */
    9083            3 :         expr = rvalue (expr);
    9084              :     }
    9085              : 
    9086              :   /* Resolve overloaded address here rather than once in
    9087              :      implicit_conversion and again in the inverse code below.  */
    9088     46839324 :   if (TYPE_PTRMEMFUNC_P (type) && type_unknown_p (expr))
    9089              :     {
    9090           21 :       expr = instantiate_type (type, expr, complain);
    9091           21 :       intype = TREE_TYPE (expr);
    9092              :     }
    9093              : 
    9094              :   /* [expr.static.cast]
    9095              : 
    9096              :      Any expression can be explicitly converted to type cv void.  */
    9097     46839324 :   if (VOID_TYPE_P (type))
    9098              :     {
    9099       612148 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9100            0 :         expr = TREE_OPERAND (expr, 0);
    9101       612148 :       return convert_to_void (expr, ICV_CAST, complain);
    9102              :     }
    9103              : 
    9104              :   /* [class.abstract]
    9105              :      An abstract class shall not be used ... as the type of an explicit
    9106              :      conversion.  */
    9107     46227176 :   if (abstract_virtuals_error (ACU_CAST, type, complain))
    9108            6 :     return error_mark_node;
    9109              : 
    9110              :   /* [expr.static.cast]
    9111              : 
    9112              :      An expression e can be explicitly converted to a type T using a
    9113              :      static_cast of the form static_cast<T>(e) if the declaration T
    9114              :      t(e);" is well-formed, for some invented temporary variable
    9115              :      t.  */
    9116     46227170 :   result = perform_direct_initialization_if_possible (type, expr,
    9117              :                                                       c_cast_p, complain);
    9118              :   /* P1975 allows static_cast<Aggr>(42), as well as static_cast<T[5]>(42),
    9119              :      which initialize the first element of the aggregate.  We need to handle
    9120              :      the array case specifically.  */
    9121     46227170 :   if (result == NULL_TREE
    9122      4751306 :       && cxx_dialect >= cxx20
    9123      3375575 :       && TREE_CODE (type) == ARRAY_TYPE)
    9124              :     {
    9125              :       /* Create { EXPR } and perform direct-initialization from it.  */
    9126           15 :       tree e = build_constructor_single (init_list_type_node, NULL_TREE, expr);
    9127           15 :       CONSTRUCTOR_IS_DIRECT_INIT (e) = true;
    9128           15 :       CONSTRUCTOR_IS_PAREN_INIT (e) = true;
    9129           15 :       result = perform_direct_initialization_if_possible (type, e, c_cast_p,
    9130              :                                                           complain);
    9131              :     }
    9132      4751306 :   if (result)
    9133              :     {
    9134     41475879 :       if (processing_template_decl)
    9135              :         return expr;
    9136              : 
    9137     40769703 :       result = convert_from_reference (result);
    9138              : 
    9139              :       /* [expr.static.cast]
    9140              : 
    9141              :          If T is a reference type, the result is an lvalue; otherwise,
    9142              :          the result is an rvalue.  */
    9143     40769703 :       if (!TYPE_REF_P (type))
    9144              :         {
    9145     39585572 :           result = rvalue (result);
    9146              : 
    9147     39585572 :           if (result == expr && SCALAR_TYPE_P (type))
    9148              :             /* Leave some record of the cast.  */
    9149      2454652 :             result = build_nop (type, expr);
    9150              :         }
    9151              :       return result;
    9152              :     }
    9153              : 
    9154              :   /* [expr.static.cast]
    9155              : 
    9156              :      The inverse of any standard conversion sequence (clause _conv_),
    9157              :      other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer
    9158              :      (_conv.array_), function-to-pointer (_conv.func_), and boolean
    9159              :      (_conv.bool_) conversions, can be performed explicitly using
    9160              :      static_cast subject to the restriction that the explicit
    9161              :      conversion does not cast away constness (_expr.const.cast_), and
    9162              :      the following additional rules for specific cases:  */
    9163              :   /* For reference, the conversions not excluded are: integral
    9164              :      promotions, floating-point promotion, integral conversions,
    9165              :      floating-point conversions, floating-integral conversions,
    9166              :      pointer conversions, and pointer to member conversions.  */
    9167              :   /* DR 128
    9168              : 
    9169              :      A value of integral _or enumeration_ type can be explicitly
    9170              :      converted to an enumeration type.  */
    9171              :   /* The effect of all that is that any conversion between any two
    9172              :      types which are integral, floating, or enumeration types can be
    9173              :      performed.  */
    9174      4751291 :   if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    9175      2634057 :        || SCALAR_FLOAT_TYPE_P (type))
    9176      2238671 :       && (INTEGRAL_OR_ENUMERATION_TYPE_P (intype)
    9177       222399 :           || SCALAR_FLOAT_TYPE_P (intype)))
    9178              :     {
    9179      2137616 :       if (processing_template_decl)
    9180              :         return expr;
    9181      2045425 :       if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    9182            0 :         expr = TREE_OPERAND (expr, 0);
    9183              :       /* [expr.static.cast]: "If the value is not a bit-field, the result
    9184              :          refers to the object or the specified base class subobject thereof;
    9185              :          otherwise, the lvalue-to-rvalue conversion is applied to the
    9186              :          bit-field and the resulting prvalue is used as the operand of the
    9187              :          static_cast."  There are no prvalue bit-fields; the l-to-r conversion
    9188              :          will give us an object of the underlying type of the bit-field.  */
    9189      2045425 :       expr = decay_conversion (expr, complain);
    9190      2045425 :       return ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL, complain);
    9191              :     }
    9192              : 
    9193       808363 :   if (TYPE_PTR_P (type) && TYPE_PTR_P (intype)
    9194       803708 :       && CLASS_TYPE_P (TREE_TYPE (type))
    9195       189505 :       && CLASS_TYPE_P (TREE_TYPE (intype))
    9196      2648918 :       && can_convert (build_pointer_type (TYPE_MAIN_VARIANT
    9197              :                                           (TREE_TYPE (intype))),
    9198        35243 :                       build_pointer_type (TYPE_MAIN_VARIANT
    9199              :                                           (TREE_TYPE (type))),
    9200              :                       complain))
    9201              :     {
    9202        34903 :       tree base;
    9203              : 
    9204        34903 :       if (processing_template_decl)
    9205              :         return expr;
    9206              : 
    9207        34885 :       if (!c_cast_p
    9208        34885 :           && check_for_casting_away_constness (loc, intype, type,
    9209              :                                                STATIC_CAST_EXPR,
    9210              :                                                complain))
    9211            6 :         return error_mark_node;
    9212        69216 :       base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
    9213              :                           c_cast_p ? ba_unique : ba_check,
    9214              :                           NULL, complain);
    9215        34879 :       expr = build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false,
    9216              :                               complain);
    9217              : 
    9218        34879 :       if (sanitize_flags_p (SANITIZE_VPTR))
    9219              :         {
    9220           43 :           tree ubsan_check
    9221           43 :             = cp_ubsan_maybe_instrument_downcast (loc, type,
    9222              :                                                   intype, expr);
    9223           43 :           if (ubsan_check)
    9224        34879 :             expr = ubsan_check;
    9225              :         }
    9226              : 
    9227        34879 :       return cp_fold_convert (type, expr);
    9228              :     }
    9229              : 
    9230           89 :   if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    9231      2578772 :       || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
    9232              :     {
    9233          232 :       tree c1;
    9234          232 :       tree c2;
    9235          232 :       tree t1;
    9236          232 :       tree t2;
    9237              : 
    9238          232 :       c1 = TYPE_PTRMEM_CLASS_TYPE (intype);
    9239          232 :       c2 = TYPE_PTRMEM_CLASS_TYPE (type);
    9240              : 
    9241          232 :       if (TYPE_PTRDATAMEM_P (type))
    9242              :         {
    9243           89 :           t1 = (build_ptrmem_type
    9244           89 :                 (c1,
    9245           89 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (intype))));
    9246           89 :           t2 = (build_ptrmem_type
    9247           89 :                 (c2,
    9248           89 :                  TYPE_MAIN_VARIANT (TYPE_PTRMEM_POINTED_TO_TYPE (type))));
    9249              :         }
    9250              :       else
    9251              :         {
    9252              :           t1 = intype;
    9253              :           t2 = type;
    9254              :         }
    9255          232 :       if (can_convert (t1, t2, complain) || can_convert (t2, t1, complain))
    9256              :         {
    9257          154 :           if (!c_cast_p
    9258          154 :               && check_for_casting_away_constness (loc, intype, type,
    9259              :                                                    STATIC_CAST_EXPR,
    9260              :                                                    complain))
    9261            9 :             return error_mark_node;
    9262          145 :           if (processing_template_decl)
    9263              :             return expr;
    9264          145 :           return convert_ptrmem (type, expr, /*allow_inverse_p=*/1,
    9265          145 :                                  c_cast_p, complain);
    9266              :         }
    9267              :     }
    9268              : 
    9269              :   /* [expr.static.cast]
    9270              : 
    9271              :      An rvalue of type "pointer to cv void" can be explicitly
    9272              :      converted to a pointer to object type.  A value of type pointer
    9273              :      to object converted to "pointer to cv void" and back to the
    9274              :      original pointer type will have its original value.  */
    9275      2578618 :   if (TYPE_PTR_P (intype)
    9276       867541 :       && VOID_TYPE_P (TREE_TYPE (intype))
    9277      3310785 :       && TYPE_PTROB_P (type))
    9278              :     {
    9279       699881 :       if (!c_cast_p
    9280       699881 :           && check_for_casting_away_constness (loc, intype, type,
    9281              :                                                STATIC_CAST_EXPR,
    9282              :                                                complain))
    9283           21 :         return error_mark_node;
    9284       699860 :       if (processing_template_decl)
    9285              :         return expr;
    9286       615141 :       return build_nop (type, expr);
    9287              :     }
    9288              : 
    9289      1878737 :   *valid_p = false;
    9290      1878737 :   return error_mark_node;
    9291              : }
    9292              : 
    9293              : /* Return an expression representing static_cast<TYPE>(EXPR).  */
    9294              : 
    9295              : tree
    9296     17632481 : build_static_cast (location_t loc, tree type, tree oexpr,
    9297              :                    tsubst_flags_t complain)
    9298              : {
    9299     17632481 :   tree expr = oexpr;
    9300     17632481 :   tree result;
    9301     17632481 :   bool valid_p;
    9302              : 
    9303     17632481 :   if (type == error_mark_node || expr == error_mark_node)
    9304              :     return error_mark_node;
    9305              : 
    9306     17632229 :   bool dependent = (dependent_type_p (type)
    9307     17632229 :                     || type_dependent_expression_p (expr));
    9308     12287439 :   if (dependent)
    9309              :     {
    9310      6467442 :     tmpl:
    9311      6467442 :       expr = build_min (STATIC_CAST_EXPR, type, oexpr);
    9312              :       /* We don't know if it will or will not have side effects.  */
    9313      6467442 :       TREE_SIDE_EFFECTS (expr) = 1;
    9314      6467442 :       result = convert_from_reference (expr);
    9315      6467442 :       protected_set_expr_location (result, loc);
    9316      6467442 :       return result;
    9317              :     }
    9318              : 
    9319              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9320              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9321     12287439 :   if (!TYPE_REF_P (type)
    9322      6490603 :       && TREE_CODE (expr) == NOP_EXPR
    9323     12398629 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9324           92 :     expr = TREE_OPERAND (expr, 0);
    9325              : 
    9326     12287439 :   result = build_static_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    9327              :                                 &valid_p, complain);
    9328     12287439 :   if (valid_p)
    9329              :     {
    9330     12287138 :       if (result != error_mark_node)
    9331              :         {
    9332     12287021 :           maybe_warn_about_useless_cast (loc, type, expr, complain);
    9333     12287021 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9334              :         }
    9335     12287138 :       if (processing_template_decl)
    9336      1122652 :         goto tmpl;
    9337     11164486 :       protected_set_expr_location (result, loc);
    9338     11164486 :       return result;
    9339              :     }
    9340              : 
    9341          301 :   if (complain & tf_error)
    9342              :     {
    9343          172 :       auto_diagnostic_group d;
    9344          172 :       error_at (loc, "invalid %<static_cast%> from type %qT to type %qT",
    9345          172 :                 TREE_TYPE (expr), type);
    9346          172 :       if ((TYPE_PTR_P (type) || TYPE_REF_P (type))
    9347          130 :           && CLASS_TYPE_P (TREE_TYPE (type))
    9348          201 :             && !COMPLETE_TYPE_P (TREE_TYPE (type)))
    9349           17 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (TREE_TYPE (type))),
    9350           17 :                 "class type %qT is incomplete", TREE_TYPE (type));
    9351          172 :       tree expr_type = TREE_TYPE (expr);
    9352          172 :       if (TYPE_PTR_P (expr_type))
    9353           44 :         expr_type = TREE_TYPE (expr_type);
    9354          172 :       if (CLASS_TYPE_P (expr_type) && !COMPLETE_TYPE_P (expr_type))
    9355           12 :         inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (expr_type)),
    9356              :                 "class type %qT is incomplete", expr_type);
    9357          172 :     }
    9358          301 :   return error_mark_node;
    9359              : }
    9360              : 
    9361              : /* EXPR is an expression with member function or pointer-to-member
    9362              :    function type.  TYPE is a pointer type.  Converting EXPR to TYPE is
    9363              :    not permitted by ISO C++, but we accept it in some modes.  If we
    9364              :    are not in one of those modes, issue a diagnostic.  Return the
    9365              :    converted expression.  */
    9366              : 
    9367              : tree
    9368          169 : convert_member_func_to_ptr (tree type, tree expr, tsubst_flags_t complain)
    9369              : {
    9370          169 :   tree intype;
    9371          169 :   tree decl;
    9372              : 
    9373          169 :   intype = TREE_TYPE (expr);
    9374          169 :   gcc_assert (TYPE_PTRMEMFUNC_P (intype)
    9375              :               || TREE_CODE (intype) == METHOD_TYPE);
    9376              : 
    9377          169 :   if (!(complain & tf_warning_or_error))
    9378            0 :     return error_mark_node;
    9379              : 
    9380          169 :   location_t loc = cp_expr_loc_or_input_loc (expr);
    9381              : 
    9382          169 :   if (pedantic || warn_pmf2ptr)
    9383          215 :     pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpmf_conversions,
    9384              :              "converting from %qH to %qI", intype, type);
    9385              : 
    9386          169 :   STRIP_ANY_LOCATION_WRAPPER (expr);
    9387              : 
    9388          169 :   if (TREE_CODE (intype) == METHOD_TYPE)
    9389           74 :     expr = build_addr_func (expr, complain);
    9390           95 :   else if (TREE_CODE (expr) == PTRMEM_CST)
    9391           77 :     expr = build_address (PTRMEM_CST_MEMBER (expr));
    9392              :   else
    9393              :     {
    9394           18 :       decl = maybe_dummy_object (TYPE_PTRMEM_CLASS_TYPE (intype), 0);
    9395           18 :       decl = build_address (decl);
    9396           18 :       expr = get_member_function_from_ptrfunc (&decl, expr, complain);
    9397              :     }
    9398              : 
    9399          169 :   if (expr == error_mark_node)
    9400              :     return error_mark_node;
    9401              : 
    9402          169 :   expr = build_nop (type, expr);
    9403          169 :   SET_EXPR_LOCATION (expr, loc);
    9404          169 :   return expr;
    9405              : }
    9406              : 
    9407              : /* Build a NOP_EXPR to TYPE, but mark it as a reinterpret_cast so that
    9408              :    constexpr evaluation knows to reject it.  */
    9409              : 
    9410              : static tree
    9411       114562 : build_nop_reinterpret (tree type, tree expr)
    9412              : {
    9413       114562 :   tree ret = build_nop (type, expr);
    9414       114562 :   if (ret != expr)
    9415       114562 :     REINTERPRET_CAST_P (ret) = true;
    9416       114562 :   return ret;
    9417              : }
    9418              : 
    9419              : /* Return a representation for a reinterpret_cast from EXPR to TYPE.
    9420              :    If C_CAST_P is true, this reinterpret cast is being done as part of
    9421              :    a C-style cast.  If VALID_P is non-NULL, *VALID_P is set to
    9422              :    indicate whether or not reinterpret_cast was valid.  */
    9423              : 
    9424              : static tree
    9425      2032754 : build_reinterpret_cast_1 (location_t loc, tree type, tree expr,
    9426              :                           bool c_cast_p, bool *valid_p,
    9427              :                           tsubst_flags_t complain)
    9428              : {
    9429      2032754 :   tree intype;
    9430              : 
    9431              :   /* Assume the cast is invalid.  */
    9432      2032754 :   if (valid_p)
    9433      1878492 :     *valid_p = true;
    9434              : 
    9435      2032754 :   if (type == error_mark_node || error_operand_p (expr))
    9436              :     return error_mark_node;
    9437              : 
    9438      2032754 :   intype = TREE_TYPE (expr);
    9439              : 
    9440              :   /* Save casted types in the function's used types hash table.  */
    9441      2032754 :   used_types_insert (type);
    9442              : 
    9443              :   /* A prvalue of non-class type is cv-unqualified.  */
    9444      2032754 :   if (!CLASS_TYPE_P (type))
    9445      2032745 :     type = cv_unqualified (type);
    9446              : 
    9447              :   /* [expr.reinterpret.cast]
    9448              :      A glvalue of type T1, designating an object x, can be cast to the type
    9449              :      "reference to T2" if an expression of type "pointer to T1" can be
    9450              :      explicitly converted to the type "pointer to T2" using a reinterpret_cast.
    9451              :      The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x
    9452              :      of type "pointer to T1". No temporary is created, no copy is made, and no
    9453              :      constructors (11.4.4) or conversion functions (11.4.7) are called.  */
    9454      2032754 :   if (TYPE_REF_P (type))
    9455              :     {
    9456         9817 :       if (!glvalue_p (expr))
    9457              :         {
    9458            9 :           if (complain & tf_error)
    9459            9 :             error_at (loc, "invalid cast of a prvalue expression of type "
    9460              :                       "%qT to type %qT",
    9461              :                       intype, type);
    9462            9 :           return error_mark_node;
    9463              :         }
    9464              : 
    9465              :       /* Warn about a reinterpret_cast from "A*" to "B&" if "A" and
    9466              :          "B" are related class types; the reinterpret_cast does not
    9467              :          adjust the pointer.  */
    9468         9808 :       if (TYPE_PTR_P (intype)
    9469            3 :           && (complain & tf_warning)
    9470         9811 :           && (comptypes (TREE_TYPE (intype), TREE_TYPE (type),
    9471              :                          COMPARE_BASE | COMPARE_DERIVED)))
    9472            3 :         warning_at (loc, 0, "casting %qT to %qT does not dereference pointer",
    9473              :                     intype, type);
    9474              : 
    9475         9808 :       expr = cp_build_addr_expr (expr, complain);
    9476              : 
    9477         9808 :       if (warn_strict_aliasing > 2)
    9478           72 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    9479              : 
    9480         9808 :       if (expr != error_mark_node)
    9481         9808 :         expr = build_reinterpret_cast_1
    9482         9808 :           (loc, build_pointer_type (TREE_TYPE (type)), expr, c_cast_p,
    9483              :            valid_p, complain);
    9484         9808 :       if (expr != error_mark_node)
    9485              :         /* cp_build_indirect_ref isn't right for rvalue refs.  */
    9486         9805 :         expr = convert_from_reference (fold_convert (type, expr));
    9487              :       return expr;
    9488              :     }
    9489              : 
    9490              :   /* As a G++ extension, we consider conversions from member
    9491              :      functions, and pointers to member functions to
    9492              :      pointer-to-function and pointer-to-void types.  If
    9493              :      -Wno-pmf-conversions has not been specified,
    9494              :      convert_member_func_to_ptr will issue an error message.  */
    9495          252 :   if ((TYPE_PTRMEMFUNC_P (intype)
    9496      2022763 :        || TREE_CODE (intype) == METHOD_TYPE)
    9497          248 :       && TYPE_PTR_P (type)
    9498      2023106 :       && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
    9499          127 :           || VOID_TYPE_P (TREE_TYPE (type))))
    9500          160 :     return convert_member_func_to_ptr (type, expr, complain);
    9501              : 
    9502              :   /* If the cast is not to a reference type, the lvalue-to-rvalue,
    9503              :      array-to-pointer, and function-to-pointer conversions are
    9504              :      performed.  */
    9505      2022777 :   expr = decay_conversion (expr, complain);
    9506              : 
    9507              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9508              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9509      2022777 :   if (TREE_CODE (expr) == NOP_EXPR
    9510      2022777 :       && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9511          388 :     expr = TREE_OPERAND (expr, 0);
    9512              : 
    9513      2022777 :   if (error_operand_p (expr))
    9514           30 :     return error_mark_node;
    9515              : 
    9516      2022747 :   intype = TREE_TYPE (expr);
    9517              : 
    9518              :   /* [expr.reinterpret.cast]
    9519              :      A pointer can be converted to any integral type large enough to
    9520              :      hold it. ... A value of type std::nullptr_t can be converted to
    9521              :      an integral type; the conversion has the same meaning and
    9522              :      validity as a conversion of (void*)0 to the integral type.  */
    9523      2022747 :   if (CP_INTEGRAL_TYPE_P (type)
    9524       167846 :       && (TYPE_PTR_P (intype) || NULLPTR_TYPE_P (intype)))
    9525              :     {
    9526       165939 :       if (TYPE_PRECISION (type) < TYPE_PRECISION (intype))
    9527              :         {
    9528           21 :           if (complain & tf_error)
    9529           15 :             permerror (loc, "cast from %qH to %qI loses precision",
    9530              :                        intype, type);
    9531              :           else
    9532            6 :             return error_mark_node;
    9533              :         }
    9534       165933 :       if (NULLPTR_TYPE_P (intype))
    9535           98 :         return build_int_cst (type, 0);
    9536              :     }
    9537              :   /* [expr.reinterpret.cast]
    9538              :      A value of integral or enumeration type can be explicitly
    9539              :      converted to a pointer.  */
    9540      1856808 :   else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype))
    9541              :     /* OK */
    9542              :     ;
    9543      1821784 :   else if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    9544      1819862 :             || TYPE_PTR_OR_PTRMEM_P (type))
    9545      1936846 :            && same_type_p (type, intype))
    9546              :     /* DR 799 */
    9547          468 :     return rvalue (expr);
    9548      1821316 :   else if (TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
    9549              :     {
    9550          282 :       if ((complain & tf_warning)
    9551          564 :           && !cxx_safe_function_type_cast_p (TREE_TYPE (type),
    9552          282 :                                              TREE_TYPE (intype)))
    9553          145 :         warning_at (loc, OPT_Wcast_function_type,
    9554              :                     "cast between incompatible function types"
    9555              :                     " from %qH to %qI", intype, type);
    9556          282 :       return build_nop_reinterpret (type, expr);
    9557              :     }
    9558      1821034 :   else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype))
    9559              :     {
    9560           79 :       if ((complain & tf_warning)
    9561          158 :           && !cxx_safe_function_type_cast_p
    9562           79 :                 (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (type)),
    9563           79 :                  TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (intype))))
    9564           52 :         warning_at (loc, OPT_Wcast_function_type,
    9565              :                     "cast between incompatible pointer to member types"
    9566              :                     " from %qH to %qI", intype, type);
    9567           79 :       return build_nop_reinterpret (type, expr);
    9568              :     }
    9569           21 :   else if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype))
    9570      1820955 :            || (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype)))
    9571              :     {
    9572       113946 :       if (!c_cast_p
    9573       113946 :           && check_for_casting_away_constness (loc, intype, type,
    9574              :                                                REINTERPRET_CAST_EXPR,
    9575              :                                                complain))
    9576           21 :         return error_mark_node;
    9577              :       /* Warn about possible alignment problems.  */
    9578       113925 :       if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    9579           24 :           && (complain & tf_warning)
    9580           24 :           && !VOID_TYPE_P (type)
    9581           24 :           && TREE_CODE (TREE_TYPE (intype)) != FUNCTION_TYPE
    9582           24 :           && COMPLETE_TYPE_P (TREE_TYPE (type))
    9583           24 :           && COMPLETE_TYPE_P (TREE_TYPE (intype))
    9584       113973 :           && min_align_of_type (TREE_TYPE (type))
    9585           24 :              > min_align_of_type (TREE_TYPE (intype)))
    9586           18 :         warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    9587              :                     "increases required alignment of target type",
    9588              :                     intype, type);
    9589              : 
    9590       113925 :       if (warn_strict_aliasing <= 2)
    9591              :         /* strict_aliasing_warning STRIP_NOPs its expr.  */
    9592       102087 :         cp_strict_aliasing_warning (EXPR_LOCATION (expr), type, expr);
    9593              : 
    9594       113925 :       return build_nop_reinterpret (type, expr);
    9595              :     }
    9596          297 :   else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
    9597      1707169 :            || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
    9598              :     {
    9599          276 :       if (complain & tf_warning)
    9600              :         /* C++11 5.2.10 p8 says that "Converting a function pointer to an
    9601              :            object pointer type or vice versa is conditionally-supported."  */
    9602          276 :         warning_at (loc, OPT_Wconditionally_supported,
    9603              :                     "casting between pointer-to-function and "
    9604              :                     "pointer-to-object is conditionally-supported");
    9605          276 :       return build_nop_reinterpret (type, expr);
    9606              :     }
    9607      1706733 :   else if (gnu_vector_type_p (type) && scalarish_type_p (intype))
    9608      1704776 :     return convert_to_vector (type, rvalue (expr));
    9609         1957 :   else if (gnu_vector_type_p (intype)
    9610         1957 :            && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
    9611         1855 :     return convert_to_integer_nofold (type, expr);
    9612              :   else
    9613              :     {
    9614          102 :       if (valid_p)
    9615           84 :         *valid_p = false;
    9616          102 :       if (complain & tf_error)
    9617           93 :         error_at (loc, "invalid cast from type %qT to type %qT",
    9618              :                   intype, type);
    9619          102 :       return error_mark_node;
    9620              :     }
    9621              : 
    9622       200859 :   expr = cp_convert (type, expr, complain);
    9623       200859 :   if (TREE_CODE (expr) == NOP_EXPR)
    9624              :     /* Mark any nop_expr that created as a reintepret_cast.  */
    9625            0 :     REINTERPRET_CAST_P (expr) = true;
    9626              :   return expr;
    9627              : }
    9628              : 
    9629              : tree
    9630       769020 : build_reinterpret_cast (location_t loc, tree type, tree expr,
    9631              :                         tsubst_flags_t complain)
    9632              : {
    9633       769020 :   tree r;
    9634              : 
    9635       769020 :   if (type == error_mark_node || expr == error_mark_node)
    9636              :     return error_mark_node;
    9637              : 
    9638       769013 :   if (processing_template_decl)
    9639              :     {
    9640       624503 :       tree t = build_min (REINTERPRET_CAST_EXPR, type, expr);
    9641              : 
    9642       624503 :       if (!TREE_SIDE_EFFECTS (t)
    9643       624503 :           && type_dependent_expression_p (expr))
    9644              :         /* There might turn out to be side effects inside expr.  */
    9645       293107 :         TREE_SIDE_EFFECTS (t) = 1;
    9646       624503 :       r = convert_from_reference (t);
    9647       624503 :       protected_set_expr_location (r, loc);
    9648       624503 :       return r;
    9649              :     }
    9650              : 
    9651       144510 :   r = build_reinterpret_cast_1 (loc, type, expr, /*c_cast_p=*/false,
    9652              :                                 /*valid_p=*/NULL, complain);
    9653       144510 :   if (r != error_mark_node)
    9654              :     {
    9655       144447 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9656       144447 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9657              :     }
    9658       144510 :   protected_set_expr_location (r, loc);
    9659       144510 :   return r;
    9660              : }
    9661              : 
    9662              : /* Perform a const_cast from EXPR to TYPE.  If the cast is valid,
    9663              :    return an appropriate expression.  Otherwise, return
    9664              :    error_mark_node.  If the cast is not valid, and COMPLAIN is true,
    9665              :    then a diagnostic will be issued.  If VALID_P is non-NULL, we are
    9666              :    performing a C-style cast, its value upon return will indicate
    9667              :    whether or not the conversion succeeded.  */
    9668              : 
    9669              : static tree
    9670     39565074 : build_const_cast_1 (location_t loc, tree dst_type, tree expr,
    9671              :                     tsubst_flags_t complain, bool *valid_p)
    9672              : {
    9673     39565074 :   tree src_type;
    9674     39565074 :   tree reference_type;
    9675              : 
    9676              :   /* Callers are responsible for handling error_mark_node as a
    9677              :      destination type.  */
    9678     39565074 :   gcc_assert (dst_type != error_mark_node);
    9679              :   /* In a template, callers should be building syntactic
    9680              :      representations of casts, not using this machinery.  */
    9681     39565074 :   gcc_assert (!processing_template_decl);
    9682              : 
    9683              :   /* Assume the conversion is invalid.  */
    9684     39565074 :   if (valid_p)
    9685     39366930 :     *valid_p = false;
    9686              : 
    9687     39565074 :   if (!INDIRECT_TYPE_P (dst_type) && !TYPE_PTRDATAMEM_P (dst_type))
    9688              :     {
    9689     38486951 :       if (complain & tf_error)
    9690            9 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9691              :                   "which is not a pointer, reference, "
    9692              :                   "nor a pointer-to-data-member type", dst_type);
    9693     38486951 :       return error_mark_node;
    9694              :     }
    9695              : 
    9696      1078123 :   if (TREE_CODE (TREE_TYPE (dst_type)) == FUNCTION_TYPE)
    9697              :     {
    9698         4183 :       if (complain & tf_error)
    9699            6 :         error_at (loc, "invalid use of %<const_cast%> with type %qT, "
    9700              :                   "which is a pointer or reference to a function type",
    9701              :                   dst_type);
    9702         4183 :        return error_mark_node;
    9703              :     }
    9704              : 
    9705              :   /* A prvalue of non-class type is cv-unqualified.  */
    9706      1073940 :   dst_type = cv_unqualified (dst_type);
    9707              : 
    9708              :   /* Save casted types in the function's used types hash table.  */
    9709      1073940 :   used_types_insert (dst_type);
    9710              : 
    9711      1073940 :   src_type = TREE_TYPE (expr);
    9712              :   /* Expressions do not really have reference types.  */
    9713      1073940 :   if (TYPE_REF_P (src_type))
    9714            0 :     src_type = TREE_TYPE (src_type);
    9715              : 
    9716              :   /* [expr.const.cast]
    9717              : 
    9718              :      For two object types T1 and T2, if a pointer to T1 can be explicitly
    9719              :      converted to the type "pointer to T2" using a const_cast, then the
    9720              :      following conversions can also be made:
    9721              : 
    9722              :      -- an lvalue of type T1 can be explicitly converted to an lvalue of
    9723              :      type T2 using the cast const_cast<T2&>;
    9724              : 
    9725              :      -- a glvalue of type T1 can be explicitly converted to an xvalue of
    9726              :      type T2 using the cast const_cast<T2&&>; and
    9727              : 
    9728              :      -- if T1 is a class type, a prvalue of type T1 can be explicitly
    9729              :      converted to an xvalue of type T2 using the cast const_cast<T2&&>.  */
    9730              : 
    9731      1073940 :   if (TYPE_REF_P (dst_type))
    9732              :     {
    9733       125288 :       reference_type = dst_type;
    9734       125288 :       if (!TYPE_REF_IS_RVALUE (dst_type)
    9735       125288 :           ? lvalue_p (expr)
    9736         1564 :           : obvalue_p (expr))
    9737              :         /* OK.  */;
    9738              :       else
    9739              :         {
    9740           35 :           if (complain & tf_error)
    9741            9 :             error_at (loc, "invalid %<const_cast%> of an rvalue of type %qT "
    9742              :                       "to type %qT",
    9743              :                       src_type, dst_type);
    9744           35 :           return error_mark_node;
    9745              :         }
    9746       125253 :       dst_type = build_pointer_type (TREE_TYPE (dst_type));
    9747       125253 :       src_type = build_pointer_type (src_type);
    9748              :     }
    9749              :   else
    9750              :     {
    9751       948652 :       reference_type = NULL_TREE;
    9752              :       /* If the destination type is not a reference type, the
    9753              :          lvalue-to-rvalue, array-to-pointer, and function-to-pointer
    9754              :          conversions are performed.  */
    9755       948652 :       src_type = type_decays_to (src_type);
    9756       948652 :       if (src_type == error_mark_node)
    9757              :         return error_mark_node;
    9758              :     }
    9759              : 
    9760      1073905 :   if (TYPE_PTR_P (src_type) || TYPE_PTRDATAMEM_P (src_type))
    9761              :     {
    9762       641019 :       if (comp_ptr_ttypes_const (dst_type, src_type, bounds_none))
    9763              :         {
    9764       399041 :           if (valid_p)
    9765              :             {
    9766       200975 :               *valid_p = true;
    9767              :               /* This cast is actually a C-style cast.  Issue a warning if
    9768              :                  the user is making a potentially unsafe cast.  */
    9769       200975 :               check_for_casting_away_constness (loc, src_type, dst_type,
    9770              :                                                 CAST_EXPR, complain);
    9771              :               /* ??? comp_ptr_ttypes_const ignores TYPE_ALIGN.  */
    9772       200975 :               if ((STRICT_ALIGNMENT || warn_cast_align == 2)
    9773            3 :                   && (complain & tf_warning)
    9774       200981 :                   && min_align_of_type (TREE_TYPE (dst_type))
    9775            3 :                      > min_align_of_type (TREE_TYPE (src_type)))
    9776            3 :                 warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI "
    9777              :                             "increases required alignment of target type",
    9778              :                             src_type, dst_type);
    9779              :             }
    9780       399041 :           if (reference_type)
    9781              :             {
    9782       123819 :               expr = cp_build_addr_expr (expr, complain);
    9783       123819 :               if (expr == error_mark_node)
    9784              :                 return error_mark_node;
    9785       123801 :               expr = build_nop (reference_type, expr);
    9786       123801 :               return convert_from_reference (expr);
    9787              :             }
    9788              :           else
    9789              :             {
    9790       275222 :               expr = decay_conversion (expr, complain);
    9791       275222 :               if (expr == error_mark_node)
    9792              :                 return error_mark_node;
    9793              : 
    9794              :               /* build_c_cast puts on a NOP_EXPR to make the result not an
    9795              :                  lvalue.  Strip such NOP_EXPRs if VALUE is being used in
    9796              :                  non-lvalue context.  */
    9797       275222 :               if (TREE_CODE (expr) == NOP_EXPR
    9798       275222 :                   && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0)))
    9799            3 :                 expr = TREE_OPERAND (expr, 0);
    9800       275222 :               return build_nop (dst_type, expr);
    9801              :             }
    9802              :         }
    9803       241978 :       else if (valid_p
    9804       483908 :                && !at_least_as_qualified_p (TREE_TYPE (dst_type),
    9805       241930 :                                             TREE_TYPE (src_type)))
    9806        14992 :         check_for_casting_away_constness (loc, src_type, dst_type,
    9807              :                                           CAST_EXPR, complain);
    9808              :     }
    9809              : 
    9810       674864 :   if (complain & tf_error)
    9811           30 :     error_at (loc, "invalid %<const_cast%> from type %qT to type %qT",
    9812              :               src_type, dst_type);
    9813       674864 :   return error_mark_node;
    9814              : }
    9815              : 
    9816              : tree
    9817       694363 : build_const_cast (location_t loc, tree type, tree expr,
    9818              :                   tsubst_flags_t complain)
    9819              : {
    9820       694363 :   tree r;
    9821              : 
    9822       694363 :   if (type == error_mark_node || error_operand_p (expr))
    9823              :     return error_mark_node;
    9824              : 
    9825       694355 :   if (processing_template_decl)
    9826              :     {
    9827       496211 :       tree t = build_min (CONST_CAST_EXPR, type, expr);
    9828              : 
    9829       496211 :       if (!TREE_SIDE_EFFECTS (t)
    9830       496211 :           && type_dependent_expression_p (expr))
    9831              :         /* There might turn out to be side effects inside expr.  */
    9832       379760 :         TREE_SIDE_EFFECTS (t) = 1;
    9833       496211 :       r = convert_from_reference (t);
    9834       496211 :       protected_set_expr_location (r, loc);
    9835       496211 :       return r;
    9836              :     }
    9837              : 
    9838       198144 :   r = build_const_cast_1 (loc, type, expr, complain, /*valid_p=*/NULL);
    9839       198144 :   if (r != error_mark_node)
    9840              :     {
    9841       198066 :       maybe_warn_about_useless_cast (loc, type, expr, complain);
    9842       198066 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9843              :     }
    9844       198144 :   protected_set_expr_location (r, loc);
    9845       198144 :   return r;
    9846              : }
    9847              : 
    9848              : /* Like cp_build_c_cast, but for the c-common bits.  */
    9849              : 
    9850              : tree
    9851            0 : build_c_cast (location_t loc, tree type, tree expr)
    9852              : {
    9853            0 :   return cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9854              : }
    9855              : 
    9856              : /* Like the "build_c_cast" used for c-common, but using cp_expr to
    9857              :    preserve location information even for tree nodes that don't
    9858              :    support it.  */
    9859              : 
    9860              : cp_expr
    9861     10706356 : build_c_cast (location_t loc, tree type, cp_expr expr)
    9862              : {
    9863     10706356 :   cp_expr result = cp_build_c_cast (loc, type, expr, tf_warning_or_error);
    9864     10706356 :   result.set_location (loc);
    9865     10706356 :   return result;
    9866              : }
    9867              : 
    9868              : /* Build an expression representing an explicit C-style cast to type
    9869              :    TYPE of expression EXPR.  */
    9870              : 
    9871              : tree
    9872     42188995 : cp_build_c_cast (location_t loc, tree type, tree expr,
    9873              :                  tsubst_flags_t complain)
    9874              : {
    9875     42188995 :   tree value = expr;
    9876     42188995 :   tree result;
    9877     42188995 :   bool valid_p;
    9878              : 
    9879     42188995 :   if (type == error_mark_node || error_operand_p (expr))
    9880              :     return error_mark_node;
    9881              : 
    9882     42188818 :   if (processing_template_decl)
    9883              :     {
    9884      2821879 :       tree t = build_min (CAST_EXPR, type,
    9885              :                           tree_cons (NULL_TREE, value, NULL_TREE));
    9886              :       /* We don't know if it will or will not have side effects.  */
    9887      2821879 :       TREE_SIDE_EFFECTS (t) = 1;
    9888      2821879 :       return convert_from_reference (t);
    9889              :     }
    9890              : 
    9891              :   /* Casts to a (pointer to a) specific ObjC class (or 'id' or
    9892              :      'Class') should always be retained, because this information aids
    9893              :      in method lookup.  */
    9894     39366939 :   if (objc_is_object_ptr (type)
    9895     39366939 :       && objc_is_object_ptr (TREE_TYPE (expr)))
    9896            0 :     return build_nop (type, expr);
    9897              : 
    9898              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
    9899              :      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
    9900     39366939 :   if (!TYPE_REF_P (type)
    9901     39363990 :       && TREE_CODE (value) == NOP_EXPR
    9902     39841145 :       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
    9903       241529 :     value = TREE_OPERAND (value, 0);
    9904              : 
    9905     39366939 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9906              :     {
    9907              :       /* Allow casting from T1* to T2[] because Cfront allows it.
    9908              :          NIHCL uses it. It is not valid ISO C++ however.  */
    9909            3 :       if (TYPE_PTR_P (TREE_TYPE (expr)))
    9910              :         {
    9911            0 :           if (complain & tf_error)
    9912            0 :             permerror (loc, "ISO C++ forbids casting to an array type %qT",
    9913              :                        type);
    9914              :           else
    9915            0 :             return error_mark_node;
    9916            0 :           type = build_pointer_type (TREE_TYPE (type));
    9917              :         }
    9918              :       else
    9919              :         {
    9920            3 :           if (complain & tf_error)
    9921            3 :             error_at (loc, "ISO C++ forbids casting to an array type %qT",
    9922              :                       type);
    9923            3 :           return error_mark_node;
    9924              :         }
    9925              :     }
    9926              : 
    9927     39366936 :   if (FUNC_OR_METHOD_TYPE_P (type))
    9928              :     {
    9929           15 :       if (complain & tf_error)
    9930           15 :         error_at (loc, "invalid cast to function type %qT", type);
    9931           15 :       return error_mark_node;
    9932              :     }
    9933              : 
    9934     39366921 :   if (TYPE_PTR_P (type)
    9935       876877 :       && TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
    9936              :       /* Casting to an integer of smaller size is an error detected elsewhere.  */
    9937       431431 :       && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (value))
    9938              :       /* Don't warn about converting any constant.  */
    9939     39742847 :       && !TREE_CONSTANT (value))
    9940           47 :     warning_at (loc, OPT_Wint_to_pointer_cast,
    9941              :                 "cast to pointer from integer of different size");
    9942              : 
    9943              :   /* A C-style cast can be a const_cast.  */
    9944     39366921 :   result = build_const_cast_1 (loc, type, value, complain & tf_warning,
    9945              :                                &valid_p);
    9946     39366921 :   if (valid_p)
    9947              :     {
    9948       200966 :       if (result != error_mark_node)
    9949              :         {
    9950       200957 :           maybe_warn_about_useless_cast (loc, type, value, complain);
    9951       200957 :           maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9952              :         }
    9953            9 :       else if (complain & tf_error)
    9954            9 :         build_const_cast_1 (loc, type, value, tf_error, &valid_p);
    9955              :       return result;
    9956              :     }
    9957              : 
    9958              :   /* Or a static cast.  */
    9959     39165955 :   result = build_static_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9960              :                                 &valid_p, complain);
    9961              :   /* Or a reinterpret_cast.  */
    9962     39165955 :   if (!valid_p)
    9963      1878436 :     result = build_reinterpret_cast_1 (loc, type, value, /*c_cast_p=*/true,
    9964              :                                        &valid_p, complain);
    9965              :   /* The static_cast or reinterpret_cast may be followed by a
    9966              :      const_cast.  */
    9967     39165955 :   if (valid_p
    9968              :       /* A valid cast may result in errors if, for example, a
    9969              :          conversion to an ambiguous base class is required.  */
    9970     39165955 :       && !error_operand_p (result))
    9971              :     {
    9972     39165471 :       tree result_type;
    9973              : 
    9974     39165471 :       maybe_warn_about_useless_cast (loc, type, value, complain);
    9975     39165471 :       maybe_warn_about_cast_ignoring_quals (loc, type, complain);
    9976              : 
    9977              :       /* Non-class rvalues always have cv-unqualified type.  */
    9978     39165471 :       if (!CLASS_TYPE_P (type))
    9979     36344511 :         type = TYPE_MAIN_VARIANT (type);
    9980     39165471 :       result_type = TREE_TYPE (result);
    9981     39165471 :       if (!CLASS_TYPE_P (result_type) && !TYPE_REF_P (type))
    9982     36343055 :         result_type = TYPE_MAIN_VARIANT (result_type);
    9983              :       /* If the type of RESULT does not match TYPE, perform a
    9984              :          const_cast to make it match.  If the static_cast or
    9985              :          reinterpret_cast succeeded, we will differ by at most
    9986              :          cv-qualification, so the follow-on const_cast is guaranteed
    9987              :          to succeed.  */
    9988     39165471 :       if (!same_type_p (non_reference (type), non_reference (result_type)))
    9989              :         {
    9990            0 :           result = build_const_cast_1 (loc, type, result, tf_none, &valid_p);
    9991            0 :           gcc_assert (valid_p);
    9992              :         }
    9993              :       return result;
    9994              :     }
    9995              : 
    9996          484 :   return error_mark_node;
    9997              : }
    9998              : 
    9999              : /* Warn when a value is moved to itself with std::move.  LHS is the target,
   10000              :    RHS may be the std::move call, and LOC is the location of the whole
   10001              :    assignment.  Return true if we warned.  */
   10002              : 
   10003              : bool
   10004     29235926 : maybe_warn_self_move (location_t loc, tree lhs, tree rhs)
   10005              : {
   10006     29235926 :   if (!warn_self_move)
   10007              :     return false;
   10008              : 
   10009              :   /* C++98 doesn't know move.  */
   10010       368775 :   if (cxx_dialect < cxx11)
   10011              :     return false;
   10012              : 
   10013       348948 :   if (processing_template_decl)
   10014              :     return false;
   10015              : 
   10016        26804 :   if (!REFERENCE_REF_P (rhs)
   10017       305139 :       || TREE_CODE (TREE_OPERAND (rhs, 0)) != CALL_EXPR)
   10018              :     return false;
   10019         4893 :   tree fn = TREE_OPERAND (rhs, 0);
   10020         4893 :   if (!is_std_move_p (fn))
   10021              :     return false;
   10022              : 
   10023              :   /* Just a little helper to strip * and various NOPs.  */
   10024         6693 :   auto extract_op = [] (tree &op) {
   10025         4462 :     STRIP_NOPS (op);
   10026         5683 :     while (INDIRECT_REF_P (op))
   10027         1221 :       op = TREE_OPERAND (op, 0);
   10028         4462 :     op = maybe_undo_parenthesized_ref (op);
   10029         4462 :     STRIP_ANY_LOCATION_WRAPPER (op);
   10030         4462 :   };
   10031              : 
   10032         2231 :   tree arg = CALL_EXPR_ARG (fn, 0);
   10033         2231 :   extract_op (arg);
   10034         2231 :   if (TREE_CODE (arg) == ADDR_EXPR)
   10035         1555 :     arg = TREE_OPERAND (arg, 0);
   10036         2231 :   tree type = TREE_TYPE (lhs);
   10037         2231 :   tree orig_lhs = lhs;
   10038         2231 :   extract_op (lhs);
   10039         2231 :   if (cp_tree_equal (lhs, arg)
   10040              :       /* Also warn in a member-initializer-list, as in : i(std::move(i)).  */
   10041         2231 :       || (TREE_CODE (lhs) == FIELD_DECL
   10042          642 :           && TREE_CODE (arg) == COMPONENT_REF
   10043          305 :           && cp_tree_equal (TREE_OPERAND (arg, 0), current_class_ref)
   10044            6 :           && TREE_OPERAND (arg, 1) == lhs))
   10045          117 :     if (warning_at (loc, OPT_Wself_move,
   10046              :                     "moving %qE of type %qT to itself", orig_lhs, type))
   10047              :       return true;
   10048              : 
   10049              :   return false;
   10050              : }
   10051              : 
   10052              : /* For use from the C common bits.  */
   10053              : tree
   10054         4778 : build_modify_expr (location_t location,
   10055              :                    tree lhs, tree /*lhs_origtype*/,
   10056              :                    enum tree_code modifycode,
   10057              :                    location_t /*rhs_location*/, tree rhs,
   10058              :                    tree /*rhs_origtype*/)
   10059              : {
   10060         4778 :   return cp_build_modify_expr (location, lhs, modifycode, rhs,
   10061         4778 :                                tf_warning_or_error);
   10062              : }
   10063              : 
   10064              : /* Build an assignment expression of lvalue LHS from value RHS.
   10065              :    MODIFYCODE is the code for a binary operator that we use
   10066              :    to combine the old value of LHS with RHS to get the new value.
   10067              :    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
   10068              : 
   10069              :    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.  */
   10070              : 
   10071              : tree
   10072     38270085 : cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
   10073              :                       tree rhs, tsubst_flags_t complain)
   10074              : {
   10075     38270085 :   lhs = mark_lvalue_use_nonread (lhs);
   10076              : 
   10077     38270085 :   tree result = NULL_TREE;
   10078     38270085 :   tree newrhs = rhs;
   10079     38270085 :   tree lhstype = TREE_TYPE (lhs);
   10080     38270085 :   tree olhs = lhs;
   10081     38270085 :   tree olhstype = lhstype;
   10082     38270085 :   bool plain_assign = (modifycode == NOP_EXPR);
   10083     38270085 :   bool compound_side_effects_p = false;
   10084     38270085 :   tree preeval = NULL_TREE;
   10085              : 
   10086              :   /* Avoid duplicate error messages from operands that had errors.  */
   10087     38270085 :   if (error_operand_p (lhs) || error_operand_p (rhs))
   10088           19 :     return error_mark_node;
   10089              : 
   10090     38270148 :   while (TREE_CODE (lhs) == COMPOUND_EXPR)
   10091              :     {
   10092           82 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
   10093           70 :         compound_side_effects_p = true;
   10094           82 :       lhs = TREE_OPERAND (lhs, 1);
   10095              :     }
   10096              : 
   10097              :   /* Handle control structure constructs used as "lvalues".  Note that we
   10098              :      leave COMPOUND_EXPR on the LHS because it is sequenced after the RHS.  */
   10099     38270066 :   switch (TREE_CODE (lhs))
   10100              :     {
   10101              :       /* Handle --foo = 5; as these are valid constructs in C++.  */
   10102           27 :     case PREDECREMENT_EXPR:
   10103           27 :     case PREINCREMENT_EXPR:
   10104           27 :       if (compound_side_effects_p)
   10105            9 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
   10106           27 :       lhs = genericize_compound_lvalue (lhs);
   10107          173 :     maybe_add_compound:
   10108              :       /* If we had (bar, --foo) = 5; or (bar, (baz, --foo)) = 5;
   10109              :          and looked through the COMPOUND_EXPRs, readd them now around
   10110              :          the resulting lhs.  */
   10111          173 :       if (TREE_CODE (olhs) == COMPOUND_EXPR)
   10112              :         {
   10113            9 :           lhs = build2 (COMPOUND_EXPR, lhstype, TREE_OPERAND (olhs, 0), lhs);
   10114            9 :           tree *ptr = &TREE_OPERAND (lhs, 1);
   10115            9 :           for (olhs = TREE_OPERAND (olhs, 1);
   10116           12 :                TREE_CODE (olhs) == COMPOUND_EXPR;
   10117            3 :                olhs = TREE_OPERAND (olhs, 1))
   10118              :             {
   10119            3 :               *ptr = build2 (COMPOUND_EXPR, lhstype,
   10120            3 :                              TREE_OPERAND (olhs, 0), *ptr);
   10121            3 :               ptr = &TREE_OPERAND (*ptr, 1);
   10122              :             }
   10123              :         }
   10124              :       break;
   10125              : 
   10126          146 :     case MODIFY_EXPR:
   10127          146 :       if (compound_side_effects_p)
   10128            0 :         newrhs = rhs = stabilize_expr (rhs, &preeval);
   10129          146 :       lhs = genericize_compound_lvalue (lhs);
   10130          146 :       goto maybe_add_compound;
   10131              : 
   10132            0 :     case MIN_EXPR:
   10133            0 :     case MAX_EXPR:
   10134              :       /* MIN_EXPR and MAX_EXPR are currently only permitted as lvalues,
   10135              :          when neither operand has side-effects.  */
   10136            0 :       if (!lvalue_or_else (lhs, lv_assign, complain))
   10137            0 :         return error_mark_node;
   10138              : 
   10139            0 :       gcc_assert (!TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0))
   10140              :                   && !TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 1)));
   10141              : 
   10142            0 :       lhs = build3 (COND_EXPR, TREE_TYPE (lhs),
   10143            0 :                     build2 (TREE_CODE (lhs) == MIN_EXPR ? LE_EXPR : GE_EXPR,
   10144              :                             boolean_type_node,
   10145            0 :                             TREE_OPERAND (lhs, 0),
   10146            0 :                             TREE_OPERAND (lhs, 1)),
   10147            0 :                     TREE_OPERAND (lhs, 0),
   10148            0 :                     TREE_OPERAND (lhs, 1));
   10149          212 :       gcc_fallthrough ();
   10150              : 
   10151              :       /* Handle (a ? b : c) used as an "lvalue".  */
   10152          212 :     case COND_EXPR:
   10153          212 :       {
   10154              :         /* Produce (a ? (b = rhs) : (c = rhs))
   10155              :            except that the RHS goes through a save-expr
   10156              :            so the code to compute it is only emitted once.  */
   10157          212 :         if (VOID_TYPE_P (TREE_TYPE (rhs)))
   10158              :           {
   10159           18 :             if (complain & tf_error)
   10160           24 :               error_at (cp_expr_loc_or_loc (rhs, loc),
   10161              :                         "void value not ignored as it ought to be");
   10162           18 :             return error_mark_node;
   10163              :           }
   10164              : 
   10165          194 :         rhs = stabilize_expr (rhs, &preeval);
   10166              : 
   10167              :         /* Check this here to avoid odd errors when trying to convert
   10168              :            a throw to the type of the COND_EXPR.  */
   10169          194 :         if (!lvalue_or_else (lhs, lv_assign, complain))
   10170            6 :           return error_mark_node;
   10171              : 
   10172          188 :         tree op1 = TREE_OPERAND (lhs, 1);
   10173          188 :         if (TREE_CODE (op1) != THROW_EXPR)
   10174          182 :           op1 = cp_build_modify_expr (loc, op1, modifycode, rhs, complain);
   10175              :         /* When sanitizing undefined behavior, even when rhs doesn't need
   10176              :            stabilization at this point, the sanitization might add extra
   10177              :            SAVE_EXPRs in there and so make sure there is no tree sharing
   10178              :            in the rhs, otherwise those SAVE_EXPRs will have initialization
   10179              :            only in one of the two branches.  */
   10180          188 :         if (sanitize_flags_p (SANITIZE_UNDEFINED
   10181              :                               | SANITIZE_UNDEFINED_NONDEFAULT))
   10182            3 :           rhs = unshare_expr (rhs);
   10183          188 :         tree op2 = TREE_OPERAND (lhs, 2);
   10184          188 :         if (TREE_CODE (op2) != THROW_EXPR)
   10185          182 :           op2 = cp_build_modify_expr (loc, op2, modifycode, rhs, complain);
   10186          188 :         tree cond = build_conditional_expr (input_location,
   10187          188 :                                             TREE_OPERAND (lhs, 0), op1, op2,
   10188              :                                             complain);
   10189              : 
   10190          188 :         if (cond == error_mark_node)
   10191              :           return cond;
   10192              :         /* If we had (e, (a ? b : c)) = d; or (e, (f, (a ? b : c))) = d;
   10193              :            and looked through the COMPOUND_EXPRs, readd them now around
   10194              :            the resulting cond before adding the preevaluated rhs.  */
   10195          185 :         if (TREE_CODE (olhs) == COMPOUND_EXPR)
   10196              :           {
   10197           18 :             cond = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
   10198           18 :                            TREE_OPERAND (olhs, 0), cond);
   10199           18 :             tree *ptr = &TREE_OPERAND (cond, 1);
   10200           18 :             for (olhs = TREE_OPERAND (olhs, 1);
   10201           21 :                  TREE_CODE (olhs) == COMPOUND_EXPR;
   10202            3 :                  olhs = TREE_OPERAND (olhs, 1))
   10203              :               {
   10204            3 :                 *ptr = build2 (COMPOUND_EXPR, TREE_TYPE (cond),
   10205            3 :                                TREE_OPERAND (olhs, 0), *ptr);
   10206            3 :                 ptr = &TREE_OPERAND (*ptr, 1);
   10207              :               }
   10208              :           }
   10209              :         /* Make sure the code to compute the rhs comes out
   10210              :            before the split.  */
   10211          185 :         result = cond;
   10212          185 :         goto ret;
   10213              :       }
   10214              : 
   10215              :     default:
   10216              :       lhs = olhs;
   10217              :       break;
   10218              :     }
   10219              : 
   10220     38269854 :   if (modifycode == INIT_EXPR)
   10221              :     {
   10222      4297687 :       if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
   10223              :         /* Do the default thing.  */;
   10224      4092807 :       else if (TREE_CODE (rhs) == CONSTRUCTOR)
   10225              :         {
   10226              :           /* Compound literal.  */
   10227           98 :           if (! same_type_p (TREE_TYPE (rhs), lhstype))
   10228              :             /* Call convert to generate an error; see PR 11063.  */
   10229            0 :             rhs = convert (lhstype, rhs);
   10230           98 :           result = cp_build_init_expr (lhs, rhs);
   10231           98 :           TREE_SIDE_EFFECTS (result) = 1;
   10232           98 :           goto ret;
   10233              :         }
   10234      4092709 :       else if (! MAYBE_CLASS_TYPE_P (lhstype))
   10235              :         /* Do the default thing.  */;
   10236              :       else
   10237              :         {
   10238        41483 :           releasing_vec rhs_vec = make_tree_vector_single (rhs);
   10239        41483 :           result = build_special_member_call (lhs, complete_ctor_identifier,
   10240              :                                               &rhs_vec, lhstype, LOOKUP_NORMAL,
   10241              :                                               complain);
   10242        41483 :           if (result == NULL_TREE)
   10243            0 :             return error_mark_node;
   10244        41483 :           goto ret;
   10245        41483 :         }
   10246              :     }
   10247              :   else
   10248              :     {
   10249     33972167 :       lhs = require_complete_type (lhs, complain);
   10250     33972167 :       if (lhs == error_mark_node)
   10251              :         return error_mark_node;
   10252              : 
   10253     33972001 :       if (modifycode == NOP_EXPR)
   10254              :         {
   10255     29186726 :           maybe_warn_self_move (loc, lhs, rhs);
   10256              : 
   10257     29186726 :           if (c_dialect_objc ())
   10258              :             {
   10259            0 :               result = objc_maybe_build_modify_expr (lhs, rhs);
   10260            0 :               if (result)
   10261            0 :                 goto ret;
   10262              :             }
   10263              : 
   10264              :           /* `operator=' is not an inheritable operator.  */
   10265     29186726 :           if (! MAYBE_CLASS_TYPE_P (lhstype))
   10266              :             /* Do the default thing.  */;
   10267              :           else
   10268              :             {
   10269      3574485 :               result = build_new_op (input_location, MODIFY_EXPR,
   10270              :                                      LOOKUP_NORMAL, lhs, rhs,
   10271              :                                      make_node (NOP_EXPR), NULL_TREE,
   10272              :                                      /*overload=*/NULL, complain);
   10273      3574485 :               if (result == NULL_TREE)
   10274            0 :                 return error_mark_node;
   10275      3574485 :               goto ret;
   10276              :             }
   10277              :           lhstype = olhstype;
   10278              :         }
   10279              :       else
   10280              :         {
   10281      4785275 :           tree init = NULL_TREE;
   10282              : 
   10283              :           /* A binary op has been requested.  Combine the old LHS
   10284              :              value with the RHS producing the value we should actually
   10285              :              store into the LHS.  */
   10286      4785275 :           gcc_assert (!((TYPE_REF_P (lhstype)
   10287              :                          && MAYBE_CLASS_TYPE_P (TREE_TYPE (lhstype)))
   10288              :                         || MAYBE_CLASS_TYPE_P (lhstype)));
   10289              : 
   10290              :           /* Preevaluate the RHS to make sure its evaluation is complete
   10291              :              before the lvalue-to-rvalue conversion of the LHS:
   10292              : 
   10293              :              [expr.ass] With respect to an indeterminately-sequenced
   10294              :              function call, the operation of a compound assignment is a
   10295              :              single evaluation. [ Note: Therefore, a function call shall
   10296              :              not intervene between the lvalue-to-rvalue conversion and the
   10297              :              side effect associated with any single compound assignment
   10298              :              operator. -- end note ]  */
   10299      4785275 :           lhs = cp_stabilize_reference (lhs);
   10300      4785275 :           rhs = decay_conversion (rhs, complain);
   10301      4785275 :           if (rhs == error_mark_node)
   10302          123 :             return error_mark_node;
   10303              : 
   10304      4785272 :           {
   10305      4785272 :             auto_diagnostic_group d;
   10306      4785272 :             rhs = stabilize_expr (rhs, &init);
   10307      4785272 :             bool clear_decl_read = false;
   10308      4785272 :             tree stripped_lhs = tree_strip_any_location_wrapper (lhs);
   10309      1434439 :             if ((VAR_P (stripped_lhs) || TREE_CODE (stripped_lhs) == PARM_DECL)
   10310      4039649 :                 && !DECL_READ_P (stripped_lhs)
   10311      1049517 :                 && (VAR_P (stripped_lhs) ? warn_unused_but_set_variable
   10312              :                                          : warn_unused_but_set_parameter) > 2
   10313         7110 :                 && !CLASS_TYPE_P (TREE_TYPE (lhs))
   10314      4792382 :                 && !CLASS_TYPE_P (TREE_TYPE (rhs)))
   10315              :               {
   10316         7110 :                 mark_exp_read (rhs);
   10317         7110 :                 if (!DECL_READ_P (stripped_lhs))
   10318      4785272 :                   clear_decl_read = true;
   10319              :               }
   10320      4785272 :             newrhs = cp_build_binary_op (loc, modifycode, lhs, rhs, complain);
   10321      4785272 :             if (clear_decl_read)
   10322         7110 :               DECL_READ_P (stripped_lhs) = 0;
   10323      4785272 :             if (newrhs == error_mark_node)
   10324              :               {
   10325          120 :                 if (complain & tf_error)
   10326           24 :                   inform (loc, "  in evaluation of %<%Q(%#T, %#T)%>",
   10327           24 :                           modifycode, TREE_TYPE (lhs), TREE_TYPE (rhs));
   10328          120 :                 return error_mark_node;
   10329              :               }
   10330      4785272 :           }
   10331              : 
   10332      4785152 :           if (init)
   10333       294128 :             newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), init, newrhs);
   10334              : 
   10335              :           /* Now it looks like a plain assignment.  */
   10336      4785152 :           modifycode = NOP_EXPR;
   10337      4785152 :           if (c_dialect_objc ())
   10338              :             {
   10339            0 :               result = objc_maybe_build_modify_expr (lhs, newrhs);
   10340            0 :               if (result)
   10341            0 :                 goto ret;
   10342              :             }
   10343              :         }
   10344     30397393 :       gcc_assert (!TYPE_REF_P (lhstype));
   10345     30397393 :       gcc_assert (!TYPE_REF_P (TREE_TYPE (newrhs)));
   10346              :     }
   10347              : 
   10348              :   /* The left-hand side must be an lvalue.  */
   10349     34653499 :   if (!lvalue_or_else (lhs, lv_assign, complain))
   10350          839 :     return error_mark_node;
   10351              : 
   10352              :   /* Warn about modifying something that is `const'.  Don't warn if
   10353              :      this is initialization.  */
   10354     34652660 :   if (modifycode != INIT_EXPR
   10355     34652660 :       && (TREE_READONLY (lhs) || CP_TYPE_CONST_P (lhstype)
   10356              :           /* Functions are not modifiable, even though they are
   10357              :              lvalues.  */
   10358     30354148 :           || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (lhs))
   10359              :           /* If it's an aggregate and any field is const, then it is
   10360              :              effectively const.  */
   10361     30354070 :           || (CLASS_TYPE_P (lhstype)
   10362            0 :               && C_TYPE_FIELDS_READONLY (lhstype))))
   10363              :     {
   10364        42484 :       if (complain & tf_error)
   10365           89 :         cxx_readonly_error (loc, lhs, lv_assign);
   10366        42484 :       return error_mark_node;
   10367              :     }
   10368              : 
   10369              :   /* If storing into a structure or union member, it may have been given a
   10370              :      lowered bitfield type.  We need to convert to the declared type first,
   10371              :      so retrieve it now.  */
   10372              : 
   10373     34610176 :   olhstype = unlowered_expr_type (lhs);
   10374              : 
   10375              :   /* Convert new value to destination type.  */
   10376              : 
   10377     34610176 :   if (TREE_CODE (lhstype) == ARRAY_TYPE)
   10378              :     {
   10379          222 :       int from_array;
   10380              : 
   10381          222 :       if (BRACE_ENCLOSED_INITIALIZER_P (newrhs))
   10382              :         {
   10383           12 :           if (modifycode != INIT_EXPR)
   10384              :             {
   10385           12 :               if (complain & tf_error)
   10386           12 :                 error_at (loc,
   10387              :                           "assigning to an array from an initializer list");
   10388           12 :               return error_mark_node;
   10389              :             }
   10390            0 :           if (check_array_initializer (lhs, lhstype, newrhs))
   10391            0 :             return error_mark_node;
   10392            0 :           newrhs = digest_init (lhstype, newrhs, complain);
   10393            0 :           if (newrhs == error_mark_node)
   10394              :             return error_mark_node;
   10395              :         }
   10396              : 
   10397              :       /* C++11 8.5/17: "If the destination type is an array of characters,
   10398              :          an array of char16_t, an array of char32_t, or an array of wchar_t,
   10399              :          and the initializer is a string literal...".  */
   10400          210 :       else if ((TREE_CODE (tree_strip_any_location_wrapper (newrhs))
   10401              :                 == STRING_CST)
   10402           43 :                && char_type_p (TREE_TYPE (TYPE_MAIN_VARIANT (lhstype)))
   10403          253 :                && modifycode == INIT_EXPR)
   10404              :         {
   10405           28 :           newrhs = digest_init (lhstype, newrhs, complain);
   10406           28 :           if (newrhs == error_mark_node)
   10407              :             return error_mark_node;
   10408              :         }
   10409              : 
   10410          182 :       else if (!same_or_base_type_p (TYPE_MAIN_VARIANT (lhstype),
   10411              :                                      TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))))
   10412              :         {
   10413           27 :           if (complain & tf_error)
   10414           12 :             error_at (loc, "incompatible types in assignment of %qT to %qT",
   10415           12 :                       TREE_TYPE (rhs), lhstype);
   10416           27 :           return error_mark_node;
   10417              :         }
   10418              : 
   10419              :       /* Allow array assignment in compiler-generated code.  */
   10420          155 :       else if (DECL_P (lhs) && DECL_ARTIFICIAL (lhs))
   10421              :         /* OK, used by coroutines (co-await-initlist1.C).  */;
   10422          149 :       else if (!current_function_decl
   10423          149 :                || !DECL_DEFAULTED_FN (current_function_decl))
   10424              :         {
   10425              :           /* This routine is used for both initialization and assignment.
   10426              :              Make sure the diagnostic message differentiates the context.  */
   10427           99 :           if (complain & tf_error)
   10428              :             {
   10429           30 :               if (modifycode == INIT_EXPR)
   10430            9 :                 error_at (loc, "array used as initializer");
   10431              :               else
   10432           21 :                 error_at (loc, "invalid array assignment");
   10433              :             }
   10434           99 :           return error_mark_node;
   10435              :         }
   10436              : 
   10437          131 :       from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
   10438           84 :                    ? 1 + (modifycode != INIT_EXPR) : 0;
   10439           84 :       result = build_vec_init (lhs, NULL_TREE, newrhs,
   10440              :                                /*explicit_value_init_p=*/false,
   10441              :                                from_array, complain);
   10442           84 :       goto ret;
   10443              :     }
   10444              : 
   10445     34609954 :   if (modifycode == INIT_EXPR)
   10446              :     /* Calls with INIT_EXPR are all direct-initialization, so don't set
   10447              :        LOOKUP_ONLYCONVERTING.  */
   10448      4256047 :     newrhs = convert_for_initialization (lhs, olhstype, newrhs, LOOKUP_NORMAL,
   10449              :                                          ICR_INIT, NULL_TREE, 0,
   10450              :                                          complain | tf_no_cleanup);
   10451              :   else
   10452     30353907 :     newrhs = convert_for_assignment (olhstype, newrhs, ICR_ASSIGN,
   10453              :                                      NULL_TREE, 0, complain, LOOKUP_IMPLICIT);
   10454              : 
   10455     34609954 :   if (!same_type_p (lhstype, olhstype))
   10456       404493 :     newrhs = cp_convert_and_check (lhstype, newrhs, complain);
   10457              : 
   10458     34609954 :   if (modifycode != INIT_EXPR)
   10459              :     {
   10460     30353907 :       if (TREE_CODE (newrhs) == CALL_EXPR
   10461     30353907 :           && TYPE_NEEDS_CONSTRUCTING (lhstype))
   10462            0 :         newrhs = build_cplus_new (lhstype, newrhs, complain);
   10463              : 
   10464              :       /* Can't initialize directly from a TARGET_EXPR, since that would
   10465              :          cause the lhs to be constructed twice, and possibly result in
   10466              :          accidental self-initialization.  So we force the TARGET_EXPR to be
   10467              :          expanded without a target.  */
   10468     30353907 :       if (TREE_CODE (newrhs) == TARGET_EXPR)
   10469          118 :         newrhs = build2 (COMPOUND_EXPR, TREE_TYPE (newrhs), newrhs,
   10470          118 :                          TARGET_EXPR_SLOT (newrhs));
   10471              :     }
   10472              : 
   10473     34609954 :   if (newrhs == error_mark_node)
   10474              :     return error_mark_node;
   10475              : 
   10476     34609252 :   if (c_dialect_objc () && flag_objc_gc)
   10477              :     {
   10478            0 :       result = objc_generate_write_barrier (lhs, modifycode, newrhs);
   10479              : 
   10480            0 :       if (result)
   10481            0 :         goto ret;
   10482              :     }
   10483              : 
   10484     38865250 :   result = build2_loc (loc, modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
   10485              :                        lhstype, lhs, newrhs);
   10486     34609252 :   if (modifycode == INIT_EXPR)
   10487      4255998 :     set_target_expr_eliding (newrhs);
   10488              : 
   10489     34609252 :   TREE_SIDE_EFFECTS (result) = 1;
   10490     34609252 :   if (!plain_assign)
   10491      9041120 :     suppress_warning (result, OPT_Wparentheses);
   10492              : 
   10493     25568132 :  ret:
   10494     38225587 :   if (preeval)
   10495           39 :     result = build2 (COMPOUND_EXPR, TREE_TYPE (result), preeval, result);
   10496              :   return result;
   10497              : }
   10498              : 
   10499              : cp_expr
   10500     71610786 : build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode,
   10501              :                      tree rhs, tree lookups, tsubst_flags_t complain)
   10502              : {
   10503     71610786 :   tree orig_lhs = lhs;
   10504     71610786 :   tree orig_rhs = rhs;
   10505     71610786 :   tree overload = NULL_TREE;
   10506              : 
   10507     71610786 :   if (lhs == error_mark_node || rhs == error_mark_node)
   10508         2173 :     return cp_expr (error_mark_node, loc);
   10509              : 
   10510     71608613 :   tree op = build_min (modifycode, void_type_node, NULL_TREE, NULL_TREE);
   10511              : 
   10512     71608613 :   if (processing_template_decl)
   10513              :     {
   10514     49946790 :       if (type_dependent_expression_p (lhs)
   10515     49946790 :           || type_dependent_expression_p (rhs))
   10516              :         {
   10517     37499760 :           tree rval = build_min_nt_loc (loc, MODOP_EXPR, lhs, op, rhs);
   10518     37499760 :           if (modifycode != NOP_EXPR)
   10519      6361499 :             TREE_TYPE (rval)
   10520     12722998 :               = build_dependent_operator_type (lookups, modifycode, true);
   10521     37499760 :           return rval;
   10522              :         }
   10523              :     }
   10524              : 
   10525     34108853 :   tree rval;
   10526     34108853 :   if (modifycode == NOP_EXPR)
   10527     26422283 :     rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, complain);
   10528              :   else
   10529      7686570 :     rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL,
   10530              :                          lhs, rhs, op, lookups, &overload, complain);
   10531     34108853 :   if (rval == error_mark_node)
   10532         7260 :     return error_mark_node;
   10533     34101593 :   if (processing_template_decl)
   10534              :     {
   10535     12447009 :       if (overload != NULL_TREE)
   10536      1951256 :         return (build_min_non_dep_op_overload
   10537      1951256 :                 (MODIFY_EXPR, rval, overload, orig_lhs, orig_rhs));
   10538              : 
   10539     10495753 :       return (build_min_non_dep
   10540     10495753 :               (MODOP_EXPR, rval, orig_lhs, op, orig_rhs));
   10541              :     }
   10542     21654584 :   return rval;
   10543              : }
   10544              : 
   10545              : /* Helper function for get_delta_difference which assumes FROM is a base
   10546              :    class of TO.  Returns a delta for the conversion of pointer-to-member
   10547              :    of FROM to pointer-to-member of TO.  If the conversion is invalid and
   10548              :    tf_error is not set in COMPLAIN returns error_mark_node, otherwise
   10549              :    returns zero.  If FROM is not a base class of TO, returns NULL_TREE.
   10550              :    If C_CAST_P is true, this conversion is taking place as part of a
   10551              :    C-style cast.  */
   10552              : 
   10553              : static tree
   10554        28965 : get_delta_difference_1 (tree from, tree to, bool c_cast_p,
   10555              :                         tsubst_flags_t complain)
   10556              : {
   10557        28965 :   tree binfo;
   10558        28965 :   base_kind kind;
   10559              : 
   10560        57680 :   binfo = lookup_base (to, from, c_cast_p ? ba_unique : ba_check,
   10561              :                        &kind, complain);
   10562              : 
   10563        28965 :   if (binfo == error_mark_node)
   10564              :     {
   10565           51 :       if (!(complain & tf_error))
   10566              :         return error_mark_node;
   10567              : 
   10568           51 :       inform (input_location, "   in pointer to member function conversion");
   10569           51 :       return size_zero_node;
   10570              :     }
   10571        28914 :   else if (binfo)
   10572              :     {
   10573        28766 :       if (kind != bk_via_virtual)
   10574        28673 :         return BINFO_OFFSET (binfo);
   10575              :       else
   10576              :         /* FROM is a virtual base class of TO.  Issue an error or warning
   10577              :            depending on whether or not this is a reinterpret cast.  */
   10578              :         {
   10579           93 :           if (!(complain & tf_error))
   10580              :             return error_mark_node;
   10581              : 
   10582           78 :           error ("pointer to member conversion via virtual base %qT",
   10583           78 :                  BINFO_TYPE (binfo_from_vbase (binfo)));
   10584              : 
   10585           78 :           return size_zero_node;
   10586              :         }
   10587              :       }
   10588              :   else
   10589              :     return NULL_TREE;
   10590              : }
   10591              : 
   10592              : /* Get difference in deltas for different pointer to member function
   10593              :    types.  If the conversion is invalid and tf_error is not set in
   10594              :    COMPLAIN, returns error_mark_node, otherwise returns an integer
   10595              :    constant of type PTRDIFF_TYPE_NODE and its value is zero if the
   10596              :    conversion is invalid.  If ALLOW_INVERSE_P is true, then allow reverse
   10597              :    conversions as well.  If C_CAST_P is true this conversion is taking
   10598              :    place as part of a C-style cast.
   10599              : 
   10600              :    Note that the naming of FROM and TO is kind of backwards; the return
   10601              :    value is what we add to a TO in order to get a FROM.  They are named
   10602              :    this way because we call this function to find out how to convert from
   10603              :    a pointer to member of FROM to a pointer to member of TO.  */
   10604              : 
   10605              : static tree
   10606        90555 : get_delta_difference (tree from, tree to,
   10607              :                       bool allow_inverse_p,
   10608              :                       bool c_cast_p, tsubst_flags_t complain)
   10609              : {
   10610        90555 :   auto_diagnostic_group d;
   10611        90555 :   tree result;
   10612              : 
   10613        90555 :   if (same_type_ignoring_top_level_qualifiers_p (from, to))
   10614              :     /* Pointer to member of incomplete class is permitted*/
   10615        61738 :     result = size_zero_node;
   10616              :   else
   10617        28817 :     result = get_delta_difference_1 (from, to, c_cast_p, complain);
   10618              : 
   10619        90555 :   if (result == error_mark_node)
   10620              :     return error_mark_node;
   10621              : 
   10622        90540 :   if (!result)
   10623              :   {
   10624          148 :     if (!allow_inverse_p)
   10625              :       {
   10626            0 :         if (!(complain & tf_error))
   10627              :           return error_mark_node;
   10628              : 
   10629            0 :         error_not_base_type (from, to);
   10630            0 :         inform (input_location, "   in pointer to member conversion");
   10631            0 :         result = size_zero_node;
   10632              :       }
   10633              :     else
   10634              :       {
   10635          148 :         result = get_delta_difference_1 (to, from, c_cast_p, complain);
   10636              : 
   10637          148 :         if (result == error_mark_node)
   10638              :           return error_mark_node;
   10639              : 
   10640          148 :         if (result)
   10641          148 :           result = size_diffop_loc (input_location,
   10642              :                                     size_zero_node, result);
   10643              :         else
   10644              :           {
   10645            0 :             if (!(complain & tf_error))
   10646              :               return error_mark_node;
   10647              : 
   10648            0 :             error_not_base_type (from, to);
   10649            0 :             inform (input_location, "   in pointer to member conversion");
   10650            0 :             result = size_zero_node;
   10651              :           }
   10652              :       }
   10653              :   }
   10654              : 
   10655        90540 :   return convert_to_integer (ptrdiff_type_node, result);
   10656        90555 : }
   10657              : 
   10658              : /* Return a constructor for the pointer-to-member-function TYPE using
   10659              :    the other components as specified.  */
   10660              : 
   10661              : tree
   10662        61987 : build_ptrmemfunc1 (tree type, tree delta, tree pfn)
   10663              : {
   10664        61987 :   tree u = NULL_TREE;
   10665        61987 :   tree delta_field;
   10666        61987 :   tree pfn_field;
   10667        61987 :   vec<constructor_elt, va_gc> *v;
   10668              : 
   10669              :   /* Pull the FIELD_DECLs out of the type.  */
   10670        61987 :   pfn_field = TYPE_FIELDS (type);
   10671        61987 :   delta_field = DECL_CHAIN (pfn_field);
   10672              : 
   10673              :   /* Make sure DELTA has the type we want.  */
   10674        61987 :   delta = convert_and_check (input_location, delta_type_node, delta);
   10675              : 
   10676              :   /* Convert to the correct target type if necessary.  */
   10677        61987 :   pfn = fold_convert (TREE_TYPE (pfn_field), pfn);
   10678              : 
   10679              :   /* Finish creating the initializer.  */
   10680        61987 :   vec_alloc (v, 2);
   10681        61987 :   CONSTRUCTOR_APPEND_ELT(v, pfn_field, pfn);
   10682        61987 :   CONSTRUCTOR_APPEND_ELT(v, delta_field, delta);
   10683        61987 :   u = build_constructor (type, v);
   10684        61987 :   TREE_CONSTANT (u) = TREE_CONSTANT (pfn) & TREE_CONSTANT (delta);
   10685        61987 :   TREE_STATIC (u) = (TREE_CONSTANT (u)
   10686        61849 :                      && (initializer_constant_valid_p (pfn, TREE_TYPE (pfn))
   10687              :                          != NULL_TREE)
   10688       123836 :                      && (initializer_constant_valid_p (delta, TREE_TYPE (delta))
   10689              :                          != NULL_TREE));
   10690        61987 :   return u;
   10691              : }
   10692              : 
   10693              : /* Build a constructor for a pointer to member function.  It can be
   10694              :    used to initialize global variables, local variable, or used
   10695              :    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
   10696              :    want to be.
   10697              : 
   10698              :    If FORCE is nonzero, then force this conversion, even if
   10699              :    we would rather not do it.  Usually set when using an explicit
   10700              :    cast.  A C-style cast is being processed iff C_CAST_P is true.
   10701              : 
   10702              :    Return error_mark_node, if something goes wrong.  */
   10703              : 
   10704              : tree
   10705        30338 : build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p,
   10706              :                   tsubst_flags_t complain)
   10707              : {
   10708        30338 :   tree fn;
   10709        30338 :   tree pfn_type;
   10710        30338 :   tree to_type;
   10711              : 
   10712        30338 :   if (error_operand_p (pfn))
   10713            0 :     return error_mark_node;
   10714              : 
   10715        30338 :   pfn_type = TREE_TYPE (pfn);
   10716        30338 :   to_type = build_ptrmemfunc_type (type);
   10717              : 
   10718              :   /* Handle multiple conversions of pointer to member functions.  */
   10719        30338 :   if (TYPE_PTRMEMFUNC_P (pfn_type))
   10720              :     {
   10721        28532 :       tree delta = NULL_TREE;
   10722        28532 :       tree npfn = NULL_TREE;
   10723        28532 :       tree n;
   10724              : 
   10725        28532 :       if (!force
   10726        28532 :           && !can_convert_arg (to_type, TREE_TYPE (pfn), pfn,
   10727              :                                LOOKUP_NORMAL, complain))
   10728              :         {
   10729            0 :           if (complain & tf_error)
   10730            0 :             error ("invalid conversion to type %qT from type %qT",
   10731              :                    to_type, pfn_type);
   10732              :           else
   10733            0 :             return error_mark_node;
   10734              :         }
   10735              : 
   10736        28532 :       n = get_delta_difference (TYPE_PTRMEMFUNC_OBJECT_TYPE (pfn_type),
   10737        28532 :                                 TYPE_PTRMEMFUNC_OBJECT_TYPE (to_type),
   10738              :                                 force,
   10739              :                                 c_cast_p, complain);
   10740        28532 :       if (n == error_mark_node)
   10741              :         return error_mark_node;
   10742              : 
   10743        28523 :       STRIP_ANY_LOCATION_WRAPPER (pfn);
   10744              : 
   10745              :       /* We don't have to do any conversion to convert a
   10746              :          pointer-to-member to its own type.  But, we don't want to
   10747              :          just return a PTRMEM_CST if there's an explicit cast; that
   10748              :          cast should make the expression an invalid template argument.  */
   10749        28523 :       if (TREE_CODE (pfn) != PTRMEM_CST
   10750        28523 :           && same_type_p (to_type, pfn_type))
   10751              :         return pfn;
   10752              : 
   10753        28523 :       if (TREE_SIDE_EFFECTS (pfn))
   10754           18 :         pfn = save_expr (pfn);
   10755              : 
   10756              :       /* Obtain the function pointer and the current DELTA.  */
   10757        28523 :       if (TREE_CODE (pfn) == PTRMEM_CST)
   10758        28409 :         expand_ptrmemfunc_cst (pfn, &delta, &npfn);
   10759              :       else
   10760              :         {
   10761          114 :           npfn = build_ptrmemfunc_access_expr (pfn, pfn_identifier);
   10762          114 :           delta = build_ptrmemfunc_access_expr (pfn, delta_identifier);
   10763              :         }
   10764              : 
   10765              :       /* Just adjust the DELTA field.  */
   10766        28523 :       gcc_assert  (same_type_ignoring_top_level_qualifiers_p
   10767              :                    (TREE_TYPE (delta), ptrdiff_type_node));
   10768        28523 :       if (!integer_zerop (n))
   10769              :         {
   10770           56 :           if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
   10771              :             n = cp_build_binary_op (input_location,
   10772              :                                     LSHIFT_EXPR, n, integer_one_node,
   10773              :                                     complain);
   10774           56 :           delta = cp_build_binary_op (input_location,
   10775              :                                       PLUS_EXPR, delta, n, complain);
   10776              :         }
   10777        28523 :       return build_ptrmemfunc1 (to_type, delta, npfn);
   10778              :     }
   10779              : 
   10780              :   /* Handle null pointer to member function conversions.  */
   10781         1806 :   if (null_ptr_cst_p (pfn))
   10782              :     {
   10783          674 :       pfn = cp_build_c_cast (input_location,
   10784          674 :                              TYPE_PTRMEMFUNC_FN_TYPE_RAW (to_type),
   10785              :                              pfn, complain);
   10786          674 :       return build_ptrmemfunc1 (to_type,
   10787              :                                 integer_zero_node,
   10788          674 :                                 pfn);
   10789              :     }
   10790              : 
   10791         1132 :   if (type_unknown_p (pfn))
   10792            0 :     return instantiate_type (type, pfn, complain);
   10793              : 
   10794         1132 :   fn = TREE_OPERAND (pfn, 0);
   10795         1132 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
   10796              :               /* In a template, we will have preserved the
   10797              :                  OFFSET_REF.  */
   10798              :               || (processing_template_decl && TREE_CODE (fn) == OFFSET_REF));
   10799         1132 :   return make_ptrmem_cst (to_type, fn);
   10800              : }
   10801              : 
   10802              : /* Return the DELTA, IDX, PFN, and DELTA2 values for the PTRMEM_CST
   10803              :    given by CST.
   10804              : 
   10805              :    ??? There is no consistency as to the types returned for the above
   10806              :    values.  Some code acts as if it were a sizetype and some as if it were
   10807              :    integer_type_node.  */
   10808              : 
   10809              : void
   10810        61605 : expand_ptrmemfunc_cst (tree cst, tree *delta, tree *pfn)
   10811              : {
   10812        61605 :   tree type = TREE_TYPE (cst);
   10813        61605 :   tree fn = PTRMEM_CST_MEMBER (cst);
   10814        61605 :   tree ptr_class, fn_class;
   10815              : 
   10816        61605 :   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL);
   10817              : 
   10818              :   /* The class that the function belongs to.  */
   10819        61605 :   fn_class = DECL_CONTEXT (fn);
   10820              : 
   10821              :   /* The class that we're creating a pointer to member of.  */
   10822        61605 :   ptr_class = TYPE_PTRMEMFUNC_OBJECT_TYPE (type);
   10823              : 
   10824              :   /* First, calculate the adjustment to the function's class.  */
   10825        61605 :   *delta = get_delta_difference (fn_class, ptr_class, /*force=*/0,
   10826              :                                  /*c_cast_p=*/0, tf_warning_or_error);
   10827              : 
   10828        61605 :   if (!DECL_VIRTUAL_P (fn))
   10829              :     {
   10830        60488 :       tree t = build_addr_func (fn, tf_warning_or_error);
   10831        60488 :       if (TREE_CODE (t) == ADDR_EXPR)
   10832        60488 :         SET_EXPR_LOCATION (t, PTRMEM_CST_LOCATION (cst));
   10833        60488 :       *pfn = convert (TYPE_PTRMEMFUNC_FN_TYPE (type), t);
   10834              :     }
   10835              :   else
   10836              :     {
   10837              :       /* If we're dealing with a virtual function, we have to adjust 'this'
   10838              :          again, to point to the base which provides the vtable entry for
   10839              :          fn; the call will do the opposite adjustment.  */
   10840         1117 :       tree orig_class = DECL_CONTEXT (fn);
   10841         1117 :       tree binfo = binfo_or_else (orig_class, fn_class);
   10842         1117 :       *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10843              :                             *delta, BINFO_OFFSET (binfo));
   10844              : 
   10845              :       /* We set PFN to the vtable offset at which the function can be
   10846              :          found, plus one (unless ptrmemfunc_vbit_in_delta, in which
   10847              :          case delta is shifted left, and then incremented).  */
   10848         1117 :       *pfn = DECL_VINDEX (fn);
   10849         1117 :       *pfn = fold_build2 (MULT_EXPR, integer_type_node, *pfn,
   10850              :                           TYPE_SIZE_UNIT (vtable_entry_type));
   10851              : 
   10852         1117 :       switch (TARGET_PTRMEMFUNC_VBIT_LOCATION)
   10853              :         {
   10854         1117 :         case ptrmemfunc_vbit_in_pfn:
   10855         1117 :           *pfn = fold_build2 (PLUS_EXPR, integer_type_node, *pfn,
   10856              :                               integer_one_node);
   10857         1117 :           break;
   10858              : 
   10859              :         case ptrmemfunc_vbit_in_delta:
   10860              :           *delta = fold_build2 (LSHIFT_EXPR, TREE_TYPE (*delta),
   10861              :                                 *delta, integer_one_node);
   10862              :           *delta = fold_build2 (PLUS_EXPR, TREE_TYPE (*delta),
   10863              :                                 *delta, integer_one_node);
   10864              :           break;
   10865              : 
   10866              :         default:
   10867              :           gcc_unreachable ();
   10868              :         }
   10869              : 
   10870         1117 :       *pfn = fold_convert (TYPE_PTRMEMFUNC_FN_TYPE (type), *pfn);
   10871              :     }
   10872        61605 : }
   10873              : 
   10874              : /* Return an expression for PFN from the pointer-to-member function
   10875              :    given by T.  */
   10876              : 
   10877              : static tree
   10878        87154 : pfn_from_ptrmemfunc (tree t)
   10879              : {
   10880        87154 :   if (TREE_CODE (t) == PTRMEM_CST)
   10881              :     {
   10882          203 :       tree delta;
   10883          203 :       tree pfn;
   10884              : 
   10885          203 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10886          203 :       if (pfn)
   10887          203 :         return pfn;
   10888              :     }
   10889              : 
   10890        86951 :   return build_ptrmemfunc_access_expr (t, pfn_identifier);
   10891              : }
   10892              : 
   10893              : /* Return an expression for DELTA from the pointer-to-member function
   10894              :    given by T.  */
   10895              : 
   10896              : static tree
   10897        87154 : delta_from_ptrmemfunc (tree t)
   10898              : {
   10899        87154 :   if (TREE_CODE (t) == PTRMEM_CST)
   10900              :     {
   10901          203 :       tree delta;
   10902          203 :       tree pfn;
   10903              : 
   10904          203 :       expand_ptrmemfunc_cst (t, &delta, &pfn);
   10905          203 :       if (delta)
   10906          203 :         return delta;
   10907              :     }
   10908              : 
   10909        86951 :   return build_ptrmemfunc_access_expr (t, delta_identifier);
   10910              : }
   10911              : 
   10912              : /* Convert value RHS to type TYPE as preparation for an assignment to
   10913              :    an lvalue of type TYPE.  ERRTYPE indicates what kind of error the
   10914              :    implicit conversion is.  If FNDECL is non-NULL, we are doing the
   10915              :    conversion in order to pass the PARMNUMth argument of FNDECL.
   10916              :    If FNDECL is NULL, we are doing the conversion in function pointer
   10917              :    argument passing, conversion in initialization, etc. */
   10918              : 
   10919              : static tree
   10920    184308215 : convert_for_assignment (tree type, tree rhs,
   10921              :                         impl_conv_rhs errtype, tree fndecl, int parmnum,
   10922              :                         tsubst_flags_t complain, int flags)
   10923              : {
   10924    184308215 :   tree rhstype;
   10925    184308215 :   enum tree_code coder;
   10926              : 
   10927    184308215 :   location_t rhs_loc = cp_expr_loc_or_input_loc (rhs);
   10928    184308215 :   bool has_loc = EXPR_LOCATION (rhs) != UNKNOWN_LOCATION;
   10929              :   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue,
   10930              :      but preserve location wrappers.  */
   10931    184308215 :   if (TREE_CODE (rhs) == NON_LVALUE_EXPR
   10932    184308215 :       && !location_wrapper_p (rhs))
   10933         8530 :     rhs = TREE_OPERAND (rhs, 0);
   10934              : 
   10935              :   /* Handle [dcl.init.list] direct-list-initialization from
   10936              :      single element of enumeration with a fixed underlying type.  */
   10937    184308215 :   if (is_direct_enum_init (type, rhs))
   10938              :     {
   10939           20 :       tree elt = CONSTRUCTOR_ELT (rhs, 0)->value;
   10940           20 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
   10941              :         {
   10942           11 :           warning_sentinel w (warn_useless_cast);
   10943           11 :           warning_sentinel w2 (warn_ignored_qualifiers);
   10944           11 :           rhs = cp_build_c_cast (rhs_loc, type, elt, complain);
   10945           11 :         }
   10946              :       else
   10947            9 :         rhs = error_mark_node;
   10948              :     }
   10949              : 
   10950    184308215 :   rhstype = TREE_TYPE (rhs);
   10951    184308215 :   coder = TREE_CODE (rhstype);
   10952              : 
   10953      1382153 :   if (VECTOR_TYPE_P (type) && coder == VECTOR_TYPE
   10954    185690214 :       && vector_types_convertible_p (type, rhstype, true))
   10955              :     {
   10956      1381990 :       rhs = mark_rvalue_use (rhs);
   10957      1381990 :       return convert (type, rhs);
   10958              :     }
   10959              : 
   10960    182926225 :   if (rhs == error_mark_node || rhstype == error_mark_node)
   10961              :     return error_mark_node;
   10962    182926216 :   if (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)
   10963              :     return error_mark_node;
   10964              : 
   10965              :   /* The RHS of an assignment cannot have void type.  */
   10966    182926216 :   if (coder == VOID_TYPE)
   10967              :     {
   10968           50 :       if (complain & tf_error)
   10969           30 :         error_at (rhs_loc, "void value not ignored as it ought to be");
   10970           50 :       return error_mark_node;
   10971              :     }
   10972              : 
   10973    182926166 :   if (c_dialect_objc ())
   10974              :     {
   10975            0 :       int parmno;
   10976            0 :       tree selector;
   10977            0 :       tree rname = fndecl;
   10978              : 
   10979            0 :       switch (errtype)
   10980              :         {
   10981              :           case ICR_ASSIGN:
   10982              :             parmno = -1;
   10983              :             break;
   10984            0 :           case ICR_INIT:
   10985            0 :             parmno = -2;
   10986            0 :             break;
   10987            0 :           default:
   10988            0 :             selector = objc_message_selector ();
   10989            0 :             parmno = parmnum;
   10990            0 :             if (selector && parmno > 1)
   10991              :               {
   10992            0 :                 rname = selector;
   10993            0 :                 parmno -= 1;
   10994              :               }
   10995              :         }
   10996              : 
   10997            0 :       if (objc_compare_types (type, rhstype, parmno, rname))
   10998              :         {
   10999            0 :           rhs = mark_rvalue_use (rhs);
   11000            0 :           return convert (type, rhs);
   11001              :         }
   11002              :     }
   11003              : 
   11004              :   /* [expr.ass]
   11005              : 
   11006              :      The expression is implicitly converted (clause _conv_) to the
   11007              :      cv-unqualified type of the left operand.
   11008              : 
   11009              :      We allow bad conversions here because by the time we get to this point
   11010              :      we are committed to doing the conversion.  If we end up doing a bad
   11011              :      conversion, convert_like will complain.  */
   11012    182926166 :   if (!can_convert_arg_bad (type, rhstype, rhs, flags, complain))
   11013              :     {
   11014              :       /* When -Wno-pmf-conversions is use, we just silently allow
   11015              :          conversions from pointers-to-members to plain pointers.  If
   11016              :          the conversion doesn't work, cp_convert will complain.  */
   11017         1698 :       if (!warn_pmf2ptr
   11018            9 :           && TYPE_PTR_P (type)
   11019         1707 :           && TYPE_PTRMEMFUNC_P (rhstype))
   11020            9 :         rhs = cp_convert (strip_top_quals (type), rhs, complain);
   11021              :       else
   11022              :         {
   11023         1689 :           if (complain & tf_error)
   11024              :             {
   11025         1364 :               auto_diagnostic_group d;
   11026              : 
   11027              :               /* If the right-hand side has unknown type, then it is an
   11028              :                  overloaded function.  Call instantiate_type to get error
   11029              :                  messages.  */
   11030         1364 :               if (rhstype == unknown_type_node)
   11031              :                 {
   11032          225 :                   tree r = instantiate_type (type, rhs, tf_warning_or_error);
   11033              :                   /* -fpermissive might allow this; recurse.  */
   11034          225 :                   if (!seen_error ())
   11035           15 :                     return convert_for_assignment (type, r, errtype, fndecl,
   11036              :                                                    parmnum, complain, flags);
   11037              :                 }
   11038         1139 :               else if (fndecl)
   11039          140 :                 complain_about_bad_argument (rhs_loc,
   11040              :                                              rhstype, type,
   11041              :                                              fndecl, parmnum);
   11042              :               else
   11043              :                 {
   11044          999 :                   range_label_for_type_mismatch label (rhstype, type);
   11045          999 :                   gcc_rich_location richloc
   11046              :                     (rhs_loc,
   11047              :                      has_loc ? &label : NULL,
   11048          999 :                      has_loc ? highlight_colors::percent_h : NULL);
   11049              : 
   11050          999 :                   switch (errtype)
   11051              :                     {
   11052            0 :                     case ICR_DEFAULT_ARGUMENT:
   11053            0 :                       error_at (&richloc,
   11054              :                                 "cannot convert %qH to %qI in default argument",
   11055              :                                 rhstype, type);
   11056            0 :                       break;
   11057            6 :                     case ICR_ARGPASS:
   11058            6 :                       error_at (&richloc,
   11059              :                                 "cannot convert %qH to %qI in argument passing",
   11060              :                                 rhstype, type);
   11061            6 :                       break;
   11062            0 :                     case ICR_CONVERTING:
   11063            0 :                       error_at (&richloc, "cannot convert %qH to %qI",
   11064              :                                 rhstype, type);
   11065            0 :                       break;
   11066          561 :                     case ICR_INIT:
   11067          561 :                       error_at (&richloc,
   11068              :                                 "cannot convert %qH to %qI in initialization",
   11069              :                                 rhstype, type);
   11070          561 :                       break;
   11071           18 :                     case ICR_RETURN:
   11072           18 :                       error_at (&richloc, "cannot convert %qH to %qI in return",
   11073              :                                 rhstype, type);
   11074           18 :                       break;
   11075          414 :                     case ICR_ASSIGN:
   11076          414 :                       error_at (&richloc,
   11077              :                                 "cannot convert %qH to %qI in assignment",
   11078              :                                 rhstype, type);
   11079          414 :                       break;
   11080            0 :                     default:
   11081            0 :                       gcc_unreachable();
   11082              :                   }
   11083          999 :                 }
   11084              : 
   11085              :               /* See if we can be more helpful.  */
   11086         1349 :               maybe_show_nonconverting_candidate (type, rhstype, rhs, flags);
   11087              : 
   11088         1349 :               if (TYPE_PTR_P (rhstype)
   11089          413 :                   && TYPE_PTR_P (type)
   11090          398 :                   && CLASS_TYPE_P (TREE_TYPE (rhstype))
   11091          280 :                   && CLASS_TYPE_P (TREE_TYPE (type))
   11092         1413 :                   && !COMPLETE_TYPE_P (TREE_TYPE (rhstype)))
   11093            3 :                 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL
   11094              :                                               (TREE_TYPE (rhstype))),
   11095            3 :                         "class type %qT is incomplete", TREE_TYPE (rhstype));
   11096         1364 :             }
   11097         1674 :           return error_mark_node;
   11098              :         }
   11099              :     }
   11100    182924477 :   if (warn_suggest_attribute_format)
   11101              :     {
   11102         2383 :       const enum tree_code codel = TREE_CODE (type);
   11103         2383 :       if ((codel == POINTER_TYPE || codel == REFERENCE_TYPE)
   11104          596 :           && coder == codel
   11105          508 :           && check_missing_format_attribute (type, rhstype)
   11106         2401 :           && (complain & tf_warning))
   11107           18 :         switch (errtype)
   11108              :           {
   11109            0 :             case ICR_ARGPASS:
   11110            0 :             case ICR_DEFAULT_ARGUMENT:
   11111            0 :               if (fndecl)
   11112            0 :                 warning (OPT_Wsuggest_attribute_format,
   11113              :                          "parameter %qP of %qD might be a candidate "
   11114              :                          "for a format attribute", parmnum, fndecl);
   11115              :               else
   11116            0 :                 warning (OPT_Wsuggest_attribute_format,
   11117              :                          "parameter might be a candidate "
   11118              :                          "for a format attribute");
   11119              :               break;
   11120            0 :             case ICR_CONVERTING:
   11121            0 :               warning (OPT_Wsuggest_attribute_format,
   11122              :                        "target of conversion might be a candidate "
   11123              :                        "for a format attribute");
   11124            0 :               break;
   11125            6 :             case ICR_INIT:
   11126            6 :               warning (OPT_Wsuggest_attribute_format,
   11127              :                        "target of initialization might be a candidate "
   11128              :                        "for a format attribute");
   11129            6 :               break;
   11130            6 :             case ICR_RETURN:
   11131            6 :               warning (OPT_Wsuggest_attribute_format,
   11132              :                        "return type might be a candidate "
   11133              :                        "for a format attribute");
   11134            6 :               break;
   11135            6 :             case ICR_ASSIGN:
   11136            6 :               warning (OPT_Wsuggest_attribute_format,
   11137              :                        "left-hand side of assignment might be a candidate "
   11138              :                        "for a format attribute");
   11139            6 :               break;
   11140            0 :             default:
   11141            0 :               gcc_unreachable();
   11142              :           }
   11143              :     }
   11144              : 
   11145    182924477 :   if (TREE_CODE (type) == BOOLEAN_TYPE)
   11146     37697374 :     maybe_warn_unparenthesized_assignment (rhs, /*nested_p=*/true, complain);
   11147              : 
   11148    182924477 :   if (complain & tf_warning)
   11149    180352032 :     warn_for_address_of_packed_member (type, rhs);
   11150              : 
   11151    182924477 :   return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
   11152    182924477 :                                             complain, flags);
   11153              : }
   11154              : 
   11155              : /* Convert RHS to be of type TYPE.
   11156              :    If EXP is nonzero, it is the target of the initialization.
   11157              :    ERRTYPE indicates what kind of error the implicit conversion is.
   11158              : 
   11159              :    Two major differences between the behavior of
   11160              :    `convert_for_assignment' and `convert_for_initialization'
   11161              :    are that references are bashed in the former, while
   11162              :    copied in the latter, and aggregates are assigned in
   11163              :    the former (operator=) while initialized in the
   11164              :    latter (X(X&)).
   11165              : 
   11166              :    If using constructor make sure no conversion operator exists, if one does
   11167              :    exist, an ambiguity exists.  */
   11168              : 
   11169              : tree
   11170    170515143 : convert_for_initialization (tree exp, tree type, tree rhs, int flags,
   11171              :                             impl_conv_rhs errtype, tree fndecl, int parmnum,
   11172              :                             tsubst_flags_t complain)
   11173              : {
   11174    170515143 :   enum tree_code codel = TREE_CODE (type);
   11175    170515143 :   tree rhstype;
   11176    170515143 :   enum tree_code coder;
   11177              : 
   11178              :   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
   11179              :      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
   11180    170515143 :   if (TREE_CODE (rhs) == NOP_EXPR
   11181      5937380 :       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
   11182    171005545 :       && codel != REFERENCE_TYPE)
   11183       490402 :     rhs = TREE_OPERAND (rhs, 0);
   11184              : 
   11185    170515143 :   if (type == error_mark_node
   11186    170515100 :       || rhs == error_mark_node
   11187    341030174 :       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
   11188              :     return error_mark_node;
   11189              : 
   11190    170515031 :   if (MAYBE_CLASS_TYPE_P (non_reference (type)))
   11191              :     ;
   11192    155925801 :   else if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
   11193      2396692 :             && TREE_CODE (type) != ARRAY_TYPE
   11194      2396692 :             && (!TYPE_REF_P (type)
   11195         1172 :                 || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
   11196    153530278 :            || (TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
   11197        26284 :                && !TYPE_REFFN_P (type))
   11198    309431030 :            || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
   11199      2420578 :     rhs = decay_conversion (rhs, complain);
   11200              : 
   11201    170515031 :   rhstype = TREE_TYPE (rhs);
   11202    170515031 :   coder = TREE_CODE (rhstype);
   11203              : 
   11204    170515031 :   if (coder == ERROR_MARK)
   11205            9 :     return error_mark_node;
   11206              : 
   11207              :   /* We accept references to incomplete types, so we can
   11208              :      return here before checking if RHS is of complete type.  */
   11209              : 
   11210    170515022 :   if (codel == REFERENCE_TYPE)
   11211              :     {
   11212      6048849 :       auto_diagnostic_group d;
   11213              :       /* This should eventually happen in convert_arguments.  */
   11214      6048849 :       int savew = 0, savee = 0;
   11215              : 
   11216      6048849 :       if (fndecl)
   11217       296555 :         savew = warningcount + werrorcount, savee = errorcount;
   11218      6048849 :       rhs = initialize_reference (type, rhs, flags, complain);
   11219              : 
   11220      6048849 :       if (fndecl
   11221      6048849 :           && (warningcount + werrorcount > savew || errorcount > savee))
   11222           36 :         inform (get_fndecl_argument_location (fndecl, parmnum),
   11223              :                 "in passing argument %P of %qD", parmnum, fndecl);
   11224      6048849 :       return rhs;
   11225      6048849 :     }
   11226              : 
   11227    164466173 :   if (exp != 0)
   11228      4256047 :     exp = require_complete_type (exp, complain);
   11229    164466173 :   if (exp == error_mark_node)
   11230              :     return error_mark_node;
   11231              : 
   11232    164466173 :   type = complete_type (type);
   11233              : 
   11234    164466173 :   if (DIRECT_INIT_EXPR_P (type, rhs))
   11235              :     /* Don't try to do copy-initialization if we already have
   11236              :        direct-initialization.  */
   11237              :     return rhs;
   11238              : 
   11239    164464740 :   if (MAYBE_CLASS_TYPE_P (type))
   11240     10510447 :     return perform_implicit_conversion_flags (type, rhs, complain, flags);
   11241              : 
   11242    153954293 :   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum,
   11243    153954293 :                                  complain, flags);
   11244              : }
   11245              : 
   11246              : /* If RETVAL is the address of, or a reference to, a local variable or
   11247              :    temporary give an appropriate warning and return true.  */
   11248              : 
   11249              : static bool
   11250     43803731 : maybe_warn_about_returning_address_of_local (tree retval, location_t loc)
   11251              : {
   11252     43804770 :   tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
   11253     43804770 :   tree whats_returned = fold_for_warn (retval);
   11254     43804770 :   if (!loc)
   11255     43804770 :     loc = cp_expr_loc_or_input_loc (retval);
   11256              : 
   11257     53331935 :   for (;;)
   11258              :     {
   11259     53331935 :       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
   11260       775236 :         whats_returned = TREE_OPERAND (whats_returned, 1);
   11261     52556699 :       else if (CONVERT_EXPR_P (whats_returned)
   11262     43822383 :                || TREE_CODE (whats_returned) == NON_LVALUE_EXPR)
   11263      8751929 :         whats_returned = TREE_OPERAND (whats_returned, 0);
   11264              :       else
   11265              :         break;
   11266              :     }
   11267              : 
   11268     43804770 :   if (TREE_CODE (whats_returned) == TARGET_EXPR
   11269     43804770 :       && is_std_init_list (TREE_TYPE (whats_returned)))
   11270              :     {
   11271           16 :       tree init = TARGET_EXPR_INITIAL (whats_returned);
   11272           16 :       if (TREE_CODE (init) == CONSTRUCTOR)
   11273              :         /* Pull out the array address.  */
   11274            7 :         whats_returned = CONSTRUCTOR_ELT (init, 0)->value;
   11275            9 :       else if (TREE_CODE (init) == INDIRECT_REF)
   11276              :         /* The source of a trivial copy looks like *(T*)&var.  */
   11277            6 :         whats_returned = TREE_OPERAND (init, 0);
   11278              :       else
   11279              :         return false;
   11280           13 :       STRIP_NOPS (whats_returned);
   11281              :     }
   11282              : 
   11283              :   /* As a special case, we handle a call to std::move or std::forward.  */
   11284     43804767 :   if (TREE_CODE (whats_returned) == CALL_EXPR
   11285     43804767 :       && (is_std_move_p (whats_returned)
   11286     10414508 :           || is_std_forward_p (whats_returned)))
   11287              :     {
   11288         1027 :       tree arg = CALL_EXPR_ARG (whats_returned, 0);
   11289         1027 :       return maybe_warn_about_returning_address_of_local (arg, loc);
   11290              :     }
   11291              : 
   11292     43803740 :   if (TREE_CODE (whats_returned) != ADDR_EXPR)
   11293              :     return false;
   11294       920786 :   whats_returned = TREE_OPERAND (whats_returned, 0);
   11295              : 
   11296       920786 :   while (TREE_CODE (whats_returned) == COMPONENT_REF
   11297      1787711 :          || TREE_CODE (whats_returned) == ARRAY_REF)
   11298       866925 :     whats_returned = TREE_OPERAND (whats_returned, 0);
   11299              : 
   11300       920786 :   if (TREE_CODE (whats_returned) == AGGR_INIT_EXPR
   11301       920786 :       || TREE_CODE (whats_returned) == TARGET_EXPR)
   11302              :     {
   11303           50 :       if (TYPE_REF_P (valtype))
   11304              :         /* P2748 made this an error in C++26.  */
   11305           72 :         emit_diagnostic ((cxx_dialect >= cxx26
   11306              :                           ? diagnostics::kind::permerror
   11307              :                           : diagnostics::kind::warning),
   11308           41 :                          loc, OPT_Wreturn_local_addr,
   11309              :                          "returning reference to temporary");
   11310            9 :       else if (TYPE_PTR_P (valtype))
   11311            3 :         warning_at (loc, OPT_Wreturn_local_addr,
   11312              :                     "returning pointer to temporary");
   11313            6 :       else if (is_std_init_list (valtype))
   11314            6 :         warning_at (loc, OPT_Winit_list_lifetime,
   11315              :                     "returning temporary %<initializer_list%> does not extend "
   11316              :                     "the lifetime of the underlying array");
   11317              :       return true;
   11318              :     }
   11319              : 
   11320       920736 :   STRIP_ANY_LOCATION_WRAPPER (whats_returned);
   11321              : 
   11322       920736 :   if (DECL_P (whats_returned)
   11323       120031 :       && DECL_NAME (whats_returned)
   11324       120031 :       && DECL_FUNCTION_SCOPE_P (whats_returned)
   11325        12387 :       && !is_capture_proxy (whats_returned)
   11326       933093 :       && !(TREE_STATIC (whats_returned)
   11327          161 :            || TREE_PUBLIC (whats_returned)))
   11328              :     {
   11329          114 :       if (DECL_DECOMPOSITION_P (whats_returned)
   11330           39 :           && !DECL_DECOMP_IS_BASE (whats_returned)
   11331          200 :           && DECL_HAS_VALUE_EXPR_P (whats_returned))
   11332              :         {
   11333              :           /* When returning address of a structured binding, if the structured
   11334              :              binding is not a reference, continue normally, if it is a
   11335              :              reference, recurse on the initializer of the structured
   11336              :              binding.  */
   11337           39 :           tree base = DECL_DECOMP_BASE (whats_returned);
   11338           39 :           if (TYPE_REF_P (TREE_TYPE (base)))
   11339              :             {
   11340           15 :               if (tree init = DECL_INITIAL (base))
   11341              :                 return maybe_warn_about_returning_address_of_local (init, loc);
   11342              :               else
   11343              :                 return false;
   11344              :             }
   11345              :         }
   11346          146 :       bool w = false;
   11347          146 :       auto_diagnostic_group d;
   11348          146 :       if (TYPE_REF_P (valtype))
   11349           89 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11350              :                         "reference to local variable %qD returned",
   11351              :                         whats_returned);
   11352           57 :       else if (is_std_init_list (valtype))
   11353            3 :         w = warning_at (loc, OPT_Winit_list_lifetime,
   11354              :                         "returning local %<initializer_list%> variable %qD "
   11355              :                         "does not extend the lifetime of the underlying array",
   11356              :                         whats_returned);
   11357           54 :       else if (POINTER_TYPE_P (valtype)
   11358           48 :                && TREE_CODE (whats_returned) == LABEL_DECL)
   11359            6 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11360              :                         "address of label %qD returned",
   11361              :                         whats_returned);
   11362           48 :       else if (POINTER_TYPE_P (valtype))
   11363           42 :         w = warning_at (loc, OPT_Wreturn_local_addr,
   11364              :                         "address of local variable %qD returned",
   11365              :                         whats_returned);
   11366          140 :       if (w)
   11367          117 :         inform (DECL_SOURCE_LOCATION (whats_returned),
   11368              :                 "declared here");
   11369          146 :       return true;
   11370          146 :     }
   11371              : 
   11372              :   return false;
   11373              : }
   11374              : 
   11375              : /* Returns true if DECL is in the std namespace.  */
   11376              : 
   11377              : bool
   11378     88423818 : decl_in_std_namespace_p (tree decl)
   11379              : {
   11380    102591549 :   while (decl)
   11381              :     {
   11382    102172481 :       decl = decl_namespace_context (decl);
   11383    102172481 :       if (DECL_NAMESPACE_STD_P (decl))
   11384              :         return true;
   11385              :       /* Allow inline namespaces inside of std namespace, e.g. with
   11386              :          --enable-symvers=gnu-versioned-namespace std::forward would be
   11387              :          actually std::_8::forward.  */
   11388     48634380 :       if (!DECL_NAMESPACE_INLINE_P (decl))
   11389              :         return false;
   11390     14167731 :       decl = CP_DECL_CONTEXT (decl);
   11391              :     }
   11392              :   return false;
   11393              : }
   11394              : 
   11395              : /* Returns true if FN, a CALL_EXPR, is a call to std::forward.  */
   11396              : 
   11397              : static bool
   11398     10414508 : is_std_forward_p (tree fn)
   11399              : {
   11400              :   /* std::forward only takes one argument.  */
   11401     10414508 :   if (call_expr_nargs (fn) != 1)
   11402              :     return false;
   11403              : 
   11404      4842791 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   11405      4842791 :   if (!decl_in_std_namespace_p (fndecl))
   11406              :     return false;
   11407              : 
   11408      1820457 :   tree name = DECL_NAME (fndecl);
   11409      1820457 :   return name && id_equal (name, "forward");
   11410              : }
   11411              : 
   11412              : /* Returns true if FN, a CALL_EXPR, is a call to std::move.  */
   11413              : 
   11414              : static bool
   11415     10422152 : is_std_move_p (tree fn)
   11416              : {
   11417              :   /* std::move only takes one argument.  */
   11418     10422152 :   if (call_expr_nargs (fn) != 1)
   11419              :     return false;
   11420              : 
   11421      4849656 :   tree fndecl = cp_get_callee_fndecl_nofold (fn);
   11422      4849656 :   if (!decl_in_std_namespace_p (fndecl))
   11423              :     return false;
   11424              : 
   11425      1826838 :   tree name = DECL_NAME (fndecl);
   11426      1826838 :   return name && id_equal (name, "move");
   11427              : }
   11428              : 
   11429              : /* Returns true if RETVAL is a good candidate for the NRVO as per
   11430              :    [class.copy.elision].  FUNCTYPE is the type the function is declared
   11431              :    to return.  */
   11432              : 
   11433              : static bool
   11434     56885739 : can_do_nrvo_p (tree retval, tree functype)
   11435              : {
   11436     56885739 :   if (functype == error_mark_node)
   11437              :     return false;
   11438     56885693 :   if (retval)
   11439     55210166 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   11440     56885693 :   tree result = DECL_RESULT (current_function_decl);
   11441     56885693 :   return (retval != NULL_TREE
   11442     55210166 :           && !processing_template_decl
   11443              :           /* Must be a local, automatic variable.  */
   11444     45302154 :           && VAR_P (retval)
   11445      3974087 :           && DECL_CONTEXT (retval) == current_function_decl
   11446      2901269 :           && !TREE_STATIC (retval)
   11447              :           /* And not a lambda or anonymous union proxy.  */
   11448      2898438 :           && !DECL_HAS_VALUE_EXPR_P (retval)
   11449      2898156 :           && (DECL_ALIGN (retval) <= DECL_ALIGN (result))
   11450              :           /* The cv-unqualified type of the returned value must be the
   11451              :              same as the cv-unqualified return type of the
   11452              :              function.  */
   11453      2898027 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   11454              :                           TYPE_MAIN_VARIANT (functype))
   11455              :           /* And the returned value must be non-volatile.  */
   11456     59760048 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   11457              : }
   11458              : 
   11459              : /* True if we would like to perform NRVO, i.e. can_do_nrvo_p is true and we
   11460              :    would otherwise return in memory.  */
   11461              : 
   11462              : static bool
   11463     56885369 : want_nrvo_p (tree retval, tree functype)
   11464              : {
   11465     56885369 :   return (can_do_nrvo_p (retval, functype)
   11466     56885369 :           && aggregate_value_p (functype, current_function_decl));
   11467              : }
   11468              : 
   11469              : /* Like can_do_nrvo_p, but we check if we're trying to move a class
   11470              :    prvalue.  */
   11471              : 
   11472              : static bool
   11473         1441 : can_elide_copy_prvalue_p (tree retval, tree functype)
   11474              : {
   11475         1441 :   if (functype == error_mark_node)
   11476              :     return false;
   11477         1441 :   if (retval)
   11478         1441 :     STRIP_ANY_LOCATION_WRAPPER (retval);
   11479         1441 :   return (retval != NULL_TREE
   11480         1441 :           && !glvalue_p (retval)
   11481          135 :           && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (retval)),
   11482              :                           TYPE_MAIN_VARIANT (functype))
   11483         1549 :           && !TYPE_VOLATILE (TREE_TYPE (retval)));
   11484              : }
   11485              : 
   11486              : /* If we should treat RETVAL, an expression being returned, as if it were
   11487              :    designated by an rvalue, returns it adjusted accordingly; otherwise, returns
   11488              :    NULL_TREE.  See [class.copy.elision].  RETURN_P is true if this is a return
   11489              :    context (rather than throw).  */
   11490              : 
   11491              : tree
   11492     11741003 : treat_lvalue_as_rvalue_p (tree expr, bool return_p)
   11493              : {
   11494     11741003 :   if (cxx_dialect == cxx98)
   11495              :     return NULL_TREE;
   11496              : 
   11497     11733130 :   tree retval = expr;
   11498     11733130 :   STRIP_ANY_LOCATION_WRAPPER (retval);
   11499     11733130 :   if (REFERENCE_REF_P (retval))
   11500       588826 :     retval = TREE_OPERAND (retval, 0);
   11501              : 
   11502              :   /* An implicitly movable entity is a variable of automatic storage duration
   11503              :      that is either a non-volatile object or (C++20) an rvalue reference to a
   11504              :      non-volatile object type.  */
   11505     11733130 :   if (!(((VAR_P (retval) && !DECL_HAS_VALUE_EXPR_P (retval))
   11506     10457967 :          || TREE_CODE (retval) == PARM_DECL)
   11507      1840175 :         && !TREE_STATIC (retval)
   11508      1745636 :         && !CP_TYPE_VOLATILE_P (non_reference (TREE_TYPE (retval)))
   11509      1745631 :         && (TREE_CODE (TREE_TYPE (retval)) != REFERENCE_TYPE
   11510       129077 :             || (cxx_dialect >= cxx20
   11511       128525 :                 && TYPE_REF_IS_RVALUE (TREE_TYPE (retval))))))
   11512              :     return NULL_TREE;
   11513              : 
   11514              :   /* If the expression in a return or co_return statement is a (possibly
   11515              :      parenthesized) id-expression that names an implicitly movable entity
   11516              :      declared in the body or parameter-declaration-clause of the innermost
   11517              :      enclosing function or lambda-expression, */
   11518      1617401 :   if (return_p)
   11519              :     {
   11520      1607962 :       if (DECL_CONTEXT (retval) != current_function_decl)
   11521              :         return NULL_TREE;
   11522      1607895 :       expr = move (expr);
   11523      1607895 :       if (expr == error_mark_node)
   11524              :         return NULL_TREE;
   11525      1607893 :       return set_implicit_rvalue_p (expr);
   11526              :     }
   11527              : 
   11528              :   /* if the id-expression (possibly parenthesized) is the operand of
   11529              :      a throw-expression, and names an implicitly movable entity that belongs
   11530              :      to a scope that does not contain the compound-statement of the innermost
   11531              :      lambda-expression, try-block, or function-try-block (if any) whose
   11532              :      compound-statement or ctor-initializer contains the throw-expression.  */
   11533              : 
   11534              :   /* C++20 added move on throw of parms.  */
   11535         9439 :   if (TREE_CODE (retval) == PARM_DECL && cxx_dialect < cxx20)
   11536              :     return NULL_TREE;
   11537              : 
   11538              :   /* We don't check for lambda-expression here, because we should not get past
   11539              :      the DECL_HAS_VALUE_EXPR_P check above.  */
   11540         9423 :   for (cp_binding_level *b = current_binding_level;
   11541         9519 :        b->kind != sk_namespace; b = b->level_chain)
   11542              :     {
   11543         9517 :       for (tree decl = b->names; decl; decl = TREE_CHAIN (decl))
   11544          103 :         if (decl == retval)
   11545           91 :           return set_implicit_rvalue_p (move (expr));
   11546         9414 :       if (b->kind == sk_try)
   11547              :         return NULL_TREE;
   11548              :     }
   11549              : 
   11550           14 :   return set_implicit_rvalue_p (move (expr));
   11551              : }
   11552              : 
   11553              : /* Warn about dubious usage of std::move (in a return statement, if RETURN_P
   11554              :    is true).  EXPR is the std::move expression; TYPE is the type of the object
   11555              :    being initialized.  */
   11556              : 
   11557              : void
   11558    156528935 : maybe_warn_pessimizing_move (tree expr, tree type, bool return_p)
   11559              : {
   11560    156528935 :   if (!(warn_pessimizing_move || warn_redundant_move))
   11561              :     return;
   11562              : 
   11563      4630679 :   const location_t loc = cp_expr_loc_or_input_loc (expr);
   11564              : 
   11565              :   /* C++98 doesn't know move.  */
   11566      4630679 :   if (cxx_dialect < cxx11)
   11567              :     return;
   11568              : 
   11569              :   /* Wait until instantiation time, since we can't gauge if we should do
   11570              :      the NRVO until then.  */
   11571      4567986 :   if (processing_template_decl)
   11572              :     return;
   11573              : 
   11574              :   /* This is only interesting for class types.  */
   11575      4478336 :   if (!CLASS_TYPE_P (type))
   11576              :     return;
   11577              : 
   11578       113126 :   bool wrapped_p = false;
   11579              :   /* A a = std::move (A());  */
   11580       113126 :   if (TREE_CODE (expr) == TREE_LIST)
   11581              :     {
   11582         8982 :       if (list_length (expr) == 1)
   11583              :         {
   11584         6001 :           expr = TREE_VALUE (expr);
   11585         6001 :           wrapped_p = true;
   11586              :         }
   11587              :       else
   11588              :         return;
   11589              :     }
   11590              :   /* A a = {std::move (A())};
   11591              :      A a{std::move (A())};  */
   11592       104144 :   else if (TREE_CODE (expr) == CONSTRUCTOR)
   11593              :     {
   11594         7969 :       if (CONSTRUCTOR_NELTS (expr) == 1)
   11595              :         {
   11596          890 :           expr = CONSTRUCTOR_ELT (expr, 0)->value;
   11597          890 :           wrapped_p = true;
   11598              :         }
   11599              :       else
   11600              :         return;
   11601              :     }
   11602              : 
   11603              :   /* First, check if this is a call to std::move.  */
   11604         6836 :   if (!REFERENCE_REF_P (expr)
   11605       107871 :       || TREE_CODE (TREE_OPERAND (expr, 0)) != CALL_EXPR)
   11606              :     return;
   11607         2710 :   tree fn = TREE_OPERAND (expr, 0);
   11608         2710 :   if (!is_std_move_p (fn))
   11609              :     return;
   11610         2084 :   tree arg = CALL_EXPR_ARG (fn, 0);
   11611         2084 :   if (TREE_CODE (arg) != NOP_EXPR)
   11612              :     return;
   11613              :   /* If we're looking at *std::move<T&> ((T &) &arg), do the pessimizing N/RVO
   11614              :      and implicitly-movable warnings.  */
   11615         2084 :   if (TREE_CODE (TREE_OPERAND (arg, 0)) == ADDR_EXPR)
   11616              :     {
   11617         1441 :       arg = TREE_OPERAND (arg, 0);
   11618         1441 :       arg = TREE_OPERAND (arg, 0);
   11619         1441 :       arg = convert_from_reference (arg);
   11620         1441 :       if (can_elide_copy_prvalue_p (arg, type))
   11621              :         {
   11622          108 :           auto_diagnostic_group d;
   11623          108 :           if (warning_at (loc, OPT_Wpessimizing_move,
   11624              :                           "moving a temporary object prevents copy elision"))
   11625          108 :             inform (loc, "remove %<std::move%> call");
   11626          108 :         }
   11627              :       /* The rest of the warnings is only relevant for when we are returning
   11628              :          from a function.  */
   11629         1441 :       if (!return_p)
   11630              :         return;
   11631              : 
   11632          370 :       tree moved;
   11633              :       /* Warn if we could do copy elision were it not for the move.  */
   11634          370 :       if (can_do_nrvo_p (arg, type))
   11635              :         {
   11636           48 :           auto_diagnostic_group d;
   11637           48 :           if (!warning_suppressed_p (expr, OPT_Wpessimizing_move)
   11638           48 :               && warning_at (loc, OPT_Wpessimizing_move,
   11639              :                              "moving a local object in a return statement "
   11640              :                              "prevents copy elision"))
   11641           42 :             inform (loc, "remove %<std::move%> call");
   11642           48 :         }
   11643              :       /* Warn if the move is redundant.  It is redundant when we would
   11644              :          do maybe-rvalue overload resolution even without std::move.  */
   11645          322 :       else if (warn_redundant_move
   11646              :                /* This doesn't apply for return {std::move (t)};.  */
   11647          224 :                && !wrapped_p
   11648          221 :                && !warning_suppressed_p (expr, OPT_Wredundant_move)
   11649          418 :                && (moved = treat_lvalue_as_rvalue_p (arg, /*return*/true)))
   11650              :         {
   11651              :           /* Make sure that overload resolution would actually succeed
   11652              :              if we removed the std::move call.  */
   11653           54 :           tree t = convert_for_initialization (NULL_TREE, type,
   11654              :                                                moved,
   11655              :                                                (LOOKUP_NORMAL
   11656              :                                                 | LOOKUP_ONLYCONVERTING),
   11657              :                                                ICR_RETURN, NULL_TREE, 0,
   11658              :                                                tf_none);
   11659              :           /* If this worked, implicit rvalue would work, so the call to
   11660              :              std::move is redundant.  */
   11661           54 :           if (t != error_mark_node)
   11662              :             {
   11663           54 :               auto_diagnostic_group d;
   11664           54 :               if (warning_at (loc, OPT_Wredundant_move,
   11665              :                               "redundant move in return statement"))
   11666           54 :                 inform (loc, "remove %<std::move%> call");
   11667           54 :             }
   11668              :         }
   11669              :      }
   11670              :   /* Also try to warn about redundant std::move in code such as
   11671              :       T f (const T& t)
   11672              :       {
   11673              :         return std::move(t);
   11674              :       }
   11675              :     for which EXPR will be something like
   11676              :       *std::move<const T&> ((const struct T &) (const struct T *) t)
   11677              :      and where the std::move does nothing if T does not have a T(const T&&)
   11678              :      constructor, because the argument is const.  It will not use T(T&&)
   11679              :      because that would mean losing the const.  */
   11680          643 :   else if (warn_redundant_move
   11681          521 :            && !warning_suppressed_p (expr, OPT_Wredundant_move)
   11682           66 :            && TYPE_REF_P (TREE_TYPE (arg))
   11683          709 :            && CP_TYPE_CONST_P (TREE_TYPE (TREE_TYPE (arg))))
   11684              :     {
   11685           18 :       tree rtype = TREE_TYPE (TREE_TYPE (arg));
   11686           18 :       if (!same_type_ignoring_top_level_qualifiers_p (rtype, type))
   11687            9 :         return;
   11688              :       /* Check for the unlikely case there's T(const T&&) (we don't care if
   11689              :          it's deleted).  */
   11690           54 :       for (tree fn : ovl_range (CLASSTYPE_CONSTRUCTORS (rtype)))
   11691           30 :         if (move_fn_p (fn))
   11692              :           {
   11693           15 :             tree t = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (fn));
   11694           15 :             if (UNLIKELY (CP_TYPE_CONST_P (TREE_TYPE (t))))
   11695            6 :               return;
   11696              :           }
   11697            9 :       auto_diagnostic_group d;
   11698           18 :       if (return_p
   11699            9 :           ? warning_at (loc, OPT_Wredundant_move,
   11700              :                         "redundant move in return statement")
   11701            9 :           : warning_at (loc, OPT_Wredundant_move,
   11702              :                         "redundant move in initialization"))
   11703            9 :         inform (loc, "remove %<std::move%> call");
   11704            9 :     }
   11705              : }
   11706              : 
   11707              : /* Check that returning RETVAL from the current function is valid.
   11708              :    Return an expression explicitly showing all conversions required to
   11709              :    change RETVAL into the function return type, and to assign it to
   11710              :    the DECL_RESULT for the function.  Set *NO_WARNING to true if
   11711              :    code reaches end of non-void function warning shouldn't be issued
   11712              :    on this RETURN_EXPR.  Set *DANGLING to true if code returns the
   11713              :    address of a local variable.  */
   11714              : 
   11715              : tree
   11716    131695111 : check_return_expr (tree retval, bool *no_warning, bool *dangling)
   11717              : {
   11718    131695111 :   tree result;
   11719              :   /* The type actually returned by the function.  */
   11720    131695111 :   tree valtype;
   11721              :   /* The type the function is declared to return, or void if
   11722              :      the declared type is incomplete.  */
   11723    131695111 :   tree functype;
   11724    131695111 :   int fn_returns_value_p;
   11725    131695111 :   location_t loc = cp_expr_loc_or_input_loc (retval);
   11726              : 
   11727    131695111 :   *no_warning = false;
   11728    131695111 :   *dangling = false;
   11729              : 
   11730              :   /* A `volatile' function is one that isn't supposed to return, ever.
   11731              :      (This is a G++ extension, used to get better code for functions
   11732              :      that call the `volatile' function.)  */
   11733    131695111 :   if (TREE_THIS_VOLATILE (current_function_decl))
   11734           12 :     warning (0, "function declared %<noreturn%> has a %<return%> statement");
   11735              : 
   11736              :   /* Check for various simple errors.  */
   11737    263390222 :   if (DECL_DESTRUCTOR_P (current_function_decl))
   11738              :     {
   11739         3577 :       if (retval)
   11740            3 :         error_at (loc, "returning a value from a destructor");
   11741              : 
   11742         3577 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11743            0 :         retval = current_class_ptr;
   11744              :       else
   11745              :         return NULL_TREE;
   11746              :     }
   11747    131691534 :   else if (DECL_CONSTRUCTOR_P (current_function_decl))
   11748              :     {
   11749       162738 :       if (in_function_try_handler)
   11750              :         /* If a return statement appears in a handler of the
   11751              :            function-try-block of a constructor, the program is ill-formed.  */
   11752            0 :         error ("cannot return from a handler of a function-try-block of a constructor");
   11753       162738 :       else if (retval)
   11754              :         /* You can't return a value from a constructor.  */
   11755            3 :         error_at (loc, "returning a value from a constructor");
   11756              : 
   11757       162738 :       if (targetm.cxx.cdtor_returns_this () && !processing_template_decl)
   11758            0 :         retval = current_class_ptr;
   11759              :       else
   11760              :         return NULL_TREE;
   11761              :     }
   11762              : 
   11763    131528796 :   const tree saved_retval = retval;
   11764              : 
   11765    131528796 :   if (processing_template_decl)
   11766              :     {
   11767              :       /* If in expansion statement body, we don't know if the body
   11768              :          will be instantiated at all.  */
   11769     85528919 :       if (in_expansion_stmt)
   11770           82 :         goto dependent;
   11771              : 
   11772     85528837 :       current_function_returns_value = 1;
   11773              : 
   11774     85528837 :       if (check_for_bare_parameter_packs (retval))
   11775           14 :         return error_mark_node;
   11776              : 
   11777              :       /* If one of the types might be void, we can't tell whether we're
   11778              :          returning a value.  */
   11779     85528823 :       if ((WILDCARD_TYPE_P (TREE_TYPE (DECL_RESULT (current_function_decl)))
   11780     35909968 :            && !FNDECL_USED_AUTO (current_function_decl))
   11781     49618855 :           || (retval != NULL_TREE
   11782     48472176 :               && (TREE_TYPE (retval) == NULL_TREE
   11783     33499766 :                   || WILDCARD_TYPE_P (TREE_TYPE (retval)))))
   11784     58130407 :         goto dependent;
   11785              :     }
   11786              : 
   11787     73398293 :   functype = TREE_TYPE (TREE_TYPE (current_function_decl));
   11788              : 
   11789              :   /* Deduce auto return type from a return statement.  */
   11790     73398293 :   if (FNDECL_USED_AUTO (current_function_decl))
   11791              :     {
   11792      1289761 :       tree pattern = DECL_SAVED_AUTO_RETURN_TYPE (current_function_decl);
   11793      1289761 :       tree auto_node;
   11794      1289761 :       tree type;
   11795              : 
   11796      1289761 :       if (!retval && !is_auto (pattern))
   11797              :         {
   11798              :           /* Give a helpful error message.  */
   11799            3 :           auto_diagnostic_group d;
   11800            3 :           error ("return-statement with no value, in function returning %qT",
   11801              :                  pattern);
   11802            3 :           inform (input_location, "only plain %<auto%> return type can be "
   11803              :                   "deduced to %<void%>");
   11804            3 :           type = error_mark_node;
   11805            3 :         }
   11806      1289758 :       else if (retval && BRACE_ENCLOSED_INITIALIZER_P (retval))
   11807              :         {
   11808            6 :           error ("returning initializer list");
   11809            6 :           type = error_mark_node;
   11810              :         }
   11811              :       else
   11812              :         {
   11813      1289752 :           if (!retval)
   11814         2600 :             retval = void_node;
   11815      1289752 :           auto_node = type_uses_auto (pattern);
   11816      1289752 :           type = do_auto_deduction (pattern, retval, auto_node,
   11817              :                                     tf_warning_or_error, adc_return_type);
   11818              :         }
   11819              : 
   11820      1289761 :       if (type == error_mark_node)
   11821              :         /* Leave it.  */;
   11822      1289513 :       else if (functype == pattern)
   11823      1051081 :         apply_deduced_return_type (current_function_decl, type);
   11824       238432 :       else if (!same_type_p (type, functype))
   11825              :         {
   11826           24 :           if (LAMBDA_FUNCTION_P (current_function_decl))
   11827            6 :             error_at (loc, "inconsistent types %qT and %qT deduced for "
   11828              :                       "lambda return type", functype, type);
   11829              :           else
   11830           12 :             error_at (loc, "inconsistent deduction for auto return type: "
   11831              :                       "%qT and then %qT", functype, type);
   11832              :         }
   11833              :       functype = type;
   11834              :     }
   11835              : 
   11836     73398293 :   result = DECL_RESULT (current_function_decl);
   11837     73398293 :   valtype = TREE_TYPE (result);
   11838     73398293 :   gcc_assert (valtype != NULL_TREE);
   11839     73398293 :   fn_returns_value_p = !VOID_TYPE_P (valtype);
   11840              : 
   11841              :   /* Check for a return statement with no return value in a function
   11842              :      that's supposed to return a value.  */
   11843     73398293 :   if (!retval && fn_returns_value_p)
   11844              :     {
   11845           33 :       if (functype != error_mark_node)
   11846           30 :         permerror (input_location, "return-statement with no value, in "
   11847              :                    "function returning %qT", valtype);
   11848              :       /* Remember that this function did return.  */
   11849           33 :       current_function_returns_value = 1;
   11850              :       /* But suppress NRV  .*/
   11851           33 :       current_function_return_value = error_mark_node;
   11852              :       /* And signal caller that TREE_NO_WARNING should be set on the
   11853              :          RETURN_EXPR to avoid control reaches end of non-void function
   11854              :          warnings in tree-cfg.cc.  */
   11855           33 :       *no_warning = true;
   11856              :     }
   11857              :   /* Check for a return statement with a value in a function that
   11858              :      isn't supposed to return a value.  */
   11859     73398260 :   else if (retval && !fn_returns_value_p)
   11860              :     {
   11861       177774 :       if (VOID_TYPE_P (TREE_TYPE (retval)))
   11862              :         /* You can return a `void' value from a function of `void'
   11863              :            type.  In that case, we have to evaluate the expression for
   11864              :            its side-effects.  */
   11865       177735 :         finish_expr_stmt (retval);
   11866           39 :       else if (retval != error_mark_node)
   11867           36 :         permerror (loc, "return-statement with a value, in function "
   11868              :                    "returning %qT", valtype);
   11869       177774 :       current_function_returns_null = 1;
   11870              : 
   11871              :       /* There's really no value to return, after all.  */
   11872       177774 :       return NULL_TREE;
   11873              :     }
   11874     73220486 :   else if (!retval)
   11875              :     /* Remember that this function can sometimes return without a
   11876              :        value.  */
   11877      1675512 :     current_function_returns_null = 1;
   11878              :   else
   11879              :     /* Remember that this function did return a value.  */
   11880     71544974 :     current_function_returns_value = 1;
   11881              : 
   11882              :   /* Check for erroneous operands -- but after giving ourselves a
   11883              :      chance to provide an error about returning a value from a void
   11884              :      function.  */
   11885     73220519 :   if (error_operand_p (retval))
   11886              :     {
   11887         1101 :       current_function_return_value = error_mark_node;
   11888         1101 :       return error_mark_node;
   11889              :     }
   11890              : 
   11891              :   /* Only operator new(...) throw(), can return NULL [expr.new/13].  */
   11892    146438836 :   if (IDENTIFIER_NEW_OP_P (DECL_NAME (current_function_decl))
   11893        32016 :       && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
   11894         2679 :       && ! flag_check_new
   11895     73222088 :       && retval && null_ptr_cst_p (retval))
   11896           24 :     warning (0, "%<operator new%> must not return NULL unless it is "
   11897              :              "declared %<throw()%> (or %<-fcheck-new%> is in effect)");
   11898              : 
   11899              :   /* Effective C++ rule 15.  See also start_function.  */
   11900     73219418 :   if (warn_ecpp
   11901           42 :       && DECL_NAME (current_function_decl) == assign_op_identifier
   11902     73219448 :       && !type_dependent_expression_p (retval))
   11903              :     {
   11904           27 :       bool warn = true;
   11905              : 
   11906              :       /* The function return type must be a reference to the current
   11907              :         class.  */
   11908           27 :       if (TYPE_REF_P (valtype)
   11909           45 :           && same_type_ignoring_top_level_qualifiers_p
   11910           18 :               (TREE_TYPE (valtype), TREE_TYPE (current_class_ref)))
   11911              :         {
   11912              :           /* Returning '*this' is obviously OK.  */
   11913           18 :           if (retval == current_class_ref)
   11914              :             warn = false;
   11915              :           /* If we are calling a function whose return type is the same of
   11916              :              the current class reference, it is ok.  */
   11917            6 :           else if (INDIRECT_REF_P (retval)
   11918            6 :                    && TREE_CODE (TREE_OPERAND (retval, 0)) == CALL_EXPR)
   11919              :             warn = false;
   11920              :         }
   11921              : 
   11922              :       if (warn)
   11923            9 :         warning_at (loc, OPT_Weffc__,
   11924              :                     "%<operator=%> should return a reference to %<*this%>");
   11925              :     }
   11926              : 
   11927     73219418 :   if (dependent_type_p (functype)
   11928     73219418 :       || type_dependent_expression_p (retval))
   11929              :     {
   11930     74464538 :     dependent:
   11931              :       /* We should not have changed the return value.  */
   11932     74464538 :       gcc_assert (retval == saved_retval);
   11933              :       /* We don't know if this is an lvalue or rvalue use, but
   11934              :          either way we can mark it as read.  */
   11935     74464538 :       mark_exp_read (retval);
   11936     74464538 :       return retval;
   11937              :     }
   11938              : 
   11939              :   /* The fabled Named Return Value optimization, as per [class.copy]/15:
   11940              : 
   11941              :      [...]      For  a function with a class return type, if the expression
   11942              :      in the return statement is the name of a local  object,  and  the  cv-
   11943              :      unqualified  type  of  the  local  object  is the same as the function
   11944              :      return type, an implementation is permitted to omit creating the  tem-
   11945              :      porary  object  to  hold  the function return value [...]
   11946              : 
   11947              :      So, if this is a value-returning function that always returns the same
   11948              :      local variable, remember it.
   11949              : 
   11950              :      We choose the first suitable variable even if the function sometimes
   11951              :      returns something else, but only if the variable is out of scope at the
   11952              :      other return sites, or else we run the risk of clobbering the variable we
   11953              :      chose if the other returned expression uses the chosen variable somehow.
   11954              : 
   11955              :      We don't currently do this if the first return is a non-variable, as it
   11956              :      would be complicated to determine whether an NRV selected later was in
   11957              :      scope at the point of the earlier return.  We also don't currently support
   11958              :      multiple variables with non-overlapping scopes (53637).
   11959              : 
   11960              :      See finish_function and finalize_nrv for the rest of this optimization.  */
   11961     56885369 :   tree bare_retval = NULL_TREE;
   11962     56885369 :   if (retval)
   11963              :     {
   11964     55209839 :       retval = maybe_undo_parenthesized_ref (retval);
   11965     55209839 :       bare_retval = tree_strip_any_location_wrapper (retval);
   11966              :     }
   11967              : 
   11968     56885369 :   bool named_return_value_okay_p = want_nrvo_p (bare_retval, functype);
   11969     56885369 :   if (fn_returns_value_p && flag_elide_constructors
   11970     55209816 :       && current_function_return_value != bare_retval)
   11971              :     {
   11972     55203743 :       if (named_return_value_okay_p
   11973       270224 :           && current_function_return_value == NULL_TREE)
   11974       229630 :         current_function_return_value = bare_retval;
   11975     54974113 :       else if (current_function_return_value
   11976     11182396 :                && VAR_P (current_function_return_value)
   11977          209 :                && DECL_NAME (current_function_return_value)
   11978     54974322 :                && !decl_in_scope_p (current_function_return_value))
   11979              :         {
   11980              :           /* The earlier NRV is out of scope at this point, so it's safe to
   11981          145 :              leave it alone; the current return can't refer to it.  */;
   11982          145 :           if (named_return_value_okay_p
   11983          145 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11984              :             {
   11985           12 :               warning (OPT_Wnrvo, "not eliding copy on return from %qD",
   11986              :                        bare_retval);
   11987           12 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   11988              :             }
   11989              :         }
   11990              :       else
   11991              :         {
   11992     54973968 :           if ((named_return_value_okay_p
   11993     54933388 :                || (current_function_return_value
   11994     11141671 :                    && current_function_return_value != error_mark_node))
   11995     54974010 :               && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
   11996              :             {
   11997        40545 :               warning (OPT_Wnrvo, "not eliding copy on return in %qD",
   11998              :                        current_function_decl);
   11999        40545 :               suppress_warning (current_function_decl, OPT_Wnrvo);
   12000              :             }
   12001     54973968 :           current_function_return_value = error_mark_node;
   12002              :         }
   12003              :     }
   12004              : 
   12005              :   /* We don't need to do any conversions when there's nothing being
   12006              :      returned.  */
   12007     56885369 :   if (!retval)
   12008              :     return NULL_TREE;
   12009              : 
   12010     55209839 :   if (!named_return_value_okay_p)
   12011     54933542 :     maybe_warn_pessimizing_move (retval, functype, /*return_p*/true);
   12012              : 
   12013              :   /* Do any required conversions.  */
   12014    110419678 :   if (bare_retval == result || DECL_CONSTRUCTOR_P (current_function_decl))
   12015              :     /* No conversions are required.  */
   12016              :     ;
   12017              :   else
   12018              :     {
   12019     55209839 :       int flags = LOOKUP_NORMAL | LOOKUP_ONLYCONVERTING;
   12020              : 
   12021              :       /* The functype's return type will have been set to void, if it
   12022              :          was an incomplete type.  Just treat this as 'return;' */
   12023     55209839 :       if (VOID_TYPE_P (functype))
   12024            6 :         return error_mark_node;
   12025              : 
   12026              :       /* Under C++11 [12.8/32 class.copy], a returned lvalue is sometimes
   12027              :          treated as an rvalue for the purposes of overload resolution to
   12028              :          favor move constructors over copy constructors.
   12029              : 
   12030              :          Note that these conditions are similar to, but not as strict as,
   12031              :          the conditions for the named return value optimization.  */
   12032     55209833 :       bool converted = false;
   12033     55209833 :       tree moved;
   12034              :       /* Until C++23, this was only interesting for class type, but in C++23,
   12035              :          we should do the below when we're converting from/to a class/reference
   12036              :          (a non-scalar type).  */
   12037     55209833 :         if ((cxx_dialect < cxx23
   12038      7793339 :              ? CLASS_TYPE_P (functype)
   12039     10115301 :              : !SCALAR_TYPE_P (functype) || !SCALAR_TYPE_P (TREE_TYPE (retval)))
   12040     66106036 :             && (moved = treat_lvalue_as_rvalue_p (retval, /*return*/true)))
   12041              :           /* In C++20 and earlier we treat the return value as an rvalue
   12042              :              that can bind to lvalue refs.  In C++23, such an expression is just
   12043              :              an xvalue (see reference_binding).  */
   12044              :           retval = moved;
   12045              : 
   12046              :       /* The call in a (lambda) thunk needs no conversions.  */
   12047     55209833 :       if (TREE_CODE (retval) == CALL_EXPR
   12048     55209833 :           && call_from_lambda_thunk_p (retval))
   12049              :         converted = true;
   12050              : 
   12051              :       /* Don't check copy-initialization for NRV in a coroutine ramp; we
   12052              :          implement this case as NRV, but it's specified as directly
   12053              :          initializing the return value from get_return_object().  */
   12054     55209833 :       if (DECL_RAMP_P (current_function_decl) && named_return_value_okay_p)
   12055              :         converted = true;
   12056              : 
   12057              :       /* First convert the value to the function's return type, then
   12058              :          to the type of return value's location to handle the
   12059              :          case that functype is smaller than the valtype.  */
   12060     55209571 :       if (!converted)
   12061     55153222 :         retval = convert_for_initialization
   12062     55153222 :           (NULL_TREE, functype, retval, flags, ICR_RETURN, NULL_TREE, 0,
   12063              :            tf_warning_or_error);
   12064     55209833 :       retval = convert (valtype, retval);
   12065              : 
   12066              :       /* If the conversion failed, treat this just like `return;'.  */
   12067     55209833 :       if (retval == error_mark_node)
   12068              :         {
   12069              :           /* And suppress NRV.  */
   12070          213 :           current_function_return_value = error_mark_node;
   12071          213 :           return retval;
   12072              :         }
   12073              :       /* We can't initialize a register from a AGGR_INIT_EXPR.  */
   12074     55209620 :       else if (! cfun->returns_struct
   12075     53065123 :                && TREE_CODE (retval) == TARGET_EXPR
   12076     62046880 :                && TREE_CODE (TARGET_EXPR_INITIAL (retval)) == AGGR_INIT_EXPR)
   12077      1497889 :         retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval,
   12078      1497889 :                          TARGET_EXPR_SLOT (retval));
   12079     53711731 :       else if (!processing_template_decl
   12080     43803731 :                && maybe_warn_about_returning_address_of_local (retval, loc)
   12081     53711927 :                && INDIRECT_TYPE_P (valtype))
   12082          181 :         *dangling = true;
   12083              :     }
   12084              : 
   12085              :   /* A naive attempt to reduce the number of -Wdangling-reference false
   12086              :      positives: if we know that this function can return a variable with
   12087              :      static storage duration rather than one of its parameters, suppress
   12088              :      the warning.  */
   12089     55209620 :   if (warn_dangling_reference
   12090       415787 :       && TYPE_REF_P (functype)
   12091        27671 :       && bare_retval
   12092        27671 :       && VAR_P (bare_retval)
   12093           50 :       && TREE_STATIC (bare_retval))
   12094           50 :     suppress_warning (current_function_decl, OPT_Wdangling_reference);
   12095              : 
   12096     55209620 :   if (processing_template_decl)
   12097              :     return saved_retval;
   12098              : 
   12099              :   /* Actually copy the value returned into the appropriate location.  */
   12100     45301620 :   if (retval && retval != result)
   12101     45301620 :     retval = cp_build_init_expr (result, retval);
   12102              : 
   12103     45301620 :   if (current_function_return_value == bare_retval)
   12104       235697 :     INIT_EXPR_NRV_P (retval) = true;
   12105              : 
   12106     45301620 :   if (tree set = maybe_set_retval_sentinel ())
   12107       133263 :     retval = build2 (COMPOUND_EXPR, void_type_node, retval, set);
   12108              : 
   12109              :   return retval;
   12110              : }
   12111              : 
   12112              : 
   12113              : /* Returns nonzero if the pointer-type FROM can be converted to the
   12114              :    pointer-type TO via a qualification conversion.  If CONSTP is -1,
   12115              :    then we return nonzero if the pointers are similar, and the
   12116              :    cv-qualification signature of FROM is a proper subset of that of TO.
   12117              : 
   12118              :    If CONSTP is positive, then all outer pointers have been
   12119              :    const-qualified.  */
   12120              : 
   12121              : static bool
   12122    195278980 : comp_ptr_ttypes_real (tree to, tree from, int constp)
   12123              : {
   12124    195278980 :   bool to_more_cv_qualified = false;
   12125    195278980 :   bool is_opaque_pointer = false;
   12126              : 
   12127       667917 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   12128              :     {
   12129    195946897 :       if (TREE_CODE (to) != TREE_CODE (from))
   12130              :         return false;
   12131              : 
   12132    129516882 :       if (TREE_CODE (from) == OFFSET_TYPE
   12133    129516882 :           && !same_type_p (TYPE_OFFSET_BASETYPE (from),
   12134              :                            TYPE_OFFSET_BASETYPE (to)))
   12135              :         return false;
   12136              : 
   12137              :       /* Const and volatile mean something different for function and
   12138              :          array types, so the usual checks are not appropriate.  We'll
   12139              :          check the array type elements in further iterations.  */
   12140    129516882 :       if (!FUNC_OR_METHOD_TYPE_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   12141              :         {
   12142    129266386 :           if (!at_least_as_qualified_p (to, from))
   12143              :             return false;
   12144              : 
   12145    115076493 :           if (!at_least_as_qualified_p (from, to))
   12146              :             {
   12147     78036300 :               if (constp == 0)
   12148              :                 return false;
   12149              :               to_more_cv_qualified = true;
   12150              :             }
   12151              : 
   12152    115076224 :           if (constp > 0)
   12153    115071892 :             constp &= TYPE_READONLY (to);
   12154              :         }
   12155              : 
   12156    115326720 :       if (VECTOR_TYPE_P (to))
   12157        10121 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   12158              : 
   12159              :       /* P0388R4 allows a conversion from int[N] to int[] but not the
   12160              :          other way round.  When both arrays have bounds but they do
   12161              :          not match, then no conversion is possible.  */
   12162    115326720 :       if (TREE_CODE (to) == ARRAY_TYPE
   12163    115326720 :           && !comp_array_types (to, from, bounds_first, /*strict=*/false))
   12164              :         return false;
   12165              : 
   12166    115325882 :       if (!TYPE_PTR_P (to)
   12167              :           && !TYPE_PTRDATAMEM_P (to)
   12168              :           /* CWG 330 says we need to look through arrays.  */
   12169              :           && TREE_CODE (to) != ARRAY_TYPE)
   12170    114657965 :         return ((constp >= 0 || to_more_cv_qualified)
   12171    114657965 :                 && (is_opaque_pointer
   12172    114657367 :                     || same_type_ignoring_top_level_qualifiers_p (to, from)));
   12173              :     }
   12174              : }
   12175              : 
   12176              : /* When comparing, say, char ** to char const **, this function takes
   12177              :    the 'char *' and 'char const *'.  Do not pass non-pointer/reference
   12178              :    types to this function.  */
   12179              : 
   12180              : int
   12181    195278284 : comp_ptr_ttypes (tree to, tree from)
   12182              : {
   12183    195278284 :   return comp_ptr_ttypes_real (to, from, 1);
   12184              : }
   12185              : 
   12186              : /* Returns true iff FNTYPE is a non-class type that involves
   12187              :    error_mark_node.  We can get FUNCTION_TYPE with buried error_mark_node
   12188              :    if a parameter type is ill-formed.  */
   12189              : 
   12190              : bool
   12191       715642 : error_type_p (const_tree type)
   12192              : {
   12193       756384 :   tree t;
   12194              : 
   12195       756384 :   switch (TREE_CODE (type))
   12196              :     {
   12197              :     case ERROR_MARK:
   12198              :       return true;
   12199              : 
   12200        40653 :     case POINTER_TYPE:
   12201        40653 :     case REFERENCE_TYPE:
   12202        40653 :     case OFFSET_TYPE:
   12203        40653 :       return error_type_p (TREE_TYPE (type));
   12204              : 
   12205         3263 :     case FUNCTION_TYPE:
   12206         3263 :     case METHOD_TYPE:
   12207         3263 :       if (error_type_p (TREE_TYPE (type)))
   12208              :         return true;
   12209         8816 :       for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
   12210         5559 :         if (error_type_p (TREE_VALUE (t)))
   12211              :           return true;
   12212              :       return false;
   12213              : 
   12214       190531 :     case RECORD_TYPE:
   12215       190531 :       if (TYPE_PTRMEMFUNC_P (type))
   12216           89 :         return error_type_p (TYPE_PTRMEMFUNC_FN_TYPE (type));
   12217              :       return false;
   12218              : 
   12219              :     default:
   12220              :       return false;
   12221              :     }
   12222              : }
   12223              : 
   12224              : /* Returns true if to and from are (possibly multi-level) pointers to the same
   12225              :    type or inheritance-related types, regardless of cv-quals.  */
   12226              : 
   12227              : bool
   12228    140702386 : ptr_reasonably_similar (const_tree to, const_tree from)
   12229              : {
   12230         1548 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   12231              :     {
   12232              :       /* Any target type is similar enough to void.  */
   12233    140703934 :       if (VOID_TYPE_P (to))
   12234         2100 :         return !error_type_p (from);
   12235    140701834 :       if (VOID_TYPE_P (from))
   12236       702430 :         return !error_type_p (to);
   12237              : 
   12238    139999404 :       if (TREE_CODE (to) != TREE_CODE (from))
   12239              :         return false;
   12240              : 
   12241     74131488 :       if (TREE_CODE (from) == OFFSET_TYPE
   12242     74131488 :           && comptypes (TYPE_OFFSET_BASETYPE (to),
   12243            3 :                         TYPE_OFFSET_BASETYPE (from),
   12244              :                         COMPARE_BASE | COMPARE_DERIVED))
   12245            3 :         continue;
   12246              : 
   12247     74131482 :       if (VECTOR_TYPE_P (to)
   12248     74131482 :           && vector_types_convertible_p (to, from, false))
   12249              :         return true;
   12250              : 
   12251     74131398 :       if (TREE_CODE (to) == INTEGER_TYPE
   12252     74131398 :           && TYPE_PRECISION (to) == TYPE_PRECISION (from))
   12253              :         return true;
   12254              : 
   12255     73929706 :       if (TREE_CODE (to) == FUNCTION_TYPE)
   12256         1145 :         return !error_type_p (to) && !error_type_p (from);
   12257              : 
   12258     73928561 :       if (!TYPE_PTR_P (to))
   12259              :         {
   12260              :           /* When either type is incomplete avoid DERIVED_FROM_P,
   12261              :              which may call complete_type (c++/57942).  */
   12262     73927016 :           bool b = !COMPLETE_TYPE_P (to) || !COMPLETE_TYPE_P (from);
   12263              :           return comptypes
   12264     73927016 :             (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from),
   12265     73927016 :              b ? COMPARE_STRICT : COMPARE_BASE | COMPARE_DERIVED);
   12266              :         }
   12267         1548 :     }
   12268              : }
   12269              : 
   12270              : /* Return true if TO and FROM (both of which are POINTER_TYPEs or
   12271              :    pointer-to-member types) are the same, ignoring cv-qualification at
   12272              :    all levels.  CB says how we should behave when comparing array bounds.  */
   12273              : 
   12274              : bool
   12275      1111064 : comp_ptr_ttypes_const (tree to, tree from, compare_bounds_t cb)
   12276              : {
   12277      1111064 :   bool is_opaque_pointer = false;
   12278              : 
   12279      1113611 :   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
   12280              :     {
   12281      2224675 :       if (TREE_CODE (to) != TREE_CODE (from))
   12282              :         return false;
   12283              : 
   12284      1891889 :       if (TREE_CODE (from) == OFFSET_TYPE
   12285      1889917 :           && same_type_p (TYPE_OFFSET_BASETYPE (from),
   12286              :                           TYPE_OFFSET_BASETYPE (to)))
   12287         1972 :           continue;
   12288              : 
   12289      1887945 :       if (VECTOR_TYPE_P (to))
   12290         8632 :         is_opaque_pointer = vector_targets_convertible_p (to, from);
   12291              : 
   12292      1887945 :       if (TREE_CODE (to) == ARRAY_TYPE
   12293              :           /* Ignore cv-qualification, but if we see e.g. int[3] and int[4],
   12294              :              we must fail.  */
   12295      1887945 :           && !comp_array_types (to, from, cb, /*strict=*/false))
   12296              :         return false;
   12297              : 
   12298              :       /* CWG 330 says we need to look through arrays.  */
   12299      1885143 :       if (!TYPE_PTR_P (to) && TREE_CODE (to) != ARRAY_TYPE)
   12300       773504 :         return (is_opaque_pointer
   12301       773504 :                 || same_type_ignoring_top_level_qualifiers_p (to, from));
   12302              :     }
   12303              : }
   12304              : 
   12305              : /* Returns the type qualifiers for this type, including the qualifiers on the
   12306              :    elements for an array type.  */
   12307              : 
   12308              : cv_qualifier
   12309  64906245249 : cp_type_quals (const_tree type)
   12310              : {
   12311  64906245249 :   cv_qualifier quals;
   12312  64906245249 :   addr_space_t as;
   12313              :   /* This CONST_CAST is okay because strip_array_types returns its
   12314              :      argument unmodified and we assign it to a const_tree.  */
   12315  64906245249 :   type = strip_array_types (const_cast<tree> (type));
   12316  64906245249 :   if (type == error_mark_node
   12317              :       /* Quals on a FUNCTION_TYPE are memfn quals.  */
   12318  64868865260 :       || TREE_CODE (type) == FUNCTION_TYPE)
   12319              :     return TYPE_UNQUALIFIED;
   12320              : 
   12321  64814992994 :   std::tie (quals, as) = TYPE_QUALS (type).split ();
   12322              :   /* No address space support yet.  */
   12323  64814992994 :   gcc_assert (ADDR_SPACE_GENERIC_P (as));
   12324              :   /* METHOD and REFERENCE_TYPEs should never have quals.  */
   12325  64814992994 :   gcc_assert ((TREE_CODE (type) != METHOD_TYPE
   12326              :                && !TYPE_REF_P (type))
   12327              :               || ((quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))
   12328              :                   == TYPE_UNQUALIFIED));
   12329              :   return quals;
   12330              : }
   12331              : 
   12332              : /* Returns the function-ref-qualifier for TYPE */
   12333              : 
   12334              : cp_ref_qualifier
   12335   3487473550 : type_memfn_rqual (const_tree type)
   12336              : {
   12337   3487473550 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (type));
   12338              : 
   12339   3487473550 :   if (!FUNCTION_REF_QUALIFIED (type))
   12340              :     return REF_QUAL_NONE;
   12341     32341378 :   else if (FUNCTION_RVALUE_QUALIFIED (type))
   12342              :     return REF_QUAL_RVALUE;
   12343              :   else
   12344     16062628 :     return REF_QUAL_LVALUE;
   12345              : }
   12346              : 
   12347              : /* Returns the function-cv-quals for TYPE, which must be a FUNCTION_TYPE or
   12348              :    METHOD_TYPE.  */
   12349              : 
   12350              : cv_qualifier
   12351   1123633059 : type_memfn_quals (const_tree type)
   12352              : {
   12353   1123633059 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12354              :     {
   12355     96647023 :       cv_qualifier quals;
   12356     96647023 :       addr_space_t as;
   12357     96647023 :       std::tie (quals, as) = TYPE_QUALS (type).split ();
   12358              :       /* No address space support yet.  */
   12359     96647023 :       gcc_assert (ADDR_SPACE_GENERIC_P (as));
   12360              :       return quals;
   12361              :     }
   12362   1026986036 :   else if (TREE_CODE (type) == METHOD_TYPE)
   12363   1026986036 :     return cp_type_quals (class_of_this_parm (type));
   12364              :   else
   12365            0 :     gcc_unreachable ();
   12366              : }
   12367              : 
   12368              : /* Returns the FUNCTION_TYPE TYPE with its function-cv-quals changed to
   12369              :    MEMFN_QUALS and its ref-qualifier to RQUAL. */
   12370              : 
   12371              : tree
   12372     75860769 : apply_memfn_quals (tree type, cp_cv_quals memfn_quals, cp_ref_qualifier rqual)
   12373              : {
   12374              :   /* Could handle METHOD_TYPE here if necessary.  */
   12375     75860769 :   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
   12376     75860769 :   if (TYPE_QUALS (type) == memfn_quals
   12377     75155992 :       && type_memfn_rqual (type) == rqual)
   12378              :     return type;
   12379              : 
   12380              :   /* This should really have a different TYPE_MAIN_VARIANT, but that gets
   12381              :      complex.  */
   12382       708804 :   tree result = build_qualified_type (type, memfn_quals);
   12383       708804 :   return build_ref_qualified_type (result, rqual);
   12384              : }
   12385              : 
   12386              : /* Returns nonzero if TYPE is const or volatile.  */
   12387              : 
   12388              : bool
   12389   1259177046 : cv_qualified_p (const_tree type)
   12390              : {
   12391   1259177046 :   int quals = cp_type_quals (type);
   12392   1259177046 :   return (quals & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE)) != 0;
   12393              : }
   12394              : 
   12395              : /* Returns nonzero if the TYPE contains a mutable member.  */
   12396              : 
   12397              : bool
   12398    964891457 : cp_has_mutable_p (const_tree type)
   12399              : {
   12400              :   /* This CONST_CAST is okay because strip_array_types returns its
   12401              :      argument unmodified and we assign it to a const_tree.  */
   12402    964891457 :   type = strip_array_types (const_cast<tree> (type));
   12403              : 
   12404    964891457 :   return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
   12405              : }
   12406              : 
   12407              : /* Set TREE_READONLY and TREE_VOLATILE on DECL as indicated by the
   12408              :    TYPE_QUALS.  For a VAR_DECL, this may be an optimistic
   12409              :    approximation.  In particular, consider:
   12410              : 
   12411              :      int f();
   12412              :      struct S { int i; };
   12413              :      const S s = { f(); }
   12414              : 
   12415              :    Here, we will make "s" as TREE_READONLY (because it is declared
   12416              :    "const") -- only to reverse ourselves upon seeing that the
   12417              :    initializer is non-constant.  */
   12418              : 
   12419              : void
   12420   1040935539 : cp_apply_type_quals_to_decl (cv_qualifier type_quals, tree decl)
   12421              : {
   12422   1040935539 :   tree type = TREE_TYPE (decl);
   12423              : 
   12424   1040935539 :   if (type == error_mark_node)
   12425              :     return;
   12426              : 
   12427   1040934812 :   if (TREE_CODE (decl) == TYPE_DECL)
   12428              :     return;
   12429              : 
   12430    918075439 :   gcc_assert (!(TREE_CODE (type) == FUNCTION_TYPE
   12431              :                 && type_quals != TYPE_UNQUALIFIED));
   12432              : 
   12433              :   /* Avoid setting TREE_READONLY incorrectly.  */
   12434              :   /* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
   12435              :      constructor can produce constant init, so rely on cp_finish_decl to
   12436              :      clear TREE_READONLY if the variable has non-constant init.  */
   12437              : 
   12438              :   /* If the type has (or might have) a mutable component, that component
   12439              :      might be modified.  */
   12440    918075439 :   if (TYPE_HAS_MUTABLE_P (type) || !COMPLETE_TYPE_P (type))
   12441     85244270 :     type_quals &= ~TYPE_QUAL_CONST;
   12442              : 
   12443    918075439 :   c_apply_type_quals_to_decl (type_quals, decl);
   12444              : }
   12445              : 
   12446              : /* Subroutine of casts_away_constness.  Make T1 and T2 point at
   12447              :    exemplar types such that casting T1 to T2 is casting away constness
   12448              :    if and only if there is no implicit conversion from T1 to T2.  */
   12449              : 
   12450              : static void
   12451      1308447 : casts_away_constness_r (tree *t1, tree *t2, tsubst_flags_t complain)
   12452              : {
   12453      1308447 :   cv_qualifier quals1;
   12454      1308447 :   cv_qualifier quals2;
   12455              : 
   12456              :   /* [expr.const.cast]
   12457              : 
   12458              :      For multi-level pointer to members and multi-level mixed pointers
   12459              :      and pointers to members (conv.qual), the "member" aspect of a
   12460              :      pointer to member level is ignored when determining if a const
   12461              :      cv-qualifier has been cast away.  */
   12462              :   /* [expr.const.cast]
   12463              : 
   12464              :      For  two  pointer types:
   12465              : 
   12466              :             X1 is T1cv1,1 * ... cv1,N *   where T1 is not a pointer type
   12467              :             X2 is T2cv2,1 * ... cv2,M *   where T2 is not a pointer type
   12468              :             K is min(N,M)
   12469              : 
   12470              :      casting from X1 to X2 casts away constness if, for a non-pointer
   12471              :      type T there does not exist an implicit conversion (clause
   12472              :      _conv_) from:
   12473              : 
   12474              :             Tcv1,(N-K+1) * cv1,(N-K+2) * ... cv1,N *
   12475              : 
   12476              :      to
   12477              : 
   12478              :             Tcv2,(M-K+1) * cv2,(M-K+2) * ... cv2,M *.  */
   12479      1308447 :   if ((!TYPE_PTR_P (*t1) && !TYPE_PTRDATAMEM_P (*t1))
   12480       654576 :       || (!TYPE_PTR_P (*t2) && !TYPE_PTRDATAMEM_P (*t2)))
   12481              :     {
   12482       654051 :       *t1 = cp_build_qualified_type (void_type_node,
   12483              :                                      cp_type_quals (*t1));
   12484       654051 :       *t2 = cp_build_qualified_type (void_type_node,
   12485              :                                      cp_type_quals (*t2));
   12486       654051 :       return;
   12487              :     }
   12488              : 
   12489       654396 :   quals1 = cp_type_quals (*t1);
   12490       654396 :   quals2 = cp_type_quals (*t2);
   12491              : 
   12492       654396 :   if (TYPE_PTRDATAMEM_P (*t1))
   12493            0 :     *t1 = TYPE_PTRMEM_POINTED_TO_TYPE (*t1);
   12494              :   else
   12495       654396 :     *t1 = TREE_TYPE (*t1);
   12496       654396 :   if (TYPE_PTRDATAMEM_P (*t2))
   12497            0 :     *t2 = TYPE_PTRMEM_POINTED_TO_TYPE (*t2);
   12498              :   else
   12499       654396 :     *t2 = TREE_TYPE (*t2);
   12500              : 
   12501       654396 :   casts_away_constness_r (t1, t2, complain);
   12502       654396 :   *t1 = build_pointer_type (*t1);
   12503       654396 :   *t2 = build_pointer_type (*t2);
   12504       654396 :   *t1 = cp_build_qualified_type (*t1, quals1);
   12505       654396 :   *t2 = cp_build_qualified_type (*t2, quals2);
   12506              : }
   12507              : 
   12508              : /* Returns nonzero if casting from TYPE1 to TYPE2 casts away
   12509              :    constness.
   12510              : 
   12511              :    ??? This function returns non-zero if casting away qualifiers not
   12512              :    just const.  We would like to return to the caller exactly which
   12513              :    qualifiers are casted away to give more accurate diagnostics.
   12514              : */
   12515              : 
   12516              : static bool
   12517       654123 : casts_away_constness (tree t1, tree t2, tsubst_flags_t complain)
   12518              : {
   12519       654123 :   if (TYPE_REF_P (t2))
   12520              :     {
   12521              :       /* [expr.const.cast]
   12522              : 
   12523              :          Casting from an lvalue of type T1 to an lvalue of type T2
   12524              :          using a reference cast casts away constness if a cast from an
   12525              :          rvalue of type "pointer to T1" to the type "pointer to T2"
   12526              :          casts away constness.  */
   12527            0 :       t1 = (TYPE_REF_P (t1) ? TREE_TYPE (t1) : t1);
   12528            0 :       return casts_away_constness (build_pointer_type (t1),
   12529            0 :                                    build_pointer_type (TREE_TYPE (t2)),
   12530            0 :                                    complain);
   12531              :     }
   12532              : 
   12533       654123 :   if (TYPE_PTRDATAMEM_P (t1) && TYPE_PTRDATAMEM_P (t2))
   12534              :     /* [expr.const.cast]
   12535              : 
   12536              :        Casting from an rvalue of type "pointer to data member of X
   12537              :        of type T1" to the type "pointer to data member of Y of type
   12538              :        T2" casts away constness if a cast from an rvalue of type
   12539              :        "pointer to T1" to the type "pointer to T2" casts away
   12540              :        constness.  */
   12541           48 :     return casts_away_constness
   12542           48 :       (build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t1)),
   12543           48 :        build_pointer_type (TYPE_PTRMEM_POINTED_TO_TYPE (t2)),
   12544           48 :        complain);
   12545              : 
   12546              :   /* Casting away constness is only something that makes sense for
   12547              :      pointer or reference types.  */
   12548       654075 :   if (!TYPE_PTR_P (t1) || !TYPE_PTR_P (t2))
   12549              :     return false;
   12550              : 
   12551              :   /* Top-level qualifiers don't matter.  */
   12552       654051 :   t1 = TYPE_MAIN_VARIANT (t1);
   12553       654051 :   t2 = TYPE_MAIN_VARIANT (t2);
   12554       654051 :   casts_away_constness_r (&t1, &t2, complain);
   12555       654051 :   if (!can_convert (t2, t1, complain))
   12556          402 :     return true;
   12557              : 
   12558              :   return false;
   12559              : }
   12560              : 
   12561              : /* If T is a REFERENCE_TYPE return the type to which T refers.
   12562              :    Otherwise, return T itself.  */
   12563              : 
   12564              : tree
   12565   4501528513 : non_reference (tree t)
   12566              : {
   12567   4501528513 :   if (t && TYPE_REF_P (t))
   12568    405166159 :     t = TREE_TYPE (t);
   12569   4501528513 :   return t;
   12570              : }
   12571              : 
   12572              : 
   12573              : /* Return nonzero if REF is an lvalue valid for this language;
   12574              :    otherwise, print an error message and return zero.  USE says
   12575              :    how the lvalue is being used and so selects the error message.  */
   12576              : 
   12577              : int
   12578     43443451 : lvalue_or_else (tree ref, enum lvalue_use use, tsubst_flags_t complain)
   12579              : {
   12580     43443451 :   cp_lvalue_kind kind = lvalue_kind (ref);
   12581              : 
   12582     43443451 :   if (kind == clk_none)
   12583              :     {
   12584          690 :       if (complain & tf_error)
   12585          126 :         lvalue_error (cp_expr_loc_or_input_loc (ref), use);
   12586              :       return 0;
   12587              :     }
   12588     43442761 :   else if (kind & (clk_rvalueref|clk_class))
   12589              :     {
   12590          220 :       if (!(complain & tf_error))
   12591              :         return 0;
   12592              :       /* Make this a permerror because we used to accept it.  */
   12593           18 :       permerror (cp_expr_loc_or_input_loc (ref),
   12594              :                  "using rvalue as lvalue");
   12595              :     }
   12596              :   return 1;
   12597              : }
   12598              : 
   12599              : /* Return true if a user-defined literal operator is a raw operator.  */
   12600              : 
   12601              : bool
   12602       115042 : check_raw_literal_operator (const_tree decl)
   12603              : {
   12604       115042 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   12605       115042 :   tree argtype;
   12606       115042 :   int arity;
   12607       115042 :   bool maybe_raw_p = false;
   12608              : 
   12609              :   /* Count the number and type of arguments and check for ellipsis.  */
   12610       115042 :   for (argtype = argtypes, arity = 0;
   12611       172580 :        argtype && argtype != void_list_node;
   12612        57538 :        ++arity, argtype = TREE_CHAIN (argtype))
   12613              :     {
   12614        57538 :       tree t = TREE_VALUE (argtype);
   12615              : 
   12616        57538 :       if (same_type_p (t, const_string_type_node))
   12617            9 :         maybe_raw_p = true;
   12618              :     }
   12619       115042 :   if (!argtype)
   12620              :     return false; /* Found ellipsis.  */
   12621              : 
   12622       115042 :   if (!maybe_raw_p || arity != 1)
   12623       115036 :     return false;
   12624              : 
   12625              :   return true;
   12626              : }
   12627              : 
   12628              : 
   12629              : /* Return true if a user-defined literal operator has one of the allowed
   12630              :    argument types.  */
   12631              : 
   12632              : bool
   12633       313506 : check_literal_operator_args (const_tree decl,
   12634              :                              bool *long_long_unsigned_p, bool *long_double_p)
   12635              : {
   12636       313506 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   12637              : 
   12638       313506 :   *long_long_unsigned_p = false;
   12639       313506 :   *long_double_p = false;
   12640       313506 :   if (processing_template_decl || processing_specialization)
   12641        57660 :     return argtypes == void_list_node;
   12642              :   else
   12643              :     {
   12644              :       tree argtype;
   12645              :       int arity;
   12646              :       int max_arity = 2;
   12647              : 
   12648              :       /* Count the number and type of arguments and check for ellipsis.  */
   12649       255718 :       for (argtype = argtypes, arity = 0;
   12650       511564 :            argtype && argtype != void_list_node;
   12651       255718 :            argtype = TREE_CHAIN (argtype))
   12652              :         {
   12653       255852 :           tree t = TREE_VALUE (argtype);
   12654       255852 :           ++arity;
   12655              : 
   12656       255852 :           if (TYPE_PTR_P (t))
   12657              :             {
   12658       123060 :               bool maybe_raw_p = false;
   12659       123060 :               t = TREE_TYPE (t);
   12660       123060 :               if (cp_type_quals (t) != TYPE_QUAL_CONST)
   12661              :                 return false;
   12662       123057 :               t = TYPE_MAIN_VARIANT (t);
   12663       123057 :               if ((maybe_raw_p = same_type_p (t, char_type_node))
   12664        98255 :                   || same_type_p (t, wchar_type_node)
   12665        73639 :                   || same_type_p (t, char8_type_node)
   12666        49244 :                   || same_type_p (t, char16_type_node)
   12667       147679 :                   || same_type_p (t, char32_type_node))
   12668              :                 {
   12669       123054 :                   argtype = TREE_CHAIN (argtype);
   12670       123054 :                   if (!argtype)
   12671              :                     return false;
   12672       123054 :                   t = TREE_VALUE (argtype);
   12673       123054 :                   if (maybe_raw_p && argtype == void_list_node)
   12674              :                     return true;
   12675       122947 :                   else if (same_type_p (t, size_type_node))
   12676              :                     {
   12677       122941 :                       ++arity;
   12678       122941 :                       continue;
   12679              :                     }
   12680              :                   else
   12681              :                     return false;
   12682              :                 }
   12683              :             }
   12684       132792 :           else if (same_type_p (t, long_long_unsigned_type_node))
   12685              :             {
   12686        46893 :               max_arity = 1;
   12687        46893 :               *long_long_unsigned_p = true;
   12688              :             }
   12689        85899 :           else if (same_type_p (t, long_double_type_node))
   12690              :             {
   12691        85799 :               max_arity = 1;
   12692        85799 :               *long_double_p = true;
   12693              :             }
   12694          100 :           else if (same_type_p (t, char_type_node))
   12695              :             max_arity = 1;
   12696           56 :           else if (same_type_p (t, wchar_type_node))
   12697              :             max_arity = 1;
   12698           45 :           else if (same_type_p (t, char8_type_node))
   12699              :             max_arity = 1;
   12700           40 :           else if (same_type_p (t, char16_type_node))
   12701              :             max_arity = 1;
   12702           29 :           else if (same_type_p (t, char32_type_node))
   12703              :             max_arity = 1;
   12704              :           else
   12705              :             return false;
   12706              :         }
   12707       255712 :       if (!argtype)
   12708              :         return false; /* Found ellipsis.  */
   12709              : 
   12710       255709 :       if (arity != max_arity)
   12711              :         return false;
   12712              : 
   12713       255703 :       return true;
   12714              :     }
   12715              : }
   12716              : 
   12717              : /* Always returns false since unlike C90, C++ has no concept of implicit
   12718              :    function declarations.  */
   12719              : 
   12720              : bool
   12721          395 : c_decl_implicit (const_tree)
   12722              : {
   12723          395 :   return false;
   12724              : }
        

Generated by: LCOV version 2.6-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.