LCOV - code coverage report
Current view: top level - gcc/cp - tree.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.3 % 3203 2988
Test Date: 2026-09-12 16:25:28 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   2725376185 : lvalue_kind (const_tree ref)
      63              : {
      64   2997668703 :   cp_lvalue_kind op1_lvalue_kind = clk_none;
      65   2997668703 :   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   2997668703 :   if (REFERENCE_REF_P (ref))
      72    256178285 :     return lvalue_kind (TREE_OPERAND (ref, 0));
      73              : 
      74   2741490418 :   if (TREE_TYPE (ref)
      75   2741490418 :       && TYPE_REF_P (TREE_TYPE (ref)))
      76              :     {
      77              :       /* unnamed rvalue references are rvalues */
      78    260342246 :       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    310914790 :           && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE)
      84              :         {
      85     50571519 :           op1_lvalue_kind = clk_rvalueref;
      86     50571519 :           if (implicit_rvalue_p (ref))
      87      8440326 :             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   2481148172 :   if (ref == current_class_ptr)
      96              :     return clk_none;
      97              : 
      98              :   /* Expressions with cv void type are prvalues.  */
      99   2478039828 :   if (TREE_TYPE (ref) && VOID_TYPE_P (TREE_TYPE (ref)))
     100              :     return clk_none;
     101              : 
     102   2477710675 :   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    312600840 :     case PREINCREMENT_EXPR:
     110    312600840 :     case PREDECREMENT_EXPR:
     111    312600840 :     case TRY_CATCH_EXPR:
     112    312600840 :     case REALPART_EXPR:
     113    312600840 :     case IMAGPART_EXPR:
     114    312600840 :     case VIEW_CONVERT_EXPR:
     115    312600840 :       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    312600840 :       if (op1_lvalue_kind == clk_class
     121    312600854 :           && !(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      3624381 :     case ARRAY_REF:
     128      3624381 :       {
     129      3624381 :         tree op1 = TREE_OPERAND (ref, 0);
     130      3624381 :         if (TREE_CODE (TREE_TYPE (op1)) == ARRAY_TYPE)
     131              :           {
     132      3135024 :             op1_lvalue_kind = lvalue_kind (op1);
     133      3135024 :             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    159748554 :     case COMPONENT_REF:
     159    159748554 :       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    159748527 :       op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0));
     171    159748527 :       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    159571310 :       if (!op1_lvalue_kind)
     178              :         ;
     179    159748503 :       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    159748404 :       else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
     185              :         /* This can be IDENTIFIER_NODE in a template.  */;
     186    152577297 :       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      6227391 :           op1_lvalue_kind &= ~clk_ordinary;
     191              :           /* The lvalue is for a bitfield.  */
     192      6227391 :           op1_lvalue_kind |= clk_bitfield;
     193              :         }
     194    146349906 :       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      3016463 :     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      3016463 :       if (! TREE_STATIC (ref))
     211              :         return clk_none;
     212              :       /* FALLTHRU */
     213    258480940 :     case VAR_DECL:
     214    258480940 :       if (VAR_P (ref) && DECL_HAS_VALUE_EXPR_P (ref))
     215       936073 :         return lvalue_kind (DECL_VALUE_EXPR (const_cast<tree> (ref)));
     216              : 
     217    367579835 :       if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
     218     14293627 :           && DECL_LANG_SPECIFIC (ref)
     219    258471811 :           && DECL_IN_AGGR_P (ref))
     220              :         return clk_none;
     221              : 
     222    257544867 :       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     11815185 :     case SCOPE_REF:
     236     11815185 :       gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     237     11815185 :       {
     238     11815185 :         tree op = TREE_OPERAND (ref, 1);
     239     11815185 :         if (TREE_CODE (op) == FIELD_DECL)
     240        18775 :           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     13190383 :     case COND_EXPR:
     256     13190383 :       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      1233142 :           gcc_assert (!type_dependent_expression_p (const_cast<tree> (ref)));
     265      1233142 :           goto default_;
     266              :         }
     267     11957241 :       {
     268     11957241 :         tree op1 = TREE_OPERAND (ref, 1);
     269     11957241 :         if (!op1) op1 = TREE_OPERAND (ref, 0);
     270     11957241 :         tree op2 = TREE_OPERAND (ref, 2);
     271     11957241 :         op1_lvalue_kind = lvalue_kind (op1);
     272     11957241 :         op2_lvalue_kind = lvalue_kind (op2);
     273     11957241 :         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       576750 :             if (op1_lvalue_kind && TREE_CODE (op2) == THROW_EXPR)
     279              :               op2_lvalue_kind = op1_lvalue_kind;
     280       576705 :             else if (op2_lvalue_kind && TREE_CODE (op1) == THROW_EXPR)
     281     11957726 :               op1_lvalue_kind = op2_lvalue_kind;
     282              :           }
     283              :       }
     284              :       break;
     285              : 
     286        97688 :     case MODOP_EXPR:
     287              :       /* We expect to see unlowered MODOP_EXPRs only during
     288              :          template processing.  */
     289        97688 :       gcc_assert (processing_template_decl);
     290        97688 :       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      3343685 :     case COMPOUND_EXPR:
     300      3343685 :       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    122776005 :     case CALL_EXPR:
     309              :       /* We can see calls outside of TARGET_EXPR in templates.  */
     310    122776005 :       if (CLASS_TYPE_P (TREE_TYPE (ref)))
     311              :         return clk_class;
     312              :       return clk_none;
     313              : 
     314    130322647 :     case FUNCTION_DECL:
     315              :       /* All functions (except non-static-member functions) are
     316              :          lvalues.  */
     317    130322647 :       return (DECL_IOBJ_MEMBER_FUNCTION_P (ref)
     318    130322647 :               ? clk_none : clk_ordinary);
     319              : 
     320         2174 :     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         2174 :       return lvalue_kind (BASELINK_FUNCTIONS (const_cast<tree> (ref)));
     326              : 
     327        35864 :     case PAREN_EXPR:
     328        35864 :       return lvalue_kind (TREE_OPERAND (ref, 0));
     329              : 
     330     17667372 :     case TEMPLATE_PARM_INDEX:
     331     17667372 :       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   1039584906 :     default:
     337   1039584906 :     default_:
     338   1039584906 :       if (!TREE_TYPE (ref))
     339              :         return clk_none;
     340   2079169812 :       if (CLASS_TYPE_P (TREE_TYPE (ref))
     341   2075942805 :           || 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     11957726 :   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      3637489 :   op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind;
     354              :   /* It's not an ordinary lvalue if it involves any other kind.  */
     355      3637489 :   if ((op1_lvalue_kind & ~clk_ordinary) != clk_none)
     356       189882 :     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       189882 :   if ((op1_lvalue_kind & (clk_rvalueref|clk_class))
     360        39203 :       && (op1_lvalue_kind & (clk_bitfield|clk_packed)))
     361   2725376185 :     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     45201579 : real_lvalue_p (const_tree ref)
     369              : {
     370     45201579 :   cp_lvalue_kind kind = lvalue_kind (ref);
     371     45201579 :   if (kind & (clk_rvalueref|clk_class))
     372              :     return clk_none;
     373              :   else
     374     43070970 :     return kind;
     375              : }
     376              : 
     377              : /* c-common wants us to return bool.  */
     378              : 
     379              : bool
     380     44331782 : lvalue_p (const_tree t)
     381              : {
     382     44331782 :   return real_lvalue_p (t);
     383              : }
     384              : 
     385              : /* This differs from lvalue_p in that xvalues are included.  */
     386              : 
     387              : bool
     388    155833901 : glvalue_p (const_tree ref)
     389              : {
     390    155833901 :   cp_lvalue_kind kind = lvalue_kind (ref);
     391    155833901 :   if (kind & clk_class)
     392              :     return false;
     393              :   else
     394    152525463 :     return (kind != clk_none);
     395              : }
     396              : 
     397              : /* This differs from glvalue_p in that class prvalues are included.  */
     398              : 
     399              : bool
     400   1309060000 : obvalue_p (const_tree ref)
     401              : {
     402   1309060000 :   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      7063421 : xvalue_p (const_tree ref)
     410              : {
     411      7063421 :   return (lvalue_kind (ref) & clk_rvalueref);
     412              : }
     413              : 
     414              : /* True if REF is a bit-field.  */
     415              : 
     416              : bool
     417    216178389 : bitfield_p (const_tree ref)
     418              : {
     419    216178389 :   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      5116294 : cp_stabilize_reference (tree ref)
     514              : {
     515      5116294 :   if (processing_template_decl)
     516              :     /* As in cp_save_expr.  */
     517              :     return ref;
     518              : 
     519      4188144 :   STRIP_ANY_LOCATION_WRAPPER (ref);
     520      4188144 :   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      4188120 :   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    586744694 : builtin_valid_in_constant_expr_p (const_tree decl)
     562              : {
     563    586744694 :   STRIP_ANY_LOCATION_WRAPPER (decl);
     564    586744694 :   if (TREE_CODE (decl) != FUNCTION_DECL)
     565              :     /* Not a function.  */
     566              :     return false;
     567    299826505 :   if (DECL_BUILT_IN_CLASS (decl) != BUILT_IN_NORMAL)
     568              :     {
     569    251168050 :       if (fndecl_built_in_p (decl, BUILT_IN_FRONTEND))
     570       277025 :         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     48658455 :   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     37723763 : build_target_expr (tree decl, tree value, tsubst_flags_t complain)
     618              : {
     619     37723763 :   tree t;
     620     37723763 :   tree type = TREE_TYPE (decl);
     621              : 
     622     37723763 :   value = mark_rvalue_use (value);
     623              : 
     624     37723763 :   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     37723763 :   if (CP_TYPE_CONST_NON_VOLATILE_P (type)
     635      2022336 :       && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     636      1896077 :       && !VOID_TYPE_P (TREE_TYPE (value))
     637      1168638 :       && !TYPE_HAS_MUTABLE_P (type)
     638     38892393 :       && reduced_constant_expression_p (value))
     639       348293 :     TREE_READONLY (decl) = true;
     640              : 
     641     37723763 :   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     36794260 :       t = cxx_maybe_build_cleanup (decl, complain);
     647     36794260 :       if (t == error_mark_node)
     648              :         return error_mark_node;
     649              :     }
     650              : 
     651     37723715 :   set_target_expr_eliding (value);
     652              : 
     653     37723715 :   t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE);
     654     37723715 :   if (location_t eloc = cp_expr_location (value))
     655     24765807 :     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     37723715 :   TREE_SIDE_EFFECTS (t) = 1;
     661              : 
     662     37723715 :   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     42522557 : build_local_temp (tree type)
     670              : {
     671     42522557 :   tree slot = build_decl (input_location,
     672              :                           VAR_DECL, NULL_TREE, type);
     673     42522557 :   DECL_ARTIFICIAL (slot) = 1;
     674     42522557 :   DECL_IGNORED_P (slot) = 1;
     675     42522557 :   DECL_CONTEXT (slot) = current_function_decl;
     676     42522557 :   layout_decl (slot, 0);
     677     42522557 :   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     55488312 : is_local_temp (tree decl)
     685              : {
     686     55488312 :   return (VAR_P (decl) && DECL_ARTIFICIAL (decl)
     687     56065294 :           && !TREE_STATIC (decl));
     688              : }
     689              : 
     690              : /* Set various status flags when building an AGGR_INIT_EXPR object T.  */
     691              : 
     692              : static void
     693     13338082 : process_aggr_init_operands (tree t)
     694              : {
     695     13338082 :   bool side_effects;
     696              : 
     697     13338082 :   side_effects = TREE_SIDE_EFFECTS (t);
     698     13338082 :   if (!side_effects)
     699              :     {
     700     13338082 :       int i, n;
     701     13338082 :       n = TREE_OPERAND_LENGTH (t);
     702     73146452 :       for (i = 1; i < n; i++)
     703              :         {
     704     50172446 :           tree op = TREE_OPERAND (t, i);
     705     50172446 :           if (op && TREE_SIDE_EFFECTS (op))
     706              :             {
     707              :               side_effects = 1;
     708              :               break;
     709              :             }
     710              :         }
     711              :     }
     712     13338082 :   TREE_SIDE_EFFECTS (t) = side_effects;
     713     13338082 : }
     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     13338082 : build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs,
     721              :                        tree *args)
     722              : {
     723     13338082 :   tree t;
     724     13338082 :   int i;
     725              : 
     726     13338082 :   t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3);
     727     13338082 :   TREE_TYPE (t) = return_type;
     728     13338082 :   AGGR_INIT_EXPR_FN (t) = fn;
     729     13338082 :   AGGR_INIT_EXPR_SLOT (t) = slot;
     730     38471985 :   for (i = 0; i < nargs; i++)
     731     25133903 :     AGGR_INIT_EXPR_ARG (t, i) = args[i];
     732     13338082 :   process_aggr_init_operands (t);
     733     13338082 :   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     41454735 : build_aggr_init_expr (tree type, tree init)
     748              : {
     749     41454735 :   tree fn;
     750     41454735 :   tree slot;
     751     41454735 :   tree rval;
     752     41454735 :   int is_ctor;
     753              : 
     754     41454735 :   gcc_assert (!VOID_TYPE_P (type));
     755              : 
     756              :   /* Don't build AGGR_INIT_EXPR in a template.  */
     757     41454735 :   if (processing_template_decl)
     758              :     return init;
     759              : 
     760     41347765 :   fn = cp_get_callee (init);
     761     41347765 :   if (fn == NULL_TREE)
     762     16721719 :     return convert (type, init);
     763              : 
     764     50500621 :   is_ctor = (TREE_CODE (fn) == ADDR_EXPR
     765     24577960 :              && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
     766     73781966 :              && 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     12536493 :   if (is_ctor || TREE_ADDRESSABLE (type))
     780              :     {
     781     13338082 :       slot = build_local_temp (type);
     782              : 
     783     13338082 :       if (TREE_CODE (init) == CALL_EXPR)
     784              :         {
     785     51213180 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     786     12803295 :                                         call_expr_nargs (init),
     787     12803295 :                                         CALL_EXPR_ARGP (init));
     788     12803295 :           AGGR_INIT_FROM_THUNK_P (rval)
     789     12803295 :             = CALL_FROM_THUNK_P (init);
     790              :         }
     791              :       else
     792              :         {
     793       534787 :           rval = build_aggr_init_array (void_type_node, fn, slot,
     794       534787 :                                         aggr_init_expr_nargs (init),
     795       534787 :                                         AGGR_INIT_EXPR_ARGP (init));
     796       534787 :           AGGR_INIT_FROM_THUNK_P (rval)
     797       534787 :             = AGGR_INIT_FROM_THUNK_P (init);
     798              :         }
     799     13338082 :       TREE_SIDE_EFFECTS (rval) = 1;
     800     13338082 :       AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
     801     13338082 :       TREE_NOTHROW (rval) = TREE_NOTHROW (init);
     802     13338082 :       CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
     803     13338082 :       CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
     804     13338082 :       CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
     805     13338082 :       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     35760035 : 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     35760035 :   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     35759541 :   tree rval = build_aggr_init_expr (type, init);
     834     35759541 :   tree slot;
     835              : 
     836     35759541 :   if (init == error_mark_node)
     837              :     return error_mark_node;
     838              : 
     839     35757424 :   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     35757418 :   if (abstract_virtuals_error (NULL_TREE, type, complain))
     845           33 :     return error_mark_node;
     846              : 
     847     35757385 :   if (TREE_CODE (rval) == AGGR_INIT_EXPR)
     848      7952236 :     slot = AGGR_INIT_EXPR_SLOT (rval);
     849     27805149 :   else if (TREE_CODE (rval) == CALL_EXPR
     850     16429174 :            || TREE_CODE (rval) == CONSTRUCTOR)
     851     11376367 :     slot = build_local_temp (type);
     852              :   else
     853              :     return rval;
     854              : 
     855     19328603 :   rval = build_target_expr (slot, rval, complain);
     856              : 
     857     19328603 :   if (rval != error_mark_node)
     858     19328603 :     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         1305 : build_vec_init_elt (tree type, tree init, tsubst_flags_t complain)
     876              : {
     877         1305 :   tree inner_type = strip_array_types (type);
     878              : 
     879         1305 :   if (integer_zerop (array_type_nelts_total (type))
     880         1305 :       || !CLASS_TYPE_P (inner_type))
     881              :     /* No interesting initialization to do.  */
     882          218 :     return integer_zero_node;
     883         1087 :   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         1024 :   if (init == void_type_node)
     897          195 :     return build_value_init (inner_type, complain);
     898              : 
     899          829 :   releasing_vec argvec;
     900          829 :   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          829 :   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          829 :   if (TREE_CODE (init) == TARGET_EXPR)
     915           32 :     init = TARGET_EXPR_INITIAL (init);
     916              : 
     917          829 :   return init;
     918          829 : }
     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         1323 : build_vec_init_expr (tree type, tree init, tsubst_flags_t complain)
     926              : {
     927         1323 :   if (tree vi = get_vec_init_expr (init))
     928              :     return vi;
     929              : 
     930         1307 :   tree elt_init;
     931          674 :   if (init && TREE_CODE (init) == CONSTRUCTOR
     932         1538 :       && !BRACE_ENCLOSED_INITIALIZER_P (init))
     933              :     /* We built any needed constructor calls in digest_init.  */
     934              :     elt_init = init;
     935              :   else
     936         1303 :     elt_init = build_vec_init_elt (type, init, complain);
     937              : 
     938         1307 :   bool value_init = false;
     939         1307 :   if (init == void_type_node)
     940              :     {
     941          228 :       value_init = true;
     942          228 :       init = NULL_TREE;
     943              :     }
     944              : 
     945         1307 :   tree slot = build_local_temp (type);
     946         1307 :   init = build2 (VEC_INIT_EXPR, type, slot, init);
     947         1307 :   TREE_SIDE_EFFECTS (init) = true;
     948         1307 :   SET_EXPR_LOCATION (init, input_location);
     949              : 
     950         1307 :   if (cxx_dialect >= cxx11)
     951              :     {
     952         1221 :       bool cx = potential_constant_expression (elt_init);
     953         1221 :       if (BRACE_ENCLOSED_INITIALIZER_P (init))
     954            0 :         cx &= potential_constant_expression (init);
     955         1221 :       VEC_INIT_EXPR_IS_CONSTEXPR (init) = cx;
     956              :     }
     957         1307 :   VEC_INIT_EXPR_VALUE_INIT (init) = value_init;
     958              : 
     959         1307 :   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         1125 : expand_vec_init_expr (tree target, tree vec_init, tsubst_flags_t complain,
     967              :                       vec<tree,va_gc> **flags)
     968              : {
     969         1125 :   iloc_sentinel ils = EXPR_LOCATION (vec_init);
     970              : 
     971         1125 :   if (!target)
     972            0 :     target = VEC_INIT_EXPR_SLOT (vec_init);
     973         1125 :   tree init = VEC_INIT_EXPR_INIT (vec_init);
     974         1125 :   int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
     975         3375 :   return build_vec_init (target, NULL_TREE, init,
     976         1125 :                          VEC_INIT_EXPR_VALUE_INIT (vec_init),
     977         1125 :                          from_array, complain, flags);
     978         1125 : }
     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      9977561 : build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain)
    1009              : {
    1010      9977561 :   gcc_assert (!VOID_TYPE_P (type));
    1011      9977561 :   gcc_assert (!VOID_TYPE_P (TREE_TYPE (init)));
    1012              : 
    1013      9977561 :   if (TREE_CODE (init) == TARGET_EXPR
    1014      8799232 :       || init == error_mark_node)
    1015              :     return init;
    1016      6478306 :   else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
    1017        57496 :            && TREE_CODE (init) != COND_EXPR
    1018              :            && TREE_CODE (init) != CONSTRUCTOR
    1019              :            && TREE_CODE (init) != VA_ARG_EXPR
    1020      8798973 :            && 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      8798973 :   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     17806778 : force_target_expr (tree type, tree init, tsubst_flags_t complain)
    1039              : {
    1040     17806778 :   tree slot;
    1041              : 
    1042     17806778 :   gcc_assert (!VOID_TYPE_P (type));
    1043              : 
    1044     17806778 :   slot = build_local_temp (type);
    1045     17806778 :   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      8040401 : get_target_expr (tree init, tsubst_flags_t complain /* = tf_warning_or_error */)
    1052              : {
    1053      8040401 :   if (TREE_CODE (init) == AGGR_INIT_EXPR)
    1054       587955 :     return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain);
    1055      7452446 :   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      7452019 :       init = convert_bitfield_to_declared_type (init);
    1060      7452019 :       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      3120935 : get_internal_target_expr (tree init)
    1075              : {
    1076      3120935 :   init = convert_bitfield_to_declared_type (init);
    1077      3120935 :   tree t = force_target_expr (TREE_TYPE (init), init, tf_warning_or_error);
    1078      3120935 :   TARGET_EXPR_INTERNAL_P (t) = true;
    1079      3120935 :   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   1100999584 : convert_bitfield_to_declared_type (tree expr)
    1088              : {
    1089   1100999584 :   tree bitfield_type;
    1090              : 
    1091   1100999584 :   bitfield_type = is_bitfield_expr_with_lowered_type (expr);
    1092   1100999584 :   if (bitfield_type)
    1093       653073 :     expr = convert_to_integer_nofold (TYPE_MAIN_VARIANT (bitfield_type),
    1094              :                                       expr);
    1095   1100999584 :   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    195079032 : rvalue (tree expr)
    1103              : {
    1104    195079032 :   tree type;
    1105              : 
    1106    195079032 :   if (error_operand_p (expr))
    1107              :     return expr;
    1108              : 
    1109    195078696 :   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    195078696 :   type = TREE_TYPE (expr);
    1115    195078696 :   if (!CLASS_TYPE_P (type) && TREE_CODE (type) != ARRAY_TYPE
    1116    386830294 :       && cv_qualified_p (type))
    1117     38127695 :     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    195078696 :   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     10575885 :       gcc_checking_assert (!CLASS_TYPE_P (type));
    1126     10575885 :       expr = build1 (NON_LVALUE_EXPR, type, expr);
    1127              :     }
    1128    184502811 :   else if (type != TREE_TYPE (expr))
    1129     37781744 :     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     39435583 : cplus_array_hasher::hash (tree t)
    1153              : {
    1154     39435583 :   hashval_t hash;
    1155              : 
    1156     39435583 :   hash = TYPE_UID (TREE_TYPE (t));
    1157     39435583 :   if (TYPE_DOMAIN (t))
    1158     37361959 :     hash ^= TYPE_UID (TYPE_DOMAIN (t));
    1159     39435583 :   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     51335308 : cplus_array_hasher::equal (tree t1, cplus_array_info *t2)
    1167              : {
    1168     54207933 :   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      5575624 : build_min_array_type (tree elt_type, tree index_type)
    1179              : {
    1180      5575624 :   tree t = cxx_make_type (ARRAY_TYPE);
    1181      5575624 :   TREE_TYPE (t) = elt_type;
    1182      5575624 :   TYPE_DOMAIN (t) = index_type;
    1183      5575624 :   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      5575624 : 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      5575624 :   if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
    1194      5575624 :       || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
    1195      1402173 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1196      4173451 :   else if (TYPE_CANONICAL (elt_type) != elt_type
    1197      4173451 :            || (index_type && TYPE_CANONICAL (index_type) != index_type))
    1198      1236340 :     TYPE_CANONICAL (t)
    1199      3238052 :       = build_cplus_array_type (TYPE_CANONICAL (elt_type),
    1200              :                                 index_type
    1201       765372 :                                 ? TYPE_CANONICAL (index_type) : index_type,
    1202              :                                 dep);
    1203              :   else
    1204      2937111 :     TYPE_CANONICAL (t) = t;
    1205      5575624 : }
    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     68831603 : build_cplus_array_type (tree elt_type, tree index_type, int dependent)
    1214              : {
    1215     68831603 :   tree t;
    1216              : 
    1217     68831603 :   if (elt_type == error_mark_node || index_type == error_mark_node)
    1218              :     return error_mark_node;
    1219              : 
    1220     68831600 :   if (dependent < 0)
    1221     71767896 :     dependent = (uses_template_parms (elt_type)
    1222     35883948 :                  || (index_type && uses_template_parms (index_type)));
    1223              : 
    1224     68831600 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1225              :     /* Start with an array of the TYPE_MAIN_VARIANT.  */
    1226     29247897 :     t = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type),
    1227              :                                 index_type, dependent);
    1228     39583703 :   else if (dependent)
    1229              :     {
    1230              :       /* Since type_hash_canon calls layout_type, we need to use our own
    1231              :          hash table.  */
    1232      4853159 :       cplus_array_info cai;
    1233      4853159 :       hashval_t hash;
    1234              : 
    1235      4853159 :       if (cplus_array_htab == NULL)
    1236        18338 :         cplus_array_htab = hash_table<cplus_array_hasher>::create_ggc (61);
    1237              : 
    1238      4853159 :       hash = TYPE_UID (elt_type);
    1239      4853159 :       if (index_type)
    1240      2625852 :         hash ^= TYPE_UID (index_type);
    1241      4853159 :       cai.type = elt_type;
    1242      4853159 :       cai.domain = index_type;
    1243              : 
    1244      4853159 :       tree *e = cplus_array_htab->find_slot_with_hash (&cai, hash, INSERT);
    1245      4853159 :       if (*e)
    1246              :         /* We have found the type: we're done.  */
    1247      2803079 :         return (tree) *e;
    1248              :       else
    1249              :         {
    1250              :           /* Build a new array type.  */
    1251      2050080 :           t = build_min_array_type (elt_type, index_type);
    1252              : 
    1253              :           /* Store it in the hash table. */
    1254      2050080 :           *e = t;
    1255              : 
    1256              :           /* Set the canonical type for this new node.  */
    1257      2050080 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1258              : 
    1259              :           /* Mark it as dependent now, this saves time later.  */
    1260      2050080 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1261      2050080 :           TYPE_DEPENDENT_P (t) = true;
    1262              :         }
    1263              :     }
    1264              :   else
    1265              :     {
    1266     34730544 :       bool typeless_storage = is_byte_access_type (elt_type);
    1267     34730544 :       t = build_array_type (elt_type, index_type, typeless_storage);
    1268              : 
    1269              :       /* Mark as non-dependenty now, this will save time later.  */
    1270     34730544 :       TYPE_DEPENDENT_P_VALID (t) = true;
    1271              :     }
    1272              : 
    1273              :   /* Now check whether we already have this array variant.  */
    1274     66028521 :   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
    1275              :     {
    1276              :       tree m = t;
    1277     59442638 :       for (t = m; t; t = TYPE_NEXT_VARIANT (t))
    1278     55917094 :         if (TREE_TYPE (t) == elt_type
    1279     25732605 :             && TYPE_NAME (t) == NULL_TREE
    1280     25722356 :             && TYPE_ATTRIBUTES (t) == NULL_TREE
    1281     25722356 :             && (!TYPE_USER_ALIGN (t)
    1282        18725 :                 || (TYPE_USER_ALIGN (elt_type)
    1283        18722 :                     && TYPE_ALIGN (t) == TYPE_ALIGN (elt_type)))
    1284     25722353 :             && !TREE_DEPRECATED (t)
    1285     81639447 :             && !TREE_UNAVAILABLE (t))
    1286              :           break;
    1287     29247897 :       if (!t)
    1288              :         {
    1289      3525544 :           t = build_min_array_type (elt_type, index_type);
    1290              :           /* Mark dependency now, this saves time later.  */
    1291      3525544 :           TYPE_DEPENDENT_P_VALID (t) = true;
    1292      3525544 :           TYPE_DEPENDENT_P (t) = dependent;
    1293      3525544 :           set_array_type_canon (t, elt_type, index_type, dependent);
    1294      3525544 :           if (!dependent)
    1295              :             {
    1296      2918903 :               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      2918903 :               TYPE_SIZE (t) = TYPE_SIZE (m);
    1301      2918903 :               TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
    1302      2918903 :               TYPE_TYPELESS_STORAGE (t) = TYPE_TYPELESS_STORAGE (m);
    1303              :             }
    1304              : 
    1305      3525544 :           TYPE_MAIN_VARIANT (t) = m;
    1306      3525544 :           TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
    1307      3525544 :           TYPE_NEXT_VARIANT (m) = t;
    1308              :         }
    1309              :     }
    1310              : 
    1311              :   /* Avoid spurious warnings with VLAs (c++/54583).  */
    1312     66028521 :   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    132057042 :   bool needs_ctor = (TYPE_NEEDS_CONSTRUCTING (t)
    1318     66028521 :                      = TYPE_NEEDS_CONSTRUCTING (elt_type));
    1319    132057042 :   bool needs_dtor = (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1320     66028521 :                      = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type));
    1321              : 
    1322     63203901 :   if (!dependent && t == TYPE_MAIN_VARIANT (t)
    1323    100759065 :       && !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      2923204 :       layout_type (t);
    1329      4245480 :       for (tree v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
    1330              :         {
    1331      1322276 :           TYPE_NEEDS_CONSTRUCTING (v) = needs_ctor;
    1332      1322276 :           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      2286333 : build_array_of_n_type (tree elt, unsigned HOST_WIDE_INT n)
    1343              : {
    1344      2286333 :   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      7642564 : array_of_unknown_bound_p (const_tree t)
    1351              : {
    1352      7642564 :   return (TREE_CODE (t) == ARRAY_TYPE
    1353      7642564 :           && !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       608564 : array_of_runtime_bound_p (tree t)
    1363              : {
    1364       608564 :   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     44859056 : vla_type_p (tree t)
    1380              : {
    1381     45684059 :   for (; t && TREE_CODE (t) == ARRAY_TYPE;
    1382       825003 :        t = TREE_TYPE (t))
    1383       825182 :     if (tree dom = TYPE_DOMAIN (t))
    1384              :       {
    1385       825118 :         tree max = TYPE_MAX_VALUE (dom);
    1386       825118 :         if (!potential_rvalue_constant_expression (max)
    1387       825118 :             || (!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    661611903 : cp_build_reference_type_for_mode (tree to_type, machine_mode mode, bool rval)
    1401              : {
    1402    661611903 :   tree lvalue_ref, t;
    1403              : 
    1404    661611903 :   if (to_type == error_mark_node)
    1405              :     return error_mark_node;
    1406              : 
    1407    661611898 :   if (TYPE_REF_P (to_type))
    1408              :     {
    1409         2132 :       rval = rval && TYPE_REF_IS_RVALUE (to_type);
    1410         2132 :       to_type = TREE_TYPE (to_type);
    1411              :     }
    1412              : 
    1413    661611898 :   lvalue_ref = build_reference_type_for_mode (to_type, mode, false);
    1414              : 
    1415    661611898 :   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    114310653 :   for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); )
    1427     84975400 :     if (TYPE_REF_IS_RVALUE (t))
    1428              :       return t;
    1429              : 
    1430     29335253 :   t = build_distinct_type_copy (lvalue_ref);
    1431              : 
    1432     29335253 :   TYPE_REF_IS_RVALUE (t) = true;
    1433     29335253 :   TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref);
    1434     29335253 :   TYPE_NEXT_REF_TO (lvalue_ref) = t;
    1435              : 
    1436     29335253 :   if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
    1437      1030834 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
    1438     28304419 :   else if (TYPE_CANONICAL (to_type) != to_type)
    1439     16106695 :     TYPE_CANONICAL (t)
    1440     32213390 :       = cp_build_reference_type_for_mode (TYPE_CANONICAL (to_type), mode, rval);
    1441              :   else
    1442     12197724 :     TYPE_CANONICAL (t) = t;
    1443              : 
    1444     29335253 :   layout_type (t);
    1445              : 
    1446     29335253 :   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    542485751 : cp_build_reference_type (tree to_type, bool rval)
    1456              : {
    1457    542485751 :   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      2212254 : move (tree expr)
    1464              : {
    1465      2212254 :   tree type = TREE_TYPE (expr);
    1466      2212254 :   gcc_assert (!TYPE_REF_P (type));
    1467      2212254 :   if (xvalue_p (expr))
    1468              :     return expr;
    1469      2212022 :   type = cp_build_reference_type (type, /*rval*/true);
    1470      2212022 :   return build_static_cast (input_location, type, expr,
    1471      2212022 :                             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     27886937 : c_build_qualified_type (tree type, int type_quals, tree /* orig_qual_type */,
    1479              :                         size_t /* orig_qual_indirect */)
    1480              : {
    1481     27886937 :   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  19174425492 : cp_build_qualified_type (tree type, int type_quals,
    1507              :                          tsubst_flags_t complain /* = tf_warning_or_error */)
    1508              : {
    1509  19174425492 :   tree result;
    1510  19174425492 :   int bad_quals = TYPE_UNQUALIFIED;
    1511              : 
    1512  19174425492 :   if (type == error_mark_node)
    1513              :     return type;
    1514              : 
    1515  19137914755 :   if (type_quals == cp_type_quals (type))
    1516              :     return type;
    1517              : 
    1518   3290367420 :   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     34020710 :       tree t;
    1523     34020710 :       tree element_type
    1524     34020710 :         = cp_build_qualified_type (TREE_TYPE (type), type_quals, complain);
    1525              : 
    1526     34020710 :       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     65088659 :       for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    1532     38161058 :         if (TREE_TYPE (t) == element_type
    1533      7636913 :             && TYPE_NAME (t) == TYPE_NAME (type)
    1534      7093109 :             && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
    1535     45254167 :             && attribute_list_equal (TYPE_ATTRIBUTES (t),
    1536      7093109 :                                      TYPE_ATTRIBUTES (type)))
    1537              :           break;
    1538              : 
    1539     34020710 :       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     26927601 :           t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
    1545     26927601 :                                       TYPE_DEPENDENT_P_VALID (type)
    1546       570624 :                                       ? int (TYPE_DEPENDENT_P (type)) : -1);
    1547              : 
    1548              :           /* Keep the typedef name.  */
    1549     26927601 :           if (TYPE_NAME (t) != TYPE_NAME (type))
    1550              :             {
    1551        14379 :               t = build_variant_type_copy (t);
    1552        14379 :               TYPE_NAME (t) = TYPE_NAME (type);
    1553        14379 :               SET_TYPE_ALIGN (t, TYPE_ALIGN (type));
    1554        14379 :               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     68041420 :       TYPE_NEEDS_CONSTRUCTING (t)
    1566     34020710 :         = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type));
    1567     68041420 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
    1568     34020710 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
    1569     34020710 :       return t;
    1570              :     }
    1571   3256346710 :   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   3256346703 :   if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)
    1589   1034184741 :       && (TYPE_REF_P (type)
    1590   1033753103 :           || FUNC_OR_METHOD_TYPE_P (type)))
    1591              :     {
    1592       432453 :       if (TYPE_REF_P (type)
    1593       432453 :           && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))
    1594              :         bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1595       432453 :       type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);
    1596              :     }
    1597              : 
    1598              :   /* But preserve any function-cv-quals on a FUNCTION_TYPE.  */
    1599   3256346703 :   if (TREE_CODE (type) == FUNCTION_TYPE)
    1600          818 :     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   3256346703 :   if ((type_quals & TYPE_QUAL_RESTRICT)
    1605      9006179 :       && TREE_CODE (type) != TEMPLATE_TYPE_PARM
    1606      9006142 :       && TREE_CODE (type) != TYPENAME_TYPE
    1607      9006136 :       && !INDIRECT_TYPE_P (type))
    1608              :     {
    1609           25 :       bad_quals |= TYPE_QUAL_RESTRICT;
    1610           25 :       type_quals &= ~TYPE_QUAL_RESTRICT;
    1611              :     }
    1612              : 
    1613   3256346703 :   if (bad_quals == TYPE_UNQUALIFIED
    1614       294722 :       || (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   3256346703 :   result = build_qualified_type (type, type_quals);
    1627              : 
    1628   3256346703 :   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    278352101 : cp_build_function_type (tree value_type, tree arg_types)
    1638              : {
    1639    312196792 :   return build_function_type (value_type, arg_types,
    1640    278352101 :                               cxx_dialect >= cxx26
    1641    278352101 :                               && arg_types == NULL_TREE);
    1642              : }
    1643              : 
    1644              : /* Return TYPE with const and volatile removed.  */
    1645              : 
    1646              : tree
    1647   1798123063 : cv_unqualified (tree type)
    1648              : {
    1649   1798123063 :   int quals;
    1650              : 
    1651   1798123063 :   if (type == error_mark_node)
    1652              :     return type;
    1653              : 
    1654   1798122818 :   quals = cp_type_quals (type);
    1655   1798122818 :   quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE);
    1656   1798122818 :   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      9870965 : apply_identity_attributes (tree result, tree attribs, bool *remove_attributes)
    1665              : {
    1666      9870965 :   tree first_ident = NULL_TREE;
    1667      9870965 :   tree new_attribs = NULL_TREE;
    1668      9870965 :   tree *p = &new_attribs;
    1669              : 
    1670      9870965 :   if (OVERLOAD_TYPE_P (result))
    1671              :     {
    1672              :       /* On classes and enums all attributes are ingrained.  */
    1673      9869974 :       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   3049936959 : strip_typedefs (tree t, bool *remove_attributes /* = NULL */,
    1742              :                 unsigned int flags /* = 0 */)
    1743              : {
    1744   3049936959 :   tree result = NULL, type = NULL, t0 = NULL;
    1745              : 
    1746   3049936959 :   if (!t || t == error_mark_node)
    1747              :     return t;
    1748              : 
    1749   3009248394 :   if (!TYPE_P (t))
    1750    205100836 :     return strip_typedefs_expr (t, remove_attributes, flags);
    1751              : 
    1752   2804147558 :   if (t == TYPE_CANONICAL (t))
    1753              :     return t;
    1754              : 
    1755   1092140309 :   if (typedef_variant_p (t))
    1756              :     {
    1757    364936682 :       if ((flags & STF_USER_VISIBLE)
    1758    364936682 :           && !user_facing_original_type_p (t))
    1759              :         return t;
    1760              : 
    1761    364936554 :       if ((flags & STF_KEEP_INJ_CLASS_NAME)
    1762        35824 :           && CLASS_TYPE_P (t)
    1763    364946437 :           && DECL_SELF_REFERENCE_P (TYPE_NAME (t)))
    1764              :         return t;
    1765              : 
    1766    364936553 :       if (dependent_opaque_alias_p (t))
    1767              :         return t;
    1768              : 
    1769    364931683 :       if (alias_template_specialization_p (t, nt_opaque))
    1770              :         {
    1771    105218575 :           if (dependent_alias_template_spec_p (t, nt_opaque)
    1772    105218575 :               && !(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    259713108 :         flags |= STF_STRIP_DEPENDENT;
    1782              : 
    1783    349741526 :       result = strip_typedefs (DECL_ORIGINAL_TYPE (TYPE_NAME (t)),
    1784              :                                remove_attributes, flags);
    1785    349741526 :       goto stripped;
    1786              :     }
    1787              : 
    1788    727203627 :   switch (TREE_CODE (t))
    1789              :     {
    1790     10975113 :     case POINTER_TYPE:
    1791     10975113 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1792     10975113 :       result = build_pointer_type_for_mode (type, TYPE_MODE (t), false);
    1793     10975113 :       break;
    1794    103019457 :     case REFERENCE_TYPE:
    1795    103019457 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1796    103019457 :       result = cp_build_reference_type_for_mode (type, TYPE_MODE (t), TYPE_REF_IS_RVALUE (t));
    1797    103019457 :       break;
    1798       331125 :     case OFFSET_TYPE:
    1799       331125 :       t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t), remove_attributes, flags);
    1800       331125 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1801       331125 :       result = build_offset_type (t0, type);
    1802       331125 :       break;
    1803     26367808 :     case RECORD_TYPE:
    1804     26367808 :       if (TYPE_PTRMEMFUNC_P (t))
    1805              :         {
    1806      1594539 :           t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t),
    1807              :                                remove_attributes, flags);
    1808      1594539 :           result = build_ptrmemfunc_type (t0);
    1809              :         }
    1810              :       break;
    1811      1871321 :     case ARRAY_TYPE:
    1812      1871321 :       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1813      1871321 :       t0  = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
    1814      1871321 :       gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
    1815              :                            || !dependent_type_p (t));
    1816      1871321 :       result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
    1817      1871321 :       break;
    1818      8087383 :     case FUNCTION_TYPE:
    1819      8087383 :     case METHOD_TYPE:
    1820      8087383 :       {
    1821      8087383 :         tree arg_types = NULL, arg_node, arg_node2, arg_type;
    1822      8087383 :         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      8087383 :         bool is_variant = typedef_variant_p (t);
    1830      8087383 :         if (remove_attributes
    1831      8087383 :             && (TYPE_ATTRIBUTES (t) || TYPE_USER_ALIGN (t)))
    1832              :           is_variant = true;
    1833              : 
    1834      8087383 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    1835      8087383 :         tree canon_spec = (flag_noexcept_type
    1836      8076554 :                            ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t))
    1837      8087383 :                            : NULL_TREE);
    1838     10720526 :         changed = (type != TREE_TYPE (t) || is_variant
    1839     10720323 :                    || TYPE_RAISES_EXCEPTIONS (t) != canon_spec);
    1840              : 
    1841      8087383 :         for (arg_node = TYPE_ARG_TYPES (t);
    1842     12496779 :              arg_node;
    1843      4409396 :              arg_node = TREE_CHAIN (arg_node))
    1844              :           {
    1845     11683882 :             if (arg_node == void_list_node)
    1846              :               break;
    1847      4409396 :             arg_type = strip_typedefs (TREE_VALUE (arg_node),
    1848              :                                        remove_attributes, flags);
    1849      4409396 :             gcc_assert (arg_type);
    1850      4409396 :             if (arg_type == TREE_VALUE (arg_node) && !changed)
    1851      4146227 :               continue;
    1852              : 
    1853       263169 :             if (!changed)
    1854              :               {
    1855        40426 :                 changed = true;
    1856        40426 :                 for (arg_node2 = TYPE_ARG_TYPES (t);
    1857        51285 :                      arg_node2 != arg_node;
    1858        10859 :                      arg_node2 = TREE_CHAIN (arg_node2))
    1859        10859 :                   arg_types
    1860        10859 :                     = tree_cons (TREE_PURPOSE (arg_node2),
    1861        10859 :                                  TREE_VALUE (arg_node2), arg_types);
    1862              :               }
    1863              : 
    1864       263169 :             arg_types
    1865       263169 :               = tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types);
    1866              :           }
    1867              : 
    1868      8087383 :         if (!changed)
    1869              :           return t;
    1870              : 
    1871      5496312 :         if (arg_types)
    1872        62809 :           arg_types = nreverse (arg_types);
    1873              : 
    1874              :         /* A list of parameters not ending with an ellipsis
    1875              :            must end with void_list_node.  */
    1876      5496312 :         if (arg_node)
    1877      5496271 :           arg_types = chainon (arg_types, void_list_node);
    1878              : 
    1879      5496312 :         if (TREE_CODE (t) == METHOD_TYPE)
    1880              :           {
    1881        28597 :             tree class_type = TREE_TYPE (TREE_VALUE (arg_types));
    1882        28597 :             gcc_assert (class_type);
    1883        28597 :             result =
    1884        28597 :               build_method_type_directly (class_type, type,
    1885        28597 :                                           TREE_CHAIN (arg_types));
    1886              :           }
    1887              :         else
    1888              :           {
    1889     16403145 :             result = build_function_type (type, arg_types,
    1890      5467715 :                                           TYPE_NO_NAMED_ARGS_STDARG_P (t));
    1891      5467715 :             result = apply_memfn_quals (result, type_memfn_quals (t));
    1892              :           }
    1893              : 
    1894     16488936 :         result = build_cp_fntype_variant (result,
    1895              :                                           type_memfn_rqual (t), canon_spec,
    1896      5496312 :                                           TYPE_HAS_LATE_RETURN_TYPE (t));
    1897              :       }
    1898      5496312 :       break;
    1899     79486602 :     case TYPENAME_TYPE:
    1900     79486602 :       {
    1901     79486602 :         bool changed = false;
    1902     79486602 :         tree fullname = TYPENAME_TYPE_FULLNAME (t);
    1903     79486602 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
    1904     79486602 :             && TREE_OPERAND (fullname, 1))
    1905              :           {
    1906      4965281 :             tree args = TREE_OPERAND (fullname, 1);
    1907      4965281 :             tree new_args = copy_node (args);
    1908     18740772 :             for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
    1909              :               {
    1910      8810210 :                 tree arg = TREE_VEC_ELT (args, i);
    1911      8810210 :                 tree strip_arg = strip_typedefs (arg, remove_attributes, flags);
    1912      8810210 :                 TREE_VEC_ELT (new_args, i) = strip_arg;
    1913      8810210 :                 if (strip_arg != arg)
    1914       257396 :                   changed = true;
    1915              :               }
    1916      4965281 :             if (changed)
    1917              :               {
    1918       257396 :                 NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_args)
    1919       257396 :                   = NON_DEFAULT_TEMPLATE_ARGS_COUNT (args);
    1920       257396 :                 fullname
    1921       257396 :                   = lookup_template_function (TREE_OPERAND (fullname, 0),
    1922              :                                               new_args);
    1923              :               }
    1924              :             else
    1925      4707885 :               ggc_free (new_args);
    1926              :           }
    1927     79486602 :         tree ctx = strip_typedefs (TYPE_CONTEXT (t), remove_attributes, flags);
    1928     79486602 :         if (!changed && ctx == TYPE_CONTEXT (t) && !typedef_variant_p (t))
    1929              :           return t;
    1930      4865685 :         tree name = fullname;
    1931      4865685 :         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
    1932       281938 :           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      4865685 :         result = build_typename_type (ctx, name, fullname, typename_type);
    1936              :       }
    1937      4865685 :       break;
    1938     13677848 :     case DECLTYPE_TYPE:
    1939     13677848 :       result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t),
    1940              :                                     remove_attributes, flags);
    1941     13677848 :       if (result == DECLTYPE_TYPE_EXPR (t))
    1942              :         result = NULL_TREE;
    1943              :       else
    1944       382614 :         result = (finish_decltype_type
    1945       382614 :                   (result,
    1946       382614 :                    DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t),
    1947              :                    tf_none));
    1948              :       break;
    1949       860919 :     case TRAIT_TYPE:
    1950       860919 :       {
    1951       860919 :         tree type1 = strip_typedefs (TRAIT_TYPE_TYPE1 (t),
    1952              :                                      remove_attributes, flags);
    1953       860919 :         tree type2 = strip_typedefs (TRAIT_TYPE_TYPE2 (t),
    1954              :                                      remove_attributes, flags);
    1955       860919 :         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     25165590 :     case TYPE_PACK_EXPANSION:
    1963     25165590 :       {
    1964     25165590 :         tree pat = PACK_EXPANSION_PATTERN (t);
    1965     25165590 :         if (TYPE_P (pat))
    1966              :           {
    1967     25165590 :             type = strip_typedefs (pat, remove_attributes, flags);
    1968     25165590 :             if (type != pat)
    1969              :               {
    1970       310293 :                 result = build_distinct_type_copy (t);
    1971       310293 :                 PACK_EXPANSION_PATTERN (result) = type;
    1972              :               }
    1973              :           }
    1974              :       }
    1975              :       break;
    1976              :     default:
    1977              :       break;
    1978              :     }
    1979              : 
    1980    128846459 :   if (!result)
    1981    521145180 :     result = TYPE_MAIN_VARIANT (t);
    1982              : 
    1983    128846459 : 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    999733165 :   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    999733159 :       if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result)
    1996    999733159 :           || 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    999733159 :       if (TYPE_ATTRIBUTES (t))
    2012              :         {
    2013      9881128 :           if (remove_attributes)
    2014      9870965 :             result = apply_identity_attributes (result, TYPE_ATTRIBUTES (t),
    2015              :                                                 remove_attributes);
    2016              :           else
    2017        10163 :             result = cp_build_type_attribute_variant (result,
    2018        10163 :                                                       TYPE_ATTRIBUTES (t));
    2019              :         }
    2020              :     }
    2021              : 
    2022    999733165 :   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    393482421 : strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
    2038              : {
    2039    393482421 :   unsigned i,n;
    2040    393482421 :   tree r, type, *ops;
    2041    393482421 :   enum tree_code code;
    2042              : 
    2043    393482421 :   if (t == NULL_TREE || t == error_mark_node)
    2044              :     return t;
    2045              : 
    2046    393482421 :   STRIP_ANY_LOCATION_WRAPPER (t);
    2047              : 
    2048    393482421 :   if (DECL_P (t) || CONSTANT_CLASS_P (t))
    2049              :     return t;
    2050              : 
    2051    218584177 :   code = TREE_CODE (t);
    2052    218584177 :   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      2445880 :     case TRAIT_EXPR:
    2063      2445880 :       {
    2064      2445880 :         tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t),
    2065              :                                      remove_attributes, flags);
    2066      2445880 :         tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t),
    2067              :                                      remove_attributes, flags);
    2068      2445880 :         if (type1 == TRAIT_EXPR_TYPE1 (t)
    2069      2445880 :             && type2 == TRAIT_EXPR_TYPE2 (t))
    2070              :           return t;
    2071        55041 :         r = copy_node (t);
    2072        55041 :         TRAIT_EXPR_TYPE1 (r) = type1;
    2073        55041 :         TRAIT_EXPR_TYPE2 (r) = type2;
    2074        55041 :         return r;
    2075              :       }
    2076              : 
    2077      1036003 :     case TREE_LIST:
    2078      1036003 :       {
    2079      1036003 :         bool changed = false;
    2080      1036003 :         auto_vec<tree_pair, 4> vec;
    2081      1036003 :         r = t;
    2082      2213352 :         for (; t; t = TREE_CHAIN (t))
    2083              :           {
    2084      1177349 :             tree purpose = strip_typedefs (TREE_PURPOSE (t),
    2085      1177349 :                                            remove_attributes, flags);
    2086      1177349 :             tree value = strip_typedefs (TREE_VALUE (t),
    2087      1177349 :                                          remove_attributes, flags);
    2088      1177349 :             if (purpose != TREE_PURPOSE (t) || value != TREE_VALUE (t))
    2089              :               changed = true;
    2090      1177349 :             vec.safe_push ({purpose, value});
    2091              :           }
    2092      1036003 :         if (changed)
    2093              :           {
    2094       248836 :             r = NULL_TREE;
    2095       813809 :             for (int i = vec.length () - 1; i >= 0; i--)
    2096       316137 :               r = tree_cons (vec[i].first, vec[i].second, r);
    2097              :           }
    2098      1036003 :         return r;
    2099      1036003 :       }
    2100              : 
    2101     21387892 :     case TREE_VEC:
    2102     21387892 :       {
    2103     21387892 :         bool changed = false;
    2104     21387892 :         releasing_vec vec;
    2105     21387892 :         n = TREE_VEC_LENGTH (t);
    2106     21387892 :         vec_safe_reserve (vec, n);
    2107     67332864 :         for (i = 0; i < n; ++i)
    2108              :           {
    2109     24557080 :             tree op = strip_typedefs (TREE_VEC_ELT (t, i),
    2110     24557080 :                                       remove_attributes, flags);
    2111     24557080 :             vec->quick_push (op);
    2112     24557080 :             if (op != TREE_VEC_ELT (t, i))
    2113       218684 :               changed = true;
    2114              :           }
    2115     21387892 :         if (changed)
    2116              :           {
    2117       218684 :             r = copy_node (t);
    2118       676545 :             for (i = 0; i < n; ++i)
    2119       239177 :               TREE_VEC_ELT (r, i) = (*vec)[i];
    2120       437368 :             NON_DEFAULT_TEMPLATE_ARGS_COUNT (r)
    2121       437368 :               = NON_DEFAULT_TEMPLATE_ARGS_COUNT (t);
    2122              :           }
    2123              :         else
    2124              :           r = t;
    2125     21387892 :         return r;
    2126     21387892 :       }
    2127              : 
    2128       317084 :     case CONSTRUCTOR:
    2129       317084 :       {
    2130       317084 :         bool changed = false;
    2131       317084 :         vec<constructor_elt, va_gc> *vec
    2132       317084 :           = vec_safe_copy (CONSTRUCTOR_ELTS (t));
    2133       317084 :         n = CONSTRUCTOR_NELTS (t);
    2134       317084 :         type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
    2135       654943 :         for (i = 0; i < n; ++i)
    2136              :           {
    2137        20775 :             constructor_elt *e = &(*vec)[i];
    2138        20775 :             tree op = strip_typedefs (e->value, remove_attributes, flags);
    2139        20775 :             if (op != e->value)
    2140              :               {
    2141            6 :                 changed = true;
    2142            6 :                 e->value = op;
    2143              :               }
    2144        20775 :             gcc_checking_assert
    2145              :               (e->index == strip_typedefs (e->index, remove_attributes,
    2146              :                                            flags));
    2147              :           }
    2148              : 
    2149       317084 :         if (!changed && type == TREE_TYPE (t))
    2150              :           {
    2151       293957 :             vec_free (vec);
    2152              :             return t;
    2153              :           }
    2154              :         else
    2155              :           {
    2156        23127 :             r = copy_node (t);
    2157        23127 :             TREE_TYPE (r) = type;
    2158        23127 :             CONSTRUCTOR_ELTS (r) = vec;
    2159        23127 :             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    116853259 :     default:
    2170    116853259 :       break;
    2171              :     }
    2172              : 
    2173    116853259 :   gcc_assert (EXPR_P (t));
    2174              : 
    2175    116853259 :   n = cp_tree_operand_length (t);
    2176    116853259 :   ops = XALLOCAVEC (tree, n);
    2177    116853259 :   type = TREE_TYPE (t);
    2178              : 
    2179    116853259 :   switch (code)
    2180              :     {
    2181      7618117 :     CASE_CONVERT:
    2182      7618117 :     case IMPLICIT_CONV_EXPR:
    2183      7618117 :     case DYNAMIC_CAST_EXPR:
    2184      7618117 :     case STATIC_CAST_EXPR:
    2185      7618117 :     case CONST_CAST_EXPR:
    2186      7618117 :     case REINTERPRET_CAST_EXPR:
    2187      7618117 :     case CAST_EXPR:
    2188      7618117 :     case NEW_EXPR:
    2189      7618117 :       type = strip_typedefs (type, remove_attributes, flags);
    2190              :       /* fallthrough */
    2191              : 
    2192    116853259 :     default:
    2193    385557969 :       for (i = 0; i < n; ++i)
    2194    268704710 :         ops[i] = strip_typedefs (TREE_OPERAND (t, i),
    2195              :                                  remove_attributes, flags);
    2196              :       break;
    2197              :     }
    2198              : 
    2199              :   /* If nothing changed, return t.  */
    2200    379339980 :   for (i = 0; i < n; ++i)
    2201    266529280 :     if (ops[i] != TREE_OPERAND (t, i))
    2202              :       break;
    2203    116853259 :   if (i == n && type == TREE_TYPE (t))
    2204              :     return t;
    2205              : 
    2206      4318572 :   r = copy_node (t);
    2207      4318572 :   TREE_TYPE (r) = type;
    2208     13732211 :   for (i = 0; i < n; ++i)
    2209      9413639 :     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     38671075 : copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt)
    2233              : {
    2234     38671075 :   tree new_binfo;
    2235              : 
    2236     38671075 :   if (virt)
    2237              :     {
    2238              :       /* See if we've already made this virtual base.  */
    2239       295161 :       new_binfo = binfo_for_vbase (type, t);
    2240       295161 :       if (new_binfo)
    2241              :         return new_binfo;
    2242              :     }
    2243              : 
    2244     69992672 :   new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0);
    2245     38599976 :   BINFO_TYPE (new_binfo) = type;
    2246              : 
    2247              :   /* Chain it into the inheritance graph.  */
    2248     38599976 :   TREE_CHAIN (*igo_prev) = new_binfo;
    2249     38599976 :   *igo_prev = new_binfo;
    2250              : 
    2251     69992672 :   if (binfo && !BINFO_DEPENDENT_BASE_P (binfo))
    2252              :     {
    2253     31392687 :       int ix;
    2254     31392687 :       tree base_binfo;
    2255              : 
    2256     31392687 :       gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type));
    2257              : 
    2258     31392687 :       BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo);
    2259     31392687 :       BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo);
    2260              : 
    2261              :       /* We do not need to copy the accesses, as they are read only.  */
    2262     31392687 :       BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo);
    2263              : 
    2264              :       /* Recursively copy base binfos of BINFO.  */
    2265     35754323 :       for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
    2266              :         {
    2267      4361636 :           tree new_base_binfo;
    2268      4361636 :           new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo),
    2269              :                                        t, igo_prev,
    2270      4361636 :                                        BINFO_VIRTUAL_P (base_binfo));
    2271              : 
    2272      4361636 :           if (!BINFO_INHERITANCE_CHAIN (new_base_binfo))
    2273      4137172 :             BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo;
    2274      4361636 :           BINFO_BASE_APPEND (new_binfo, new_base_binfo);
    2275              :         }
    2276              :     }
    2277              :   else
    2278      7207289 :     BINFO_DEPENDENT_BASE_P (new_binfo) = 1;
    2279              : 
    2280     38599976 :   if (virt)
    2281              :     {
    2282              :       /* Push it onto the list after any virtual bases it contains
    2283              :          will have been pushed.  */
    2284       224062 :       CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo);
    2285       224062 :       BINFO_VIRTUAL_P (new_binfo) = 1;
    2286       224062 :       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   2672393276 : list_hasher::equal (tree t, list_proxy *proxy)
    2323              : {
    2324   2672393276 :   return (TREE_VALUE (t) == proxy->value
    2325    177735167 :           && TREE_PURPOSE (t) == proxy->purpose
    2326   2847844968 :           && 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   2475169187 : list_hash_pieces (tree purpose, tree value, tree chain)
    2335              : {
    2336   2475169187 :   hashval_t hashcode = 0;
    2337              : 
    2338   2475169187 :   if (chain)
    2339   2475009467 :     hashcode += TREE_HASH (chain);
    2340              : 
    2341   2475169187 :   if (value)
    2342   2475169187 :     hashcode += TREE_HASH (value);
    2343              :   else
    2344            0 :     hashcode += 1007;
    2345   2475169187 :   if (purpose)
    2346    157888824 :     hashcode += TREE_HASH (purpose);
    2347              :   else
    2348   2317280363 :     hashcode += 1009;
    2349   2475169187 :   return hashcode;
    2350              : }
    2351              : 
    2352              : /* Hash an already existing TREE_LIST.  */
    2353              : 
    2354              : hashval_t
    2355   2150683721 : list_hasher::hash (tree t)
    2356              : {
    2357   2150683721 :   return list_hash_pieces (TREE_PURPOSE (t),
    2358   2150683721 :                            TREE_VALUE (t),
    2359   2150683721 :                            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    324485466 : hash_tree_cons (tree purpose, tree value, tree chain)
    2368              : {
    2369    324485466 :   int hashcode = 0;
    2370    324485466 :   tree *slot;
    2371    324485466 :   struct list_proxy proxy;
    2372              : 
    2373              :   /* Hash the list node.  */
    2374    324485466 :   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    324485466 :   proxy.purpose = purpose;
    2378    324485466 :   proxy.value = value;
    2379    324485466 :   proxy.chain = chain;
    2380              :   /* See if it is already in the table.  */
    2381    324485466 :   slot = list_hash_table->find_slot_with_hash (&proxy, hashcode, INSERT);
    2382              :   /* If not, create a new node.  */
    2383    324485466 :   if (!*slot)
    2384    155739836 :     *slot = tree_cons (purpose, value, chain);
    2385    324485466 :   return (tree) *slot;
    2386              : }
    2387              : 
    2388              : /* Constructor for hashed lists.  */
    2389              : 
    2390              : tree
    2391      2357358 : hash_tree_chain (tree value, tree chain)
    2392              : {
    2393      2357358 :   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    159892540 : build_qualified_name (tree type, tree scope, tree name, bool template_p)
    2438              : {
    2439    159892540 :   tree t;
    2440    159892540 :   if (type == error_mark_node
    2441    159892540 :       || scope == error_mark_node
    2442    159892537 :       || name == error_mark_node)
    2443              :     return error_mark_node;
    2444    159892537 :   gcc_assert (TREE_CODE (name) != SCOPE_REF);
    2445    159892537 :   t = build2 (SCOPE_REF, type, scope, name);
    2446    159892537 :   QUALIFIED_NAME_IS_TEMPLATE (t) = template_p;
    2447    159892537 :   PTRMEM_OK_P (t) = true;
    2448    159892537 :   if (type)
    2449     10822876 :     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   1319599361 : cp_check_qualified_type (const_tree cand, const_tree base, int type_quals,
    2459              :                          cp_ref_qualifier rqual, tree raises, bool late)
    2460              : {
    2461   1319599361 :   return (TYPE_QUALS (cand) == type_quals
    2462   1319503850 :           && check_base_type (cand, base)
    2463   1319386044 :           && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (cand),
    2464              :                                 ce_exact)
    2465    631733768 :           && TYPE_HAS_LATE_RETURN_TYPE (cand) == late
    2466   1909925375 :           && type_memfn_rqual (cand) == rqual);
    2467              : }
    2468              : 
    2469              : /* Build the FUNCTION_TYPE or METHOD_TYPE with the ref-qualifier RQUAL.  */
    2470              : 
    2471              : tree
    2472       742263 : build_ref_qualified_type (tree type, cp_ref_qualifier rqual)
    2473              : {
    2474       742263 :   tree raises = TYPE_RAISES_EXCEPTIONS (type);
    2475       742263 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    2476       742263 :   return build_cp_fntype_variant (type, rqual, raises, late);
    2477              : }
    2478              : 
    2479              : tree
    2480       213051 : 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       213051 :   gcc_checking_assert (clusters <= (unsigned short)(~0));
    2485       213051 :   size_t length = (offsetof (tree_binding_vec, vec)
    2486              :                    + clusters * sizeof (binding_cluster));
    2487       213051 :   tree vec = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
    2488       213051 :   TREE_SET_CODE (vec, BINDING_VECTOR);
    2489       213051 :   BINDING_VECTOR_NAME (vec) = name;
    2490       213051 :   BINDING_VECTOR_ALLOC_CLUSTERS (vec) = clusters;
    2491       213051 :   BINDING_VECTOR_NUM_CLUSTERS (vec) = 0;
    2492              : 
    2493       213051 :   return vec;
    2494              : }
    2495              : 
    2496              : /* Make a raw overload node containing FN.  */
    2497              : 
    2498              : tree
    2499    397098067 : ovl_make (tree fn, tree next)
    2500              : {
    2501    397098067 :   tree result = make_node (OVERLOAD);
    2502              : 
    2503    397098067 :   if (TREE_CODE (fn) == OVERLOAD)
    2504     14916532 :     OVL_NESTED_P (result) = true;
    2505              : 
    2506    518954700 :   TREE_TYPE (result) = (next || TREE_CODE (fn) == TEMPLATE_DECL
    2507    518954700 :                         ? unknown_type_node : TREE_TYPE (fn));
    2508    397098067 :   if (next && TREE_CODE (next) == OVERLOAD && OVL_DEDUP_P (next))
    2509     16103386 :     OVL_DEDUP_P (result) = true;
    2510    397098067 :   OVL_FUNCTION (result) = fn;
    2511    397098067 :   OVL_CHAIN (result) = next;
    2512    397098067 :   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    725583525 : ovl_insert (tree fn, tree maybe_ovl, int using_or_hidden)
    2523              : {
    2524    725583525 :   tree result = maybe_ovl;
    2525    725583525 :   tree insert_after = NULL_TREE;
    2526              : 
    2527              :   /* Skip hidden.  */
    2528   1043961739 :   for (; maybe_ovl && TREE_CODE (maybe_ovl) == OVERLOAD
    2529   1104103259 :          && OVL_HIDDEN_P (maybe_ovl);
    2530    120162549 :        maybe_ovl = OVL_CHAIN (maybe_ovl))
    2531              :     {
    2532    120162549 :       gcc_checking_assert (!OVL_LOOKUP_P (maybe_ovl));
    2533    120162549 :       insert_after = maybe_ovl;
    2534              :     }
    2535              : 
    2536    725583525 :   if (maybe_ovl || using_or_hidden || TREE_CODE (fn) == TEMPLATE_DECL)
    2537              :     {
    2538    315722325 :       maybe_ovl = ovl_make (fn, maybe_ovl);
    2539              : 
    2540    315722325 :       if (using_or_hidden < 0)
    2541     81295048 :         OVL_HIDDEN_P (maybe_ovl) = true;
    2542    315722325 :       if (using_or_hidden > 0)
    2543              :         {
    2544     13715820 :           OVL_DEDUP_P (maybe_ovl) = OVL_USING_P (maybe_ovl) = true;
    2545     13715820 :           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    725583525 :   if (insert_after)
    2555              :     {
    2556      9461473 :       OVL_CHAIN (insert_after) = maybe_ovl;
    2557      9461473 :       TREE_TYPE (insert_after) = unknown_type_node;
    2558              :     }
    2559              :   else
    2560              :     result = maybe_ovl;
    2561              : 
    2562    725583525 :   return result;
    2563              : }
    2564              : 
    2565              : /* Skip any hidden names at the beginning of OVL.   */
    2566              : 
    2567              : tree
    2568   2117940096 : ovl_skip_hidden (tree ovl)
    2569              : {
    2570   3909582725 :   while (ovl && TREE_CODE (ovl) == OVERLOAD && OVL_HIDDEN_P (ovl))
    2571   1791642629 :     ovl = OVL_CHAIN (ovl);
    2572              : 
    2573   2117940096 :   return ovl;
    2574              : }
    2575              : 
    2576              : /* NODE is an OVL_HIDDEN_P node that is now revealed.  */
    2577              : 
    2578              : tree
    2579      4126415 : 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      4126415 :   OVL_HIDDEN_P (node) = false;
    2585      4126415 :   if (tree chain = OVL_CHAIN (node))
    2586       175580 :     if (TREE_CODE (chain) == OVERLOAD)
    2587              :       {
    2588       166078 :         if (OVL_HIDDEN_P (chain))
    2589              :           {
    2590              :             /* The node needs moving, and the simplest way is to remove it
    2591              :                and reinsert.  */
    2592        75855 :             overload = remove_node (overload, node);
    2593        75855 :             overload = ovl_insert (OVL_FUNCTION (node), overload);
    2594              :           }
    2595        90223 :         else if (OVL_DEDUP_P (chain))
    2596            9 :           OVL_DEDUP_P (node) = true;
    2597              :       }
    2598      4126415 :   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       394892 : ovl_iterator::remove_node (tree overload, tree node)
    2608              : {
    2609       394892 :   tree *slot = &overload;
    2610      2334256 :   while (*slot != node)
    2611              :     {
    2612      1939364 :       tree probe = *slot;
    2613      1939364 :       gcc_checking_assert (!OVL_LOOKUP_P (probe));
    2614              : 
    2615      1939364 :       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       394892 :   if (TREE_CODE (node) != OVERLOAD)
    2623              :     /* Cloned inherited ctors don't mark themselves as via_using.  */
    2624              :     *slot = NULL_TREE;
    2625              :   else
    2626       152968 :     *slot = OVL_CHAIN (node);
    2627              : 
    2628       394892 :   return overload;
    2629              : }
    2630              : 
    2631              : /* Mark or unmark a lookup set. */
    2632              : 
    2633              : void
    2634    121534244 : lookup_mark (tree ovl, bool val)
    2635              : {
    2636   1487325862 :   for (lkp_iterator iter (ovl); iter; ++iter)
    2637              :     {
    2638   1365791618 :       gcc_checking_assert (LOOKUP_SEEN_P (*iter) != val);
    2639   1365791618 :       LOOKUP_SEEN_P (*iter) = val;
    2640              :     }
    2641    121534244 : }
    2642              : 
    2643              : /* Add a set of new FNS into a lookup.  */
    2644              : 
    2645              : tree
    2646    683661504 : lookup_add (tree fns, tree lookup)
    2647              : {
    2648    683661504 :   if (fns == error_mark_node || lookup == error_mark_node)
    2649              :     return error_mark_node;
    2650              : 
    2651    683661492 :   if (lookup || TREE_CODE (fns) == TEMPLATE_DECL)
    2652              :     {
    2653     75210524 :       lookup = ovl_make (fns, lookup);
    2654     75210524 :       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    684828803 : lookup_maybe_add (tree fns, tree lookup, bool deduping)
    2667              : {
    2668    684828803 :   if (deduping)
    2669    790511018 :     for (tree next, probe = fns; probe; probe = next)
    2670              :       {
    2671    707666423 :         tree fn = probe;
    2672    707666423 :         next = NULL_TREE;
    2673              : 
    2674    707666423 :         if (TREE_CODE (probe) == OVERLOAD)
    2675              :           {
    2676    675331447 :             fn = OVL_FUNCTION (probe);
    2677    675331447 :             next = OVL_CHAIN (probe);
    2678              :           }
    2679              : 
    2680    707666423 :         if (!LOOKUP_SEEN_P (fn))
    2681    520854602 :           LOOKUP_SEEN_P (fn) = true;
    2682              :         else
    2683              :           {
    2684              :             /* This function was already seen.  Insert all the
    2685              :                predecessors onto the lookup.  */
    2686    204255927 :             for (; fns != probe; fns = OVL_CHAIN (fns))
    2687              :               {
    2688              :                 /* Propagate OVL_USING, but OVL_HIDDEN &
    2689              :                    OVL_DEDUP_P don't matter.  */
    2690     17444106 :                 if (OVL_USING_P (fns))
    2691              :                   {
    2692       434447 :                     lookup = ovl_make (OVL_FUNCTION (fns), lookup);
    2693       434447 :                     OVL_USING_P (lookup) = true;
    2694              :                   }
    2695              :                 else
    2696     17009659 :                   lookup = lookup_add (OVL_FUNCTION (fns), lookup);
    2697              :               }
    2698              : 
    2699              :             /* And now skip this function.  */
    2700              :             fns = next;
    2701              :           }
    2702              :       }
    2703              : 
    2704    684828803 :   if (fns)
    2705              :     /* We ended in a set of new functions.  Add them all in one go.  */
    2706    665721310 :     lookup = lookup_add (fns, lookup);
    2707              : 
    2708    684828803 :   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   7503337102 : is_overloaded_fn (tree x)
    2720              : {
    2721   7503337102 :   STRIP_ANY_LOCATION_WRAPPER (x);
    2722              : 
    2723              :   /* A baselink is also considered an overloaded function.  */
    2724   7503337102 :   if (TREE_CODE (x) == OFFSET_REF
    2725   7503270217 :       || TREE_CODE (x) == COMPONENT_REF)
    2726    401781880 :     x = TREE_OPERAND (x, 1);
    2727   7503337102 :   x = MAYBE_BASELINK_FUNCTIONS (x);
    2728   7503337102 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2729    212111113 :     x = TREE_OPERAND (x, 0);
    2730              : 
    2731   8658099162 :   if (DECL_FUNCTION_TEMPLATE_P (OVL_FIRST (x))
    2732   7540973533 :       || (TREE_CODE (x) == OVERLOAD && !OVL_SINGLE_P (x)))
    2733              :     return 2;
    2734              : 
    2735   7873210151 :   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    333168898 : 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    333168898 :   if (identifier_p (x))
    2748              :     return x;
    2749    332986569 :   if (TREE_CODE (x) == TEMPLATE_ID_EXPR)
    2750    167861970 :     x = TREE_OPERAND (x, 0);
    2751    332986569 :   if (OVL_P (x))
    2752    310169783 :     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    332457826 : call_expr_dependent_name (tree x)
    2761              : {
    2762    332457826 :   if (TREE_TYPE (x) != NULL_TREE)
    2763              :     /* X isn't dependent, so its callee isn't a dependent name.  */
    2764              :     return NULL_TREE;
    2765    328028414 :   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    644526071 : really_overloaded_fn (tree x)
    2774              : {
    2775    644526071 :   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   4835482503 : maybe_get_fns (tree from)
    2783              : {
    2784   4835482503 :   STRIP_ANY_LOCATION_WRAPPER (from);
    2785              : 
    2786              :   /* A baselink is also considered an overloaded function.  */
    2787   4835482503 :   if (TREE_CODE (from) == OFFSET_REF
    2788   4835420878 :       || TREE_CODE (from) == COMPONENT_REF)
    2789    154355635 :     from = TREE_OPERAND (from, 1);
    2790   4835482503 :   if (BASELINK_P (from))
    2791    143292691 :     from = BASELINK_FUNCTIONS (from);
    2792   4835482503 :   if (TREE_CODE (from) == TEMPLATE_ID_EXPR)
    2793    124503720 :     from = TREE_OPERAND (from, 0);
    2794              : 
    2795   4835482503 :   if (OVL_P (from))
    2796   1222025818 :     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    872750724 : get_fns (tree from)
    2805              : {
    2806    872750724 :   tree res = maybe_get_fns (from);
    2807              : 
    2808    872750724 :   gcc_assert (res);
    2809    872750724 :   return res;
    2810              : }
    2811              : 
    2812              : /* Return the first function of the overload set FROM refers to.  */
    2813              : 
    2814              : tree
    2815    534884355 : get_first_fn (tree from)
    2816              : {
    2817    534884355 :   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       218090 : maybe_get_first_fn (tree from)
    2825              : {
    2826       218090 :   if (tree res = maybe_get_fns (from))
    2827       218090 :     return OVL_FIRST (res);
    2828              :   return from;
    2829              : }
    2830              : 
    2831              : /* Return the scope where the overloaded functions OVL were found.  */
    2832              : 
    2833              : tree
    2834    221364149 : ovl_scope (tree ovl)
    2835              : {
    2836    221364149 :   if (TREE_CODE (ovl) == OFFSET_REF
    2837    221364149 :       || TREE_CODE (ovl) == COMPONENT_REF)
    2838            0 :     ovl = TREE_OPERAND (ovl, 1);
    2839    221364149 :   if (TREE_CODE (ovl) == BASELINK)
    2840     47144040 :     return BINFO_TYPE (BASELINK_BINFO (ovl));
    2841    174220109 :   if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR)
    2842     78964326 :     ovl = TREE_OPERAND (ovl, 0);
    2843              :   /* Skip using-declarations.  */
    2844    174220109 :   lkp_iterator iter (ovl);
    2845    182816183 :   do
    2846    182816183 :     ovl = *iter;
    2847    357036292 :   while (iter.using_p () && ++iter);
    2848              : 
    2849    174220109 :   return CP_DECL_CONTEXT (ovl);
    2850              : }
    2851              : 
    2852              : #define PRINT_RING_SIZE 4
    2853              : 
    2854              : static const char *
    2855       178249 : cxx_printable_name_internal (tree decl, int v, bool translate)
    2856              : {
    2857       178249 :   static unsigned int uid_ring[PRINT_RING_SIZE];
    2858       178249 :   static char *print_ring[PRINT_RING_SIZE];
    2859       178249 :   static bool trans_ring[PRINT_RING_SIZE];
    2860       178249 :   static int ring_counter;
    2861       178249 :   int i;
    2862              : 
    2863              :   /* Only cache functions.  */
    2864       178249 :   if (v < 2
    2865        96267 :       || TREE_CODE (decl) != FUNCTION_DECL
    2866       271312 :       || DECL_LANG_SPECIFIC (decl) == 0)
    2867        86306 :     return lang_decl_name (decl, v, translate);
    2868              : 
    2869              :   /* See if this print name is lying around.  */
    2870       419163 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2871       343765 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2872              :       /* yes, so return it.  */
    2873        16545 :       return print_ring[i];
    2874              : 
    2875        75398 :   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       452388 :   for (i = 0; i < PRINT_RING_SIZE; i++)
    2880       301592 :     if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
    2881              :       /* yes, so return it.  */
    2882            0 :       return print_ring[i];
    2883              : 
    2884        75398 :   if (++ring_counter == PRINT_RING_SIZE)
    2885        15614 :     ring_counter = 0;
    2886              : 
    2887        75398 :   if (current_function_decl != NULL_TREE)
    2888              :     {
    2889              :       /* There may be both translated and untranslated versions of the
    2890              :          name cached.  */
    2891       207180 :       for (i = 0; i < 2; i++)
    2892              :         {
    2893       138120 :           if (uid_ring[ring_counter] == DECL_UID (current_function_decl))
    2894           79 :             ring_counter += 1;
    2895       138120 :           if (ring_counter == PRINT_RING_SIZE)
    2896            7 :             ring_counter = 0;
    2897              :         }
    2898        69060 :       gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
    2899              :     }
    2900              : 
    2901        75398 :   free (print_ring[ring_counter]);
    2902              : 
    2903        75398 :   print_ring[ring_counter] = xstrdup (ret);
    2904        75398 :   uid_ring[ring_counter] = DECL_UID (decl);
    2905        75398 :   trans_ring[ring_counter] = translate;
    2906        75398 :   return print_ring[ring_counter];
    2907              : }
    2908              : 
    2909              : const char *
    2910       178249 : cxx_printable_name (tree decl, int v)
    2911              : {
    2912       178249 :   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    226917304 : canonical_eh_spec (tree raises)
    2926              : {
    2927    226917304 :   if (raises == NULL_TREE)
    2928              :     return raises;
    2929    200519757 :   else if (DEFERRED_NOEXCEPT_SPEC_P (raises)
    2930    164061785 :            || UNPARSED_NOEXCEPT_SPEC_P (raises)
    2931    155027077 :            || uses_template_parms (raises)
    2932    155027077 :            || uses_template_parms (TREE_PURPOSE (raises)))
    2933              :     /* Keep a dependent or deferred exception specification.  */
    2934              :     return raises;
    2935    153126558 :   else if (nothrow_spec_p (raises))
    2936              :     /* throw() -> noexcept.  */
    2937    152588876 :     return noexcept_true_spec;
    2938              :   else
    2939              :     /* For C++17 type matching, anything else -> nothing.  */
    2940              :     return NULL_TREE;
    2941              : }
    2942              : 
    2943              : tree
    2944    786362728 : build_cp_fntype_variant (tree type, cp_ref_qualifier rqual,
    2945              :                          tree raises, bool late)
    2946              : {
    2947    786362728 :   cp_cv_quals type_quals = TYPE_QUALS (type);
    2948              : 
    2949    786362728 :   if (cp_check_qualified_type (type, type, type_quals, rqual, raises, late))
    2950              :     return type;
    2951              : 
    2952    334100131 :   tree v = TYPE_MAIN_VARIANT (type);
    2953    733262877 :   for (; v; v = TYPE_NEXT_VARIANT (v))
    2954    533236633 :     if (cp_check_qualified_type (v, type, type_quals, rqual, raises, late))
    2955              :       return v;
    2956              : 
    2957              :   /* Need to build a new variant.  */
    2958    200026244 :   v = build_variant_type_copy (type);
    2959    200026244 :   if (!TYPE_DEPENDENT_P (v))
    2960              :     /* We no longer know that it's not type-dependent.  */
    2961    199176267 :     TYPE_DEPENDENT_P_VALID (v) = false;
    2962    200026244 :   TYPE_RAISES_EXCEPTIONS (v) = raises;
    2963    200026244 :   TYPE_HAS_LATE_RETURN_TYPE (v) = late;
    2964    200026244 :   switch (rqual)
    2965              :     {
    2966      1294039 :     case REF_QUAL_RVALUE:
    2967      1294039 :       FUNCTION_RVALUE_QUALIFIED (v) = 1;
    2968      1294039 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2969      1294039 :       break;
    2970      1225289 :     case REF_QUAL_LVALUE:
    2971      1225289 :       FUNCTION_RVALUE_QUALIFIED (v) = 0;
    2972      1225289 :       FUNCTION_REF_QUALIFIED (v) = 1;
    2973      1225289 :       break;
    2974    197506916 :     default:
    2975    197506916 :       FUNCTION_REF_QUALIFIED (v) = 0;
    2976    197506916 :       break;
    2977              :     }
    2978              : 
    2979              :   /* Canonicalize the exception specification.  */
    2980    200026244 :   tree cr = flag_noexcept_type ? canonical_eh_spec (raises) : NULL_TREE;
    2981    188820214 :   bool complex_eh_spec_p = (cr && cr != noexcept_true_spec
    2982    245801964 :                             && !UNPARSED_NOEXCEPT_SPEC_P (cr));
    2983              : 
    2984    162272674 :   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      5781544 :     type = build_cp_fntype_variant (type, rqual, /*raises=*/NULL_TREE, late);
    2988    200026244 :   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     51882019 :     SET_TYPE_STRUCTURAL_EQUALITY (v);
    2993    148144225 :   else if (TYPE_CANONICAL (type) != type || cr != raises || late)
    2994              :     /* Build the underlying canonical type, since it is different
    2995              :        from TYPE. */
    2996     63803647 :     TYPE_CANONICAL (v) = build_cp_fntype_variant (TYPE_CANONICAL (type),
    2997              :                                                   rqual, cr, false);
    2998              :   else
    2999              :     /* T is its own canonical type. */
    3000     84340578 :     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      3660060 : fixup_deferred_exception_variants (tree type, tree raises)
    3012              : {
    3013      3660060 :   tree original = TYPE_RAISES_EXCEPTIONS (type);
    3014              : 
    3015      7320120 :   gcc_checking_assert (UNPARSED_NOEXCEPT_SPEC_P (original));
    3016              : 
    3017      3660060 :   for (tree variant = TYPE_MAIN_VARIANT (type);
    3018     11877372 :        variant; variant = TYPE_NEXT_VARIANT (variant))
    3019      8217312 :     if (TYPE_RAISES_EXCEPTIONS (variant) == original)
    3020              :       {
    3021      3950883 :         gcc_checking_assert (variant != TYPE_MAIN_VARIANT (type));
    3022              : 
    3023      3950883 :         SET_TYPE_STRUCTURAL_EQUALITY (variant);
    3024      3950883 :         TYPE_RAISES_EXCEPTIONS (variant) = raises;
    3025              : 
    3026      3950883 :         if (!TYPE_DEPENDENT_P (variant))
    3027              :           /* We no longer know that it's not type-dependent.  */
    3028       295874 :           TYPE_DEPENDENT_P_VALID (variant) = false;
    3029              :       }
    3030      3660060 : }
    3031              : 
    3032              : /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions
    3033              :    listed in RAISES.  */
    3034              : 
    3035              : tree
    3036    198105124 : build_exception_variant (tree type, tree raises)
    3037              : {
    3038    198105124 :   cp_ref_qualifier rqual = type_memfn_rqual (type);
    3039    198105124 :   bool late = TYPE_HAS_LATE_RETURN_TYPE (type);
    3040    198105124 :   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       373281 : bind_template_template_parm (tree t, tree newargs)
    3049              : {
    3050       373281 :   tree decl = TYPE_NAME (t);
    3051       373281 :   tree t2;
    3052              : 
    3053       373281 :   t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM);
    3054       373281 :   decl = build_decl (input_location,
    3055       373281 :                      TYPE_DECL, DECL_NAME (decl), NULL_TREE);
    3056       373281 :   SET_DECL_TEMPLATE_PARM_P (decl);
    3057              : 
    3058              :   /* These nodes have to be created to reflect new TYPE_DECL and template
    3059              :      arguments.  */
    3060       373281 :   TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t));
    3061       373281 :   TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl;
    3062       373281 :   TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2)
    3063       746562 :     = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs);
    3064              : 
    3065       373281 :   TREE_TYPE (decl) = t2;
    3066       373281 :   TYPE_NAME (t2) = decl;
    3067       373281 :   TYPE_STUB_DECL (t2) = decl;
    3068       373281 :   TYPE_SIZE (t2) = 0;
    3069              : 
    3070       373281 :   if (any_template_arguments_need_structural_equality_p (newargs))
    3071           13 :     SET_TYPE_STRUCTURAL_EQUALITY (t2);
    3072              :   else
    3073       373268 :     TYPE_CANONICAL (t2) = canonical_type_parameter (t2);
    3074              : 
    3075       373281 :   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       633388 : verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data)
    3106              : {
    3107       633388 :   tree t = *tp;
    3108       633388 :   hash_table<nofree_ptr_hash <tree_node> > *statements
    3109              :       = static_cast <hash_table<nofree_ptr_hash <tree_node> > *> (data);
    3110       633388 :   tree_node **slot;
    3111              : 
    3112       633388 :   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    315454184 : no_linkage_check (tree t, bool relaxed_p)
    3144              : {
    3145    369236110 :   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    416486880 :   if (LAMBDA_TYPE_P (t)
    3154    373103205 :       && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node)
    3155              :     {
    3156      2200516 :       tree extra = LAMBDA_TYPE_EXTRA_SCOPE (t);
    3157      2200516 :       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    369231605 :   if (processing_template_decl)
    3164              :     return NULL_TREE;
    3165              : 
    3166    230604241 :   switch (TREE_CODE (t))
    3167              :     {
    3168    121072764 :     case RECORD_TYPE:
    3169    121072764 :       if (TYPE_PTRMEMFUNC_P (t))
    3170       126078 :         goto ptrmem;
    3171              :       /* Fall through.  */
    3172    122326889 :     case UNION_TYPE:
    3173    122326889 :       if (!CLASS_TYPE_P (t))
    3174              :         return NULL_TREE;
    3175              :       /* Fall through.  */
    3176    127131084 :     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    258849490 :       if (TYPE_UNNAMED_P (t) && TYPE_NAMESPACE_SCOPE_P (t))
    3180              :         return t;
    3181              : 
    3182    126353380 :       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    129017703 :           if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r)))
    3188        82173 :             return no_linkage_check (TYPE_CONTEXT (t), relaxed_p);
    3189    128935530 :           else if (TREE_CODE (r) == FUNCTION_DECL)
    3190              :             {
    3191      3222047 :               if (relaxed_p
    3192      3222047 :                   && (vague_linkage_p (r)
    3193         7746 :                       || (TREE_PUBLIC (r) && module_maybe_has_cmi_p ())))
    3194      2664323 :                 r = CP_DECL_CONTEXT (r);
    3195              :               else
    3196              :                 return t;
    3197              :             }
    3198              :           else
    3199              :             break;
    3200              :         }
    3201              : 
    3202              :       return NULL_TREE;
    3203              : 
    3204     29111029 :     case ARRAY_TYPE:
    3205     29111029 :     case POINTER_TYPE:
    3206     29111029 :     case REFERENCE_TYPE:
    3207     29111029 :     case VECTOR_TYPE:
    3208     29111029 :       return no_linkage_check (TREE_TYPE (t), relaxed_p);
    3209              : 
    3210       129235 :     case OFFSET_TYPE:
    3211       129235 :     ptrmem:
    3212       129235 :       r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t),
    3213              :                             relaxed_p);
    3214       129235 :       if (r)
    3215              :         return r;
    3216       129235 :       return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p);
    3217              : 
    3218     25001989 :     case METHOD_TYPE:
    3219     25001989 :     case FUNCTION_TYPE:
    3220     25001989 :       {
    3221     25001989 :         tree parm = TYPE_ARG_TYPES (t);
    3222     25001989 :         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     12616702 :           parm = TREE_CHAIN (parm);
    3226     32064774 :         for (;
    3227     57066763 :              parm && parm != void_list_node;
    3228     32064774 :              parm = TREE_CHAIN (parm))
    3229              :           {
    3230     32607274 :             r = no_linkage_check (TREE_VALUE (parm), relaxed_p);
    3231     32607274 :             if (r)
    3232              :               return r;
    3233              :           }
    3234     24459489 :         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         6853 : array_type_nelts_total (tree type)
    3259              : {
    3260         6853 :   tree sz = array_type_nelts_top (type);
    3261         6853 :   type = TREE_TYPE (type);
    3262         7127 :   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         6853 :   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     60405196 : bot_manip (tree* tp, int* walk_subtrees, void* data_)
    3282              : {
    3283     60405196 :   bot_data &data = *(bot_data*)data_;
    3284     60405196 :   splay_tree target_remap = data.target_remap;
    3285     60405196 :   tree t = *tp;
    3286              : 
    3287     60405196 :   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     24665926 :       *walk_subtrees = 0;
    3295     24665926 :       *tp = unshare_expr (t);
    3296     24665926 :       return NULL_TREE;
    3297              :     }
    3298     35739270 :   if (TREE_CODE (t) == TARGET_EXPR)
    3299              :     {
    3300       767208 :       tree u;
    3301              : 
    3302       767208 :       if (TREE_CODE (TARGET_EXPR_INITIAL (t)) == AGGR_INIT_EXPR)
    3303              :         {
    3304       534787 :           u = build_cplus_new (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3305              :                                tf_warning_or_error);
    3306       534787 :           if (u == error_mark_node)
    3307              :             return u;
    3308       534787 :           if (AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (t)))
    3309         6642 :             AGGR_INIT_ZERO_FIRST (TARGET_EXPR_INITIAL (u)) = true;
    3310              :         }
    3311              :       else
    3312       232421 :         u = force_target_expr (TREE_TYPE (t), TARGET_EXPR_INITIAL (t),
    3313              :                                tf_warning_or_error);
    3314              : 
    3315       767208 :       TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
    3316       767208 :       TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
    3317       767208 :       TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t);
    3318       767208 :       TARGET_EXPR_ELIDING_P (u) = TARGET_EXPR_ELIDING_P (t);
    3319       767208 :       TREE_CONSTANT (u) = TREE_CONSTANT (t);
    3320              : 
    3321              :       /* Map the old variable to the new one.  */
    3322      2301624 :       splay_tree_insert (target_remap,
    3323       767208 :                          (splay_tree_key) TARGET_EXPR_SLOT (t),
    3324       767208 :                          (splay_tree_value) TARGET_EXPR_SLOT (u));
    3325              : 
    3326       767208 :       TARGET_EXPR_INITIAL (u) = break_out_target_exprs (TARGET_EXPR_INITIAL (u),
    3327              :                                                         data.clear_location);
    3328       767208 :       if (TARGET_EXPR_INITIAL (u) == error_mark_node)
    3329              :         return error_mark_node;
    3330              : 
    3331       767208 :       if (data.clear_location)
    3332       414586 :         SET_EXPR_LOCATION (u, input_location);
    3333              : 
    3334              :       /* Replace the old expression with the new version.  */
    3335       767208 :       *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       767208 :       *walk_subtrees = 0;
    3340       767208 :       return NULL_TREE;
    3341              :     }
    3342     34972062 :   if (TREE_CODE (*tp) == SAVE_EXPR)
    3343              :     {
    3344       104154 :       t = *tp;
    3345       104154 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3346              :                                              (splay_tree_key) t);
    3347       104154 :       if (n)
    3348              :         {
    3349        52798 :           *tp = (tree)n->value;
    3350        52798 :           *walk_subtrees = 0;
    3351              :         }
    3352              :       else
    3353              :         {
    3354        51356 :           copy_tree_r (tp, walk_subtrees, NULL);
    3355        51356 :           splay_tree_insert (target_remap,
    3356              :                              (splay_tree_key)t,
    3357        51356 :                              (splay_tree_value)*tp);
    3358              :           /* Make sure we don't remap an already-remapped SAVE_EXPR.  */
    3359        51356 :           splay_tree_insert (target_remap,
    3360              :                              (splay_tree_key)*tp,
    3361        51356 :                              (splay_tree_value)*tp);
    3362              :         }
    3363              :       return NULL_TREE;
    3364              :     }
    3365     34867908 :   if (TREE_CODE (*tp) == DECL_EXPR
    3366          199 :       && VAR_P (DECL_EXPR_DECL (*tp))
    3367          199 :       && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp))
    3368     34868107 :       && !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     34867709 :   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     34867708 :   t = copy_tree_r (tp, walk_subtrees, NULL);
    3410     34867708 :   if (TREE_CODE (*tp) == CALL_EXPR || TREE_CODE (*tp) == AGGR_INIT_EXPR)
    3411      5985460 :     if (!processing_template_decl)
    3412      5985460 :       set_flags_from_callee (*tp);
    3413     34867708 :   if (data.clear_location && EXPR_HAS_LOCATION (*tp))
    3414     10407069 :     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     85202237 : bot_replace (tree* t, int */*walk_subtrees*/, void* data_)
    3424              : {
    3425     85202237 :   bot_data &data = *(bot_data*)data_;
    3426     85202237 :   splay_tree target_remap = data.target_remap;
    3427              : 
    3428     85202237 :   if (VAR_P (*t))
    3429              :     {
    3430      2610362 :       splay_tree_node n = splay_tree_lookup (target_remap,
    3431              :                                              (splay_tree_key) *t);
    3432      2610362 :       if (n)
    3433         2203 :         *t = (tree) n->value;
    3434              :     }
    3435     82591875 :   else if (TREE_CODE (*t) == PARM_DECL
    3436      5669563 :            && DECL_NAME (*t) == this_identifier
    3437     84579021 :            && !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        25184 :       *t = current_class_ptr;
    3442              :     }
    3443     82566691 :   else if (TREE_CODE (*t) == CONVERT_EXPR
    3444     82566691 :            && 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     85202237 :   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     12869649 : break_out_target_exprs (tree t, bool clear_location /* = false */)
    3467              : {
    3468     12869649 :   static int target_remap_count;
    3469     12869649 :   static splay_tree target_remap;
    3470              : 
    3471              :   /* We shouldn't be called on templated trees, nor do we want to
    3472              :      produce them.  */
    3473     12869649 :   gcc_checking_assert (!processing_template_decl);
    3474              : 
    3475     12869649 :   if (!target_remap_count++)
    3476     12102441 :     target_remap = splay_tree_new (splay_tree_compare_pointers,
    3477              :                                    /*splay_tree_delete_key_fn=*/NULL,
    3478              :                                    /*splay_tree_delete_value_fn=*/NULL);
    3479     12869649 :   bot_data data = { target_remap, clear_location };
    3480     12869649 :   if (cp_walk_tree (&t, bot_manip, &data, NULL) == error_mark_node)
    3481            0 :     t = error_mark_node;
    3482     12869649 :   if (cp_walk_tree (&t, bot_replace, &data, NULL) == error_mark_node)
    3483            0 :     t = error_mark_node;
    3484              : 
    3485     12869649 :   if (!--target_remap_count)
    3486              :     {
    3487     12102441 :       splay_tree_delete (target_remap);
    3488     12102441 :       target_remap = NULL;
    3489              :     }
    3490              : 
    3491     12869649 :   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      1533792 : build_ctor_subob_ref (tree index, tree type, tree obj)
    3499              : {
    3500      1533792 :   if (index == NULL_TREE)
    3501              :     /* Can't refer to a particular member of a vector.  */
    3502              :     obj = NULL_TREE;
    3503      1533792 :   else if (TREE_CODE (index) == INTEGER_CST)
    3504        56908 :     obj = cp_build_array_ref (input_location, obj, index, tf_none);
    3505              :   else
    3506      1476884 :     obj = build_class_member_access_expr (obj, index, NULL_TREE,
    3507              :                                           /*reference*/false, tf_none);
    3508      1533792 :   if (obj)
    3509              :     {
    3510      1533792 :       tree objtype = TREE_TYPE (obj);
    3511      1533792 :       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      1533709 :         gcc_assert (same_type_ignoring_top_level_qualifiers_p (type, objtype));
    3522              :     }
    3523              : 
    3524      1533792 :   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     27685477 : replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
    3540              : {
    3541     27685477 :   replace_placeholders_t *d = static_cast<replace_placeholders_t*>(data_);
    3542     27685477 :   tree obj = d->obj;
    3543              : 
    3544     27685477 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3545              :     {
    3546      9634900 :       *walk_subtrees = false;
    3547      9634900 :       return NULL_TREE;
    3548              :     }
    3549              : 
    3550     18050577 :   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       362443 :     case CONSTRUCTOR:
    3566       362443 :       {
    3567       362443 :         constructor_elt *ce;
    3568       362443 :         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       362443 :         if ((CONSTRUCTOR_PLACEHOLDER_BOUNDARY (*t)
    3573          648 :              && *t != d->exp)
    3574       362986 :             || d->pset->add (*t))
    3575              :           {
    3576          105 :             *walk_subtrees = false;
    3577          105 :             return NULL_TREE;
    3578              :           }
    3579      1107642 :         for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i)
    3580              :           {
    3581       745304 :             tree *valp = &ce->value;
    3582       745304 :             tree type = TREE_TYPE (*valp);
    3583       745304 :             tree subob = obj;
    3584              : 
    3585              :             /* Elements with RANGE_EXPR index shouldn't have any
    3586              :                placeholders in them.  */
    3587       745304 :             if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
    3588            9 :               continue;
    3589              : 
    3590       745295 :             if (TREE_CODE (*valp) == CONSTRUCTOR
    3591         2996 :                 && 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         2982 :                 if (same_type_ignoring_top_level_qualifiers_p
    3597         2982 :                     (TREE_TYPE (*t), TREE_TYPE (obj)))
    3598         2928 :                   subob = build_ctor_subob_ref (ce->index, type, obj);
    3599         2982 :                 if (TREE_CODE (*valp) == TARGET_EXPR)
    3600            0 :                   valp = &TARGET_EXPR_INITIAL (*valp);
    3601              :               }
    3602       745295 :             d->obj = subob;
    3603       745295 :             cp_walk_tree (valp, replace_placeholders_r, data_, NULL);
    3604       745295 :             d->obj = obj;
    3605              :           }
    3606       362338 :         *walk_subtrees = false;
    3607       362338 :         break;
    3608              :       }
    3609              : 
    3610     17687552 :     default:
    3611     17687552 :       if (d->pset->add (*t))
    3612       670354 :         *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     67059711 : replace_placeholders (tree exp, tree obj, bool *seen_p /*= NULL*/)
    3624              : {
    3625              :   /* This is only relevant for C++14.  */
    3626     67059711 :   if (cxx_dialect < cxx14)
    3627       913205 :     return exp;
    3628              : 
    3629              :   /* If the object isn't a (member of a) class, do nothing.  */
    3630              :   tree op0 = obj;
    3631     66831454 :   while (handled_component_p (op0))
    3632       684948 :     op0 = TREE_OPERAND (op0, 0);
    3633     66146506 :   if (!CLASS_TYPE_P (strip_array_types (TREE_TYPE (op0))))
    3634     59882971 :     return exp;
    3635              : 
    3636      6263535 :   tree *tp = &exp;
    3637      6263535 :   if (TREE_CODE (exp) == TARGET_EXPR)
    3638       827895 :     tp = &TARGET_EXPR_INITIAL (exp);
    3639      6263535 :   hash_set<tree> pset;
    3640      6263535 :   replace_placeholders_t data = { obj, *tp, false, &pset };
    3641      6263535 :   cp_walk_tree (tp, replace_placeholders_r, &data, NULL);
    3642      6263535 :   if (seen_p)
    3643       203732 :     *seen_p = data.seen;
    3644      6263535 :   return exp;
    3645      6263535 : }
    3646              : 
    3647              : /* Callback function for find_placeholders.  */
    3648              : 
    3649              : static tree
    3650      8985225 : find_placeholders_r (tree *t, int *walk_subtrees, void *)
    3651              : {
    3652      8985225 :   if (TYPE_P (*t) || TREE_CONSTANT (*t))
    3653              :     {
    3654      3998347 :       *walk_subtrees = false;
    3655      3998347 :       return NULL_TREE;
    3656              :     }
    3657              : 
    3658      4986878 :   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       238398 : find_placeholders (tree exp)
    3680              : {
    3681              :   /* This is only relevant for C++14.  */
    3682       238398 :   if (cxx_dialect < cxx14)
    3683              :     return false;
    3684              : 
    3685       238398 :   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    339097830 : build_min_nt_loc (location_t loc, enum tree_code code, ...)
    3693              : {
    3694    339097830 :   tree t;
    3695    339097830 :   int length;
    3696    339097830 :   int i;
    3697    339097830 :   va_list p;
    3698              : 
    3699    339097830 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3700              : 
    3701    339097830 :   va_start (p, code);
    3702              : 
    3703    339097830 :   t = make_node (code);
    3704    339097830 :   SET_EXPR_LOCATION (t, loc);
    3705    339097830 :   length = TREE_CODE_LENGTH (code);
    3706              : 
    3707   1114332726 :   for (i = 0; i < length; i++)
    3708    775234896 :     TREE_OPERAND (t, i) = va_arg (p, tree);
    3709              : 
    3710    339097830 :   va_end (p);
    3711    339097830 :   return t;
    3712              : }
    3713              : 
    3714              : /* Similar to `build', but for template definitions.  */
    3715              : 
    3716              : tree
    3717    257665968 : build_min (enum tree_code code, tree tt, ...)
    3718              : {
    3719    257665968 :   tree t;
    3720    257665968 :   int length;
    3721    257665968 :   int i;
    3722    257665968 :   va_list p;
    3723              : 
    3724    257665968 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3725              : 
    3726    257665968 :   va_start (p, tt);
    3727              : 
    3728    257665968 :   t = make_node (code);
    3729    257665968 :   length = TREE_CODE_LENGTH (code);
    3730    257665968 :   TREE_TYPE (t) = tt;
    3731              : 
    3732    688185942 :   for (i = 0; i < length; i++)
    3733              :     {
    3734    430519974 :       tree x = va_arg (p, tree);
    3735    430519974 :       TREE_OPERAND (t, i) = x;
    3736    430519974 :       if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x))
    3737      3394426 :         TREE_SIDE_EFFECTS (t) = 1;
    3738              :     }
    3739              : 
    3740    257665968 :   va_end (p);
    3741              : 
    3742    257665968 :   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    132135779 : build_min_non_dep (enum tree_code code, tree non_dep, ...)
    3751              : {
    3752    132135779 :   tree t;
    3753    132135779 :   int length;
    3754    132135779 :   int i;
    3755    132135779 :   va_list p;
    3756              : 
    3757    132135779 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    3758              : 
    3759    132135779 :   va_start (p, non_dep);
    3760              : 
    3761    132135779 :   if (REFERENCE_REF_P (non_dep))
    3762      1326958 :     non_dep = TREE_OPERAND (non_dep, 0);
    3763              : 
    3764    132135779 :   t = make_node (code);
    3765    178119152 :   SET_EXPR_LOCATION (t, cp_expr_loc_or_input_loc (non_dep));
    3766    132135779 :   length = TREE_CODE_LENGTH (code);
    3767    132135779 :   TREE_TYPE (t) = unlowered_expr_type (non_dep);
    3768    132135779 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3769              : 
    3770    463404570 :   for (i = 0; i < length; i++)
    3771              :     {
    3772    331268791 :       tree x = va_arg (p, tree);
    3773    331268791 :       TREE_OPERAND (t, i) = x;
    3774    331268791 :       if (x && !TYPE_P (x))
    3775    260871228 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3776              :     }
    3777              : 
    3778    132135779 :   va_end (p);
    3779    132135779 :   return convert_from_reference (t);
    3780              : }
    3781              : 
    3782              : /* Similar to build_min_nt, but call expressions  */
    3783              : 
    3784              : tree
    3785    234131181 : build_min_nt_call_vec (tree fn, vec<tree, va_gc> *args)
    3786              : {
    3787    234131181 :   tree ret, t;
    3788    234131181 :   unsigned int ix;
    3789              : 
    3790    468177093 :   ret = build_vl_exp (CALL_EXPR, vec_safe_length (args) + 3);
    3791    234131181 :   CALL_EXPR_FN (ret) = fn;
    3792    234131181 :   CALL_EXPR_STATIC_CHAIN (ret) = NULL_TREE;
    3793    494710463 :   FOR_EACH_VEC_SAFE_ELT (args, ix, t)
    3794    260579282 :     CALL_EXPR_ARG (ret, ix) = t;
    3795              : 
    3796    234131181 :   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     13701577 : build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec)
    3805              : {
    3806     13701577 :   tree t = build_min_nt_call_vec (fn, argvec);
    3807     13701577 :   if (REFERENCE_REF_P (non_dep))
    3808            6 :     non_dep = TREE_OPERAND (non_dep, 0);
    3809     13701577 :   TREE_TYPE (t) = TREE_TYPE (non_dep);
    3810     13701577 :   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
    3811     13701577 :   if (argvec)
    3812     28144982 :     for (tree x : *argvec)
    3813     14528674 :       if (x && !TYPE_P (x))
    3814     14528674 :         TREE_SIDE_EFFECTS (t) |= TREE_SIDE_EFFECTS (x);
    3815     13701577 :   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      6514891 : build_min_non_dep_op_overload (enum tree_code op,
    3826              :                                tree non_dep,
    3827              :                                tree overload, ...)
    3828              : {
    3829      6514891 :   va_list p;
    3830      6514891 :   int nargs, expected_nargs;
    3831      6514891 :   tree fn, call, obj = NULL_TREE;
    3832              : 
    3833      6514891 :   releasing_vec args;
    3834      6514891 :   va_start (p, overload);
    3835              : 
    3836      6514891 :   bool negated = false, rewritten = false, reversed = false;
    3837      6514891 :   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       545479 :       gcc_checking_assert (TREE_CODE_CLASS (op) == tcc_comparison
    3843              :                            || op == SPACESHIP_EXPR);
    3844       545479 :       int flags = TREE_INT_CST_LOW (TREE_PURPOSE (overload));
    3845       545479 :       if (TREE_CODE (non_dep) == TRUTH_NOT_EXPR)
    3846              :         {
    3847       498351 :           negated = true;
    3848       498351 :           non_dep = TREE_OPERAND (non_dep, 0);
    3849              :         }
    3850       545479 :       if (flags & LOOKUP_REWRITTEN)
    3851       545479 :         rewritten = true;
    3852       545479 :       if (flags & LOOKUP_REVERSED)
    3853          121 :         reversed = true;
    3854       545479 :       if (rewritten
    3855       545479 :           && 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        47106 :           tree spaceship_non_dep = (TREE_CODE (non_dep) == CALL_EXPR
    3863        94095 :                                     ? CALL_EXPR_ARG (non_dep, reversed ? 1 : 0)
    3864        47142 :                                     : TREE_OPERAND (non_dep, reversed ? 1 : 0));
    3865              : 
    3866        47106 :           tree int_promotion = NULL_TREE;
    3867        47106 :           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        47106 :           gcc_checking_assert (TREE_CODE (spaceship_non_dep) == CALL_EXPR);
    3875        47106 :           tree spaceship_op0 = va_arg (p, tree);
    3876        47106 :           tree spaceship_op1 = va_arg (p, tree);
    3877        47106 :           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        47106 :           tree op0 = build_min_non_dep_op_overload (SPACESHIP_EXPR,
    3883              :                                                     spaceship_non_dep,
    3884        47106 :                                                     TREE_VALUE (overload),
    3885              :                                                     spaceship_op0,
    3886        47106 :                                                     spaceship_op1);
    3887        47106 :           tree op1 = (TREE_CODE (non_dep) == CALL_EXPR
    3888        94176 :                       ? CALL_EXPR_ARG (non_dep, reversed ? 0 : 1)
    3889          117 :                       : TREE_OPERAND (non_dep, reversed ? 0 : 1));
    3890        47106 :           gcc_checking_assert (integer_zerop (op1));
    3891              : 
    3892        47106 :           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        47025 :           vec_safe_push (args, op0);
    3904        47025 :           vec_safe_push (args, op1);
    3905        47025 :           overload = CALL_EXPR_FN (non_dep);
    3906              :         }
    3907              :       else
    3908       498373 :         overload = TREE_VALUE (overload);
    3909              :     }
    3910      6514810 :   non_dep = extract_call_expr (non_dep);
    3911              : 
    3912      6514810 :   nargs = call_expr_nargs (non_dep);
    3913              : 
    3914      6514810 :   expected_nargs = cp_tree_code_length (op);
    3915     12280532 :   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     12278105 :       || op == ARRAY_REF)
    3922       751524 :     expected_nargs -= 1;
    3923      6514810 :   if ((op == POSTINCREMENT_EXPR
    3924      6514810 :        || op == POSTDECREMENT_EXPR)
    3925              :       /* With -fpermissive non_dep could be operator++().  */
    3926        11551 :       && (!flag_permissive || nargs != expected_nargs))
    3927        11548 :     expected_nargs += 1;
    3928      6514810 :   gcc_assert (nargs == expected_nargs);
    3929              : 
    3930      6514810 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (overload))
    3931              :     {
    3932      5763295 :       fn = overload;
    3933      5763295 :       if (vec_safe_length (args) != 0)
    3934              :         /* The correct arguments were already pushed above.  */
    3935        47025 :         gcc_checking_assert (rewritten);
    3936              :       else
    3937              :         {
    3938      5716270 :           if (op == ARRAY_REF)
    3939            9 :             obj = va_arg (p, tree);
    3940     17064088 :           for (int i = 0; i < nargs; i++)
    3941              :             {
    3942     11347818 :               tree arg = va_arg (p, tree);
    3943     11347818 :               vec_safe_push (args, arg);
    3944              :             }
    3945              :         }
    3946      5763295 :       if (reversed)
    3947           52 :         std::swap ((*args)[0], (*args)[1]);
    3948              :     }
    3949              :   else
    3950              :     {
    3951       751515 :       gcc_checking_assert (vec_safe_length (args) == 0);
    3952       751515 :       tree object = va_arg (p, tree);
    3953      2013515 :       for (int i = 0; i < nargs; i++)
    3954              :         {
    3955       510485 :           tree arg = va_arg (p, tree);
    3956       510485 :           vec_safe_push (args, arg);
    3957              :         }
    3958       751515 :       if (reversed)
    3959           24 :         std::swap (object, (*args)[0]);
    3960       751515 :       tree binfo = TYPE_BINFO (TREE_TYPE (object));
    3961       751515 :       tree method = build_baselink (binfo, binfo, overload, NULL_TREE);
    3962       751515 :       fn = build_min (COMPONENT_REF, TREE_TYPE (overload),
    3963              :                       object, method, NULL_TREE);
    3964              :     }
    3965              : 
    3966      6514810 :   va_end (p);
    3967      6514810 :   call = build_min_non_dep_call_vec (non_dep, fn, args);
    3968              : 
    3969      6514810 :   tree call_expr = extract_call_expr (call);
    3970      6514810 :   KOENIG_LOOKUP_P (call_expr) = KOENIG_LOOKUP_P (non_dep);
    3971      6514810 :   CALL_EXPR_OPERATOR_SYNTAX (call_expr) = true;
    3972      6514810 :   CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (non_dep);
    3973      6514810 :   CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (non_dep);
    3974              : 
    3975      6514810 :   if (negated)
    3976       498351 :     call = build_min (TRUTH_NOT_EXPR, boolean_type_node, call);
    3977      6514810 :   if (obj)
    3978            9 :     return keep_unused_object_arg (call, obj, overload);
    3979              :   return call;
    3980      6514891 : }
    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         9425 : vec_copy_and_insert (vec<tree, va_gc> *old_vec, tree elt, unsigned idx)
    4020              : {
    4021         9425 :   unsigned len = vec_safe_length (old_vec);
    4022         9425 :   gcc_assert (idx <= len);
    4023              : 
    4024         9425 :   vec<tree, va_gc> *new_vec = NULL;
    4025         9425 :   vec_alloc (new_vec, len + 1);
    4026              : 
    4027         9425 :   unsigned i;
    4028        28336 :   for (i = 0; i < len; ++i)
    4029              :     {
    4030         9486 :       if (i == idx)
    4031           61 :         new_vec->quick_push (elt);
    4032         9486 :       new_vec->quick_push ((*old_vec)[i]);
    4033              :     }
    4034         9425 :   if (i == idx)
    4035         9364 :     new_vec->quick_push (elt);
    4036              : 
    4037         9425 :   return new_vec;
    4038              : }
    4039              : 
    4040              : tree
    4041       150393 : get_type_decl (tree t)
    4042              : {
    4043       150393 :   if (TREE_CODE (t) == TYPE_DECL)
    4044              :     return t;
    4045       150393 :   if (TYPE_P (t))
    4046       150393 :     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   1360088355 : decl_namespace_context (tree decl)
    4056              : {
    4057   2824431459 :   while (1)
    4058              :     {
    4059   2824431459 :       if (TREE_CODE (decl) == NAMESPACE_DECL)
    4060   1360088355 :         return decl;
    4061   1464343104 :       else if (TYPE_P (decl))
    4062    888042742 :         decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
    4063              :       else
    4064    576300362 :         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   1401270170 : decl_internal_context_p (const_tree decl)
    4081              : {
    4082   2807624308 :   while (TREE_CODE (decl) != NAMESPACE_DECL)
    4083              :     {
    4084              :       /* Classes inside anonymous namespaces have TREE_PUBLIC == 0.  */
    4085   1771017627 :       if (TYPE_P (decl))
    4086    364663489 :         return !TREE_PUBLIC (TYPE_MAIN_DECL (decl));
    4087              : 
    4088   1406354138 :       decl = CP_DECL_CONTEXT (decl);
    4089              :     }
    4090   1036606681 :   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     54827130 : 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     54827130 :   tree name1 = call_expr_dependent_name (t1);
    4102     54827130 :   tree name2 = call_expr_dependent_name (t2);
    4103     54827130 :   t1 = CALL_EXPR_FN (t1);
    4104     54827130 :   t2 = CALL_EXPR_FN (t2);
    4105     54827130 :   if (name1 || name2)
    4106              :     {
    4107     47146618 :       tree targs1 = NULL_TREE, targs2 = NULL_TREE;
    4108              : 
    4109     47146618 :       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     46389788 :       if (is_overloaded_fn (t1) && is_overloaded_fn (t2)
    4117     92813067 :           && (DECL_CONTEXT (get_first_fn (t1))
    4118     46389785 :               != DECL_CONTEXT (get_first_fn (t2))))
    4119              :         return false;
    4120              : 
    4121     46423282 :       if (TREE_CODE (t1) == TEMPLATE_ID_EXPR)
    4122     29042021 :         targs1 = TREE_OPERAND (t1, 1);
    4123     46423282 :       if (TREE_CODE (t2) == TEMPLATE_ID_EXPR)
    4124     29042021 :         targs2 = TREE_OPERAND (t2, 1);
    4125     46423282 :       return cp_tree_equal (targs1, targs2);
    4126              :     }
    4127              :   else
    4128      7680512 :     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   2738777606 : cp_tree_equal (tree t1, tree t2)
    4136              : {
    4137   2746935278 :   enum tree_code code1, code2;
    4138              : 
    4139   2746935278 :   if (t1 == t2)
    4140              :     return true;
    4141   1250317836 :   if (!t1 || !t2)
    4142              :     return false;
    4143              : 
    4144   1249585493 :   code1 = TREE_CODE (t1);
    4145   1249585493 :   code2 = TREE_CODE (t2);
    4146              : 
    4147   1249585493 :   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   1249585493 :   if (code1 != code2)
    4168              :     return false;
    4169              : 
    4170   1132251201 :   if (CONSTANT_CLASS_P (t1)
    4171   1132251201 :       && !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
    4172              :     return false;
    4173              : 
    4174   1132165701 :   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    177738926 :     case INTEGER_CST:
    4182    177738926 :       return tree_int_cst_equal (t1, t2);
    4183              : 
    4184       112295 :     case REAL_CST:
    4185       112295 :       return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
    4186              : 
    4187       152905 :     case STRING_CST:
    4188       152905 :       return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
    4189       152905 :         && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
    4190       152905 :                     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      1580308 :     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      1580308 :       if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
    4208      3416379 :           || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2))
    4209              :         return false;
    4210              :       {
    4211              :         tree field, value;
    4212              :         unsigned int i;
    4213      1727551 :         FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value)
    4214              :           {
    4215       194076 :             constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i);
    4216       194076 :             if (!cp_tree_equal (field, elt2->index)
    4217       194076 :                 || !cp_tree_equal (value, elt2->value))
    4218              :               return false;
    4219              :           }
    4220              :       }
    4221              :       return true;
    4222              : 
    4223      6122250 :     case TREE_LIST:
    4224      6122250 :       if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
    4225              :         return false;
    4226      6122250 :       if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
    4227              :         return false;
    4228        28322 :       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     54986182 :     case CALL_EXPR:
    4234     54986182 :       {
    4235     54986182 :         if (KOENIG_LOOKUP_P (t1) != KOENIG_LOOKUP_P (t2))
    4236              :           return false;
    4237              : 
    4238     54827130 :         if (!called_fns_equal (t1, t2))
    4239              :           return false;
    4240              : 
    4241     24880210 :         call_expr_arg_iterator iter1, iter2;
    4242     24880210 :         init_call_expr_arg_iterator (t1, &iter1);
    4243     24880210 :         init_call_expr_arg_iterator (t2, &iter2);
    4244     24880210 :         if (iter1.n != iter2.n)
    4245              :           return false;
    4246              : 
    4247     26421101 :         while (more_call_expr_args_p (&iter1))
    4248              :           {
    4249     18136049 :             tree arg1 = next_call_expr_arg (&iter1);
    4250     18136049 :             tree arg2 = next_call_expr_arg (&iter2);
    4251              : 
    4252     18136049 :             gcc_checking_assert (arg1 && arg2);
    4253     18136049 :             if (!cp_tree_equal (arg1, arg2))
    4254              :               return false;
    4255              :           }
    4256              : 
    4257              :         return true;
    4258              :       }
    4259              : 
    4260       427623 :     case TARGET_EXPR:
    4261       427623 :       {
    4262       427623 :         tree o1 = TARGET_EXPR_SLOT (t1);
    4263       427623 :         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       427623 :         if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
    4270       855246 :             && !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       427623 :         return cp_tree_equal (TARGET_EXPR_INITIAL (t1),
    4279       855246 :                               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      1967707 :     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      1967707 :       if (comparing_specializations
    4322      1967707 :           && 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      1571473 :       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       802179 :           if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
    4338              :             return false;
    4339       802179 :           if (CONSTRAINT_VAR_P (t1) ^ CONSTRAINT_VAR_P (t2))
    4340              :             return false;
    4341       802179 :           if (DECL_ARTIFICIAL (t1)
    4342       802179 :               || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
    4343       801540 :                   && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
    4344              :             return true;
    4345              :         }
    4346              :       return false;
    4347              : 
    4348     33713772 :     case TEMPLATE_DECL:
    4349     33713772 :       if (DECL_TEMPLATE_TEMPLATE_PARM_P (t1)
    4350     34900184 :           && DECL_TEMPLATE_TEMPLATE_PARM_P (t2))
    4351       168704 :         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      5203390 :     case BASELINK:
    4365      5203390 :       return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2)
    4366      4430588 :               && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2)
    4367      4430588 :               && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2)
    4368      9633966 :               && cp_tree_equal (BASELINK_FUNCTIONS (t1),
    4369      4430576 :                                 BASELINK_FUNCTIONS (t2)));
    4370              : 
    4371     14096084 :     case TEMPLATE_PARM_INDEX:
    4372     14096084 :       return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
    4373     13384700 :               && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
    4374     12761698 :               && (TEMPLATE_PARM_PARAMETER_PACK (t1)
    4375     12761698 :                   == TEMPLATE_PARM_PARAMETER_PACK (t2))
    4376     26810715 :               && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
    4377              :                               TREE_TYPE (TEMPLATE_PARM_DECL (t2))));
    4378              : 
    4379     22580187 :     case TEMPLATE_ID_EXPR:
    4380     22580187 :       if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4381              :         return false;
    4382     21838342 :       if (!comp_template_args (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)))
    4383              :         return false;
    4384              :       return true;
    4385              : 
    4386      7530643 :     case CONSTRAINT_INFO:
    4387     22591929 :       return cp_tree_equal (CI_ASSOCIATED_CONSTRAINTS (t1),
    4388     22591929 :                             CI_ASSOCIATED_CONSTRAINTS (t2));
    4389              : 
    4390     57319507 :     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     57319507 :       if (!comp_template_args (t1, t2))
    4394              :         return false;
    4395              :       return true;
    4396              : 
    4397      1642124 :     case SIZEOF_EXPR:
    4398      1642124 :     case ALIGNOF_EXPR:
    4399      1642124 :       {
    4400      1642124 :         tree o1 = TREE_OPERAND (t1, 0);
    4401      1642124 :         tree o2 = TREE_OPERAND (t2, 0);
    4402              : 
    4403      1642124 :         if (code1 == SIZEOF_EXPR)
    4404              :           {
    4405      1632684 :             if (SIZEOF_EXPR_TYPE_P (t1))
    4406            0 :               o1 = TREE_TYPE (o1);
    4407      1632684 :             if (SIZEOF_EXPR_TYPE_P (t2))
    4408            0 :               o2 = TREE_TYPE (o2);
    4409              :           }
    4410         9440 :         else if (ALIGNOF_EXPR_STD_P (t1) != ALIGNOF_EXPR_STD_P (t2))
    4411              :           return false;
    4412              : 
    4413      1642118 :         if (TREE_CODE (o1) != TREE_CODE (o2))
    4414              :           return false;
    4415              : 
    4416      1642088 :         if (ARGUMENT_PACK_P (o1))
    4417           10 :           return template_args_equal (o1, o2);
    4418      1642078 :         else if (TYPE_P (o1))
    4419      1640718 :           return same_type_p (o1, o2);
    4420              :         else
    4421              :           return cp_tree_equal (o1, o2);
    4422              :       }
    4423              : 
    4424         3108 :     case MODOP_EXPR:
    4425         3108 :       {
    4426         3108 :         tree t1_op1, t2_op1;
    4427              : 
    4428         3108 :         if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
    4429              :           return false;
    4430              : 
    4431         2620 :         t1_op1 = TREE_OPERAND (t1, 1);
    4432         2620 :         t2_op1 = TREE_OPERAND (t2, 1);
    4433         2620 :         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        20952 :     case OVERLOAD:
    4448        20952 :       {
    4449              :         /* Two overloads. Must be exactly the same set of decls.  */
    4450        20952 :         lkp_iterator first (t1);
    4451        20952 :         lkp_iterator second (t2);
    4452              : 
    4453        30186 :         for (; first && second; ++first, ++second)
    4454        21495 :           if (*first != *second)
    4455              :             return false;
    4456         8691 :         return !(first || second);
    4457              :       }
    4458              : 
    4459      7769067 :     case TRAIT_EXPR:
    4460      7769067 :       if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2))
    4461              :         return false;
    4462       793253 :       return cp_tree_equal (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2))
    4463      1570301 :         && cp_tree_equal (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2));
    4464              : 
    4465      1146721 :     case NON_LVALUE_EXPR:
    4466      1146721 :     case VIEW_CONVERT_EXPR:
    4467              :       /* Used for location wrappers with possibly NULL types.  */
    4468      1146721 :       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      3382296 :     case CAST_EXPR:
    4477      3382296 :     case STATIC_CAST_EXPR:
    4478      3382296 :     case REINTERPRET_CAST_EXPR:
    4479      3382296 :     case CONST_CAST_EXPR:
    4480      3382296 :     case DYNAMIC_CAST_EXPR:
    4481      3382296 :     case IMPLICIT_CONV_EXPR:
    4482      3382296 :     case NEW_EXPR:
    4483      3382296 :     case BIT_CAST_EXPR:
    4484      3382296 :     CASE_CONVERT:
    4485      3382296 :       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    631988768 :     case TYPE_ARGUMENT_PACK:
    4501    631988768 :     case NONTYPE_ARGUMENT_PACK:
    4502    631988768 :       {
    4503    631988768 :         tree p1 = ARGUMENT_PACK_ARGS (t1);
    4504    631988768 :         tree p2 = ARGUMENT_PACK_ARGS (t2);
    4505    631988768 :         int len = TREE_VEC_LENGTH (p1);
    4506    631988768 :         if (TREE_VEC_LENGTH (p2) != len)
    4507              :           return false;
    4508              : 
    4509    761499416 :         for (int ix = 0; ix != len; ix++)
    4510    676397576 :           if (!template_args_equal (TREE_VEC_ELT (p1, ix),
    4511    676397576 :                                     TREE_VEC_ELT (p2, ix)))
    4512              :             return false;
    4513              :         return true;
    4514              :       }
    4515              : 
    4516       772114 :     case EXPR_PACK_EXPANSION:
    4517       772114 :       if (!cp_tree_equal (PACK_EXPANSION_PATTERN (t1),
    4518       772114 :                           PACK_EXPANSION_PATTERN (t2)))
    4519              :         return false;
    4520        26142 :       if (!comp_template_args (PACK_EXPANSION_EXTRA_ARGS (t1),
    4521        26142 :                                PACK_EXPANSION_EXTRA_ARGS (t2)))
    4522              :         return false;
    4523              :       return true;
    4524              : 
    4525         2230 :     case PACK_INDEX_EXPR:
    4526         2230 :       if (!cp_tree_equal (PACK_INDEX_PACK (t1),
    4527         2230 :                           PACK_INDEX_PACK (t2)))
    4528              :         return false;
    4529          106 :       if (!cp_tree_equal (PACK_INDEX_INDEX (t1),
    4530          106 :                           PACK_INDEX_INDEX (t2)))
    4531              :         return false;
    4532              :       return true;
    4533              : 
    4534         2086 :     case REFLECT_EXPR:
    4535         2086 :       return compare_reflections (t1, t2);
    4536              : 
    4537      6261305 :     case REQUIRES_EXPR:
    4538     12522610 :       if (cp_tree_equal (REQUIRES_EXPR_PARMS (t1),
    4539      6261305 :                           REQUIRES_EXPR_PARMS (t2))
    4540      6090639 :           && cp_tree_equal (REQUIRES_EXPR_REQS (t1),
    4541      6090639 :                             REQUIRES_EXPR_REQS (t2))
    4542      6271573 :           && 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     63211829 :   switch (TREE_CODE_CLASS (code1))
    4552              :     {
    4553     60372182 :     case tcc_unary:
    4554     60372182 :     case tcc_binary:
    4555     60372182 :     case tcc_comparison:
    4556     60372182 :     case tcc_expression:
    4557     60372182 :     case tcc_vl_exp:
    4558     60372182 :     case tcc_reference:
    4559     60372182 :     case tcc_statement:
    4560     60372182 :       {
    4561     60372182 :         int n = cp_tree_operand_length (t1);
    4562     60372182 :         if (TREE_CODE_CLASS (code1) == tcc_vl_exp
    4563     60372182 :             && n != TREE_OPERAND_LENGTH (t2))
    4564              :           return false;
    4565              : 
    4566    104339581 :         for (int i = 0; i < n; ++i)
    4567     77588804 :           if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
    4568              :             return false;
    4569              : 
    4570              :         return true;
    4571              :       }
    4572              : 
    4573      2839647 :     case tcc_type:
    4574      2839647 :       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    903724203 : lvalue_type (tree arg)
    4588              : {
    4589    903724203 :   tree type = TREE_TYPE (arg);
    4590    903724203 :   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       512662 : varargs_function_p (const_tree function)
    4617              : {
    4618       512662 :   return stdarg_p (TREE_TYPE (function));
    4619              : }
    4620              : 
    4621              : /* Returns 1 if decl is a member of a class.  */
    4622              : 
    4623              : int
    4624        11455 : member_p (const_tree decl)
    4625              : {
    4626        11455 :   const_tree const ctx = DECL_CONTEXT (decl);
    4627        11455 :   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     86822774 : build_dummy_object (tree type)
    4636              : {
    4637     86822774 :   tree decl = build1 (CONVERT_EXPR, build_pointer_type (type), void_node);
    4638     86822774 :   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    114039548 : maybe_dummy_object (tree type, tree* binfop)
    4647              : {
    4648    114039548 :   tree decl, context;
    4649    114039548 :   tree binfo;
    4650    114039548 :   tree current = current_nonlambda_class_type ();
    4651              : 
    4652    114039548 :   if (current
    4653    114039548 :       && (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      8488568 :       context = type;
    4660      8488568 :       binfo = TYPE_BINFO (type);
    4661              :     }
    4662              : 
    4663    114039548 :   if (binfop)
    4664       111597 :     *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    114039548 :   tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE;
    4670    104733476 :   if (ctype
    4671    104733476 :       && same_type_ignoring_top_level_qualifiers_p (ctype, context))
    4672    101438067 :     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     12601481 :       if (ctype)
    4678              :         {
    4679      3295409 :           int quals = TYPE_UNQUALIFIED;
    4680      3295409 :           if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype))
    4681              :             {
    4682       424012 :               if (tree cap = lambda_expr_this_capture (lambda, false))
    4683       409131 :                 quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap)));
    4684              :             }
    4685              :           else
    4686      2871397 :             quals = cp_type_quals (ctype);
    4687      3295409 :           context = cp_build_qualified_type (context, quals);
    4688              :         }
    4689     12601481 :       decl = build_dummy_object (context);
    4690              :     }
    4691              : 
    4692    114039548 :   return decl;
    4693              : }
    4694              : 
    4695              : /* Returns 1 if OB is a placeholder object, or a pointer to one.  */
    4696              : 
    4697              : bool
    4698    539421769 : is_dummy_object (const_tree ob)
    4699              : {
    4700    539421769 :   if (INDIRECT_REF_P (ob))
    4701    413988958 :     ob = TREE_OPERAND (ob, 0);
    4702    539421769 :   return (TREE_CODE (ob) == CONVERT_EXPR
    4703    539421769 :           && TREE_OPERAND (ob, 0) == void_node);
    4704              : }
    4705              : 
    4706              : /* Returns true if TYPE is char, unsigned char, or std::byte.  */
    4707              : 
    4708              : bool
    4709     34755493 : is_byte_access_type (tree type)
    4710              : {
    4711     34755493 :   type = TYPE_MAIN_VARIANT (type);
    4712     34755493 :   if (type == char_type_node
    4713      7485879 :       || type == unsigned_char_type_node)
    4714              :     return true;
    4715              : 
    4716      7342652 :   return (TREE_CODE (type) == ENUMERAL_TYPE
    4717        28190 :           && TYPE_CONTEXT (type) == std_node
    4718      7361614 :           && !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     91946609 : scalarish_type_p (const_tree t)
    4738              : {
    4739     91946609 :   if (t == error_mark_node)
    4740              :     return 1;
    4741              : 
    4742     91946394 :   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    378720186 : maybe_warn_parm_abi (tree t, location_t loc)
    4771              : {
    4772    378720186 :   if (!deleted_copy_types
    4773    378720186 :       || !deleted_copy_types->contains (t))
    4774    378720156 :     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     60673851 : type_has_nontrivial_copy_init (const_tree type)
    4809              : {
    4810     60673851 :   tree t = strip_array_types (const_cast<tree> (type));
    4811              : 
    4812     60673851 :   if (CLASS_TYPE_P (t))
    4813              :     {
    4814     60000158 :       gcc_assert (COMPLETE_TYPE_P (t));
    4815              : 
    4816     60000158 :       if (TYPE_HAS_COMPLEX_COPY_CTOR (t)
    4817     60000158 :           || TYPE_HAS_COMPLEX_MOVE_CTOR (t))
    4818              :         /* Nontrivial.  */
    4819              :         return true;
    4820              : 
    4821     55841700 :       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     55739949 :       if (!abi_version_at_least (12)
    4828         8132 :           && !(warn_abi && abi_version_crosses (12)))
    4829              :         return false;
    4830              : 
    4831     55732047 :       bool saw_copy = false;
    4832     55732047 :       bool saw_non_deleted = false;
    4833     55732047 :       bool saw_non_deleted_move = false;
    4834              : 
    4835     55732047 :       if (CLASSTYPE_LAZY_MOVE_CTOR (t))
    4836              :         saw_copy = saw_non_deleted = true;
    4837      5104399 :       else if (CLASSTYPE_LAZY_COPY_CTOR (t))
    4838              :         {
    4839       600387 :           saw_copy = true;
    4840       600387 :           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     20471267 :         for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
    4853              :           {
    4854     12156513 :             tree fn = *iter;
    4855     12156513 :             if (copy_fn_p (fn))
    4856              :               {
    4857      4504067 :                 saw_copy = true;
    4858      4504067 :                 if (!DECL_DELETED_FN (fn))
    4859              :                   {
    4860              :                     /* Not deleted, therefore trivial.  */
    4861              :                     saw_non_deleted = true;
    4862              :                     break;
    4863              :                   }
    4864              :               }
    4865      7652446 :             else if (move_fn_p (fn))
    4866      3149865 :               if (!DECL_DELETED_FN (fn))
    4867      3127614 :                 saw_non_deleted_move = true;
    4868              :           }
    4869              : 
    4870     55732047 :       gcc_assert (saw_copy);
    4871              : 
    4872              :       /* ABI v12 buggily ignored move constructors.  */
    4873     55732047 :       bool v11nontriv = false;
    4874     55732047 :       bool v12nontriv = !saw_non_deleted;
    4875     55732047 :       bool v13nontriv = !saw_non_deleted && !saw_non_deleted_move;
    4876     55732047 :       bool nontriv = (abi_version_at_least (13) ? v13nontriv
    4877          124 :                       : flag_abi_version == 12 ? v12nontriv
    4878          124 :                       : v11nontriv);
    4879     55732047 :       bool warn_nontriv = (warn_abi_version >= 13 ? v13nontriv
    4880          428 :                            : warn_abi_version == 12 ? v12nontriv
    4881              :                            : v11nontriv);
    4882     55732047 :       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       554178 : trivially_copyable_p (const_tree t)
    4896              : {
    4897       554178 :   t = strip_array_types (const_cast<tree> (t));
    4898              : 
    4899       554178 :   if (CLASS_TYPE_P (t))
    4900        86710 :     return ((!TYPE_HAS_COPY_CTOR (t)
    4901        86710 :              || !TYPE_HAS_COMPLEX_COPY_CTOR (t))
    4902        85765 :             && !TYPE_HAS_COMPLEX_MOVE_CTOR (t)
    4903        85727 :             && (!TYPE_HAS_COPY_ASSIGN (t)
    4904        85727 :                 || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t))
    4905        84747 :             && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t)
    4906       171288 :             && TYPE_HAS_TRIVIAL_DESTRUCTOR (t));
    4907              :   else
    4908              :     /* CWG 2094 makes volatile-qualified scalars trivially copyable again.  */
    4909       467468 :     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        79003 : trivial_type_p (const_tree t)
    4917              : {
    4918        79003 :   t = strip_array_types (const_cast<tree> (t));
    4919              : 
    4920        79003 :   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        19934 :     return (type_has_non_deleted_trivial_default_ctor (const_cast<tree> (t))
    4924        19934 :             && trivially_copyable_p (t));
    4925              :   else
    4926        59069 :     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         1715 : implicit_lifetime_type_p (tree t)
    4962              : {
    4963         1715 :   if (SCALAR_TYPE_P (t)
    4964         1411 :       || (TREE_CODE (t) == ARRAY_TYPE
    4965          480 :           && !(TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t))))
    4966              :       /* GNU extension.  */
    4967          936 :       || TREE_CODE (t) == VECTOR_TYPE)
    4968              :     return true;
    4969          931 :   if (!CLASS_TYPE_P (t))
    4970              :     return false;
    4971          859 :   t = TYPE_MAIN_VARIANT (t);
    4972              :   /* It is an aggregate whose destructor is not user-provided.  */
    4973         1718 :   if (CP_AGGREGATE_TYPE_P (t)
    4974         1163 :       && (!CLASSTYPE_DESTRUCTOR (t)
    4975          219 :           || !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        11786 : 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        11786 :   t = strip_array_types (const_cast<tree>(t));
    5010              : 
    5011        11786 :   if (!CLASS_TYPE_P (t))
    5012          722 :     return scalarish_type_p (t);
    5013        11064 :   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        10743 :     return (std_layout_type_p (t) && trivial_type_p (t));
    5021              :   else
    5022              :     /* The C++98 definition of POD is different.  */
    5023          321 :     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     18733566 : layout_pod_type_p (const_tree t)
    5031              : {
    5032     18733566 :   t = strip_array_types (const_cast<tree> (t));
    5033              : 
    5034     18733566 :   if (CLASS_TYPE_P (t))
    5035      3787223 :     return !CLASSTYPE_NON_LAYOUT_POD_P (t);
    5036              :   else
    5037     14946343 :     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     18809802 : std_layout_type_p (const_tree t)
    5045              : {
    5046     18809802 :   t = strip_array_types (const_cast<tree> (t));
    5047              : 
    5048     18809802 :   if (CLASS_TYPE_P (t))
    5049      3801052 :     return !CLASSTYPE_NON_STD_LAYOUT (t);
    5050              :   else
    5051     15008750 :     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        61761 : type_has_unique_obj_representations (const_tree t, bool explain/*=false*/)
    5061              : {
    5062        71154 :   bool ret;
    5063              : 
    5064        71154 :   t = strip_array_types (const_cast<tree> (t));
    5065              : 
    5066        71154 :   if (t == error_mark_node)
    5067              :     return false;
    5068              : 
    5069        71151 :   location_t loc = input_location;
    5070        71151 :   if (tree m = TYPE_MAIN_DECL (t))
    5071         9631 :     loc = DECL_SOURCE_LOCATION (m);
    5072              : 
    5073        71151 :   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          237 :   if (CLASS_TYPE_P (t)
    5081          234 :       && CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t)
    5082        71244 :       && !explain)
    5083           96 :     return CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS (t);
    5084              : 
    5085        71025 :   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         9375 :     case ENUMERAL_TYPE:
    5100         9375 :       return type_has_unique_obj_representations (ENUM_UNDERLYING_TYPE (t),
    5101         9375 :                                                   explain);
    5102              : 
    5103        33096 :     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        33096 :       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          120 :     case RECORD_TYPE:
    5125          120 :       ret = record_has_unique_obj_representations (t, TYPE_SIZE (t), explain);
    5126          120 :       if (CLASS_TYPE_P (t))
    5127              :         {
    5128          117 :           CLASSTYPE_UNIQUE_OBJ_REPRESENTATIONS_SET (t) = 1;
    5129          117 :           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            0 :     default:
    5179            0 :       gcc_unreachable ();
    5180              :     }
    5181              : }
    5182              : 
    5183              : /* Helper function for type_has_unique_obj_representations.  */
    5184              : 
    5185              : static bool
    5186          131 : record_has_unique_obj_representations (const_tree t, const_tree sz,
    5187              :                                        bool explain)
    5188              : {
    5189          666 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5190          565 :     if (TREE_CODE (field) != FIELD_DECL)
    5191              :       ;
    5192              :     /* For bases, can't use type_has_unique_obj_representations here, as in
    5193              :         struct S { int i : 24; S (); };
    5194              :         struct T : public S { int j : 8; T (); };
    5195              :         S doesn't have unique obj representations, but T does.  */
    5196          180 :     else if (DECL_FIELD_IS_BASE (field))
    5197              :       {
    5198           11 :         if (!record_has_unique_obj_representations (TREE_TYPE (field),
    5199           11 :                                                     DECL_SIZE (field),
    5200              :                                                     /*explain=*/false))
    5201              :           {
    5202            6 :             if (explain)
    5203            3 :               inform (DECL_SOURCE_LOCATION (field),
    5204              :                       "base %qT does not have unique object representations",
    5205            3 :                       TREE_TYPE (field));
    5206              :             return false;
    5207              :           }
    5208              :       }
    5209          169 :     else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field))
    5210              :       {
    5211           59 :         tree btype = DECL_BIT_FIELD_TYPE (field);
    5212           59 :         if (!type_has_unique_obj_representations (btype))
    5213              :           {
    5214            0 :             if (explain)
    5215            0 :               inform (DECL_SOURCE_LOCATION (field),
    5216              :                       "%qD with type %qT does not have "
    5217              :                       "unique object representations",
    5218              :                       field, btype);
    5219              :             return false;
    5220              :           }
    5221              :       }
    5222          110 :     else if (!type_has_unique_obj_representations (TREE_TYPE (field)))
    5223              :       {
    5224           24 :         if (explain)
    5225            6 :           inform (DECL_SOURCE_LOCATION (field),
    5226              :                   "%qD with type %qT does not have "
    5227              :                   "unique object representations",
    5228            6 :                   field, TREE_TYPE (field));
    5229              :         return false;
    5230              :       }
    5231              : 
    5232          101 :   offset_int cur = 0;
    5233          101 :   tree last_field = NULL_TREE;
    5234          101 :   tree last_named_field = NULL_TREE;
    5235          565 :   for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5236          496 :     if (TREE_CODE (field) == FIELD_DECL)
    5237              :       {
    5238          144 :         if (DECL_UNNAMED_BIT_FIELD (field))
    5239              :           {
    5240           16 :             last_field = field;
    5241           16 :             continue;
    5242              :           }
    5243          128 :         offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field));
    5244          128 :         offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
    5245          128 :         fld = fld * BITS_PER_UNIT + bitpos;
    5246          128 :         if (cur != fld)
    5247              :           {
    5248           32 :             if (explain)
    5249              :               {
    5250            6 :                 if (last_named_field)
    5251            3 :                   inform (DECL_SOURCE_LOCATION (last_named_field),
    5252              :                           "padding occurs between %qD and %qD",
    5253              :                           last_named_field, field);
    5254            3 :                 else if (last_field)
    5255            3 :                   inform (DECL_SOURCE_LOCATION (last_field),
    5256              :                           "unnamed bit-field inserts padding before %qD",
    5257              :                           field);
    5258              :                 else
    5259            0 :                   inform (DECL_SOURCE_LOCATION (field),
    5260              :                           "padding occurs before %qD", field);
    5261              :               }
    5262           32 :             return false;
    5263              :           }
    5264           96 :         if (DECL_SIZE (field))
    5265              :           {
    5266           93 :             offset_int size = wi::to_offset (DECL_SIZE (field));
    5267           93 :             cur += size;
    5268              :           }
    5269           96 :         last_named_field = last_field = field;
    5270              :       }
    5271           69 :   if (cur != wi::to_offset (sz))
    5272              :     {
    5273           33 :       if (explain)
    5274              :         {
    5275            6 :           if (last_named_field)
    5276            3 :             inform (DECL_SOURCE_LOCATION (last_named_field),
    5277              :                     "padding occurs after %qD", last_named_field);
    5278              :           else
    5279            3 :             inform (location_of (const_cast <tree> (t)),
    5280              :                     "%qT has padding and no data fields", t);
    5281              :         }
    5282              :       return false;
    5283              :     }
    5284              : 
    5285              :   return true;
    5286              : }
    5287              : 
    5288              : /* Nonzero iff type T is a class template implicit specialization.  */
    5289              : 
    5290              : bool
    5291    140985546 : class_tmpl_impl_spec_p (const_tree t)
    5292              : {
    5293    140985546 :   return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t);
    5294              : }
    5295              : 
    5296              : /* Returns 1 iff zero initialization of type T means actually storing
    5297              :    zeros in it.  */
    5298              : 
    5299              : int
    5300     21006656 : zero_init_p (const_tree t)
    5301              : {
    5302              :   /* This CONST_CAST is okay because strip_array_types returns its
    5303              :      argument unmodified and we assign it to a const_tree.  */
    5304     21006656 :   t = strip_array_types (const_cast<tree> (t));
    5305              : 
    5306     21006656 :   if (t == error_mark_node)
    5307              :     return 1;
    5308              : 
    5309              :   /* NULL pointers to data members are initialized with -1.  */
    5310     21006656 :   if (TYPE_PTRDATAMEM_P (t))
    5311              :     return 0;
    5312              : 
    5313              :   /* Classes that contain types that can't be zero-initialized, cannot
    5314              :      be zero-initialized themselves.  */
    5315     21006053 :   if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t))
    5316          143 :     return 0;
    5317              : 
    5318              :   return 1;
    5319              : }
    5320              : 
    5321              : /* Returns true if the expression or initializer T is the result of
    5322              :    zero-initialization for its type, taking pointers to members
    5323              :    into consideration.  */
    5324              : 
    5325              : bool
    5326       685035 : zero_init_expr_p (tree t)
    5327              : {
    5328       685035 :   tree type = TREE_TYPE (t);
    5329       685035 :   if (!type || uses_template_parms (type))
    5330              :     return false;
    5331       685035 :   if (TYPE_PTRMEM_P (type))
    5332         1224 :     return null_member_pointer_value_p (t);
    5333       683811 :   if (REFLECTION_TYPE_P (type))
    5334          396 :     return null_reflection_p (t);
    5335       683415 :   if (TREE_CODE (t) == CONSTRUCTOR)
    5336              :     {
    5337       282360 :       if (COMPOUND_LITERAL_P (t)
    5338       282360 :           || BRACE_ENCLOSED_INITIALIZER_P (t))
    5339              :         /* Undigested, conversions might change the zeroness.  */
    5340              :         return false;
    5341       849640 :       for (constructor_elt &elt : CONSTRUCTOR_ELTS (t))
    5342              :         {
    5343       289147 :           if (TREE_CODE (type) == UNION_TYPE
    5344       289147 :               && elt.index != first_field (type))
    5345              :             return false;
    5346       289136 :           if (!zero_init_expr_p (elt.value))
    5347              :             return false;
    5348              :         }
    5349              :       return true;
    5350              :     }
    5351       401055 :   if (zero_init_p (type))
    5352       401055 :     return initializer_zerop (t);
    5353              :   return false;
    5354              : }
    5355              : 
    5356              : /* True IFF T is a C++20 structural type (P1907R1) that can be used as a
    5357              :    non-type template parameter.  If EXPLAIN, explain why not.  */
    5358              : 
    5359              : bool
    5360       212445 : structural_type_p (tree t, bool explain)
    5361              : {
    5362              :   /* A structural type is one of the following: */
    5363              : 
    5364              :   /* a scalar type, or */
    5365       212445 :   if (SCALAR_TYPE_P (t))
    5366              :     return true;
    5367              :   /* an lvalue reference type, or */
    5368       106420 :   if (TYPE_REF_P (t) && !TYPE_REF_IS_RVALUE (t))
    5369              :     return true;
    5370              :   /* a literal class type with the following properties:
    5371              :      - all base classes and non-static data members are public and non-mutable
    5372              :        and
    5373              :      - the types of all bases classes and non-static data members are
    5374              :        structural types or (possibly multi-dimensional) array thereof.  */
    5375       106404 :   if (!CLASS_TYPE_P (t))
    5376              :     return false;
    5377       106364 :   if (!literal_type_p (t))
    5378              :     {
    5379           52 :       if (explain)
    5380           10 :         explain_non_literal_class (t);
    5381              :       return false;
    5382              :     }
    5383       234516 :   for (tree m = next_aggregate_field (TYPE_FIELDS (t)); m;
    5384       128204 :        m = next_aggregate_field (DECL_CHAIN (m)))
    5385              :     {
    5386       128537 :       if (TREE_PRIVATE (m) || TREE_PROTECTED (m))
    5387              :         {
    5388          255 :           if (explain)
    5389              :             {
    5390           97 :               if (DECL_FIELD_IS_BASE (m))
    5391            3 :                 inform (location_of (m), "base class %qT is not public",
    5392            3 :                         TREE_TYPE (m));
    5393              :               else
    5394           94 :                 inform (location_of (m), "%qD is not public", m);
    5395              :             }
    5396              :           return false;
    5397              :         }
    5398       128282 :       if (DECL_MUTABLE_P (m))
    5399              :         {
    5400           58 :           if (explain)
    5401            8 :             inform (location_of (m), "%qD is mutable", m);
    5402              :           return false;
    5403              :         }
    5404       128224 :       tree mtype = strip_array_types (TREE_TYPE (m));
    5405       128224 :       if (!structural_type_p (mtype))
    5406              :         {
    5407           20 :           if (explain)
    5408              :             {
    5409            2 :               inform (location_of (m), "%qD has a non-structural type", m);
    5410            2 :               structural_type_p (mtype, true);
    5411              :             }
    5412              :           return false;
    5413              :         }
    5414              :     }
    5415              :   return true;
    5416              : }
    5417              : 
    5418              : /* Partially handle the C++11 [[carries_dependency]] attribute.
    5419              :    Just emit a different diagnostics when it is used on something the
    5420              :    spec doesn't allow vs. where it allows and we just choose to ignore
    5421              :    it.  */
    5422              : 
    5423              : static tree
    5424          142 : handle_carries_dependency_attribute (tree *node, tree name,
    5425              :                                      tree ARG_UNUSED (args),
    5426              :                                      int ARG_UNUSED (flags),
    5427              :                                      bool *no_add_attrs)
    5428              : {
    5429          142 :   if (TREE_CODE (*node) != FUNCTION_DECL
    5430          121 :       && TREE_CODE (*node) != PARM_DECL)
    5431              :     {
    5432           76 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5433              :                "functions or parameters", name);
    5434           76 :       *no_add_attrs = true;
    5435              :     }
    5436              :   else
    5437              :     {
    5438           66 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5439           66 :       *no_add_attrs = true;
    5440              :     }
    5441          142 :   return NULL_TREE;
    5442              : }
    5443              : 
    5444              : /* Handle the C++17 [[nodiscard]] attribute, which is similar to the GNU
    5445              :    warn_unused_result attribute.  */
    5446              : 
    5447              : static tree
    5448     13826740 : handle_nodiscard_attribute (tree *node, tree name, tree args,
    5449              :                             int /*flags*/, bool *no_add_attrs)
    5450              : {
    5451     13826908 :   if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    5452              :     {
    5453            6 :       error ("%qE attribute argument must be a string constant", name);
    5454            6 :       *no_add_attrs = true;
    5455              :     }
    5456     13826740 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    5457              :     {
    5458     13825584 :       if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))
    5459     13929311 :           && !DECL_CONSTRUCTOR_P (*node))
    5460            9 :         warning_at (DECL_SOURCE_LOCATION (*node),
    5461            9 :                     OPT_Wattributes, "%qE attribute applied to %qD with void "
    5462              :                     "return type", name, *node);
    5463              :     }
    5464         1156 :   else if (OVERLOAD_TYPE_P (*node))
    5465              :     /* OK */;
    5466              :   else
    5467              :     {
    5468          148 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5469              :                "functions or to class or enumeration types", name);
    5470          148 :       *no_add_attrs = true;
    5471              :     }
    5472     13826740 :   return NULL_TREE;
    5473              : }
    5474              : 
    5475              : /* Handle a C++20 "no_unique_address" attribute; arguments as in
    5476              :    struct attribute_spec.handler.  */
    5477              : static tree
    5478       744401 : handle_no_unique_addr_attribute (tree* node,
    5479              :                                  tree name,
    5480              :                                  tree /*args*/,
    5481              :                                  int /*flags*/,
    5482              :                                  bool* no_add_attrs)
    5483              : {
    5484       744401 :   if (TREE_CODE (*node) == VAR_DECL)
    5485              :     {
    5486           48 :       DECL_MERGEABLE (*node) = true;
    5487           48 :       if (pedantic)
    5488           42 :         warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5489              :                  "non-static data members", name);
    5490              :     }
    5491       744353 :   else if (TREE_CODE (*node) != FIELD_DECL)
    5492              :     {
    5493           82 :       warning (OPT_Wattributes, "%qE attribute can only be applied to "
    5494              :                "non-static data members", name);
    5495           82 :       *no_add_attrs = true;
    5496              :     }
    5497       744271 :   else if (DECL_C_BIT_FIELD (*node))
    5498              :     {
    5499            6 :       warning (OPT_Wattributes, "%qE attribute cannot be applied to "
    5500              :                "a bit-field", name);
    5501            6 :       *no_add_attrs = true;
    5502              :     }
    5503              : 
    5504       744401 :   return NULL_TREE;
    5505              : }
    5506              : 
    5507              : /* The C++20 [[likely]] and [[unlikely]] attributes on labels map to the GNU
    5508              :    hot/cold attributes.  */
    5509              : 
    5510              : static tree
    5511          392 : handle_likeliness_attribute (tree *node, tree name, tree args,
    5512              :                              int flags, bool *no_add_attrs)
    5513              : {
    5514          392 :   *no_add_attrs = true;
    5515          392 :   if (TREE_CODE (*node) == LABEL_DECL
    5516          392 :       || TREE_CODE (*node) == FUNCTION_DECL)
    5517              :     {
    5518           90 :       if (args)
    5519            0 :         warning (OPT_Wattributes, "%qE attribute takes no arguments", name);
    5520           90 :       tree bname = (is_attribute_p ("likely", name)
    5521           90 :                     ? get_identifier ("hot") : get_identifier ("cold"));
    5522           90 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5523           33 :         warning (OPT_Wattributes, "ISO C++ %qE attribute does not apply to "
    5524              :                  "functions; treating as %<[[gnu::%E]]%>", name, bname);
    5525           90 :       tree battr = build_tree_list (bname, NULL_TREE);
    5526           90 :       decl_attributes (node, battr, flags);
    5527           90 :       return NULL_TREE;
    5528              :     }
    5529              :   else
    5530          302 :     return error_mark_node;
    5531              : }
    5532              : 
    5533              : /* The C++11 alignment specifier.  It mostly maps to GNU aligned attribute,
    5534              :    but we need to do some extra pedantic checking.  */
    5535              : 
    5536              : static tree
    5537       316738 : handle_alignas_attribute (tree *node, tree name, tree args, int flags,
    5538              :                           bool *no_add_attrs)
    5539              : {
    5540       316738 :   tree t = *node;
    5541       316738 :   tree ret = handle_aligned_attribute (node, name, args, flags, no_add_attrs);
    5542       316738 :   if (pedantic)
    5543              :     {
    5544         1264 :       if (TREE_CODE (*node) == FUNCTION_DECL)
    5545           15 :         pedwarn (input_location, OPT_Wattributes,
    5546              :                  "%<alignas%> on function declaration");
    5547         1249 :       else if (TREE_CODE (*node) == ENUMERAL_TYPE)
    5548            9 :         pedwarn (input_location, OPT_Wattributes,
    5549              :                  "%<alignas%> on enumerated type");
    5550         1240 :       else if (TYPE_P (*node) && t != *node)
    5551           56 :         pedwarn (input_location, OPT_Wattributes,
    5552              :                  "%<alignas%> on a type other than class");
    5553         1184 :       else if (TREE_CODE (*node) == FIELD_DECL && DECL_C_BIT_FIELD (*node))
    5554            9 :         pedwarn (input_location, OPT_Wattributes, "%<alignas%> on bit-field");
    5555         1175 :       else if (TREE_CODE (t) == TYPE_DECL)
    5556            9 :         pedwarn (input_location, OPT_Wattributes,
    5557              :                  "%<alignas%> on a type alias");
    5558              :     }
    5559       316738 :   return ret;
    5560              : }
    5561              : 
    5562              : /* The C++14 [[deprecated]] attribute mostly maps to the GNU deprecated
    5563              :    attribute.  */
    5564              : 
    5565              : static tree
    5566       312063 : handle_std_deprecated_attribute (tree *node, tree name, tree args, int flags,
    5567              :                                  bool *no_add_attrs)
    5568              : {
    5569       312063 :   tree t = *node;
    5570       312063 :   tree ret = handle_deprecated_attribute (node, name, args, flags,
    5571              :                                           no_add_attrs);
    5572       312063 :   if (TYPE_P (*node) && t != *node)
    5573           48 :     pedwarn (input_location, OPT_Wattributes,
    5574              :              "%qE on a type other than class or enumeration definition", name);
    5575       312015 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5576            4 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5577              :              name);
    5578       312063 :   return ret;
    5579              : }
    5580              : 
    5581              : /* The C++17 [[maybe_unused]] attribute mostly maps to the GNU unused
    5582              :    attribute.  */
    5583              : 
    5584              : static tree
    5585       104029 : handle_maybe_unused_attribute (tree *node, tree name, tree args, int flags,
    5586              :                                bool *no_add_attrs)
    5587              : {
    5588       104029 :   tree t = *node;
    5589       104029 :   tree ret = handle_unused_attribute (node, name, args, flags, no_add_attrs);
    5590       104029 :   if (TYPE_P (*node) && t != *node)
    5591           36 :     pedwarn (input_location, OPT_Wattributes,
    5592              :              "%qE on a type other than class or enumeration definition", name);
    5593       103993 :   else if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5594            3 :     pedwarn (input_location, OPT_Wattributes, "%qE on unnamed bit-field",
    5595              :              name);
    5596       103990 :   else if (TREE_CODE (*node) == LABEL_DECL && DECL_NAME (*node) == NULL_TREE)
    5597            6 :     pedwarn (input_location, OPT_Wattributes,
    5598              :              "%qE on %<case%> or %<default%> label", name);
    5599       104029 :   return ret;
    5600              : }
    5601              : 
    5602              : /* The C++26 [[indeterminate]] attribute.  */
    5603              : 
    5604              : static tree
    5605          231 : handle_indeterminate_attribute (tree *node, tree name, tree, int,
    5606              :                                 bool *no_add_attrs)
    5607              : {
    5608          231 :   if (TREE_CODE (*node) != PARM_DECL
    5609          231 :       && (!VAR_P (*node) || is_global_var (*node)))
    5610              :     {
    5611           67 :       pedwarn (input_location, OPT_Wattributes,
    5612              :                "%qE on declaration other than parameter or automatic variable",
    5613              :                name);
    5614           67 :       *no_add_attrs = true;
    5615              :     }
    5616          231 :   return NULL_TREE;
    5617              : }
    5618              : 
    5619              : /* Table of valid C++ attributes.  */
    5620              : // clang-format off
    5621              : static const attribute_spec cxx_gnu_attributes[] =
    5622              : {
    5623              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5624              :        affects_type_identity, handler, exclude } */
    5625              :   { "init_priority",  1, 1, true,  false, false, false,
    5626              :     handle_init_priority_attribute, NULL },
    5627              :   { "abi_tag", 1, -1, false, false, false, true,
    5628              :     handle_abi_tag_attribute, NULL },
    5629              :   { "no_dangling", 0, 1, false, true, false, false,
    5630              :     handle_no_dangling_attribute, NULL },
    5631              :   { "no_specializations", 0, 1, false, false, false, false,
    5632              :     handle_gnu_no_specializations_attribute, NULL },
    5633              :   { "trivial_abi", 0, 0, false, true, false, true,
    5634              :     handle_gnu_trivial_abi_attribute, NULL },
    5635              : };
    5636              : // clang-format on
    5637              : 
    5638              : const scoped_attribute_specs cxx_gnu_attribute_table =
    5639              : {
    5640              :   "gnu", { cxx_gnu_attributes }
    5641              : };
    5642              : 
    5643              : /* Table of C++ standard attributes.  */
    5644              : static const attribute_spec std_attributes[] =
    5645              : {
    5646              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
    5647              :        affects_type_identity, handler, exclude } */
    5648              :   { "deprecated", 0, 1, false, false, false, false,
    5649              :     handle_std_deprecated_attribute, NULL },
    5650              :   { "maybe_unused", 0, 0, false, false, false, false,
    5651              :     handle_maybe_unused_attribute, NULL },
    5652              :   { "nodiscard", 0, 1, false, false, false, false,
    5653              :     handle_nodiscard_attribute, NULL },
    5654              :   { "no_unique_address", 0, 0, true, false, false, false,
    5655              :     handle_no_unique_addr_attribute, NULL },
    5656              :   { "likely", 0, 0, false, false, false, false,
    5657              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5658              :   { "unlikely", 0, 0, false, false, false, false,
    5659              :     handle_likeliness_attribute, attr_cold_hot_exclusions },
    5660              :   { "noreturn", 0, 0, true, false, false, false,
    5661              :     handle_noreturn_attribute, attr_noreturn_exclusions },
    5662              :   { "carries_dependency", 0, 0, true, false, false, false,
    5663              :     handle_carries_dependency_attribute, NULL },
    5664              :   { "indeterminate", 0, 0, true, false, false, false,
    5665              :     handle_indeterminate_attribute, NULL },
    5666              : };
    5667              : 
    5668              : const scoped_attribute_specs std_attribute_table =
    5669              : {
    5670              :   nullptr, { std_attributes }
    5671              : };
    5672              : 
    5673              : /* Table of internal attributes.  */
    5674              : static const attribute_spec internal_attributes[] =
    5675              : {
    5676              :   { "aligned", 0, 1, false, false, false, false,
    5677              :     handle_alignas_attribute, attr_aligned_exclusions },
    5678              :   { "annotation ", 1, 1, false, false, false, false,
    5679              :     handle_annotation_attribute, NULL }
    5680              : };
    5681              : 
    5682              : const scoped_attribute_specs internal_attribute_table =
    5683              : {
    5684              :   "internal ", { internal_attributes }
    5685              : };
    5686              : 
    5687              : /* Table of C++ attributes also recognized in the clang:: namespace.  */
    5688              : // clang-format off
    5689              : static const attribute_spec cxx_clang_attributes[] =
    5690              : {
    5691              :   { "no_specializations", 0, 1, false, false, false, false,
    5692              :     handle_no_specializations_attribute, NULL },
    5693              :   { "trivial_abi", 0, 0, false, true, false, true,
    5694              :     handle_trivial_abi_attribute, NULL },
    5695              : };
    5696              : 
    5697              : const scoped_attribute_specs cxx_clang_attribute_table =
    5698              : {
    5699              :   "clang", { cxx_clang_attributes }
    5700              : };
    5701              : // clang-format on
    5702              : 
    5703              : /* Handle an "init_priority" attribute; arguments as in
    5704              :    struct attribute_spec.handler.  */
    5705              : static tree
    5706           35 : handle_init_priority_attribute (tree* node,
    5707              :                                 tree name,
    5708              :                                 tree args,
    5709              :                                 int /*flags*/,
    5710              :                                 bool* no_add_attrs)
    5711              : {
    5712           35 :   if (!SUPPORTS_INIT_PRIORITY)
    5713              :     /* Treat init_priority as an unrecognized attribute (mirroring
    5714              :        __has_attribute) if the target doesn't support init priorities.  */
    5715              :     return error_mark_node;
    5716              : 
    5717           35 :   tree initp_expr = TREE_VALUE (args);
    5718           35 :   tree decl = *node;
    5719           35 :   tree type = TREE_TYPE (decl);
    5720           35 :   int pri;
    5721              : 
    5722           35 :   STRIP_NOPS (initp_expr);
    5723           35 :   initp_expr = default_conversion (initp_expr);
    5724           35 :   if (initp_expr)
    5725           35 :     initp_expr = maybe_constant_value (initp_expr);
    5726              : 
    5727           35 :   if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
    5728              :     {
    5729            0 :       error ("requested %<init_priority%> is not an integer constant");
    5730            0 :       cxx_constant_value (initp_expr);
    5731            0 :       *no_add_attrs = true;
    5732            0 :       return NULL_TREE;
    5733              :     }
    5734              : 
    5735           35 :   pri = TREE_INT_CST_LOW (initp_expr);
    5736              : 
    5737           35 :   type = strip_array_types (type);
    5738              : 
    5739           35 :   if (decl == NULL_TREE
    5740           35 :       || !VAR_P (decl)
    5741           35 :       || !TREE_STATIC (decl)
    5742           35 :       || DECL_EXTERNAL (decl)
    5743           35 :       || (TREE_CODE (type) != RECORD_TYPE
    5744           35 :           && TREE_CODE (type) != UNION_TYPE)
    5745              :       /* Static objects in functions are initialized the
    5746              :          first time control passes through that
    5747              :          function. This is not precise enough to pin down an
    5748              :          init_priority value, so don't allow it.  */
    5749           70 :       || current_function_decl)
    5750              :     {
    5751            0 :       error ("can only use %qE attribute on file-scope definitions "
    5752              :              "of objects of class type", name);
    5753            0 :       *no_add_attrs = true;
    5754            0 :       return NULL_TREE;
    5755              :     }
    5756              : 
    5757           35 :   if (pri > MAX_INIT_PRIORITY || pri <= 0)
    5758              :     {
    5759            0 :       error ("requested %<init_priority%> %i is out of range [0, %i]",
    5760              :              pri, MAX_INIT_PRIORITY);
    5761            0 :       *no_add_attrs = true;
    5762            0 :       return NULL_TREE;
    5763              :     }
    5764              : 
    5765              :   /* Check for init_priorities that are reserved for
    5766              :      language and runtime support implementations.*/
    5767           35 :   if (pri <= MAX_RESERVED_INIT_PRIORITY
    5768           35 :       && !in_system_header_at (input_location))
    5769              :     {
    5770           10 :       warning
    5771           10 :         (OPT_Wprio_ctor_dtor,
    5772              :          "requested %<init_priority%> %i is reserved for internal use",
    5773              :          pri);
    5774              :     }
    5775              : 
    5776           35 :   SET_DECL_INIT_PRIORITY (decl, pri);
    5777           35 :   DECL_HAS_INIT_PRIORITY_P (decl) = 1;
    5778           35 :   return NULL_TREE;
    5779              : }
    5780              : 
    5781              : /* DECL is being redeclared; the old declaration had the abi tags in OLD,
    5782              :    and the new one has the tags in NEW_.  Give an error if there are tags
    5783              :    in NEW_ that weren't in OLD.  */
    5784              : 
    5785              : bool
    5786     11631844 : check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_)
    5787              : {
    5788     11702072 :   if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST)
    5789              :     old = TREE_VALUE (old);
    5790     11654670 :   if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST)
    5791              :     new_ = TREE_VALUE (new_);
    5792     11631844 :   bool err = false;
    5793     11631844 :   auto_diagnostic_group d;
    5794     23286514 :   for (const_tree t = new_; t; t = TREE_CHAIN (t))
    5795              :     {
    5796        22826 :       tree str = TREE_VALUE (t);
    5797        22826 :       for (const_tree in = old; in; in = TREE_CHAIN (in))
    5798              :         {
    5799        22817 :           tree ostr = TREE_VALUE (in);
    5800        22817 :           if (cp_tree_equal (str, ostr))
    5801        22817 :             goto found;
    5802              :         }
    5803            9 :       error ("redeclaration of %qD adds abi tag %qE", decl, str);
    5804            9 :       err = true;
    5805        22826 :     found:;
    5806              :     }
    5807     11631844 :   if (err)
    5808              :     {
    5809            9 :       inform (DECL_SOURCE_LOCATION (decl), "previous declaration here");
    5810            9 :       return false;
    5811              :     }
    5812              :   return true;
    5813     11631844 : }
    5814              : 
    5815              : /* The abi_tag attribute with the name NAME was given ARGS.  If they are
    5816              :    ill-formed, give an error and return false; otherwise, return true.  */
    5817              : 
    5818              : bool
    5819       463937 : check_abi_tag_args (tree args, tree name)
    5820              : {
    5821       463937 :   if (!args)
    5822              :     {
    5823            0 :       error ("the %qE attribute requires arguments", name);
    5824            0 :       return false;
    5825              :     }
    5826       927913 :   for (tree arg = args; arg; arg = TREE_CHAIN (arg))
    5827              :     {
    5828       463988 :       tree elt = TREE_VALUE (arg);
    5829       463988 :       if (TREE_CODE (elt) != STRING_CST
    5830       927970 :           || (!same_type_ignoring_top_level_qualifiers_p
    5831       463982 :               (strip_array_types (TREE_TYPE (elt)),
    5832              :                char_type_node)))
    5833              :         {
    5834            9 :           error ("arguments to the %qE attribute must be narrow string "
    5835              :                  "literals", name);
    5836            9 :           return false;
    5837              :         }
    5838       463979 :       const char *begin = TREE_STRING_POINTER (elt);
    5839       463979 :       const char *end = begin + TREE_STRING_LENGTH (elt);
    5840      3285545 :       for (const char *p = begin; p != end; ++p)
    5841              :         {
    5842      2821569 :           char c = *p;
    5843      2821569 :           if (p == begin)
    5844              :             {
    5845       463979 :               if (!ISALPHA (c) && c != '_')
    5846              :                 {
    5847            3 :                   auto_diagnostic_group d;
    5848            3 :                   error ("arguments to the %qE attribute must contain valid "
    5849              :                          "identifiers", name);
    5850            3 :                   inform (input_location, "%<%c%> is not a valid first "
    5851              :                           "character for an identifier", c);
    5852            3 :                   return false;
    5853            3 :                 }
    5854              :             }
    5855      2357590 :           else if (p == end - 1)
    5856       463976 :             gcc_assert (c == 0);
    5857              :           else
    5858              :             {
    5859      1893614 :               if (!ISALNUM (c) && c != '_')
    5860              :                 {
    5861            0 :                   auto_diagnostic_group d;
    5862            0 :                   error ("arguments to the %qE attribute must contain valid "
    5863              :                          "identifiers", name);
    5864            0 :                   inform (input_location, "%<%c%> is not a valid character "
    5865              :                           "in an identifier", c);
    5866            0 :                   return false;
    5867            0 :                 }
    5868              :             }
    5869              :         }
    5870              :     }
    5871              :   return true;
    5872              : }
    5873              : 
    5874              : /* Handle an "abi_tag" attribute; arguments as in
    5875              :    struct attribute_spec.handler.  */
    5876              : 
    5877              : static tree
    5878       414439 : handle_abi_tag_attribute (tree* node, tree name, tree args,
    5879              :                           int flags, bool* no_add_attrs)
    5880              : {
    5881       414439 :   if (!check_abi_tag_args (args, name))
    5882           12 :     goto fail;
    5883              : 
    5884       414427 :   if (TYPE_P (*node))
    5885              :     {
    5886        11713 :       if (!OVERLOAD_TYPE_P (*node))
    5887              :         {
    5888            0 :           error ("%qE attribute applied to non-class, non-enum type %qT",
    5889              :                  name, *node);
    5890            0 :           goto fail;
    5891              :         }
    5892        11713 :       else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE))
    5893              :         {
    5894            0 :           error ("%qE attribute applied to %qT after its definition",
    5895              :                  name, *node);
    5896            0 :           goto fail;
    5897              :         }
    5898        11710 :       else if (CLASS_TYPE_P (*node)
    5899        23423 :                && CLASSTYPE_TEMPLATE_INSTANTIATION (*node))
    5900              :         {
    5901            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5902              :                    "template instantiation %qT", name, *node);
    5903            3 :           goto fail;
    5904              :         }
    5905        11707 :       else if (CLASS_TYPE_P (*node)
    5906        23417 :                && CLASSTYPE_TEMPLATE_SPECIALIZATION (*node))
    5907              :         {
    5908            3 :           warning (OPT_Wattributes, "ignoring %qE attribute applied to "
    5909              :                    "template specialization %qT", name, *node);
    5910            3 :           goto fail;
    5911              :         }
    5912              : 
    5913        11707 :       tree attributes = TYPE_ATTRIBUTES (*node);
    5914        11707 :       tree decl = TYPE_NAME (*node);
    5915              : 
    5916              :       /* Make sure all declarations have the same abi tags.  */
    5917        11707 :       if (DECL_SOURCE_LOCATION (decl) != input_location)
    5918              :         {
    5919            6 :           if (!check_abi_tag_redeclaration (decl,
    5920            6 :                                             lookup_attribute ("abi_tag",
    5921              :                                                               attributes),
    5922              :                                             args))
    5923            6 :             goto fail;
    5924              :         }
    5925              :     }
    5926              :   else
    5927              :     {
    5928       402714 :       if (!VAR_OR_FUNCTION_DECL_P (*node))
    5929              :         {
    5930            0 :           error ("%qE attribute applied to non-function, non-variable %qD",
    5931              :                  name, *node);
    5932            0 :           goto fail;
    5933              :         }
    5934       402714 :       else if (DECL_LANGUAGE (*node) == lang_c)
    5935              :         {
    5936            0 :           error ("%qE attribute applied to extern \"C\" declaration %qD",
    5937              :                  name, *node);
    5938            0 :           goto fail;
    5939              :         }
    5940              :     }
    5941              : 
    5942              :   return NULL_TREE;
    5943              : 
    5944           24 :  fail:
    5945           24 :   *no_add_attrs = true;
    5946           24 :   return NULL_TREE;
    5947              : }
    5948              : 
    5949              : /* Handle a "no_dangling" attribute; arguments as in
    5950              :    struct attribute_spec.handler.  */
    5951              : 
    5952              : tree
    5953           96 : handle_no_dangling_attribute (tree *node, tree name, tree args, int,
    5954              :                               bool *no_add_attrs)
    5955              : {
    5956          147 :   if (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
    5957              :     {
    5958            3 :       error ("%qE attribute argument must be an expression that evaluates "
    5959              :              "to true or false", name);
    5960            3 :       *no_add_attrs = true;
    5961              :     }
    5962           93 :   else if (!FUNC_OR_METHOD_TYPE_P (*node)
    5963           51 :            && !RECORD_OR_UNION_TYPE_P (*node))
    5964              :     {
    5965           18 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5966           18 :       *no_add_attrs = true;
    5967              :     }
    5968              : 
    5969           96 :   return NULL_TREE;
    5970              : }
    5971              : 
    5972              : /* Perform checking for annotations.  */
    5973              : 
    5974              : tree
    5975          846 : handle_annotation_attribute (tree *node, tree ARG_UNUSED (name),
    5976              :                              tree args, int ARG_UNUSED (flags),
    5977              :                              bool *no_add_attrs)
    5978              : {
    5979          846 :   if (TYPE_P (*node)
    5980          118 :       && TREE_CODE (*node) != ENUMERAL_TYPE
    5981          110 :       && TREE_CODE (*node) != RECORD_TYPE
    5982           24 :       && TREE_CODE (*node) != UNION_TYPE)
    5983              :     {
    5984           24 :       error ("annotation on a type other than class or enumeration "
    5985              :              "definition");
    5986           24 :       *no_add_attrs = true;
    5987           24 :       return NULL_TREE;
    5988              :     }
    5989          822 :   if (TREE_CODE (*node) == LABEL_DECL)
    5990              :     {
    5991            6 :       error ("annotation applied to a label");
    5992            6 :       *no_add_attrs = true;
    5993            6 :       return NULL_TREE;
    5994              :     }
    5995          816 :   if (TREE_CODE (*node) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (*node))
    5996              :     {
    5997            2 :       error ("annotation on unnamed bit-field");
    5998            2 :       *no_add_attrs = true;
    5999            2 :       return NULL_TREE;
    6000              :     }
    6001          814 :   if (TREE_CODE (*node) == PARM_DECL && VOID_TYPE_P (TREE_TYPE (*node)))
    6002              :     {
    6003            2 :       error ("annotation on void parameter");
    6004            2 :       *no_add_attrs = true;
    6005            2 :       return NULL_TREE;
    6006              :     }
    6007              : 
    6008              :   /* Annotations are treated as late attributes so we shouldn't see
    6009              :      anything type-dependent now.  */
    6010          812 :   gcc_assert (!type_dependent_expression_p (TREE_VALUE (args)));
    6011              :   /* FIXME We should be using convert_reflect_constant_arg here to
    6012              :      implement std::meta::reflect_constant(constant-expression)
    6013              :      properly, but that introduces new crashes.  */
    6014          812 :   TREE_VALUE (args) = decay_conversion (TREE_VALUE (args), tf_warning_or_error);
    6015              : 
    6016          812 :   if (!structural_type_p (TREE_TYPE (TREE_VALUE (args))))
    6017              :     {
    6018          102 :       auto_diagnostic_group d;
    6019          102 :       error ("annotation does not have structural type");
    6020          102 :       structural_type_p (TREE_TYPE (TREE_VALUE (args)), true);
    6021          102 :       *no_add_attrs = true;
    6022          102 :       return NULL_TREE;
    6023          102 :     }
    6024          710 :   if (CLASS_TYPE_P (TREE_TYPE (TREE_VALUE (args))))
    6025              :     {
    6026           62 :       tree arg = make_tree_vec (1);
    6027           62 :       tree type = TREE_TYPE (TREE_VALUE (args));
    6028           62 :       TREE_VEC_ELT (arg, 0) = build_const_lref (type);
    6029           62 :       if (!is_xible (INIT_EXPR, type, arg))
    6030              :         {
    6031            4 :           auto_diagnostic_group d;
    6032            4 :           error ("annotation does not have copy constructible type");
    6033            4 :           is_xible (INIT_EXPR, type, arg, /*explain=*/true);
    6034            4 :           *no_add_attrs = true;
    6035            4 :           return NULL_TREE;
    6036            4 :         }
    6037              :     }
    6038          706 :   if (!processing_template_decl)
    6039              :     {
    6040          698 :       location_t loc = EXPR_LOCATION (TREE_VALUE (args));
    6041          698 :       TREE_VALUE (args) = cxx_constant_value (TREE_VALUE (args));
    6042          698 :       if (error_operand_p (TREE_VALUE (args)))
    6043            4 :         *no_add_attrs = true;
    6044          698 :       auto suppression
    6045          698 :         = make_temp_override (suppress_location_wrappers, 0);
    6046          698 :       TREE_VALUE (args) = maybe_wrap_with_location (TREE_VALUE (args), loc);
    6047          698 :     }
    6048          706 :   ATTR_UNIQUE_VALUE_P (args) = 1;
    6049          706 :   return NULL_TREE;
    6050              : }
    6051              : 
    6052              : /* Handle a "trivial_abi" attribute applied via [[gnu::trivial_abi]].
    6053              :    We reject that spelling; suggest [[clang::trivial_abi]] or
    6054              :    __attribute__((trivial_abi)) instead.  */
    6055              : 
    6056              : static tree
    6057           84 : handle_gnu_trivial_abi_attribute (tree *node, tree name, tree args, int flags,
    6058              :                                   bool *no_add_attrs)
    6059              : {
    6060           84 :   if (flags & ATTR_FLAG_CXX11)
    6061              :     {
    6062            3 :       warning (OPT_Wattributes,
    6063              :                "%<[[gnu::trivial_abi]]%> is not supported; use "
    6064              :                "%<[[clang::trivial_abi]]%> or "
    6065              :                "%<__attribute__((trivial_abi))%> instead");
    6066            3 :       *no_add_attrs = true;
    6067            3 :       return NULL_TREE;
    6068              :     }
    6069          165 :   return handle_trivial_abi_attribute (node, name, args, flags, no_add_attrs);
    6070              : }
    6071              : 
    6072              : /* Handle a "trivial_abi" attribute.  */
    6073              : 
    6074              : static tree
    6075          160 : handle_trivial_abi_attribute (tree *node, tree name, tree, int,
    6076              :                               bool *no_add_attrs)
    6077              : {
    6078          160 :   tree type = *node;
    6079              : 
    6080              :   /* Only allow on class types (struct, class, union) */
    6081          160 :   if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
    6082              :     {
    6083            9 :       warning (OPT_Wattributes, "%qE attribute only applies to classes", name);
    6084            9 :       *no_add_attrs = true;
    6085            9 :       return NULL_TREE;
    6086              :     }
    6087              : 
    6088              :   return NULL_TREE;
    6089              : }
    6090              : 
    6091              : /* Return true if TYPE has the trivial_abi attribute.  */
    6092              : 
    6093              : bool
    6094    191035528 : has_trivial_abi_attribute (tree type)
    6095              : {
    6096    191035528 :   if (type == NULL_TREE || !TYPE_P (type))
    6097              :     return false;
    6098    191035487 :   return lookup_attribute ("trivial_abi", TYPE_ATTRIBUTES (type));
    6099              : }
    6100              : 
    6101              : /* Handle a "no_specializations" attribute applied via
    6102              :    [[gnu::no_specializations]].
    6103              :    We reject that spelling; suggest [[clang::no_specializations]] or
    6104              :    __attribute__((no_specializations)) instead.  */
    6105              : 
    6106              : static tree
    6107          122 : handle_gnu_no_specializations_attribute (tree *node, tree name, tree args,
    6108              :                                          int flags, bool *no_add_attrs)
    6109              : {
    6110          122 :   if (flags & ATTR_FLAG_CXX11)
    6111              :     {
    6112            8 :       warning (OPT_Wattributes,
    6113              :                "%<[[gnu::no_specializations]]%> is not supported; use "
    6114              :                "%<[[clang::no_specializations]]%> or "
    6115              :                "%<__attribute__((no_specializations))%> instead");
    6116            8 :       *no_add_attrs = true;
    6117            8 :       return NULL_TREE;
    6118              :     }
    6119          114 :   return handle_no_specializations_attribute (node, name, args, flags,
    6120          114 :                                               no_add_attrs);
    6121              : }
    6122              : 
    6123              : /* Handle a "no_specializations" attribute.  */
    6124              : 
    6125              : static tree
    6126        74172 : handle_no_specializations_attribute (tree *node, tree name, tree args, int,
    6127              :                                      bool *no_add_attrs)
    6128              : {
    6129        74325 :   if (args && TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    6130              :     {
    6131            3 :       error ("%qE attribute argument must be a string constant", name);
    6132            3 :       *no_add_attrs = true;
    6133            3 :       return NULL_TREE;
    6134              :     }
    6135              :   /* Only allow on class templates, variable templates
    6136              :      and function templates.  */
    6137        74169 :   if (!CLASS_TYPE_P (*node) && !VAR_OR_FUNCTION_DECL_P (*node))
    6138              :     {
    6139          343 :     invalid:
    6140          343 :       warning (OPT_Wattributes, "%qE attribute only applies to class, "
    6141              :                                 "function or variable templates", name);
    6142          343 :       *no_add_attrs = true;
    6143          343 :       return NULL_TREE;
    6144              :     }
    6145        74033 :   tree ti = NULL_TREE;
    6146        74033 :   if (TYPE_P (*node))
    6147              :     {
    6148        73840 :       if (!TYPE_NAME (*node)
    6149        73840 :           || !DECL_IMPLICIT_TYPEDEF_P (TYPE_NAME (*node))
    6150       221508 :           || LAMBDA_TYPE_P (*node))
    6151            0 :         goto invalid;
    6152        73840 :       if (TYPE_LANG_SPECIFIC (*node))
    6153              :         {
    6154        73840 :           if (CLASSTYPE_TEMPLATE_SPECIALIZATION (*node)
    6155        73840 :               || CLASSTYPE_EXPLICIT_INSTANTIATION (*node))
    6156           39 :             goto invalid;
    6157        73801 :           ti = CLASSTYPE_TEMPLATE_INFO (*node);
    6158              :         }
    6159              :     }
    6160          193 :   else if (DECL_LANG_SPECIFIC (*node))
    6161              :     {
    6162          157 :       if (DECL_TEMPLATE_SPECIALIZATION (*node)
    6163          157 :           || DECL_EXPLICIT_INSTANTIATION (*node))
    6164           36 :         goto invalid;
    6165          121 :       ti = DECL_TEMPLATE_INFO (*node);
    6166              :     }
    6167        73922 :   if (ti)
    6168              :     {
    6169        73797 :       if (!PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)))
    6170           24 :         goto invalid;
    6171        73773 :       if (TYPE_P (*node) && DECL_ALIAS_TEMPLATE_P (TI_TEMPLATE (ti)))
    6172            0 :         goto invalid;
    6173              :     }
    6174          161 :   else if (!processing_template_decl || !template_parm_scope_p ())
    6175          108 :     goto invalid;
    6176              : 
    6177              :   return NULL_TREE;
    6178              : }
    6179              : 
    6180              : /* Validate the trivial_abi attribute on a completed class type.
    6181              :    Called from finish_struct after the class is complete.  */
    6182              : 
    6183              : void
    6184     53493855 : validate_trivial_abi_attribute (tree type)
    6185              : {
    6186     53493855 :   if (!has_trivial_abi_attribute (type))
    6187     53493746 :     return;
    6188              : 
    6189          151 :   gcc_assert (COMPLETE_TYPE_P (type));
    6190              : 
    6191          193 :   auto remove_trivial_abi_attribute = [type] {
    6192          138 :     for (tree variant = TYPE_MAIN_VARIANT (type); variant;
    6193           96 :          variant = TYPE_NEXT_VARIANT (variant))
    6194           96 :       TYPE_ATTRIBUTES (variant)
    6195          192 :         = remove_attribute ("trivial_abi", TYPE_ATTRIBUTES (variant));
    6196          193 :   };
    6197              : 
    6198              :   /* Check for virtual bases.  */
    6199          151 :   if (CLASSTYPE_VBASECLASSES (type))
    6200              :     {
    6201            6 :       auto_diagnostic_group d;
    6202            6 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6203              :                    type))
    6204            6 :         inform (input_location, "has a virtual base");
    6205            6 :       remove_trivial_abi_attribute ();
    6206            6 :       return;
    6207            6 :     }
    6208              : 
    6209              :   /* Check for virtual member functions.  */
    6210          145 :   if (TYPE_POLYMORPHIC_P (type))
    6211              :     {
    6212            9 :       auto_diagnostic_group d;
    6213            9 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6214              :                    type))
    6215            9 :         inform (input_location, "is polymorphic");
    6216            9 :       remove_trivial_abi_attribute ();
    6217            9 :       return;
    6218            9 :     }
    6219              : 
    6220              :   /* Check for non-trivial base classes.  */
    6221          136 :   if (TYPE_BINFO (type))
    6222              :     {
    6223          136 :       unsigned int n_bases = BINFO_N_BASE_BINFOS (TYPE_BINFO (type));
    6224          151 :       for (unsigned int i = 0; i < n_bases; ++i)
    6225              :         {
    6226           18 :           tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), i);
    6227           18 :           tree base_type = BINFO_TYPE (base_binfo);
    6228              : 
    6229           18 :           if (TREE_ADDRESSABLE (base_type))
    6230              :             {
    6231            3 :               auto_diagnostic_group d;
    6232            3 :               if (warning (OPT_Wattributes,
    6233              :                            "%<trivial_abi%> cannot be applied to %qT", type))
    6234            3 :                 inform (input_location, "has a non-trivial base class %qT",
    6235              :                         base_type);
    6236            3 :               remove_trivial_abi_attribute ();
    6237            3 :               return;
    6238            3 :             }
    6239              :         }
    6240              :     }
    6241              : 
    6242              :   /* Check for non-trivial member types.  */
    6243          741 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    6244              :     {
    6245          620 :       if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field))
    6246              :         {
    6247          118 :           tree field_type = strip_array_types (TREE_TYPE (field));
    6248              : 
    6249          118 :           if (CLASS_TYPE_P (field_type) && TREE_ADDRESSABLE (field_type))
    6250              :             {
    6251           12 :               auto_diagnostic_group d;
    6252           12 :               if (warning (OPT_Wattributes,
    6253              :                            "%<trivial_abi%> cannot be applied to %qT", type))
    6254           12 :                 inform (input_location, "has a non-static data member "
    6255              :                         "of non-trivial type %qT", field_type);
    6256           12 :               remove_trivial_abi_attribute ();
    6257           12 :               return;
    6258           12 :             }
    6259              :         }
    6260              :     }
    6261              : 
    6262              :   /* Check that not all copy/move constructors are deleted.  */
    6263          121 :   if (!classtype_has_non_deleted_copy_or_move_ctor (type))
    6264              :     {
    6265           12 :       auto_diagnostic_group d;
    6266           12 :       if (warning (OPT_Wattributes, "%<trivial_abi%> cannot be applied to %qT",
    6267              :                    type))
    6268           12 :         inform (input_location,
    6269              :                 "copy constructors and move constructors are all deleted");
    6270           12 :       remove_trivial_abi_attribute ();
    6271           12 :       return;
    6272           12 :     }
    6273              : }
    6274              : /* Return a new PTRMEM_CST of the indicated TYPE.  The MEMBER is the
    6275              :    thing pointed to by the constant.  */
    6276              : 
    6277              : tree
    6278        64372 : make_ptrmem_cst (tree type, tree member)
    6279              : {
    6280        64372 :   tree ptrmem_cst = make_node (PTRMEM_CST);
    6281        64372 :   TREE_TYPE (ptrmem_cst) = type;
    6282        64372 :   PTRMEM_CST_MEMBER (ptrmem_cst) = member;
    6283        64372 :   PTRMEM_CST_LOCATION (ptrmem_cst) = input_location;
    6284        64372 :   return ptrmem_cst;
    6285              : }
    6286              : 
    6287              : /* Build a variant of TYPE that has the indicated ATTRIBUTES.  May
    6288              :    return an existing type if an appropriate type already exists.  */
    6289              : 
    6290              : tree
    6291     16659877 : cp_build_type_attribute_variant (tree type, tree attributes)
    6292              : {
    6293     16659877 :   tree new_type;
    6294              : 
    6295     16659877 :   new_type = build_type_attribute_variant (type, attributes);
    6296     16659877 :   if (FUNC_OR_METHOD_TYPE_P (new_type))
    6297     16588834 :     gcc_checking_assert (cxx_type_hash_eq (type, new_type));
    6298              : 
    6299              :   /* Making a new main variant of a class type is broken.  */
    6300     16659877 :   gcc_assert (!CLASS_TYPE_P (type) || new_type == type);
    6301              : 
    6302     16659877 :   return new_type;
    6303              : }
    6304              : 
    6305              : /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
    6306              :    Called only after doing all language independent checks.  */
    6307              : 
    6308              : bool
    6309    345465888 : cxx_type_hash_eq (const_tree typea, const_tree typeb)
    6310              : {
    6311    345465888 :   gcc_assert (FUNC_OR_METHOD_TYPE_P (typea));
    6312              : 
    6313    345465888 :   if (type_memfn_rqual (typea) != type_memfn_rqual (typeb))
    6314              :     return false;
    6315    345458213 :   if (TYPE_HAS_LATE_RETURN_TYPE (typea) != TYPE_HAS_LATE_RETURN_TYPE (typeb))
    6316              :     return false;
    6317    345456984 :   return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea),
    6318    690913968 :                             TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
    6319              : }
    6320              : 
    6321              : /* Copy the language-specific type variant modifiers from TYPEB to TYPEA.  For
    6322              :    C++, these are the exception-specifier and ref-qualifier.  */
    6323              : 
    6324              : tree
    6325     27003894 : cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
    6326              : {
    6327     27003894 :   tree type = const_cast<tree> (typea);
    6328     27003894 :   if (FUNC_OR_METHOD_TYPE_P (type))
    6329     27002587 :     type = build_cp_fntype_variant (type, type_memfn_rqual (typeb),
    6330     27002587 :                                     TYPE_RAISES_EXCEPTIONS (typeb),
    6331     27002587 :                                     TYPE_HAS_LATE_RETURN_TYPE (typeb));
    6332     27003894 :   return type;
    6333              : }
    6334              : 
    6335              : /* Apply FUNC to all language-specific sub-trees of TP in a pre-order
    6336              :    traversal.  Called from walk_tree.  */
    6337              : 
    6338              : tree
    6339  25553656071 : cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
    6340              :                   void *data, hash_set<tree> *pset)
    6341              : {
    6342  25553656071 :   tree t = *tp;
    6343  25553656071 :   enum tree_code code = TREE_CODE (t);
    6344  25553656071 :   tree result;
    6345              : 
    6346              : #define WALK_SUBTREE(NODE)                              \
    6347              :   do                                                    \
    6348              :     {                                                   \
    6349              :       result = cp_walk_tree (&(NODE), func, data, pset);    \
    6350              :       if (result) goto out;                             \
    6351              :     }                                                   \
    6352              :   while (0)
    6353              : 
    6354  25553656071 :   if (TYPE_P (t))
    6355              :     {
    6356              :       /* If *WALK_SUBTREES_P is 1, we're interested in the syntactic form of
    6357              :          the argument, so don't look through typedefs, but do walk into
    6358              :          template arguments for alias templates (and non-typedefed classes).
    6359              : 
    6360              :          If *WALK_SUBTREES_P > 1, we're interested in type identity or
    6361              :          equivalence, so look through typedefs, ignoring template arguments for
    6362              :          alias templates, and walk into template args of classes.
    6363              : 
    6364              :          See find_abi_tags_r for an example of setting *WALK_SUBTREES_P to 2
    6365              :          when that's the behavior the walk_tree_fn wants.  */
    6366   7564819430 :       if (*walk_subtrees_p == 1 && typedef_variant_p (t))
    6367              :         {
    6368     77875088 :           if (tree ti = TYPE_ALIAS_TEMPLATE_INFO (t))
    6369     59862455 :             WALK_SUBTREE (TI_ARGS (ti));
    6370     77830107 :           *walk_subtrees_p = 0;
    6371     77830107 :           return NULL_TREE;
    6372              :         }
    6373              : 
    6374   7486944342 :       if (tree ti = TYPE_TEMPLATE_INFO (t))
    6375    855949327 :         WALK_SUBTREE (TI_ARGS (ti));
    6376              :     }
    6377              : 
    6378              :   /* Not one of the easy cases.  We must explicitly go through the
    6379              :      children.  */
    6380  25475609988 :   result = NULL_TREE;
    6381  25475609988 :   switch (code)
    6382              :     {
    6383   1953357641 :     case TEMPLATE_TYPE_PARM:
    6384   1953357641 :       if (template_placeholder_p (t))
    6385      1369361 :         WALK_SUBTREE (CLASS_PLACEHOLDER_TEMPLATE (t));
    6386              :       /* Fall through.  */
    6387   2113483757 :     case DEFERRED_PARSE:
    6388   2113483757 :     case TEMPLATE_TEMPLATE_PARM:
    6389   2113483757 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    6390   2113483757 :     case UNBOUND_CLASS_TEMPLATE:
    6391   2113483757 :     case TEMPLATE_PARM_INDEX:
    6392   2113483757 :     case TYPEOF_TYPE:
    6393              :       /* None of these have subtrees other than those already walked
    6394              :          above.  */
    6395   2113483757 :       *walk_subtrees_p = 0;
    6396   2113483757 :       break;
    6397              : 
    6398    222057080 :     case TYPENAME_TYPE:
    6399    222057080 :       WALK_SUBTREE (TYPE_CONTEXT (t));
    6400    221965109 :       WALK_SUBTREE (TYPENAME_TYPE_FULLNAME (t));
    6401    221962940 :       *walk_subtrees_p = 0;
    6402    221962940 :       break;
    6403              : 
    6404     85190372 :     case BASELINK:
    6405     85190372 :       if (BASELINK_QUALIFIED_P (t))
    6406      1554260 :         WALK_SUBTREE (BINFO_TYPE (BASELINK_ACCESS_BINFO (t)));
    6407     85190372 :       WALK_SUBTREE (BASELINK_FUNCTIONS (t));
    6408     85086744 :       *walk_subtrees_p = 0;
    6409     85086744 :       break;
    6410              : 
    6411       133926 :     case PTRMEM_CST:
    6412       133926 :       WALK_SUBTREE (TREE_TYPE (t));
    6413       133926 :       *walk_subtrees_p = 0;
    6414       133926 :       break;
    6415              : 
    6416    281614557 :     case TREE_LIST:
    6417    281614557 :       WALK_SUBTREE (TREE_PURPOSE (t));
    6418              :       break;
    6419              : 
    6420    321724446 :     case OVERLOAD:
    6421    321724446 :       WALK_SUBTREE (OVL_FUNCTION (t));
    6422    321724441 :       WALK_SUBTREE (OVL_CHAIN (t));
    6423    321724441 :       *walk_subtrees_p = 0;
    6424    321724441 :       break;
    6425              : 
    6426      8168965 :     case USING_DECL:
    6427      8168965 :       WALK_SUBTREE (DECL_NAME (t));
    6428      8168965 :       WALK_SUBTREE (USING_DECL_SCOPE (t));
    6429      8168962 :       WALK_SUBTREE (USING_DECL_DECLS (t));
    6430      8168962 :       *walk_subtrees_p = 0;
    6431      8168962 :       break;
    6432              : 
    6433    989103855 :     case RECORD_TYPE:
    6434    989103855 :       if (TYPE_PTRMEMFUNC_P (t))
    6435      5729156 :         WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (t));
    6436              :       break;
    6437              : 
    6438    153150673 :     case TYPE_ARGUMENT_PACK:
    6439    153150673 :     case NONTYPE_ARGUMENT_PACK:
    6440    153150673 :       {
    6441    153150673 :         tree args = ARGUMENT_PACK_ARGS (t);
    6442    400395374 :         for (tree arg : tree_vec_range (args))
    6443    247342078 :           WALK_SUBTREE (arg);
    6444              :       }
    6445    153053296 :       break;
    6446              : 
    6447     31077407 :     case TYPE_PACK_EXPANSION:
    6448     31077407 :       WALK_SUBTREE (TREE_TYPE (t));
    6449     31068371 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6450     31068371 :       *walk_subtrees_p = 0;
    6451     31068371 :       break;
    6452              : 
    6453      6262036 :     case EXPR_PACK_EXPANSION:
    6454      6262036 :       WALK_SUBTREE (TREE_OPERAND (t, 0));
    6455      6258236 :       WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (t));
    6456      6258236 :       *walk_subtrees_p = 0;
    6457      6258236 :       break;
    6458              : 
    6459        19099 :     case PACK_INDEX_TYPE:
    6460        19099 :     case PACK_INDEX_EXPR:
    6461        19099 :       WALK_SUBTREE (PACK_INDEX_PACK (t));
    6462        19099 :       WALK_SUBTREE (PACK_INDEX_INDEX (t));
    6463        19099 :       *walk_subtrees_p = 0;
    6464        19099 :       break;
    6465              : 
    6466    115327573 :     case CAST_EXPR:
    6467    115327573 :     case REINTERPRET_CAST_EXPR:
    6468    115327573 :     case STATIC_CAST_EXPR:
    6469    115327573 :     case CONST_CAST_EXPR:
    6470    115327573 :     case DYNAMIC_CAST_EXPR:
    6471    115327573 :     case IMPLICIT_CONV_EXPR:
    6472    115327573 :     case BIT_CAST_EXPR:
    6473    115327573 :       if (TREE_TYPE (t))
    6474    115327573 :         WALK_SUBTREE (TREE_TYPE (t));
    6475              :       break;
    6476              : 
    6477    107861582 :     case CONSTRUCTOR:
    6478    107861582 :       if (COMPOUND_LITERAL_P (t))
    6479      9484214 :         WALK_SUBTREE (TREE_TYPE (t));
    6480              :       break;
    6481              : 
    6482     16174003 :     case TRAIT_EXPR:
    6483     16174003 :       WALK_SUBTREE (TRAIT_EXPR_TYPE1 (t));
    6484     16173991 :       WALK_SUBTREE (TRAIT_EXPR_TYPE2 (t));
    6485     16173991 :       *walk_subtrees_p = 0;
    6486     16173991 :       break;
    6487              : 
    6488      2182872 :     case TRAIT_TYPE:
    6489      2182872 :       WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
    6490      2182872 :       WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
    6491      2182872 :       *walk_subtrees_p = 0;
    6492      2182872 :       break;
    6493              : 
    6494     21914406 :     case DECLTYPE_TYPE:
    6495     21914406 :       {
    6496     21914406 :         cp_unevaluated u;
    6497     21914406 :         WALK_SUBTREE (DECLTYPE_TYPE_EXPR (t));
    6498     21545759 :         *walk_subtrees_p = 0;
    6499     21545759 :         break;
    6500     21914406 :       }
    6501              : 
    6502     28553036 :     case ALIGNOF_EXPR:
    6503     28553036 :     case SIZEOF_EXPR:
    6504     28553036 :     case NOEXCEPT_EXPR:
    6505     28553036 :       {
    6506     28553036 :         cp_unevaluated u;
    6507     28553036 :         WALK_SUBTREE (TREE_OPERAND (t, 0));
    6508     25392020 :         *walk_subtrees_p = 0;
    6509     25392020 :         break;
    6510     28553036 :       }
    6511              : 
    6512     13436634 :     case REQUIRES_EXPR:
    6513     13436634 :       {
    6514     13436634 :         cp_unevaluated u;
    6515     22553300 :         for (tree parm = REQUIRES_EXPR_PARMS (t); parm; parm = DECL_CHAIN (parm))
    6516              :           /* Walk the types of each parameter, but not the parameter itself,
    6517              :              since doing so would cause false positives in the unexpanded pack
    6518              :              checker if the requires-expr introduces a function parameter pack,
    6519              :              e.g. requires (Ts... ts) { }.   */
    6520      9117566 :           WALK_SUBTREE (TREE_TYPE (parm));
    6521     13435734 :         WALK_SUBTREE (REQUIRES_EXPR_REQS (t));
    6522     13431850 :         *walk_subtrees_p = 0;
    6523     13431850 :         break;
    6524     13436634 :       }
    6525              : 
    6526    134769751 :     case DECL_EXPR:
    6527              :       /* User variables should be mentioned in BIND_EXPR_VARS
    6528              :          and their initializers and sizes walked when walking
    6529              :          the containing BIND_EXPR.  Compiler temporaries are
    6530              :          handled here.  And also normal variables in templates,
    6531              :          since do_poplevel doesn't build a BIND_EXPR then.  */
    6532    134769751 :       if (VAR_P (TREE_OPERAND (t, 0))
    6533    134769751 :           && (processing_template_decl
    6534    118536783 :               || (DECL_ARTIFICIAL (TREE_OPERAND (t, 0))
    6535      6599115 :                   && !TREE_STATIC (TREE_OPERAND (t, 0)))))
    6536              :         {
    6537     15667764 :           tree decl = TREE_OPERAND (t, 0);
    6538     15667764 :           WALK_SUBTREE (TREE_TYPE (decl));
    6539     15667764 :           WALK_SUBTREE (DECL_INITIAL (decl));
    6540     15667734 :           WALK_SUBTREE (DECL_SIZE (decl));
    6541     15667734 :           WALK_SUBTREE (DECL_SIZE_UNIT (decl));
    6542              :         }
    6543    134769721 :       if (is_typedef_decl (TREE_OPERAND (t, 0)))
    6544              :         /* We avoid walking into typedefs above, but we do want to walk
    6545              :            into them if we're looking at the actual declaration.  */
    6546      1339796 :         WALK_SUBTREE (DECL_ORIGINAL_TYPE (TREE_OPERAND (t, 0)));
    6547              :       break;
    6548              : 
    6549      2068829 :     case LAMBDA_EXPR:
    6550              :       /* Don't walk into the body of the lambda, but the capture initializers
    6551              :          are part of the enclosing context.  */
    6552      4942948 :       for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (t); cap;
    6553      2874119 :            cap = TREE_CHAIN (cap))
    6554      2874119 :         WALK_SUBTREE (TREE_VALUE (cap));
    6555              :       break;
    6556              : 
    6557         4439 :     case CO_YIELD_EXPR:
    6558         4439 :       if (TREE_OPERAND (t, 1))
    6559              :         /* Operand 1 is the tree for the relevant co_await which has any
    6560              :            interesting sub-trees.  */
    6561          601 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6562              :       break;
    6563              : 
    6564        27582 :     case CO_AWAIT_EXPR:
    6565        27582 :       if (TREE_OPERAND (t, 1))
    6566              :         /* Operand 1 is frame variable.  */
    6567        27394 :         WALK_SUBTREE (TREE_OPERAND (t, 1));
    6568        27582 :       if (TREE_OPERAND (t, 2))
    6569              :         /* Operand 2 has the initialiser, and we need to walk any subtrees
    6570              :            there.  */
    6571         5521 :         WALK_SUBTREE (TREE_OPERAND (t, 2));
    6572              :       break;
    6573              : 
    6574          885 :     case CO_RETURN_EXPR:
    6575          885 :       if (TREE_OPERAND (t, 0))
    6576              :         {
    6577          699 :           if (VOID_TYPE_P (TREE_OPERAND (t, 0)))
    6578              :             /* For void expressions, operand 1 is a trivial call, and any
    6579              :                interesting subtrees will be part of operand 0.  */
    6580            0 :             WALK_SUBTREE (TREE_OPERAND (t, 0));
    6581          699 :           else if (TREE_OPERAND (t, 1))
    6582              :             /* Interesting sub-trees will be in the return_value () call
    6583              :                arguments.  */
    6584          657 :             WALK_SUBTREE (TREE_OPERAND (t, 1));
    6585              :         }
    6586              :       break;
    6587              : 
    6588       667575 :     case STATIC_ASSERT:
    6589       667575 :       WALK_SUBTREE (STATIC_ASSERT_CONDITION (t));
    6590       667575 :       WALK_SUBTREE (STATIC_ASSERT_MESSAGE (t));
    6591              :       break;
    6592              : 
    6593    787635901 :     case INTEGER_TYPE:
    6594              :       /* Removed from walk_type_fields in r119481.  */
    6595    787635901 :       WALK_SUBTREE (TYPE_MIN_VALUE (t));
    6596    787635901 :       WALK_SUBTREE (TYPE_MAX_VALUE (t));
    6597              :       break;
    6598              : 
    6599          600 :     case SPLICE_SCOPE:
    6600          600 :       WALK_SUBTREE (SPLICE_SCOPE_EXPR (t));
    6601          594 :       *walk_subtrees_p = 0;
    6602          594 :       break;
    6603              : 
    6604              :     default:
    6605              :       return NULL_TREE;
    6606              :     }
    6607              : 
    6608              :   /* We didn't find what we were looking for.  */
    6609  25553656071 :  out:
    6610              :   return result;
    6611              : 
    6612              : #undef WALK_SUBTREE
    6613              : }
    6614              : 
    6615              : /* Like save_expr, but for C++.  */
    6616              : 
    6617              : tree
    6618       330995 : cp_save_expr (tree expr)
    6619              : {
    6620              :   /* There is no reason to create a SAVE_EXPR within a template; if
    6621              :      needed, we can create the SAVE_EXPR when instantiating the
    6622              :      template.  Furthermore, the middle-end cannot handle C++-specific
    6623              :      tree codes.  */
    6624       330995 :   if (processing_template_decl)
    6625              :     return expr;
    6626              : 
    6627              :   /* TARGET_EXPRs are only expanded once.  */
    6628       255288 :   if (TREE_CODE (expr) == TARGET_EXPR)
    6629              :     return expr;
    6630              : 
    6631       255288 :   return save_expr (expr);
    6632              : }
    6633              : 
    6634              : /* Initialize tree.cc.  */
    6635              : 
    6636              : void
    6637       101479 : init_tree (void)
    6638              : {
    6639       101479 :   list_hash_table = hash_table<list_hasher>::create_ggc (61);
    6640       101479 : }
    6641              : 
    6642              : /* Returns the kind of special function that DECL (a FUNCTION_DECL)
    6643              :    is.  Note that sfk_none is zero, so this function can be used as a
    6644              :    predicate to test whether or not DECL is a special function.  */
    6645              : 
    6646              : special_function_kind
    6647    156730704 : special_function_p (const_tree decl)
    6648              : {
    6649              :   /* Rather than doing all this stuff with magic names, we should
    6650              :      probably have a field of type `special_function_kind' in
    6651              :      DECL_LANG_SPECIFIC.  */
    6652    313461408 :   if (DECL_INHERITED_CTOR (decl))
    6653              :     return sfk_inheriting_constructor;
    6654    312678070 :   if (DECL_COPY_CONSTRUCTOR_P (decl))
    6655              :     return sfk_copy_constructor;
    6656    282507530 :   if (DECL_MOVE_CONSTRUCTOR_P (decl))
    6657              :     return sfk_move_constructor;
    6658    262424862 :   if (DECL_CONSTRUCTOR_P (decl))
    6659              :     return sfk_constructor;
    6660    112548920 :   if (DECL_ASSIGNMENT_OPERATOR_P (decl)
    6661    112548920 :       && DECL_OVERLOADED_OPERATOR_IS (decl, NOP_EXPR))
    6662              :     {
    6663     12880893 :       if (copy_fn_p (decl))
    6664              :         return sfk_copy_assignment;
    6665      5133423 :       if (move_fn_p (decl))
    6666              :         return sfk_move_assignment;
    6667              :     }
    6668     99881736 :   if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl))
    6669              :     return sfk_destructor;
    6670     57924107 :   if (DECL_COMPLETE_DESTRUCTOR_P (decl))
    6671              :     return sfk_complete_destructor;
    6672     44034917 :   if (DECL_BASE_DESTRUCTOR_P (decl))
    6673              :     return sfk_base_destructor;
    6674     43089655 :   if (DECL_DELETING_DESTRUCTOR_P (decl))
    6675              :     return sfk_deleting_destructor;
    6676     31069051 :   if (DECL_CONV_FN_P (decl))
    6677              :     return sfk_conversion;
    6678     31066702 :   if (deduction_guide_p (decl))
    6679              :     return sfk_deduction_guide;
    6680     31037040 :   if (DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) >= OVL_OP_EQ_EXPR
    6681     31037040 :       && DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) <= OVL_OP_SPACESHIP_EXPR)
    6682      4377418 :     return sfk_comparison;
    6683              : 
    6684              :   return sfk_none;
    6685              : }
    6686              : 
    6687              : /* As above, but only if DECL is a special member function as per 11.3.3
    6688              :    [special]: default/copy/move ctor, copy/move assignment, or destructor.  */
    6689              : 
    6690              : special_function_kind
    6691      3103278 : special_memfn_p (const_tree decl)
    6692              : {
    6693      3103278 :   switch (special_function_kind sfk = special_function_p (decl))
    6694              :     {
    6695      2863471 :     case sfk_constructor:
    6696      2863471 :       if (!default_ctor_p (decl))
    6697              :         break;
    6698              :       gcc_fallthrough();
    6699              :     case sfk_copy_constructor:
    6700              :     case sfk_copy_assignment:
    6701              :     case sfk_move_assignment:
    6702              :     case sfk_move_constructor:
    6703              :     case sfk_destructor:
    6704              :       return sfk;
    6705              : 
    6706              :     default:
    6707              :       break;
    6708              :     }
    6709              :   return sfk_none;
    6710              : }
    6711              : 
    6712              : /* Returns nonzero if TYPE is a character type, including wchar_t.  */
    6713              : 
    6714              : int
    6715     12888627 : char_type_p (tree type)
    6716              : {
    6717     12888627 :   return (same_type_p (type, char_type_node)
    6718     11686249 :           || same_type_p (type, unsigned_char_type_node)
    6719     11633068 :           || same_type_p (type, signed_char_type_node)
    6720     11632491 :           || same_type_p (type, char8_type_node)
    6721     11632351 :           || same_type_p (type, char16_type_node)
    6722     11631841 :           || same_type_p (type, char32_type_node)
    6723     24398165 :           || same_type_p (type, wchar_type_node));
    6724              : }
    6725              : 
    6726              : /* Returns the kind of linkage associated with the indicated DECL.  The
    6727              :    value returned is as specified by the language standard; it is
    6728              :    independent of implementation details regarding template
    6729              :    instantiation, etc.  For example, it is possible that a declaration
    6730              :    to which this function assigns external linkage would not show up
    6731              :    as a global symbol when you run `nm' on the resulting object file.  */
    6732              : 
    6733              : linkage_kind
    6734    482120556 : decl_linkage (tree decl)
    6735              : {
    6736              :   /* This function doesn't attempt to calculate the linkage from first
    6737              :      principles as given in [basic.link].  Instead, it makes use of
    6738              :      the fact that we have already set TREE_PUBLIC appropriately, and
    6739              :      then handles a few special cases.  Ideally, we would calculate
    6740              :      linkage first, and then transform that into a concrete
    6741              :      implementation.  */
    6742              : 
    6743              :   /* An explicit type alias has no linkage.  Nor do the built-in declarations
    6744              :      of 'int' and such.  */
    6745    530409146 :   if (TREE_CODE (decl) == TYPE_DECL
    6746    530409146 :       && !DECL_IMPLICIT_TYPEDEF_P (decl))
    6747              :     {
    6748              :       /* But this could be a typedef name for linkage purposes, in which
    6749              :          case we're interested in the linkage of the main decl.  */
    6750      1025434 :       tree type = TREE_TYPE (decl);
    6751      1025434 :       if (type == error_mark_node)
    6752              :         return lk_none;
    6753      1025432 :       else if (decl == TYPE_NAME (TYPE_MAIN_VARIANT (type))
    6754              :                /* Likewise for the injected-class-name.  */
    6755      1025432 :                || DECL_SELF_REFERENCE_P (decl))
    6756        72777 :         decl = TYPE_MAIN_DECL (type);
    6757              :       else
    6758              :         return lk_none;
    6759              :     }
    6760              : 
    6761              :   /* Namespace-scope entities with no name usually have no linkage.  */
    6762    529456489 :   if (NAMESPACE_SCOPE_P (decl)
    6763   1006879122 :       && (!DECL_NAME (decl) || IDENTIFIER_ANON_P (DECL_NAME (decl))))
    6764              :     {
    6765      3920589 :       if (TREE_CODE (decl) == TYPE_DECL && !TYPE_UNNAMED_P (TREE_TYPE (decl)))
    6766              :         /* This entity has a name for linkage purposes.  */;
    6767      3899465 :       else if (DECL_DECOMPOSITION_P (decl) && DECL_DECOMP_IS_BASE (decl))
    6768              :         /* Namespace-scope structured bindings can have linkage.  */;
    6769      3899360 :       else if (TREE_CODE (decl) == NAMESPACE_DECL && cxx_dialect >= cxx11)
    6770              :         /* An anonymous namespace has internal linkage since C++11.  */
    6771              :         return lk_internal;
    6772              :       else
    6773      3899360 :         return lk_none;
    6774              :     }
    6775              : 
    6776              :   /* Fields and parameters have no linkage.  */
    6777    525557129 :   if (TREE_CODE (decl) == FIELD_DECL || TREE_CODE (decl) == PARM_DECL)
    6778              :     return lk_none;
    6779              : 
    6780              :   /* Things in block scope do not have linkage.  */
    6781    477743156 :   if (decl_function_context (decl))
    6782              :     return lk_none;
    6783              : 
    6784              :   /* Things in class scope have the linkage of their owning class.  */
    6785    473999820 :   if (tree ctype = DECL_CLASS_CONTEXT (decl))
    6786     48288590 :     return decl_linkage (TYPE_NAME (ctype));
    6787              : 
    6788              :   /* Anonymous namespaces don't provide internal linkage in C++98,
    6789              :      but otherwise consider such declarations to be internal.  */
    6790    425711230 :   if (cxx_dialect >= cxx11 && decl_internal_context_p (decl))
    6791              :     return lk_internal;
    6792              : 
    6793              :   /* Helper to decide if T is lk_module or lk_external.  */
    6794    850887679 :   auto external_or_module = [] (tree t)
    6795              :     {
    6796    425362293 :       if (t
    6797    425362260 :           && DECL_LANG_SPECIFIC (t)
    6798    313469310 :           && DECL_MODULE_ATTACH_P (t)
    6799    425380309 :           && !DECL_MODULE_EXPORT_P (t))
    6800         7583 :         return lk_module;
    6801              : 
    6802              :       return lk_external;
    6803              :     };
    6804              : 
    6805              :   /* Templates don't properly propagate TREE_PUBLIC, consider the
    6806              :      template result instead.  Any template that isn't a variable
    6807              :      or function must be external linkage by this point.  */
    6808    425525386 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    6809              :     {
    6810      1337737 :       decl = DECL_TEMPLATE_RESULT (decl);
    6811      1337737 :       if (!decl || !VAR_OR_FUNCTION_DECL_P (decl))
    6812       621376 :         return external_or_module (decl);
    6813              :     }
    6814              : 
    6815              :   /* Things that are TREE_PUBLIC have external linkage.  */
    6816    424904010 :   if (TREE_PUBLIC (decl))
    6817    332494438 :     return external_or_module (decl);
    6818              : 
    6819              :   /* All types have external linkage in C++98, since anonymous namespaces
    6820              :      didn't explicitly confer internal linkage.  */
    6821     92409572 :   if (TREE_CODE (decl) == TYPE_DECL && cxx_dialect < cxx11)
    6822            4 :     return external_or_module (decl);
    6823              : 
    6824              :   /* Variables or function decls not marked as TREE_PUBLIC might still
    6825              :      be external linkage, such as for template instantiations on targets
    6826              :      without weak symbols, decls referring to internal-linkage entities,
    6827              :      or compiler-generated entities; in such cases, decls really meant to
    6828              :      have internal linkage will have DECL_THIS_STATIC set.  */
    6829     92409568 :   if (VAR_OR_FUNCTION_DECL_P (decl) && !DECL_THIS_STATIC (decl))
    6830     92246475 :     return external_or_module (decl);
    6831              : 
    6832              :   /* Everything else has internal linkage.  */
    6833              :   return lk_internal;
    6834              : }
    6835              : 
    6836              : /* Returns the storage duration of the object or reference associated with
    6837              :    the indicated DECL, which should be a VAR_DECL or PARM_DECL.  */
    6838              : 
    6839              : duration_kind
    6840     64027251 : decl_storage_duration (tree decl)
    6841              : {
    6842     64027251 :   if (TREE_CODE (decl) == PARM_DECL)
    6843              :     return dk_auto;
    6844     64027239 :   if (TREE_CODE (decl) == FUNCTION_DECL)
    6845              :     return dk_static;
    6846     64027239 :   gcc_assert (VAR_P (decl));
    6847     64027239 :   if (!TREE_STATIC (decl)
    6848     64027239 :       && !DECL_EXTERNAL (decl))
    6849              :     return dk_auto;
    6850     38510821 :   if (CP_DECL_THREAD_LOCAL_P (decl))
    6851        21074 :     return dk_thread;
    6852              :   return dk_static;
    6853              : }
    6854              : 
    6855              : /* EXP is an expression that we want to pre-evaluate.  Returns (in
    6856              :    *INITP) an expression that will perform the pre-evaluation.  The
    6857              :    value returned by this function is a side-effect free expression
    6858              :    equivalent to the pre-evaluated expression.  Callers must ensure
    6859              :    that *INITP is evaluated before EXP.
    6860              : 
    6861              :    Note that if EXPR is a glvalue, the return value is a glvalue denoting the
    6862              :    same address; this function does not guard against modification of the
    6863              :    stored value like save_expr or get_target_expr do.  */
    6864              : 
    6865              : tree
    6866      6187512 : stabilize_expr (tree exp, tree* initp)
    6867              : {
    6868      6187512 :   tree init_expr;
    6869              : 
    6870      6187512 :   if (!TREE_SIDE_EFFECTS (exp))
    6871              :     init_expr = NULL_TREE;
    6872       977986 :   else if (VOID_TYPE_P (TREE_TYPE (exp)))
    6873              :     {
    6874            0 :       init_expr = exp;
    6875            0 :       exp = void_node;
    6876              :     }
    6877              :   /* There are no expressions with REFERENCE_TYPE, but there can be call
    6878              :      arguments with such a type; just treat it as a pointer.  */
    6879       977986 :   else if (TYPE_REF_P (TREE_TYPE (exp))
    6880       977851 :            || SCALAR_TYPE_P (TREE_TYPE (exp))
    6881       978046 :            || !glvalue_p (exp))
    6882              :     {
    6883       977980 :       init_expr = get_target_expr (exp);
    6884       977980 :       exp = TARGET_EXPR_SLOT (init_expr);
    6885       977980 :       if (CLASS_TYPE_P (TREE_TYPE (exp)))
    6886            9 :         exp = move (exp);
    6887              :       else
    6888       977971 :         exp = rvalue (exp);
    6889              :     }
    6890              :   else
    6891              :     {
    6892            6 :       bool xval = !lvalue_p (exp);
    6893            6 :       exp = cp_build_addr_expr (exp, tf_warning_or_error);
    6894            6 :       init_expr = get_target_expr (exp);
    6895            6 :       exp = TARGET_EXPR_SLOT (init_expr);
    6896            6 :       exp = cp_build_fold_indirect_ref (exp);
    6897            6 :       if (xval)
    6898            0 :         exp = move (exp);
    6899              :     }
    6900      6187512 :   *initp = init_expr;
    6901              : 
    6902      6187512 :   gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp));
    6903      6187512 :   return exp;
    6904              : }
    6905              : 
    6906              : /* Add NEW_EXPR, an expression whose value we don't care about, after the
    6907              :    similar expression ORIG.  */
    6908              : 
    6909              : tree
    6910      1382295 : add_stmt_to_compound (tree orig, tree new_expr)
    6911              : {
    6912      1382295 :   if (!new_expr || !TREE_SIDE_EFFECTS (new_expr))
    6913              :     return orig;
    6914       694964 :   if (!orig || !TREE_SIDE_EFFECTS (orig))
    6915              :     return new_expr;
    6916        13286 :   return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr);
    6917              : }
    6918              : 
    6919              : /* Like stabilize_expr, but for a call whose arguments we want to
    6920              :    pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6921              :    arguments, while, upon return, *INITP contains an expression to
    6922              :    compute the arguments.  */
    6923              : 
    6924              : void
    6925       683051 : stabilize_call (tree call, tree *initp)
    6926              : {
    6927       683051 :   tree inits = NULL_TREE;
    6928       683051 :   int i;
    6929       683051 :   int nargs = call_expr_nargs (call);
    6930              : 
    6931       683051 :   if (call == error_mark_node || processing_template_decl)
    6932              :     {
    6933           39 :       *initp = NULL_TREE;
    6934           39 :       return;
    6935              :     }
    6936              : 
    6937       683012 :   gcc_assert (TREE_CODE (call) == CALL_EXPR);
    6938              : 
    6939      2049118 :   for (i = 0; i < nargs; i++)
    6940              :     {
    6941      1366106 :       tree init;
    6942      1366106 :       CALL_EXPR_ARG (call, i) =
    6943      1366106 :         stabilize_expr (CALL_EXPR_ARG (call, i), &init);
    6944      1366106 :       inits = add_stmt_to_compound (inits, init);
    6945              :     }
    6946              : 
    6947       683012 :   *initp = inits;
    6948              : }
    6949              : 
    6950              : /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want
    6951              :    to pre-evaluate.  CALL is modified in place to use the pre-evaluated
    6952              :    arguments, while, upon return, *INITP contains an expression to
    6953              :    compute the arguments.  */
    6954              : 
    6955              : static void
    6956            0 : stabilize_aggr_init (tree call, tree *initp)
    6957              : {
    6958            0 :   tree inits = NULL_TREE;
    6959            0 :   int i;
    6960            0 :   int nargs = aggr_init_expr_nargs (call);
    6961              : 
    6962            0 :   if (call == error_mark_node)
    6963              :     return;
    6964              : 
    6965            0 :   gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR);
    6966              : 
    6967            0 :   for (i = 0; i < nargs; i++)
    6968              :     {
    6969            0 :       tree init;
    6970            0 :       AGGR_INIT_EXPR_ARG (call, i) =
    6971            0 :         stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init);
    6972            0 :       inits = add_stmt_to_compound (inits, init);
    6973              :     }
    6974              : 
    6975            0 :   *initp = inits;
    6976              : }
    6977              : 
    6978              : /* Like stabilize_expr, but for an initialization.
    6979              : 
    6980              :    If the initialization is for an object of class type, this function
    6981              :    takes care not to introduce additional temporaries.
    6982              : 
    6983              :    Returns TRUE iff the expression was successfully pre-evaluated,
    6984              :    i.e., if INIT is now side-effect free, except for, possibly, a
    6985              :    single call to a constructor.  */
    6986              : 
    6987              : bool
    6988            0 : stabilize_init (tree init, tree *initp)
    6989              : {
    6990            0 :   tree t = init;
    6991              : 
    6992            0 :   *initp = NULL_TREE;
    6993              : 
    6994            0 :   if (t == error_mark_node || processing_template_decl)
    6995              :     return true;
    6996              : 
    6997            0 :   if (TREE_CODE (t) == INIT_EXPR)
    6998            0 :     t = TREE_OPERAND (t, 1);
    6999            0 :   if (TREE_CODE (t) == TARGET_EXPR)
    7000            0 :     t = TARGET_EXPR_INITIAL (t);
    7001              : 
    7002              :   /* If the RHS can be stabilized without breaking copy elision, stabilize
    7003              :      it.  We specifically don't stabilize class prvalues here because that
    7004              :      would mean an extra copy, but they might be stabilized below.  */
    7005            0 :   if (TREE_CODE (init) == INIT_EXPR
    7006            0 :       && TREE_CODE (t) != CONSTRUCTOR
    7007            0 :       && TREE_CODE (t) != AGGR_INIT_EXPR
    7008            0 :       && (SCALAR_TYPE_P (TREE_TYPE (t))
    7009            0 :           || glvalue_p (t)))
    7010              :     {
    7011            0 :       TREE_OPERAND (init, 1) = stabilize_expr (t, initp);
    7012            0 :       return true;
    7013              :     }
    7014              : 
    7015            0 :   if (TREE_CODE (t) == COMPOUND_EXPR
    7016            0 :       && TREE_CODE (init) == INIT_EXPR)
    7017              :     {
    7018            0 :       tree last = expr_last (t);
    7019              :       /* Handle stabilizing the EMPTY_CLASS_EXPR pattern.  */
    7020            0 :       if (!TREE_SIDE_EFFECTS (last))
    7021              :         {
    7022            0 :           *initp = t;
    7023            0 :           TREE_OPERAND (init, 1) = last;
    7024            0 :           return true;
    7025              :         }
    7026              :     }
    7027              : 
    7028            0 :   if (TREE_CODE (t) == CONSTRUCTOR)
    7029              :     {
    7030              :       /* Aggregate initialization: stabilize each of the field
    7031              :          initializers.  */
    7032            0 :       unsigned i;
    7033            0 :       constructor_elt *ce;
    7034            0 :       bool good = true;
    7035            0 :       vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t);
    7036            0 :       for (i = 0; vec_safe_iterate (v, i, &ce); ++i)
    7037              :         {
    7038            0 :           tree type = TREE_TYPE (ce->value);
    7039            0 :           tree subinit;
    7040            0 :           if (TYPE_REF_P (type)
    7041            0 :               || SCALAR_TYPE_P (type))
    7042            0 :             ce->value = stabilize_expr (ce->value, &subinit);
    7043            0 :           else if (!stabilize_init (ce->value, &subinit))
    7044            0 :             good = false;
    7045            0 :           *initp = add_stmt_to_compound (*initp, subinit);
    7046              :         }
    7047              :       return good;
    7048              :     }
    7049              : 
    7050            0 :   if (TREE_CODE (t) == CALL_EXPR)
    7051              :     {
    7052            0 :       stabilize_call (t, initp);
    7053            0 :       return true;
    7054              :     }
    7055              : 
    7056            0 :   if (TREE_CODE (t) == AGGR_INIT_EXPR)
    7057              :     {
    7058            0 :       stabilize_aggr_init (t, initp);
    7059            0 :       return true;
    7060              :     }
    7061              : 
    7062              :   /* The initialization is being performed via a bitwise copy -- and
    7063              :      the item copied may have side effects.  */
    7064            0 :   return !TREE_SIDE_EFFECTS (init);
    7065              : }
    7066              : 
    7067              : /* Returns true if a cast to TYPE may appear in an integral constant
    7068              :    expression.  */
    7069              : 
    7070              : bool
    7071     98932736 : cast_valid_in_integral_constant_expression_p (tree type)
    7072              : {
    7073     98932736 :   return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
    7074     70723410 :           || cxx_dialect >= cxx11
    7075       487741 :           || dependent_type_p (type)
    7076     99306615 :           || type == error_mark_node);
    7077              : }
    7078              : 
    7079              : /* Return true if we need to fix linkage information of DECL.  */
    7080              : 
    7081              : static bool
    7082        76391 : cp_fix_function_decl_p (tree decl)
    7083              : {
    7084              :   /* Skip if DECL is not externally visible.  */
    7085        76391 :   if (!TREE_PUBLIC (decl))
    7086              :     return false;
    7087              : 
    7088              :   /* We need to fix DECL if it a appears to be exported but with no
    7089              :      function body.  Thunks do not have CFGs and we may need to
    7090              :      handle them specially later.   */
    7091        73970 :   if (!gimple_has_body_p (decl)
    7092        27684 :       && !DECL_THUNK_P (decl)
    7093       101268 :       && !DECL_EXTERNAL (decl))
    7094              :     {
    7095        12916 :       struct cgraph_node *node = cgraph_node::get (decl);
    7096              : 
    7097              :       /* Don't fix same_body aliases.  Although they don't have their own
    7098              :          CFG, they share it with what they alias to.  */
    7099        12916 :       if (!node || !node->alias || !node->num_references ())
    7100         6768 :         return true;
    7101              :     }
    7102              : 
    7103              :   return false;
    7104              : }
    7105              : 
    7106              : /* Clean the C++ specific parts of the tree T. */
    7107              : 
    7108              : void
    7109       744244 : cp_free_lang_data (tree t)
    7110              : {
    7111       744244 :   if (FUNC_OR_METHOD_TYPE_P (t))
    7112              :     {
    7113              :       /* Default args are not interesting anymore.  */
    7114        61655 :       tree argtypes = TYPE_ARG_TYPES (t);
    7115       222103 :       while (argtypes)
    7116              :         {
    7117       160448 :           TREE_PURPOSE (argtypes) = 0;
    7118       160448 :           argtypes = TREE_CHAIN (argtypes);
    7119              :         }
    7120              :     }
    7121       682589 :   else if (TREE_CODE (t) == FUNCTION_DECL
    7122       682589 :            && cp_fix_function_decl_p (t))
    7123              :     {
    7124              :       /* If T is used in this translation unit at all,  the definition
    7125              :          must exist somewhere else since we have decided to not emit it
    7126              :          in this TU.  So make it an external reference.  */
    7127         6768 :       DECL_EXTERNAL (t) = 1;
    7128         6768 :       TREE_STATIC (t) = 0;
    7129              :     }
    7130       744244 :   if (TREE_CODE (t) == NAMESPACE_DECL)
    7131              :     /* We do not need the leftover chaining of namespaces from the
    7132              :        binding level.  */
    7133         1683 :     DECL_CHAIN (t) = NULL_TREE;
    7134       744244 : }
    7135              : 
    7136              : /* Stub for c-common.  Please keep in sync with c-decl.cc.
    7137              :    FIXME: If address space support is target specific, then this
    7138              :    should be a C target hook.  But currently this is not possible,
    7139              :    because this function is called via REGISTER_TARGET_PRAGMAS.  */
    7140              : void
    7141       202958 : c_register_addr_space (const char * /*word*/, addr_space_t /*as*/)
    7142              : {
    7143       202958 : }
    7144              : 
    7145              : /* Return the number of operands in T that we care about for things like
    7146              :    mangling.  */
    7147              : 
    7148              : int
    7149    604075418 : cp_tree_operand_length (const_tree t)
    7150              : {
    7151    604075418 :   enum tree_code code = TREE_CODE (t);
    7152              : 
    7153    604075418 :   if (TREE_CODE_CLASS (code) == tcc_vl_exp)
    7154     69810190 :     return VL_EXP_OPERAND_LENGTH (t);
    7155              : 
    7156    534265228 :   return cp_tree_code_length (code);
    7157              : }
    7158              : 
    7159              : /* Like cp_tree_operand_length, but takes a tree_code CODE.  */
    7160              : 
    7161              : int
    7162    540780038 : cp_tree_code_length (enum tree_code code)
    7163              : {
    7164    540780038 :   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
    7165              : 
    7166    540780038 :   switch (code)
    7167              :     {
    7168              :     case PREINCREMENT_EXPR:
    7169              :     case PREDECREMENT_EXPR:
    7170              :     case POSTINCREMENT_EXPR:
    7171              :     case POSTDECREMENT_EXPR:
    7172              :       return 1;
    7173              : 
    7174      1124719 :     case ARRAY_REF:
    7175      1124719 :       return 2;
    7176              : 
    7177              :     case EXPR_PACK_EXPANSION:
    7178              :       return 1;
    7179              : 
    7180    537089160 :     default:
    7181    537089160 :       return TREE_CODE_LENGTH (code);
    7182              :     }
    7183              : }
    7184              : 
    7185              : /* Implement -Wzero_as_null_pointer_constant.  Return true if the
    7186              :    conditions for the warning hold, false otherwise.  */
    7187              : bool
    7188      7696097 : maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
    7189              : {
    7190      7696097 :   if (c_inhibit_evaluation_warnings == 0
    7191     14333802 :       && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
    7192              :     {
    7193      2747978 :       warning_at (loc, OPT_Wzero_as_null_pointer_constant,
    7194              :                   "zero as null pointer constant");
    7195      2747978 :       return true;
    7196              :     }
    7197              :   return false;
    7198              : }
    7199              : 
    7200              : /* FNDECL is a function declaration whose type may have been altered by
    7201              :    adding extra parameters such as this, in-charge, or VTT.  When this
    7202              :    takes place, the positional arguments supplied by the user (as in the
    7203              :    'format' attribute arguments) may refer to the wrong argument.  This
    7204              :    function returns an integer indicating how many arguments should be
    7205              :    skipped.  */
    7206              : 
    7207              : int
    7208     38475795 : maybe_adjust_arg_pos_for_attribute (const_tree fndecl)
    7209              : {
    7210     38475795 :   if (!fndecl)
    7211              :     return 0;
    7212      7521925 :   int n = num_artificial_parms_for (fndecl);
    7213              :   /* The manual states that it's the user's responsibility to account
    7214              :      for the implicit this parameter.  */
    7215      7521925 :   return n > 0 ? n - 1 : 0;
    7216              : }
    7217              : 
    7218              : /* True if ATTR is annotation.  */
    7219              : 
    7220              : bool
    7221     59197599 : annotation_p (tree attr)
    7222              : {
    7223     59197599 :   return is_attribute_p ("annotation ", get_attribute_name (attr));
    7224              : }
    7225              : 
    7226              : /* Lookup the annotation in ATTR, if present.  */
    7227              : 
    7228              : tree
    7229        74109 : lookup_annotation (tree attr)
    7230              : {
    7231        74109 :   return lookup_attribute ("internal ", "annotation ", attr);
    7232              : }
    7233              : 
    7234              : 
    7235              : /* Release memory we no longer need after parsing.  */
    7236              : void
    7237        99724 : cp_tree_c_finish_parsing ()
    7238              : {
    7239        99724 :   if (previous_class_level)
    7240        70501 :     invalidate_class_lookup_cache ();
    7241        99724 :   deleted_copy_types = NULL;
    7242        99724 : }
    7243              : 
    7244              : #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
    7245              : /* Complain that some language-specific thing hanging off a tree
    7246              :    node has been accessed improperly.  */
    7247              : 
    7248              : void
    7249            0 : lang_check_failed (const char* file, int line, const char* function)
    7250              : {
    7251            0 :   internal_error ("%<lang_*%> check: failed in %s, at %s:%d",
    7252              :                   function, trim_filename (file), line);
    7253              : }
    7254              : #endif /* ENABLE_TREE_CHECKING */
    7255              : 
    7256              : #if CHECKING_P
    7257              : 
    7258              : namespace selftest {
    7259              : 
    7260              : /* Verify that lvalue_kind () works, for various expressions,
    7261              :    and that location wrappers don't affect the results.  */
    7262              : 
    7263              : static void
    7264            1 : test_lvalue_kind ()
    7265              : {
    7266            1 :   location_t loc = BUILTINS_LOCATION;
    7267              : 
    7268              :   /* Verify constants and parameters, without and with
    7269              :      location wrappers.  */
    7270            1 :   tree int_cst = build_int_cst (integer_type_node, 42);
    7271            1 :   ASSERT_EQ (clk_none, lvalue_kind (int_cst));
    7272              : 
    7273            1 :   tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
    7274            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
    7275            1 :   ASSERT_EQ (clk_none, lvalue_kind (wrapped_int_cst));
    7276              : 
    7277            1 :   tree string_lit = build_string (4, "foo");
    7278            1 :   TREE_TYPE (string_lit) = char_array_type_node;
    7279            1 :   string_lit = fix_string_type (string_lit);
    7280            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (string_lit));
    7281              : 
    7282            1 :   tree wrapped_string_lit = maybe_wrap_with_location (string_lit, loc);
    7283            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_string_lit));
    7284            1 :   ASSERT_EQ (clk_ordinary|clk_mergeable, lvalue_kind (wrapped_string_lit));
    7285              : 
    7286            1 :   tree parm = build_decl (UNKNOWN_LOCATION, PARM_DECL,
    7287              :                           get_identifier ("some_parm"),
    7288              :                           integer_type_node);
    7289            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (parm));
    7290              : 
    7291            1 :   tree wrapped_parm = maybe_wrap_with_location (parm, loc);
    7292            1 :   ASSERT_TRUE (location_wrapper_p (wrapped_parm));
    7293            1 :   ASSERT_EQ (clk_ordinary, lvalue_kind (wrapped_parm));
    7294              : 
    7295              :   /* Verify that lvalue_kind of std::move on a parm isn't
    7296              :      affected by location wrappers.  */
    7297            1 :   tree rvalue_ref_of_parm = move (parm);
    7298            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
    7299            1 :   tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
    7300            1 :   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
    7301              : 
    7302              :   /* Verify lvalue_p.  */
    7303            1 :   ASSERT_FALSE (lvalue_p (int_cst));
    7304            1 :   ASSERT_FALSE (lvalue_p (wrapped_int_cst));
    7305            1 :   ASSERT_TRUE (lvalue_p (parm));
    7306            1 :   ASSERT_TRUE (lvalue_p (wrapped_parm));
    7307            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
    7308            1 :   ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
    7309            1 : }
    7310              : 
    7311              : /* Run all of the selftests within this file.  */
    7312              : 
    7313              : void
    7314            1 : cp_tree_cc_tests ()
    7315              : {
    7316            1 :   test_lvalue_kind ();
    7317            1 : }
    7318              : 
    7319              : } // namespace selftest
    7320              : 
    7321              : #endif /* #if CHECKING_P */
    7322              : 
    7323              : 
    7324              : #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.