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