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