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

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