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