LCOV - code coverage report
Current view: top level - gcc/cp - mangle.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.4 % 2095 1936
Test Date: 2024-04-20 14:03:02 Functions: 95.4 % 108 103
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

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