LCOV - code coverage report
Current view: top level - gcc/cp - mangle.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.2 % 2259 2106
Test Date: 2026-02-28 14:20:25 Functions: 97.3 % 111 108
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Name mangling for the 3.0 -*- C++ -*- ABI.
       2              :    Copyright (C) 2000-2026 Free Software Foundation, Inc.
       3              :    Written by Alex Samuel <samuel@codesourcery.com>
       4              : 
       5              :    This file is part of GCC.
       6              : 
       7              :    GCC is free software; you can redistribute it and/or modify it
       8              :    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, but
      13              :    WITHOUT ANY WARRANTY; without even the implied warranty of
      14              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15              :    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              : /* This file implements mangling of C++ names according to the IA64
      22              :    C++ ABI specification.  A mangled name encodes a function or
      23              :    variable's name, scope, type, and/or template arguments into a text
      24              :    identifier.  This identifier is used as the function's or
      25              :    variable's linkage name, to preserve compatibility between C++'s
      26              :    language features (templates, scoping, and overloading) and C
      27              :    linkers.
      28              : 
      29              :    Additionally, g++ uses mangled names internally.  To support this,
      30              :    mangling of types is allowed, even though the mangled name of a
      31              :    type should not appear by itself as an exported name.  Ditto for
      32              :    uninstantiated templates.
      33              : 
      34              :    The primary entry point for this module is mangle_decl, which
      35              :    returns an identifier containing the mangled name for a decl.
      36              :    Additional entry points are provided to build mangled names of
      37              :    particular constructs when the appropriate decl for that construct
      38              :    is not available.  These are:
      39              : 
      40              :      mangle_typeinfo_for_type:          typeinfo data
      41              :      mangle_typeinfo_string_for_type:   typeinfo type name
      42              :      mangle_vtbl_for_type:              virtual table data
      43              :      mangle_vtt_for_type:               VTT data
      44              :      mangle_ctor_vtbl_for_type:         `C-in-B' constructor virtual table data
      45              :      mangle_thunk:                      thunk function or entry  */
      46              : 
      47              : #include "config.h"
      48              : #include "system.h"
      49              : #include "coretypes.h"
      50              : #include "target.h"
      51              : #include "vtable-verify.h"
      52              : #include "cp-tree.h"
      53              : #include "stringpool.h"
      54              : #include "cgraph.h"
      55              : #include "stor-layout.h"
      56              : #include "flags.h"
      57              : #include "attribs.h"
      58              : #include "contracts.h"
      59              : 
      60              : /* Debugging support.  */
      61              : 
      62              : /* Define DEBUG_MANGLE to enable very verbose trace messages.  */
      63              : #ifndef DEBUG_MANGLE
      64              : #define DEBUG_MANGLE 0
      65              : #endif
      66              : 
      67              : /* Macros for tracing the write_* functions.  */
      68              : #if DEBUG_MANGLE
      69              : # define MANGLE_TRACE(FN, INPUT) \
      70              :   fprintf (stderr, "  %-24s: %-24s\n", (FN), (INPUT))
      71              : # define MANGLE_TRACE_TREE(FN, NODE) \
      72              :   fprintf (stderr, "  %-24s: %-24s (%p)\n", \
      73              :            (FN), get_tree_code_name (TREE_CODE (NODE)), (void *) (NODE))
      74              : #else
      75              : # define MANGLE_TRACE(FN, INPUT)
      76              : # define MANGLE_TRACE_TREE(FN, NODE)
      77              : #endif
      78              : 
      79              : /* Nonzero if NODE is a class template-id.  We can't rely on
      80              :    CLASSTYPE_USE_TEMPLATE here because of tricky bugs in the parser
      81              :    that hard to distinguish A<T> from A, where A<T> is the type as
      82              :    instantiated outside of the template, and A is the type used
      83              :    without parameters inside the template.  */
      84              : #define CLASSTYPE_TEMPLATE_ID_P(NODE)                                   \
      85              :   (TREE_CODE (NODE) == BOUND_TEMPLATE_TEMPLATE_PARM                     \
      86              :    || (CLASS_TYPE_P (NODE)                                              \
      87              :        && CLASSTYPE_TEMPLATE_INFO (NODE) != NULL                        \
      88              :        && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE))))
      89              : 
      90              : /* For deciding whether to set G.need_abi_warning, we need to consider both
      91              :    warn_abi_version and flag_abi_compat_version.  */
      92              : #define abi_warn_or_compat_version_crosses(N) \
      93              :   (abi_version_crosses (N) || abi_compat_version_crosses (N))
      94              : 
      95              : /* And sometimes we can simplify the code path if we don't need to worry about
      96              :    previous ABIs.  */
      97              : #define abi_flag_at_least(flag,N) (flag == 0 || flag >= N)
      98              : #define any_abi_below(N) \
      99              :   (!abi_version_at_least (N) \
     100              :    || !abi_flag_at_least (warn_abi_version, (N)) \
     101              :    || !abi_flag_at_least (flag_abi_compat_version, (N)))
     102              : 
     103              : /* Things we only need one of.  This module is not reentrant.  */
     104              : struct GTY(()) globals {
     105              :   /* An array of the current substitution candidates, in the order
     106              :      we've seen them.  Contains NULLS, which correspond to module
     107              :      substitutions.  */
     108              :   vec<tree, va_gc> *substitutions;
     109              : 
     110              :   /* The entity that is being mangled.  */
     111              :   tree GTY ((skip)) entity;
     112              : 
     113              :   /* How many parameter scopes we are inside.  */
     114              :   int parm_depth;
     115              : 
     116              :   /* True if the mangling will be different in a future version of the
     117              :      ABI.  */
     118              :   bool need_abi_warning;
     119              : 
     120              :   /* True if the mangling will be different in C++17 mode.  */
     121              :   bool need_cxx17_warning;
     122              : 
     123              :   /* True if we mangled a module name.  */
     124              :   bool mod;
     125              : };
     126              : 
     127              : static GTY (()) globals G;
     128              : 
     129              : /* The obstack on which we build mangled names.  */
     130              : static struct obstack *mangle_obstack;
     131              : 
     132              : /* The obstack on which we build mangled names that are not going to
     133              :    be IDENTIFIER_NODEs.  */
     134              : static struct obstack name_obstack;
     135              : 
     136              : /* The first object on the name_obstack; we use this to free memory
     137              :    allocated on the name_obstack.  */
     138              : static void *name_base;
     139              : 
     140              : /* Indices into subst_identifiers.  These are identifiers used in
     141              :    special substitution rules.  */
     142              : typedef enum
     143              : {
     144              :   SUBID_ALLOCATOR,
     145              :   SUBID_BASIC_STRING,
     146              :   SUBID_CHAR_TRAITS,
     147              :   SUBID_BASIC_ISTREAM,
     148              :   SUBID_BASIC_OSTREAM,
     149              :   SUBID_BASIC_IOSTREAM,
     150              :   SUBID_MAX
     151              : }
     152              : substitution_identifier_index_t;
     153              : 
     154              : /* For quick substitution checks, look up these common identifiers
     155              :    once only.  */
     156              : static GTY(()) tree subst_identifiers[SUBID_MAX];
     157              : 
     158              : /* Single-letter codes for builtin integer types, defined in
     159              :    <builtin-type>.  These are indexed by integer_type_kind values.  */
     160              : static const char
     161              : integer_type_codes[itk_none] =
     162              : {
     163              :   'c',  /* itk_char */
     164              :   'a',  /* itk_signed_char */
     165              :   'h',  /* itk_unsigned_char */
     166              :   's',  /* itk_short */
     167              :   't',  /* itk_unsigned_short */
     168              :   'i',  /* itk_int */
     169              :   'j',  /* itk_unsigned_int */
     170              :   'l',  /* itk_long */
     171              :   'm',  /* itk_unsigned_long */
     172              :   'x',  /* itk_long_long */
     173              :   'y',  /* itk_unsigned_long_long */
     174              :   /* __intN types are handled separately */
     175              :   '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'
     176              : };
     177              : 
     178              : static tree maybe_template_info (const tree);
     179              : 
     180              : /* Functions for handling substitutions.  */
     181              : 
     182              : static inline tree canonicalize_for_substitution (tree);
     183              : static void add_substitution (tree);
     184              : static inline bool is_std_substitution (const tree,
     185              :                                        const substitution_identifier_index_t);
     186              : static inline bool is_std_substitution_char (const tree,
     187              :                                             const substitution_identifier_index_t);
     188              : static int find_substitution (tree);
     189              : static void mangle_call_offset (const tree, const tree);
     190              : 
     191              : /* Functions for emitting mangled representations of things.  */
     192              : 
     193              : static void write_mangled_name (const tree, bool);
     194              : static void write_encoding (const tree);
     195              : static void write_name (tree, const int);
     196              : static void write_abi_tags (tree);
     197              : static void write_unscoped_name (const tree);
     198              : static void write_unscoped_template_name (const tree);
     199              : static void write_nested_name (const tree);
     200              : static void write_prefix (const tree);
     201              : static void write_template_prefix (const tree);
     202              : static void write_unqualified_name (tree);
     203              : static void write_conversion_operator_name (const tree);
     204              : static void write_source_name (tree);
     205              : static void write_literal_operator_name (tree);
     206              : static void write_unnamed_type_name (const tree);
     207              : static void write_unnamed_enum_name (const tree);
     208              : static void write_closure_type_name (const tree);
     209              : static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
     210              :                            const unsigned int);
     211              : static void write_number (unsigned HOST_WIDE_INT, const int,
     212              :                           const unsigned int);
     213              : static void write_compact_number (int num);
     214              : static void write_integer_cst (const tree);
     215              : static void write_real_cst (const tree);
     216              : static void write_identifier (const char *);
     217              : static void write_special_name_constructor (const tree);
     218              : static void write_special_name_destructor (const tree);
     219              : static void write_type (tree);
     220              : static int write_CV_qualifiers_for_type (const tree);
     221              : static void write_builtin_type (tree);
     222              : static void write_function_type (const tree);
     223              : static void write_bare_function_type (const tree, const int, const tree);
     224              : static void write_method_parms (tree, const int, const tree);
     225              : static void write_class_enum_type (const tree);
     226              : static void write_template_args (tree, tree = NULL_TREE);
     227              : static void write_expression (tree);
     228              : static void write_template_arg_literal (const tree);
     229              : static void write_template_arg (tree);
     230              : static void write_template_template_arg (const tree);
     231              : static void write_array_type (const tree);
     232              : static void write_pointer_to_member_type (const tree);
     233              : static void write_template_param (const tree);
     234              : static void write_template_template_param (const tree);
     235              : static void write_substitution (const int);
     236              : static int discriminator_for_local_entity (tree);
     237              : static int discriminator_for_string_literal (tree, tree);
     238              : static void write_discriminator (const int);
     239              : static void write_local_name (tree, const tree, const tree);
     240              : static void dump_substitution_candidates (void);
     241              : static tree mangle_decl_string (const tree);
     242              : static void maybe_check_abi_tags (tree, tree = NULL_TREE, int = 10);
     243              : 
     244              : /* Control functions.  */
     245              : 
     246              : static inline void start_mangling (const tree);
     247              : static tree mangle_special_for_type (const tree, const char *);
     248              : 
     249              : /* Append a single character to the end of the mangled
     250              :    representation.  */
     251              : #define write_char(CHAR)                                                \
     252              :   obstack_1grow (mangle_obstack, (CHAR))
     253              : 
     254              : /* Append a sized buffer to the end of the mangled representation.  */
     255              : #define write_chars(CHAR, LEN)                                          \
     256              :   obstack_grow (mangle_obstack, (CHAR), (LEN))
     257              : 
     258              : /* Append a NUL-terminated string to the end of the mangled
     259              :    representation.  */
     260              : #define write_string(STRING)                                            \
     261              :   obstack_grow (mangle_obstack, (STRING), strlen (STRING))
     262              : 
     263              : /* Nonzero if NODE1 and NODE2 are both TREE_LIST nodes and have the
     264              :    same purpose (context, which may be a type) and value (template
     265              :    decl).  See write_template_prefix for more information on what this
     266              :    is used for.  */
     267              : #define NESTED_TEMPLATE_MATCH(NODE1, NODE2)                             \
     268              :   (TREE_CODE (NODE1) == TREE_LIST                                       \
     269              :    && TREE_CODE (NODE2) == TREE_LIST                                    \
     270              :    && ((TYPE_P (TREE_PURPOSE (NODE1))                                   \
     271              :         && same_type_p (TREE_PURPOSE (NODE1), TREE_PURPOSE (NODE2)))    \
     272              :        || TREE_PURPOSE (NODE1) == TREE_PURPOSE (NODE2))                 \
     273              :    && TREE_VALUE (NODE1) == TREE_VALUE (NODE2))
     274              : 
     275              : /* Write out an unsigned quantity in base 10.  */
     276              : #define write_unsigned_number(NUMBER)                                   \
     277              :   write_number ((NUMBER), /*unsigned_p=*/1, 10)
     278              : 
     279              : /* Check for -fabi-version dependent mangling and also set the need_abi_warning
     280              :    flag as appropriate.  */
     281              : 
     282              : static bool
     283     16169237 : abi_check (int ver)
     284              : {
     285     80731024 :   if (abi_warn_or_compat_version_crosses (ver))
     286        61243 :     G.need_abi_warning = true;
     287     16169237 :   return abi_version_at_least (ver);
     288              : }
     289              : 
     290              : /* If DECL is a template instance (including the uninstantiated template
     291              :    itself), return its TEMPLATE_INFO.  Otherwise return NULL.  */
     292              : 
     293              : static tree
     294   1456503338 : maybe_template_info (const tree decl)
     295              : {
     296   1456503338 :   if (TREE_CODE (decl) == TYPE_DECL)
     297              :     {
     298              :       /* TYPE_DECLs are handled specially.  Look at its type to decide
     299              :          if this is a template instantiation.  */
     300    561802019 :       const tree type = TREE_TYPE (decl);
     301              : 
     302    561802019 :       if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_ID_P (type))
     303    447795552 :         return TYPE_TEMPLATE_INFO (type);
     304              :     }
     305              :   else
     306              :     {
     307              :       /* Check if the template is a primary template.  */
     308    894701319 :       if (DECL_LANG_SPECIFIC (decl) != NULL
     309    893434477 :           && VAR_OR_FUNCTION_DECL_P (decl)
     310    752666573 :           && DECL_TEMPLATE_INFO (decl)
     311   1491836050 :           && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
     312    109357734 :         return DECL_TEMPLATE_INFO (decl);
     313              :     }
     314              : 
     315              :   /* It's not a template id.  */
     316              :   return NULL_TREE;
     317              : }
     318              : 
     319              : /* Produce debugging output of current substitution candidates.  */
     320              : 
     321              : static void
     322            0 : dump_substitution_candidates (void)
     323              : {
     324            0 :   unsigned i;
     325            0 :   tree el;
     326              : 
     327            0 :   fprintf (stderr, "  ++ substitutions  ");
     328            0 :   FOR_EACH_VEC_ELT (*G.substitutions, i, el)
     329              :     {
     330            0 :       const char *name = "???";
     331              : 
     332            0 :       if (i > 0)
     333            0 :         fprintf (stderr, "                    ");
     334            0 :       if (!el)
     335              :         name = "module";
     336            0 :       else if (DECL_P (el))
     337            0 :         name = IDENTIFIER_POINTER (DECL_NAME (el));
     338            0 :       else if (TREE_CODE (el) == TREE_LIST)
     339            0 :         name = IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (el)));
     340            0 :       else if (TYPE_NAME (el))
     341            0 :         name = TYPE_NAME_STRING (el);
     342            0 :       fprintf (stderr, " S%d_ = ", i - 1);
     343            0 :       if (el)
     344              :         {
     345            0 :           if (TYPE_P (el) &&
     346            0 :               (CP_TYPE_RESTRICT_P (el)
     347            0 :                || CP_TYPE_VOLATILE_P (el)
     348            0 :                || CP_TYPE_CONST_P (el)))
     349            0 :             fprintf (stderr, "CV-");
     350            0 :           fprintf (stderr, "%s (%s at %p)",
     351            0 :                    name, get_tree_code_name (TREE_CODE (el)), (void *) el);
     352              :         }
     353            0 :       fprintf (stderr, "\n");
     354              :     }
     355            0 : }
     356              : 
     357              : /* <exception-spec> ::=
     358              :       Do  -- non-throwing exception specification
     359              :       DO <expression> E  -- computed (instantiation-dependent) noexcept
     360              :       Dw <type>* E  -- throw (types)  */
     361              : 
     362              : static void
     363      3073459 : write_exception_spec (tree spec)
     364              : {
     365              : 
     366      3073459 :   if (!spec || spec == noexcept_false_spec)
     367              :     /* Nothing.  */
     368              :     return;
     369              : 
     370        33596 :   if (!flag_noexcept_type)
     371              :     {
     372           17 :       G.need_cxx17_warning = true;
     373           17 :       return;
     374              :     }
     375              : 
     376        33579 :   if (spec == noexcept_true_spec || spec == empty_except_spec)
     377        33564 :     write_string ("Do");
     378           15 :   else if (tree expr = TREE_PURPOSE (spec))
     379              :     {
     380              :       /* noexcept (expr)  */
     381           15 :       gcc_assert (uses_template_parms (expr));
     382           15 :       write_string ("DO");
     383           15 :       write_expression (expr);
     384           15 :       write_char ('E');
     385              :     }
     386              :   else
     387              :     {
     388              :       /* throw (type-list) */
     389            0 :       write_string ("Dw");
     390            0 :       for (tree t = spec; t; t = TREE_CHAIN (t))
     391            0 :         write_type (TREE_VALUE (t));
     392            0 :       write_char ('E');
     393              :     }
     394              : }
     395              : 
     396              : /* Both decls and types can be substitution candidates, but sometimes
     397              :    they refer to the same thing.  For instance, a TYPE_DECL and
     398              :    RECORD_TYPE for the same class refer to the same thing, and should
     399              :    be treated accordingly in substitutions.  This function returns a
     400              :    canonicalized tree node representing NODE that is used when adding
     401              :    and substitution candidates and finding matches.  */
     402              : 
     403              : static inline tree
     404   5167147538 : canonicalize_for_substitution (tree node)
     405              : {
     406              :   /* For a TYPE_DECL, use the type instead.  */
     407   5167147538 :   if (TREE_CODE (node) == TYPE_DECL)
     408          912 :     node = TREE_TYPE (node);
     409   5167147538 :   if (TYPE_P (node)
     410   3779357847 :       && TYPE_CANONICAL (node) != node
     411   5603216047 :       && TYPE_MAIN_VARIANT (node) != node)
     412              :     {
     413    114514448 :       tree orig = node;
     414              :       /* Here we want to strip the topmost typedef only.
     415              :          We need to do that so is_std_substitution can do proper
     416              :          name matching.  */
     417    114514448 :       if (TREE_CODE (node) == FUNCTION_TYPE)
     418              :         /* Use build_qualified_type and TYPE_QUALS here to preserve
     419              :            the old buggy mangling of attribute noreturn with abi<5.  */
     420        27153 :         node = build_qualified_type (TYPE_MAIN_VARIANT (node),
     421        27153 :                                      TYPE_QUALS (node));
     422              :       else
     423    114487295 :         node = cp_build_qualified_type (TYPE_MAIN_VARIANT (node),
     424              :                                         cp_type_quals (node));
     425    114514448 :       if (FUNC_OR_METHOD_TYPE_P (node))
     426              :         {
     427        27162 :           node = build_ref_qualified_type (node, type_memfn_rqual (orig));
     428        27162 :           tree r = canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (orig));
     429        27162 :           if (flag_noexcept_type)
     430        27118 :             node = build_exception_variant (node, r);
     431              :           else
     432              :             /* Set the warning flag if appropriate.  */
     433           44 :             write_exception_spec (r);
     434              :         }
     435              :     }
     436   5167147538 :   return node;
     437              : }
     438              : 
     439              : /* Add NODE as a substitution candidate.  NODE must not already be on
     440              :    the list of candidates.  */
     441              : 
     442              : static void
     443   1348634378 : add_substitution (tree node)
     444              : {
     445   1348634378 :   tree c;
     446              : 
     447   1348634378 :   if (DEBUG_MANGLE)
     448              :     fprintf (stderr, "  ++ add_substitution (%s at %10p)\n",
     449              :              get_tree_code_name (TREE_CODE (node)), (void *) node);
     450              : 
     451              :   /* Get the canonicalized substitution candidate for NODE.  */
     452   1348634378 :   c = canonicalize_for_substitution (node);
     453   1348634378 :   if (DEBUG_MANGLE && c != node)
     454              :     fprintf (stderr, "  ++ using candidate (%s at %10p)\n",
     455              :              get_tree_code_name (TREE_CODE (node)), (void *) node);
     456   1348634378 :   node = c;
     457              : 
     458              :   /* Make sure NODE isn't already a candidate.  */
     459   1348634378 :   if (flag_checking)
     460              :     {
     461              :       int i;
     462              :       tree candidate;
     463              : 
     464   7184014444 :       FOR_EACH_VEC_SAFE_ELT (G.substitutions, i, candidate)
     465   5835380182 :         if (candidate)
     466              :           {
     467   5835373363 :             gcc_assert (!(DECL_P (node) && node == candidate));
     468   5835373363 :             gcc_assert (!(TYPE_P (node) && TYPE_P (candidate)
     469              :                           && same_type_p (node, candidate)));
     470              :           }
     471              :     }
     472              : 
     473              :   /* Put the decl onto the varray of substitution candidates.  */
     474   1348634378 :   vec_safe_push (G.substitutions, node);
     475              : 
     476   1348634378 :   if (DEBUG_MANGLE)
     477              :     dump_substitution_candidates ();
     478   1348634378 : }
     479              : 
     480              : /* Helper function for find_substitution.  Returns nonzero if NODE,
     481              :    which may be a class or a class template, is a template-id with template
     482              :    name of substitution_index[INDEX] in the ::std namespace, with
     483              :    global module attachment.  */
     484              : 
     485              : static bool
     486   4535659642 : is_std_substitution (const tree node,
     487              :                      const substitution_identifier_index_t index)
     488              : {
     489   4535659642 :   tree type = NULL_TREE;
     490   4535659642 :   tree decl = NULL_TREE;
     491              : 
     492   9039463375 :   auto std_substitution_p = [&] (tree decl, tree type)
     493              :     {
     494   4503803733 :       if (!DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl)))
     495              :         return false;
     496              : 
     497   1708542332 :       if (!(TYPE_LANG_SPECIFIC (type) && TYPE_TEMPLATE_INFO (type)))
     498              :         return false;
     499              : 
     500   1252237446 :       tree tmpl = TYPE_TI_TEMPLATE (type);
     501   1252237446 :       if (DECL_NAME (tmpl) != subst_identifiers[index])
     502              :         return false;
     503              : 
     504    141650992 :       if (modules_p () && get_originating_module (tmpl, true) >= 0)
     505           27 :         return false;
     506              : 
     507              :       return true;
     508   4535659642 :     };
     509              : 
     510   4535659642 :   if (TREE_CODE (node) == TYPE_DECL || DECL_CLASS_TEMPLATE_P (node))
     511              :     {
     512   3559934729 :       type = TREE_TYPE (node);
     513   3559934729 :       decl = node;
     514              :     }
     515    975724913 :   else if (CLASS_TYPE_P (node))
     516              :     {
     517      6578945 :       type = node;
     518      6578945 :       decl = TYPE_NAME (node);
     519              :     }
     520              :   else
     521              :     {
     522              :       /* We used to accept all _DECL nodes in this function but now we
     523              :          only accept classes or class templates.  Verify that we don't
     524              :          return false for something that used to yield true.  */
     525    969145968 :       gcc_checking_assert (!DECL_P (node)
     526              :                            || !std_substitution_p (node, TREE_TYPE (node)));
     527              :       /* These are not the droids you're looking for.  */
     528              :       return false;
     529              :     }
     530              : 
     531   3566513674 :   return std_substitution_p (decl, type);
     532              : }
     533              : 
     534              : /* Return the ABI tags (the TREE_VALUE of the "abi_tag" attribute entry) for T,
     535              :    which can be a decl or type.  */
     536              : 
     537              : static tree
     538   1971062348 : get_abi_tags (tree t)
     539              : {
     540   1971062348 :   if (!t || TREE_CODE (t) == NAMESPACE_DECL)
     541              :     return NULL_TREE;
     542              : 
     543   1831175804 :   if (DECL_P (t) && DECL_DECLARES_TYPE_P (t))
     544    497007163 :     t = TREE_TYPE (t);
     545              : 
     546   1831175804 :   if (TREE_CODE (t) == TEMPLATE_DECL && DECL_TEMPLATE_RESULT (t))
     547              :     {
     548     20601724 :       tree tags = get_abi_tags (DECL_TEMPLATE_RESULT (t));
     549              :       /* We used to overlook abi_tag on function and variable templates.  */
     550     20601724 :       if (tags && abi_check (19))
     551              :         return tags;
     552              :       else
     553     20601714 :         return NULL_TREE;
     554              :     }
     555              : 
     556   1810574080 :   tree attrs;
     557   1810574080 :   if (TYPE_P (t))
     558   1576239024 :     attrs = TYPE_ATTRIBUTES (t);
     559              :   else
     560    234335056 :     attrs = DECL_ATTRIBUTES (t);
     561              : 
     562   1810574080 :   tree tags = lookup_attribute ("abi_tag", attrs);
     563   1810574080 :   if (tags)
     564     11738966 :     tags = TREE_VALUE (tags);
     565              :   return tags;
     566              : }
     567              : 
     568              : /* Helper function for find_substitution.  Returns nonzero if NODE,
     569              :    which may be a decl or a CLASS_TYPE, is the template-id
     570              :    ::std::identifier<char>, where identifier is
     571              :    substitution_index[INDEX].  */
     572              : 
     573              : static bool
     574      9739486 : is_std_substitution_char (const tree node,
     575              :                           const substitution_identifier_index_t index)
     576              : {
     577      9739486 :   tree args;
     578              :   /* Check NODE's name is ::std::identifier.  */
     579      9739486 :   if (!is_std_substitution (node, index))
     580              :     return 0;
     581              :   /* Figure out its template args.  */
     582      5681134 :   if (DECL_P (node))
     583            0 :     args = DECL_TI_ARGS (node);
     584      5681134 :   else if (CLASS_TYPE_P (node))
     585      5681134 :     args = CLASSTYPE_TI_ARGS (node);
     586              :   else
     587              :     /* Oops, not a template.  */
     588              :     return 0;
     589              :   /* NODE's template arg list should be <char>.  */
     590      5681134 :   return
     591      5681134 :     TREE_VEC_LENGTH (args) == 1
     592      5681134 :     && TREE_VEC_ELT (args, 0) == char_type_node;
     593              : }
     594              : 
     595              : /* Check whether a substitution should be used to represent NODE in
     596              :    the mangling.
     597              : 
     598              :    First, check standard special-case substitutions.
     599              : 
     600              :      <substitution> ::= St
     601              :          # ::std
     602              : 
     603              :                     ::= Sa
     604              :          # ::std::allocator
     605              : 
     606              :                     ::= Sb
     607              :          # ::std::basic_string
     608              : 
     609              :                     ::= Ss
     610              :          # ::std::basic_string<char,
     611              :                                ::std::char_traits<char>,
     612              :                                ::std::allocator<char> >
     613              : 
     614              :                     ::= Si
     615              :          # ::std::basic_istream<char, ::std::char_traits<char> >
     616              : 
     617              :                     ::= So
     618              :          # ::std::basic_ostream<char, ::std::char_traits<char> >
     619              : 
     620              :                     ::= Sd
     621              :          # ::std::basic_iostream<char, ::std::char_traits<char> >
     622              : 
     623              :    Then examine the stack of currently available substitution
     624              :    candidates for entities appearing earlier in the same mangling
     625              : 
     626              :    If a substitution is found, write its mangled representation and
     627              :    return nonzero.  If none is found, just return zero.  */
     628              : 
     629              : static int
     630   2463622257 : find_substitution (tree node)
     631              : {
     632   2463622257 :   int i;
     633   2463622257 :   const int size = vec_safe_length (G.substitutions);
     634   2463622257 :   tree decl;
     635   2463622257 :   tree type;
     636   2463622257 :   const char *abbr = NULL;
     637              : 
     638   2463622257 :   if (DEBUG_MANGLE)
     639              :     fprintf (stderr, "  ++ find_substitution (%s at %p)\n",
     640              :              get_tree_code_name (TREE_CODE (node)), (void *) node);
     641              : 
     642              :   /* Obtain the canonicalized substitution representation for NODE.
     643              :      This is what we'll compare against.  */
     644   2463622257 :   node = canonicalize_for_substitution (node);
     645              : 
     646              :   /* Check for builtin substitutions.  */
     647              : 
     648   2463622257 :   decl = TYPE_P (node) ? TYPE_NAME (node) : node;
     649   2463622257 :   type = TYPE_P (node) ? node : TREE_TYPE (node);
     650              : 
     651              :   /* Check for std::allocator.  */
     652   2463622257 :   if (decl
     653   2285802548 :       && is_std_substitution (decl, SUBID_ALLOCATOR)
     654   2598543928 :       && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
     655              :     abbr = "Sa";
     656              : 
     657              :   /* Check for std::basic_string.  */
     658   2402093358 :   else if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
     659              :     {
     660       146055 :       if (TYPE_P (node))
     661              :         {
     662              :           /* If this is a type (i.e. a fully-qualified template-id),
     663              :              check for
     664              :                  std::basic_string <char,
     665              :                                     std::char_traits<char>,
     666              :                                     std::allocator<char> > .  */
     667       102515 :           if (cp_type_quals (type) == TYPE_UNQUALIFIED
     668       102515 :               && CLASSTYPE_USE_TEMPLATE (type))
     669              :             {
     670        91458 :               tree args = CLASSTYPE_TI_ARGS (type);
     671        91458 :               if (TREE_VEC_LENGTH (args) == 3
     672        91440 :                   && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
     673        38041 :                   && is_std_substitution_char (TREE_VEC_ELT (args, 1),
     674              :                                                SUBID_CHAR_TRAITS)
     675       129488 :                   && is_std_substitution_char (TREE_VEC_ELT (args, 2),
     676              :                                                SUBID_ALLOCATOR))
     677              :                 abbr = "Ss";
     678              :             }
     679              :         }
     680              :       else
     681              :         /* Substitute for the template name only if this isn't a type.  */
     682              :         abbr = "Sb";
     683              :     }
     684              : 
     685              :   /* Check for basic_{i,o,io}stream.  */
     686   2401947303 :   else if (TYPE_P (node)
     687   1584237785 :            && cp_type_quals (type) == TYPE_UNQUALIFIED
     688   1490101277 :            && CLASS_TYPE_P (type)
     689    622541742 :            && CLASSTYPE_USE_TEMPLATE (type)
     690   2866043142 :            && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
     691              :     {
     692              :       /* First, check for the template
     693              :          args <char, std::char_traits<char> > .  */
     694    464095839 :       tree args = CLASSTYPE_TI_ARGS (type);
     695    464095839 :       if (TREE_VEC_LENGTH (args) == 2
     696    156758242 :           && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
     697    473759254 :           && is_std_substitution_char (TREE_VEC_ELT (args, 1),
     698              :                                        SUBID_CHAR_TRAITS))
     699              :         {
     700              :           /* Got them.  Is this basic_istream?  */
     701      5605069 :           if (is_std_substitution (decl, SUBID_BASIC_ISTREAM))
     702              :             abbr = "Si";
     703              :           /* Or basic_ostream?  */
     704      5308054 :           else if (is_std_substitution (decl, SUBID_BASIC_OSTREAM))
     705              :             abbr = "So";
     706              :           /* Or basic_iostream?  */
     707      4930836 :           else if (is_std_substitution (decl, SUBID_BASIC_IOSTREAM))
     708   2226588377 :             abbr = "Sd";
     709              :         }
     710              :     }
     711              : 
     712              :   /* Check for namespace std.  */
     713   1937851464 :   else if (decl && DECL_NAMESPACE_STD_P (decl))
     714              :     {
     715    237033880 :       write_string ("St");
     716    237033880 :       return 1;
     717              :     }
     718              : 
     719   2226588377 :   tree tags = NULL_TREE;
     720   2226588377 :   if (OVERLOAD_TYPE_P (node) || DECL_CLASS_TEMPLATE_P (node))
     721   1079231861 :     tags = get_abi_tags (type);
     722              :   /* Now check the list of available substitutions for this mangling
     723              :      operation.  */
     724   2226588377 :   if (!abbr || tags)
     725   9930201311 :     for (i = 0; i < size; ++i)
     726   7960297047 :       if (tree candidate = (*G.substitutions)[i])
     727              :         {
     728              :           /* NODE is a matched to a candidate if it's the same decl node or
     729              :              if it's the same type.  */
     730   7960287695 :           if (decl == candidate
     731   7892958315 :               || (TYPE_P (candidate) && type && TYPE_P (node)
     732   3374740381 :                   && same_type_p (type, candidate))
     733  15727273017 :               || NESTED_TEMPLATE_MATCH (node, candidate))
     734              :             {
     735    194171548 :               write_substitution (i);
     736    194171548 :               return 1;
     737              :             }
     738              :         }
     739              : 
     740   1969904264 :   if (!abbr)
     741              :     /* No substitution found.  */
     742              :     return 0;
     743              : 
     744     62512571 :   write_string (abbr);
     745     62512571 :   if (tags)
     746              :     {
     747              :       /* If there are ABI tags on the abbreviation, it becomes
     748              :          a substitution candidate.  */
     749            6 :       write_abi_tags (tags);
     750            6 :       add_substitution (node);
     751              :     }
     752              :   return 1;
     753              : }
     754              : 
     755              : /* Returns whether DECL's symbol name should be the plain unqualified-id
     756              :    rather than a more complicated mangled name.  */
     757              : 
     758              : static bool
     759    227569986 : unmangled_name_p (const tree decl)
     760              : {
     761    227569986 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     762              :     {
     763              :       /* The names of `extern "C"' functions are not mangled.  */
     764    190823349 :       return (DECL_EXTERN_C_FUNCTION_P (decl)
     765              :               /* But overloaded operator names *are* mangled.  */
     766      2191416 :               && !DECL_OVERLOADED_OPERATOR_P (decl));
     767              :     }
     768     36746637 :   else if (VAR_P (decl))
     769              :     {
     770              :       /* static variables are mangled.  */
     771     36743439 :       if (!DECL_EXTERNAL_LINKAGE_P (decl))
     772              :         return false;
     773              : 
     774              :       /* extern "C" declarations aren't mangled.  */
     775     36501363 :       if (DECL_EXTERN_C_P (decl))
     776              :         return true;
     777              : 
     778              :       /* Other variables at non-global scope are mangled.  */
     779     36297667 :       if (CP_DECL_CONTEXT (decl) != global_namespace)
     780              :         return false;
     781              : 
     782              :       /* Variable template instantiations are mangled.  */
     783       111140 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
     784       109518 :           && variable_template_p (DECL_TI_TEMPLATE (decl)))
     785              :         return false;
     786              : 
     787              :       /* Declarations with ABI tags are mangled.  */
     788       103818 :       if (get_abi_tags (decl))
     789              :         return false;
     790              : 
     791              :       // Declarations attached to a named module are mangled
     792       103479 :       if (modules_p () && get_originating_module (decl, true) >= 0)
     793              :         return false;
     794              : 
     795              :       /* The names of non-static global variables aren't mangled.  */
     796              :       return true;
     797              :     }
     798              : 
     799              :   return false;
     800              : }
     801              : 
     802              : /* TOP_LEVEL is true, if this is being called at outermost level of
     803              :   mangling. It should be false when mangling a decl appearing in an
     804              :   expression within some other mangling.
     805              : 
     806              :   <mangled-name>      ::= _Z <encoding>  */
     807              : 
     808              : static void
     809    227569986 : write_mangled_name (const tree decl, bool top_level)
     810              : {
     811    227569986 :   MANGLE_TRACE_TREE ("mangled-name", decl);
     812              : 
     813    227569986 :   check_abi_tags (decl);
     814              : 
     815    227569986 :   if (unmangled_name_p (decl))
     816              :     {
     817      2498181 :       if (top_level)
     818      2497979 :         write_string (IDENTIFIER_POINTER (DECL_NAME (decl)));
     819              :       else
     820              :         {
     821              :           /* The standard notes: "The <encoding> of an extern "C"
     822              :              function is treated like global-scope data, i.e. as its
     823              :              <source-name> without a type."  We cannot write
     824              :              overloaded operators that way though, because it contains
     825              :              characters invalid in assembler.  */
     826          202 :           write_string ("_Z");
     827          202 :           write_source_name (DECL_NAME (decl));
     828              :         }
     829              :     }
     830              :   else
     831              :     {
     832    225071805 :       write_string ("_Z");
     833    225071805 :       write_encoding (decl);
     834              :     }
     835              : 
     836              :   /* If this is a coroutine helper, then append an appropriate string to
     837              :      identify which.  */
     838    227569986 :   if (tree ramp = DECL_RAMP_FN (decl))
     839              :     {
     840         2978 :       if (DECL_ACTOR_FN (ramp) == decl)
     841         1489 :         write_string (JOIN_STR "actor");
     842         1489 :       else if (DECL_DESTROY_FN (ramp) == decl)
     843         1489 :         write_string (JOIN_STR "destroy");
     844              :       else
     845            0 :         gcc_unreachable ();
     846              :     }
     847    227569986 : }
     848              : 
     849              : /* Returns true if the return type of DECL is part of its signature, and
     850              :    therefore its mangling.  */
     851              : 
     852              : bool
     853    383692121 : mangle_return_type_p (tree decl)
     854              : {
     855    383692121 :   return (!DECL_CONSTRUCTOR_P (decl)
     856    319320547 :           && !DECL_DESTRUCTOR_P (decl)
     857    304451914 :           && !DECL_CONV_FN_P (decl)
     858    685250961 :           && maybe_template_info (decl));
     859              : }
     860              : 
     861              : /* <constraint-expression> ::= <expression> */
     862              : 
     863              : static void
     864      5313338 : write_constraint_expression (tree expr)
     865              : {
     866            0 :   write_expression (expr);
     867       288975 : }
     868              : 
     869              : /* Mangle a requires-clause following a template-head, if any.
     870              : 
     871              :    Q <constraint_expression> E  */
     872              : 
     873              : static void
     874    446170613 : write_tparms_constraints (tree constraints)
     875              : {
     876              :   /* In a declaration with shorthand constraints in the template-head, followed
     877              :      by a requires-clause, followed by shorthand constraints in the
     878              :      function-parameter-list, the full constraints will be some && with the
     879              :      parameter constraints on the RHS, around an && with the requires-clause on
     880              :      the RHS.  Find the requires-clause, if any.
     881              : 
     882              :      This logic relies on the && and ... from combine_constraint_expressions,
     883              :      finish_shorthand_constraint, and convert_generic_types_to_packs having
     884              :      UNKNOWN_LOCATION.  If they need to have an actual location, we could move
     885              :      to using a TREE_LANG_FLAG.  */
     886    446170613 :   if (constraints && abi_check (19))
     887              :     {
     888              :       tree probe = constraints;
     889              :       while (probe
     890       319401 :              && !EXPR_LOCATION (probe)
     891       349830 :              && TREE_CODE (probe) == TRUTH_ANDIF_EXPR)
     892              :         {
     893          154 :           tree op1 = TREE_OPERAND (probe, 1);
     894          285 :           probe = (EXPR_LOCATION (op1) ? op1
     895          131 :                    : TREE_OPERAND (probe, 0));
     896              :         }
     897       319247 :       if (probe && EXPR_LOCATION (probe))
     898              :         {
     899       288972 :           write_char ('Q');
     900       288972 :           write_constraint_expression (probe);
     901              :         }
     902              :     }
     903    446170613 : }
     904              : 
     905              : /* <type-constraint> ::= <name> */
     906              : 
     907              : static void
     908       208322 : write_type_constraint (tree cnst)
     909              : {
     910       208322 :   if (!cnst)
     911              :     return;
     912              : 
     913       208322 :   gcc_checking_assert (TREE_CODE (cnst) == TEMPLATE_ID_EXPR);
     914              : 
     915       208322 :   tree concept_decl = get_concept_check_template (cnst);
     916       208322 :   write_name (concept_decl, 0);
     917       208322 :   tree args = TREE_OPERAND (cnst, 1);
     918       208322 :   if (TREE_VEC_LENGTH (args) > 1)
     919              :     {
     920        95924 :       TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args) = true;
     921        95924 :       write_template_args (args);
     922              :     }
     923              : }
     924              : 
     925              : /*   <encoding>           ::= <function name> <bare-function-type>
     926              :                         ::= <data name>  */
     927              : 
     928              : static void
     929    232124001 : write_encoding (const tree decl)
     930              : {
     931    232124001 :   MANGLE_TRACE_TREE ("encoding", decl);
     932              : 
     933    232124001 :   if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
     934              :     {
     935              :       /* For overloaded operators write just the mangled name
     936              :          without arguments.  */
     937        10675 :       if (DECL_OVERLOADED_OPERATOR_P (decl))
     938            3 :         write_name (decl, /*ignore_local_scope=*/0);
     939              :       else
     940        10672 :         write_source_name (DECL_NAME (decl));
     941        10675 :       return;
     942              :     }
     943              : 
     944    232113326 :   write_name (decl, /*ignore_local_scope=*/0);
     945    232113326 :   if (TREE_CODE (decl) == FUNCTION_DECL)
     946              :     {
     947    195673258 :       tree fn_type;
     948    195673258 :       tree d;
     949              : 
     950    195673258 :       if (maybe_template_info (decl))
     951              :         {
     952     20802937 :           fn_type = get_mostly_instantiated_function_type (decl);
     953              :           /* FN_TYPE will not have parameter types for in-charge or
     954              :              VTT parameters.  Therefore, we pass NULL_TREE to
     955              :              write_bare_function_type -- otherwise, it will get
     956              :              confused about which artificial parameters to skip.  */
     957     20802937 :           d = NULL_TREE;
     958              :         }
     959              :       else
     960              :         {
     961    174870321 :           fn_type = TREE_TYPE (decl);
     962    174870321 :           d = decl;
     963              :         }
     964              : 
     965    195673258 :       write_bare_function_type (fn_type,
     966    195673258 :                                 mangle_return_type_p (decl),
     967              :                                 d);
     968              : 
     969    195673258 :       if (tree c = get_trailing_function_requirements (decl))
     970      5037608 :         if (abi_check (19))
     971              :           {
     972      5024363 :             ++G.parm_depth;
     973      5024363 :             write_char ('Q');
     974      5024363 :             write_constraint_expression (c);
     975      5024363 :             --G.parm_depth;
     976              :           }
     977              :     }
     978              : }
     979              : 
     980              : /* Interface to substitution and identifier mangling, used by the
     981              :    module name mangler.  */
     982              : 
     983              : void
     984          350 : mangle_module_substitution (int v)
     985              : {
     986          350 :   write_substitution (v - 1);
     987          350 : }
     988              : 
     989              : int
     990         7987 : mangle_module_component (tree comp, bool partition_p)
     991              : {
     992         7987 :   write_char ('W');
     993         7987 :   if (partition_p)
     994          190 :     write_char ('P');
     995         7987 :   write_source_name (comp);
     996              : 
     997              :   // Module substitutions use the same number-space as entity
     998              :   // substitutions, but are orthogonal.
     999         7987 :   vec_safe_push (G.substitutions, NULL_TREE);
    1000         7987 :   return G.substitutions->length ();
    1001              : }
    1002              : 
    1003              : /* If the outermost non-namespace context (including DECL itself) is
    1004              :    a module-linkage decl, mangle the module information.  For module
    1005              :    global initializers we need to include the partition part.
    1006              : 
    1007              :    <module-name> ::= <module-sub>
    1008              :                  || <subst>
    1009              :                  || <module-name> <module-sub>
    1010              :    <module-sub> :: W [P] <unqualified-name>
    1011              : */
    1012              : 
    1013              : static void
    1014         7693 : write_module (int m, bool include_partition)
    1015              : {
    1016         7693 :   G.mod = true;
    1017            0 :   mangle_module (m, include_partition);
    1018         5781 : }
    1019              : 
    1020              : static void
    1021      1229471 : maybe_write_module (tree decl)
    1022              : {
    1023      1229471 :   if (!DECL_NAMESPACE_SCOPE_P (decl))
    1024              :     return;
    1025              : 
    1026       875006 :   if (!TREE_PUBLIC (STRIP_TEMPLATE (decl)))
    1027              :     return;
    1028              : 
    1029       867968 :   if (TREE_CODE (decl) == NAMESPACE_DECL)
    1030              :     return;
    1031              : 
    1032       656597 :   int m = get_originating_module (decl, true);
    1033       656597 :   if (m >= 0)
    1034         5781 :     write_module (m, false);
    1035              : }
    1036              : 
    1037              : /* Lambdas can have a bit more context for mangling, specifically VAR_DECL
    1038              :    or PARM_DECL context, which doesn't belong in DECL_CONTEXT.  */
    1039              : 
    1040              : static tree
    1041   2184438419 : decl_mangling_context (tree decl)
    1042              : {
    1043   2184438525 :   tree tcontext = targetm.cxx.decl_mangling_context (decl);
    1044              : 
    1045   2184438525 :   if (tcontext != NULL_TREE)
    1046              :     return tcontext;
    1047              : 
    1048   2184438525 :   if (TREE_CODE (decl) == TEMPLATE_DECL
    1049   2184438525 :       && DECL_TEMPLATE_RESULT (decl))
    1050              :     decl = DECL_TEMPLATE_RESULT (decl);
    1051              : 
    1052   2184438525 :   if (TREE_CODE (decl) == TYPE_DECL
    1053   3206692696 :       && LAMBDA_TYPE_P (TREE_TYPE (decl)))
    1054              :     {
    1055      8769391 :       tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl));
    1056      8769391 :       if (extra)
    1057              :         return extra;
    1058         2130 :       tcontext = CP_DECL_CONTEXT (decl);
    1059         2258 :       if (LAMBDA_TYPE_P (tcontext))
    1060              :         /* Lambda type context means this lambda appears between the
    1061              :            lambda-introducer and the open brace of another lambda (c++/119175).
    1062              :            That isn't a real scope; look further into the enclosing scope.  */
    1063           18 :         return decl_mangling_context (TYPE_NAME (tcontext));
    1064              :     }
    1065   2175669134 :   else if (template_type_parameter_p (decl))
    1066              :      /* template type parms have no mangling context.  */
    1067              :       return NULL_TREE;
    1068              : 
    1069   2175670260 :   tcontext = CP_DECL_CONTEXT (decl);
    1070              : 
    1071   2175670260 :   if (member_like_constrained_friend_p (decl))
    1072       264548 :     tcontext = DECL_FRIEND_CONTEXT (decl);
    1073              : 
    1074              :   /* Ignore the artificial declare reduction functions.  */
    1075   2175670260 :   if (tcontext
    1076   2175670260 :       && TREE_CODE (tcontext) == FUNCTION_DECL
    1077   2181854326 :       && DECL_OMP_DECLARE_REDUCTION_P (tcontext))
    1078              :     return decl_mangling_context (tcontext);
    1079              : 
    1080              :   return tcontext;
    1081              : }
    1082              : 
    1083              : /* <name> ::= <unscoped-name>
    1084              :           ::= <unscoped-template-name> <template-args>
    1085              :           ::= <nested-name>
    1086              :           ::= <local-name>
    1087              : 
    1088              :    If IGNORE_LOCAL_SCOPE is nonzero, this production of <name> is
    1089              :    called from <local-name>, which mangles the enclosing scope
    1090              :    elsewhere and then uses this function to mangle just the part
    1091              :    underneath the function scope.  So don't use the <local-name>
    1092              :    production, to avoid an infinite recursion.  */
    1093              : 
    1094              : static void
    1095    577283584 : write_name (tree decl, const int ignore_local_scope)
    1096              : {
    1097    577283584 :   tree context;
    1098              : 
    1099    577283584 :   MANGLE_TRACE_TREE ("name", decl);
    1100              : 
    1101    577283584 :   if (TREE_CODE (decl) == TYPE_DECL)
    1102              :     {
    1103              :       /* In case this is a typedef, fish out the corresponding
    1104              :          TYPE_DECL for the main variant.  */
    1105    339245813 :       decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
    1106              :     }
    1107              : 
    1108    577283584 :   context = decl_mangling_context (decl);
    1109              : 
    1110    577283584 :   gcc_assert (context != NULL_TREE);
    1111              : 
    1112   2885937015 :   if (abi_warn_or_compat_version_crosses (7)
    1113       160047 :       && ignore_local_scope
    1114           44 :       && TREE_CODE (context) == PARM_DECL)
    1115            0 :     G.need_abi_warning = 1;
    1116              : 
    1117              :   /* A decl in :: or ::std scope is treated specially.  The former is
    1118              :      mangled using <unscoped-name> or <unscoped-template-name>, the
    1119              :      latter with a special substitution.  Also, a name that is
    1120              :      directly in a local function scope is also mangled with
    1121              :      <unscoped-name> rather than a full <nested-name>.  */
    1122    577283584 :   if (context == global_namespace
    1123    565879648 :       || DECL_NAMESPACE_STD_P (context)
    1124    341195704 :       || (ignore_local_scope
    1125      6583786 :           && (TREE_CODE (context) == FUNCTION_DECL
    1126      4834870 :               || (abi_version_at_least (7)
    1127      4834870 :                   && TREE_CODE (context) == PARM_DECL))))
    1128              :     {
    1129              :       /* Is this a template instance?  */
    1130    237836826 :       if (tree info = maybe_template_info (decl))
    1131              :         {
    1132              :           /* Yes: use <unscoped-template-name>.  */
    1133    199771117 :           write_unscoped_template_name (TI_TEMPLATE (info));
    1134              :           /* Pass down the parms of a function template in case we need to
    1135              :              mangle them; we don't mangle the parms of a non-overloadable
    1136              :              template.  */
    1137    199771117 :           tree parms = (TREE_CODE (decl) == FUNCTION_DECL
    1138    204848346 :                         ? DECL_TEMPLATE_PARMS (TI_TEMPLATE (info))
    1139      5077229 :                         : NULL_TREE);
    1140    199771117 :           write_template_args (TI_ARGS (info), parms);
    1141              :         }
    1142              :       else
    1143              :         /* Everything else gets an <unqualified-name>.  */
    1144     38065709 :         write_unscoped_name (decl);
    1145              :     }
    1146              :   else
    1147              :     {
    1148              :       /* Handle local names, unless we asked not to (that is, invoked
    1149              :          under <local-name>, to handle only the part of the name under
    1150              :          the local scope).  */
    1151    339446758 :       if (!ignore_local_scope)
    1152              :         {
    1153              :           /* Scan up the list of scope context, looking for a
    1154              :              function.  If we find one, this entity is in local
    1155              :              function scope.  local_entity tracks context one scope
    1156              :              level down, so it will contain the element that's
    1157              :              directly in that function's scope, either decl or one of
    1158              :              its enclosing scopes.  */
    1159              :           tree local_entity = decl;
    1160   1066951772 :           while (context != global_namespace)
    1161              :             {
    1162              :               /* Make sure we're always dealing with decls.  */
    1163    738923640 :               if (TYPE_P (context))
    1164    227834648 :                 context = TYPE_NAME (context);
    1165              :               /* Is this a function?  */
    1166    738923640 :               if (TREE_CODE (context) == FUNCTION_DECL
    1167    732340211 :                   || TREE_CODE (context) == PARM_DECL)
    1168              :                 {
    1169              :                   /* Yes, we have local scope.  Use the <local-name>
    1170              :                      production for the innermost function scope.  */
    1171      6583786 :                   write_local_name (context, local_entity, decl);
    1172      6583786 :                   return;
    1173              :                 }
    1174              :               /* Up one scope level.  */
    1175    732339854 :               local_entity = context;
    1176    732339854 :               context = decl_mangling_context (context);
    1177              :             }
    1178              : 
    1179              :           /* No local scope found?  Fall through to <nested-name>.  */
    1180              :         }
    1181              : 
    1182              :       /* Other decls get a <nested-name> to encode their scope.  */
    1183    332862972 :       write_nested_name (decl);
    1184              :     }
    1185              : }
    1186              : 
    1187              : /* <unscoped-name> ::= <unqualified-name>
    1188              :                    ::= St <unqualified-name>   # ::std::  */
    1189              : 
    1190              : static void
    1191    173643092 : write_unscoped_name (const tree decl)
    1192              : {
    1193    173643092 :   tree context = decl_mangling_context (decl);
    1194              : 
    1195    173643092 :   MANGLE_TRACE_TREE ("unscoped-name", decl);
    1196              : 
    1197              :   /* Is DECL in ::std?  */
    1198    173643092 :   if (DECL_NAMESPACE_STD_P (context))
    1199              :     {
    1200    163439190 :       write_string ("St");
    1201    163439190 :       write_unqualified_name (decl);
    1202              :     }
    1203              :   else
    1204              :     {
    1205              :       /* If not, it should be either in the global namespace, or directly
    1206              :          in a local function scope.  A lambda can also be mangled in the
    1207              :          scope of a default argument.  */
    1208     10203902 :       gcc_assert (context == global_namespace
    1209              :                   || TREE_CODE (context) == PARM_DECL
    1210              :                   || TREE_CODE (context) == FUNCTION_DECL);
    1211              : 
    1212     10203902 :       write_unqualified_name (decl);
    1213              :     }
    1214    173643092 : }
    1215              : 
    1216              : /* <unscoped-template-name> ::= <unscoped-name>
    1217              :                             ::= <substitution>  */
    1218              : 
    1219              : static void
    1220    199771117 : write_unscoped_template_name (const tree decl)
    1221              : {
    1222    199771117 :   MANGLE_TRACE_TREE ("unscoped-template-name", decl);
    1223              : 
    1224    199771117 :   if (find_substitution (decl))
    1225              :     return;
    1226    135577383 :   write_unscoped_name (decl);
    1227    135577383 :   add_substitution (decl);
    1228              : }
    1229              : 
    1230              : /* Write the nested name, including CV-qualifiers, of DECL.
    1231              : 
    1232              :    <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
    1233              :                  ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
    1234              : 
    1235              :    <ref-qualifier> ::= R # & ref-qualifier
    1236              :                    ::= O # && ref-qualifier
    1237              :    <CV-qualifiers> ::= [r] [V] [K]  */
    1238              : 
    1239              : static void
    1240    337074427 : write_nested_name (const tree decl)
    1241              : {
    1242    337074427 :   MANGLE_TRACE_TREE ("nested-name", decl);
    1243              : 
    1244    337074427 :   write_char ('N');
    1245              : 
    1246              :   /* Write CV-qualifiers, if this is an iobj member function.  */
    1247    337074427 :   if (TREE_CODE (decl) == FUNCTION_DECL
    1248    337074427 :       && DECL_IOBJ_MEMBER_FUNCTION_P (decl))
    1249              :     {
    1250    156429391 :       if (DECL_VOLATILE_MEMFUNC_P (decl))
    1251      8463757 :         write_char ('V');
    1252    156429391 :       if (DECL_CONST_MEMFUNC_P (decl))
    1253     49272987 :         write_char ('K');
    1254    156429391 :       if (FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)))
    1255              :         {
    1256       205213 :           if (FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl)))
    1257       135940 :             write_char ('O');
    1258              :           else
    1259        69273 :             write_char ('R');
    1260              :         }
    1261              :     }
    1262    152859322 :   else if (DECL_DECLARES_FUNCTION_P (decl)
    1263    180645036 :            && DECL_XOBJ_MEMBER_FUNCTION_P (decl))
    1264         3613 :     write_char ('H');
    1265              : 
    1266              :   /* Is this a template instance?  */
    1267    337074427 :   if (tree info = maybe_template_info (decl))
    1268              :     {
    1269              :       /* Yes, use <template-prefix>.  */
    1270     66767814 :       write_template_prefix (decl);
    1271     66767814 :       write_template_args (TI_ARGS (info));
    1272              :     }
    1273    270306613 :   else if ((!abi_version_at_least (10) || TREE_CODE (decl) == TYPE_DECL)
    1274    353737172 :            && TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
    1275              :     {
    1276      4211452 :       tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
    1277      4211452 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    1278              :         {
    1279        96210 :           write_template_prefix (decl);
    1280        96210 :           write_template_args (TREE_OPERAND (name, 1));
    1281              :         }
    1282              :       else
    1283              :         {
    1284      4115242 :           write_prefix (decl_mangling_context (decl));
    1285      4115242 :           write_unqualified_name (decl);
    1286              :         }
    1287              :     }
    1288              :   else
    1289              :     {
    1290              :       /* No, just use <prefix>  */
    1291    266095161 :       write_prefix (decl_mangling_context (decl));
    1292    266095161 :       write_unqualified_name (decl);
    1293              :     }
    1294    337074427 :   write_char ('E');
    1295    337074427 : }
    1296              : 
    1297              : /* <prefix> ::= <prefix> <unqualified-name>
    1298              :             ::= <template-param>
    1299              :             ::= <template-prefix> <template-args>
    1300              :             ::= <decltype>
    1301              :             ::= # empty
    1302              :             ::= <substitution>  */
    1303              : 
    1304              : static void
    1305    695596207 : write_prefix (const tree node)
    1306              : {
    1307    695596207 :   tree decl;
    1308              : 
    1309    695596207 :   if (node == NULL
    1310    695596207 :       || node == global_namespace)
    1311              :     return;
    1312              : 
    1313    670294782 :   MANGLE_TRACE_TREE ("prefix", node);
    1314              : 
    1315    670294782 :   if (TREE_CODE (node) == DECLTYPE_TYPE
    1316    670294618 :       || TREE_CODE (node) == TRAIT_TYPE)
    1317              :     {
    1318          167 :       write_type (node);
    1319          167 :       return;
    1320              :     }
    1321              : 
    1322    670294615 :   if (find_substitution (node))
    1323              :     return;
    1324              : 
    1325    368940486 :   tree template_info = NULL_TREE;
    1326    368940486 :   if (DECL_P (node))
    1327              :     {
    1328              :       /* If this is a function or parm decl, that means we've hit function
    1329              :          scope, so this prefix must be for a local name.  In this
    1330              :          case, we're under the <local-name> production, which encodes
    1331              :          the enclosing function scope elsewhere.  So don't continue
    1332              :          here.  */
    1333    144738200 :       if (TREE_CODE (node) == FUNCTION_DECL
    1334    139904303 :           || TREE_CODE (node) == PARM_DECL)
    1335              :         return;
    1336              : 
    1337    139903976 :       decl = node;
    1338    139903976 :       template_info = maybe_template_info (decl);
    1339              :     }
    1340              :   else
    1341              :     {
    1342              :       /* Node is a type.  */
    1343    224202286 :       decl = TYPE_NAME (node);
    1344              :       /* The DECL might not point at the node.  */
    1345    224202286 :       if (CLASSTYPE_TEMPLATE_ID_P (node))
    1346    170949575 :         template_info = TYPE_TEMPLATE_INFO (node);
    1347              :     }
    1348              : 
    1349    364106262 :   if (TREE_CODE (node) == TEMPLATE_TYPE_PARM)
    1350         9774 :     write_template_param (node);
    1351    364096488 :   else if (template_info)
    1352              :     /* Templated.  */
    1353              :     {
    1354    170951620 :       write_template_prefix (decl);
    1355    170951620 :       write_template_args (TI_ARGS (template_info));
    1356              :     }
    1357    193144868 :   else if (TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
    1358              :     {
    1359       119501 :       tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
    1360       119501 :       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    1361              :         {
    1362       111830 :           write_template_prefix (decl);
    1363       111830 :           write_template_args (TREE_OPERAND (name, 1));
    1364              :         }
    1365              :       else
    1366              :         {
    1367         7671 :           write_prefix (decl_mangling_context (decl));
    1368         7671 :           write_unqualified_name (decl);
    1369              :         }
    1370              :     }
    1371              :   else
    1372              :     /* Not templated.  */
    1373              :     {
    1374    193025367 :       write_prefix (decl_mangling_context (decl));
    1375    193025367 :       write_unqualified_name (decl);
    1376    193025367 :       if (VAR_P (decl)
    1377    193025367 :           || TREE_CODE (decl) == FIELD_DECL)
    1378              :         {
    1379              :           /* <data-member-prefix> := <member source-name> M */
    1380        15241 :           write_char ('M');
    1381              : 
    1382              :           /* Before ABI 18, we did not count these as substitution
    1383              :              candidates.  This leads to incorrect demanglings (and
    1384              :              ABI divergence to other compilers).  */
    1385        15241 :           if (!abi_check (18))
    1386              :             return;
    1387              :         }
    1388              :     }
    1389              : 
    1390    364106130 :   add_substitution (node);
    1391              : }
    1392              : 
    1393              : /* <template-prefix> ::= <prefix> <template component>
    1394              :                      ::= <template-param>
    1395              :                      ::= <substitution>  */
    1396              : 
    1397              : static void
    1398    237927474 : write_template_prefix (const tree node)
    1399              : {
    1400    237927474 :   tree decl = DECL_P (node) ? node : TYPE_NAME (node);
    1401    237927474 :   tree type = DECL_P (node) ? TREE_TYPE (node) : node;
    1402    237927474 :   tree context = decl_mangling_context (decl);
    1403    237927474 :   tree templ;
    1404    237927474 :   tree substitution;
    1405              : 
    1406    237927474 :   MANGLE_TRACE_TREE ("template-prefix", node);
    1407              : 
    1408              :   /* Find the template decl.  */
    1409    237927474 :   if (tree info = maybe_template_info (decl))
    1410    237718448 :     templ = TI_TEMPLATE (info);
    1411       209026 :   else if (TREE_CODE (type) == TYPENAME_TYPE)
    1412              :     /* For a typename type, all we have is the name.  */
    1413       208040 :     templ = DECL_NAME (decl);
    1414              :   else
    1415              :     {
    1416          986 :       gcc_assert (CLASSTYPE_TEMPLATE_ID_P (type));
    1417              : 
    1418          986 :       templ = TYPE_TI_TEMPLATE (type);
    1419              :     }
    1420              : 
    1421              :   /* For a member template, though, the template name for the
    1422              :      innermost name must have all the outer template levels
    1423              :      instantiated.  For instance, consider
    1424              : 
    1425              :        template<typename T> struct Outer {
    1426              :          template<typename U> struct Inner {};
    1427              :        };
    1428              : 
    1429              :      The template name for `Inner' in `Outer<int>::Inner<float>' is
    1430              :      `Outer<int>::Inner<U>'.  In g++, we don't instantiate the template
    1431              :      levels separately, so there's no TEMPLATE_DECL available for this
    1432              :      (there's only `Outer<T>::Inner<U>').
    1433              : 
    1434              :      In order to get the substitutions right, we create a special
    1435              :      TREE_LIST to represent the substitution candidate for a nested
    1436              :      template.  The TREE_PURPOSE is the template's context, fully
    1437              :      instantiated, and the TREE_VALUE is the TEMPLATE_DECL for the inner
    1438              :      template.
    1439              : 
    1440              :      So, for the example above, `Outer<int>::Inner' is represented as a
    1441              :      substitution candidate by a TREE_LIST whose purpose is `Outer<int>'
    1442              :      and whose value is `Outer<T>::Inner<U>'.  */
    1443    237927474 :   if (context && TYPE_P (context))
    1444     14355502 :     substitution = build_tree_list (context, templ);
    1445              :   else
    1446              :     substitution = templ;
    1447              : 
    1448    237927474 :   if (find_substitution (substitution))
    1449              :     return;
    1450              : 
    1451    232353443 :   if (TREE_TYPE (templ)
    1452    232353443 :       && TREE_CODE (TREE_TYPE (templ)) == TEMPLATE_TEMPLATE_PARM)
    1453          986 :     write_template_param (TREE_TYPE (templ));
    1454              :   else
    1455              :     {
    1456    232352457 :       write_prefix (context);
    1457    232352457 :       write_unqualified_name (decl);
    1458              :     }
    1459              : 
    1460    232353443 :   add_substitution (substitution);
    1461              : }
    1462              : 
    1463              : /* "For the purposes of mangling, the name of an anonymous union is considered
    1464              :    to be the name of the first named data member found by a pre-order,
    1465              :    depth-first, declaration-order walk of the data members of the anonymous
    1466              :    union. If there is no such data member (i.e., if all of the data members in
    1467              :    the union are unnamed), then there is no way for a program to refer to the
    1468              :    anonymous union, and there is therefore no need to mangle its name."  */
    1469              : 
    1470              : static tree
    1471           21 : anon_aggr_naming_decl (tree type)
    1472              : {
    1473           21 :   tree field = next_aggregate_field (TYPE_FIELDS (type));
    1474           21 :   for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
    1475              :     {
    1476           21 :       if (DECL_NAME (field))
    1477              :         return field;
    1478            0 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    1479            0 :         if (tree sub = anon_aggr_naming_decl (TREE_TYPE (field)))
    1480              :           return sub;
    1481              :     }
    1482              :   return NULL_TREE;
    1483              : }
    1484              : 
    1485              : /* We don't need to handle thunks, vtables, or VTTs here.  Those are
    1486              :    mangled through special entry points.
    1487              : 
    1488              :     <unqualified-name>  ::= [<module-name>] <operator-name>
    1489              :                         ::= <special-name>
    1490              :                         ::= [<module-name>] <source-name>
    1491              :                         ::= [<module-name>] <unnamed-type-name>
    1492              :                         ::= <local-source-name>
    1493              :                         ::= F <source-name> # member-like constrained friend
    1494              : 
    1495              :     <local-source-name>   ::= L <source-name> <discriminator> */
    1496              : 
    1497              : static void
    1498      8990682 : write_unqualified_id (tree identifier)
    1499              : {
    1500      8990682 :   if (IDENTIFIER_CONV_OP_P (identifier))
    1501           15 :     write_conversion_operator_name (TREE_TYPE (identifier));
    1502      8990667 :   else if (IDENTIFIER_OVL_OP_P (identifier))
    1503              :     {
    1504        46780 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (identifier);
    1505        46780 :       write_string (ovl_op->mangled_name);
    1506        46780 :     }
    1507      8943887 :   else if (UDLIT_OPER_P (identifier))
    1508            0 :     write_literal_operator_name (identifier);
    1509              :   else
    1510      8943887 :     write_source_name (identifier);
    1511      8990682 : }
    1512              : 
    1513              : static void
    1514    869242296 : write_unqualified_name (tree decl)
    1515              : {
    1516    869242296 :   MANGLE_TRACE_TREE ("unqualified-name", decl);
    1517              : 
    1518    869242296 :   if (modules_p ())
    1519      1229471 :     maybe_write_module (decl);
    1520              : 
    1521    869242296 :   if (identifier_p (decl))
    1522              :     {
    1523            0 :       write_unqualified_id (decl);
    1524            0 :       return;
    1525              :     }
    1526              : 
    1527    869242296 :   bool found = false;
    1528              : 
    1529    869242296 :   if (DECL_NAME (decl) == NULL_TREE
    1530    869242296 :       && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
    1531           21 :     decl = anon_aggr_naming_decl (TREE_TYPE (decl));
    1532    869242275 :   else if (DECL_NAME (decl) == NULL_TREE)
    1533              :     {
    1534        10925 :       found = true;
    1535        10925 :       gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
    1536        10925 :       write_source_name (DECL_ASSEMBLER_NAME (decl));
    1537              :     }
    1538    869231350 :   else if (DECL_DECLARES_FUNCTION_P (decl))
    1539              :     {
    1540    195672699 :       found = true;
    1541              : 
    1542              :       /* A constrained hidden friend is mangled like a member function, with
    1543              :          the name prefixed by 'F'.  */
    1544    195672699 :       if (member_like_constrained_friend_p (decl))
    1545        66137 :         write_char ('F');
    1546              : 
    1547    391345398 :       if (DECL_CONSTRUCTOR_P (decl))
    1548     32210681 :         write_special_name_constructor (decl);
    1549    163462018 :       else if (DECL_DESTRUCTOR_P (decl))
    1550      7666608 :         write_special_name_destructor (decl);
    1551    155795410 :       else if (DECL_CONV_FN_P (decl))
    1552              :         {
    1553              :           /* Conversion operator. Handle it right here.
    1554              :              <operator> ::= cv <type>  */
    1555      2887793 :           tree type;
    1556      2887793 :           if (maybe_template_info (decl))
    1557              :             {
    1558          506 :               tree fn_type;
    1559          506 :               fn_type = get_mostly_instantiated_function_type (decl);
    1560          506 :               type = TREE_TYPE (fn_type);
    1561              :             }
    1562      2887287 :           else if (FNDECL_USED_AUTO (decl))
    1563           60 :             type = DECL_SAVED_AUTO_RETURN_TYPE (decl);
    1564              :           else
    1565      2887227 :             type = DECL_CONV_FN_TYPE (decl);
    1566      2887793 :           write_conversion_operator_name (type);
    1567              :         }
    1568    152907617 :       else if (DECL_OVERLOADED_OPERATOR_P (decl))
    1569              :         {
    1570     34718611 :           tree t;
    1571     34718611 :           if (!(t = DECL_RAMP_FN (decl)))
    1572     34718223 :             t = decl;
    1573     34718611 :           const char *mangled_name
    1574     34718611 :             = (ovl_op_info[DECL_ASSIGNMENT_OPERATOR_P (t)]
    1575     34718611 :                [DECL_OVERLOADED_OPERATOR_CODE_RAW (t)].mangled_name);
    1576     34718611 :           write_string (mangled_name);
    1577              :         }
    1578    118189006 :       else if (UDLIT_OPER_P (DECL_NAME (decl)))
    1579       297482 :         write_literal_operator_name (DECL_NAME (decl));
    1580              :       else
    1581              :         found = false;
    1582              :     }
    1583              : 
    1584     77792121 :   if (found)
    1585              :     /* OK */;
    1586    791450196 :   else if (VAR_OR_FUNCTION_DECL_P (decl) && ! TREE_PUBLIC (decl)
    1587       120746 :            && DECL_NAMESPACE_SCOPE_P (decl)
    1588    791519634 :            && decl_linkage (decl) == lk_internal)
    1589              :     {
    1590        58971 :       MANGLE_TRACE_TREE ("local-source-name", decl);
    1591        58971 :       write_char ('L');
    1592        58971 :       write_source_name (DECL_NAME (decl));
    1593              :       /* The default discriminator is 1, and that's all we ever use,
    1594              :          so there's no code to output one here.  */
    1595              :     }
    1596              :   else
    1597              :     {
    1598    791391225 :       tree type = TREE_TYPE (decl);
    1599              : 
    1600    791391225 :       if (TREE_CODE (decl) == TYPE_DECL
    1601    791391225 :           && enum_with_enumerator_for_linkage_p (type))
    1602           19 :         write_unnamed_enum_name (type);
    1603   1176183307 :       else if (TREE_CODE (decl) == TYPE_DECL && TYPE_UNNAMED_P (type))
    1604         1364 :         write_unnamed_type_name (type);
    1605   1146333668 :       else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (type))
    1606      3640744 :         write_closure_type_name (type);
    1607              :       else
    1608    787749098 :         write_source_name (DECL_NAME (decl));
    1609              :     }
    1610              : 
    1611              :   /* We use the ABI tags from the primary class template, ignoring tags on any
    1612              :      specializations.  This is necessary because C++ doesn't require a
    1613              :      specialization to be declared before it is used unless the use requires a
    1614              :      complete type, but we need to get the tags right on incomplete types as
    1615              :      well.  */
    1616    869242296 :   if (tree tmpl = most_general_template (decl))
    1617              :     {
    1618    516297149 :       tree res = DECL_TEMPLATE_RESULT (tmpl);
    1619    516297149 :       if (res == NULL_TREE)
    1620              :         /* UNBOUND_CLASS_TEMPLATE.  */;
    1621    516297146 :       else if (DECL_DECLARES_TYPE_P (decl))
    1622              :         decl = res;
    1623    176599760 :       else if (any_abi_below (11))
    1624              :         {
    1625              :           /* ABI v10 implicit tags on the template.  */
    1626        81558 :           tree mtags = missing_abi_tags (res);
    1627              :           /* Explicit tags on the template.  */
    1628        81558 :           tree ttags = get_abi_tags (res);
    1629              :           /* Tags on the instantiation.  */
    1630        81558 :           tree dtags = get_abi_tags (decl);
    1631              : 
    1632        81636 :           if (mtags && abi_warn_or_compat_version_crosses (10))
    1633            6 :             G.need_abi_warning = 1;
    1634              : 
    1635              :           /* Add the v10 tags to the explicit tags now.  */
    1636        81558 :           mtags = chainon (mtags, ttags);
    1637              : 
    1638        81558 :           if (!G.need_abi_warning
    1639       163018 :               && abi_warn_or_compat_version_crosses (11)
    1640       163022 :               && !equal_abi_tags (dtags, mtags))
    1641            6 :             G.need_abi_warning = 1;
    1642              : 
    1643        81558 :           if (!abi_version_at_least (10))
    1644              :             /* In abi <10, we only got the explicit tags.  */
    1645              :             decl = res;
    1646          901 :           else if (flag_abi_version == 10)
    1647              :             {
    1648              :               /* In ABI 10, we want explict and implicit tags.  */
    1649           72 :               write_abi_tags (mtags);
    1650           72 :               return;
    1651              :             }
    1652              :         }
    1653              :     }
    1654              : 
    1655    869242224 :   tree tags = get_abi_tags (decl);
    1656    190595689 :   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CONV_FN_P (decl)
    1657    872130017 :       && any_abi_below (11))
    1658         2731 :     if (tree mtags = missing_abi_tags (decl))
    1659              :       {
    1660            9 :         if (!abi_check (11))
    1661            6 :           tags = chainon (mtags, tags);
    1662              :       }
    1663    869242224 :   write_abi_tags (tags);
    1664              : }
    1665              : 
    1666              : /* Write the unqualified-name for a conversion operator to TYPE.  */
    1667              : 
    1668              : static void
    1669      2887808 : write_conversion_operator_name (const tree type)
    1670              : {
    1671      2887808 :   write_string ("cv");
    1672      2887808 :   write_type (type);
    1673      2887808 : }
    1674              : 
    1675              : /* Non-terminal <source-name>.  IDENTIFIER is an IDENTIFIER_NODE.
    1676              : 
    1677              :      <source-name> ::= </length/ number> <identifier>  */
    1678              : 
    1679              : static void
    1680    796782097 : write_source_name (tree identifier)
    1681              : {
    1682    796782097 :   MANGLE_TRACE_TREE ("source-name", identifier);
    1683              : 
    1684    796782097 :   write_unsigned_number (IDENTIFIER_LENGTH (identifier));
    1685    796782097 :   write_identifier (IDENTIFIER_POINTER (identifier));
    1686    796782097 : }
    1687              : 
    1688              : /* Compare two TREE_STRINGs like strcmp.  */
    1689              : 
    1690              : static int
    1691          306 : tree_string_cmp (const void *p1, const void *p2)
    1692              : {
    1693          306 :   if (p1 == p2)
    1694              :     return 0;
    1695          306 :   tree s1 = *(const tree*)p1;
    1696          306 :   tree s2 = *(const tree*)p2;
    1697          306 :   return strcmp (TREE_STRING_POINTER (s1),
    1698          306 :                  TREE_STRING_POINTER (s2));
    1699              : }
    1700              : 
    1701              : /* Return the TREE_LIST of TAGS as a sorted VEC.  */
    1702              : 
    1703              : static vec<tree, va_gc> *
    1704       580101 : sorted_abi_tags (tree tags)
    1705              : {
    1706       580101 :   vec<tree, va_gc> * vec = make_tree_vector();
    1707              : 
    1708       997343 :   for (tree t = tags; t; t = TREE_CHAIN (t))
    1709              :     {
    1710       417242 :       if (ABI_TAG_IMPLICIT (t))
    1711            3 :         continue;
    1712       417239 :       tree str = TREE_VALUE (t);
    1713       417239 :       vec_safe_push (vec, str);
    1714              :     }
    1715              : 
    1716       580101 :   vec->qsort (tree_string_cmp);
    1717              : 
    1718       580101 :   return vec;
    1719              : }
    1720              : 
    1721              : /* ID is the name of a function or type with abi_tags attribute TAGS.
    1722              :    Write out the name, suitably decorated.  */
    1723              : 
    1724              : static void
    1725    869242332 : write_abi_tags (tree tags)
    1726              : {
    1727    869242332 :   if (tags == NULL_TREE)
    1728    869242332 :     return;
    1729              : 
    1730       417113 :   vec<tree, va_gc> * vec = sorted_abi_tags (tags);
    1731              : 
    1732       417113 :   unsigned i; tree str;
    1733       834253 :   FOR_EACH_VEC_ELT (*vec, i, str)
    1734              :     {
    1735       417140 :       write_string ("B");
    1736       417140 :       write_unsigned_number (TREE_STRING_LENGTH (str) - 1);
    1737       417140 :       write_identifier (TREE_STRING_POINTER (str));
    1738              :     }
    1739              : 
    1740       417113 :   release_tree_vector (vec);
    1741              : }
    1742              : 
    1743              : /* True iff the TREE_LISTS T1 and T2 of ABI tags are equivalent.  */
    1744              : 
    1745              : bool
    1746        81494 : equal_abi_tags (tree t1, tree t2)
    1747              : {
    1748        81494 :   releasing_vec v1 = sorted_abi_tags (t1);
    1749        81494 :   releasing_vec v2 = sorted_abi_tags (t2);
    1750              : 
    1751        81494 :   unsigned len1 = v1->length();
    1752        81494 :   if (len1 != v2->length())
    1753              :     return false;
    1754        81488 :   for (unsigned i = 0; i < len1; ++i)
    1755           21 :     if (strcmp (TREE_STRING_POINTER (v1[i]),
    1756           21 :                 TREE_STRING_POINTER (v2[i])) != 0)
    1757              :       return false;
    1758              :   return true;
    1759        81494 : }
    1760              : 
    1761              : /* Write a user-defined literal operator.
    1762              :           ::= li <source-name>    # "" <source-name>
    1763              :    IDENTIFIER is an LITERAL_IDENTIFIER_NODE.  */
    1764              : 
    1765              : static void
    1766       297482 : write_literal_operator_name (tree identifier)
    1767              : {
    1768       297482 :   const char* suffix = UDLIT_OP_SUFFIX (identifier);
    1769       297482 :   write_identifier (UDLIT_OP_MANGLED_PREFIX);
    1770       297482 :   write_unsigned_number (strlen (suffix));
    1771       297482 :   write_identifier (suffix);
    1772       297482 : }
    1773              : 
    1774              : /* Encode 0 as _, and 1+ as n-1_.  */
    1775              : 
    1776              : static void
    1777     39472861 : write_compact_number (int num)
    1778              : {
    1779     39472861 :   gcc_checking_assert (num >= 0);
    1780     39472861 :   if (num > 0)
    1781     14438420 :     write_unsigned_number (num - 1);
    1782     39472861 :   write_char ('_');
    1783     39472861 : }
    1784              : 
    1785              : /* Return how many unnamed types precede TYPE in its enclosing class.  */
    1786              : 
    1787              : static int
    1788          697 : nested_anon_class_index (tree type)
    1789              : {
    1790          697 :   int index = 0;
    1791          697 :   tree member = TYPE_FIELDS (TYPE_CONTEXT (type));
    1792        19497 :   for (; member; member = DECL_CHAIN (member))
    1793        19497 :     if (DECL_IMPLICIT_TYPEDEF_P (member))
    1794              :       {
    1795         1086 :         tree memtype = TREE_TYPE (member);
    1796         1086 :         if (memtype == type)
    1797              :           return index;
    1798          972 :         else if (TYPE_UNNAMED_P (memtype))
    1799          194 :           ++index;
    1800              :       }
    1801              : 
    1802            0 :   if (seen_error ())
    1803              :     return -1;
    1804              : 
    1805            0 :   gcc_unreachable ();
    1806              : }
    1807              : 
    1808              : /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
    1809              : 
    1810              : static void
    1811         1364 : write_unnamed_type_name (const tree type)
    1812              : {
    1813         1364 :   int discriminator;
    1814         1364 :   MANGLE_TRACE_TREE ("unnamed-type-name", type);
    1815              : 
    1816         1364 :   if (TYPE_FUNCTION_SCOPE_P (type))
    1817          331 :     discriminator = discriminator_for_local_entity (TYPE_NAME (type));
    1818         1033 :   else if (TYPE_CLASS_SCOPE_P (type))
    1819          697 :     discriminator = nested_anon_class_index (type);
    1820              :   else
    1821              :     {
    1822          336 :       gcc_assert (no_linkage_check (type, /*relaxed_p=*/true));
    1823              :       /* Just use the old mangling at namespace scope.  */
    1824          336 :       write_source_name (TYPE_IDENTIFIER (type));
    1825          336 :       return;
    1826              :     }
    1827              : 
    1828         1028 :   write_string ("Ut");
    1829         1028 :   write_compact_number (discriminator);
    1830              : }
    1831              : 
    1832              : /* <unnamed-enum-name> ::= Ue <underlying type> <enumerator source-name> */
    1833              : 
    1834              : static void
    1835           19 : write_unnamed_enum_name (const tree type)
    1836              : {
    1837           19 :   MANGLE_TRACE_TREE ("unnamed-enum-name", type);
    1838           19 :   write_string ("Ue");
    1839           19 :   write_type (ENUM_UNDERLYING_TYPE (type));
    1840           19 :   write_source_name (DECL_NAME (TREE_VALUE (TYPE_VALUES (type))));
    1841           19 : }
    1842              : 
    1843              : /* ABI issue #47: if a function template parameter is not "natural" for its
    1844              :    argument we must mangle the parameter.  */
    1845              : 
    1846              : static bool
    1847      8684966 : template_parm_natural_p (tree arg, tree parm)
    1848              : {
    1849      8684966 :   tree decl = TREE_VALUE (parm);
    1850              : 
    1851              :   /* A template parameter is "natural" if: */
    1852              : 
    1853      8684966 :   if (template_parameter_pack_p (decl))
    1854              :     {
    1855       766410 :       tree args = ARGUMENT_PACK_ARGS (arg);
    1856       766410 :       if (TREE_VEC_LENGTH (args) == 0)
    1857              :         {
    1858              : #if 0
    1859              :           /* the argument is an empty pack and the parameter is an
    1860              :              unconstrained template type parameter pack; */
    1861              :           if (TREE_CODE (decl) != TYPE_DECL)
    1862              :             return false;
    1863              : #else
    1864              :           /* Defer changing the mangling of C++11 code like
    1865              :              template <int i> int max();
    1866              :              template <int i, int j, int... rest> int max();  */
    1867              :           return true;
    1868              : #endif
    1869              :         }
    1870              :       else
    1871              :         /* the argument is a non-empty pack and a non-pack variant of the
    1872              :            parameter would be natural for the first element of the pack; */
    1873       595861 :         arg = TREE_VEC_ELT (args, 0);
    1874              :     }
    1875              : 
    1876              :   /* the argument is a template and the parameter has the exact
    1877              :      same template head; */
    1878      8514417 :   if (TREE_CODE (decl) == TEMPLATE_DECL)
    1879         8230 :     return template_heads_equivalent_p (arg, decl);
    1880              : 
    1881              :   /* the argument is a type and the parameter is unconstrained; or */
    1882      8506187 :   else if (TREE_CODE (decl) == TYPE_DECL)
    1883      7477349 :     return !TEMPLATE_PARM_CONSTRAINTS (parm);
    1884              : 
    1885              :   /* the argument is a non-type template argument and the declared parameter
    1886              :      type neither is instantiation dependent nor contains deduced types.  */
    1887      1028838 :   else if (TREE_CODE (decl) == PARM_DECL)
    1888              :     {
    1889              : #if 0
    1890              :       return !uses_template_parms (TREE_TYPE (decl));
    1891              : #else
    1892              :       /* Defer changing the mangling of C++98 code like
    1893              :          template <class T, T V> ....  */
    1894      1028838 :       return !type_uses_auto (TREE_TYPE (decl));
    1895              : #endif
    1896              :     }
    1897              : 
    1898            0 :   gcc_unreachable ();
    1899              : }
    1900              : 
    1901              : /* Used for lambda template head and non-natural function template parameters.
    1902              : 
    1903              :    <template-param-decl> ::= Ty               # template type parameter
    1904              :         ::= Tk <type-constraint>              # constrained type parameter
    1905              :         ::= Tn <type>                         # template non-type parameter
    1906              :         ::= Tt <template-param-decl>* [Q <constraint-expression] E  # ttp
    1907              :         ::= Tp <non-pack template-param-decl> # template parameter pack */
    1908              : 
    1909              : static void
    1910        74192 : write_template_param_decl (tree parm)
    1911              : {
    1912        74192 :   tree decl = TREE_VALUE (parm);
    1913              : 
    1914        74192 :   if (template_parameter_pack_p (decl))
    1915        28218 :     write_string ("Tp");
    1916              : 
    1917        74192 :   switch (TREE_CODE (decl))
    1918              :     {
    1919        19273 :     case PARM_DECL:
    1920        19273 :       {
    1921        19273 :         write_string ("Tn");
    1922              : 
    1923        19273 :         tree type = TREE_TYPE (decl);
    1924              :         /* TODO: We need to also mangle constrained auto*, auto&, etc, but
    1925              :            it's not clear how.  See finish_constrained_parameter.  */
    1926        19273 :         if (tree c = (is_auto (type)
    1927        21279 :                       ? TEMPLATE_PARM_CONSTRAINTS (parm)
    1928         2006 :                       : NULL_TREE))
    1929              :           {
    1930           19 :             if (AUTO_IS_DECLTYPE (type))
    1931            0 :               write_string ("DK");
    1932              :             else
    1933           19 :               write_string ("Dk");
    1934           19 :             write_type_constraint (c);
    1935              :           }
    1936              :         else
    1937        19254 :           write_type (type);
    1938              :       }
    1939              :       break;
    1940              : 
    1941          246 :     case TEMPLATE_DECL:
    1942          246 :       {
    1943          246 :         write_string ("Tt");
    1944          246 :         tree parms = DECL_INNERMOST_TEMPLATE_PARMS (decl);
    1945          581 :         for (tree node : tree_vec_range (parms))
    1946          335 :           write_template_param_decl (node);
    1947          246 :         write_char ('E');
    1948              :       }
    1949          246 :       break;
    1950              : 
    1951        54673 :     case TYPE_DECL:
    1952        54673 :       if (tree c = TEMPLATE_PARM_CONSTRAINTS (parm))
    1953              :         {
    1954        30403 :           if (TREE_CODE (c) == UNARY_LEFT_FOLD_EXPR)
    1955              :             {
    1956           50 :               c = FOLD_EXPR_PACK (c);
    1957           50 :               c = PACK_EXPANSION_PATTERN (c);
    1958              :             }
    1959        30403 :           if (TREE_CODE (decl) == TYPE_DECL)
    1960              :             {
    1961        30403 :               write_string ("Tk");
    1962        30403 :               write_type_constraint (c);
    1963              :             }
    1964              :         }
    1965              :       else
    1966        24270 :         write_string ("Ty");
    1967              :       break;
    1968              : 
    1969            0 :     default:
    1970            0 :       gcc_unreachable ();
    1971              :     }
    1972        74192 : }
    1973              : 
    1974              : // A template head, for templated lambdas.
    1975              : // New in ABI=18. Returns true iff we emitted anything -- used for ABI
    1976              : // version warning.
    1977              : 
    1978              : static bool
    1979       895791 : write_closure_template_head (tree tmpl)
    1980              : {
    1981       895791 :   bool any = false;
    1982              : 
    1983              :   // We only need one level of template parms
    1984       895791 :   tree parms = DECL_TEMPLATE_PARMS (tmpl);
    1985       895791 :   tree inner = INNERMOST_TEMPLATE_PARMS (parms);
    1986              : 
    1987       937365 :   for (int ix = 0, len = TREE_VEC_LENGTH (inner); ix != len; ix++)
    1988              :     {
    1989       898050 :       tree parm = TREE_VEC_ELT (inner, ix);
    1990       898050 :       if (parm == error_mark_node)
    1991            0 :         continue;
    1992              : 
    1993       898050 :       if (DECL_IMPLICIT_TEMPLATE_PARM_P (TREE_VALUE (parm)))
    1994              :         // A synthetic parm, we're done.
    1995              :         break;
    1996              : 
    1997        41574 :       any = true;
    1998        41574 :       if (abi_version_at_least (18))
    1999        41334 :         write_template_param_decl (parm);
    2000              :     }
    2001              : 
    2002       895791 :   write_tparms_constraints (TEMPLATE_PARMS_CONSTRAINTS (parms));
    2003              : 
    2004       895791 :   return any;
    2005              : }
    2006              : 
    2007              : /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _
    2008              :    <lambda-sig> ::= <parameter type>+  # Parameter types or "v" if the lambda has no parameters */
    2009              : 
    2010              : static void
    2011      3640744 : write_closure_type_name (const tree type)
    2012              : {
    2013      3640744 :   tree fn = lambda_function (type);
    2014      3640744 :   tree lambda = CLASSTYPE_LAMBDA_EXPR (type);
    2015      3640744 :   tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
    2016              : 
    2017      3640744 :   MANGLE_TRACE_TREE ("closure-type-name", type);
    2018              : 
    2019      3640744 :   write_string ("Ul");
    2020              : 
    2021      3640744 :   if (auto ti = maybe_template_info (fn))
    2022       895791 :     if (write_closure_template_head (TI_TEMPLATE (ti)))
    2023              :       // If there were any explicit template parms, we may need to
    2024              :       // issue a mangling diagnostic.
    2025       202880 :       if (abi_warn_or_compat_version_crosses (18))
    2026          198 :         G.need_abi_warning = true;
    2027              : 
    2028      3640744 :   write_method_parms (parms, TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE, fn);
    2029      3640744 :   write_char ('E');
    2030      3640744 :   if ((LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
    2031      3640744 :        != LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda))
    2032      6833084 :       && abi_warn_or_compat_version_crosses (18))
    2033          288 :     G.need_abi_warning = true;
    2034      7281488 :   write_compact_number (abi_version_at_least (18)
    2035      3640222 :                         ? LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
    2036          522 :                         : LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda));
    2037      3640744 : }
    2038              : 
    2039              : /* Convert NUMBER to ascii using base BASE and generating at least
    2040              :    MIN_DIGITS characters. BUFFER points to the _end_ of the buffer
    2041              :    into which to store the characters. Returns the number of
    2042              :    characters generated (these will be laid out in advance of where
    2043              :    BUFFER points).  */
    2044              : 
    2045              : static int
    2046   1074467445 : hwint_to_ascii (unsigned HOST_WIDE_INT number, const unsigned int base,
    2047              :                 char *buffer, const unsigned int min_digits)
    2048              : {
    2049   1074467445 :   static const char base_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    2050   1074467445 :   unsigned digits = 0;
    2051              : 
    2052   2677769204 :   while (number)
    2053              :     {
    2054   1603301759 :       unsigned HOST_WIDE_INT d = number / base;
    2055              : 
    2056   1603301759 :       *--buffer = base_digits[number - d * base];
    2057   1603301759 :       digits++;
    2058   1603301759 :       number = d;
    2059              :     }
    2060   1128679776 :   while (digits < min_digits)
    2061              :     {
    2062     54212331 :       *--buffer = base_digits[0];
    2063     54212331 :       digits++;
    2064              :     }
    2065   1074467445 :   return digits;
    2066              : }
    2067              : 
    2068              : /* Non-terminal <number>.
    2069              : 
    2070              :      <number> ::= [n] </decimal integer/>  */
    2071              : 
    2072              : static void
    2073   1074467445 : write_number (unsigned HOST_WIDE_INT number, const int unsigned_p,
    2074              :               const unsigned int base)
    2075              : {
    2076   1074467445 :   char buffer[sizeof (HOST_WIDE_INT) * 8];
    2077   1074467445 :   unsigned count = 0;
    2078              : 
    2079   1074467445 :   if (!unsigned_p && (HOST_WIDE_INT) number < 0)
    2080              :     {
    2081            0 :       write_char ('n');
    2082            0 :       number = -((HOST_WIDE_INT) number);
    2083              :     }
    2084   1074467445 :   count = hwint_to_ascii (number, base, buffer + sizeof (buffer), 1);
    2085   1074467445 :   write_chars (buffer + sizeof (buffer) - count, count);
    2086   1074467445 : }
    2087              : 
    2088              : /* Write out an integral CST in decimal. Most numbers are small, and
    2089              :    representable in a HOST_WIDE_INT. Occasionally we'll have numbers
    2090              :    bigger than that, which we must deal with.  */
    2091              : 
    2092              : static inline void
    2093     95928047 : write_integer_cst (const tree cst)
    2094              : {
    2095     95928047 :   int sign = tree_int_cst_sgn (cst);
    2096     95928047 :   widest_int abs_value = wi::abs (wi::to_widest (cst));
    2097     95928047 :   if (!wi::fits_uhwi_p (abs_value))
    2098              :     {
    2099              :       /* A bignum. We do this in chunks, each of which fits in a
    2100              :          HOST_WIDE_INT.  */
    2101            0 :       char buffer[sizeof (HOST_WIDE_INT) * 8 * 2];
    2102            0 :       unsigned HOST_WIDE_INT chunk;
    2103            0 :       unsigned chunk_digits;
    2104            0 :       char *ptr = buffer + sizeof (buffer);
    2105            0 :       unsigned count = 0;
    2106            0 :       tree n, base, type;
    2107            0 :       int done;
    2108              : 
    2109              :       /* HOST_WIDE_INT must be at least 32 bits, so 10^9 is
    2110              :          representable.  */
    2111            0 :       chunk = 1000000000;
    2112            0 :       chunk_digits = 9;
    2113              : 
    2114            0 :       if (sizeof (HOST_WIDE_INT) >= 8)
    2115              :         {
    2116              :           /* It is at least 64 bits, so 10^18 is representable.  */
    2117            0 :           chunk_digits = 18;
    2118            0 :           chunk *= chunk;
    2119              :         }
    2120              : 
    2121            0 :       type = c_common_signed_or_unsigned_type (1, TREE_TYPE (cst));
    2122            0 :       base = build_int_cstu (type, chunk);
    2123            0 :       n = wide_int_to_tree (type, wi::to_wide (cst));
    2124              : 
    2125            0 :       if (sign < 0)
    2126              :         {
    2127            0 :           write_char ('n');
    2128            0 :           n = fold_build1_loc (input_location, NEGATE_EXPR, type, n);
    2129              :         }
    2130            0 :       do
    2131              :         {
    2132            0 :           tree d = fold_build2_loc (input_location, FLOOR_DIV_EXPR, type, n, base);
    2133            0 :           tree tmp = fold_build2_loc (input_location, MULT_EXPR, type, d, base);
    2134            0 :           unsigned c;
    2135              : 
    2136            0 :           done = integer_zerop (d);
    2137            0 :           tmp = fold_build2_loc (input_location, MINUS_EXPR, type, n, tmp);
    2138            0 :           c = hwint_to_ascii (TREE_INT_CST_LOW (tmp), 10, ptr,
    2139              :                               done ? 1 : chunk_digits);
    2140            0 :           ptr -= c;
    2141            0 :           count += c;
    2142            0 :           n = d;
    2143              :         }
    2144            0 :       while (!done);
    2145            0 :       write_chars (ptr, count);
    2146              :     }
    2147              :   else
    2148              :     {
    2149              :       /* A small num.  */
    2150     95928047 :       if (sign < 0)
    2151       470961 :         write_char ('n');
    2152     95928047 :       write_unsigned_number (abs_value.to_uhwi ());
    2153              :     }
    2154     95928047 : }
    2155              : 
    2156              : /* Write out a floating-point literal.
    2157              : 
    2158              :     "Floating-point literals are encoded using the bit pattern of the
    2159              :     target processor's internal representation of that number, as a
    2160              :     fixed-length lowercase hexadecimal string, high-order bytes first
    2161              :     (even if the target processor would store low-order bytes first).
    2162              :     The "n" prefix is not used for floating-point literals; the sign
    2163              :     bit is encoded with the rest of the number.
    2164              : 
    2165              :     Here are some examples, assuming the IEEE standard representation
    2166              :     for floating point numbers.  (Spaces are for readability, not
    2167              :     part of the encoding.)
    2168              : 
    2169              :         1.0f                    Lf 3f80 0000 E
    2170              :        -1.0f                    Lf bf80 0000 E
    2171              :         1.17549435e-38f         Lf 0080 0000 E
    2172              :         1.40129846e-45f         Lf 0000 0001 E
    2173              :         0.0f                    Lf 0000 0000 E"
    2174              : 
    2175              :    Caller is responsible for the Lx and the E.  */
    2176              : static void
    2177          338 : write_real_cst (const tree value)
    2178              : {
    2179          338 :   long target_real[4];  /* largest supported float */
    2180              :   /* Buffer for eight hex digits in a 32-bit number but big enough
    2181              :      even for 64-bit long to avoid warnings.  */
    2182          338 :   char buffer[17];
    2183          338 :   int i, limit, dir;
    2184              : 
    2185          338 :   tree type = TREE_TYPE (value);
    2186          338 :   int bits = GET_MODE_BITSIZE (SCALAR_FLOAT_TYPE_MODE (type));
    2187          338 :   int words = bits / 32;
    2188              : 
    2189          338 :   real_to_target (target_real, &TREE_REAL_CST (value),
    2190          338 :                   TYPE_MODE (type));
    2191              : 
    2192          338 :   if (words == 0)
    2193              :     {
    2194              :       /* _Float16 and std::bfloat16_t are the only supported types smaller than
    2195              :          32 bits.  */
    2196            6 :       gcc_assert (bits == 16);
    2197            6 :       sprintf (buffer, "%04lx", (unsigned long) target_real[0]);
    2198            6 :       write_chars (buffer, 4);
    2199            6 :       return;
    2200              :     }
    2201              : 
    2202          332 :   gcc_assert (bits % 32 == 0);
    2203              : 
    2204              :   /* The value in target_real is in the target word order,
    2205              :      so we must write it out backward if that happens to be
    2206              :      little-endian.  write_number cannot be used, it will
    2207              :      produce uppercase.  */
    2208          332 :   if (FLOAT_WORDS_BIG_ENDIAN)
    2209              :     i = 0, limit = words, dir = 1;
    2210              :   else
    2211          332 :     i = words - 1, limit = -1, dir = -1;
    2212              : 
    2213          360 :   if (GET_MODE_PRECISION (SCALAR_FLOAT_TYPE_MODE (type)) == 80
    2214          332 :       && abi_check (21))
    2215              :     {
    2216              :       /* For -fabi-version=21 and above mangle
    2217              :          Intel/Motorola extended format 1.0L as
    2218              :          3fff8000000000000000
    2219              :          rather than the previous
    2220              :          0000000000003fff8000000000000000 (x86_64)
    2221              :          00003fff8000000000000000 (ia32)
    2222              :          3fff00008000000000000000 (m68k -mc68020)
    2223              :          i.e. without any embedded padding bits.  */
    2224           30 :       if (words == 4)
    2225              :         i += dir;
    2226              :       else
    2227            0 :         gcc_assert (words == 3);
    2228           30 :       unsigned long val = (unsigned long) target_real[i];
    2229           30 :       if (REAL_MODE_FORMAT (SCALAR_FLOAT_TYPE_MODE (type))->signbit_ro == 95)
    2230            0 :         val >>= 16;
    2231           30 :       sprintf (buffer, "%04lx", val);
    2232           30 :       write_chars (buffer, 4);
    2233           30 :       i += dir;
    2234              :     }
    2235              : 
    2236          976 :   for (; i != limit; i += dir)
    2237              :     {
    2238          644 :       sprintf (buffer, "%08lx", (unsigned long) target_real[i]);
    2239          644 :       write_chars (buffer, 8);
    2240              :     }
    2241              : }
    2242              : 
    2243              : /* Non-terminal <identifier>.
    2244              : 
    2245              :      <identifier> ::= </unqualified source code identifier>  */
    2246              : 
    2247              : static void
    2248    799260967 : write_identifier (const char *identifier)
    2249              : {
    2250    799260967 :   MANGLE_TRACE ("identifier", identifier);
    2251    799260967 :   write_string (identifier);
    2252    799260967 : }
    2253              : 
    2254              : /* Handle constructor productions of non-terminal <special-name>.
    2255              :    CTOR is a constructor FUNCTION_DECL.
    2256              : 
    2257              :      <special-name> ::= C1   # complete object constructor
    2258              :                     ::= C2   # base object constructor
    2259              :                     ::= C3   # complete object allocating constructor
    2260              : 
    2261              :    Currently, allocating constructors are never used.  */
    2262              : 
    2263              : static void
    2264     32210681 : write_special_name_constructor (const tree ctor)
    2265              : {
    2266     32210681 :   write_char ('C');
    2267     32210681 :   bool new_inh = (flag_new_inheriting_ctors
    2268     64405635 :                   && DECL_INHERITED_CTOR (ctor));
    2269       201650 :   if (new_inh)
    2270       201650 :     write_char ('I');
    2271     32210681 :   if (DECL_BASE_CONSTRUCTOR_P (ctor))
    2272      6871189 :     write_char ('2');
    2273              :   /* This is the old-style "[unified]" constructor.
    2274              :      In some cases, we may emit this function and call
    2275              :      it from the clones in order to share code and save space.  */
    2276     25339492 :   else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
    2277     18471293 :     write_char ('4');
    2278              :   else
    2279              :     {
    2280      6868199 :       gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (ctor));
    2281      6868199 :       write_char ('1');
    2282              :     }
    2283     32210681 :   if (new_inh)
    2284       403300 :     write_type (DECL_INHERITED_CTOR_BASE (ctor));
    2285     32210681 : }
    2286              : 
    2287              : /* Handle destructor productions of non-terminal <special-name>.
    2288              :    DTOR is a destructor FUNCTION_DECL.
    2289              : 
    2290              :      <special-name> ::= D0 # deleting (in-charge) destructor
    2291              :                     ::= D1 # complete object (in-charge) destructor
    2292              :                     ::= D2 # base object (not-in-charge) destructor  */
    2293              : 
    2294              : static void
    2295      7666608 : write_special_name_destructor (const tree dtor)
    2296              : {
    2297      7666608 :   if (DECL_DELETING_DESTRUCTOR_P (dtor))
    2298       601490 :     write_string ("D0");
    2299      7065118 :   else if (DECL_BASE_DESTRUCTOR_P (dtor))
    2300      1668129 :     write_string ("D2");
    2301      5396989 :   else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
    2302              :     /* This is the old-style "[unified]" destructor.
    2303              :        In some cases, we may emit this function and call
    2304              :        it from the clones in order to share code and save space.  */
    2305      3150762 :     write_string ("D4");
    2306              :   else
    2307              :     {
    2308      2246227 :       gcc_assert (DECL_COMPLETE_DESTRUCTOR_P (dtor));
    2309      2246227 :       write_string ("D1");
    2310              :     }
    2311      7666608 : }
    2312              : 
    2313              : /* Return the discriminator for ENTITY appearing inside
    2314              :    FUNCTION.  The discriminator is the lexical ordinal of VAR or TYPE among
    2315              :    entities with the same name and kind in the same FUNCTION.  */
    2316              : 
    2317              : static int
    2318      2961342 : discriminator_for_local_entity (tree entity)
    2319              : {
    2320      2961342 :   if (!DECL_LANG_SPECIFIC (entity))
    2321              :     {
    2322              :       /* Some decls, like __FUNCTION__, don't need a discriminator.  */
    2323        30912 :       gcc_checking_assert (DECL_ARTIFICIAL (entity));
    2324              :       return 0;
    2325              :     }
    2326      5689545 :   else if (tree disc = DECL_DISCRIMINATOR (entity))
    2327          459 :     return TREE_INT_CST_LOW (disc);
    2328              :   else
    2329              :     /* The first entity with a particular name doesn't get
    2330              :        DECL_DISCRIMINATOR set up.  */
    2331              :     return 0;
    2332              : }
    2333              : 
    2334              : /* Return the discriminator for STRING, a string literal used inside
    2335              :    FUNCTION.  The discriminator is the lexical ordinal of STRING among
    2336              :    string literals used in FUNCTION.  */
    2337              : 
    2338              : static int
    2339            0 : discriminator_for_string_literal (tree /*function*/,
    2340              :                                   tree /*string*/)
    2341              : {
    2342              :   /* For now, we don't discriminate amongst string literals.  */
    2343            0 :   return 0;
    2344              : }
    2345              : 
    2346              : /*   <discriminator> := _ <number>    # when number < 10
    2347              :                      := __ <number> _ # when number >= 10
    2348              : 
    2349              :    The discriminator is used only for the second and later occurrences
    2350              :    of the same name within a single function. In this case <number> is
    2351              :    n - 2, if this is the nth occurrence, in lexical order.  */
    2352              : 
    2353              : static void
    2354      2961011 : write_discriminator (const int discriminator)
    2355              : {
    2356              :   /* If discriminator is zero, don't write anything.  Otherwise...  */
    2357      2961011 :   if (discriminator > 0)
    2358              :     {
    2359          441 :       write_char ('_');
    2360          441 :       if (discriminator - 1 >= 10)
    2361              :         {
    2362            6 :           if (abi_check (11))
    2363            6 :             write_char ('_');
    2364              :         }
    2365          441 :       write_unsigned_number (discriminator - 1);
    2366          441 :       if (abi_version_at_least (11) && discriminator - 1 >= 10)
    2367            6 :         write_char ('_');
    2368              :     }
    2369      2961011 : }
    2370              : 
    2371              : /* Mangle the name of a function-scope entity.  FUNCTION is the
    2372              :    FUNCTION_DECL for the enclosing function, or a PARM_DECL for lambdas in
    2373              :    default argument scope.  ENTITY is the decl for the entity itself.
    2374              :    LOCAL_ENTITY is the entity that's directly scoped in FUNCTION_DECL,
    2375              :    either ENTITY itself or an enclosing scope of ENTITY.
    2376              : 
    2377              :      <local-name> := Z <function encoding> E <entity name> [<discriminator>]
    2378              :                   := Z <function encoding> E s [<discriminator>]
    2379              :                   := Z <function encoding> Ed [ <parameter number> ] _ <entity name> */
    2380              : 
    2381              : static void
    2382      6583786 : write_local_name (tree function, const tree local_entity,
    2383              :                   const tree entity)
    2384              : {
    2385      6583786 :   tree parm = NULL_TREE;
    2386              : 
    2387      6583786 :   MANGLE_TRACE_TREE ("local-name", entity);
    2388              : 
    2389      6583786 :   if (TREE_CODE (function) == PARM_DECL)
    2390              :     {
    2391          357 :       parm = function;
    2392          357 :       function = DECL_CONTEXT (parm);
    2393              :     }
    2394              : 
    2395      6583786 :   write_char ('Z');
    2396      6583786 :   write_encoding (function);
    2397      6583786 :   write_char ('E');
    2398              : 
    2399              :   /* For this purpose, parameters are numbered from right-to-left.  */
    2400      6583786 :   if (parm)
    2401              :     {
    2402          357 :       int i = list_length (parm);
    2403          357 :       write_char ('d');
    2404          357 :       write_compact_number (i - 1);
    2405              :     }
    2406              : 
    2407      6583786 :   if (TREE_CODE (entity) == STRING_CST)
    2408              :     {
    2409            0 :       write_char ('s');
    2410            0 :       write_discriminator (discriminator_for_string_literal (function,
    2411              :                                                              entity));
    2412              :     }
    2413              :   else
    2414              :     {
    2415              :       /* Now the <entity name>.  Let write_name know its being called
    2416              :          from <local-name>, so it doesn't try to process the enclosing
    2417              :          function scope again.  */
    2418      6583786 :       write_name (entity, /*ignore_local_scope=*/1);
    2419      6583786 :       if (DECL_DISCRIMINATOR_P (local_entity)
    2420     19548568 :           && !(TREE_CODE (local_entity) == TYPE_DECL
    2421     19144224 :                && TYPE_ANON_P (TREE_TYPE (local_entity))))
    2422      2960750 :         write_discriminator (discriminator_for_local_entity (local_entity));
    2423              :     }
    2424      6583786 : }
    2425              : 
    2426              : /* Non-terminals <type> and <CV-qualifier>.
    2427              : 
    2428              :      <type> ::= <builtin-type>
    2429              :             ::= <function-type>
    2430              :             ::= <class-enum-type>
    2431              :             ::= <array-type>
    2432              :             ::= <pointer-to-member-type>
    2433              :             ::= <template-param>
    2434              :             ::= <substitution>
    2435              :             ::= <CV-qualifier>
    2436              :             ::= P <type>    # pointer-to
    2437              :             ::= R <type>    # reference-to
    2438              :             ::= C <type>    # complex pair (C 2000)
    2439              :             ::= G <type>    # imaginary (C 2000)     [not supported]
    2440              :             ::= U <source-name> <type>   # vendor extended type qualifier
    2441              : 
    2442              :    C++0x extensions
    2443              : 
    2444              :      <type> ::= RR <type>   # rvalue reference-to
    2445              :      <type> ::= Dt <expression> # decltype of an id-expression or
    2446              :                                 # class member access
    2447              :      <type> ::= DT <expression> # decltype of an expression
    2448              :      <type> ::= Dn              # decltype of nullptr
    2449              :      <type> ::= Dm                # decltype of ^^int
    2450              : 
    2451              :    TYPE is a type node.  */
    2452              : 
    2453              : static void
    2454   1354890909 : write_type (tree type)
    2455              : {
    2456              :   /* This gets set to nonzero if TYPE turns out to be a (possibly
    2457              :      CV-qualified) builtin type.  */
    2458   1354890918 :   int is_builtin_type = 0;
    2459              : 
    2460   1354890918 :   MANGLE_TRACE_TREE ("type", type);
    2461              : 
    2462   1354890918 :   if (type == error_mark_node)
    2463              :     return;
    2464              : 
    2465   1354890903 :   type = canonicalize_for_substitution (type);
    2466   1354890903 :   if (find_substitution (type))
    2467              :     return;
    2468              : 
    2469              : 
    2470   1232359432 :   if (write_CV_qualifiers_for_type (type) > 0)
    2471              :     /* If TYPE was CV-qualified, we just wrote the qualifiers; now
    2472              :        mangle the unqualified type.  The recursive call is needed here
    2473              :        since both the qualified and unqualified types are substitution
    2474              :        candidates.  */
    2475              :     {
    2476     88389731 :       tree t = TYPE_MAIN_VARIANT (type);
    2477     88389731 :       if (TYPE_ATTRIBUTES (t) && !OVERLOAD_TYPE_P (t))
    2478              :         {
    2479           99 :           tree attrs = NULL_TREE;
    2480           99 :           if (tx_safe_fn_type_p (type))
    2481            3 :             attrs = tree_cons (get_identifier ("transaction_safe"),
    2482              :                                NULL_TREE, attrs);
    2483           99 :           t = cp_build_type_attribute_variant (t, attrs);
    2484              :         }
    2485     88389731 :       gcc_assert (t != type);
    2486     88389731 :       if (FUNC_OR_METHOD_TYPE_P (t))
    2487              :         {
    2488         3987 :           t = build_ref_qualified_type (t, type_memfn_rqual (type));
    2489         3987 :           if (flag_noexcept_type)
    2490              :             {
    2491         3966 :               tree r = TYPE_RAISES_EXCEPTIONS (type);
    2492         3966 :               t = build_exception_variant (t, r);
    2493              :             }
    2494         3987 :           if (abi_version_at_least (8)
    2495         4011 :               || type == TYPE_MAIN_VARIANT (type))
    2496              :             /* Avoid adding the unqualified function type as a substitution.  */
    2497         3963 :             write_function_type (t);
    2498              :           else
    2499           24 :             write_type (t);
    2500        19818 :           if (abi_warn_or_compat_version_crosses (8))
    2501           39 :             G.need_abi_warning = 1;
    2502              :         }
    2503              :       else
    2504     88385744 :         write_type (t);
    2505              :     }
    2506   1143969701 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    2507              :     /* It is important not to use the TYPE_MAIN_VARIANT of TYPE here
    2508              :        so that the cv-qualification of the element type is available
    2509              :        in write_array_type.  */
    2510      1597649 :     write_array_type (type);
    2511              :   else
    2512              :     {
    2513   1142372052 :       tree type_orig = type;
    2514              : 
    2515              :       /* See through any typedefs.  */
    2516   1142372052 :       type = TYPE_MAIN_VARIANT (type);
    2517   1142372052 :       if (FUNC_OR_METHOD_TYPE_P (type))
    2518      3069452 :         type = cxx_copy_lang_qualifiers (type, type_orig);
    2519              : 
    2520              :       /* According to the C++ ABI, some library classes are passed the
    2521              :          same as the scalar type of their single member and use the same
    2522              :          mangling.  */
    2523   1142372052 :       if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
    2524        16206 :         type = TREE_TYPE (first_field (type));
    2525              : 
    2526   1142372052 :       if (TYPE_PTRDATAMEM_P (type))
    2527        11183 :         write_pointer_to_member_type (type);
    2528              :       else
    2529              :         {
    2530              :           /* Handle any target-specific fundamental types.  */
    2531   1142360869 :           const char *target_mangling
    2532   1142360869 :             = targetm.mangle_type (type_orig);
    2533              : 
    2534   1142360869 :           if (target_mangling)
    2535              :             {
    2536      9988880 :               write_string (target_mangling);
    2537              :               /* Add substitutions for types other than fundamental
    2538              :                  types.  */
    2539      9988880 :               if (!VOID_TYPE_P (type)
    2540              :                   && TREE_CODE (type) != INTEGER_TYPE
    2541              :                   && TREE_CODE (type) != REAL_TYPE
    2542              :                   && TREE_CODE (type) != BOOLEAN_TYPE)
    2543            0 :                 add_substitution (type);
    2544      9988880 :               return;
    2545              :             }
    2546              : 
    2547   1132371989 :           switch (TREE_CODE (type))
    2548              :             {
    2549    604159397 :             case VOID_TYPE:
    2550    604159397 :             case BOOLEAN_TYPE:
    2551    604159397 :             case INTEGER_TYPE:  /* Includes wchar_t.  */
    2552    604159397 :             case REAL_TYPE:
    2553    604159397 :             case FIXED_POINT_TYPE:
    2554    604159397 :               {
    2555              :                 /* If this is a typedef, TYPE may not be one of
    2556              :                    the standard builtin type nodes, but an alias of one.  Use
    2557              :                    TYPE_MAIN_VARIANT to get to the underlying builtin type.  */
    2558    604159397 :                 write_builtin_type (TYPE_MAIN_VARIANT (type));
    2559    604159397 :                 ++is_builtin_type;
    2560              :               }
    2561    604159397 :               break;
    2562              : 
    2563       633071 :             case COMPLEX_TYPE:
    2564       633071 :               write_char ('C');
    2565       633071 :               write_type (TREE_TYPE (type));
    2566       633071 :               break;
    2567              : 
    2568      3069452 :             case FUNCTION_TYPE:
    2569      3069452 :             case METHOD_TYPE:
    2570      3069452 :               write_function_type (type);
    2571      3069452 :               break;
    2572              : 
    2573    337954317 :             case UNION_TYPE:
    2574    337954317 :             case RECORD_TYPE:
    2575    337954317 :             case ENUMERAL_TYPE:
    2576              :               /* A pointer-to-member function is represented as a special
    2577              :                  RECORD_TYPE, so check for this first.  */
    2578    337954317 :               if (TYPE_PTRMEMFUNC_P (type))
    2579       256452 :                 write_pointer_to_member_type (type);
    2580              :               else
    2581    337697865 :                 write_class_enum_type (type);
    2582              :               break;
    2583              : 
    2584      4211455 :             case TYPENAME_TYPE:
    2585      4211455 :             case UNBOUND_CLASS_TEMPLATE:
    2586              :               /* We handle TYPENAME_TYPEs and UNBOUND_CLASS_TEMPLATEs like
    2587              :                  ordinary nested names.  */
    2588      4211455 :               write_nested_name (TYPE_STUB_DECL (type));
    2589      4211455 :               break;
    2590              : 
    2591    141404360 :             case POINTER_TYPE:
    2592    141404360 :             case REFERENCE_TYPE:
    2593    141404360 :               if (TYPE_PTR_P (type))
    2594     61234762 :                 write_char ('P');
    2595     80169598 :               else if (TYPE_REF_IS_RVALUE (type))
    2596     13134924 :                 write_char ('O');
    2597              :               else
    2598     67034674 :                 write_char ('R');
    2599    141404360 :               {
    2600    141404360 :                 tree target = TREE_TYPE (type);
    2601              :                 /* Attribute const/noreturn are not reflected in mangling.
    2602              :                    We strip them here rather than at a lower level because
    2603              :                    a typedef or template argument can have function type
    2604              :                    with function-cv-quals (that use the same representation),
    2605              :                    but you can't have a pointer/reference to such a type.  */
    2606    141404360 :                 if (TREE_CODE (target) == FUNCTION_TYPE)
    2607              :                   {
    2608     10393235 :                     if (abi_warn_or_compat_version_crosses (5)
    2609      2079001 :                         && TYPE_QUALS (target) != TYPE_UNQUALIFIED)
    2610            3 :                       G.need_abi_warning = 1;
    2611      2078995 :                     if (abi_version_at_least (5))
    2612      2078566 :                       target = build_qualified_type (target, TYPE_UNQUALIFIED);
    2613              :                   }
    2614    141404360 :                 write_type (target);
    2615              :               }
    2616    141404360 :               break;
    2617              : 
    2618     35776184 :             case TEMPLATE_TYPE_PARM:
    2619     35776184 :               if (is_auto (type))
    2620              :                 {
    2621      1466951 :                   if (template_placeholder_p (type)
    2622      1466951 :                       && abi_check (19))
    2623              :                     {
    2624              :                       /* ABI #109: placeholder is mangled as its template.  */
    2625          185 :                       type = CLASS_PLACEHOLDER_TEMPLATE (type);
    2626          185 :                       if (find_substitution (type))
    2627              :                         return;
    2628           33 :                       write_name (type, 0);
    2629           33 :                       break;
    2630              :                     }
    2631      1466766 :                   if (AUTO_IS_DECLTYPE (type))
    2632       100578 :                     write_identifier ("Dc");
    2633              :                   else
    2634      1366188 :                     write_identifier ("Da");
    2635              :                   ++is_builtin_type;
    2636              :                   break;
    2637              :                 }
    2638              :               /* fall through.  */
    2639     34309233 :             case TEMPLATE_PARM_INDEX:
    2640     34309233 :               write_template_param (type);
    2641     34309233 :               break;
    2642              : 
    2643           93 :             case TEMPLATE_TEMPLATE_PARM:
    2644           93 :               write_template_template_param (type);
    2645           93 :               break;
    2646              : 
    2647          532 :             case BOUND_TEMPLATE_TEMPLATE_PARM:
    2648          532 :               write_template_template_param (type);
    2649          532 :               write_template_args
    2650          532 :                 (TI_ARGS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type)));
    2651          532 :               break;
    2652              : 
    2653         9482 :             case VECTOR_TYPE:
    2654         9482 :               if (abi_version_at_least (4))
    2655              :                 {
    2656         9467 :                   write_string ("Dv");
    2657              :                   /* Non-constant vector size would be encoded with
    2658              :                      _ expression, but we don't support that yet.  */
    2659         9467 :                   write_unsigned_number (TYPE_VECTOR_SUBPARTS (type)
    2660              :                                          .to_constant ());
    2661         9467 :                   write_char ('_');
    2662         9467 :                 }
    2663              :               else
    2664           15 :                 write_string ("U8__vector");
    2665        47365 :               if (abi_warn_or_compat_version_crosses (4))
    2666           15 :                 G.need_abi_warning = 1;
    2667         9482 :               write_type (TREE_TYPE (type));
    2668         9482 :               break;
    2669              : 
    2670      3139852 :             case TYPE_PACK_EXPANSION:
    2671      3139852 :               write_string ("Dp");
    2672      3139852 :               write_type (PACK_EXPANSION_PATTERN (type));
    2673      3139852 :               break;
    2674              : 
    2675      1193470 :             case DECLTYPE_TYPE:
    2676              :               /* These shouldn't make it into mangling.  */
    2677      1193470 :               gcc_assert (!DECLTYPE_FOR_LAMBDA_CAPTURE (type)
    2678              :                           && !DECLTYPE_FOR_LAMBDA_PROXY (type));
    2679              : 
    2680              :               /* In ABI <5, we stripped decltype of a plain decl.  */
    2681      1193470 :               if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
    2682              :                 {
    2683          172 :                   tree expr = DECLTYPE_TYPE_EXPR (type);
    2684          172 :                   tree etype = NULL_TREE;
    2685          172 :                   switch (TREE_CODE (expr))
    2686              :                     {
    2687          118 :                     case VAR_DECL:
    2688          118 :                     case PARM_DECL:
    2689          118 :                     case RESULT_DECL:
    2690          118 :                     case FUNCTION_DECL:
    2691          118 :                     case CONST_DECL:
    2692          118 :                     case TEMPLATE_PARM_INDEX:
    2693          118 :                       etype = TREE_TYPE (expr);
    2694          118 :                       break;
    2695              : 
    2696              :                     default:
    2697              :                       break;
    2698              :                     }
    2699              : 
    2700          118 :                   if (etype && !type_uses_auto (etype))
    2701              :                     {
    2702          117 :                       if (!abi_check (5))
    2703              :                         {
    2704              :                           write_type (etype);
    2705              :                           return;
    2706              :                         }
    2707              :                     }
    2708              :                 }
    2709              : 
    2710      1193461 :               write_char ('D');
    2711      1193461 :               if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
    2712          163 :                 write_char ('t');
    2713              :               else
    2714      1193298 :                 write_char ('T');
    2715      1193461 :               ++cp_unevaluated_operand;
    2716      1193461 :               write_expression (DECLTYPE_TYPE_EXPR (type));
    2717      1193461 :               --cp_unevaluated_operand;
    2718      1193461 :               write_char ('E');
    2719      1193461 :               break;
    2720              : 
    2721       759051 :             case NULLPTR_TYPE:
    2722       759051 :               write_string ("Dn");
    2723       759051 :               if (abi_check (7))
    2724              :                 ++is_builtin_type;
    2725              :               break;
    2726              : 
    2727        61244 :             case META_TYPE:
    2728        61244 :               write_string ("Dm");
    2729        61244 :               ++is_builtin_type;
    2730        61244 :               break;
    2731              : 
    2732            3 :             case TYPEOF_TYPE:
    2733            3 :               sorry ("mangling %<typeof%>, use %<decltype%> instead");
    2734            3 :               break;
    2735              : 
    2736           21 :             case TRAIT_TYPE:
    2737           21 :               error ("use of built-in trait %qT in function signature; "
    2738              :                      "use library traits instead", type);
    2739           21 :               break;
    2740              : 
    2741            5 :             case PACK_INDEX_TYPE:
    2742              :               /* TODO Mangle pack indexing
    2743              :                  <https://github.com/itanium-cxx-abi/cxx-abi/issues/175>.  */
    2744            5 :               sorry ("mangling type pack index");
    2745            5 :               break;
    2746              : 
    2747            0 :             case LANG_TYPE:
    2748              :               /* fall through.  */
    2749              : 
    2750            0 :             default:
    2751            0 :               gcc_unreachable ();
    2752              :             }
    2753              :         }
    2754              :     }
    2755              : 
    2756              :   /* Types other than builtin types are substitution candidates.  */
    2757   1220140626 :   if (!is_builtin_type)
    2758    615923935 :     add_substitution (type);
    2759              : }
    2760              : 
    2761              : /* qsort callback for sorting a vector of attribute entries.  */
    2762              : 
    2763              : static int
    2764            0 : attr_strcmp (const void *p1, const void *p2)
    2765              : {
    2766            0 :   tree a1 = *(const tree*)p1;
    2767            0 :   tree a2 = *(const tree*)p2;
    2768              : 
    2769            0 :   const attribute_spec *as1 = lookup_attribute_spec (get_attribute_name (a1));
    2770            0 :   const attribute_spec *as2 = lookup_attribute_spec (get_attribute_name (a2));
    2771              : 
    2772            0 :   return strcmp (as1->name, as2->name);
    2773              : }
    2774              : 
    2775              : /* Return true if we should mangle a type attribute with name NAME.  */
    2776              : 
    2777              : static bool
    2778        12210 : mangle_type_attribute_p (tree name)
    2779              : {
    2780        12210 :   const attribute_spec *as = lookup_attribute_spec (name);
    2781        12210 :   if (!as || !as->affects_type_identity)
    2782              :     return false;
    2783              : 
    2784              :   /* Skip internal-only attributes, which are distinguished from others
    2785              :      by having a space.  At present, all internal-only attributes that
    2786              :      affect type identity are target-specific and are handled by
    2787              :      targetm.mangle_type instead.
    2788              : 
    2789              :      Another reason to do this is that a space isn't a valid identifier
    2790              :      character for most file formats.  */
    2791           57 :   if (strchr (IDENTIFIER_POINTER (name), ' '))
    2792              :     return false;
    2793              : 
    2794              :   /* The following attributes are mangled specially.  */
    2795           57 :   if (is_attribute_p ("transaction_safe", name))
    2796              :     return false;
    2797           33 :   if (is_attribute_p ("abi_tag", name))
    2798            0 :     return false;
    2799              : 
    2800              :   return true;
    2801              : }
    2802              : 
    2803              : /* Non-terminal <CV-qualifiers> for type nodes.  Returns the number of
    2804              :    CV-qualifiers written for TYPE.
    2805              : 
    2806              :      <CV-qualifiers> ::= [r] [V] [K]  */
    2807              : 
    2808              : static int
    2809   1232615884 : write_CV_qualifiers_for_type (const tree type)
    2810              : {
    2811   1232615884 :   int num_qualifiers = 0;
    2812              : 
    2813              :   /* The order is specified by:
    2814              : 
    2815              :        "In cases where multiple order-insensitive qualifiers are
    2816              :        present, they should be ordered 'K' (closest to the base type),
    2817              :        'V', 'r', and 'U' (farthest from the base type) ..."  */
    2818              : 
    2819              :   /* Mangle attributes that affect type identity as extended qualifiers.
    2820              : 
    2821              :      We don't do this with classes and enums because their attributes
    2822              :      are part of their definitions, not something added on.  */
    2823              : 
    2824   1232615884 :   if (!OVERLOAD_TYPE_P (type))
    2825              :     {
    2826    858683870 :       auto_vec<tree> vec;
    2827    858696080 :       for (tree a = TYPE_ATTRIBUTES (type); a; a = TREE_CHAIN (a))
    2828        12210 :         if (mangle_type_attribute_p (get_attribute_name (a)))
    2829           33 :           vec.safe_push (a);
    2830   4292659247 :       if (abi_warn_or_compat_version_crosses (10) && !vec.is_empty ())
    2831            0 :         G.need_abi_warning = true;
    2832    858683870 :       if (abi_version_at_least (10))
    2833              :         {
    2834    858435241 :           vec.qsort (attr_strcmp);
    2835    858683936 :           while (!vec.is_empty())
    2836              :             {
    2837           33 :               tree a = vec.pop();
    2838           33 :               const attribute_spec *as
    2839           33 :                 = lookup_attribute_spec (get_attribute_name (a));
    2840              : 
    2841           33 :               write_char ('U');
    2842           33 :               write_unsigned_number (strlen (as->name));
    2843           33 :               write_string (as->name);
    2844           33 :               if (TREE_VALUE (a))
    2845              :                 {
    2846            3 :                   write_char ('I');
    2847            6 :                   for (tree args = TREE_VALUE (a); args;
    2848            3 :                        args = TREE_CHAIN (args))
    2849              :                     {
    2850            3 :                       tree arg = TREE_VALUE (args);
    2851            3 :                       write_template_arg (arg);
    2852              :                     }
    2853            3 :                   write_char ('E');
    2854              :                 }
    2855              : 
    2856           33 :               ++num_qualifiers;
    2857              :             }
    2858              :         }
    2859    858683870 :     }
    2860              : 
    2861              :   /* Note that we do not use cp_type_quals below; given "const
    2862              :      int[3]", the "const" is emitted with the "int", not with the
    2863              :      array.  */
    2864   1232615884 :   cp_cv_quals quals = TYPE_QUALS (type);
    2865              : 
    2866   1232615884 :   if (quals & TYPE_QUAL_RESTRICT)
    2867              :     {
    2868           43 :       write_char ('r');
    2869           43 :       ++num_qualifiers;
    2870              :     }
    2871   1232615884 :   if (quals & TYPE_QUAL_VOLATILE)
    2872              :     {
    2873       504069 :       write_char ('V');
    2874       504069 :       ++num_qualifiers;
    2875              :     }
    2876   1232615884 :   if (quals & TYPE_QUAL_CONST)
    2877              :     {
    2878     88327500 :       write_char ('K');
    2879     88327500 :       ++num_qualifiers;
    2880              :     }
    2881              : 
    2882   1232615884 :   return num_qualifiers;
    2883              : }
    2884              : 
    2885              : /* Non-terminal <builtin-type>.
    2886              : 
    2887              :      <builtin-type> ::= v   # void
    2888              :                     ::= b   # bool
    2889              :                     ::= w   # wchar_t
    2890              :                     ::= c   # char
    2891              :                     ::= a   # signed char
    2892              :                     ::= h   # unsigned char
    2893              :                     ::= s   # short
    2894              :                     ::= t   # unsigned short
    2895              :                     ::= i   # int
    2896              :                     ::= j   # unsigned int
    2897              :                     ::= l   # long
    2898              :                     ::= m   # unsigned long
    2899              :                     ::= x   # long long, __int64
    2900              :                     ::= y   # unsigned long long, __int64
    2901              :                     ::= n   # __int128
    2902              :                     ::= o   # unsigned __int128
    2903              :                     ::= f   # float
    2904              :                     ::= d   # double
    2905              :                     ::= e   # long double, __float80
    2906              :                     ::= g   # __float128          [not supported]
    2907              :                     ::= u <source-name>  # vendor extended type */
    2908              : 
    2909              : static void
    2910    604159397 : write_builtin_type (tree type)
    2911              : {
    2912    604159397 :   if (TYPE_CANONICAL (type))
    2913    604159397 :     type = TYPE_CANONICAL (type);
    2914              : 
    2915    604159397 :   switch (TREE_CODE (type))
    2916              :     {
    2917     82542449 :     case VOID_TYPE:
    2918     82542449 :       write_char ('v');
    2919     82542449 :       break;
    2920              : 
    2921     49483970 :     case BOOLEAN_TYPE:
    2922     49483970 :       write_char ('b');
    2923     49483970 :       break;
    2924              : 
    2925    453609471 :     case INTEGER_TYPE:
    2926              :       /* TYPE may still be wchar_t, char8_t, char16_t, or char32_t, since that
    2927              :          isn't in integer_type_nodes.  */
    2928    453609471 :       if (type == wchar_type_node)
    2929     52868319 :         write_char ('w');
    2930    400741152 :       else if (type == char8_type_node)
    2931     21625061 :         write_string ("Du");
    2932    379116091 :       else if (type == char16_type_node)
    2933     21446042 :         write_string ("Ds");
    2934    357670049 :       else if (type == char32_type_node)
    2935     30291502 :         write_string ("Di");
    2936              :       else
    2937              :         {
    2938    327378560 :           size_t itk;
    2939              :           /* Assume TYPE is one of the shared integer type nodes.  Find
    2940              :              it in the array of these nodes.  */
    2941    327378547 :         iagain:
    2942   2020411947 :           for (itk = 0; itk < itk_none; ++itk)
    2943   2018431940 :             if (integer_types[itk] != NULL_TREE
    2944   2006551898 :                 && integer_type_codes[itk] != '\0'
    2945   2002591884 :                 && type == integer_types[itk])
    2946              :               {
    2947              :                 /* Print the corresponding single-letter code.  */
    2948    325398553 :                 write_char (integer_type_codes[itk]);
    2949    325398553 :                 break;
    2950              :               }
    2951              : 
    2952    327378560 :           if (itk == itk_none)
    2953              :             {
    2954      1980007 :               tree t = c_common_type_for_mode (TYPE_MODE (type),
    2955      1980007 :                                                TYPE_UNSIGNED (type));
    2956      1980007 :               if (type != t)
    2957              :                 {
    2958           13 :                   type = t;
    2959           13 :                   goto iagain;
    2960              :                 }
    2961              : 
    2962      1979994 :               if (TYPE_PRECISION (type) == 128)
    2963      2823349 :                 write_char (TYPE_UNSIGNED (type) ? 'o' : 'n');
    2964              :               else
    2965              :                 {
    2966              :                   /* Allow for cases where TYPE is not one of the shared
    2967              :                      integer type nodes and write a "vendor extended builtin
    2968              :                      type" with a name the form intN or uintN, respectively.
    2969              :                      Situations like this can happen if you have an
    2970              :                      __attribute__((__mode__(__SI__))) type and use exotic
    2971              :                      switches like '-mint8' on AVR.  Of course, this is
    2972              :                      undefined by the C++ ABI (and '-mint8' is not even
    2973              :                      Standard C conforming), but when using such special
    2974              :                      options you're pretty much in nowhere land anyway.  */
    2975            0 :                   const char *prefix;
    2976            0 :                   char prec[11];        /* up to ten digits for an unsigned */
    2977              : 
    2978            0 :                   prefix = TYPE_UNSIGNED (type) ? "uint" : "int";
    2979            0 :                   sprintf (prec, "%u", (unsigned) TYPE_PRECISION (type));
    2980            0 :                   write_char ('u');     /* "vendor extended builtin type" */
    2981            0 :                   write_unsigned_number (strlen (prefix) + strlen (prec));
    2982            0 :                   write_string (prefix);
    2983            0 :                   write_string (prec);
    2984              :                 }
    2985              :             }
    2986              :         }
    2987              :       break;
    2988              : 
    2989     18523507 :     case REAL_TYPE:
    2990     18523507 :       if (type == float_type_node)
    2991      6151931 :         write_char ('f');
    2992     12371576 :       else if (type == double_type_node)
    2993      9882948 :         write_char ('d');
    2994      2488628 :       else if (type == long_double_type_node)
    2995            0 :         write_char ('e');
    2996      2488628 :       else if (type == dfloat32_type_node)
    2997         6152 :         write_string ("Df");
    2998      2482476 :       else if (type == dfloat64_type_node)
    2999         6041 :         write_string ("Dd");
    3000      2476435 :       else if (type == dfloat128_type_node)
    3001         6008 :         write_string ("De");
    3002      2470427 :       else if (type == float16_type_node)
    3003            0 :         write_string ("DF16_");
    3004      2470427 :       else if (type == float32_type_node)
    3005       888992 :         write_string ("DF32_");
    3006      1581435 :       else if (type == float64_type_node)
    3007       888992 :         write_string ("DF64_");
    3008       692443 :       else if (type == float128_type_node)
    3009       635493 :         write_string ("DF128_");
    3010        56950 :       else if (type == float32x_type_node)
    3011        28475 :         write_string ("DF32x");
    3012        28475 :       else if (type == float64x_type_node)
    3013        28475 :         write_string ("DF64x");
    3014            0 :       else if (type == float128x_type_node)
    3015            0 :         write_string ("DF128x");
    3016            0 :       else if (type == bfloat16_type_node)
    3017            0 :         write_string ("DF16b");
    3018              :       else
    3019            0 :         gcc_unreachable ();
    3020              :       break;
    3021              : 
    3022            0 :     default:
    3023            0 :       gcc_unreachable ();
    3024              :     }
    3025    604159397 : }
    3026              : 
    3027              : /* Non-terminal <function-type>.  NODE is a FUNCTION_TYPE or
    3028              :    METHOD_TYPE.  The return type is mangled before the parameter
    3029              :    types.
    3030              : 
    3031              :      <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E   */
    3032              : 
    3033              : static void
    3034      3073415 : write_function_type (const tree type)
    3035              : {
    3036      3073415 :   MANGLE_TRACE_TREE ("function-type", type);
    3037              : 
    3038              :   /* For a pointer to member function, the function type may have
    3039              :      cv-qualifiers, indicating the quals for the artificial 'this'
    3040              :      parameter.  */
    3041      3073415 :   if (TREE_CODE (type) == METHOD_TYPE)
    3042              :     {
    3043              :       /* The first parameter must be a POINTER_TYPE pointing to the
    3044              :          `this' parameter.  */
    3045       256452 :       tree this_type = class_of_this_parm (type);
    3046       256452 :       write_CV_qualifiers_for_type (this_type);
    3047              :     }
    3048              : 
    3049      3073415 :   write_exception_spec (TYPE_RAISES_EXCEPTIONS (type));
    3050              : 
    3051      3073415 :   if (tx_safe_fn_type_p (type))
    3052           24 :     write_string ("Dx");
    3053              : 
    3054      3073415 :   write_char ('F');
    3055              :   /* We don't track whether or not a type is `extern "C"'.  Note that
    3056              :      you can have an `extern "C"' function that does not have
    3057              :      `extern "C"' type, and vice versa:
    3058              : 
    3059              :        extern "C" typedef void function_t();
    3060              :        function_t f; // f has C++ linkage, but its type is
    3061              :                      // `extern "C"'
    3062              : 
    3063              :        typedef void function_t();
    3064              :        extern "C" function_t f; // Vice versa.
    3065              : 
    3066              :      See [dcl.link].  */
    3067      3073415 :   write_bare_function_type (type, /*include_return_type_p=*/1,
    3068              :                             /*decl=*/NULL);
    3069      3073415 :   if (FUNCTION_REF_QUALIFIED (type))
    3070              :     {
    3071         1495 :       if (FUNCTION_RVALUE_QUALIFIED (type))
    3072          623 :         write_char ('O');
    3073              :       else
    3074          872 :         write_char ('R');
    3075              :     }
    3076      3073415 :   write_char ('E');
    3077      3073415 : }
    3078              : 
    3079              : /* Non-terminal <bare-function-type>.  TYPE is a FUNCTION_TYPE or
    3080              :    METHOD_TYPE.  If INCLUDE_RETURN_TYPE is nonzero, the return value
    3081              :    is mangled before the parameter types.  If non-NULL, DECL is
    3082              :    FUNCTION_DECL for the function whose type is being emitted.  */
    3083              : 
    3084              : static void
    3085    198746673 : write_bare_function_type (const tree type, const int include_return_type_p,
    3086              :                           const tree decl)
    3087              : {
    3088    198746673 :   MANGLE_TRACE_TREE ("bare-function-type", type);
    3089              : 
    3090              :   /* Mangle the return type, if requested.  */
    3091    198746673 :   if (include_return_type_p)
    3092     20961867 :     write_type (TREE_TYPE (type));
    3093              : 
    3094              :   /* Now mangle the types of the arguments.  */
    3095    198746673 :   ++G.parm_depth;
    3096    198746673 :   write_method_parms (TYPE_ARG_TYPES (type),
    3097    198746673 :                       TREE_CODE (type) == METHOD_TYPE,
    3098              :                       decl);
    3099    198746673 :   --G.parm_depth;
    3100    198746673 : }
    3101              : 
    3102              : /* Write the mangled representation of a method parameter list of
    3103              :    types given in PARM_TYPES.  If METHOD_P is nonzero, the function is
    3104              :    considered a non-static method, and the this parameter is omitted.
    3105              :    If non-NULL, DECL is the FUNCTION_DECL for the function whose
    3106              :    parameters are being emitted.  */
    3107              : 
    3108              : static void
    3109    202387417 : write_method_parms (tree parm_types, const int method_p, const tree decl)
    3110              : {
    3111    202387417 :   tree first_parm_type;
    3112    380898482 :   tree parm_decl = decl ? DECL_ARGUMENTS (decl) : NULL_TREE;
    3113              : 
    3114              :   /* Assume this parameter type list is variable-length.  If it ends
    3115              :      with a void type, then it's not.  */
    3116    202387417 :   int varargs_p = 1;
    3117              : 
    3118              :   /* If this is a member function, skip the first arg, which is the
    3119              :      this pointer.
    3120              :        "Member functions do not encode the type of their implicit this
    3121              :        parameter."
    3122              : 
    3123              :      Similarly, there's no need to mangle artificial parameters, like
    3124              :      the VTT parameters for constructors and destructors.  */
    3125    202387417 :   if (method_p)
    3126              :     {
    3127    160324680 :       parm_types = TREE_CHAIN (parm_types);
    3128    160324680 :       parm_decl = parm_decl ? DECL_CHAIN (parm_decl) : NULL_TREE;
    3129              : 
    3130    160364879 :       while (parm_decl && DECL_ARTIFICIAL (parm_decl))
    3131              :         {
    3132        40199 :           parm_types = TREE_CHAIN (parm_types);
    3133        40199 :           parm_decl = DECL_CHAIN (parm_decl);
    3134              :         }
    3135              : 
    3136    160324680 :       if (decl && ctor_omit_inherited_parms (decl))
    3137              :         /* Bring back parameters omitted from an inherited ctor.  */
    3138           54 :         parm_types = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (decl));
    3139              :     }
    3140              : 
    3141    202387417 :   for (first_parm_type = parm_types;
    3142    629427304 :        parm_types;
    3143    427039887 :        parm_types = TREE_CHAIN (parm_types))
    3144              :     {
    3145    427039887 :       tree parm = TREE_VALUE (parm_types);
    3146    427039887 :       if (parm == void_type_node)
    3147              :         {
    3148              :           /* "Empty parameter lists, whether declared as () or
    3149              :              conventionally as (void), are encoded with a void parameter
    3150              :              (v)."  */
    3151    202343926 :           if (parm_types == first_parm_type)
    3152     69643198 :             write_type (parm);
    3153              :           /* If the parm list is terminated with a void type, it's
    3154              :              fixed-length.  */
    3155    202343926 :           varargs_p = 0;
    3156              :           /* A void type better be the last one.  */
    3157    202343926 :           gcc_assert (TREE_CHAIN (parm_types) == NULL);
    3158              :         }
    3159              :       else
    3160    224695961 :         write_type (parm);
    3161              :     }
    3162              : 
    3163    202387417 :   if (varargs_p)
    3164              :     /* <builtin-type> ::= z  # ellipsis  */
    3165        43491 :     write_char ('z');
    3166    202387417 : }
    3167              : 
    3168              : /* <class-enum-type> ::= <name>  */
    3169              : 
    3170              : static void
    3171    337697865 : write_class_enum_type (const tree type)
    3172              : {
    3173    337697865 :   write_name (TYPE_NAME (type), /*ignore_local_scope=*/0);
    3174    337697865 : }
    3175              : 
    3176              : /* Mangle a requirement REQ in a requires-expression.  */
    3177              : 
    3178              : static void
    3179       767294 : write_requirement (tree req)
    3180              : {
    3181       767294 :   tree op = TREE_OPERAND (req, 0);
    3182              : 
    3183       767294 :   switch (tree_code code = TREE_CODE (req))
    3184              :     {
    3185              :       /* # simple-requirement or compound-requirement
    3186              :          <requirement> ::= X <expression> [ N ] [ R <type-constraint> ] */
    3187       766885 :     case SIMPLE_REQ:
    3188       766885 :     case COMPOUND_REQ:
    3189       766885 :       write_char ('X');
    3190       766885 :       write_expression (op);
    3191       766885 :       if (code == SIMPLE_REQ)
    3192              :         break;
    3193       177903 :       if (COMPOUND_REQ_NOEXCEPT_P (req))
    3194            3 :         write_char ('N');
    3195       177903 :       if (tree constr = TREE_OPERAND (req, 1))
    3196              :         {
    3197       177900 :           write_char ('R');
    3198       177900 :           write_type_constraint (PLACEHOLDER_TYPE_CONSTRAINTS (constr));
    3199              :         }
    3200              :       break;
    3201              : 
    3202              :       /* <requirement> ::= T <type> # type-requirement */
    3203          406 :     case TYPE_REQ:
    3204          406 :       write_char ('T');
    3205          406 :       write_type (op);
    3206          406 :       break;
    3207              : 
    3208              :       /* <requirement> ::= Q <constraint-expression> # nested-requirement */
    3209            3 :     case NESTED_REQ:
    3210            3 :       write_char ('Q');
    3211            3 :       write_constraint_expression (op);
    3212            3 :       break;
    3213              : 
    3214            0 :     default:
    3215            0 :       gcc_unreachable ();
    3216              :     }
    3217       767294 : }
    3218              : 
    3219              : /* # requires { ... }
    3220              :    <expression> ::= rq <requirement>+ E
    3221              :    # requires (...) { ... }
    3222              :    <expression> ::= rQ <bare-function-type> _ <requirement>+ E */
    3223              : 
    3224              : static void
    3225       726261 : write_requires_expr (tree expr)
    3226              : {
    3227       726261 :   tree parms = REQUIRES_EXPR_PARMS (expr);
    3228       726261 :   if (parms)
    3229              :     {
    3230        85140 :       write_string ("rQ");
    3231        85140 :       ++G.parm_depth;
    3232       170629 :       for (; parms; parms = DECL_CHAIN (parms))
    3233        85489 :         write_type (cv_unqualified (TREE_TYPE (parms)));
    3234        85140 :       --G.parm_depth;
    3235        85140 :       write_char ('_');
    3236              :     }
    3237              :   else
    3238       641121 :     write_string ("rq");
    3239              : 
    3240      1493555 :   for (tree reqs = REQUIRES_EXPR_REQS (expr); reqs;
    3241       767294 :        reqs = TREE_CHAIN (reqs))
    3242       767294 :     write_requirement (TREE_VALUE (reqs));
    3243              : 
    3244       726261 :   write_char ('E');
    3245       726261 : }
    3246              : 
    3247              : /* Non-terminal <template-args>.  ARGS is a TREE_VEC of template
    3248              :    arguments.
    3249              : 
    3250              :      <template-args> ::= I <template-arg>* [Q <constraint-expr>] E  */
    3251              : 
    3252              : static void
    3253    445274822 : write_template_args (tree args, tree parms /*= NULL_TREE*/)
    3254              : {
    3255    445274822 :   int i;
    3256    445274822 :   int length = 0;
    3257              : 
    3258    445274822 :   MANGLE_TRACE_TREE ("template-args", args);
    3259              : 
    3260    445274822 :   write_char ('I');
    3261              : 
    3262    445274822 :   if (args)
    3263    445274822 :     length = TREE_VEC_LENGTH (args);
    3264              : 
    3265    445274822 :   tree constraints = NULL_TREE;
    3266    445274822 :   if (parms)
    3267              :     {
    3268      5077229 :       constraints = TEMPLATE_PARMS_CONSTRAINTS (parms);
    3269      5077229 :       parms = INNERMOST_TEMPLATE_PARMS (parms);
    3270              :     }
    3271              : 
    3272    445274822 :   if (args && length && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
    3273              :     {
    3274              :       /* We have nested template args.  We want the innermost template
    3275              :          argument list.  */
    3276      8354971 :       args = TREE_VEC_ELT (args, length - 1);
    3277      8354971 :       length = TREE_VEC_LENGTH (args);
    3278              :     }
    3279    445274822 :   if (TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args))
    3280              :     /* Skip the constrained type.  */
    3281              :     i = 1;
    3282              :   else
    3283    445178898 :     i = 0;
    3284              :   bool implicit_parm_scope = false;
    3285   1235190838 :   for (; i < length; ++i)
    3286              :     {
    3287    789916016 :       tree arg = TREE_VEC_ELT (args, i);
    3288    789916016 :       if (parms)
    3289              :         {
    3290      8684966 :           tree parm = TREE_VEC_ELT (parms, i);
    3291      8684966 :           tree decl = TREE_VALUE (parm);
    3292      8684966 :           if (DECL_IMPLICIT_TEMPLATE_PARM_P (decl)
    3293      8684966 :               && !implicit_parm_scope)
    3294              :             {
    3295              :               /* The rest of the template parameters are based on generic
    3296              :                  function parameters, so any expressions in their
    3297              :                  type-constraints are in parameter scope.  */
    3298         4637 :               implicit_parm_scope = true;
    3299         4637 :               ++G.parm_depth;
    3300              :             }
    3301      8684966 :           if (!template_parm_natural_p (arg, parm)
    3302      8684966 :               && abi_check (19))
    3303        32523 :             write_template_param_decl (parm);
    3304              :         }
    3305    789916016 :       write_template_arg (arg);
    3306              :     }
    3307    445274822 :   if (implicit_parm_scope)
    3308         4637 :     --G.parm_depth;
    3309              : 
    3310    445274822 :   write_tparms_constraints (constraints);
    3311              : 
    3312    445274822 :   write_char ('E');
    3313    445274822 : }
    3314              : 
    3315              : /* Write out the
    3316              :    <unqualified-name>
    3317              :    <unqualified-name> <template-args>
    3318              :    part of SCOPE_REF or COMPONENT_REF mangling.  */
    3319              : 
    3320              : static void
    3321       816203 : write_member_name (tree member)
    3322              : {
    3323       816203 :   if (identifier_p (member))
    3324              :     {
    3325       409705 :       if (IDENTIFIER_ANY_OP_P (member))
    3326              :         {
    3327        46757 :           if (abi_check (11))
    3328        46733 :             write_string ("on");
    3329              :         }
    3330       409705 :       write_unqualified_id (member);
    3331              :     }
    3332       406498 :   else if (DECL_P (member))
    3333              :     {
    3334         1196 :       if (ANON_AGGR_TYPE_P (TREE_TYPE (member)))
    3335              :         ;
    3336         1190 :       else if (DECL_OVERLOADED_OPERATOR_P (member))
    3337              :         {
    3338           15 :           if (abi_check (16))
    3339            9 :             write_string ("on");
    3340              :         }
    3341         1196 :       write_unqualified_name (member);
    3342              :     }
    3343       405302 :   else if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
    3344              :     {
    3345          271 :       tree name = TREE_OPERAND (member, 0);
    3346          271 :       name = OVL_FIRST (name);
    3347          271 :       write_member_name (name);
    3348          271 :       write_template_args (TREE_OPERAND (member, 1));
    3349              :     }
    3350              :   else
    3351       405031 :     write_expression (member);
    3352       816203 : }
    3353              : 
    3354              : /* EXPR is a base COMPONENT_REF; write the minimized base conversion path for
    3355              :    converting to BASE, or just the conversion of EXPR if BASE is null.
    3356              : 
    3357              :    "Given a fully explicit base path P := C_n -> ... -> C_0, the minimized base
    3358              :    path Min(P) is defined as follows: let C_i be the last element for which the
    3359              :    conversion to C_0 is unambiguous; if that element is C_n, the minimized path
    3360              :    is C_n -> C_0; otherwise, the minimized path is Min(C_n -> ... -> C_i) ->
    3361              :    C_0."
    3362              : 
    3363              :    We mangle the conversion to C_i if it's different from C_n.  */
    3364              : 
    3365              : static bool
    3366       475037 : write_base_ref (tree expr, tree base = NULL_TREE)
    3367              : {
    3368       475037 :   if (TREE_CODE (expr) != COMPONENT_REF)
    3369              :     return false;
    3370              : 
    3371       475031 :   tree field = TREE_OPERAND (expr, 1);
    3372              : 
    3373       475031 :   if (TREE_CODE (field) != FIELD_DECL || !DECL_FIELD_IS_BASE (field))
    3374              :     return false;
    3375              : 
    3376           18 :   tree object = TREE_OPERAND (expr, 0);
    3377              : 
    3378           18 :   tree binfo = NULL_TREE;
    3379           18 :   if (base)
    3380              :     {
    3381            9 :       tree cur = TREE_TYPE (object);
    3382            9 :       binfo = lookup_base (cur, base, ba_unique, NULL, tf_none);
    3383              :     }
    3384              :   else
    3385              :     /* We're at the end of the base conversion chain, so it can't be
    3386              :        ambiguous.  */
    3387            9 :     base = TREE_TYPE (field);
    3388              : 
    3389           18 :   if (binfo == error_mark_node)
    3390              :     {
    3391              :       /* cur->base is ambiguous, so make the conversion to
    3392              :          last explicit, expressed as a cast (last&)object.  */
    3393            3 :       tree last = TREE_TYPE (expr);
    3394            3 :       write_string (OVL_OP_INFO (false, CAST_EXPR)->mangled_name);
    3395            3 :       write_type (build_reference_type (last));
    3396            3 :       write_expression (object);
    3397              :     }
    3398           15 :   else if (write_base_ref (object, base))
    3399              :     /* cur->base is unambiguous, but we had another base conversion
    3400              :        underneath and wrote it out.  */;
    3401              :   else
    3402              :     /* No more base conversions, just write out the object.  */
    3403            6 :     write_expression (object);
    3404              : 
    3405              :   return true;
    3406              : }
    3407              : 
    3408              : /* The number of elements spanned by a RANGE_EXPR.  */
    3409              : 
    3410              : unsigned HOST_WIDE_INT
    3411           15 : range_expr_nelts (tree expr)
    3412              : {
    3413           15 :   tree lo = TREE_OPERAND (expr, 0);
    3414           15 :   tree hi = TREE_OPERAND (expr, 1);
    3415           15 :   return tree_to_uhwi (hi) - tree_to_uhwi (lo) + 1;
    3416              : }
    3417              : 
    3418              : /* <expression> ::= <unary operator-name> <expression>
    3419              :                 ::= <binary operator-name> <expression> <expression>
    3420              :                 ::= <expr-primary>
    3421              : 
    3422              :    <expr-primary> ::= <template-param>
    3423              :                   ::= L <type> <value number> E             # literal
    3424              :                   ::= L <mangled-name> E          # external name
    3425              :                   ::= st <type>                           # sizeof
    3426              :                   ::= sr <type> <unqualified-name>  # dependent name
    3427              :                   ::= sr <type> <unqualified-name> <template-args> */
    3428              : 
    3429              : static void
    3430     21339565 : write_expression (tree expr)
    3431              : {
    3432     21897630 :   enum tree_code code = TREE_CODE (expr);
    3433              : 
    3434     21897630 :   if (TREE_CODE (expr) == TARGET_EXPR)
    3435              :     {
    3436            0 :       expr = TARGET_EXPR_INITIAL (expr);
    3437            0 :       code = TREE_CODE (expr);
    3438              :     }
    3439              : 
    3440              :   /* Skip NOP_EXPR and CONVERT_EXPR.  They can occur when (say) a pointer
    3441              :      argument is converted (via qualification conversions) to another type.  */
    3442     22898570 :   while (CONVERT_EXPR_CODE_P (code)
    3443     22538628 :          || code == IMPLICIT_CONV_EXPR
    3444     22538499 :          || location_wrapper_p (expr)
    3445              :          /* Parentheses aren't mangled.  */
    3446     21897996 :          || code == PAREN_EXPR
    3447     21897996 :          || code == NON_LVALUE_EXPR
    3448     44796566 :          || (code == VIEW_CONVERT_EXPR
    3449          366 :              && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX))
    3450              :     {
    3451      1000940 :       expr = TREE_OPERAND (expr, 0);
    3452      1000940 :       code = TREE_CODE (expr);
    3453              :     }
    3454              : 
    3455     21897630 :   if (code == BASELINK
    3456     21897630 :       && (!type_unknown_p (expr)
    3457       978592 :           || !BASELINK_QUALIFIED_P (expr)))
    3458              :     {
    3459      1025754 :       expr = BASELINK_FUNCTIONS (expr);
    3460      1025754 :       code = TREE_CODE (expr);
    3461              :     }
    3462              : 
    3463              :   /* Handle pointers-to-members by making them look like expression
    3464              :      nodes.  */
    3465     21897630 :   if (code == PTRMEM_CST)
    3466              :     {
    3467         7026 :       expr = build_nt (ADDR_EXPR,
    3468              :                        build_qualified_name (/*type=*/NULL_TREE,
    3469         3513 :                                              PTRMEM_CST_CLASS (expr),
    3470         3513 :                                              PTRMEM_CST_MEMBER (expr),
    3471              :                                              /*template_p=*/false));
    3472         3513 :       code = TREE_CODE (expr);
    3473              :     }
    3474              : 
    3475              :   /* Handle template parameters.  */
    3476     21897630 :   if (code == TEMPLATE_TYPE_PARM
    3477     21897630 :       || code == TEMPLATE_TEMPLATE_PARM
    3478     21897630 :       || code == BOUND_TEMPLATE_TEMPLATE_PARM
    3479     21895076 :       || code == TEMPLATE_PARM_INDEX)
    3480       962586 :     write_template_param (expr);
    3481              :   /* Handle literals.  */
    3482     20935044 :   else if (TREE_CODE_CLASS (code) == tcc_constant
    3483     20596490 :            || code == CONST_DECL
    3484     20596490 :            || code == REFLECT_EXPR)
    3485       376662 :     write_template_arg_literal (expr);
    3486     20558382 :   else if (code == EXCESS_PRECISION_EXPR
    3487     20558382 :            && TREE_CODE (TREE_OPERAND (expr, 0)) == REAL_CST)
    3488            0 :     write_template_arg_literal (fold_convert (TREE_TYPE (expr),
    3489              :                                               TREE_OPERAND (expr, 0)));
    3490     20558382 :   else if (code == PARM_DECL && DECL_ARTIFICIAL (expr))
    3491              :     {
    3492       359087 :       gcc_assert (id_equal (DECL_NAME (expr), "this"));
    3493       359087 :       write_string ("fpT");
    3494              :     }
    3495     20199295 :   else if (code == PARM_DECL)
    3496              :     {
    3497              :       /* A function parameter used in a late-specified return type.  */
    3498       523371 :       int index = DECL_PARM_INDEX (expr);
    3499       523371 :       int level = DECL_PARM_LEVEL (expr);
    3500       523371 :       int delta = G.parm_depth - level + 1;
    3501       523371 :       gcc_assert (index >= 1);
    3502       523371 :       write_char ('f');
    3503       523371 :       if (delta != 0)
    3504              :         {
    3505       283621 :           gcc_checking_assert (delta > 0);
    3506       283621 :           if (abi_check (5))
    3507              :             {
    3508              :               /* Let L be the number of function prototype scopes from the
    3509              :                  innermost one (in which the parameter reference occurs) up
    3510              :                  to (and including) the one containing the declaration of
    3511              :                  the referenced parameter.  If the parameter declaration
    3512              :                  clause of the innermost function prototype scope has been
    3513              :                  completely seen, it is not counted (in that case -- which
    3514              :                  is perhaps the most common -- L can be zero).  */
    3515       283618 :               write_char ('L');
    3516       283618 :               write_unsigned_number (delta - 1);
    3517              :             }
    3518              :         }
    3519       523371 :       write_char ('p');
    3520       523371 :       write_compact_number (index - 1);
    3521              :     }
    3522     19675924 :   else if (DECL_P (expr))
    3523              :     {
    3524      1000112 :       write_char ('L');
    3525      1000112 :       write_mangled_name (expr, false);
    3526      1000112 :       write_char ('E');
    3527              :     }
    3528     18675812 :   else if (TREE_CODE (expr) == SIZEOF_EXPR)
    3529              :     {
    3530         4251 :       tree op = TREE_OPERAND (expr, 0);
    3531              : 
    3532         4251 :       if (PACK_EXPANSION_P (op))
    3533              :         {
    3534         3039 :     sizeof_pack:
    3535         3042 :           if (abi_check (11))
    3536              :             {
    3537              :               /* sZ rather than szDp.  */
    3538         3033 :               write_string ("sZ");
    3539         3033 :               write_expression (PACK_EXPANSION_PATTERN (op));
    3540         3033 :               return;
    3541              :             }
    3542              :         }
    3543              : 
    3544         1221 :       if (SIZEOF_EXPR_TYPE_P (expr))
    3545              :         {
    3546            0 :           write_string ("st");
    3547            0 :           write_type (TREE_TYPE (op));
    3548              :         }
    3549         1221 :       else if (ARGUMENT_PACK_P (op))
    3550              :         {
    3551           15 :           tree args = ARGUMENT_PACK_ARGS (op);
    3552           15 :           int length = TREE_VEC_LENGTH (args);
    3553           15 :           if (abi_check (10))
    3554              :             {
    3555              :               /* Before v19 we wrongly mangled all single pack expansions with
    3556              :                  sZ, but now only for expressions, as types ICEd (95298).  */
    3557           12 :               if (length == 1)
    3558              :                 {
    3559            9 :                   tree arg = TREE_VEC_ELT (args, 0);
    3560            9 :                   if (TREE_CODE (arg) == EXPR_PACK_EXPANSION
    3561            9 :                       && !abi_check (19))
    3562              :                     {
    3563            3 :                       op = arg;
    3564            3 :                       goto sizeof_pack;
    3565              :                     }
    3566              :                 }
    3567              : 
    3568              :               /* sP <template-arg>* E # sizeof...(T), size of a captured
    3569              :                  template parameter pack from an alias template */
    3570            9 :               write_string ("sP");
    3571           24 :               for (int i = 0; i < length; ++i)
    3572           15 :                 write_template_arg (TREE_VEC_ELT (args, i));
    3573            9 :               write_char ('E');
    3574              :             }
    3575              :           else
    3576              :             {
    3577              :               /* In GCC 5 we represented this sizeof wrong, with the effect
    3578              :                  that we mangled it as the last element of the pack.  */
    3579            3 :               tree arg = TREE_VEC_ELT (args, length-1);
    3580            3 :               if (TYPE_P (op))
    3581              :                 {
    3582            3 :                   write_string ("st");
    3583            3 :                   write_type (arg);
    3584              :                 }
    3585              :               else
    3586              :                 {
    3587            0 :                   write_string ("sz");
    3588            0 :                   write_expression (arg);
    3589              :                 }
    3590              :             }
    3591              :         }
    3592         1206 :       else if (TYPE_P (TREE_OPERAND (expr, 0)))
    3593              :         {
    3594         1092 :           write_string ("st");
    3595         1092 :           write_type (TREE_OPERAND (expr, 0));
    3596              :         }
    3597              :       else
    3598          114 :         goto normal_expr;
    3599              :     }
    3600     18671561 :   else if (TREE_CODE (expr) == ALIGNOF_EXPR)
    3601              :     {
    3602           36 :       if (!ALIGNOF_EXPR_STD_P (expr))
    3603              :         {
    3604           24 :           if (abi_check (16))
    3605              :             {
    3606              :               /* We used to mangle __alignof__ like alignof.  */
    3607           18 :               write_string ("u11__alignof__");
    3608           18 :               write_template_arg (TREE_OPERAND (expr, 0));
    3609           18 :               write_char ('E');
    3610           18 :               return;
    3611              :             }
    3612              :         }
    3613           18 :       if (TYPE_P (TREE_OPERAND (expr, 0)))
    3614              :         {
    3615            9 :           write_string ("at");
    3616            9 :           write_type (TREE_OPERAND (expr, 0));
    3617              :         }
    3618              :       else
    3619            9 :         goto normal_expr;
    3620              :     }
    3621     18671525 :   else if (code == SCOPE_REF
    3622     18671525 :            || code == BASELINK)
    3623              :     {
    3624       344431 :       tree scope, member;
    3625       344431 :       if (code == SCOPE_REF)
    3626              :         {
    3627       344398 :           scope = TREE_OPERAND (expr, 0);
    3628       344398 :           member = TREE_OPERAND (expr, 1);
    3629       344398 :           if (BASELINK_P (member))
    3630           21 :             member = BASELINK_FUNCTIONS (member);
    3631              :         }
    3632              :       else
    3633              :         {
    3634           33 :           scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (expr));
    3635           33 :           member = BASELINK_FUNCTIONS (expr);
    3636              :         }
    3637              : 
    3638              :       /* If the MEMBER is a real declaration, then the qualifying
    3639              :          scope was not dependent.  Ideally, we would not have a
    3640              :          SCOPE_REF in those cases, but sometimes we do.  If the second
    3641              :          argument is a DECL, then the name must not have been
    3642              :          dependent.  */
    3643       344431 :       if (DECL_P (member))
    3644              :         write_expression (member);
    3645              :       else
    3646              :         {
    3647       340672 :           gcc_assert (code != BASELINK || BASELINK_QUALIFIED_P (expr));
    3648       340639 :           write_string ("sr");
    3649       340639 :           write_type (scope);
    3650       340639 :           write_member_name (member);
    3651              :         }
    3652              :     }
    3653     18327094 :   else if (INDIRECT_REF_P (expr)
    3654       764828 :            && TREE_TYPE (TREE_OPERAND (expr, 0))
    3655     19090229 :            && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
    3656              :     {
    3657       403044 :       write_expression (TREE_OPERAND (expr, 0));
    3658              :     }
    3659     17924050 :   else if (identifier_p (expr))
    3660              :     {
    3661              :       /* An operator name appearing as a dependent name needs to be
    3662              :          specially marked to disambiguate between a use of the operator
    3663              :          name and a use of the operator in an expression.  */
    3664       743409 :       if (IDENTIFIER_ANY_OP_P (expr))
    3665           26 :         write_string ("on");
    3666       743409 :       write_unqualified_id (expr);
    3667              :     }
    3668     17180641 :   else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
    3669              :     {
    3670      7479504 :       tree fn = TREE_OPERAND (expr, 0);
    3671      9467253 :       if (!identifier_p (fn))
    3672      7479501 :         fn = OVL_NAME (fn);
    3673      7479504 :       if (IDENTIFIER_ANY_OP_P (fn))
    3674            3 :         write_string ("on");
    3675      7479504 :       write_unqualified_id (fn);
    3676      7479504 :       write_template_args (TREE_OPERAND (expr, 1));
    3677              :     }
    3678      9701137 :   else if (TREE_CODE (expr) == MODOP_EXPR)
    3679              :     {
    3680           45 :       enum tree_code subop = TREE_CODE (TREE_OPERAND (expr, 1));
    3681           45 :       const char *name = OVL_OP_INFO (true, subop)->mangled_name;
    3682              : 
    3683           45 :       write_string (name);
    3684           45 :       write_expression (TREE_OPERAND (expr, 0));
    3685           45 :       write_expression (TREE_OPERAND (expr, 2));
    3686              :     }
    3687      9701092 :   else if (code == NEW_EXPR || code == VEC_NEW_EXPR)
    3688              :     {
    3689              :       /* ::= [gs] nw <expression>* _ <type> E
    3690              :          ::= [gs] nw <expression>* _ <type> <initializer>
    3691              :          ::= [gs] na <expression>* _ <type> E
    3692              :          ::= [gs] na <expression>* _ <type> <initializer>
    3693              :          <initializer> ::= pi <expression>* E  */
    3694       146077 :       tree placement = TREE_OPERAND (expr, 0);
    3695       146077 :       tree type = TREE_OPERAND (expr, 1);
    3696       146077 :       tree nelts = TREE_OPERAND (expr, 2);
    3697       146077 :       tree init = TREE_OPERAND (expr, 3);
    3698       146077 :       tree t;
    3699              : 
    3700       146077 :       gcc_assert (code == NEW_EXPR);
    3701       146077 :       if (TREE_OPERAND (expr, 2))
    3702           12 :         code = VEC_NEW_EXPR;
    3703              : 
    3704       146077 :       if (NEW_EXPR_USE_GLOBAL (expr))
    3705       146052 :         write_string ("gs");
    3706              : 
    3707       146077 :       write_string (OVL_OP_INFO (false, code)->mangled_name);
    3708              : 
    3709       292129 :       for (t = placement; t; t = TREE_CHAIN (t))
    3710       146052 :         write_expression (TREE_VALUE (t));
    3711              : 
    3712       146077 :       write_char ('_');
    3713              : 
    3714       146077 :       if (nelts)
    3715              :         {
    3716           12 :           ++processing_template_decl;
    3717              :           /* Avoid compute_array_index_type complaints about
    3718              :              non-constant nelts.  */
    3719           12 :           tree max = cp_build_binary_op (input_location, MINUS_EXPR,
    3720              :                                          fold_convert (sizetype, nelts),
    3721              :                                          size_one_node,
    3722              :                                          tf_warning_or_error);
    3723           12 :           max = maybe_constant_value (max);
    3724           12 :           tree domain = build_index_type (max);
    3725           12 :           type = build_cplus_array_type (type, domain);
    3726           12 :           --processing_template_decl;
    3727              :         }
    3728       146077 :       write_type (type);
    3729              : 
    3730       146065 :       if (init && TREE_CODE (init) == TREE_LIST
    3731       292136 :           && DIRECT_LIST_INIT_P (TREE_VALUE (init)))
    3732              :         write_expression (TREE_VALUE (init));
    3733              :       else
    3734              :         {
    3735       146074 :           if (init)
    3736       146062 :             write_string ("pi");
    3737       146062 :           if (init && init != void_node)
    3738       292112 :             for (t = init; t; t = TREE_CHAIN (t))
    3739       146056 :               write_expression (TREE_VALUE (t));
    3740       146074 :           write_char ('E');
    3741              :         }
    3742              :     }
    3743              :   else if (code == DELETE_EXPR || code == VEC_DELETE_EXPR)
    3744              :     {
    3745           12 :       gcc_assert (code == DELETE_EXPR);
    3746           12 :       if (DELETE_EXPR_USE_VEC (expr))
    3747            6 :         code = VEC_DELETE_EXPR;
    3748              : 
    3749           12 :       if (DELETE_EXPR_USE_GLOBAL (expr))
    3750            6 :         write_string ("gs");
    3751              : 
    3752           12 :       write_string (OVL_OP_INFO (false, code)->mangled_name);
    3753              : 
    3754           12 :       write_expression (TREE_OPERAND (expr, 0));
    3755              :     }
    3756              :   else if (code == THROW_EXPR)
    3757              :     {
    3758            8 :       tree op = TREE_OPERAND (expr, 0);
    3759            8 :       if (op)
    3760              :         {
    3761            5 :           write_string ("tw");
    3762            5 :           write_expression (op);
    3763              :         }
    3764              :       else
    3765            3 :         write_string ("tr");
    3766              :     }
    3767              :   else if (code == NOEXCEPT_EXPR)
    3768              :     {
    3769            6 :       write_string ("nx");
    3770            6 :       write_expression (TREE_OPERAND (expr, 0));
    3771              :     }
    3772              :   else if (code == CONSTRUCTOR)
    3773              :     {
    3774        81203 :       bool braced_init = BRACE_ENCLOSED_INITIALIZER_P (expr);
    3775        81203 :       tree etype = TREE_TYPE (expr);
    3776              : 
    3777        81203 :       if (braced_init)
    3778           87 :         write_string ("il");
    3779              :       else
    3780              :         {
    3781        81116 :           write_string ("tl");
    3782        81116 :           write_type (etype);
    3783              :         }
    3784              : 
    3785              :       /* If this is an undigested initializer, mangle it as written.
    3786              :          COMPOUND_LITERAL_P doesn't actually distinguish between digested and
    3787              :          undigested braced casts, but it should work to use it to distinguish
    3788              :          between braced casts in a template signature (undigested) and template
    3789              :          parm object values (digested), and all CONSTRUCTORS that get here
    3790              :          should be one of those two cases.  */
    3791        81203 :       bool undigested = braced_init || COMPOUND_LITERAL_P (expr);
    3792        80859 :       if (undigested || !zero_init_expr_p (expr))
    3793              :         {
    3794              :           /* Convert braced initializer lists to STRING_CSTs so that
    3795              :              A<"Foo"> mangles the same as A<{'F', 'o', 'o', 0}> while
    3796              :              still using the latter mangling for strings that
    3797              :              originated as braced initializer lists.  */
    3798        69125 :           expr = braced_lists_to_strings (etype, expr);
    3799              : 
    3800        69125 :           if (TREE_CODE (expr) == CONSTRUCTOR)
    3801              :             {
    3802        69121 :               vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (expr);
    3803        69121 :               unsigned last_nonzero = UINT_MAX;
    3804        69121 :               constructor_elt *ce;
    3805              : 
    3806        69121 :               if (!undigested)
    3807       177415 :                 for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
    3808       108638 :                   if ((TREE_CODE (etype) == UNION_TYPE
    3809           33 :                        && ce->index != first_field (etype))
    3810       108662 :                       || !zero_init_expr_p (ce->value))
    3811              :                     last_nonzero = i;
    3812              : 
    3813        69121 :               tree prev_field = NULL_TREE;
    3814        69121 :               if (undigested || last_nonzero != UINT_MAX)
    3815       175717 :                 for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
    3816              :                   {
    3817       108605 :                     if (i > last_nonzero)
    3818              :                       break;
    3819       106443 :                     if (!undigested && !CONSTRUCTOR_NO_CLEARING (expr)
    3820       106596 :                         && (TREE_CODE (etype) == RECORD_TYPE
    3821       106443 :                             || TREE_CODE (etype) == ARRAY_TYPE))
    3822              :                       {
    3823              :                         /* Write out any implicit non-trailing zeros
    3824              :                            (which we neglected to do before v21).  */
    3825       106410 :                         if (TREE_CODE (etype) == RECORD_TYPE)
    3826              :                           {
    3827        43972 :                             tree field;
    3828        43972 :                             if (i == 0)
    3829        43049 :                               field = first_field (etype);
    3830              :                             else
    3831          923 :                               field = DECL_CHAIN (prev_field);
    3832        44216 :                             for (;;)
    3833              :                               {
    3834        44094 :                                 field = next_subobject_field (field);
    3835        44094 :                                 if (field == ce->index)
    3836              :                                   break;
    3837          122 :                                 if (abi_check (21))
    3838          117 :                                   write_expression (build_zero_cst
    3839          117 :                                                     (TREE_TYPE (field)));
    3840          122 :                                 field = DECL_CHAIN (field);
    3841              :                               }
    3842              :                           }
    3843        62438 :                         else if (TREE_CODE (etype) == ARRAY_TYPE)
    3844              :                           {
    3845        62438 :                             unsigned HOST_WIDE_INT j;
    3846        62438 :                             if (i == 0)
    3847              :                               j = 0;
    3848              :                             else
    3849        36743 :                               j = 1 + tree_to_uhwi (prev_field);
    3850        62438 :                             unsigned HOST_WIDE_INT k;
    3851        62438 :                             if (TREE_CODE (ce->index) == RANGE_EXPR)
    3852           12 :                               k = tree_to_uhwi (TREE_OPERAND (ce->index, 0));
    3853              :                             else
    3854        62426 :                               k = tree_to_uhwi (ce->index);
    3855        62438 :                             tree zero = NULL_TREE;
    3856        64208 :                             for (; j < k; ++j)
    3857         1770 :                               if (abi_check (21))
    3858              :                                 {
    3859         1188 :                                   if (!zero)
    3860           30 :                                     zero = build_zero_cst (TREE_TYPE (etype));
    3861         1188 :                                   write_expression (zero);
    3862              :                                 }
    3863              :                           }
    3864              :                       }
    3865              : 
    3866       106596 :                     if (!undigested && TREE_CODE (etype) == UNION_TYPE)
    3867              :                       {
    3868              :                         /* Express the active member as a designator.  */
    3869           33 :                         write_string ("di");
    3870           33 :                         write_unqualified_name (ce->index);
    3871              :                       }
    3872       106596 :                     unsigned reps = 1;
    3873       106596 :                     if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
    3874           12 :                       reps = range_expr_nelts (ce->index);
    3875       106596 :                     if (TREE_CODE (ce->value) == RAW_DATA_CST)
    3876              :                       {
    3877           30 :                         gcc_assert (reps == 1);
    3878           30 :                         unsigned int len = RAW_DATA_LENGTH (ce->value);
    3879              :                         /* If this is the last non-zero element, skip
    3880              :                            zeros at the end.  */
    3881           30 :                         if (i == last_nonzero)
    3882          282 :                           while (len)
    3883              :                             {
    3884          282 :                               if (RAW_DATA_POINTER (ce->value)[len - 1])
    3885              :                                 break;
    3886              :                               --len;
    3887              :                             }
    3888           30 :                         tree valtype = TREE_TYPE (ce->value);
    3889         3906 :                         for (unsigned int i = 0; i < len; ++i)
    3890              :                           {
    3891         3876 :                             write_char ('L');
    3892         3876 :                             write_type (valtype);
    3893         3876 :                             unsigned HOST_WIDE_INT v;
    3894         3876 :                             if (!TYPE_UNSIGNED (valtype)
    3895          780 :                                 && TYPE_PRECISION (valtype) == BITS_PER_UNIT
    3896         4656 :                                 && RAW_DATA_SCHAR_ELT (ce->value, i) < 0)
    3897              :                               {
    3898            0 :                                 write_char ('n');
    3899            0 :                                 v = -RAW_DATA_SCHAR_ELT (ce->value, i);
    3900              :                               }
    3901              :                             else
    3902         3876 :                               v = RAW_DATA_UCHAR_ELT (ce->value, i);
    3903         3876 :                             write_unsigned_number (v);
    3904         3876 :                             write_char ('E');
    3905              :                           }
    3906              :                       }
    3907              :                     else
    3908       213150 :                       for (unsigned j = 0; j < reps; ++j)
    3909       106584 :                         write_expression (ce->value);
    3910       106596 :                     prev_field = ce->index;
    3911       106596 :                     if (prev_field && TREE_CODE (prev_field) == RANGE_EXPR)
    3912           12 :                       prev_field = TREE_OPERAND (prev_field, 1);
    3913              :                   }
    3914              :             }
    3915              :           else
    3916              :             {
    3917            4 :               gcc_assert (TREE_CODE (expr) == STRING_CST);
    3918            4 :               write_expression (expr);
    3919              :             }
    3920              :         }
    3921        81203 :       write_char ('E');
    3922              :     }
    3923              :   else if (code == LAMBDA_EXPR)
    3924              :     {
    3925              :       /* [temp.over.link] Two lambda-expressions are never considered
    3926              :          equivalent.
    3927              : 
    3928              :          So just use the closure type mangling.  */
    3929           56 :       write_char ('L');
    3930           56 :       write_type (LAMBDA_EXPR_CLOSURE (expr));
    3931           56 :       write_char ('E');
    3932              :     }
    3933              :   else if (code == REQUIRES_EXPR)
    3934       726261 :     write_requires_expr (expr);
    3935      8747469 :   else if (dependent_name (expr))
    3936              :     {
    3937       358059 :       tree name = dependent_name (expr);
    3938       358059 :       if (IDENTIFIER_ANY_OP_P (name))
    3939              :         {
    3940            9 :           if (abi_check (16))
    3941            6 :             write_string ("on");
    3942              :         }
    3943       358059 :       write_unqualified_id (name);
    3944              :     }
    3945              :   else
    3946              :     {
    3947      8389410 :     normal_expr:
    3948      8389533 :       int i, len;
    3949      8389533 :       const char *name;
    3950              : 
    3951              :       /* When we bind a variable or function to a non-type template
    3952              :          argument with reference type, we create an ADDR_EXPR to show
    3953              :          the fact that the entity's address has been taken.  But, we
    3954              :          don't actually want to output a mangling code for the `&'.  */
    3955      8389533 :       if (TREE_CODE (expr) == ADDR_EXPR
    3956         4535 :           && TREE_TYPE (expr)
    3957      8390555 :           && TYPE_REF_P (TREE_TYPE (expr)))
    3958              :         {
    3959            0 :           expr = TREE_OPERAND (expr, 0);
    3960            0 :           if (DECL_P (expr))
    3961              :             {
    3962              :               write_expression (expr);
    3963              :               return;
    3964              :             }
    3965              : 
    3966            0 :           code = TREE_CODE (expr);
    3967              :         }
    3968              : 
    3969      8389533 :       if (code == COMPONENT_REF)
    3970              :         {
    3971       475302 :           tree ob = TREE_OPERAND (expr, 0);
    3972              : 
    3973       475302 :           if (TREE_CODE (ob) == ARROW_EXPR)
    3974              :             {
    3975          280 :               write_string (OVL_OP_INFO (false, code)->mangled_name);
    3976          280 :               ob = TREE_OPERAND (ob, 0);
    3977          280 :               write_expression (ob);
    3978              :             }
    3979       475022 :           else if (write_base_ref (expr))
    3980              :             return;
    3981       475013 :           else if (!is_dummy_object (ob))
    3982              :             {
    3983       475007 :               write_string ("dt");
    3984       475007 :               write_expression (ob);
    3985              :             }
    3986              :           /* else, for a non-static data member with no associated object (in
    3987              :              unevaluated context), use the unresolved-name mangling.  */
    3988              : 
    3989       475293 :           write_member_name (TREE_OPERAND (expr, 1));
    3990       475293 :           return;
    3991              :         }
    3992              : 
    3993              :       /* If it wasn't any of those, recursively expand the expression.  */
    3994      7914231 :       name = OVL_OP_INFO (false, code)->mangled_name;
    3995              : 
    3996              :       /* We used to mangle const_cast and static_cast like a C cast.  */
    3997      7914231 :       if (code == CONST_CAST_EXPR
    3998      7914231 :           || code == STATIC_CAST_EXPR)
    3999              :         {
    4000          263 :           if (!abi_check (6))
    4001           15 :             name = OVL_OP_INFO (false, CAST_EXPR)->mangled_name;
    4002              :         }
    4003              : 
    4004      7914231 :       if (name == NULL)
    4005              :         {
    4006            5 :           switch (code)
    4007              :             {
    4008            3 :             case TRAIT_EXPR:
    4009            3 :               error ("use of built-in trait %qE in function signature; "
    4010              :                      "use library traits instead", expr);
    4011            3 :               break;
    4012              : 
    4013            2 :             default:
    4014            2 :               sorry ("mangling %C", code);
    4015            2 :               break;
    4016              :             }
    4017            5 :           return;
    4018              :         }
    4019              :       else
    4020      7914226 :         write_string (name);
    4021              : 
    4022      7914226 :       switch (code)
    4023              :         {
    4024      3998434 :         case CALL_EXPR:
    4025      3998434 :           {
    4026      3998434 :             tree fn = CALL_EXPR_FN (expr);
    4027              : 
    4028      3998434 :             if (TREE_CODE (fn) == ADDR_EXPR)
    4029            0 :               fn = TREE_OPERAND (fn, 0);
    4030              : 
    4031              :             /* Mangle a dependent name as the name, not whatever happens to
    4032              :                be the first function in the overload set.  */
    4033      3997789 :             if (OVL_P (fn)
    4034      4741725 :                 && type_dependent_expression_p_push (expr))
    4035       743386 :               fn = OVL_NAME (fn);
    4036              : 
    4037      3998434 :             write_expression (fn);
    4038              :           }
    4039              : 
    4040      9648046 :           for (i = 0; i < call_expr_nargs (expr); ++i)
    4041      1651178 :             write_expression (CALL_EXPR_ARG (expr, i));
    4042      3998434 :           write_char ('E');
    4043      3998434 :           break;
    4044              : 
    4045       148005 :         case CAST_EXPR:
    4046       148005 :           write_type (TREE_TYPE (expr));
    4047       148005 :           if (list_length (TREE_OPERAND (expr, 0)) == 1)
    4048       147856 :             write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));
    4049              :           else
    4050              :             {
    4051          149 :               tree args = TREE_OPERAND (expr, 0);
    4052          149 :               write_char ('_');
    4053          161 :               for (; args; args = TREE_CHAIN (args))
    4054           12 :                 write_expression (TREE_VALUE (args));
    4055          149 :               write_char ('E');
    4056              :             }
    4057              :           break;
    4058              : 
    4059          269 :         case DYNAMIC_CAST_EXPR:
    4060          269 :         case REINTERPRET_CAST_EXPR:
    4061          269 :         case STATIC_CAST_EXPR:
    4062          269 :         case CONST_CAST_EXPR:
    4063          269 :           write_type (TREE_TYPE (expr));
    4064          269 :           write_expression (TREE_OPERAND (expr, 0));
    4065          269 :           break;
    4066              : 
    4067           31 :         case PREINCREMENT_EXPR:
    4068           31 :         case PREDECREMENT_EXPR:
    4069           31 :           if (abi_check (6))
    4070           22 :             write_char ('_');
    4071              :           /* Fall through.  */
    4072              : 
    4073      3767518 :         default:
    4074              :           /* In the middle-end, some expressions have more operands than
    4075              :              they do in templates (and mangling).  */
    4076      3767518 :           len = cp_tree_operand_length (expr);
    4077              : 
    4078     10003419 :           for (i = 0; i < len; ++i)
    4079              :             {
    4080      6235901 :               tree operand = TREE_OPERAND (expr, i);
    4081              :               /* As a GNU extension, the middle operand of a
    4082              :                  conditional may be omitted.  Since expression
    4083              :                  manglings are supposed to represent the input token
    4084              :                  stream, there's no good way to mangle such an
    4085              :                  expression without extending the C++ ABI.  */
    4086      6235901 :               if (code == COND_EXPR && i == 1 && !operand)
    4087              :                 {
    4088            3 :                   error ("omitted middle operand to %<?:%> operand "
    4089              :                          "cannot be mangled");
    4090            3 :                   continue;
    4091              :                 }
    4092      6235898 :               else if (FOLD_EXPR_P (expr))
    4093              :                 {
    4094              :                   /* The first 'operand' of a fold-expression is the operator
    4095              :                      that it folds over.  */
    4096       292780 :                   if (i == 0)
    4097              :                     {
    4098       146317 :                       int fcode = TREE_INT_CST_LOW (operand);
    4099       146317 :                       write_string (OVL_OP_INFO (false, fcode)->mangled_name);
    4100       146317 :                       continue;
    4101       146317 :                     }
    4102       146463 :                   else if (code == BINARY_LEFT_FOLD_EXPR)
    4103              :                     {
    4104              :                       /* The order of operands of the binary left and right
    4105              :                          folds is the same, but we want to mangle them in
    4106              :                          lexical order, i.e. non-pack first.  */
    4107          286 :                       if (i == 1)
    4108          143 :                         operand = FOLD_EXPR_INIT (expr);
    4109              :                       else
    4110          143 :                         operand = FOLD_EXPR_PACK (expr);
    4111              :                     }
    4112       146463 :                   if (PACK_EXPANSION_P (operand))
    4113       146317 :                     operand = PACK_EXPANSION_PATTERN (operand);
    4114              :                 }
    4115      6089581 :               write_expression (operand);
    4116              :             }
    4117              :         }
    4118              :     }
    4119              : }
    4120              : 
    4121              : /* Non-terminal <reflection>.
    4122              : 
    4123              :      <reflection> ::= nu                          # null reflection
    4124              :                   ::= vl <expression>                     # value
    4125              :                   ::= ob <expression>                     # object
    4126              :                   ::= vr <variable name>          # variable
    4127              :                   ::= sb <sb name>                        # structured binding
    4128              :                   ::= fn <function encoding>              # function
    4129              :                   ::= pa [ <nonnegative number> ] _ <encoding>      # fn param
    4130              :                   ::= en <prefix> <unqualified-name>        # enumerator
    4131              :                   ::= an [ <nonnegative number> ] _       # annotation
    4132              :                   ::= ta <alias prefix>                   # type alias
    4133              :                   ::= ty <type>                           # type
    4134              :                   ::= dm <prefix> <unqualified-name>        # ns data member
    4135              :                   ::= un <prefix> [ <nonnegative number> ] _ # unnamed bitfld
    4136              :                   ::= ct [ <prefix> ] <unqualified-name> # class template
    4137              :                   ::= ft [ <prefix> ] <unqualified-name> # function template
    4138              :                   ::= vt [ <prefix> ] <unqualified-name> # variable template
    4139              :                   ::= at [ <prefix> ] <unqualified-name> # alias template
    4140              :                   ::= co [ <prefix> ] <unqualified-name> # concept
    4141              :                   ::= na [ <prefix> ] <unqualified-name> # namespace alias
    4142              :                   ::= ns [ <prefix> ] <unqualified-name> # namespace
    4143              :                   ::= ng                                # ^^::
    4144              :                   ::= ba [ <nonnegative number> ] _ <type> # dir. base cls rel
    4145              :                   ::= ds <type> _ [ <unqualified-name> ] _
    4146              :                       [ <alignment number> ] _ [ <bit-width number> ] _
    4147              :                       [ n ]                             # data member spec  */
    4148              : 
    4149              : static void
    4150          541 : write_reflection (tree refl)
    4151              : {
    4152          541 :   char prefix[3];
    4153          541 :   tree arg = reflection_mangle_prefix (refl, prefix);
    4154          541 :   write_string (prefix);
    4155              :   /* If there is no argument, nothing further needs to be mangled.  */
    4156          541 :   if (arg == NULL_TREE)
    4157           15 :     return;
    4158          526 :   if (strcmp (prefix, "vl") == 0 || strcmp (prefix, "ob") == 0)
    4159            7 :     write_expression (arg);
    4160          519 :   else if (strcmp (prefix, "vr") == 0 || strcmp (prefix, "sb") == 0)
    4161           90 :     write_name (arg, 0);
    4162          429 :   else if (strcmp (prefix, "fn") == 0)
    4163           49 :     write_encoding (arg);
    4164          380 :   else if (strcmp (prefix, "pa") == 0)
    4165              :     {
    4166           16 :       tree fn = DECL_CONTEXT (arg);
    4167           16 :       tree args = FUNCTION_FIRST_USER_PARM (fn);
    4168           16 :       int idx = 0;
    4169           36 :       while (arg != args)
    4170              :         {
    4171            4 :           args = DECL_CHAIN (args);
    4172            4 :           ++idx;
    4173              :         }
    4174           16 :       write_compact_number (idx);
    4175           16 :       write_encoding (fn);
    4176              :     }
    4177          364 :   else if (strcmp (prefix, "en") == 0)
    4178              :     {
    4179            7 :       write_prefix (decl_mangling_context (arg));
    4180            7 :       write_unqualified_name (arg);
    4181              :     }
    4182          357 :   else if (strcmp (prefix, "an") == 0)
    4183            5 :     write_compact_number (tree_to_uhwi (arg));
    4184          352 :   else if (strcmp (prefix, "ta") == 0)
    4185              :     {
    4186            6 :       arg = TYPE_NAME (arg);
    4187            6 :       write_prefix (arg);
    4188              :     }
    4189          346 :   else if (strcmp (prefix, "ty") == 0)
    4190          127 :     write_type (arg);
    4191          219 :   else if (strcmp (prefix, "dm") == 0)
    4192              :     {
    4193           82 :       tree ctx = decl_mangling_context (arg);
    4194          168 :       while (ctx && ANON_UNION_TYPE_P (ctx))
    4195            4 :         ctx = decl_mangling_context (TYPE_NAME (ctx));
    4196           82 :       write_prefix (ctx);
    4197           82 :       write_unqualified_name (arg);
    4198              :     }
    4199          137 :   else if (strcmp (prefix, "un") == 0)
    4200              :     {
    4201            4 :       tree ctx = DECL_CONTEXT (arg);
    4202            4 :       int idx = 0;
    4203           71 :       for (tree f = TYPE_FIELDS (ctx); f; f = DECL_CHAIN (f))
    4204           71 :         if (f == arg)
    4205              :           break;
    4206           67 :         else if (TREE_CODE (f) == FIELD_DECL && DECL_UNNAMED_BIT_FIELD (f))
    4207            3 :           ++idx;
    4208            4 :       write_prefix (decl_mangling_context (arg));
    4209            4 :       write_compact_number (idx);
    4210              :     }
    4211          133 :   else if (strcmp (prefix, "ct") == 0
    4212          118 :            || strcmp (prefix, "ft") == 0
    4213          104 :            || strcmp (prefix, "vt") == 0
    4214           97 :            || strcmp (prefix, "at") == 0
    4215           89 :            || strcmp (prefix, "co") == 0
    4216           83 :            || strcmp (prefix, "na") == 0
    4217           79 :            || strcmp (prefix, "ns") == 0)
    4218              :     {
    4219          116 :       write_prefix (decl_mangling_context (arg));
    4220          116 :       write_unqualified_name (arg);
    4221              :     }
    4222           17 :   else if (strcmp (prefix, "ba") == 0)
    4223              :     {
    4224           10 :       gcc_assert (TREE_CODE (arg) == TREE_BINFO);
    4225              :       tree c = arg, base_binfo;
    4226           20 :       while (BINFO_INHERITANCE_CHAIN (c))
    4227              :         c = BINFO_INHERITANCE_CHAIN (c);
    4228              : 
    4229              :       unsigned idx;
    4230           11 :       for (idx = 0; BINFO_BASE_ITERATE (c, idx, base_binfo); idx++)
    4231           11 :         if (base_binfo == arg)
    4232              :           break;
    4233           10 :       write_compact_number (idx);
    4234           10 :       write_type (BINFO_TYPE (c));
    4235              :     }
    4236            7 :   else if (strcmp (prefix, "ds") == 0)
    4237              :     {
    4238            7 :       gcc_assert (TREE_CODE (arg) == TREE_VEC);
    4239            7 :       write_type (TREE_VEC_ELT (arg, 0));
    4240            7 :       write_char ('_');
    4241            7 :       if (TREE_VEC_ELT (arg, 1))
    4242            5 :         write_unqualified_id (TREE_VEC_ELT (arg, 1));
    4243            7 :       write_char ('_');
    4244            7 :       if (TREE_VEC_ELT (arg, 2))
    4245            1 :         write_number (tree_to_shwi (TREE_VEC_ELT (arg, 2)), 0, 10);
    4246            7 :       write_char ('_');
    4247            7 :       if (TREE_VEC_ELT (arg, 3))
    4248            3 :         write_number (tree_to_shwi (TREE_VEC_ELT (arg, 3)), 0, 10);
    4249            7 :       write_char ('_');
    4250            7 :       if (integer_nonzerop (TREE_VEC_ELT (arg, 4)))
    4251            1 :         write_char ('n');
    4252              :     }
    4253              : }
    4254              : 
    4255              : /* Literal subcase of non-terminal <template-arg>.
    4256              : 
    4257              :      "Literal arguments, e.g. "A<42L>", are encoded with their type
    4258              :      and value. Negative integer values are preceded with "n"; for
    4259              :      example, "A<-42L>" becomes "1AILln42EE". The bool value false is
    4260              :      encoded as 0, true as 1."  */
    4261              : 
    4262              : static void
    4263     94866136 : write_template_arg_literal (const tree value)
    4264              : {
    4265     94866136 :   if (TREE_CODE (value) == STRING_CST)
    4266              :     /* Temporarily mangle strings as braced initializer lists.  */
    4267         1421 :     write_string ("tl");
    4268              :   else
    4269     94864715 :     write_char ('L');
    4270              : 
    4271     94866136 :   tree valtype = TREE_TYPE (value);
    4272     94866136 :   write_type (valtype);
    4273              : 
    4274              :   /* Write a null member pointer value as (type)0, regardless of its
    4275              :      real representation.  */
    4276     94866136 :   if (null_member_pointer_value_p (value))
    4277          192 :     write_integer_cst (integer_zero_node);
    4278              :   else
    4279     94865944 :     switch (TREE_CODE (value))
    4280              :       {
    4281        38062 :       case CONST_DECL:
    4282        38062 :         write_integer_cst (DECL_INITIAL (value));
    4283        38062 :         break;
    4284              : 
    4285     94825582 :       case INTEGER_CST:
    4286     94825582 :         gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node)
    4287              :                     || integer_zerop (value) || integer_onep (value));
    4288     94825582 :         if (!(abi_version_at_least (14)
    4289     94818712 :               && NULLPTR_TYPE_P (TREE_TYPE (value))))
    4290     94825527 :           write_integer_cst (value);
    4291              :         break;
    4292              : 
    4293          332 :       case REAL_CST:
    4294          332 :         write_real_cst (value);
    4295          332 :         break;
    4296              : 
    4297            6 :       case COMPLEX_CST:
    4298            6 :         if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST
    4299            6 :             && TREE_CODE (TREE_IMAGPART (value)) == INTEGER_CST)
    4300              :           {
    4301            3 :             write_integer_cst (TREE_REALPART (value));
    4302            3 :             write_char ('_');
    4303            3 :             write_integer_cst (TREE_IMAGPART (value));
    4304              :           }
    4305            3 :         else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST
    4306            3 :                  && TREE_CODE (TREE_IMAGPART (value)) == REAL_CST)
    4307              :           {
    4308            3 :             write_real_cst (TREE_REALPART (value));
    4309            3 :             write_char ('_');
    4310            3 :             write_real_cst (TREE_IMAGPART (value));
    4311              :           }
    4312              :         else
    4313            0 :           gcc_unreachable ();
    4314              :         break;
    4315              : 
    4316         1421 :       case STRING_CST:
    4317         1421 :         {
    4318              :           /* Mangle strings the same as braced initializer lists.  */
    4319         1421 :           unsigned n = TREE_STRING_LENGTH (value);
    4320         1421 :           const char *str = TREE_STRING_POINTER (value);
    4321              : 
    4322              :           /* Count the number of trailing nuls and subtract them from
    4323              :              STRSIZE because they don't need to be mangled.  */
    4324         3819 :           for (const char *p = str + n - 1; ; --p)
    4325              :             {
    4326         3819 :               if (*p || p == str)
    4327              :                 {
    4328         1421 :                   n -= str + n - !!*p - p;
    4329         1421 :                   break;
    4330              :                 }
    4331              :             }
    4332         1421 :           tree eltype = TREE_TYPE (valtype);
    4333         7646 :           for (const char *p = str; n--; ++p)
    4334              :             {
    4335         6225 :               write_char ('L');
    4336         6225 :               write_type (eltype);
    4337         6225 :               write_unsigned_number (*(const unsigned char*)p);
    4338         6225 :               write_string ("E");
    4339              :             }
    4340              :           break;
    4341              :         }
    4342              : 
    4343          541 :       case REFLECT_EXPR:
    4344          541 :         write_reflection (value);
    4345          541 :         break;
    4346              : 
    4347            0 :       default:
    4348            0 :         gcc_unreachable ();
    4349              :       }
    4350              : 
    4351     94866136 :   write_char ('E');
    4352     94866136 : }
    4353              : 
    4354              : /* Non-terminal <template-arg>.
    4355              : 
    4356              :      <template-arg> ::= <type>                              # type
    4357              :                     ::= L <type> </value/ number> E # literal
    4358              :                     ::= LZ <name> E                       # external name
    4359              :                     ::= X <expression> E          # expression  */
    4360              : 
    4361              : static void
    4362    803534456 : write_template_arg (tree node)
    4363              : {
    4364    803534456 :   enum tree_code code = TREE_CODE (node);
    4365              : 
    4366    803534456 :   MANGLE_TRACE_TREE ("template-arg", node);
    4367              : 
    4368              :   /* A template template parameter's argument list contains TREE_LIST
    4369              :      nodes of which the value field is the actual argument.  */
    4370    803534456 :   if (code == TREE_LIST)
    4371              :     {
    4372            0 :       node = TREE_VALUE (node);
    4373              :       /* If it's a decl, deal with its type instead.  */
    4374            0 :       if (DECL_P (node))
    4375              :         {
    4376            0 :           node = TREE_TYPE (node);
    4377            0 :           code = TREE_CODE (node);
    4378              :         }
    4379              :     }
    4380              : 
    4381    803534456 :   if (VAR_P (node) && DECL_NTTP_OBJECT_P (node))
    4382              :     /* We want to mangle the argument, not the var we stored it in.  */
    4383        44403 :     node = tparm_object_argument (node);
    4384              : 
    4385              :   /* Strip a conversion added by convert_nontype_argument.  */
    4386    803534456 :   if (TREE_CODE (node) == IMPLICIT_CONV_EXPR)
    4387           54 :     node = TREE_OPERAND (node, 0);
    4388    803534456 :   if (REFERENCE_REF_P (node))
    4389          266 :     node = TREE_OPERAND (node, 0);
    4390    803534456 :   if (TREE_CODE (node) == NOP_EXPR
    4391    803534456 :       && TYPE_REF_P (TREE_TYPE (node)))
    4392              :     {
    4393              :       /* Template parameters can be of reference type. To maintain
    4394              :          internal consistency, such arguments use a conversion from
    4395              :          address of object to reference type.  */
    4396          266 :       gcc_assert (TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR);
    4397          266 :       node = TREE_OPERAND (TREE_OPERAND (node, 0), 0);
    4398              :     }
    4399              : 
    4400    803534456 :   if (TREE_CODE (node) == BASELINK
    4401    803534456 :       && !type_unknown_p (node))
    4402              :     {
    4403              :       /* Before v6 we wrongly wrapped a class-scope function in X/E.  */
    4404           18 :       if (abi_check (6))
    4405           12 :         node = BASELINK_FUNCTIONS (node);
    4406              :     }
    4407              : 
    4408    803534456 :   if (ARGUMENT_PACK_P (node))
    4409              :     {
    4410              :       /* Expand the template argument pack. */
    4411      9633361 :       tree args = ARGUMENT_PACK_ARGS (node);
    4412      9633361 :       int i, length = TREE_VEC_LENGTH (args);
    4413      9633361 :       if (abi_check (6))
    4414      9633343 :         write_char ('J');
    4415              :       else
    4416           18 :         write_char ('I');
    4417     23251765 :       for (i = 0; i < length; ++i)
    4418     13618404 :         write_template_arg (TREE_VEC_ELT (args, i));
    4419      9633361 :       write_char ('E');
    4420              :     }
    4421    793901095 :   else if (TYPE_P (node))
    4422    697871942 :     write_type (node);
    4423     96029153 :   else if (code == TEMPLATE_DECL)
    4424              :     /* A template appearing as a template arg is a template template arg.  */
    4425       737431 :     write_template_template_arg (node);
    4426     94492227 :   else if ((TREE_CODE_CLASS (code) == tcc_constant && code != PTRMEM_CST)
    4427       799495 :            || code == CONST_DECL
    4428       802838 :            || null_member_pointer_value_p (node)
    4429     96094465 :            || code == REFLECT_EXPR)
    4430     94489474 :     write_template_arg_literal (node);
    4431       802248 :   else if (code == EXCESS_PRECISION_EXPR
    4432       802248 :            && TREE_CODE (TREE_OPERAND (node, 0)) == REAL_CST)
    4433            0 :     write_template_arg_literal (fold_convert (TREE_TYPE (node),
    4434              :                                               TREE_OPERAND (node, 0)));
    4435       802248 :   else if (DECL_P (node))
    4436              :     {
    4437          286 :       write_char ('L');
    4438              :       /* Until ABI version 3, the underscore before the mangled name
    4439              :          was incorrectly omitted.  */
    4440          286 :       if (!abi_check (3))
    4441           21 :         write_char ('Z');
    4442              :       else
    4443          265 :         write_string ("_Z");
    4444          286 :       write_encoding (node);
    4445          286 :       write_char ('E');
    4446              :     }
    4447              :   else
    4448              :     {
    4449              :       /* Template arguments may be expressions.  */
    4450       801962 :       write_char ('X');
    4451       801962 :       write_expression (node);
    4452       801962 :       write_char ('E');
    4453              :     }
    4454    803534456 : }
    4455              : 
    4456              : /*  <template-template-arg>
    4457              :                         ::= <name>
    4458              :                         ::= <substitution>  */
    4459              : 
    4460              : static void
    4461       737431 : write_template_template_arg (const tree decl)
    4462              : {
    4463       737431 :   MANGLE_TRACE_TREE ("template-template-arg", decl);
    4464              : 
    4465       737431 :   if (find_substitution (decl))
    4466              :     return;
    4467       672949 :   write_name (decl, /*ignore_local_scope=*/0);
    4468       672949 :   add_substitution (decl);
    4469              : }
    4470              : 
    4471              : 
    4472              : /* Non-terminal <array-type>.  TYPE is an ARRAY_TYPE.
    4473              : 
    4474              :      <array-type> ::= A [</dimension/ number>] _ </element/ type>
    4475              :                   ::= A <expression> _ </element/ type>
    4476              : 
    4477              :      "Array types encode the dimension (number of elements) and the
    4478              :      element type.  For variable length arrays, the dimension (but not
    4479              :      the '_' separator) is omitted."
    4480              :      Note that for flexible array members, like for other arrays of
    4481              :      unspecified size, the dimension is also omitted.  */
    4482              : 
    4483              : static void
    4484      1597649 : write_array_type (const tree type)
    4485              : {
    4486      1597649 :   write_char ('A');
    4487      1597649 :   if (TYPE_DOMAIN (type))
    4488              :     {
    4489       476271 :       tree index_type;
    4490              : 
    4491       476271 :       index_type = TYPE_DOMAIN (type);
    4492              :       /* The INDEX_TYPE gives the upper and lower bounds of the array.
    4493              :          It's null for flexible array members which have no upper bound
    4494              :          (this is a change from GCC 5 and prior where such members were
    4495              :          incorrectly mangled as zero-length arrays).  */
    4496       476271 :       if (tree max = TYPE_MAX_VALUE (index_type))
    4497              :         {
    4498       476271 :           if (TREE_CODE (max) == INTEGER_CST)
    4499              :             {
    4500              :               /* The ABI specifies that we should mangle the number of
    4501              :                  elements in the array, not the largest allowed index.  */
    4502       242766 :               offset_int wmax = wi::to_offset (max) + 1;
    4503              :               /* Truncate the result - this will mangle [0, SIZE_INT_MAX]
    4504              :                  number of elements as zero.  */
    4505       242766 :               wmax = wi::zext (wmax, TYPE_PRECISION (TREE_TYPE (max)));
    4506       242766 :               gcc_assert (wi::fits_uhwi_p (wmax));
    4507       242766 :               write_unsigned_number (wmax.to_uhwi ());
    4508              :             }
    4509              :           else
    4510              :             {
    4511       233505 :               gcc_checking_assert (TREE_CODE (max) == MINUS_EXPR
    4512              :                                    && integer_onep (TREE_OPERAND (max, 1)));
    4513       233505 :               max = TREE_OPERAND (max, 0);
    4514       233505 :               write_expression (max);
    4515              :             }
    4516              :         }
    4517              :     }
    4518      1597649 :   write_char ('_');
    4519      1597649 :   write_type (TREE_TYPE (type));
    4520      1597649 : }
    4521              : 
    4522              : /* Non-terminal <pointer-to-member-type> for pointer-to-member
    4523              :    variables.  TYPE is a pointer-to-member POINTER_TYPE.
    4524              : 
    4525              :      <pointer-to-member-type> ::= M </class/ type> </member/ type>  */
    4526              : 
    4527              : static void
    4528       267635 : write_pointer_to_member_type (const tree type)
    4529              : {
    4530       267635 :   write_char ('M');
    4531       267635 :   write_type (TYPE_PTRMEM_CLASS_TYPE (type));
    4532       267635 :   write_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
    4533       267635 : }
    4534              : 
    4535              : /* Non-terminal <template-param>.  PARM is a TEMPLATE_TYPE_PARM,
    4536              :    TEMPLATE_TEMPLATE_PARM, BOUND_TEMPLATE_TEMPLATE_PARM or a
    4537              :    TEMPLATE_PARM_INDEX.
    4538              : 
    4539              :      <template-param> ::= T </parameter/ number> _  */
    4540              : 
    4541              : static void
    4542     35283204 : write_template_param (const tree parm)
    4543              : {
    4544     35283204 :   int parm_index;
    4545     35283204 :   int level;
    4546              : 
    4547     35283204 :   MANGLE_TRACE_TREE ("template-parm", parm);
    4548              : 
    4549     35283204 :   switch (TREE_CODE (parm))
    4550              :     {
    4551     34323172 :     case TEMPLATE_TYPE_PARM:
    4552     34323172 :     case TEMPLATE_TEMPLATE_PARM:
    4553     34323172 :     case BOUND_TEMPLATE_TEMPLATE_PARM:
    4554     34323172 :       parm_index = TEMPLATE_TYPE_IDX (parm);
    4555     34323172 :       level = TEMPLATE_TYPE_LEVEL (parm);
    4556     34323172 :       break;
    4557              : 
    4558       960032 :     case TEMPLATE_PARM_INDEX:
    4559       960032 :       parm_index = TEMPLATE_PARM_IDX (parm);
    4560       960032 :       level = TEMPLATE_PARM_LEVEL (parm);
    4561       960032 :       break;
    4562              : 
    4563            0 :     default:
    4564            0 :       gcc_unreachable ();
    4565              :     }
    4566              : 
    4567     35283204 :   write_char ('T');
    4568     35283204 :   if (level > 1)
    4569              :     {
    4570        23324 :       if (abi_check (19))
    4571              :         {
    4572        23312 :           write_char ('L');
    4573        23312 :           write_compact_number (level - 1);
    4574              :         }
    4575              :     }
    4576              :   /* NUMBER as it appears in the mangling is (-1)-indexed, with the
    4577              :      earliest template param denoted by `_'.  */
    4578     35283204 :   write_compact_number (parm_index);
    4579     35283204 : }
    4580              : 
    4581              : /*  <template-template-param>
    4582              :                         ::= <template-param>
    4583              :                         ::= <substitution>  */
    4584              : 
    4585              : static void
    4586          625 : write_template_template_param (const tree parm)
    4587              : {
    4588          625 :   tree templ = NULL_TREE;
    4589              : 
    4590              :   /* PARM, a TEMPLATE_TEMPLATE_PARM, is an instantiation of the
    4591              :      template template parameter.  The substitution candidate here is
    4592              :      only the template.  */
    4593          625 :   if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
    4594              :     {
    4595          532 :       templ
    4596          532 :         = TI_TEMPLATE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm));
    4597          532 :       if (find_substitution (templ))
    4598              :         return;
    4599              :     }
    4600              : 
    4601              :   /* <template-param> encodes only the template parameter position,
    4602              :      not its template arguments, which is fine here.  */
    4603          625 :   write_template_param (parm);
    4604          625 :   if (templ)
    4605          532 :     add_substitution (templ);
    4606              : }
    4607              : 
    4608              : /* Non-terminal <substitution>.
    4609              : 
    4610              :       <substitution> ::= S <seq-id> _
    4611              :                      ::= S_  */
    4612              : 
    4613              : static void
    4614    194171898 : write_substitution (const int seq_id)
    4615              : {
    4616    194171898 :   MANGLE_TRACE ("substitution", "");
    4617              : 
    4618    194171898 :   write_char ('S');
    4619    194171898 :   if (seq_id > 0)
    4620    166057829 :     write_number (seq_id - 1, /*unsigned=*/1, 36);
    4621    194171898 :   write_char ('_');
    4622    194171898 : }
    4623              : 
    4624              : /* Start mangling ENTITY.  */
    4625              : 
    4626              : static inline void
    4627    234037164 : start_mangling (const tree entity)
    4628              : {
    4629    234037164 :   G = {};
    4630    234037164 :   G.entity = entity;
    4631    234037164 :   obstack_free (&name_obstack, name_base);
    4632    234037164 :   mangle_obstack = &name_obstack;
    4633    234037164 :   name_base = obstack_alloc (&name_obstack, 0);
    4634    234037164 : }
    4635              : 
    4636              : /* Done with mangling.  Release the data.  */
    4637              : 
    4638              : static void
    4639    234037164 : finish_mangling_internal (void)
    4640              : {
    4641              :   /* Clear all the substitutions.  */
    4642    234037164 :   vec_safe_truncate (G.substitutions, 0);
    4643              : 
    4644    234037164 :   if (G.mod)
    4645         7297 :     mangle_module_fini ();
    4646              : 
    4647              :   /* Null-terminate the string.  */
    4648    234037164 :   write_char ('\0');
    4649    234037164 : }
    4650              : 
    4651              : 
    4652              : /* Like finish_mangling_internal, but return the mangled string.  */
    4653              : 
    4654              : static inline const char *
    4655       514800 : finish_mangling (void)
    4656              : {
    4657       514800 :   finish_mangling_internal ();
    4658       514800 :   return (const char *) obstack_finish (mangle_obstack);
    4659              : }
    4660              : 
    4661              : /* Like finish_mangling_internal, but return an identifier.  */
    4662              : 
    4663              : static tree
    4664    233522364 : finish_mangling_get_identifier (void)
    4665              : {
    4666    233522364 :   finish_mangling_internal ();
    4667              :   /* Don't obstack_finish here, and the next start_mangling will
    4668              :      remove the identifier.  */
    4669    233522364 :   return get_identifier ((const char *) obstack_base (mangle_obstack));
    4670              : }
    4671              : 
    4672              : /* Initialize data structures for mangling.  */
    4673              : 
    4674              : void
    4675        97402 : init_mangle (void)
    4676              : {
    4677        97402 :   gcc_obstack_init (&name_obstack);
    4678        97402 :   name_base = obstack_alloc (&name_obstack, 0);
    4679        97402 :   vec_alloc (G.substitutions, 0);
    4680              : 
    4681              :   /* Cache these identifiers for quick comparison when checking for
    4682              :      standard substitutions.  */
    4683        97402 :   subst_identifiers[SUBID_ALLOCATOR] = get_identifier ("allocator");
    4684        97402 :   subst_identifiers[SUBID_BASIC_STRING] = get_identifier ("basic_string");
    4685        97402 :   subst_identifiers[SUBID_CHAR_TRAITS] = get_identifier ("char_traits");
    4686        97402 :   subst_identifiers[SUBID_BASIC_ISTREAM] = get_identifier ("basic_istream");
    4687        97402 :   subst_identifiers[SUBID_BASIC_OSTREAM] = get_identifier ("basic_ostream");
    4688        97402 :   subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream");
    4689        97402 : }
    4690              : 
    4691              : /* Generate a mangling for MODULE's global initializer fn.  */
    4692              : 
    4693              : tree
    4694         1912 : mangle_module_global_init (int module)
    4695              : {
    4696         1912 :   start_mangling (NULL_TREE);
    4697              : 
    4698         1912 :   write_string ("_ZGI");
    4699         1912 :   write_module (module, true);
    4700              : 
    4701         1912 :   return finish_mangling_get_identifier ();
    4702              : }
    4703              : 
    4704              : /* Generate the mangled name of DECL.  */
    4705              : 
    4706              : static tree
    4707    226893240 : mangle_decl_string (const tree decl)
    4708              : {
    4709    226893240 :   tree result;
    4710    226893240 :   tree saved_fn = current_function_decl;
    4711              : 
    4712              :   /* We shouldn't be trying to mangle an uninstantiated template.  */
    4713    226893240 :   gcc_assert (!type_dependent_expression_p (decl));
    4714              : 
    4715    226893240 :   current_function_decl = NULL_TREE;
    4716    226893240 :   iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
    4717              : 
    4718    226893240 :   start_mangling (decl);
    4719              : 
    4720    226893240 :   if (TREE_CODE (decl) == TYPE_DECL)
    4721       323366 :     write_type (TREE_TYPE (decl));
    4722              :   else
    4723    226569874 :     write_mangled_name (decl, true);
    4724              : 
    4725    226893240 :   result = finish_mangling_get_identifier ();
    4726    226893240 :   if (DEBUG_MANGLE)
    4727              :     fprintf (stderr, "mangle_decl_string = '%s'\n\n",
    4728              :              IDENTIFIER_POINTER (result));
    4729              : 
    4730    226893240 :   current_function_decl = saved_fn;
    4731    226893240 :   return result;
    4732    226893240 : }
    4733              : 
    4734              : /* Return an identifier for the external mangled name of DECL.  */
    4735              : 
    4736              : static tree
    4737    173027806 : get_mangled_id (tree decl)
    4738              : {
    4739    173027806 :   tree id = mangle_decl_string (decl);
    4740    173027806 :   return targetm.mangle_decl_assembler_name (decl, id);
    4741              : }
    4742              : 
    4743              : /* Create an identifier for the external mangled name of DECL.  */
    4744              : 
    4745              : void
    4746    173035628 : mangle_decl (const tree decl)
    4747              : {
    4748    173035628 :   tree id;
    4749    173035628 :   bool dep;
    4750              : 
    4751              :   /* Don't bother mangling uninstantiated templates.  */
    4752    173035628 :   ++processing_template_decl;
    4753    173035628 :   if (TREE_CODE (decl) == TYPE_DECL)
    4754       323790 :     dep = dependent_type_p (TREE_TYPE (decl));
    4755              :   else
    4756    344148538 :     dep = (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
    4757    292051976 :            && any_dependent_template_arguments_p (DECL_TI_ARGS (decl)));
    4758    173035628 :   --processing_template_decl;
    4759    173035628 :   if (dep)
    4760              :     return;
    4761              : 
    4762              :   /* During LTO we keep mangled names of TYPE_DECLs for ODR type merging.
    4763              :      It is not needed to assign names to anonymous namespace, but we use the
    4764              :      "<anon>" marker to be able to tell if type is C++ ODR type or type
    4765              :      produced by other language.  */
    4766    173028230 :   if (TREE_CODE (decl) == TYPE_DECL
    4767       323790 :       && TYPE_STUB_DECL (TREE_TYPE (decl))
    4768    173341566 :       && !TREE_PUBLIC (TYPE_STUB_DECL (TREE_TYPE (decl))))
    4769          424 :     id = get_identifier ("<anon>");
    4770              :   else
    4771              :     {
    4772    173027806 :       gcc_assert (TREE_CODE (decl) != TYPE_DECL
    4773              :                   || !no_linkage_check (TREE_TYPE (decl), true));
    4774    173027806 :       if (abi_version_at_least (10))
    4775    172909768 :         if (tree fn = decl_function_context (decl))
    4776      5022220 :           maybe_check_abi_tags (fn, decl);
    4777    173027806 :       id = get_mangled_id (decl);
    4778              :     }
    4779    173028230 :   SET_DECL_ASSEMBLER_NAME (decl, id);
    4780              : 
    4781    173028230 :   if (G.need_cxx17_warning
    4782    173028230 :       && (TREE_PUBLIC (decl) || DECL_REALLY_EXTERN (decl)))
    4783           10 :     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wnoexcept_type,
    4784              :                 "mangled name for %qD will change in C++17 because the "
    4785              :                 "exception specification is part of a function type",
    4786              :                 decl);
    4787              : 
    4788    173028230 :   if (id != DECL_NAME (decl)
    4789              :       /* Don't do this for a fake symbol we aren't going to emit anyway.  */
    4790    170530279 :       && TREE_CODE (decl) != TYPE_DECL
    4791    343234719 :       && !DECL_MAYBE_IN_CHARGE_CDTOR_P (decl))
    4792              :     {
    4793    148641874 :       int save_ver = flag_abi_version;
    4794    148641874 :       tree id2 = NULL_TREE;
    4795              : 
    4796    148641874 :       if (!DECL_REALLY_EXTERN (decl))
    4797              :         {
    4798     94060661 :           record_mangling (decl, G.need_abi_warning);
    4799              : 
    4800     94060661 :           if (!G.need_abi_warning)
    4801              :             return;
    4802              : 
    4803        25713 :           flag_abi_version = flag_abi_compat_version;
    4804        25713 :           id2 = mangle_decl_string (decl);
    4805        25713 :           id2 = targetm.mangle_decl_assembler_name (decl, id2);
    4806        25713 :           flag_abi_version = save_ver;
    4807              : 
    4808        25713 :           if (id2 != id)
    4809        25597 :             note_mangling_alias (decl, id2);
    4810              :         }
    4811              : 
    4812     54606926 :       if (warn_abi)
    4813              :         {
    4814     53839916 :           const char fabi_version[] = "-fabi-version";
    4815              : 
    4816     53839916 :           if (flag_abi_compat_version != warn_abi_version
    4817     53839199 :               || id2 == NULL_TREE)
    4818              :             {
    4819     53839721 :               flag_abi_version = warn_abi_version;
    4820     53839721 :               id2 = mangle_decl_string (decl);
    4821     53839721 :               id2 = targetm.mangle_decl_assembler_name (decl, id2);
    4822              :             }
    4823     53839916 :           flag_abi_version = save_ver;
    4824              : 
    4825     53839916 :           if (id2 == id)
    4826              :             /* OK.  */;
    4827          266 :           else if (warn_abi_version != 0
    4828          266 :                    && abi_version_at_least (warn_abi_version))
    4829          222 :             warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
    4830              :                         "the mangled name of %qD changed between "
    4831              :                         "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
    4832              :                         G.entity, fabi_version, warn_abi_version, id2,
    4833              :                         fabi_version, save_ver, id);
    4834              :           else
    4835           44 :             warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
    4836              :                         "the mangled name of %qD changes between "
    4837              :                         "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
    4838              :                         G.entity, fabi_version, save_ver, id,
    4839              :                         fabi_version, warn_abi_version, id2);
    4840              :         }
    4841              : 
    4842     54606926 :       flag_abi_version = save_ver;
    4843              :     }
    4844              : }
    4845              : 
    4846              : /* Generate the mangled representation of TYPE.  */
    4847              : 
    4848              : const char *
    4849       514800 : mangle_type_string (const tree type)
    4850              : {
    4851       514800 :   const char *result;
    4852              : 
    4853       514800 :   start_mangling (type);
    4854       514800 :   write_type (type);
    4855       514800 :   result = finish_mangling ();
    4856       514800 :   if (DEBUG_MANGLE)
    4857              :     fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
    4858       514800 :   return result;
    4859              : }
    4860              : 
    4861              : /* Create an identifier for the mangled name of a special component
    4862              :    for belonging to TYPE.  CODE is the ABI-specified code for this
    4863              :    component.  */
    4864              : 
    4865              : static tree
    4866      5894806 : mangle_special_for_type (const tree type, const char *code)
    4867              : {
    4868      5894806 :   tree result;
    4869              : 
    4870              :   /* We don't have an actual decl here for the special component, so
    4871              :      we can't just process the <encoded-name>.  Instead, fake it.  */
    4872      5894806 :   start_mangling (type);
    4873              : 
    4874              :   /* Start the mangling.  */
    4875      5894806 :   write_string ("_Z");
    4876      5894806 :   write_string (code);
    4877              : 
    4878              :   /* Add the type.  */
    4879      5894806 :   write_type (type);
    4880      5894806 :   result = finish_mangling_get_identifier ();
    4881              : 
    4882      5894806 :   if (DEBUG_MANGLE)
    4883              :     fprintf (stderr, "mangle_special_for_type = %s\n\n",
    4884              :              IDENTIFIER_POINTER (result));
    4885              : 
    4886      5894806 :   return result;
    4887              : }
    4888              : 
    4889              : /* Create an identifier for the mangled representation of the typeinfo
    4890              :    structure for TYPE.  */
    4891              : 
    4892              : tree
    4893      3351305 : mangle_typeinfo_for_type (const tree type)
    4894              : {
    4895      3351305 :   return mangle_special_for_type (type, "TI");
    4896              : }
    4897              : 
    4898              : /* Create an identifier for the mangled name of the NTBS containing
    4899              :    the mangled name of TYPE.  */
    4900              : 
    4901              : tree
    4902       507140 : mangle_typeinfo_string_for_type (const tree type)
    4903              : {
    4904       507140 :   return mangle_special_for_type (type, "TS");
    4905              : }
    4906              : 
    4907              : /* Create an identifier for the mangled name of the vtable for TYPE.  */
    4908              : 
    4909              : tree
    4910      1857567 : mangle_vtbl_for_type (const tree type)
    4911              : {
    4912      1857567 :   return mangle_special_for_type (type, "TV");
    4913              : }
    4914              : 
    4915              : /* Returns an identifier for the mangled name of the VTT for TYPE.  */
    4916              : 
    4917              : tree
    4918       178794 : mangle_vtt_for_type (const tree type)
    4919              : {
    4920       178794 :   return mangle_special_for_type (type, "TT");
    4921              : }
    4922              : 
    4923              : /* Returns an identifier for the mangled name of the decomposition
    4924              :    artificial variable DECL.  DECLS is the vector of the VAR_DECLs
    4925              :    for the identifier-list.  */
    4926              : 
    4927              : tree
    4928          761 : mangle_decomp (const tree decl, vec<tree> &decls)
    4929              : {
    4930          761 :   gcc_assert (!type_dependent_expression_p (decl));
    4931              : 
    4932          761 :   location_t saved_loc = input_location;
    4933          761 :   input_location = DECL_SOURCE_LOCATION (decl);
    4934              : 
    4935          761 :   check_abi_tags (decl);
    4936          761 :   start_mangling (decl);
    4937          761 :   write_string ("_Z");
    4938              : 
    4939          761 :   tree context = decl_mangling_context (decl);
    4940          761 :   gcc_assert (context != NULL_TREE);
    4941              : 
    4942          761 :   bool nested = false;
    4943          761 :   bool local = false;
    4944          761 :   if (DECL_NAMESPACE_STD_P (context))
    4945            9 :     write_string ("St");
    4946          752 :   else if (TREE_CODE (context) == FUNCTION_DECL)
    4947              :     {
    4948          261 :       local = true;
    4949          261 :       write_char ('Z');
    4950          261 :       write_encoding (context);
    4951          261 :       write_char ('E');
    4952              :     }
    4953          491 :   else if (context != global_namespace)
    4954              :     {
    4955           94 :       nested = true;
    4956           94 :       write_char ('N');
    4957           94 :       write_prefix (context);
    4958              :     }
    4959              : 
    4960          761 :   write_string ("DC");
    4961          761 :   unsigned int i;
    4962          761 :   tree d;
    4963         2633 :   FOR_EACH_VEC_ELT (decls, i, d)
    4964         1872 :     write_unqualified_name (d);
    4965          761 :   write_char ('E');
    4966              : 
    4967          761 :   if (tree tags = get_abi_tags (decl))
    4968              :     {
    4969              :       /* We didn't emit ABI tags for structured bindings before ABI 19.  */
    4970           30 :       if (!G.need_abi_warning
    4971           30 :           && TREE_PUBLIC (decl)
    4972          120 :           && abi_warn_or_compat_version_crosses (19))
    4973           30 :         G.need_abi_warning = 1;
    4974              : 
    4975           30 :       if (abi_version_at_least (19))
    4976           30 :         write_abi_tags (tags);
    4977              :     }
    4978              : 
    4979          761 :   if (nested)
    4980           94 :     write_char ('E');
    4981          667 :   else if (local && DECL_DISCRIMINATOR_P (decl))
    4982          261 :     write_discriminator (discriminator_for_local_entity (decl));
    4983              : 
    4984          761 :   tree id = finish_mangling_get_identifier ();
    4985          761 :   if (DEBUG_MANGLE)
    4986              :     fprintf (stderr, "mangle_decomp = '%s'\n\n",
    4987              :              IDENTIFIER_POINTER (id));
    4988              : 
    4989          761 :   input_location = saved_loc;
    4990              : 
    4991          761 :   if (warn_abi && G.need_abi_warning)
    4992              :     {
    4993            0 :       const char fabi_version[] = "-fabi-version";
    4994            0 :       tree id2 = id;
    4995            0 :       int save_ver = flag_abi_version;
    4996              : 
    4997            0 :       if (flag_abi_version != warn_abi_version)
    4998              :         {
    4999            0 :           flag_abi_version = warn_abi_version;
    5000            0 :           id2 = mangle_decomp (decl, decls);
    5001            0 :           flag_abi_version = save_ver;
    5002              :         }
    5003              : 
    5004            0 :       if (id2 == id)
    5005              :         /* OK.  */;
    5006            0 :       else if (warn_abi_version != 0
    5007            0 :                && abi_version_at_least (warn_abi_version))
    5008            0 :         warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
    5009              :                     "the mangled name of %qD changed between "
    5010              :                     "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
    5011              :                     G.entity, fabi_version, warn_abi_version, id2,
    5012              :                     fabi_version, save_ver, id);
    5013              :       else
    5014            0 :         warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
    5015              :                     "the mangled name of %qD changes between "
    5016              :                     "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
    5017              :                     G.entity, fabi_version, save_ver, id,
    5018              :                     fabi_version, warn_abi_version, id2);
    5019              :     }
    5020              : 
    5021          761 :   return id;
    5022              : }
    5023              : 
    5024              : /* Return an identifier for a construction vtable group.  TYPE is
    5025              :    the most derived class in the hierarchy; BINFO is the base
    5026              :    subobject for which this construction vtable group will be used.
    5027              : 
    5028              :    This mangling isn't part of the ABI specification; in the ABI
    5029              :    specification, the vtable group is dumped in the same COMDAT as the
    5030              :    main vtable, and is referenced only from that vtable, so it doesn't
    5031              :    need an external name.  For binary formats without COMDAT sections,
    5032              :    though, we need external names for the vtable groups.
    5033              : 
    5034              :    We use the production
    5035              : 
    5036              :     <special-name> ::= CT <type> <offset number> _ <base type>  */
    5037              : 
    5038              : tree
    5039       245537 : mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
    5040              : {
    5041       245537 :   tree result;
    5042              : 
    5043       245537 :   start_mangling (type);
    5044              : 
    5045       245537 :   write_string ("_Z");
    5046       245537 :   write_string ("TC");
    5047       245537 :   write_type (type);
    5048       245537 :   write_integer_cst (BINFO_OFFSET (binfo));
    5049       245537 :   write_char ('_');
    5050       245537 :   write_type (BINFO_TYPE (binfo));
    5051              : 
    5052       245537 :   result = finish_mangling_get_identifier ();
    5053       245537 :   if (DEBUG_MANGLE)
    5054              :     fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n",
    5055              :              IDENTIFIER_POINTER (result));
    5056       245537 :   return result;
    5057              : }
    5058              : 
    5059              : /* Mangle a this pointer or result pointer adjustment.
    5060              : 
    5061              :    <call-offset> ::= h <fixed offset number> _
    5062              :                  ::= v <fixed offset number> _ <virtual offset number> _ */
    5063              : 
    5064              : static void
    5065       468179 : mangle_call_offset (const tree fixed_offset, const tree virtual_offset)
    5066              : {
    5067       468179 :   write_char (virtual_offset ? 'v' : 'h');
    5068              : 
    5069              :   /* For either flavor, write the fixed offset.  */
    5070       468179 :   write_integer_cst (fixed_offset);
    5071       468179 :   write_char ('_');
    5072              : 
    5073              :   /* For a virtual thunk, add the virtual offset.  */
    5074       468179 :   if (virtual_offset)
    5075              :     {
    5076       350544 :       write_integer_cst (virtual_offset);
    5077       350544 :       write_char ('_');
    5078              :     }
    5079       468179 : }
    5080              : 
    5081              : /* Return an identifier for the mangled name of a this-adjusting or
    5082              :    covariant thunk to FN_DECL.  FIXED_OFFSET is the initial adjustment
    5083              :    to this used to find the vptr.  If VIRTUAL_OFFSET is non-NULL, this
    5084              :    is a virtual thunk, and it is the vtbl offset in
    5085              :    bytes. THIS_ADJUSTING is nonzero for a this adjusting thunk and
    5086              :    zero for a covariant thunk. Note, that FN_DECL might be a covariant
    5087              :    thunk itself. A covariant thunk name always includes the adjustment
    5088              :    for the this pointer, even if there is none.
    5089              : 
    5090              :    <special-name> ::= T <call-offset> <base encoding>
    5091              :                   ::= Tc <this_adjust call-offset> <result_adjust call-offset>
    5092              :                                         <base encoding>  */
    5093              : 
    5094              : tree
    5095       467798 : mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
    5096              :               tree virtual_offset, tree thunk)
    5097              : {
    5098       467798 :   tree result;
    5099              : 
    5100       467798 :   if (abi_version_at_least (11))
    5101       467795 :     maybe_check_abi_tags (fn_decl, thunk, 11);
    5102              : 
    5103       467798 :   start_mangling (fn_decl);
    5104              : 
    5105       467798 :   write_string ("_Z");
    5106       467798 :   write_char ('T');
    5107              : 
    5108       467798 :   if (!this_adjusting)
    5109              :     {
    5110              :       /* Covariant thunk with no this adjustment */
    5111          214 :       write_char ('c');
    5112          214 :       mangle_call_offset (integer_zero_node, NULL_TREE);
    5113          214 :       mangle_call_offset (fixed_offset, virtual_offset);
    5114              :     }
    5115       467584 :   else if (!DECL_THUNK_P (fn_decl))
    5116              :     /* Plain this adjusting thunk.  */
    5117       467417 :     mangle_call_offset (fixed_offset, virtual_offset);
    5118              :   else
    5119              :     {
    5120              :       /* This adjusting thunk to covariant thunk.  */
    5121          167 :       write_char ('c');
    5122          167 :       mangle_call_offset (fixed_offset, virtual_offset);
    5123          167 :       fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn_decl));
    5124          167 :       virtual_offset = THUNK_VIRTUAL_OFFSET (fn_decl);
    5125          167 :       if (virtual_offset)
    5126          124 :         virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
    5127          167 :       mangle_call_offset (fixed_offset, virtual_offset);
    5128          167 :       fn_decl = THUNK_TARGET (fn_decl);
    5129              :     }
    5130              : 
    5131              :   /* Scoped name.  */
    5132       467798 :   write_encoding (fn_decl);
    5133              : 
    5134       467798 :   result = finish_mangling_get_identifier ();
    5135       467798 :   if (DEBUG_MANGLE)
    5136              :     fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
    5137       467798 :   return result;
    5138              : }
    5139              : 
    5140              : /* Handle ABI backwards compatibility for past bugs where we didn't call
    5141              :    check_abi_tags in places where it's needed: call check_abi_tags and warn if
    5142              :    it makes a difference.  If FOR_DECL is non-null, it's the declaration
    5143              :    that we're actually trying to mangle; if it's null, we're mangling the
    5144              :    guard variable for T.  */
    5145              : 
    5146              : static void
    5147      5494744 : maybe_check_abi_tags (tree t, tree for_decl, int ver)
    5148              : {
    5149      5494744 :   if (DECL_ASSEMBLER_NAME_SET_P (t))
    5150              :     return;
    5151              : 
    5152       859422 :   tree oldtags = get_abi_tags (t);
    5153              : 
    5154       859422 :   mangle_decl (t);
    5155              : 
    5156       859422 :   tree newtags = get_abi_tags (t);
    5157       859422 :   if (newtags && newtags != oldtags
    5158           30 :       && abi_version_crosses (ver))
    5159              :     {
    5160           12 :       if (for_decl && DECL_THUNK_P (for_decl))
    5161            3 :         warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
    5162              :                     "the mangled name of a thunk for %qD changes between "
    5163              :                     "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
    5164              :                     t, flag_abi_version, warn_abi_version);
    5165            9 :       else if (for_decl)
    5166            6 :         warning_at (DECL_SOURCE_LOCATION (for_decl), OPT_Wabi,
    5167              :                     "the mangled name of %qD changes between "
    5168              :                     "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
    5169              :                     for_decl, flag_abi_version, warn_abi_version);
    5170              :       else
    5171            3 :         warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
    5172              :                     "the mangled name of the initialization guard variable "
    5173              :                     "for %qD changes between %<-fabi-version=%d%> and "
    5174              :                     "%<-fabi-version=%d%>",
    5175              :                     t, flag_abi_version, warn_abi_version);
    5176              :     }
    5177              : }
    5178              : 
    5179              : /* Write out the appropriate string for this variable when generating
    5180              :    another mangled name based on this one.  */
    5181              : 
    5182              : static void
    5183         7496 : write_guarded_var_name (const tree variable)
    5184              : {
    5185         7496 :   if (DECL_NAME (variable)
    5186         7496 :       && startswith (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR"))
    5187              :     /* The name of a guard variable for a reference temporary should refer
    5188              :        to the reference, not the temporary.  */
    5189           18 :     write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
    5190         7478 :   else if (DECL_DECOMPOSITION_P (variable)
    5191          829 :            && DECL_NAME (variable) == NULL_TREE
    5192         7746 :            && startswith (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)),
    5193              :                           "_Z"))
    5194              :     /* The name of a guard variable for a structured binding needs special
    5195              :        casing.  */
    5196          268 :     write_string (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)) + 2);
    5197              :   else
    5198         7210 :     write_name (variable, /*ignore_local_scope=*/0);
    5199         7496 : }
    5200              : 
    5201              : /* Return an identifier for the name of an initialization guard
    5202              :    variable for indicated VARIABLE.  */
    5203              : 
    5204              : tree
    5205         4735 : mangle_guard_variable (const tree variable)
    5206              : {
    5207         4735 :   if (abi_version_at_least (10))
    5208         4729 :     maybe_check_abi_tags (variable);
    5209         4735 :   start_mangling (variable);
    5210         4735 :   write_string ("_ZGV");
    5211         4735 :   write_guarded_var_name (variable);
    5212         4735 :   return finish_mangling_get_identifier ();
    5213              : }
    5214              : 
    5215              : /* Return an identifier for the name of a thread_local initialization
    5216              :    function for VARIABLE.  */
    5217              : 
    5218              : tree
    5219         1202 : mangle_tls_init_fn (const tree variable)
    5220              : {
    5221         1202 :   check_abi_tags (variable);
    5222         1202 :   start_mangling (variable);
    5223         1202 :   write_string ("_ZTH");
    5224         1202 :   write_guarded_var_name (variable);
    5225         1202 :   return finish_mangling_get_identifier ();
    5226              : }
    5227              : 
    5228              : /* Return an identifier for the name of a thread_local wrapper
    5229              :    function for VARIABLE.  */
    5230              : 
    5231              : #define TLS_WRAPPER_PREFIX "_ZTW"
    5232              : 
    5233              : tree
    5234          749 : mangle_tls_wrapper_fn (const tree variable)
    5235              : {
    5236          749 :   check_abi_tags (variable);
    5237          749 :   start_mangling (variable);
    5238          749 :   write_string (TLS_WRAPPER_PREFIX);
    5239          749 :   write_guarded_var_name (variable);
    5240          749 :   return finish_mangling_get_identifier ();
    5241              : }
    5242              : 
    5243              : /* Return true iff FN is a thread_local wrapper function.  */
    5244              : 
    5245              : bool
    5246      2207037 : decl_tls_wrapper_p (const tree fn)
    5247              : {
    5248      2207037 :   if (TREE_CODE (fn) != FUNCTION_DECL)
    5249              :     return false;
    5250      1708178 :   tree name = DECL_NAME (fn);
    5251      1708178 :   return startswith (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX);
    5252              : }
    5253              : 
    5254              : /* Return an identifier for the name of a temporary variable used to
    5255              :    initialize a static reference.  This is now part of the ABI.  */
    5256              : 
    5257              : tree
    5258          810 : mangle_ref_init_variable (const tree variable)
    5259              : {
    5260          810 :   start_mangling (variable);
    5261          810 :   write_string ("_ZGR");
    5262          810 :   check_abi_tags (variable);
    5263          810 :   write_guarded_var_name (variable);
    5264              :   /* Avoid name clashes with aggregate initialization of multiple
    5265              :      references at once.  */
    5266          810 :   write_compact_number (current_ref_temp_count++);
    5267          810 :   return finish_mangling_get_identifier ();
    5268              : }
    5269              : 
    5270              : /* Return an identifier for the mangled name of a C++20 template parameter
    5271              :    object for template argument EXPR.  */
    5272              : 
    5273              : tree
    5274        10814 : mangle_template_parm_object (tree expr)
    5275              : {
    5276        10814 :   start_mangling (expr);
    5277        10814 :   write_string ("_ZTAX");
    5278        10814 :   write_expression (expr);
    5279        10814 :   write_char ('E');
    5280        10814 :   return finish_mangling_get_identifier ();
    5281              : }
    5282              : 
    5283              : /* Given a CLASS_TYPE, such as a record for std::bad_exception this
    5284              :    function generates a mangled name for the vtable map variable of
    5285              :    the class type.  For example, if the class type is
    5286              :    "std::bad_exception", the mangled name for the class is
    5287              :    "St13bad_exception".  This function would generate the name
    5288              :    "_ZN4_VTVISt13bad_exceptionE12__vtable_mapE", which unmangles as:
    5289              :    "_VTV<std::bad_exception>::__vtable_map".  */
    5290              : 
    5291              : 
    5292              : char *
    5293            6 : get_mangled_vtable_map_var_name (tree class_type)
    5294              : {
    5295            6 :   char *var_name = NULL;
    5296            6 :   const char *prefix = "_ZN4_VTVI";
    5297            6 :   const char *postfix = "E12__vtable_mapE";
    5298              : 
    5299            6 :   gcc_assert (TREE_CODE (class_type) == RECORD_TYPE);
    5300              : 
    5301            6 :   tree class_id = DECL_ASSEMBLER_NAME (TYPE_NAME (class_type));
    5302              : 
    5303            6 :   if (strstr (IDENTIFIER_POINTER (class_id), "<anon>") != NULL)
    5304              :     {
    5305            0 :       class_id = get_mangled_id (TYPE_NAME (class_type));
    5306            0 :       vtbl_register_mangled_name (TYPE_NAME (class_type), class_id);
    5307              :     }
    5308              : 
    5309            6 :   unsigned int len = strlen (IDENTIFIER_POINTER (class_id)) +
    5310              :                      strlen (prefix) +
    5311            6 :                      strlen (postfix) + 1;
    5312              : 
    5313            6 :   var_name = (char *) xmalloc (len);
    5314              : 
    5315            6 :   sprintf (var_name, "%s%s%s", prefix, IDENTIFIER_POINTER (class_id), postfix);
    5316              : 
    5317            6 :   return var_name;
    5318              : }
    5319              : 
    5320              : #include "gt-cp-mangle.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.