LCOV - code coverage report
Current view: top level - gcc/cp - tree.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.0 % 3079 2862
Test Date: 2026-02-28 14:20:25 Functions: 95.1 % 183 174
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Language-dependent node constructors for parse phase of GNU 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              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "tree.h"
      25              : #include "cp-tree.h"
      26              : #include "gimple-expr.h"
      27              : #include "cgraph.h"
      28              : #include "stor-layout.h"
      29              : #include "print-tree.h"
      30              : #include "tree-iterator.h"
      31              : #include "tree-inline.h"
      32              : #include "debug.h"
      33              : #include "convert.h"
      34              : #include "gimplify.h"
      35              : #include "stringpool.h"
      36              : #include "attribs.h"
      37              : #include "flags.h"
      38              : #include "selftest.h"
      39              : 
      40              : static tree bot_manip (tree *, int *, void *);
      41              : static tree bot_replace (tree *, int *, void *);
      42              : static hashval_t list_hash_pieces (tree, tree, tree);
      43              : static tree build_target_expr (tree, tree, tsubst_flags_t);
      44              : static tree count_trees_r (tree *, int *, void *);
      45              : static tree verify_stmt_tree_r (tree *, int *, void *);
      46              : 
      47              : static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
      48              : static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *);
      49              : static tree handle_no_dangling_attribute (tree *, tree, tree, int, bool *);
      50              : static tree handle_annotation_attribute (tree *, tree, tree, int, bool *);
      51              : 
      52              : /* If REF is an lvalue, returns the kind of lvalue that REF is.
      53              :    Otherwise, returns clk_none.  */
      54              : 
      55              : cp_lvalue_kind
      56   3349948589 : lvalue_kind (const_tree ref)
      57              : {
      58   3718886453 :   cp_lvalue_kind op1_lvalue_kind = clk_none;
      59   3718886453 :   cp_lvalue_kind op2_lvalue_kind = clk_none;
      60              : 
      61              :   /* Expressions of reference type are sometimes wrapped in
      62              :      INDIRECT_REFs.  INDIRECT_REFs are just internal compiler
      63              :      representation, not part of the language, so we have to look
      64              :      through them.  */
      65   3718886453 :   if (REFERENCE_REF_P (ref))
      66    352904424 :     return lvalue_kind (TREE_OPERAND (ref, 0));
      67              : 
      68   3365982029 :   if (TREE_TYPE (ref)
      69   3365982029 :       && TYPE_REF_P (TREE_TYPE (ref)))
      70              :     {
      71              :       /* unnamed rvalue references are rvalues */
      72    357908726 :       if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
      73              :           && TREE_CODE (ref) != PARM_DECL
      74              :           && !VAR_P (ref)
      75              :           && TREE_CODE (ref) != COMPONENT_REF
      76              :           /* Functions are always lvalues.  */
      77    419894273 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
      78              :         {
      79     61984847 :           op1_lvalue_kind = clk_rvalueref;
      80     61984847 :           if (implicit_rvalue_p (ref))
      81      8610583 :             op1_lvalue_kind |= clk_implicit_rval;
      82     61984847 :           return op1_lvalue_kind;
      83              :         }
      84              : 
      85              :       /* lvalue references and named rvalue references are lvalues.  */
      86              :       return clk_ordinary;
      87              :     }
      88              : 
      89   3008073303 :   if (ref == current_class_ptr)
      90              :     return clk_none;
      91              : 
      92              :   /* Expressions with cv void type are prvalues.  */
      93   3005164838 :   if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
      94              :     return clk_none;
      95              : 
      96   3004383308 :   switch (TREE_CODE (ref))
      97              :     {
      98              :     case SAVE_EXPR:
      99              :       return clk_none;
     100              : 
     101              :       /* preincrements and predecrements are valid lvals, provided
     102              :          what they refer to are valid lvals.  */
     103    415196707 :     case PREINCREMENT_EXPR:
     104    415196707 :     case PREDECREMENT_EXPR:
     105    415196707 :     case TRY_CATCH_EXPR:
     106    415196707 :     case REALPART_EXPR:
     107    415196707 :     case IMAGPART_EXPR:
     108    415196707 :     case VIEW_CONVERT_EXPR:
     109    415196707 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     110              :       /* As for ARRAY_REF and COMPONENT_REF, these codes turn a class prvalue
     111              :          into an xvalue: we need to materialize the temporary before we mess
     112              :          with it.  Except VIEW_CONVERT_EXPR that doesn't actually change the
     113              :          type, as in location wrapper and REF_PARENTHESIZED_P.  */
     114    415196707 :       if (op1_lvalue_kind == clk_class
     115    415196721 :           && !(TREE_CODE (ref) == VIEW_CONVERT_EXPR
     116              :                && (same_type_ignoring_top_level_qualifiers_p
     117           14 :                    (TREE_TYPE (ref), TREE_TYPE (TREE_OPERAND (ref, 0))))))
     118           14 :         return clk_rvalueref;
     119              :       return op1_lvalue_kind;
     120              : 
     121      3400467 :     case ARRAY_REF:
     122      3400467 :       {
     123      3400467 :         tree op1 = TREE_OPERAND (ref, 0);
     124      3400467 :         if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
     125              :           {
     126      2936024 :             op1_lvalue_kind = lvalue_kind (op1);
     127      2936024 :             if (op1_lvalue_kind == clk_class)
     128              :               /* in the case of an array operand, the result is an lvalue if
     129              :                  that operand is an lvalue and an xvalue otherwise */
     130         2190 :               op1_lvalue_kind = clk_rvalueref;
     131      2936024 :             return op1_lvalue_kind;
     132              :           }
     133              :         else
     134              :           return clk_ordinary;
     135              :       }
     136              : 
     137           21 :     case MEMBER_REF:
     138           21 :     case DOTSTAR_EXPR:
     139           21 :       if (TREE_CODE (ref) == MEMBER_REF)
     140              :         op1_lvalue_kind = clk_ordinary;
     141              :       else
     142            9 :         op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     143           21 :       if (TYPE_PTRMEMFUNC_P (TREE_TYPE (TREE_OPERAND (ref, 1))))
     144              :         op1_lvalue_kind = clk_none;
     145           21 :       else if (op1_lvalue_kind == clk_class)
     146              :         /* The result of a .* expression whose second operand is a pointer to a
     147              :            data member is an lvalue if the first operand is an lvalue and an
     148              :            xvalue otherwise.  */
     149           14 :         op1_lvalue_kind = clk_rvalueref;
     150              :       return op1_lvalue_kind;
     151              : 
     152    248932670 :     case COMPONENT_REF:
     153    248932670 :       if (BASELINK_P (TREE_OPERAND (ref, 1)))
     154              :         {
     155          118 :           tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (ref, 1));
     156              : 
     157              :           /* For static member function recurse on the BASELINK, we can get
     158              :              here e.g. from reference_binding.  If BASELINK_FUNCTIONS is
     159              :              OVERLOAD, the overload is resolved first if possible through
     160              :              resolve_address_of_overloaded_function.  */
     161          118 :           if (TREE_CODE (fn) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (fn))
     162           27 :             return lvalue_kind (TREE_OPERAND (ref, 1));
     163              :         }
     164    248932643 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     165    248932643 :       if (op1_lvalue_kind == clk_class)
     166              :         /* If E1 is an lvalue, then E1.E2 is an lvalue;
     167              :            otherwise E1.E2 is an xvalue.  */
     168              :         op1_lvalue_kind = clk_rvalueref;
     169              : 
     170              :       /* Look at the member designator.  */
     171    248426159 :       if (!op1_lvalue_kind)
     172              :         ;
     173    248932619 :       else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
     174              :         /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
     175              :            situations.  If we're seeing a COMPONENT_REF, it's a non-static
     176              :            member, so it isn't an lvalue. */
     177              :         op1_lvalue_kind = clk_none;
     178    248932528 :       else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
     179              :         /* This can be IDENTIFIER_NODE in a template.  */;
     180    241383286 :       else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
     181              :         {
     182              :           /* Clear the ordinary bit.  If this object was a class
     183              :              rvalue we want to preserve that information.  */
     184     30088706 :           op1_lvalue_kind &= ~clk_ordinary;
     185              :           /* The lvalue is for a bitfield.  */
     186     30088706 :           op1_lvalue_kind |= clk_bitfield;
     187              :         }
     188    211294580 :       else if (DECL_PACKED (TREE_OPERAND (ref, 1)))
     189        15177 :         op1_lvalue_kind |= clk_packed;
     190              : 
     191              :       return op1_lvalue_kind;
     192              : 
     193              :     case STRING_CST:
     194              :       return clk_ordinary | clk_mergeable;
     195              : 
     196              :     case COMPOUND_LITERAL_EXPR:
     197              :       return clk_ordinary;
     198              : 
     199      4038426 :     case CONST_DECL:
     200              :       /* CONST_DECL without TREE_STATIC are enumeration values and
     201              :          thus not lvalues.  With TREE_STATIC they are used by ObjC++
     202              :          in objc_build_string_object and need to be considered as
     203              :          lvalues.  */
     204      4038426 :       if (! TREE_STATIC (ref))
     205              :         return clk_none;
     206              :       /* FALLTHRU */
     207    346510482 :     case VAR_DECL:
     208    346510482 :       if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
     209      1203128 :         return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
     210              : 
     211    484533363 :       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
     212     23659504 :           && DECL_LANG_SPECIFIC (ref)
     213    346417647 :           && DECL_IN_AGGR_P (ref))
     214              :         return clk_none;
     215              : 
     216    345307354 :       if (TREE_CODE (ref) == CONST_DECL || DECL_MERGEABLE (ref))
     217              :         return clk_ordinary | clk_mergeable;
     218              : 
     219              :       /* FALLTHRU */
     220              :     case INDIRECT_REF:
     221              :     case ARROW_EXPR:
     222              :     case PARM_DECL:
     223              :     case RESULT_DECL:
     224              :     case PLACEHOLDER_EXPR:
     225              :       return clk_ordinary;
     226              : 
     227              :       /* A scope ref in a template, left as SCOPE_REF to support later
     228              :          access checking.  */
     229     11134154 :     case SCOPE_REF:
     230     11134154 :       gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     231     11134154 :       {
     232     11134154 :         tree op = TREE_OPERAND (ref, 1);
     233     11134154 :         if (TREE_CODE (op) == FIELD_DECL)
     234        17933 :           return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary);
     235              :         else
     236              :           return lvalue_kind (op);
     237              :       }
     238              : 
     239          485 :     case MAX_EXPR:
     240          485 :     case MIN_EXPR:
     241              :       /* Disallow <? and >? as lvalues if either argument side-effects.  */
     242          485 :       if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0))
     243          485 :           || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1)))
     244              :         return clk_none;
     245          485 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     246          485 :       op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1));
     247          485 :       break;
     248              : 
     249     14787535 :     case COND_EXPR:
     250     14787535 :       if (processing_template_decl)
     251              :         {
     252              :           /* Within templates, a REFERENCE_TYPE will indicate whether
     253              :              the COND_EXPR result is an ordinary lvalue or rvalueref.
     254              :              Since REFERENCE_TYPEs are handled above, if we reach this
     255              :              point, we know we got a plain rvalue.  Unless we have a
     256              :              type-dependent expr, that is, but we shouldn't be testing
     257              :              lvalueness if we can't even tell the types yet!  */
     258      1180603 :           gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     259      1180603 :           goto default_;
     260              :         }
     261     13606932 :       {
     262     13606932 :         tree op1 = TREE_OPERAND (ref, 1);
     263     13606932 :         if (!op1) op1 = TREE_OPERAND (ref, 0);
     264     13606932 :         tree op2 = TREE_OPERAND (ref, 2);
     265     13606932 :         op1_lvalue_kind = lvalue_kind (op1);
     266     13606932 :         op2_lvalue_kind = lvalue_kind (op2);
     267     13606932 :         if (!op1_lvalue_kind != !op2_lvalue_kind)
     268              :           {
     269              :             /* The second or the third operand (but not both) is a
     270              :                throw-expression; the result is of the type
     271              :                and value category of the other.  */
     272       544703 :             if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
     273              :               op2_lvalue_kind = op1_lvalue_kind;
     274       544661 :             else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
     275     13607417 :               op1_lvalue_kind = op2_lvalue_kind;
     276              :           }
     277              :       }
     278              :       break;
     279              : 
     280        93248 :     case MODOP_EXPR:
     281              :       /* We expect to see unlowered MODOP_EXPRs only during
     282              :          template processing.  */
     283        93248 :       gcc_assert (processing_template_decl);
     284        93248 :       if (CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (ref, 0))))
     285            3 :         goto default_;
     286              :       else
     287              :         return clk_ordinary;
     288              : 
     289              :     case MODIFY_EXPR:
     290              :     case TYPEID_EXPR:
     291              :       return clk_ordinary;
     292              : 
     293      3680138 :     case COMPOUND_EXPR:
     294      3680138 :       return lvalue_kind (TREE_OPERAND (ref, 1));
     295              : 
     296              :     case TARGET_EXPR:
     297              :       return clk_class;
     298              : 
     299         1395 :     case VA_ARG_EXPR:
     300         1395 :       return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none);
     301              : 
     302    144679122 :     case CALL_EXPR:
     303              :       /* We can see calls outside of TARGET_EXPR in templates.  */
     304    144679122 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
     305              :         return clk_class;
     306              :       return clk_none;
     307              : 
     308    162375746 :     case FUNCTION_DECL:
     309              :       /* All functions (except non-static-member functions) are
     310              :          lvalues.  */
     311    162375746 :       return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
     312    162375746 :               ? clk_none : clk_ordinary);
     313              : 
     314         1474 :     case BASELINK:
     315              :       /* We now represent a reference to a single static member function
     316              :          with a BASELINK.  */
     317              :       /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns
     318              :          its argument unmodified and we assign it to a const_tree.  */
     319         1474 :       return lvalue_kind (BASELINK_FUNCTIONS (const_cast<tree> (ref)));
     320              : 
     321        32452 :     case PAREN_EXPR:
     322        32452 :       return lvalue_kind (TREE_OPERAND (ref, 0));
     323              : 
     324     15985770 :     case TEMPLATE_PARM_INDEX:
     325     15985770 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
     326              :         /* A template parameter object is an lvalue.  */
     327              :         return clk_ordinary;
     328              :       return clk_none;
     329              : 
     330   1125268572 :     default:
     331   1125268572 :     default_:
     332   1125268572 :       if (!TREE_TYPE (ref))
     333              :         return clk_none;
     334   2250537144 :       if (CLASS_TYPE_P (TREE_TYPE (ref))
     335   2247198785 :           || TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
     336              :         return clk_class;
     337              :       return clk_none;
     338              :     }
     339              : 
     340              :   /* If one operand is not an lvalue at all, then this expression is
     341              :      not an lvalue.  */
     342     13607417 :   if (!op1_lvalue_kind || !op2_lvalue_kind)
     343              :     return clk_none;
     344              : 
     345              :   /* Otherwise, it's an lvalue, and it has all the odd properties
     346              :      contributed by either operand.  */
     347      4718504 :   op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
     348              :   /* It's not an ordinary lvalue if it involves any other kind.  */
     349      4718504 :   if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
     350      1063643 :     op1_lvalue_kind &= ~clk_ordinary;
     351              :   /* It can't be both a pseudo-lvalue and a non-addressable lvalue.
     352              :      A COND_EXPR of those should be wrapped in a TARGET_EXPR.  */
     353      1063643 :   if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
     354        37342 :       && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
     355   1268898123 :     op1_lvalue_kind = clk_none;
     356              :   return op1_lvalue_kind;
     357              : }
     358              : 
     359              : /* Returns the kind of lvalue that REF is, in the sense of [basic.lval].  */
     360              : 
     361              : cp_lvalue_kind
     362     47362517 : real_lvalue_p (const_tree ref)
     363              : {
     364     47362517 :   cp_lvalue_kind kind = lvalue_kind (ref);
     365     47362517 :   if (kind & (clk_rvalueref|clk_class))
     366              :     return clk_none;
     367              :   else
     368     45293543 :     return kind;
     369              : }
     370              : 
     371              : /* c-common wants us to return bool.  */
     372              : 
     373              : bool
     374     46458261 : lvalue_p (const_tree t)
     375              : {
     376     46458261 :   return real_lvalue_p (t);
     377              : }
     378              : 
     379              : /* This differs from lvalue_p in that xvalues are included.  */
     380              : 
     381              : bool
     382    177496755 : glvalue_p (const_tree ref)
     383              : {
     384    177496755 :   cp_lvalue_kind kind = lvalue_kind (ref);
     385    177496755 :   if (kind & clk_class)
     386              :     return false;
     387              :   else
     388    173820502 :     return (kind != clk_none);
     389              : }
     390              : 
     391              : /* This differs from glvalue_p in that class prvalues are included.  */
     392              : 
     393              : bool
     394   1488679032 : obvalue_p (const_tree ref)
     395              : {
     396   1488679032 :   return (lvalue_kind (ref) != clk_none);
     397              : }
     398              : 
     399              : /* Returns true if REF is an xvalue (the result of dereferencing an rvalue
     400              :    reference), false otherwise.  */
     401              : 
     402              : bool
     403      7207684 : xvalue_p (const_tree ref)
     404              : {
     405      7207684 :   return (lvalue_kind (ref) & clk_rvalueref);
     406              : }
     407              : 
     408              : /* True if REF is a bit-field.  */
     409              : 
     410              : bool
     411    280729480 : bitfield_p (const_tree ref)
     412              : {
     413    280729480 :   return (lvalue_kind (ref) & clk_bitfield);
     414              : }
     415              : 
     416              : /* True if REF is a glvalue with a unique address, excluding mergeable glvalues
     417              :    such as string constants.  */
     418              : 
     419              : bool
     420          108 : non_mergeable_glvalue_p (const_tree ref)
     421              : {
     422          108 :   auto kind = lvalue_kind (ref);
     423          108 :   return (kind != clk_none
     424          108 :           && !(kind & (clk_class|clk_mergeable)));
     425              : }
     426              : 
     427              : /* C++-specific version of stabilize_reference for bit-fields and
     428              :    DECL_PACKED fields.  We can't bind a reference to those.  */
     429              : 
     430              : static tree
     431           48 : cp_stabilize_bitfield_reference (tree ref)
     432              : {
     433           48 :   tree op1, op2, op3;
     434           48 :   STRIP_ANY_LOCATION_WRAPPER (ref);
     435           48 :   switch (TREE_CODE (ref))
     436              :     {
     437           24 :     case VAR_DECL:
     438           24 :     case PARM_DECL:
     439           24 :     case RESULT_DECL:
     440           24 :     CASE_CONVERT:
     441           24 :     case FLOAT_EXPR:
     442           24 :     case FIX_TRUNC_EXPR:
     443           24 :     case INDIRECT_REF:
     444           24 :     case COMPONENT_REF:
     445           24 :     case BIT_FIELD_REF:
     446           24 :     case ARRAY_REF:
     447           24 :     case ARRAY_RANGE_REF:
     448           24 :     case ERROR_MARK:
     449           24 :     case REALPART_EXPR:
     450           24 :     case IMAGPART_EXPR:
     451           24 :     default:
     452           24 :       break;
     453           24 :     case COMPOUND_EXPR:
     454           24 :       op2 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 1));
     455           24 :       if (op2 == TREE_OPERAND (ref, 1))
     456              :         return ref;
     457           24 :       op1 = TREE_OPERAND (ref, 0);
     458           24 :       if (TREE_SIDE_EFFECTS (op1))
     459              :         {
     460           24 :           if (VOID_TYPE_P (TREE_TYPE (op1)))
     461            0 :             op1 = save_expr (op1);
     462              :           else
     463              :             {
     464           24 :               op1 = build2 (COMPOUND_EXPR, void_type_node, op1,
     465              :                             void_node);
     466           24 :               op1 = save_expr (op1);
     467              :             }
     468              :         }
     469           24 :       return build2 (COMPOUND_EXPR, TREE_TYPE (op2), op1, op2);
     470            0 :     case COND_EXPR:
     471            0 :       op1 = TREE_OPERAND (ref, 0);
     472            0 :       op2 = TREE_OPERAND (ref, 1);
     473            0 :       op3 = TREE_OPERAND (ref, 2);
     474            0 :       if (op2 && TREE_CODE (op2) != THROW_EXPR)
     475            0 :         op2 = cp_stabilize_bitfield_reference (op2);
     476            0 :       if (TREE_CODE (op3) != THROW_EXPR)
     477            0 :         op3 = cp_stabilize_bitfield_reference (op3);
     478            0 :       if (op2 == NULL_TREE)
     479            0 :         op1 = cp_stabilize_bitfield_reference (op1);
     480            0 :       if (op1 == TREE_OPERAND (ref, 0)
     481            0 :           && op2 == TREE_OPERAND (ref, 1)
     482            0 :           && op3 == TREE_OPERAND (ref, 2))
     483              :         return ref;
     484            0 :       if (op2 != NULL_TREE && TREE_SIDE_EFFECTS (op1))
     485            0 :         op1 = save_expr (op1);
     486            0 :       return build3 (COND_EXPR, TREE_TYPE (ref), op1, op2, op3);
     487            0 :     case PREINCREMENT_EXPR:
     488            0 :     case PREDECREMENT_EXPR:
     489            0 :       op1 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 0));
     490            0 :       if (op1 == TREE_OPERAND (ref, 0))
     491              :         return ref;
     492            0 :       return build2 (COMPOUND_EXPR, TREE_TYPE (ref),
     493            0 :                      build2 (TREE_CODE (ref), TREE_TYPE (ref), op1,
     494            0 :                              TREE_OPERAND (ref, 0)), op1);
     495            0 :     case PAREN_EXPR:
     496            0 :       op1 = cp_stabilize_bitfield_reference (TREE_OPERAND (ref, 0));
     497            0 :       if (op1 == TREE_OPERAND (ref, 0))
     498              :         return ref;
     499            0 :       return build1 (PAREN_EXPR, TREE_TYPE (ref), op1);
     500              :     }
     501           24 :   return stabilize_reference (ref);
     502              : }
     503              : 
     504              : /* C++-specific version of stabilize_reference.  */
     505              : 
     506              : tree
     507      5213317 : cp_stabilize_reference (tree ref)
     508              : {
     509      5213317 :   if (processing_template_decl)
     510              :     /* As in cp_save_expr.  */
     511              :     return ref;
     512              : 
     513      4515364 :   STRIP_ANY_LOCATION_WRAPPER (ref);
     514      4515364 :   switch (TREE_CODE (ref))
     515              :     {
     516              :     /* We need to treat specially anything stabilize_reference doesn't
     517              :        handle specifically.  */
     518              :     case VAR_DECL:
     519              :     case PARM_DECL:
     520              :     case RESULT_DECL:
     521              :     CASE_CONVERT:
     522              :     case FLOAT_EXPR:
     523              :     case FIX_TRUNC_EXPR:
     524              :     case INDIRECT_REF:
     525              :     case COMPONENT_REF:
     526              :     case BIT_FIELD_REF:
     527              :     case ARRAY_REF:
     528              :     case ARRAY_RANGE_REF:
     529              :     case ERROR_MARK:
     530              :       break;
     531          449 :     default:
     532          449 :       cp_lvalue_kind kind = lvalue_kind (ref);
     533          449 :       if ((kind & ~clk_class) != clk_none)
     534              :         {
     535          440 :           if (kind & (clk_bitfield | clk_packed))
     536           24 :             return cp_stabilize_bitfield_reference (ref);
     537          416 :           tree type = unlowered_expr_type (ref);
     538          416 :           bool rval = !!(kind & clk_rvalueref);
     539          416 :           type = cp_build_reference_type (type, rval);
     540              :           /* This inhibits warnings in, eg, cxx_mark_addressable
     541              :              (c++/60955).  */
     542          416 :           warning_sentinel s (extra_warnings);
     543          416 :           ref = build_static_cast (input_location, type, ref,
     544              :                                    tf_error);
     545          416 :         }
     546              :     }
     547              : 
     548      4515340 :   return stabilize_reference (ref);
     549              : }
     550              : 
     551              : /* Test whether DECL is a builtin that may appear in a
     552              :    constant-expression. */
     553              : 
     554              : bool
     555    585843230 : builtin_valid_in_constant_expr_p (const_tree decl)
     556              : {
     557    585843230 :   STRIP_ANY_LOCATION_WRAPPER (decl);
     558    585843230 :   if (TREE_CODE (decl) != FUNCTION_DECL)
     559              :     /* Not a function.  */
     560              :     return false;
     561    317962857 :   if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
     562              :     {
     563    280358077 :       if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
     564       223436 :         switch (DECL_FE_FUNCTION_CODE (decl))
     565              :           {
     566              :           case CP_BUILT_IN_IS_CONSTANT_EVALUATED:
     567              :           case CP_BUILT_IN_SOURCE_LOCATION:
     568              :           case CP_BUILT_IN_IS_CORRESPONDING_MEMBER:
     569              :           case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS:
     570              :           case CP_BUILT_IN_EH_PTR_ADJUST_REF:
     571              :           case CP_BUILT_IN_IS_STRING_LITERAL:
     572              :           case CP_BUILT_IN_CONSTEXPR_DIAG:
     573              :             return true;
     574              :           default:
     575              :             break;
     576              :           }
     577              :       /* Not a built-in.  */
     578              :       return false;
     579              :     }
     580     37604780 :   switch (DECL_FUNCTION_CODE (decl))
     581              :     {
     582              :       /* These always have constant results like the corresponding
     583              :          macros/symbol.  */
     584              :     case BUILT_IN_FILE:
     585              :     case BUILT_IN_FUNCTION:
     586              :     case BUILT_IN_LINE:
     587              : 
     588              :       /* The following built-ins are valid in constant expressions
     589              :          when their arguments are.  */
     590              :     case BUILT_IN_ADD_OVERFLOW_P:
     591              :     case BUILT_IN_SUB_OVERFLOW_P:
     592              :     case BUILT_IN_MUL_OVERFLOW_P:
     593              : 
     594              :       /* These have constant results even if their operands are
     595              :          non-constant.  */
     596              :     case BUILT_IN_CONSTANT_P:
     597              :     case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE:
     598              :       return true;
     599              :     default:
     600              :       return false;
     601              :     }
     602              : }
     603              : 
     604              : /* Build a TARGET_EXPR, initializing the DECL with the VALUE.  */
     605              : 
     606              : static tree
     607     48207026 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
     608              : {
     609     48207026 :   tree t;
     610     48207026 :   tree type = TREE_TYPE (decl);
     611              : 
     612     48207026 :   value = mark_rvalue_use (value);
     613              : 
     614     48207026 :   gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
     615              :                        || TREE_TYPE (decl) == TREE_TYPE (value)
     616              :                        /* On ARM ctors return 'this'.  */
     617              :                        || (TYPE_PTR_P (TREE_TYPE (value))
     618              :                            && TREE_CODE (value) == CALL_EXPR)
     619              :                        || useless_type_conversion_p (TREE_TYPE (decl),
     620              :                                                      TREE_TYPE (value)));
     621              : 
     622              :   /* Set TREE_READONLY for optimization, such as gimplify_init_constructor
     623              :      moving a constant aggregate into .rodata.  */
     624     48207026 :   if (CP_TYPE_CONST_NON_VOLATILE_P (type)
     625      2536571 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     626      2365033 :       && !VOID_TYPE_P (TREE_TYPE (value))
     627      1222925 :       && !TYPE_HAS_MUTABLE_P (type)
     628     49429944 :       && reduced_constant_expression_p (value))
     629       317426 :     TREE_READONLY (decl) = true;
     630              : 
     631     48207026 :   if (complain & tf_no_cleanup)
     632              :     /* The caller is building a new-expr and does not need a cleanup.  */
     633              :     t = NULL_TREE;
     634              :   else
     635              :     {
     636     47427088 :       t = cxx_maybe_build_cleanup (decl, complain);
     637     47427088 :       if (t == error_mark_node)
     638              :         return error_mark_node;
     639              :     }
     640              : 
     641     48206990 :   set_target_expr_eliding (value);
     642              : 
     643     48206990 :   t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
     644     48206990 :   if (location_t eloc = cp_expr_location (value))
     645     31985983 :     SET_EXPR_LOCATION (t, eloc);
     646              :   /* We always set TREE_SIDE_EFFECTS so that expand_expr does not
     647              :      ignore the TARGET_EXPR.  If there really turn out to be no
     648              :      side-effects, then the optimizer should be able to get rid of
     649              :      whatever code is generated anyhow.  */
     650     48206990 :   TREE_SIDE_EFFECTS (t) = 1;
     651              : 
     652     48206990 :   return t;
     653              : }
     654              : 
     655              : /* Return an undeclared local temporary of type TYPE for use in building a
     656              :    TARGET_EXPR.  */
     657              : 
     658              : tree
     659     54297802 : build_local_temp (tree type)
     660              : {
     661     54297802 :   tree slot = build_decl (input_location,
     662              :                           VAR_DECL, NULL_TREE, type);
     663     54297802 :   DECL_ARTIFICIAL (slot) = 1;
     664     54297802 :   DECL_IGNORED_P (slot) = 1;
     665     54297802 :   DECL_CONTEXT (slot) = current_function_decl;
     666     54297802 :   layout_decl (slot, 0);
     667     54297802 :   return slot;
     668              : }
     669              : 
     670              : /* Return whether DECL is such a local temporary (or one from
     671              :    create_tmp_var_raw).  */
     672              : 
     673              : bool
     674     63932716 : is_local_temp (tree decl)
     675              : {
     676     63932716 :   return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
     677     64645894 :           && !TREE_STATIC (decl));
     678              : }
     679              : 
     680              : /* Set various status flags when building an AGGR_INIT_EXPR object T.  */
     681              : 
     682              : static void
     683     16051769 : process_aggr_init_operands (tree t)
     684              : {
     685     16051769 :   bool side_effects;
     686              : 
     687     16051769 :   side_effects = TREE_SIDE_EFFECTS (t);
     688     16051769 :   if (!side_effects)
     689              :     {
     690     16051769 :       int i, n;
     691     16051769 :       n = TREE_OPERAND_LENGTH (t);
     692     71863294 :       for (i = 1; i < n; i++)
     693              :         {
     694     60197824 :           tree op = TREE_OPERAND (t, i);
     695     60197824 :           if (op && TREE_SIDE_EFFECTS (op))
     696              :             {
     697              :               side_effects = 1;
     698              :               break;
     699              :             }
     700              :         }
     701              :     }
     702     16051769 :   TREE_SIDE_EFFECTS (t) = side_effects;
     703     16051769 : }
     704              : 
     705              : /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE,
     706              :    FN, and SLOT.  NARGS is the number of call arguments which are specified
     707              :    as a tree array ARGS.  */
     708              : 
     709              : static tree
     710     16051769 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
     711              :                        tree *args)
     712              : {
     713     16051769 :   tree t;
     714     16051769 :   int i;
     715              : 
     716     16051769 :   t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
     717     16051769 :   TREE_TYPE (t) = return_type;
     718     16051769 :   AGGR_INIT_EXPR_FN (t) = fn;
     719     16051769 :   AGGR_INIT_EXPR_SLOT (t) = slot;
     720     46253310 :   for (i = 0; i < nargs; i++)
     721     30201541 :     AGGR_INIT_EXPR_ARG (t, i) = args[i];
     722     16051769 :   process_aggr_init_operands (t);
     723     16051769 :   return t;
     724              : }
     725              : 
     726              : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
     727              :    target.  TYPE is the type to be initialized.
     728              : 
     729              :    Build an AGGR_INIT_EXPR to represent the initialization.  This function
     730              :    differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used
     731              :    to initialize another object, whereas a TARGET_EXPR can either
     732              :    initialize another object or create its own temporary object, and as a
     733              :    result building up a TARGET_EXPR requires that the type's destructor be
     734              :    callable.  */
     735              : 
     736              : tree
     737     56565289 : build_aggr_init_expr (tree type, tree init)
     738              : {
     739     56565289 :   tree fn;
     740     56565289 :   tree slot;
     741     56565289 :   tree rval;
     742     56565289 :   int is_ctor;
     743              : 
     744     56565289 :   gcc_assert (!VOID_TYPE_P (type));
     745              : 
     746              :   /* Don't build AGGR_INIT_EXPR in a template.  */
     747     56565289 :   if (processing_template_decl)
     748              :     return init;
     749              : 
     750     56427890 :   fn = cp_get_callee (init);
     751     56427890 :   if (fn == NULL_TREE)
     752     23583089 :     return convert (type, init);
     753              : 
     754     67165791 :   is_ctor = (TREE_CODE (fn) == ADDR_EXPR
     755     32735580 :              && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
     756     98315961 :              && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
     757              : 
     758              :   /* We split the CALL_EXPR into its function and its arguments here.
     759              :      Then, in expand_expr, we put them back together.  The reason for
     760              :      this is that this expression might be a default argument
     761              :      expression.  In that case, we need a new temporary every time the
     762              :      expression is used.  That's what break_out_target_exprs does; it
     763              :      replaces every AGGR_INIT_EXPR with a copy that uses a fresh
     764              :      temporary slot.  Then, expand_expr builds up a call-expression
     765              :      using the new slot.  */
     766              : 
     767              :   /* If we don't need to use a constructor to create an object of this
     768              :      type, don't mess with AGGR_INIT_EXPR.  */
     769     18269221 :   if (is_ctor || TREE_ADDRESSABLE (type))
     770              :     {
     771     16051769 :       slot = build_local_temp (type);
     772              : 
     773     16051769 :       if (TREE_CODE (init) == CALL_EXPR)
     774              :         {
     775     62163896 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     776     15540974 :                                         call_expr_nargs (init),
     777     15540974 :                                         CALL_EXPR_ARGP (init));
     778     15540974 :           AGGR_INIT_FROM_THUNK_P (rval)
     779     15540974 :             = CALL_FROM_THUNK_P (init);
     780              :         }
     781              :       else
     782              :         {
     783       510795 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     784       510795 :                                         aggr_init_expr_nargs (init),
     785       510795 :                                         AGGR_INIT_EXPR_ARGP (init));
     786       510795 :           AGGR_INIT_FROM_THUNK_P (rval)
     787       510795 :             = AGGR_INIT_FROM_THUNK_P (init);
     788              :         }
     789     16051769 :       TREE_SIDE_EFFECTS (rval) = 1;
     790     16051769 :       AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
     791     16051769 :       TREE_NOTHROW (rval) = TREE_NOTHROW (init);
     792     16051769 :       CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
     793     16051769 :       CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
     794     16051769 :       CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
     795     16051769 :       SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
     796              :     }
     797              :   else
     798              :     rval = init;
     799              : 
     800              :   return rval;
     801              : }
     802              : 
     803              : /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its
     804              :    target.  TYPE is the type that this initialization should appear to
     805              :    have.
     806              : 
     807              :    Build an encapsulation of the initialization to perform
     808              :    and return it so that it can be processed by language-independent
     809              :    and language-specific expression expanders.  */
     810              : 
     811              : tree
     812     49597654 : build_cplus_new (tree type, tree init, tsubst_flags_t complain)
     813              : {
     814              :   /* This function should cope with what build_special_member_call
     815              :      can produce.  When performing parenthesized aggregate initialization,
     816              :      it can produce a { }.  */
     817     49597654 :   if (BRACE_ENCLOSED_INITIALIZER_P (init))
     818              :     {
     819          310 :       gcc_assert (cxx_dialect >= cxx20);
     820          310 :       return finish_compound_literal (type, init, complain);
     821              :     }
     822              : 
     823     49597344 :   tree rval = build_aggr_init_expr (type, init);
     824     49597344 :   tree slot;
     825              : 
     826     49597344 :   if (init == error_mark_node)
     827              :     return error_mark_node;
     828              : 
     829     49595283 :   if (!complete_type_or_maybe_complain (type, init, complain))
     830            6 :     return error_mark_node;
     831              : 
     832              :   /* Make sure that we're not trying to create an instance of an
     833              :      abstract class.  */
     834     49595277 :   if (abstract_virtuals_error (NULL_TREE, type, complain))
     835           19 :     return error_mark_node;
     836              : 
     837     49595258 :   if (TREE_CODE (rval) == AGGR_INIT_EXPR)
     838      9337212 :     slot = AGGR_INIT_EXPR_SLOT (rval);
     839     40258046 :   else if (TREE_CODE (rval) == CALL_EXPR
     840     23327632 :            || TREE_CODE (rval) == CONSTRUCTOR)
     841     16930564 :     slot = build_local_temp (type);
     842              :   else
     843              :     return rval;
     844              : 
     845     26267776 :   rval = build_target_expr (slot, rval, complain);
     846              : 
     847     26267776 :   if (rval != error_mark_node)
     848     26267776 :     TARGET_EXPR_IMPLICIT_P (rval) = 1;
     849              : 
     850              :   return rval;
     851              : }
     852              : 
     853              : /* Subroutine of build_vec_init_expr: Build up a single element
     854              :    intialization as a proxy for the full array initialization to get things
     855              :    marked as used and any appropriate diagnostics.
     856              : 
     857              :    This used to be necessary because we were deferring building the actual
     858              :    constructor calls until gimplification time; now we only do it to set
     859              :    VEC_INIT_EXPR_IS_CONSTEXPR.
     860              : 
     861              :    We assume that init is either NULL_TREE, {}, void_type_node (indicating
     862              :    value-initialization), or another array to copy.  */
     863              : 
     864              : static tree
     865         1167 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
     866              : {
     867         1167 :   tree inner_type = strip_array_types (type);
     868              : 
     869         1167 :   if (integer_zerop (array_type_nelts_total (type))
     870         1167 :       || !CLASS_TYPE_P (inner_type))
     871              :     /* No interesting initialization to do.  */
     872          216 :     return integer_zero_node;
     873          951 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
     874              :     {
     875              :       /* Even if init has initializers for some array elements,
     876              :          we're interested in the {}-init of trailing elements.  */
     877          119 :       if (CP_AGGREGATE_TYPE_P (inner_type))
     878              :         {
     879           34 :           tree empty = build_constructor (init_list_type_node, nullptr);
     880           34 :           return digest_init (inner_type, empty, complain);
     881              :         }
     882              :       else
     883              :         /* It's equivalent to value-init.  */
     884           85 :         init = void_type_node;
     885              :     }
     886          917 :   if (init == void_type_node)
     887          116 :     return build_value_init (inner_type, complain);
     888              : 
     889          801 :   releasing_vec argvec;
     890          801 :   if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
     891              :     {
     892          202 :       tree init_type = strip_array_types (TREE_TYPE (init));
     893          202 :       tree dummy = build_dummy_object (init_type);
     894          202 :       if (!lvalue_p (init))
     895          157 :         dummy = move (dummy);
     896          202 :       argvec->quick_push (dummy);
     897              :     }
     898          801 :   init = build_special_member_call (NULL_TREE, complete_ctor_identifier,
     899              :                                     &argvec, inner_type, LOOKUP_NORMAL,
     900              :                                     complain);
     901              : 
     902              :   /* For a trivial constructor, build_over_call creates a TARGET_EXPR.  But
     903              :      we don't want one here because we aren't creating a temporary.  */
     904          801 :   if (TREE_CODE (init) == TARGET_EXPR)
     905           32 :     init = TARGET_EXPR_INITIAL (init);
     906              : 
     907          801 :   return init;
     908          801 : }
     909              : 
     910              : /* Return a TARGET_EXPR which expresses the initialization of an array to
     911              :    be named later, either default-initialization or copy-initialization
     912              :    from another array of the same type.  */
     913              : 
     914              : tree
     915         1184 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
     916              : {
     917         1184 :   if (tree vi = get_vec_init_expr (init))
     918              :     return vi;
     919              : 
     920         1169 :   tree elt_init;
     921          558 :   if (init && TREE_CODE (init) == CONSTRUCTOR
     922         1292 :       && !BRACE_ENCLOSED_INITIALIZER_P (init))
     923              :     /* We built any needed constructor calls in digest_init.  */
     924              :     elt_init = init;
     925              :   else
     926         1165 :     elt_init = build_vec_init_elt (type, init, complain);
     927              : 
     928         1169 :   bool value_init = false;
     929         1169 :   if (init == void_type_node)
     930              :     {
     931          226 :       value_init = true;
     932          226 :       init = NULL_TREE;
     933              :     }
     934              : 
     935         1169 :   tree slot = build_local_temp (type);
     936         1169 :   init = build2 (VEC_INIT_EXPR, type, slot, init);
     937         1169 :   TREE_SIDE_EFFECTS (init) = true;
     938         1169 :   SET_EXPR_LOCATION (init, input_location);
     939              : 
     940         1169 :   if (cxx_dialect >= cxx11)
     941              :     {
     942         1104 :       bool cx = potential_constant_expression (elt_init);
     943         1104 :       if (BRACE_ENCLOSED_INITIALIZER_P (init))
     944            0 :         cx &= potential_constant_expression (init);
     945         1104 :       VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
     946              :     }
     947         1169 :   VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
     948              : 
     949         1169 :   return init;
     950              : }
     951              : 
     952              : /* Call build_vec_init to expand VEC_INIT into TARGET (for which NULL_TREE
     953              :    means VEC_INIT_EXPR_SLOT).  */
     954              : 
     955              : tree
     956         1185 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
     957              :                       vec<tree,va_gc> **flags)
     958              : {
     959         1185 :   iloc_sentinel ils = EXPR_LOCATION (vec_init);
     960              : 
     961         1185 :   if (!target)
     962            0 :     target = VEC_INIT_EXPR_SLOT (vec_init);
     963         1185 :   tree init = VEC_INIT_EXPR_INIT (vec_init);
     964         1185 :   int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
     965         3555 :   return build_vec_init (target, NULL_TREE, init,
     966         1185 :                          VEC_INIT_EXPR_VALUE_INIT (vec_init),
     967         1185 :                          from_array, complain, flags);
     968         1185 : }
     969              : 
     970              : /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context
     971              :    that requires a constant expression.  */
     972              : 
     973              : void
     974            2 : diagnose_non_constexpr_vec_init (tree expr)
     975              : {
     976            2 :   tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr));
     977            2 :   tree init, elt_init;
     978            2 :   if (VEC_INIT_EXPR_VALUE_INIT (expr))
     979            2 :     init = void_type_node;
     980              :   else
     981            0 :     init = VEC_INIT_EXPR_INIT (expr);
     982              : 
     983            2 :   elt_init = build_vec_init_elt (type, init, tf_warning_or_error);
     984            2 :   require_potential_constant_expression (elt_init);
     985            2 : }
     986              : 
     987              : tree
     988           19 : build_array_copy (tree init)
     989              : {
     990           19 :   return get_target_expr (build_vec_init_expr
     991           19 :                           (TREE_TYPE (init), init, tf_warning_or_error));
     992              : }
     993              : 
     994              : /* Build a TARGET_EXPR using INIT to initialize a new temporary of the
     995              :    indicated TYPE.  */
     996              : 
     997              : tree
     998     10830399 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
     999              : {
    1000     10830399 :   gcc_assert (!VOID_TYPE_P (type));
    1001     10830399 :   gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
    1002              : 
    1003     10830399 :   if (TREE_CODE (init) == TARGET_EXPR
    1004      9278758 :       || init == error_mark_node)
    1005              :     return init;
    1006      6783688 :   else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
    1007        85715 :            && TREE_CODE (init) != COND_EXPR
    1008              :            && TREE_CODE (init) != CONSTRUCTOR
    1009              :            && TREE_CODE (init) != VA_ARG_EXPR
    1010      9278500 :            && TREE_CODE (init) != CALL_EXPR)
    1011              :     /* We need to build up a copy constructor call.  COND_EXPR is a special
    1012              :        case because we already have copies on the arms and we don't want
    1013              :        another one here.  A CONSTRUCTOR is aggregate initialization, which
    1014              :        is handled separately.  A VA_ARG_EXPR is magic creation of an
    1015              :        aggregate; there's no additional work to be done.  A CALL_EXPR
    1016              :        already creates a prvalue.  */
    1017            0 :     return force_rvalue (init, complain);
    1018              : 
    1019      9278500 :   return force_target_expr (type, init, complain);
    1020              : }
    1021              : 
    1022              : /* Like the above function, but without the checking.  This function should
    1023              :    only be used by code which is deliberately trying to subvert the type
    1024              :    system, such as call_builtin_trap.  Or build_over_call, to avoid
    1025              :    infinite recursion.  */
    1026              : 
    1027              : tree
    1028     21314277 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
    1029              : {
    1030     21314277 :   tree slot;
    1031              : 
    1032     21314277 :   gcc_assert (!VOID_TYPE_P (type));
    1033              : 
    1034     21314277 :   slot = build_local_temp (type);
    1035     21314277 :   return build_target_expr (slot, init, complain);
    1036              : }
    1037              : 
    1038              : /* Like build_target_expr_with_type, but use the type of INIT.  */
    1039              : 
    1040              : tree
    1041      8454373 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
    1042              : {
    1043      8454373 :   if (TREE_CODE (init) == AGGR_INIT_EXPR)
    1044       624679 :     return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
    1045      7829694 :   else if (TREE_CODE (init) == VEC_INIT_EXPR)
    1046          294 :     return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
    1047              :   else
    1048              :     {
    1049      7829400 :       init = convert_bitfield_to_declared_type (init);
    1050      7829400 :       return build_target_expr_with_type (init, TREE_TYPE (init), complain);
    1051              :     }
    1052              : }
    1053              : 
    1054              : /* Like get_target_expr, but for an internal detail like a cleanup flag or loop
    1055              :    iterator.  These variables should not be extended by extend_all_temps.
    1056              : 
    1057              :    This function can also be used for an ephemeral copy of a scalar value such
    1058              :    as the pointer to the allocated memory in build_new_1.
    1059              : 
    1060              :    This function should not be used for objects that are part of the abstract
    1061              :    C++ semantics such as in stabilize_expr.  */
    1062              : 
    1063              : tree
    1064      3035133 : get_internal_target_expr (tree init)
    1065              : {
    1066      3035133 :   init = convert_bitfield_to_declared_type (init);
    1067      3035133 :   tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
    1068      3035133 :   TARGET_EXPR_INTERNAL_P (t) = true;
    1069      3035133 :   return t;
    1070              : }
    1071              : 
    1072              : /* If EXPR is a bitfield reference, convert it to the declared type of
    1073              :    the bitfield, and return the resulting expression.  Otherwise,
    1074              :    return EXPR itself.  */
    1075              : 
    1076              : tree
    1077   1231873236 : convert_bitfield_to_declared_type (tree expr)
    1078              : {
    1079   1231873236 :   tree bitfield_type;
    1080              : 
    1081   1231873236 :   bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1082   1231873236 :   if (bitfield_type)
    1083      2132903 :     expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
    1084              :                                       expr);
    1085   1231873236 :   return expr;
    1086              : }
    1087              : 
    1088              : /* EXPR is being used in an rvalue context.  Return a version of EXPR
    1089              :    that is marked as an rvalue.  */
    1090              : 
    1091              : tree
    1092    214806250 : rvalue (tree expr)
    1093              : {
    1094    214806250 :   tree type;
    1095              : 
    1096    214806250 :   if (error_operand_p (expr))
    1097              :     return expr;
    1098              : 
    1099    214805933 :   expr = mark_rvalue_use (expr);
    1100              : 
    1101              :   /* [expr.type]: "If a prvalue initially has the type "cv T", where T is a
    1102              :      cv-unqualified non-class, non-array type, the type of the expression is
    1103              :      adjusted to T prior to any further analysis.  */
    1104    214805933 :   type = TREE_TYPE (expr);
    1105    214805933 :   if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
    1106    425917726 :       && cv_qualified_p (type))
    1107     34980666 :     type = cv_unqualified (type);
    1108              : 
    1109              :   /* We need to do this for rvalue refs as well to get the right answer
    1110              :      from decltype; see c++/36628.  */
    1111    214805933 :   if (!processing_template_decl && glvalue_p (expr))
    1112              :     {
    1113              :       /* But don't use this function for class lvalues; use move (to treat an
    1114              :          lvalue as an xvalue) or force_rvalue (to make a prvalue copy).  */
    1115     11817150 :       gcc_checking_assert (!CLASS_TYPE_P (type));
    1116     11817150 :       expr = build1 (NON_LVALUE_EXPR, type, expr);
    1117              :     }
    1118    202988783 :   else if (type != TREE_TYPE (expr))
    1119     34734662 :     expr = build_nop (type, expr);
    1120              : 
    1121              :   return expr;
    1122              : }
    1123              : 
    1124              : 
    1125              : struct cplus_array_info
    1126              : {
    1127              :   tree type;
    1128              :   tree domain;
    1129              : };
    1130              : 
    1131              : struct cplus_array_hasher : ggc_ptr_hash<tree_node>
    1132              : {
    1133              :   typedef cplus_array_info *compare_type;
    1134              : 
    1135              :   static hashval_t hash (tree t);
    1136              :   static bool equal (tree, cplus_array_info *);
    1137              : };
    1138              : 
    1139              : /* Hash an ARRAY_TYPE.  K is really of type `tree'.  */
    1140              : 
    1141              : hashval_t
    1142     37734346 : cplus_array_hasher::hash (tree t)
    1143              : {
    1144     37734346 :   hashval_t hash;
    1145              : 
    1146     37734346 :   hash = TYPE_UID (TREE_TYPE (t));
    1147     37734346 :   if (TYPE_DOMAIN (t))
    1148     35952677 :     hash ^= TYPE_UID (TYPE_DOMAIN (t));
    1149     37734346 :   return hash;
    1150              : }
    1151              : 
    1152              : /* Compare two ARRAY_TYPEs.  K1 is really of type `tree', K2 is really
    1153              :    of type `cplus_array_info*'. */
    1154              : 
    1155              : bool
    1156     47301451 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
    1157              : {
    1158     50120209 :   return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain);
    1159              : }
    1160              : 
    1161              : /* Hash table containing dependent array types, which are unsuitable for
    1162              :    the language-independent type hash table.  */
    1163              : static GTY (()) hash_table<cplus_array_hasher> *cplus_array_htab;
    1164              : 
    1165              : /* Build an ARRAY_TYPE without laying it out.  */
    1166              : 
    1167              : static tree
    1168      5323010 : build_min_array_type (tree elt_type, tree index_type)
    1169              : {
    1170      5323010 :   tree t = cxx_make_type (ARRAY_TYPE);
    1171      5323010 :   TREE_TYPE (t) = elt_type;
    1172      5323010 :   TYPE_DOMAIN (t) = index_type;
    1173      5323010 :   return t;
    1174              : }
    1175              : 
    1176              : /* Set TYPE_CANONICAL like build_array_type_1, but using
    1177              :    build_cplus_array_type.  */
    1178              : 
    1179              : static void
    1180      5323010 : set_array_type_canon (tree t, tree elt_type, tree index_type, bool dep)
    1181              : {
    1182              :   /* Set the canonical type for this new node.  */
    1183      5323010 :   if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
    1184      5323010 :       || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
    1185      1434515 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1186      3888495 :   else if (TYPE_CANONICAL (elt_type) != elt_type
    1187      3888495 :            || (index_type && TYPE_CANONICAL (index_type) != index_type))
    1188      1159177 :     TYPE_CANONICAL (t)
    1189      3022464 :       = build_cplus_array_type (TYPE_CANONICAL (elt_type),
    1190              :                                 index_type
    1191       704110 :                                 ? TYPE_CANONICAL (index_type) : index_type,
    1192              :                                 dep);
    1193              :   else
    1194      2729318 :     TYPE_CANONICAL (t) = t;
    1195      5323010 : }
    1196              : 
    1197              : /* Like build_array_type, but handle special C++ semantics: an array of a
    1198              :    variant element type is a variant of the array of the main variant of
    1199              :    the element type.  IS_DEPENDENT is -ve if we should determine the
    1200              :    dependency.  Otherwise its bool value indicates dependency.  */
    1201              : 
    1202              : tree
    1203     63712791 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
    1204              : {
    1205     63712791 :   tree t;
    1206              : 
    1207     63712791 :   if (elt_type == error_mark_node || index_type == error_mark_node)
    1208              :     return error_mark_node;
    1209              : 
    1210     63712788 :   if (dependent < 0)
    1211     66563642 :     dependent = (uses_template_parms (elt_type)
    1212     33281821 :                  || (index_type && uses_template_parms (index_type)));
    1213              : 
    1214     63712788 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1215              :     /* Start with an array of the TYPE_MAIN_VARIANT.  */
    1216     26842025 :     t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
    1217              :                                 index_type, dependent);
    1218     36870763 :   else if (dependent)
    1219              :     {
    1220              :       /* Since type_hash_canon calls layout_type, we need to use our own
    1221              :          hash table.  */
    1222      4680849 :       cplus_array_info cai;
    1223      4680849 :       hashval_t hash;
    1224              : 
    1225      4680849 :       if (cplus_array_htab == NULL)
    1226        16830 :         cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
    1227              : 
    1228      4680849 :       hash = TYPE_UID (elt_type);
    1229      4680849 :       if (index_type)
    1230      2403063 :         hash ^= TYPE_UID (index_type);
    1231      4680849 :       cai.type = elt_type;
    1232      4680849 :       cai.domain = index_type;
    1233              : 
    1234      4680849 :       tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
    1235      4680849 :       if (*e)
    1236              :         /* We have found the type: we're done.  */
    1237      2711313 :         return (tree) *e;
    1238              :       else
    1239              :         {
    1240              :           /* Build a new array type.  */
    1241      1969536 :           t = build_min_array_type (elt_type, index_type);
    1242              : 
    1243              :           /* Store it in the hash table. */
    1244      1969536 :           *e = t;
    1245              : 
    1246              :           /* Set the canonical type for this new node.  */
    1247      1969536 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1248              : 
    1249              :           /* Mark it as dependent now, this saves time later.  */
    1250      1969536 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1251      1969536 :           TYPE_DEPENDENT_P (t) = true;
    1252              :         }
    1253              :     }
    1254              :   else
    1255              :     {
    1256     32189914 :       bool typeless_storage = is_byte_access_type (elt_type);
    1257     32189914 :       t = build_array_type (elt_type, index_type, typeless_storage);
    1258              : 
    1259              :       /* Mark as non-dependenty now, this will save time later.  */
    1260     32189914 :       TYPE_DEPENDENT_P_VALID (t) = true;
    1261              :     }
    1262              : 
    1263              :   /* Now check whether we already have this array variant.  */
    1264     61001475 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1265              :     {
    1266              :       tree m = t;
    1267     54864737 :       for (t = m; t; t = TYPE_NEXT_VARIANT (t))
    1268     51511263 :         if (TREE_TYPE (t) == elt_type
    1269     23502616 :             && TYPE_NAME (t) == NULL_TREE
    1270     23488554 :             && TYPE_ATTRIBUTES (t) == NULL_TREE
    1271     23488554 :             && (!TYPE_USER_ALIGN (t)
    1272        17891 :                 || (TYPE_USER_ALIGN (elt_type)
    1273        17888 :                     && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
    1274     23488551 :             && !TREE_DEPRECATED (t)
    1275     74999814 :             && !TREE_UNAVAILABLE (t))
    1276              :           break;
    1277     26842025 :       if (!t)
    1278              :         {
    1279      3353474 :           t = build_min_array_type (elt_type, index_type);
    1280              :           /* Mark dependency now, this saves time later.  */
    1281      3353474 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1282      3353474 :           TYPE_DEPENDENT_P (t) = dependent;
    1283      3353474 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1284      3353474 :           if (!dependent)
    1285              :             {
    1286      2744648 :               layout_type (t);
    1287              :               /* Make sure sizes are shared with the main variant.
    1288              :                  layout_type can't be called after setting TYPE_NEXT_VARIANT,
    1289              :                  as it will overwrite alignment etc. of all variants.  */
    1290      2744648 :               TYPE_SIZE (t) = TYPE_SIZE (m);
    1291      2744648 :               TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
    1292      2744648 :               TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
    1293              :             }
    1294              : 
    1295      3353474 :           TYPE_MAIN_VARIANT (t) = m;
    1296      3353474 :           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
    1297      3353474 :           TYPE_NEXT_VARIANT (m) = t;
    1298              :         }
    1299              :     }
    1300              : 
    1301              :   /* Avoid spurious warnings with VLAs (c++/54583).  */
    1302     61001475 :   if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
    1303         2042 :     suppress_warning (TYPE_SIZE (t), OPT_Wunused);
    1304              : 
    1305              :   /* Push these needs up to the ARRAY_TYPE so that initialization takes
    1306              :      place more easily.  */
    1307    122002950 :   bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
    1308     61001475 :                      = TYPE_NEEDS_CONSTRUCTING (elt_type));
    1309    122002950 :   bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1310     61001475 :                      = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
    1311              : 
    1312     58282047 :   if (!dependent && t == TYPE_MAIN_VARIANT (t)
    1313     93191389 :       && !COMPLETE_TYPE_P (t) && COMPLETE_TYPE_P (elt_type))
    1314              :     {
    1315              :       /* The element type has been completed since the last time we saw
    1316              :          this array type; update the layout and 'tor flags for any variants
    1317              :          that need it.  */
    1318      2949041 :       layout_type (t);
    1319      4522295 :       for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    1320              :         {
    1321      1573254 :           TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
    1322      1573254 :           TYPE_HAS_NONTRIVIAL_DESTRUCTOR (v) = needs_dtor;
    1323              :         }
    1324              :     }
    1325              : 
    1326              :   return t;
    1327              : }
    1328              : 
    1329              : /* Return an ARRAY_TYPE with element type ELT and length N.  */
    1330              : 
    1331              : tree
    1332      2252922 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
    1333              : {
    1334      2252922 :   return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
    1335              : }
    1336              : 
    1337              : /* True iff T is an array of unknown bound.  */
    1338              : 
    1339              : bool
    1340      8401635 : array_of_unknown_bound_p (const_tree t)
    1341              : {
    1342      8401635 :   return (TREE_CODE (t) == ARRAY_TYPE
    1343      8401635 :           && !TYPE_DOMAIN (t));
    1344              : }
    1345              : 
    1346              : /* True iff T is an N3639 array of runtime bound (VLA).  These were approved
    1347              :    for C++14 but then removed.  This should only be used for N3639
    1348              :    specifically; code wondering more generally if something is a VLA should use
    1349              :    vla_type_p.  */
    1350              : 
    1351              : bool
    1352       537923 : array_of_runtime_bound_p (tree t)
    1353              : {
    1354       537923 :   if (!t || TREE_CODE (t) != ARRAY_TYPE)
    1355              :     return false;
    1356          247 :   if (variably_modified_type_p (TREE_TYPE (t), NULL_TREE))
    1357              :     return false;
    1358          235 :   tree dom = TYPE_DOMAIN (t);
    1359          235 :   if (!dom)
    1360              :     return false;
    1361          232 :   tree max = TYPE_MAX_VALUE (dom);
    1362          232 :   return (!potential_rvalue_constant_expression (max)
    1363          232 :           || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)));
    1364              : }
    1365              : 
    1366              : /* True iff T is a variable length array.  */
    1367              : 
    1368              : bool
    1369     49896344 : vla_type_p (tree t)
    1370              : {
    1371     50786958 :   for (; t && TREE_CODE (t) == ARRAY_TYPE;
    1372       890614 :        t = TREE_TYPE (t))
    1373       890797 :     if (tree dom = TYPE_DOMAIN (t))
    1374              :       {
    1375       890733 :         tree max = TYPE_MAX_VALUE (dom);
    1376       890733 :         if (!potential_rvalue_constant_expression (max)
    1377       890733 :             || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max)))
    1378          183 :           return true;
    1379              :       }
    1380              :   return false;
    1381              : }
    1382              : 
    1383              : 
    1384              : /* Return a reference type node of MODE referring to TO_TYPE.  If MODE
    1385              :    is VOIDmode the standard pointer mode will be picked.  If RVAL is
    1386              :    true, return an rvalue reference type, otherwise return an lvalue
    1387              :    reference type.  If a type node exists, reuse it, otherwise create
    1388              :    a new one.  */
    1389              : tree
    1390    770103505 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
    1391              : {
    1392    770103505 :   tree lvalue_ref, t;
    1393              : 
    1394    770103505 :   if (to_type == error_mark_node)
    1395              :     return error_mark_node;
    1396              : 
    1397    770103500 :   if (TYPE_REF_P (to_type))
    1398              :     {
    1399         1180 :       rval = rval && TYPE_REF_IS_RVALUE (to_type);
    1400         1180 :       to_type = TREE_TYPE (to_type);
    1401              :     }
    1402              : 
    1403    770103500 :   lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
    1404              : 
    1405    770103500 :   if (!rval)
    1406              :     return lvalue_ref;
    1407              : 
    1408              :   /* This code to create rvalue reference types is based on and tied
    1409              :      to the code creating lvalue reference types in the middle-end
    1410              :      functions build_reference_type_for_mode and build_reference_type.
    1411              : 
    1412              :      It works by putting the rvalue reference type nodes after the
    1413              :      lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so
    1414              :      they will effectively be ignored by the middle end.  */
    1415              : 
    1416    116358798 :   for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
    1417     87603509 :     if (TYPE_REF_IS_RVALUE (t))
    1418              :       return t;
    1419              : 
    1420     28755289 :   t = build_distinct_type_copy (lvalue_ref);
    1421              : 
    1422     28755289 :   TYPE_REF_IS_RVALUE (t) = true;
    1423     28755289 :   TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
    1424     28755289 :   TYPE_NEXT_REF_TO (lvalue_ref) = t;
    1425              : 
    1426     28755289 :   if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
    1427       968046 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1428     27787243 :   else if (TYPE_CANONICAL (to_type) != to_type)
    1429     15100910 :     TYPE_CANONICAL (t)
    1430     30201820 :       = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
    1431              :   else
    1432     12686333 :     TYPE_CANONICAL (t) = t;
    1433              : 
    1434     28755289 :   layout_type (t);
    1435              : 
    1436     28755289 :   return t;
    1437              : 
    1438              : }
    1439              : 
    1440              : /* Return a reference type node referring to TO_TYPE.  If RVAL is
    1441              :    true, return an rvalue reference type, otherwise return an lvalue
    1442              :    reference type.  If a type node exists, reuse it, otherwise create
    1443              :    a new one.  */
    1444              : tree
    1445    624982150 : cp_build_reference_type (tree to_type, bool rval)
    1446              : {
    1447    624982150 :   return cp_build_reference_type_for_mode (to_type, VOIDmode, rval);
    1448              : }
    1449              : 
    1450              : /* Returns EXPR cast to rvalue reference type, like std::move.  */
    1451              : 
    1452              : tree
    1453      2239506 : move (tree expr)
    1454              : {
    1455      2239506 :   tree type = TREE_TYPE (expr);
    1456      2239506 :   gcc_assert (!TYPE_REF_P (type));
    1457      2239506 :   if (xvalue_p (expr))
    1458              :     return expr;
    1459      2239249 :   type = cp_build_reference_type (type, /*rval*/true);
    1460      2239249 :   return build_static_cast (input_location, type, expr,
    1461      2239249 :                             tf_warning_or_error);
    1462              : }
    1463              : 
    1464              : /* Used by the C++ front end to build qualified array types.  However,
    1465              :    the C version of this function does not properly maintain canonical
    1466              :    types (which are not used in C).  */
    1467              : tree
    1468     25608310 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
    1469              :                         size_t /* orig_qual_indirect */)
    1470              : {
    1471     25608310 :   return cp_build_qualified_type (type, type_quals);
    1472              : }
    1473              : 
    1474              : 
    1475              : /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
    1476              :    arrays correctly.  In particular, if TYPE is an array of T's, and
    1477              :    TYPE_QUALS is non-empty, returns an array of qualified T's.
    1478              : 
    1479              :    FLAGS determines how to deal with ill-formed qualifications. If
    1480              :    tf_ignore_bad_quals is set, then bad qualifications are dropped
    1481              :    (this is permitted if TYPE was introduced via a typedef or template
    1482              :    type parameter). If bad qualifications are dropped and tf_warning
    1483              :    is set, then a warning is issued for non-const qualifications.  If
    1484              :    tf_ignore_bad_quals is not set and tf_error is not set, we
    1485              :    return error_mark_node. Otherwise, we issue an error, and ignore
    1486              :    the qualifications.
    1487              : 
    1488              :    Qualification of a reference type is valid when the reference came
    1489              :    via a typedef or template type argument. [dcl.ref] No such
    1490              :    dispensation is provided for qualifying a function type.  [dcl.fct]
    1491              :    DR 295 queries this and the proposed resolution brings it into line
    1492              :    with qualifying a reference.  We implement the DR.  We also behave
    1493              :    in a similar manner for restricting non-pointer types.  */
    1494              : 
    1495              : tree
    1496  21777449966 : cp_build_qualified_type (tree type, int type_quals,
    1497              :                          tsubst_flags_t complain /* = tf_warning_or_error */)
    1498              : {
    1499  21777449966 :   tree result;
    1500  21777449966 :   int bad_quals = TYPE_UNQUALIFIED;
    1501              : 
    1502  21777449966 :   if (type == error_mark_node)
    1503              :     return type;
    1504              : 
    1505  21721336265 :   if (type_quals == cp_type_quals (type))
    1506              :     return type;
    1507              : 
    1508   4235502954 :   if (TREE_CODE (type) == ARRAY_TYPE)
    1509              :     {
    1510              :       /* In C++, the qualification really applies to the array element
    1511              :          type.  Obtain the appropriately qualified element type.  */
    1512     31816868 :       tree t;
    1513     31816868 :       tree element_type
    1514     31816868 :         = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
    1515              : 
    1516     31816868 :       if (element_type == error_mark_node)
    1517              :         return error_mark_node;
    1518              : 
    1519              :       /* See if we already have an identically qualified type.  Tests
    1520              :          should be equivalent to those in check_qualified_type.  */
    1521     59730354 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    1522     35454632 :         if (TREE_TYPE (t) == element_type
    1523      7928898 :             && TYPE_NAME (t) == TYPE_NAME (type)
    1524      7541146 :             && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
    1525     42995778 :             && attribute_list_equal (TYPE_ATTRIBUTES (t),
    1526      7541146 :                                      TYPE_ATTRIBUTES (type)))
    1527              :           break;
    1528              : 
    1529     31816868 :       if (!t)
    1530              :         {
    1531              :           /* If we already know the dependentness, tell the array type
    1532              :              constructor.  This is important for module streaming, as we cannot
    1533              :              dynamically determine that on read in.  */
    1534     24275722 :           t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
    1535     24275722 :                                       TYPE_DEPENDENT_P_VALID (type)
    1536       546098 :                                       ? int (TYPE_DEPENDENT_P (type)) : -1);
    1537              : 
    1538              :           /* Keep the typedef name.  */
    1539     24275722 :           if (TYPE_NAME (t) != TYPE_NAME (type))
    1540              :             {
    1541        29226 :               t = build_variant_type_copy (t);
    1542        29226 :               TYPE_NAME (t) = TYPE_NAME (type);
    1543        29226 :               SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
    1544        29226 :               TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
    1545              :             }
    1546              :         }
    1547              : 
    1548              :       /* Even if we already had this variant, we update
    1549              :          TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
    1550              :          they changed since the variant was originally created.
    1551              : 
    1552              :          This seems hokey; if there is some way to use a previous
    1553              :          variant *without* coming through here,
    1554              :          TYPE_NEEDS_CONSTRUCTING will never be updated.  */
    1555     63633736 :       TYPE_NEEDS_CONSTRUCTING (t)
    1556     31816868 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
    1557     63633736 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1558     31816868 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
    1559     31816868 :       return t;
    1560              :     }
    1561   4203686086 :   else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
    1562              :     {
    1563            3 :       tree t = PACK_EXPANSION_PATTERN (type);
    1564              : 
    1565            3 :       t = cp_build_qualified_type (t, type_quals, complain);
    1566            3 :       return make_pack_expansion (t, complain);
    1567              :     }
    1568              : 
    1569              :   /* A reference or method type shall not be cv-qualified.
    1570              :      [dcl.ref], [dcl.fct].  This used to be an error, but as of DR 295
    1571              :      (in CD1) we always ignore extra cv-quals on functions.  */
    1572              : 
    1573              :   /* [dcl.ref/1] Cv-qualified references are ill-formed except when
    1574              :      the cv-qualifiers are introduced through the use of a typedef-name
    1575              :      ([dcl.typedef], [temp.param]) or decltype-specifier
    1576              :      ([dcl.type.decltype]),in which case the cv-qualifiers are
    1577              :      ignored.  */
    1578   4203686083 :   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
    1579   1197294717 :       && (TYPE_REF_P (type)
    1580   1196754103 :           || FUNC_OR_METHOD_TYPE_P (type)))
    1581              :     {
    1582       541368 :       if (TYPE_REF_P (type)
    1583       541368 :           && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
    1584              :         bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1585       541368 :       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1586              :     }
    1587              : 
    1588              :   /* But preserve any function-cv-quals on a FUNCTION_TYPE.  */
    1589   4203686083 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    1590          757 :     type_quals |= type_memfn_quals (type);
    1591              : 
    1592              :   /* A restrict-qualified type must be a pointer (or reference)
    1593              :      to object or incomplete type. */
    1594   4203686083 :   if ((type_quals & TYPE_QUAL_RESTRICT)
    1595      8362512 :       && TREE_CODE (type) != TEMPLATE_TYPE_PARM
    1596      8362475 :       && TREE_CODE (type) != TYPENAME_TYPE
    1597      8362469 :       && !INDIRECT_TYPE_P (type))
    1598              :     {
    1599           25 :       bad_quals |= TYPE_QUAL_RESTRICT;
    1600           25 :       type_quals &= ~TYPE_QUAL_RESTRICT;
    1601              :     }
    1602              : 
    1603   4203686083 :   if (bad_quals == TYPE_UNQUALIFIED
    1604       367464 :       || (complain & tf_ignore_bad_quals))
    1605              :     /*OK*/;
    1606           12 :   else if (!(complain & tf_error))
    1607            0 :     return error_mark_node;
    1608              :   else
    1609              :     {
    1610           12 :       tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
    1611           12 :       error ("%qV qualifiers cannot be applied to %qT",
    1612              :              bad_type, type);
    1613              :     }
    1614              : 
    1615              :   /* Retrieve (or create) the appropriately qualified variant.  */
    1616   4203686083 :   result = build_qualified_type (type, type_quals);
    1617              : 
    1618   4203686083 :   return result;
    1619              : }
    1620              : 
    1621              : /* Return a FUNCTION_TYPE for a function returning VALUE_TYPE
    1622              :    with ARG_TYPES arguments.  Wrapper around build_function_type
    1623              :    which ensures TYPE_NO_NAMED_ARGS_STDARG_P is set if ARG_TYPES
    1624              :    is NULL for C++26.  */
    1625              : 
    1626              : tree
    1627    267598277 : cp_build_function_type (tree value_type, tree arg_types)
    1628              : {
    1629    267598277 :   return build_function_type (value_type, arg_types,
    1630    267598277 :                               cxx_dialect >= cxx26
    1631    267598277 :                               && arg_types == NULL_TREE);
    1632              : }
    1633              : 
    1634              : /* Return TYPE with const and volatile removed.  */
    1635              : 
    1636              : tree
    1637   1870536691 : cv_unqualified (tree type)
    1638              : {
    1639   1870536691 :   int quals;
    1640              : 
    1641   1870536691 :   if (type == error_mark_node)
    1642              :     return type;
    1643              : 
    1644   1870536492 :   quals = cp_type_quals (type);
    1645   1870536492 :   quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
    1646   1870536492 :   return cp_build_qualified_type (type, quals);
    1647              : }
    1648              : 
    1649              : /* Subroutine of strip_typedefs.  We want to apply to RESULT the attributes
    1650              :    from ATTRIBS that affect type identity, and no others.  If any are not
    1651              :    applied, set *remove_attributes to true.  */
    1652              : 
    1653              : static tree
    1654      8560528 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
    1655              : {
    1656      8560528 :   tree first_ident = NULL_TREE;
    1657      8560528 :   tree new_attribs = NULL_TREE;
    1658      8560528 :   tree *p = &new_attribs;
    1659              : 
    1660      8560528 :   if (OVERLOAD_TYPE_P (result))
    1661              :     {
    1662              :       /* On classes and enums all attributes are ingrained.  */
    1663      8559753 :       gcc_assert (attribs == TYPE_ATTRIBUTES (result));
    1664              :       return result;
    1665              :     }
    1666              : 
    1667         1553 :   for (tree a = attribs; a; a = TREE_CHAIN (a))
    1668              :     {
    1669          778 :       const attribute_spec *as
    1670          778 :         = lookup_attribute_spec (get_attribute_name (a));
    1671          778 :       if (as && as->affects_type_identity)
    1672              :         {
    1673          178 :           if (!first_ident)
    1674              :             first_ident = a;
    1675            0 :           else if (first_ident == error_mark_node)
    1676              :             {
    1677            0 :               *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
    1678            0 :               p = &TREE_CHAIN (*p);
    1679              :             }
    1680              :         }
    1681          600 :       else if (first_ident && first_ident != error_mark_node)
    1682              :         {
    1683            0 :           for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
    1684              :             {
    1685            0 :               *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
    1686            0 :               p = &TREE_CHAIN (*p);
    1687              :             }
    1688            0 :           first_ident = error_mark_node;
    1689              :         }
    1690              :     }
    1691          775 :   if (first_ident != error_mark_node)
    1692          775 :     new_attribs = first_ident;
    1693              : 
    1694          775 :   if (first_ident == attribs)
    1695              :     /* All attributes affected type identity.  */;
    1696              :   else
    1697          597 :     *remove_attributes = true;
    1698              : 
    1699          775 :   return cp_build_type_attribute_variant (result, new_attribs);
    1700              : }
    1701              : 
    1702              : /* Builds a qualified variant of T that is either not a typedef variant
    1703              :    (the default behavior) or not a typedef variant of a user-facing type
    1704              :    (if FLAGS contains STF_USER_VISIBLE).  If T is not a type, then this
    1705              :    just dispatches to strip_typedefs_expr.
    1706              : 
    1707              :    E.g. consider the following declarations:
    1708              :      typedef const int ConstInt;
    1709              :      typedef ConstInt* PtrConstInt;
    1710              :    If T is PtrConstInt, this function returns a type representing
    1711              :      const int*.
    1712              :    In other words, if T is a typedef, the function returns the underlying type.
    1713              :    The cv-qualification and attributes of the type returned match the
    1714              :    input type.
    1715              :    They will always be compatible types.
    1716              :    The returned type is built so that all of its subtypes
    1717              :    recursively have their typedefs stripped as well.
    1718              : 
    1719              :    This is different from just returning TYPE_CANONICAL (T)
    1720              :    Because of several reasons:
    1721              :     * If T is a type that needs structural equality
    1722              :       its TYPE_CANONICAL (T) will be NULL.
    1723              :     * TYPE_CANONICAL (T) desn't carry type attributes
    1724              :       and loses template parameter names.
    1725              : 
    1726              :    If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
    1727              :    affect type identity, and set the referent to true if any were
    1728              :    stripped.  */
    1729              : 
    1730              : tree
    1731   3276799007 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
    1732              :                 unsigned int flags /* = 0 */)
    1733              : {
    1734   3276799007 :   tree result = NULL, type = NULL, t0 = NULL;
    1735              : 
    1736   3276799007 :   if (!t || t == error_mark_node)
    1737              :     return t;
    1738              : 
    1739   3241827814 :   if (!TYPE_P (t))
    1740    172009362 :     return strip_typedefs_expr (t, remove_attributes, flags);
    1741              : 
    1742   3069818452 :   if (t == TYPE_CANONICAL (t))
    1743              :     return t;
    1744              : 
    1745   1207623812 :   if (typedef_variant_p (t))
    1746              :     {
    1747    485472267 :       if ((flags & STF_USER_VISIBLE)
    1748    485472267 :           && !user_facing_original_type_p (t))
    1749              :         return t;
    1750              : 
    1751    485472149 :       if ((flags & STF_KEEP_INJ_CLASS_NAME)
    1752        31835 :           && CLASS_TYPE_P (t)
    1753    485481527 :           && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
    1754              :         return t;
    1755              : 
    1756    485472148 :       if (dependent_opaque_alias_p (t))
    1757              :         return t;
    1758              : 
    1759    485472047 :       if (alias_template_specialization_p (t, nt_opaque))
    1760              :         {
    1761    128375235 :           if (dependent_alias_template_spec_p (t, nt_opaque)
    1762    128375235 :               && !(flags & STF_STRIP_DEPENDENT))
    1763              :             /* DR 1558: However, if the template-id is dependent, subsequent
    1764              :                template argument substitution still applies to the template-id.  */
    1765              :             return t;
    1766              :         }
    1767              :       else
    1768              :         /* If T is a non-template alias or typedef, we can assume that
    1769              :            instantiating its definition will hit any substitution failure,
    1770              :            so we don't need to retain it here as well.  */
    1771    357096812 :         flags |= STF_STRIP_DEPENDENT;
    1772              : 
    1773    471266431 :       result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
    1774              :                                remove_attributes, flags);
    1775    471266431 :       goto stripped;
    1776              :     }
    1777              : 
    1778    722151545 :   switch (TREE_CODE (t))
    1779              :     {
    1780     10797400 :     case POINTER_TYPE:
    1781     10797400 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1782     10797400 :       result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
    1783     10797400 :       break;
    1784    130020445 :     case REFERENCE_TYPE:
    1785    130020445 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1786    130020445 :       result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
    1787    130020445 :       break;
    1788       309132 :     case OFFSET_TYPE:
    1789       309132 :       t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
    1790       309132 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1791       309132 :       result = build_offset_type (t0, type);
    1792       309132 :       break;
    1793     24549728 :     case RECORD_TYPE:
    1794     24549728 :       if (TYPE_PTRMEMFUNC_P (t))
    1795              :         {
    1796      1511012 :           t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
    1797              :                                remove_attributes, flags);
    1798      1511012 :           result = build_ptrmemfunc_type (t0);
    1799              :         }
    1800              :       break;
    1801      1865142 :     case ARRAY_TYPE:
    1802      1865142 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1803      1865142 :       t0  = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
    1804      1865142 :       gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
    1805              :                            || !dependent_type_p (t));
    1806      1865142 :       result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
    1807      1865142 :       break;
    1808      8434400 :     case FUNCTION_TYPE:
    1809      8434400 :     case METHOD_TYPE:
    1810      8434400 :       {
    1811      8434400 :         tree arg_types = NULL, arg_node, arg_node2, arg_type;
    1812      8434400 :         bool changed;
    1813              : 
    1814              :         /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
    1815              :            around the compiler (e.g. cp_parser_late_parsing_default_args), we
    1816              :            can't expect that re-hashing a function type will find a previous
    1817              :            equivalent type, so try to reuse the input type if nothing has
    1818              :            changed.  If the type is itself a variant, that will change.  */
    1819      8434400 :         bool is_variant = typedef_variant_p (t);
    1820      8434400 :         if (remove_attributes
    1821      8434400 :             && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
    1822              :           is_variant = true;
    1823              : 
    1824      8434400 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1825      8434400 :         tree canon_spec = (flag_noexcept_type
    1826      8423952 :                            ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
    1827      8434400 :                            : NULL_TREE);
    1828     10890801 :         changed = (type != TREE_TYPE (t) || is_variant
    1829     10890598 :                    || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
    1830              : 
    1831      8434400 :         for (arg_node = TYPE_ARG_TYPES (t);
    1832     12578111 :              arg_node;
    1833      4143711 :              arg_node = TREE_CHAIN (arg_node))
    1834              :           {
    1835     11806290 :             if (arg_node == void_list_node)
    1836              :               break;
    1837      4143711 :             arg_type = strip_typedefs (TREE_VALUE (arg_node),
    1838              :                                        remove_attributes, flags);
    1839      4143711 :             gcc_assert (arg_type);
    1840      4143711 :             if (arg_type == TREE_VALUE (arg_node) && !changed)
    1841      3894342 :               continue;
    1842              : 
    1843       249369 :             if (!changed)
    1844              :               {
    1845        37919 :                 changed = true;
    1846        37919 :                 for (arg_node2 = TYPE_ARG_TYPES (t);
    1847        47968 :                      arg_node2 != arg_node;
    1848        10049 :                      arg_node2 = TREE_CHAIN (arg_node2))
    1849        10049 :                   arg_types
    1850        10049 :                     = tree_cons (TREE_PURPOSE (arg_node2),
    1851        10049 :                                  TREE_VALUE (arg_node2), arg_types);
    1852              :               }
    1853              : 
    1854       249369 :             arg_types
    1855       249369 :               = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
    1856              :           }
    1857              : 
    1858      8434400 :         if (!changed)
    1859              :           return t;
    1860              : 
    1861      6016993 :         if (arg_types)
    1862        58004 :           arg_types = nreverse (arg_types);
    1863              : 
    1864              :         /* A list of parameters not ending with an ellipsis
    1865              :            must end with void_list_node.  */
    1866      6016993 :         if (arg_node)
    1867      6016952 :           arg_types = chainon (arg_types, void_list_node);
    1868              : 
    1869      6016993 :         if (TREE_CODE (t) == METHOD_TYPE)
    1870              :           {
    1871        27330 :             tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
    1872        27330 :             gcc_assert (class_type);
    1873        27330 :             result =
    1874        27330 :               build_method_type_directly (class_type, type,
    1875        27330 :                                           TREE_CHAIN (arg_types));
    1876              :           }
    1877              :         else
    1878              :           {
    1879     17968989 :             result = build_function_type (type, arg_types,
    1880      5989663 :                                           TYPE_NO_NAMED_ARGS_STDARG_P (t));
    1881      5989663 :             result = apply_memfn_quals (result, type_memfn_quals (t));
    1882              :           }
    1883              : 
    1884     18050979 :         result = build_cp_fntype_variant (result,
    1885              :                                           type_memfn_rqual (t), canon_spec,
    1886      6016993 :                                           TYPE_HAS_LATE_RETURN_TYPE (t));
    1887              :       }
    1888      6016993 :       break;
    1889     73823524 :     case TYPENAME_TYPE:
    1890     73823524 :       {
    1891     73823524 :         bool changed = false;
    1892     73823524 :         tree fullname = TYPENAME_TYPE_FULLNAME (t);
    1893     73823524 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
    1894     73823524 :             && TREE_OPERAND (fullname, 1))
    1895              :           {
    1896      4189400 :             tree args = TREE_OPERAND (fullname, 1);
    1897      4189400 :             tree new_args = copy_node (args);
    1898     11616752 :             for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
    1899              :               {
    1900      7427352 :                 tree arg = TREE_VEC_ELT (args, i);
    1901      7427352 :                 tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
    1902      7427352 :                 TREE_VEC_ELT (new_args, i) = strip_arg;
    1903      7427352 :                 if (strip_arg != arg)
    1904       230576 :                   changed = true;
    1905              :               }
    1906      4189400 :             if (changed)
    1907              :               {
    1908       230576 :                 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
    1909       230576 :                   = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
    1910       230576 :                 fullname
    1911       230576 :                   = lookup_template_function (TREE_OPERAND (fullname, 0),
    1912              :                                               new_args);
    1913              :               }
    1914              :             else
    1915      3958824 :               ggc_free (new_args);
    1916              :           }
    1917     73823524 :         tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
    1918     73823524 :         if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
    1919              :           return t;
    1920      4542772 :         tree name = fullname;
    1921      4542772 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
    1922       253812 :           name = TREE_OPERAND (fullname, 0);
    1923              :         /* Use build_typename_type rather than make_typename_type because we
    1924              :            don't want to resolve it here, just strip typedefs.  */
    1925      4542772 :         result = build_typename_type (ctx, name, fullname, typename_type);
    1926              :       }
    1927      4542772 :       break;
    1928     11979123 :     case DECLTYPE_TYPE:
    1929     11979123 :       result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
    1930              :                                     remove_attributes, flags);
    1931     11979123 :       if (result == DECLTYPE_TYPE_EXPR (t))
    1932              :         result = NULL_TREE;
    1933              :       else
    1934       349724 :         result = (finish_decltype_type
    1935       349724 :                   (result,
    1936       349724 :                    DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
    1937              :                    tf_none));
    1938              :       break;
    1939       782863 :     case TRAIT_TYPE:
    1940       782863 :       {
    1941       782863 :         tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
    1942              :                                      remove_attributes, flags);
    1943       782863 :         tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
    1944              :                                      remove_attributes, flags);
    1945       782863 :         if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
    1946              :           result = NULL_TREE;
    1947              :         else
    1948            0 :           result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
    1949              :                                       tf_warning_or_error);
    1950              :       }
    1951              :       break;
    1952     24651561 :     case TYPE_PACK_EXPANSION:
    1953     24651561 :       {
    1954     24651561 :         tree pat = PACK_EXPANSION_PATTERN (t);
    1955     24651561 :         if (TYPE_P (pat))
    1956              :           {
    1957     24651561 :             type = strip_typedefs (pat, remove_attributes, flags);
    1958     24651561 :             if (type != pat)
    1959              :               {
    1960       280944 :                 result = build_distinct_type_copy (t);
    1961       280944 :                 PACK_EXPANSION_PATTERN (result) = type;
    1962              :               }
    1963              :           }
    1964              :       }
    1965              :       break;
    1966              :     default:
    1967              :       break;
    1968              :     }
    1969              : 
    1970    155693564 :   if (!result)
    1971    494759822 :     result = TYPE_MAIN_VARIANT (t);
    1972              : 
    1973    155693564 : stripped:
    1974              :   /*gcc_assert (!typedef_variant_p (result)
    1975              :               || dependent_alias_template_spec_p (result, nt_opaque)
    1976              :               || ((flags & STF_USER_VISIBLE)
    1977              :                   && !user_facing_original_type_p (result)));*/
    1978              : 
    1979   1121719817 :   if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
    1980              :   /* If RESULT is complete and T isn't, it's likely the case that T
    1981              :      is a variant of RESULT which hasn't been updated yet.  Skip the
    1982              :      attribute handling.  */;
    1983              :   else
    1984              :     {
    1985   1121719811 :       if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
    1986   1121719811 :           || TYPE_ALIGN (t) != TYPE_ALIGN (result))
    1987              :         {
    1988           21 :           gcc_assert (TYPE_USER_ALIGN (t));
    1989           21 :           if (remove_attributes)
    1990           12 :             *remove_attributes = true;
    1991              :           else
    1992              :             {
    1993            9 :               if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
    1994            0 :                 result = build_variant_type_copy (result);
    1995              :               else
    1996            9 :                 result = build_aligned_type (result, TYPE_ALIGN (t));
    1997            9 :               TYPE_USER_ALIGN (result) = true;
    1998              :             }
    1999              :         }
    2000              : 
    2001   1121719811 :       if (TYPE_ATTRIBUTES (t))
    2002              :         {
    2003      8570266 :           if (remove_attributes)
    2004      8560528 :             result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
    2005              :                                                 remove_attributes);
    2006              :           else
    2007         9738 :             result = cp_build_type_attribute_variant (result,
    2008         9738 :                                                       TYPE_ATTRIBUTES (t));
    2009              :         }
    2010              :     }
    2011              : 
    2012   1121719817 :   return cp_build_qualified_type (result, cp_type_quals (t));
    2013              : }
    2014              : 
    2015              : /* Like strip_typedefs above, but works on expressions (and other
    2016              :    non-types such as TREE_VEC), so that in
    2017              : 
    2018              :    template<class T> struct A
    2019              :    {
    2020              :      typedef T TT;
    2021              :      B<sizeof(TT)> b;
    2022              :    };
    2023              : 
    2024              :    sizeof(TT) is replaced by sizeof(T).  */
    2025              : 
    2026              : tree
    2027    371908796 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
    2028              : {
    2029    371908796 :   unsigned i,n;
    2030    371908796 :   tree r, type, *ops;
    2031    371908796 :   enum tree_code code;
    2032              : 
    2033    371908796 :   if (t == NULL_TREE || t == error_mark_node)
    2034              :     return t;
    2035              : 
    2036    371908796 :   STRIP_ANY_LOCATION_WRAPPER (t);
    2037              : 
    2038    371908796 :   if (DECL_P (t) || CONSTANT_CLASS_P (t))
    2039              :     return t;
    2040              : 
    2041    184696745 :   code = TREE_CODE (t);
    2042    184696745 :   switch (code)
    2043              :     {
    2044              :     case IDENTIFIER_NODE:
    2045              :     case TEMPLATE_PARM_INDEX:
    2046              :     case OVERLOAD:
    2047              :     case BASELINK:
    2048              :     case ARGUMENT_PACK_SELECT:
    2049              :       return t;
    2050              : 
    2051      2216668 :     case TRAIT_EXPR:
    2052      2216668 :       {
    2053      2216668 :         tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
    2054              :                                      remove_attributes, flags);
    2055      2216668 :         tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
    2056              :                                      remove_attributes, flags);
    2057      2216668 :         if (type1 == TRAIT_EXPR_TYPE1 (t)
    2058      2216668 :             && type2 == TRAIT_EXPR_TYPE2 (t))
    2059              :           return t;
    2060        50053 :         r = copy_node (t);
    2061        50053 :         TRAIT_EXPR_TYPE1 (r) = type1;
    2062        50053 :         TRAIT_EXPR_TYPE2 (r) = type2;
    2063        50053 :         return r;
    2064              :       }
    2065              : 
    2066      1007583 :     case TREE_LIST:
    2067      1007583 :       {
    2068      1007583 :         bool changed = false;
    2069      1007583 :         auto_vec<tree_pair, 4> vec;
    2070      1007583 :         r = t;
    2071      2146604 :         for (; t; t = TREE_CHAIN (t))
    2072              :           {
    2073      1139021 :             tree purpose = strip_typedefs (TREE_PURPOSE (t),
    2074      1139021 :                                            remove_attributes, flags);
    2075      1139021 :             tree value = strip_typedefs (TREE_VALUE (t),
    2076      1139021 :                                          remove_attributes, flags);
    2077      1139021 :             if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
    2078              :               changed = true;
    2079      1139021 :             vec.safe_push ({purpose, value});
    2080              :           }
    2081      1007583 :         if (changed)
    2082              :           {
    2083       225101 :             r = NULL_TREE;
    2084       737370 :             for (int i = vec.length () - 1; i >= 0; i--)
    2085       287168 :               r = tree_cons (vec[i].first, vec[i].second, r);
    2086              :           }
    2087      1007583 :         return r;
    2088      1007583 :       }
    2089              : 
    2090     18643798 :     case TREE_VEC:
    2091     18643798 :       {
    2092     18643798 :         bool changed = false;
    2093     18643798 :         releasing_vec vec;
    2094     18643798 :         n = TREE_VEC_LENGTH (t);
    2095     18643798 :         vec_safe_reserve (vec, n);
    2096     39682126 :         for (i = 0; i < n; ++i)
    2097              :           {
    2098     21038328 :             tree op = strip_typedefs (TREE_VEC_ELT (t, i),
    2099     21038328 :                                       remove_attributes, flags);
    2100     21038328 :             vec->quick_push (op);
    2101     21038328 :             if (op != TREE_VEC_ELT (t, i))
    2102       202457 :               changed = true;
    2103              :           }
    2104     18643798 :         if (changed)
    2105              :           {
    2106       202457 :             r = copy_node (t);
    2107       626122 :             for (i = 0; i < n; ++i)
    2108       221208 :               TREE_VEC_ELT (r, i) = (*vec)[i];
    2109       404914 :             NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
    2110       404914 :               = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
    2111              :           }
    2112              :         else
    2113              :           r = t;
    2114     18643798 :         return r;
    2115     18643798 :       }
    2116              : 
    2117       293082 :     case CONSTRUCTOR:
    2118       293082 :       {
    2119       293082 :         bool changed = false;
    2120       293082 :         vec<constructor_elt, va_gc> *vec
    2121       293082 :           = vec_safe_copy (CONSTRUCTOR_ELTS (t));
    2122       293082 :         n = CONSTRUCTOR_NELTS (t);
    2123       293082 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    2124       312448 :         for (i = 0; i < n; ++i)
    2125              :           {
    2126        19366 :             constructor_elt *e = &(*vec)[i];
    2127        19366 :             tree op = strip_typedefs (e->value, remove_attributes, flags);
    2128        19366 :             if (op != e->value)
    2129              :               {
    2130            6 :                 changed = true;
    2131            6 :                 e->value = op;
    2132              :               }
    2133        19366 :             gcc_checking_assert
    2134              :               (e->index == strip_typedefs (e->index, remove_attributes,
    2135              :                                            flags));
    2136              :           }
    2137              : 
    2138       293082 :         if (!changed && type == TREE_TYPE (t))
    2139              :           {
    2140       271668 :             vec_free (vec);
    2141       271668 :             return t;
    2142              :           }
    2143              :         else
    2144              :           {
    2145        21414 :             r = copy_node (t);
    2146        21414 :             TREE_TYPE (r) = type;
    2147        21414 :             CONSTRUCTOR_ELTS (r) = vec;
    2148        21414 :             return r;
    2149              :           }
    2150              :       }
    2151              : 
    2152              :     case LAMBDA_EXPR:
    2153              :     case STMT_EXPR:
    2154              :       return t;
    2155              : 
    2156     97706579 :     default:
    2157     97706579 :       break;
    2158              :     }
    2159              : 
    2160     97706579 :   gcc_assert (EXPR_P (t));
    2161              : 
    2162     97706579 :   n = cp_tree_operand_length (t);
    2163     97706579 :   ops = XALLOCAVEC (tree, n);
    2164     97706579 :   type = TREE_TYPE (t);
    2165              : 
    2166     97706579 :   switch (code)
    2167              :     {
    2168      7156192 :     CASE_CONVERT:
    2169      7156192 :     case IMPLICIT_CONV_EXPR:
    2170      7156192 :     case DYNAMIC_CAST_EXPR:
    2171      7156192 :     case STATIC_CAST_EXPR:
    2172      7156192 :     case CONST_CAST_EXPR:
    2173      7156192 :     case REINTERPRET_CAST_EXPR:
    2174      7156192 :     case CAST_EXPR:
    2175      7156192 :     case NEW_EXPR:
    2176      7156192 :       type = strip_typedefs (type, remove_attributes, flags);
    2177              :       /* fallthrough */
    2178              : 
    2179     97706579 :     default:
    2180    320081102 :       for (i = 0; i < n; ++i)
    2181    222374523 :         ops[i] = strip_typedefs (TREE_OPERAND (t, i),
    2182              :                                  remove_attributes, flags);
    2183              :       break;
    2184              :     }
    2185              : 
    2186              :   /* If nothing changed, return t.  */
    2187    314372719 :   for (i = 0; i < n; ++i)
    2188    220358822 :     if (ops[i] != TREE_OPERAND (t, i))
    2189              :       break;
    2190     97706579 :   if (i == n && type == TREE_TYPE (t))
    2191              :     return t;
    2192              : 
    2193      3949600 :   r = copy_node (t);
    2194      3949600 :   TREE_TYPE (r) = type;
    2195     12503745 :   for (i = 0; i < n; ++i)
    2196      8554145 :     TREE_OPERAND (r, i) = ops[i];
    2197              :   return r;
    2198              : }
    2199              : 
    2200              : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
    2201              :    graph dominated by T.  If BINFO is NULL, TYPE is a dependent base,
    2202              :    and we do a shallow copy.  If BINFO is non-NULL, we do a deep copy.
    2203              :    VIRT indicates whether TYPE is inherited virtually or not.
    2204              :    IGO_PREV points at the previous binfo of the inheritance graph
    2205              :    order chain.  The newly copied binfo's TREE_CHAIN forms this
    2206              :    ordering.
    2207              : 
    2208              :    The CLASSTYPE_VBASECLASSES vector of T is constructed in the
    2209              :    correct order. That is in the order the bases themselves should be
    2210              :    constructed in.
    2211              : 
    2212              :    The BINFO_INHERITANCE of a virtual base class points to the binfo
    2213              :    of the most derived type. ??? We could probably change this so that
    2214              :    BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
    2215              :    remove a field.  They currently can only differ for primary virtual
    2216              :    virtual bases.  */
    2217              : 
    2218              : tree
    2219     38667672 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
    2220              : {
    2221     38667672 :   tree new_binfo;
    2222              : 
    2223     38667672 :   if (virt)
    2224              :     {
    2225              :       /* See if we've already made this virtual base.  */
    2226       281435 :       new_binfo = binfo_for_vbase (type, t);
    2227       281435 :       if (new_binfo)
    2228              :         return new_binfo;
    2229              :     }
    2230              : 
    2231     70462088 :   new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
    2232     38599820 :   BINFO_TYPE (new_binfo) = type;
    2233              : 
    2234              :   /* Chain it into the inheritance graph.  */
    2235     38599820 :   TREE_CHAIN (*igo_prev) = new_binfo;
    2236     38599820 :   *igo_prev = new_binfo;
    2237              : 
    2238     70462088 :   if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
    2239              :     {
    2240     31862259 :       int ix;
    2241     31862259 :       tree base_binfo;
    2242              : 
    2243     31862259 :       gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
    2244              : 
    2245     31862259 :       BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
    2246     31862259 :       BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
    2247              : 
    2248              :       /* We do not need to copy the accesses, as they are read only.  */
    2249     31862259 :       BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
    2250              : 
    2251              :       /* Recursively copy base binfos of BINFO.  */
    2252     36058334 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    2253              :         {
    2254      4196075 :           tree new_base_binfo;
    2255      4196075 :           new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
    2256              :                                        t, igo_prev,
    2257      4196075 :                                        BINFO_VIRTUAL_P (base_binfo));
    2258              : 
    2259      4196075 :           if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
    2260      3981601 :             BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
    2261      4196075 :           BINFO_BASE_APPEND (new_binfo, new_base_binfo);
    2262              :         }
    2263              :     }
    2264              :   else
    2265      6737561 :     BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
    2266              : 
    2267     38599820 :   if (virt)
    2268              :     {
    2269              :       /* Push it onto the list after any virtual bases it contains
    2270              :          will have been pushed.  */
    2271       213583 :       CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
    2272       213583 :       BINFO_VIRTUAL_P (new_binfo) = 1;
    2273       213583 :       BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
    2274              :     }
    2275              : 
    2276              :   return new_binfo;
    2277              : }
    2278              : 
    2279              : /* Hashing of lists so that we don't make duplicates.
    2280              :    The entry point is `list_hash_canon'.  */
    2281              : 
    2282              : struct list_proxy
    2283              : {
    2284              :   tree purpose;
    2285              :   tree value;
    2286              :   tree chain;
    2287              : };
    2288              : 
    2289              : struct list_hasher : ggc_ptr_hash<tree_node>
    2290              : {
    2291              :   typedef list_proxy *compare_type;
    2292              : 
    2293              :   static hashval_t hash (tree);
    2294              :   static bool equal (tree, list_proxy *);
    2295              : };
    2296              : 
    2297              : /* Now here is the hash table.  When recording a list, it is added
    2298              :    to the slot whose index is the hash code mod the table size.
    2299              :    Note that the hash table is used for several kinds of lists.
    2300              :    While all these live in the same table, they are completely independent,
    2301              :    and the hash code is computed differently for each of these.  */
    2302              : 
    2303              : static GTY (()) hash_table<list_hasher> *list_hash_table;
    2304              : 
    2305              : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
    2306              :    for a node we are thinking about adding).  */
    2307              : 
    2308              : bool
    2309   2641419551 : list_hasher::equal (tree t, list_proxy *proxy)
    2310              : {
    2311   2641419551 :   return (TREE_VALUE (t) == proxy->value
    2312    178783829 :           && TREE_PURPOSE (t) == proxy->purpose
    2313   2818535671 :           && TREE_CHAIN (t) == proxy->chain);
    2314              : }
    2315              : 
    2316              : /* Compute a hash code for a list (chain of TREE_LIST nodes
    2317              :    with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
    2318              :    TREE_COMMON slots), by adding the hash codes of the individual entries.  */
    2319              : 
    2320              : static hashval_t
    2321   2433301157 : list_hash_pieces (tree purpose, tree value, tree chain)
    2322              : {
    2323   2433301157 :   hashval_t hashcode = 0;
    2324              : 
    2325   2433301157 :   if (chain)
    2326   2433123052 :     hashcode += TREE_HASH (chain);
    2327              : 
    2328   2433301157 :   if (value)
    2329   2433301157 :     hashcode += TREE_HASH (value);
    2330              :   else
    2331            0 :     hashcode += 1007;
    2332   2433301157 :   if (purpose)
    2333    152465015 :     hashcode += TREE_HASH (purpose);
    2334              :   else
    2335   2280836142 :     hashcode += 1009;
    2336   2433301157 :   return hashcode;
    2337              : }
    2338              : 
    2339              : /* Hash an already existing TREE_LIST.  */
    2340              : 
    2341              : hashval_t
    2342   2108421830 : list_hasher::hash (tree t)
    2343              : {
    2344   2108421830 :   return list_hash_pieces (TREE_PURPOSE (t),
    2345   2108421830 :                            TREE_VALUE (t),
    2346   2108421830 :                            TREE_CHAIN (t));
    2347              : }
    2348              : 
    2349              : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
    2350              :    object for an identical list if one already exists.  Otherwise, build a
    2351              :    new one, and record it as the canonical object.  */
    2352              : 
    2353              : tree
    2354    324879327 : hash_tree_cons (tree purpose, tree value, tree chain)
    2355              : {
    2356    324879327 :   int hashcode = 0;
    2357    324879327 :   tree *slot;
    2358    324879327 :   struct list_proxy proxy;
    2359              : 
    2360              :   /* Hash the list node.  */
    2361    324879327 :   hashcode = list_hash_pieces (purpose, value, chain);
    2362              :   /* Create a proxy for the TREE_LIST we would like to create.  We
    2363              :      don't actually create it so as to avoid creating garbage.  */
    2364    324879327 :   proxy.purpose = purpose;
    2365    324879327 :   proxy.value = value;
    2366    324879327 :   proxy.chain = chain;
    2367              :   /* See if it is already in the table.  */
    2368    324879327 :   slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
    2369              :   /* If not, create a new node.  */
    2370    324879327 :   if (!*slot)
    2371    153541085 :     *slot = tree_cons (purpose, value, chain);
    2372    324879327 :   return (tree) *slot;
    2373              : }
    2374              : 
    2375              : /* Constructor for hashed lists.  */
    2376              : 
    2377              : tree
    2378      2244272 : hash_tree_chain (tree value, tree chain)
    2379              : {
    2380      2244272 :   return hash_tree_cons (NULL_TREE, value, chain);
    2381              : }
    2382              : 
    2383              : void
    2384            0 : debug_binfo (tree elem)
    2385              : {
    2386            0 :   HOST_WIDE_INT n;
    2387            0 :   tree virtuals;
    2388              : 
    2389            0 :   fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
    2390              :            "\nvtable type:\n",
    2391            0 :            TYPE_NAME_STRING (BINFO_TYPE (elem)),
    2392            0 :            TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
    2393            0 :   debug_tree (BINFO_TYPE (elem));
    2394            0 :   if (BINFO_VTABLE (elem))
    2395            0 :     fprintf (stderr, "vtable decl \"%s\"\n",
    2396            0 :              IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
    2397              :   else
    2398            0 :     fprintf (stderr, "no vtable decl yet\n");
    2399            0 :   fprintf (stderr, "virtuals:\n");
    2400            0 :   virtuals = BINFO_VIRTUALS (elem);
    2401            0 :   n = 0;
    2402              : 
    2403            0 :   while (virtuals)
    2404              :     {
    2405            0 :       tree fndecl = TREE_VALUE (virtuals);
    2406            0 :       fprintf (stderr, "%s [" HOST_WIDE_INT_PRINT_DEC " =? "
    2407              :                        HOST_WIDE_INT_PRINT_DEC "]\n",
    2408            0 :                IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
    2409            0 :                n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
    2410            0 :       ++n;
    2411            0 :       virtuals = TREE_CHAIN (virtuals);
    2412              :     }
    2413            0 : }
    2414              : 
    2415              : /* Build a representation for the qualified name SCOPE::NAME.  TYPE is
    2416              :    the type of the result expression, if known, or NULL_TREE if the
    2417              :    resulting expression is type-dependent.  If TEMPLATE_P is true,
    2418              :    NAME is known to be a template because the user explicitly used the
    2419              :    "template" keyword after the "::".
    2420              : 
    2421              :    All SCOPE_REFs should be built by use of this function.  */
    2422              : 
    2423              : tree
    2424    149006391 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
    2425              : {
    2426    149006391 :   tree t;
    2427    149006391 :   if (type == error_mark_node
    2428    149006391 :       || scope == error_mark_node
    2429    149006388 :       || name == error_mark_node)
    2430              :     return error_mark_node;
    2431    149006388 :   gcc_assert (TREE_CODE (name) != SCOPE_REF);
    2432    149006388 :   t = build2 (SCOPE_REF, type, scope, name);
    2433    149006388 :   QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
    2434    149006388 :   PTRMEM_OK_P (t) = true;
    2435    149006388 :   if (type)
    2436     10246829 :     t = convert_from_reference (t);
    2437              :   return t;
    2438              : }
    2439              : 
    2440              : /* Like check_qualified_type, but also check ref-qualifier, exception
    2441              :    specification, and whether the return type was specified after the
    2442              :    parameters.  */
    2443              : 
    2444              : static bool
    2445   1292685496 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
    2446              :                          cp_ref_qualifier rqual, tree raises, bool late)
    2447              : {
    2448   1292685496 :   return (TYPE_QUALS (cand) == type_quals
    2449   1292626403 :           && check_base_type (cand, base)
    2450   1292533137 :           && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
    2451              :                                 ce_exact)
    2452    616909935 :           && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
    2453   1867390258 :           && type_memfn_rqual (cand) == rqual);
    2454              : }
    2455              : 
    2456              : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL.  */
    2457              : 
    2458              : tree
    2459      1287990 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
    2460              : {
    2461      1287990 :   tree raises = TYPE_RAISES_EXCEPTIONS (type);
    2462      1287990 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    2463      1287990 :   return build_cp_fntype_variant (type, rqual, raises, late);
    2464              : }
    2465              : 
    2466              : tree
    2467       190986 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
    2468              : {
    2469              :   /* Stored in an unsigned short, but we're limited to the number of
    2470              :      modules anyway.  */
    2471       190986 :   gcc_checking_assert (clusters <= (unsigned short)(~0));
    2472       190986 :   size_t length = (offsetof (tree_binding_vec, vec)
    2473       190986 :                    + clusters * sizeof (binding_cluster));
    2474       190986 :   tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
    2475       190986 :   TREE_SET_CODE (vec, BINDING_VECTOR);
    2476       190986 :   BINDING_VECTOR_NAME (vec) = name;
    2477       190986 :   BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
    2478       190986 :   BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
    2479              : 
    2480       190986 :   return vec;
    2481              : }
    2482              : 
    2483              : /* Make a raw overload node containing FN.  */
    2484              : 
    2485              : tree
    2486    406154837 : ovl_make (tree fn, tree next)
    2487              : {
    2488    406154837 :   tree result = make_node (OVERLOAD);
    2489              : 
    2490    406154837 :   if (TREE_CODE (fn) == OVERLOAD)
    2491     19925284 :     OVL_NESTED_P (result) = true;
    2492              : 
    2493    522394334 :   TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
    2494    522394334 :                         ? unknown_type_node : TREE_TYPE (fn));
    2495    406154837 :   if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
    2496     15150587 :     OVL_DEDUP_P (result) = true;
    2497    406154837 :   OVL_FUNCTION (result) = fn;
    2498    406154837 :   OVL_CHAIN (result) = next;
    2499    406154837 :   return result;
    2500              : }
    2501              : 
    2502              : /* Add FN to the (potentially NULL) overload set OVL.  USING_OR_HIDDEN is > 0
    2503              :    if this is a using-decl.  It is > 1 if we're revealing the using decl.
    2504              :    It is > 2 if we're also exporting it.  USING_OR_HIDDEN is < 0, if FN is
    2505              :    hidden.  (A decl cannot be both using and hidden.)  We keep the hidden
    2506              :    decls first, but remaining ones are unordered.  */
    2507              : 
    2508              : tree
    2509    703625956 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
    2510              : {
    2511    703625956 :   tree result = maybe_ovl;
    2512    703625956 :   tree insert_after = NULL_TREE;
    2513              : 
    2514              :   /* Skip hidden.  */
    2515    977396791 :   for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
    2516    996833236 :          && OVL_HIDDEN_P (maybe_ovl);
    2517     79756193 :        maybe_ovl = OVL_CHAIN (maybe_ovl))
    2518              :     {
    2519     79756193 :       gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
    2520     79756193 :       insert_after = maybe_ovl;
    2521              :     }
    2522              : 
    2523    703625956 :   if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
    2524              :     {
    2525    306045589 :       maybe_ovl = ovl_make (fn, maybe_ovl);
    2526              : 
    2527    306045589 :       if (using_or_hidden < 0)
    2528     77755793 :         OVL_HIDDEN_P (maybe_ovl) = true;
    2529    306045589 :       if (using_or_hidden > 0)
    2530              :         {
    2531     12747470 :           OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
    2532     12747470 :           if (using_or_hidden > 1)
    2533        13497 :             OVL_PURVIEW_P (maybe_ovl) = true;
    2534        13497 :           if (using_or_hidden > 2)
    2535        12977 :             OVL_EXPORT_P (maybe_ovl) = true;
    2536              :         }
    2537              :     }
    2538              :   else
    2539              :     maybe_ovl = fn;
    2540              : 
    2541    703625956 :   if (insert_after)
    2542              :     {
    2543      8864157 :       OVL_CHAIN (insert_after) = maybe_ovl;
    2544      8864157 :       TREE_TYPE (insert_after) = unknown_type_node;
    2545              :     }
    2546              :   else
    2547              :     result = maybe_ovl;
    2548              : 
    2549    703625956 :   return result;
    2550              : }
    2551              : 
    2552              : /* Skip any hidden names at the beginning of OVL.   */
    2553              : 
    2554              : tree
    2555   2013561795 : ovl_skip_hidden (tree ovl)
    2556              : {
    2557   3857263655 :   while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
    2558   1843701860 :     ovl = OVL_CHAIN (ovl);
    2559              : 
    2560   2013561795 :   return ovl;
    2561              : }
    2562              : 
    2563              : /* NODE is an OVL_HIDDEN_P node that is now revealed.  */
    2564              : 
    2565              : tree
    2566      3902901 : ovl_iterator::reveal_node (tree overload, tree node)
    2567              : {
    2568              :   /* We cannot have returned NODE as part of a lookup overload, so we
    2569              :      don't have to worry about preserving that.  */
    2570              : 
    2571      3902901 :   OVL_HIDDEN_P (node) = false;
    2572      3902901 :   if (tree chain = OVL_CHAIN (node))
    2573       167087 :     if (TREE_CODE (chain) == OVERLOAD)
    2574              :       {
    2575       158010 :         if (OVL_HIDDEN_P (chain))
    2576              :           {
    2577              :             /* The node needs moving, and the simplest way is to remove it
    2578              :                and reinsert.  */
    2579        72403 :             overload = remove_node (overload, node);
    2580        72403 :             overload = ovl_insert (OVL_FUNCTION (node), overload);
    2581              :           }
    2582        85607 :         else if (OVL_DEDUP_P (chain))
    2583            9 :           OVL_DEDUP_P (node) = true;
    2584              :       }
    2585      3902901 :   return overload;
    2586              : }
    2587              : 
    2588              : /* NODE is on the overloads of OVL.  Remove it.
    2589              :    The removed node is unaltered and may continue to be iterated
    2590              :    from (i.e. it is safe to remove a node from an overload one is
    2591              :    currently iterating over).  */
    2592              : 
    2593              : tree
    2594       374067 : ovl_iterator::remove_node (tree overload, tree node)
    2595              : {
    2596       374067 :   tree *slot = &overload;
    2597      2215432 :   while (*slot != node)
    2598              :     {
    2599      1841365 :       tree probe = *slot;
    2600      1841365 :       gcc_checking_assert (!OVL_LOOKUP_P (probe));
    2601              : 
    2602      1841365 :       slot = &OVL_CHAIN (probe);
    2603              :     }
    2604              : 
    2605              :   /* Stitch out NODE.  We don't have to worry about now making a
    2606              :      singleton overload (and consequently maybe setting its type),
    2607              :      because all uses of this function will be followed by inserting a
    2608              :      new node that must follow the place we've cut this out from.  */
    2609       374067 :   if (TREE_CODE (node) != OVERLOAD)
    2610              :     /* Cloned inherited ctors don't mark themselves as via_using.  */
    2611       229383 :     *slot = NULL_TREE;
    2612              :   else
    2613       144684 :     *slot = OVL_CHAIN (node);
    2614              : 
    2615       374067 :   return overload;
    2616              : }
    2617              : 
    2618              : /* Mark or unmark a lookup set. */
    2619              : 
    2620              : void
    2621    130207476 : lookup_mark (tree ovl, bool val)
    2622              : {
    2623   1987515669 :   for (lkp_iterator iter (ovl); iter; ++iter)
    2624              :     {
    2625   1857308193 :       gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
    2626   1857308193 :       LOOKUP_SEEN_P (*iter) = val;
    2627              :     }
    2628    130207476 : }
    2629              : 
    2630              : /* Add a set of new FNS into a lookup.  */
    2631              : 
    2632              : tree
    2633    672313762 : lookup_add (tree fns, tree lookup)
    2634              : {
    2635    672313762 :   if (fns == error_mark_node || lookup == error_mark_node)
    2636              :     return error_mark_node;
    2637              : 
    2638    672313750 :   if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
    2639              :     {
    2640     94624871 :       lookup = ovl_make (fns, lookup);
    2641     94624871 :       OVL_LOOKUP_P (lookup) = true;
    2642              :     }
    2643              :   else
    2644              :     lookup = fns;
    2645              : 
    2646              :   return lookup;
    2647              : }
    2648              : 
    2649              : /* FNS is a new overload set, add them to LOOKUP, if they are not
    2650              :    already present there.  */
    2651              : 
    2652              : tree
    2653    668020766 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
    2654              : {
    2655    668020766 :   if (deduping)
    2656    846897981 :     for (tree next, probe = fns; probe; probe = next)
    2657              :       {
    2658    756267627 :         tree fn = probe;
    2659    756267627 :         next = NULL_TREE;
    2660              : 
    2661    756267627 :         if (TREE_CODE (probe) == OVERLOAD)
    2662              :           {
    2663    716735449 :             fn = OVL_FUNCTION (probe);
    2664    716735449 :             next = OVL_CHAIN (probe);
    2665              :           }
    2666              : 
    2667    756267627 :         if (!LOOKUP_SEEN_P (fn))
    2668    560116297 :           LOOKUP_SEEN_P (fn) = true;
    2669              :         else
    2670              :           {
    2671              :             /* This function was already seen.  Insert all the
    2672              :                predecessors onto the lookup.  */
    2673    219218049 :             for (; fns != probe; fns = OVL_CHAIN (fns))
    2674              :               {
    2675              :                 /* Propagate OVL_USING, but OVL_HIDDEN &
    2676              :                    OVL_DEDUP_P don't matter.  */
    2677     23066719 :                 if (OVL_USING_P (fns))
    2678              :                   {
    2679        29808 :                     lookup = ovl_make (OVL_FUNCTION (fns), lookup);
    2680        29808 :                     OVL_USING_P (lookup) = true;
    2681              :                   }
    2682              :                 else
    2683     23036911 :                   lookup = lookup_add (OVL_FUNCTION (fns), lookup);
    2684              :               }
    2685              : 
    2686              :             /* And now skip this function.  */
    2687              :             fns = next;
    2688              :           }
    2689              :       }
    2690              : 
    2691    668020766 :   if (fns)
    2692              :     /* We ended in a set of new functions.  Add them all in one go.  */
    2693    648059106 :     lookup = lookup_add (fns, lookup);
    2694              : 
    2695    668020766 :   return lookup;
    2696              : }
    2697              : 
    2698              : /* Returns nonzero if X is an expression for a (possibly overloaded)
    2699              :    function.  If "f" is a function or function template, "f", "c->f",
    2700              :    "c.f", "C::f", and "f<int>" will all be considered possibly
    2701              :    overloaded functions.  Returns 2 if the function is actually
    2702              :    overloaded, i.e., if it is impossible to know the type of the
    2703              :    function without performing overload resolution.  */
    2704              : 
    2705              : int
    2706   8437330280 : is_overloaded_fn (tree x)
    2707              : {
    2708   8437330280 :   STRIP_ANY_LOCATION_WRAPPER (x);
    2709              : 
    2710              :   /* A baselink is also considered an overloaded function.  */
    2711   8437330280 :   if (TREE_CODE (x) == OFFSET_REF
    2712   8437266686 :       || TREE_CODE (x) == COMPONENT_REF)
    2713    432729580 :     x = TREE_OPERAND (x, 1);
    2714   8437330280 :   x = MAYBE_BASELINK_FUNCTIONS (x);
    2715   8437330280 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2716    232344526 :     x = TREE_OPERAND (x, 0);
    2717              : 
    2718   9706452674 :   if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
    2719   8468288061 :       || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
    2720              :     return 2;
    2721              : 
    2722   8883721092 :   return OVL_P (x);
    2723              : }
    2724              : 
    2725              : /* X is the CALL_EXPR_FN of a CALL_EXPR.  If X represents a dependent name
    2726              :    (14.6.2), return the IDENTIFIER_NODE for that name.  Otherwise, return
    2727              :    NULL_TREE.  */
    2728              : 
    2729              : tree
    2730    228017534 : dependent_name (tree x)
    2731              : {
    2732              :   /* FIXME a dependent name must be unqualified, but this function doesn't
    2733              :      distinguish between qualified and unqualified identifiers.  */
    2734    228017534 :   if (identifier_p (x))
    2735              :     return x;
    2736    227857223 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2737    112792734 :     x = TREE_OPERAND (x, 0);
    2738    227857223 :   if (OVL_P (x))
    2739    198157865 :     return OVL_NAME (x);
    2740              :   return NULL_TREE;
    2741              : }
    2742              : 
    2743              : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
    2744              :    its dependence.  */
    2745              : 
    2746              : tree
    2747    223684229 : call_expr_dependent_name (tree x)
    2748              : {
    2749    223684229 :   if (TREE_TYPE (x) != NULL_TREE)
    2750              :     /* X isn't dependent, so its callee isn't a dependent name.  */
    2751              :     return NULL_TREE;
    2752    218912006 :   return dependent_name (CALL_EXPR_FN (x));
    2753              : }
    2754              : 
    2755              : /* Returns true iff X is an expression for an overloaded function
    2756              :    whose type cannot be known without performing overload
    2757              :    resolution.  */
    2758              : 
    2759              : bool
    2760    716226692 : really_overloaded_fn (tree x)
    2761              : {
    2762    716226692 :   return is_overloaded_fn (x) == 2;
    2763              : }
    2764              : 
    2765              : /* Get the overload set FROM refers to.  Returns NULL if it's not an
    2766              :    overload set.  */
    2767              : 
    2768              : tree
    2769   4613172013 : maybe_get_fns (tree from)
    2770              : {
    2771   4613172013 :   STRIP_ANY_LOCATION_WRAPPER (from);
    2772              : 
    2773              :   /* A baselink is also considered an overloaded function.  */
    2774   4613172013 :   if (TREE_CODE (from) == OFFSET_REF
    2775   4613113188 :       || TREE_CODE (from) == COMPONENT_REF)
    2776    147059434 :     from = TREE_OPERAND (from, 1);
    2777   4613172013 :   if (BASELINK_P (from))
    2778    137963045 :     from = BASELINK_FUNCTIONS (from);
    2779   4613172013 :   if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
    2780    118544616 :     from = TREE_OPERAND (from, 0);
    2781              : 
    2782   4613172013 :   if (OVL_P (from))
    2783   1246178712 :     return from;
    2784              : 
    2785              :   return NULL_TREE;
    2786              : }
    2787              : 
    2788              : /* FROM refers to an overload set.  Return that set (or die).  */
    2789              : 
    2790              : tree
    2791    923846882 : get_fns (tree from)
    2792              : {
    2793    923846882 :   tree res = maybe_get_fns (from);
    2794              : 
    2795    923846882 :   gcc_assert (res);
    2796    923846882 :   return res;
    2797              : }
    2798              : 
    2799              : /* Return the first function of the overload set FROM refers to.  */
    2800              : 
    2801              : tree
    2802    561499835 : get_first_fn (tree from)
    2803              : {
    2804    561499835 :   return OVL_FIRST (get_fns (from));
    2805              : }
    2806              : 
    2807              : /* Return the first function of the overload set FROM refers to if
    2808              :    there is an overload set, otherwise return FROM unchanged.  */
    2809              : 
    2810              : tree
    2811        88689 : maybe_get_first_fn (tree from)
    2812              : {
    2813        88689 :   if (tree res = maybe_get_fns (from))
    2814        88689 :     return OVL_FIRST (res);
    2815              :   return from;
    2816              : }
    2817              : 
    2818              : /* Return the scope where the overloaded functions OVL were found.  */
    2819              : 
    2820              : tree
    2821    262514072 : ovl_scope (tree ovl)
    2822              : {
    2823    262514072 :   if (TREE_CODE (ovl) == OFFSET_REF
    2824    262514072 :       || TREE_CODE (ovl) == COMPONENT_REF)
    2825            0 :     ovl = TREE_OPERAND (ovl, 1);
    2826    262514072 :   if (TREE_CODE (ovl) == BASELINK)
    2827     43761498 :     return BINFO_TYPE (BASELINK_BINFO (ovl));
    2828    218752574 :   if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
    2829    109520816 :     ovl = TREE_OPERAND (ovl, 0);
    2830              :   /* Skip using-declarations.  */
    2831    218752574 :   lkp_iterator iter (ovl);
    2832    234264621 :   do
    2833    234264621 :     ovl = *iter;
    2834    453017195 :   while (iter.using_p () && ++iter);
    2835              : 
    2836    218752574 :   return CP_DECL_CONTEXT (ovl);
    2837              : }
    2838              : 
    2839              : #define PRINT_RING_SIZE 4
    2840              : 
    2841              : static const char *
    2842       154571 : cxx_printable_name_internal (tree decl, int v, bool translate)
    2843              : {
    2844       154571 :   static unsigned int uid_ring[PRINT_RING_SIZE];
    2845       154571 :   static char *print_ring[PRINT_RING_SIZE];
    2846       154571 :   static bool trans_ring[PRINT_RING_SIZE];
    2847       154571 :   static int ring_counter;
    2848       154571 :   int i;
    2849              : 
    2850              :   /* Only cache functions.  */
    2851       154571 :   if (v < 2
    2852        74048 :       || TREE_CODE (decl) != FUNCTION_DECL
    2853       225539 :       || DECL_LANG_SPECIFIC (decl) == 0)
    2854        84987 :     return lang_decl_name (decl, v, translate);
    2855              : 
    2856              :   /* See if this print name is lying around.  */
    2857       323045 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2858       263576 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2859              :       /* yes, so return it.  */
    2860        10115 :       return print_ring[i];
    2861              : 
    2862        59469 :   const char *ret = lang_decl_name (decl, v, translate);
    2863              : 
    2864              :   /* The lang_decl_name call could have called this function recursively,
    2865              :      so check again.  */
    2866       356814 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2867       237876 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2868              :       /* yes, so return it.  */
    2869            0 :       return print_ring[i];
    2870              : 
    2871        59469 :   if (++ring_counter == PRINT_RING_SIZE)
    2872        11996 :     ring_counter = 0;
    2873              : 
    2874        59469 :   if (current_function_decl != NULL_TREE)
    2875              :     {
    2876              :       /* There may be both translated and untranslated versions of the
    2877              :          name cached.  */
    2878       159690 :       for (i = 0; i < 2; i++)
    2879              :         {
    2880       106460 :           if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
    2881           73 :             ring_counter += 1;
    2882       106460 :           if (ring_counter == PRINT_RING_SIZE)
    2883           10 :             ring_counter = 0;
    2884              :         }
    2885        53230 :       gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
    2886              :     }
    2887              : 
    2888        59469 :   free (print_ring[ring_counter]);
    2889              : 
    2890        59469 :   print_ring[ring_counter] = xstrdup (ret);
    2891        59469 :   uid_ring[ring_counter] = DECL_UID (decl);
    2892        59469 :   trans_ring[ring_counter] = translate;
    2893        59469 :   return print_ring[ring_counter];
    2894              : }
    2895              : 
    2896              : const char *
    2897       154571 : cxx_printable_name (tree decl, int v)
    2898              : {
    2899       154571 :   return cxx_printable_name_internal (decl, v, false);
    2900              : }
    2901              : 
    2902              : const char *
    2903            0 : cxx_printable_name_translate (tree decl, int v)
    2904              : {
    2905            0 :   return cxx_printable_name_internal (decl, v, true);
    2906              : }
    2907              : 
    2908              : /* Return the canonical version of exception-specification RAISES for a C++17
    2909              :    function type, for use in type comparison and building TYPE_CANONICAL.  */
    2910              : 
    2911              : tree
    2912    223864760 : canonical_eh_spec (tree raises)
    2913              : {
    2914    223864760 :   if (raises == NULL_TREE)
    2915              :     return raises;
    2916    197674835 :   else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
    2917    158353525 :            || UNPARSED_NOEXCEPT_SPEC_P (raises)
    2918    150234481 :            || uses_template_parms (raises)
    2919    150234481 :            || uses_template_parms (TREE_PURPOSE (raises)))
    2920              :     /* Keep a dependent or deferred exception specification.  */
    2921     49151316 :     return raises;
    2922    148523519 :   else if (nothrow_spec_p (raises))
    2923              :     /* throw() -> noexcept.  */
    2924    147999840 :     return noexcept_true_spec;
    2925              :   else
    2926              :     /* For C++17 type matching, anything else -> nothing.  */
    2927              :     return NULL_TREE;
    2928              : }
    2929              : 
    2930              : tree
    2931    768749614 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
    2932              :                          tree raises, bool late)
    2933              : {
    2934    768749614 :   cp_cv_quals type_quals = TYPE_QUALS (type);
    2935              : 
    2936    768749614 :   if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
    2937              :     return type;
    2938              : 
    2939    328959256 :   tree v = TYPE_MAIN_VARIANT (type);
    2940    721949018 :   for (; v; v = TYPE_NEXT_VARIANT (v))
    2941    523935882 :     if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
    2942              :       return v;
    2943              : 
    2944              :   /* Need to build a new variant.  */
    2945    198013136 :   v = build_variant_type_copy (type);
    2946    198013136 :   if (!TYPE_DEPENDENT_P (v))
    2947              :     /* We no longer know that it's not type-dependent.  */
    2948    197224270 :     TYPE_DEPENDENT_P_VALID (v) = false;
    2949    198013136 :   TYPE_RAISES_EXCEPTIONS (v) = raises;
    2950    198013136 :   TYPE_HAS_LATE_RETURN_TYPE (v) = late;
    2951    198013136 :   switch (rqual)
    2952              :     {
    2953      1284429 :     case REF_QUAL_RVALUE:
    2954      1284429 :       FUNCTION_RVALUE_QUALIFIED (v) = 1;
    2955      1284429 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2956      1284429 :       break;
    2957      1189020 :     case REF_QUAL_LVALUE:
    2958      1189020 :       FUNCTION_RVALUE_QUALIFIED (v) = 0;
    2959      1189020 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2960      1189020 :       break;
    2961    195539687 :     default:
    2962    195539687 :       FUNCTION_REF_QUALIFIED (v) = 0;
    2963    195539687 :       break;
    2964              :     }
    2965              : 
    2966              :   /* Canonicalize the exception specification.  */
    2967    198013136 :   tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
    2968    186790660 :   bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
    2969    245657932 :                             && !UNPARSED_NOEXCEPT_SPEC_P (cr));
    2970              : 
    2971    157516035 :   if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
    2972              :     /* We want to consider structural equality of the exception-less
    2973              :        variant since we'll be replacing the exception specification.  */
    2974      6667011 :     type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
    2975    198013136 :   if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
    2976              :     /* Propagate structural equality.  And always use structural equality
    2977              :        for function types with a complex noexcept-spec since their identity
    2978              :        may depend on e.g. whether comparing_specializations is set.  */
    2979     53695437 :     SET_TYPE_STRUCTURAL_EQUALITY (v);
    2980    144317699 :   else if (TYPE_CANONICAL (type) != type || cr != raises || late)
    2981              :     /* Build the underlying canonical type, since it is different
    2982              :        from TYPE. */
    2983     61860864 :     TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
    2984              :                                                   rqual, cr, false);
    2985              :   else
    2986              :     /* T is its own canonical type. */
    2987     82456835 :     TYPE_CANONICAL (v) = v;
    2988              : 
    2989              :   return v;
    2990              : }
    2991              : 
    2992              : /* TYPE is a function or method type with a deferred exception
    2993              :    specification that has been parsed to RAISES.  Fixup all the type
    2994              :    variants that are affected in place.  Via decltype &| noexcept
    2995              :    tricks, the unparsed spec could have escaped into the type system.  */
    2996              : 
    2997              : void
    2998      3288075 : fixup_deferred_exception_variants (tree type, tree raises)
    2999              : {
    3000      3288075 :   tree original = TYPE_RAISES_EXCEPTIONS (type);
    3001              : 
    3002      6576150 :   gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
    3003              : 
    3004      3288075 :   for (tree variant = TYPE_MAIN_VARIANT (type);
    3005     10657308 :        variant; variant = TYPE_NEXT_VARIANT (variant))
    3006      7369233 :     if (TYPE_RAISES_EXCEPTIONS (variant) == original)
    3007              :       {
    3008      3554952 :         gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
    3009              : 
    3010      3554952 :         SET_TYPE_STRUCTURAL_EQUALITY (variant);
    3011      3554952 :         TYPE_RAISES_EXCEPTIONS (variant) = raises;
    3012              : 
    3013      3554952 :         if (!TYPE_DEPENDENT_P (variant))
    3014              :           /* We no longer know that it's not type-dependent.  */
    3015       270323 :           TYPE_DEPENDENT_P_VALID (variant) = false;
    3016              :       }
    3017      3288075 : }
    3018              : 
    3019              : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
    3020              :    listed in RAISES.  */
    3021              : 
    3022              : tree
    3023    197373205 : build_exception_variant (tree type, tree raises)
    3024              : {
    3025    197373205 :   cp_ref_qualifier rqual = type_memfn_rqual (type);
    3026    197373205 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    3027    197373205 :   return build_cp_fntype_variant (type, rqual, raises, late);
    3028              : }
    3029              : 
    3030              : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
    3031              :    BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
    3032              :    arguments.  */
    3033              : 
    3034              : tree
    3035       335785 : bind_template_template_parm (tree t, tree newargs)
    3036              : {
    3037       335785 :   tree decl = TYPE_NAME (t);
    3038       335785 :   tree t2;
    3039              : 
    3040       335785 :   t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
    3041       335785 :   decl = build_decl (input_location,
    3042       335785 :                      TYPE_DECL, DECL_NAME (decl), NULL_TREE);
    3043       335785 :   SET_DECL_TEMPLATE_PARM_P (decl);
    3044              : 
    3045              :   /* These nodes have to be created to reflect new TYPE_DECL and template
    3046              :      arguments.  */
    3047       335785 :   TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
    3048       335785 :   TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
    3049       335785 :   TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
    3050       671570 :     = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
    3051              : 
    3052       335785 :   TREE_TYPE (decl) = t2;
    3053       335785 :   TYPE_NAME (t2) = decl;
    3054       335785 :   TYPE_STUB_DECL (t2) = decl;
    3055       335785 :   TYPE_SIZE (t2) = 0;
    3056              : 
    3057       335785 :   if (any_template_arguments_need_structural_equality_p (newargs))
    3058           13 :     SET_TYPE_STRUCTURAL_EQUALITY (t2);
    3059              :   else
    3060       335772 :     TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
    3061              : 
    3062       335785 :   return t2;
    3063              : }
    3064              : 
    3065              : /* Called from count_trees via walk_tree.  */
    3066              : 
    3067              : static tree
    3068            0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
    3069              : {
    3070            0 :   ++*((int *) data);
    3071              : 
    3072            0 :   if (TYPE_P (*tp))
    3073            0 :     *walk_subtrees = 0;
    3074              : 
    3075            0 :   return NULL_TREE;
    3076              : }
    3077              : 
    3078              : /* Debugging function for measuring the rough complexity of a tree
    3079              :    representation.  */
    3080              : 
    3081              : int
    3082            0 : count_trees (tree t)
    3083              : {
    3084            0 :   int n_trees = 0;
    3085            0 :   cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
    3086            0 :   return n_trees;
    3087              : }
    3088              : 
    3089              : /* Called from verify_stmt_tree via walk_tree.  */
    3090              : 
    3091              : static tree
    3092       600157 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
    3093              : {
    3094       600157 :   tree t = *tp;
    3095       600157 :   hash_table<nofree_ptr_hash <tree_node> > *statements
    3096              :       = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
    3097       600157 :   tree_node **slot;
    3098              : 
    3099       600157 :   if (!STATEMENT_CODE_P (TREE_CODE (t)))
    3100              :     return NULL_TREE;
    3101              : 
    3102              :   /* If this statement is already present in the hash table, then
    3103              :      there is a circularity in the statement tree.  */
    3104        32302 :   gcc_assert (!statements->find (t));
    3105              : 
    3106        32302 :   slot = statements->find_slot (t, INSERT);
    3107        32302 :   *slot = t;
    3108              : 
    3109        32302 :   return NULL_TREE;
    3110              : }
    3111              : 
    3112              : /* Debugging function to check that the statement T has not been
    3113              :    corrupted.  For now, this function simply checks that T contains no
    3114              :    circularities.  */
    3115              : 
    3116              : void
    3117         1589 : verify_stmt_tree (tree t)
    3118              : {
    3119         1589 :   hash_table<nofree_ptr_hash <tree_node> > statements (37);
    3120         1589 :   cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
    3121         1589 : }
    3122              : 
    3123              : /* Check if the type T depends on a type with no linkage and if so,
    3124              :    return it.  If RELAXED_P then do not consider a class type declared
    3125              :    within a vague-linkage function or in a module CMI to have no linkage,
    3126              :    since it can still be accessed within a different TU.  Remember:
    3127              :    no-linkage is not the same as internal-linkage.  */
    3128              : 
    3129              : tree
    3130    380651285 : no_linkage_check (tree t, bool relaxed_p)
    3131              : {
    3132    380651285 :   tree r;
    3133              : 
    3134              :   /* Lambda types that don't have mangling scope have no linkage.  We
    3135              :      check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
    3136              :      when we get here from pushtag none of the lambda information is
    3137              :      set up yet, so we want to assume that the lambda has linkage and
    3138              :      fix it up later if not.  We need to check this even in templates so
    3139              :      that we properly handle a lambda-expression in the signature.  */
    3140    422360750 :   if (LAMBDA_TYPE_P (t)
    3141    384844884 :       && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
    3142              :     {
    3143      2420759 :       tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
    3144      2420759 :       if (!extra)
    3145              :         return t;
    3146              :     }
    3147              : 
    3148              :   /* Otherwise there's no point in checking linkage on template functions; we
    3149              :      can't know their complete types.  */
    3150    380650180 :   if (processing_template_decl)
    3151              :     return NULL_TREE;
    3152              : 
    3153    251401195 :   switch (TREE_CODE (t))
    3154              :     {
    3155    129728574 :     case RECORD_TYPE:
    3156    129728574 :       if (TYPE_PTRMEMFUNC_P (t))
    3157       120429 :         goto ptrmem;
    3158              :       /* Fall through.  */
    3159    130900871 :     case UNION_TYPE:
    3160    130900871 :       if (!CLASS_TYPE_P (t))
    3161              :         return NULL_TREE;
    3162              :       /* Fall through.  */
    3163    136028451 :     case ENUMERAL_TYPE:
    3164              :       /* Only treat unnamed types as having no linkage if they're at
    3165              :          namespace scope.  This is core issue 966.  */
    3166    277238974 :       if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
    3167              :         return t;
    3168              : 
    3169    135307687 :       for (r = CP_TYPE_CONTEXT (t); ; )
    3170              :         {
    3171              :           /* If we're a nested type of a !TREE_PUBLIC class, we might not
    3172              :              have linkage, or we might just be in an anonymous namespace.
    3173              :              If we're in a TREE_PUBLIC class, we have linkage.  */
    3174    138636123 :           if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
    3175        79214 :             return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
    3176    138556909 :           else if (TREE_CODE (r) == FUNCTION_DECL)
    3177              :             {
    3178      3998371 :               if (relaxed_p
    3179      3998371 :                   && (vague_linkage_p (r)
    3180         6915 :                       || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
    3181      3328436 :                 r = CP_DECL_CONTEXT (r);
    3182              :               else
    3183       669935 :                 return t;
    3184              :             }
    3185              :           else
    3186              :             break;
    3187              :         }
    3188              : 
    3189              :       return NULL_TREE;
    3190              : 
    3191     32122050 :     case ARRAY_TYPE:
    3192     32122050 :     case POINTER_TYPE:
    3193     32122050 :     case REFERENCE_TYPE:
    3194     32122050 :     case VECTOR_TYPE:
    3195     32122050 :       return no_linkage_check (TREE_TYPE (t), relaxed_p);
    3196              : 
    3197       123305 :     case OFFSET_TYPE:
    3198       123305 :     ptrmem:
    3199       123305 :       r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
    3200              :                             relaxed_p);
    3201       123305 :       if (r)
    3202              :         return r;
    3203       123305 :       return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
    3204              : 
    3205     29009852 :     case METHOD_TYPE:
    3206     29009852 :     case FUNCTION_TYPE:
    3207     29009852 :       {
    3208     29009852 :         tree parm = TYPE_ARG_TYPES (t);
    3209     29009852 :         if (TREE_CODE (t) == METHOD_TYPE)
    3210              :           /* The 'this' pointer isn't interesting; a method has the same
    3211              :              linkage (or lack thereof) as its enclosing class.  */
    3212     16000898 :           parm = TREE_CHAIN (parm);
    3213     35788572 :         for (;
    3214     64798424 :              parm && parm != void_list_node;
    3215     35788572 :              parm = TREE_CHAIN (parm))
    3216              :           {
    3217     36444773 :             r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
    3218     36444773 :             if (r)
    3219              :               return r;
    3220              :           }
    3221     28353651 :         return no_linkage_check (TREE_TYPE (t), relaxed_p);
    3222              :       }
    3223              : 
    3224              :     default:
    3225              :       return NULL_TREE;
    3226              :     }
    3227              : }
    3228              : 
    3229              : extern int depth_reached;
    3230              : 
    3231              : void
    3232            0 : cxx_print_statistics (void)
    3233              : {
    3234            0 :   print_template_statistics ();
    3235            0 :   if (GATHER_STATISTICS)
    3236              :     fprintf (stderr, "maximum template instantiation depth reached: %d\n",
    3237              :              depth_reached);
    3238            0 : }
    3239              : 
    3240              : /* Return, as an INTEGER_CST node, the number of elements for TYPE
    3241              :    (which is an ARRAY_TYPE).  This one is a recursive count of all
    3242              :    ARRAY_TYPEs that are clumped together.  */
    3243              : 
    3244              : tree
    3245         4722 : array_type_nelts_total (tree type)
    3246              : {
    3247         4722 :   tree sz = array_type_nelts_top (type);
    3248         4722 :   type = TREE_TYPE (type);
    3249         4982 :   while (TREE_CODE (type) == ARRAY_TYPE)
    3250              :     {
    3251          260 :       tree n = array_type_nelts_top (type);
    3252          260 :       sz = fold_build2_loc (input_location,
    3253              :                         MULT_EXPR, sizetype, sz, n);
    3254          260 :       type = TREE_TYPE (type);
    3255              :     }
    3256         4722 :   return sz;
    3257              : }
    3258              : 
    3259              : struct bot_data
    3260              : {
    3261              :   splay_tree target_remap;
    3262              :   bool clear_location;
    3263              : };
    3264              : 
    3265              : /* Called from break_out_target_exprs via mapcar.  */
    3266              : 
    3267              : static tree
    3268     44359526 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
    3269              : {
    3270     44359526 :   bot_data &data = *(bot_data*)data_;
    3271     44359526 :   splay_tree target_remap = data.target_remap;
    3272     44359526 :   tree t = *tp;
    3273              : 
    3274     44359526 :   if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
    3275              :     {
    3276              :       /* There can't be any TARGET_EXPRs or their slot variables below this
    3277              :          point.  But we must make a copy, in case subsequent processing
    3278              :          alters any part of it.  For example, during gimplification a cast
    3279              :          of the form (T) &X::f (where "f" is a member function) will lead
    3280              :          to replacing the PTRMEM_CST for &X::f with a VAR_DECL.  */
    3281     15792304 :       *walk_subtrees = 0;
    3282     15792304 :       *tp = unshare_expr (t);
    3283     15792304 :       return NULL_TREE;
    3284              :     }
    3285     28567222 :   if (TREE_CODE (t) == TARGET_EXPR)
    3286              :     {
    3287       865059 :       tree u;
    3288              : 
    3289       865059 :       if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
    3290              :         {
    3291       510795 :           u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3292              :                                tf_warning_or_error);
    3293       510795 :           if (u == error_mark_node)
    3294              :             return u;
    3295       510795 :           if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
    3296         1297 :             AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
    3297              :         }
    3298              :       else
    3299       354264 :         u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3300              :                                tf_warning_or_error);
    3301              : 
    3302       865059 :       TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
    3303       865059 :       TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
    3304       865059 :       TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
    3305       865059 :       TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
    3306       865059 :       TREE_CONSTANT (u) = TREE_CONSTANT (t);
    3307              : 
    3308              :       /* Map the old variable to the new one.  */
    3309      2595177 :       splay_tree_insert (target_remap,
    3310       865059 :                          (splay_tree_key) TARGET_EXPR_SLOT (t),
    3311       865059 :                          (splay_tree_value) TARGET_EXPR_SLOT (u));
    3312              : 
    3313       865059 :       TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
    3314       865059 :                                                         data.clear_location);
    3315       865059 :       if (TARGET_EXPR_INITIAL (u) == error_mark_node)
    3316              :         return error_mark_node;
    3317              : 
    3318       865059 :       if (data.clear_location)
    3319       435240 :         SET_EXPR_LOCATION (u, input_location);
    3320              : 
    3321              :       /* Replace the old expression with the new version.  */
    3322       865059 :       *tp = u;
    3323              :       /* We don't have to go below this point; the recursive call to
    3324              :          break_out_target_exprs will have handled anything below this
    3325              :          point.  */
    3326       865059 :       *walk_subtrees = 0;
    3327       865059 :       return NULL_TREE;
    3328              :     }
    3329     27702163 :   if (TREE_CODE (*tp) == SAVE_EXPR)
    3330              :     {
    3331       100693 :       t = *tp;
    3332       100693 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3333              :                                              (splay_tree_key) t);
    3334       100693 :       if (n)
    3335              :         {
    3336        50352 :           *tp = (tree)n->value;
    3337        50352 :           *walk_subtrees = 0;
    3338              :         }
    3339              :       else
    3340              :         {
    3341        50341 :           copy_tree_r (tp, walk_subtrees, NULL);
    3342        50341 :           splay_tree_insert (target_remap,
    3343              :                              (splay_tree_key)t,
    3344        50341 :                              (splay_tree_value)*tp);
    3345              :           /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
    3346        50341 :           splay_tree_insert (target_remap,
    3347              :                              (splay_tree_key)*tp,
    3348        50341 :                              (splay_tree_value)*tp);
    3349              :         }
    3350       100693 :       return NULL_TREE;
    3351              :     }
    3352     27601470 :   if (TREE_CODE (*tp) == DECL_EXPR
    3353          199 :       && VAR_P (DECL_EXPR_DECL (*tp))
    3354          199 :       && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
    3355     27601669 :       && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
    3356              :     {
    3357          199 :       tree t;
    3358          199 :       splay_tree_node n
    3359          398 :         = splay_tree_lookup (target_remap,
    3360          199 :                              (splay_tree_key) DECL_EXPR_DECL (*tp));
    3361          199 :       if (n)
    3362            1 :         t = (tree) n->value;
    3363              :       else
    3364              :         {
    3365          198 :           t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
    3366          198 :           DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
    3367          396 :           splay_tree_insert (target_remap,
    3368          198 :                              (splay_tree_key) DECL_EXPR_DECL (*tp),
    3369              :                              (splay_tree_value) t);
    3370              :         }
    3371          199 :       copy_tree_r (tp, walk_subtrees, NULL);
    3372          199 :       DECL_EXPR_DECL (*tp) = t;
    3373          199 :       if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3374           12 :         SET_EXPR_LOCATION (*tp, input_location);
    3375          199 :       return NULL_TREE;
    3376              :     }
    3377     27601271 :   if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
    3378              :     {
    3379            1 :       copy_tree_r (tp, walk_subtrees, NULL);
    3380            2 :       for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
    3381              :         {
    3382            1 :           gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
    3383            1 :           tree t = create_temporary_var (TREE_TYPE (*p));
    3384            1 :           DECL_INITIAL (t) = DECL_INITIAL (*p);
    3385            1 :           DECL_CHAIN (t) = DECL_CHAIN (*p);
    3386            1 :           splay_tree_insert (target_remap, (splay_tree_key) *p,
    3387              :                              (splay_tree_value) t);
    3388            1 :           *p = t;
    3389              :         }
    3390            1 :       if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3391            0 :         SET_EXPR_LOCATION (*tp, input_location);
    3392            1 :       return NULL_TREE;
    3393              :     }
    3394              : 
    3395              :   /* Make a copy of this node.  */
    3396     27601270 :   t = copy_tree_r (tp, walk_subtrees, NULL);
    3397     27601270 :   if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
    3398      3383135 :     if (!processing_template_decl)
    3399      3383135 :       set_flags_from_callee (*tp);
    3400     27601270 :   if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3401       468612 :     SET_EXPR_LOCATION (*tp, input_location);
    3402              :   return t;
    3403              : }
    3404              : 
    3405              : /* Replace all remapped VAR_DECLs in T with their new equivalents.
    3406              :    DATA is really a splay-tree mapping old variables to new
    3407              :    variables.  */
    3408              : 
    3409              : static tree
    3410     65577946 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
    3411              : {
    3412     65577946 :   bot_data &data = *(bot_data*)data_;
    3413     65577946 :   splay_tree target_remap = data.target_remap;
    3414              : 
    3415     65577946 :   if (VAR_P (*t))
    3416              :     {
    3417      2843085 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3418              :                                              (splay_tree_key) *t);
    3419      2843085 :       if (n)
    3420         2167 :         *t = (tree) n->value;
    3421              :     }
    3422     62734861 :   else if (TREE_CODE (*t) == PARM_DECL
    3423      6287766 :            && DECL_NAME (*t) == this_identifier
    3424     64992038 :            && !DECL_CONTEXT (*t))
    3425              :     {
    3426              :       /* In an NSDMI we need to replace the 'this' parameter we used for
    3427              :          parsing with the real one for this function.  */
    3428        23596 :       *t = current_class_ptr;
    3429              :     }
    3430     62711265 :   else if (TREE_CODE (*t) == CONVERT_EXPR
    3431     62711265 :            && CONVERT_EXPR_VBASE_PATH (*t))
    3432              :     {
    3433              :       /* In an NSDMI build_base_path defers building conversions to morally
    3434              :          virtual bases, and we handle it here.  */
    3435           63 :       tree basetype = TREE_TYPE (*t);
    3436           63 :       *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
    3437              :                             /*check_access=*/false, /*nonnull=*/true,
    3438              :                             tf_warning_or_error);
    3439              :     }
    3440              : 
    3441     65577946 :   return NULL_TREE;
    3442              : }
    3443              : 
    3444              : /* When we parse a default argument expression, we may create
    3445              :    temporary variables via TARGET_EXPRs.  When we actually use the
    3446              :    default-argument expression, we make a copy of the expression
    3447              :    and replace the temporaries with appropriate local versions.
    3448              : 
    3449              :    If CLEAR_LOCATION is true, override any EXPR_LOCATION with
    3450              :    input_location.  */
    3451              : 
    3452              : tree
    3453     14878478 : break_out_target_exprs (tree t, bool clear_location /* = false */)
    3454              : {
    3455     14878478 :   static int target_remap_count;
    3456     14878478 :   static splay_tree target_remap;
    3457              : 
    3458              :   /* We shouldn't be called on templated trees, nor do we want to
    3459              :      produce them.  */
    3460     14878478 :   gcc_checking_assert (!processing_template_decl);
    3461              : 
    3462     14878478 :   if (!target_remap_count++)
    3463     14013419 :     target_remap = splay_tree_new (splay_tree_compare_pointers,
    3464              :                                    /*splay_tree_delete_key_fn=*/NULL,
    3465              :                                    /*splay_tree_delete_value_fn=*/NULL);
    3466     14878478 :   bot_data data = { target_remap, clear_location };
    3467     14878478 :   if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
    3468            0 :     t = error_mark_node;
    3469     14878478 :   if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
    3470            0 :     t = error_mark_node;
    3471              : 
    3472     14878478 :   if (!--target_remap_count)
    3473              :     {
    3474     14013419 :       splay_tree_delete (target_remap);
    3475     14013419 :       target_remap = NULL;
    3476              :     }
    3477              : 
    3478     14878478 :   return t;
    3479              : }
    3480              : 
    3481              : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
    3482              :    which we expect to have type TYPE.  */
    3483              : 
    3484              : tree
    3485       545306 : build_ctor_subob_ref (tree index, tree type, tree obj)
    3486              : {
    3487       545306 :   if (index == NULL_TREE)
    3488              :     /* Can't refer to a particular member of a vector.  */
    3489              :     obj = NULL_TREE;
    3490       545306 :   else if (TREE_CODE (index) == INTEGER_CST)
    3491         7514 :     obj = cp_build_array_ref (input_location, obj, index, tf_none);
    3492              :   else
    3493       537792 :     obj = build_class_member_access_expr (obj, index, NULL_TREE,
    3494              :                                           /*reference*/false, tf_none);
    3495       545306 :   if (obj)
    3496              :     {
    3497       545306 :       tree objtype = TREE_TYPE (obj);
    3498       545306 :       if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
    3499              :         {
    3500              :           /* When the destination object refers to a flexible array member
    3501              :              verify that it matches the type of the source object except
    3502              :              for its domain and qualifiers.  */
    3503           83 :           gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
    3504              :                                  TYPE_MAIN_VARIANT (objtype),
    3505              :                                  COMPARE_REDECLARATION));
    3506              :         }
    3507              :       else
    3508       545223 :         gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
    3509              :     }
    3510              : 
    3511       545306 :   return obj;
    3512              : }
    3513              : 
    3514              : struct replace_placeholders_t
    3515              : {
    3516              :   tree obj;         /* The object to be substituted for a PLACEHOLDER_EXPR.  */
    3517              :   tree exp;         /* The outermost exp.  */
    3518              :   bool seen;        /* Whether we've encountered a PLACEHOLDER_EXPR.  */
    3519              :   hash_set<tree> *pset;   /* To avoid walking same trees multiple times.  */
    3520              : };
    3521              : 
    3522              : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
    3523              :    build up subexpressions as we go deeper.  */
    3524              : 
    3525              : static tree
    3526     34438627 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
    3527              : {
    3528     34438627 :   replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
    3529     34438627 :   tree obj = d->obj;
    3530              : 
    3531     34438627 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3532              :     {
    3533     11101886 :       *walk_subtrees = false;
    3534     11101886 :       return NULL_TREE;
    3535              :     }
    3536              : 
    3537     23336741 :   switch (TREE_CODE (*t))
    3538              :     {
    3539              :     case PLACEHOLDER_EXPR:
    3540              :       {
    3541              :         tree x = obj;
    3542          635 :         for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
    3543          635 :                                                            TREE_TYPE (x));
    3544           77 :              x = TREE_OPERAND (x, 0))
    3545           77 :           gcc_assert (handled_component_p (x));
    3546          558 :         *t = unshare_expr (x);
    3547          558 :         *walk_subtrees = false;
    3548          558 :         d->seen = true;
    3549              :       }
    3550          558 :       break;
    3551              : 
    3552       703254 :     case CONSTRUCTOR:
    3553       703254 :       {
    3554       703254 :         constructor_elt *ce;
    3555       703254 :         vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
    3556              :         /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
    3557              :            other than the d->exp one, those have PLACEHOLDER_EXPRs
    3558              :            related to another object.  */
    3559       703254 :         if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
    3560          621 :              && *t != d->exp)
    3561       703770 :             || d->pset->add (*t))
    3562              :           {
    3563          105 :             *walk_subtrees = false;
    3564          105 :             return NULL_TREE;
    3565              :           }
    3566      2421394 :         for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
    3567              :           {
    3568      1718245 :             tree *valp = &ce->value;
    3569      1718245 :             tree type = TREE_TYPE (*valp);
    3570      1718245 :             tree subob = obj;
    3571              : 
    3572              :             /* Elements with RANGE_EXPR index shouldn't have any
    3573              :                placeholders in them.  */
    3574      1718245 :             if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
    3575            2 :               continue;
    3576              : 
    3577      1718243 :             if (TREE_CODE (*valp) == CONSTRUCTOR
    3578         1795 :                 && AGGREGATE_TYPE_P (type))
    3579              :               {
    3580              :                 /* If we're looking at the initializer for OBJ, then build
    3581              :                    a sub-object reference.  If we're looking at an
    3582              :                    initializer for another object, just pass OBJ down.  */
    3583         1781 :                 if (same_type_ignoring_top_level_qualifiers_p
    3584         1781 :                     (TREE_TYPE (*t), TREE_TYPE (obj)))
    3585         1748 :                   subob = build_ctor_subob_ref (ce->index, type, obj);
    3586         1781 :                 if (TREE_CODE (*valp) == TARGET_EXPR)
    3587            0 :                   valp = &TARGET_EXPR_INITIAL (*valp);
    3588              :               }
    3589      1718243 :             d->obj = subob;
    3590      1718243 :             cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
    3591      1718243 :             d->obj = obj;
    3592              :           }
    3593       703149 :         *walk_subtrees = false;
    3594       703149 :         break;
    3595              :       }
    3596              : 
    3597     22632929 :     default:
    3598     22632929 :       if (d->pset->add (*t))
    3599       734184 :         *walk_subtrees = false;
    3600              :       break;
    3601              :     }
    3602              : 
    3603              :   return NULL_TREE;
    3604              : }
    3605              : 
    3606              : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ.  SEEN_P is set if
    3607              :    a PLACEHOLDER_EXPR has been encountered.  */
    3608              : 
    3609              : tree
    3610     73271709 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
    3611              : {
    3612              :   /* This is only relevant for C++14.  */
    3613     73271709 :   if (cxx_dialect < cxx14)
    3614       889303 :     return exp;
    3615              : 
    3616              :   /* If the object isn't a (member of a) class, do nothing.  */
    3617              :   tree op0 = obj;
    3618     72973682 :   while (handled_component_p (op0))
    3619       591276 :     op0 = TREE_OPERAND (op0, 0);
    3620     72382406 :   if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
    3621     64809635 :     return exp;
    3622              : 
    3623      7572771 :   tree *tp = &exp;
    3624      7572771 :   if (TREE_CODE (exp) == TARGET_EXPR)
    3625       988956 :     tp = &TARGET_EXPR_INITIAL (exp);
    3626      7572771 :   hash_set<tree> pset;
    3627      7572771 :   replace_placeholders_t data = { obj, *tp, false, &pset };
    3628      7572771 :   cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
    3629      7572771 :   if (seen_p)
    3630       194255 :     *seen_p = data.seen;
    3631      7572771 :   return exp;
    3632      7572771 : }
    3633              : 
    3634              : /* Callback function for find_placeholders.  */
    3635              : 
    3636              : static tree
    3637       317227 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
    3638              : {
    3639       317227 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3640              :     {
    3641       307920 :       *walk_subtrees = false;
    3642       307920 :       return NULL_TREE;
    3643              :     }
    3644              : 
    3645         9307 :   switch (TREE_CODE (*t))
    3646              :     {
    3647              :     case PLACEHOLDER_EXPR:
    3648              :       return *t;
    3649              : 
    3650          604 :     case CONSTRUCTOR:
    3651          604 :       if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
    3652          173 :         *walk_subtrees = false;
    3653              :       break;
    3654              : 
    3655              :     default:
    3656              :       break;
    3657              :     }
    3658              : 
    3659              :   return NULL_TREE;
    3660              : }
    3661              : 
    3662              : /* Return true if EXP contains a PLACEHOLDER_EXPR.  Don't walk into
    3663              :    ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set.  */
    3664              : 
    3665              : bool
    3666       307967 : find_placeholders (tree exp)
    3667              : {
    3668              :   /* This is only relevant for C++14.  */
    3669       307967 :   if (cxx_dialect < cxx14)
    3670              :     return false;
    3671              : 
    3672       307967 :   return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
    3673              : }
    3674              : 
    3675              : /* Similar to `build_nt', but for template definitions of dependent
    3676              :    expressions  */
    3677              : 
    3678              : tree
    3679    316701150 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
    3680              : {
    3681    316701150 :   tree t;
    3682    316701150 :   int length;
    3683    316701150 :   int i;
    3684    316701150 :   va_list p;
    3685              : 
    3686    316701150 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3687              : 
    3688    316701150 :   va_start (p, code);
    3689              : 
    3690    316701150 :   t = make_node (code);
    3691    316701150 :   SET_EXPR_LOCATION (t, loc);
    3692    316701150 :   length = TREE_CODE_LENGTH (code);
    3693              : 
    3694   1040864077 :   for (i = 0; i < length; i++)
    3695    724162927 :     TREE_OPERAND (t, i) = va_arg (p, tree);
    3696              : 
    3697    316701150 :   va_end (p);
    3698    316701150 :   return t;
    3699              : }
    3700              : 
    3701              : /* Similar to `build', but for template definitions.  */
    3702              : 
    3703              : tree
    3704    257209367 : build_min (enum tree_code code, tree tt, ...)
    3705              : {
    3706    257209367 :   tree t;
    3707    257209367 :   int length;
    3708    257209367 :   int i;
    3709    257209367 :   va_list p;
    3710              : 
    3711    257209367 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3712              : 
    3713    257209367 :   va_start (p, tt);
    3714              : 
    3715    257209367 :   t = make_node (code);
    3716    257209367 :   length = TREE_CODE_LENGTH (code);
    3717    257209367 :   TREE_TYPE (t) = tt;
    3718              : 
    3719    687708710 :   for (i = 0; i < length; i++)
    3720              :     {
    3721    430499343 :       tree x = va_arg (p, tree);
    3722    430499343 :       TREE_OPERAND (t, i) = x;
    3723    430499343 :       if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
    3724      3200813 :         TREE_SIDE_EFFECTS (t) = 1;
    3725              :     }
    3726              : 
    3727    257209367 :   va_end (p);
    3728              : 
    3729    257209367 :   return t;
    3730              : }
    3731              : 
    3732              : /* Similar to `build', but for template definitions of non-dependent
    3733              :    expressions. NON_DEP is the non-dependent expression that has been
    3734              :    built.  */
    3735              : 
    3736              : tree
    3737    122442640 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
    3738              : {
    3739    122442640 :   tree t;
    3740    122442640 :   int length;
    3741    122442640 :   int i;
    3742    122442640 :   va_list p;
    3743              : 
    3744    122442640 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3745              : 
    3746    122442640 :   va_start (p, non_dep);
    3747              : 
    3748    122442640 :   if (REFERENCE_REF_P (non_dep))
    3749      1263298 :     non_dep = TREE_OPERAND (non_dep, 0);
    3750              : 
    3751    122442640 :   t = make_node (code);
    3752    164295895 :   SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
    3753    122442640 :   length = TREE_CODE_LENGTH (code);
    3754    122442640 :   TREE_TYPE (t) = unlowered_expr_type (non_dep);
    3755    122442640 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3756              : 
    3757    430362557 :   for (i = 0; i < length; i++)
    3758              :     {
    3759    307919917 :       tree x = va_arg (p, tree);
    3760    307919917 :       TREE_OPERAND (t, i) = x;
    3761    307919917 :       if (x && !TYPE_P (x))
    3762    241883495 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3763              :     }
    3764              : 
    3765    122442640 :   va_end (p);
    3766    122442640 :   return convert_from_reference (t);
    3767              : }
    3768              : 
    3769              : /* Similar to build_min_nt, but call expressions  */
    3770              : 
    3771              : tree
    3772    218346992 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
    3773              : {
    3774    218346992 :   tree ret, t;
    3775    218346992 :   unsigned int ix;
    3776              : 
    3777    436558459 :   ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
    3778    218346992 :   CALL_EXPR_FN (ret) = fn;
    3779    218346992 :   CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
    3780    460508146 :   FOR_EACH_VEC_SAFE_ELT (args, ix, t)
    3781    484322308 :     CALL_EXPR_ARG (ret, ix) = t;
    3782              : 
    3783    218346992 :   return ret;
    3784              : }
    3785              : 
    3786              : /* Similar to `build_min_nt_call_vec', but for template definitions of
    3787              :    non-dependent expressions. NON_DEP is the non-dependent expression
    3788              :    that has been built.  */
    3789              : 
    3790              : tree
    3791     13792377 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
    3792              : {
    3793     13792377 :   tree t = build_min_nt_call_vec (fn, argvec);
    3794     13792377 :   if (REFERENCE_REF_P (non_dep))
    3795            6 :     non_dep = TREE_OPERAND (non_dep, 0);
    3796     13792377 :   TREE_TYPE (t) = TREE_TYPE (non_dep);
    3797     13792377 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3798     13792377 :   if (argvec)
    3799     27684135 :     for (tree x : *argvec)
    3800     14027283 :       if (x && !TYPE_P (x))
    3801     14027283 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3802     13792377 :   return convert_from_reference (t);
    3803              : }
    3804              : 
    3805              : /* Similar to build_min_non_dep, but for expressions that have been resolved to
    3806              :    a call to an operator overload.  OP is the operator that has been
    3807              :    overloaded.  NON_DEP is the non-dependent expression that's been built,
    3808              :    which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR.  OVERLOAD is
    3809              :    the overload that NON_DEP is calling.  */
    3810              : 
    3811              : tree
    3812      6347794 : build_min_non_dep_op_overload (enum tree_code op,
    3813              :                                tree non_dep,
    3814              :                                tree overload, ...)
    3815              : {
    3816      6347794 :   va_list p;
    3817      6347794 :   int nargs, expected_nargs;
    3818      6347794 :   tree fn, call, obj = NULL_TREE;
    3819              : 
    3820      6347794 :   releasing_vec args;
    3821      6347794 :   va_start (p, overload);
    3822              : 
    3823      6347794 :   bool negated = false, rewritten = false, reversed = false;
    3824      6347794 :   if (cxx_dialect >= cxx20 && TREE_CODE (overload) == TREE_LIST)
    3825              :     {
    3826              :       /* Handle rebuilding a C++20 rewritten comparison operator expression,
    3827              :          e.g. !(x == y), y <=> x, (x <=> y) @ 0 etc, that resolved to a call
    3828              :          to a user-defined operator<=>/==.  */
    3829       553859 :       gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
    3830              :                            || op == SPACESHIP_EXPR);
    3831       553859 :       int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
    3832       553859 :       if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
    3833              :         {
    3834       508899 :           negated = true;
    3835       508899 :           non_dep = TREE_OPERAND (non_dep, 0);
    3836              :         }
    3837       553859 :       if (flags & LOOKUP_REWRITTEN)
    3838       553859 :         rewritten = true;
    3839       553859 :       if (flags & LOOKUP_REVERSED)
    3840           69 :         reversed = true;
    3841       553859 :       if (rewritten
    3842       553859 :           && DECL_OVERLOADED_OPERATOR_IS (TREE_VALUE (overload),
    3843              :                                           SPACESHIP_EXPR))
    3844              :         {
    3845              :           /* Handle (x <=> y) @ 0 and 0 @ (y <=> x) by recursing to first
    3846              :              rebuild the <=>.  Note that both OVERLOAD and the provided arguments
    3847              :              in this case already correspond to the selected operator<=>.  */
    3848              : 
    3849        44954 :           tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
    3850        89845 :                                     ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
    3851        44966 :                                     : TREE_OPERAND (non_dep, reversed ? 1 : 0));
    3852        44954 :           gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
    3853        44954 :           tree spaceship_op0 = va_arg (p, tree);
    3854        44954 :           tree spaceship_op1 = va_arg (p, tree);
    3855        44954 :           if (reversed)
    3856           51 :             std::swap (spaceship_op0, spaceship_op1);
    3857              : 
    3858              :           /* Push the correct arguments for the operator OP expression, and
    3859              :              set OVERLOAD appropriately.  */
    3860        44954 :           tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
    3861              :                                                     spaceship_non_dep,
    3862        44954 :                                                     TREE_VALUE (overload),
    3863              :                                                     spaceship_op0,
    3864        44954 :                                                     spaceship_op1);
    3865        44954 :           tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
    3866        89872 :                       ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
    3867           39 :                       : TREE_OPERAND (non_dep, reversed ? 0 : 1));
    3868        44954 :           gcc_checking_assert (integer_zerop (op1));
    3869              : 
    3870        44954 :           if (TREE_CODE (non_dep) != CALL_EXPR)
    3871              :             {
    3872           27 :               gcc_checking_assert (COMPARISON_CLASS_P (non_dep)
    3873              :                                    || TREE_CODE (non_dep) == SPACESHIP_EXPR);
    3874           27 :               if (reversed)
    3875           15 :                 std::swap (op0, op1);
    3876           27 :               return build_min_non_dep (TREE_CODE (non_dep), non_dep, op0, op1);
    3877              :             }
    3878              : 
    3879        44927 :           vec_safe_push (args, op0);
    3880        44927 :           vec_safe_push (args, op1);
    3881        44927 :           overload = CALL_EXPR_FN (non_dep);
    3882              :         }
    3883              :       else
    3884       508905 :         overload = TREE_VALUE (overload);
    3885              :     }
    3886      6347767 :   non_dep = extract_call_expr (non_dep);
    3887              : 
    3888      6347767 :   nargs = call_expr_nargs (non_dep);
    3889              : 
    3890      6347767 :   expected_nargs = cp_tree_code_length (op);
    3891     11865260 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
    3892              :       /* For ARRAY_REF, operator[] is either a non-static member or newly
    3893              :          static member, never out of class and for the static member case
    3894              :          if user uses single index the operator[] needs to have a single
    3895              :          argument as well, but the function is called with 2 - the object
    3896              :          it is invoked on and the index.  */
    3897     11863642 :       || op == ARRAY_REF)
    3898       831899 :     expected_nargs -= 1;
    3899      6347767 :   if ((op == POSTINCREMENT_EXPR
    3900      6347767 :        || op == POSTDECREMENT_EXPR)
    3901              :       /* With -fpermissive non_dep could be operator++().  */
    3902        10467 :       && (!flag_permissive || nargs != expected_nargs))
    3903        10464 :     expected_nargs += 1;
    3904      6347767 :   gcc_assert (nargs == expected_nargs);
    3905              : 
    3906      6347767 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
    3907              :     {
    3908      5515875 :       fn = overload;
    3909      5515875 :       if (vec_safe_length (args) != 0)
    3910              :         /* The correct arguments were already pushed above.  */
    3911        44927 :         gcc_checking_assert (rewritten);
    3912              :       else
    3913              :         {
    3914      5470948 :           if (op == ARRAY_REF)
    3915            7 :             obj = va_arg (p, tree);
    3916     16332372 :           for (int i = 0; i < nargs; i++)
    3917              :             {
    3918     10861424 :               tree arg = va_arg (p, tree);
    3919     10861424 :               vec_safe_push (args, arg);
    3920              :             }
    3921              :         }
    3922      5515875 :       if (reversed)
    3923           36 :         std::swap ((*args)[0], (*args)[1]);
    3924              :     }
    3925              :   else
    3926              :     {
    3927       831892 :       gcc_checking_assert (vec_safe_length (args) == 0);
    3928       831892 :       tree object = va_arg (p, tree);
    3929      1402623 :       for (int i = 0; i < nargs; i++)
    3930              :         {
    3931       570731 :           tree arg = va_arg (p, tree);
    3932       570731 :           vec_safe_push (args, arg);
    3933              :         }
    3934       831892 :       if (reversed)
    3935           18 :         std::swap (object, (*args)[0]);
    3936       831892 :       tree binfo = TYPE_BINFO (TREE_TYPE (object));
    3937       831892 :       tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
    3938       831892 :       fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
    3939              :                       object, method, NULL_TREE);
    3940              :     }
    3941              : 
    3942      6347767 :   va_end (p);
    3943      6347767 :   call = build_min_non_dep_call_vec (non_dep, fn, args);
    3944              : 
    3945      6347767 :   tree call_expr = extract_call_expr (call);
    3946      6347767 :   KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
    3947      6347767 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
    3948      6347767 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
    3949      6347767 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
    3950              : 
    3951      6347767 :   if (negated)
    3952       508899 :     call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
    3953      6347767 :   if (obj)
    3954            7 :     return keep_unused_object_arg (call, obj, overload);
    3955              :   return call;
    3956      6347794 : }
    3957              : 
    3958              : /* Similar to above build_min_non_dep_op_overload, but arguments
    3959              :    are taken from ARGS vector.  */
    3960              : 
    3961              : tree
    3962           22 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
    3963              :                                vec<tree, va_gc> *args)
    3964              : {
    3965           22 :   non_dep = extract_call_expr (non_dep);
    3966              : 
    3967           22 :   unsigned int nargs = call_expr_nargs (non_dep);
    3968           22 :   tree fn = overload;
    3969           22 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
    3970              :     {
    3971           14 :       tree binfo = TYPE_BINFO (TREE_TYPE (object));
    3972           14 :       tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
    3973           14 :       fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
    3974              :                       object, method, NULL_TREE);
    3975           14 :       object = NULL_TREE;
    3976              :     }
    3977           44 :   gcc_assert (vec_safe_length (args) == nargs);
    3978              : 
    3979           22 :   tree call = build_min_non_dep_call_vec (non_dep, fn, args);
    3980              : 
    3981           22 :   tree call_expr = extract_call_expr (call);
    3982           22 :   KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
    3983           22 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
    3984           22 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
    3985           22 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
    3986              : 
    3987           22 :   if (object)
    3988            8 :     return keep_unused_object_arg (call, object, overload);
    3989              :   return call;
    3990              : }
    3991              : 
    3992              : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX.  */
    3993              : 
    3994              : vec<tree, va_gc> *
    3995         8976 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
    3996              : {
    3997         8976 :   unsigned len = vec_safe_length (old_vec);
    3998         8976 :   gcc_assert (idx <= len);
    3999              : 
    4000         8976 :   vec<tree, va_gc> *new_vec = NULL;
    4001         8976 :   vec_alloc (new_vec, len + 1);
    4002              : 
    4003         8976 :   unsigned i;
    4004        26957 :   for (i = 0; i < len; ++i)
    4005              :     {
    4006         9005 :       if (i == idx)
    4007           29 :         new_vec->quick_push (elt);
    4008         9005 :       new_vec->quick_push ((*old_vec)[i]);
    4009              :     }
    4010         8976 :   if (i == idx)
    4011         8947 :     new_vec->quick_push (elt);
    4012              : 
    4013         8976 :   return new_vec;
    4014              : }
    4015              : 
    4016              : tree
    4017       128465 : get_type_decl (tree t)
    4018              : {
    4019       128465 :   if (TREE_CODE (t) == TYPE_DECL)
    4020              :     return t;
    4021       128465 :   if (TYPE_P (t))
    4022       128465 :     return TYPE_STUB_DECL (t);
    4023            0 :   gcc_assert (t == error_mark_node);
    4024              :   return t;
    4025              : }
    4026              : 
    4027              : /* Returns the namespace that contains DECL, whether directly or
    4028              :    indirectly.  */
    4029              : 
    4030              : tree
    4031   1496473262 : decl_namespace_context (tree decl)
    4032              : {
    4033   3138250628 :   while (1)
    4034              :     {
    4035   3138250628 :       if (TREE_CODE (decl) == NAMESPACE_DECL)
    4036   1496473262 :         return decl;
    4037   1641777366 :       else if (TYPE_P (decl))
    4038    914531403 :         decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
    4039              :       else
    4040    727245963 :         decl = CP_DECL_CONTEXT (decl);
    4041              :     }
    4042              : }
    4043              : 
    4044              : /* Returns true if decl is within an anonymous namespace, however deeply
    4045              :    nested, or false otherwise.  */
    4046              : 
    4047              : bool
    4048           23 : decl_anon_ns_mem_p (tree decl)
    4049              : {
    4050           23 :   return !TREE_PUBLIC (decl_namespace_context (decl));
    4051              : }
    4052              : 
    4053              : /* Returns true if the enclosing scope of DECL has internal or no linkage.  */
    4054              : 
    4055              : bool
    4056   1374673315 : decl_internal_context_p (const_tree decl)
    4057              : {
    4058   2754797662 :   while (TREE_CODE (decl) != NAMESPACE_DECL)
    4059              :     {
    4060              :       /* Classes inside anonymous namespaces have TREE_PUBLIC == 0.  */
    4061   1736605650 :       if (TYPE_P (decl))
    4062    356481303 :         return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
    4063              : 
    4064   1380124347 :       decl = CP_DECL_CONTEXT (decl);
    4065              :     }
    4066   1018192012 :   return !TREE_PUBLIC (decl);
    4067              : }
    4068              : 
    4069              : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
    4070              :    Return whether their CALL_EXPR_FNs are equivalent.  */
    4071              : 
    4072              : static bool
    4073     52401559 : called_fns_equal (tree t1, tree t2)
    4074              : {
    4075              :   /* Core 1321: dependent names are equivalent even if the overload sets
    4076              :      are different.  But do compare explicit template arguments.  */
    4077     52401559 :   tree name1 = call_expr_dependent_name (t1);
    4078     52401559 :   tree name2 = call_expr_dependent_name (t2);
    4079     52401559 :   t1 = CALL_EXPR_FN (t1);
    4080     52401559 :   t2 = CALL_EXPR_FN (t2);
    4081     52401559 :   if (name1 || name2)
    4082              :     {
    4083     44671787 :       tree targs1 = NULL_TREE, targs2 = NULL_TREE;
    4084              : 
    4085     44671787 :       if (name1 != name2)
    4086              :         return false;
    4087              : 
    4088              :       /* FIXME dependent_name currently returns an unqualified name regardless
    4089              :          of whether the function was named with a qualified- or unqualified-id.
    4090              :          Until that's fixed, check that we aren't looking at overload sets from
    4091              :          different scopes.  */
    4092     43606214 :       if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
    4093     87240344 :           && (DECL_CONTEXT (get_first_fn (t1))
    4094     43606211 :               != DECL_CONTEXT (get_first_fn (t2))))
    4095              :         return false;
    4096              : 
    4097     43634133 :       if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
    4098     28415159 :         targs1 = TREE_OPERAND (t1, 1);
    4099     43634133 :       if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
    4100     28415159 :         targs2 = TREE_OPERAND (t2, 1);
    4101     43634133 :       return cp_tree_equal (targs1, targs2);
    4102              :     }
    4103              :   else
    4104      7729772 :     return cp_tree_equal (t1, t2);
    4105              : }
    4106              : 
    4107              : /* Return truthvalue of whether T1 is the same tree structure as T2.
    4108              :    Return 1 if they are the same. Return 0 if they are different.  */
    4109              : 
    4110              : bool
    4111   3094545943 : cp_tree_equal (tree t1, tree t2)
    4112              : {
    4113   3102180265 :   enum tree_code code1, code2;
    4114              : 
    4115   3102180265 :   if (t1 == t2)
    4116              :     return true;
    4117   1292004388 :   if (!t1 || !t2)
    4118              :     return false;
    4119              : 
    4120   1291407085 :   code1 = TREE_CODE (t1);
    4121   1291407085 :   code2 = TREE_CODE (t2);
    4122              : 
    4123   1291407085 :   if (comparing_contracts)
    4124              :     {
    4125              :       /* When comparing contracts, one declaration may already be
    4126              :          genericized. Check for invisible references and unravel them
    4127              :          for comparison purposes. Remember that a parameter is an invisible
    4128              :          reference so we can compare the parameter types accordingly.  */
    4129          150 :       if (code1 == VIEW_CONVERT_EXPR
    4130          150 :           && is_invisiref_parm (TREE_OPERAND(t1, 0)))
    4131              :         {
    4132            2 :           t1 = TREE_OPERAND(t1, 0);
    4133            2 :           code1 = TREE_CODE(t1);
    4134              :         }
    4135          150 :       if (code2 == VIEW_CONVERT_EXPR
    4136          150 :           && is_invisiref_parm (TREE_OPERAND(t2, 0)))
    4137              :         {
    4138            0 :           t2 = TREE_OPERAND(t2, 0);
    4139            0 :           code2 = TREE_CODE(t2);
    4140              :         }
    4141              :     }
    4142              : 
    4143   1291407085 :   if (code1 != code2)
    4144              :     return false;
    4145              : 
    4146   1175260921 :   if (CONSTANT_CLASS_P (t1)
    4147   1175260921 :       && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    4148              :     return false;
    4149              : 
    4150   1175188643 :   switch (code1)
    4151              :     {
    4152            0 :     case VOID_CST:
    4153              :       /* There's only a single VOID_CST node, so we should never reach
    4154              :          here.  */
    4155            0 :       gcc_unreachable ();
    4156              : 
    4157    165975487 :     case INTEGER_CST:
    4158    165975487 :       return tree_int_cst_equal (t1, t2);
    4159              : 
    4160       105839 :     case REAL_CST:
    4161       105839 :       return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
    4162              : 
    4163        94510 :     case STRING_CST:
    4164        94510 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
    4165        94510 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
    4166        94510 :                     TREE_STRING_LENGTH (t1));
    4167              : 
    4168            0 :     case FIXED_CST:
    4169            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
    4170              :                                      TREE_FIXED_CST (t2));
    4171              : 
    4172            1 :     case COMPLEX_CST:
    4173            1 :       return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
    4174            2 :         && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
    4175              : 
    4176         3837 :     case VECTOR_CST:
    4177         3837 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
    4178              : 
    4179      1660802 :     case CONSTRUCTOR:
    4180              :       /* We need to do this when determining whether or not two
    4181              :          non-type pointer to member function template arguments
    4182              :          are the same.  */
    4183      1660802 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    4184      3544876 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
    4185              :         return false;
    4186              :       {
    4187              :         tree field, value;
    4188              :         unsigned int i;
    4189      1785473 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
    4190              :           {
    4191       168709 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
    4192       168709 :             if (!cp_tree_equal (field, elt2->index)
    4193       168709 :                 || !cp_tree_equal (value, elt2->value))
    4194           20 :               return false;
    4195              :           }
    4196              :       }
    4197              :       return true;
    4198              : 
    4199      9203263 :     case TREE_LIST:
    4200      9203263 :       if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
    4201              :         return false;
    4202      9203263 :       if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
    4203              :         return false;
    4204        22173 :       return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
    4205              : 
    4206          743 :     case SAVE_EXPR:
    4207          743 :       return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
    4208              : 
    4209     52604895 :     case CALL_EXPR:
    4210     52604895 :       {
    4211     52604895 :         if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
    4212              :           return false;
    4213              : 
    4214     52401559 :         if (!called_fns_equal (t1, t2))
    4215              :           return false;
    4216              : 
    4217     22178178 :         call_expr_arg_iterator iter1, iter2;
    4218     22178178 :         init_call_expr_arg_iterator (t1, &iter1);
    4219     22178178 :         init_call_expr_arg_iterator (t2, &iter2);
    4220     22178178 :         if (iter1.n != iter2.n)
    4221              :           return false;
    4222              : 
    4223     23528259 :         while (more_call_expr_args_p (&iter1))
    4224              :           {
    4225     16060206 :             tree arg1 = next_call_expr_arg (&iter1);
    4226     16060206 :             tree arg2 = next_call_expr_arg (&iter2);
    4227              : 
    4228     16060206 :             gcc_checking_assert (arg1 && arg2);
    4229     16060206 :             if (!cp_tree_equal (arg1, arg2))
    4230              :               return false;
    4231              :           }
    4232              : 
    4233              :         return true;
    4234              :       }
    4235              : 
    4236       481536 :     case TARGET_EXPR:
    4237       481536 :       {
    4238       481536 :         tree o1 = TARGET_EXPR_SLOT (t1);
    4239       481536 :         tree o2 = TARGET_EXPR_SLOT (t2);
    4240              : 
    4241              :         /* Special case: if either target is an unallocated VAR_DECL,
    4242              :            it means that it's going to be unified with whatever the
    4243              :            TARGET_EXPR is really supposed to initialize, so treat it
    4244              :            as being equivalent to anything.  */
    4245       481536 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
    4246       963072 :             && !DECL_RTL_SET_P (o1))
    4247              :           /*Nop*/;
    4248            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
    4249            0 :                  && !DECL_RTL_SET_P (o2))
    4250              :           /*Nop*/;
    4251            0 :         else if (!cp_tree_equal (o1, o2))
    4252              :           return false;
    4253              : 
    4254       481536 :         return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
    4255       963072 :                               TARGET_EXPR_INITIAL (t2));
    4256              :       }
    4257              : 
    4258           25 :     case AGGR_INIT_EXPR:
    4259           25 :       {
    4260           25 :         int n = aggr_init_expr_nargs (t1);
    4261           25 :         if (n != aggr_init_expr_nargs (t2))
    4262              :           return false;
    4263              : 
    4264           50 :         if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
    4265           25 :                             AGGR_INIT_EXPR_FN (t2)))
    4266              :           return false;
    4267              : 
    4268           25 :         tree o1 = AGGR_INIT_EXPR_SLOT (t1);
    4269           25 :         tree o2 = AGGR_INIT_EXPR_SLOT (t2);
    4270              : 
    4271              :         /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
    4272              :            going to unify the initialization, so treat it as equivalent
    4273              :            to anything.  */
    4274           25 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
    4275           50 :             && !DECL_RTL_SET_P (o1))
    4276              :           /*Nop*/;
    4277            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
    4278            0 :                  && !DECL_RTL_SET_P (o2))
    4279              :           /*Nop*/;
    4280            0 :         else if (!cp_tree_equal (o1, o2))
    4281              :           return false;
    4282              : 
    4283           51 :         for (int i = 0; i < n; ++i)
    4284           31 :           if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
    4285           31 :                               AGGR_INIT_EXPR_ARG (t2, i)))
    4286              :             return false;
    4287              : 
    4288              :         return true;
    4289              :       }
    4290              : 
    4291      2465615 :     case PARM_DECL:
    4292              :       /* For comparing uses of parameters in late-specified return types
    4293              :          with an out-of-class definition of the function, but can also come
    4294              :          up for expressions that involve 'this' in a member function
    4295              :          template.  */
    4296              : 
    4297      2465615 :       if (comparing_specializations
    4298      2465615 :           && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
    4299              :         /* When comparing hash table entries, only an exact match is
    4300              :            good enough; we don't want to replace 'this' with the
    4301              :            version from another function.  But be more flexible
    4302              :            with parameters with identical contexts.  */
    4303              :         return false;
    4304              : 
    4305      2202382 :       if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) || comparing_contracts)
    4306              :         {
    4307              :           /* When comparing contracts, we already know the declarations match,
    4308              :             and that the arguments have the same type. If one of the declarations
    4309              :             has been genericised, then the type of arguments in that declaration
    4310              :             will be adjusted for an invisible reference and the type comparison
    4311              :             would spuriosly fail. The only thing we care about when comparing
    4312              :             contractsis that we're using the same parameter.  */
    4313      1325786 :           if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
    4314              :             return false;
    4315      1325786 :           if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
    4316              :             return false;
    4317      1325786 :           if (DECL_ARTIFICIAL (t1)
    4318      1325786 :               || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
    4319      1325151 :                   && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
    4320              :             return true;
    4321              :         }
    4322              :       return false;
    4323              : 
    4324     25098452 :     case TEMPLATE_DECL:
    4325     25098452 :       if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
    4326     25388477 :           && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
    4327       132353 :         return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
    4328              :       /* Fall through.  */
    4329              :     case VAR_DECL:
    4330              :     case CONST_DECL:
    4331              :     case FIELD_DECL:
    4332              :     case FUNCTION_DECL:
    4333              :     case IDENTIFIER_NODE:
    4334              :     case SSA_NAME:
    4335              :     case USING_DECL:
    4336              :     case DEFERRED_PARSE:
    4337              :     case NAMESPACE_DECL:
    4338              :       return false;
    4339              : 
    4340      4770683 :     case BASELINK:
    4341      4770683 :       return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
    4342      4020522 :               && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
    4343      4020522 :               && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
    4344      8791193 :               && cp_tree_equal (BASELINK_FUNCTIONS (t1),
    4345      4020510 :                                 BASELINK_FUNCTIONS (t2)));
    4346              : 
    4347     13305597 :     case TEMPLATE_PARM_INDEX:
    4348     13305597 :       return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
    4349     12667653 :               && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
    4350     12154192 :               && (TEMPLATE_PARM_PARAMETER_PACK (t1)
    4351     12154192 :                   == TEMPLATE_PARM_PARAMETER_PACK (t2))
    4352     25415680 :               && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
    4353              :                               TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
    4354              : 
    4355     29420717 :     case TEMPLATE_ID_EXPR:
    4356     29420717 :       if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4357              :         return false;
    4358     28603321 :       if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
    4359              :         return false;
    4360              :       return true;
    4361              : 
    4362      6996450 :     case CONSTRAINT_INFO:
    4363     20989350 :       return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
    4364     20989350 :                             CI_ASSOCIATED_CONSTRAINTS (t2));
    4365              : 
    4366     55283666 :     case TREE_VEC:
    4367              :       /* These are template args.  Really we should be getting the
    4368              :          caller to do this as it knows it to be true.  */
    4369     55283666 :       if (!comp_template_args (t1, t2))
    4370              :         return false;
    4371              :       return true;
    4372              : 
    4373      1515936 :     case SIZEOF_EXPR:
    4374      1515936 :     case ALIGNOF_EXPR:
    4375      1515936 :       {
    4376      1515936 :         tree o1 = TREE_OPERAND (t1, 0);
    4377      1515936 :         tree o2 = TREE_OPERAND (t2, 0);
    4378              : 
    4379      1515936 :         if (code1 == SIZEOF_EXPR)
    4380              :           {
    4381      1506915 :             if (SIZEOF_EXPR_TYPE_P (t1))
    4382            0 :               o1 = TREE_TYPE (o1);
    4383      1506915 :             if (SIZEOF_EXPR_TYPE_P (t2))
    4384            0 :               o2 = TREE_TYPE (o2);
    4385              :           }
    4386         9021 :         else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
    4387              :           return false;
    4388              : 
    4389      1515930 :         if (TREE_CODE (o1) != TREE_CODE (o2))
    4390              :           return false;
    4391              : 
    4392      1515900 :         if (ARGUMENT_PACK_P (o1))
    4393            0 :           return template_args_equal (o1, o2);
    4394      1515900 :         else if (TYPE_P (o1))
    4395      1515132 :           return same_type_p (o1, o2);
    4396              :         else
    4397              :           return cp_tree_equal (o1, o2);
    4398              :       }
    4399              : 
    4400         1219 :     case MODOP_EXPR:
    4401         1219 :       {
    4402         1219 :         tree t1_op1, t2_op1;
    4403              : 
    4404         1219 :         if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4405              :           return false;
    4406              : 
    4407         1055 :         t1_op1 = TREE_OPERAND (t1, 1);
    4408         1055 :         t2_op1 = TREE_OPERAND (t2, 1);
    4409         1055 :         if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
    4410              :           return false;
    4411              : 
    4412          299 :         return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
    4413              :       }
    4414              : 
    4415          779 :     case PTRMEM_CST:
    4416              :       /* Two pointer-to-members are the same if they point to the same
    4417              :          field or function in the same class.  */
    4418          779 :       if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
    4419              :         return false;
    4420              : 
    4421          832 :       return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
    4422              : 
    4423        19568 :     case OVERLOAD:
    4424        19568 :       {
    4425              :         /* Two overloads. Must be exactly the same set of decls.  */
    4426        19568 :         lkp_iterator first (t1);
    4427        19568 :         lkp_iterator second (t2);
    4428              : 
    4429        28781 :         for (; first && second; ++first, ++second)
    4430        20111 :           if (*first != *second)
    4431              :             return false;
    4432         8670 :         return !(first || second);
    4433              :       }
    4434              : 
    4435      9776788 :     case TRAIT_EXPR:
    4436      9776788 :       if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
    4437              :         return false;
    4438       724432 :       return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
    4439      1434863 :         && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
    4440              : 
    4441      1042249 :     case NON_LVALUE_EXPR:
    4442      1042249 :     case VIEW_CONVERT_EXPR:
    4443              :       /* Used for location wrappers with possibly NULL types.  */
    4444      1042249 :       if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
    4445              :         {
    4446           23 :           if (TREE_TYPE (t1) || TREE_TYPE (t2))
    4447              :             return false;
    4448              :           break;
    4449              :         }
    4450              :       /* FALLTHROUGH  */
    4451              : 
    4452      2943459 :     case CAST_EXPR:
    4453      2943459 :     case STATIC_CAST_EXPR:
    4454      2943459 :     case REINTERPRET_CAST_EXPR:
    4455      2943459 :     case CONST_CAST_EXPR:
    4456      2943459 :     case DYNAMIC_CAST_EXPR:
    4457      2943459 :     case IMPLICIT_CONV_EXPR:
    4458      2943459 :     case NEW_EXPR:
    4459      2943459 :     case BIT_CAST_EXPR:
    4460      2943459 :     CASE_CONVERT:
    4461      2943459 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    4462              :         return false;
    4463              :       /* Now compare operands as usual.  */
    4464              :       break;
    4465              : 
    4466            0 :     case DEFERRED_NOEXCEPT:
    4467            0 :       return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
    4468            0 :                              DEFERRED_NOEXCEPT_PATTERN (t2))
    4469            0 :               && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
    4470            0 :                                      DEFERRED_NOEXCEPT_ARGS (t2)));
    4471              : 
    4472              :     case LAMBDA_EXPR:
    4473              :       /* Two lambda-expressions are never considered equivalent.  */
    4474              :       return false;
    4475              : 
    4476    674505601 :     case TYPE_ARGUMENT_PACK:
    4477    674505601 :     case NONTYPE_ARGUMENT_PACK:
    4478    674505601 :       {
    4479    674505601 :         tree p1 = ARGUMENT_PACK_ARGS (t1);
    4480    674505601 :         tree p2 = ARGUMENT_PACK_ARGS (t2);
    4481    674505601 :         int len = TREE_VEC_LENGTH (p1);
    4482    674505601 :         if (TREE_VEC_LENGTH (p2) != len)
    4483              :           return false;
    4484              : 
    4485    833514492 :         for (int ix = 0; ix != len; ix++)
    4486    733701493 :           if (!template_args_equal (TREE_VEC_ELT (p1, ix),
    4487    733701493 :                                     TREE_VEC_ELT (p2, ix)))
    4488              :             return false;
    4489              :         return true;
    4490              :       }
    4491              : 
    4492      1201678 :     case EXPR_PACK_EXPANSION:
    4493      1201678 :       if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
    4494      1201678 :                           PACK_EXPANSION_PATTERN (t2)))
    4495              :         return false;
    4496        14081 :       if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    4497        14081 :                                PACK_EXPANSION_EXTRA_ARGS (t2)))
    4498              :         return false;
    4499              :       return true;
    4500              : 
    4501         2196 :     case PACK_INDEX_EXPR:
    4502         2196 :       if (!cp_tree_equal (PACK_INDEX_PACK (t1),
    4503         2196 :                           PACK_INDEX_PACK (t2)))
    4504              :         return false;
    4505           93 :       if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
    4506           93 :                           PACK_INDEX_INDEX (t2)))
    4507              :         return false;
    4508              :       return true;
    4509              : 
    4510          798 :     case REFLECT_EXPR:
    4511          798 :       if (!cp_tree_equal (REFLECT_EXPR_HANDLE (t1), REFLECT_EXPR_HANDLE (t2))
    4512         1588 :           || REFLECT_EXPR_KIND (t1) != REFLECT_EXPR_KIND (t2))
    4513              :         return false;
    4514              :       return true;
    4515              : 
    4516              :     default:
    4517              :       break;
    4518              :     }
    4519              : 
    4520     83394366 :   switch (TREE_CODE_CLASS (code1))
    4521              :     {
    4522     80789336 :     case tcc_unary:
    4523     80789336 :     case tcc_binary:
    4524     80789336 :     case tcc_comparison:
    4525     80789336 :     case tcc_expression:
    4526     80789336 :     case tcc_vl_exp:
    4527     80789336 :     case tcc_reference:
    4528     80789336 :     case tcc_statement:
    4529     80789336 :       {
    4530     80789336 :         int n = cp_tree_operand_length (t1);
    4531     80789336 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
    4532     80789336 :             && n != TREE_OPERAND_LENGTH (t2))
    4533              :           return false;
    4534              : 
    4535    136493882 :         for (int i = 0; i < n; ++i)
    4536    106397837 :           if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
    4537              :             return false;
    4538              : 
    4539              :         return true;
    4540              :       }
    4541              : 
    4542      2605030 :     case tcc_type:
    4543      2605030 :       return same_type_p (t1, t2);
    4544              : 
    4545            0 :     default:
    4546            0 :       gcc_unreachable ();
    4547              :     }
    4548              : 
    4549              :   /* We can get here with --disable-checking.  */
    4550              :   return false;
    4551              : }
    4552              : 
    4553              : /* The type of ARG when used as an lvalue.  */
    4554              : 
    4555              : tree
    4556   1195612640 : lvalue_type (tree arg)
    4557              : {
    4558   1195612640 :   tree type = TREE_TYPE (arg);
    4559   1195612640 :   return type;
    4560              : }
    4561              : 
    4562              : /* The type of ARG for printing error messages; denote lvalues with
    4563              :    reference types.  */
    4564              : 
    4565              : tree
    4566         3717 : error_type (tree arg)
    4567              : {
    4568         3717 :   tree type = TREE_TYPE (arg);
    4569              : 
    4570         3717 :   if (TREE_CODE (type) == ARRAY_TYPE)
    4571              :     ;
    4572         3606 :   else if (TREE_CODE (type) == ERROR_MARK)
    4573              :     ;
    4574         3606 :   else if (lvalue_p (arg))
    4575         1245 :     type = build_reference_type (lvalue_type (arg));
    4576         2361 :   else if (MAYBE_CLASS_TYPE_P (type))
    4577          747 :     type = lvalue_type (arg);
    4578              : 
    4579         3717 :   return type;
    4580              : }
    4581              : 
    4582              : /* Does FUNCTION use a variable-length argument list?  */
    4583              : 
    4584              : int
    4585       542883 : varargs_function_p (const_tree function)
    4586              : {
    4587       542883 :   return stdarg_p (TREE_TYPE (function));
    4588              : }
    4589              : 
    4590              : /* Returns 1 if decl is a member of a class.  */
    4591              : 
    4592              : int
    4593        11057 : member_p (const_tree decl)
    4594              : {
    4595        11057 :   const_tree const ctx = DECL_CONTEXT (decl);
    4596        11057 :   return (ctx && TYPE_P (ctx));
    4597              : }
    4598              : 
    4599              : /* Create a placeholder for member access where we don't actually have an
    4600              :    object that the access is against.  For a general declval<T> equivalent,
    4601              :    use build_stub_object instead.  */
    4602              : 
    4603              : tree
    4604    115101808 : build_dummy_object (tree type)
    4605              : {
    4606    115101808 :   tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
    4607    115101808 :   return cp_build_fold_indirect_ref (decl);
    4608              : }
    4609              : 
    4610              : /* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
    4611              :    or a dummy object otherwise.  If BINFOP is non-0, it is filled with the
    4612              :    binfo path from current_class_type to TYPE, or 0.  */
    4613              : 
    4614              : tree
    4615    108039782 : maybe_dummy_object (tree type, tree* binfop)
    4616              : {
    4617    108039782 :   tree decl, context;
    4618    108039782 :   tree binfo;
    4619    108039782 :   tree current = current_nonlambda_class_type ();
    4620              : 
    4621    108039782 :   if (current
    4622    108039782 :       && (binfo = lookup_base (current, type, ba_any, NULL,
    4623              :                                tf_warning_or_error)))
    4624              :     context = current;
    4625              :   else
    4626              :     {
    4627              :       /* Reference from a nested class member function.  */
    4628      8802661 :       context = type;
    4629      8802661 :       binfo = TYPE_BINFO (type);
    4630              :     }
    4631              : 
    4632    108039782 :   if (binfop)
    4633       105695 :     *binfop = binfo;
    4634              : 
    4635              :   /* current_class_ref might not correspond to current_class_type if
    4636              :      we're in tsubst_default_argument or a lambda-declarator; in either
    4637              :      case, we want to use current_class_ref if it matches CONTEXT.  */
    4638    108039782 :   tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
    4639     98748167 :   if (ctype
    4640     98748167 :       && same_type_ignoring_top_level_qualifiers_p (ctype, context))
    4641     95320014 :     decl = current_class_ref;
    4642              :   else
    4643              :     {
    4644              :       /* Return a dummy object whose cv-quals are consistent with (the
    4645              :          non-lambda) 'this' if available.  */
    4646     12719768 :       if (ctype)
    4647              :         {
    4648      3428153 :           int quals = TYPE_UNQUALIFIED;
    4649      3428153 :           if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
    4650              :             {
    4651       400949 :               if (tree cap = lambda_expr_this_capture (lambda, false))
    4652       390333 :                 quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
    4653              :             }
    4654              :           else
    4655      3027204 :             quals = cp_type_quals (ctype);
    4656      3428153 :           context = cp_build_qualified_type (context, quals);
    4657              :         }
    4658     12719768 :       decl = build_dummy_object (context);
    4659              :     }
    4660              : 
    4661    108039782 :   return decl;
    4662              : }
    4663              : 
    4664              : /* Returns 1 if OB is a placeholder object, or a pointer to one.  */
    4665              : 
    4666              : bool
    4667    611014934 : is_dummy_object (const_tree ob)
    4668              : {
    4669    611014934 :   if (INDIRECT_REF_P (ob))
    4670    457825286 :     ob = TREE_OPERAND (ob, 0);
    4671    611014934 :   return (TREE_CODE (ob) == CONVERT_EXPR
    4672    611014934 :           && TREE_OPERAND (ob, 0) == void_node);
    4673              : }
    4674              : 
    4675              : /* Returns true if TYPE is char, unsigned char, or std::byte.  */
    4676              : 
    4677              : bool
    4678     32202203 : is_byte_access_type (tree type)
    4679              : {
    4680     32202203 :   type = TYPE_MAIN_VARIANT (type);
    4681     32202203 :   if (type == char_type_node
    4682      7219584 :       || type == unsigned_char_type_node)
    4683              :     return true;
    4684              : 
    4685      7069985 :   return (TREE_CODE (type) == ENUMERAL_TYPE
    4686        15054 :           && TYPE_CONTEXT (type) == std_node
    4687      7088095 :           && !strcmp ("byte", TYPE_NAME_STRING (type)));
    4688              : }
    4689              : 
    4690              : /* Returns true if TYPE is unsigned char or std::byte.  */
    4691              : 
    4692              : bool
    4693         1754 : is_byte_access_type_not_plain_char (tree type)
    4694              : {
    4695         1754 :   type = TYPE_MAIN_VARIANT (type);
    4696         1754 :   if (type == char_type_node)
    4697              :     return false;
    4698              : 
    4699         1506 :   return is_byte_access_type (type);
    4700              : }
    4701              : 
    4702              : /* Returns 1 iff type T is something we want to treat as a scalar type for
    4703              :    the purpose of deciding whether it is trivial/POD/standard-layout.  */
    4704              : 
    4705              : bool
    4706    102613997 : scalarish_type_p (const_tree t)
    4707              : {
    4708    102613997 :   if (t == error_mark_node)
    4709              :     return 1;
    4710              : 
    4711    102613796 :   return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
    4712              : }
    4713              : 
    4714              : /* Returns true iff T requires non-trivial default initialization.  */
    4715              : 
    4716              : bool
    4717            0 : type_has_nontrivial_default_init (const_tree t)
    4718              : {
    4719            0 :   t = strip_array_types (const_cast<tree> (t));
    4720              : 
    4721            0 :   if (CLASS_TYPE_P (t))
    4722            0 :     return TYPE_HAS_COMPLEX_DFLT (t);
    4723              :   else
    4724              :     return 0;
    4725              : }
    4726              : 
    4727              : /* Track classes with only deleted copy/move constructors so that we can warn
    4728              :    if they are used in call/return by value.  */
    4729              : 
    4730              : static GTY(()) hash_set<tree>* deleted_copy_types;
    4731              : static void
    4732            9 : remember_deleted_copy (const_tree t)
    4733              : {
    4734            9 :   if (!deleted_copy_types)
    4735            9 :     deleted_copy_types = hash_set<tree>::create_ggc(37);
    4736            9 :   deleted_copy_types->add (const_cast<tree> (t));
    4737            9 : }
    4738              : void
    4739    416614305 : maybe_warn_parm_abi (tree t, location_t loc)
    4740              : {
    4741    416614305 :   if (!deleted_copy_types
    4742    416614305 :       || !deleted_copy_types->contains (t))
    4743    416614275 :     return;
    4744              : 
    4745           30 :   if ((flag_abi_version == 12 || warn_abi_version == 12)
    4746           36 :       && classtype_has_non_deleted_move_ctor (t))
    4747              :     {
    4748            6 :       bool w;
    4749            6 :       auto_diagnostic_group d;
    4750            6 :       if (flag_abi_version > 12)
    4751            0 :         w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
    4752              :                         "the calling convention for %qT, which was "
    4753              :                         "accidentally changed in 8.1", t);
    4754              :       else
    4755            6 :         w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
    4756              :                         "accidentally changes the calling convention for %qT",
    4757              :                         t);
    4758            6 :       if (w)
    4759            6 :         inform (location_of (t), " declared here");
    4760            6 :       return;
    4761            6 :     }
    4762              : 
    4763           30 :   auto_diagnostic_group d;
    4764           30 :   if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
    4765              :                   "%<-fabi-version=13%> (GCC 8.2)", t))
    4766           30 :     inform (location_of (t), " because all of its copy and move "
    4767              :             "constructors are deleted");
    4768           30 : }
    4769              : 
    4770              : /* Returns true iff copying an object of type T (including via move
    4771              :    constructor) is non-trivial.  That is, T has no non-trivial copy
    4772              :    constructors and no non-trivial move constructors, and not all copy/move
    4773              :    constructors are deleted.  This function implements the ABI notion of
    4774              :    non-trivial copy, which has diverged from the one in the standard.  */
    4775              : 
    4776              : bool
    4777     63195262 : type_has_nontrivial_copy_init (const_tree type)
    4778              : {
    4779     63195262 :   tree t = strip_array_types (const_cast<tree> (type));
    4780              : 
    4781     63195262 :   if (CLASS_TYPE_P (t))
    4782              :     {
    4783     62591468 :       gcc_assert (COMPLETE_TYPE_P (t));
    4784              : 
    4785     62591468 :       if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
    4786     62591468 :           || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
    4787              :         /* Nontrivial.  */
    4788              :         return true;
    4789              : 
    4790     58542939 :       if (cxx_dialect < cxx11)
    4791              :         /* No deleted functions before C++11.  */
    4792              :         return false;
    4793              : 
    4794              :       /* Before ABI v12 we did a bitwise copy of types with only deleted
    4795              :          copy/move constructors.  */
    4796     58446758 :       if (!abi_version_at_least (12)
    4797         8132 :           && !(warn_abi && abi_version_crosses (12)))
    4798              :         return false;
    4799              : 
    4800     58438856 :       bool saw_copy = false;
    4801     58438856 :       bool saw_non_deleted = false;
    4802     58438856 :       bool saw_non_deleted_move = false;
    4803              : 
    4804     58438856 :       if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    4805              :         saw_copy = saw_non_deleted = true;
    4806      5008491 :       else if (CLASSTYPE_LAZY_COPY_CTOR (t))
    4807              :         {
    4808       667632 :           saw_copy = true;
    4809       667632 :           if (classtype_has_move_assign_or_move_ctor_p (t, true))
    4810              :             /* [class.copy]/8 If the class definition declares a move
    4811              :                constructor or move assignment operator, the implicitly declared
    4812              :                copy constructor is defined as deleted.... */;
    4813              :           else
    4814              :             /* Any other reason the implicitly-declared function would be
    4815              :                deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
    4816              :                set.  */
    4817              :             saw_non_deleted = true;
    4818              :         }
    4819              : 
    4820              :       if (!saw_non_deleted)
    4821     19009265 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    4822              :           {
    4823     11360668 :             tree fn = *iter;
    4824     11360668 :             if (copy_fn_p (fn))
    4825              :               {
    4826      4340900 :                 saw_copy = true;
    4827      4340900 :                 if (!DECL_DELETED_FN (fn))
    4828              :                   {
    4829              :                     /* Not deleted, therefore trivial.  */
    4830              :                     saw_non_deleted = true;
    4831              :                     break;
    4832              :                   }
    4833              :               }
    4834      7019768 :             else if (move_fn_p (fn))
    4835      3004340 :               if (!DECL_DELETED_FN (fn))
    4836      2983362 :                 saw_non_deleted_move = true;
    4837              :           }
    4838              : 
    4839     58438856 :       gcc_assert (saw_copy);
    4840              : 
    4841              :       /* ABI v12 buggily ignored move constructors.  */
    4842     58438856 :       bool v11nontriv = false;
    4843     58438856 :       bool v12nontriv = !saw_non_deleted;
    4844     58438856 :       bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
    4845     58438856 :       bool nontriv = (abi_version_at_least (13) ? v13nontriv
    4846          124 :                       : flag_abi_version == 12 ? v12nontriv
    4847          124 :                       : v11nontriv);
    4848     58439261 :       bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
    4849          405 :                            : warn_abi_version == 12 ? v12nontriv
    4850              :                            : v11nontriv);
    4851     58438856 :       if (nontriv != warn_nontriv)
    4852            9 :         remember_deleted_copy (t);
    4853              : 
    4854     58438856 :       return nontriv;
    4855              :     }
    4856              :   else
    4857              :     return 0;
    4858              : }
    4859              : 
    4860              : /* Returns 1 iff type T is a trivially copyable type, as defined in
    4861              :    [basic.types] and [class].  */
    4862              : 
    4863              : bool
    4864       513108 : trivially_copyable_p (const_tree t)
    4865              : {
    4866       513108 :   t = strip_array_types (const_cast<tree> (t));
    4867              : 
    4868       513108 :   if (CLASS_TYPE_P (t))
    4869        79405 :     return ((!TYPE_HAS_COPY_CTOR (t)
    4870        79405 :              || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
    4871        78492 :             && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
    4872        78458 :             && (!TYPE_HAS_COPY_ASSIGN (t)
    4873        78458 :                 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
    4874        77483 :             && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    4875       156719 :             && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
    4876              :   else
    4877              :     /* CWG 2094 makes volatile-qualified scalars trivially copyable again.  */
    4878       433703 :     return scalarish_type_p (t);
    4879              : }
    4880              : 
    4881              : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
    4882              :    [class].  */
    4883              : 
    4884              : bool
    4885        73513 : trivial_type_p (const_tree t)
    4886              : {
    4887        73513 :   t = strip_array_types (const_cast<tree> (t));
    4888              : 
    4889        73513 :   if (CLASS_TYPE_P (t))
    4890              :     /* A trivial class is a class that is trivially copyable and has one or
    4891              :        more eligible default constructors, all of which are trivial.  */
    4892        19340 :     return (type_has_non_deleted_trivial_default_ctor (const_cast<tree> (t))
    4893        19340 :             && trivially_copyable_p (t));
    4894              :   else
    4895        54173 :     return scalarish_type_p (t);
    4896              : }
    4897              : 
    4898              : /* Returns 1 iff type T is an implicit-lifetime type, as defined in
    4899              :    [basic.types.general] and [class.prop].  */
    4900              : 
    4901              : bool
    4902          741 : implicit_lifetime_type_p (tree t)
    4903              : {
    4904          741 :   if (SCALAR_TYPE_P (t)
    4905          503 :       || (TREE_CODE (t) == ARRAY_TYPE
    4906           76 :           && !(TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))))
    4907              :       /* GNU extension.  */
    4908          431 :       || TREE_CODE (t) == VECTOR_TYPE)
    4909          314 :     return true;
    4910          427 :   if (!CLASS_TYPE_P (t))
    4911              :     return false;
    4912          367 :   t = TYPE_MAIN_VARIANT (t);
    4913          734 :   if (CP_AGGREGATE_TYPE_P (t)
    4914          489 :       && (!CLASSTYPE_DESTRUCTOR (t)
    4915           50 :           || !user_provided_p (CLASSTYPE_DESTRUCTOR (t))))
    4916           99 :     return true;
    4917          268 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    4918              :     return false;
    4919          232 :   if (TYPE_HAS_COMPLEX_DFLT (t)
    4920          116 :       && TYPE_HAS_COMPLEX_COPY_CTOR (t)
    4921          291 :       && TYPE_HAS_COMPLEX_MOVE_CTOR (t))
    4922              :     return false;
    4923          208 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    4924          107 :     lazily_declare_fn (sfk_destructor, t);
    4925          208 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    4926          208 :   if (!fn || DECL_DELETED_FN (fn))
    4927              :     return false;
    4928          273 :   for (ovl_iterator iter (get_class_binding (t, complete_ctor_identifier));
    4929          273 :        iter; ++iter)
    4930              :     {
    4931          259 :       fn = *iter;
    4932          459 :       if ((default_ctor_p (fn) || copy_fn_p (fn) || move_fn_p (fn))
    4933          259 :           && trivial_fn_p (fn)
    4934          453 :           && !DECL_DELETED_FN (fn))
    4935          194 :         return true;
    4936              :     }
    4937           14 :   return false;
    4938              : }
    4939              : 
    4940              : /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
    4941              : 
    4942              : bool
    4943        11186 : pod_type_p (const_tree t)
    4944              : {
    4945              :   /* This CONST_CAST is okay because strip_array_types returns its
    4946              :      argument unmodified and we assign it to a const_tree.  */
    4947        11186 :   t = strip_array_types (const_cast<tree>(t));
    4948              : 
    4949        11186 :   if (!CLASS_TYPE_P (t))
    4950          690 :     return scalarish_type_p (t);
    4951        10496 :   else if (cxx_dialect > cxx98)
    4952              :     /* [class]/10: A POD struct is a class that is both a trivial class and a
    4953              :        standard-layout class, and has no non-static data members of type
    4954              :        non-POD struct, non-POD union (or array of such types).
    4955              : 
    4956              :        We don't need to check individual members because if a member is
    4957              :        non-std-layout or non-trivial, the class will be too.  */
    4958        10219 :     return (std_layout_type_p (t) && trivial_type_p (t));
    4959              :   else
    4960              :     /* The C++98 definition of POD is different.  */
    4961          277 :     return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    4962              : }
    4963              : 
    4964              : /* Returns true iff T is POD for the purpose of layout, as defined in the
    4965              :    C++ ABI.  */
    4966              : 
    4967              : bool
    4968     19620133 : layout_pod_type_p (const_tree t)
    4969              : {
    4970     19620133 :   t = strip_array_types (const_cast<tree> (t));
    4971              : 
    4972     19620133 :   if (CLASS_TYPE_P (t))
    4973      4190419 :     return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    4974              :   else
    4975     15429714 :     return scalarish_type_p (t);
    4976              : }
    4977              : 
    4978              : /* Returns true iff T is a standard-layout type, as defined in
    4979              :    [basic.types].  */
    4980              : 
    4981              : bool
    4982     19689244 : std_layout_type_p (const_tree t)
    4983              : {
    4984     19689244 :   t = strip_array_types (const_cast<tree> (t));
    4985              : 
    4986     19689244 :   if (CLASS_TYPE_P (t))
    4987      4203001 :     return !CLASSTYPE_NON_STD_LAYOUT (t);
    4988              :   else
    4989     15486243 :     return scalarish_type_p (t);
    4990              : }
    4991              : 
    4992              : static bool record_has_unique_obj_representations (const_tree, const_tree, bool);
    4993              : 
    4994              : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
    4995              :    as defined in [meta.unary.prop].  If EXPLAIN is true, explain why not.  */
    4996              : 
    4997              : bool
    4998        66615 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
    4999              : {
    5000        66615 :   bool ret;
    5001              : 
    5002        66615 :   t = strip_array_types (const_cast<tree> (t));
    5003              : 
    5004        66615 :   if (t == error_mark_node)
    5005              :     return false;
    5006              : 
    5007        66612 :   location_t loc = input_location;
    5008        66612 :   if (tree m = TYPE_MAIN_DECL (t))
    5009         9183 :     loc = DECL_SOURCE_LOCATION (m);
    5010              : 
    5011        66612 :   if (!trivially_copyable_p (t))
    5012              :     {
    5013           23 :       if (explain)
    5014            6 :         inform (loc, "%qT is not trivially copyable", t);
    5015           23 :       return false;
    5016              :     }
    5017              : 
    5018          215 :   if (CLASS_TYPE_P (t)
    5019          212 :       && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
    5020        66697 :       && !explain)
    5021           84 :     return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
    5022              : 
    5023        66505 :   switch (TREE_CODE (t))
    5024              :     {
    5025              :     case INTEGER_TYPE:
    5026              :     case POINTER_TYPE:
    5027              :     case REFERENCE_TYPE:
    5028              :       /* If some backend has any paddings in these types, we should add
    5029              :          a target hook for this and handle it there.  */
    5030              :       return true;
    5031              : 
    5032              :     case BOOLEAN_TYPE:
    5033              :       /* For bool values other than 0 and 1 should only appear with
    5034              :          undefined behavior.  */
    5035              :       return true;
    5036              : 
    5037         8953 :     case ENUMERAL_TYPE:
    5038         8953 :       return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
    5039         8953 :                                                   explain);
    5040              : 
    5041        30284 :     case REAL_TYPE:
    5042              :       /* XFmode certainly contains padding on x86, which the CPU doesn't store
    5043              :          when storing long double values, so for that we have to return false.
    5044              :          Other kinds of floating point values are questionable due to +.0/-.0
    5045              :          and NaNs, let's play safe for now.  */
    5046        30284 :       if (explain)
    5047            0 :         inform (loc, "%qT is a floating-point type", t);
    5048              :       return false;
    5049              : 
    5050            0 :     case FIXED_POINT_TYPE:
    5051            0 :       if (explain)
    5052            0 :         inform (loc, "%qT is a fixed-point type", t);
    5053              :       return false;
    5054              : 
    5055              :     case OFFSET_TYPE:
    5056              :       return true;
    5057              : 
    5058           18 :     case COMPLEX_TYPE:
    5059           18 :     case VECTOR_TYPE:
    5060           18 :       return type_has_unique_obj_representations (TREE_TYPE (t), explain);
    5061              : 
    5062          110 :     case RECORD_TYPE:
    5063          110 :       ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
    5064          110 :       if (CLASS_TYPE_P (t))
    5065              :         {
    5066          107 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
    5067          107 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
    5068              :         }
    5069              :       return ret;
    5070              : 
    5071           21 :     case UNION_TYPE:
    5072           21 :       ret = true;
    5073           21 :       bool any_fields;
    5074           21 :       any_fields = false;
    5075           42 :       for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5076           33 :         if (TREE_CODE (field) == FIELD_DECL)
    5077              :           {
    5078           24 :             any_fields = true;
    5079           24 :             if (simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
    5080              :               {
    5081           12 :                 if (explain)
    5082            3 :                   inform (DECL_SOURCE_LOCATION (field),
    5083              :                           "%qD does not fill all bits of %q#T", field, t);
    5084              :                 ret = false;
    5085              :                 break;
    5086              :               }
    5087           12 :             if (!type_has_unique_obj_representations (TREE_TYPE (field)))
    5088              :               {
    5089            0 :                 if (explain)
    5090            0 :                   inform (DECL_SOURCE_LOCATION (field),
    5091              :                           "%qD has type %qT that does not have "
    5092              :                           "unique object representations",
    5093            0 :                           field, TREE_TYPE (field));
    5094              :                 ret = false;
    5095              :                 break;
    5096              :               }
    5097              :           }
    5098            9 :       if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
    5099              :         {
    5100            6 :           if (explain)
    5101            3 :             inform (loc, "%q#T has no data fields", t);
    5102              :           ret = false;
    5103              :         }
    5104           21 :       if (CLASS_TYPE_P (t))
    5105              :         {
    5106           21 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
    5107           21 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
    5108              :         }
    5109              :       return ret;
    5110              : 
    5111            3 :     case NULLPTR_TYPE:
    5112            3 :       if (explain)
    5113            0 :         inform (loc, "%<std::nullptr_t%> has padding bits and no value bits");
    5114              :       return false;
    5115              : 
    5116            0 :     default:
    5117            0 :       gcc_unreachable ();
    5118              :     }
    5119              : }
    5120              : 
    5121              : /* Helper function for type_has_unique_obj_representations.  */
    5122              : 
    5123              : static bool
    5124          121 : record_has_unique_obj_representations (const_tree t, const_tree sz,
    5125              :                                        bool explain)
    5126              : {
    5127          627 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5128          536 :     if (TREE_CODE (field) != FIELD_DECL)
    5129              :       ;
    5130              :     /* For bases, can't use type_has_unique_obj_representations here, as in
    5131              :         struct S { int i : 24; S (); };
    5132              :         struct T : public S { int j : 8; T (); };
    5133              :         S doesn't have unique obj representations, but T does.  */
    5134          174 :     else if (DECL_FIELD_IS_BASE (field))
    5135              :       {
    5136           11 :         if (!record_has_unique_obj_representations (TREE_TYPE (field),
    5137           11 :                                                     DECL_SIZE (field),
    5138              :                                                     /*explain=*/false))
    5139              :           {
    5140            6 :             if (explain)
    5141            3 :               inform (DECL_SOURCE_LOCATION (field),
    5142              :                       "base %qT does not have unique object representations",
    5143            3 :                       TREE_TYPE (field));
    5144            6 :             return false;
    5145              :           }
    5146              :       }
    5147          163 :     else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
    5148              :       {
    5149           58 :         tree btype = DECL_BIT_FIELD_TYPE (field);
    5150           58 :         if (!type_has_unique_obj_representations (btype))
    5151              :           {
    5152            0 :             if (explain)
    5153            0 :               inform (DECL_SOURCE_LOCATION (field),
    5154              :                       "%qD with type %qT does not have "
    5155              :                       "unique object representations",
    5156              :                       field, btype);
    5157            0 :             return false;
    5158              :           }
    5159              :       }
    5160          105 :     else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
    5161              :       {
    5162           24 :         if (explain)
    5163            6 :           inform (DECL_SOURCE_LOCATION (field),
    5164              :                   "%qD with type %qT does not have "
    5165              :                   "unique object representations",
    5166            6 :                   field, TREE_TYPE (field));
    5167           24 :         return false;
    5168              :       }
    5169              : 
    5170           91 :   offset_int cur = 0;
    5171           91 :   tree last_field = NULL_TREE;
    5172           91 :   tree last_named_field = NULL_TREE;
    5173          529 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5174          469 :     if (TREE_CODE (field) == FIELD_DECL)
    5175              :       {
    5176          138 :         if (DECL_UNNAMED_BIT_FIELD (field))
    5177              :           {
    5178           16 :             last_field = field;
    5179           16 :             continue;
    5180              :           }
    5181          122 :         offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
    5182          122 :         offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
    5183          122 :         fld = fld * BITS_PER_UNIT + bitpos;
    5184          122 :         if (cur != fld)
    5185              :           {
    5186           31 :             if (explain)
    5187              :               {
    5188            6 :                 if (last_named_field)
    5189            3 :                   inform (DECL_SOURCE_LOCATION (last_named_field),
    5190              :                           "padding occurs between %qD and %qD",
    5191              :                           last_named_field, field);
    5192            3 :                 else if (last_field)
    5193            3 :                   inform (DECL_SOURCE_LOCATION (last_field),
    5194              :                           "unnamed bit-field inserts padding before %qD",
    5195              :                           field);
    5196              :                 else
    5197            0 :                   inform (DECL_SOURCE_LOCATION (field),
    5198              :                           "padding occurs before %qD", field);
    5199              :               }
    5200           31 :             return false;
    5201              :           }
    5202           91 :         if (DECL_SIZE (field))
    5203              :           {
    5204           88 :             offset_int size = wi::to_offset (DECL_SIZE (field));
    5205           88 :             cur += size;
    5206              :           }
    5207           91 :         last_named_field = last_field = field;
    5208              :       }
    5209           60 :   if (cur != wi::to_offset (sz))
    5210              :     {
    5211           25 :       if (explain)
    5212              :         {
    5213            3 :           if (last_named_field)
    5214            3 :             inform (DECL_SOURCE_LOCATION (last_named_field),
    5215              :                     "padding occurs after %qD", last_named_field);
    5216              :           else
    5217            0 :             inform (DECL_SOURCE_LOCATION (t),
    5218              :                     "%qT has padding and no data fields", t);
    5219              :         }
    5220           25 :       return false;
    5221              :     }
    5222              : 
    5223              :   return true;
    5224              : }
    5225              : 
    5226              : /* Nonzero iff type T is a class template implicit specialization.  */
    5227              : 
    5228              : bool
    5229    150087112 : class_tmpl_impl_spec_p (const_tree t)
    5230              : {
    5231    150087112 :   return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
    5232              : }
    5233              : 
    5234              : /* Returns 1 iff zero initialization of type T means actually storing
    5235              :    zeros in it.  */
    5236              : 
    5237              : int
    5238     23876929 : zero_init_p (const_tree t)
    5239              : {
    5240              :   /* This CONST_CAST is okay because strip_array_types returns its
    5241              :      argument unmodified and we assign it to a const_tree.  */
    5242     23876929 :   t = strip_array_types (const_cast<tree> (t));
    5243              : 
    5244     23876929 :   if (t == error_mark_node)
    5245              :     return 1;
    5246              : 
    5247              :   /* NULL pointers to data members are initialized with -1.  */
    5248     23876929 :   if (TYPE_PTRDATAMEM_P (t))
    5249              :     return 0;
    5250              : 
    5251              :   /* Classes that contain types that can't be zero-initialized, cannot
    5252              :      be zero-initialized themselves.  */
    5253     23876327 :   if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
    5254          148 :     return 0;
    5255              : 
    5256              :   return 1;
    5257              : }
    5258              : 
    5259              : /* Returns true if the expression or initializer T is the result of
    5260              :    zero-initialization for its type, taking pointers to members
    5261              :    into consideration.  */
    5262              : 
    5263              : bool
    5264       325108 : zero_init_expr_p (tree t)
    5265              : {
    5266       325108 :   tree type = TREE_TYPE (t);
    5267       325108 :   if (!type || uses_template_parms (type))
    5268            0 :     return false;
    5269       325108 :   if (TYPE_PTRMEM_P (type))
    5270         1251 :     return null_member_pointer_value_p (t);
    5271       323857 :   if (TREE_CODE (t) == CONSTRUCTOR)
    5272              :     {
    5273       136060 :       if (COMPOUND_LITERAL_P (t)
    5274       136060 :           || BRACE_ENCLOSED_INITIALIZER_P (t))
    5275              :         /* Undigested, conversions might change the zeroness.  */
    5276              :         return false;
    5277       406042 :       for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
    5278              :         {
    5279       135629 :           if (TREE_CODE (type) == UNION_TYPE
    5280       135629 :               && elt.index != first_field (type))
    5281              :             return false;
    5282       135620 :           if (!zero_init_expr_p (elt.value))
    5283              :             return false;
    5284              :         }
    5285              :       return true;
    5286              :     }
    5287       187797 :   if (zero_init_p (type))
    5288       187797 :     return initializer_zerop (t);
    5289              :   return false;
    5290              : }
    5291              : 
    5292              : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
    5293              :    non-type template parameter.  If EXPLAIN, explain why not.  */
    5294              : 
    5295              : bool
    5296        23472 : structural_type_p (tree t, bool explain)
    5297              : {
    5298              :   /* A structural type is one of the following: */
    5299              : 
    5300              :   /* a scalar type, or */
    5301        23472 :   if (SCALAR_TYPE_P (t))
    5302              :     return true;
    5303              :   /* an lvalue reference type, or */
    5304        12325 :   if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
    5305              :     return true;
    5306              :   /* a literal class type with the following properties:
    5307              :      - all base classes and non-static data members are public and non-mutable
    5308              :        and
    5309              :      - the types of all bases classes and non-static data members are
    5310              :        structural types or (possibly multi-dimensional) array thereof.  */
    5311        12281 :   if (!CLASS_TYPE_P (t))
    5312              :     return false;
    5313        12277 :   if (!literal_type_p (t))
    5314              :     {
    5315           18 :       if (explain)
    5316            8 :         explain_non_literal_class (t);
    5317           18 :       return false;
    5318              :     }
    5319        22581 :   for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
    5320        10322 :        m = next_aggregate_field (DECL_CHAIN (m)))
    5321              :     {
    5322        10507 :       if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
    5323              :         {
    5324          137 :           if (explain)
    5325              :             {
    5326           50 :               if (DECL_FIELD_IS_BASE (m))
    5327            3 :                 inform (location_of (m), "base class %qT is not public",
    5328            3 :                         TREE_TYPE (m));
    5329              :               else
    5330           47 :                 inform (location_of (m), "%qD is not public", m);
    5331              :             }
    5332          137 :           return false;
    5333              :         }
    5334        10370 :       if (DECL_MUTABLE_P (m))
    5335              :         {
    5336           12 :           if (explain)
    5337            3 :             inform (location_of (m), "%qD is mutable", m);
    5338           12 :           return false;
    5339              :         }
    5340        10358 :       tree mtype = strip_array_types (TREE_TYPE (m));
    5341        10358 :       if (!structural_type_p (mtype))
    5342              :         {
    5343           36 :           if (explain)
    5344              :             {
    5345            1 :               inform (location_of (m), "%qD has a non-structural type", m);
    5346            1 :               structural_type_p (mtype, true);
    5347              :             }
    5348           36 :           return false;
    5349              :         }
    5350              :     }
    5351              :   return true;
    5352              : }
    5353              : 
    5354              : /* Partially handle the C++11 [[carries_dependency]] attribute.
    5355              :    Just emit a different diagnostics when it is used on something the
    5356              :    spec doesn't allow vs. where it allows and we just choose to ignore
    5357              :    it.  */
    5358              : 
    5359              : static tree
    5360          142 : handle_carries_dependency_attribute (tree *node, tree name,
    5361              :                                      tree ARG_UNUSED (args),
    5362              :                                      int ARG_UNUSED (flags),
    5363              :                                      bool *no_add_attrs)
    5364              : {
    5365          142 :   if (TREE_CODE (*node) != FUNCTION_DECL
    5366          121 :       && TREE_CODE (*node) != PARM_DECL)
    5367              :     {
    5368           76 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5369              :                "functions or parameters", name);
    5370           76 :       *no_add_attrs = true;
    5371              :     }
    5372              :   else
    5373              :     {
    5374           66 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5375           66 :       *no_add_attrs = true;
    5376              :     }
    5377          142 :   return NULL_TREE;
    5378              : }
    5379              : 
    5380              : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
    5381              :    warn_unused_result attribute.  */
    5382              : 
    5383              : static tree
    5384     12748987 : handle_nodiscard_attribute (tree *node, tree name, tree args,
    5385              :                             int /*flags*/, bool *no_add_attrs)
    5386              : {
    5387     12749132 :   if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    5388              :     {
    5389            6 :       error ("%qE attribute argument must be a string constant", name);
    5390            6 :       *no_add_attrs = true;
    5391              :     }
    5392     12748987 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    5393              :     {
    5394     12748718 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
    5395     12847778 :           && !DECL_CONSTRUCTOR_P (*node))
    5396            9 :         warning_at (DECL_SOURCE_LOCATION (*node),
    5397            9 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    5398              :                     "return type", name, *node);
    5399              :     }
    5400          269 :   else if (OVERLOAD_TYPE_P (*node))
    5401              :     /* OK */;
    5402              :   else
    5403              :     {
    5404          148 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5405              :                "functions or to class or enumeration types", name);
    5406          148 :       *no_add_attrs = true;
    5407              :     }
    5408     12748987 :   return NULL_TREE;
    5409              : }
    5410              : 
    5411              : /* Handle a C++20 "no_unique_address" attribute; arguments as in
    5412              :    struct attribute_spec.handler.  */
    5413              : static tree
    5414       650109 : handle_no_unique_addr_attribute (tree* node,
    5415              :                                  tree name,
    5416              :                                  tree /*args*/,
    5417              :                                  int /*flags*/,
    5418              :                                  bool* no_add_attrs)
    5419              : {
    5420       650109 :   if (TREE_CODE (*node) == VAR_DECL)
    5421              :     {
    5422           48 :       DECL_MERGEABLE (*node) = true;
    5423           48 :       if (pedantic)
    5424           42 :         warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5425              :                  "non-static data members", name);
    5426              :     }
    5427       650061 :   else if (TREE_CODE (*node) != FIELD_DECL)
    5428              :     {
    5429           82 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5430              :                "non-static data members", name);
    5431           82 :       *no_add_attrs = true;
    5432              :     }
    5433       649979 :   else if (DECL_C_BIT_FIELD (*node))
    5434              :     {
    5435            6 :       warning (OPT_Wattributes, "%qE attribute cannot be applied to "
    5436              :                "a bit-field", name);
    5437            6 :       *no_add_attrs = true;
    5438              :     }
    5439              : 
    5440       650109 :   return NULL_TREE;
    5441              : }
    5442              : 
    5443              : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
    5444              :    hot/cold attributes.  */
    5445              : 
    5446              : static tree
    5447          392 : handle_likeliness_attribute (tree *node, tree name, tree args,
    5448              :                              int flags, bool *no_add_attrs)
    5449              : {
    5450          392 :   *no_add_attrs = true;
    5451          392 :   if (TREE_CODE (*node) == LABEL_DECL
    5452          392 :       || TREE_CODE (*node) == FUNCTION_DECL)
    5453              :     {
    5454           90 :       if (args)
    5455            0 :         warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
    5456           90 :       tree bname = (is_attribute_p ("likely", name)
    5457           90 :                     ? get_identifier ("hot") : get_identifier ("cold"));
    5458           90 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5459           33 :         warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
    5460              :                  "functions; treating as %<[[gnu::%E]]%>", name, bname);
    5461           90 :       tree battr = build_tree_list (bname, NULL_TREE);
    5462           90 :       decl_attributes (node, battr, flags);
    5463           90 :       return NULL_TREE;
    5464              :     }
    5465              :   else
    5466          302 :     return error_mark_node;
    5467              : }
    5468              : 
    5469              : /* The C++11 alignment specifier.  It mostly maps to GNU aligned attribute,
    5470              :    but we need to do some extra pedantic checking.  */
    5471              : 
    5472              : static tree
    5473       299601 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
    5474              :                           bool *no_add_attrs)
    5475              : {
    5476       299601 :   tree t = *node;
    5477       299601 :   tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
    5478       299601 :   if (pedantic)
    5479              :     {
    5480         1216 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5481           15 :         pedwarn (input_location, OPT_Wattributes,
    5482              :                  "%<alignas%> on function declaration");
    5483         1201 :       else if (TREE_CODE (*node) == ENUMERAL_TYPE)
    5484            9 :         pedwarn (input_location, OPT_Wattributes,
    5485              :                  "%<alignas%> on enumerated type");
    5486         1192 :       else if (TYPE_P (*node) && t != *node)
    5487           56 :         pedwarn (input_location, OPT_Wattributes,
    5488              :                  "%<alignas%> on a type other than class");
    5489         1136 :       else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
    5490            9 :         pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
    5491         1127 :       else if (TREE_CODE (t) == TYPE_DECL)
    5492            9 :         pedwarn (input_location, OPT_Wattributes,
    5493              :                  "%<alignas%> on a type alias");
    5494              :     }
    5495       299601 :   return ret;
    5496              : }
    5497              : 
    5498              : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
    5499              :    attribute.  */
    5500              : 
    5501              : static tree
    5502       137934 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
    5503              :                                  bool *no_add_attrs)
    5504              : {
    5505       137934 :   tree t = *node;
    5506       137934 :   tree ret = handle_deprecated_attribute (node, name, args, flags,
    5507              :                                           no_add_attrs);
    5508       137934 :   if (TYPE_P (*node) && t != *node)
    5509           48 :     pedwarn (input_location, OPT_Wattributes,
    5510              :              "%qE on a type other than class or enumeration definition", name);
    5511       137886 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5512            4 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5513              :              name);
    5514       137934 :   return ret;
    5515              : }
    5516              : 
    5517              : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
    5518              :    attribute.  */
    5519              : 
    5520              : static tree
    5521        95973 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
    5522              :                                bool *no_add_attrs)
    5523              : {
    5524        95973 :   tree t = *node;
    5525        95973 :   tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
    5526        95973 :   if (TYPE_P (*node) && t != *node)
    5527           36 :     pedwarn (input_location, OPT_Wattributes,
    5528              :              "%qE on a type other than class or enumeration definition", name);
    5529        95937 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5530            3 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5531              :              name);
    5532        95934 :   else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
    5533            6 :     pedwarn (input_location, OPT_Wattributes,
    5534              :              "%qE on %<case%> or %<default%> label", name);
    5535        95973 :   return ret;
    5536              : }
    5537              : 
    5538              : /* The C++26 [[indeterminate]] attribute.  */
    5539              : 
    5540              : static tree
    5541          231 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
    5542              :                                 bool *no_add_attrs)
    5543              : {
    5544          231 :   if (TREE_CODE (*node) != PARM_DECL
    5545          231 :       && (!VAR_P (*node) || is_global_var (*node)))
    5546              :     {
    5547           67 :       pedwarn (input_location, OPT_Wattributes,
    5548              :                "%qE on declaration other than parameter or automatic variable",
    5549              :                name);
    5550           67 :       *no_add_attrs = true;
    5551              :     }
    5552          231 :   return NULL_TREE;
    5553              : }
    5554              : 
    5555              : /* Table of valid C++ attributes.  */
    5556              : static const attribute_spec cxx_gnu_attributes[] =
    5557              : {
    5558              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5559              :        affects_type_identity, handler, exclude } */
    5560              :   { "init_priority",  1, 1, true,  false, false, false,
    5561              :     handle_init_priority_attribute, NULL },
    5562              :   { "abi_tag", 1, -1, false, false, false, true,
    5563              :     handle_abi_tag_attribute, NULL },
    5564              :   { "no_dangling", 0, 1, false, true, false, false,
    5565              :     handle_no_dangling_attribute, NULL },
    5566              : };
    5567              : 
    5568              : const scoped_attribute_specs cxx_gnu_attribute_table =
    5569              : {
    5570              :   "gnu", { cxx_gnu_attributes }
    5571              : };
    5572              : 
    5573              : /* Table of C++ standard attributes.  */
    5574              : static const attribute_spec std_attributes[] =
    5575              : {
    5576              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5577              :        affects_type_identity, handler, exclude } */
    5578              :   { "deprecated", 0, 1, false, false, false, false,
    5579              :     handle_std_deprecated_attribute, NULL },
    5580              :   { "maybe_unused", 0, 0, false, false, false, false,
    5581              :     handle_maybe_unused_attribute, NULL },
    5582              :   { "nodiscard", 0, 1, false, false, false, false,
    5583              :     handle_nodiscard_attribute, NULL },
    5584              :   { "no_unique_address", 0, 0, true, false, false, false,
    5585              :     handle_no_unique_addr_attribute, NULL },
    5586              :   { "likely", 0, 0, false, false, false, false,
    5587              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5588              :   { "unlikely", 0, 0, false, false, false, false,
    5589              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5590              :   { "noreturn", 0, 0, true, false, false, false,
    5591              :     handle_noreturn_attribute, attr_noreturn_exclusions },
    5592              :   { "carries_dependency", 0, 0, true, false, false, false,
    5593              :     handle_carries_dependency_attribute, NULL },
    5594              :   { "indeterminate", 0, 0, true, false, false, false,
    5595              :     handle_indeterminate_attribute, NULL },
    5596              : };
    5597              : 
    5598              : const scoped_attribute_specs std_attribute_table =
    5599              : {
    5600              :   nullptr, { std_attributes }
    5601              : };
    5602              : 
    5603              : /* Table of internal attributes.  */
    5604              : static const attribute_spec internal_attributes[] =
    5605              : {
    5606              :   { "aligned", 0, 1, false, false, false, false,
    5607              :     handle_alignas_attribute, attr_aligned_exclusions },
    5608              :   { "annotation ", 1, 1, false, false, false, false,
    5609              :     handle_annotation_attribute, NULL }
    5610              : };
    5611              : 
    5612              : const scoped_attribute_specs internal_attribute_table =
    5613              : {
    5614              :   "internal ", { internal_attributes }
    5615              : };
    5616              : 
    5617              : /* Handle an "init_priority" attribute; arguments as in
    5618              :    struct attribute_spec.handler.  */
    5619              : static tree
    5620           35 : handle_init_priority_attribute (tree* node,
    5621              :                                 tree name,
    5622              :                                 tree args,
    5623              :                                 int /*flags*/,
    5624              :                                 bool* no_add_attrs)
    5625              : {
    5626           35 :   if (!SUPPORTS_INIT_PRIORITY)
    5627              :     /* Treat init_priority as an unrecognized attribute (mirroring
    5628              :        __has_attribute) if the target doesn't support init priorities.  */
    5629              :     return error_mark_node;
    5630              : 
    5631           35 :   tree initp_expr = TREE_VALUE (args);
    5632           35 :   tree decl = *node;
    5633           35 :   tree type = TREE_TYPE (decl);
    5634           35 :   int pri;
    5635              : 
    5636           35 :   STRIP_NOPS (initp_expr);
    5637           35 :   initp_expr = default_conversion (initp_expr);
    5638           35 :   if (initp_expr)
    5639           35 :     initp_expr = maybe_constant_value (initp_expr);
    5640              : 
    5641           35 :   if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
    5642              :     {
    5643            0 :       error ("requested %<init_priority%> is not an integer constant");
    5644            0 :       cxx_constant_value (initp_expr);
    5645            0 :       *no_add_attrs = true;
    5646            0 :       return NULL_TREE;
    5647              :     }
    5648              : 
    5649           35 :   pri = TREE_INT_CST_LOW (initp_expr);
    5650              : 
    5651           35 :   type = strip_array_types (type);
    5652              : 
    5653           35 :   if (decl == NULL_TREE
    5654           35 :       || !VAR_P (decl)
    5655           35 :       || !TREE_STATIC (decl)
    5656           35 :       || DECL_EXTERNAL (decl)
    5657           35 :       || (TREE_CODE (type) != RECORD_TYPE
    5658           35 :           && TREE_CODE (type) != UNION_TYPE)
    5659              :       /* Static objects in functions are initialized the
    5660              :          first time control passes through that
    5661              :          function. This is not precise enough to pin down an
    5662              :          init_priority value, so don't allow it.  */
    5663           70 :       || current_function_decl)
    5664              :     {
    5665            0 :       error ("can only use %qE attribute on file-scope definitions "
    5666              :              "of objects of class type", name);
    5667            0 :       *no_add_attrs = true;
    5668            0 :       return NULL_TREE;
    5669              :     }
    5670              : 
    5671           35 :   if (pri > MAX_INIT_PRIORITY || pri <= 0)
    5672              :     {
    5673            0 :       error ("requested %<init_priority%> %i is out of range [0, %i]",
    5674              :              pri, MAX_INIT_PRIORITY);
    5675            0 :       *no_add_attrs = true;
    5676            0 :       return NULL_TREE;
    5677              :     }
    5678              : 
    5679              :   /* Check for init_priorities that are reserved for
    5680              :      language and runtime support implementations.*/
    5681           35 :   if (pri <= MAX_RESERVED_INIT_PRIORITY
    5682           35 :       && !in_system_header_at (input_location))
    5683              :     {
    5684           10 :       warning
    5685           10 :         (OPT_Wprio_ctor_dtor,
    5686              :          "requested %<init_priority%> %i is reserved for internal use",
    5687              :          pri);
    5688              :     }
    5689              : 
    5690           35 :   SET_DECL_INIT_PRIORITY (decl, pri);
    5691           35 :   DECL_HAS_INIT_PRIORITY_P (decl) = 1;
    5692           35 :   return NULL_TREE;
    5693              : }
    5694              : 
    5695              : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
    5696              :    and the new one has the tags in NEW_.  Give an error if there are tags
    5697              :    in NEW_ that weren't in OLD.  */
    5698              : 
    5699              : bool
    5700     10925471 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
    5701              : {
    5702     10992332 :   if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
    5703              :     old = TREE_VALUE (old);
    5704     10947069 :   if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
    5705              :     new_ = TREE_VALUE (new_);
    5706     10925471 :   bool err = false;
    5707     10925471 :   auto_diagnostic_group d;
    5708     10947069 :   for (const_tree t = new_; t; t = TREE_CHAIN (t))
    5709              :     {
    5710        21598 :       tree str = TREE_VALUE (t);
    5711        21598 :       for (const_tree in = old; in; in = TREE_CHAIN (in))
    5712              :         {
    5713        21589 :           tree ostr = TREE_VALUE (in);
    5714        21589 :           if (cp_tree_equal (str, ostr))
    5715        21589 :             goto found;
    5716              :         }
    5717            9 :       error ("redeclaration of %qD adds abi tag %qE", decl, str);
    5718            9 :       err = true;
    5719        21598 :     found:;
    5720              :     }
    5721     10925471 :   if (err)
    5722              :     {
    5723            9 :       inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
    5724            9 :       return false;
    5725              :     }
    5726              :   return true;
    5727     10925471 : }
    5728              : 
    5729              : /* The abi_tag attribute with the name NAME was given ARGS.  If they are
    5730              :    ill-formed, give an error and return false; otherwise, return true.  */
    5731              : 
    5732              : bool
    5733       419425 : check_abi_tag_args (tree args, tree name)
    5734              : {
    5735       419425 :   if (!args)
    5736              :     {
    5737            0 :       error ("the %qE attribute requires arguments", name);
    5738            0 :       return false;
    5739              :     }
    5740       838889 :   for (tree arg = args; arg; arg = TREE_CHAIN (arg))
    5741              :     {
    5742       419476 :       tree elt = TREE_VALUE (arg);
    5743       419476 :       if (TREE_CODE (elt) != STRING_CST
    5744       838946 :           || (!same_type_ignoring_top_level_qualifiers_p
    5745       419470 :               (strip_array_types (TREE_TYPE (elt)),
    5746              :                char_type_node)))
    5747              :         {
    5748            9 :           error ("arguments to the %qE attribute must be narrow string "
    5749              :                  "literals", name);
    5750            9 :           return false;
    5751              :         }
    5752       419467 :       const char *begin = TREE_STRING_POINTER (elt);
    5753       419467 :       const char *end = begin + TREE_STRING_LENGTH (elt);
    5754      2990205 :       for (const char *p = begin; p != end; ++p)
    5755              :         {
    5756      2570741 :           char c = *p;
    5757      2570741 :           if (p == begin)
    5758              :             {
    5759       419467 :               if (!ISALPHA (c) && c != '_')
    5760              :                 {
    5761            3 :                   auto_diagnostic_group d;
    5762            3 :                   error ("arguments to the %qE attribute must contain valid "
    5763              :                          "identifiers", name);
    5764            3 :                   inform (input_location, "%<%c%> is not a valid first "
    5765              :                           "character for an identifier", c);
    5766            3 :                   return false;
    5767            3 :                 }
    5768              :             }
    5769      2151274 :           else if (p == end - 1)
    5770       419464 :             gcc_assert (c == 0);
    5771              :           else
    5772              :             {
    5773      1731810 :               if (!ISALNUM (c) && c != '_')
    5774              :                 {
    5775            0 :                   auto_diagnostic_group d;
    5776            0 :                   error ("arguments to the %qE attribute must contain valid "
    5777              :                          "identifiers", name);
    5778            0 :                   inform (input_location, "%<%c%> is not a valid character "
    5779              :                           "in an identifier", c);
    5780            0 :                   return false;
    5781            0 :                 }
    5782              :             }
    5783              :         }
    5784              :     }
    5785              :   return true;
    5786              : }
    5787              : 
    5788              : /* Handle an "abi_tag" attribute; arguments as in
    5789              :    struct attribute_spec.handler.  */
    5790              : 
    5791              : static tree
    5792       373231 : handle_abi_tag_attribute (tree* node, tree name, tree args,
    5793              :                           int flags, bool* no_add_attrs)
    5794              : {
    5795       373231 :   if (!check_abi_tag_args (args, name))
    5796           12 :     goto fail;
    5797              : 
    5798       373219 :   if (TYPE_P (*node))
    5799              :     {
    5800        11037 :       if (!OVERLOAD_TYPE_P (*node))
    5801              :         {
    5802            0 :           error ("%qE attribute applied to non-class, non-enum type %qT",
    5803              :                  name, *node);
    5804            0 :           goto fail;
    5805              :         }
    5806        11037 :       else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
    5807              :         {
    5808            0 :           error ("%qE attribute applied to %qT after its definition",
    5809              :                  name, *node);
    5810            0 :           goto fail;
    5811              :         }
    5812        11034 :       else if (CLASS_TYPE_P (*node)
    5813        22071 :                && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
    5814              :         {
    5815            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5816              :                    "template instantiation %qT", name, *node);
    5817            3 :           goto fail;
    5818              :         }
    5819        11031 :       else if (CLASS_TYPE_P (*node)
    5820        22065 :                && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
    5821              :         {
    5822            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5823              :                    "template specialization %qT", name, *node);
    5824            3 :           goto fail;
    5825              :         }
    5826              : 
    5827        11031 :       tree attributes = TYPE_ATTRIBUTES (*node);
    5828        11031 :       tree decl = TYPE_NAME (*node);
    5829              : 
    5830              :       /* Make sure all declarations have the same abi tags.  */
    5831        11031 :       if (DECL_SOURCE_LOCATION (decl) != input_location)
    5832              :         {
    5833            6 :           if (!check_abi_tag_redeclaration (decl,
    5834            6 :                                             lookup_attribute ("abi_tag",
    5835              :                                                               attributes),
    5836              :                                             args))
    5837            6 :             goto fail;
    5838              :         }
    5839              :     }
    5840              :   else
    5841              :     {
    5842       362182 :       if (!VAR_OR_FUNCTION_DECL_P (*node))
    5843              :         {
    5844            0 :           error ("%qE attribute applied to non-function, non-variable %qD",
    5845              :                  name, *node);
    5846            0 :           goto fail;
    5847              :         }
    5848       362182 :       else if (DECL_LANGUAGE (*node) == lang_c)
    5849              :         {
    5850            0 :           error ("%qE attribute applied to extern \"C\" declaration %qD",
    5851              :                  name, *node);
    5852            0 :           goto fail;
    5853              :         }
    5854              :     }
    5855              : 
    5856              :   return NULL_TREE;
    5857              : 
    5858           24 :  fail:
    5859           24 :   *no_add_attrs = true;
    5860           24 :   return NULL_TREE;
    5861              : }
    5862              : 
    5863              : /* Handle a "no_dangling" attribute; arguments as in
    5864              :    struct attribute_spec.handler.  */
    5865              : 
    5866              : tree
    5867           96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
    5868              :                               bool *no_add_attrs)
    5869              : {
    5870          147 :   if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
    5871              :     {
    5872            3 :       error ("%qE attribute argument must be an expression that evaluates "
    5873              :              "to true or false", name);
    5874            3 :       *no_add_attrs = true;
    5875              :     }
    5876           93 :   else if (!FUNC_OR_METHOD_TYPE_P (*node)
    5877           51 :            && !RECORD_OR_UNION_TYPE_P (*node))
    5878              :     {
    5879           18 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5880           18 :       *no_add_attrs = true;
    5881              :     }
    5882              : 
    5883           96 :   return NULL_TREE;
    5884              : }
    5885              : 
    5886              : /* Perform checking for annotations.  */
    5887              : 
    5888              : tree
    5889          329 : handle_annotation_attribute (tree *node, tree ARG_UNUSED (name),
    5890              :                              tree args, int ARG_UNUSED (flags),
    5891              :                              bool *no_add_attrs)
    5892              : {
    5893          329 :   if (TYPE_P (*node)
    5894           46 :       && TREE_CODE (*node) != ENUMERAL_TYPE
    5895           42 :       && TREE_CODE (*node) != RECORD_TYPE
    5896           12 :       && TREE_CODE (*node) != UNION_TYPE)
    5897              :     {
    5898           12 :       error ("annotation on a type other than class or enumeration "
    5899              :              "definition");
    5900           12 :       *no_add_attrs = true;
    5901           12 :       return NULL_TREE;
    5902              :     }
    5903          317 :   if (TREE_CODE (*node) == LABEL_DECL)
    5904              :     {
    5905            3 :       error ("annotation applied to a label");
    5906            3 :       *no_add_attrs = true;
    5907            3 :       return NULL_TREE;
    5908              :     }
    5909          314 :   if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5910              :     {
    5911            1 :       error ("annotation on unnamed bit-field");
    5912            1 :       *no_add_attrs = true;
    5913            1 :       return NULL_TREE;
    5914              :     }
    5915          313 :   if (!type_dependent_expression_p (TREE_VALUE (args)))
    5916              :     {
    5917          313 :       if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
    5918              :         {
    5919           51 :           auto_diagnostic_group d;
    5920           51 :           error ("annotation does not have structural type");
    5921           51 :           structural_type_p (TREE_TYPE (TREE_VALUE (args)), true);
    5922           51 :           *no_add_attrs = true;
    5923           51 :           return NULL_TREE;
    5924           51 :         }
    5925          262 :       if (CLASS_TYPE_P (TREE_TYPE (TREE_VALUE (args))))
    5926              :         {
    5927           30 :           tree arg = make_tree_vec (1);
    5928           30 :           tree type = TREE_TYPE (TREE_VALUE (args));
    5929           30 :           TREE_VEC_ELT (arg, 0)
    5930           30 :             = build_stub_type (type, cp_type_quals (type) | TYPE_QUAL_CONST,
    5931              :                                /*rvalue=*/false);
    5932           30 :           if (!is_xible (INIT_EXPR, type, arg))
    5933              :             {
    5934            2 :               auto_diagnostic_group d;
    5935            2 :               error ("annotation does not have copy constructible type");
    5936            2 :               is_xible (INIT_EXPR, type, arg, /*explain=*/true);
    5937            2 :               *no_add_attrs = true;
    5938            2 :               return NULL_TREE;
    5939            2 :             }
    5940              :         }
    5941              :     }
    5942          260 :   if (!processing_template_decl)
    5943              :     {
    5944          256 :       location_t loc = EXPR_LOCATION (TREE_VALUE (args));
    5945          256 :       TREE_VALUE (args) = cxx_constant_value (TREE_VALUE (args));
    5946          256 :       if (error_operand_p (TREE_VALUE (args)))
    5947            2 :         *no_add_attrs = true;
    5948          256 :       auto suppression
    5949          256 :         = make_temp_override (suppress_location_wrappers, 0);
    5950          256 :       TREE_VALUE (args) = maybe_wrap_with_location (TREE_VALUE (args), loc);
    5951          256 :     }
    5952          260 :   ATTR_UNIQUE_VALUE_P (args) = 1;
    5953          260 :   return NULL_TREE;
    5954              : }
    5955              : 
    5956              : /* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
    5957              :    thing pointed to by the constant.  */
    5958              : 
    5959              : tree
    5960        61526 : make_ptrmem_cst (tree type, tree member)
    5961              : {
    5962        61526 :   tree ptrmem_cst = make_node (PTRMEM_CST);
    5963        61526 :   TREE_TYPE (ptrmem_cst) = type;
    5964        61526 :   PTRMEM_CST_MEMBER (ptrmem_cst) = member;
    5965        61526 :   PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
    5966        61526 :   return ptrmem_cst;
    5967              : }
    5968              : 
    5969              : /* Build a variant of TYPE that has the indicated ATTRIBUTES.  May
    5970              :    return an existing type if an appropriate type already exists.  */
    5971              : 
    5972              : tree
    5973     15969670 : cp_build_type_attribute_variant (tree type, tree attributes)
    5974              : {
    5975     15969670 :   tree new_type;
    5976              : 
    5977     15969670 :   new_type = build_type_attribute_variant (type, attributes);
    5978     15969670 :   if (FUNC_OR_METHOD_TYPE_P (new_type))
    5979     15899797 :     gcc_checking_assert (cxx_type_hash_eq (type, new_type));
    5980              : 
    5981              :   /* Making a new main variant of a class type is broken.  */
    5982     15969670 :   gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
    5983              : 
    5984     15969670 :   return new_type;
    5985              : }
    5986              : 
    5987              : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
    5988              :    Called only after doing all language independent checks.  */
    5989              : 
    5990              : bool
    5991    334054362 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
    5992              : {
    5993    334054362 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
    5994              : 
    5995    334054362 :   if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
    5996              :     return false;
    5997    334049324 :   if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
    5998              :     return false;
    5999    334048356 :   return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
    6000    668096712 :                             TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
    6001              : }
    6002              : 
    6003              : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA.  For
    6004              :    C++, these are the exception-specifier and ref-qualifier.  */
    6005              : 
    6006              : tree
    6007     26828970 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
    6008              : {
    6009     26828970 :   tree type = const_cast<tree> (typea);
    6010     26828970 :   if (FUNC_OR_METHOD_TYPE_P (type))
    6011     26828065 :     type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
    6012     26828065 :                                     TYPE_RAISES_EXCEPTIONS (typeb),
    6013     26828065 :                                     TYPE_HAS_LATE_RETURN_TYPE (typeb));
    6014     26828970 :   return type;
    6015              : }
    6016              : 
    6017              : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
    6018              :    traversal.  Called from walk_tree.  */
    6019              : 
    6020              : tree
    6021  25239124719 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
    6022              :                   void *data, hash_set<tree> *pset)
    6023              : {
    6024  25239124719 :   tree t = *tp;
    6025  25239124719 :   enum tree_code code = TREE_CODE (t);
    6026  25239124719 :   tree result;
    6027              : 
    6028              : #define WALK_SUBTREE(NODE)                              \
    6029              :   do                                                    \
    6030              :     {                                                   \
    6031              :       result = cp_walk_tree (&(NODE), func, data, pset);    \
    6032              :       if (result) goto out;                             \
    6033              :     }                                                   \
    6034              :   while (0)
    6035              : 
    6036  25239124719 :   if (TYPE_P (t))
    6037              :     {
    6038              :       /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
    6039              :          the argument, so don't look through typedefs, but do walk into
    6040              :          template arguments for alias templates (and non-typedefed classes).
    6041              : 
    6042              :          If *WALK_SUBTREES_P > 1, we're interested in type identity or
    6043              :          equivalence, so look through typedefs, ignoring template arguments for
    6044              :          alias templates, and walk into template args of classes.
    6045              : 
    6046              :          See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
    6047              :          when that's the behavior the walk_tree_fn wants.  */
    6048   6789222807 :       if (*walk_subtrees_p == 1 && typedef_variant_p (t))
    6049              :         {
    6050     24244119 :           if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
    6051     16592432 :             WALK_SUBTREE (TI_ARGS (ti));
    6052     24205498 :           *walk_subtrees_p = 0;
    6053     24205498 :           return NULL_TREE;
    6054              :         }
    6055              : 
    6056   6764978688 :       if (tree ti = TYPE_TEMPLATE_INFO (t))
    6057    605736039 :         WALK_SUBTREE (TI_ARGS (ti));
    6058              :     }
    6059              : 
    6060              :   /* Not one of the easy cases.  We must explicitly go through the
    6061              :      children.  */
    6062  25214707850 :   result = NULL_TREE;
    6063  25214707850 :   switch (code)
    6064              :     {
    6065   1759053889 :     case TEMPLATE_TYPE_PARM:
    6066   1759053889 :       if (template_placeholder_p (t))
    6067      1557438 :         WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
    6068              :       /* Fall through.  */
    6069   1898522806 :     case DEFERRED_PARSE:
    6070   1898522806 :     case TEMPLATE_TEMPLATE_PARM:
    6071   1898522806 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    6072   1898522806 :     case UNBOUND_CLASS_TEMPLATE:
    6073   1898522806 :     case TEMPLATE_PARM_INDEX:
    6074   1898522806 :     case TYPEOF_TYPE:
    6075              :       /* None of these have subtrees other than those already walked
    6076              :          above.  */
    6077   1898522806 :       *walk_subtrees_p = 0;
    6078   1898522806 :       break;
    6079              : 
    6080    168982622 :     case TYPENAME_TYPE:
    6081    168982622 :       WALK_SUBTREE (TYPE_CONTEXT (t));
    6082    168879528 :       WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
    6083    168878094 :       *walk_subtrees_p = 0;
    6084    168878094 :       break;
    6085              : 
    6086     76169241 :     case BASELINK:
    6087     76169241 :       if (BASELINK_QUALIFIED_P (t))
    6088      1440988 :         WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
    6089     76169241 :       WALK_SUBTREE (BASELINK_FUNCTIONS (t));
    6090     76075141 :       *walk_subtrees_p = 0;
    6091     76075141 :       break;
    6092              : 
    6093       153174 :     case PTRMEM_CST:
    6094       153174 :       WALK_SUBTREE (TREE_TYPE (t));
    6095       153174 :       *walk_subtrees_p = 0;
    6096       153174 :       break;
    6097              : 
    6098    285939957 :     case TREE_LIST:
    6099    285939957 :       WALK_SUBTREE (TREE_PURPOSE (t));
    6100              :       break;
    6101              : 
    6102    283064055 :     case OVERLOAD:
    6103    283064055 :       WALK_SUBTREE (OVL_FUNCTION (t));
    6104    283064050 :       WALK_SUBTREE (OVL_CHAIN (t));
    6105    283064050 :       *walk_subtrees_p = 0;
    6106    283064050 :       break;
    6107              : 
    6108      7670212 :     case USING_DECL:
    6109      7670212 :       WALK_SUBTREE (DECL_NAME (t));
    6110      7670212 :       WALK_SUBTREE (USING_DECL_SCOPE (t));
    6111      7670209 :       WALK_SUBTREE (USING_DECL_DECLS (t));
    6112      7670209 :       *walk_subtrees_p = 0;
    6113      7670209 :       break;
    6114              : 
    6115    695273053 :     case RECORD_TYPE:
    6116    695273053 :       if (TYPE_PTRMEMFUNC_P (t))
    6117      5080639 :         WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
    6118              :       break;
    6119              : 
    6120    123873671 :     case TYPE_ARGUMENT_PACK:
    6121    123873671 :     case NONTYPE_ARGUMENT_PACK:
    6122    123873671 :       {
    6123    123873671 :         tree args = ARGUMENT_PACK_ARGS (t);
    6124    319116142 :         for (tree arg : tree_vec_range (args))
    6125    195334535 :           WALK_SUBTREE (arg);
    6126              :       }
    6127    123781607 :       break;
    6128              : 
    6129     24510005 :     case TYPE_PACK_EXPANSION:
    6130     24510005 :       WALK_SUBTREE (TREE_TYPE (t));
    6131     24504558 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6132     24504558 :       *walk_subtrees_p = 0;
    6133     24504558 :       break;
    6134              : 
    6135      3433199 :     case EXPR_PACK_EXPANSION:
    6136      3433199 :       WALK_SUBTREE (TREE_OPERAND (t, 0));
    6137      3430324 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6138      3430324 :       *walk_subtrees_p = 0;
    6139      3430324 :       break;
    6140              : 
    6141         7230 :     case PACK_INDEX_TYPE:
    6142         7230 :     case PACK_INDEX_EXPR:
    6143         7230 :       WALK_SUBTREE (PACK_INDEX_PACK (t));
    6144         7230 :       WALK_SUBTREE (PACK_INDEX_INDEX (t));
    6145         7230 :       *walk_subtrees_p = 0;
    6146         7230 :       break;
    6147              : 
    6148    100298773 :     case CAST_EXPR:
    6149    100298773 :     case REINTERPRET_CAST_EXPR:
    6150    100298773 :     case STATIC_CAST_EXPR:
    6151    100298773 :     case CONST_CAST_EXPR:
    6152    100298773 :     case DYNAMIC_CAST_EXPR:
    6153    100298773 :     case IMPLICIT_CONV_EXPR:
    6154    100298773 :     case BIT_CAST_EXPR:
    6155    100298773 :       if (TREE_TYPE (t))
    6156    100298773 :         WALK_SUBTREE (TREE_TYPE (t));
    6157              :       break;
    6158              : 
    6159    124280195 :     case CONSTRUCTOR:
    6160    124280195 :       if (COMPOUND_LITERAL_P (t))
    6161      8509725 :         WALK_SUBTREE (TREE_TYPE (t));
    6162              :       break;
    6163              : 
    6164     13345665 :     case TRAIT_EXPR:
    6165     13345665 :       WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
    6166     13345653 :       WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
    6167     13345653 :       *walk_subtrees_p = 0;
    6168     13345653 :       break;
    6169              : 
    6170      1247788 :     case TRAIT_TYPE:
    6171      1247788 :       WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
    6172      1247788 :       WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
    6173      1247788 :       *walk_subtrees_p = 0;
    6174      1247788 :       break;
    6175              : 
    6176     14616534 :     case DECLTYPE_TYPE:
    6177     14616534 :       {
    6178     14616534 :         cp_unevaluated u;
    6179     14616534 :         WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
    6180     14253672 :         *walk_subtrees_p = 0;
    6181     14253672 :         break;
    6182     14616534 :       }
    6183              : 
    6184     25285966 :     case ALIGNOF_EXPR:
    6185     25285966 :     case SIZEOF_EXPR:
    6186     25285966 :     case NOEXCEPT_EXPR:
    6187     25285966 :       {
    6188     25285966 :         cp_unevaluated u;
    6189     25285966 :         WALK_SUBTREE (TREE_OPERAND (t, 0));
    6190     22430868 :         *walk_subtrees_p = 0;
    6191     22430868 :         break;
    6192     25285966 :       }
    6193              : 
    6194     12536270 :     case REQUIRES_EXPR:
    6195     12536270 :       {
    6196     12536270 :         cp_unevaluated u;
    6197     21465080 :         for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
    6198              :           /* Walk the types of each parameter, but not the parameter itself,
    6199              :              since doing so would cause false positives in the unexpanded pack
    6200              :              checker if the requires-expr introduces a function parameter pack,
    6201              :              e.g. requires (Ts... ts) { }.   */
    6202      8928906 :           WALK_SUBTREE (TREE_TYPE (parm));
    6203     12536174 :         WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
    6204     12533189 :         *walk_subtrees_p = 0;
    6205     12533189 :         break;
    6206     12536270 :       }
    6207              : 
    6208    167242563 :     case DECL_EXPR:
    6209              :       /* User variables should be mentioned in BIND_EXPR_VARS
    6210              :          and their initializers and sizes walked when walking
    6211              :          the containing BIND_EXPR.  Compiler temporaries are
    6212              :          handled here.  And also normal variables in templates,
    6213              :          since do_poplevel doesn't build a BIND_EXPR then.  */
    6214    167242563 :       if (VAR_P (TREE_OPERAND (t, 0))
    6215    167242563 :           && (processing_template_decl
    6216    152917376 :               || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
    6217     13208364 :                   && !TREE_STATIC (TREE_OPERAND (t, 0)))))
    6218              :         {
    6219     20979471 :           tree decl = TREE_OPERAND (t, 0);
    6220     20979471 :           WALK_SUBTREE (TREE_TYPE (decl));
    6221     20979471 :           WALK_SUBTREE (DECL_INITIAL (decl));
    6222     20979441 :           WALK_SUBTREE (DECL_SIZE (decl));
    6223     20979441 :           WALK_SUBTREE (DECL_SIZE_UNIT (decl));
    6224              :         }
    6225              :       break;
    6226              : 
    6227      1754480 :     case LAMBDA_EXPR:
    6228              :       /* Don't walk into the body of the lambda, but the capture initializers
    6229              :          are part of the enclosing context.  */
    6230      4160936 :       for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
    6231      2406456 :            cap = TREE_CHAIN (cap))
    6232      2406456 :         WALK_SUBTREE (TREE_VALUE (cap));
    6233              :       break;
    6234              : 
    6235         3173 :     case CO_YIELD_EXPR:
    6236         3173 :       if (TREE_OPERAND (t, 1))
    6237              :         /* Operand 1 is the tree for the relevant co_await which has any
    6238              :            interesting sub-trees.  */
    6239          587 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6240              :       break;
    6241              : 
    6242        26863 :     case CO_AWAIT_EXPR:
    6243        26863 :       if (TREE_OPERAND (t, 1))
    6244              :         /* Operand 1 is frame variable.  */
    6245        26675 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6246        26863 :       if (TREE_OPERAND (t, 2))
    6247              :         /* Operand 2 has the initialiser, and we need to walk any subtrees
    6248              :            there.  */
    6249         5367 :         WALK_SUBTREE (TREE_OPERAND (t, 2));
    6250              :       break;
    6251              : 
    6252          881 :     case CO_RETURN_EXPR:
    6253          881 :       if (TREE_OPERAND (t, 0))
    6254              :         {
    6255          698 :           if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
    6256              :             /* For void expressions, operand 1 is a trivial call, and any
    6257              :                interesting subtrees will be part of operand 0.  */
    6258            0 :             WALK_SUBTREE (TREE_OPERAND (t, 0));
    6259          698 :           else if (TREE_OPERAND (t, 1))
    6260              :             /* Interesting sub-trees will be in the return_value () call
    6261              :                arguments.  */
    6262          656 :             WALK_SUBTREE (TREE_OPERAND (t, 1));
    6263              :         }
    6264              :       break;
    6265              : 
    6266       564617 :     case STATIC_ASSERT:
    6267       564617 :       WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
    6268       564617 :       WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
    6269              :       break;
    6270              : 
    6271    728696950 :     case INTEGER_TYPE:
    6272              :       /* Removed from walk_type_fields in r119481.  */
    6273    728696950 :       WALK_SUBTREE (TYPE_MIN_VALUE (t));
    6274    728696950 :       WALK_SUBTREE (TYPE_MAX_VALUE (t));
    6275              :       break;
    6276              : 
    6277          184 :     case SPLICE_SCOPE:
    6278          184 :       WALK_SUBTREE (SPLICE_SCOPE_EXPR (t));
    6279          184 :       *walk_subtrees_p = 0;
    6280          184 :       break;
    6281              : 
    6282              :     default:
    6283              :       return NULL_TREE;
    6284              :     }
    6285              : 
    6286              :   /* We didn't find what we were looking for.  */
    6287              :  out:
    6288              :   return result;
    6289              : 
    6290              : #undef WALK_SUBTREE
    6291              : }
    6292              : 
    6293              : /* Like save_expr, but for C++.  */
    6294              : 
    6295              : tree
    6296       316018 : cp_save_expr (tree expr)
    6297              : {
    6298              :   /* There is no reason to create a SAVE_EXPR within a template; if
    6299              :      needed, we can create the SAVE_EXPR when instantiating the
    6300              :      template.  Furthermore, the middle-end cannot handle C++-specific
    6301              :      tree codes.  */
    6302       316018 :   if (processing_template_decl)
    6303              :     return expr;
    6304              : 
    6305              :   /* TARGET_EXPRs are only expanded once.  */
    6306       244080 :   if (TREE_CODE (expr) == TARGET_EXPR)
    6307              :     return expr;
    6308              : 
    6309       244080 :   return save_expr (expr);
    6310              : }
    6311              : 
    6312              : /* Initialize tree.cc.  */
    6313              : 
    6314              : void
    6315        97402 : init_tree (void)
    6316              : {
    6317        97402 :   list_hash_table = hash_table<list_hasher>::create_ggc (61);
    6318        97402 : }
    6319              : 
    6320              : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
    6321              :    is.  Note that sfk_none is zero, so this function can be used as a
    6322              :    predicate to test whether or not DECL is a special function.  */
    6323              : 
    6324              : special_function_kind
    6325    178437713 : special_function_p (const_tree decl)
    6326              : {
    6327              :   /* Rather than doing all this stuff with magic names, we should
    6328              :      probably have a field of type `special_function_kind' in
    6329              :      DECL_LANG_SPECIFIC.  */
    6330    356875426 :   if (DECL_INHERITED_CTOR (decl))
    6331              :     return sfk_inheriting_constructor;
    6332    355904592 :   if (DECL_COPY_CONSTRUCTOR_P (decl))
    6333              :     return sfk_copy_constructor;
    6334    316260282 :   if (DECL_MOVE_CONSTRUCTOR_P (decl))
    6335              :     return sfk_move_constructor;
    6336    295240096 :   if (DECL_CONSTRUCTOR_P (decl))
    6337              :     return sfk_constructor;
    6338    123599088 :   if (DECL_ASSIGNMENT_OPERATOR_P (decl)
    6339    123599088 :       && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
    6340              :     {
    6341     17613822 :       if (copy_fn_p (decl))
    6342              :         return sfk_copy_assignment;
    6343      6847212 :       if (move_fn_p (decl))
    6344              :         return sfk_move_assignment;
    6345              :     }
    6346    106187330 :   if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
    6347              :     return sfk_destructor;
    6348     62478236 :   if (DECL_COMPLETE_DESTRUCTOR_P (decl))
    6349              :     return sfk_complete_destructor;
    6350     49195967 :   if (DECL_BASE_DESTRUCTOR_P (decl))
    6351              :     return sfk_base_destructor;
    6352     48298215 :   if (DECL_DELETING_DESTRUCTOR_P (decl))
    6353              :     return sfk_deleting_destructor;
    6354     36828622 :   if (DECL_CONV_FN_P (decl))
    6355              :     return sfk_conversion;
    6356     36827490 :   if (deduction_guide_p (decl))
    6357              :     return sfk_deduction_guide;
    6358     36737428 :   if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
    6359     36737428 :       && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
    6360      6422319 :     return sfk_comparison;
    6361              : 
    6362              :   return sfk_none;
    6363              : }
    6364              : 
    6365              : /* As above, but only if DECL is a special member function as per 11.3.3
    6366              :    [special]: default/copy/move ctor, copy/move assignment, or destructor.  */
    6367              : 
    6368              : special_function_kind
    6369      2943503 : special_memfn_p (const_tree decl)
    6370              : {
    6371      2943503 :   switch (special_function_kind sfk = special_function_p (decl))
    6372              :     {
    6373      2609452 :     case sfk_constructor:
    6374      2609452 :       if (!default_ctor_p (decl))
    6375              :         break;
    6376              :       gcc_fallthrough();
    6377              :     case sfk_copy_constructor:
    6378              :     case sfk_copy_assignment:
    6379              :     case sfk_move_assignment:
    6380              :     case sfk_move_constructor:
    6381              :     case sfk_destructor:
    6382              :       return sfk;
    6383              : 
    6384              :     default:
    6385              :       break;
    6386              :     }
    6387              :   return sfk_none;
    6388              : }
    6389              : 
    6390              : /* Returns nonzero if TYPE is a character type, including wchar_t.  */
    6391              : 
    6392              : int
    6393     13461105 : char_type_p (tree type)
    6394              : {
    6395     13461105 :   return (same_type_p (type, char_type_node)
    6396     12160562 :           || same_type_p (type, unsigned_char_type_node)
    6397     12083872 :           || same_type_p (type, signed_char_type_node)
    6398     12083344 :           || same_type_p (type, char8_type_node)
    6399     12083225 :           || same_type_p (type, char16_type_node)
    6400     12082727 :           || same_type_p (type, char32_type_node)
    6401     25395807 :           || same_type_p (type, wchar_type_node));
    6402              : }
    6403              : 
    6404              : /* Returns the kind of linkage associated with the indicated DECL.  The
    6405              :    value returned is as specified by the language standard; it is
    6406              :    independent of implementation details regarding template
    6407              :    instantiation, etc.  For example, it is possible that a declaration
    6408              :    to which this function assigns external linkage would not show up
    6409              :    as a global symbol when you run `nm' on the resulting object file.  */
    6410              : 
    6411              : linkage_kind
    6412    470298601 : decl_linkage (tree decl)
    6413              : {
    6414              :   /* This function doesn't attempt to calculate the linkage from first
    6415              :      principles as given in [basic.link].  Instead, it makes use of
    6416              :      the fact that we have already set TREE_PUBLIC appropriately, and
    6417              :      then handles a few special cases.  Ideally, we would calculate
    6418              :      linkage first, and then transform that into a concrete
    6419              :      implementation.  */
    6420              : 
    6421              :   /* An explicit type alias has no linkage.  Nor do the built-in declarations
    6422              :      of 'int' and such.  */
    6423    520879807 :   if (TREE_CODE (decl) == TYPE_DECL
    6424    520879807 :       && !DECL_IMPLICIT_TYPEDEF_P (decl))
    6425              :     {
    6426              :       /* But this could be a typedef name for linkage purposes, in which
    6427              :          case we're interested in the linkage of the main decl.  */
    6428       927607 :       tree type = TREE_TYPE (decl);
    6429       927607 :       if (type == error_mark_node)
    6430              :         return lk_none;
    6431       927605 :       else if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (type))
    6432              :                /* Likewise for the injected-class-name.  */
    6433       927605 :                || DECL_SELF_REFERENCE_P (decl))
    6434        33329 :         decl = TYPE_MAIN_DECL (type);
    6435              :       else
    6436              :         return lk_none;
    6437              :     }
    6438              : 
    6439              :   /* Namespace-scope entities with no name usually have no linkage.  */
    6440    519985529 :   if (NAMESPACE_SCOPE_P (decl)
    6441    983670148 :       && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
    6442              :     {
    6443      3660020 :       if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
    6444              :         /* This entity has a name for linkage purposes.  */;
    6445      3649561 :       else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
    6446              :         /* Namespace-scope structured bindings can have linkage.  */;
    6447      3649461 :       else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
    6448              :         /* An anonymous namespace has internal linkage since C++11.  */
    6449              :         return lk_internal;
    6450              :       else
    6451              :         return lk_none;
    6452              :     }
    6453              : 
    6454              :   /* Fields and parameters have no linkage.  */
    6455    516336068 :   if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
    6456              :     return lk_none;
    6457              : 
    6458              :   /* Things in block scope do not have linkage.  */
    6459    471366280 :   if (decl_function_context (decl))
    6460              :     return lk_none;
    6461              : 
    6462              :   /* Things in class scope have the linkage of their owning class.  */
    6463    465648222 :   if (tree ctype = DECL_CLASS_CONTEXT (decl))
    6464     50581206 :     return decl_linkage (TYPE_NAME (ctype));
    6465              : 
    6466              :   /* Anonymous namespaces don't provide internal linkage in C++98,
    6467              :      but otherwise consider such declarations to be internal.  */
    6468    415067016 :   if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
    6469              :     return lk_internal;
    6470              : 
    6471              :   /* Templates don't properly propagate TREE_PUBLIC, consider the
    6472              :      template result instead.  Any template that isn't a variable
    6473              :      or function must be external linkage by this point.  */
    6474    414889400 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    6475              :     {
    6476       716324 :       decl = DECL_TEMPLATE_RESULT (decl);
    6477       716324 :       if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
    6478              :         return lk_external;
    6479              :     }
    6480              : 
    6481              :   /* Things that are TREE_PUBLIC have external linkage.  */
    6482    414591637 :   if (TREE_PUBLIC (decl))
    6483              :     return lk_external;
    6484              : 
    6485              :   /* All types have external linkage in C++98, since anonymous namespaces
    6486              :      didn't explicitly confer internal linkage.  */
    6487     86535861 :   if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
    6488              :     return lk_external;
    6489              : 
    6490              :   /* Variables or function decls not marked as TREE_PUBLIC might still
    6491              :      be external linkage, such as for template instantiations on targets
    6492              :      without weak symbols, decls referring to internal-linkage entities,
    6493              :      or compiler-generated entities; in such cases, decls really meant to
    6494              :      have internal linkage will have DECL_THIS_STATIC set.  */
    6495     86535857 :   if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
    6496              :     return lk_external;
    6497              : 
    6498              :   /* Everything else has internal linkage.  */
    6499              :   return lk_internal;
    6500              : }
    6501              : 
    6502              : /* Returns the storage duration of the object or reference associated with
    6503              :    the indicated DECL, which should be a VAR_DECL or PARM_DECL.  */
    6504              : 
    6505              : duration_kind
    6506     71657985 : decl_storage_duration (tree decl)
    6507              : {
    6508     71657985 :   if (TREE_CODE (decl) == PARM_DECL)
    6509              :     return dk_auto;
    6510     71657979 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6511              :     return dk_static;
    6512     71657979 :   gcc_assert (VAR_P (decl));
    6513     71657979 :   if (!TREE_STATIC (decl)
    6514     71657979 :       && !DECL_EXTERNAL (decl))
    6515              :     return dk_auto;
    6516     40684396 :   if (CP_DECL_THREAD_LOCAL_P (decl))
    6517        20197 :     return dk_thread;
    6518              :   return dk_static;
    6519              : }
    6520              : 
    6521              : /* EXP is an expression that we want to pre-evaluate.  Returns (in
    6522              :    *INITP) an expression that will perform the pre-evaluation.  The
    6523              :    value returned by this function is a side-effect free expression
    6524              :    equivalent to the pre-evaluated expression.  Callers must ensure
    6525              :    that *INITP is evaluated before EXP.
    6526              : 
    6527              :    Note that if EXPR is a glvalue, the return value is a glvalue denoting the
    6528              :    same address; this function does not guard against modification of the
    6529              :    stored value like save_expr or get_target_expr do.  */
    6530              : 
    6531              : tree
    6532      5997239 : stabilize_expr (tree exp, tree* initp)
    6533              : {
    6534      5997239 :   tree init_expr;
    6535              : 
    6536      5997239 :   if (!TREE_SIDE_EFFECTS (exp))
    6537              :     init_expr = NULL_TREE;
    6538      1057811 :   else if (VOID_TYPE_P (TREE_TYPE (exp)))
    6539              :     {
    6540            0 :       init_expr = exp;
    6541            0 :       exp = void_node;
    6542              :     }
    6543              :   /* There are no expressions with REFERENCE_TYPE, but there can be call
    6544              :      arguments with such a type; just treat it as a pointer.  */
    6545      1057811 :   else if (TYPE_REF_P (TREE_TYPE (exp))
    6546      1057677 :            || SCALAR_TYPE_P (TREE_TYPE (exp))
    6547      1057857 :            || !glvalue_p (exp))
    6548              :     {
    6549      1057805 :       init_expr = get_target_expr (exp);
    6550      1057805 :       exp = TARGET_EXPR_SLOT (init_expr);
    6551      1057805 :       if (CLASS_TYPE_P (TREE_TYPE (exp)))
    6552            9 :         exp = move (exp);
    6553              :       else
    6554      1057796 :         exp = rvalue (exp);
    6555              :     }
    6556              :   else
    6557              :     {
    6558            6 :       bool xval = !lvalue_p (exp);
    6559            6 :       exp = cp_build_addr_expr (exp, tf_warning_or_error);
    6560            6 :       init_expr = get_target_expr (exp);
    6561            6 :       exp = TARGET_EXPR_SLOT (init_expr);
    6562            6 :       exp = cp_build_fold_indirect_ref (exp);
    6563            6 :       if (xval)
    6564            0 :         exp = move (exp);
    6565              :     }
    6566      5997239 :   *initp = init_expr;
    6567              : 
    6568      5997239 :   gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
    6569      5997239 :   return exp;
    6570              : }
    6571              : 
    6572              : /* Add NEW_EXPR, an expression whose value we don't care about, after the
    6573              :    similar expression ORIG.  */
    6574              : 
    6575              : tree
    6576      1270909 : add_stmt_to_compound (tree orig, tree new_expr)
    6577              : {
    6578      1270909 :   if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
    6579              :     return orig;
    6580       639052 :   if (!orig || !TREE_SIDE_EFFECTS (orig))
    6581              :     return new_expr;
    6582        12796 :   return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
    6583              : }
    6584              : 
    6585              : /* Like stabilize_expr, but for a call whose arguments we want to
    6586              :    pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6587              :    arguments, while, upon return, *INITP contains an expression to
    6588              :    compute the arguments.  */
    6589              : 
    6590              : void
    6591       627620 : stabilize_call (tree call, tree *initp)
    6592              : {
    6593       627620 :   tree inits = NULL_TREE;
    6594       627620 :   int i;
    6595       627620 :   int nargs = call_expr_nargs (call);
    6596              : 
    6597       627620 :   if (call == error_mark_node || processing_template_decl)
    6598              :     {
    6599           31 :       *initp = NULL_TREE;
    6600           31 :       return;
    6601              :     }
    6602              : 
    6603       627589 :   gcc_assert (TREE_CODE (call) == CALL_EXPR);
    6604              : 
    6605      1882848 :   for (i = 0; i < nargs; i++)
    6606              :     {
    6607      1255259 :       tree init;
    6608      1255259 :       CALL_EXPR_ARG (call, i) =
    6609      1255259 :         stabilize_expr (CALL_EXPR_ARG (call, i), &init);
    6610      1255259 :       inits = add_stmt_to_compound (inits, init);
    6611              :     }
    6612              : 
    6613       627589 :   *initp = inits;
    6614              : }
    6615              : 
    6616              : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
    6617              :    to pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6618              :    arguments, while, upon return, *INITP contains an expression to
    6619              :    compute the arguments.  */
    6620              : 
    6621              : static void
    6622            0 : stabilize_aggr_init (tree call, tree *initp)
    6623              : {
    6624            0 :   tree inits = NULL_TREE;
    6625            0 :   int i;
    6626            0 :   int nargs = aggr_init_expr_nargs (call);
    6627              : 
    6628            0 :   if (call == error_mark_node)
    6629              :     return;
    6630              : 
    6631            0 :   gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
    6632              : 
    6633            0 :   for (i = 0; i < nargs; i++)
    6634              :     {
    6635            0 :       tree init;
    6636            0 :       AGGR_INIT_EXPR_ARG (call, i) =
    6637            0 :         stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
    6638            0 :       inits = add_stmt_to_compound (inits, init);
    6639              :     }
    6640              : 
    6641            0 :   *initp = inits;
    6642              : }
    6643              : 
    6644              : /* Like stabilize_expr, but for an initialization.
    6645              : 
    6646              :    If the initialization is for an object of class type, this function
    6647              :    takes care not to introduce additional temporaries.
    6648              : 
    6649              :    Returns TRUE iff the expression was successfully pre-evaluated,
    6650              :    i.e., if INIT is now side-effect free, except for, possibly, a
    6651              :    single call to a constructor.  */
    6652              : 
    6653              : bool
    6654            0 : stabilize_init (tree init, tree *initp)
    6655              : {
    6656            0 :   tree t = init;
    6657              : 
    6658            0 :   *initp = NULL_TREE;
    6659              : 
    6660            0 :   if (t == error_mark_node || processing_template_decl)
    6661              :     return true;
    6662              : 
    6663            0 :   if (TREE_CODE (t) == INIT_EXPR)
    6664            0 :     t = TREE_OPERAND (t, 1);
    6665            0 :   if (TREE_CODE (t) == TARGET_EXPR)
    6666            0 :     t = TARGET_EXPR_INITIAL (t);
    6667              : 
    6668              :   /* If the RHS can be stabilized without breaking copy elision, stabilize
    6669              :      it.  We specifically don't stabilize class prvalues here because that
    6670              :      would mean an extra copy, but they might be stabilized below.  */
    6671            0 :   if (TREE_CODE (init) == INIT_EXPR
    6672            0 :       && TREE_CODE (t) != CONSTRUCTOR
    6673            0 :       && TREE_CODE (t) != AGGR_INIT_EXPR
    6674            0 :       && (SCALAR_TYPE_P (TREE_TYPE (t))
    6675            0 :           || glvalue_p (t)))
    6676              :     {
    6677            0 :       TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
    6678            0 :       return true;
    6679              :     }
    6680              : 
    6681            0 :   if (TREE_CODE (t) == COMPOUND_EXPR
    6682            0 :       && TREE_CODE (init) == INIT_EXPR)
    6683              :     {
    6684            0 :       tree last = expr_last (t);
    6685              :       /* Handle stabilizing the EMPTY_CLASS_EXPR pattern.  */
    6686            0 :       if (!TREE_SIDE_EFFECTS (last))
    6687              :         {
    6688            0 :           *initp = t;
    6689            0 :           TREE_OPERAND (init, 1) = last;
    6690            0 :           return true;
    6691              :         }
    6692              :     }
    6693              : 
    6694            0 :   if (TREE_CODE (t) == CONSTRUCTOR)
    6695              :     {
    6696              :       /* Aggregate initialization: stabilize each of the field
    6697              :          initializers.  */
    6698            0 :       unsigned i;
    6699            0 :       constructor_elt *ce;
    6700            0 :       bool good = true;
    6701            0 :       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
    6702            0 :       for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
    6703              :         {
    6704            0 :           tree type = TREE_TYPE (ce->value);
    6705            0 :           tree subinit;
    6706            0 :           if (TYPE_REF_P (type)
    6707            0 :               || SCALAR_TYPE_P (type))
    6708            0 :             ce->value = stabilize_expr (ce->value, &subinit);
    6709            0 :           else if (!stabilize_init (ce->value, &subinit))
    6710            0 :             good = false;
    6711            0 :           *initp = add_stmt_to_compound (*initp, subinit);
    6712              :         }
    6713              :       return good;
    6714              :     }
    6715              : 
    6716            0 :   if (TREE_CODE (t) == CALL_EXPR)
    6717              :     {
    6718            0 :       stabilize_call (t, initp);
    6719            0 :       return true;
    6720              :     }
    6721              : 
    6722            0 :   if (TREE_CODE (t) == AGGR_INIT_EXPR)
    6723              :     {
    6724            0 :       stabilize_aggr_init (t, initp);
    6725            0 :       return true;
    6726              :     }
    6727              : 
    6728              :   /* The initialization is being performed via a bitwise copy -- and
    6729              :      the item copied may have side effects.  */
    6730            0 :   return !TREE_SIDE_EFFECTS (init);
    6731              : }
    6732              : 
    6733              : /* Returns true if a cast to TYPE may appear in an integral constant
    6734              :    expression.  */
    6735              : 
    6736              : bool
    6737     92927095 : cast_valid_in_integral_constant_expression_p (tree type)
    6738              : {
    6739     92927095 :   return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    6740     66231181 :           || cxx_dialect >= cxx11
    6741       482672 :           || dependent_type_p (type)
    6742     93305460 :           || type == error_mark_node);
    6743              : }
    6744              : 
    6745              : /* Return true if we need to fix linkage information of DECL.  */
    6746              : 
    6747              : static bool
    6748        73278 : cp_fix_function_decl_p (tree decl)
    6749              : {
    6750              :   /* Skip if DECL is not externally visible.  */
    6751        73278 :   if (!TREE_PUBLIC (decl))
    6752              :     return false;
    6753              : 
    6754              :   /* We need to fix DECL if it a appears to be exported but with no
    6755              :      function body.  Thunks do not have CFGs and we may need to
    6756              :      handle them specially later.   */
    6757        71058 :   if (!gimple_has_body_p (decl)
    6758        26699 :       && !DECL_THUNK_P (decl)
    6759        97371 :       && !DECL_EXTERNAL (decl))
    6760              :     {
    6761        12497 :       struct cgraph_node *node = cgraph_node::get (decl);
    6762              : 
    6763              :       /* Don't fix same_body aliases.  Although they don't have their own
    6764              :          CFG, they share it with what they alias to.  */
    6765        12497 :       if (!node || !node->alias || !node->num_references ())
    6766              :         return true;
    6767              :     }
    6768              : 
    6769              :   return false;
    6770              : }
    6771              : 
    6772              : /* Clean the C++ specific parts of the tree T. */
    6773              : 
    6774              : void
    6775       714704 : cp_free_lang_data (tree t)
    6776              : {
    6777       714704 :   if (FUNC_OR_METHOD_TYPE_P (t))
    6778              :     {
    6779              :       /* Default args are not interesting anymore.  */
    6780        57693 :       tree argtypes = TYPE_ARG_TYPES (t);
    6781       208191 :       while (argtypes)
    6782              :         {
    6783       150498 :           TREE_PURPOSE (argtypes) = 0;
    6784       150498 :           argtypes = TREE_CHAIN (argtypes);
    6785              :         }
    6786              :     }
    6787       657011 :   else if (TREE_CODE (t) == FUNCTION_DECL
    6788       657011 :            && cp_fix_function_decl_p (t))
    6789              :     {
    6790              :       /* If T is used in this translation unit at all,  the definition
    6791              :          must exist somewhere else since we have decided to not emit it
    6792              :          in this TU.  So make it an external reference.  */
    6793         6562 :       DECL_EXTERNAL (t) = 1;
    6794         6562 :       TREE_STATIC (t) = 0;
    6795              :     }
    6796       714704 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    6797              :     /* We do not need the leftover chaining of namespaces from the
    6798              :        binding level.  */
    6799         1627 :     DECL_CHAIN (t) = NULL_TREE;
    6800       714704 : }
    6801              : 
    6802              : /* Stub for c-common.  Please keep in sync with c-decl.cc.
    6803              :    FIXME: If address space support is target specific, then this
    6804              :    should be a C target hook.  But currently this is not possible,
    6805              :    because this function is called via REGISTER_TARGET_PRAGMAS.  */
    6806              : void
    6807       194804 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
    6808              : {
    6809       194804 : }
    6810              : 
    6811              : /* Return the number of operands in T that we care about for things like
    6812              :    mangling.  */
    6813              : 
    6814              : int
    6815    614839621 : cp_tree_operand_length (const_tree t)
    6816              : {
    6817    614839621 :   enum tree_code code = TREE_CODE (t);
    6818              : 
    6819    614839621 :   if (TREE_CODE_CLASS (code) == tcc_vl_exp)
    6820     69470045 :     return VL_EXP_OPERAND_LENGTH (t);
    6821              : 
    6822    545369576 :   return cp_tree_code_length (code);
    6823              : }
    6824              : 
    6825              : /* Like cp_tree_operand_length, but takes a tree_code CODE.  */
    6826              : 
    6827              : int
    6828    551717343 : cp_tree_code_length (enum tree_code code)
    6829              : {
    6830    551717343 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    6831              : 
    6832    551717343 :   switch (code)
    6833              :     {
    6834              :     case PREINCREMENT_EXPR:
    6835              :     case PREDECREMENT_EXPR:
    6836              :     case POSTINCREMENT_EXPR:
    6837              :     case POSTDECREMENT_EXPR:
    6838              :       return 1;
    6839              : 
    6840      1011123 :     case ARRAY_REF:
    6841      1011123 :       return 2;
    6842              : 
    6843              :     case EXPR_PACK_EXPANSION:
    6844              :       return 1;
    6845              : 
    6846    548203917 :     default:
    6847    548203917 :       return TREE_CODE_LENGTH (code);
    6848              :     }
    6849              : }
    6850              : 
    6851              : /* Implement -Wzero_as_null_pointer_constant.  Return true if the
    6852              :    conditions for the warning hold, false otherwise.  */
    6853              : bool
    6854      7779461 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
    6855              : {
    6856      7779461 :   if (c_inhibit_evaluation_warnings == 0
    6857     14524357 :       && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
    6858              :     {
    6859      2700667 :       warning_at (loc, OPT_Wzero_as_null_pointer_constant,
    6860              :                   "zero as null pointer constant");
    6861      2700667 :       return true;
    6862              :     }
    6863              :   return false;
    6864              : }
    6865              : 
    6866              : /* FNDECL is a function declaration whose type may have been altered by
    6867              :    adding extra parameters such as this, in-charge, or VTT.  When this
    6868              :    takes place, the positional arguments supplied by the user (as in the
    6869              :    'format' attribute arguments) may refer to the wrong argument.  This
    6870              :    function returns an integer indicating how many arguments should be
    6871              :    skipped.  */
    6872              : 
    6873              : int
    6874     36568678 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
    6875              : {
    6876     36568678 :   if (!fndecl)
    6877              :     return 0;
    6878      7083094 :   int n = num_artificial_parms_for (fndecl);
    6879              :   /* The manual states that it's the user's responsibility to account
    6880              :      for the implicit this parameter.  */
    6881      7083094 :   return n > 0 ? n - 1 : 0;
    6882              : }
    6883              : 
    6884              : /* True if ATTR is annotation.  */
    6885              : 
    6886              : bool
    6887     54396421 : annotation_p (tree attr)
    6888              : {
    6889     54396421 :   return is_attribute_p ("annotation ", get_attribute_name (attr));
    6890              : }
    6891              : 
    6892              : 
    6893              : /* Release memory we no longer need after parsing.  */
    6894              : void
    6895        95785 : cp_tree_c_finish_parsing ()
    6896              : {
    6897        95785 :   if (previous_class_level)
    6898        67782 :     invalidate_class_lookup_cache ();
    6899        95785 :   deleted_copy_types = NULL;
    6900        95785 : }
    6901              : 
    6902              : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
    6903              : /* Complain that some language-specific thing hanging off a tree
    6904              :    node has been accessed improperly.  */
    6905              : 
    6906              : void
    6907            0 : lang_check_failed (const char* file, int line, const char* function)
    6908              : {
    6909            0 :   internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
    6910              :                   function, trim_filename (file), line);
    6911              : }
    6912              : #endif /* ENABLE_TREE_CHECKING */
    6913              : 
    6914              : #if CHECKING_P
    6915              : 
    6916              : namespace selftest {
    6917              : 
    6918              : /* Verify that lvalue_kind () works, for various expressions,
    6919              :    and that location wrappers don't affect the results.  */
    6920              : 
    6921              : static void
    6922            1 : test_lvalue_kind ()
    6923              : {
    6924            1 :   location_t loc = BUILTINS_LOCATION;
    6925              : 
    6926              :   /* Verify constants and parameters, without and with
    6927              :      location wrappers.  */
    6928            1 :   tree int_cst = build_int_cst (integer_type_node, 42);
    6929            1 :   ASSERT_EQ (clk_none, lvalue_kind (int_cst));
    6930              : 
    6931            1 :   tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
    6932            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
    6933            1 :   ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
    6934              : 
    6935            1 :   tree string_lit = build_string (4, "foo");
    6936            1 :   TREE_TYPE (string_lit) = char_array_type_node;
    6937            1 :   string_lit = fix_string_type (string_lit);
    6938            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
    6939              : 
    6940            1 :   tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
    6941            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
    6942            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
    6943              : 
    6944            1 :   tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
    6945              :                           get_identifier ("some_parm"),
    6946              :                           integer_type_node);
    6947            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
    6948              : 
    6949            1 :   tree wrapped_parm = maybe_wrap_with_location (parm, loc);
    6950            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_parm));
    6951            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
    6952              : 
    6953              :   /* Verify that lvalue_kind of std::move on a parm isn't
    6954              :      affected by location wrappers.  */
    6955            1 :   tree rvalue_ref_of_parm = move (parm);
    6956            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
    6957            1 :   tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
    6958            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
    6959              : 
    6960              :   /* Verify lvalue_p.  */
    6961            1 :   ASSERT_FALSE (lvalue_p (int_cst));
    6962            1 :   ASSERT_FALSE (lvalue_p (wrapped_int_cst));
    6963            1 :   ASSERT_TRUE (lvalue_p (parm));
    6964            1 :   ASSERT_TRUE (lvalue_p (wrapped_parm));
    6965            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
    6966            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
    6967            1 : }
    6968              : 
    6969              : /* Run all of the selftests within this file.  */
    6970              : 
    6971              : void
    6972            1 : cp_tree_cc_tests ()
    6973              : {
    6974            1 :   test_lvalue_kind ();
    6975            1 : }
    6976              : 
    6977              : } // namespace selftest
    6978              : 
    6979              : #endif /* #if CHECKING_P */
    6980              : 
    6981              : 
    6982              : #include "gt-cp-tree.h"
        

Generated by: LCOV version 2.4-beta

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