LCOV - code coverage report
Current view: top level - gcc/cp - tree.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.2 % 3208 2991
Test Date: 2026-10-03 16:17:38 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   2743149450 : lvalue_kind (const_tree ref)
      63              : {
      64   3015984690 :   cp_lvalue_kind op1_lvalue_kind = clk_none;
      65   3015984690 :   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   3015984690 :   if (REFERENCE_REF_P (ref))
      72    256692472 :     return lvalue_kind (TREE_OPERAND (ref, 0));
      73              : 
      74   2759292218 :   if (TREE_TYPE (ref)
      75   2759292218 :       && TYPE_REF_P (TREE_TYPE (ref)))
      76              :     {
      77              :       /* unnamed rvalue references are rvalues */
      78    260862552 :       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    311528718 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
      84              :         {
      85     50665141 :           op1_lvalue_kind = clk_rvalueref;
      86     50665141 :           if (implicit_rvalue_p (ref))
      87      8454108 :             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   2498429666 :   if (ref == current_class_ptr)
      96              :     return clk_none;
      97              : 
      98              :   /* Expressions with cv void type are prvalues.  */
      99   2495316855 :   if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
     100              :     return clk_none;
     101              : 
     102   2494987069 :   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    313838845 :     case PREINCREMENT_EXPR:
     110    313838845 :     case PREDECREMENT_EXPR:
     111    313838845 :     case TRY_CATCH_EXPR:
     112    313838845 :     case REALPART_EXPR:
     113    313838845 :     case IMAGPART_EXPR:
     114    313838845 :     case VIEW_CONVERT_EXPR:
     115    313838845 :       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    313838845 :       if (op1_lvalue_kind == clk_class
     121    313838859 :           && !(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      3630272 :     case ARRAY_REF:
     128      3630272 :       {
     129      3630272 :         tree op1 = TREE_OPERAND (ref, 0);
     130      3630272 :         if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
     131              :           {
     132      3140421 :             op1_lvalue_kind = lvalue_kind (op1);
     133      3140421 :             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    161288694 :     case COMPONENT_REF:
     159    161288694 :       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    161288667 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     171    161288667 :       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    161109024 :       if (!op1_lvalue_kind)
     178              :         ;
     179    161288643 :       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    161288544 :       else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
     185              :         /* This can be IDENTIFIER_NODE in a template.  */;
     186    154105428 :       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      6237992 :           op1_lvalue_kind &= ~clk_ordinary;
     191              :           /* The lvalue is for a bitfield.  */
     192      6237992 :           op1_lvalue_kind |= clk_bitfield;
     193              :         }
     194    147867436 :       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      3021842 :     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      3021842 :       if (! TREE_STATIC (ref))
     211              :         return clk_none;
     212              :       /* FALLTHRU */
     213    260059789 :     case VAR_DECL:
     214    260059789 :       if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
     215       944828 :         return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
     216              : 
     217    370245679 :       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
     218     14318797 :           && DECL_LANG_SPECIFIC (ref)
     219    260044041 :           && DECL_IN_AGGR_P (ref))
     220              :         return clk_none;
     221              : 
     222    259114961 :       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     11827913 :     case SCOPE_REF:
     236     11827913 :       gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     237     11827913 :       {
     238     11827913 :         tree op = TREE_OPERAND (ref, 1);
     239     11827913 :         if (TREE_CODE (op) == FIELD_DECL)
     240        18803 :           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     13224451 :     case COND_EXPR:
     256     13224451 :       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      1245133 :           gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     265      1245133 :           goto default_;
     266              :         }
     267     11979318 :       {
     268     11979318 :         tree op1 = TREE_OPERAND (ref, 1);
     269     11979318 :         if (!op1) op1 = TREE_OPERAND (ref, 0);
     270     11979318 :         tree op2 = TREE_OPERAND (ref, 2);
     271     11979318 :         op1_lvalue_kind = lvalue_kind (op1);
     272     11979318 :         op2_lvalue_kind = lvalue_kind (op2);
     273     11979318 :         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       577635 :             if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
     279              :               op2_lvalue_kind = op1_lvalue_kind;
     280       577590 :             else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
     281     11979803 :               op1_lvalue_kind = op2_lvalue_kind;
     282              :           }
     283              :       }
     284              :       break;
     285              : 
     286        97817 :     case MODOP_EXPR:
     287              :       /* We expect to see unlowered MODOP_EXPRs only during
     288              :          template processing.  */
     289        97817 :       gcc_assert (processing_template_decl);
     290        97817 :       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      3350707 :     case COMPOUND_EXPR:
     300      3350707 :       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    122975110 :     case CALL_EXPR:
     309              :       /* We can see calls outside of TARGET_EXPR in templates.  */
     310    122975110 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
     311              :         return clk_class;
     312              :       return clk_none;
     313              : 
     314    130851545 :     case FUNCTION_DECL:
     315              :       /* All functions (except non-static-member functions) are
     316              :          lvalues.  */
     317    130851545 :       return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
     318    130851545 :               ? clk_none : clk_ordinary);
     319              : 
     320         2178 :     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         2178 :       return lvalue_kind (BASELINK_FUNCTIONS (const_cast<tree> (ref)));
     326              : 
     327        35918 :     case PAREN_EXPR:
     328        35918 :       return lvalue_kind (TREE_OPERAND (ref, 0));
     329              : 
     330     21037410 :     case TEMPLATE_PARM_INDEX:
     331     21037410 :       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   1046049847 :     default:
     337   1046049847 :     default_:
     338   1046049847 :       if (!TREE_TYPE (ref))
     339              :         return clk_none;
     340   2092099694 :       if (CLASS_TYPE_P (TREE_TYPE (ref))
     341   2088857363 :           || 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     11979803 :   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      3642977 :   op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
     354              :   /* It's not an ordinary lvalue if it involves any other kind.  */
     355      3642977 :   if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
     356       190176 :     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       190176 :   if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
     360        39257 :       && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
     361   2743149450 :     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     45287300 : real_lvalue_p (const_tree ref)
     369              : {
     370     45287300 :   cp_lvalue_kind kind = lvalue_kind (ref);
     371     45287300 :   if (kind & (clk_rvalueref|clk_class))
     372              :     return clk_none;
     373              :   else
     374     43154007 :     return kind;
     375              : }
     376              : 
     377              : /* c-common wants us to return bool.  */
     378              : 
     379              : bool
     380     44415958 : lvalue_p (const_tree t)
     381              : {
     382     44415958 :   return real_lvalue_p (t);
     383              : }
     384              : 
     385              : /* This differs from lvalue_p in that xvalues are included.  */
     386              : 
     387              : bool
     388    156193829 : glvalue_p (const_tree ref)
     389              : {
     390    156193829 :   cp_lvalue_kind kind = lvalue_kind (ref);
     391    156193829 :   if (kind & clk_class)
     392              :     return false;
     393              :   else
     394    152878831 :     return (kind != clk_none);
     395              : }
     396              : 
     397              : /* This differs from glvalue_p in that class prvalues are included.  */
     398              : 
     399              : bool
     400   1319235594 : obvalue_p (const_tree ref)
     401              : {
     402   1319235594 :   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      7100368 : xvalue_p (const_tree ref)
     410              : {
     411      7100368 :   return (lvalue_kind (ref) & clk_rvalueref);
     412              : }
     413              : 
     414              : /* True if REF is a bit-field.  */
     415              : 
     416              : bool
     417    216947480 : bitfield_p (const_tree ref)
     418              : {
     419    216947480 :   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      5133734 : cp_stabilize_reference (tree ref)
     514              : {
     515      5133734 :   if (processing_template_decl)
     516              :     /* As in cp_save_expr.  */
     517              :     return ref;
     518              : 
     519      4194589 :   STRIP_ANY_LOCATION_WRAPPER (ref);
     520      4194589 :   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          451 :     default:
     538          451 :       cp_lvalue_kind kind = lvalue_kind (ref);
     539          451 :       if ((kind & ~clk_class) != clk_none)
     540              :         {
     541          442 :           if (kind & (clk_bitfield | clk_packed))
     542           24 :             return cp_stabilize_bitfield_reference (ref);
     543          418 :           tree type = unlowered_expr_type (ref);
     544          418 :           bool rval = !!(kind & clk_rvalueref);
     545          418 :           type = cp_build_reference_type (type, rval);
     546              :           /* This inhibits warnings in, eg, cxx_mark_addressable
     547              :              (c++/60955).  */
     548          418 :           warning_sentinel s (extra_warnings);
     549          418 :           ref = build_static_cast (input_location, type, ref,
     550              :                                    tf_error);
     551          418 :         }
     552              :     }
     553              : 
     554      4194565 :   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    588641522 : builtin_valid_in_constant_expr_p (const_tree decl)
     562              : {
     563    588641522 :   STRIP_ANY_LOCATION_WRAPPER (decl);
     564    588641522 :   if (TREE_CODE (decl) != FUNCTION_DECL)
     565              :     /* Not a function.  */
     566              :     return false;
     567    300342298 :   if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
     568              :     {
     569    251595329 :       if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
     570       278350 :         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     48746969 :   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     37803291 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
     618              : {
     619     37803291 :   tree t;
     620     37803291 :   tree type = TREE_TYPE (decl);
     621              : 
     622     37803291 :   value = mark_rvalue_use (value);
     623              : 
     624     37803291 :   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     37803291 :   if (CP_TYPE_CONST_NON_VOLATILE_P (type)
     635      2025191 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     636      1897541 :       && !VOID_TYPE_P (TREE_TYPE (value))
     637      1168888 :       && !TYPE_HAS_MUTABLE_P (type)
     638     38972171 :       && reduced_constant_expression_p (value))
     639       347407 :     TREE_READONLY (decl) = true;
     640              : 
     641     37803291 :   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     36872278 :       t = cxx_maybe_build_cleanup (decl, complain);
     647     36872278 :       if (t == error_mark_node)
     648              :         return error_mark_node;
     649              :     }
     650              : 
     651     37803243 :   set_target_expr_eliding (value);
     652              : 
     653     37803243 :   t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
     654     37803243 :   if (location_t eloc = cp_expr_location (value))
     655     24820984 :     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     37803243 :   TREE_SIDE_EFFECTS (t) = 1;
     661              : 
     662     37803243 :   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     42613360 : build_local_temp (tree type)
     670              : {
     671     42613360 :   tree slot = build_decl (input_location,
     672              :                           VAR_DECL, NULL_TREE, type);
     673     42613360 :   DECL_ARTIFICIAL (slot) = 1;
     674     42613360 :   DECL_IGNORED_P (slot) = 1;
     675     42613360 :   DECL_CONTEXT (slot) = current_function_decl;
     676     42613360 :   layout_decl (slot, 0);
     677     42613360 :   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     55594619 : is_local_temp (tree decl)
     685              : {
     686     55594619 :   return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
     687     56174344 :           && !TREE_STATIC (decl));
     688              : }
     689              : 
     690              : /* Set various status flags when building an AGGR_INIT_EXPR object T.  */
     691              : 
     692              : static void
     693     13371751 : process_aggr_init_operands (tree t)
     694              : {
     695     13371751 :   bool side_effects;
     696              : 
     697     13371751 :   side_effects = TREE_SIDE_EFFECTS (t);
     698     13371751 :   if (!side_effects)
     699              :     {
     700     13371751 :       int i, n;
     701     13371751 :       n = TREE_OPERAND_LENGTH (t);
     702     73331530 :       for (i = 1; i < n; i++)
     703              :         {
     704     50298977 :           tree op = TREE_OPERAND (t, i);
     705     50298977 :           if (op && TREE_SIDE_EFFECTS (op))
     706              :             {
     707              :               side_effects = 1;
     708              :               break;
     709              :             }
     710              :         }
     711              :     }
     712     13371751 :   TREE_SIDE_EFFECTS (t) = side_effects;
     713     13371751 : }
     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     13371751 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
     721              :                        tree *args)
     722              : {
     723     13371751 :   tree t;
     724     13371751 :   int i;
     725              : 
     726     13371751 :   t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
     727     13371751 :   TREE_TYPE (t) = return_type;
     728     13371751 :   AGGR_INIT_EXPR_FN (t) = fn;
     729     13371751 :   AGGR_INIT_EXPR_SLOT (t) = slot;
     730     38567648 :   for (i = 0; i < nargs; i++)
     731     25195897 :     AGGR_INIT_EXPR_ARG (t, i) = args[i];
     732     13371751 :   process_aggr_init_operands (t);
     733     13371751 :   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     41543774 : build_aggr_init_expr (tree type, tree init)
     748              : {
     749     41543774 :   tree fn;
     750     41543774 :   tree slot;
     751     41543774 :   tree rval;
     752     41543774 :   int is_ctor;
     753              : 
     754     41543774 :   gcc_assert (!VOID_TYPE_P (type));
     755              : 
     756              :   /* Don't build AGGR_INIT_EXPR in a template.  */
     757     41543774 :   if (processing_template_decl)
     758              :     return init;
     759              : 
     760     41436576 :   fn = cp_get_callee (init);
     761     41436576 :   if (fn == NULL_TREE)
     762     16754609 :     return convert (type, init);
     763              : 
     764     50617618 :   is_ctor = (TREE_CODE (fn) == ADDR_EXPR
     765     24633589 :              && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
     766     73949145 :              && 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     12563900 :   if (is_ctor || TREE_ADDRESSABLE (type))
     780              :     {
     781     13371751 :       slot = build_local_temp (type);
     782              : 
     783     13371751 :       if (TREE_CODE (init) == CALL_EXPR)
     784              :         {
     785     51341504 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     786     12835376 :                                         call_expr_nargs (init),
     787     12835376 :                                         CALL_EXPR_ARGP (init));
     788     12835376 :           AGGR_INIT_FROM_THUNK_P (rval)
     789     12835376 :             = CALL_FROM_THUNK_P (init);
     790              :         }
     791              :       else
     792              :         {
     793       536375 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     794       536375 :                                         aggr_init_expr_nargs (init),
     795       536375 :                                         AGGR_INIT_EXPR_ARGP (init));
     796       536375 :           AGGR_INIT_FROM_THUNK_P (rval)
     797       536375 :             = AGGR_INIT_FROM_THUNK_P (init);
     798              :         }
     799     13371751 :       TREE_SIDE_EFFECTS (rval) = 1;
     800     13371751 :       AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
     801     13371751 :       TREE_NOTHROW (rval) = TREE_NOTHROW (init);
     802     13371751 :       CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
     803     13371751 :       CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
     804     13371751 :       CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
     805     13371751 :       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     35836297 : 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     35836297 :   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     35835803 :   tree rval = build_aggr_init_expr (type, init);
     834     35835803 :   tree slot;
     835              : 
     836     35835803 :   if (init == error_mark_node)
     837              :     return error_mark_node;
     838              : 
     839     35833618 :   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     35833612 :   if (abstract_virtuals_error (NULL_TREE, type, complain))
     845           33 :     return error_mark_node;
     846              : 
     847     35833579 :   if (TREE_CODE (rval) == AGGR_INIT_EXPR)
     848      7973516 :     slot = AGGR_INIT_EXPR_SLOT (rval);
     849     27860063 :   else if (TREE_CODE (rval) == CALL_EXPR
     850     16461641 :            || TREE_CODE (rval) == CONSTRUCTOR)
     851     11398794 :     slot = build_local_temp (type);
     852              :   else
     853              :     return rval;
     854              : 
     855     19372310 :   rval = build_target_expr (slot, rval, complain);
     856              : 
     857     19372310 :   if (rval != error_mark_node)
     858     19372310 :     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         1307 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
     876              : {
     877         1307 :   tree inner_type = strip_array_types (type);
     878              : 
     879         1307 :   if (integer_zerop (array_type_nelts_total (type))
     880         1307 :       || !CLASS_TYPE_P (inner_type))
     881              :     /* No interesting initialization to do.  */
     882          219 :     return integer_zero_node;
     883         1088 :   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          227 :       if (CP_AGGREGATE_TYPE_P (inner_type))
     888              :         {
     889           63 :           tree empty = build_constructor (init_list_type_node, nullptr);
     890           63 :           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         1025 :   if (init == void_type_node)
     897          195 :     return build_value_init (inner_type, complain);
     898              : 
     899          830 :   releasing_vec argvec;
     900          830 :   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          830 :   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          830 :   if (TREE_CODE (init) == TARGET_EXPR)
     915           32 :     init = TARGET_EXPR_INITIAL (init);
     916              : 
     917          830 :   return init;
     918          830 : }
     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         1325 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
     926              : {
     927         1325 :   if (tree vi = get_vec_init_expr (init))
     928              :     return vi;
     929              : 
     930         1309 :   tree elt_init;
     931          675 :   if (init && TREE_CODE (init) == CONSTRUCTOR
     932         1540 :       && !BRACE_ENCLOSED_INITIALIZER_P (init))
     933              :     /* We built any needed constructor calls in digest_init.  */
     934              :     elt_init = init;
     935              :   else
     936         1305 :     elt_init = build_vec_init_elt (type, init, complain);
     937              : 
     938         1309 :   bool value_init = false;
     939         1309 :   if (init == void_type_node)
     940              :     {
     941          229 :       value_init = true;
     942          229 :       init = NULL_TREE;
     943              :     }
     944              : 
     945         1309 :   tree slot = build_local_temp (type);
     946         1309 :   init = build2 (VEC_INIT_EXPR, type, slot, init);
     947         1309 :   TREE_SIDE_EFFECTS (init) = true;
     948         1309 :   SET_EXPR_LOCATION (init, input_location);
     949              : 
     950         1309 :   if (cxx_dialect >= cxx11)
     951              :     {
     952         1223 :       bool cx = potential_constant_expression (elt_init);
     953         1223 :       if (BRACE_ENCLOSED_INITIALIZER_P (init))
     954            0 :         cx &= potential_constant_expression (init);
     955         1223 :       VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
     956              :     }
     957         1309 :   VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
     958              : 
     959         1309 :   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         1126 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
     967              :                       vec<tree,va_gc> **flags)
     968              : {
     969         1126 :   iloc_sentinel ils = EXPR_LOCATION (vec_init);
     970              : 
     971         1126 :   if (!target)
     972            0 :     target = VEC_INIT_EXPR_SLOT (vec_init);
     973         1126 :   tree init = VEC_INIT_EXPR_INIT (vec_init);
     974         1126 :   int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
     975         3378 :   return build_vec_init (target, NULL_TREE, init,
     976         1126 :                          VEC_INIT_EXPR_VALUE_INIT (vec_init),
     977         1126 :                          from_array, complain, flags);
     978         1126 : }
     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      9994191 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
    1009              : {
    1010      9994191 :   gcc_assert (!VOID_TYPE_P (type));
    1011      9994191 :   gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
    1012              : 
    1013      9994191 :   if (TREE_CODE (init) == TARGET_EXPR
    1014      8812841 :       || init == error_mark_node)
    1015              :     return init;
    1016      6490155 :   else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
    1017        57604 :            && TREE_CODE (init) != COND_EXPR
    1018              :            && TREE_CODE (init) != CONSTRUCTOR
    1019              :            && TREE_CODE (init) != VA_ARG_EXPR
    1020      8812582 :            && 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      8812582 :   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     17841483 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
    1039              : {
    1040     17841483 :   tree slot;
    1041              : 
    1042     17841483 :   gcc_assert (!VOID_TYPE_P (type));
    1043              : 
    1044     17841483 :   slot = build_local_temp (type);
    1045     17841483 :   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      8053686 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
    1052              : {
    1053      8053686 :   if (TREE_CODE (init) == AGGR_INIT_EXPR)
    1054       589071 :     return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
    1055      7464615 :   else if (TREE_CODE (init) == VEC_INIT_EXPR)
    1056          427 :     return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
    1057              :   else
    1058              :     {
    1059      7464188 :       init = convert_bitfield_to_declared_type (init);
    1060      7464188 :       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      3132395 : get_internal_target_expr (tree init)
    1075              : {
    1076      3132395 :   init = convert_bitfield_to_declared_type (init);
    1077      3132395 :   tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
    1078      3132395 :   TARGET_EXPR_INTERNAL_P (t) = true;
    1079      3132395 :   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   1107468957 : convert_bitfield_to_declared_type (tree expr)
    1088              : {
    1089   1107468957 :   tree bitfield_type;
    1090              : 
    1091   1107468957 :   bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1092   1107468957 :   if (bitfield_type)
    1093       654303 :     expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
    1094              :                                       expr);
    1095   1107468957 :   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    195996254 : rvalue (tree expr)
    1103              : {
    1104    195996254 :   tree type;
    1105              : 
    1106    195996254 :   if (error_operand_p (expr))
    1107              :     return expr;
    1108              : 
    1109    195995854 :   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    195995854 :   type = TREE_TYPE (expr);
    1115    195995854 :   if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
    1116    388657976 :       && cv_qualified_p (type))
    1117     38561141 :     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    195995854 :   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     10597263 :       gcc_checking_assert (!CLASS_TYPE_P (type));
    1126     10597263 :       expr = build1 (NON_LVALUE_EXPR, type, expr);
    1127              :     }
    1128    185398591 :   else if (type != TREE_TYPE (expr))
    1129     38214696 :     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     39473541 : cplus_array_hasher::hash (tree t)
    1153              : {
    1154     39473541 :   hashval_t hash;
    1155              : 
    1156     39473541 :   hash = TYPE_UID (TREE_TYPE (t));
    1157     39473541 :   if (TYPE_DOMAIN (t))
    1158     35561521 :     hash ^= TYPE_UID (TYPE_DOMAIN (t));
    1159     39473541 :   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     48166565 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
    1167              : {
    1168     51076548 :   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      5604320 : build_min_array_type (tree elt_type, tree index_type)
    1179              : {
    1180      5604320 :   tree t = cxx_make_type (ARRAY_TYPE);
    1181      5604320 :   TREE_TYPE (t) = elt_type;
    1182      5604320 :   TYPE_DOMAIN (t) = index_type;
    1183      5604320 :   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      5604320 : 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      5604320 :   if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
    1194      5604320 :       || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
    1195      1413869 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1196      4190451 :   else if (TYPE_CANONICAL (elt_type) != elt_type
    1197      4190451 :            || (index_type && TYPE_CANONICAL (index_type) != index_type))
    1198      1238406 :     TYPE_CANONICAL (t)
    1199      3243373 :       = build_cplus_array_type (TYPE_CANONICAL (elt_type),
    1200              :                                 index_type
    1201       766561 :                                 ? TYPE_CANONICAL (index_type) : index_type,
    1202              :                                 dep);
    1203              :   else
    1204      2952045 :     TYPE_CANONICAL (t) = t;
    1205      5604320 : }
    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     69094240 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
    1214              : {
    1215     69094240 :   tree t;
    1216              : 
    1217     69094240 :   if (elt_type == error_mark_node || index_type == error_mark_node)
    1218              :     return error_mark_node;
    1219              : 
    1220     69094237 :   if (dependent < 0)
    1221     72043254 :     dependent = (uses_template_parms (elt_type)
    1222     36021627 :                  || (index_type && uses_template_parms (index_type)));
    1223              : 
    1224     69094237 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1225              :     /* Start with an array of the TYPE_MAIN_VARIANT.  */
    1226     29366811 :     t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
    1227              :                                 index_type, dependent);
    1228     39727426 :   else if (dependent)
    1229              :     {
    1230              :       /* Since type_hash_canon calls layout_type, we need to use our own
    1231              :          hash table.  */
    1232      4869921 :       cplus_array_info cai;
    1233      4869921 :       hashval_t hash;
    1234              : 
    1235      4869921 :       if (cplus_array_htab == NULL)
    1236        18356 :         cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
    1237              : 
    1238      4869921 :       hash = TYPE_UID (elt_type);
    1239      4869921 :       if (index_type)
    1240      2639089 :         hash ^= TYPE_UID (index_type);
    1241      4869921 :       cai.type = elt_type;
    1242      4869921 :       cai.domain = index_type;
    1243              : 
    1244      4869921 :       tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
    1245      4869921 :       if (*e)
    1246              :         /* We have found the type: we're done.  */
    1247      2807428 :         return (tree) *e;
    1248              :       else
    1249              :         {
    1250              :           /* Build a new array type.  */
    1251      2062493 :           t = build_min_array_type (elt_type, index_type);
    1252              : 
    1253              :           /* Store it in the hash table. */
    1254      2062493 :           *e = t;
    1255              : 
    1256              :           /* Set the canonical type for this new node.  */
    1257      2062493 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1258              : 
    1259              :           /* Mark it as dependent now, this saves time later.  */
    1260      2062493 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1261      2062493 :           TYPE_DEPENDENT_P (t) = true;
    1262              :         }
    1263              :     }
    1264              :   else
    1265              :     {
    1266     34857505 :       bool typeless_storage = is_byte_access_type (elt_type);
    1267     34857505 :       t = build_array_type (elt_type, index_type, typeless_storage);
    1268              : 
    1269              :       /* Mark as non-dependenty now, this will save time later.  */
    1270     34857505 :       TYPE_DEPENDENT_P_VALID (t) = true;
    1271              :     }
    1272              : 
    1273              :   /* Now check whether we already have this array variant.  */
    1274     66286809 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1275              :     {
    1276              :       tree m = t;
    1277     59682391 :       for (t = m; t; t = TYPE_NEXT_VARIANT (t))
    1278     56140564 :         if (TREE_TYPE (t) == elt_type
    1279     25835238 :             && TYPE_NAME (t) == NULL_TREE
    1280     25824987 :             && TYPE_ATTRIBUTES (t) == NULL_TREE
    1281     25824987 :             && (!TYPE_USER_ALIGN (t)
    1282        18753 :                 || (TYPE_USER_ALIGN (elt_type)
    1283        18750 :                     && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
    1284     25824984 :             && !TREE_DEPRECATED (t)
    1285     81965548 :             && !TREE_UNAVAILABLE (t))
    1286              :           break;
    1287     29366811 :       if (!t)
    1288              :         {
    1289      3541827 :           t = build_min_array_type (elt_type, index_type);
    1290              :           /* Mark dependency now, this saves time later.  */
    1291      3541827 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1292      3541827 :           TYPE_DEPENDENT_P (t) = dependent;
    1293      3541827 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1294      3541827 :           if (!dependent)
    1295              :             {
    1296      2934175 :               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      2934175 :               TYPE_SIZE (t) = TYPE_SIZE (m);
    1301      2934175 :               TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
    1302      2934175 :               TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
    1303              :             }
    1304              : 
    1305      3541827 :           TYPE_MAIN_VARIANT (t) = m;
    1306      3541827 :           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
    1307      3541827 :           TYPE_NEXT_VARIANT (m) = t;
    1308              :         }
    1309              :     }
    1310              : 
    1311              :   /* Avoid spurious warnings with VLAs (c++/54583).  */
    1312     66286809 :   if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
    1313         1997 :     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    132573618 :   bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
    1318     66286809 :                      = TYPE_NEEDS_CONSTRUCTING (elt_type));
    1319    132573618 :   bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1320     66286809 :                      = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
    1321              : 
    1322     63448510 :   if (!dependent && t == TYPE_MAIN_VARIANT (t)
    1323    101144314 :       && !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      2935250 :       layout_type (t);
    1329      4266437 :       for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    1330              :         {
    1331      1331187 :           TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
    1332      1331187 :           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      2287936 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
    1343              : {
    1344      2287936 :   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      7655810 : array_of_unknown_bound_p (const_tree t)
    1351              : {
    1352      7655810 :   return (TREE_CODE (t) == ARRAY_TYPE
    1353      7655810 :           && !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       609410 : array_of_runtime_bound_p (tree t)
    1363              : {
    1364       609410 :   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     44930587 : vla_type_p (tree t)
    1380              : {
    1381     45757466 :   for (; t && TREE_CODE (t) == ARRAY_TYPE;
    1382       826879 :        t = TREE_TYPE (t))
    1383       827058 :     if (tree dom = TYPE_DOMAIN (t))
    1384              :       {
    1385       826994 :         tree max = TYPE_MAX_VALUE (dom);
    1386       826994 :         if (!potential_rvalue_constant_expression (max)
    1387       826994 :             || (!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    663620869 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
    1401              : {
    1402    663620869 :   tree lvalue_ref, t;
    1403              : 
    1404    663620869 :   if (to_type == error_mark_node)
    1405              :     return error_mark_node;
    1406              : 
    1407    663620864 :   if (TYPE_REF_P (to_type))
    1408              :     {
    1409         2136 :       rval = rval && TYPE_REF_IS_RVALUE (to_type);
    1410         2136 :       to_type = TREE_TYPE (to_type);
    1411              :     }
    1412              : 
    1413    663620864 :   lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
    1414              : 
    1415    663620864 :   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    114535131 :   for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
    1427     85137011 :     if (TYPE_REF_IS_RVALUE (t))
    1428              :       return t;
    1429              : 
    1430     29398120 :   t = build_distinct_type_copy (lvalue_ref);
    1431              : 
    1432     29398120 :   TYPE_REF_IS_RVALUE (t) = true;
    1433     29398120 :   TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
    1434     29398120 :   TYPE_NEXT_REF_TO (lvalue_ref) = t;
    1435              : 
    1436     29398120 :   if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
    1437      1032336 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1438     28365784 :   else if (TYPE_CANONICAL (to_type) != to_type)
    1439     16148433 :     TYPE_CANONICAL (t)
    1440     32296866 :       = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
    1441              :   else
    1442     12217351 :     TYPE_CANONICAL (t) = t;
    1443              : 
    1444     29398120 :   layout_type (t);
    1445              : 
    1446     29398120 :   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    543932294 : cp_build_reference_type (tree to_type, bool rval)
    1456              : {
    1457    543932294 :   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      2215765 : move (tree expr)
    1464              : {
    1465      2215765 :   tree type = TREE_TYPE (expr);
    1466      2215765 :   gcc_assert (!TYPE_REF_P (type));
    1467      2215765 :   if (xvalue_p (expr))
    1468              :     return expr;
    1469      2215533 :   type = cp_build_reference_type (type, /*rval*/true);
    1470      2215533 :   return build_static_cast (input_location, type, expr,
    1471      2215533 :                             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     27998538 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
    1479              :                         size_t /* orig_qual_indirect */)
    1480              : {
    1481     27998538 :   return cp_build_qualified_type (type, type_quals);
    1482              : }
    1483              : 
    1484              : 
    1485              : /* Make a variant of TYPE, qualified with the TYPE_QUALS.  Handles
    1486              :    arrays correctly.  In particular, if TYPE is an array of T's, and
    1487              :    TYPE_QUALS is non-empty, returns an array of qualified T's.
    1488              : 
    1489              :    FLAGS determines how to deal with ill-formed qualifications. If
    1490              :    tf_ignore_bad_quals is set, then bad qualifications are dropped
    1491              :    (this is permitted if TYPE was introduced via a typedef or template
    1492              :    type parameter). If bad qualifications are dropped and tf_warning
    1493              :    is set, then a warning is issued for non-const qualifications.  If
    1494              :    tf_ignore_bad_quals is not set and tf_error is not set, we
    1495              :    return error_mark_node. Otherwise, we issue an error, and ignore
    1496              :    the qualifications.
    1497              : 
    1498              :    Qualification of a reference type is valid when the reference came
    1499              :    via a typedef or template type argument. [dcl.ref] No such
    1500              :    dispensation is provided for qualifying a function type.  [dcl.fct]
    1501              :    DR 295 queries this and the proposed resolution brings it into line
    1502              :    with qualifying a reference.  We implement the DR.  We also behave
    1503              :    in a similar manner for restricting non-pointer types.  */
    1504              : 
    1505              : tree
    1506  19332884487 : cp_build_qualified_type (tree type, int type_quals,
    1507              :                          tsubst_flags_t complain /* = tf_warning_or_error */)
    1508              : {
    1509  19332884487 :   tree result;
    1510  19332884487 :   int bad_quals = TYPE_UNQUALIFIED;
    1511              : 
    1512  19332884487 :   if (type == error_mark_node)
    1513              :     return type;
    1514              : 
    1515  19295065372 :   if (type_quals == cp_type_quals (type))
    1516              :     return type;
    1517              : 
    1518   3333362725 :   if (TREE_CODE (type) == ARRAY_TYPE)
    1519              :     {
    1520              :       /* In C++, the qualification really applies to the array element
    1521              :          type.  Obtain the appropriately qualified element type.  */
    1522     34432926 :       tree t;
    1523     34432926 :       tree element_type
    1524     34432926 :         = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
    1525              : 
    1526     34432926 :       if (element_type == error_mark_node)
    1527              :         return error_mark_node;
    1528              : 
    1529              :       /* See if we already have an identically qualified type.  Tests
    1530              :          should be equivalent to those in check_qualified_type.  */
    1531     65616466 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    1532     38579761 :         if (TREE_TYPE (t) == element_type
    1533      7939810 :             && TYPE_NAME (t) == TYPE_NAME (type)
    1534      7396221 :             && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
    1535     45975982 :             && attribute_list_equal (TYPE_ATTRIBUTES (t),
    1536      7396221 :                                      TYPE_ATTRIBUTES (type)))
    1537              :           break;
    1538              : 
    1539     34432926 :       if (!t)
    1540              :         {
    1541              :           /* If we already know the dependentness, tell the array type
    1542              :              constructor.  This is important for module streaming, as we cannot
    1543              :              dynamically determine that on read in.  */
    1544     27036705 :           t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
    1545     27036705 :                                       TYPE_DEPENDENT_P_VALID (type)
    1546       571573 :                                       ? int (TYPE_DEPENDENT_P (type)) : -1);
    1547              : 
    1548              :           /* Keep the typedef name.  */
    1549     27036705 :           if (TYPE_NAME (t) != TYPE_NAME (type))
    1550              :             {
    1551        14402 :               t = build_variant_type_copy (t);
    1552        14402 :               TYPE_NAME (t) = TYPE_NAME (type);
    1553        14402 :               SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
    1554        14402 :               TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type);
    1555              :             }
    1556              :         }
    1557              : 
    1558              :       /* Even if we already had this variant, we update
    1559              :          TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case
    1560              :          they changed since the variant was originally created.
    1561              : 
    1562              :          This seems hokey; if there is some way to use a previous
    1563              :          variant *without* coming through here,
    1564              :          TYPE_NEEDS_CONSTRUCTING will never be updated.  */
    1565     68865852 :       TYPE_NEEDS_CONSTRUCTING (t)
    1566     34432926 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
    1567     68865852 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1568     34432926 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
    1569     34432926 :       return t;
    1570              :     }
    1571   3298929799 :   else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
    1572              :     {
    1573            7 :       tree t = PACK_EXPANSION_PATTERN (type);
    1574              : 
    1575            7 :       t = cp_build_qualified_type (t, type_quals, complain);
    1576            7 :       return make_pack_expansion (t, complain);
    1577              :     }
    1578              : 
    1579              :   /* A reference or method type shall not be cv-qualified.
    1580              :      [dcl.ref], [dcl.fct].  This used to be an error, but as of DR 295
    1581              :      (in CD1) we always ignore extra cv-quals on functions.  */
    1582              : 
    1583              :   /* [dcl.ref/1] Cv-qualified references are ill-formed except when
    1584              :      the cv-qualifiers are introduced through the use of a typedef-name
    1585              :      ([dcl.typedef], [temp.param]) or decltype-specifier
    1586              :      ([dcl.type.decltype]),in which case the cv-qualifiers are
    1587              :      ignored.  */
    1588   3298929792 :   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
    1589   1037024260 :       && (TYPE_REF_P (type)
    1590   1036592189 :           || FUNC_OR_METHOD_TYPE_P (type)))
    1591              :     {
    1592       432898 :       if (TYPE_REF_P (type)
    1593       432898 :           && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
    1594              :         bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1595       432898 :       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1596              :     }
    1597              : 
    1598              :   /* But preserve any function-cv-quals on a FUNCTION_TYPE.  */
    1599   3298929792 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    1600          830 :     type_quals |= type_memfn_quals (type);
    1601              : 
    1602              :   /* A restrict-qualified type must be a pointer (or reference)
    1603              :      to object or incomplete type. */
    1604   3298929792 :   if ((type_quals & TYPE_QUAL_RESTRICT)
    1605      9014955 :       && TREE_CODE (type) != TEMPLATE_TYPE_PARM
    1606      9014918 :       && TREE_CODE (type) != TYPENAME_TYPE
    1607      9014912 :       && !INDIRECT_TYPE_P (type))
    1608              :     {
    1609           25 :       bad_quals |= TYPE_QUAL_RESTRICT;
    1610           25 :       type_quals &= ~TYPE_QUAL_RESTRICT;
    1611              :     }
    1612              : 
    1613   3298929792 :   if (bad_quals == TYPE_UNQUALIFIED
    1614       295113 :       || (complain & tf_ignore_bad_quals))
    1615              :     /*OK*/;
    1616           12 :   else if (!(complain & tf_error))
    1617            0 :     return error_mark_node;
    1618              :   else
    1619              :     {
    1620           12 :       tree bad_type = build_qualified_type (ptr_type_node, bad_quals);
    1621           12 :       error ("%qV qualifiers cannot be applied to %qT",
    1622              :              bad_type, type);
    1623              :     }
    1624              : 
    1625              :   /* Retrieve (or create) the appropriately qualified variant.  */
    1626   3298929792 :   result = build_qualified_type (type, type_quals);
    1627              : 
    1628   3298929792 :   return result;
    1629              : }
    1630              : 
    1631              : /* Return a FUNCTION_TYPE for a function returning VALUE_TYPE
    1632              :    with ARG_TYPES arguments.  Wrapper around build_function_type
    1633              :    which ensures TYPE_NO_NAMED_ARGS_STDARG_P is set if ARG_TYPES
    1634              :    is NULL for C++26.  */
    1635              : 
    1636              : tree
    1637    279389330 : cp_build_function_type (tree value_type, tree arg_types)
    1638              : {
    1639    313366157 :   return build_function_type (value_type, arg_types,
    1640    279389330 :                               cxx_dialect >= cxx26
    1641    279389330 :                               && arg_types == NULL_TREE);
    1642              : }
    1643              : 
    1644              : /* Return TYPE with const and volatile removed.  */
    1645              : 
    1646              : tree
    1647   1807084538 : cv_unqualified (tree type)
    1648              : {
    1649   1807084538 :   int quals;
    1650              : 
    1651   1807084538 :   if (type == error_mark_node)
    1652              :     return type;
    1653              : 
    1654   1807084293 :   quals = cp_type_quals (type);
    1655   1807084293 :   quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
    1656   1807084293 :   return cp_build_qualified_type (type, quals);
    1657              : }
    1658              : 
    1659              : /* Subroutine of strip_typedefs.  We want to apply to RESULT the attributes
    1660              :    from ATTRIBS that affect type identity, and no others.  If any are not
    1661              :    applied, set *remove_attributes to true.  */
    1662              : 
    1663              : static tree
    1664      9891199 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
    1665              : {
    1666      9891199 :   tree first_ident = NULL_TREE;
    1667      9891199 :   tree new_attribs = NULL_TREE;
    1668      9891199 :   tree *p = &new_attribs;
    1669              : 
    1670      9891199 :   if (OVERLOAD_TYPE_P (result))
    1671              :     {
    1672              :       /* On classes and enums all attributes are ingrained.  */
    1673      9890208 :       gcc_assert (attribs == TYPE_ATTRIBUTES (result));
    1674              :       return result;
    1675              :     }
    1676              : 
    1677         1985 :   for (tree a = attribs; a; a = TREE_CHAIN (a))
    1678              :     {
    1679          994 :       const attribute_spec *as
    1680          994 :         = lookup_attribute_spec (get_attribute_name (a));
    1681          994 :       if (as && as->affects_type_identity)
    1682              :         {
    1683          178 :           if (!first_ident)
    1684              :             first_ident = a;
    1685            0 :           else if (first_ident == error_mark_node)
    1686              :             {
    1687            0 :               *p = tree_cons (TREE_PURPOSE (a), TREE_VALUE (a), NULL_TREE);
    1688            0 :               p = &TREE_CHAIN (*p);
    1689              :             }
    1690              :         }
    1691          816 :       else if (first_ident && first_ident != error_mark_node)
    1692              :         {
    1693            0 :           for (tree a2 = first_ident; a2 != a; a2 = TREE_CHAIN (a2))
    1694              :             {
    1695            0 :               *p = tree_cons (TREE_PURPOSE (a2), TREE_VALUE (a2), NULL_TREE);
    1696            0 :               p = &TREE_CHAIN (*p);
    1697              :             }
    1698            0 :           first_ident = error_mark_node;
    1699              :         }
    1700              :     }
    1701          991 :   if (first_ident != error_mark_node)
    1702          991 :     new_attribs = first_ident;
    1703              : 
    1704          991 :   if (first_ident == attribs)
    1705              :     /* All attributes affected type identity.  */;
    1706              :   else
    1707          813 :     *remove_attributes = true;
    1708              : 
    1709          991 :   return cp_build_type_attribute_variant (result, new_attribs);
    1710              : }
    1711              : 
    1712              : /* Builds a qualified variant of T that is either not a typedef variant
    1713              :    (the default behavior) or not a typedef variant of a user-facing type
    1714              :    (if FLAGS contains STF_USER_VISIBLE).  If T is not a type, then this
    1715              :    just dispatches to strip_typedefs_expr.
    1716              : 
    1717              :    E.g. consider the following declarations:
    1718              :      typedef const int ConstInt;
    1719              :      typedef ConstInt* PtrConstInt;
    1720              :    If T is PtrConstInt, this function returns a type representing
    1721              :      const int*.
    1722              :    In other words, if T is a typedef, the function returns the underlying type.
    1723              :    The cv-qualification and attributes of the type returned match the
    1724              :    input type.
    1725              :    They will always be compatible types.
    1726              :    The returned type is built so that all of its subtypes
    1727              :    recursively have their typedefs stripped as well.
    1728              : 
    1729              :    This is different from just returning TYPE_CANONICAL (T)
    1730              :    Because of several reasons:
    1731              :     * If T is a type that needs structural equality
    1732              :       its TYPE_CANONICAL (T) will be NULL.
    1733              :     * TYPE_CANONICAL (T) doesn't carry type attributes
    1734              :       and loses template parameter names.
    1735              : 
    1736              :    If REMOVE_ATTRIBUTES is non-null, also strip attributes that don't
    1737              :    affect type identity, and set the referent to true if any were
    1738              :    stripped.  */
    1739              : 
    1740              : tree
    1741   3062049950 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
    1742              :                 unsigned int flags /* = 0 */)
    1743              : {
    1744   3062049950 :   tree result = NULL, type = NULL, t0 = NULL;
    1745              : 
    1746   3062049950 :   if (!t || t == error_mark_node)
    1747              :     return t;
    1748              : 
    1749   3021285496 :   if (!TYPE_P (t))
    1750    207137559 :     return strip_typedefs_expr (t, remove_attributes, flags);
    1751              : 
    1752   2814147937 :   if (t == TYPE_CANONICAL (t))
    1753              :     return t;
    1754              : 
    1755   1096190754 :   if (typedef_variant_p (t))
    1756              :     {
    1757    365677172 :       if ((flags & STF_USER_VISIBLE)
    1758    365677172 :           && !user_facing_original_type_p (t))
    1759              :         return t;
    1760              : 
    1761    365677044 :       if ((flags & STF_KEEP_INJ_CLASS_NAME)
    1762        35892 :           && CLASS_TYPE_P (t)
    1763    365686941 :           && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
    1764              :         return t;
    1765              : 
    1766    365677043 :       if (dependent_opaque_alias_p (t))
    1767              :         return t;
    1768              : 
    1769    365672173 :       if (alias_template_specialization_p (t, nt_opaque))
    1770              :         {
    1771    105421729 :           if (dependent_alias_template_spec_p (t, nt_opaque)
    1772    105421729 :               && !(flags & STF_STRIP_DEPENDENT))
    1773              :             /* DR 1558: However, if the template-id is dependent, subsequent
    1774              :                template argument substitution still applies to the template-id.  */
    1775              :             return t;
    1776              :         }
    1777              :       else
    1778              :         /* If T is a non-template alias or typedef, we can assume that
    1779              :            instantiating its definition will hit any substitution failure,
    1780              :            so we don't need to retain it here as well.  */
    1781    260250444 :         flags |= STF_STRIP_DEPENDENT;
    1782              : 
    1783    350455121 :       result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
    1784              :                                remove_attributes, flags);
    1785    350455121 :       goto stripped;
    1786              :     }
    1787              : 
    1788    730513582 :   switch (TREE_CODE (t))
    1789              :     {
    1790     11198065 :     case POINTER_TYPE:
    1791     11198065 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1792     11198065 :       result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
    1793     11198065 :       break;
    1794    103540142 :     case REFERENCE_TYPE:
    1795    103540142 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1796    103540142 :       result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
    1797    103540142 :       break;
    1798       331949 :     case OFFSET_TYPE:
    1799       331949 :       t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
    1800       331949 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1801       331949 :       result = build_offset_type (t0, type);
    1802       331949 :       break;
    1803     26475669 :     case RECORD_TYPE:
    1804     26475669 :       if (TYPE_PTRMEMFUNC_P (t))
    1805              :         {
    1806      1597749 :           t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
    1807              :                                remove_attributes, flags);
    1808      1597749 :           result = build_ptrmemfunc_type (t0);
    1809              :         }
    1810              :       break;
    1811      1874326 :     case ARRAY_TYPE:
    1812      1874326 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1813      1874326 :       t0  = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
    1814      1874326 :       gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
    1815              :                            || !dependent_type_p (t));
    1816      1874326 :       result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
    1817      1874326 :       break;
    1818      8102023 :     case FUNCTION_TYPE:
    1819      8102023 :     case METHOD_TYPE:
    1820      8102023 :       {
    1821      8102023 :         tree arg_types = NULL, arg_node, arg_node2, arg_type;
    1822      8102023 :         bool changed;
    1823              : 
    1824              :         /* Because we stomp on TREE_PURPOSE of TYPE_ARG_TYPES in many places
    1825              :            around the compiler (e.g. cp_parser_late_parsing_default_args), we
    1826              :            can't expect that re-hashing a function type will find a previous
    1827              :            equivalent type, so try to reuse the input type if nothing has
    1828              :            changed.  If the type is itself a variant, that will change.  */
    1829      8102023 :         bool is_variant = typedef_variant_p (t);
    1830      8102023 :         if (remove_attributes
    1831      8102023 :             && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
    1832              :           is_variant = true;
    1833              : 
    1834      8102023 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1835      8102023 :         tree canon_spec = (flag_noexcept_type
    1836      8091194 :                            ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
    1837      8102023 :                            : NULL_TREE);
    1838     10741303 :         changed = (type != TREE_TYPE (t) || is_variant
    1839     10741100 :                    || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
    1840              : 
    1841      8102023 :         for (arg_node = TYPE_ARG_TYPES (t);
    1842     12521159 :              arg_node;
    1843      4419136 :              arg_node = TREE_CHAIN (arg_node))
    1844              :           {
    1845     11706759 :             if (arg_node == void_list_node)
    1846              :               break;
    1847      4419136 :             arg_type = strip_typedefs (TREE_VALUE (arg_node),
    1848              :                                        remove_attributes, flags);
    1849      4419136 :             gcc_assert (arg_type);
    1850      4419136 :             if (arg_type == TREE_VALUE (arg_node) && !changed)
    1851      4155540 :               continue;
    1852              : 
    1853       263596 :             if (!changed)
    1854              :               {
    1855        40486 :                 changed = true;
    1856        40486 :                 for (arg_node2 = TYPE_ARG_TYPES (t);
    1857        51363 :                      arg_node2 != arg_node;
    1858        10877 :                      arg_node2 = TREE_CHAIN (arg_node2))
    1859        10877 :                   arg_types
    1860        10877 :                     = tree_cons (TREE_PURPOSE (arg_node2),
    1861        10877 :                                  TREE_VALUE (arg_node2), arg_types);
    1862              :               }
    1863              : 
    1864       263596 :             arg_types
    1865       263596 :               = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
    1866              :           }
    1867              : 
    1868      8102023 :         if (!changed)
    1869              :           return t;
    1870              : 
    1871      5504875 :         if (arg_types)
    1872        62942 :           arg_types = nreverse (arg_types);
    1873              : 
    1874              :         /* A list of parameters not ending with an ellipsis
    1875              :            must end with void_list_node.  */
    1876      5504875 :         if (arg_node)
    1877      5504834 :           arg_types = chainon (arg_types, void_list_node);
    1878              : 
    1879      5504875 :         if (TREE_CODE (t) == METHOD_TYPE)
    1880              :           {
    1881        28639 :             tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
    1882        28639 :             gcc_assert (class_type);
    1883        28639 :             result =
    1884        28639 :               build_method_type_directly (class_type, type,
    1885        28639 :                                           TREE_CHAIN (arg_types));
    1886              :           }
    1887              :         else
    1888              :           {
    1889     16428708 :             result = build_function_type (type, arg_types,
    1890      5476236 :                                           TYPE_NO_NAMED_ARGS_STDARG_P (t));
    1891      5476236 :             result = apply_memfn_quals (result, type_memfn_quals (t));
    1892              :           }
    1893              : 
    1894     16514625 :         result = build_cp_fntype_variant (result,
    1895              :                                           type_memfn_rqual (t), canon_spec,
    1896      5504875 :                                           TYPE_HAS_LATE_RETURN_TYPE (t));
    1897              :       }
    1898      5504875 :       break;
    1899     79725977 :     case TYPENAME_TYPE:
    1900     79725977 :       {
    1901     79725977 :         bool changed = false;
    1902     79725977 :         tree fullname = TYPENAME_TYPE_FULLNAME (t);
    1903     79725977 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
    1904     79725977 :             && TREE_OPERAND (fullname, 1))
    1905              :           {
    1906      4965849 :             tree args = TREE_OPERAND (fullname, 1);
    1907      4965849 :             tree new_args = copy_node (args);
    1908     18741333 :             for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
    1909              :               {
    1910      8809635 :                 tree arg = TREE_VEC_ELT (args, i);
    1911      8809635 :                 tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
    1912      8809635 :                 TREE_VEC_ELT (new_args, i) = strip_arg;
    1913      8809635 :                 if (strip_arg != arg)
    1914       257803 :                   changed = true;
    1915              :               }
    1916      4965849 :             if (changed)
    1917              :               {
    1918       257803 :                 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
    1919       257803 :                   = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
    1920       257803 :                 fullname
    1921       257803 :                   = lookup_template_function (TREE_OPERAND (fullname, 0),
    1922              :                                               new_args);
    1923              :               }
    1924              :             else
    1925      4708046 :               ggc_free (new_args);
    1926              :           }
    1927     79725977 :         tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
    1928     79725977 :         if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
    1929              :           return t;
    1930      4888112 :         tree name = fullname;
    1931      4888112 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
    1932       282373 :           name = TREE_OPERAND (fullname, 0);
    1933              :         /* Use build_typename_type rather than make_typename_type because we
    1934              :            don't want to resolve it here, just strip typedefs.  */
    1935      4888112 :         result = build_typename_type (ctx, name, fullname, typename_type);
    1936              :       }
    1937      4888112 :       break;
    1938     13707463 :     case DECLTYPE_TYPE:
    1939     13707463 :       result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
    1940              :                                     remove_attributes, flags);
    1941     13707463 :       if (result == DECLTYPE_TYPE_EXPR (t))
    1942              :         result = NULL_TREE;
    1943              :       else
    1944       383198 :         result = (finish_decltype_type
    1945       383198 :                   (result,
    1946       383198 :                    DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
    1947              :                    tf_none));
    1948              :       break;
    1949       861837 :     case TRAIT_TYPE:
    1950       861837 :       {
    1951       861837 :         tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
    1952              :                                      remove_attributes, flags);
    1953       861837 :         tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
    1954              :                                      remove_attributes, flags);
    1955       861837 :         if (type1 == TRAIT_TYPE_TYPE1 (t) && type2 == TRAIT_TYPE_TYPE2 (t))
    1956              :           result = NULL_TREE;
    1957              :         else
    1958            0 :           result = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2,
    1959              :                                       tf_warning_or_error);
    1960              :       }
    1961              :       break;
    1962     25211462 :     case TYPE_PACK_EXPANSION:
    1963     25211462 :       {
    1964     25211462 :         tree pat = PACK_EXPANSION_PATTERN (t);
    1965     25211462 :         if (TYPE_P (pat))
    1966              :           {
    1967     25211462 :             type = strip_typedefs (pat, remove_attributes, flags);
    1968     25211462 :             if (type != pat)
    1969              :               {
    1970       310792 :                 result = build_distinct_type_copy (t);
    1971       310792 :                 PACK_EXPANSION_PATTERN (result) = type;
    1972              :               }
    1973              :           }
    1974              :       }
    1975              :       break;
    1976              :     default:
    1977              :       break;
    1978              :     }
    1979              : 
    1980    129629208 :   if (!result)
    1981    523449361 :     result = TYPE_MAIN_VARIANT (t);
    1982              : 
    1983    129629208 : stripped:
    1984              :   /*gcc_assert (!typedef_variant_p (result)
    1985              :               || dependent_alias_template_spec_p (result, nt_opaque)
    1986              :               || ((flags & STF_USER_VISIBLE)
    1987              :                   && !user_facing_original_type_p (result)));*/
    1988              : 
    1989   1003533690 :   if (COMPLETE_TYPE_P (result) && !COMPLETE_TYPE_P (t))
    1990              :   /* If RESULT is complete and T isn't, it's likely the case that T
    1991              :      is a variant of RESULT which hasn't been updated yet.  Skip the
    1992              :      attribute handling.  */;
    1993              :   else
    1994              :     {
    1995   1003533684 :       if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
    1996   1003533684 :           || TYPE_ALIGN (t) != TYPE_ALIGN (result))
    1997              :         {
    1998           21 :           gcc_assert (TYPE_USER_ALIGN (t));
    1999           21 :           if (remove_attributes)
    2000           12 :             *remove_attributes = true;
    2001              :           else
    2002              :             {
    2003            9 :               if (TYPE_ALIGN (t) == TYPE_ALIGN (result))
    2004            0 :                 result = build_variant_type_copy (result);
    2005              :               else
    2006            9 :                 result = build_aligned_type (result, TYPE_ALIGN (t));
    2007            9 :               TYPE_USER_ALIGN (result) = true;
    2008              :             }
    2009              :         }
    2010              : 
    2011   1003533684 :       if (TYPE_ATTRIBUTES (t))
    2012              :         {
    2013      9901376 :           if (remove_attributes)
    2014      9891199 :             result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
    2015              :                                                 remove_attributes);
    2016              :           else
    2017        10177 :             result = cp_build_type_attribute_variant (result,
    2018        10177 :                                                       TYPE_ATTRIBUTES (t));
    2019              :         }
    2020              :     }
    2021              : 
    2022   1003533690 :   return cp_build_qualified_type (result, cp_type_quals (t));
    2023              : }
    2024              : 
    2025              : /* Like strip_typedefs above, but works on expressions (and other
    2026              :    non-types such as TREE_VEC), so that in
    2027              : 
    2028              :    template<class T> struct A
    2029              :    {
    2030              :      typedef T TT;
    2031              :      B<sizeof(TT)> b;
    2032              :    };
    2033              : 
    2034              :    sizeof(TT) is replaced by sizeof(T).  */
    2035              : 
    2036              : tree
    2037    396987075 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
    2038              : {
    2039    396987075 :   unsigned i,n;
    2040    396987075 :   tree r, type, *ops;
    2041    396987075 :   enum tree_code code;
    2042              : 
    2043    396987075 :   if (t == NULL_TREE || t == error_mark_node)
    2044              :     return t;
    2045              : 
    2046    396987075 :   STRIP_ANY_LOCATION_WRAPPER (t);
    2047              : 
    2048    396987075 :   if (DECL_P (t) || CONSTANT_CLASS_P (t))
    2049              :     return t;
    2050              : 
    2051    220936202 :   code = TREE_CODE (t);
    2052    220936202 :   switch (code)
    2053              :     {
    2054              :     case IDENTIFIER_NODE:
    2055              :     case TEMPLATE_PARM_INDEX:
    2056              :     case OVERLOAD:
    2057              :     case BASELINK:
    2058              :     case ARGUMENT_PACK_SELECT:
    2059              :     case REQUIRES_EXPR:
    2060              :       return t;
    2061              : 
    2062      2448765 :     case TRAIT_EXPR:
    2063      2448765 :       {
    2064      2448765 :         tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
    2065              :                                      remove_attributes, flags);
    2066      2448765 :         tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
    2067              :                                      remove_attributes, flags);
    2068      2448765 :         if (type1 == TRAIT_EXPR_TYPE1 (t)
    2069      2448765 :             && type2 == TRAIT_EXPR_TYPE2 (t))
    2070              :           return t;
    2071        55105 :         r = copy_node (t);
    2072        55105 :         TRAIT_EXPR_TYPE1 (r) = type1;
    2073        55105 :         TRAIT_EXPR_TYPE2 (r) = type2;
    2074        55105 :         return r;
    2075              :       }
    2076              : 
    2077      1037327 :     case TREE_LIST:
    2078      1037327 :       {
    2079      1037327 :         bool changed = false;
    2080      1037327 :         auto_vec<tree_pair, 4> vec;
    2081      1037327 :         r = t;
    2082      2216182 :         for (; t; t = TREE_CHAIN (t))
    2083              :           {
    2084      1178855 :             tree purpose = strip_typedefs (TREE_PURPOSE (t),
    2085      1178855 :                                            remove_attributes, flags);
    2086      1178855 :             tree value = strip_typedefs (TREE_VALUE (t),
    2087      1178855 :                                          remove_attributes, flags);
    2088      1178855 :             if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
    2089              :               changed = true;
    2090      1178855 :             vec.safe_push ({purpose, value});
    2091              :           }
    2092      1037327 :         if (changed)
    2093              :           {
    2094       249184 :             r = NULL_TREE;
    2095       814941 :             for (int i = vec.length () - 1; i >= 0; i--)
    2096       316573 :               r = tree_cons (vec[i].first, vec[i].second, r);
    2097              :           }
    2098      1037327 :         return r;
    2099      1037327 :       }
    2100              : 
    2101     21428443 :     case TREE_VEC:
    2102     21428443 :       {
    2103     21428443 :         bool changed = false;
    2104     21428443 :         releasing_vec vec;
    2105     21428443 :         n = TREE_VEC_LENGTH (t);
    2106     21428443 :         vec_safe_reserve (vec, n);
    2107     67459173 :         for (i = 0; i < n; ++i)
    2108              :           {
    2109     24602287 :             tree op = strip_typedefs (TREE_VEC_ELT (t, i),
    2110     24602287 :                                       remove_attributes, flags);
    2111     24602287 :             vec->quick_push (op);
    2112     24602287 :             if (op != TREE_VEC_ELT (t, i))
    2113       219076 :               changed = true;
    2114              :           }
    2115     21428443 :         if (changed)
    2116              :           {
    2117       219076 :             r = copy_node (t);
    2118       677749 :             for (i = 0; i < n; ++i)
    2119       239597 :               TREE_VEC_ELT (r, i) = (*vec)[i];
    2120       438152 :             NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
    2121       438152 :               = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
    2122              :           }
    2123              :         else
    2124              :           r = t;
    2125     21428443 :         return r;
    2126     21428443 :       }
    2127              : 
    2128       317515 :     case CONSTRUCTOR:
    2129       317515 :       {
    2130       317515 :         bool changed = false;
    2131       317515 :         vec<constructor_elt, va_gc> *vec
    2132       317515 :           = vec_safe_copy (CONSTRUCTOR_ELTS (t));
    2133       317515 :         n = CONSTRUCTOR_NELTS (t);
    2134       317515 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    2135       655839 :         for (i = 0; i < n; ++i)
    2136              :           {
    2137        20809 :             constructor_elt *e = &(*vec)[i];
    2138        20809 :             tree op = strip_typedefs (e->value, remove_attributes, flags);
    2139        20809 :             if (op != e->value)
    2140              :               {
    2141            6 :                 changed = true;
    2142            6 :                 e->value = op;
    2143              :               }
    2144        20809 :             gcc_checking_assert
    2145              :               (e->index == strip_typedefs (e->index, remove_attributes,
    2146              :                                            flags));
    2147              :           }
    2148              : 
    2149       317515 :         if (!changed && type == TREE_TYPE (t))
    2150              :           {
    2151       294362 :             vec_free (vec);
    2152              :             return t;
    2153              :           }
    2154              :         else
    2155              :           {
    2156        23153 :             r = copy_node (t);
    2157        23153 :             TREE_TYPE (r) = type;
    2158        23153 :             CONSTRUCTOR_ELTS (r) = vec;
    2159        23153 :             return r;
    2160              :           }
    2161              :       }
    2162              : 
    2163              :     case LAMBDA_EXPR:
    2164              :     case STMT_EXPR:
    2165              :     /* ^^alias represents the alias itself, not the underlying type.  */
    2166              :     case REFLECT_EXPR:
    2167              :       return t;
    2168              : 
    2169    118381955 :     default:
    2170    118381955 :       break;
    2171              :     }
    2172              : 
    2173    118381955 :   gcc_assert (EXPR_P (t));
    2174              : 
    2175    118381955 :   n = cp_tree_operand_length (t);
    2176    118381955 :   ops = XALLOCAVEC (tree, n);
    2177    118381955 :   type = TREE_TYPE (t);
    2178              : 
    2179    118381955 :   switch (code)
    2180              :     {
    2181      7960532 :     CASE_CONVERT:
    2182      7960532 :     case IMPLICIT_CONV_EXPR:
    2183      7960532 :     case DYNAMIC_CAST_EXPR:
    2184      7960532 :     case STATIC_CAST_EXPR:
    2185      7960532 :     case CONST_CAST_EXPR:
    2186      7960532 :     case REINTERPRET_CAST_EXPR:
    2187      7960532 :     case CAST_EXPR:
    2188      7960532 :     case NEW_EXPR:
    2189      7960532 :       type = strip_typedefs (type, remove_attributes, flags);
    2190              :       /* fallthrough */
    2191              : 
    2192    118381955 :     default:
    2193    389761977 :       for (i = 0; i < n; ++i)
    2194    271380022 :         ops[i] = strip_typedefs (TREE_OPERAND (t, i),
    2195              :                                  remove_attributes, flags);
    2196              :       break;
    2197              :     }
    2198              : 
    2199              :   /* If nothing changed, return t.  */
    2200    383534895 :   for (i = 0; i < n; ++i)
    2201    269201535 :     if (ops[i] != TREE_OPERAND (t, i))
    2202              :       break;
    2203    118381955 :   if (i == n && type == TREE_TYPE (t))
    2204              :     return t;
    2205              : 
    2206      4325029 :   r = copy_node (t);
    2207      4325029 :   TREE_TYPE (r) = type;
    2208     13752774 :   for (i = 0; i < n; ++i)
    2209      9427745 :     TREE_OPERAND (r, i) = ops[i];
    2210              :   return r;
    2211              : }
    2212              : 
    2213              : /* Makes a copy of BINFO and TYPE, which is to be inherited into a
    2214              :    graph dominated by T.  If BINFO is NULL, TYPE is a dependent base,
    2215              :    and we do a shallow copy.  If BINFO is non-NULL, we do a deep copy.
    2216              :    VIRT indicates whether TYPE is inherited virtually or not.
    2217              :    IGO_PREV points at the previous binfo of the inheritance graph
    2218              :    order chain.  The newly copied binfo's TREE_CHAIN forms this
    2219              :    ordering.
    2220              : 
    2221              :    The CLASSTYPE_VBASECLASSES vector of T is constructed in the
    2222              :    correct order. That is in the order the bases themselves should be
    2223              :    constructed in.
    2224              : 
    2225              :    The BINFO_INHERITANCE of a virtual base class points to the binfo
    2226              :    of the most derived type. ??? We could probably change this so that
    2227              :    BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence
    2228              :    remove a field.  They currently can only differ for primary virtual
    2229              :    virtual bases.  */
    2230              : 
    2231              : tree
    2232     38787928 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
    2233              : {
    2234     38787928 :   tree new_binfo;
    2235              : 
    2236     38787928 :   if (virt)
    2237              :     {
    2238              :       /* See if we've already made this virtual base.  */
    2239       295410 :       new_binfo = binfo_for_vbase (type, t);
    2240       295410 :       if (new_binfo)
    2241              :         return new_binfo;
    2242              :     }
    2243              : 
    2244     70181681 :   new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
    2245     38716771 :   BINFO_TYPE (new_binfo) = type;
    2246              : 
    2247              :   /* Chain it into the inheritance graph.  */
    2248     38716771 :   TREE_CHAIN (*igo_prev) = new_binfo;
    2249     38716771 :   *igo_prev = new_binfo;
    2250              : 
    2251     70181681 :   if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
    2252              :     {
    2253     31464901 :       int ix;
    2254     31464901 :       tree base_binfo;
    2255              : 
    2256     31464901 :       gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
    2257              : 
    2258     31464901 :       BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
    2259     31464901 :       BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
    2260              : 
    2261              :       /* We do not need to copy the accesses, as they are read only.  */
    2262     31464901 :       BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
    2263              : 
    2264              :       /* Recursively copy base binfos of BINFO.  */
    2265     35833934 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    2266              :         {
    2267      4369033 :           tree new_base_binfo;
    2268      4369033 :           new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
    2269              :                                        t, igo_prev,
    2270      4369033 :                                        BINFO_VIRTUAL_P (base_binfo));
    2271              : 
    2272      4369033 :           if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
    2273      4144365 :             BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
    2274      4369033 :           BINFO_BASE_APPEND (new_binfo, new_base_binfo);
    2275              :         }
    2276              :     }
    2277              :   else
    2278      7251870 :     BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
    2279              : 
    2280     38716771 :   if (virt)
    2281              :     {
    2282              :       /* Push it onto the list after any virtual bases it contains
    2283              :          will have been pushed.  */
    2284       224253 :       CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
    2285       224253 :       BINFO_VIRTUAL_P (new_binfo) = 1;
    2286       224253 :       BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t);
    2287              :     }
    2288              : 
    2289              :   return new_binfo;
    2290              : }
    2291              : 
    2292              : /* Hashing of lists so that we don't make duplicates.
    2293              :    The entry point is `list_hash_canon'.  */
    2294              : 
    2295              : struct list_proxy
    2296              : {
    2297              :   tree purpose;
    2298              :   tree value;
    2299              :   tree chain;
    2300              : };
    2301              : 
    2302              : struct list_hasher : ggc_ptr_hash<tree_node>
    2303              : {
    2304              :   typedef list_proxy *compare_type;
    2305              : 
    2306              :   static hashval_t hash (tree);
    2307              :   static bool equal (tree, list_proxy *);
    2308              : };
    2309              : 
    2310              : /* Now here is the hash table.  When recording a list, it is added
    2311              :    to the slot whose index is the hash code mod the table size.
    2312              :    Note that the hash table is used for several kinds of lists.
    2313              :    While all these live in the same table, they are completely independent,
    2314              :    and the hash code is computed differently for each of these.  */
    2315              : 
    2316              : static GTY (()) hash_table<list_hasher> *list_hash_table;
    2317              : 
    2318              : /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy
    2319              :    for a node we are thinking about adding).  */
    2320              : 
    2321              : bool
    2322   2577980978 : list_hasher::equal (tree t, list_proxy *proxy)
    2323              : {
    2324   2577980978 :   return (TREE_VALUE (t) == proxy->value
    2325    177985412 :           && TREE_PURPOSE (t) == proxy->purpose
    2326   2753977223 :           && TREE_CHAIN (t) == proxy->chain);
    2327              : }
    2328              : 
    2329              : /* Compute a hash code for a list (chain of TREE_LIST nodes
    2330              :    with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the
    2331              :    TREE_COMMON slots), by adding the hash codes of the individual entries.  */
    2332              : 
    2333              : static hashval_t
    2334   2386716245 : list_hash_pieces (tree purpose, tree value, tree chain)
    2335              : {
    2336   2386716245 :   hashval_t hashcode = 0;
    2337              : 
    2338   2386716245 :   if (chain)
    2339   2386570111 :     hashcode += TREE_HASH (chain);
    2340              : 
    2341   2386716245 :   if (value)
    2342   2386716245 :     hashcode += TREE_HASH (value);
    2343              :   else
    2344            0 :     hashcode += 1007;
    2345   2386716245 :   if (purpose)
    2346    147409192 :     hashcode += TREE_HASH (purpose);
    2347              :   else
    2348   2239307053 :     hashcode += 1009;
    2349   2386716245 :   return hashcode;
    2350              : }
    2351              : 
    2352              : /* Hash an already existing TREE_LIST.  */
    2353              : 
    2354              : hashval_t
    2355   2061676695 : list_hasher::hash (tree t)
    2356              : {
    2357   2061676695 :   return list_hash_pieces (TREE_PURPOSE (t),
    2358   2061676695 :                            TREE_VALUE (t),
    2359   2061676695 :                            TREE_CHAIN (t));
    2360              : }
    2361              : 
    2362              : /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical
    2363              :    object for an identical list if one already exists.  Otherwise, build a
    2364              :    new one, and record it as the canonical object.  */
    2365              : 
    2366              : tree
    2367    325039550 : hash_tree_cons (tree purpose, tree value, tree chain)
    2368              : {
    2369    325039550 :   int hashcode = 0;
    2370    325039550 :   tree *slot;
    2371    325039550 :   struct list_proxy proxy;
    2372              : 
    2373              :   /* Hash the list node.  */
    2374    325039550 :   hashcode = list_hash_pieces (purpose, value, chain);
    2375              :   /* Create a proxy for the TREE_LIST we would like to create.  We
    2376              :      don't actually create it so as to avoid creating garbage.  */
    2377    325039550 :   proxy.purpose = purpose;
    2378    325039550 :   proxy.value = value;
    2379    325039550 :   proxy.chain = chain;
    2380              :   /* See if it is already in the table.  */
    2381    325039550 :   slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
    2382              :   /* If not, create a new node.  */
    2383    325039550 :   if (!*slot)
    2384    156130720 :     *slot = tree_cons (purpose, value, chain);
    2385    325039550 :   return (tree) *slot;
    2386              : }
    2387              : 
    2388              : /* Constructor for hashed lists.  */
    2389              : 
    2390              : tree
    2391      2359772 : hash_tree_chain (tree value, tree chain)
    2392              : {
    2393      2359772 :   return hash_tree_cons (NULL_TREE, value, chain);
    2394              : }
    2395              : 
    2396              : void
    2397            0 : debug_binfo (tree elem)
    2398              : {
    2399            0 :   HOST_WIDE_INT n;
    2400            0 :   tree virtuals;
    2401              : 
    2402            0 :   fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC
    2403              :            "\nvtable type:\n",
    2404            0 :            TYPE_NAME_STRING (BINFO_TYPE (elem)),
    2405            0 :            TREE_INT_CST_LOW (BINFO_OFFSET (elem)));
    2406            0 :   debug_tree (BINFO_TYPE (elem));
    2407            0 :   if (BINFO_VTABLE (elem))
    2408            0 :     fprintf (stderr, "vtable decl \"%s\"\n",
    2409            0 :              IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem))));
    2410              :   else
    2411            0 :     fprintf (stderr, "no vtable decl yet\n");
    2412            0 :   fprintf (stderr, "virtuals:\n");
    2413            0 :   virtuals = BINFO_VIRTUALS (elem);
    2414            0 :   n = 0;
    2415              : 
    2416            0 :   while (virtuals)
    2417              :     {
    2418            0 :       tree fndecl = TREE_VALUE (virtuals);
    2419            0 :       fprintf (stderr, "%s [" HOST_WIDE_INT_PRINT_DEC " =? "
    2420              :                        HOST_WIDE_INT_PRINT_DEC "]\n",
    2421            0 :                IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)),
    2422            0 :                n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl)));
    2423            0 :       ++n;
    2424            0 :       virtuals = TREE_CHAIN (virtuals);
    2425              :     }
    2426            0 : }
    2427              : 
    2428              : /* Build a representation for the qualified name SCOPE::NAME.  TYPE is
    2429              :    the type of the result expression, if known, or NULL_TREE if the
    2430              :    resulting expression is type-dependent.  If TEMPLATE_P is true,
    2431              :    NAME is known to be a template because the user explicitly used the
    2432              :    "template" keyword after the "::".
    2433              : 
    2434              :    All SCOPE_REFs should be built by use of this function.  */
    2435              : 
    2436              : tree
    2437    159980601 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
    2438              : {
    2439    159980601 :   tree t;
    2440    159980601 :   if (type == error_mark_node
    2441    159980601 :       || scope == error_mark_node
    2442    159980598 :       || name == error_mark_node)
    2443              :     return error_mark_node;
    2444    159980598 :   gcc_assert (TREE_CODE (name) != SCOPE_REF);
    2445    159980598 :   t = build2 (SCOPE_REF, type, scope, name);
    2446    159980598 :   QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
    2447    159980598 :   PTRMEM_OK_P (t) = true;
    2448    159980598 :   if (type)
    2449     10834515 :     t = convert_from_reference (t);
    2450              :   return t;
    2451              : }
    2452              : 
    2453              : /* Like check_qualified_type, but also check ref-qualifier, exception
    2454              :    specification, and whether the return type was specified after the
    2455              :    parameters.  */
    2456              : 
    2457              : static bool
    2458   1313886701 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
    2459              :                          cp_ref_qualifier rqual, tree raises, bool late)
    2460              : {
    2461   1313886701 :   return (TYPE_QUALS (cand) == type_quals
    2462   1313791097 :           && check_base_type (cand, base)
    2463   1313673168 :           && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
    2464              :                                 ce_exact)
    2465    629030842 :           && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
    2466   1901440965 :           && type_memfn_rqual (cand) == rqual);
    2467              : }
    2468              : 
    2469              : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL.  */
    2470              : 
    2471              : tree
    2472       743281 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
    2473              : {
    2474       743281 :   tree raises = TYPE_RAISES_EXCEPTIONS (type);
    2475       743281 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    2476       743281 :   return build_cp_fntype_variant (type, rqual, raises, late);
    2477              : }
    2478              : 
    2479              : tree
    2480       213339 : make_binding_vec (tree name, unsigned clusters MEM_STAT_DECL)
    2481              : {
    2482              :   /* Stored in an unsigned short, but we're limited to the number of
    2483              :      modules anyway.  */
    2484       213339 :   gcc_checking_assert (clusters <= (unsigned short)(~0));
    2485       213339 :   size_t length = (offsetof (tree_binding_vec, vec)
    2486              :                    + clusters * sizeof (binding_cluster));
    2487       213339 :   tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
    2488       213339 :   TREE_SET_CODE (vec, BINDING_VECTOR);
    2489       213339 :   BINDING_VECTOR_NAME (vec) = name;
    2490       213339 :   BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
    2491       213339 :   BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
    2492              : 
    2493       213339 :   return vec;
    2494              : }
    2495              : 
    2496              : /* Make a raw overload node containing FN.  */
    2497              : 
    2498              : tree
    2499    398468164 : ovl_make (tree fn, tree next)
    2500              : {
    2501    398468164 :   tree result = make_node (OVERLOAD);
    2502              : 
    2503    398468164 :   if (TREE_CODE (fn) == OVERLOAD)
    2504     15266728 :     OVL_NESTED_P (result) = true;
    2505              : 
    2506    520493758 :   TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
    2507    520493758 :                         ? unknown_type_node : TREE_TYPE (fn));
    2508    398468164 :   if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
    2509     16136117 :     OVL_DEDUP_P (result) = true;
    2510    398468164 :   OVL_FUNCTION (result) = fn;
    2511    398468164 :   OVL_CHAIN (result) = next;
    2512    398468164 :   return result;
    2513              : }
    2514              : 
    2515              : /* Add FN to the (potentially NULL) overload set OVL.  USING_OR_HIDDEN is > 0
    2516              :    if this is a using-decl.  It is > 1 if we're revealing the using decl.
    2517              :    It is > 2 if we're also exporting it.  USING_OR_HIDDEN is < 0, if FN is
    2518              :    hidden.  (A decl cannot be both using and hidden.)  We keep the hidden
    2519              :    decls first, but remaining ones are unordered.  */
    2520              : 
    2521              : tree
    2522    726654954 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
    2523              : {
    2524    726654954 :   tree result = maybe_ovl;
    2525    726654954 :   tree insert_after = NULL_TREE;
    2526              : 
    2527              :   /* Skip hidden.  */
    2528   1045563565 :   for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
    2529   1105727972 :          && OVL_HIDDEN_P (maybe_ovl);
    2530    120316994 :        maybe_ovl = OVL_CHAIN (maybe_ovl))
    2531              :     {
    2532    120316994 :       gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
    2533    120316994 :       insert_after = maybe_ovl;
    2534              :     }
    2535              : 
    2536    726654954 :   if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
    2537              :     {
    2538    316259928 :       maybe_ovl = ovl_make (fn, maybe_ovl);
    2539              : 
    2540    316259928 :       if (using_or_hidden < 0)
    2541     81298314 :         OVL_HIDDEN_P (maybe_ovl) = true;
    2542    316259928 :       if (using_or_hidden > 0)
    2543              :         {
    2544     13737052 :           OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
    2545     13737052 :           if (using_or_hidden > 1)
    2546        31092 :             OVL_PURVIEW_P (maybe_ovl) = true;
    2547        31092 :           if (using_or_hidden > 2)
    2548        30575 :             OVL_EXPORT_P (maybe_ovl) = true;
    2549              :         }
    2550              :     }
    2551              :   else
    2552              :     maybe_ovl = fn;
    2553              : 
    2554    726654954 :   if (insert_after)
    2555              :     {
    2556      9474903 :       OVL_CHAIN (insert_after) = maybe_ovl;
    2557      9474903 :       TREE_TYPE (insert_after) = unknown_type_node;
    2558              :     }
    2559              :   else
    2560              :     result = maybe_ovl;
    2561              : 
    2562    726654954 :   return result;
    2563              : }
    2564              : 
    2565              : /* Skip any hidden names at the beginning of OVL.   */
    2566              : 
    2567              : tree
    2568   2131381791 : ovl_skip_hidden (tree ovl)
    2569              : {
    2570   3947642743 :   while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
    2571   1816260952 :     ovl = OVL_CHAIN (ovl);
    2572              : 
    2573   2131381791 :   return ovl;
    2574              : }
    2575              : 
    2576              : /* NODE is an OVL_HIDDEN_P node that is now revealed.  */
    2577              : 
    2578              : tree
    2579      4132130 : ovl_iterator::reveal_node (tree overload, tree node)
    2580              : {
    2581              :   /* We cannot have returned NODE as part of a lookup overload, so we
    2582              :      don't have to worry about preserving that.  */
    2583              : 
    2584      4132130 :   OVL_HIDDEN_P (node) = false;
    2585      4132130 :   if (tree chain = OVL_CHAIN (node))
    2586       175833 :     if (TREE_CODE (chain) == OVERLOAD)
    2587              :       {
    2588       166317 :         if (OVL_HIDDEN_P (chain))
    2589              :           {
    2590              :             /* The node needs moving, and the simplest way is to remove it
    2591              :                and reinsert.  */
    2592        75969 :             overload = remove_node (overload, node);
    2593        75969 :             overload = ovl_insert (OVL_FUNCTION (node), overload);
    2594              :           }
    2595        90348 :         else if (OVL_DEDUP_P (chain))
    2596            9 :           OVL_DEDUP_P (node) = true;
    2597              :       }
    2598      4132130 :   return overload;
    2599              : }
    2600              : 
    2601              : /* NODE is on the overloads of OVL.  Remove it.
    2602              :    The removed node is unaltered and may continue to be iterated
    2603              :    from (i.e. it is safe to remove a node from an overload one is
    2604              :    currently iterating over).  */
    2605              : 
    2606              : tree
    2607       395608 : ovl_iterator::remove_node (tree overload, tree node)
    2608              : {
    2609       395608 :   tree *slot = &overload;
    2610      2337693 :   while (*slot != node)
    2611              :     {
    2612      1942085 :       tree probe = *slot;
    2613      1942085 :       gcc_checking_assert (!OVL_LOOKUP_P (probe));
    2614              : 
    2615      1942085 :       slot = &OVL_CHAIN (probe);
    2616              :     }
    2617              : 
    2618              :   /* Stitch out NODE.  We don't have to worry about now making a
    2619              :      singleton overload (and consequently maybe setting its type),
    2620              :      because all uses of this function will be followed by inserting a
    2621              :      new node that must follow the place we've cut this out from.  */
    2622       395608 :   if (TREE_CODE (node) != OVERLOAD)
    2623              :     /* Cloned inherited ctors don't mark themselves as via_using.  */
    2624              :     *slot = NULL_TREE;
    2625              :   else
    2626       153183 :     *slot = OVL_CHAIN (node);
    2627              : 
    2628       395608 :   return overload;
    2629              : }
    2630              : 
    2631              : /* Mark or unmark a lookup set. */
    2632              : 
    2633              : void
    2634    122373962 : lookup_mark (tree ovl, bool val)
    2635              : {
    2636   1527918407 :   for (lkp_iterator iter (ovl); iter; ++iter)
    2637              :     {
    2638   1405544445 :       gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
    2639   1405544445 :       LOOKUP_SEEN_P (*iter) = val;
    2640              :     }
    2641    122373962 : }
    2642              : 
    2643              : /* Add a set of new FNS into a lookup.  */
    2644              : 
    2645              : tree
    2646    688240519 : lookup_add (tree fns, tree lookup)
    2647              : {
    2648    688240519 :   if (fns == error_mark_node || lookup == error_mark_node)
    2649              :     return error_mark_node;
    2650              : 
    2651    688240507 :   if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
    2652              :     {
    2653     76034945 :       lookup = ovl_make (fns, lookup);
    2654     76034945 :       OVL_LOOKUP_P (lookup) = true;
    2655              :     }
    2656              :   else
    2657              :     lookup = fns;
    2658              : 
    2659              :   return lookup;
    2660              : }
    2661              : 
    2662              : /* FNS is a new overload set, add them to LOOKUP, if they are not
    2663              :    already present there.  */
    2664              : 
    2665              : tree
    2666    689395340 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
    2667              : {
    2668    689395340 :   if (deduping)
    2669    792312257 :     for (tree next, probe = fns; probe; probe = next)
    2670              :       {
    2671    709318597 :         tree fn = probe;
    2672    709318597 :         next = NULL_TREE;
    2673              : 
    2674    709318597 :         if (TREE_CODE (probe) == OVERLOAD)
    2675              :           {
    2676    676929307 :             fn = OVL_FUNCTION (probe);
    2677    676929307 :             next = OVL_CHAIN (probe);
    2678              :           }
    2679              : 
    2680    709318597 :         if (!LOOKUP_SEEN_P (fn))
    2681    522204153 :           LOOKUP_SEEN_P (fn) = true;
    2682              :         else
    2683              :           {
    2684              :             /* This function was already seen.  Insert all the
    2685              :                predecessors onto the lookup.  */
    2686    204596643 :             for (; fns != probe; fns = OVL_CHAIN (fns))
    2687              :               {
    2688              :                 /* Propagate OVL_USING, but OVL_HIDDEN &
    2689              :                    OVL_DEDUP_P don't matter.  */
    2690     17482199 :                 if (OVL_USING_P (fns))
    2691              :                   {
    2692       434360 :                     lookup = ovl_make (OVL_FUNCTION (fns), lookup);
    2693       434360 :                     OVL_USING_P (lookup) = true;
    2694              :                   }
    2695              :                 else
    2696     17047839 :                   lookup = lookup_add (OVL_FUNCTION (fns), lookup);
    2697              :               }
    2698              : 
    2699              :             /* And now skip this function.  */
    2700              :             fns = next;
    2701              :           }
    2702              :       }
    2703              : 
    2704    689395340 :   if (fns)
    2705              :     /* We ended in a set of new functions.  Add them all in one go.  */
    2706    670260681 :     lookup = lookup_add (fns, lookup);
    2707              : 
    2708    689395340 :   return lookup;
    2709              : }
    2710              : 
    2711              : /* Returns nonzero if X is an expression for a (possibly overloaded)
    2712              :    function.  If "f" is a function or function template, "f", "c->f",
    2713              :    "c.f", "C::f", and "f<int>" will all be considered possibly
    2714              :    overloaded functions.  Returns 2 if the function is actually
    2715              :    overloaded, i.e., if it is impossible to know the type of the
    2716              :    function without performing overload resolution.  */
    2717              : 
    2718              : int
    2719   7537158272 : is_overloaded_fn (tree x)
    2720              : {
    2721   7537158272 :   STRIP_ANY_LOCATION_WRAPPER (x);
    2722              : 
    2723              :   /* A baselink is also considered an overloaded function.  */
    2724   7537158272 :   if (TREE_CODE (x) == OFFSET_REF
    2725   7537091275 :       || TREE_CODE (x) == COMPONENT_REF)
    2726    403842040 :     x = TREE_OPERAND (x, 1);
    2727   7537158272 :   x = MAYBE_BASELINK_FUNCTIONS (x);
    2728   7537158272 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2729    212990380 :     x = TREE_OPERAND (x, 0);
    2730              : 
    2731   8697342860 :   if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
    2732   7574919033 :       || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
    2733              :     return 2;
    2734              : 
    2735   7908994440 :   return OVL_P (x);
    2736              : }
    2737              : 
    2738              : /* X is the CALL_EXPR_FN of a CALL_EXPR.  If X represents a dependent name
    2739              :    (14.6.2), return the IDENTIFIER_NODE for that name.  Otherwise, return
    2740              :    NULL_TREE.  */
    2741              : 
    2742              : tree
    2743    335588416 : dependent_name (tree x)
    2744              : {
    2745              :   /* FIXME a dependent name must be unqualified, but this function doesn't
    2746              :      distinguish between qualified and unqualified identifiers.  */
    2747    335588416 :   if (identifier_p (x))
    2748              :     return x;
    2749    335405790 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2750    169296145 :     x = TREE_OPERAND (x, 0);
    2751    335405790 :   if (OVL_P (x))
    2752    312746556 :     return OVL_NAME (x);
    2753              :   return NULL_TREE;
    2754              : }
    2755              : 
    2756              : /* Like dependent_name, but instead takes a CALL_EXPR and also checks
    2757              :    its dependence.  */
    2758              : 
    2759              : tree
    2760    334870786 : call_expr_dependent_name (tree x)
    2761              : {
    2762    334870786 :   if (TREE_TYPE (x) != NULL_TREE)
    2763              :     /* X isn't dependent, so its callee isn't a dependent name.  */
    2764              :     return NULL_TREE;
    2765    330436309 :   return dependent_name (CALL_EXPR_FN (x));
    2766              : }
    2767              : 
    2768              : /* Returns true iff X is an expression for an overloaded function
    2769              :    whose type cannot be known without performing overload
    2770              :    resolution.  */
    2771              : 
    2772              : bool
    2773    648102068 : really_overloaded_fn (tree x)
    2774              : {
    2775    648102068 :   return is_overloaded_fn (x) == 2;
    2776              : }
    2777              : 
    2778              : /* Get the overload set FROM refers to.  Returns NULL if it's not an
    2779              :    overload set.  */
    2780              : 
    2781              : tree
    2782   4858350185 : maybe_get_fns (tree from)
    2783              : {
    2784   4858350185 :   STRIP_ANY_LOCATION_WRAPPER (from);
    2785              : 
    2786              :   /* A baselink is also considered an overloaded function.  */
    2787   4858350185 :   if (TREE_CODE (from) == OFFSET_REF
    2788   4858288462 :       || TREE_CODE (from) == COMPONENT_REF)
    2789    155441733 :     from = TREE_OPERAND (from, 1);
    2790   4858350185 :   if (BASELINK_P (from))
    2791    143884268 :     from = BASELINK_FUNCTIONS (from);
    2792   4858350185 :   if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
    2793    125270192 :     from = TREE_OPERAND (from, 0);
    2794              : 
    2795   4858350185 :   if (OVL_P (from))
    2796   1226623758 :     return from;
    2797              : 
    2798              :   return NULL_TREE;
    2799              : }
    2800              : 
    2801              : /* FROM refers to an overload set.  Return that set (or die).  */
    2802              : 
    2803              : tree
    2804    875801113 : get_fns (tree from)
    2805              : {
    2806    875801113 :   tree res = maybe_get_fns (from);
    2807              : 
    2808    875801113 :   gcc_assert (res);
    2809    875801113 :   return res;
    2810              : }
    2811              : 
    2812              : /* Return the first function of the overload set FROM refers to.  */
    2813              : 
    2814              : tree
    2815    537021000 : get_first_fn (tree from)
    2816              : {
    2817    537021000 :   return OVL_FIRST (get_fns (from));
    2818              : }
    2819              : 
    2820              : /* Return the first function of the overload set FROM refers to if
    2821              :    there is an overload set, otherwise return FROM unchanged.  */
    2822              : 
    2823              : tree
    2824       180794 : maybe_get_first_fn (tree from)
    2825              : {
    2826       180794 :   if (tree res = maybe_get_fns (from))
    2827       180794 :     return OVL_FIRST (res);
    2828              :   return from;
    2829              : }
    2830              : 
    2831              : /* Return the scope where the overloaded functions OVL were found.  */
    2832              : 
    2833              : tree
    2834    221958285 : ovl_scope (tree ovl)
    2835              : {
    2836    221958285 :   if (TREE_CODE (ovl) == OFFSET_REF
    2837    221958285 :       || TREE_CODE (ovl) == COMPONENT_REF)
    2838            0 :     ovl = TREE_OPERAND (ovl, 1);
    2839    221958285 :   if (TREE_CODE (ovl) == BASELINK)
    2840     47394151 :     return BINFO_TYPE (BASELINK_BINFO (ovl));
    2841    174564134 :   if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
    2842     79079775 :     ovl = TREE_OPERAND (ovl, 0);
    2843              :   /* Skip using-declarations.  */
    2844    174564134 :   lkp_iterator iter (ovl);
    2845    183173043 :   do
    2846    183173043 :     ovl = *iter;
    2847    357737177 :   while (iter.using_p () && ++iter);
    2848              : 
    2849    174564134 :   return CP_DECL_CONTEXT (ovl);
    2850              : }
    2851              : 
    2852              : #define PRINT_RING_SIZE 4
    2853              : 
    2854              : static const char *
    2855       178997 : cxx_printable_name_internal (tree decl, int v, bool translate)
    2856              : {
    2857       178997 :   static unsigned int uid_ring[PRINT_RING_SIZE];
    2858       178997 :   static char *print_ring[PRINT_RING_SIZE];
    2859       178997 :   static bool trans_ring[PRINT_RING_SIZE];
    2860       178997 :   static int ring_counter;
    2861       178997 :   int i;
    2862              : 
    2863              :   /* Only cache functions.  */
    2864       178997 :   if (v < 2
    2865        96564 :       || TREE_CODE (decl) != FUNCTION_DECL
    2866       272357 :       || DECL_LANG_SPECIFIC (decl) == 0)
    2867        86757 :     return lang_decl_name (decl, v, translate);
    2868              : 
    2869              :   /* See if this print name is lying around.  */
    2870       420642 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2871       344949 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2872              :       /* yes, so return it.  */
    2873        16547 :       return print_ring[i];
    2874              : 
    2875        75693 :   const char *ret = lang_decl_name (decl, v, translate);
    2876              : 
    2877              :   /* The lang_decl_name call could have called this function recursively,
    2878              :      so check again.  */
    2879       454158 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2880       302772 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2881              :       /* yes, so return it.  */
    2882            0 :       return print_ring[i];
    2883              : 
    2884        75693 :   if (++ring_counter == PRINT_RING_SIZE)
    2885        15677 :     ring_counter = 0;
    2886              : 
    2887        75693 :   if (current_function_decl != NULL_TREE)
    2888              :     {
    2889              :       /* There may be both translated and untranslated versions of the
    2890              :          name cached.  */
    2891       208029 :       for (i = 0; i < 2; i++)
    2892              :         {
    2893       138686 :           if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
    2894           79 :             ring_counter += 1;
    2895       138686 :           if (ring_counter == PRINT_RING_SIZE)
    2896            7 :             ring_counter = 0;
    2897              :         }
    2898        69343 :       gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
    2899              :     }
    2900              : 
    2901        75693 :   free (print_ring[ring_counter]);
    2902              : 
    2903        75693 :   print_ring[ring_counter] = xstrdup (ret);
    2904        75693 :   uid_ring[ring_counter] = DECL_UID (decl);
    2905        75693 :   trans_ring[ring_counter] = translate;
    2906        75693 :   return print_ring[ring_counter];
    2907              : }
    2908              : 
    2909              : const char *
    2910       178997 : cxx_printable_name (tree decl, int v)
    2911              : {
    2912       178997 :   return cxx_printable_name_internal (decl, v, false);
    2913              : }
    2914              : 
    2915              : const char *
    2916            0 : cxx_printable_name_translate (tree decl, int v)
    2917              : {
    2918            0 :   return cxx_printable_name_internal (decl, v, true);
    2919              : }
    2920              : 
    2921              : /* Return the canonical version of exception-specification RAISES for a C++17
    2922              :    function type, for use in type comparison and building TYPE_CANONICAL.  */
    2923              : 
    2924              : tree
    2925    217848019 : canonical_eh_spec (tree raises)
    2926              : {
    2927    217848019 :   if (raises == NULL_TREE)
    2928              :     return raises;
    2929    196159041 :   else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
    2930    159644882 :            || UNPARSED_NOEXCEPT_SPEC_P (raises)
    2931    150597314 :            || uses_template_parms (raises)
    2932    150597314 :            || uses_template_parms (TREE_PURPOSE (raises)))
    2933              :     /* Keep a dependent or deferred exception specification.  */
    2934              :     return raises;
    2935    148693961 :   else if (nothrow_spec_p (raises))
    2936              :     /* throw() -> noexcept.  */
    2937    148155642 :     return noexcept_true_spec;
    2938              :   else
    2939              :     /* For C++17 type matching, anything else -> nothing.  */
    2940              :     return NULL_TREE;
    2941              : }
    2942              : 
    2943              : tree
    2944    783971539 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
    2945              :                          tree raises, bool late)
    2946              : {
    2947    783971539 :   cp_cv_quals type_quals = TYPE_QUALS (type);
    2948              : 
    2949    783971539 :   if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
    2950              :     return type;
    2951              : 
    2952    330152556 :   tree v = TYPE_MAIN_VARIANT (type);
    2953    730348133 :   for (; v; v = TYPE_NEXT_VARIANT (v))
    2954    529915162 :     if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
    2955              :       return v;
    2956              : 
    2957              :   /* Need to build a new variant.  */
    2958    200432971 :   v = build_variant_type_copy (type);
    2959    200432971 :   if (!TYPE_DEPENDENT_P (v))
    2960              :     /* We no longer know that it's not type-dependent.  */
    2961    199581837 :     TYPE_DEPENDENT_P_VALID (v) = false;
    2962    200432971 :   TYPE_RAISES_EXCEPTIONS (v) = raises;
    2963    200432971 :   TYPE_HAS_LATE_RETURN_TYPE (v) = late;
    2964    200432971 :   switch (rqual)
    2965              :     {
    2966      1305960 :     case REF_QUAL_RVALUE:
    2967      1305960 :       FUNCTION_RVALUE_QUALIFIED (v) = 1;
    2968      1305960 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2969      1305960 :       break;
    2970      1227342 :     case REF_QUAL_LVALUE:
    2971      1227342 :       FUNCTION_RVALUE_QUALIFIED (v) = 0;
    2972      1227342 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2973      1227342 :       break;
    2974    197899669 :     default:
    2975    197899669 :       FUNCTION_REF_QUALIFIED (v) = 0;
    2976    197899669 :       break;
    2977              :     }
    2978              : 
    2979              :   /* Canonicalize the exception specification.  */
    2980    200432971 :   tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
    2981    189202818 :   bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
    2982    246280940 :                             && !UNPARSED_NOEXCEPT_SPEC_P (cr));
    2983              : 
    2984    162621339 :   if (!complex_eh_spec_p && TYPE_RAISES_EXCEPTIONS (type))
    2985              :     /* We want to consider structural equality of the exception-less
    2986              :        variant since we'll be replacing the exception specification.  */
    2987      5791598 :     type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
    2988    200432971 :   if (TYPE_STRUCTURAL_EQUALITY_P (type) || complex_eh_spec_p)
    2989              :     /* Propagate structural equality.  And always use structural equality
    2990              :        for function types with a complex noexcept-spec since their identity
    2991              :        may depend on e.g. whether comparing_specializations is set.  */
    2992     51984470 :     SET_TYPE_STRUCTURAL_EQUALITY (v);
    2993    148448501 :   else if (TYPE_CANONICAL (type) != type || cr != raises || late)
    2994              :     /* Build the underlying canonical type, since it is different
    2995              :        from TYPE. */
    2996     63926219 :     TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
    2997              :                                                   rqual, cr, false);
    2998              :   else
    2999              :     /* T is its own canonical type. */
    3000     84522282 :     TYPE_CANONICAL (v) = v;
    3001              : 
    3002              :   return v;
    3003              : }
    3004              : 
    3005              : /* TYPE is a function or method type with a deferred exception
    3006              :    specification that has been parsed to RAISES.  Fixup all the type
    3007              :    variants that are affected in place.  Via decltype &| noexcept
    3008              :    tricks, the unparsed spec could have escaped into the type system.  */
    3009              : 
    3010              : void
    3011      3665265 : fixup_deferred_exception_variants (tree type, tree raises)
    3012              : {
    3013      3665265 :   tree original = TYPE_RAISES_EXCEPTIONS (type);
    3014              : 
    3015      7330530 :   gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
    3016              : 
    3017      3665265 :   for (tree variant = TYPE_MAIN_VARIANT (type);
    3018     11894173 :        variant; variant = TYPE_NEXT_VARIANT (variant))
    3019      8228908 :     if (TYPE_RAISES_EXCEPTIONS (variant) == original)
    3020              :       {
    3021      3956441 :         gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
    3022              : 
    3023      3956441 :         SET_TYPE_STRUCTURAL_EQUALITY (variant);
    3024      3956441 :         TYPE_RAISES_EXCEPTIONS (variant) = raises;
    3025              : 
    3026      3956441 :         if (!TYPE_DEPENDENT_P (variant))
    3027              :           /* We no longer know that it's not type-dependent.  */
    3028       296237 :           TYPE_DEPENDENT_P_VALID (variant) = false;
    3029              :       }
    3030      3665265 : }
    3031              : 
    3032              : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
    3033              :    listed in RAISES.  */
    3034              : 
    3035              : tree
    3036    193859029 : build_exception_variant (tree type, tree raises)
    3037              : {
    3038    193859029 :   cp_ref_qualifier rqual = type_memfn_rqual (type);
    3039    193859029 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    3040    193859029 :   return build_cp_fntype_variant (type, rqual, raises, late);
    3041              : }
    3042              : 
    3043              : /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new
    3044              :    BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template
    3045              :    arguments.  */
    3046              : 
    3047              : tree
    3048       374493 : bind_template_template_parm (tree t, tree newargs)
    3049              : {
    3050       374493 :   tree decl = TYPE_NAME (t);
    3051       374493 :   tree t2;
    3052              : 
    3053       374493 :   t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
    3054       374493 :   decl = build_decl (input_location,
    3055       374493 :                      TYPE_DECL, DECL_NAME (decl), NULL_TREE);
    3056       374493 :   SET_DECL_TEMPLATE_PARM_P (decl);
    3057              : 
    3058              :   /* These nodes have to be created to reflect new TYPE_DECL and template
    3059              :      arguments.  */
    3060       374493 :   TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
    3061       374493 :   TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
    3062       374493 :   TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
    3063       748986 :     = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
    3064              : 
    3065       374493 :   TREE_TYPE (decl) = t2;
    3066       374493 :   TYPE_NAME (t2) = decl;
    3067       374493 :   TYPE_STUB_DECL (t2) = decl;
    3068       374493 :   TYPE_SIZE (t2) = 0;
    3069              : 
    3070       374493 :   if (any_template_arguments_need_structural_equality_p (newargs))
    3071           13 :     SET_TYPE_STRUCTURAL_EQUALITY (t2);
    3072              :   else
    3073       374480 :     TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
    3074              : 
    3075       374493 :   return t2;
    3076              : }
    3077              : 
    3078              : /* Called from count_trees via walk_tree.  */
    3079              : 
    3080              : static tree
    3081            0 : count_trees_r (tree *tp, int *walk_subtrees, void *data)
    3082              : {
    3083            0 :   ++*((int *) data);
    3084              : 
    3085            0 :   if (TYPE_P (*tp))
    3086            0 :     *walk_subtrees = 0;
    3087              : 
    3088            0 :   return NULL_TREE;
    3089              : }
    3090              : 
    3091              : /* Debugging function for measuring the rough complexity of a tree
    3092              :    representation.  */
    3093              : 
    3094              : int
    3095            0 : count_trees (tree t)
    3096              : {
    3097            0 :   int n_trees = 0;
    3098            0 :   cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees);
    3099            0 :   return n_trees;
    3100              : }
    3101              : 
    3102              : /* Called from verify_stmt_tree via walk_tree.  */
    3103              : 
    3104              : static tree
    3105       633458 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
    3106              : {
    3107       633458 :   tree t = *tp;
    3108       633458 :   hash_table<nofree_ptr_hash <tree_node> > *statements
    3109              :       = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
    3110       633458 :   tree_node **slot;
    3111              : 
    3112       633458 :   if (!STATEMENT_CODE_P (TREE_CODE (t)))
    3113              :     return NULL_TREE;
    3114              : 
    3115              :   /* If this statement is already present in the hash table, then
    3116              :      there is a circularity in the statement tree.  */
    3117        33064 :   gcc_assert (!statements->find (t));
    3118              : 
    3119        33064 :   slot = statements->find_slot (t, INSERT);
    3120        33064 :   *slot = t;
    3121              : 
    3122        33064 :   return NULL_TREE;
    3123              : }
    3124              : 
    3125              : /* Debugging function to check that the statement T has not been
    3126              :    corrupted.  For now, this function simply checks that T contains no
    3127              :    circularities.  */
    3128              : 
    3129              : void
    3130         1626 : verify_stmt_tree (tree t)
    3131              : {
    3132         1626 :   hash_table<nofree_ptr_hash <tree_node> > statements (37);
    3133         1626 :   cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL);
    3134         1626 : }
    3135              : 
    3136              : /* Check if the type T depends on a type with no linkage and if so,
    3137              :    return it.  If RELAXED_P then do not consider a class type declared
    3138              :    within a vague-linkage function or in a module CMI to have no linkage,
    3139              :    since it can still be accessed within a different TU.  Remember:
    3140              :    no-linkage is not the same as internal-linkage.  */
    3141              : 
    3142              : tree
    3143    316560027 : no_linkage_check (tree t, bool relaxed_p)
    3144              : {
    3145    370435824 :   tree r;
    3146              : 
    3147              :   /* Lambda types that don't have mangling scope have no linkage.  We
    3148              :      check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
    3149              :      when we get here from pushtag none of the lambda information is
    3150              :      set up yet, so we want to assume that the lambda has linkage and
    3151              :      fix it up later if not.  We need to check this even in templates so
    3152              :      that we properly handle a lambda-expression in the signature.  */
    3153    417940961 :   if (LAMBDA_TYPE_P (t)
    3154    374328671 :       && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
    3155              :     {
    3156      2213750 :       tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
    3157      2213750 :       if (!extra)
    3158              :         return t;
    3159              :     }
    3160              : 
    3161              :   /* Otherwise there's no point in checking linkage on template functions; we
    3162              :      can't know their complete types.  */
    3163    370431319 :   if (processing_template_decl)
    3164              :     return NULL_TREE;
    3165              : 
    3166    231081478 :   switch (TREE_CODE (t))
    3167              :     {
    3168    121355392 :     case RECORD_TYPE:
    3169    121355392 :       if (TYPE_PTRMEMFUNC_P (t))
    3170       126260 :         goto ptrmem;
    3171              :       /* Fall through.  */
    3172    122613497 :     case UNION_TYPE:
    3173    122613497 :       if (!CLASS_TYPE_P (t))
    3174              :         return NULL_TREE;
    3175              :       /* Fall through.  */
    3176    127435752 :     case ENUMERAL_TYPE:
    3177              :       /* Only treat unnamed types as having no linkage if they're at
    3178              :          namespace scope.  This is core issue 966.  */
    3179    259468077 :       if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
    3180              :         return t;
    3181              : 
    3182    126655811 :       for (r = CP_TYPE_CONTEXT (t); ; )
    3183              :         {
    3184              :           /* If we're a nested type of a !TREE_PUBLIC class, we might not
    3185              :              have linkage, or we might just be in an anonymous namespace.
    3186              :              If we're in a TREE_PUBLIC class, we have linkage.  */
    3187    129323546 :           if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
    3188        82439 :             return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
    3189    129241107 :           else if (TREE_CODE (r) == FUNCTION_DECL)
    3190              :             {
    3191      3226320 :               if (relaxed_p
    3192      3226320 :                   && (vague_linkage_p (r)
    3193         7770 :                       || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
    3194      2667735 :                 r = CP_DECL_CONTEXT (r);
    3195              :               else
    3196              :                 return t;
    3197              :             }
    3198              :           else
    3199              :             break;
    3200              :         }
    3201              : 
    3202              :       return NULL_TREE;
    3203              : 
    3204     29157760 :     case ARRAY_TYPE:
    3205     29157760 :     case POINTER_TYPE:
    3206     29157760 :     case REFERENCE_TYPE:
    3207     29157760 :     case VECTOR_TYPE:
    3208     29157760 :       return no_linkage_check (TREE_TYPE (t), relaxed_p);
    3209              : 
    3210       129422 :     case OFFSET_TYPE:
    3211       129422 :     ptrmem:
    3212       129422 :       r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
    3213              :                             relaxed_p);
    3214       129422 :       if (r)
    3215              :         return r;
    3216       129422 :       return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
    3217              : 
    3218     25049461 :     case METHOD_TYPE:
    3219     25049461 :     case FUNCTION_TYPE:
    3220     25049461 :       {
    3221     25049461 :         tree parm = TYPE_ARG_TYPES (t);
    3222     25049461 :         if (TREE_CODE (t) == METHOD_TYPE)
    3223              :           /* The 'this' pointer isn't interesting; a method has the same
    3224              :              linkage (or lack thereof) as its enclosing class.  */
    3225     12644221 :           parm = TREE_CHAIN (parm);
    3226     32119631 :         for (;
    3227     57169092 :              parm && parm != void_list_node;
    3228     32119631 :              parm = TREE_CHAIN (parm))
    3229              :           {
    3230     32662916 :             r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
    3231     32662916 :             if (r)
    3232              :               return r;
    3233              :           }
    3234     24506176 :         return no_linkage_check (TREE_TYPE (t), relaxed_p);
    3235              :       }
    3236              : 
    3237              :     default:
    3238              :       return NULL_TREE;
    3239              :     }
    3240              : }
    3241              : 
    3242              : extern int depth_reached;
    3243              : 
    3244              : void
    3245            0 : cxx_print_statistics (void)
    3246              : {
    3247            0 :   print_template_statistics ();
    3248            0 :   if (GATHER_STATISTICS)
    3249              :     fprintf (stderr, "maximum template instantiation depth reached: %d\n",
    3250              :              depth_reached);
    3251            0 : }
    3252              : 
    3253              : /* Return, as an INTEGER_CST node, the number of elements for TYPE
    3254              :    (which is an ARRAY_TYPE).  This one is a recursive count of all
    3255              :    ARRAY_TYPEs that are clumped together.  */
    3256              : 
    3257              : tree
    3258         6857 : array_type_nelts_total (tree type)
    3259              : {
    3260         6857 :   tree sz = array_type_nelts_top (type);
    3261         6857 :   type = TREE_TYPE (type);
    3262         7131 :   while (TREE_CODE (type) == ARRAY_TYPE)
    3263              :     {
    3264          274 :       tree n = array_type_nelts_top (type);
    3265          274 :       sz = fold_build2_loc (input_location,
    3266              :                         MULT_EXPR, sizetype, sz, n);
    3267          274 :       type = TREE_TYPE (type);
    3268              :     }
    3269         6857 :   return sz;
    3270              : }
    3271              : 
    3272              : struct bot_data
    3273              : {
    3274              :   splay_tree target_remap;
    3275              :   bool clear_location;
    3276              : };
    3277              : 
    3278              : /* Called from break_out_target_exprs via mapcar.  */
    3279              : 
    3280              : static tree
    3281     60495554 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
    3282              : {
    3283     60495554 :   bot_data &data = *(bot_data*)data_;
    3284     60495554 :   splay_tree target_remap = data.target_remap;
    3285     60495554 :   tree t = *tp;
    3286              : 
    3287     60495554 :   if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t))
    3288              :     {
    3289              :       /* There can't be any TARGET_EXPRs or their slot variables below this
    3290              :          point.  But we must make a copy, in case subsequent processing
    3291              :          alters any part of it.  For example, during gimplification a cast
    3292              :          of the form (T) &X::f (where "f" is a member function) will lead
    3293              :          to replacing the PTRMEM_CST for &X::f with a VAR_DECL.  */
    3294     24698983 :       *walk_subtrees = 0;
    3295     24698983 :       *tp = unshare_expr (t);
    3296     24698983 :       return NULL_TREE;
    3297              :     }
    3298     35796571 :   if (TREE_CODE (t) == TARGET_EXPR)
    3299              :     {
    3300       769154 :       tree u;
    3301              : 
    3302       769154 :       if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
    3303              :         {
    3304       536375 :           u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3305              :                                tf_warning_or_error);
    3306       536375 :           if (u == error_mark_node)
    3307              :             return u;
    3308       536375 :           if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
    3309         6632 :             AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
    3310              :         }
    3311              :       else
    3312       232779 :         u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3313              :                                tf_warning_or_error);
    3314              : 
    3315       769154 :       TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
    3316       769154 :       TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
    3317       769154 :       TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
    3318       769154 :       TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
    3319       769154 :       TREE_CONSTANT (u) = TREE_CONSTANT (t);
    3320              : 
    3321              :       /* Map the old variable to the new one.  */
    3322      2307462 :       splay_tree_insert (target_remap,
    3323       769154 :                          (splay_tree_key) TARGET_EXPR_SLOT (t),
    3324       769154 :                          (splay_tree_value) TARGET_EXPR_SLOT (u));
    3325              : 
    3326       769154 :       TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
    3327              :                                                         data.clear_location);
    3328       769154 :       if (TARGET_EXPR_INITIAL (u) == error_mark_node)
    3329              :         return error_mark_node;
    3330              : 
    3331       769154 :       if (data.clear_location)
    3332       415941 :         SET_EXPR_LOCATION (u, input_location);
    3333              : 
    3334              :       /* Replace the old expression with the new version.  */
    3335       769154 :       *tp = u;
    3336              :       /* We don't have to go below this point; the recursive call to
    3337              :          break_out_target_exprs will have handled anything below this
    3338              :          point.  */
    3339       769154 :       *walk_subtrees = 0;
    3340       769154 :       return NULL_TREE;
    3341              :     }
    3342     35027417 :   if (TREE_CODE (*tp) == SAVE_EXPR)
    3343              :     {
    3344       104298 :       t = *tp;
    3345       104298 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3346              :                                              (splay_tree_key) t);
    3347       104298 :       if (n)
    3348              :         {
    3349        52870 :           *tp = (tree)n->value;
    3350        52870 :           *walk_subtrees = 0;
    3351              :         }
    3352              :       else
    3353              :         {
    3354        51428 :           copy_tree_r (tp, walk_subtrees, NULL);
    3355        51428 :           splay_tree_insert (target_remap,
    3356              :                              (splay_tree_key)t,
    3357        51428 :                              (splay_tree_value)*tp);
    3358              :           /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
    3359        51428 :           splay_tree_insert (target_remap,
    3360              :                              (splay_tree_key)*tp,
    3361        51428 :                              (splay_tree_value)*tp);
    3362              :         }
    3363              :       return NULL_TREE;
    3364              :     }
    3365     34923119 :   if (TREE_CODE (*tp) == DECL_EXPR
    3366          199 :       && VAR_P (DECL_EXPR_DECL (*tp))
    3367          199 :       && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
    3368     34923318 :       && !TREE_STATIC (DECL_EXPR_DECL (*tp)))
    3369              :     {
    3370          199 :       tree t;
    3371          199 :       splay_tree_node n
    3372          398 :         = splay_tree_lookup (target_remap,
    3373          199 :                              (splay_tree_key) DECL_EXPR_DECL (*tp));
    3374          199 :       if (n)
    3375            1 :         t = (tree) n->value;
    3376              :       else
    3377              :         {
    3378          198 :           t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp)));
    3379          198 :           DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp));
    3380          396 :           splay_tree_insert (target_remap,
    3381          198 :                              (splay_tree_key) DECL_EXPR_DECL (*tp),
    3382              :                              (splay_tree_value) t);
    3383              :         }
    3384          199 :       copy_tree_r (tp, walk_subtrees, NULL);
    3385          199 :       DECL_EXPR_DECL (*tp) = t;
    3386          199 :       if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3387           12 :         SET_EXPR_LOCATION (*tp, input_location);
    3388              :       return NULL_TREE;
    3389              :     }
    3390     34922920 :   if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_VARS (*tp))
    3391              :     {
    3392            1 :       copy_tree_r (tp, walk_subtrees, NULL);
    3393            2 :       for (tree *p = &BIND_EXPR_VARS (*tp); *p; p = &DECL_CHAIN (*p))
    3394              :         {
    3395            1 :           gcc_assert (VAR_P (*p) && DECL_ARTIFICIAL (*p) && !TREE_STATIC (*p));
    3396            1 :           tree t = create_temporary_var (TREE_TYPE (*p));
    3397            1 :           DECL_INITIAL (t) = DECL_INITIAL (*p);
    3398            1 :           DECL_CHAIN (t) = DECL_CHAIN (*p);
    3399            1 :           splay_tree_insert (target_remap, (splay_tree_key) *p,
    3400              :                              (splay_tree_value) t);
    3401            1 :           *p = t;
    3402              :         }
    3403            1 :       if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3404            0 :         SET_EXPR_LOCATION (*tp, input_location);
    3405              :       return NULL_TREE;
    3406              :     }
    3407              : 
    3408              :   /* Make a copy of this node.  */
    3409     34922919 :   t = copy_tree_r (tp, walk_subtrees, NULL);
    3410     34922919 :   if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
    3411      5992253 :     if (!processing_template_decl)
    3412      5992253 :       set_flags_from_callee (*tp);
    3413     34922919 :   if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3414     10414130 :     SET_EXPR_LOCATION (*tp, input_location);
    3415              :   return t;
    3416              : }
    3417              : 
    3418              : /* Replace all remapped VAR_DECLs in T with their new equivalents.
    3419              :    DATA is really a splay-tree mapping old variables to new
    3420              :    variables.  */
    3421              : 
    3422              : static tree
    3423     85340463 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
    3424              : {
    3425     85340463 :   bot_data &data = *(bot_data*)data_;
    3426     85340463 :   splay_tree target_remap = data.target_remap;
    3427              : 
    3428     85340463 :   if (VAR_P (*t))
    3429              :     {
    3430      2622935 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3431              :                                              (splay_tree_key) *t);
    3432      2622935 :       if (n)
    3433         2203 :         *t = (tree) n->value;
    3434              :     }
    3435     82717528 :   else if (TREE_CODE (*t) == PARM_DECL
    3436      5678997 :            && DECL_NAME (*t) == this_identifier
    3437     84707909 :            && !DECL_CONTEXT (*t))
    3438              :     {
    3439              :       /* In an NSDMI we need to replace the 'this' parameter we used for
    3440              :          parsing with the real one for this function.  */
    3441        25206 :       *t = current_class_ptr;
    3442              :     }
    3443     82692322 :   else if (TREE_CODE (*t) == CONVERT_EXPR
    3444     82692322 :            && CONVERT_EXPR_VBASE_PATH (*t))
    3445              :     {
    3446              :       /* In an NSDMI build_base_path defers building conversions to morally
    3447              :          virtual bases, and we handle it here.  */
    3448           63 :       tree basetype = TREE_TYPE (*t);
    3449           63 :       *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
    3450              :                             /*check_access=*/false, /*nonnull=*/true,
    3451              :                             tf_warning_or_error);
    3452              :     }
    3453              : 
    3454     85340463 :   return NULL_TREE;
    3455              : }
    3456              : 
    3457              : /* When we parse a default argument expression, we may create
    3458              :    temporary variables via TARGET_EXPRs.  When we actually use the
    3459              :    default-argument expression, we make a copy of the expression
    3460              :    and replace the temporaries with appropriate local versions.
    3461              : 
    3462              :    If CLEAR_LOCATION is true, override any EXPR_LOCATION with
    3463              :    input_location.  */
    3464              : 
    3465              : tree
    3466     12902653 : break_out_target_exprs (tree t, bool clear_location /* = false */)
    3467              : {
    3468     12902653 :   static int target_remap_count;
    3469     12902653 :   static splay_tree target_remap;
    3470              : 
    3471              :   /* We shouldn't be called on templated trees, nor do we want to
    3472              :      produce them.  */
    3473     12902653 :   gcc_checking_assert (!processing_template_decl);
    3474              : 
    3475     12902653 :   if (!target_remap_count++)
    3476     12133499 :     target_remap = splay_tree_new (splay_tree_compare_pointers,
    3477              :                                    /*splay_tree_delete_key_fn=*/NULL,
    3478              :                                    /*splay_tree_delete_value_fn=*/NULL);
    3479     12902653 :   bot_data data = { target_remap, clear_location };
    3480     12902653 :   if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
    3481            0 :     t = error_mark_node;
    3482     12902653 :   if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
    3483            0 :     t = error_mark_node;
    3484              : 
    3485     12902653 :   if (!--target_remap_count)
    3486              :     {
    3487     12133499 :       splay_tree_delete (target_remap);
    3488     12133499 :       target_remap = NULL;
    3489              :     }
    3490              : 
    3491     12902653 :   return t;
    3492              : }
    3493              : 
    3494              : /* Build an expression for the subobject of OBJ at CONSTRUCTOR index INDEX,
    3495              :    which we expect to have type TYPE.  */
    3496              : 
    3497              : tree
    3498      1537637 : build_ctor_subob_ref (tree index, tree type, tree obj)
    3499              : {
    3500      1537637 :   if (index == NULL_TREE)
    3501              :     /* Can't refer to a particular member of a vector.  */
    3502              :     obj = NULL_TREE;
    3503      1537637 :   else if (TREE_CODE (index) == INTEGER_CST)
    3504        56914 :     obj = cp_build_array_ref (input_location, obj, index, tf_none);
    3505              :   else
    3506      1480723 :     obj = build_class_member_access_expr (obj, index, NULL_TREE,
    3507              :                                           /*reference*/false, tf_none);
    3508      1537637 :   if (obj)
    3509              :     {
    3510      1537637 :       tree objtype = TREE_TYPE (obj);
    3511      1537637 :       if (TREE_CODE (objtype) == ARRAY_TYPE && !TYPE_DOMAIN (objtype))
    3512              :         {
    3513              :           /* When the destination object refers to a flexible array member
    3514              :              verify that it matches the type of the source object except
    3515              :              for its domain and qualifiers.  */
    3516           83 :           gcc_assert (comptypes (TYPE_MAIN_VARIANT (type),
    3517              :                                  TYPE_MAIN_VARIANT (objtype),
    3518              :                                  COMPARE_REDECLARATION));
    3519              :         }
    3520              :       else
    3521      1537554 :         gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
    3522              :     }
    3523              : 
    3524      1537637 :   return obj;
    3525              : }
    3526              : 
    3527              : struct replace_placeholders_t
    3528              : {
    3529              :   tree obj;         /* The object to be substituted for a PLACEHOLDER_EXPR.  */
    3530              :   tree exp;         /* The outermost exp.  */
    3531              :   bool seen;        /* Whether we've encountered a PLACEHOLDER_EXPR.  */
    3532              :   hash_set<tree> *pset;   /* To avoid walking same trees multiple times.  */
    3533              : };
    3534              : 
    3535              : /* Like substitute_placeholder_in_expr, but handle C++ tree codes and
    3536              :    build up subexpressions as we go deeper.  */
    3537              : 
    3538              : static tree
    3539     27995762 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
    3540              : {
    3541     27995762 :   replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
    3542     27995762 :   tree obj = d->obj;
    3543              : 
    3544     27995762 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3545              :     {
    3546      9733557 :       *walk_subtrees = false;
    3547      9733557 :       return NULL_TREE;
    3548              :     }
    3549              : 
    3550     18262205 :   switch (TREE_CODE (*t))
    3551              :     {
    3552              :     case PLACEHOLDER_EXPR:
    3553              :       {
    3554              :         tree x = obj;
    3555          659 :         for (; !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (*t),
    3556          659 :                                                            TREE_TYPE (x));
    3557           77 :              x = TREE_OPERAND (x, 0))
    3558           77 :           gcc_assert (handled_component_p (x));
    3559          582 :         *t = unshare_expr (x);
    3560          582 :         *walk_subtrees = false;
    3561          582 :         d->seen = true;
    3562              :       }
    3563          582 :       break;
    3564              : 
    3565       363085 :     case CONSTRUCTOR:
    3566       363085 :       {
    3567       363085 :         constructor_elt *ce;
    3568       363085 :         vec<constructor_elt,va_gc> *v = CONSTRUCTOR_ELTS (*t);
    3569              :         /* Don't walk into CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors
    3570              :            other than the d->exp one, those have PLACEHOLDER_EXPRs
    3571              :            related to another object.  */
    3572       363085 :         if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
    3573          648 :              && *t != d->exp)
    3574       363628 :             || d->pset->add (*t))
    3575              :           {
    3576          105 :             *walk_subtrees = false;
    3577          105 :             return NULL_TREE;
    3578              :           }
    3579      1109500 :         for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
    3580              :           {
    3581       746520 :             tree *valp = &ce->value;
    3582       746520 :             tree type = TREE_TYPE (*valp);
    3583       746520 :             tree subob = obj;
    3584              : 
    3585              :             /* Elements with RANGE_EXPR index shouldn't have any
    3586              :                placeholders in them.  */
    3587       746520 :             if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
    3588            9 :               continue;
    3589              : 
    3590       746511 :             if (TREE_CODE (*valp) == CONSTRUCTOR
    3591         3005 :                 && AGGREGATE_TYPE_P (type))
    3592              :               {
    3593              :                 /* If we're looking at the initializer for OBJ, then build
    3594              :                    a sub-object reference.  If we're looking at an
    3595              :                    initializer for another object, just pass OBJ down.  */
    3596         2991 :                 if (same_type_ignoring_top_level_qualifiers_p
    3597         2991 :                     (TREE_TYPE (*t), TREE_TYPE (obj)))
    3598         2937 :                   subob = build_ctor_subob_ref (ce->index, type, obj);
    3599         2991 :                 if (TREE_CODE (*valp) == TARGET_EXPR)
    3600            0 :                   valp = &TARGET_EXPR_INITIAL (*valp);
    3601              :               }
    3602       746511 :             d->obj = subob;
    3603       746511 :             cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
    3604       746511 :             d->obj = obj;
    3605              :           }
    3606       362980 :         *walk_subtrees = false;
    3607       362980 :         break;
    3608              :       }
    3609              : 
    3610     17898538 :     default:
    3611     17898538 :       if (d->pset->add (*t))
    3612       687695 :         *walk_subtrees = false;
    3613              :       break;
    3614              :     }
    3615              : 
    3616              :   return NULL_TREE;
    3617              : }
    3618              : 
    3619              : /* Replace PLACEHOLDER_EXPRs in EXP with object OBJ.  SEEN_P is set if
    3620              :    a PLACEHOLDER_EXPR has been encountered.  */
    3621              : 
    3622              : tree
    3623     67295430 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
    3624              : {
    3625              :   /* This is only relevant for C++14.  */
    3626     67295430 :   if (cxx_dialect < cxx14)
    3627       912271 :     return exp;
    3628              : 
    3629              :   /* If the object isn't a (member of a) class, do nothing.  */
    3630              :   tree op0 = obj;
    3631     67069679 :   while (handled_component_p (op0))
    3632       686520 :     op0 = TREE_OPERAND (op0, 0);
    3633     66383159 :   if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
    3634     60084482 :     return exp;
    3635              : 
    3636      6298677 :   tree *tp = &exp;
    3637      6298677 :   if (TREE_CODE (exp) == TARGET_EXPR)
    3638       829937 :     tp = &TARGET_EXPR_INITIAL (exp);
    3639      6298677 :   hash_set<tree> pset;
    3640      6298677 :   replace_placeholders_t data = { obj, *tp, false, &pset };
    3641      6298677 :   cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
    3642      6298677 :   if (seen_p)
    3643       204099 :     *seen_p = data.seen;
    3644      6298677 :   return exp;
    3645      6298677 : }
    3646              : 
    3647              : /* Callback function for find_placeholders.  */
    3648              : 
    3649              : static tree
    3650      8985820 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
    3651              : {
    3652      8985820 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3653              :     {
    3654      3998926 :       *walk_subtrees = false;
    3655      3998926 :       return NULL_TREE;
    3656              :     }
    3657              : 
    3658      4986894 :   switch (TREE_CODE (*t))
    3659              :     {
    3660              :     case PLACEHOLDER_EXPR:
    3661              :       return *t;
    3662              : 
    3663          604 :     case CONSTRUCTOR:
    3664          604 :       if (CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t))
    3665          173 :         *walk_subtrees = false;
    3666              :       break;
    3667              : 
    3668              :     default:
    3669              :       break;
    3670              :     }
    3671              : 
    3672              :   return NULL_TREE;
    3673              : }
    3674              : 
    3675              : /* Return true if EXP contains a PLACEHOLDER_EXPR.  Don't walk into
    3676              :    ctors with CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag set.  */
    3677              : 
    3678              : bool
    3679       238975 : find_placeholders (tree exp)
    3680              : {
    3681              :   /* This is only relevant for C++14.  */
    3682       238975 :   if (cxx_dialect < cxx14)
    3683              :     return false;
    3684              : 
    3685       238975 :   return cp_walk_tree_without_duplicates (&exp, find_placeholders_r, NULL);
    3686              : }
    3687              : 
    3688              : /* Similar to `build_nt', but for template definitions of dependent
    3689              :    expressions  */
    3690              : 
    3691              : tree
    3692    341320577 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
    3693              : {
    3694    341320577 :   tree t;
    3695    341320577 :   int length;
    3696    341320577 :   int i;
    3697    341320577 :   va_list p;
    3698              : 
    3699    341320577 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3700              : 
    3701    341320577 :   va_start (p, code);
    3702              : 
    3703    341320577 :   t = make_node (code);
    3704    341320577 :   SET_EXPR_LOCATION (t, loc);
    3705    341320577 :   length = TREE_CODE_LENGTH (code);
    3706              : 
    3707   1121961508 :   for (i = 0; i < length; i++)
    3708    780640931 :     TREE_OPERAND (t, i) = va_arg (p, tree);
    3709              : 
    3710    341320577 :   va_end (p);
    3711    341320577 :   return t;
    3712              : }
    3713              : 
    3714              : /* Similar to `build', but for template definitions.  */
    3715              : 
    3716              : tree
    3717    259468126 : build_min (enum tree_code code, tree tt, ...)
    3718              : {
    3719    259468126 :   tree t;
    3720    259468126 :   int length;
    3721    259468126 :   int i;
    3722    259468126 :   va_list p;
    3723              : 
    3724    259468126 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3725              : 
    3726    259468126 :   va_start (p, tt);
    3727              : 
    3728    259468126 :   t = make_node (code);
    3729    259468126 :   length = TREE_CODE_LENGTH (code);
    3730    259468126 :   TREE_TYPE (t) = tt;
    3731              : 
    3732    692902045 :   for (i = 0; i < length; i++)
    3733              :     {
    3734    433433919 :       tree x = va_arg (p, tree);
    3735    433433919 :       TREE_OPERAND (t, i) = x;
    3736    433433919 :       if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
    3737      3408427 :         TREE_SIDE_EFFECTS (t) = 1;
    3738              :     }
    3739              : 
    3740    259468126 :   va_end (p);
    3741              : 
    3742    259468126 :   return t;
    3743              : }
    3744              : 
    3745              : /* Similar to `build', but for template definitions of non-dependent
    3746              :    expressions. NON_DEP is the non-dependent expression that has been
    3747              :    built.  */
    3748              : 
    3749              : tree
    3750    133635920 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
    3751              : {
    3752    133635920 :   tree t;
    3753    133635920 :   int length;
    3754    133635920 :   int i;
    3755    133635920 :   va_list p;
    3756              : 
    3757    133635920 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3758              : 
    3759    133635920 :   va_start (p, non_dep);
    3760              : 
    3761    133635920 :   if (REFERENCE_REF_P (non_dep))
    3762      1328910 :     non_dep = TREE_OPERAND (non_dep, 0);
    3763              : 
    3764    133635920 :   t = make_node (code);
    3765    180584408 :   SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
    3766    133635920 :   length = TREE_CODE_LENGTH (code);
    3767    133635920 :   TREE_TYPE (t) = unlowered_expr_type (non_dep);
    3768    133635920 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3769              : 
    3770    468198723 :   for (i = 0; i < length; i++)
    3771              :     {
    3772    334562803 :       tree x = va_arg (p, tree);
    3773    334562803 :       TREE_OPERAND (t, i) = x;
    3774    334562803 :       if (x && !TYPE_P (x))
    3775    263800238 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3776              :     }
    3777              : 
    3778    133635920 :   va_end (p);
    3779    133635920 :   return convert_from_reference (t);
    3780              : }
    3781              : 
    3782              : /* Similar to build_min_nt, but call expressions  */
    3783              : 
    3784              : tree
    3785    235189171 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
    3786              : {
    3787    235189171 :   tree ret, t;
    3788    235189171 :   unsigned int ix;
    3789              : 
    3790    470292848 :   ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
    3791    235189171 :   CALL_EXPR_FN (ret) = fn;
    3792    235189171 :   CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
    3793    496463581 :   FOR_EACH_VEC_SAFE_ELT (args, ix, t)
    3794    261274410 :     CALL_EXPR_ARG (ret, ix) = t;
    3795              : 
    3796    235189171 :   return ret;
    3797              : }
    3798              : 
    3799              : /* Similar to `build_min_nt_call_vec', but for template definitions of
    3800              :    non-dependent expressions. NON_DEP is the non-dependent expression
    3801              :    that has been built.  */
    3802              : 
    3803              : tree
    3804     13731065 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
    3805              : {
    3806     13731065 :   tree t = build_min_nt_call_vec (fn, argvec);
    3807     13731065 :   if (REFERENCE_REF_P (non_dep))
    3808            6 :     non_dep = TREE_OPERAND (non_dep, 0);
    3809     13731065 :   TREE_TYPE (t) = TREE_TYPE (non_dep);
    3810     13731065 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3811     13731065 :   if (argvec)
    3812     28218346 :     for (tree x : *argvec)
    3813     14572775 :       if (x && !TYPE_P (x))
    3814     14572775 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3815     13731065 :   return convert_from_reference (t);
    3816              : }
    3817              : 
    3818              : /* Similar to build_min_non_dep, but for expressions that have been resolved to
    3819              :    a call to an operator overload.  OP is the operator that has been
    3820              :    overloaded.  NON_DEP is the non-dependent expression that's been built,
    3821              :    which should be a CALL_EXPR or an INDIRECT_REF to a CALL_EXPR.  OVERLOAD is
    3822              :    the overload that NON_DEP is calling.  */
    3823              : 
    3824              : tree
    3825      6533842 : build_min_non_dep_op_overload (enum tree_code op,
    3826              :                                tree non_dep,
    3827              :                                tree overload, ...)
    3828              : {
    3829      6533842 :   va_list p;
    3830      6533842 :   int nargs, expected_nargs;
    3831      6533842 :   tree fn, call, obj = NULL_TREE;
    3832              : 
    3833      6533842 :   releasing_vec args;
    3834      6533842 :   va_start (p, overload);
    3835              : 
    3836      6533842 :   bool negated = false, rewritten = false, reversed = false;
    3837      6533842 :   if (cxx_dialect >= cxx20 && TREE_CODE (overload) == TREE_LIST)
    3838              :     {
    3839              :       /* Handle rebuilding a C++20 rewritten comparison operator expression,
    3840              :          e.g. !(x == y), y <=> x, (x <=> y) @ 0 etc, that resolved to a call
    3841              :          to a user-defined operator<=>/==.  */
    3842       546282 :       gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
    3843              :                            || op == SPACESHIP_EXPR);
    3844       546282 :       int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
    3845       546282 :       if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
    3846              :         {
    3847       499084 :           negated = true;
    3848       499084 :           non_dep = TREE_OPERAND (non_dep, 0);
    3849              :         }
    3850       546282 :       if (flags & LOOKUP_REWRITTEN)
    3851       546282 :         rewritten = true;
    3852       546282 :       if (flags & LOOKUP_REVERSED)
    3853          121 :         reversed = true;
    3854       546282 :       if (rewritten
    3855       546282 :           && DECL_OVERLOADED_OPERATOR_IS (TREE_VALUE (overload),
    3856              :                                           SPACESHIP_EXPR))
    3857              :         {
    3858              :           /* Handle (x <=> y) @ 0 and 0 @ (y <=> x) by recursing to first
    3859              :              rebuild the <=>.  Note that both OVERLOAD and the provided arguments
    3860              :              in this case already correspond to the selected operator<=>.  */
    3861              : 
    3862        47176 :           tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
    3863        94235 :                                     ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
    3864        47212 :                                     : TREE_OPERAND (non_dep, reversed ? 1 : 0));
    3865              : 
    3866        47176 :           tree int_promotion = NULL_TREE;
    3867        47176 :           if (TREE_CODE (spaceship_non_dep) == NOP_EXPR)
    3868              :             {
    3869           27 :               gcc_checking_assert (TREE_CODE (non_dep) != CALL_EXPR);
    3870           27 :               int_promotion = TREE_TYPE (spaceship_non_dep);
    3871           27 :               spaceship_non_dep = TREE_OPERAND (spaceship_non_dep, 0);
    3872              :             }
    3873              : 
    3874        47176 :           gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
    3875        47176 :           tree spaceship_op0 = va_arg (p, tree);
    3876        47176 :           tree spaceship_op1 = va_arg (p, tree);
    3877        47176 :           if (reversed)
    3878           81 :             std::swap (spaceship_op0, spaceship_op1);
    3879              : 
    3880              :           /* Push the correct arguments for the operator OP expression, and
    3881              :              set OVERLOAD appropriately.  */
    3882        47176 :           tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
    3883              :                                                     spaceship_non_dep,
    3884        47176 :                                                     TREE_VALUE (overload),
    3885              :                                                     spaceship_op0,
    3886        47176 :                                                     spaceship_op1);
    3887        47176 :           tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
    3888        94316 :                       ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
    3889          117 :                       : TREE_OPERAND (non_dep, reversed ? 0 : 1));
    3890        47176 :           gcc_checking_assert (integer_zerop (op1));
    3891              : 
    3892        47176 :           if (TREE_CODE (non_dep) != CALL_EXPR)
    3893              :             {
    3894           81 :               gcc_checking_assert (COMPARISON_CLASS_P (non_dep)
    3895              :                                    || TREE_CODE (non_dep) == SPACESHIP_EXPR);
    3896           81 :               if (int_promotion)
    3897           27 :                 op0 = build_nop (int_promotion, op0);
    3898           81 :               if (reversed)
    3899           45 :                 std::swap (op0, op1);
    3900           81 :               return build_min_non_dep (TREE_CODE (non_dep), non_dep, op0, op1);
    3901              :             }
    3902              : 
    3903        47095 :           vec_safe_push (args, op0);
    3904        47095 :           vec_safe_push (args, op1);
    3905        47095 :           overload = CALL_EXPR_FN (non_dep);
    3906              :         }
    3907              :       else
    3908       499106 :         overload = TREE_VALUE (overload);
    3909              :     }
    3910      6533761 :   non_dep = extract_call_expr (non_dep);
    3911              : 
    3912      6533761 :   nargs = call_expr_nargs (non_dep);
    3913              : 
    3914      6533761 :   expected_nargs = cp_tree_code_length (op);
    3915     12311838 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (overload)
    3916              :       /* For ARRAY_REF, operator[] is either a non-static member or newly
    3917              :          static member, never out of class and for the static member case
    3918              :          if user uses single index the operator[] needs to have a single
    3919              :          argument as well, but the function is called with 2 - the object
    3920              :          it is invoked on and the index.  */
    3921     12309411 :       || op == ARRAY_REF)
    3922       758120 :     expected_nargs -= 1;
    3923      6533761 :   if ((op == POSTINCREMENT_EXPR
    3924      6533761 :        || op == POSTDECREMENT_EXPR)
    3925              :       /* With -fpermissive non_dep could be operator++().  */
    3926        11568 :       && (!flag_permissive || nargs != expected_nargs))
    3927        11565 :     expected_nargs += 1;
    3928      6533761 :   gcc_assert (nargs == expected_nargs);
    3929              : 
    3930      6533761 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
    3931              :     {
    3932      5775650 :       fn = overload;
    3933      5775650 :       if (vec_safe_length (args) != 0)
    3934              :         /* The correct arguments were already pushed above.  */
    3935        47095 :         gcc_checking_assert (rewritten);
    3936              :       else
    3937              :         {
    3938      5728555 :           if (op == ARRAY_REF)
    3939            9 :             obj = va_arg (p, tree);
    3940     17100875 :           for (int i = 0; i < nargs; i++)
    3941              :             {
    3942     11372320 :               tree arg = va_arg (p, tree);
    3943     11372320 :               vec_safe_push (args, arg);
    3944              :             }
    3945              :         }
    3946      5775650 :       if (reversed)
    3947           52 :         std::swap ((*args)[0], (*args)[1]);
    3948              :     }
    3949              :   else
    3950              :     {
    3951       758111 :       gcc_checking_assert (vec_safe_length (args) == 0);
    3952       758111 :       tree object = va_arg (p, tree);
    3953      2032943 :       for (int i = 0; i < nargs; i++)
    3954              :         {
    3955       516721 :           tree arg = va_arg (p, tree);
    3956       516721 :           vec_safe_push (args, arg);
    3957              :         }
    3958       758111 :       if (reversed)
    3959           24 :         std::swap (object, (*args)[0]);
    3960       758111 :       tree binfo = TYPE_BINFO (TREE_TYPE (object));
    3961       758111 :       tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
    3962       758111 :       fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
    3963              :                       object, method, NULL_TREE);
    3964              :     }
    3965              : 
    3966      6533761 :   va_end (p);
    3967      6533761 :   call = build_min_non_dep_call_vec (non_dep, fn, args);
    3968              : 
    3969      6533761 :   tree call_expr = extract_call_expr (call);
    3970      6533761 :   KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
    3971      6533761 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
    3972      6533761 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
    3973      6533761 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
    3974              : 
    3975      6533761 :   if (negated)
    3976       499084 :     call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
    3977      6533761 :   if (obj)
    3978            9 :     return keep_unused_object_arg (call, obj, overload);
    3979              :   return call;
    3980      6533842 : }
    3981              : 
    3982              : /* Similar to above build_min_non_dep_op_overload, but arguments
    3983              :    are taken from ARGS vector.  */
    3984              : 
    3985              : tree
    3986           29 : build_min_non_dep_op_overload (tree non_dep, tree overload, tree object,
    3987              :                                vec<tree, va_gc> *args)
    3988              : {
    3989           29 :   non_dep = extract_call_expr (non_dep);
    3990              : 
    3991           29 :   unsigned int nargs = call_expr_nargs (non_dep);
    3992           29 :   tree fn = overload;
    3993           29 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (overload))
    3994              :     {
    3995           17 :       tree binfo = TYPE_BINFO (TREE_TYPE (object));
    3996           17 :       tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
    3997           17 :       fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
    3998              :                       object, method, NULL_TREE);
    3999           17 :       object = NULL_TREE;
    4000              :     }
    4001           58 :   gcc_assert (vec_safe_length (args) == nargs);
    4002              : 
    4003           29 :   tree call = build_min_non_dep_call_vec (non_dep, fn, args);
    4004              : 
    4005           29 :   tree call_expr = extract_call_expr (call);
    4006           29 :   KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
    4007           29 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
    4008           29 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
    4009           29 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
    4010              : 
    4011           29 :   if (object)
    4012           12 :     return keep_unused_object_arg (call, object, overload);
    4013              :   return call;
    4014              : }
    4015              : 
    4016              : /* Return a new tree vec copied from VEC, with ELT inserted at index IDX.  */
    4017              : 
    4018              : vec<tree, va_gc> *
    4019         9439 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
    4020              : {
    4021         9439 :   unsigned len = vec_safe_length (old_vec);
    4022         9439 :   gcc_assert (idx <= len);
    4023              : 
    4024         9439 :   vec<tree, va_gc> *new_vec = NULL;
    4025         9439 :   vec_alloc (new_vec, len + 1);
    4026              : 
    4027         9439 :   unsigned i;
    4028        28378 :   for (i = 0; i < len; ++i)
    4029              :     {
    4030         9500 :       if (i == idx)
    4031           61 :         new_vec->quick_push (elt);
    4032         9500 :       new_vec->quick_push ((*old_vec)[i]);
    4033              :     }
    4034         9439 :   if (i == idx)
    4035         9378 :     new_vec->quick_push (elt);
    4036              : 
    4037         9439 :   return new_vec;
    4038              : }
    4039              : 
    4040              : tree
    4041       150603 : get_type_decl (tree t)
    4042              : {
    4043       150603 :   if (TREE_CODE (t) == TYPE_DECL)
    4044              :     return t;
    4045       150603 :   if (TYPE_P (t))
    4046       150603 :     return TYPE_STUB_DECL (t);
    4047            0 :   gcc_assert (t == error_mark_node);
    4048              :   return t;
    4049              : }
    4050              : 
    4051              : /* Returns the namespace that contains DECL, whether directly or
    4052              :    indirectly.  */
    4053              : 
    4054              : tree
    4055   1372848703 : decl_namespace_context (tree decl)
    4056              : {
    4057   2849758145 :   while (1)
    4058              :     {
    4059   2849758145 :       if (TREE_CODE (decl) == NAMESPACE_DECL)
    4060   1372848703 :         return decl;
    4061   1476909442 :       else if (TYPE_P (decl))
    4062    894544904 :         decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
    4063              :       else
    4064    582364538 :         decl = CP_DECL_CONTEXT (decl);
    4065              :     }
    4066              : }
    4067              : 
    4068              : /* Returns true if decl is within an anonymous namespace, however deeply
    4069              :    nested, or false otherwise.  */
    4070              : 
    4071              : bool
    4072         2022 : decl_anon_ns_mem_p (tree decl)
    4073              : {
    4074         2022 :   return !TREE_PUBLIC (decl_namespace_context (decl));
    4075              : }
    4076              : 
    4077              : /* Returns true if the enclosing scope of DECL has internal or no linkage.  */
    4078              : 
    4079              : bool
    4080   1404048263 : decl_internal_context_p (const_tree decl)
    4081              : {
    4082   2813208048 :   while (TREE_CODE (decl) != NAMESPACE_DECL)
    4083              :     {
    4084              :       /* Classes inside anonymous namespaces have TREE_PUBLIC == 0.  */
    4085   1774665652 :       if (TYPE_P (decl))
    4086    365505867 :         return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
    4087              : 
    4088   1409159785 :       decl = CP_DECL_CONTEXT (decl);
    4089              :     }
    4090   1038542396 :   return !TREE_PUBLIC (decl);
    4091              : }
    4092              : 
    4093              : /* Subroutine of cp_tree_equal: t1 and t2 are two CALL_EXPRs.
    4094              :    Return whether their CALL_EXPR_FNs are equivalent.  */
    4095              : 
    4096              : static bool
    4097     55037740 : called_fns_equal (tree t1, tree t2)
    4098              : {
    4099              :   /* Core 1321: dependent names are equivalent even if the overload sets
    4100              :      are different.  But do compare explicit template arguments.  */
    4101     55037740 :   tree name1 = call_expr_dependent_name (t1);
    4102     55037740 :   tree name2 = call_expr_dependent_name (t2);
    4103     55037740 :   t1 = CALL_EXPR_FN (t1);
    4104     55037740 :   t2 = CALL_EXPR_FN (t2);
    4105     55037740 :   if (name1 || name2)
    4106              :     {
    4107     47272985 :       tree targs1 = NULL_TREE, targs2 = NULL_TREE;
    4108              : 
    4109     47272985 :       if (name1 != name2)
    4110              :         return false;
    4111              : 
    4112              :       /* FIXME dependent_name currently returns an unqualified name regardless
    4113              :          of whether the function was named with a qualified- or unqualified-id.
    4114              :          Until that's fixed, check that we aren't looking at overload sets from
    4115              :          different scopes.  */
    4116     46515340 :       if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
    4117     93064229 :           && (DECL_CONTEXT (get_first_fn (t1))
    4118     46515337 :               != DECL_CONTEXT (get_first_fn (t2))))
    4119              :         return false;
    4120              : 
    4121     46548892 :       if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
    4122     29181480 :         targs1 = TREE_OPERAND (t1, 1);
    4123     46548892 :       if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
    4124     29181480 :         targs2 = TREE_OPERAND (t2, 1);
    4125     46548892 :       return cp_tree_equal (targs1, targs2);
    4126              :     }
    4127              :   else
    4128      7764755 :     return cp_tree_equal (t1, t2);
    4129              : }
    4130              : 
    4131              : /* Return truthvalue of whether T1 is the same tree structure as T2.
    4132              :    Return 1 if they are the same. Return 0 if they are different.  */
    4133              : 
    4134              : bool
    4135   2785509466 : cp_tree_equal (tree t1, tree t2)
    4136              : {
    4137   2793715941 :   enum tree_code code1, code2;
    4138              : 
    4139   2793715941 :   if (t1 == t2)
    4140              :     return true;
    4141   1267896602 :   if (!t1 || !t2)
    4142              :     return false;
    4143              : 
    4144   1267169161 :   code1 = TREE_CODE (t1);
    4145   1267169161 :   code2 = TREE_CODE (t2);
    4146              : 
    4147   1267169161 :   if (comparing_contracts)
    4148              :     {
    4149              :       /* When comparing contracts, one declaration may already be
    4150              :          genericized. Check for invisible references and unravel them
    4151              :          for comparison purposes. Remember that a parameter is an invisible
    4152              :          reference so we can compare the parameter types accordingly.  */
    4153          213 :       if (code1 == VIEW_CONVERT_EXPR
    4154          213 :           && is_invisiref_parm (TREE_OPERAND(t1, 0)))
    4155              :         {
    4156            3 :           t1 = TREE_OPERAND(t1, 0);
    4157            3 :           code1 = TREE_CODE(t1);
    4158              :         }
    4159          213 :       if (code2 == VIEW_CONVERT_EXPR
    4160          213 :           && is_invisiref_parm (TREE_OPERAND(t2, 0)))
    4161              :         {
    4162            0 :           t2 = TREE_OPERAND(t2, 0);
    4163            0 :           code2 = TREE_CODE(t2);
    4164              :         }
    4165              :     }
    4166              : 
    4167   1267169161 :   if (code1 != code2)
    4168              :     return false;
    4169              : 
    4170   1139751933 :   if (CONSTANT_CLASS_P (t1)
    4171   1139751933 :       && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    4172              :     return false;
    4173              : 
    4174   1139665611 :   switch (code1)
    4175              :     {
    4176            0 :     case VOID_CST:
    4177              :       /* There's only a single VOID_CST node, so we should never reach
    4178              :          here.  */
    4179            0 :       gcc_unreachable ();
    4180              : 
    4181    178511467 :     case INTEGER_CST:
    4182    178511467 :       return tree_int_cst_equal (t1, t2);
    4183              : 
    4184       112435 :     case REAL_CST:
    4185       112435 :       return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
    4186              : 
    4187       153866 :     case STRING_CST:
    4188       153866 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
    4189       153866 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
    4190       153866 :                     TREE_STRING_LENGTH (t1));
    4191              : 
    4192            0 :     case FIXED_CST:
    4193            0 :       return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1),
    4194              :                                      TREE_FIXED_CST (t2));
    4195              : 
    4196           25 :     case COMPLEX_CST:
    4197           25 :       return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2))
    4198           50 :         && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2));
    4199              : 
    4200        15045 :     case VECTOR_CST:
    4201        15045 :       return operand_equal_p (t1, t2, OEP_ONLY_CONST);
    4202              : 
    4203      1582789 :     case CONSTRUCTOR:
    4204              :       /* We need to do this when determining whether or not two
    4205              :          non-type pointer to member function template arguments
    4206              :          are the same.  */
    4207      1582789 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    4208      3421388 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
    4209              :         return false;
    4210              :       {
    4211              :         tree field, value;
    4212              :         unsigned int i;
    4213      1729982 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
    4214              :           {
    4215       194031 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
    4216       194031 :             if (!cp_tree_equal (field, elt2->index)
    4217       194031 :                 || !cp_tree_equal (value, elt2->value))
    4218              :               return false;
    4219              :           }
    4220              :       }
    4221              :       return true;
    4222              : 
    4223      6324029 :     case TREE_LIST:
    4224      6324029 :       if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
    4225              :         return false;
    4226      6324029 :       if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
    4227              :         return false;
    4228        26968 :       return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
    4229              : 
    4230          743 :     case SAVE_EXPR:
    4231          743 :       return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
    4232              : 
    4233     55199737 :     case CALL_EXPR:
    4234     55199737 :       {
    4235     55199737 :         if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
    4236              :           return false;
    4237              : 
    4238     55037740 :         if (!called_fns_equal (t1, t2))
    4239              :           return false;
    4240              : 
    4241     24885227 :         call_expr_arg_iterator iter1, iter2;
    4242     24885227 :         init_call_expr_arg_iterator (t1, &iter1);
    4243     24885227 :         init_call_expr_arg_iterator (t2, &iter2);
    4244     24885227 :         if (iter1.n != iter2.n)
    4245              :           return false;
    4246              : 
    4247     26433312 :         while (more_call_expr_args_p (&iter1))
    4248              :           {
    4249     18121800 :             tree arg1 = next_call_expr_arg (&iter1);
    4250     18121800 :             tree arg2 = next_call_expr_arg (&iter2);
    4251              : 
    4252     18121800 :             gcc_checking_assert (arg1 && arg2);
    4253     18121800 :             if (!cp_tree_equal (arg1, arg2))
    4254              :               return false;
    4255              :           }
    4256              : 
    4257              :         return true;
    4258              :       }
    4259              : 
    4260       428265 :     case TARGET_EXPR:
    4261       428265 :       {
    4262       428265 :         tree o1 = TARGET_EXPR_SLOT (t1);
    4263       428265 :         tree o2 = TARGET_EXPR_SLOT (t2);
    4264              : 
    4265              :         /* Special case: if either target is an unallocated VAR_DECL,
    4266              :            it means that it's going to be unified with whatever the
    4267              :            TARGET_EXPR is really supposed to initialize, so treat it
    4268              :            as being equivalent to anything.  */
    4269       428265 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
    4270       856530 :             && !DECL_RTL_SET_P (o1))
    4271              :           /*Nop*/;
    4272            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
    4273            0 :                  && !DECL_RTL_SET_P (o2))
    4274              :           /*Nop*/;
    4275            0 :         else if (!cp_tree_equal (o1, o2))
    4276              :           return false;
    4277              : 
    4278       428265 :         return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
    4279       856530 :                               TARGET_EXPR_INITIAL (t2));
    4280              :       }
    4281              : 
    4282           27 :     case AGGR_INIT_EXPR:
    4283           27 :       {
    4284           27 :         int n = aggr_init_expr_nargs (t1);
    4285           27 :         if (n != aggr_init_expr_nargs (t2))
    4286              :           return false;
    4287              : 
    4288           54 :         if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
    4289           27 :                             AGGR_INIT_EXPR_FN (t2)))
    4290              :           return false;
    4291              : 
    4292           27 :         tree o1 = AGGR_INIT_EXPR_SLOT (t1);
    4293           27 :         tree o2 = AGGR_INIT_EXPR_SLOT (t2);
    4294              : 
    4295              :         /* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
    4296              :            going to unify the initialization, so treat it as equivalent
    4297              :            to anything.  */
    4298           27 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
    4299           54 :             && !DECL_RTL_SET_P (o1))
    4300              :           /*Nop*/;
    4301            0 :         else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
    4302            0 :                  && !DECL_RTL_SET_P (o2))
    4303              :           /*Nop*/;
    4304            0 :         else if (!cp_tree_equal (o1, o2))
    4305              :           return false;
    4306              : 
    4307           56 :         for (int i = 0; i < n; ++i)
    4308           35 :           if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
    4309           35 :                               AGGR_INIT_EXPR_ARG (t2, i)))
    4310              :             return false;
    4311              : 
    4312              :         return true;
    4313              :       }
    4314              : 
    4315      1989493 :     case PARM_DECL:
    4316              :       /* For comparing uses of parameters in late-specified return types
    4317              :          with an out-of-class definition of the function, but can also come
    4318              :          up for expressions that involve 'this' in a member function
    4319              :          template.  */
    4320              : 
    4321      1989493 :       if (comparing_specializations
    4322      1989493 :           && DECL_CONTEXT (t1) != DECL_CONTEXT (t2))
    4323              :         /* When comparing hash table entries, only an exact match is
    4324              :            good enough; we don't want to replace 'this' with the
    4325              :            version from another function.  But be more flexible
    4326              :            with parameters with identical contexts.  */
    4327              :         return false;
    4328              : 
    4329      1593730 :       if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) || comparing_contracts)
    4330              :         {
    4331              :           /* When comparing contracts, we already know the declarations match,
    4332              :             and that the arguments have the same type. If one of the declarations
    4333              :             has been genericised, then the type of arguments in that declaration
    4334              :             will be adjusted for an invisible reference and the type comparison
    4335              :             would spuriosly fail. The only thing we care about when comparing
    4336              :             contractsis that we're using the same parameter.  */
    4337       823556 :           if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
    4338              :             return false;
    4339       823556 :           if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
    4340              :             return false;
    4341       823556 :           if (DECL_ARTIFICIAL (t1)
    4342       823556 :               || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
    4343       822917 :                   && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
    4344              :             return true;
    4345              :         }
    4346              :       return false;
    4347              : 
    4348     30457432 :     case TEMPLATE_DECL:
    4349     30457432 :       if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
    4350     32888465 :           && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
    4351       165733 :         return cp_tree_equal (TREE_TYPE (t1), TREE_TYPE (t2));
    4352              :       /* Fall through.  */
    4353              :     case VAR_DECL:
    4354              :     case CONST_DECL:
    4355              :     case FIELD_DECL:
    4356              :     case FUNCTION_DECL:
    4357              :     case IDENTIFIER_NODE:
    4358              :     case SSA_NAME:
    4359              :     case USING_DECL:
    4360              :     case DEFERRED_PARSE:
    4361              :     case NAMESPACE_DECL:
    4362              :       return false;
    4363              : 
    4364      5280659 :     case BASELINK:
    4365      5280659 :       return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
    4366      4439025 :               && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
    4367      4439025 :               && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
    4368      9719672 :               && cp_tree_equal (BASELINK_FUNCTIONS (t1),
    4369      4439013 :                                 BASELINK_FUNCTIONS (t2)));
    4370              : 
    4371     14173658 :     case TEMPLATE_PARM_INDEX:
    4372     14173658 :       return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
    4373     13502622 :               && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
    4374     12815352 :               && (TEMPLATE_PARM_PARAMETER_PACK (t1)
    4375     12815352 :                   == TEMPLATE_PARM_PARAMETER_PACK (t2))
    4376     26941225 :               && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
    4377              :                               TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
    4378              : 
    4379     23064391 :     case TEMPLATE_ID_EXPR:
    4380     23064391 :       if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4381              :         return false;
    4382     22385315 :       if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
    4383              :         return false;
    4384              :       return true;
    4385              : 
    4386      7583101 :     case CONSTRAINT_INFO:
    4387     22749303 :       return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
    4388     22749303 :                             CI_ASSOCIATED_CONSTRAINTS (t2));
    4389              : 
    4390     57454971 :     case TREE_VEC:
    4391              :       /* These are template args.  Really we should be getting the
    4392              :          caller to do this as it knows it to be true.  */
    4393     57454971 :       if (!comp_template_args (t1, t2))
    4394              :         return false;
    4395              :       return true;
    4396              : 
    4397      1707514 :     case SIZEOF_EXPR:
    4398      1707514 :     case ALIGNOF_EXPR:
    4399      1707514 :       {
    4400      1707514 :         tree o1 = TREE_OPERAND (t1, 0);
    4401      1707514 :         tree o2 = TREE_OPERAND (t2, 0);
    4402              : 
    4403      1707514 :         if (code1 == SIZEOF_EXPR)
    4404              :           {
    4405      1698060 :             if (SIZEOF_EXPR_TYPE_P (t1))
    4406            0 :               o1 = TREE_TYPE (o1);
    4407      1698060 :             if (SIZEOF_EXPR_TYPE_P (t2))
    4408            0 :               o2 = TREE_TYPE (o2);
    4409              :           }
    4410         9454 :         else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
    4411              :           return false;
    4412              : 
    4413      1707508 :         if (TREE_CODE (o1) != TREE_CODE (o2))
    4414              :           return false;
    4415              : 
    4416      1707504 :         if (ARGUMENT_PACK_P (o1))
    4417           10 :           return template_args_equal (o1, o2);
    4418      1707494 :         else if (TYPE_P (o1))
    4419      1706106 :           return same_type_p (o1, o2);
    4420              :         else
    4421              :           return cp_tree_equal (o1, o2);
    4422              :       }
    4423              : 
    4424         5518 :     case MODOP_EXPR:
    4425         5518 :       {
    4426         5518 :         tree t1_op1, t2_op1;
    4427              : 
    4428         5518 :         if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4429              :           return false;
    4430              : 
    4431         2994 :         t1_op1 = TREE_OPERAND (t1, 1);
    4432         2994 :         t2_op1 = TREE_OPERAND (t2, 1);
    4433         2994 :         if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
    4434              :           return false;
    4435              : 
    4436          277 :         return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
    4437              :       }
    4438              : 
    4439          759 :     case PTRMEM_CST:
    4440              :       /* Two pointer-to-members are the same if they point to the same
    4441              :          field or function in the same class.  */
    4442          759 :       if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
    4443              :         return false;
    4444              : 
    4445          934 :       return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
    4446              : 
    4447        20960 :     case OVERLOAD:
    4448        20960 :       {
    4449              :         /* Two overloads. Must be exactly the same set of decls.  */
    4450        20960 :         lkp_iterator first (t1);
    4451        20960 :         lkp_iterator second (t2);
    4452              : 
    4453        30194 :         for (; first && second; ++first, ++second)
    4454        21503 :           if (*first != *second)
    4455              :             return false;
    4456         8691 :         return !(first || second);
    4457              :       }
    4458              : 
    4459      7758264 :     case TRAIT_EXPR:
    4460      7758264 :       if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
    4461              :         return false;
    4462       794247 :       return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
    4463      1572172 :         && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
    4464              : 
    4465      1148197 :     case NON_LVALUE_EXPR:
    4466      1148197 :     case VIEW_CONVERT_EXPR:
    4467              :       /* Used for location wrappers with possibly NULL types.  */
    4468      1148197 :       if (!TREE_TYPE (t1) || !TREE_TYPE (t2))
    4469              :         {
    4470           23 :           if (TREE_TYPE (t1) || TREE_TYPE (t2))
    4471              :             return false;
    4472              :           break;
    4473              :         }
    4474              :       /* FALLTHROUGH  */
    4475              : 
    4476      3480560 :     case CAST_EXPR:
    4477      3480560 :     case STATIC_CAST_EXPR:
    4478      3480560 :     case REINTERPRET_CAST_EXPR:
    4479      3480560 :     case CONST_CAST_EXPR:
    4480      3480560 :     case DYNAMIC_CAST_EXPR:
    4481      3480560 :     case IMPLICIT_CONV_EXPR:
    4482      3480560 :     case NEW_EXPR:
    4483      3480560 :     case BIT_CAST_EXPR:
    4484      3480560 :     CASE_CONVERT:
    4485      3480560 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    4486              :         return false;
    4487              :       /* Now compare operands as usual.  */
    4488              :       break;
    4489              : 
    4490            0 :     case DEFERRED_NOEXCEPT:
    4491            0 :       return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1),
    4492            0 :                              DEFERRED_NOEXCEPT_PATTERN (t2))
    4493            0 :               && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1),
    4494            0 :                                      DEFERRED_NOEXCEPT_ARGS (t2)));
    4495              : 
    4496              :     case LAMBDA_EXPR:
    4497              :       /* Two lambda-expressions are never considered equivalent.  */
    4498              :       return false;
    4499              : 
    4500    633634448 :     case TYPE_ARGUMENT_PACK:
    4501    633634448 :     case NONTYPE_ARGUMENT_PACK:
    4502    633634448 :       {
    4503    633634448 :         tree p1 = ARGUMENT_PACK_ARGS (t1);
    4504    633634448 :         tree p2 = ARGUMENT_PACK_ARGS (t2);
    4505    633634448 :         int len = TREE_VEC_LENGTH (p1);
    4506    633634448 :         if (TREE_VEC_LENGTH (p2) != len)
    4507              :           return false;
    4508              : 
    4509    765109807 :         for (int ix = 0; ix != len; ix++)
    4510    679735957 :           if (!template_args_equal (TREE_VEC_ELT (p1, ix),
    4511    679735957 :                                     TREE_VEC_ELT (p2, ix)))
    4512              :             return false;
    4513              :         return true;
    4514              :       }
    4515              : 
    4516       793655 :     case EXPR_PACK_EXPANSION:
    4517       793655 :       if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
    4518       793655 :                           PACK_EXPANSION_PATTERN (t2)))
    4519              :         return false;
    4520        26219 :       if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    4521        26219 :                                PACK_EXPANSION_EXTRA_ARGS (t2)))
    4522              :         return false;
    4523              :       return true;
    4524              : 
    4525         2232 :     case PACK_INDEX_EXPR:
    4526         2232 :       if (!cp_tree_equal (PACK_INDEX_PACK (t1),
    4527         2232 :                           PACK_INDEX_PACK (t2)))
    4528              :         return false;
    4529          108 :       if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
    4530          108 :                           PACK_INDEX_INDEX (t2)))
    4531              :         return false;
    4532              :       return true;
    4533              : 
    4534         2098 :     case REFLECT_EXPR:
    4535         2098 :       return compare_reflections (t1, t2);
    4536              : 
    4537      6464653 :     case REQUIRES_EXPR:
    4538     12929306 :       if (cp_tree_equal (REQUIRES_EXPR_PARMS (t1),
    4539      6464653 :                           REQUIRES_EXPR_PARMS (t2))
    4540      6293987 :           && cp_tree_equal (REQUIRES_EXPR_REQS (t1),
    4541      6293987 :                             REQUIRES_EXPR_REQS (t2))
    4542      6474921 :           && cp_tree_equal (REQUIRES_EXPR_EXTRA_ARGS (t1),
    4543        10268 :                             REQUIRES_EXPR_EXTRA_ARGS (t2)))
    4544              :         return true;
    4545              :       return false;
    4546              : 
    4547              :     default:
    4548              :       break;
    4549              :     }
    4550              : 
    4551     70606930 :   switch (TREE_CODE_CLASS (code1))
    4552              :     {
    4553     64944897 :     case tcc_unary:
    4554     64944897 :     case tcc_binary:
    4555     64944897 :     case tcc_comparison:
    4556     64944897 :     case tcc_expression:
    4557     64944897 :     case tcc_vl_exp:
    4558     64944897 :     case tcc_reference:
    4559     64944897 :     case tcc_statement:
    4560     64944897 :       {
    4561     64944897 :         int n = cp_tree_operand_length (t1);
    4562     64944897 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
    4563     64944897 :             && n != TREE_OPERAND_LENGTH (t2))
    4564              :           return false;
    4565              : 
    4566    110422028 :         for (int i = 0; i < n; ++i)
    4567     82682035 :           if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
    4568              :             return false;
    4569              : 
    4570              :         return true;
    4571              :       }
    4572              : 
    4573      5662033 :     case tcc_type:
    4574      5662033 :       return same_type_p (t1, t2);
    4575              : 
    4576            0 :     default:
    4577            0 :       gcc_unreachable ();
    4578              :     }
    4579              : 
    4580              :   /* We can get here with --disable-checking.  */
    4581              :   return false;
    4582              : }
    4583              : 
    4584              : /* The type of ARG when used as an lvalue.  */
    4585              : 
    4586              : tree
    4587    909698675 : lvalue_type (tree arg)
    4588              : {
    4589    909698675 :   tree type = TREE_TYPE (arg);
    4590    909698675 :   return type;
    4591              : }
    4592              : 
    4593              : /* The type of ARG for printing error messages; denote lvalues with
    4594              :    reference types.  */
    4595              : 
    4596              : tree
    4597         3791 : error_type (tree arg)
    4598              : {
    4599         3791 :   tree type = TREE_TYPE (arg);
    4600              : 
    4601         3791 :   if (TREE_CODE (type) == ARRAY_TYPE)
    4602              :     ;
    4603         3680 :   else if (TREE_CODE (type) == ERROR_MARK)
    4604              :     ;
    4605         3680 :   else if (lvalue_p (arg))
    4606         1282 :     type = build_reference_type (lvalue_type (arg));
    4607         2398 :   else if (MAYBE_CLASS_TYPE_P (type))
    4608          754 :     type = lvalue_type (arg);
    4609              : 
    4610         3791 :   return type;
    4611              : }
    4612              : 
    4613              : /* Does FUNCTION use a variable-length argument list?  */
    4614              : 
    4615              : int
    4616       513707 : varargs_function_p (const_tree function)
    4617              : {
    4618       513707 :   return stdarg_p (TREE_TYPE (function));
    4619              : }
    4620              : 
    4621              : /* Returns 1 if decl is a member of a class.  */
    4622              : 
    4623              : int
    4624        11546 : member_p (const_tree decl)
    4625              : {
    4626        11546 :   const_tree const ctx = DECL_CONTEXT (decl);
    4627        11546 :   return (ctx && TYPE_P (ctx));
    4628              : }
    4629              : 
    4630              : /* Create a placeholder for member access where we don't actually have an
    4631              :    object that the access is against.  For a general declval<T> equivalent,
    4632              :    use build_stub_object instead.  */
    4633              : 
    4634              : tree
    4635     88185891 : build_dummy_object (tree type)
    4636              : {
    4637     88185891 :   tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
    4638     88185891 :   return cp_build_fold_indirect_ref (decl);
    4639              : }
    4640              : 
    4641              : /* We've gotten a reference to a member of TYPE.  Return *this if appropriate,
    4642              :    or a dummy object otherwise.  If BINFOP is non-0, it is filled with the
    4643              :    binfo path from current_class_type to TYPE, or 0.  */
    4644              : 
    4645              : tree
    4646    114784355 : maybe_dummy_object (tree type, tree* binfop)
    4647              : {
    4648    114784355 :   tree decl, context;
    4649    114784355 :   tree binfo;
    4650    114784355 :   tree current = current_nonlambda_class_type ();
    4651              : 
    4652    114784355 :   if (current
    4653    114784355 :       && (binfo = lookup_base (current, type, ba_any, NULL,
    4654              :                                tf_warning_or_error)))
    4655              :     context = current;
    4656              :   else
    4657              :     {
    4658              :       /* Reference from a nested class member function.  */
    4659      8502408 :       context = type;
    4660      8502408 :       binfo = TYPE_BINFO (type);
    4661              :     }
    4662              : 
    4663    114784355 :   if (binfop)
    4664       111775 :     *binfop = binfo;
    4665              : 
    4666              :   /* current_class_ref might not correspond to current_class_type if
    4667              :      we're in tsubst_default_argument or a lambda-declarator; in either
    4668              :      case, we want to use current_class_ref if it matches CONTEXT.  */
    4669    114784355 :   tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
    4670    105461147 :   if (ctype
    4671    105461147 :       && same_type_ignoring_top_level_qualifiers_p (ctype, context))
    4672    102159128 :     decl = current_class_ref;
    4673              :   else
    4674              :     {
    4675              :       /* Return a dummy object whose cv-quals are consistent with (the
    4676              :          non-lambda) 'this' if available.  */
    4677     12625227 :       if (ctype)
    4678              :         {
    4679      3302019 :           int quals = TYPE_UNQUALIFIED;
    4680      3302019 :           if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
    4681              :             {
    4682       424702 :               if (tree cap = lambda_expr_this_capture (lambda, false))
    4683       409817 :                 quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
    4684              :             }
    4685              :           else
    4686      2877317 :             quals = cp_type_quals (ctype);
    4687      3302019 :           context = cp_build_qualified_type (context, quals);
    4688              :         }
    4689     12625227 :       decl = build_dummy_object (context);
    4690              :     }
    4691              : 
    4692    114784355 :   return decl;
    4693              : }
    4694              : 
    4695              : /* Returns 1 if OB is a placeholder object, or a pointer to one.  */
    4696              : 
    4697              : bool
    4698    541767374 : is_dummy_object (const_tree ob)
    4699              : {
    4700    541767374 :   if (INDIRECT_REF_P (ob))
    4701    415867338 :     ob = TREE_OPERAND (ob, 0);
    4702    541767374 :   return (TREE_CODE (ob) == CONVERT_EXPR
    4703    541767374 :           && TREE_OPERAND (ob, 0) == void_node);
    4704              : }
    4705              : 
    4706              : /* Returns true if TYPE is char, unsigned char, or std::byte.  */
    4707              : 
    4708              : bool
    4709     34882454 : is_byte_access_type (tree type)
    4710              : {
    4711     34882454 :   type = TYPE_MAIN_VARIANT (type);
    4712     34882454 :   if (type == char_type_node
    4713      7495548 :       || type == unsigned_char_type_node)
    4714              :     return true;
    4715              : 
    4716      7352009 :   return (TREE_CODE (type) == ENUMERAL_TYPE
    4717        28231 :           && TYPE_CONTEXT (type) == std_node
    4718      7370999 :           && !strcmp ("byte", TYPE_NAME_STRING (type)));
    4719              : }
    4720              : 
    4721              : /* Returns true if TYPE is unsigned char or std::byte.  */
    4722              : 
    4723              : bool
    4724        14414 : is_byte_access_type_not_plain_char (tree type)
    4725              : {
    4726        14414 :   type = TYPE_MAIN_VARIANT (type);
    4727        14414 :   if (type == char_type_node)
    4728              :     return false;
    4729              : 
    4730        14166 :   return is_byte_access_type (type);
    4731              : }
    4732              : 
    4733              : /* Returns 1 iff type T is something we want to treat as a scalar type for
    4734              :    the purpose of deciding whether it is trivial/POD/standard-layout.  */
    4735              : 
    4736              : bool
    4737     92316005 : scalarish_type_p (const_tree t)
    4738              : {
    4739     92316005 :   if (t == error_mark_node)
    4740              :     return 1;
    4741              : 
    4742     92315790 :   return (SCALAR_TYPE_P (t) || VECTOR_TYPE_P (t));
    4743              : }
    4744              : 
    4745              : /* Returns true iff T requires non-trivial default initialization.  */
    4746              : 
    4747              : bool
    4748            0 : type_has_nontrivial_default_init (const_tree t)
    4749              : {
    4750            0 :   t = strip_array_types (const_cast<tree> (t));
    4751              : 
    4752            0 :   if (CLASS_TYPE_P (t))
    4753            0 :     return TYPE_HAS_COMPLEX_DFLT (t);
    4754              :   else
    4755              :     return 0;
    4756              : }
    4757              : 
    4758              : /* Track classes with only deleted copy/move constructors so that we can warn
    4759              :    if they are used in call/return by value.  */
    4760              : 
    4761              : static GTY(()) hash_set<tree>* deleted_copy_types;
    4762              : static void
    4763            9 : remember_deleted_copy (const_tree t)
    4764              : {
    4765            9 :   if (!deleted_copy_types)
    4766            9 :     deleted_copy_types = hash_set<tree>::create_ggc(37);
    4767            9 :   deleted_copy_types->add (const_cast<tree> (t));
    4768            9 : }
    4769              : void
    4770    379773510 : maybe_warn_parm_abi (tree t, location_t loc)
    4771              : {
    4772    379773510 :   if (!deleted_copy_types
    4773    379773510 :       || !deleted_copy_types->contains (t))
    4774    379773480 :     return;
    4775              : 
    4776           30 :   if ((flag_abi_version == 12 || warn_abi_version == 12)
    4777           36 :       && classtype_has_non_deleted_move_ctor (t))
    4778              :     {
    4779            6 :       bool w;
    4780            6 :       auto_diagnostic_group d;
    4781            6 :       if (flag_abi_version > 12)
    4782            0 :         w = warning_at (loc, OPT_Wabi, "%<-fabi-version=13%> (GCC 8.2) fixes "
    4783              :                         "the calling convention for %qT, which was "
    4784              :                         "accidentally changed in 8.1", t);
    4785              :       else
    4786            6 :         w = warning_at (loc, OPT_Wabi, "%<-fabi-version=12%> (GCC 8.1) "
    4787              :                         "accidentally changes the calling convention for %qT",
    4788              :                         t);
    4789            6 :       if (w)
    4790            6 :         inform (location_of (t), " declared here");
    4791            6 :       return;
    4792            6 :     }
    4793              : 
    4794           30 :   auto_diagnostic_group d;
    4795           30 :   if (warning_at (loc, OPT_Wabi, "the calling convention for %qT changes in "
    4796              :                   "%<-fabi-version=13%> (GCC 8.2)", t))
    4797           30 :     inform (location_of (t), " because all of its copy and move "
    4798              :             "constructors are deleted");
    4799           30 : }
    4800              : 
    4801              : /* Returns true iff copying an object of type T (including via move
    4802              :    constructor) is non-trivial.  That is, T has no non-trivial copy
    4803              :    constructors and no non-trivial move constructors, and not all copy/move
    4804              :    constructors are deleted.  This function implements the ABI notion of
    4805              :    non-trivial copy, which has diverged from the one in the standard.  */
    4806              : 
    4807              : bool
    4808     60802218 : type_has_nontrivial_copy_init (const_tree type)
    4809              : {
    4810     60802218 :   tree t = strip_array_types (const_cast<tree> (type));
    4811              : 
    4812     60802218 :   if (CLASS_TYPE_P (t))
    4813              :     {
    4814     60127464 :       gcc_assert (COMPLETE_TYPE_P (t));
    4815              : 
    4816     60127464 :       if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
    4817     60127464 :           || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
    4818              :         /* Nontrivial.  */
    4819              :         return true;
    4820              : 
    4821     55962539 :       if (cxx_dialect < cxx11)
    4822              :         /* No deleted functions before C++11.  */
    4823              :         return false;
    4824              : 
    4825              :       /* Before ABI v12 we did a bitwise copy of types with only deleted
    4826              :          copy/move constructors.  */
    4827     55860793 :       if (!abi_version_at_least (12)
    4828         8132 :           && !(warn_abi && abi_version_crosses (12)))
    4829              :         return false;
    4830              : 
    4831     55852891 :       bool saw_copy = false;
    4832     55852891 :       bool saw_non_deleted = false;
    4833     55852891 :       bool saw_non_deleted_move = false;
    4834              : 
    4835     55852891 :       if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    4836              :         saw_copy = saw_non_deleted = true;
    4837      5107232 :       else if (CLASSTYPE_LAZY_COPY_CTOR (t))
    4838              :         {
    4839       594478 :           saw_copy = true;
    4840       594478 :           if (classtype_has_move_assign_or_move_ctor_p (t, true))
    4841              :             /* [class.copy]/8 If the class definition declares a move
    4842              :                constructor or move assignment operator, the implicitly declared
    4843              :                copy constructor is defined as deleted.... */;
    4844              :           else
    4845              :             /* Any other reason the implicitly-declared function would be
    4846              :                deleted would also cause TYPE_HAS_COMPLEX_COPY_CTOR to be
    4847              :                set.  */
    4848              :             saw_non_deleted = true;
    4849              :         }
    4850              : 
    4851              :       if (!saw_non_deleted)
    4852     20511233 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    4853              :           {
    4854     12180331 :             tree fn = *iter;
    4855     12180331 :             if (copy_fn_p (fn))
    4856              :               {
    4857      4512809 :                 saw_copy = true;
    4858      4512809 :                 if (!DECL_DELETED_FN (fn))
    4859              :                   {
    4860              :                     /* Not deleted, therefore trivial.  */
    4861              :                     saw_non_deleted = true;
    4862              :                     break;
    4863              :                   }
    4864              :               }
    4865      7667522 :             else if (move_fn_p (fn))
    4866      3156548 :               if (!DECL_DELETED_FN (fn))
    4867      3134267 :                 saw_non_deleted_move = true;
    4868              :           }
    4869              : 
    4870     55852891 :       gcc_assert (saw_copy);
    4871              : 
    4872              :       /* ABI v12 buggily ignored move constructors.  */
    4873     55852891 :       bool v11nontriv = false;
    4874     55852891 :       bool v12nontriv = !saw_non_deleted;
    4875     55852891 :       bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
    4876     55852891 :       bool nontriv = (abi_version_at_least (13) ? v13nontriv
    4877          124 :                       : flag_abi_version == 12 ? v12nontriv
    4878          124 :                       : v11nontriv);
    4879     55852891 :       bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
    4880          428 :                            : warn_abi_version == 12 ? v12nontriv
    4881              :                            : v11nontriv);
    4882     55852891 :       if (nontriv != warn_nontriv)
    4883            9 :         remember_deleted_copy (t);
    4884              : 
    4885              :       return nontriv;
    4886              :     }
    4887              :   else
    4888              :     return 0;
    4889              : }
    4890              : 
    4891              : /* Returns 1 iff type T is a trivially copyable type, as defined in
    4892              :    [basic.types] and [class].  */
    4893              : 
    4894              : bool
    4895       555176 : trivially_copyable_p (const_tree t)
    4896              : {
    4897       555176 :   t = strip_array_types (const_cast<tree> (t));
    4898              : 
    4899       555176 :   if (CLASS_TYPE_P (t))
    4900        86974 :     return ((!TYPE_HAS_COPY_CTOR (t)
    4901        86974 :              || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
    4902        86029 :             && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
    4903        85991 :             && (!TYPE_HAS_COPY_ASSIGN (t)
    4904        85991 :                 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
    4905        84975 :             && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    4906       171780 :             && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
    4907              :   else
    4908              :     /* CWG 2094 makes volatile-qualified scalars trivially copyable again.  */
    4909       468202 :     return scalarish_type_p (t);
    4910              : }
    4911              : 
    4912              : /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and
    4913              :    [class].  */
    4914              : 
    4915              : bool
    4916        79440 : trivial_type_p (const_tree t)
    4917              : {
    4918        79440 :   t = strip_array_types (const_cast<tree> (t));
    4919              : 
    4920        79440 :   if (CLASS_TYPE_P (t))
    4921              :     /* A trivial class is a class that is trivially copyable and has one or
    4922              :        more eligible default constructors, all of which are trivial.  */
    4923        20225 :     return (type_has_non_deleted_trivial_default_ctor (const_cast<tree> (t))
    4924        20225 :             && trivially_copyable_p (t));
    4925              :   else
    4926        59215 :     return scalarish_type_p (t);
    4927              : }
    4928              : 
    4929              : /* Returns true iff type T is a trivially copy constructible type.  */
    4930              : 
    4931              : bool
    4932           89 : trivially_copy_constructible_p (tree t)
    4933              : {
    4934           89 :   tree arg = make_tree_vec (1);
    4935           89 :   TREE_VEC_ELT (arg, 0) = build_const_lref (t);
    4936           89 :   return is_trivially_xible (INIT_EXPR, t, arg);
    4937              : }
    4938              : 
    4939              : /* Returns true iff FN (which is a special member function) is
    4940              :    an eligible special member function, as defined in [special]/6.
    4941              :    The "no special member function of the same kind whose associated
    4942              :    constraints, if any, are satisfied is more constrained" condition
    4943              :    is not checked, this is checked during add_method instead.  */
    4944              : 
    4945              : static bool
    4946          494 : eligible_special_member_function_p (tree fn)
    4947              : {
    4948              :   /* The function is not deleted.  */
    4949          494 :   if (DECL_DELETED_FN (fn))
    4950              :     return false;
    4951              :   /* The associated constraints, if any, are satisfied.  */
    4952          494 :   if (!constraints_satisfied_p (fn))
    4953              :     return false;
    4954              :   return true;
    4955              : }
    4956              : 
    4957              : /* Returns true iff type T is an implicit-lifetime type, as defined in
    4958              :    [basic.types.general] and [class.prop].  */
    4959              : 
    4960              : bool
    4961         1730 : implicit_lifetime_type_p (tree t)
    4962              : {
    4963         1730 :   if (SCALAR_TYPE_P (t)
    4964         1426 :       || (TREE_CODE (t) == ARRAY_TYPE
    4965          483 :           && !(TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))))
    4966              :       /* GNU extension.  */
    4967          948 :       || TREE_CODE (t) == VECTOR_TYPE)
    4968              :     return true;
    4969          943 :   if (!CLASS_TYPE_P (t))
    4970              :     return false;
    4971          871 :   t = TYPE_MAIN_VARIANT (t);
    4972              :   /* It is an aggregate whose destructor is not user-provided.  */
    4973         1742 :   if (CP_AGGREGATE_TYPE_P (t)
    4974         1187 :       && (!CLASSTYPE_DESTRUCTOR (t)
    4975          231 :           || !user_provided_p (CLASSTYPE_DESTRUCTOR (t))))
    4976              :     return true;
    4977          584 :   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
    4978              :     return false;
    4979          535 :   if (TYPE_HAS_COMPLEX_DFLT (t)
    4980          172 :       && TYPE_HAS_COMPLEX_COPY_CTOR (t)
    4981          598 :       && TYPE_HAS_COMPLEX_MOVE_CTOR (t))
    4982              :     return false;
    4983          509 :   if (CLASSTYPE_LAZY_DESTRUCTOR (t))
    4984          126 :     lazily_declare_fn (sfk_destructor, t);
    4985              :   /* It has at least one trivial eligible constructor and a trivial,
    4986              :      non-deleted destructor.  */
    4987          509 :   tree fn = CLASSTYPE_DESTRUCTOR (t);
    4988          509 :   if (!fn || DECL_DELETED_FN (fn))
    4989              :     return false;
    4990          613 :   for (ovl_iterator iter (get_class_binding (t, complete_ctor_identifier));
    4991          613 :        iter; ++iter)
    4992              :     {
    4993          595 :       fn = *iter;
    4994         1109 :       if ((default_ctor_p (fn) || copy_fn_p (fn) || move_fn_p (fn))
    4995          579 :           && trivial_fn_p (fn)
    4996         1089 :           && eligible_special_member_function_p (fn))
    4997          491 :         return true;
    4998              :     }
    4999           18 :   return false;
    5000              : }
    5001              : 
    5002              : /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
    5003              : 
    5004              : bool
    5005        11847 : pod_type_p (const_tree t)
    5006              : {
    5007              :   /* This CONST_CAST is okay because strip_array_types returns its
    5008              :      argument unmodified and we assign it to a const_tree.  */
    5009        11847 :   t = strip_array_types (const_cast<tree>(t));
    5010              : 
    5011        11847 :   if (!CLASS_TYPE_P (t))
    5012          728 :     return scalarish_type_p (t);
    5013        11119 :   else if (cxx_dialect > cxx98)
    5014              :     /* [class]/10: A POD struct is a class that is both a trivial class and a
    5015              :        standard-layout class, and has no non-static data members of type
    5016              :        non-POD struct, non-POD union (or array of such types).
    5017              : 
    5018              :        We don't need to check individual members because if a member is
    5019              :        non-std-layout or non-trivial, the class will be too.  */
    5020        10802 :     return (std_layout_type_p (t) && trivial_type_p (t));
    5021              :   else
    5022              :     /* The C++98 definition of POD is different.  */
    5023          317 :     return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    5024              : }
    5025              : 
    5026              : /* Returns true iff T is POD for the purpose of layout, as defined in the
    5027              :    C++ ABI.  */
    5028              : 
    5029              : bool
    5030     18749423 : layout_pod_type_p (const_tree t)
    5031              : {
    5032     18749423 :   t = strip_array_types (const_cast<tree> (t));
    5033              : 
    5034     18749423 :   if (CLASS_TYPE_P (t))
    5035      3793574 :     return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    5036              :   else
    5037     14955849 :     return scalarish_type_p (t);
    5038              : }
    5039              : 
    5040              : /* Returns true iff T is a standard-layout type, as defined in
    5041              :    [basic.types].  */
    5042              : 
    5043              : bool
    5044     18825809 : std_layout_type_p (const_tree t)
    5045              : {
    5046     18825809 :   t = strip_array_types (const_cast<tree> (t));
    5047              : 
    5048     18825809 :   if (CLASS_TYPE_P (t))
    5049      3807458 :     return !CLASSTYPE_NON_STD_LAYOUT (t);
    5050              :   else
    5051     15018351 :     return scalarish_type_p (t);
    5052              : }
    5053              : 
    5054              : static bool record_has_unique_obj_representations (const_tree, const_tree, bool);
    5055              : 
    5056              : /* Returns true iff T satisfies std::has_unique_object_representations<T>,
    5057              :    as defined in [meta.unary.prop].  If EXPLAIN is true, explain why not.  */
    5058              : 
    5059              : bool
    5060        61865 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
    5061              : {
    5062        71272 :   bool ret;
    5063              : 
    5064        71272 :   t = strip_array_types (const_cast<tree> (t));
    5065              : 
    5066        71272 :   if (t == error_mark_node)
    5067              :     return false;
    5068              : 
    5069        71269 :   location_t loc = input_location;
    5070        71269 :   if (tree m = TYPE_MAIN_DECL (t))
    5071         9647 :     loc = DECL_SOURCE_LOCATION (m);
    5072              : 
    5073        71269 :   if (!trivially_copyable_p (t))
    5074              :     {
    5075           30 :       if (explain)
    5076            6 :         inform (loc, "%qT is not trivially copyable", t);
    5077              :       return false;
    5078              :     }
    5079              : 
    5080          239 :   if (CLASS_TYPE_P (t)
    5081          236 :       && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
    5082        71362 :       && !explain)
    5083           96 :     return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
    5084              : 
    5085        71143 :   switch (TREE_CODE (t))
    5086              :     {
    5087              :     case INTEGER_TYPE:
    5088              :     case POINTER_TYPE:
    5089              :     case REFERENCE_TYPE:
    5090              :       /* If some backend has any paddings in these types, we should add
    5091              :          a target hook for this and handle it there.  */
    5092              :       return true;
    5093              : 
    5094              :     case BOOLEAN_TYPE:
    5095              :       /* For bool values other than 0 and 1 should only appear with
    5096              :          undefined behavior.  */
    5097              :       return true;
    5098              : 
    5099         9389 :     case ENUMERAL_TYPE:
    5100         9389 :       return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
    5101         9389 :                                                   explain);
    5102              : 
    5103        33148 :     case REAL_TYPE:
    5104              :       /* XFmode certainly contains padding on x86, which the CPU doesn't store
    5105              :          when storing long double values, so for that we have to return false.
    5106              :          Other kinds of floating point values are questionable due to +.0/-.0
    5107              :          and NaNs, let's play safe for now.  */
    5108        33148 :       if (explain)
    5109            0 :         inform (loc, "%qT is a floating-point type", t);
    5110              :       return false;
    5111              : 
    5112            0 :     case FIXED_POINT_TYPE:
    5113            0 :       if (explain)
    5114            0 :         inform (loc, "%qT is a fixed-point type", t);
    5115              :       return false;
    5116              : 
    5117              :     case OFFSET_TYPE:
    5118              :       return true;
    5119              : 
    5120           18 :     case COMPLEX_TYPE:
    5121           18 :     case VECTOR_TYPE:
    5122           18 :       return type_has_unique_obj_representations (TREE_TYPE (t), explain);
    5123              : 
    5124          122 :     case RECORD_TYPE:
    5125          122 :       ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
    5126          122 :       if (CLASS_TYPE_P (t))
    5127              :         {
    5128          119 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
    5129          119 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
    5130              :         }
    5131              :       return ret;
    5132              : 
    5133           21 :     case UNION_TYPE:
    5134           21 :       ret = true;
    5135           21 :       bool any_fields;
    5136           21 :       any_fields = false;
    5137           42 :       for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5138           33 :         if (TREE_CODE (field) == FIELD_DECL)
    5139              :           {
    5140           24 :             any_fields = true;
    5141           24 :             if (simple_cst_equal (DECL_SIZE (field), TYPE_SIZE (t)) != 1)
    5142              :               {
    5143           12 :                 if (explain)
    5144            3 :                   inform (DECL_SOURCE_LOCATION (field),
    5145              :                           "%qD does not fill all bits of %q#T", field, t);
    5146              :                 ret = false;
    5147              :                 break;
    5148              :               }
    5149           12 :             if (!type_has_unique_obj_representations (TREE_TYPE (field)))
    5150              :               {
    5151            0 :                 if (explain)
    5152            0 :                   inform (DECL_SOURCE_LOCATION (field),
    5153              :                           "%qD has type %qT that does not have "
    5154              :                           "unique object representations",
    5155            0 :                           field, TREE_TYPE (field));
    5156              :                 ret = false;
    5157              :                 break;
    5158              :               }
    5159              :           }
    5160           12 :       if (!any_fields && !integer_zerop (TYPE_SIZE (t)))
    5161              :         {
    5162            6 :           if (explain)
    5163            3 :             inform (loc, "%q#T has no data fields", t);
    5164              :           ret = false;
    5165              :         }
    5166           21 :       if (CLASS_TYPE_P (t))
    5167              :         {
    5168           21 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
    5169           21 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t) = ret;
    5170              :         }
    5171              :       return ret;
    5172              : 
    5173            3 :     case NULLPTR_TYPE:
    5174            3 :       if (explain)
    5175            0 :         inform (loc, "%<std::nullptr_t%> has padding bits and no value bits");
    5176              :       return false;
    5177              : 
    5178            8 :     case LANG_TYPE:
    5179            8 :       if (REFLECTION_TYPE_P (t))
    5180              :         {
    5181            8 :           if (explain)
    5182            0 :             inform (loc, "%<std::meta::info%> has an unspecified object "
    5183              :                     "representation");
    5184              :           return false;
    5185              :         }
    5186            0 :       gcc_fallthrough ();
    5187              : 
    5188            0 :     default:
    5189            0 :       gcc_unreachable ();
    5190              :     }
    5191              : }
    5192              : 
    5193              : /* Helper function for type_has_unique_obj_representations.  */
    5194              : 
    5195              : static bool
    5196          133 : record_has_unique_obj_representations (const_tree t, const_tree sz,
    5197              :                                        bool explain)
    5198              : {
    5199          668 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5200          567 :     if (TREE_CODE (field) != FIELD_DECL)
    5201              :       ;
    5202              :     /* For bases, can't use type_has_unique_obj_representations here, as in
    5203              :         struct S { int i : 24; S (); };
    5204              :         struct T : public S { int j : 8; T (); };
    5205              :         S doesn't have unique obj representations, but T does.  */
    5206          182 :     else if (DECL_FIELD_IS_BASE (field))
    5207              :       {
    5208           11 :         if (!record_has_unique_obj_representations (TREE_TYPE (field),
    5209           11 :                                                     DECL_SIZE (field),
    5210              :                                                     /*explain=*/false))
    5211              :           {
    5212            6 :             if (explain)
    5213            3 :               inform (DECL_SOURCE_LOCATION (field),
    5214              :                       "base %qT does not have unique object representations",
    5215            3 :                       TREE_TYPE (field));
    5216              :             return false;
    5217              :           }
    5218              :       }
    5219          171 :     else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
    5220              :       {
    5221           59 :         tree btype = DECL_BIT_FIELD_TYPE (field);
    5222           59 :         if (!type_has_unique_obj_representations (btype))
    5223              :           {
    5224            0 :             if (explain)
    5225            0 :               inform (DECL_SOURCE_LOCATION (field),
    5226              :                       "%qD with type %qT does not have "
    5227              :                       "unique object representations",
    5228              :                       field, btype);
    5229              :             return false;
    5230              :           }
    5231              :       }
    5232          112 :     else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
    5233              :       {
    5234           26 :         if (explain)
    5235            6 :           inform (DECL_SOURCE_LOCATION (field),
    5236              :                   "%qD with type %qT does not have "
    5237              :                   "unique object representations",
    5238            6 :                   field, TREE_TYPE (field));
    5239              :         return false;
    5240              :       }
    5241              : 
    5242          101 :   offset_int cur = 0;
    5243          101 :   tree last_field = NULL_TREE;
    5244          101 :   tree last_named_field = NULL_TREE;
    5245          565 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5246          496 :     if (TREE_CODE (field) == FIELD_DECL)
    5247              :       {
    5248          144 :         if (DECL_UNNAMED_BIT_FIELD (field))
    5249              :           {
    5250           16 :             last_field = field;
    5251           16 :             continue;
    5252              :           }
    5253          128 :         offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
    5254          128 :         offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
    5255          128 :         fld = fld * BITS_PER_UNIT + bitpos;
    5256          128 :         if (cur != fld)
    5257              :           {
    5258           32 :             if (explain)
    5259              :               {
    5260            6 :                 if (last_named_field)
    5261            3 :                   inform (DECL_SOURCE_LOCATION (last_named_field),
    5262              :                           "padding occurs between %qD and %qD",
    5263              :                           last_named_field, field);
    5264            3 :                 else if (last_field)
    5265            3 :                   inform (DECL_SOURCE_LOCATION (last_field),
    5266              :                           "unnamed bit-field inserts padding before %qD",
    5267              :                           field);
    5268              :                 else
    5269            0 :                   inform (DECL_SOURCE_LOCATION (field),
    5270              :                           "padding occurs before %qD", field);
    5271              :               }
    5272           32 :             return false;
    5273              :           }
    5274           96 :         if (DECL_SIZE (field))
    5275              :           {
    5276           93 :             offset_int size = wi::to_offset (DECL_SIZE (field));
    5277           93 :             cur += size;
    5278              :           }
    5279           96 :         last_named_field = last_field = field;
    5280              :       }
    5281           69 :   if (cur != wi::to_offset (sz))
    5282              :     {
    5283           33 :       if (explain)
    5284              :         {
    5285            6 :           if (last_named_field)
    5286            3 :             inform (DECL_SOURCE_LOCATION (last_named_field),
    5287              :                     "padding occurs after %qD", last_named_field);
    5288              :           else
    5289            3 :             inform (location_of (const_cast <tree> (t)),
    5290              :                     "%qT has padding and no data fields", t);
    5291              :         }
    5292              :       return false;
    5293              :     }
    5294              : 
    5295              :   return true;
    5296              : }
    5297              : 
    5298              : /* Nonzero iff type T is a class template implicit specialization.  */
    5299              : 
    5300              : bool
    5301    141284843 : class_tmpl_impl_spec_p (const_tree t)
    5302              : {
    5303    141284843 :   return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
    5304              : }
    5305              : 
    5306              : /* Returns 1 iff zero initialization of type T means actually storing
    5307              :    zeros in it.  */
    5308              : 
    5309              : int
    5310     21026435 : zero_init_p (const_tree t)
    5311              : {
    5312              :   /* This CONST_CAST is okay because strip_array_types returns its
    5313              :      argument unmodified and we assign it to a const_tree.  */
    5314     21026435 :   t = strip_array_types (const_cast<tree> (t));
    5315              : 
    5316     21026435 :   if (t == error_mark_node)
    5317              :     return 1;
    5318              : 
    5319              :   /* NULL pointers to data members are initialized with -1.  */
    5320     21026435 :   if (TYPE_PTRDATAMEM_P (t))
    5321              :     return 0;
    5322              : 
    5323              :   /* Classes that contain types that can't be zero-initialized, cannot
    5324              :      be zero-initialized themselves.  */
    5325     21025832 :   if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
    5326          143 :     return 0;
    5327              : 
    5328              :   return 1;
    5329              : }
    5330              : 
    5331              : /* Returns true if the expression or initializer T is the result of
    5332              :    zero-initialization for its type, taking pointers to members
    5333              :    into consideration.  */
    5334              : 
    5335              : bool
    5336       684973 : zero_init_expr_p (tree t)
    5337              : {
    5338       684973 :   tree type = TREE_TYPE (t);
    5339       684973 :   if (!type || uses_template_parms (type))
    5340              :     return false;
    5341       684973 :   if (TYPE_PTRMEM_P (type))
    5342         1224 :     return null_member_pointer_value_p (t);
    5343       683749 :   if (REFLECTION_TYPE_P (type))
    5344          404 :     return null_reflection_p (t);
    5345       683345 :   if (TREE_CODE (t) == CONSTRUCTOR)
    5346              :     {
    5347       282344 :       if (COMPOUND_LITERAL_P (t)
    5348       282344 :           || BRACE_ENCLOSED_INITIALIZER_P (t))
    5349              :         /* Undigested, conversions might change the zeroness.  */
    5350              :         return false;
    5351       849594 :       for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
    5352              :         {
    5353       289133 :           if (TREE_CODE (type) == UNION_TYPE
    5354       289133 :               && elt.index != first_field (type))
    5355              :             return false;
    5356       289122 :           if (!zero_init_expr_p (elt.value))
    5357              :             return false;
    5358              :         }
    5359              :       return true;
    5360              :     }
    5361       401001 :   if (zero_init_p (type))
    5362       401001 :     return initializer_zerop (t);
    5363              :   return false;
    5364              : }
    5365              : 
    5366              : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
    5367              :    non-type template parameter.  If EXPLAIN, explain why not.  */
    5368              : 
    5369              : bool
    5370       212303 : structural_type_p (tree t, bool explain)
    5371              : {
    5372              :   /* A structural type is one of the following: */
    5373              : 
    5374              :   /* a scalar type, or */
    5375       212303 :   if (SCALAR_TYPE_P (t))
    5376              :     return true;
    5377              :   /* an lvalue reference type, or */
    5378       106386 :   if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
    5379              :     return true;
    5380              :   /* a literal class type with the following properties:
    5381              :      - all base classes and non-static data members are public and non-mutable
    5382              :        and
    5383              :      - the types of all bases classes and non-static data members are
    5384              :        structural types or (possibly multi-dimensional) array thereof.  */
    5385       106370 :   if (!CLASS_TYPE_P (t))
    5386              :     return false;
    5387       106330 :   if (!literal_type_p (t))
    5388              :     {
    5389           52 :       if (explain)
    5390           10 :         explain_non_literal_class (t);
    5391              :       return false;
    5392              :     }
    5393       234414 :   for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
    5394       128136 :        m = next_aggregate_field (DECL_CHAIN (m)))
    5395              :     {
    5396       128469 :       if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
    5397              :         {
    5398          255 :           if (explain)
    5399              :             {
    5400           97 :               if (DECL_FIELD_IS_BASE (m))
    5401            3 :                 inform (location_of (m), "base class %qT is not public",
    5402            3 :                         TREE_TYPE (m));
    5403              :               else
    5404           94 :                 inform (location_of (m), "%qD is not public", m);
    5405              :             }
    5406              :           return false;
    5407              :         }
    5408       128214 :       if (DECL_MUTABLE_P (m))
    5409              :         {
    5410           58 :           if (explain)
    5411            8 :             inform (location_of (m), "%qD is mutable", m);
    5412              :           return false;
    5413              :         }
    5414       128156 :       tree mtype = strip_array_types (TREE_TYPE (m));
    5415       128156 :       if (!structural_type_p (mtype))
    5416              :         {
    5417           20 :           if (explain)
    5418              :             {
    5419            2 :               inform (location_of (m), "%qD has a non-structural type", m);
    5420            2 :               structural_type_p (mtype, true);
    5421              :             }
    5422              :           return false;
    5423              :         }
    5424              :     }
    5425              :   return true;
    5426              : }
    5427              : 
    5428              : /* Partially handle the C++11 [[carries_dependency]] attribute.
    5429              :    Just emit a different diagnostics when it is used on something the
    5430              :    spec doesn't allow vs. where it allows and we just choose to ignore
    5431              :    it.  */
    5432              : 
    5433              : static tree
    5434          142 : handle_carries_dependency_attribute (tree *node, tree name,
    5435              :                                      tree ARG_UNUSED (args),
    5436              :                                      int ARG_UNUSED (flags),
    5437              :                                      bool *no_add_attrs)
    5438              : {
    5439          142 :   if (TREE_CODE (*node) != FUNCTION_DECL
    5440          121 :       && TREE_CODE (*node) != PARM_DECL)
    5441              :     {
    5442           76 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5443              :                "functions or parameters", name);
    5444           76 :       *no_add_attrs = true;
    5445              :     }
    5446              :   else
    5447              :     {
    5448           66 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5449           66 :       *no_add_attrs = true;
    5450              :     }
    5451          142 :   return NULL_TREE;
    5452              : }
    5453              : 
    5454              : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
    5455              :    warn_unused_result attribute.  */
    5456              : 
    5457              : static tree
    5458     13845484 : handle_nodiscard_attribute (tree *node, tree name, tree args,
    5459              :                             int /*flags*/, bool *no_add_attrs)
    5460              : {
    5461     13845652 :   if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    5462              :     {
    5463            6 :       error ("%qE attribute argument must be a string constant", name);
    5464            6 :       *no_add_attrs = true;
    5465              :     }
    5466     13845484 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    5467              :     {
    5468     13844328 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
    5469     13948205 :           && !DECL_CONSTRUCTOR_P (*node))
    5470            9 :         warning_at (DECL_SOURCE_LOCATION (*node),
    5471            9 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    5472              :                     "return type", name, *node);
    5473              :     }
    5474         1156 :   else if (OVERLOAD_TYPE_P (*node))
    5475              :     /* OK */;
    5476              :   else
    5477              :     {
    5478          148 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5479              :                "functions or to class or enumeration types", name);
    5480          148 :       *no_add_attrs = true;
    5481              :     }
    5482     13845484 :   return NULL_TREE;
    5483              : }
    5484              : 
    5485              : /* Handle a C++20 "no_unique_address" attribute; arguments as in
    5486              :    struct attribute_spec.handler.  */
    5487              : static tree
    5488       745491 : handle_no_unique_addr_attribute (tree* node,
    5489              :                                  tree name,
    5490              :                                  tree /*args*/,
    5491              :                                  int /*flags*/,
    5492              :                                  bool* no_add_attrs)
    5493              : {
    5494       745491 :   if (TREE_CODE (*node) == VAR_DECL)
    5495              :     {
    5496           48 :       DECL_MERGEABLE (*node) = true;
    5497           48 :       if (pedantic)
    5498           42 :         warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5499              :                  "non-static data members", name);
    5500              :     }
    5501       745443 :   else if (TREE_CODE (*node) != FIELD_DECL)
    5502              :     {
    5503           82 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5504              :                "non-static data members", name);
    5505           82 :       *no_add_attrs = true;
    5506              :     }
    5507       745361 :   else if (DECL_C_BIT_FIELD (*node))
    5508              :     {
    5509            6 :       warning (OPT_Wattributes, "%qE attribute cannot be applied to "
    5510              :                "a bit-field", name);
    5511            6 :       *no_add_attrs = true;
    5512              :     }
    5513              : 
    5514       745491 :   return NULL_TREE;
    5515              : }
    5516              : 
    5517              : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
    5518              :    hot/cold attributes.  */
    5519              : 
    5520              : static tree
    5521          392 : handle_likeliness_attribute (tree *node, tree name, tree args,
    5522              :                              int flags, bool *no_add_attrs)
    5523              : {
    5524          392 :   *no_add_attrs = true;
    5525          392 :   if (TREE_CODE (*node) == LABEL_DECL
    5526          392 :       || TREE_CODE (*node) == FUNCTION_DECL)
    5527              :     {
    5528           90 :       if (args)
    5529            0 :         warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
    5530           90 :       tree bname = (is_attribute_p ("likely", name)
    5531           90 :                     ? get_identifier ("hot") : get_identifier ("cold"));
    5532           90 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5533           33 :         warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
    5534              :                  "functions; treating as %<[[gnu::%E]]%>", name, bname);
    5535           90 :       tree battr = build_tree_list (bname, NULL_TREE);
    5536           90 :       decl_attributes (node, battr, flags);
    5537           90 :       return NULL_TREE;
    5538              :     }
    5539              :   else
    5540          302 :     return error_mark_node;
    5541              : }
    5542              : 
    5543              : /* The C++11 alignment specifier.  It mostly maps to GNU aligned attribute,
    5544              :    but we need to do some extra pedantic checking.  */
    5545              : 
    5546              : static tree
    5547       317236 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
    5548              :                           bool *no_add_attrs)
    5549              : {
    5550       317236 :   tree t = *node;
    5551       317236 :   tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
    5552       317236 :   if (pedantic)
    5553              :     {
    5554         1264 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5555           15 :         pedwarn (input_location, OPT_Wattributes,
    5556              :                  "%<alignas%> on function declaration");
    5557         1249 :       else if (TREE_CODE (*node) == ENUMERAL_TYPE)
    5558            9 :         pedwarn (input_location, OPT_Wattributes,
    5559              :                  "%<alignas%> on enumerated type");
    5560         1240 :       else if (TYPE_P (*node) && t != *node)
    5561           56 :         pedwarn (input_location, OPT_Wattributes,
    5562              :                  "%<alignas%> on a type other than class");
    5563         1184 :       else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
    5564            9 :         pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
    5565         1175 :       else if (TREE_CODE (t) == TYPE_DECL)
    5566            9 :         pedwarn (input_location, OPT_Wattributes,
    5567              :                  "%<alignas%> on a type alias");
    5568              :     }
    5569       317236 :   return ret;
    5570              : }
    5571              : 
    5572              : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
    5573              :    attribute.  */
    5574              : 
    5575              : static tree
    5576       312808 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
    5577              :                                  bool *no_add_attrs)
    5578              : {
    5579       312808 :   tree t = *node;
    5580       312808 :   tree ret = handle_deprecated_attribute (node, name, args, flags,
    5581              :                                           no_add_attrs);
    5582       312808 :   if (TYPE_P (*node) && t != *node)
    5583           48 :     pedwarn (input_location, OPT_Wattributes,
    5584              :              "%qE on a type other than class or enumeration definition", name);
    5585       312760 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5586            4 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5587              :              name);
    5588       312808 :   return ret;
    5589              : }
    5590              : 
    5591              : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
    5592              :    attribute.  */
    5593              : 
    5594              : static tree
    5595       104172 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
    5596              :                                bool *no_add_attrs)
    5597              : {
    5598       104172 :   tree t = *node;
    5599       104172 :   tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
    5600       104172 :   if (TYPE_P (*node) && t != *node)
    5601           36 :     pedwarn (input_location, OPT_Wattributes,
    5602              :              "%qE on a type other than class or enumeration definition", name);
    5603       104136 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5604            3 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5605              :              name);
    5606       104133 :   else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
    5607            6 :     pedwarn (input_location, OPT_Wattributes,
    5608              :              "%qE on %<case%> or %<default%> label", name);
    5609       104172 :   return ret;
    5610              : }
    5611              : 
    5612              : /* The C++26 [[indeterminate]] attribute.  */
    5613              : 
    5614              : static tree
    5615          231 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
    5616              :                                 bool *no_add_attrs)
    5617              : {
    5618          231 :   if (TREE_CODE (*node) != PARM_DECL
    5619          231 :       && (!VAR_P (*node) || is_global_var (*node)))
    5620              :     {
    5621           67 :       pedwarn (input_location, OPT_Wattributes,
    5622              :                "%qE on declaration other than parameter or automatic variable",
    5623              :                name);
    5624           67 :       *no_add_attrs = true;
    5625              :     }
    5626          231 :   return NULL_TREE;
    5627              : }
    5628              : 
    5629              : /* Table of valid C++ attributes.  */
    5630              : // clang-format off
    5631              : static const attribute_spec cxx_gnu_attributes[] =
    5632              : {
    5633              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5634              :        affects_type_identity, handler, exclude } */
    5635              :   { "init_priority",  1, 1, true,  false, false, false,
    5636              :     handle_init_priority_attribute, NULL },
    5637              :   { "abi_tag", 1, -1, false, false, false, true,
    5638              :     handle_abi_tag_attribute, NULL },
    5639              :   { "no_dangling", 0, 1, false, true, false, false,
    5640              :     handle_no_dangling_attribute, NULL },
    5641              :   { "no_specializations", 0, 1, false, false, false, false,
    5642              :     handle_gnu_no_specializations_attribute, NULL },
    5643              :   { "trivial_abi", 0, 0, false, true, false, true,
    5644              :     handle_gnu_trivial_abi_attribute, NULL },
    5645              : };
    5646              : // clang-format on
    5647              : 
    5648              : const scoped_attribute_specs cxx_gnu_attribute_table =
    5649              : {
    5650              :   "gnu", { cxx_gnu_attributes }
    5651              : };
    5652              : 
    5653              : /* Table of C++ standard attributes.  */
    5654              : static const attribute_spec std_attributes[] =
    5655              : {
    5656              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5657              :        affects_type_identity, handler, exclude } */
    5658              :   { "deprecated", 0, 1, false, false, false, false,
    5659              :     handle_std_deprecated_attribute, NULL },
    5660              :   { "maybe_unused", 0, 0, false, false, false, false,
    5661              :     handle_maybe_unused_attribute, NULL },
    5662              :   { "nodiscard", 0, 1, false, false, false, false,
    5663              :     handle_nodiscard_attribute, NULL },
    5664              :   { "no_unique_address", 0, 0, true, false, false, false,
    5665              :     handle_no_unique_addr_attribute, NULL },
    5666              :   { "likely", 0, 0, false, false, false, false,
    5667              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5668              :   { "unlikely", 0, 0, false, false, false, false,
    5669              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5670              :   { "noreturn", 0, 0, true, false, false, false,
    5671              :     handle_noreturn_attribute, attr_noreturn_exclusions },
    5672              :   { "carries_dependency", 0, 0, true, false, false, false,
    5673              :     handle_carries_dependency_attribute, NULL },
    5674              :   { "indeterminate", 0, 0, true, false, false, false,
    5675              :     handle_indeterminate_attribute, NULL },
    5676              : };
    5677              : 
    5678              : const scoped_attribute_specs std_attribute_table =
    5679              : {
    5680              :   nullptr, { std_attributes }
    5681              : };
    5682              : 
    5683              : /* Table of internal attributes.  */
    5684              : static const attribute_spec internal_attributes[] =
    5685              : {
    5686              :   { "aligned", 0, 1, false, false, false, false,
    5687              :     handle_alignas_attribute, attr_aligned_exclusions },
    5688              :   { "annotation ", 1, 1, false, false, false, false,
    5689              :     handle_annotation_attribute, NULL }
    5690              : };
    5691              : 
    5692              : const scoped_attribute_specs internal_attribute_table =
    5693              : {
    5694              :   "internal ", { internal_attributes }
    5695              : };
    5696              : 
    5697              : /* Table of C++ attributes also recognized in the clang:: namespace.  */
    5698              : // clang-format off
    5699              : static const attribute_spec cxx_clang_attributes[] =
    5700              : {
    5701              :   { "no_specializations", 0, 1, false, false, false, false,
    5702              :     handle_no_specializations_attribute, NULL },
    5703              :   { "trivial_abi", 0, 0, false, true, false, true,
    5704              :     handle_trivial_abi_attribute, NULL },
    5705              : };
    5706              : 
    5707              : const scoped_attribute_specs cxx_clang_attribute_table =
    5708              : {
    5709              :   "clang", { cxx_clang_attributes }
    5710              : };
    5711              : // clang-format on
    5712              : 
    5713              : /* Handle an "init_priority" attribute; arguments as in
    5714              :    struct attribute_spec.handler.  */
    5715              : static tree
    5716           35 : handle_init_priority_attribute (tree* node,
    5717              :                                 tree name,
    5718              :                                 tree args,
    5719              :                                 int /*flags*/,
    5720              :                                 bool* no_add_attrs)
    5721              : {
    5722           35 :   if (!SUPPORTS_INIT_PRIORITY)
    5723              :     /* Treat init_priority as an unrecognized attribute (mirroring
    5724              :        __has_attribute) if the target doesn't support init priorities.  */
    5725              :     return error_mark_node;
    5726              : 
    5727           35 :   tree initp_expr = TREE_VALUE (args);
    5728           35 :   tree decl = *node;
    5729           35 :   tree type = TREE_TYPE (decl);
    5730           35 :   int pri;
    5731              : 
    5732           35 :   STRIP_NOPS (initp_expr);
    5733           35 :   initp_expr = default_conversion (initp_expr);
    5734           35 :   if (initp_expr)
    5735           35 :     initp_expr = maybe_constant_value (initp_expr);
    5736              : 
    5737           35 :   if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
    5738              :     {
    5739            0 :       error ("requested %<init_priority%> is not an integer constant");
    5740            0 :       cxx_constant_value (initp_expr);
    5741            0 :       *no_add_attrs = true;
    5742            0 :       return NULL_TREE;
    5743              :     }
    5744              : 
    5745           35 :   pri = TREE_INT_CST_LOW (initp_expr);
    5746              : 
    5747           35 :   type = strip_array_types (type);
    5748              : 
    5749           35 :   if (decl == NULL_TREE
    5750           35 :       || !VAR_P (decl)
    5751           35 :       || !TREE_STATIC (decl)
    5752           35 :       || DECL_EXTERNAL (decl)
    5753           35 :       || (TREE_CODE (type) != RECORD_TYPE
    5754           35 :           && TREE_CODE (type) != UNION_TYPE)
    5755              :       /* Static objects in functions are initialized the
    5756              :          first time control passes through that
    5757              :          function. This is not precise enough to pin down an
    5758              :          init_priority value, so don't allow it.  */
    5759           70 :       || current_function_decl)
    5760              :     {
    5761            0 :       error ("can only use %qE attribute on file-scope definitions "
    5762              :              "of objects of class type", name);
    5763            0 :       *no_add_attrs = true;
    5764            0 :       return NULL_TREE;
    5765              :     }
    5766              : 
    5767           35 :   if (pri > MAX_INIT_PRIORITY || pri <= 0)
    5768              :     {
    5769            0 :       error ("requested %<init_priority%> %i is out of range [0, %i]",
    5770              :              pri, MAX_INIT_PRIORITY);
    5771            0 :       *no_add_attrs = true;
    5772            0 :       return NULL_TREE;
    5773              :     }
    5774              : 
    5775              :   /* Check for init_priorities that are reserved for
    5776              :      language and runtime support implementations.*/
    5777           35 :   if (pri <= MAX_RESERVED_INIT_PRIORITY
    5778           35 :       && !in_system_header_at (input_location))
    5779              :     {
    5780           10 :       warning
    5781           10 :         (OPT_Wprio_ctor_dtor,
    5782              :          "requested %<init_priority%> %i is reserved for internal use",
    5783              :          pri);
    5784              :     }
    5785              : 
    5786           35 :   SET_DECL_INIT_PRIORITY (decl, pri);
    5787           35 :   DECL_HAS_INIT_PRIORITY_P (decl) = 1;
    5788           35 :   return NULL_TREE;
    5789              : }
    5790              : 
    5791              : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
    5792              :    and the new one has the tags in NEW_.  Give an error if there are tags
    5793              :    in NEW_ that weren't in OLD.  */
    5794              : 
    5795              : bool
    5796     11836499 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
    5797              : {
    5798     11906807 :   if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
    5799              :     old = TREE_VALUE (old);
    5800     11859337 :   if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
    5801              :     new_ = TREE_VALUE (new_);
    5802     11836499 :   bool err = false;
    5803     11836499 :   auto_diagnostic_group d;
    5804     23695836 :   for (const_tree t = new_; t; t = TREE_CHAIN (t))
    5805              :     {
    5806        22838 :       tree str = TREE_VALUE (t);
    5807        22838 :       for (const_tree in = old; in; in = TREE_CHAIN (in))
    5808              :         {
    5809        22829 :           tree ostr = TREE_VALUE (in);
    5810        22829 :           if (cp_tree_equal (str, ostr))
    5811        22829 :             goto found;
    5812              :         }
    5813            9 :       error ("redeclaration of %qD adds abi tag %qE", decl, str);
    5814            9 :       err = true;
    5815        22838 :     found:;
    5816              :     }
    5817     11836499 :   if (err)
    5818              :     {
    5819            9 :       inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
    5820            9 :       return false;
    5821              :     }
    5822              :   return true;
    5823     11836499 : }
    5824              : 
    5825              : /* The abi_tag attribute with the name NAME was given ARGS.  If they are
    5826              :    ill-formed, give an error and return false; otherwise, return true.  */
    5827              : 
    5828              : bool
    5829       464733 : check_abi_tag_args (tree args, tree name)
    5830              : {
    5831       464733 :   if (!args)
    5832              :     {
    5833            0 :       error ("the %qE attribute requires arguments", name);
    5834            0 :       return false;
    5835              :     }
    5836       929505 :   for (tree arg = args; arg; arg = TREE_CHAIN (arg))
    5837              :     {
    5838       464784 :       tree elt = TREE_VALUE (arg);
    5839       464784 :       if (TREE_CODE (elt) != STRING_CST
    5840       929562 :           || (!same_type_ignoring_top_level_qualifiers_p
    5841       464778 :               (strip_array_types (TREE_TYPE (elt)),
    5842              :                char_type_node)))
    5843              :         {
    5844            9 :           error ("arguments to the %qE attribute must be narrow string "
    5845              :                  "literals", name);
    5846            9 :           return false;
    5847              :         }
    5848       464775 :       const char *begin = TREE_STRING_POINTER (elt);
    5849       464775 :       const char *end = begin + TREE_STRING_LENGTH (elt);
    5850      3291171 :       for (const char *p = begin; p != end; ++p)
    5851              :         {
    5852      2826399 :           char c = *p;
    5853      2826399 :           if (p == begin)
    5854              :             {
    5855       464775 :               if (!ISALPHA (c) && c != '_')
    5856              :                 {
    5857            3 :                   auto_diagnostic_group d;
    5858            3 :                   error ("arguments to the %qE attribute must contain valid "
    5859              :                          "identifiers", name);
    5860            3 :                   inform (input_location, "%<%c%> is not a valid first "
    5861              :                           "character for an identifier", c);
    5862            3 :                   return false;
    5863            3 :                 }
    5864              :             }
    5865      2361624 :           else if (p == end - 1)
    5866       464772 :             gcc_assert (c == 0);
    5867              :           else
    5868              :             {
    5869      1896852 :               if (!ISALNUM (c) && c != '_')
    5870              :                 {
    5871            0 :                   auto_diagnostic_group d;
    5872            0 :                   error ("arguments to the %qE attribute must contain valid "
    5873              :                          "identifiers", name);
    5874            0 :                   inform (input_location, "%<%c%> is not a valid character "
    5875              :                           "in an identifier", c);
    5876            0 :                   return false;
    5877            0 :                 }
    5878              :             }
    5879              :         }
    5880              :     }
    5881              :   return true;
    5882              : }
    5883              : 
    5884              : /* Handle an "abi_tag" attribute; arguments as in
    5885              :    struct attribute_spec.handler.  */
    5886              : 
    5887              : static tree
    5888       414948 : handle_abi_tag_attribute (tree* node, tree name, tree args,
    5889              :                           int flags, bool* no_add_attrs)
    5890              : {
    5891       414948 :   if (!check_abi_tag_args (args, name))
    5892           12 :     goto fail;
    5893              : 
    5894       414936 :   if (TYPE_P (*node))
    5895              :     {
    5896        11721 :       if (!OVERLOAD_TYPE_P (*node))
    5897              :         {
    5898            0 :           error ("%qE attribute applied to non-class, non-enum type %qT",
    5899              :                  name, *node);
    5900            0 :           goto fail;
    5901              :         }
    5902        11721 :       else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
    5903              :         {
    5904            0 :           error ("%qE attribute applied to %qT after its definition",
    5905              :                  name, *node);
    5906            0 :           goto fail;
    5907              :         }
    5908        11718 :       else if (CLASS_TYPE_P (*node)
    5909        23439 :                && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
    5910              :         {
    5911            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5912              :                    "template instantiation %qT", name, *node);
    5913            3 :           goto fail;
    5914              :         }
    5915        11715 :       else if (CLASS_TYPE_P (*node)
    5916        23433 :                && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
    5917              :         {
    5918            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5919              :                    "template specialization %qT", name, *node);
    5920            3 :           goto fail;
    5921              :         }
    5922              : 
    5923        11715 :       tree attributes = TYPE_ATTRIBUTES (*node);
    5924        11715 :       tree decl = TYPE_NAME (*node);
    5925              : 
    5926              :       /* Make sure all declarations have the same abi tags.  */
    5927        11715 :       if (DECL_SOURCE_LOCATION (decl) != input_location)
    5928              :         {
    5929            6 :           if (!check_abi_tag_redeclaration (decl,
    5930            6 :                                             lookup_attribute ("abi_tag",
    5931              :                                                               attributes),
    5932              :                                             args))
    5933            6 :             goto fail;
    5934              :         }
    5935              :     }
    5936              :   else
    5937              :     {
    5938       403215 :       if (!VAR_OR_FUNCTION_DECL_P (*node))
    5939              :         {
    5940            0 :           error ("%qE attribute applied to non-function, non-variable %qD",
    5941              :                  name, *node);
    5942            0 :           goto fail;
    5943              :         }
    5944       403215 :       else if (DECL_LANGUAGE (*node) == lang_c)
    5945              :         {
    5946            0 :           error ("%qE attribute applied to extern \"C\" declaration %qD",
    5947              :                  name, *node);
    5948            0 :           goto fail;
    5949              :         }
    5950              :     }
    5951              : 
    5952              :   return NULL_TREE;
    5953              : 
    5954           24 :  fail:
    5955           24 :   *no_add_attrs = true;
    5956           24 :   return NULL_TREE;
    5957              : }
    5958              : 
    5959              : /* Handle a "no_dangling" attribute; arguments as in
    5960              :    struct attribute_spec.handler.  */
    5961              : 
    5962              : tree
    5963           96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
    5964              :                               bool *no_add_attrs)
    5965              : {
    5966          147 :   if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
    5967              :     {
    5968            3 :       error ("%qE attribute argument must be an expression that evaluates "
    5969              :              "to true or false", name);
    5970            3 :       *no_add_attrs = true;
    5971              :     }
    5972           93 :   else if (!FUNC_OR_METHOD_TYPE_P (*node)
    5973           51 :            && !RECORD_OR_UNION_TYPE_P (*node))
    5974              :     {
    5975           18 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5976           18 :       *no_add_attrs = true;
    5977              :     }
    5978              : 
    5979           96 :   return NULL_TREE;
    5980              : }
    5981              : 
    5982              : /* Perform checking for annotations.  */
    5983              : 
    5984              : tree
    5985          846 : handle_annotation_attribute (tree *node, tree ARG_UNUSED (name),
    5986              :                              tree args, int ARG_UNUSED (flags),
    5987              :                              bool *no_add_attrs)
    5988              : {
    5989          846 :   if (TYPE_P (*node)
    5990          118 :       && TREE_CODE (*node) != ENUMERAL_TYPE
    5991          110 :       && TREE_CODE (*node) != RECORD_TYPE
    5992           24 :       && TREE_CODE (*node) != UNION_TYPE)
    5993              :     {
    5994           24 :       error ("annotation on a type other than class or enumeration "
    5995              :              "definition");
    5996           24 :       *no_add_attrs = true;
    5997           24 :       return NULL_TREE;
    5998              :     }
    5999          822 :   if (TREE_CODE (*node) == LABEL_DECL)
    6000              :     {
    6001            6 :       error ("annotation applied to a label");
    6002            6 :       *no_add_attrs = true;
    6003            6 :       return NULL_TREE;
    6004              :     }
    6005          816 :   if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    6006              :     {
    6007            2 :       error ("annotation on unnamed bit-field");
    6008            2 :       *no_add_attrs = true;
    6009            2 :       return NULL_TREE;
    6010              :     }
    6011          814 :   if (TREE_CODE (*node) == PARM_DECL && VOID_TYPE_P (TREE_TYPE (*node)))
    6012              :     {
    6013            2 :       error ("annotation on void parameter");
    6014            2 :       *no_add_attrs = true;
    6015            2 :       return NULL_TREE;
    6016              :     }
    6017              : 
    6018              :   /* Annotations are treated as late attributes so we shouldn't see
    6019              :      anything type-dependent now.  */
    6020          812 :   gcc_assert (!type_dependent_expression_p (TREE_VALUE (args)));
    6021              :   /* FIXME We should be using convert_reflect_constant_arg here to
    6022              :      implement std::meta::reflect_constant(constant-expression)
    6023              :      properly, but that introduces new crashes.  */
    6024          812 :   TREE_VALUE (args) = decay_conversion (TREE_VALUE (args), tf_warning_or_error);
    6025              : 
    6026          812 :   if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
    6027              :     {
    6028          102 :       auto_diagnostic_group d;
    6029          102 :       error ("annotation does not have structural type");
    6030          102 :       structural_type_p (TREE_TYPE (TREE_VALUE (args)), true);
    6031          102 :       *no_add_attrs = true;
    6032          102 :       return NULL_TREE;
    6033          102 :     }
    6034          710 :   if (CLASS_TYPE_P (TREE_TYPE (TREE_VALUE (args))))
    6035              :     {
    6036           62 :       tree arg = make_tree_vec (1);
    6037           62 :       tree type = TREE_TYPE (TREE_VALUE (args));
    6038           62 :       TREE_VEC_ELT (arg, 0) = build_const_lref (type);
    6039           62 :       if (!is_xible (INIT_EXPR, type, arg))
    6040              :         {
    6041            4 :           auto_diagnostic_group d;
    6042            4 :           error ("annotation does not have copy constructible type");
    6043            4 :           is_xible (INIT_EXPR, type, arg, /*explain=*/true);
    6044            4 :           *no_add_attrs = true;
    6045            4 :           return NULL_TREE;
    6046            4 :         }
    6047              :     }
    6048          706 :   if (!processing_template_decl)
    6049              :     {
    6050          698 :       location_t loc = EXPR_LOCATION (TREE_VALUE (args));
    6051          698 :       TREE_VALUE (args) = cxx_constant_value (TREE_VALUE (args));
    6052          698 :       if (error_operand_p (TREE_VALUE (args)))
    6053            4 :         *no_add_attrs = true;
    6054          698 :       auto suppression
    6055          698 :         = make_temp_override (suppress_location_wrappers, 0);
    6056          698 :       TREE_VALUE (args) = maybe_wrap_with_location (TREE_VALUE (args), loc);
    6057          698 :     }
    6058          706 :   ATTR_UNIQUE_VALUE_P (args) = 1;
    6059          706 :   return NULL_TREE;
    6060              : }
    6061              : 
    6062              : /* Handle a "trivial_abi" attribute applied via [[gnu::trivial_abi]].
    6063              :    We reject that spelling; suggest [[clang::trivial_abi]] or
    6064              :    __attribute__((trivial_abi)) instead.  */
    6065              : 
    6066              : static tree
    6067           84 : handle_gnu_trivial_abi_attribute (tree *node, tree name, tree args, int flags,
    6068              :                                   bool *no_add_attrs)
    6069              : {
    6070           84 :   if (flags & ATTR_FLAG_CXX11)
    6071              :     {
    6072            3 :       warning (OPT_Wattributes,
    6073              :                "%<[[gnu::trivial_abi]]%> is not supported; use "
    6074              :                "%<[[clang::trivial_abi]]%> or "
    6075              :                "%<__attribute__((trivial_abi))%> instead");
    6076            3 :       *no_add_attrs = true;
    6077            3 :       return NULL_TREE;
    6078              :     }
    6079          165 :   return handle_trivial_abi_attribute (node, name, args, flags, no_add_attrs);
    6080              : }
    6081              : 
    6082              : /* Handle a "trivial_abi" attribute.  */
    6083              : 
    6084              : static tree
    6085          160 : handle_trivial_abi_attribute (tree *node, tree name, tree, int,
    6086              :                               bool *no_add_attrs)
    6087              : {
    6088          160 :   tree type = *node;
    6089              : 
    6090              :   /* Only allow on class types (struct, class, union) */
    6091          160 :   if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
    6092              :     {
    6093            9 :       warning (OPT_Wattributes, "%qE attribute only applies to classes", name);
    6094            9 :       *no_add_attrs = true;
    6095            9 :       return NULL_TREE;
    6096              :     }
    6097              : 
    6098              :   return NULL_TREE;
    6099              : }
    6100              : 
    6101              : /* Return true if TYPE has the trivial_abi attribute.  */
    6102              : 
    6103              : bool
    6104    191422290 : has_trivial_abi_attribute (tree type)
    6105              : {
    6106    191422290 :   if (type == NULL_TREE || !TYPE_P (type))
    6107              :     return false;
    6108    191422249 :   return lookup_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
    6109              : }
    6110              : 
    6111              : /* Handle a "no_specializations" attribute applied via
    6112              :    [[gnu::no_specializations]].
    6113              :    We reject that spelling; suggest [[clang::no_specializations]] or
    6114              :    __attribute__((no_specializations)) instead.  */
    6115              : 
    6116              : static tree
    6117          122 : handle_gnu_no_specializations_attribute (tree *node, tree name, tree args,
    6118              :                                          int flags, bool *no_add_attrs)
    6119              : {
    6120          122 :   if (flags & ATTR_FLAG_CXX11)
    6121              :     {
    6122            8 :       warning (OPT_Wattributes,
    6123              :                "%<[[gnu::no_specializations]]%> is not supported; use "
    6124              :                "%<[[clang::no_specializations]]%> or "
    6125              :                "%<__attribute__((no_specializations))%> instead");
    6126            8 :       *no_add_attrs = true;
    6127            8 :       return NULL_TREE;
    6128              :     }
    6129          114 :   return handle_no_specializations_attribute (node, name, args, flags,
    6130          114 :                                               no_add_attrs);
    6131              : }
    6132              : 
    6133              : /* Handle a "no_specializations" attribute.  */
    6134              : 
    6135              : static tree
    6136        74278 : handle_no_specializations_attribute (tree *node, tree name, tree args, int,
    6137              :                                      bool *no_add_attrs)
    6138              : {
    6139        74431 :   if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    6140              :     {
    6141            3 :       error ("%qE attribute argument must be a string constant", name);
    6142            3 :       *no_add_attrs = true;
    6143            3 :       return NULL_TREE;
    6144              :     }
    6145              :   /* Only allow on class templates, variable templates
    6146              :      and function templates.  */
    6147        74275 :   if (!CLASS_TYPE_P (*node) && !VAR_OR_FUNCTION_DECL_P (*node))
    6148              :     {
    6149          343 :     invalid:
    6150          343 :       warning (OPT_Wattributes, "%qE attribute only applies to class, "
    6151              :                                 "function or variable templates", name);
    6152          343 :       *no_add_attrs = true;
    6153          343 :       return NULL_TREE;
    6154              :     }
    6155        74139 :   tree ti = NULL_TREE;
    6156        74139 :   if (TYPE_P (*node))
    6157              :     {
    6158        73946 :       if (!TYPE_NAME (*node)
    6159        73946 :           || !DECL_IMPLICIT_TYPEDEF_P (TYPE_NAME (*node))
    6160       221826 :           || LAMBDA_TYPE_P (*node))
    6161            0 :         goto invalid;
    6162        73946 :       if (TYPE_LANG_SPECIFIC (*node))
    6163              :         {
    6164        73946 :           if (CLASSTYPE_TEMPLATE_SPECIALIZATION (*node)
    6165        73946 :               || CLASSTYPE_EXPLICIT_INSTANTIATION (*node))
    6166           39 :             goto invalid;
    6167        73907 :           ti = CLASSTYPE_TEMPLATE_INFO (*node);
    6168              :         }
    6169              :     }
    6170          193 :   else if (DECL_LANG_SPECIFIC (*node))
    6171              :     {
    6172          157 :       if (DECL_TEMPLATE_SPECIALIZATION (*node)
    6173          157 :           || DECL_EXPLICIT_INSTANTIATION (*node))
    6174           36 :         goto invalid;
    6175          121 :       ti = DECL_TEMPLATE_INFO (*node);
    6176              :     }
    6177        74028 :   if (ti)
    6178              :     {
    6179        73903 :       if (!PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)))
    6180           24 :         goto invalid;
    6181        73879 :       if (TYPE_P (*node) && DECL_ALIAS_TEMPLATE_P (TI_TEMPLATE (ti)))
    6182            0 :         goto invalid;
    6183              :     }
    6184          161 :   else if (!processing_template_decl || !template_parm_scope_p ())
    6185          108 :     goto invalid;
    6186              : 
    6187              :   return NULL_TREE;
    6188              : }
    6189              : 
    6190              : /* Validate the trivial_abi attribute on a completed class type.
    6191              :    Called from finish_struct after the class is complete.  */
    6192              : 
    6193              : void
    6194     53609360 : validate_trivial_abi_attribute (tree type)
    6195              : {
    6196     53609360 :   if (!has_trivial_abi_attribute (type))
    6197     53609251 :     return;
    6198              : 
    6199          151 :   gcc_assert (COMPLETE_TYPE_P (type));
    6200              : 
    6201          193 :   auto remove_trivial_abi_attribute = [type] {
    6202          138 :     for (tree variant = TYPE_MAIN_VARIANT (type); variant;
    6203           96 :          variant = TYPE_NEXT_VARIANT (variant))
    6204           96 :       TYPE_ATTRIBUTES (variant)
    6205          192 :         = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (variant));
    6206          193 :   };
    6207              : 
    6208              :   /* Check for virtual bases.  */
    6209          151 :   if (CLASSTYPE_VBASECLASSES (type))
    6210              :     {
    6211            6 :       auto_diagnostic_group d;
    6212            6 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6213              :                    type))
    6214            6 :         inform (input_location, "has a virtual base");
    6215            6 :       remove_trivial_abi_attribute ();
    6216            6 :       return;
    6217            6 :     }
    6218              : 
    6219              :   /* Check for virtual member functions.  */
    6220          145 :   if (TYPE_POLYMORPHIC_P (type))
    6221              :     {
    6222            9 :       auto_diagnostic_group d;
    6223            9 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6224              :                    type))
    6225            9 :         inform (input_location, "is polymorphic");
    6226            9 :       remove_trivial_abi_attribute ();
    6227            9 :       return;
    6228            9 :     }
    6229              : 
    6230              :   /* Check for non-trivial base classes.  */
    6231          136 :   if (TYPE_BINFO (type))
    6232              :     {
    6233          136 :       unsigned int n_bases = BINFO_N_BASE_BINFOS (TYPE_BINFO (type));
    6234          151 :       for (unsigned int i = 0; i < n_bases; ++i)
    6235              :         {
    6236           18 :           tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    6237           18 :           tree base_type = BINFO_TYPE (base_binfo);
    6238              : 
    6239           18 :           if (TREE_ADDRESSABLE (base_type))
    6240              :             {
    6241            3 :               auto_diagnostic_group d;
    6242            3 :               if (warning (OPT_Wattributes,
    6243              :                            "%<trivial_abi%> cannot be applied to %qT", type))
    6244            3 :                 inform (input_location, "has a non-trivial base class %qT",
    6245              :                         base_type);
    6246            3 :               remove_trivial_abi_attribute ();
    6247            3 :               return;
    6248            3 :             }
    6249              :         }
    6250              :     }
    6251              : 
    6252              :   /* Check for non-trivial member types.  */
    6253          741 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    6254              :     {
    6255          620 :       if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
    6256              :         {
    6257          118 :           tree field_type = strip_array_types (TREE_TYPE (field));
    6258              : 
    6259          118 :           if (CLASS_TYPE_P (field_type) && TREE_ADDRESSABLE (field_type))
    6260              :             {
    6261           12 :               auto_diagnostic_group d;
    6262           12 :               if (warning (OPT_Wattributes,
    6263              :                            "%<trivial_abi%> cannot be applied to %qT", type))
    6264           12 :                 inform (input_location, "has a non-static data member "
    6265              :                         "of non-trivial type %qT", field_type);
    6266           12 :               remove_trivial_abi_attribute ();
    6267           12 :               return;
    6268           12 :             }
    6269              :         }
    6270              :     }
    6271              : 
    6272              :   /* Check that not all copy/move constructors are deleted.  */
    6273          121 :   if (!classtype_has_non_deleted_copy_or_move_ctor (type))
    6274              :     {
    6275           12 :       auto_diagnostic_group d;
    6276           12 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6277              :                    type))
    6278           12 :         inform (input_location,
    6279              :                 "copy constructors and move constructors are all deleted");
    6280           12 :       remove_trivial_abi_attribute ();
    6281           12 :       return;
    6282           12 :     }
    6283              : }
    6284              : /* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
    6285              :    thing pointed to by the constant.  */
    6286              : 
    6287              : tree
    6288        64490 : make_ptrmem_cst (tree type, tree member)
    6289              : {
    6290        64490 :   tree ptrmem_cst = make_node (PTRMEM_CST);
    6291        64490 :   TREE_TYPE (ptrmem_cst) = type;
    6292        64490 :   PTRMEM_CST_MEMBER (ptrmem_cst) = member;
    6293        64490 :   PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
    6294        64490 :   return ptrmem_cst;
    6295              : }
    6296              : 
    6297              : /* Build a variant of TYPE that has the indicated ATTRIBUTES.  May
    6298              :    return an existing type if an appropriate type already exists.  */
    6299              : 
    6300              : tree
    6301     16684534 : cp_build_type_attribute_variant (tree type, tree attributes)
    6302              : {
    6303     16684534 :   tree new_type;
    6304              : 
    6305     16684534 :   new_type = build_type_attribute_variant (type, attributes);
    6306     16684534 :   if (FUNC_OR_METHOD_TYPE_P (new_type))
    6307     16613477 :     gcc_checking_assert (cxx_type_hash_eq (type, new_type));
    6308              : 
    6309              :   /* Making a new main variant of a class type is broken.  */
    6310     16684534 :   gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
    6311              : 
    6312     16684534 :   return new_type;
    6313              : }
    6314              : 
    6315              : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
    6316              :    Called only after doing all language independent checks.  */
    6317              : 
    6318              : bool
    6319    345705666 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
    6320              : {
    6321    345705666 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
    6322              : 
    6323    345705666 :   if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
    6324              :     return false;
    6325    345697979 :   if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
    6326              :     return false;
    6327    345696750 :   return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
    6328    691393500 :                             TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
    6329              : }
    6330              : 
    6331              : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA.  For
    6332              :    C++, these are the exception-specifier and ref-qualifier.  */
    6333              : 
    6334              : tree
    6335     27041634 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
    6336              : {
    6337     27041634 :   tree type = const_cast<tree> (typea);
    6338     27041634 :   if (FUNC_OR_METHOD_TYPE_P (type))
    6339     27040327 :     type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
    6340     27040327 :                                     TYPE_RAISES_EXCEPTIONS (typeb),
    6341     27040327 :                                     TYPE_HAS_LATE_RETURN_TYPE (typeb));
    6342     27041634 :   return type;
    6343              : }
    6344              : 
    6345              : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
    6346              :    traversal.  Called from walk_tree.  */
    6347              : 
    6348              : tree
    6349  25619096141 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
    6350              :                   void *data, hash_set<tree> *pset)
    6351              : {
    6352  25619096141 :   tree t = *tp;
    6353  25619096141 :   enum tree_code code = TREE_CODE (t);
    6354  25619096141 :   tree result;
    6355              : 
    6356              : #define WALK_SUBTREE(NODE)                              \
    6357              :   do                                                    \
    6358              :     {                                                   \
    6359              :       result = cp_walk_tree (&(NODE), func, data, pset);    \
    6360              :       if (result) goto out;                             \
    6361              :     }                                                   \
    6362              :   while (0)
    6363              : 
    6364  25619096141 :   if (TYPE_P (t))
    6365              :     {
    6366              :       /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
    6367              :          the argument, so don't look through typedefs, but do walk into
    6368              :          template arguments for alias templates (and non-typedefed classes).
    6369              : 
    6370              :          If *WALK_SUBTREES_P > 1, we're interested in type identity or
    6371              :          equivalence, so look through typedefs, ignoring template arguments for
    6372              :          alias templates, and walk into template args of classes.
    6373              : 
    6374              :          See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
    6375              :          when that's the behavior the walk_tree_fn wants.  */
    6376   7595650278 :       if (*walk_subtrees_p == 1 && typedef_variant_p (t))
    6377              :         {
    6378     78315864 :           if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
    6379     60256595 :             WALK_SUBTREE (TI_ARGS (ti));
    6380     78270899 :           *walk_subtrees_p = 0;
    6381     78270899 :           return NULL_TREE;
    6382              :         }
    6383              : 
    6384   7517334414 :       if (tree ti = TYPE_TEMPLATE_INFO (t))
    6385    860777259 :         WALK_SUBTREE (TI_ARGS (ti));
    6386              :     }
    6387              : 
    6388              :   /* Not one of the easy cases.  We must explicitly go through the
    6389              :      children.  */
    6390  25540609149 :   result = NULL_TREE;
    6391  25540609149 :   switch (code)
    6392              :     {
    6393   1963193417 :     case TEMPLATE_TYPE_PARM:
    6394   1963193417 :       if (template_placeholder_p (t))
    6395      1371792 :         WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
    6396              :       /* Fall through.  */
    6397   2124671789 :     case DEFERRED_PARSE:
    6398   2124671789 :     case TEMPLATE_TEMPLATE_PARM:
    6399   2124671789 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    6400   2124671789 :     case UNBOUND_CLASS_TEMPLATE:
    6401   2124671789 :     case TEMPLATE_PARM_INDEX:
    6402   2124671789 :     case TYPEOF_TYPE:
    6403              :       /* None of these have subtrees other than those already walked
    6404              :          above.  */
    6405   2124671789 :       *walk_subtrees_p = 0;
    6406   2124671789 :       break;
    6407              : 
    6408    222992296 :     case TYPENAME_TYPE:
    6409    222992296 :       WALK_SUBTREE (TYPE_CONTEXT (t));
    6410    222900274 :       WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
    6411    222898097 :       *walk_subtrees_p = 0;
    6412    222898097 :       break;
    6413              : 
    6414     85546495 :     case BASELINK:
    6415     85546495 :       if (BASELINK_QUALIFIED_P (t))
    6416      1554540 :         WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
    6417     85546495 :       WALK_SUBTREE (BASELINK_FUNCTIONS (t));
    6418     85442771 :       *walk_subtrees_p = 0;
    6419     85442771 :       break;
    6420              : 
    6421       134264 :     case PTRMEM_CST:
    6422       134264 :       WALK_SUBTREE (TREE_TYPE (t));
    6423       134264 :       *walk_subtrees_p = 0;
    6424       134264 :       break;
    6425              : 
    6426    284441838 :     case TREE_LIST:
    6427    284441838 :       WALK_SUBTREE (TREE_PURPOSE (t));
    6428              :       break;
    6429              : 
    6430    322591073 :     case OVERLOAD:
    6431    322591073 :       WALK_SUBTREE (OVL_FUNCTION (t));
    6432    322591068 :       WALK_SUBTREE (OVL_CHAIN (t));
    6433    322591068 :       *walk_subtrees_p = 0;
    6434    322591068 :       break;
    6435              : 
    6436      8181355 :     case USING_DECL:
    6437      8181355 :       WALK_SUBTREE (DECL_NAME (t));
    6438      8181355 :       WALK_SUBTREE (USING_DECL_SCOPE (t));
    6439      8181352 :       WALK_SUBTREE (USING_DECL_DECLS (t));
    6440      8181352 :       *walk_subtrees_p = 0;
    6441      8181352 :       break;
    6442              : 
    6443    994546242 :     case RECORD_TYPE:
    6444    994546242 :       if (TYPE_PTRMEMFUNC_P (t))
    6445      5739590 :         WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
    6446              :       break;
    6447              : 
    6448    153930346 :     case TYPE_ARGUMENT_PACK:
    6449    153930346 :     case NONTYPE_ARGUMENT_PACK:
    6450    153930346 :       {
    6451    153930346 :         tree args = ARGUMENT_PACK_ARGS (t);
    6452    402102786 :         for (tree arg : tree_vec_range (args))
    6453    248269749 :           WALK_SUBTREE (arg);
    6454              :       }
    6455    153833037 :       break;
    6456              : 
    6457     31131744 :     case TYPE_PACK_EXPANSION:
    6458     31131744 :       WALK_SUBTREE (TREE_TYPE (t));
    6459     31122676 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6460     31122676 :       *walk_subtrees_p = 0;
    6461     31122676 :       break;
    6462              : 
    6463      6271406 :     case EXPR_PACK_EXPANSION:
    6464      6271406 :       WALK_SUBTREE (TREE_OPERAND (t, 0));
    6465      6267602 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6466      6267602 :       *walk_subtrees_p = 0;
    6467      6267602 :       break;
    6468              : 
    6469        19118 :     case PACK_INDEX_TYPE:
    6470        19118 :     case PACK_INDEX_EXPR:
    6471        19118 :       WALK_SUBTREE (PACK_INDEX_PACK (t));
    6472        19118 :       WALK_SUBTREE (PACK_INDEX_INDEX (t));
    6473        19118 :       *walk_subtrees_p = 0;
    6474        19118 :       break;
    6475              : 
    6476    116113306 :     case CAST_EXPR:
    6477    116113306 :     case REINTERPRET_CAST_EXPR:
    6478    116113306 :     case STATIC_CAST_EXPR:
    6479    116113306 :     case CONST_CAST_EXPR:
    6480    116113306 :     case DYNAMIC_CAST_EXPR:
    6481    116113306 :     case IMPLICIT_CONV_EXPR:
    6482    116113306 :     case BIT_CAST_EXPR:
    6483    116113306 :       if (TREE_TYPE (t))
    6484    116113306 :         WALK_SUBTREE (TREE_TYPE (t));
    6485              :       break;
    6486              : 
    6487    108431751 :     case CONSTRUCTOR:
    6488    108431751 :       if (COMPOUND_LITERAL_P (t))
    6489      9536680 :         WALK_SUBTREE (TREE_TYPE (t));
    6490              :       break;
    6491              : 
    6492     16264190 :     case TRAIT_EXPR:
    6493     16264190 :       WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
    6494     16264178 :       WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
    6495     16264178 :       *walk_subtrees_p = 0;
    6496     16264178 :       break;
    6497              : 
    6498      2185193 :     case TRAIT_TYPE:
    6499      2185193 :       WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
    6500      2185193 :       WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
    6501      2185193 :       *walk_subtrees_p = 0;
    6502      2185193 :       break;
    6503              : 
    6504     22041119 :     case DECLTYPE_TYPE:
    6505     22041119 :       {
    6506     22041119 :         cp_unevaluated u;
    6507     22041119 :         WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
    6508     21671983 :         *walk_subtrees_p = 0;
    6509     21671983 :         break;
    6510     22041119 :       }
    6511              : 
    6512     29231105 :     case ALIGNOF_EXPR:
    6513     29231105 :     case SIZEOF_EXPR:
    6514     29231105 :     case NOEXCEPT_EXPR:
    6515     29231105 :       {
    6516     29231105 :         cp_unevaluated u;
    6517     29231105 :         WALK_SUBTREE (TREE_OPERAND (t, 0));
    6518     26065548 :         *walk_subtrees_p = 0;
    6519     26065548 :         break;
    6520     29231105 :       }
    6521              : 
    6522     13465608 :     case REQUIRES_EXPR:
    6523     13465608 :       {
    6524     13465608 :         cp_unevaluated u;
    6525     22601756 :         for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
    6526              :           /* Walk the types of each parameter, but not the parameter itself,
    6527              :              since doing so would cause false positives in the unexpanded pack
    6528              :              checker if the requires-expr introduces a function parameter pack,
    6529              :              e.g. requires (Ts... ts) { }.   */
    6530      9137048 :           WALK_SUBTREE (TREE_TYPE (parm));
    6531     13464708 :         WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
    6532     13460826 :         *walk_subtrees_p = 0;
    6533     13460826 :         break;
    6534     13465608 :       }
    6535              : 
    6536    135057391 :     case DECL_EXPR:
    6537              :       /* User variables should be mentioned in BIND_EXPR_VARS
    6538              :          and their initializers and sizes walked when walking
    6539              :          the containing BIND_EXPR.  Compiler temporaries are
    6540              :          handled here.  And also normal variables in templates,
    6541              :          since do_poplevel doesn't build a BIND_EXPR then.  */
    6542    135057391 :       if (VAR_P (TREE_OPERAND (t, 0))
    6543    135057391 :           && (processing_template_decl
    6544    118790589 :               || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
    6545      6618275 :                   && !TREE_STATIC (TREE_OPERAND (t, 0)))))
    6546              :         {
    6547     15694332 :           tree decl = TREE_OPERAND (t, 0);
    6548     15694332 :           WALK_SUBTREE (TREE_TYPE (decl));
    6549     15694332 :           WALK_SUBTREE (DECL_INITIAL (decl));
    6550     15694302 :           WALK_SUBTREE (DECL_SIZE (decl));
    6551     15694302 :           WALK_SUBTREE (DECL_SIZE_UNIT (decl));
    6552              :         }
    6553    135057361 :       if (is_typedef_decl (TREE_OPERAND (t, 0)))
    6554              :         /* We avoid walking into typedefs above, but we do want to walk
    6555              :            into them if we're looking at the actual declaration.  */
    6556      1341715 :         WALK_SUBTREE (DECL_ORIGINAL_TYPE (TREE_OPERAND (t, 0)));
    6557              :       break;
    6558              : 
    6559      2092017 :     case LAMBDA_EXPR:
    6560              :       /* Don't walk into the body of the lambda, but the capture initializers
    6561              :          are part of the enclosing context.  */
    6562      5010320 :       for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
    6563      2918303 :            cap = TREE_CHAIN (cap))
    6564      2918303 :         WALK_SUBTREE (TREE_VALUE (cap));
    6565              :       break;
    6566              : 
    6567         4447 :     case CO_YIELD_EXPR:
    6568         4447 :       if (TREE_OPERAND (t, 1))
    6569              :         /* Operand 1 is the tree for the relevant co_await which has any
    6570              :            interesting sub-trees.  */
    6571          601 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6572              :       break;
    6573              : 
    6574        27582 :     case CO_AWAIT_EXPR:
    6575        27582 :       if (TREE_OPERAND (t, 1))
    6576              :         /* Operand 1 is frame variable.  */
    6577        27394 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6578        27582 :       if (TREE_OPERAND (t, 2))
    6579              :         /* Operand 2 has the initialiser, and we need to walk any subtrees
    6580              :            there.  */
    6581         5521 :         WALK_SUBTREE (TREE_OPERAND (t, 2));
    6582              :       break;
    6583              : 
    6584          885 :     case CO_RETURN_EXPR:
    6585          885 :       if (TREE_OPERAND (t, 0))
    6586              :         {
    6587          699 :           if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
    6588              :             /* For void expressions, operand 1 is a trivial call, and any
    6589              :                interesting subtrees will be part of operand 0.  */
    6590            0 :             WALK_SUBTREE (TREE_OPERAND (t, 0));
    6591          699 :           else if (TREE_OPERAND (t, 1))
    6592              :             /* Interesting sub-trees will be in the return_value () call
    6593              :                arguments.  */
    6594          657 :             WALK_SUBTREE (TREE_OPERAND (t, 1));
    6595              :         }
    6596              :       break;
    6597              : 
    6598       670825 :     case STATIC_ASSERT:
    6599       670825 :       WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
    6600       670825 :       WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
    6601              :       break;
    6602              : 
    6603    789180556 :     case INTEGER_TYPE:
    6604              :       /* Removed from walk_type_fields in r119481.  */
    6605    789180556 :       WALK_SUBTREE (TYPE_MIN_VALUE (t));
    6606    789180556 :       WALK_SUBTREE (TYPE_MAX_VALUE (t));
    6607              :       break;
    6608              : 
    6609          642 :     case SPLICE_SCOPE:
    6610          642 :       WALK_SUBTREE (SPLICE_SCOPE_EXPR (t));
    6611          636 :       *walk_subtrees_p = 0;
    6612          636 :       break;
    6613              : 
    6614              :     default:
    6615              :       return NULL_TREE;
    6616              :     }
    6617              : 
    6618              :   /* We didn't find what we were looking for.  */
    6619  25619096141 :  out:
    6620              :   return result;
    6621              : 
    6622              : #undef WALK_SUBTREE
    6623              : }
    6624              : 
    6625              : /* Like save_expr, but for C++.  */
    6626              : 
    6627              : tree
    6628       331374 : cp_save_expr (tree expr)
    6629              : {
    6630              :   /* There is no reason to create a SAVE_EXPR within a template; if
    6631              :      needed, we can create the SAVE_EXPR when instantiating the
    6632              :      template.  Furthermore, the middle-end cannot handle C++-specific
    6633              :      tree codes.  */
    6634       331374 :   if (processing_template_decl)
    6635              :     return expr;
    6636              : 
    6637              :   /* TARGET_EXPRs are only expanded once.  */
    6638       255598 :   if (TREE_CODE (expr) == TARGET_EXPR)
    6639              :     return expr;
    6640              : 
    6641       255598 :   return save_expr (expr);
    6642              : }
    6643              : 
    6644              : /* Initialize tree.cc.  */
    6645              : 
    6646              : void
    6647       101500 : init_tree (void)
    6648              : {
    6649       101500 :   list_hash_table = hash_table<list_hasher>::create_ggc (61);
    6650       101500 : }
    6651              : 
    6652              : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
    6653              :    is.  Note that sfk_none is zero, so this function can be used as a
    6654              :    predicate to test whether or not DECL is a special function.  */
    6655              : 
    6656              : special_function_kind
    6657    155903500 : special_function_p (const_tree decl)
    6658              : {
    6659              :   /* Rather than doing all this stuff with magic names, we should
    6660              :      probably have a field of type `special_function_kind' in
    6661              :      DECL_LANG_SPECIFIC.  */
    6662    311807000 :   if (DECL_INHERITED_CTOR (decl))
    6663              :     return sfk_inheriting_constructor;
    6664    311031304 :   if (DECL_COPY_CONSTRUCTOR_P (decl))
    6665              :     return sfk_copy_constructor;
    6666    280807998 :   if (DECL_MOVE_CONSTRUCTOR_P (decl))
    6667              :     return sfk_move_constructor;
    6668    260698050 :   if (DECL_CONSTRUCTOR_P (decl))
    6669              :     return sfk_constructor;
    6670    111713591 :   if (DECL_ASSIGNMENT_OPERATOR_P (decl)
    6671    111713591 :       && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
    6672              :     {
    6673     12901896 :       if (copy_fn_p (decl))
    6674              :         return sfk_copy_assignment;
    6675      5140784 :       if (move_fn_p (decl))
    6676              :         return sfk_move_assignment;
    6677              :     }
    6678     99025574 :   if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
    6679              :     return sfk_destructor;
    6680     57055469 :   if (DECL_COMPLETE_DESTRUCTOR_P (decl))
    6681              :     return sfk_complete_destructor;
    6682     43146505 :   if (DECL_BASE_DESTRUCTOR_P (decl))
    6683              :     return sfk_base_destructor;
    6684     42199419 :   if (DECL_DELETING_DESTRUCTOR_P (decl))
    6685              :     return sfk_deleting_destructor;
    6686     30162455 :   if (DECL_CONV_FN_P (decl))
    6687              :     return sfk_conversion;
    6688     30160784 :   if (deduction_guide_p (decl))
    6689              :     return sfk_deduction_guide;
    6690     30131072 :   if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
    6691     30131072 :       && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
    6692      4362658 :     return sfk_comparison;
    6693              : 
    6694              :   return sfk_none;
    6695              : }
    6696              : 
    6697              : /* As above, but only if DECL is a special member function as per 11.3.3
    6698              :    [special]: default/copy/move ctor, copy/move assignment, or destructor.  */
    6699              : 
    6700              : special_function_kind
    6701      3109888 : special_memfn_p (const_tree decl)
    6702              : {
    6703      3109888 :   switch (special_function_kind sfk = special_function_p (decl))
    6704              :     {
    6705      2869518 :     case sfk_constructor:
    6706      2869518 :       if (!default_ctor_p (decl))
    6707              :         break;
    6708              :       gcc_fallthrough();
    6709              :     case sfk_copy_constructor:
    6710              :     case sfk_copy_assignment:
    6711              :     case sfk_move_assignment:
    6712              :     case sfk_move_constructor:
    6713              :     case sfk_destructor:
    6714              :       return sfk;
    6715              : 
    6716              :     default:
    6717              :       break;
    6718              :     }
    6719              :   return sfk_none;
    6720              : }
    6721              : 
    6722              : /* Returns nonzero if TYPE is a character type, including wchar_t.  */
    6723              : 
    6724              : int
    6725     12913741 : char_type_p (tree type)
    6726              : {
    6727     12913741 :   return (same_type_p (type, char_type_node)
    6728     11708208 :           || same_type_p (type, unsigned_char_type_node)
    6729     11654939 :           || same_type_p (type, signed_char_type_node)
    6730     11654362 :           || same_type_p (type, char8_type_node)
    6731     11654222 :           || same_type_p (type, char16_type_node)
    6732     11653712 :           || same_type_p (type, char32_type_node)
    6733     24444950 :           || same_type_p (type, wchar_type_node));
    6734              : }
    6735              : 
    6736              : /* Returns the kind of linkage associated with the indicated DECL.  The
    6737              :    value returned is as specified by the language standard; it is
    6738              :    independent of implementation details regarding template
    6739              :    instantiation, etc.  For example, it is possible that a declaration
    6740              :    to which this function assigns external linkage would not show up
    6741              :    as a global symbol when you run `nm' on the resulting object file.  */
    6742              : 
    6743              : linkage_kind
    6744    483265610 : decl_linkage (tree decl)
    6745              : {
    6746              :   /* This function doesn't attempt to calculate the linkage from first
    6747              :      principles as given in [basic.link].  Instead, it makes use of
    6748              :      the fact that we have already set TREE_PUBLIC appropriately, and
    6749              :      then handles a few special cases.  Ideally, we would calculate
    6750              :      linkage first, and then transform that into a concrete
    6751              :      implementation.  */
    6752              : 
    6753              :   /* An explicit type alias has no linkage.  Nor do the built-in declarations
    6754              :      of 'int' and such.  */
    6755    531637439 :   if (TREE_CODE (decl) == TYPE_DECL
    6756    531637439 :       && !DECL_IMPLICIT_TYPEDEF_P (decl))
    6757              :     {
    6758              :       /* But this could be a typedef name for linkage purposes, in which
    6759              :          case we're interested in the linkage of the main decl.  */
    6760      1029052 :       tree type = TREE_TYPE (decl);
    6761      1029052 :       if (type == error_mark_node)
    6762              :         return lk_none;
    6763      1029050 :       else if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (type))
    6764              :                /* Likewise for the injected-class-name.  */
    6765      1029050 :                || DECL_SELF_REFERENCE_P (decl))
    6766        72803 :         decl = TYPE_MAIN_DECL (type);
    6767              :       else
    6768              :         return lk_none;
    6769              :     }
    6770              : 
    6771              :   /* Namespace-scope entities with no name usually have no linkage.  */
    6772    530681190 :   if (NAMESPACE_SCOPE_P (decl)
    6773   1009239435 :       && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
    6774              :     {
    6775      3935008 :       if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
    6776              :         /* This entity has a name for linkage purposes.  */;
    6777      3913884 :       else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
    6778              :         /* Namespace-scope structured bindings can have linkage.  */;
    6779      3913779 :       else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
    6780              :         /* An anonymous namespace has internal linkage since C++11.  */
    6781              :         return lk_internal;
    6782              :       else
    6783      3913779 :         return lk_none;
    6784              :     }
    6785              : 
    6786              :   /* Fields and parameters have no linkage.  */
    6787    526767411 :   if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
    6788              :     return lk_none;
    6789              : 
    6790              :   /* Things in block scope do not have linkage.  */
    6791    478560285 :   if (decl_function_context (decl))
    6792              :     return lk_none;
    6793              : 
    6794              :   /* Things in class scope have the linkage of their owning class.  */
    6795    474811097 :   if (tree ctype = DECL_CLASS_CONTEXT (decl))
    6796     48371829 :     return decl_linkage (TYPE_NAME (ctype));
    6797              : 
    6798              :   /* Anonymous namespaces don't provide internal linkage in C++98,
    6799              :      but otherwise consider such declarations to be internal.  */
    6800    426439268 :   if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
    6801              :     return lk_internal;
    6802              : 
    6803              :   /* Helper to decide if T is lk_module or lk_external.  */
    6804    852342784 :   auto external_or_module = [] (tree t)
    6805              :     {
    6806    426089391 :       if (t
    6807    426089358 :           && DECL_LANG_SPECIFIC (t)
    6808    313785938 :           && DECL_MODULE_ATTACH_P (t)
    6809    426107409 :           && !DECL_MODULE_EXPORT_P (t))
    6810         7585 :         return lk_module;
    6811              : 
    6812              :       return lk_external;
    6813              :     };
    6814              : 
    6815              :   /* Templates don't properly propagate TREE_PUBLIC, consider the
    6816              :      template result instead.  Any template that isn't a variable
    6817              :      or function must be external linkage by this point.  */
    6818    426253393 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    6819              :     {
    6820      1336305 :       decl = DECL_TEMPLATE_RESULT (decl);
    6821      1336305 :       if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
    6822       621896 :         return external_or_module (decl);
    6823              :     }
    6824              : 
    6825              :   /* Things that are TREE_PUBLIC have external linkage.  */
    6826    425631497 :   if (TREE_PUBLIC (decl))
    6827    332687606 :     return external_or_module (decl);
    6828              : 
    6829              :   /* All types have external linkage in C++98, since anonymous namespaces
    6830              :      didn't explicitly confer internal linkage.  */
    6831     92943891 :   if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
    6832            4 :     return external_or_module (decl);
    6833              : 
    6834              :   /* Variables or function decls not marked as TREE_PUBLIC might still
    6835              :      be external linkage, such as for template instantiations on targets
    6836              :      without weak symbols, decls referring to internal-linkage entities,
    6837              :      or compiler-generated entities; in such cases, decls really meant to
    6838              :      have internal linkage will have DECL_THIS_STATIC set.  */
    6839     92943887 :   if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
    6840     92779885 :     return external_or_module (decl);
    6841              : 
    6842              :   /* Everything else has internal linkage.  */
    6843              :   return lk_internal;
    6844              : }
    6845              : 
    6846              : /* Returns the storage duration of the object or reference associated with
    6847              :    the indicated DECL, which should be a VAR_DECL or PARM_DECL.  */
    6848              : 
    6849              : duration_kind
    6850     64133011 : decl_storage_duration (tree decl)
    6851              : {
    6852     64133011 :   if (TREE_CODE (decl) == PARM_DECL)
    6853              :     return dk_auto;
    6854     64132999 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6855              :     return dk_static;
    6856     64132999 :   gcc_assert (VAR_P (decl));
    6857     64132999 :   if (!TREE_STATIC (decl)
    6858     64132999 :       && !DECL_EXTERNAL (decl))
    6859              :     return dk_auto;
    6860     38570408 :   if (CP_DECL_THREAD_LOCAL_P (decl))
    6861        21097 :     return dk_thread;
    6862              :   return dk_static;
    6863              : }
    6864              : 
    6865              : /* EXP is an expression that we want to pre-evaluate.  Returns (in
    6866              :    *INITP) an expression that will perform the pre-evaluation.  The
    6867              :    value returned by this function is a side-effect free expression
    6868              :    equivalent to the pre-evaluated expression.  Callers must ensure
    6869              :    that *INITP is evaluated before EXP.
    6870              : 
    6871              :    Note that if EXPR is a glvalue, the return value is a glvalue denoting the
    6872              :    same address; this function does not guard against modification of the
    6873              :    stored value like save_expr or get_target_expr do.  */
    6874              : 
    6875              : tree
    6876      6207132 : stabilize_expr (tree exp, tree* initp)
    6877              : {
    6878      6207132 :   tree init_expr;
    6879              : 
    6880      6207132 :   if (!TREE_SIDE_EFFECTS (exp))
    6881              :     init_expr = NULL_TREE;
    6882       979746 :   else if (VOID_TYPE_P (TREE_TYPE (exp)))
    6883              :     {
    6884            0 :       init_expr = exp;
    6885            0 :       exp = void_node;
    6886              :     }
    6887              :   /* There are no expressions with REFERENCE_TYPE, but there can be call
    6888              :      arguments with such a type; just treat it as a pointer.  */
    6889       979746 :   else if (TYPE_REF_P (TREE_TYPE (exp))
    6890       979611 :            || SCALAR_TYPE_P (TREE_TYPE (exp))
    6891       979806 :            || !glvalue_p (exp))
    6892              :     {
    6893       979740 :       init_expr = get_target_expr (exp);
    6894       979740 :       exp = TARGET_EXPR_SLOT (init_expr);
    6895       979740 :       if (CLASS_TYPE_P (TREE_TYPE (exp)))
    6896            9 :         exp = move (exp);
    6897              :       else
    6898       979731 :         exp = rvalue (exp);
    6899              :     }
    6900              :   else
    6901              :     {
    6902            6 :       bool xval = !lvalue_p (exp);
    6903            6 :       exp = cp_build_addr_expr (exp, tf_warning_or_error);
    6904            6 :       init_expr = get_target_expr (exp);
    6905            6 :       exp = TARGET_EXPR_SLOT (init_expr);
    6906            6 :       exp = cp_build_fold_indirect_ref (exp);
    6907            6 :       if (xval)
    6908            0 :         exp = move (exp);
    6909              :     }
    6910      6207132 :   *initp = init_expr;
    6911              : 
    6912      6207132 :   gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
    6913      6207132 :   return exp;
    6914              : }
    6915              : 
    6916              : /* Add NEW_EXPR, an expression whose value we don't care about, after the
    6917              :    similar expression ORIG.  */
    6918              : 
    6919              : tree
    6920      1385071 : add_stmt_to_compound (tree orig, tree new_expr)
    6921              : {
    6922      1385071 :   if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
    6923              :     return orig;
    6924       696348 :   if (!orig || !TREE_SIDE_EFFECTS (orig))
    6925              :     return new_expr;
    6926        13411 :   return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
    6927              : }
    6928              : 
    6929              : /* Like stabilize_expr, but for a call whose arguments we want to
    6930              :    pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6931              :    arguments, while, upon return, *INITP contains an expression to
    6932              :    compute the arguments.  */
    6933              : 
    6934              : void
    6935       684349 : stabilize_call (tree call, tree *initp)
    6936              : {
    6937       684349 :   tree inits = NULL_TREE;
    6938       684349 :   int i;
    6939       684349 :   int nargs = call_expr_nargs (call);
    6940              : 
    6941       684349 :   if (call == error_mark_node || processing_template_decl)
    6942              :     {
    6943           39 :       *initp = NULL_TREE;
    6944           39 :       return;
    6945              :     }
    6946              : 
    6947       684310 :   gcc_assert (TREE_CODE (call) == CALL_EXPR);
    6948              : 
    6949      2053048 :   for (i = 0; i < nargs; i++)
    6950              :     {
    6951      1368738 :       tree init;
    6952      1368738 :       CALL_EXPR_ARG (call, i) =
    6953      1368738 :         stabilize_expr (CALL_EXPR_ARG (call, i), &init);
    6954      1368738 :       inits = add_stmt_to_compound (inits, init);
    6955              :     }
    6956              : 
    6957       684310 :   *initp = inits;
    6958              : }
    6959              : 
    6960              : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
    6961              :    to pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6962              :    arguments, while, upon return, *INITP contains an expression to
    6963              :    compute the arguments.  */
    6964              : 
    6965              : static void
    6966            0 : stabilize_aggr_init (tree call, tree *initp)
    6967              : {
    6968            0 :   tree inits = NULL_TREE;
    6969            0 :   int i;
    6970            0 :   int nargs = aggr_init_expr_nargs (call);
    6971              : 
    6972            0 :   if (call == error_mark_node)
    6973              :     return;
    6974              : 
    6975            0 :   gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
    6976              : 
    6977            0 :   for (i = 0; i < nargs; i++)
    6978              :     {
    6979            0 :       tree init;
    6980            0 :       AGGR_INIT_EXPR_ARG (call, i) =
    6981            0 :         stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
    6982            0 :       inits = add_stmt_to_compound (inits, init);
    6983              :     }
    6984              : 
    6985            0 :   *initp = inits;
    6986              : }
    6987              : 
    6988              : /* Like stabilize_expr, but for an initialization.
    6989              : 
    6990              :    If the initialization is for an object of class type, this function
    6991              :    takes care not to introduce additional temporaries.
    6992              : 
    6993              :    Returns TRUE iff the expression was successfully pre-evaluated,
    6994              :    i.e., if INIT is now side-effect free, except for, possibly, a
    6995              :    single call to a constructor.  */
    6996              : 
    6997              : bool
    6998            0 : stabilize_init (tree init, tree *initp)
    6999              : {
    7000            0 :   tree t = init;
    7001              : 
    7002            0 :   *initp = NULL_TREE;
    7003              : 
    7004            0 :   if (t == error_mark_node || processing_template_decl)
    7005              :     return true;
    7006              : 
    7007            0 :   if (TREE_CODE (t) == INIT_EXPR)
    7008            0 :     t = TREE_OPERAND (t, 1);
    7009            0 :   if (TREE_CODE (t) == TARGET_EXPR)
    7010            0 :     t = TARGET_EXPR_INITIAL (t);
    7011              : 
    7012              :   /* If the RHS can be stabilized without breaking copy elision, stabilize
    7013              :      it.  We specifically don't stabilize class prvalues here because that
    7014              :      would mean an extra copy, but they might be stabilized below.  */
    7015            0 :   if (TREE_CODE (init) == INIT_EXPR
    7016            0 :       && TREE_CODE (t) != CONSTRUCTOR
    7017            0 :       && TREE_CODE (t) != AGGR_INIT_EXPR
    7018            0 :       && (SCALAR_TYPE_P (TREE_TYPE (t))
    7019            0 :           || glvalue_p (t)))
    7020              :     {
    7021            0 :       TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
    7022            0 :       return true;
    7023              :     }
    7024              : 
    7025            0 :   if (TREE_CODE (t) == COMPOUND_EXPR
    7026            0 :       && TREE_CODE (init) == INIT_EXPR)
    7027              :     {
    7028            0 :       tree last = expr_last (t);
    7029              :       /* Handle stabilizing the EMPTY_CLASS_EXPR pattern.  */
    7030            0 :       if (!TREE_SIDE_EFFECTS (last))
    7031              :         {
    7032            0 :           *initp = t;
    7033            0 :           TREE_OPERAND (init, 1) = last;
    7034            0 :           return true;
    7035              :         }
    7036              :     }
    7037              : 
    7038            0 :   if (TREE_CODE (t) == CONSTRUCTOR)
    7039              :     {
    7040              :       /* Aggregate initialization: stabilize each of the field
    7041              :          initializers.  */
    7042            0 :       unsigned i;
    7043            0 :       constructor_elt *ce;
    7044            0 :       bool good = true;
    7045            0 :       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
    7046            0 :       for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
    7047              :         {
    7048            0 :           tree type = TREE_TYPE (ce->value);
    7049            0 :           tree subinit;
    7050            0 :           if (TYPE_REF_P (type)
    7051            0 :               || SCALAR_TYPE_P (type))
    7052            0 :             ce->value = stabilize_expr (ce->value, &subinit);
    7053            0 :           else if (!stabilize_init (ce->value, &subinit))
    7054            0 :             good = false;
    7055            0 :           *initp = add_stmt_to_compound (*initp, subinit);
    7056              :         }
    7057              :       return good;
    7058              :     }
    7059              : 
    7060            0 :   if (TREE_CODE (t) == CALL_EXPR)
    7061              :     {
    7062            0 :       stabilize_call (t, initp);
    7063            0 :       return true;
    7064              :     }
    7065              : 
    7066            0 :   if (TREE_CODE (t) == AGGR_INIT_EXPR)
    7067              :     {
    7068            0 :       stabilize_aggr_init (t, initp);
    7069            0 :       return true;
    7070              :     }
    7071              : 
    7072              :   /* The initialization is being performed via a bitwise copy -- and
    7073              :      the item copied may have side effects.  */
    7074            0 :   return !TREE_SIDE_EFFECTS (init);
    7075              : }
    7076              : 
    7077              : /* Returns true if a cast to TYPE may appear in an integral constant
    7078              :    expression.  */
    7079              : 
    7080              : bool
    7081     99361533 : cast_valid_in_integral_constant_expression_p (tree type)
    7082              : {
    7083     99361533 :   return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    7084     71009785 :           || cxx_dialect >= cxx11
    7085       487326 :           || dependent_type_p (type)
    7086     99735724 :           || type == error_mark_node);
    7087              : }
    7088              : 
    7089              : /* Return true if we need to fix linkage information of DECL.  */
    7090              : 
    7091              : static bool
    7092        76325 : cp_fix_function_decl_p (tree decl)
    7093              : {
    7094              :   /* Skip if DECL is not externally visible.  */
    7095        76325 :   if (!TREE_PUBLIC (decl))
    7096              :     return false;
    7097              : 
    7098              :   /* We need to fix DECL if it a appears to be exported but with no
    7099              :      function body.  Thunks do not have CFGs and we may need to
    7100              :      handle them specially later.   */
    7101        73904 :   if (!gimple_has_body_p (decl)
    7102        27660 :       && !DECL_THUNK_P (decl)
    7103       101178 :       && !DECL_EXTERNAL (decl))
    7104              :     {
    7105        12916 :       struct cgraph_node *node = cgraph_node::get (decl);
    7106              : 
    7107              :       /* Don't fix same_body aliases.  Although they don't have their own
    7108              :          CFG, they share it with what they alias to.  */
    7109        12916 :       if (!node || !node->alias || !node->num_references ())
    7110         6768 :         return true;
    7111              :     }
    7112              : 
    7113              :   return false;
    7114              : }
    7115              : 
    7116              : /* Clean the C++ specific parts of the tree T. */
    7117              : 
    7118              : void
    7119       743511 : cp_free_lang_data (tree t)
    7120              : {
    7121       743511 :   if (FUNC_OR_METHOD_TYPE_P (t))
    7122              :     {
    7123              :       /* Default args are not interesting anymore.  */
    7124        61580 :       tree argtypes = TYPE_ARG_TYPES (t);
    7125       221962 :       while (argtypes)
    7126              :         {
    7127       160382 :           TREE_PURPOSE (argtypes) = 0;
    7128       160382 :           argtypes = TREE_CHAIN (argtypes);
    7129              :         }
    7130              :     }
    7131       681931 :   else if (TREE_CODE (t) == FUNCTION_DECL
    7132       681931 :            && cp_fix_function_decl_p (t))
    7133              :     {
    7134              :       /* If T is used in this translation unit at all,  the definition
    7135              :          must exist somewhere else since we have decided to not emit it
    7136              :          in this TU.  So make it an external reference.  */
    7137         6768 :       DECL_EXTERNAL (t) = 1;
    7138         6768 :       TREE_STATIC (t) = 0;
    7139              :     }
    7140       743511 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    7141              :     /* We do not need the leftover chaining of namespaces from the
    7142              :        binding level.  */
    7143         1683 :     DECL_CHAIN (t) = NULL_TREE;
    7144       743511 : }
    7145              : 
    7146              : /* Stub for c-common.  Please keep in sync with c-decl.cc.
    7147              :    FIXME: If address space support is target specific, then this
    7148              :    should be a C target hook.  But currently this is not possible,
    7149              :    because this function is called via REGISTER_TARGET_PRAGMAS.  */
    7150              : void
    7151       203000 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
    7152              : {
    7153       203000 : }
    7154              : 
    7155              : /* Return the number of operands in T that we care about for things like
    7156              :    mangling.  */
    7157              : 
    7158              : int
    7159    597684174 : cp_tree_operand_length (const_tree t)
    7160              : {
    7161    597684174 :   enum tree_code code = TREE_CODE (t);
    7162              : 
    7163    597684174 :   if (TREE_CODE_CLASS (code) == tcc_vl_exp)
    7164     69933703 :     return VL_EXP_OPERAND_LENGTH (t);
    7165              : 
    7166    527750471 :   return cp_tree_code_length (code);
    7167              : }
    7168              : 
    7169              : /* Like cp_tree_operand_length, but takes a tree_code CODE.  */
    7170              : 
    7171              : int
    7172    534284232 : cp_tree_code_length (enum tree_code code)
    7173              : {
    7174    534284232 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    7175              : 
    7176    534284232 :   switch (code)
    7177              :     {
    7178              :     case PREINCREMENT_EXPR:
    7179              :     case PREDECREMENT_EXPR:
    7180              :     case POSTINCREMENT_EXPR:
    7181              :     case POSTDECREMENT_EXPR:
    7182              :       return 1;
    7183              : 
    7184      1126533 :     case ARRAY_REF:
    7185      1126533 :       return 2;
    7186              : 
    7187              :     case EXPR_PACK_EXPANSION:
    7188              :       return 1;
    7189              : 
    7190    530586689 :     default:
    7191    530586689 :       return TREE_CODE_LENGTH (code);
    7192              :     }
    7193              : }
    7194              : 
    7195              : /* Implement -Wzero_as_null_pointer_constant.  Return true if the
    7196              :    conditions for the warning hold, false otherwise.  */
    7197              : bool
    7198      7711853 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
    7199              : {
    7200      7711853 :   if (c_inhibit_evaluation_warnings == 0
    7201     14363243 :       && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
    7202              :     {
    7203      2753883 :       warning_at (loc, OPT_Wzero_as_null_pointer_constant,
    7204              :                   "zero as null pointer constant");
    7205      2753883 :       return true;
    7206              :     }
    7207              :   return false;
    7208              : }
    7209              : 
    7210              : /* FNDECL is a function declaration whose type may have been altered by
    7211              :    adding extra parameters such as this, in-charge, or VTT.  When this
    7212              :    takes place, the positional arguments supplied by the user (as in the
    7213              :    'format' attribute arguments) may refer to the wrong argument.  This
    7214              :    function returns an integer indicating how many arguments should be
    7215              :    skipped.  */
    7216              : 
    7217              : int
    7218     38488230 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
    7219              : {
    7220     38488230 :   if (!fndecl)
    7221              :     return 0;
    7222      7523045 :   int n = num_artificial_parms_for (fndecl);
    7223              :   /* The manual states that it's the user's responsibility to account
    7224              :      for the implicit this parameter.  */
    7225      7523045 :   return n > 0 ? n - 1 : 0;
    7226              : }
    7227              : 
    7228              : /* True if ATTR is annotation.  */
    7229              : 
    7230              : bool
    7231     59465725 : annotation_p (tree attr)
    7232              : {
    7233     59465725 :   return is_attribute_p ("annotation ", get_attribute_name (attr));
    7234              : }
    7235              : 
    7236              : /* Lookup the annotation in ATTR, if present.  */
    7237              : 
    7238              : tree
    7239        77171 : lookup_annotation (tree attr)
    7240              : {
    7241        77171 :   return lookup_attribute ("internal ", "annotation ", attr);
    7242              : }
    7243              : 
    7244              : 
    7245              : /* Release memory we no longer need after parsing.  */
    7246              : void
    7247        99773 : cp_tree_c_finish_parsing ()
    7248              : {
    7249        99773 :   if (previous_class_level)
    7250        70706 :     invalidate_class_lookup_cache ();
    7251        99773 :   deleted_copy_types = NULL;
    7252        99773 : }
    7253              : 
    7254              : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
    7255              : /* Complain that some language-specific thing hanging off a tree
    7256              :    node has been accessed improperly.  */
    7257              : 
    7258              : void
    7259            0 : lang_check_failed (const char* file, int line, const char* function)
    7260              : {
    7261            0 :   internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
    7262              :                   function, trim_filename (file), line);
    7263              : }
    7264              : #endif /* ENABLE_TREE_CHECKING */
    7265              : 
    7266              : #if CHECKING_P
    7267              : 
    7268              : namespace selftest {
    7269              : 
    7270              : /* Verify that lvalue_kind () works, for various expressions,
    7271              :    and that location wrappers don't affect the results.  */
    7272              : 
    7273              : static void
    7274            1 : test_lvalue_kind ()
    7275              : {
    7276            1 :   location_t loc = BUILTINS_LOCATION;
    7277              : 
    7278              :   /* Verify constants and parameters, without and with
    7279              :      location wrappers.  */
    7280            1 :   tree int_cst = build_int_cst (integer_type_node, 42);
    7281            1 :   ASSERT_EQ (clk_none, lvalue_kind (int_cst));
    7282              : 
    7283            1 :   tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
    7284            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
    7285            1 :   ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
    7286              : 
    7287            1 :   tree string_lit = build_string (4, "foo");
    7288            1 :   TREE_TYPE (string_lit) = char_array_type_node;
    7289            1 :   string_lit = fix_string_type (string_lit);
    7290            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
    7291              : 
    7292            1 :   tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
    7293            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
    7294            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
    7295              : 
    7296            1 :   tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
    7297              :                           get_identifier ("some_parm"),
    7298              :                           integer_type_node);
    7299            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
    7300              : 
    7301            1 :   tree wrapped_parm = maybe_wrap_with_location (parm, loc);
    7302            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_parm));
    7303            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
    7304              : 
    7305              :   /* Verify that lvalue_kind of std::move on a parm isn't
    7306              :      affected by location wrappers.  */
    7307            1 :   tree rvalue_ref_of_parm = move (parm);
    7308            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
    7309            1 :   tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
    7310            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
    7311              : 
    7312              :   /* Verify lvalue_p.  */
    7313            1 :   ASSERT_FALSE (lvalue_p (int_cst));
    7314            1 :   ASSERT_FALSE (lvalue_p (wrapped_int_cst));
    7315            1 :   ASSERT_TRUE (lvalue_p (parm));
    7316            1 :   ASSERT_TRUE (lvalue_p (wrapped_parm));
    7317            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
    7318            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
    7319            1 : }
    7320              : 
    7321              : /* Run all of the selftests within this file.  */
    7322              : 
    7323              : void
    7324            1 : cp_tree_cc_tests ()
    7325              : {
    7326            1 :   test_lvalue_kind ();
    7327            1 : }
    7328              : 
    7329              : } // namespace selftest
    7330              : 
    7331              : #endif /* #if CHECKING_P */
    7332              : 
    7333              : 
    7334              : #include "gt-cp-tree.h"
        

Generated by: LCOV version 2.4-beta

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