Branch data Line data Source code
1 : : /* Name mangling for the 3.0 -*- C++ -*- ABI.
2 : : Copyright (C) 2000-2025 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 : 10230665 : abi_check (int ver)
284 : : {
285 : 51093511 : if (abi_warn_or_compat_version_crosses (ver))
286 : 31244 : G.need_abi_warning = true;
287 : 10230665 : 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 : 1137652370 : maybe_template_info (const tree decl)
295 : : {
296 : 1137652370 : 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 : 445527121 : const tree type = TREE_TYPE (decl);
301 : :
302 : 445527121 : if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_ID_P (type))
303 : 355542910 : return TYPE_TEMPLATE_INFO (type);
304 : : }
305 : : else
306 : : {
307 : : /* Check if the template is a primary template. */
308 : 692125249 : if (DECL_LANG_SPECIFIC (decl) != NULL
309 : 690855816 : && VAR_OR_FUNCTION_DECL_P (decl)
310 : 594389171 : && DECL_TEMPLATE_INFO (decl)
311 : 1154932371 : && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
312 : 64807735 : 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 : 3081693 : write_exception_spec (tree spec)
364 : : {
365 : :
366 : 3081693 : if (!spec || spec == noexcept_false_spec)
367 : : /* Nothing. */
368 : : return;
369 : :
370 : 15410 : if (!flag_noexcept_type)
371 : : {
372 : 17 : G.need_cxx17_warning = true;
373 : 17 : return;
374 : : }
375 : :
376 : 15393 : if (spec == noexcept_true_spec || spec == empty_except_spec)
377 : 15378 : 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 : 4010959029 : canonicalize_for_substitution (tree node)
405 : : {
406 : : /* For a TYPE_DECL, use the type instead. */
407 : 4010959029 : if (TREE_CODE (node) == TYPE_DECL)
408 : 644 : node = TREE_TYPE (node);
409 : 4010959029 : if (TYPE_P (node)
410 : 2965942058 : && TYPE_CANONICAL (node) != node
411 : 4340852066 : && TYPE_MAIN_VARIANT (node) != node)
412 : : {
413 : 93371485 : 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 : 93371485 : 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 : 7344 : node = build_qualified_type (TYPE_MAIN_VARIANT (node),
421 : 7344 : TYPE_QUALS (node));
422 : : else
423 : 93364141 : node = cp_build_qualified_type (TYPE_MAIN_VARIANT (node),
424 : : cp_type_quals (node));
425 : 93371485 : if (FUNC_OR_METHOD_TYPE_P (node))
426 : : {
427 : 7353 : node = build_ref_qualified_type (node, type_memfn_rqual (orig));
428 : 7353 : tree r = canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (orig));
429 : 7353 : if (flag_noexcept_type)
430 : 7309 : node = build_exception_variant (node, r);
431 : : else
432 : : /* Set the warning flag if appropriate. */
433 : 44 : write_exception_spec (r);
434 : : }
435 : : }
436 : 4010959029 : 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 : 1032426149 : add_substitution (tree node)
444 : : {
445 : 1032426149 : tree c;
446 : :
447 : 1032426149 : 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 : 1032426149 : c = canonicalize_for_substitution (node);
453 : 1032426149 : 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 : 1032426149 : node = c;
457 : :
458 : : /* Make sure NODE isn't already a candidate. */
459 : 1032426149 : if (flag_checking)
460 : : {
461 : : int i;
462 : : tree candidate;
463 : :
464 : 5567452151 : FOR_EACH_VEC_SAFE_ELT (G.substitutions, i, candidate)
465 : 4535026117 : if (candidate)
466 : : {
467 : 4535020462 : gcc_assert (!(DECL_P (node) && node == candidate));
468 : 4535020462 : 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 : 1032426149 : vec_safe_push (G.substitutions, node);
475 : :
476 : 1032426149 : if (DEBUG_MANGLE)
477 : : dump_substitution_candidates ();
478 : 1032426149 : }
479 : :
480 : : /* Helper function for find_substitution. Returns nonzero if NODE,
481 : : which may be a decl or a CLASS_TYPE, 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 : 3537054419 : is_std_substitution (const tree node,
487 : : const substitution_identifier_index_t index)
488 : : {
489 : 3537054419 : tree type = NULL;
490 : 3537054419 : tree decl = NULL;
491 : :
492 : 3537054419 : if (DECL_P (node))
493 : : {
494 : 3512269597 : type = TREE_TYPE (node);
495 : 3512269597 : decl = node;
496 : : }
497 : 24784822 : else if (CLASS_TYPE_P (node))
498 : : {
499 : 4717237 : type = node;
500 : 4717237 : decl = TYPE_NAME (node);
501 : : }
502 : : else
503 : : /* These are not the droids you're looking for. */
504 : : return false;
505 : :
506 : 3516986834 : if (!DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl)))
507 : : return false;
508 : :
509 : 1382110385 : if (!(TYPE_LANG_SPECIFIC (type) && TYPE_TEMPLATE_INFO (type)))
510 : : return false;
511 : :
512 : 1056370317 : tree tmpl = TYPE_TI_TEMPLATE (type);
513 : 1056370317 : if (DECL_NAME (tmpl) != subst_identifiers[index])
514 : : return false;
515 : :
516 : 124370378 : if (modules_p () && get_originating_module (tmpl, true) >= 0)
517 : 27 : return false;
518 : :
519 : : return true;
520 : : }
521 : :
522 : : /* Return the ABI tags (the TREE_VALUE of the "abi_tag" attribute entry) for T,
523 : : which can be a decl or type. */
524 : :
525 : : static tree
526 : 1546287433 : get_abi_tags (tree t)
527 : : {
528 : 1546287433 : if (!t || TREE_CODE (t) == NAMESPACE_DECL)
529 : : return NULL_TREE;
530 : :
531 : 1450367477 : if (DECL_P (t) && DECL_DECLARES_TYPE_P (t))
532 : 395405044 : t = TREE_TYPE (t);
533 : :
534 : 1450367477 : if (TREE_CODE (t) == TEMPLATE_DECL && DECL_TEMPLATE_RESULT (t))
535 : : {
536 : 8982611 : tree tags = get_abi_tags (DECL_TEMPLATE_RESULT (t));
537 : : /* We used to overlook abi_tag on function and variable templates. */
538 : 8982611 : if (tags && abi_check (19))
539 : : return tags;
540 : : else
541 : 8982601 : return NULL_TREE;
542 : : }
543 : :
544 : 1441384866 : tree attrs;
545 : 1441384866 : if (TYPE_P (t))
546 : 1262135476 : attrs = TYPE_ATTRIBUTES (t);
547 : : else
548 : 179249390 : attrs = DECL_ATTRIBUTES (t);
549 : :
550 : 1441384866 : tree tags = lookup_attribute ("abi_tag", attrs);
551 : 1441384866 : if (tags)
552 : 10109855 : tags = TREE_VALUE (tags);
553 : : return tags;
554 : : }
555 : :
556 : : /* Helper function for find_substitution. Returns nonzero if NODE,
557 : : which may be a decl or a CLASS_TYPE, is the template-id
558 : : ::std::identifier<char>, where identifier is
559 : : substitution_index[INDEX]. */
560 : :
561 : : static bool
562 : 6462300 : is_std_substitution_char (const tree node,
563 : : const substitution_identifier_index_t index)
564 : : {
565 : 6462300 : tree args;
566 : : /* Check NODE's name is ::std::identifier. */
567 : 6462300 : if (!is_std_substitution (node, index))
568 : : return 0;
569 : : /* Figure out its template args. */
570 : 4316230 : if (DECL_P (node))
571 : 0 : args = DECL_TI_ARGS (node);
572 : 4316230 : else if (CLASS_TYPE_P (node))
573 : 4316230 : args = CLASSTYPE_TI_ARGS (node);
574 : : else
575 : : /* Oops, not a template. */
576 : : return 0;
577 : : /* NODE's template arg list should be <char>. */
578 : 4316230 : return
579 : 4316230 : TREE_VEC_LENGTH (args) == 1
580 : 4316230 : && TREE_VEC_ELT (args, 0) == char_type_node;
581 : : }
582 : :
583 : : /* Check whether a substitution should be used to represent NODE in
584 : : the mangling.
585 : :
586 : : First, check standard special-case substitutions.
587 : :
588 : : <substitution> ::= St
589 : : # ::std
590 : :
591 : : ::= Sa
592 : : # ::std::allocator
593 : :
594 : : ::= Sb
595 : : # ::std::basic_string
596 : :
597 : : ::= Ss
598 : : # ::std::basic_string<char,
599 : : ::std::char_traits<char>,
600 : : ::std::allocator<char> >
601 : :
602 : : ::= Si
603 : : # ::std::basic_istream<char, ::std::char_traits<char> >
604 : :
605 : : ::= So
606 : : # ::std::basic_ostream<char, ::std::char_traits<char> >
607 : :
608 : : ::= Sd
609 : : # ::std::basic_iostream<char, ::std::char_traits<char> >
610 : :
611 : : Then examine the stack of currently available substitution
612 : : candidates for entities appearing earlier in the same mangling
613 : :
614 : : If a substitution is found, write its mangled representation and
615 : : return nonzero. If none is found, just return zero. */
616 : :
617 : : static int
618 : 1914902903 : find_substitution (tree node)
619 : : {
620 : 1914902903 : int i;
621 : 1914902903 : const int size = vec_safe_length (G.substitutions);
622 : 1914902903 : tree decl;
623 : 1914902903 : tree type;
624 : 1914902903 : const char *abbr = NULL;
625 : :
626 : 1914902903 : if (DEBUG_MANGLE)
627 : : fprintf (stderr, " ++ find_substitution (%s at %p)\n",
628 : : get_tree_code_name (TREE_CODE (node)), (void *) node);
629 : :
630 : : /* Obtain the canonicalized substitution representation for NODE.
631 : : This is what we'll compare against. */
632 : 1914902903 : node = canonicalize_for_substitution (node);
633 : :
634 : : /* Check for builtin substitutions. */
635 : :
636 : 1914902903 : decl = TYPE_P (node) ? TYPE_NAME (node) : node;
637 : 1914902903 : type = TYPE_P (node) ? node : TREE_TYPE (node);
638 : :
639 : : /* Check for std::allocator. */
640 : 1914902903 : if (decl
641 : 1786630765 : && is_std_substitution (decl, SUBID_ALLOCATOR)
642 : 2033868974 : && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
643 : : abbr = "Sa";
644 : :
645 : : /* Check for std::basic_string. */
646 : 1860527248 : else if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
647 : : {
648 : 141260 : if (TYPE_P (node))
649 : : {
650 : : /* If this is a type (i.e. a fully-qualified template-id),
651 : : check for
652 : : std::basic_string <char,
653 : : std::char_traits<char>,
654 : : std::allocator<char> > . */
655 : 99820 : if (cp_type_quals (type) == TYPE_UNQUALIFIED
656 : 99820 : && CLASSTYPE_USE_TEMPLATE (type))
657 : : {
658 : 89002 : tree args = CLASSTYPE_TI_ARGS (type);
659 : 89002 : if (TREE_VEC_LENGTH (args) == 3
660 : 88984 : && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
661 : 38125 : && is_std_substitution_char (TREE_VEC_ELT (args, 1),
662 : : SUBID_CHAR_TRAITS)
663 : 127116 : && is_std_substitution_char (TREE_VEC_ELT (args, 2),
664 : : SUBID_ALLOCATOR))
665 : : abbr = "Ss";
666 : : }
667 : : }
668 : : else
669 : : /* Substitute for the template name only if this isn't a type. */
670 : : abbr = "Sb";
671 : : }
672 : :
673 : : /* Check for basic_{i,o,io}stream. */
674 : 1860385988 : else if (TYPE_P (node)
675 : 1246811818 : && cp_type_quals (type) == TYPE_UNQUALIFIED
676 : 1178928594 : && CLASS_TYPE_P (type)
677 : 501040650 : && CLASSTYPE_USE_TEMPLATE (type)
678 : 2233671752 : && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
679 : : {
680 : : /* First, check for the template
681 : : args <char, std::char_traits<char> > . */
682 : 373285764 : tree args = CLASSTYPE_TI_ARGS (type);
683 : 373285764 : if (TREE_VEC_LENGTH (args) == 2
684 : 111005139 : && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
685 : 379671825 : && is_std_substitution_char (TREE_VEC_ELT (args, 1),
686 : : SUBID_CHAR_TRAITS))
687 : : {
688 : : /* Got them. Is this basic_istream? */
689 : 4239997 : if (is_std_substitution (decl, SUBID_BASIC_ISTREAM))
690 : : abbr = "Si";
691 : : /* Or basic_ostream? */
692 : 3931515 : else if (is_std_substitution (decl, SUBID_BASIC_OSTREAM))
693 : : abbr = "So";
694 : : /* Or basic_iostream? */
695 : 3534732 : else if (is_std_substitution (decl, SUBID_BASIC_IOSTREAM))
696 : 1735605097 : abbr = "Sd";
697 : : }
698 : : }
699 : :
700 : : /* Check for namespace std. */
701 : 1487100224 : else if (decl && DECL_NAMESPACE_STD_P (decl))
702 : : {
703 : 179297806 : write_string ("St");
704 : 179297806 : return 1;
705 : : }
706 : :
707 : 1735605097 : tree tags = NULL_TREE;
708 : 1735605097 : if (OVERLOAD_TYPE_P (node) || DECL_CLASS_TEMPLATE_P (node))
709 : 866730432 : tags = get_abi_tags (type);
710 : : /* Now check the list of available substitutions for this mangling
711 : : operation. */
712 : 1735605097 : if (!abbr || tags)
713 : 7779967586 : for (i = 0; i < size; ++i)
714 : 6246666256 : if (tree candidate = (*G.substitutions)[i])
715 : : {
716 : : /* NODE is a matched to a candidate if it's the same decl node or
717 : : if it's the same type. */
718 : 6246658515 : if (decl == candidate
719 : 6192531367 : || (TYPE_P (candidate) && type && TYPE_P (node)
720 : 2728287125 : && same_type_p (type, candidate))
721 : 12347093492 : || NESTED_TEMPLATE_MATCH (node, candidate))
722 : : {
723 : 146901777 : write_substitution (i);
724 : 146901777 : return 1;
725 : : }
726 : : }
727 : :
728 : 1533301330 : if (!abbr)
729 : : /* No substitution found. */
730 : : return 0;
731 : :
732 : 55401996 : write_string (abbr);
733 : 55401996 : if (tags)
734 : : {
735 : : /* If there are ABI tags on the abbreviation, it becomes
736 : : a substitution candidate. */
737 : 6 : write_abi_tags (tags);
738 : 6 : add_substitution (node);
739 : : }
740 : : return 1;
741 : : }
742 : :
743 : : /* Returns whether DECL's symbol name should be the plain unqualified-id
744 : : rather than a more complicated mangled name. */
745 : :
746 : : static bool
747 : 175104770 : unmangled_name_p (const tree decl)
748 : : {
749 : 175104770 : if (TREE_CODE (decl) == FUNCTION_DECL)
750 : : {
751 : : /* The names of `extern "C"' functions are not mangled. */
752 : 155343878 : return (DECL_EXTERN_C_FUNCTION_P (decl)
753 : : /* But overloaded operator names *are* mangled. */
754 : 2215895 : && !DECL_OVERLOADED_OPERATOR_P (decl));
755 : : }
756 : 19760892 : else if (VAR_P (decl))
757 : : {
758 : : /* static variables are mangled. */
759 : 19757722 : if (!DECL_EXTERNAL_LINKAGE_P (decl))
760 : : return false;
761 : :
762 : : /* extern "C" declarations aren't mangled. */
763 : 19541912 : if (DECL_EXTERN_C_P (decl))
764 : : return true;
765 : :
766 : : /* Other variables at non-global scope are mangled. */
767 : 19328691 : if (CP_DECL_CONTEXT (decl) != global_namespace)
768 : : return false;
769 : :
770 : : /* Variable template instantiations are mangled. */
771 : 106581 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
772 : 105055 : && variable_template_p (DECL_TI_TEMPLATE (decl)))
773 : : return false;
774 : :
775 : : /* Declarations with ABI tags are mangled. */
776 : 101989 : if (get_abi_tags (decl))
777 : : return false;
778 : :
779 : : // Declarations attached to a named module are mangled
780 : 101641 : if (modules_p () && get_originating_module (decl, true) >= 0)
781 : : return false;
782 : :
783 : : /* The names of non-static global variables aren't mangled. */
784 : : return true;
785 : : }
786 : :
787 : : return false;
788 : : }
789 : :
790 : : /* TOP_LEVEL is true, if this is being called at outermost level of
791 : : mangling. It should be false when mangling a decl appearing in an
792 : : expression within some other mangling.
793 : :
794 : : <mangled-name> ::= _Z <encoding> */
795 : :
796 : : static void
797 : 175104770 : write_mangled_name (const tree decl, bool top_level)
798 : : {
799 : 175104770 : MANGLE_TRACE_TREE ("mangled-name", decl);
800 : :
801 : 175104770 : check_abi_tags (decl);
802 : :
803 : 175104770 : if (unmangled_name_p (decl))
804 : : {
805 : 2530374 : if (top_level)
806 : 2530202 : write_string (IDENTIFIER_POINTER (DECL_NAME (decl)));
807 : : else
808 : : {
809 : : /* The standard notes: "The <encoding> of an extern "C"
810 : : function is treated like global-scope data, i.e. as its
811 : : <source-name> without a type." We cannot write
812 : : overloaded operators that way though, because it contains
813 : : characters invalid in assembler. */
814 : 172 : write_string ("_Z");
815 : 172 : write_source_name (DECL_NAME (decl));
816 : : }
817 : : }
818 : : else
819 : : {
820 : 172574396 : write_string ("_Z");
821 : 172574396 : write_encoding (decl);
822 : : }
823 : :
824 : : /* If this is the pre/post function for a guarded function, append
825 : : .pre/post, like something from create_virtual_clone. */
826 : 175104770 : if (DECL_IS_PRE_FN_P (decl))
827 : 289 : write_string (".pre");
828 : 175104481 : else if (DECL_IS_POST_FN_P (decl))
829 : 63 : write_string (".post");
830 : :
831 : : /* If this is a coroutine helper, then append an appropriate string to
832 : : identify which. */
833 : 175104770 : if (tree ramp = DECL_RAMP_FN (decl))
834 : : {
835 : 2956 : if (DECL_ACTOR_FN (ramp) == decl)
836 : 1478 : write_string (JOIN_STR "actor");
837 : 1478 : else if (DECL_DESTROY_FN (ramp) == decl)
838 : 1478 : write_string (JOIN_STR "destroy");
839 : : else
840 : 0 : gcc_unreachable ();
841 : : }
842 : 175104770 : }
843 : :
844 : : /* Returns true if the return type of DECL is part of its signature, and
845 : : therefore its mangling. */
846 : :
847 : : bool
848 : 311506375 : mangle_return_type_p (tree decl)
849 : : {
850 : 311506375 : return (!DECL_CONSTRUCTOR_P (decl)
851 : 261312563 : && !DECL_DESTRUCTOR_P (decl)
852 : 247883602 : && !DECL_CONV_FN_P (decl)
853 : 557589744 : && maybe_template_info (decl));
854 : : }
855 : :
856 : : /* <constraint-expression> ::= <expression> */
857 : :
858 : : static void
859 : 1846220 : write_constraint_expression (tree expr)
860 : : {
861 : 0 : write_expression (expr);
862 : 78305 : }
863 : :
864 : : /* Mangle a requires-clause following a template-head, if any.
865 : :
866 : : Q <constraint_expression> E */
867 : :
868 : : static void
869 : 344440378 : write_tparms_constraints (tree constraints)
870 : : {
871 : : /* In a declaration with shorthand constraints in the template-head, followed
872 : : by a requires-clause, followed by shorthand constraints in the
873 : : function-parameter-list, the full constraints will be some && with the
874 : : parameter constraints on the RHS, around an && with the requires-clause on
875 : : the RHS. Find the requires-clause, if any.
876 : :
877 : : This logic relies on the && and ... from combine_constraint_expressions,
878 : : finish_shorthand_constraint, and convert_generic_types_to_packs having
879 : : UNKNOWN_LOCATION. If they need to have an actual location, we could move
880 : : to using a TREE_LANG_FLAG. */
881 : 344440378 : if (constraints && abi_check (19))
882 : : {
883 : : tree probe = constraints;
884 : : while (probe
885 : 138226 : && !EXPR_LOCATION (probe)
886 : 198150 : && TREE_CODE (probe) == TRUTH_ANDIF_EXPR)
887 : : {
888 : 127 : tree op1 = TREE_OPERAND (probe, 1);
889 : 235 : probe = (EXPR_LOCATION (op1) ? op1
890 : 108 : : TREE_OPERAND (probe, 0));
891 : : }
892 : 138099 : if (probe && EXPR_LOCATION (probe))
893 : : {
894 : 78302 : write_char ('Q');
895 : 78302 : write_constraint_expression (probe);
896 : : }
897 : : }
898 : 344440378 : }
899 : :
900 : : /* <type-constraint> ::= <name> */
901 : :
902 : : static void
903 : 113648 : write_type_constraint (tree cnst)
904 : : {
905 : 113648 : if (!cnst)
906 : : return;
907 : :
908 : 113648 : gcc_checking_assert (TREE_CODE (cnst) == TEMPLATE_ID_EXPR);
909 : :
910 : 113648 : tree concept_decl = get_concept_check_template (cnst);
911 : 113648 : write_name (concept_decl, 0);
912 : 113648 : tree args = TREE_OPERAND (cnst, 1);
913 : 113648 : if (TREE_VEC_LENGTH (args) > 1)
914 : : {
915 : 27061 : TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args) = true;
916 : 27061 : write_template_args (args);
917 : : }
918 : : }
919 : :
920 : : /* <encoding> ::= <function name> <bare-function-type>
921 : : ::= <data name> */
922 : :
923 : : static void
924 : 177333164 : write_encoding (const tree decl)
925 : : {
926 : 177333164 : MANGLE_TRACE_TREE ("encoding", decl);
927 : :
928 : 177333164 : if (DECL_LANG_SPECIFIC (decl) && DECL_EXTERN_C_FUNCTION_P (decl))
929 : : {
930 : : /* For overloaded operators write just the mangled name
931 : : without arguments. */
932 : 12420 : if (DECL_OVERLOADED_OPERATOR_P (decl))
933 : 3 : write_name (decl, /*ignore_local_scope=*/0);
934 : : else
935 : 12417 : write_source_name (DECL_NAME (decl));
936 : 12420 : return;
937 : : }
938 : :
939 : 177320744 : write_name (decl, /*ignore_local_scope=*/0);
940 : 177320744 : if (TREE_CODE (decl) == FUNCTION_DECL)
941 : : {
942 : 157874142 : tree fn_type;
943 : 157874142 : tree d;
944 : :
945 : 157874142 : if (maybe_template_info (decl))
946 : : {
947 : 13732508 : fn_type = get_mostly_instantiated_function_type (decl);
948 : : /* FN_TYPE will not have parameter types for in-charge or
949 : : VTT parameters. Therefore, we pass NULL_TREE to
950 : : write_bare_function_type -- otherwise, it will get
951 : : confused about which artificial parameters to skip. */
952 : 13732508 : d = NULL_TREE;
953 : : }
954 : : else
955 : : {
956 : 144141634 : fn_type = TREE_TYPE (decl);
957 : 144141634 : d = decl;
958 : : }
959 : :
960 : 157874142 : write_bare_function_type (fn_type,
961 : 157874142 : mangle_return_type_p (decl),
962 : : d);
963 : :
964 : 157874142 : if (tree c = get_trailing_function_requirements (decl))
965 : 1775866 : if (abi_check (19))
966 : : {
967 : 1767915 : ++G.parm_depth;
968 : 1767915 : write_char ('Q');
969 : 1767915 : write_constraint_expression (c);
970 : 1767915 : --G.parm_depth;
971 : : }
972 : : }
973 : : }
974 : :
975 : : /* Interface to substitution and identifier mangling, used by the
976 : : module name mangler. */
977 : :
978 : : void
979 : 192 : mangle_module_substitution (int v)
980 : : {
981 : 192 : write_substitution (v - 1);
982 : 192 : }
983 : :
984 : : int
985 : 7225 : mangle_module_component (tree comp, bool partition_p)
986 : : {
987 : 7225 : write_char ('W');
988 : 7225 : if (partition_p)
989 : 172 : write_char ('P');
990 : 7225 : write_source_name (comp);
991 : :
992 : : // Module substitutions use the same number-space as entity
993 : : // substitutions, but are orthogonal.
994 : 7225 : vec_safe_push (G.substitutions, NULL_TREE);
995 : 7225 : return G.substitutions->length ();
996 : : }
997 : :
998 : : /* If the outermost non-namespace context (including DECL itself) is
999 : : a module-linkage decl, mangle the module information. For module
1000 : : global initializers we need to include the partition part.
1001 : :
1002 : : <module-name> ::= <module-sub>
1003 : : || <subst>
1004 : : || <module-name> <module-sub>
1005 : : <module-sub> :: W [P] <unqualified-name>
1006 : : */
1007 : :
1008 : : static void
1009 : 6792 : write_module (int m, bool include_partition)
1010 : : {
1011 : 6792 : G.mod = true;
1012 : 0 : mangle_module (m, include_partition);
1013 : 5009 : }
1014 : :
1015 : : static void
1016 : 925573 : maybe_write_module (tree decl)
1017 : : {
1018 : 925573 : if (!DECL_NAMESPACE_SCOPE_P (decl))
1019 : : return;
1020 : :
1021 : 658449 : if (!TREE_PUBLIC (STRIP_TEMPLATE (decl)))
1022 : : return;
1023 : :
1024 : 652264 : if (TREE_CODE (decl) == NAMESPACE_DECL)
1025 : : return;
1026 : :
1027 : 494612 : int m = get_originating_module (decl, true);
1028 : 494612 : if (m >= 0)
1029 : 5009 : write_module (m, false);
1030 : : }
1031 : :
1032 : : /* Lambdas can have a bit more context for mangling, specifically VAR_DECL
1033 : : or PARM_DECL context, which doesn't belong in DECL_CONTEXT. */
1034 : :
1035 : : static tree
1036 : 1695281517 : decl_mangling_context (tree decl)
1037 : : {
1038 : 1695281623 : tree tcontext = targetm.cxx.decl_mangling_context (decl);
1039 : :
1040 : 1695281623 : if (tcontext != NULL_TREE)
1041 : : return tcontext;
1042 : :
1043 : 1695281623 : if (TREE_CODE (decl) == TEMPLATE_DECL
1044 : 1695281623 : && DECL_TEMPLATE_RESULT (decl))
1045 : : decl = DECL_TEMPLATE_RESULT (decl);
1046 : :
1047 : 1695281623 : if (TREE_CODE (decl) == TYPE_DECL
1048 : 2518751674 : && LAMBDA_TYPE_P (TREE_TYPE (decl)))
1049 : : {
1050 : 4382992 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl));
1051 : 4382992 : if (extra)
1052 : : return extra;
1053 : 1621 : tcontext = CP_DECL_CONTEXT (decl);
1054 : 1749 : if (LAMBDA_TYPE_P (tcontext))
1055 : : /* Lambda type context means this lambda appears between the
1056 : : lambda-introducer and the open brace of another lambda (c++/119175).
1057 : : That isn't a real scope; look further into the enclosing scope. */
1058 : 18 : return decl_mangling_context (TYPE_NAME (tcontext));
1059 : : }
1060 : 1690898631 : else if (template_type_parameter_p (decl))
1061 : : /* template type parms have no mangling context. */
1062 : : return NULL_TREE;
1063 : :
1064 : 1690899248 : tcontext = CP_DECL_CONTEXT (decl);
1065 : :
1066 : 1690899248 : if (member_like_constrained_friend_p (decl))
1067 : 83020 : tcontext = DECL_FRIEND_CONTEXT (decl);
1068 : :
1069 : : /* Ignore the artificial declare reduction functions. */
1070 : 1690899248 : if (tcontext
1071 : 1690899248 : && TREE_CODE (tcontext) == FUNCTION_DECL
1072 : 1696213481 : && DECL_OMP_DECLARE_REDUCTION_P (tcontext))
1073 : : return decl_mangling_context (tcontext);
1074 : :
1075 : : return tcontext;
1076 : : }
1077 : :
1078 : : /* <name> ::= <unscoped-name>
1079 : : ::= <unscoped-template-name> <template-args>
1080 : : ::= <nested-name>
1081 : : ::= <local-name>
1082 : :
1083 : : If IGNORE_LOCAL_SCOPE is nonzero, this production of <name> is
1084 : : called from <local-name>, which mangles the enclosing scope
1085 : : elsewhere and then uses this function to mangle just the part
1086 : : underneath the function scope. So don't use the <local-name>
1087 : : production, to avoid an infinite recursion. */
1088 : :
1089 : : static void
1090 : 457775427 : write_name (tree decl, const int ignore_local_scope)
1091 : : {
1092 : 457775427 : tree context;
1093 : :
1094 : 457775427 : MANGLE_TRACE_TREE ("name", decl);
1095 : :
1096 : 457775427 : if (TREE_CODE (decl) == TYPE_DECL)
1097 : : {
1098 : : /* In case this is a typedef, fish out the corresponding
1099 : : TYPE_DECL for the main variant. */
1100 : 276606080 : decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
1101 : : }
1102 : :
1103 : 457775427 : context = decl_mangling_context (decl);
1104 : :
1105 : 457775427 : gcc_assert (context != NULL_TREE);
1106 : :
1107 : 2288396458 : if (abi_warn_or_compat_version_crosses (7)
1108 : 159971 : && ignore_local_scope
1109 : 44 : && TREE_CODE (context) == PARM_DECL)
1110 : 0 : G.need_abi_warning = 1;
1111 : :
1112 : : /* A decl in :: or ::std scope is treated specially. The former is
1113 : : mangled using <unscoped-name> or <unscoped-template-name>, the
1114 : : latter with a special substitution. Also, a name that is
1115 : : directly in a local function scope is also mangled with
1116 : : <unscoped-name> rather than a full <nested-name>. */
1117 : 457775427 : if (context == global_namespace
1118 : 447964910 : || DECL_NAMESPACE_STD_P (context)
1119 : 263787946 : || (ignore_local_scope
1120 : 4260576 : && (TREE_CODE (context) == FUNCTION_DECL
1121 : 3119867 : || (abi_version_at_least (7)
1122 : 3119867 : && TREE_CODE (context) == PARM_DECL))))
1123 : : {
1124 : : /* Is this a template instance? */
1125 : 195128220 : if (tree info = maybe_template_info (decl))
1126 : : {
1127 : : /* Yes: use <unscoped-template-name>. */
1128 : 163009426 : write_unscoped_template_name (TI_TEMPLATE (info));
1129 : : /* Pass down the parms of a function template in case we need to
1130 : : mangle them; we don't mangle the parms of a non-overloadable
1131 : : template. */
1132 : 163009426 : tree parms = (TREE_CODE (decl) == FUNCTION_DECL
1133 : 166895945 : ? DECL_TEMPLATE_PARMS (TI_TEMPLATE (info))
1134 : 3886519 : : NULL_TREE);
1135 : 163009426 : write_template_args (TI_ARGS (info), parms);
1136 : : }
1137 : : else
1138 : : /* Everything else gets an <unqualified-name>. */
1139 : 32118794 : write_unscoped_name (decl);
1140 : : }
1141 : : else
1142 : : {
1143 : : /* Handle local names, unless we asked not to (that is, invoked
1144 : : under <local-name>, to handle only the part of the name under
1145 : : the local scope). */
1146 : 262647207 : if (!ignore_local_scope)
1147 : : {
1148 : : /* Scan up the list of scope context, looking for a
1149 : : function. If we find one, this entity is in local
1150 : : function scope. local_entity tracks context one scope
1151 : : level down, so it will contain the element that's
1152 : : directly in that function's scope, either decl or one of
1153 : : its enclosing scopes. */
1154 : : tree local_entity = decl;
1155 : 823841876 : while (context != global_namespace)
1156 : : {
1157 : : /* Make sure we're always dealing with decls. */
1158 : 568575082 : if (TYPE_P (context))
1159 : 183910673 : context = TYPE_NAME (context);
1160 : : /* Is this a function? */
1161 : 568575082 : if (TREE_CODE (context) == FUNCTION_DECL
1162 : 564314866 : || TREE_CODE (context) == PARM_DECL)
1163 : : {
1164 : : /* Yes, we have local scope. Use the <local-name>
1165 : : production for the innermost function scope. */
1166 : 4260576 : write_local_name (context, local_entity, decl);
1167 : 4260576 : return;
1168 : : }
1169 : : /* Up one scope level. */
1170 : 564314506 : local_entity = context;
1171 : 564314506 : context = decl_mangling_context (context);
1172 : : }
1173 : :
1174 : : /* No local scope found? Fall through to <nested-name>. */
1175 : : }
1176 : :
1177 : : /* Other decls get a <nested-name> to encode their scope. */
1178 : 258386631 : write_nested_name (decl);
1179 : : }
1180 : : }
1181 : :
1182 : : /* <unscoped-name> ::= <unqualified-name>
1183 : : ::= St <unqualified-name> # ::std:: */
1184 : :
1185 : : static void
1186 : 138684942 : write_unscoped_name (const tree decl)
1187 : : {
1188 : 138684942 : tree context = decl_mangling_context (decl);
1189 : :
1190 : 138684942 : MANGLE_TRACE_TREE ("unscoped-name", decl);
1191 : :
1192 : : /* Is DECL in ::std? */
1193 : 138684942 : if (DECL_NAMESPACE_STD_P (context))
1194 : : {
1195 : 129955275 : write_string ("St");
1196 : 129955275 : write_unqualified_name (decl);
1197 : : }
1198 : : else
1199 : : {
1200 : : /* If not, it should be either in the global namespace, or directly
1201 : : in a local function scope. A lambda can also be mangled in the
1202 : : scope of a default argument. */
1203 : 8729667 : gcc_assert (context == global_namespace
1204 : : || TREE_CODE (context) == PARM_DECL
1205 : : || TREE_CODE (context) == FUNCTION_DECL);
1206 : :
1207 : 8729667 : write_unqualified_name (decl);
1208 : : }
1209 : 138684942 : }
1210 : :
1211 : : /* <unscoped-template-name> ::= <unscoped-name>
1212 : : ::= <substitution> */
1213 : :
1214 : : static void
1215 : 163009426 : write_unscoped_template_name (const tree decl)
1216 : : {
1217 : 163009426 : MANGLE_TRACE_TREE ("unscoped-template-name", decl);
1218 : :
1219 : 163009426 : if (find_substitution (decl))
1220 : : return;
1221 : 106566148 : write_unscoped_name (decl);
1222 : 106566148 : add_substitution (decl);
1223 : : }
1224 : :
1225 : : /* Write the nested name, including CV-qualifiers, of DECL.
1226 : :
1227 : : <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1228 : : ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1229 : :
1230 : : <ref-qualifier> ::= R # & ref-qualifier
1231 : : ::= O # && ref-qualifier
1232 : : <CV-qualifiers> ::= [r] [V] [K] */
1233 : :
1234 : : static void
1235 : 260596932 : write_nested_name (const tree decl)
1236 : : {
1237 : 260596932 : MANGLE_TRACE_TREE ("nested-name", decl);
1238 : :
1239 : 260596932 : write_char ('N');
1240 : :
1241 : : /* Write CV-qualifiers, if this is an iobj member function. */
1242 : 260596932 : if (TREE_CODE (decl) == FUNCTION_DECL
1243 : 260596932 : && DECL_IOBJ_MEMBER_FUNCTION_P (decl))
1244 : : {
1245 : 125557378 : if (DECL_VOLATILE_MEMFUNC_P (decl))
1246 : 7895454 : write_char ('V');
1247 : 125557378 : if (DECL_CONST_MEMFUNC_P (decl))
1248 : 37433322 : write_char ('K');
1249 : 125557378 : if (FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)))
1250 : : {
1251 : 96570 : if (FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl)))
1252 : 55770 : write_char ('O');
1253 : : else
1254 : 40800 : write_char ('R');
1255 : : }
1256 : : }
1257 : 113154351 : else if (DECL_DECLARES_FUNCTION_P (decl)
1258 : 135039554 : && DECL_XOBJ_MEMBER_FUNCTION_P (decl))
1259 : 3342 : write_char ('H');
1260 : :
1261 : : /* Is this a template instance? */
1262 : 260596932 : if (tree info = maybe_template_info (decl))
1263 : : {
1264 : : /* Yes, use <template-prefix>. */
1265 : 44612282 : write_template_prefix (decl);
1266 : 44612282 : write_template_args (TI_ARGS (info));
1267 : : }
1268 : 215984650 : else if ((!abi_version_at_least (10) || TREE_CODE (decl) == TYPE_DECL)
1269 : 281182735 : && TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
1270 : : {
1271 : 2210298 : tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
1272 : 2210298 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1273 : : {
1274 : 37461 : write_template_prefix (decl);
1275 : 37461 : write_template_args (TREE_OPERAND (name, 1));
1276 : : }
1277 : : else
1278 : : {
1279 : 2172837 : write_prefix (decl_mangling_context (decl));
1280 : 2172837 : write_unqualified_name (decl);
1281 : : }
1282 : : }
1283 : : else
1284 : : {
1285 : : /* No, just use <prefix> */
1286 : 213774352 : write_prefix (decl_mangling_context (decl));
1287 : 213774352 : write_unqualified_name (decl);
1288 : : }
1289 : 260596932 : write_char ('E');
1290 : 260596932 : }
1291 : :
1292 : : /* <prefix> ::= <prefix> <unqualified-name>
1293 : : ::= <template-param>
1294 : : ::= <template-prefix> <template-args>
1295 : : ::= <decltype>
1296 : : ::= # empty
1297 : : ::= <substitution> */
1298 : :
1299 : : static void
1300 : 530097534 : write_prefix (const tree node)
1301 : : {
1302 : 530097534 : tree decl;
1303 : :
1304 : 530097534 : if (node == NULL
1305 : 530097534 : || node == global_namespace)
1306 : : return;
1307 : :
1308 : 509297235 : MANGLE_TRACE_TREE ("prefix", node);
1309 : :
1310 : 509297235 : if (TREE_CODE (node) == DECLTYPE_TYPE
1311 : 509297116 : || TREE_CODE (node) == TRAIT_TYPE)
1312 : : {
1313 : 122 : write_type (node);
1314 : 122 : return;
1315 : : }
1316 : :
1317 : 509297113 : if (find_substitution (node))
1318 : : return;
1319 : :
1320 : 277036585 : tree template_info = NULL_TREE;
1321 : 277036585 : if (DECL_P (node))
1322 : : {
1323 : : /* If this is a function or parm decl, that means we've hit function
1324 : : scope, so this prefix must be for a local name. In this
1325 : : case, we're under the <local-name> production, which encodes
1326 : : the enclosing function scope elsewhere. So don't continue
1327 : : here. */
1328 : 99056113 : if (TREE_CODE (node) == FUNCTION_DECL
1329 : 95937243 : || TREE_CODE (node) == PARM_DECL)
1330 : : return;
1331 : :
1332 : 95936913 : decl = node;
1333 : 95936913 : template_info = maybe_template_info (decl);
1334 : : }
1335 : : else
1336 : : {
1337 : : /* Node is a type. */
1338 : 177980472 : decl = TYPE_NAME (node);
1339 : : /* The DECL might not point at the node. */
1340 : 177980472 : if (CLASSTYPE_TEMPLATE_ID_P (node))
1341 : 133817472 : template_info = TYPE_TEMPLATE_INFO (node);
1342 : : }
1343 : :
1344 : 273917385 : if (TREE_CODE (node) == TEMPLATE_TYPE_PARM)
1345 : 8280 : write_template_param (node);
1346 : 273909105 : else if (template_info)
1347 : : /* Templated. */
1348 : : {
1349 : 133819362 : write_template_prefix (decl);
1350 : 133819362 : write_template_args (TI_ARGS (template_info));
1351 : : }
1352 : 140089743 : else if (TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
1353 : : {
1354 : 37056 : tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
1355 : 37056 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1356 : : {
1357 : 28112 : write_template_prefix (decl);
1358 : 28112 : write_template_args (TREE_OPERAND (name, 1));
1359 : : }
1360 : : else
1361 : : {
1362 : 8944 : write_prefix (decl_mangling_context (decl));
1363 : 8944 : write_unqualified_name (decl);
1364 : : }
1365 : : }
1366 : : else
1367 : : /* Not templated. */
1368 : : {
1369 : 140052687 : write_prefix (decl_mangling_context (decl));
1370 : 140052687 : write_unqualified_name (decl);
1371 : 140052687 : if (VAR_P (decl)
1372 : 140052687 : || TREE_CODE (decl) == FIELD_DECL)
1373 : : {
1374 : : /* <data-member-prefix> := <member source-name> M */
1375 : 14905 : write_char ('M');
1376 : :
1377 : : /* Before ABI 18, we did not count these as substitution
1378 : : candidates. This leads to incorrect demanglings (and
1379 : : ABI divergence to other compilers). */
1380 : 14905 : if (!abi_check (18))
1381 : : return;
1382 : : }
1383 : : }
1384 : :
1385 : 273917253 : add_substitution (node);
1386 : : }
1387 : :
1388 : : /* <template-prefix> ::= <prefix> <template component>
1389 : : ::= <template-param>
1390 : : ::= <substitution> */
1391 : :
1392 : : static void
1393 : 178497217 : write_template_prefix (const tree node)
1394 : : {
1395 : 178497217 : tree decl = DECL_P (node) ? node : TYPE_NAME (node);
1396 : 178497217 : tree type = DECL_P (node) ? TREE_TYPE (node) : node;
1397 : 178497217 : tree context = decl_mangling_context (decl);
1398 : 178497217 : tree templ;
1399 : 178497217 : tree substitution;
1400 : :
1401 : 178497217 : MANGLE_TRACE_TREE ("template-prefix", node);
1402 : :
1403 : : /* Find the template decl. */
1404 : 178497217 : if (tree info = maybe_template_info (decl))
1405 : 178430658 : templ = TI_TEMPLATE (info);
1406 : 66559 : else if (TREE_CODE (type) == TYPENAME_TYPE)
1407 : : /* For a typename type, all we have is the name. */
1408 : 65573 : templ = DECL_NAME (decl);
1409 : : else
1410 : : {
1411 : 986 : gcc_assert (CLASSTYPE_TEMPLATE_ID_P (type));
1412 : :
1413 : 986 : templ = TYPE_TI_TEMPLATE (type);
1414 : : }
1415 : :
1416 : : /* For a member template, though, the template name for the
1417 : : innermost name must have all the outer template levels
1418 : : instantiated. For instance, consider
1419 : :
1420 : : template<typename T> struct Outer {
1421 : : template<typename U> struct Inner {};
1422 : : };
1423 : :
1424 : : The template name for `Inner' in `Outer<int>::Inner<float>' is
1425 : : `Outer<int>::Inner<U>'. In g++, we don't instantiate the template
1426 : : levels separately, so there's no TEMPLATE_DECL available for this
1427 : : (there's only `Outer<T>::Inner<U>').
1428 : :
1429 : : In order to get the substitutions right, we create a special
1430 : : TREE_LIST to represent the substitution candidate for a nested
1431 : : template. The TREE_PURPOSE is the template's context, fully
1432 : : instantiated, and the TREE_VALUE is the TEMPLATE_DECL for the inner
1433 : : template.
1434 : :
1435 : : So, for the example above, `Outer<int>::Inner' is represented as a
1436 : : substitution candidate by a TREE_LIST whose purpose is `Outer<int>'
1437 : : and whose value is `Outer<T>::Inner<U>'. */
1438 : 178497217 : if (context && TYPE_P (context))
1439 : 9170095 : substitution = build_tree_list (context, templ);
1440 : : else
1441 : : substitution = templ;
1442 : :
1443 : 178497217 : if (find_substitution (substitution))
1444 : : return;
1445 : :
1446 : 174089628 : if (TREE_TYPE (templ)
1447 : 174089628 : && TREE_CODE (TREE_TYPE (templ)) == TEMPLATE_TEMPLATE_PARM)
1448 : 986 : write_template_param (TREE_TYPE (templ));
1449 : : else
1450 : : {
1451 : 174088642 : write_prefix (context);
1452 : 174088642 : write_unqualified_name (decl);
1453 : : }
1454 : :
1455 : 174089628 : add_substitution (substitution);
1456 : : }
1457 : :
1458 : : /* "For the purposes of mangling, the name of an anonymous union is considered
1459 : : to be the name of the first named data member found by a pre-order,
1460 : : depth-first, declaration-order walk of the data members of the anonymous
1461 : : union. If there is no such data member (i.e., if all of the data members in
1462 : : the union are unnamed), then there is no way for a program to refer to the
1463 : : anonymous union, and there is therefore no need to mangle its name." */
1464 : :
1465 : : static tree
1466 : 21 : anon_aggr_naming_decl (tree type)
1467 : : {
1468 : 21 : tree field = next_aggregate_field (TYPE_FIELDS (type));
1469 : 21 : for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
1470 : : {
1471 : 21 : if (DECL_NAME (field))
1472 : : return field;
1473 : 0 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
1474 : 0 : if (tree sub = anon_aggr_naming_decl (TREE_TYPE (field)))
1475 : : return sub;
1476 : : }
1477 : : return NULL_TREE;
1478 : : }
1479 : :
1480 : : /* We don't need to handle thunks, vtables, or VTTs here. Those are
1481 : : mangled through special entry points.
1482 : :
1483 : : <unqualified-name> ::= [<module-name>] <operator-name>
1484 : : ::= <special-name>
1485 : : ::= [<module-name>] <source-name>
1486 : : ::= [<module-name>] <unnamed-type-name>
1487 : : ::= <local-source-name>
1488 : : ::= F <source-name> # member-like constrained friend
1489 : :
1490 : : <local-source-name> ::= L <source-name> <discriminator> */
1491 : :
1492 : : static void
1493 : 3205309 : write_unqualified_id (tree identifier)
1494 : : {
1495 : 3205309 : if (IDENTIFIER_CONV_OP_P (identifier))
1496 : 15 : write_conversion_operator_name (TREE_TYPE (identifier));
1497 : 3205294 : else if (IDENTIFIER_OVL_OP_P (identifier))
1498 : : {
1499 : 24909 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (identifier);
1500 : 24909 : write_string (ovl_op->mangled_name);
1501 : 24909 : }
1502 : 3180385 : else if (UDLIT_OPER_P (identifier))
1503 : 0 : write_literal_operator_name (identifier);
1504 : : else
1505 : 3180385 : write_source_name (identifier);
1506 : 3205309 : }
1507 : :
1508 : : static void
1509 : 668785412 : write_unqualified_name (tree decl)
1510 : : {
1511 : 668785412 : MANGLE_TRACE_TREE ("unqualified-name", decl);
1512 : :
1513 : 668785412 : if (modules_p ())
1514 : 925573 : maybe_write_module (decl);
1515 : :
1516 : 668785412 : if (identifier_p (decl))
1517 : : {
1518 : 0 : write_unqualified_id (decl);
1519 : 0 : return;
1520 : : }
1521 : :
1522 : 668785412 : bool found = false;
1523 : :
1524 : 668785412 : if (DECL_NAME (decl) == NULL_TREE
1525 : 668785412 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
1526 : 21 : decl = anon_aggr_naming_decl (TREE_TYPE (decl));
1527 : 668785391 : else if (DECL_NAME (decl) == NULL_TREE)
1528 : : {
1529 : 10288 : found = true;
1530 : 10288 : gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
1531 : 10288 : write_source_name (DECL_ASSEMBLER_NAME (decl));
1532 : : }
1533 : 668775103 : else if (DECL_DECLARES_FUNCTION_P (decl))
1534 : : {
1535 : 157873423 : found = true;
1536 : :
1537 : : /* A constrained hidden friend is mangled like a member function, with
1538 : : the name prefixed by 'F'. */
1539 : 157873423 : if (member_like_constrained_friend_p (decl))
1540 : 20755 : write_char ('F');
1541 : :
1542 : 315746846 : if (DECL_CONSTRUCTOR_P (decl))
1543 : 25123672 : write_special_name_constructor (decl);
1544 : 132749751 : else if (DECL_DESTRUCTOR_P (decl))
1545 : 6961698 : write_special_name_destructor (decl);
1546 : 125788053 : else if (DECL_CONV_FN_P (decl))
1547 : : {
1548 : : /* Conversion operator. Handle it right here.
1549 : : <operator> ::= cv <type> */
1550 : 1794952 : tree type;
1551 : 1794952 : if (maybe_template_info (decl))
1552 : : {
1553 : 557 : tree fn_type;
1554 : 557 : fn_type = get_mostly_instantiated_function_type (decl);
1555 : 557 : type = TREE_TYPE (fn_type);
1556 : : }
1557 : 1794395 : else if (FNDECL_USED_AUTO (decl))
1558 : 212 : type = DECL_SAVED_AUTO_RETURN_TYPE (decl);
1559 : : else
1560 : 1794183 : type = DECL_CONV_FN_TYPE (decl);
1561 : 1794952 : write_conversion_operator_name (type);
1562 : : }
1563 : 123993101 : else if (DECL_OVERLOADED_OPERATOR_P (decl))
1564 : : {
1565 : 27362706 : tree t;
1566 : 27362706 : if (!(t = DECL_RAMP_FN (decl)))
1567 : 27362318 : t = decl;
1568 : 27362706 : const char *mangled_name
1569 : 27362706 : = (ovl_op_info[DECL_ASSIGNMENT_OPERATOR_P (t)]
1570 : 27362706 : [DECL_OVERLOADED_OPERATOR_CODE_RAW (t)].mangled_name);
1571 : 27362706 : write_string (mangled_name);
1572 : : }
1573 : 96630395 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
1574 : 236362 : write_literal_operator_name (DECL_NAME (decl));
1575 : : else
1576 : : found = false;
1577 : : }
1578 : :
1579 : 61489699 : if (found)
1580 : : /* OK */;
1581 : 607295734 : else if (VAR_OR_FUNCTION_DECL_P (decl) && ! TREE_PUBLIC (decl)
1582 : 123234 : && DECL_NAMESPACE_SCOPE_P (decl)
1583 : 607364124 : && decl_linkage (decl) == lk_internal)
1584 : : {
1585 : 58083 : MANGLE_TRACE_TREE ("local-source-name", decl);
1586 : 58083 : write_char ('L');
1587 : 58083 : write_source_name (DECL_NAME (decl));
1588 : : /* The default discriminator is 1, and that's all we ever use,
1589 : : so there's no code to output one here. */
1590 : : }
1591 : : else
1592 : : {
1593 : 607237651 : tree type = TREE_TYPE (decl);
1594 : :
1595 : 607237651 : if (TREE_CODE (decl) == TYPE_DECL
1596 : 607237651 : && enum_with_enumerator_for_linkage_p (type))
1597 : 22 : write_unnamed_enum_name (type);
1598 : 906254254 : else if (TREE_CODE (decl) == TYPE_DECL && TYPE_UNNAMED_P (type))
1599 : 1234 : write_unnamed_type_name (type);
1600 : 884741003 : else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (type))
1601 : 1740625 : write_closure_type_name (type);
1602 : : else
1603 : 605495770 : write_source_name (DECL_NAME (decl));
1604 : : }
1605 : :
1606 : : /* We use the ABI tags from the primary class template, ignoring tags on any
1607 : : specializations. This is necessary because C++ doesn't require a
1608 : : specialization to be declared before it is used unless the use requires a
1609 : : complete type, but we need to get the tags right on incomplete types as
1610 : : well. */
1611 : 668785412 : if (tree tmpl = most_general_template (decl))
1612 : : {
1613 : 398547681 : tree res = DECL_TEMPLATE_RESULT (tmpl);
1614 : 398547681 : if (res == NULL_TREE)
1615 : : /* UNBOUND_CLASS_TEMPLATE. */;
1616 : 398547678 : else if (DECL_DECLARES_TYPE_P (decl))
1617 : : decl = res;
1618 : 131425137 : else if (any_abi_below (11))
1619 : : {
1620 : : /* ABI v10 implicit tags on the template. */
1621 : 81558 : tree mtags = missing_abi_tags (res);
1622 : : /* Explicit tags on the template. */
1623 : 81558 : tree ttags = get_abi_tags (res);
1624 : : /* Tags on the instantiation. */
1625 : 81558 : tree dtags = get_abi_tags (decl);
1626 : :
1627 : 81636 : if (mtags && abi_warn_or_compat_version_crosses (10))
1628 : 6 : G.need_abi_warning = 1;
1629 : :
1630 : : /* Add the v10 tags to the explicit tags now. */
1631 : 81558 : mtags = chainon (mtags, ttags);
1632 : :
1633 : 81558 : if (!G.need_abi_warning
1634 : 163018 : && abi_warn_or_compat_version_crosses (11)
1635 : 163022 : && !equal_abi_tags (dtags, mtags))
1636 : 6 : G.need_abi_warning = 1;
1637 : :
1638 : 81558 : if (!abi_version_at_least (10))
1639 : : /* In abi <10, we only got the explicit tags. */
1640 : : decl = res;
1641 : 901 : else if (flag_abi_version == 10)
1642 : : {
1643 : : /* In ABI 10, we want explict and implicit tags. */
1644 : 72 : write_abi_tags (mtags);
1645 : 72 : return;
1646 : : }
1647 : : }
1648 : : }
1649 : :
1650 : 668785340 : tree tags = get_abi_tags (decl);
1651 : 153987283 : if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CONV_FN_P (decl)
1652 : 670580292 : && any_abi_below (11))
1653 : 2731 : if (tree mtags = missing_abi_tags (decl))
1654 : : {
1655 : 9 : if (!abi_check (11))
1656 : 6 : tags = chainon (mtags, tags);
1657 : : }
1658 : 668785340 : write_abi_tags (tags);
1659 : : }
1660 : :
1661 : : /* Write the unqualified-name for a conversion operator to TYPE. */
1662 : :
1663 : : static void
1664 : 1794967 : write_conversion_operator_name (const tree type)
1665 : : {
1666 : 1794967 : write_string ("cv");
1667 : 1794967 : write_type (type);
1668 : 1794967 : }
1669 : :
1670 : : /* Non-terminal <source-name>. IDENTIFIER is an IDENTIFIER_NODE.
1671 : :
1672 : : <source-name> ::= </length/ number> <identifier> */
1673 : :
1674 : : static void
1675 : 608764673 : write_source_name (tree identifier)
1676 : : {
1677 : 608764673 : MANGLE_TRACE_TREE ("source-name", identifier);
1678 : :
1679 : 608764673 : write_unsigned_number (IDENTIFIER_LENGTH (identifier));
1680 : 608764673 : write_identifier (IDENTIFIER_POINTER (identifier));
1681 : 608764673 : }
1682 : :
1683 : : /* Compare two TREE_STRINGs like strcmp. */
1684 : :
1685 : : static int
1686 : 306 : tree_string_cmp (const void *p1, const void *p2)
1687 : : {
1688 : 306 : if (p1 == p2)
1689 : : return 0;
1690 : 306 : tree s1 = *(const tree*)p1;
1691 : 306 : tree s2 = *(const tree*)p2;
1692 : 306 : return strcmp (TREE_STRING_POINTER (s1),
1693 : 306 : TREE_STRING_POINTER (s2));
1694 : : }
1695 : :
1696 : : /* Return the TREE_LIST of TAGS as a sorted VEC. */
1697 : :
1698 : : static vec<tree, va_gc> *
1699 : 468556 : sorted_abi_tags (tree tags)
1700 : : {
1701 : 468556 : vec<tree, va_gc> * vec = make_tree_vector();
1702 : :
1703 : 774253 : for (tree t = tags; t; t = TREE_CHAIN (t))
1704 : : {
1705 : 305697 : if (ABI_TAG_IMPLICIT (t))
1706 : 3 : continue;
1707 : 305694 : tree str = TREE_VALUE (t);
1708 : 305694 : vec_safe_push (vec, str);
1709 : : }
1710 : :
1711 : 468556 : vec->qsort (tree_string_cmp);
1712 : :
1713 : 468556 : return vec;
1714 : : }
1715 : :
1716 : : /* ID is the name of a function or type with abi_tags attribute TAGS.
1717 : : Write out the name, suitably decorated. */
1718 : :
1719 : : static void
1720 : 668785448 : write_abi_tags (tree tags)
1721 : : {
1722 : 668785448 : if (tags == NULL_TREE)
1723 : 668785448 : return;
1724 : :
1725 : 305568 : vec<tree, va_gc> * vec = sorted_abi_tags (tags);
1726 : :
1727 : 305568 : unsigned i; tree str;
1728 : 611163 : FOR_EACH_VEC_ELT (*vec, i, str)
1729 : : {
1730 : 305595 : write_string ("B");
1731 : 305595 : write_unsigned_number (TREE_STRING_LENGTH (str) - 1);
1732 : 305595 : write_identifier (TREE_STRING_POINTER (str));
1733 : : }
1734 : :
1735 : 305568 : release_tree_vector (vec);
1736 : : }
1737 : :
1738 : : /* True iff the TREE_LISTS T1 and T2 of ABI tags are equivalent. */
1739 : :
1740 : : bool
1741 : 81494 : equal_abi_tags (tree t1, tree t2)
1742 : : {
1743 : 81494 : releasing_vec v1 = sorted_abi_tags (t1);
1744 : 81494 : releasing_vec v2 = sorted_abi_tags (t2);
1745 : :
1746 : 81494 : unsigned len1 = v1->length();
1747 : 81494 : if (len1 != v2->length())
1748 : : return false;
1749 : 81488 : for (unsigned i = 0; i < len1; ++i)
1750 : 21 : if (strcmp (TREE_STRING_POINTER (v1[i]),
1751 : 21 : TREE_STRING_POINTER (v2[i])) != 0)
1752 : : return false;
1753 : : return true;
1754 : 81494 : }
1755 : :
1756 : : /* Write a user-defined literal operator.
1757 : : ::= li <source-name> # "" <source-name>
1758 : : IDENTIFIER is an LITERAL_IDENTIFIER_NODE. */
1759 : :
1760 : : static void
1761 : 236362 : write_literal_operator_name (tree identifier)
1762 : : {
1763 : 236362 : const char* suffix = UDLIT_OP_SUFFIX (identifier);
1764 : 236362 : write_identifier (UDLIT_OP_MANGLED_PREFIX);
1765 : 236362 : write_unsigned_number (strlen (suffix));
1766 : 236362 : write_identifier (suffix);
1767 : 236362 : }
1768 : :
1769 : : /* Encode 0 as _, and 1+ as n-1_. */
1770 : :
1771 : : static void
1772 : 24872026 : write_compact_number (int num)
1773 : : {
1774 : 24872026 : gcc_checking_assert (num >= 0);
1775 : 24872026 : if (num > 0)
1776 : 9680660 : write_unsigned_number (num - 1);
1777 : 24872026 : write_char ('_');
1778 : 24872026 : }
1779 : :
1780 : : /* Return how many unnamed types precede TYPE in its enclosing class. */
1781 : :
1782 : : static int
1783 : 603 : nested_anon_class_index (tree type)
1784 : : {
1785 : 603 : int index = 0;
1786 : 603 : tree member = TYPE_FIELDS (TYPE_CONTEXT (type));
1787 : 18682 : for (; member; member = DECL_CHAIN (member))
1788 : 18682 : if (DECL_IMPLICIT_TYPEDEF_P (member))
1789 : : {
1790 : 988 : tree memtype = TREE_TYPE (member);
1791 : 988 : if (memtype == type)
1792 : : return index;
1793 : 962 : else if (TYPE_UNNAMED_P (memtype))
1794 : 189 : ++index;
1795 : : }
1796 : :
1797 : 0 : if (seen_error ())
1798 : : return -1;
1799 : :
1800 : 0 : gcc_unreachable ();
1801 : : }
1802 : :
1803 : : /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
1804 : :
1805 : : static void
1806 : 1234 : write_unnamed_type_name (const tree type)
1807 : : {
1808 : 1234 : int discriminator;
1809 : 1234 : MANGLE_TRACE_TREE ("unnamed-type-name", type);
1810 : :
1811 : 1234 : if (TYPE_FUNCTION_SCOPE_P (type))
1812 : 320 : discriminator = discriminator_for_local_entity (TYPE_NAME (type));
1813 : 914 : else if (TYPE_CLASS_SCOPE_P (type))
1814 : 603 : discriminator = nested_anon_class_index (type);
1815 : : else
1816 : : {
1817 : 311 : gcc_assert (no_linkage_check (type, /*relaxed_p=*/true));
1818 : : /* Just use the old mangling at namespace scope. */
1819 : 311 : write_source_name (TYPE_IDENTIFIER (type));
1820 : 311 : return;
1821 : : }
1822 : :
1823 : 923 : write_string ("Ut");
1824 : 923 : write_compact_number (discriminator);
1825 : : }
1826 : :
1827 : : /* <unnamed-enum-name> ::= Ue <underlying type> <enumerator source-name> */
1828 : :
1829 : : static void
1830 : 22 : write_unnamed_enum_name (const tree type)
1831 : : {
1832 : 22 : MANGLE_TRACE_TREE ("unnamed-enum-name", type);
1833 : 22 : write_string ("Ue");
1834 : 22 : write_type (ENUM_UNDERLYING_TYPE (type));
1835 : 22 : write_source_name (DECL_NAME (TREE_VALUE (TYPE_VALUES (type))));
1836 : 22 : }
1837 : :
1838 : : /* ABI issue #47: if a function template parameter is not "natural" for its
1839 : : argument we must mangle the parameter. */
1840 : :
1841 : : static bool
1842 : 6719101 : template_parm_natural_p (tree arg, tree parm)
1843 : : {
1844 : 6719101 : tree decl = TREE_VALUE (parm);
1845 : :
1846 : : /* A template parameter is "natural" if: */
1847 : :
1848 : 6719101 : if (template_parameter_pack_p (decl))
1849 : : {
1850 : 654117 : tree args = ARGUMENT_PACK_ARGS (arg);
1851 : 654117 : if (TREE_VEC_LENGTH (args) == 0)
1852 : : {
1853 : : #if 0
1854 : : /* the argument is an empty pack and the parameter is an
1855 : : unconstrained template type parameter pack; */
1856 : : if (TREE_CODE (decl) != TYPE_DECL)
1857 : : return false;
1858 : : #else
1859 : : /* Defer changing the mangling of C++11 code like
1860 : : template <int i> int max();
1861 : : template <int i, int j, int... rest> int max(); */
1862 : : return true;
1863 : : #endif
1864 : : }
1865 : : else
1866 : : /* the argument is a non-empty pack and a non-pack variant of the
1867 : : parameter would be natural for the first element of the pack; */
1868 : 500432 : arg = TREE_VEC_ELT (args, 0);
1869 : : }
1870 : :
1871 : : /* the argument is a template and the parameter has the exact
1872 : : same template head; */
1873 : 6565416 : if (TREE_CODE (decl) == TEMPLATE_DECL)
1874 : 11741 : return template_heads_equivalent_p (arg, decl);
1875 : :
1876 : : /* the argument is a type and the parameter is unconstrained; or */
1877 : 6553675 : else if (TREE_CODE (decl) == TYPE_DECL)
1878 : 5700236 : return !TEMPLATE_PARM_CONSTRAINTS (parm);
1879 : :
1880 : : /* the argument is a non-type template argument and the declared parameter
1881 : : type neither is instantiation dependent nor contains deduced types. */
1882 : 853439 : else if (TREE_CODE (decl) == PARM_DECL)
1883 : : {
1884 : : #if 0
1885 : : return !uses_template_parms (TREE_TYPE (decl));
1886 : : #else
1887 : : /* Defer changing the mangling of C++98 code like
1888 : : template <class T, T V> .... */
1889 : 853439 : return !type_uses_auto (TREE_TYPE (decl));
1890 : : #endif
1891 : : }
1892 : :
1893 : 0 : gcc_unreachable ();
1894 : : }
1895 : :
1896 : : /* Used for lambda template head and non-natural function template parameters.
1897 : :
1898 : : <template-param-decl> ::= Ty # template type parameter
1899 : : ::= Tk <type-constraint> # constrained type parameter
1900 : : ::= Tn <type> # template non-type parameter
1901 : : ::= Tt <template-param-decl>* [Q <constraint-expression] E # ttp
1902 : : ::= Tp <non-pack template-param-decl> # template parameter pack */
1903 : :
1904 : : static void
1905 : 94994 : write_template_param_decl (tree parm)
1906 : : {
1907 : 94994 : tree decl = TREE_VALUE (parm);
1908 : :
1909 : 94994 : if (template_parameter_pack_p (decl))
1910 : 17091 : write_string ("Tp");
1911 : :
1912 : 94994 : switch (TREE_CODE (decl))
1913 : : {
1914 : 10616 : case PARM_DECL:
1915 : 10616 : {
1916 : 10616 : write_string ("Tn");
1917 : :
1918 : 10616 : tree type = TREE_TYPE (decl);
1919 : 10616 : if (tree c = (is_auto (type)
1920 : 14700 : ? PLACEHOLDER_TYPE_CONSTRAINTS (type)
1921 : 19 : : NULL_TREE))
1922 : : {
1923 : 19 : if (AUTO_IS_DECLTYPE (type))
1924 : 0 : write_string ("DK");
1925 : : else
1926 : 19 : write_string ("Dk");
1927 : 19 : write_type_constraint (c);
1928 : : }
1929 : : else
1930 : 10597 : write_type (type);
1931 : : }
1932 : : break;
1933 : :
1934 : 239 : case TEMPLATE_DECL:
1935 : 239 : {
1936 : 239 : write_string ("Tt");
1937 : 239 : tree parms = DECL_INNERMOST_TEMPLATE_PARMS (decl);
1938 : 560 : for (tree node : tree_vec_range (parms))
1939 : 321 : write_template_param_decl (node);
1940 : 239 : write_char ('E');
1941 : : }
1942 : 239 : break;
1943 : :
1944 : 84139 : case TYPE_DECL:
1945 : 84139 : if (tree c = TEMPLATE_PARM_CONSTRAINTS (parm))
1946 : : {
1947 : 59855 : if (TREE_CODE (c) == UNARY_LEFT_FOLD_EXPR)
1948 : : {
1949 : 50 : c = FOLD_EXPR_PACK (c);
1950 : 50 : c = PACK_EXPANSION_PATTERN (c);
1951 : : }
1952 : 59855 : if (TREE_CODE (decl) == TYPE_DECL)
1953 : : {
1954 : 59855 : write_string ("Tk");
1955 : 59855 : write_type_constraint (c);
1956 : : }
1957 : : }
1958 : : else
1959 : 24284 : write_string ("Ty");
1960 : : break;
1961 : :
1962 : 0 : default:
1963 : 0 : gcc_unreachable ();
1964 : : }
1965 : 94994 : }
1966 : :
1967 : : // A template head, for templated lambdas.
1968 : : // New in ABI=18. Returns true iff we emitted anything -- used for ABI
1969 : : // version warning.
1970 : :
1971 : : static bool
1972 : 329843 : write_closure_template_head (tree tmpl)
1973 : : {
1974 : 329843 : bool any = false;
1975 : :
1976 : : // We only need one level of template parms
1977 : 329843 : tree parms = DECL_TEMPLATE_PARMS (tmpl);
1978 : 329843 : tree inner = INNERMOST_TEMPLATE_PARMS (parms);
1979 : :
1980 : 360688 : for (int ix = 0, len = TREE_VEC_LENGTH (inner); ix != len; ix++)
1981 : : {
1982 : 330887 : tree parm = TREE_VEC_ELT (inner, ix);
1983 : 330887 : if (parm == error_mark_node)
1984 : 0 : continue;
1985 : :
1986 : 330887 : if (DECL_IMPLICIT_TEMPLATE_PARM_P (TREE_VALUE (parm)))
1987 : : // A synthetic parm, we're done.
1988 : : break;
1989 : :
1990 : 30845 : any = true;
1991 : 30845 : if (abi_version_at_least (18))
1992 : 30605 : write_template_param_decl (parm);
1993 : : }
1994 : :
1995 : 329843 : write_tparms_constraints (TEMPLATE_PARMS_CONSTRAINTS (parms));
1996 : :
1997 : 329843 : return any;
1998 : : }
1999 : :
2000 : : /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _
2001 : : <lambda-sig> ::= <parameter type>+ # Parameter types or "v" if the lambda has no parameters */
2002 : :
2003 : : static void
2004 : 1740625 : write_closure_type_name (const tree type)
2005 : : {
2006 : 1740625 : tree fn = lambda_function (type);
2007 : 1740625 : tree lambda = CLASSTYPE_LAMBDA_EXPR (type);
2008 : 1740625 : tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
2009 : :
2010 : 1740625 : MANGLE_TRACE_TREE ("closure-type-name", type);
2011 : :
2012 : 1740625 : write_string ("Ul");
2013 : :
2014 : 1740625 : if (auto ti = maybe_template_info (fn))
2015 : 329843 : if (write_closure_template_head (TI_TEMPLATE (ti)))
2016 : : // If there were any explicit template parms, we may need to
2017 : : // issue a mangling diagnostic.
2018 : 148970 : if (abi_warn_or_compat_version_crosses (18))
2019 : 198 : G.need_abi_warning = true;
2020 : :
2021 : 1740625 : write_method_parms (parms, TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE, fn);
2022 : 1740625 : write_char ('E');
2023 : 1740625 : if ((LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
2024 : 1740625 : != LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda))
2025 : 2717025 : && abi_warn_or_compat_version_crosses (18))
2026 : 288 : G.need_abi_warning = true;
2027 : 3481250 : write_compact_number (abi_version_at_least (18)
2028 : 1740103 : ? LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
2029 : 522 : : LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda));
2030 : 1740625 : }
2031 : :
2032 : : /* Convert NUMBER to ascii using base BASE and generating at least
2033 : : MIN_DIGITS characters. BUFFER points to the _end_ of the buffer
2034 : : into which to store the characters. Returns the number of
2035 : : characters generated (these will be laid out in advance of where
2036 : : BUFFER points). */
2037 : :
2038 : : static int
2039 : 824750459 : hwint_to_ascii (unsigned HOST_WIDE_INT number, const unsigned int base,
2040 : : char *buffer, const unsigned int min_digits)
2041 : : {
2042 : 824750459 : static const char base_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2043 : 824750459 : unsigned digits = 0;
2044 : :
2045 : 2035826385 : while (number)
2046 : : {
2047 : 1211075926 : unsigned HOST_WIDE_INT d = number / base;
2048 : :
2049 : 1211075926 : *--buffer = base_digits[number - d * base];
2050 : 1211075926 : digits++;
2051 : 1211075926 : number = d;
2052 : : }
2053 : 871517998 : while (digits < min_digits)
2054 : : {
2055 : 46767539 : *--buffer = base_digits[0];
2056 : 46767539 : digits++;
2057 : : }
2058 : 824750459 : return digits;
2059 : : }
2060 : :
2061 : : /* Non-terminal <number>.
2062 : :
2063 : : <number> ::= [n] </decimal integer/> */
2064 : :
2065 : : static void
2066 : 824750459 : write_number (unsigned HOST_WIDE_INT number, const int unsigned_p,
2067 : : const unsigned int base)
2068 : : {
2069 : 824750459 : char buffer[sizeof (HOST_WIDE_INT) * 8];
2070 : 824750459 : unsigned count = 0;
2071 : :
2072 : 824750459 : if (!unsigned_p && (HOST_WIDE_INT) number < 0)
2073 : : {
2074 : 0 : write_char ('n');
2075 : 0 : number = -((HOST_WIDE_INT) number);
2076 : : }
2077 : 824750459 : count = hwint_to_ascii (number, base, buffer + sizeof (buffer), 1);
2078 : 824750459 : write_chars (buffer + sizeof (buffer) - count, count);
2079 : 824750459 : }
2080 : :
2081 : : /* Write out an integral CST in decimal. Most numbers are small, and
2082 : : representable in a HOST_WIDE_INT. Occasionally we'll have numbers
2083 : : bigger than that, which we must deal with. */
2084 : :
2085 : : static inline void
2086 : 75141483 : write_integer_cst (const tree cst)
2087 : : {
2088 : 75141483 : int sign = tree_int_cst_sgn (cst);
2089 : 75141483 : widest_int abs_value = wi::abs (wi::to_widest (cst));
2090 : 75141483 : if (!wi::fits_uhwi_p (abs_value))
2091 : : {
2092 : : /* A bignum. We do this in chunks, each of which fits in a
2093 : : HOST_WIDE_INT. */
2094 : 0 : char buffer[sizeof (HOST_WIDE_INT) * 8 * 2];
2095 : 0 : unsigned HOST_WIDE_INT chunk;
2096 : 0 : unsigned chunk_digits;
2097 : 0 : char *ptr = buffer + sizeof (buffer);
2098 : 0 : unsigned count = 0;
2099 : 0 : tree n, base, type;
2100 : 0 : int done;
2101 : :
2102 : : /* HOST_WIDE_INT must be at least 32 bits, so 10^9 is
2103 : : representable. */
2104 : 0 : chunk = 1000000000;
2105 : 0 : chunk_digits = 9;
2106 : :
2107 : 0 : if (sizeof (HOST_WIDE_INT) >= 8)
2108 : : {
2109 : : /* It is at least 64 bits, so 10^18 is representable. */
2110 : 0 : chunk_digits = 18;
2111 : 0 : chunk *= chunk;
2112 : : }
2113 : :
2114 : 0 : type = c_common_signed_or_unsigned_type (1, TREE_TYPE (cst));
2115 : 0 : base = build_int_cstu (type, chunk);
2116 : 0 : n = wide_int_to_tree (type, wi::to_wide (cst));
2117 : :
2118 : 0 : if (sign < 0)
2119 : : {
2120 : 0 : write_char ('n');
2121 : 0 : n = fold_build1_loc (input_location, NEGATE_EXPR, type, n);
2122 : : }
2123 : 0 : do
2124 : : {
2125 : 0 : tree d = fold_build2_loc (input_location, FLOOR_DIV_EXPR, type, n, base);
2126 : 0 : tree tmp = fold_build2_loc (input_location, MULT_EXPR, type, d, base);
2127 : 0 : unsigned c;
2128 : :
2129 : 0 : done = integer_zerop (d);
2130 : 0 : tmp = fold_build2_loc (input_location, MINUS_EXPR, type, n, tmp);
2131 : 0 : c = hwint_to_ascii (TREE_INT_CST_LOW (tmp), 10, ptr,
2132 : : done ? 1 : chunk_digits);
2133 : 0 : ptr -= c;
2134 : 0 : count += c;
2135 : 0 : n = d;
2136 : : }
2137 : 0 : while (!done);
2138 : 0 : write_chars (ptr, count);
2139 : : }
2140 : : else
2141 : : {
2142 : : /* A small num. */
2143 : 75141483 : if (sign < 0)
2144 : 500326 : write_char ('n');
2145 : 75141483 : write_unsigned_number (abs_value.to_uhwi ());
2146 : : }
2147 : 75141483 : }
2148 : :
2149 : : /* Write out a floating-point literal.
2150 : :
2151 : : "Floating-point literals are encoded using the bit pattern of the
2152 : : target processor's internal representation of that number, as a
2153 : : fixed-length lowercase hexadecimal string, high-order bytes first
2154 : : (even if the target processor would store low-order bytes first).
2155 : : The "n" prefix is not used for floating-point literals; the sign
2156 : : bit is encoded with the rest of the number.
2157 : :
2158 : : Here are some examples, assuming the IEEE standard representation
2159 : : for floating point numbers. (Spaces are for readability, not
2160 : : part of the encoding.)
2161 : :
2162 : : 1.0f Lf 3f80 0000 E
2163 : : -1.0f Lf bf80 0000 E
2164 : : 1.17549435e-38f Lf 0080 0000 E
2165 : : 1.40129846e-45f Lf 0000 0001 E
2166 : : 0.0f Lf 0000 0000 E"
2167 : :
2168 : : Caller is responsible for the Lx and the E. */
2169 : : static void
2170 : 273 : write_real_cst (const tree value)
2171 : : {
2172 : 273 : long target_real[4]; /* largest supported float */
2173 : : /* Buffer for eight hex digits in a 32-bit number but big enough
2174 : : even for 64-bit long to avoid warnings. */
2175 : 273 : char buffer[17];
2176 : 273 : int i, limit, dir;
2177 : :
2178 : 273 : tree type = TREE_TYPE (value);
2179 : 273 : int bits = GET_MODE_BITSIZE (SCALAR_FLOAT_TYPE_MODE (type));
2180 : 273 : int words = bits / 32;
2181 : :
2182 : 273 : real_to_target (target_real, &TREE_REAL_CST (value),
2183 : 273 : TYPE_MODE (type));
2184 : :
2185 : 273 : if (words == 0)
2186 : : {
2187 : : /* _Float16 and std::bfloat16_t are the only supported types smaller than
2188 : : 32 bits. */
2189 : 6 : gcc_assert (bits == 16);
2190 : 6 : sprintf (buffer, "%04lx", (unsigned long) target_real[0]);
2191 : 6 : write_chars (buffer, 4);
2192 : 6 : return;
2193 : : }
2194 : :
2195 : 267 : gcc_assert (bits % 32 == 0);
2196 : :
2197 : : /* The value in target_real is in the target word order,
2198 : : so we must write it out backward if that happens to be
2199 : : little-endian. write_number cannot be used, it will
2200 : : produce uppercase. */
2201 : 267 : if (FLOAT_WORDS_BIG_ENDIAN)
2202 : : i = 0, limit = words, dir = 1;
2203 : : else
2204 : 267 : i = words - 1, limit = -1, dir = -1;
2205 : :
2206 : 291 : if (GET_MODE_PRECISION (SCALAR_FLOAT_TYPE_MODE (type)) == 80
2207 : 267 : && abi_check (21))
2208 : : {
2209 : : /* For -fabi-version=21 and above mangle
2210 : : Intel/Motorola extended format 1.0L as
2211 : : 3fff8000000000000000
2212 : : rather than the previous
2213 : : 0000000000003fff8000000000000000 (x86_64)
2214 : : 00003fff8000000000000000 (ia32)
2215 : : 3fff00008000000000000000 (m68k -mc68020)
2216 : : i.e. without any embedded padding bits. */
2217 : 26 : if (words == 4)
2218 : : i += dir;
2219 : : else
2220 : 0 : gcc_assert (words == 3);
2221 : 26 : unsigned long val = (unsigned long) target_real[i];
2222 : 26 : if (REAL_MODE_FORMAT (SCALAR_FLOAT_TYPE_MODE (type))->signbit_ro == 95)
2223 : 0 : val >>= 16;
2224 : 26 : sprintf (buffer, "%04lx", val);
2225 : 26 : write_chars (buffer, 4);
2226 : 26 : i += dir;
2227 : : }
2228 : :
2229 : 821 : for (; i != limit; i += dir)
2230 : : {
2231 : 554 : sprintf (buffer, "%08lx", (unsigned long) target_real[i]);
2232 : 554 : write_chars (buffer, 8);
2233 : : }
2234 : : }
2235 : :
2236 : : /* Non-terminal <identifier>.
2237 : :
2238 : : <identifier> ::= </unqualified source code identifier> */
2239 : :
2240 : : static void
2241 : 610057892 : write_identifier (const char *identifier)
2242 : : {
2243 : 610057892 : MANGLE_TRACE ("identifier", identifier);
2244 : 610057892 : write_string (identifier);
2245 : 610057892 : }
2246 : :
2247 : : /* Handle constructor productions of non-terminal <special-name>.
2248 : : CTOR is a constructor FUNCTION_DECL.
2249 : :
2250 : : <special-name> ::= C1 # complete object constructor
2251 : : ::= C2 # base object constructor
2252 : : ::= C3 # complete object allocating constructor
2253 : :
2254 : : Currently, allocating constructors are never used. */
2255 : :
2256 : : static void
2257 : 25123672 : write_special_name_constructor (const tree ctor)
2258 : : {
2259 : 25123672 : write_char ('C');
2260 : 25123672 : bool new_inh = (flag_new_inheriting_ctors
2261 : 50231617 : && DECL_INHERITED_CTOR (ctor));
2262 : 128648 : if (new_inh)
2263 : 128648 : write_char ('I');
2264 : 25123672 : if (DECL_BASE_CONSTRUCTOR_P (ctor))
2265 : 5166750 : write_char ('2');
2266 : : /* This is the old-style "[unified]" constructor.
2267 : : In some cases, we may emit this function and call
2268 : : it from the clones in order to share code and save space. */
2269 : 19956922 : else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
2270 : 14794293 : write_char ('4');
2271 : : else
2272 : : {
2273 : 5162629 : gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (ctor));
2274 : 5162629 : write_char ('1');
2275 : : }
2276 : 25123672 : if (new_inh)
2277 : 257296 : write_type (DECL_INHERITED_CTOR_BASE (ctor));
2278 : 25123672 : }
2279 : :
2280 : : /* Handle destructor productions of non-terminal <special-name>.
2281 : : DTOR is a destructor FUNCTION_DECL.
2282 : :
2283 : : <special-name> ::= D0 # deleting (in-charge) destructor
2284 : : ::= D1 # complete object (in-charge) destructor
2285 : : ::= D2 # base object (not-in-charge) destructor */
2286 : :
2287 : : static void
2288 : 6961698 : write_special_name_destructor (const tree dtor)
2289 : : {
2290 : 6961698 : if (DECL_DELETING_DESTRUCTOR_P (dtor))
2291 : 638227 : write_string ("D0");
2292 : 6323471 : else if (DECL_BASE_DESTRUCTOR_P (dtor))
2293 : 1479157 : write_string ("D2");
2294 : 4844314 : else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
2295 : : /* This is the old-style "[unified]" destructor.
2296 : : In some cases, we may emit this function and call
2297 : : it from the clones in order to share code and save space. */
2298 : 2750748 : write_string ("D4");
2299 : : else
2300 : : {
2301 : 2093566 : gcc_assert (DECL_COMPLETE_DESTRUCTOR_P (dtor));
2302 : 2093566 : write_string ("D1");
2303 : : }
2304 : 6961698 : }
2305 : :
2306 : : /* Return the discriminator for ENTITY appearing inside
2307 : : FUNCTION. The discriminator is the lexical ordinal of VAR or TYPE among
2308 : : entities with the same name and kind in the same FUNCTION. */
2309 : :
2310 : : static int
2311 : 2537493 : discriminator_for_local_entity (tree entity)
2312 : : {
2313 : 2537493 : if (!DECL_LANG_SPECIFIC (entity))
2314 : : {
2315 : : /* Some decls, like __FUNCTION__, don't need a discriminator. */
2316 : 31808 : gcc_checking_assert (DECL_ARTIFICIAL (entity));
2317 : : return 0;
2318 : : }
2319 : 4866871 : else if (tree disc = DECL_DISCRIMINATOR (entity))
2320 : 454 : return TREE_INT_CST_LOW (disc);
2321 : : else
2322 : : /* The first entity with a particular name doesn't get
2323 : : DECL_DISCRIMINATOR set up. */
2324 : : return 0;
2325 : : }
2326 : :
2327 : : /* Return the discriminator for STRING, a string literal used inside
2328 : : FUNCTION. The discriminator is the lexical ordinal of STRING among
2329 : : string literals used in FUNCTION. */
2330 : :
2331 : : static int
2332 : 0 : discriminator_for_string_literal (tree /*function*/,
2333 : : tree /*string*/)
2334 : : {
2335 : : /* For now, we don't discriminate amongst string literals. */
2336 : 0 : return 0;
2337 : : }
2338 : :
2339 : : /* <discriminator> := _ <number> # when number < 10
2340 : : := __ <number> _ # when number >= 10
2341 : :
2342 : : The discriminator is used only for the second and later occurrences
2343 : : of the same name within a single function. In this case <number> is
2344 : : n - 2, if this is the nth occurrence, in lexical order. */
2345 : :
2346 : : static void
2347 : 2537173 : write_discriminator (const int discriminator)
2348 : : {
2349 : : /* If discriminator is zero, don't write anything. Otherwise... */
2350 : 2537173 : if (discriminator > 0)
2351 : : {
2352 : 441 : write_char ('_');
2353 : 441 : if (discriminator - 1 >= 10)
2354 : : {
2355 : 6 : if (abi_check (11))
2356 : 6 : write_char ('_');
2357 : : }
2358 : 441 : write_unsigned_number (discriminator - 1);
2359 : 441 : if (abi_version_at_least (11) && discriminator - 1 >= 10)
2360 : 6 : write_char ('_');
2361 : : }
2362 : 2537173 : }
2363 : :
2364 : : /* Mangle the name of a function-scope entity. FUNCTION is the
2365 : : FUNCTION_DECL for the enclosing function, or a PARM_DECL for lambdas in
2366 : : default argument scope. ENTITY is the decl for the entity itself.
2367 : : LOCAL_ENTITY is the entity that's directly scoped in FUNCTION_DECL,
2368 : : either ENTITY itself or an enclosing scope of ENTITY.
2369 : :
2370 : : <local-name> := Z <function encoding> E <entity name> [<discriminator>]
2371 : : := Z <function encoding> E s [<discriminator>]
2372 : : := Z <function encoding> Ed [ <parameter number> ] _ <entity name> */
2373 : :
2374 : : static void
2375 : 4260576 : write_local_name (tree function, const tree local_entity,
2376 : : const tree entity)
2377 : : {
2378 : 4260576 : tree parm = NULL_TREE;
2379 : :
2380 : 4260576 : MANGLE_TRACE_TREE ("local-name", entity);
2381 : :
2382 : 4260576 : if (TREE_CODE (function) == PARM_DECL)
2383 : : {
2384 : 360 : parm = function;
2385 : 360 : function = DECL_CONTEXT (parm);
2386 : : }
2387 : :
2388 : 4260576 : write_char ('Z');
2389 : 4260576 : write_encoding (function);
2390 : 4260576 : write_char ('E');
2391 : :
2392 : : /* For this purpose, parameters are numbered from right-to-left. */
2393 : 4260576 : if (parm)
2394 : : {
2395 : 360 : int i = list_length (parm);
2396 : 360 : write_char ('d');
2397 : 360 : write_compact_number (i - 1);
2398 : : }
2399 : :
2400 : 4260576 : if (TREE_CODE (entity) == STRING_CST)
2401 : : {
2402 : 0 : write_char ('s');
2403 : 0 : write_discriminator (discriminator_for_string_literal (function,
2404 : : entity));
2405 : : }
2406 : : else
2407 : : {
2408 : : /* Now the <entity name>. Let write_name know its being called
2409 : : from <local-name>, so it doesn't try to process the enclosing
2410 : : function scope again. */
2411 : 4260576 : write_name (entity, /*ignore_local_scope=*/1);
2412 : 4260576 : if (DECL_DISCRIMINATOR_P (local_entity)
2413 : 12604860 : && !(TREE_CODE (local_entity) == TYPE_DECL
2414 : 12252354 : && TYPE_ANON_P (TREE_TYPE (local_entity))))
2415 : 2536914 : write_discriminator (discriminator_for_local_entity (local_entity));
2416 : : }
2417 : 4260576 : }
2418 : :
2419 : : /* Non-terminals <type> and <CV-qualifier>.
2420 : :
2421 : : <type> ::= <builtin-type>
2422 : : ::= <function-type>
2423 : : ::= <class-enum-type>
2424 : : ::= <array-type>
2425 : : ::= <pointer-to-member-type>
2426 : : ::= <template-param>
2427 : : ::= <substitution>
2428 : : ::= <CV-qualifier>
2429 : : ::= P <type> # pointer-to
2430 : : ::= R <type> # reference-to
2431 : : ::= C <type> # complex pair (C 2000)
2432 : : ::= G <type> # imaginary (C 2000) [not supported]
2433 : : ::= U <source-name> <type> # vendor extended type qualifier
2434 : :
2435 : : C++0x extensions
2436 : :
2437 : : <type> ::= RR <type> # rvalue reference-to
2438 : : <type> ::= Dt <expression> # decltype of an id-expression or
2439 : : # class member access
2440 : : <type> ::= DT <expression> # decltype of an expression
2441 : : <type> ::= Dn # decltype of nullptr
2442 : :
2443 : : TYPE is a type node. */
2444 : :
2445 : : static void
2446 : 1063629983 : write_type (tree type)
2447 : : {
2448 : : /* This gets set to nonzero if TYPE turns out to be a (possibly
2449 : : CV-qualified) builtin type. */
2450 : 1063629992 : int is_builtin_type = 0;
2451 : :
2452 : 1063629992 : MANGLE_TRACE_TREE ("type", type);
2453 : :
2454 : 1063629992 : if (type == error_mark_node)
2455 : : return;
2456 : :
2457 : 1063629977 : type = canonicalize_for_substitution (type);
2458 : 1063629977 : if (find_substitution (type))
2459 : : return;
2460 : :
2461 : :
2462 : 975175498 : if (write_CV_qualifiers_for_type (type) > 0)
2463 : : /* If TYPE was CV-qualified, we just wrote the qualifiers; now
2464 : : mangle the unqualified type. The recursive call is needed here
2465 : : since both the qualified and unqualified types are substitution
2466 : : candidates. */
2467 : : {
2468 : 64577941 : tree t = TYPE_MAIN_VARIANT (type);
2469 : 64577941 : if (TYPE_ATTRIBUTES (t) && !OVERLOAD_TYPE_P (t))
2470 : : {
2471 : 95 : tree attrs = NULL_TREE;
2472 : 95 : if (tx_safe_fn_type_p (type))
2473 : 3 : attrs = tree_cons (get_identifier ("transaction_safe"),
2474 : : NULL_TREE, attrs);
2475 : 95 : t = cp_build_type_attribute_variant (t, attrs);
2476 : : }
2477 : 64577941 : gcc_assert (t != type);
2478 : 64577941 : if (FUNC_OR_METHOD_TYPE_P (t))
2479 : : {
2480 : 3845 : t = build_ref_qualified_type (t, type_memfn_rqual (type));
2481 : 3845 : if (flag_noexcept_type)
2482 : : {
2483 : 3825 : tree r = TYPE_RAISES_EXCEPTIONS (type);
2484 : 3825 : t = build_exception_variant (t, r);
2485 : : }
2486 : 3845 : if (abi_version_at_least (8)
2487 : 3869 : || type == TYPE_MAIN_VARIANT (type))
2488 : : /* Avoid adding the unqualified function type as a substitution. */
2489 : 3821 : write_function_type (t);
2490 : : else
2491 : 24 : write_type (t);
2492 : 19108 : if (abi_warn_or_compat_version_crosses (8))
2493 : 39 : G.need_abi_warning = 1;
2494 : : }
2495 : : else
2496 : 64574096 : write_type (t);
2497 : : }
2498 : 910597557 : else if (TREE_CODE (type) == ARRAY_TYPE)
2499 : : /* It is important not to use the TYPE_MAIN_VARIANT of TYPE here
2500 : : so that the cv-qualification of the element type is available
2501 : : in write_array_type. */
2502 : 795465 : write_array_type (type);
2503 : : else
2504 : : {
2505 : 909802092 : tree type_orig = type;
2506 : :
2507 : : /* See through any typedefs. */
2508 : 909802092 : type = TYPE_MAIN_VARIANT (type);
2509 : 909802092 : if (FUNC_OR_METHOD_TYPE_P (type))
2510 : 3077828 : type = cxx_copy_lang_qualifiers (type, type_orig);
2511 : :
2512 : : /* According to the C++ ABI, some library classes are passed the
2513 : : same as the scalar type of their single member and use the same
2514 : : mangling. */
2515 : 909802092 : if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
2516 : 16206 : type = TREE_TYPE (first_field (type));
2517 : :
2518 : 909802092 : if (TYPE_PTRDATAMEM_P (type))
2519 : 8542 : write_pointer_to_member_type (type);
2520 : : else
2521 : : {
2522 : : /* Handle any target-specific fundamental types. */
2523 : 909793550 : const char *target_mangling
2524 : 909793550 : = targetm.mangle_type (type_orig);
2525 : :
2526 : 909793550 : if (target_mangling)
2527 : : {
2528 : 8771934 : write_string (target_mangling);
2529 : : /* Add substitutions for types other than fundamental
2530 : : types. */
2531 : 8771934 : if (!VOID_TYPE_P (type)
2532 : : && TREE_CODE (type) != INTEGER_TYPE
2533 : : && TREE_CODE (type) != REAL_TYPE
2534 : : && TREE_CODE (type) != BOOLEAN_TYPE)
2535 : 0 : add_substitution (type);
2536 : 8771934 : return;
2537 : : }
2538 : :
2539 : 901021616 : switch (TREE_CODE (type))
2540 : : {
2541 : 487916874 : case VOID_TYPE:
2542 : 487916874 : case BOOLEAN_TYPE:
2543 : 487916874 : case INTEGER_TYPE: /* Includes wchar_t. */
2544 : 487916874 : case REAL_TYPE:
2545 : 487916874 : case FIXED_POINT_TYPE:
2546 : 487916874 : {
2547 : : /* If this is a typedef, TYPE may not be one of
2548 : : the standard builtin type nodes, but an alias of one. Use
2549 : : TYPE_MAIN_VARIANT to get to the underlying builtin type. */
2550 : 487916874 : write_builtin_type (TYPE_MAIN_VARIANT (type));
2551 : 487916874 : ++is_builtin_type;
2552 : : }
2553 : 487916874 : break;
2554 : :
2555 : 755549 : case COMPLEX_TYPE:
2556 : 755549 : write_char ('C');
2557 : 755549 : write_type (TREE_TYPE (type));
2558 : 755549 : break;
2559 : :
2560 : 3077828 : case FUNCTION_TYPE:
2561 : 3077828 : case METHOD_TYPE:
2562 : 3077828 : write_function_type (type);
2563 : 3077828 : break;
2564 : :
2565 : 275913878 : case UNION_TYPE:
2566 : 275913878 : case RECORD_TYPE:
2567 : 275913878 : case ENUMERAL_TYPE:
2568 : : /* A pointer-to-member function is represented as a special
2569 : : RECORD_TYPE, so check for this first. */
2570 : 275913878 : if (TYPE_PTRMEMFUNC_P (type))
2571 : 273496 : write_pointer_to_member_type (type);
2572 : : else
2573 : 275640382 : write_class_enum_type (type);
2574 : : break;
2575 : :
2576 : 2210301 : case TYPENAME_TYPE:
2577 : 2210301 : case UNBOUND_CLASS_TEMPLATE:
2578 : : /* We handle TYPENAME_TYPEs and UNBOUND_CLASS_TEMPLATEs like
2579 : : ordinary nested names. */
2580 : 2210301 : write_nested_name (TYPE_STUB_DECL (type));
2581 : 2210301 : break;
2582 : :
2583 : 104380855 : case POINTER_TYPE:
2584 : 104380855 : case REFERENCE_TYPE:
2585 : 104380855 : if (TYPE_PTR_P (type))
2586 : 43789670 : write_char ('P');
2587 : 60591185 : else if (TYPE_REF_IS_RVALUE (type))
2588 : 10435900 : write_char ('O');
2589 : : else
2590 : 50155285 : write_char ('R');
2591 : 104380855 : {
2592 : 104380855 : tree target = TREE_TYPE (type);
2593 : : /* Attribute const/noreturn are not reflected in mangling.
2594 : : We strip them here rather than at a lower level because
2595 : : a typedef or template argument can have function type
2596 : : with function-cv-quals (that use the same representation),
2597 : : but you can't have a pointer/reference to such a type. */
2598 : 104380855 : if (TREE_CODE (target) == FUNCTION_TYPE)
2599 : : {
2600 : 10088880 : if (abi_warn_or_compat_version_crosses (5)
2601 : 2018130 : && TYPE_QUALS (target) != TYPE_UNQUALIFIED)
2602 : 3 : G.need_abi_warning = 1;
2603 : 2018124 : if (abi_version_at_least (5))
2604 : 2017695 : target = build_qualified_type (target, TYPE_UNQUALIFIED);
2605 : : }
2606 : 104380855 : write_type (target);
2607 : : }
2608 : 104380855 : break;
2609 : :
2610 : 22947372 : case TEMPLATE_TYPE_PARM:
2611 : 22947372 : if (is_auto (type))
2612 : : {
2613 : 515033 : if (template_placeholder_p (type)
2614 : 515033 : && abi_check (19))
2615 : : {
2616 : : /* ABI #109: placeholder is mangled as its template. */
2617 : 133 : type = CLASS_PLACEHOLDER_TEMPLATE (type);
2618 : 133 : if (find_substitution (type))
2619 : : return;
2620 : 33 : write_name (type, 0);
2621 : 33 : break;
2622 : : }
2623 : 514900 : if (AUTO_IS_DECLTYPE (type))
2624 : 48019 : write_identifier ("Dc");
2625 : : else
2626 : 466881 : write_identifier ("Da");
2627 : : ++is_builtin_type;
2628 : : break;
2629 : : }
2630 : : /* fall through. */
2631 : 22432339 : case TEMPLATE_PARM_INDEX:
2632 : 22432339 : write_template_param (type);
2633 : 22432339 : break;
2634 : :
2635 : 93 : case TEMPLATE_TEMPLATE_PARM:
2636 : 93 : write_template_template_param (type);
2637 : 93 : break;
2638 : :
2639 : 532 : case BOUND_TEMPLATE_TEMPLATE_PARM:
2640 : 532 : write_template_template_param (type);
2641 : 532 : write_template_args
2642 : 532 : (TI_ARGS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type)));
2643 : 532 : break;
2644 : :
2645 : 9391 : case VECTOR_TYPE:
2646 : 9391 : if (abi_version_at_least (4))
2647 : : {
2648 : 9376 : write_string ("Dv");
2649 : : /* Non-constant vector size would be encoded with
2650 : : _ expression, but we don't support that yet. */
2651 : 9376 : write_unsigned_number (TYPE_VECTOR_SUBPARTS (type)
2652 : : .to_constant ());
2653 : 9376 : write_char ('_');
2654 : 9376 : }
2655 : : else
2656 : 15 : write_string ("U8__vector");
2657 : 46910 : if (abi_warn_or_compat_version_crosses (4))
2658 : 15 : G.need_abi_warning = 1;
2659 : 9391 : write_type (TREE_TYPE (type));
2660 : 9391 : break;
2661 : :
2662 : 2867974 : case TYPE_PACK_EXPANSION:
2663 : 2867974 : write_string ("Dp");
2664 : 2867974 : write_type (PACK_EXPANSION_PATTERN (type));
2665 : 2867974 : break;
2666 : :
2667 : 388939 : case DECLTYPE_TYPE:
2668 : : /* These shouldn't make it into mangling. */
2669 : 388939 : gcc_assert (!DECLTYPE_FOR_LAMBDA_CAPTURE (type)
2670 : : && !DECLTYPE_FOR_LAMBDA_PROXY (type));
2671 : :
2672 : : /* In ABI <5, we stripped decltype of a plain decl. */
2673 : 388939 : if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
2674 : : {
2675 : 239 : tree expr = DECLTYPE_TYPE_EXPR (type);
2676 : 239 : tree etype = NULL_TREE;
2677 : 239 : switch (TREE_CODE (expr))
2678 : : {
2679 : 183 : case VAR_DECL:
2680 : 183 : case PARM_DECL:
2681 : 183 : case RESULT_DECL:
2682 : 183 : case FUNCTION_DECL:
2683 : 183 : case CONST_DECL:
2684 : 183 : case TEMPLATE_PARM_INDEX:
2685 : 183 : etype = TREE_TYPE (expr);
2686 : 183 : break;
2687 : :
2688 : : default:
2689 : : break;
2690 : : }
2691 : :
2692 : 183 : if (etype && !type_uses_auto (etype))
2693 : : {
2694 : 114 : if (!abi_check (5))
2695 : : {
2696 : : write_type (etype);
2697 : : return;
2698 : : }
2699 : : }
2700 : : }
2701 : :
2702 : 388930 : write_char ('D');
2703 : 388930 : if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
2704 : 230 : write_char ('t');
2705 : : else
2706 : 388700 : write_char ('T');
2707 : 388930 : ++cp_unevaluated_operand;
2708 : 388930 : write_expression (DECLTYPE_TYPE_EXPR (type));
2709 : 388930 : --cp_unevaluated_operand;
2710 : 388930 : write_char ('E');
2711 : 388930 : break;
2712 : :
2713 : 552001 : case NULLPTR_TYPE:
2714 : 552001 : write_string ("Dn");
2715 : 552001 : if (abi_check (7))
2716 : : ++is_builtin_type;
2717 : : break;
2718 : :
2719 : 3 : case TYPEOF_TYPE:
2720 : 3 : sorry ("mangling %<typeof%>, use %<decltype%> instead");
2721 : 3 : break;
2722 : :
2723 : 21 : case TRAIT_TYPE:
2724 : 21 : error ("use of built-in trait %qT in function signature; "
2725 : : "use library traits instead", type);
2726 : 21 : break;
2727 : :
2728 : 5 : case PACK_INDEX_TYPE:
2729 : : /* TODO Mangle pack indexing
2730 : : <https://github.com/itanium-cxx-abi/cxx-abi/issues/175>. */
2731 : 5 : sorry ("mangling type pack index");
2732 : 5 : break;
2733 : :
2734 : 0 : case LANG_TYPE:
2735 : : /* fall through. */
2736 : :
2737 : 0 : default:
2738 : 0 : gcc_unreachable ();
2739 : : }
2740 : : }
2741 : : }
2742 : :
2743 : : /* Types other than builtin types are substitution candidates. */
2744 : 965332748 : if (!is_builtin_type)
2745 : 477419682 : add_substitution (type);
2746 : : }
2747 : :
2748 : : /* qsort callback for sorting a vector of attribute entries. */
2749 : :
2750 : : static int
2751 : 0 : attr_strcmp (const void *p1, const void *p2)
2752 : : {
2753 : 0 : tree a1 = *(const tree*)p1;
2754 : 0 : tree a2 = *(const tree*)p2;
2755 : :
2756 : 0 : const attribute_spec *as1 = lookup_attribute_spec (get_attribute_name (a1));
2757 : 0 : const attribute_spec *as2 = lookup_attribute_spec (get_attribute_name (a2));
2758 : :
2759 : 0 : return strcmp (as1->name, as2->name);
2760 : : }
2761 : :
2762 : : /* Return true if we should mangle a type attribute with name NAME. */
2763 : :
2764 : : static bool
2765 : 11788 : mangle_type_attribute_p (tree name)
2766 : : {
2767 : 11788 : const attribute_spec *as = lookup_attribute_spec (name);
2768 : 11788 : if (!as || !as->affects_type_identity)
2769 : : return false;
2770 : :
2771 : : /* Skip internal-only attributes, which are distinguished from others
2772 : : by having a space. At present, all internal-only attributes that
2773 : : affect type identity are target-specific and are handled by
2774 : : targetm.mangle_type instead.
2775 : :
2776 : : Another reason to do this is that a space isn't a valid identifier
2777 : : character for most file formats. */
2778 : 53 : if (strchr (IDENTIFIER_POINTER (name), ' '))
2779 : : return false;
2780 : :
2781 : : /* The following attributes are mangled specially. */
2782 : 53 : if (is_attribute_p ("transaction_safe", name))
2783 : : return false;
2784 : 29 : if (is_attribute_p ("abi_tag", name))
2785 : 0 : return false;
2786 : :
2787 : : return true;
2788 : : }
2789 : :
2790 : : /* Non-terminal <CV-qualifiers> for type nodes. Returns the number of
2791 : : CV-qualifiers written for TYPE.
2792 : :
2793 : : <CV-qualifiers> ::= [r] [V] [K] */
2794 : :
2795 : : static int
2796 : 975448994 : write_CV_qualifiers_for_type (const tree type)
2797 : : {
2798 : 975448994 : int num_qualifiers = 0;
2799 : :
2800 : : /* The order is specified by:
2801 : :
2802 : : "In cases where multiple order-insensitive qualifiers are
2803 : : present, they should be ordered 'K' (closest to the base type),
2804 : : 'V', 'r', and 'U' (farthest from the base type) ..." */
2805 : :
2806 : : /* Mangle attributes that affect type identity as extended qualifiers.
2807 : :
2808 : : We don't do this with classes and enums because their attributes
2809 : : are part of their definitions, not something added on. */
2810 : :
2811 : 975448994 : if (!OVERLOAD_TYPE_P (type))
2812 : : {
2813 : 672075310 : auto_vec<tree> vec;
2814 : 672087098 : for (tree a = TYPE_ATTRIBUTES (type); a; a = TREE_CHAIN (a))
2815 : 11788 : if (mangle_type_attribute_p (get_attribute_name (a)))
2816 : 29 : vec.safe_push (a);
2817 : 3359616675 : if (abi_warn_or_compat_version_crosses (10) && !vec.is_empty ())
2818 : 0 : G.need_abi_warning = true;
2819 : 672075310 : if (abi_version_at_least (10))
2820 : : {
2821 : 671826717 : vec.qsort (attr_strcmp);
2822 : 672075368 : while (!vec.is_empty())
2823 : : {
2824 : 29 : tree a = vec.pop();
2825 : 29 : const attribute_spec *as
2826 : 29 : = lookup_attribute_spec (get_attribute_name (a));
2827 : :
2828 : 29 : write_char ('U');
2829 : 29 : write_unsigned_number (strlen (as->name));
2830 : 29 : write_string (as->name);
2831 : 29 : if (TREE_VALUE (a))
2832 : : {
2833 : 3 : write_char ('I');
2834 : 6 : for (tree args = TREE_VALUE (a); args;
2835 : 3 : args = TREE_CHAIN (args))
2836 : : {
2837 : 3 : tree arg = TREE_VALUE (args);
2838 : 3 : write_template_arg (arg);
2839 : : }
2840 : 3 : write_char ('E');
2841 : : }
2842 : :
2843 : 29 : ++num_qualifiers;
2844 : : }
2845 : : }
2846 : 672075310 : }
2847 : :
2848 : : /* Note that we do not use cp_type_quals below; given "const
2849 : : int[3]", the "const" is emitted with the "int", not with the
2850 : : array. */
2851 : 975448994 : cp_cv_quals quals = TYPE_QUALS (type);
2852 : :
2853 : 975448994 : if (quals & TYPE_QUAL_RESTRICT)
2854 : : {
2855 : 39 : write_char ('r');
2856 : 39 : ++num_qualifiers;
2857 : : }
2858 : 975448994 : if (quals & TYPE_QUAL_VOLATILE)
2859 : : {
2860 : 274483 : write_char ('V');
2861 : 274483 : ++num_qualifiers;
2862 : : }
2863 : 975448994 : if (quals & TYPE_QUAL_CONST)
2864 : : {
2865 : 64515797 : write_char ('K');
2866 : 64515797 : ++num_qualifiers;
2867 : : }
2868 : :
2869 : 975448994 : return num_qualifiers;
2870 : : }
2871 : :
2872 : : /* Non-terminal <builtin-type>.
2873 : :
2874 : : <builtin-type> ::= v # void
2875 : : ::= b # bool
2876 : : ::= w # wchar_t
2877 : : ::= c # char
2878 : : ::= a # signed char
2879 : : ::= h # unsigned char
2880 : : ::= s # short
2881 : : ::= t # unsigned short
2882 : : ::= i # int
2883 : : ::= j # unsigned int
2884 : : ::= l # long
2885 : : ::= m # unsigned long
2886 : : ::= x # long long, __int64
2887 : : ::= y # unsigned long long, __int64
2888 : : ::= n # __int128
2889 : : ::= o # unsigned __int128
2890 : : ::= f # float
2891 : : ::= d # double
2892 : : ::= e # long double, __float80
2893 : : ::= g # __float128 [not supported]
2894 : : ::= u <source-name> # vendor extended type */
2895 : :
2896 : : static void
2897 : 487916874 : write_builtin_type (tree type)
2898 : : {
2899 : 487916874 : if (TYPE_CANONICAL (type))
2900 : 487916874 : type = TYPE_CANONICAL (type);
2901 : :
2902 : 487916874 : switch (TREE_CODE (type))
2903 : : {
2904 : 65607213 : case VOID_TYPE:
2905 : 65607213 : write_char ('v');
2906 : 65607213 : break;
2907 : :
2908 : 46095835 : case BOOLEAN_TYPE:
2909 : 46095835 : write_char ('b');
2910 : 46095835 : break;
2911 : :
2912 : 360030511 : case INTEGER_TYPE:
2913 : : /* TYPE may still be wchar_t, char8_t, char16_t, or char32_t, since that
2914 : : isn't in integer_type_nodes. */
2915 : 360030511 : if (type == wchar_type_node)
2916 : 36427758 : write_char ('w');
2917 : 323602753 : else if (type == char8_type_node)
2918 : 5273169 : write_string ("Du");
2919 : 318329584 : else if (type == char16_type_node)
2920 : 20254065 : write_string ("Ds");
2921 : 298075519 : else if (type == char32_type_node)
2922 : 22406426 : write_string ("Di");
2923 : : else
2924 : : {
2925 : 275669109 : size_t itk;
2926 : : /* Assume TYPE is one of the shared integer type nodes. Find
2927 : : it in the array of these nodes. */
2928 : 275669093 : iagain:
2929 : 1714430106 : for (itk = 0; itk < itk_none; ++itk)
2930 : 1713061483 : if (integer_types[itk] != NULL_TREE
2931 : 1704849745 : && integer_type_codes[itk] != '\0'
2932 : 1702112499 : && type == integer_types[itk])
2933 : : {
2934 : : /* Print the corresponding single-letter code. */
2935 : 274300486 : write_char (integer_type_codes[itk]);
2936 : 274300486 : break;
2937 : : }
2938 : :
2939 : 275669109 : if (itk == itk_none)
2940 : : {
2941 : 1368623 : tree t = c_common_type_for_mode (TYPE_MODE (type),
2942 : 1368623 : TYPE_UNSIGNED (type));
2943 : 1368623 : if (type != t)
2944 : : {
2945 : 16 : type = t;
2946 : 16 : goto iagain;
2947 : : }
2948 : :
2949 : 1368607 : if (TYPE_PRECISION (type) == 128)
2950 : 1937624 : write_char (TYPE_UNSIGNED (type) ? 'o' : 'n');
2951 : : else
2952 : : {
2953 : : /* Allow for cases where TYPE is not one of the shared
2954 : : integer type nodes and write a "vendor extended builtin
2955 : : type" with a name the form intN or uintN, respectively.
2956 : : Situations like this can happen if you have an
2957 : : __attribute__((__mode__(__SI__))) type and use exotic
2958 : : switches like '-mint8' on AVR. Of course, this is
2959 : : undefined by the C++ ABI (and '-mint8' is not even
2960 : : Standard C conforming), but when using such special
2961 : : options you're pretty much in nowhere land anyway. */
2962 : 0 : const char *prefix;
2963 : 0 : char prec[11]; /* up to ten digits for an unsigned */
2964 : :
2965 : 0 : prefix = TYPE_UNSIGNED (type) ? "uint" : "int";
2966 : 0 : sprintf (prec, "%u", (unsigned) TYPE_PRECISION (type));
2967 : 0 : write_char ('u'); /* "vendor extended builtin type" */
2968 : 0 : write_unsigned_number (strlen (prefix) + strlen (prec));
2969 : 0 : write_string (prefix);
2970 : 0 : write_string (prec);
2971 : : }
2972 : : }
2973 : : }
2974 : : break;
2975 : :
2976 : 16183315 : case REAL_TYPE:
2977 : 16183315 : if (type == float_type_node)
2978 : 4835899 : write_char ('f');
2979 : 11347416 : else if (type == double_type_node)
2980 : 8678854 : write_char ('d');
2981 : 2668562 : else if (type == long_double_type_node)
2982 : 0 : write_char ('e');
2983 : 2668562 : else if (type == dfloat32_type_node)
2984 : 6152 : write_string ("Df");
2985 : 2662410 : else if (type == dfloat64_type_node)
2986 : 6041 : write_string ("Dd");
2987 : 2656369 : else if (type == dfloat128_type_node)
2988 : 6005 : write_string ("De");
2989 : 2650364 : else if (type == float16_type_node)
2990 : 0 : write_string ("DF16_");
2991 : 2650364 : else if (type == float32_type_node)
2992 : 883002 : write_string ("DF32_");
2993 : 1767362 : else if (type == float64_type_node)
2994 : 883002 : write_string ("DF64_");
2995 : 884360 : else if (type == float128_type_node)
2996 : 823120 : write_string ("DF128_");
2997 : 61240 : else if (type == float32x_type_node)
2998 : 30620 : write_string ("DF32x");
2999 : 30620 : else if (type == float64x_type_node)
3000 : 30620 : write_string ("DF64x");
3001 : 0 : else if (type == float128x_type_node)
3002 : 0 : write_string ("DF128x");
3003 : 0 : else if (type == bfloat16_type_node)
3004 : 0 : write_string ("DF16b");
3005 : : else
3006 : 0 : gcc_unreachable ();
3007 : : break;
3008 : :
3009 : 0 : default:
3010 : 0 : gcc_unreachable ();
3011 : : }
3012 : 487916874 : }
3013 : :
3014 : : /* Non-terminal <function-type>. NODE is a FUNCTION_TYPE or
3015 : : METHOD_TYPE. The return type is mangled before the parameter
3016 : : types.
3017 : :
3018 : : <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
3019 : :
3020 : : static void
3021 : 3081649 : write_function_type (const tree type)
3022 : : {
3023 : 3081649 : MANGLE_TRACE_TREE ("function-type", type);
3024 : :
3025 : : /* For a pointer to member function, the function type may have
3026 : : cv-qualifiers, indicating the quals for the artificial 'this'
3027 : : parameter. */
3028 : 3081649 : if (TREE_CODE (type) == METHOD_TYPE)
3029 : : {
3030 : : /* The first parameter must be a POINTER_TYPE pointing to the
3031 : : `this' parameter. */
3032 : 273496 : tree this_type = class_of_this_parm (type);
3033 : 273496 : write_CV_qualifiers_for_type (this_type);
3034 : : }
3035 : :
3036 : 3081649 : write_exception_spec (TYPE_RAISES_EXCEPTIONS (type));
3037 : :
3038 : 3081649 : if (tx_safe_fn_type_p (type))
3039 : 24 : write_string ("Dx");
3040 : :
3041 : 3081649 : write_char ('F');
3042 : : /* We don't track whether or not a type is `extern "C"'. Note that
3043 : : you can have an `extern "C"' function that does not have
3044 : : `extern "C"' type, and vice versa:
3045 : :
3046 : : extern "C" typedef void function_t();
3047 : : function_t f; // f has C++ linkage, but its type is
3048 : : // `extern "C"'
3049 : :
3050 : : typedef void function_t();
3051 : : extern "C" function_t f; // Vice versa.
3052 : :
3053 : : See [dcl.link]. */
3054 : 3081649 : write_bare_function_type (type, /*include_return_type_p=*/1,
3055 : : /*decl=*/NULL);
3056 : 3081649 : if (FUNCTION_REF_QUALIFIED (type))
3057 : : {
3058 : 1500 : if (FUNCTION_RVALUE_QUALIFIED (type))
3059 : 622 : write_char ('O');
3060 : : else
3061 : 878 : write_char ('R');
3062 : : }
3063 : 3081649 : write_char ('E');
3064 : 3081649 : }
3065 : :
3066 : : /* Non-terminal <bare-function-type>. TYPE is a FUNCTION_TYPE or
3067 : : METHOD_TYPE. If INCLUDE_RETURN_TYPE is nonzero, the return value
3068 : : is mangled before the parameter types. If non-NULL, DECL is
3069 : : FUNCTION_DECL for the function whose type is being emitted. */
3070 : :
3071 : : static void
3072 : 160955791 : write_bare_function_type (const tree type, const int include_return_type_p,
3073 : : const tree decl)
3074 : : {
3075 : 160955791 : MANGLE_TRACE_TREE ("bare-function-type", type);
3076 : :
3077 : : /* Mangle the return type, if requested. */
3078 : 160955791 : if (include_return_type_p)
3079 : 14750055 : write_type (TREE_TYPE (type));
3080 : :
3081 : : /* Now mangle the types of the arguments. */
3082 : 160955791 : ++G.parm_depth;
3083 : 160955791 : write_method_parms (TYPE_ARG_TYPES (type),
3084 : 160955791 : TREE_CODE (type) == METHOD_TYPE,
3085 : : decl);
3086 : 160955791 : --G.parm_depth;
3087 : 160955791 : }
3088 : :
3089 : : /* Write the mangled representation of a method parameter list of
3090 : : types given in PARM_TYPES. If METHOD_P is nonzero, the function is
3091 : : considered a non-static method, and the this parameter is omitted.
3092 : : If non-NULL, DECL is the FUNCTION_DECL for the function whose
3093 : : parameters are being emitted. */
3094 : :
3095 : : static void
3096 : 162696416 : write_method_parms (tree parm_types, const int method_p, const tree decl)
3097 : : {
3098 : 162696416 : tree first_parm_type;
3099 : 308578675 : tree parm_decl = decl ? DECL_ARGUMENTS (decl) : NULL_TREE;
3100 : :
3101 : : /* Assume this parameter type list is variable-length. If it ends
3102 : : with a void type, then it's not. */
3103 : 162696416 : int varargs_p = 1;
3104 : :
3105 : : /* If this is a member function, skip the first arg, which is the
3106 : : this pointer.
3107 : : "Member functions do not encode the type of their implicit this
3108 : : parameter."
3109 : :
3110 : : Similarly, there's no need to mangle artificial parameters, like
3111 : : the VTT parameters for constructors and destructors. */
3112 : 162696416 : if (method_p)
3113 : : {
3114 : 127570669 : parm_types = TREE_CHAIN (parm_types);
3115 : 127570669 : parm_decl = parm_decl ? DECL_CHAIN (parm_decl) : NULL_TREE;
3116 : :
3117 : 127612685 : while (parm_decl && DECL_ARTIFICIAL (parm_decl))
3118 : : {
3119 : 42016 : parm_types = TREE_CHAIN (parm_types);
3120 : 42016 : parm_decl = DECL_CHAIN (parm_decl);
3121 : : }
3122 : :
3123 : 127570669 : if (decl && ctor_omit_inherited_parms (decl))
3124 : : /* Bring back parameters omitted from an inherited ctor. */
3125 : 54 : parm_types = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (decl));
3126 : : }
3127 : :
3128 : 162696416 : for (first_parm_type = parm_types;
3129 : 509734917 : parm_types;
3130 : 347038501 : parm_types = TREE_CHAIN (parm_types))
3131 : : {
3132 : 347038501 : tree parm = TREE_VALUE (parm_types);
3133 : 347038501 : if (parm == void_type_node)
3134 : : {
3135 : : /* "Empty parameter lists, whether declared as () or
3136 : : conventionally as (void), are encoded with a void parameter
3137 : : (v)." */
3138 : 162636644 : if (parm_types == first_parm_type)
3139 : 54127557 : write_type (parm);
3140 : : /* If the parm list is terminated with a void type, it's
3141 : : fixed-length. */
3142 : 162636644 : varargs_p = 0;
3143 : : /* A void type better be the last one. */
3144 : 162636644 : gcc_assert (TREE_CHAIN (parm_types) == NULL);
3145 : : }
3146 : : else
3147 : 184401857 : write_type (parm);
3148 : : }
3149 : :
3150 : 162696416 : if (varargs_p)
3151 : : /* <builtin-type> ::= z # ellipsis */
3152 : 59772 : write_char ('z');
3153 : 162696416 : }
3154 : :
3155 : : /* <class-enum-type> ::= <name> */
3156 : :
3157 : : static void
3158 : 275640382 : write_class_enum_type (const tree type)
3159 : : {
3160 : 275640382 : write_name (TYPE_NAME (type), /*ignore_local_scope=*/0);
3161 : 275640382 : }
3162 : :
3163 : : /* Mangle a requirement REQ in a requires-expression. */
3164 : :
3165 : : static void
3166 : 242484 : write_requirement (tree req)
3167 : : {
3168 : 242484 : tree op = TREE_OPERAND (req, 0);
3169 : :
3170 : 242484 : switch (tree_code code = TREE_CODE (req))
3171 : : {
3172 : : /* # simple-requirement or compound-requirement
3173 : : <requirement> ::= X <expression> [ N ] [ R <type-constraint> ] */
3174 : 242178 : case SIMPLE_REQ:
3175 : 242178 : case COMPOUND_REQ:
3176 : 242178 : write_char ('X');
3177 : 242178 : write_expression (op);
3178 : 242178 : if (code == SIMPLE_REQ)
3179 : : break;
3180 : 53777 : if (COMPOUND_REQ_NOEXCEPT_P (req))
3181 : 3 : write_char ('N');
3182 : 53777 : if (tree constr = TREE_OPERAND (req, 1))
3183 : : {
3184 : 53774 : write_char ('R');
3185 : 53774 : write_type_constraint (PLACEHOLDER_TYPE_CONSTRAINTS (constr));
3186 : : }
3187 : : break;
3188 : :
3189 : : /* <requirement> ::= T <type> # type-requirement */
3190 : 303 : case TYPE_REQ:
3191 : 303 : write_char ('T');
3192 : 303 : write_type (op);
3193 : 303 : break;
3194 : :
3195 : : /* <requirement> ::= Q <constraint-expression> # nested-requirement */
3196 : 3 : case NESTED_REQ:
3197 : 3 : write_char ('Q');
3198 : 3 : write_constraint_expression (op);
3199 : 3 : break;
3200 : :
3201 : 0 : default:
3202 : 0 : gcc_unreachable ();
3203 : : }
3204 : 242484 : }
3205 : :
3206 : : /* # requires { ... }
3207 : : <expression> ::= rq <requirement>+ E
3208 : : # requires (...) { ... }
3209 : : <expression> ::= rQ <bare-function-type> _ <requirement>+ E */
3210 : :
3211 : : static void
3212 : 228984 : write_requires_expr (tree expr)
3213 : : {
3214 : 228984 : tree parms = REQUIRES_EXPR_PARMS (expr);
3215 : 228984 : if (parms)
3216 : : {
3217 : 36192 : write_string ("rQ");
3218 : 36192 : ++G.parm_depth;
3219 : 72633 : for (; parms; parms = DECL_CHAIN (parms))
3220 : 36441 : write_type (cv_unqualified (TREE_TYPE (parms)));
3221 : 36192 : --G.parm_depth;
3222 : 36192 : write_char ('_');
3223 : : }
3224 : : else
3225 : 192792 : write_string ("rq");
3226 : :
3227 : 471468 : for (tree reqs = REQUIRES_EXPR_REQS (expr); reqs;
3228 : 242484 : reqs = TREE_CHAIN (reqs))
3229 : 242484 : write_requirement (TREE_VALUE (reqs));
3230 : :
3231 : 228984 : write_char ('E');
3232 : 228984 : }
3233 : :
3234 : : /* Non-terminal <template-args>. ARGS is a TREE_VEC of template
3235 : : arguments.
3236 : :
3237 : : <template-args> ::= I <template-arg>* [Q <constraint-expr>] E */
3238 : :
3239 : : static void
3240 : 344110535 : write_template_args (tree args, tree parms /*= NULL_TREE*/)
3241 : : {
3242 : 344110535 : int i;
3243 : 344110535 : int length = 0;
3244 : :
3245 : 344110535 : MANGLE_TRACE_TREE ("template-args", args);
3246 : :
3247 : 344110535 : write_char ('I');
3248 : :
3249 : 344110535 : if (args)
3250 : 344110535 : length = TREE_VEC_LENGTH (args);
3251 : :
3252 : 344110535 : tree constraints = NULL_TREE;
3253 : 344110535 : if (parms)
3254 : : {
3255 : 3886519 : constraints = TEMPLATE_PARMS_CONSTRAINTS (parms);
3256 : 3886519 : parms = INNERMOST_TEMPLATE_PARMS (parms);
3257 : : }
3258 : :
3259 : 344110535 : if (args && length && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
3260 : : {
3261 : : /* We have nested template args. We want the innermost template
3262 : : argument list. */
3263 : 4911506 : args = TREE_VEC_ELT (args, length - 1);
3264 : 4911506 : length = TREE_VEC_LENGTH (args);
3265 : : }
3266 : 344110535 : if (TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args))
3267 : : /* Skip the constrained type. */
3268 : : i = 1;
3269 : : else
3270 : 344083474 : i = 0;
3271 : : bool implicit_parm_scope = false;
3272 : 969866503 : for (; i < length; ++i)
3273 : : {
3274 : 625755968 : tree arg = TREE_VEC_ELT (args, i);
3275 : 625755968 : if (parms)
3276 : : {
3277 : 6719101 : tree parm = TREE_VEC_ELT (parms, i);
3278 : 6719101 : tree decl = TREE_VALUE (parm);
3279 : 6719101 : if (DECL_IMPLICIT_TEMPLATE_PARM_P (decl)
3280 : 6719101 : && !implicit_parm_scope)
3281 : : {
3282 : : /* The rest of the template parameters are based on generic
3283 : : function parameters, so any expressions in their
3284 : : type-constraints are in parameter scope. */
3285 : 1732 : implicit_parm_scope = true;
3286 : 1732 : ++G.parm_depth;
3287 : : }
3288 : 6719101 : if (!template_parm_natural_p (arg, parm)
3289 : 6719101 : && abi_check (19))
3290 : 64068 : write_template_param_decl (parm);
3291 : : }
3292 : 625755968 : write_template_arg (arg);
3293 : : }
3294 : 344110535 : if (implicit_parm_scope)
3295 : 1732 : --G.parm_depth;
3296 : :
3297 : 344110535 : write_tparms_constraints (constraints);
3298 : :
3299 : 344110535 : write_char ('E');
3300 : 344110535 : }
3301 : :
3302 : : /* Write out the
3303 : : <unqualified-name>
3304 : : <unqualified-name> <template-args>
3305 : : part of SCOPE_REF or COMPONENT_REF mangling. */
3306 : :
3307 : : static void
3308 : 399110 : write_member_name (tree member)
3309 : : {
3310 : 399110 : if (identifier_p (member))
3311 : : {
3312 : 273063 : if (IDENTIFIER_ANY_OP_P (member))
3313 : : {
3314 : 24886 : if (abi_check (11))
3315 : 24862 : write_string ("on");
3316 : : }
3317 : 273063 : write_unqualified_id (member);
3318 : : }
3319 : 126047 : else if (DECL_P (member))
3320 : : {
3321 : 1384 : if (ANON_AGGR_TYPE_P (TREE_TYPE (member)))
3322 : : ;
3323 : 1378 : else if (DECL_OVERLOADED_OPERATOR_P (member))
3324 : : {
3325 : 15 : if (abi_check (16))
3326 : 9 : write_string ("on");
3327 : : }
3328 : 1384 : write_unqualified_name (member);
3329 : : }
3330 : 124663 : else if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
3331 : : {
3332 : 271 : tree name = TREE_OPERAND (member, 0);
3333 : 271 : name = OVL_FIRST (name);
3334 : 271 : write_member_name (name);
3335 : 271 : write_template_args (TREE_OPERAND (member, 1));
3336 : : }
3337 : : else
3338 : 124392 : write_expression (member);
3339 : 399110 : }
3340 : :
3341 : : /* EXPR is a base COMPONENT_REF; write the minimized base conversion path for
3342 : : converting to BASE, or just the conversion of EXPR if BASE is null.
3343 : :
3344 : : "Given a fully explicit base path P := C_n -> ... -> C_0, the minimized base
3345 : : path Min(P) is defined as follows: let C_i be the last element for which the
3346 : : conversion to C_0 is unambiguous; if that element is C_n, the minimized path
3347 : : is C_n -> C_0; otherwise, the minimized path is Min(C_n -> ... -> C_i) ->
3348 : : C_0."
3349 : :
3350 : : We mangle the conversion to C_i if it's different from C_n. */
3351 : :
3352 : : static bool
3353 : 158707 : write_base_ref (tree expr, tree base = NULL_TREE)
3354 : : {
3355 : 158707 : if (TREE_CODE (expr) != COMPONENT_REF)
3356 : : return false;
3357 : :
3358 : 158701 : tree field = TREE_OPERAND (expr, 1);
3359 : :
3360 : 158701 : if (TREE_CODE (field) != FIELD_DECL || !DECL_FIELD_IS_BASE (field))
3361 : : return false;
3362 : :
3363 : 18 : tree object = TREE_OPERAND (expr, 0);
3364 : :
3365 : 18 : tree binfo = NULL_TREE;
3366 : 18 : if (base)
3367 : : {
3368 : 9 : tree cur = TREE_TYPE (object);
3369 : 9 : binfo = lookup_base (cur, base, ba_unique, NULL, tf_none);
3370 : : }
3371 : : else
3372 : : /* We're at the end of the base conversion chain, so it can't be
3373 : : ambiguous. */
3374 : 9 : base = TREE_TYPE (field);
3375 : :
3376 : 18 : if (binfo == error_mark_node)
3377 : : {
3378 : : /* cur->base is ambiguous, so make the conversion to
3379 : : last explicit, expressed as a cast (last&)object. */
3380 : 3 : tree last = TREE_TYPE (expr);
3381 : 3 : write_string (OVL_OP_INFO (false, CAST_EXPR)->mangled_name);
3382 : 3 : write_type (build_reference_type (last));
3383 : 3 : write_expression (object);
3384 : : }
3385 : 15 : else if (write_base_ref (object, base))
3386 : : /* cur->base is unambiguous, but we had another base conversion
3387 : : underneath and wrote it out. */;
3388 : : else
3389 : : /* No more base conversions, just write out the object. */
3390 : 6 : write_expression (object);
3391 : :
3392 : : return true;
3393 : : }
3394 : :
3395 : : /* The number of elements spanned by a RANGE_EXPR. */
3396 : :
3397 : : unsigned HOST_WIDE_INT
3398 : 9 : range_expr_nelts (tree expr)
3399 : : {
3400 : 9 : tree lo = TREE_OPERAND (expr, 0);
3401 : 9 : tree hi = TREE_OPERAND (expr, 1);
3402 : 9 : return tree_to_uhwi (hi) - tree_to_uhwi (lo) + 1;
3403 : : }
3404 : :
3405 : : /* <expression> ::= <unary operator-name> <expression>
3406 : : ::= <binary operator-name> <expression> <expression>
3407 : : ::= <expr-primary>
3408 : :
3409 : : <expr-primary> ::= <template-param>
3410 : : ::= L <type> <value number> E # literal
3411 : : ::= L <mangled-name> E # external name
3412 : : ::= st <type> # sizeof
3413 : : ::= sr <type> <unqualified-name> # dependent name
3414 : : ::= sr <type> <unqualified-name> <template-args> */
3415 : :
3416 : : static void
3417 : 7432646 : write_expression (tree expr)
3418 : : {
3419 : 7606156 : enum tree_code code = TREE_CODE (expr);
3420 : :
3421 : 7606156 : if (TREE_CODE (expr) == TARGET_EXPR)
3422 : : {
3423 : 0 : expr = TARGET_EXPR_INITIAL (expr);
3424 : 0 : code = TREE_CODE (expr);
3425 : : }
3426 : :
3427 : : /* Skip NOP_EXPR and CONVERT_EXPR. They can occur when (say) a pointer
3428 : : argument is converted (via qualification conversions) to another type. */
3429 : 7912370 : while (CONVERT_EXPR_CODE_P (code)
3430 : 7796755 : || code == IMPLICIT_CONV_EXPR
3431 : 7796583 : || location_wrapper_p (expr)
3432 : : /* Parentheses aren't mangled. */
3433 : 7606522 : || code == PAREN_EXPR
3434 : 7606522 : || code == NON_LVALUE_EXPR
3435 : 15518892 : || (code == VIEW_CONVERT_EXPR
3436 : 366 : && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX))
3437 : : {
3438 : 306214 : expr = TREE_OPERAND (expr, 0);
3439 : 306214 : code = TREE_CODE (expr);
3440 : : }
3441 : :
3442 : 7606156 : if (code == BASELINK
3443 : 7606156 : && (!type_unknown_p (expr)
3444 : 342733 : || !BASELINK_QUALIFIED_P (expr)))
3445 : : {
3446 : 353523 : expr = BASELINK_FUNCTIONS (expr);
3447 : 353523 : code = TREE_CODE (expr);
3448 : : }
3449 : :
3450 : : /* Handle pointers-to-members by making them look like expression
3451 : : nodes. */
3452 : 7606156 : if (code == PTRMEM_CST)
3453 : : {
3454 : 6866 : expr = build_nt (ADDR_EXPR,
3455 : : build_qualified_name (/*type=*/NULL_TREE,
3456 : 3433 : PTRMEM_CST_CLASS (expr),
3457 : 3433 : PTRMEM_CST_MEMBER (expr),
3458 : : /*template_p=*/false));
3459 : 3433 : code = TREE_CODE (expr);
3460 : : }
3461 : :
3462 : : /* Handle template parameters. */
3463 : 7606156 : if (code == TEMPLATE_TYPE_PARM
3464 : 7606156 : || code == TEMPLATE_TEMPLATE_PARM
3465 : 7606156 : || code == BOUND_TEMPLATE_TEMPLATE_PARM
3466 : 7602501 : || code == TEMPLATE_PARM_INDEX)
3467 : 490857 : write_template_param (expr);
3468 : : /* Handle literals. */
3469 : 7115299 : else if (TREE_CODE_CLASS (code) == tcc_constant
3470 : 6983435 : || code == CONST_DECL)
3471 : 145299 : write_template_arg_literal (expr);
3472 : 6970000 : else if (code == EXCESS_PRECISION_EXPR
3473 : 6970000 : && TREE_CODE (TREE_OPERAND (expr, 0)) == REAL_CST)
3474 : 0 : write_template_arg_literal (fold_convert (TREE_TYPE (expr),
3475 : : TREE_OPERAND (expr, 0)));
3476 : 6970000 : else if (code == PARM_DECL && DECL_ARTIFICIAL (expr))
3477 : : {
3478 : 114845 : gcc_assert (id_equal (DECL_NAME (expr), "this"));
3479 : 114845 : write_string ("fpT");
3480 : : }
3481 : 6855155 : else if (code == PARM_DECL)
3482 : : {
3483 : : /* A function parameter used in a late-specified return type. */
3484 : 172635 : int index = DECL_PARM_INDEX (expr);
3485 : 172635 : int level = DECL_PARM_LEVEL (expr);
3486 : 172635 : int delta = G.parm_depth - level + 1;
3487 : 172635 : gcc_assert (index >= 1);
3488 : 172635 : write_char ('f');
3489 : 172635 : if (delta != 0)
3490 : : {
3491 : 86444 : gcc_checking_assert (delta > 0);
3492 : 86444 : if (abi_check (5))
3493 : : {
3494 : : /* Let L be the number of function prototype scopes from the
3495 : : innermost one (in which the parameter reference occurs) up
3496 : : to (and including) the one containing the declaration of
3497 : : the referenced parameter. If the parameter declaration
3498 : : clause of the innermost function prototype scope has been
3499 : : completely seen, it is not counted (in that case -- which
3500 : : is perhaps the most common -- L can be zero). */
3501 : 86441 : write_char ('L');
3502 : 86441 : write_unsigned_number (delta - 1);
3503 : : }
3504 : : }
3505 : 172635 : write_char ('p');
3506 : 172635 : write_compact_number (index - 1);
3507 : : }
3508 : 6682520 : else if (DECL_P (expr))
3509 : : {
3510 : 307738 : write_char ('L');
3511 : 307738 : write_mangled_name (expr, false);
3512 : 307738 : write_char ('E');
3513 : : }
3514 : 6374782 : else if (TREE_CODE (expr) == SIZEOF_EXPR)
3515 : : {
3516 : 4963 : tree op = TREE_OPERAND (expr, 0);
3517 : :
3518 : 4963 : if (PACK_EXPANSION_P (op))
3519 : : {
3520 : 3739 : sizeof_pack:
3521 : 3742 : if (abi_check (11))
3522 : : {
3523 : : /* sZ rather than szDp. */
3524 : 3733 : write_string ("sZ");
3525 : 3733 : write_expression (PACK_EXPANSION_PATTERN (op));
3526 : 3733 : return;
3527 : : }
3528 : : }
3529 : :
3530 : 1233 : if (SIZEOF_EXPR_TYPE_P (expr))
3531 : : {
3532 : 0 : write_string ("st");
3533 : 0 : write_type (TREE_TYPE (op));
3534 : : }
3535 : 1233 : else if (ARGUMENT_PACK_P (op))
3536 : : {
3537 : 15 : tree args = ARGUMENT_PACK_ARGS (op);
3538 : 15 : int length = TREE_VEC_LENGTH (args);
3539 : 15 : if (abi_check (10))
3540 : : {
3541 : : /* Before v19 we wrongly mangled all single pack expansions with
3542 : : sZ, but now only for expressions, as types ICEd (95298). */
3543 : 12 : if (length == 1)
3544 : : {
3545 : 9 : tree arg = TREE_VEC_ELT (args, 0);
3546 : 9 : if (TREE_CODE (arg) == EXPR_PACK_EXPANSION
3547 : 9 : && !abi_check (19))
3548 : : {
3549 : 3 : op = arg;
3550 : 3 : goto sizeof_pack;
3551 : : }
3552 : : }
3553 : :
3554 : : /* sP <template-arg>* E # sizeof...(T), size of a captured
3555 : : template parameter pack from an alias template */
3556 : 9 : write_string ("sP");
3557 : 24 : for (int i = 0; i < length; ++i)
3558 : 15 : write_template_arg (TREE_VEC_ELT (args, i));
3559 : 9 : write_char ('E');
3560 : : }
3561 : : else
3562 : : {
3563 : : /* In GCC 5 we represented this sizeof wrong, with the effect
3564 : : that we mangled it as the last element of the pack. */
3565 : 3 : tree arg = TREE_VEC_ELT (args, length-1);
3566 : 3 : if (TYPE_P (op))
3567 : : {
3568 : 3 : write_string ("st");
3569 : 3 : write_type (arg);
3570 : : }
3571 : : else
3572 : : {
3573 : 0 : write_string ("sz");
3574 : 0 : write_expression (arg);
3575 : : }
3576 : : }
3577 : : }
3578 : 1218 : else if (TYPE_P (TREE_OPERAND (expr, 0)))
3579 : : {
3580 : 1104 : write_string ("st");
3581 : 1104 : write_type (TREE_OPERAND (expr, 0));
3582 : : }
3583 : : else
3584 : 114 : goto normal_expr;
3585 : : }
3586 : 6369819 : else if (TREE_CODE (expr) == ALIGNOF_EXPR)
3587 : : {
3588 : 36 : if (!ALIGNOF_EXPR_STD_P (expr))
3589 : : {
3590 : 24 : if (abi_check (16))
3591 : : {
3592 : : /* We used to mangle __alignof__ like alignof. */
3593 : 18 : write_string ("u11__alignof__");
3594 : 18 : write_template_arg (TREE_OPERAND (expr, 0));
3595 : 18 : write_char ('E');
3596 : 18 : return;
3597 : : }
3598 : : }
3599 : 18 : if (TYPE_P (TREE_OPERAND (expr, 0)))
3600 : : {
3601 : 9 : write_string ("at");
3602 : 9 : write_type (TREE_OPERAND (expr, 0));
3603 : : }
3604 : : else
3605 : 9 : goto normal_expr;
3606 : : }
3607 : 6369783 : else if (code == SCOPE_REF
3608 : 6369783 : || code == BASELINK)
3609 : : {
3610 : 243408 : tree scope, member;
3611 : 243408 : if (code == SCOPE_REF)
3612 : : {
3613 : 243375 : scope = TREE_OPERAND (expr, 0);
3614 : 243375 : member = TREE_OPERAND (expr, 1);
3615 : 243375 : if (BASELINK_P (member))
3616 : 21 : member = BASELINK_FUNCTIONS (member);
3617 : : }
3618 : : else
3619 : : {
3620 : 33 : scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (expr));
3621 : 33 : member = BASELINK_FUNCTIONS (expr);
3622 : : }
3623 : :
3624 : : /* If the MEMBER is a real declaration, then the qualifying
3625 : : scope was not dependent. Ideally, we would not have a
3626 : : SCOPE_REF in those cases, but sometimes we do. If the second
3627 : : argument is a DECL, then the name must not have been
3628 : : dependent. */
3629 : 243408 : if (DECL_P (member))
3630 : : write_expression (member);
3631 : : else
3632 : : {
3633 : 239801 : gcc_assert (code != BASELINK || BASELINK_QUALIFIED_P (expr));
3634 : 239768 : write_string ("sr");
3635 : 239768 : write_type (scope);
3636 : 239768 : write_member_name (member);
3637 : : }
3638 : : }
3639 : 6126375 : else if (INDIRECT_REF_P (expr)
3640 : 244054 : && TREE_TYPE (TREE_OPERAND (expr, 0))
3641 : 6368503 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
3642 : : {
3643 : 126078 : write_expression (TREE_OPERAND (expr, 0));
3644 : : }
3645 : 6000297 : else if (identifier_p (expr))
3646 : : {
3647 : : /* An operator name appearing as a dependent name needs to be
3648 : : specially marked to disambiguate between a use of the operator
3649 : : name and a use of the operator in an expression. */
3650 : 242557 : if (IDENTIFIER_ANY_OP_P (expr))
3651 : 26 : write_string ("on");
3652 : 242557 : write_unqualified_id (expr);
3653 : : }
3654 : 5757740 : else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
3655 : : {
3656 : 2576028 : tree fn = TREE_OPERAND (expr, 0);
3657 : 3240016 : if (!identifier_p (fn))
3658 : 2576025 : fn = OVL_NAME (fn);
3659 : 2576028 : if (IDENTIFIER_ANY_OP_P (fn))
3660 : 3 : write_string ("on");
3661 : 2576028 : write_unqualified_id (fn);
3662 : 2576028 : write_template_args (TREE_OPERAND (expr, 1));
3663 : : }
3664 : 3181712 : else if (TREE_CODE (expr) == MODOP_EXPR)
3665 : : {
3666 : 150 : enum tree_code subop = TREE_CODE (TREE_OPERAND (expr, 1));
3667 : 150 : const char *name = OVL_OP_INFO (true, subop)->mangled_name;
3668 : :
3669 : 150 : write_string (name);
3670 : 150 : write_expression (TREE_OPERAND (expr, 0));
3671 : 150 : write_expression (TREE_OPERAND (expr, 2));
3672 : : }
3673 : 3181562 : else if (code == NEW_EXPR || code == VEC_NEW_EXPR)
3674 : : {
3675 : : /* ::= [gs] nw <expression>* _ <type> E
3676 : : ::= [gs] nw <expression>* _ <type> <initializer>
3677 : : ::= [gs] na <expression>* _ <type> E
3678 : : ::= [gs] na <expression>* _ <type> <initializer>
3679 : : <initializer> ::= pi <expression>* E */
3680 : 37846 : tree placement = TREE_OPERAND (expr, 0);
3681 : 37846 : tree type = TREE_OPERAND (expr, 1);
3682 : 37846 : tree nelts = TREE_OPERAND (expr, 2);
3683 : 37846 : tree init = TREE_OPERAND (expr, 3);
3684 : 37846 : tree t;
3685 : :
3686 : 37846 : gcc_assert (code == NEW_EXPR);
3687 : 37846 : if (TREE_OPERAND (expr, 2))
3688 : 12 : code = VEC_NEW_EXPR;
3689 : :
3690 : 37846 : if (NEW_EXPR_USE_GLOBAL (expr))
3691 : 37821 : write_string ("gs");
3692 : :
3693 : 37846 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3694 : :
3695 : 75667 : for (t = placement; t; t = TREE_CHAIN (t))
3696 : 37821 : write_expression (TREE_VALUE (t));
3697 : :
3698 : 37846 : write_char ('_');
3699 : :
3700 : 37846 : if (nelts)
3701 : : {
3702 : 12 : ++processing_template_decl;
3703 : : /* Avoid compute_array_index_type complaints about
3704 : : non-constant nelts. */
3705 : 12 : tree max = cp_build_binary_op (input_location, MINUS_EXPR,
3706 : : fold_convert (sizetype, nelts),
3707 : : size_one_node,
3708 : : tf_warning_or_error);
3709 : 12 : max = maybe_constant_value (max);
3710 : 12 : tree domain = build_index_type (max);
3711 : 12 : type = build_cplus_array_type (type, domain);
3712 : 12 : --processing_template_decl;
3713 : : }
3714 : 37846 : write_type (type);
3715 : :
3716 : 37834 : if (init && TREE_CODE (init) == TREE_LIST
3717 : 75674 : && DIRECT_LIST_INIT_P (TREE_VALUE (init)))
3718 : : write_expression (TREE_VALUE (init));
3719 : : else
3720 : : {
3721 : 37843 : if (init)
3722 : 37831 : write_string ("pi");
3723 : 37831 : if (init && init != void_node)
3724 : 75650 : for (t = init; t; t = TREE_CHAIN (t))
3725 : 37825 : write_expression (TREE_VALUE (t));
3726 : 37843 : write_char ('E');
3727 : : }
3728 : : }
3729 : : else if (code == DELETE_EXPR || code == VEC_DELETE_EXPR)
3730 : : {
3731 : 12 : gcc_assert (code == DELETE_EXPR);
3732 : 12 : if (DELETE_EXPR_USE_VEC (expr))
3733 : 6 : code = VEC_DELETE_EXPR;
3734 : :
3735 : 12 : if (DELETE_EXPR_USE_GLOBAL (expr))
3736 : 6 : write_string ("gs");
3737 : :
3738 : 12 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3739 : :
3740 : 12 : write_expression (TREE_OPERAND (expr, 0));
3741 : : }
3742 : : else if (code == THROW_EXPR)
3743 : : {
3744 : 7 : tree op = TREE_OPERAND (expr, 0);
3745 : 7 : if (op)
3746 : : {
3747 : 4 : write_string ("tw");
3748 : 4 : write_expression (op);
3749 : : }
3750 : : else
3751 : 3 : write_string ("tr");
3752 : : }
3753 : : else if (code == NOEXCEPT_EXPR)
3754 : : {
3755 : 6 : write_string ("nx");
3756 : 6 : write_expression (TREE_OPERAND (expr, 0));
3757 : : }
3758 : : else if (code == CONSTRUCTOR)
3759 : : {
3760 : 55456 : bool braced_init = BRACE_ENCLOSED_INITIALIZER_P (expr);
3761 : 55456 : tree etype = TREE_TYPE (expr);
3762 : :
3763 : 55456 : if (braced_init)
3764 : 113 : write_string ("il");
3765 : : else
3766 : : {
3767 : 55343 : write_string ("tl");
3768 : 55343 : write_type (etype);
3769 : : }
3770 : :
3771 : : /* If this is an undigested initializer, mangle it as written.
3772 : : COMPOUND_LITERAL_P doesn't actually distinguish between digested and
3773 : : undigested braced casts, but it should work to use it to distinguish
3774 : : between braced casts in a template signature (undigested) and template
3775 : : parm object values (digested), and all CONSTRUCTORS that get here
3776 : : should be one of those two cases. */
3777 : 55456 : bool undigested = braced_init || COMPOUND_LITERAL_P (expr);
3778 : 55060 : if (undigested || !zero_init_expr_p (expr))
3779 : : {
3780 : : /* Convert braced initializer lists to STRING_CSTs so that
3781 : : A<"Foo"> mangles the same as A<{'F', 'o', 'o', 0}> while
3782 : : still using the latter mangling for strings that
3783 : : originated as braced initializer lists. */
3784 : 46190 : expr = braced_lists_to_strings (etype, expr);
3785 : :
3786 : 46190 : if (TREE_CODE (expr) == CONSTRUCTOR)
3787 : : {
3788 : 46190 : vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (expr);
3789 : 46190 : unsigned last_nonzero = UINT_MAX;
3790 : 46190 : constructor_elt *ce;
3791 : :
3792 : 46190 : if (!undigested)
3793 : 126674 : for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
3794 : 80880 : if ((TREE_CODE (etype) == UNION_TYPE
3795 : 33 : && ce->index != first_field (etype))
3796 : 80904 : || !zero_init_expr_p (ce->value))
3797 : : last_nonzero = i;
3798 : :
3799 : 46190 : tree prev_field = NULL_TREE;
3800 : 46190 : if (undigested || last_nonzero != UINT_MAX)
3801 : 125061 : for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
3802 : : {
3803 : 80876 : if (i > last_nonzero)
3804 : : break;
3805 : 78692 : if (!undigested && !CONSTRUCTOR_NO_CLEARING (expr)
3806 : 78871 : && (TREE_CODE (etype) == RECORD_TYPE
3807 : 78692 : || TREE_CODE (etype) == ARRAY_TYPE))
3808 : : {
3809 : : /* Write out any implicit non-trailing zeros
3810 : : (which we neglected to do before v21). */
3811 : 78659 : if (TREE_CODE (etype) == RECORD_TYPE)
3812 : : {
3813 : 24973 : tree field;
3814 : 24973 : if (i == 0)
3815 : 24254 : field = first_field (etype);
3816 : : else
3817 : 719 : field = DECL_CHAIN (prev_field);
3818 : 25081 : for (;;)
3819 : : {
3820 : 25027 : field = next_subobject_field (field);
3821 : 25027 : if (field == ce->index)
3822 : : break;
3823 : 54 : if (abi_check (21))
3824 : 54 : write_expression (build_zero_cst
3825 : 54 : (TREE_TYPE (field)));
3826 : 54 : field = DECL_CHAIN (field);
3827 : : }
3828 : : }
3829 : 53686 : else if (TREE_CODE (etype) == ARRAY_TYPE)
3830 : : {
3831 : 53686 : unsigned HOST_WIDE_INT j;
3832 : 53686 : if (i == 0)
3833 : : j = 0;
3834 : : else
3835 : 32179 : j = 1 + tree_to_uhwi (prev_field);
3836 : 53686 : unsigned HOST_WIDE_INT k;
3837 : 53686 : if (TREE_CODE (ce->index) == RANGE_EXPR)
3838 : 6 : k = tree_to_uhwi (TREE_OPERAND (ce->index, 0));
3839 : : else
3840 : 53680 : k = tree_to_uhwi (ce->index);
3841 : 53686 : tree zero = NULL_TREE;
3842 : 55456 : for (; j < k; ++j)
3843 : 1770 : if (abi_check (21))
3844 : : {
3845 : 1188 : if (!zero)
3846 : 30 : zero = build_zero_cst (TREE_TYPE (etype));
3847 : 1188 : write_expression (zero);
3848 : : }
3849 : : }
3850 : : }
3851 : :
3852 : 78871 : if (!undigested && TREE_CODE (etype) == UNION_TYPE)
3853 : : {
3854 : : /* Express the active member as a designator. */
3855 : 33 : write_string ("di");
3856 : 33 : write_unqualified_name (ce->index);
3857 : : }
3858 : 78871 : unsigned reps = 1;
3859 : 78871 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3860 : 6 : reps = range_expr_nelts (ce->index);
3861 : 78871 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
3862 : : {
3863 : 30 : gcc_assert (reps == 1);
3864 : 30 : unsigned int len = RAW_DATA_LENGTH (ce->value);
3865 : : /* If this is the last non-zero element, skip
3866 : : zeros at the end. */
3867 : 30 : if (i == last_nonzero)
3868 : 282 : while (len)
3869 : : {
3870 : 282 : if (RAW_DATA_POINTER (ce->value)[len - 1])
3871 : : break;
3872 : : --len;
3873 : : }
3874 : 30 : tree valtype = TREE_TYPE (ce->value);
3875 : 3906 : for (unsigned int i = 0; i < len; ++i)
3876 : : {
3877 : 3876 : write_char ('L');
3878 : 3876 : write_type (valtype);
3879 : 3876 : unsigned HOST_WIDE_INT v;
3880 : 3876 : if (!TYPE_UNSIGNED (valtype)
3881 : 780 : && TYPE_PRECISION (valtype) == BITS_PER_UNIT
3882 : 4656 : && RAW_DATA_SCHAR_ELT (ce->value, i) < 0)
3883 : : {
3884 : 0 : write_char ('n');
3885 : 0 : v = -RAW_DATA_SCHAR_ELT (ce->value, i);
3886 : : }
3887 : : else
3888 : 3876 : v = RAW_DATA_UCHAR_ELT (ce->value, i);
3889 : 3876 : write_unsigned_number (v);
3890 : 3876 : write_char ('E');
3891 : : }
3892 : : }
3893 : : else
3894 : 157691 : for (unsigned j = 0; j < reps; ++j)
3895 : 78850 : write_expression (ce->value);
3896 : 78871 : prev_field = ce->index;
3897 : 78871 : if (prev_field && TREE_CODE (prev_field) == RANGE_EXPR)
3898 : 6 : prev_field = TREE_OPERAND (prev_field, 1);
3899 : : }
3900 : : }
3901 : : else
3902 : : {
3903 : 0 : gcc_assert (TREE_CODE (expr) == STRING_CST);
3904 : 0 : write_expression (expr);
3905 : : }
3906 : : }
3907 : 55456 : write_char ('E');
3908 : : }
3909 : : else if (code == LAMBDA_EXPR)
3910 : : {
3911 : : /* [temp.over.link] Two lambda-expressions are never considered
3912 : : equivalent.
3913 : :
3914 : : So just use the closure type mangling. */
3915 : 46 : write_char ('L');
3916 : 46 : write_type (LAMBDA_EXPR_CLOSURE (expr));
3917 : 46 : write_char ('E');
3918 : : }
3919 : : else if (code == REQUIRES_EXPR)
3920 : 228984 : write_requires_expr (expr);
3921 : 2859205 : else if (dependent_name (expr))
3922 : : {
3923 : 113661 : tree name = dependent_name (expr);
3924 : 113661 : if (IDENTIFIER_ANY_OP_P (name))
3925 : : {
3926 : 9 : if (abi_check (16))
3927 : 6 : write_string ("on");
3928 : : }
3929 : 113661 : write_unqualified_id (name);
3930 : : }
3931 : : else
3932 : : {
3933 : 2745544 : normal_expr:
3934 : 2745667 : int i, len;
3935 : 2745667 : const char *name;
3936 : :
3937 : : /* When we bind a variable or function to a non-type template
3938 : : argument with reference type, we create an ADDR_EXPR to show
3939 : : the fact that the entity's address has been taken. But, we
3940 : : don't actually want to output a mangling code for the `&'. */
3941 : 2745667 : if (TREE_CODE (expr) == ADDR_EXPR
3942 : 4341 : && TREE_TYPE (expr)
3943 : 2746575 : && TYPE_REF_P (TREE_TYPE (expr)))
3944 : : {
3945 : 0 : expr = TREE_OPERAND (expr, 0);
3946 : 0 : if (DECL_P (expr))
3947 : : {
3948 : : write_expression (expr);
3949 : : return;
3950 : : }
3951 : :
3952 : 0 : code = TREE_CODE (expr);
3953 : : }
3954 : :
3955 : 2745667 : if (code == COMPONENT_REF)
3956 : : {
3957 : 159080 : tree ob = TREE_OPERAND (expr, 0);
3958 : :
3959 : 159080 : if (TREE_CODE (ob) == ARROW_EXPR)
3960 : : {
3961 : 388 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3962 : 388 : ob = TREE_OPERAND (ob, 0);
3963 : 388 : write_expression (ob);
3964 : : }
3965 : 158692 : else if (write_base_ref (expr))
3966 : : return;
3967 : 158683 : else if (!is_dummy_object (ob))
3968 : : {
3969 : 158677 : write_string ("dt");
3970 : 158677 : write_expression (ob);
3971 : : }
3972 : : /* else, for a non-static data member with no associated object (in
3973 : : unevaluated context), use the unresolved-name mangling. */
3974 : :
3975 : 159071 : write_member_name (TREE_OPERAND (expr, 1));
3976 : 159071 : return;
3977 : : }
3978 : :
3979 : : /* If it wasn't any of those, recursively expand the expression. */
3980 : 2586587 : name = OVL_OP_INFO (false, code)->mangled_name;
3981 : :
3982 : : /* We used to mangle const_cast and static_cast like a C cast. */
3983 : 2586587 : if (code == CONST_CAST_EXPR
3984 : 2586587 : || code == STATIC_CAST_EXPR)
3985 : : {
3986 : 262 : if (!abi_check (6))
3987 : 15 : name = OVL_OP_INFO (false, CAST_EXPR)->mangled_name;
3988 : : }
3989 : :
3990 : 2586587 : if (name == NULL)
3991 : : {
3992 : 5 : switch (code)
3993 : : {
3994 : 3 : case TRAIT_EXPR:
3995 : 3 : error ("use of built-in trait %qE in function signature; "
3996 : : "use library traits instead", expr);
3997 : 3 : break;
3998 : :
3999 : 2 : default:
4000 : 2 : sorry ("mangling %C", code);
4001 : 2 : break;
4002 : : }
4003 : 5 : return;
4004 : : }
4005 : : else
4006 : 2586582 : write_string (name);
4007 : :
4008 : 2586582 : switch (code)
4009 : : {
4010 : 1318030 : case CALL_EXPR:
4011 : 1318030 : {
4012 : 1318030 : tree fn = CALL_EXPR_FN (expr);
4013 : :
4014 : 1318030 : if (TREE_CODE (fn) == ADDR_EXPR)
4015 : 0 : fn = TREE_OPERAND (fn, 0);
4016 : :
4017 : : /* Mangle a dependent name as the name, not whatever happens to
4018 : : be the first function in the overload set. */
4019 : 1317551 : if (OVL_P (fn)
4020 : 1560426 : && type_dependent_expression_p_push (expr))
4021 : 242534 : fn = OVL_NAME (fn);
4022 : :
4023 : 1318030 : write_expression (fn);
4024 : : }
4025 : :
4026 : 3169132 : for (i = 0; i < call_expr_nargs (expr); ++i)
4027 : 533072 : write_expression (CALL_EXPR_ARG (expr, i));
4028 : 1318030 : write_char ('E');
4029 : 1318030 : break;
4030 : :
4031 : 39767 : case CAST_EXPR:
4032 : 39767 : write_type (TREE_TYPE (expr));
4033 : 39767 : if (list_length (TREE_OPERAND (expr, 0)) == 1)
4034 : 39616 : write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));
4035 : : else
4036 : : {
4037 : 151 : tree args = TREE_OPERAND (expr, 0);
4038 : 151 : write_char ('_');
4039 : 163 : for (; args; args = TREE_CHAIN (args))
4040 : 12 : write_expression (TREE_VALUE (args));
4041 : 151 : write_char ('E');
4042 : : }
4043 : : break;
4044 : :
4045 : 268 : case DYNAMIC_CAST_EXPR:
4046 : 268 : case REINTERPRET_CAST_EXPR:
4047 : 268 : case STATIC_CAST_EXPR:
4048 : 268 : case CONST_CAST_EXPR:
4049 : 268 : write_type (TREE_TYPE (expr));
4050 : 268 : write_expression (TREE_OPERAND (expr, 0));
4051 : 268 : break;
4052 : :
4053 : 58 : case PREINCREMENT_EXPR:
4054 : 58 : case PREDECREMENT_EXPR:
4055 : 58 : if (abi_check (6))
4056 : 49 : write_char ('_');
4057 : : /* Fall through. */
4058 : :
4059 : 1228517 : default:
4060 : : /* In the middle-end, some expressions have more operands than
4061 : : they do in templates (and mangling). */
4062 : 1228517 : len = cp_tree_operand_length (expr);
4063 : :
4064 : 3256604 : for (i = 0; i < len; ++i)
4065 : : {
4066 : 2028087 : tree operand = TREE_OPERAND (expr, i);
4067 : : /* As a GNU extension, the middle operand of a
4068 : : conditional may be omitted. Since expression
4069 : : manglings are supposed to represent the input token
4070 : : stream, there's no good way to mangle such an
4071 : : expression without extending the C++ ABI. */
4072 : 2028087 : if (code == COND_EXPR && i == 1 && !operand)
4073 : : {
4074 : 3 : error ("omitted middle operand to %<?:%> operand "
4075 : : "cannot be mangled");
4076 : 3 : continue;
4077 : : }
4078 : 2028084 : else if (FOLD_EXPR_P (expr))
4079 : : {
4080 : : /* The first 'operand' of a fold-expression is the operator
4081 : : that it folds over. */
4082 : 120530 : if (i == 0)
4083 : : {
4084 : 60192 : int fcode = TREE_INT_CST_LOW (operand);
4085 : 60192 : write_string (OVL_OP_INFO (false, fcode)->mangled_name);
4086 : 60192 : continue;
4087 : 60192 : }
4088 : 60338 : else if (code == BINARY_LEFT_FOLD_EXPR)
4089 : : {
4090 : : /* The order of operands of the binary left and right
4091 : : folds is the same, but we want to mangle them in
4092 : : lexical order, i.e. non-pack first. */
4093 : 286 : if (i == 1)
4094 : 143 : operand = FOLD_EXPR_INIT (expr);
4095 : : else
4096 : 143 : operand = FOLD_EXPR_PACK (expr);
4097 : : }
4098 : 60338 : if (PACK_EXPANSION_P (operand))
4099 : 60192 : operand = PACK_EXPANSION_PATTERN (operand);
4100 : : }
4101 : 1967892 : write_expression (operand);
4102 : : }
4103 : : }
4104 : : }
4105 : : }
4106 : :
4107 : : /* Literal subcase of non-terminal <template-arg>.
4108 : :
4109 : : "Literal arguments, e.g. "A<42L>", are encoded with their type
4110 : : and value. Negative integer values are preceded with "n"; for
4111 : : example, "A<-42L>" becomes "1AILln42EE". The bool value false is
4112 : : encoded as 0, true as 1." */
4113 : :
4114 : : static void
4115 : 74011086 : write_template_arg_literal (const tree value)
4116 : : {
4117 : 74011086 : if (TREE_CODE (value) == STRING_CST)
4118 : : /* Temporarily mangle strings as braced initializer lists. */
4119 : 1078 : write_string ("tl");
4120 : : else
4121 : 74010008 : write_char ('L');
4122 : :
4123 : 74011086 : tree valtype = TREE_TYPE (value);
4124 : 74011086 : write_type (valtype);
4125 : :
4126 : : /* Write a null member pointer value as (type)0, regardless of its
4127 : : real representation. */
4128 : 74011086 : if (null_member_pointer_value_p (value))
4129 : 156 : write_integer_cst (integer_zero_node);
4130 : : else
4131 : 74010930 : switch (TREE_CODE (value))
4132 : : {
4133 : 13435 : case CONST_DECL:
4134 : 13435 : write_integer_cst (DECL_INITIAL (value));
4135 : 13435 : break;
4136 : :
4137 : 73996144 : case INTEGER_CST:
4138 : 73996144 : gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node)
4139 : : || integer_zerop (value) || integer_onep (value));
4140 : 73996144 : if (!(abi_version_at_least (14)
4141 : 73989274 : && NULLPTR_TYPE_P (TREE_TYPE (value))))
4142 : 73996093 : write_integer_cst (value);
4143 : : break;
4144 : :
4145 : 267 : case REAL_CST:
4146 : 267 : write_real_cst (value);
4147 : 267 : break;
4148 : :
4149 : 6 : case COMPLEX_CST:
4150 : 6 : if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST
4151 : 6 : && TREE_CODE (TREE_IMAGPART (value)) == INTEGER_CST)
4152 : : {
4153 : 3 : write_integer_cst (TREE_REALPART (value));
4154 : 3 : write_char ('_');
4155 : 3 : write_integer_cst (TREE_IMAGPART (value));
4156 : : }
4157 : 3 : else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST
4158 : 3 : && TREE_CODE (TREE_IMAGPART (value)) == REAL_CST)
4159 : : {
4160 : 3 : write_real_cst (TREE_REALPART (value));
4161 : 3 : write_char ('_');
4162 : 3 : write_real_cst (TREE_IMAGPART (value));
4163 : : }
4164 : : else
4165 : 0 : gcc_unreachable ();
4166 : : break;
4167 : :
4168 : 1078 : case STRING_CST:
4169 : 1078 : {
4170 : : /* Mangle strings the same as braced initializer lists. */
4171 : 1078 : unsigned n = TREE_STRING_LENGTH (value);
4172 : 1078 : const char *str = TREE_STRING_POINTER (value);
4173 : :
4174 : : /* Count the number of trailing nuls and subtract them from
4175 : : STRSIZE because they don't need to be mangled. */
4176 : 2777 : for (const char *p = str + n - 1; ; --p)
4177 : : {
4178 : 2777 : if (*p || p == str)
4179 : : {
4180 : 1078 : n -= str + n - !!*p - p;
4181 : 1078 : break;
4182 : : }
4183 : : }
4184 : 1078 : tree eltype = TREE_TYPE (valtype);
4185 : 3236 : for (const char *p = str; n--; ++p)
4186 : : {
4187 : 2158 : write_char ('L');
4188 : 2158 : write_type (eltype);
4189 : 2158 : write_unsigned_number (*(const unsigned char*)p);
4190 : 2158 : write_string ("E");
4191 : : }
4192 : : break;
4193 : : }
4194 : :
4195 : 0 : default:
4196 : 0 : gcc_unreachable ();
4197 : : }
4198 : :
4199 : 74011086 : write_char ('E');
4200 : 74011086 : }
4201 : :
4202 : : /* Non-terminal <template-arg>.
4203 : :
4204 : : <template-arg> ::= <type> # type
4205 : : ::= L <type> </value/ number> E # literal
4206 : : ::= LZ <name> E # external name
4207 : : ::= X <expression> E # expression */
4208 : :
4209 : : static void
4210 : 635826947 : write_template_arg (tree node)
4211 : : {
4212 : 635826947 : enum tree_code code = TREE_CODE (node);
4213 : :
4214 : 635826947 : MANGLE_TRACE_TREE ("template-arg", node);
4215 : :
4216 : : /* A template template parameter's argument list contains TREE_LIST
4217 : : nodes of which the value field is the actual argument. */
4218 : 635826947 : if (code == TREE_LIST)
4219 : : {
4220 : 0 : node = TREE_VALUE (node);
4221 : : /* If it's a decl, deal with its type instead. */
4222 : 0 : if (DECL_P (node))
4223 : : {
4224 : 0 : node = TREE_TYPE (node);
4225 : 0 : code = TREE_CODE (node);
4226 : : }
4227 : : }
4228 : :
4229 : 635826947 : if (VAR_P (node) && DECL_NTTP_OBJECT_P (node))
4230 : : /* We want to mangle the argument, not the var we stored it in. */
4231 : 24446 : node = tparm_object_argument (node);
4232 : :
4233 : : /* Strip a conversion added by convert_nontype_argument. */
4234 : 635826947 : if (TREE_CODE (node) == IMPLICIT_CONV_EXPR)
4235 : 54 : node = TREE_OPERAND (node, 0);
4236 : 635826947 : if (REFERENCE_REF_P (node))
4237 : 256 : node = TREE_OPERAND (node, 0);
4238 : 635826947 : if (TREE_CODE (node) == NOP_EXPR
4239 : 635826947 : && TYPE_REF_P (TREE_TYPE (node)))
4240 : : {
4241 : : /* Template parameters can be of reference type. To maintain
4242 : : internal consistency, such arguments use a conversion from
4243 : : address of object to reference type. */
4244 : 256 : gcc_assert (TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR);
4245 : 256 : node = TREE_OPERAND (TREE_OPERAND (node, 0), 0);
4246 : : }
4247 : :
4248 : 635826947 : if (TREE_CODE (node) == BASELINK
4249 : 635826947 : && !type_unknown_p (node))
4250 : : {
4251 : : /* Before v6 we wrongly wrapped a class-scope function in X/E. */
4252 : 21 : if (abi_check (6))
4253 : 15 : node = BASELINK_FUNCTIONS (node);
4254 : : }
4255 : :
4256 : 635826947 : if (ARGUMENT_PACK_P (node))
4257 : : {
4258 : : /* Expand the template argument pack. */
4259 : 7539049 : tree args = ARGUMENT_PACK_ARGS (node);
4260 : 7539049 : int i, length = TREE_VEC_LENGTH (args);
4261 : 7539049 : if (abi_check (6))
4262 : 7539031 : write_char ('J');
4263 : : else
4264 : 18 : write_char ('I');
4265 : 17609992 : for (i = 0; i < length; ++i)
4266 : 10070943 : write_template_arg (TREE_VEC_ELT (args, i));
4267 : 7539049 : write_char ('E');
4268 : : }
4269 : 628287898 : else if (TYPE_P (node))
4270 : 553328246 : write_type (node);
4271 : 74959652 : else if (code == TEMPLATE_DECL)
4272 : : /* A template appearing as a template arg is a template template arg. */
4273 : 468505 : write_template_template_arg (node);
4274 : 73869000 : else if ((TREE_CODE_CLASS (code) == tcc_constant && code != PTRMEM_CST)
4275 : 622147 : || code == CONST_DECL
4276 : 75116576 : || null_member_pointer_value_p (node))
4277 : 73865787 : write_template_arg_literal (node);
4278 : 625360 : else if (code == EXCESS_PRECISION_EXPR
4279 : 625360 : && TREE_CODE (TREE_OPERAND (node, 0)) == REAL_CST)
4280 : 0 : write_template_arg_literal (fold_convert (TREE_TYPE (node),
4281 : : TREE_OPERAND (node, 0)));
4282 : 625360 : else if (DECL_P (node))
4283 : : {
4284 : 280 : write_char ('L');
4285 : : /* Until ABI version 3, the underscore before the mangled name
4286 : : was incorrectly omitted. */
4287 : 280 : if (!abi_check (3))
4288 : 21 : write_char ('Z');
4289 : : else
4290 : 259 : write_string ("_Z");
4291 : 280 : write_encoding (node);
4292 : 280 : write_char ('E');
4293 : : }
4294 : : else
4295 : : {
4296 : : /* Template arguments may be expressions. */
4297 : 625080 : write_char ('X');
4298 : 625080 : write_expression (node);
4299 : 625080 : write_char ('E');
4300 : : }
4301 : 635826947 : }
4302 : :
4303 : : /* <template-template-arg>
4304 : : ::= <name>
4305 : : ::= <substitution> */
4306 : :
4307 : : static void
4308 : 468505 : write_template_template_arg (const tree decl)
4309 : : {
4310 : 468505 : MANGLE_TRACE_TREE ("template-template-arg", decl);
4311 : :
4312 : 468505 : if (find_substitution (decl))
4313 : : return;
4314 : 432900 : write_name (decl, /*ignore_local_scope=*/0);
4315 : 432900 : add_substitution (decl);
4316 : : }
4317 : :
4318 : :
4319 : : /* Non-terminal <array-type>. TYPE is an ARRAY_TYPE.
4320 : :
4321 : : <array-type> ::= A [</dimension/ number>] _ </element/ type>
4322 : : ::= A <expression> _ </element/ type>
4323 : :
4324 : : "Array types encode the dimension (number of elements) and the
4325 : : element type. For variable length arrays, the dimension (but not
4326 : : the '_' separator) is omitted."
4327 : : Note that for flexible array members, like for other arrays of
4328 : : unspecified size, the dimension is also omitted. */
4329 : :
4330 : : static void
4331 : 795465 : write_array_type (const tree type)
4332 : : {
4333 : 795465 : write_char ('A');
4334 : 795465 : if (TYPE_DOMAIN (type))
4335 : : {
4336 : 477650 : tree index_type;
4337 : :
4338 : 477650 : index_type = TYPE_DOMAIN (type);
4339 : : /* The INDEX_TYPE gives the upper and lower bounds of the array.
4340 : : It's null for flexible array members which have no upper bound
4341 : : (this is a change from GCC 5 and prior where such members were
4342 : : incorrectly mangled as zero-length arrays). */
4343 : 477650 : if (tree max = TYPE_MAX_VALUE (index_type))
4344 : : {
4345 : 477650 : if (TREE_CODE (max) == INTEGER_CST)
4346 : : {
4347 : : /* The ABI specifies that we should mangle the number of
4348 : : elements in the array, not the largest allowed index. */
4349 : 414704 : offset_int wmax = wi::to_offset (max) + 1;
4350 : : /* Truncate the result - this will mangle [0, SIZE_INT_MAX]
4351 : : number of elements as zero. */
4352 : 414704 : wmax = wi::zext (wmax, TYPE_PRECISION (TREE_TYPE (max)));
4353 : 414704 : gcc_assert (wi::fits_uhwi_p (wmax));
4354 : 414704 : write_unsigned_number (wmax.to_uhwi ());
4355 : : }
4356 : : else
4357 : : {
4358 : 62946 : gcc_checking_assert (TREE_CODE (max) == MINUS_EXPR
4359 : : && integer_onep (TREE_OPERAND (max, 1)));
4360 : 62946 : max = TREE_OPERAND (max, 0);
4361 : 62946 : write_expression (max);
4362 : : }
4363 : : }
4364 : : }
4365 : 795465 : write_char ('_');
4366 : 795465 : write_type (TREE_TYPE (type));
4367 : 795465 : }
4368 : :
4369 : : /* Non-terminal <pointer-to-member-type> for pointer-to-member
4370 : : variables. TYPE is a pointer-to-member POINTER_TYPE.
4371 : :
4372 : : <pointer-to-member-type> ::= M </class/ type> </member/ type> */
4373 : :
4374 : : static void
4375 : 282038 : write_pointer_to_member_type (const tree type)
4376 : : {
4377 : 282038 : write_char ('M');
4378 : 282038 : write_type (TYPE_PTRMEM_CLASS_TYPE (type));
4379 : 282038 : write_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
4380 : 282038 : }
4381 : :
4382 : : /* Non-terminal <template-param>. PARM is a TEMPLATE_TYPE_PARM,
4383 : : TEMPLATE_TEMPLATE_PARM, BOUND_TEMPLATE_TEMPLATE_PARM or a
4384 : : TEMPLATE_PARM_INDEX.
4385 : :
4386 : : <template-param> ::= T </parameter/ number> _ */
4387 : :
4388 : : static void
4389 : 22933087 : write_template_param (const tree parm)
4390 : : {
4391 : 22933087 : int parm_index;
4392 : 22933087 : int level;
4393 : :
4394 : 22933087 : MANGLE_TRACE_TREE ("template-parm", parm);
4395 : :
4396 : 22933087 : switch (TREE_CODE (parm))
4397 : : {
4398 : 22445885 : case TEMPLATE_TYPE_PARM:
4399 : 22445885 : case TEMPLATE_TEMPLATE_PARM:
4400 : 22445885 : case BOUND_TEMPLATE_TEMPLATE_PARM:
4401 : 22445885 : parm_index = TEMPLATE_TYPE_IDX (parm);
4402 : 22445885 : level = TEMPLATE_TYPE_LEVEL (parm);
4403 : 22445885 : break;
4404 : :
4405 : 487202 : case TEMPLATE_PARM_INDEX:
4406 : 487202 : parm_index = TEMPLATE_PARM_IDX (parm);
4407 : 487202 : level = TEMPLATE_PARM_LEVEL (parm);
4408 : 487202 : break;
4409 : :
4410 : 0 : default:
4411 : 0 : gcc_unreachable ();
4412 : : }
4413 : :
4414 : 22933087 : write_char ('T');
4415 : 22933087 : if (level > 1)
4416 : : {
4417 : 23622 : if (abi_check (19))
4418 : : {
4419 : 23610 : write_char ('L');
4420 : 23610 : write_compact_number (level - 1);
4421 : : }
4422 : : }
4423 : : /* NUMBER as it appears in the mangling is (-1)-indexed, with the
4424 : : earliest template param denoted by `_'. */
4425 : 22933087 : write_compact_number (parm_index);
4426 : 22933087 : }
4427 : :
4428 : : /* <template-template-param>
4429 : : ::= <template-param>
4430 : : ::= <substitution> */
4431 : :
4432 : : static void
4433 : 625 : write_template_template_param (const tree parm)
4434 : : {
4435 : 625 : tree templ = NULL_TREE;
4436 : :
4437 : : /* PARM, a TEMPLATE_TEMPLATE_PARM, is an instantiation of the
4438 : : template template parameter. The substitution candidate here is
4439 : : only the template. */
4440 : 625 : if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
4441 : : {
4442 : 532 : templ
4443 : 532 : = TI_TEMPLATE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm));
4444 : 532 : if (find_substitution (templ))
4445 : : return;
4446 : : }
4447 : :
4448 : : /* <template-param> encodes only the template parameter position,
4449 : : not its template arguments, which is fine here. */
4450 : 625 : write_template_param (parm);
4451 : 625 : if (templ)
4452 : 532 : add_substitution (templ);
4453 : : }
4454 : :
4455 : : /* Non-terminal <substitution>.
4456 : :
4457 : : <substitution> ::= S <seq-id> _
4458 : : ::= S_ */
4459 : :
4460 : : static void
4461 : 146901969 : write_substitution (const int seq_id)
4462 : : {
4463 : 146901969 : MANGLE_TRACE ("substitution", "");
4464 : :
4465 : 146901969 : write_char ('S');
4466 : 146901969 : if (seq_id > 0)
4467 : 130104661 : write_number (seq_id - 1, /*unsigned=*/1, 36);
4468 : 146901969 : write_char ('_');
4469 : 146901969 : }
4470 : :
4471 : : /* Start mangling ENTITY. */
4472 : :
4473 : : static inline void
4474 : 181765059 : start_mangling (const tree entity)
4475 : : {
4476 : 181765059 : G = {};
4477 : 181765059 : G.entity = entity;
4478 : 181765059 : obstack_free (&name_obstack, name_base);
4479 : 181765059 : mangle_obstack = &name_obstack;
4480 : 181765059 : name_base = obstack_alloc (&name_obstack, 0);
4481 : 181765059 : }
4482 : :
4483 : : /* Done with mangling. Release the data. */
4484 : :
4485 : : static void
4486 : 181765059 : finish_mangling_internal (void)
4487 : : {
4488 : : /* Clear all the substitutions. */
4489 : 181765059 : vec_safe_truncate (G.substitutions, 0);
4490 : :
4491 : 181765059 : if (G.mod)
4492 : 6557 : mangle_module_fini ();
4493 : :
4494 : : /* Null-terminate the string. */
4495 : 181765059 : write_char ('\0');
4496 : 181765059 : }
4497 : :
4498 : :
4499 : : /* Like finish_mangling_internal, but return the mangled string. */
4500 : :
4501 : : static inline const char *
4502 : 406778 : finish_mangling (void)
4503 : : {
4504 : 406778 : finish_mangling_internal ();
4505 : 406778 : return (const char *) obstack_finish (mangle_obstack);
4506 : : }
4507 : :
4508 : : /* Like finish_mangling_internal, but return an identifier. */
4509 : :
4510 : : static tree
4511 : 181358281 : finish_mangling_get_identifier (void)
4512 : : {
4513 : 181358281 : finish_mangling_internal ();
4514 : : /* Don't obstack_finish here, and the next start_mangling will
4515 : : remove the identifier. */
4516 : 181358281 : return get_identifier ((const char *) obstack_base (mangle_obstack));
4517 : : }
4518 : :
4519 : : /* Initialize data structures for mangling. */
4520 : :
4521 : : void
4522 : 96471 : init_mangle (void)
4523 : : {
4524 : 96471 : gcc_obstack_init (&name_obstack);
4525 : 96471 : name_base = obstack_alloc (&name_obstack, 0);
4526 : 96471 : vec_alloc (G.substitutions, 0);
4527 : :
4528 : : /* Cache these identifiers for quick comparison when checking for
4529 : : standard substitutions. */
4530 : 96471 : subst_identifiers[SUBID_ALLOCATOR] = get_identifier ("allocator");
4531 : 96471 : subst_identifiers[SUBID_BASIC_STRING] = get_identifier ("basic_string");
4532 : 96471 : subst_identifiers[SUBID_CHAR_TRAITS] = get_identifier ("char_traits");
4533 : 96471 : subst_identifiers[SUBID_BASIC_ISTREAM] = get_identifier ("basic_istream");
4534 : 96471 : subst_identifiers[SUBID_BASIC_OSTREAM] = get_identifier ("basic_ostream");
4535 : 96471 : subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream");
4536 : 96471 : }
4537 : :
4538 : : /* Generate a mangling for MODULE's global initializer fn. */
4539 : :
4540 : : tree
4541 : 1783 : mangle_module_global_init (int module)
4542 : : {
4543 : 1783 : start_mangling (NULL_TREE);
4544 : :
4545 : 1783 : write_string ("_ZGI");
4546 : 1783 : write_module (module, true);
4547 : :
4548 : 1783 : return finish_mangling_get_identifier ();
4549 : : }
4550 : :
4551 : : /* Generate the mangled name of DECL. */
4552 : :
4553 : : static tree
4554 : 175132359 : mangle_decl_string (const tree decl)
4555 : : {
4556 : 175132359 : tree result;
4557 : 175132359 : tree saved_fn = current_function_decl;
4558 : :
4559 : : /* We shouldn't be trying to mangle an uninstantiated template. */
4560 : 175132359 : gcc_assert (!type_dependent_expression_p (decl));
4561 : :
4562 : 175132359 : current_function_decl = NULL_TREE;
4563 : 175132359 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
4564 : :
4565 : 175132359 : start_mangling (decl);
4566 : :
4567 : 175132359 : if (TREE_CODE (decl) == TYPE_DECL)
4568 : 335327 : write_type (TREE_TYPE (decl));
4569 : : else
4570 : 174797032 : write_mangled_name (decl, true);
4571 : :
4572 : 175132359 : result = finish_mangling_get_identifier ();
4573 : 175132359 : if (DEBUG_MANGLE)
4574 : : fprintf (stderr, "mangle_decl_string = '%s'\n\n",
4575 : : IDENTIFIER_POINTER (result));
4576 : :
4577 : 175132359 : current_function_decl = saved_fn;
4578 : 175132359 : return result;
4579 : 175132359 : }
4580 : :
4581 : : /* Return an identifier for the external mangled name of DECL. */
4582 : :
4583 : : static tree
4584 : 129261951 : get_mangled_id (tree decl)
4585 : : {
4586 : 129261951 : tree id = mangle_decl_string (decl);
4587 : 129261951 : return targetm.mangle_decl_assembler_name (decl, id);
4588 : : }
4589 : :
4590 : : /* Create an identifier for the external mangled name of DECL. */
4591 : :
4592 : : void
4593 : 129268582 : mangle_decl (const tree decl)
4594 : : {
4595 : 129268582 : tree id;
4596 : 129268582 : bool dep;
4597 : :
4598 : : /* Don't bother mangling uninstantiated templates. */
4599 : 129268582 : ++processing_template_decl;
4600 : 129268582 : if (TREE_CODE (decl) == TYPE_DECL)
4601 : 335739 : dep = dependent_type_p (TREE_TYPE (decl));
4602 : : else
4603 : 256594218 : dep = (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
4604 : 213285996 : && any_dependent_template_arguments_p (DECL_TI_ARGS (decl)));
4605 : 129268582 : --processing_template_decl;
4606 : 129268582 : if (dep)
4607 : : return;
4608 : :
4609 : : /* During LTO we keep mangled names of TYPE_DECLs for ODR type merging.
4610 : : It is not needed to assign names to anonymous namespace, but we use the
4611 : : "<anon>" marker to be able to tell if type is C++ ODR type or type
4612 : : produced by other language. */
4613 : 129262363 : if (TREE_CODE (decl) == TYPE_DECL
4614 : 335739 : && TYPE_STUB_DECL (TREE_TYPE (decl))
4615 : 129587724 : && !TREE_PUBLIC (TYPE_STUB_DECL (TREE_TYPE (decl))))
4616 : 412 : id = get_identifier ("<anon>");
4617 : : else
4618 : : {
4619 : 129261951 : gcc_assert (TREE_CODE (decl) != TYPE_DECL
4620 : : || !no_linkage_check (TREE_TYPE (decl), true));
4621 : 129261951 : if (abi_version_at_least (10))
4622 : 129143912 : if (tree fn = decl_function_context (decl))
4623 : 3285089 : maybe_check_abi_tags (fn, decl);
4624 : 129261951 : id = get_mangled_id (decl);
4625 : : }
4626 : 129262363 : SET_DECL_ASSEMBLER_NAME (decl, id);
4627 : :
4628 : 129262363 : if (G.need_cxx17_warning
4629 : 129262363 : && (TREE_PUBLIC (decl) || DECL_REALLY_EXTERN (decl)))
4630 : 10 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wnoexcept_type,
4631 : : "mangled name for %qD will change in C++17 because the "
4632 : : "exception specification is part of a function type",
4633 : : decl);
4634 : :
4635 : 129262363 : if (id != DECL_NAME (decl)
4636 : : /* Don't do this for a fake symbol we aren't going to emit anyway. */
4637 : 126732191 : && TREE_CODE (decl) != TYPE_DECL
4638 : 255658815 : && !DECL_MAYBE_IN_CHARGE_CDTOR_P (decl))
4639 : : {
4640 : 108912593 : int save_ver = flag_abi_version;
4641 : 108912593 : tree id2 = NULL_TREE;
4642 : :
4643 : 108912593 : if (!DECL_REALLY_EXTERN (decl))
4644 : : {
4645 : 62372340 : record_mangling (decl, G.need_abi_warning);
4646 : :
4647 : 62372340 : if (!G.need_abi_warning)
4648 : : return;
4649 : :
4650 : 13280 : flag_abi_version = flag_abi_compat_version;
4651 : 13280 : id2 = mangle_decl_string (decl);
4652 : 13280 : id2 = targetm.mangle_decl_assembler_name (decl, id2);
4653 : 13280 : flag_abi_version = save_ver;
4654 : :
4655 : 13280 : if (id2 != id)
4656 : 13164 : note_mangling_alias (decl, id2);
4657 : : }
4658 : :
4659 : 46553533 : if (warn_abi)
4660 : : {
4661 : 45857323 : const char fabi_version[] = "-fabi-version";
4662 : :
4663 : 45857323 : if (flag_abi_compat_version != warn_abi_version
4664 : 45856642 : || id2 == NULL_TREE)
4665 : : {
4666 : 45857128 : flag_abi_version = warn_abi_version;
4667 : 45857128 : id2 = mangle_decl_string (decl);
4668 : 45857128 : id2 = targetm.mangle_decl_assembler_name (decl, id2);
4669 : : }
4670 : 45857323 : flag_abi_version = save_ver;
4671 : :
4672 : 45857323 : if (id2 == id)
4673 : : /* OK. */;
4674 : 266 : else if (warn_abi_version != 0
4675 : 266 : && abi_version_at_least (warn_abi_version))
4676 : 222 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4677 : : "the mangled name of %qD changed between "
4678 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4679 : : G.entity, fabi_version, warn_abi_version, id2,
4680 : : fabi_version, save_ver, id);
4681 : : else
4682 : 44 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4683 : : "the mangled name of %qD changes between "
4684 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4685 : : G.entity, fabi_version, save_ver, id,
4686 : : fabi_version, warn_abi_version, id2);
4687 : : }
4688 : :
4689 : 46553533 : flag_abi_version = save_ver;
4690 : : }
4691 : : }
4692 : :
4693 : : /* Generate the mangled representation of TYPE. */
4694 : :
4695 : : const char *
4696 : 406778 : mangle_type_string (const tree type)
4697 : : {
4698 : 406778 : const char *result;
4699 : :
4700 : 406778 : start_mangling (type);
4701 : 406778 : write_type (type);
4702 : 406778 : result = finish_mangling ();
4703 : 406778 : if (DEBUG_MANGLE)
4704 : : fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
4705 : 406778 : return result;
4706 : : }
4707 : :
4708 : : /* Create an identifier for the mangled name of a special component
4709 : : for belonging to TYPE. CODE is the ABI-specified code for this
4710 : : component. */
4711 : :
4712 : : static tree
4713 : 5448722 : mangle_special_for_type (const tree type, const char *code)
4714 : : {
4715 : 5448722 : tree result;
4716 : :
4717 : : /* We don't have an actual decl here for the special component, so
4718 : : we can't just process the <encoded-name>. Instead, fake it. */
4719 : 5448722 : start_mangling (type);
4720 : :
4721 : : /* Start the mangling. */
4722 : 5448722 : write_string ("_Z");
4723 : 5448722 : write_string (code);
4724 : :
4725 : : /* Add the type. */
4726 : 5448722 : write_type (type);
4727 : 5448722 : result = finish_mangling_get_identifier ();
4728 : :
4729 : 5448722 : if (DEBUG_MANGLE)
4730 : : fprintf (stderr, "mangle_special_for_type = %s\n\n",
4731 : : IDENTIFIER_POINTER (result));
4732 : :
4733 : 5448722 : return result;
4734 : : }
4735 : :
4736 : : /* Create an identifier for the mangled representation of the typeinfo
4737 : : structure for TYPE. */
4738 : :
4739 : : tree
4740 : 3131740 : mangle_typeinfo_for_type (const tree type)
4741 : : {
4742 : 3131740 : return mangle_special_for_type (type, "TI");
4743 : : }
4744 : :
4745 : : /* Create an identifier for the mangled name of the NTBS containing
4746 : : the mangled name of TYPE. */
4747 : :
4748 : : tree
4749 : 399183 : mangle_typeinfo_string_for_type (const tree type)
4750 : : {
4751 : 399183 : return mangle_special_for_type (type, "TS");
4752 : : }
4753 : :
4754 : : /* Create an identifier for the mangled name of the vtable for TYPE. */
4755 : :
4756 : : tree
4757 : 1727820 : mangle_vtbl_for_type (const tree type)
4758 : : {
4759 : 1727820 : return mangle_special_for_type (type, "TV");
4760 : : }
4761 : :
4762 : : /* Returns an identifier for the mangled name of the VTT for TYPE. */
4763 : :
4764 : : tree
4765 : 189979 : mangle_vtt_for_type (const tree type)
4766 : : {
4767 : 189979 : return mangle_special_for_type (type, "TT");
4768 : : }
4769 : :
4770 : : /* Returns an identifier for the mangled name of the decomposition
4771 : : artificial variable DECL. DECLS is the vector of the VAR_DECLs
4772 : : for the identifier-list. */
4773 : :
4774 : : tree
4775 : 605 : mangle_decomp (const tree decl, vec<tree> &decls)
4776 : : {
4777 : 605 : gcc_assert (!type_dependent_expression_p (decl));
4778 : :
4779 : 605 : location_t saved_loc = input_location;
4780 : 605 : input_location = DECL_SOURCE_LOCATION (decl);
4781 : :
4782 : 605 : check_abi_tags (decl);
4783 : 605 : start_mangling (decl);
4784 : 605 : write_string ("_Z");
4785 : :
4786 : 605 : tree context = decl_mangling_context (decl);
4787 : 605 : gcc_assert (context != NULL_TREE);
4788 : :
4789 : 605 : bool nested = false;
4790 : 605 : bool local = false;
4791 : 605 : if (DECL_NAMESPACE_STD_P (context))
4792 : 9 : write_string ("St");
4793 : 596 : else if (TREE_CODE (context) == FUNCTION_DECL)
4794 : : {
4795 : 259 : local = true;
4796 : 259 : write_char ('Z');
4797 : 259 : write_encoding (context);
4798 : 259 : write_char ('E');
4799 : : }
4800 : 337 : else if (context != global_namespace)
4801 : : {
4802 : 72 : nested = true;
4803 : 72 : write_char ('N');
4804 : 72 : write_prefix (context);
4805 : : }
4806 : :
4807 : 605 : write_string ("DC");
4808 : 605 : unsigned int i;
4809 : 605 : tree d;
4810 : 2196 : FOR_EACH_VEC_ELT (decls, i, d)
4811 : 1591 : write_unqualified_name (d);
4812 : 605 : write_char ('E');
4813 : :
4814 : 605 : if (tree tags = get_abi_tags (decl))
4815 : : {
4816 : : /* We didn't emit ABI tags for structured bindings before ABI 19. */
4817 : 30 : if (!G.need_abi_warning
4818 : 30 : && TREE_PUBLIC (decl)
4819 : 120 : && abi_warn_or_compat_version_crosses (19))
4820 : 30 : G.need_abi_warning = 1;
4821 : :
4822 : 30 : if (abi_version_at_least (19))
4823 : 30 : write_abi_tags (tags);
4824 : : }
4825 : :
4826 : 605 : if (nested)
4827 : 72 : write_char ('E');
4828 : 533 : else if (local && DECL_DISCRIMINATOR_P (decl))
4829 : 259 : write_discriminator (discriminator_for_local_entity (decl));
4830 : :
4831 : 605 : tree id = finish_mangling_get_identifier ();
4832 : 605 : if (DEBUG_MANGLE)
4833 : : fprintf (stderr, "mangle_decomp = '%s'\n\n",
4834 : : IDENTIFIER_POINTER (id));
4835 : :
4836 : 605 : input_location = saved_loc;
4837 : :
4838 : 605 : if (warn_abi && G.need_abi_warning)
4839 : : {
4840 : 0 : const char fabi_version[] = "-fabi-version";
4841 : 0 : tree id2 = id;
4842 : 0 : int save_ver = flag_abi_version;
4843 : :
4844 : 0 : if (flag_abi_version != warn_abi_version)
4845 : : {
4846 : 0 : flag_abi_version = warn_abi_version;
4847 : 0 : id2 = mangle_decomp (decl, decls);
4848 : 0 : flag_abi_version = save_ver;
4849 : : }
4850 : :
4851 : 0 : if (id2 == id)
4852 : : /* OK. */;
4853 : 0 : else if (warn_abi_version != 0
4854 : 0 : && abi_version_at_least (warn_abi_version))
4855 : 0 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4856 : : "the mangled name of %qD changed between "
4857 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4858 : : G.entity, fabi_version, warn_abi_version, id2,
4859 : : fabi_version, save_ver, id);
4860 : : else
4861 : 0 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4862 : : "the mangled name of %qD changes between "
4863 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4864 : : G.entity, fabi_version, save_ver, id,
4865 : : fabi_version, warn_abi_version, id2);
4866 : : }
4867 : :
4868 : 605 : return id;
4869 : : }
4870 : :
4871 : : /* Return an identifier for a construction vtable group. TYPE is
4872 : : the most derived class in the hierarchy; BINFO is the base
4873 : : subobject for which this construction vtable group will be used.
4874 : :
4875 : : This mangling isn't part of the ABI specification; in the ABI
4876 : : specification, the vtable group is dumped in the same COMDAT as the
4877 : : main vtable, and is referenced only from that vtable, so it doesn't
4878 : : need an external name. For binary formats without COMDAT sections,
4879 : : though, we need external names for the vtable groups.
4880 : :
4881 : : We use the production
4882 : :
4883 : : <special-name> ::= CT <type> <offset number> _ <base type> */
4884 : :
4885 : : tree
4886 : 260817 : mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
4887 : : {
4888 : 260817 : tree result;
4889 : :
4890 : 260817 : start_mangling (type);
4891 : :
4892 : 260817 : write_string ("_Z");
4893 : 260817 : write_string ("TC");
4894 : 260817 : write_type (type);
4895 : 260817 : write_integer_cst (BINFO_OFFSET (binfo));
4896 : 260817 : write_char ('_');
4897 : 260817 : write_type (BINFO_TYPE (binfo));
4898 : :
4899 : 260817 : result = finish_mangling_get_identifier ();
4900 : 260817 : if (DEBUG_MANGLE)
4901 : : fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n",
4902 : : IDENTIFIER_POINTER (result));
4903 : 260817 : return result;
4904 : : }
4905 : :
4906 : : /* Mangle a this pointer or result pointer adjustment.
4907 : :
4908 : : <call-offset> ::= h <fixed offset number> _
4909 : : ::= v <fixed offset number> _ <virtual offset number> _ */
4910 : :
4911 : : static void
4912 : 498034 : mangle_call_offset (const tree fixed_offset, const tree virtual_offset)
4913 : : {
4914 : 498034 : write_char (virtual_offset ? 'v' : 'h');
4915 : :
4916 : : /* For either flavor, write the fixed offset. */
4917 : 498034 : write_integer_cst (fixed_offset);
4918 : 498034 : write_char ('_');
4919 : :
4920 : : /* For a virtual thunk, add the virtual offset. */
4921 : 498034 : if (virtual_offset)
4922 : : {
4923 : 372942 : write_integer_cst (virtual_offset);
4924 : 372942 : write_char ('_');
4925 : : }
4926 : 498034 : }
4927 : :
4928 : : /* Return an identifier for the mangled name of a this-adjusting or
4929 : : covariant thunk to FN_DECL. FIXED_OFFSET is the initial adjustment
4930 : : to this used to find the vptr. If VIRTUAL_OFFSET is non-NULL, this
4931 : : is a virtual thunk, and it is the vtbl offset in
4932 : : bytes. THIS_ADJUSTING is nonzero for a this adjusting thunk and
4933 : : zero for a covariant thunk. Note, that FN_DECL might be a covariant
4934 : : thunk itself. A covariant thunk name always includes the adjustment
4935 : : for the this pointer, even if there is none.
4936 : :
4937 : : <special-name> ::= T <call-offset> <base encoding>
4938 : : ::= Tc <this_adjust call-offset> <result_adjust call-offset>
4939 : : <base encoding> */
4940 : :
4941 : : tree
4942 : 497653 : mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
4943 : : tree virtual_offset, tree thunk)
4944 : : {
4945 : 497653 : tree result;
4946 : :
4947 : 497653 : if (abi_version_at_least (11))
4948 : 497650 : maybe_check_abi_tags (fn_decl, thunk, 11);
4949 : :
4950 : 497653 : start_mangling (fn_decl);
4951 : :
4952 : 497653 : write_string ("_Z");
4953 : 497653 : write_char ('T');
4954 : :
4955 : 497653 : if (!this_adjusting)
4956 : : {
4957 : : /* Covariant thunk with no this adjustment */
4958 : 214 : write_char ('c');
4959 : 214 : mangle_call_offset (integer_zero_node, NULL_TREE);
4960 : 214 : mangle_call_offset (fixed_offset, virtual_offset);
4961 : : }
4962 : 497439 : else if (!DECL_THUNK_P (fn_decl))
4963 : : /* Plain this adjusting thunk. */
4964 : 497272 : mangle_call_offset (fixed_offset, virtual_offset);
4965 : : else
4966 : : {
4967 : : /* This adjusting thunk to covariant thunk. */
4968 : 167 : write_char ('c');
4969 : 167 : mangle_call_offset (fixed_offset, virtual_offset);
4970 : 167 : fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn_decl));
4971 : 167 : virtual_offset = THUNK_VIRTUAL_OFFSET (fn_decl);
4972 : 167 : if (virtual_offset)
4973 : 124 : virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
4974 : 167 : mangle_call_offset (fixed_offset, virtual_offset);
4975 : 167 : fn_decl = THUNK_TARGET (fn_decl);
4976 : : }
4977 : :
4978 : : /* Scoped name. */
4979 : 497653 : write_encoding (fn_decl);
4980 : :
4981 : 497653 : result = finish_mangling_get_identifier ();
4982 : 497653 : if (DEBUG_MANGLE)
4983 : : fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
4984 : 497653 : return result;
4985 : : }
4986 : :
4987 : : /* Handle ABI backwards compatibility for past bugs where we didn't call
4988 : : check_abi_tags in places where it's needed: call check_abi_tags and warn if
4989 : : it makes a difference. If FOR_DECL is non-null, it's the declaration
4990 : : that we're actually trying to mangle; if it's null, we're mangling the
4991 : : guard variable for T. */
4992 : :
4993 : : static void
4994 : 3787421 : maybe_check_abi_tags (tree t, tree for_decl, int ver)
4995 : : {
4996 : 3787421 : if (DECL_ASSEMBLER_NAME_SET_P (t))
4997 : : return;
4998 : :
4999 : 761670 : tree oldtags = get_abi_tags (t);
5000 : :
5001 : 761670 : mangle_decl (t);
5002 : :
5003 : 761670 : tree newtags = get_abi_tags (t);
5004 : 761670 : if (newtags && newtags != oldtags
5005 : 24 : && abi_version_crosses (ver))
5006 : : {
5007 : 12 : if (for_decl && DECL_THUNK_P (for_decl))
5008 : 3 : warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
5009 : : "the mangled name of a thunk for %qD changes between "
5010 : : "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
5011 : : t, flag_abi_version, warn_abi_version);
5012 : 9 : else if (for_decl)
5013 : 6 : warning_at (DECL_SOURCE_LOCATION (for_decl), OPT_Wabi,
5014 : : "the mangled name of %qD changes between "
5015 : : "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
5016 : : for_decl, flag_abi_version, warn_abi_version);
5017 : : else
5018 : 3 : warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
5019 : : "the mangled name of the initialization guard variable "
5020 : : "for %qD changes between %<-fabi-version=%d%> and "
5021 : : "%<-fabi-version=%d%>",
5022 : : t, flag_abi_version, warn_abi_version);
5023 : : }
5024 : : }
5025 : :
5026 : : /* Write out the appropriate string for this variable when generating
5027 : : another mangled name based on this one. */
5028 : :
5029 : : static void
5030 : 7425 : write_guarded_var_name (const tree variable)
5031 : : {
5032 : 7425 : if (DECL_NAME (variable)
5033 : 7425 : && startswith (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR"))
5034 : : /* The name of a guard variable for a reference temporary should refer
5035 : : to the reference, not the temporary. */
5036 : 18 : write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
5037 : 7407 : else if (DECL_DECOMPOSITION_P (variable)
5038 : 825 : && DECL_NAME (variable) == NULL_TREE
5039 : 7673 : && startswith (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)),
5040 : : "_Z"))
5041 : : /* The name of a guard variable for a structured binding needs special
5042 : : casing. */
5043 : 266 : write_string (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)) + 2);
5044 : : else
5045 : 7141 : write_name (variable, /*ignore_local_scope=*/0);
5046 : 7425 : }
5047 : :
5048 : : /* Return an identifier for the name of an initialization guard
5049 : : variable for indicated VARIABLE. */
5050 : :
5051 : : tree
5052 : 4688 : mangle_guard_variable (const tree variable)
5053 : : {
5054 : 4688 : if (abi_version_at_least (10))
5055 : 4682 : maybe_check_abi_tags (variable);
5056 : 4688 : start_mangling (variable);
5057 : 4688 : write_string ("_ZGV");
5058 : 4688 : write_guarded_var_name (variable);
5059 : 4688 : return finish_mangling_get_identifier ();
5060 : : }
5061 : :
5062 : : /* Return an identifier for the name of a thread_local initialization
5063 : : function for VARIABLE. */
5064 : :
5065 : : tree
5066 : 1202 : mangle_tls_init_fn (const tree variable)
5067 : : {
5068 : 1202 : check_abi_tags (variable);
5069 : 1202 : start_mangling (variable);
5070 : 1202 : write_string ("_ZTH");
5071 : 1202 : write_guarded_var_name (variable);
5072 : 1202 : return finish_mangling_get_identifier ();
5073 : : }
5074 : :
5075 : : /* Return an identifier for the name of a thread_local wrapper
5076 : : function for VARIABLE. */
5077 : :
5078 : : #define TLS_WRAPPER_PREFIX "_ZTW"
5079 : :
5080 : : tree
5081 : 749 : mangle_tls_wrapper_fn (const tree variable)
5082 : : {
5083 : 749 : check_abi_tags (variable);
5084 : 749 : start_mangling (variable);
5085 : 749 : write_string (TLS_WRAPPER_PREFIX);
5086 : 749 : write_guarded_var_name (variable);
5087 : 749 : return finish_mangling_get_identifier ();
5088 : : }
5089 : :
5090 : : /* Return true iff FN is a thread_local wrapper function. */
5091 : :
5092 : : bool
5093 : 1650660 : decl_tls_wrapper_p (const tree fn)
5094 : : {
5095 : 1650660 : if (TREE_CODE (fn) != FUNCTION_DECL)
5096 : : return false;
5097 : 1327878 : tree name = DECL_NAME (fn);
5098 : 1327878 : return startswith (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX);
5099 : : }
5100 : :
5101 : : /* Return an identifier for the name of a temporary variable used to
5102 : : initialize a static reference. This is now part of the ABI. */
5103 : :
5104 : : tree
5105 : 786 : mangle_ref_init_variable (const tree variable)
5106 : : {
5107 : 786 : start_mangling (variable);
5108 : 786 : write_string ("_ZGR");
5109 : 786 : check_abi_tags (variable);
5110 : 786 : write_guarded_var_name (variable);
5111 : : /* Avoid name clashes with aggregate initialization of multiple
5112 : : references at once. */
5113 : 786 : write_compact_number (current_ref_temp_count++);
5114 : 786 : return finish_mangling_get_identifier ();
5115 : : }
5116 : :
5117 : : /* Return an identifier for the mangled name of a C++20 template parameter
5118 : : object for template argument EXPR. */
5119 : :
5120 : : tree
5121 : 8917 : mangle_template_parm_object (tree expr)
5122 : : {
5123 : 8917 : start_mangling (expr);
5124 : 8917 : write_string ("_ZTAX");
5125 : 8917 : write_expression (expr);
5126 : 8917 : write_char ('E');
5127 : 8917 : return finish_mangling_get_identifier ();
5128 : : }
5129 : :
5130 : : /* Given a CLASS_TYPE, such as a record for std::bad_exception this
5131 : : function generates a mangled name for the vtable map variable of
5132 : : the class type. For example, if the class type is
5133 : : "std::bad_exception", the mangled name for the class is
5134 : : "St13bad_exception". This function would generate the name
5135 : : "_ZN4_VTVISt13bad_exceptionE12__vtable_mapE", which unmangles as:
5136 : : "_VTV<std::bad_exception>::__vtable_map". */
5137 : :
5138 : :
5139 : : char *
5140 : 6 : get_mangled_vtable_map_var_name (tree class_type)
5141 : : {
5142 : 6 : char *var_name = NULL;
5143 : 6 : const char *prefix = "_ZN4_VTVI";
5144 : 6 : const char *postfix = "E12__vtable_mapE";
5145 : :
5146 : 6 : gcc_assert (TREE_CODE (class_type) == RECORD_TYPE);
5147 : :
5148 : 6 : tree class_id = DECL_ASSEMBLER_NAME (TYPE_NAME (class_type));
5149 : :
5150 : 6 : if (strstr (IDENTIFIER_POINTER (class_id), "<anon>") != NULL)
5151 : : {
5152 : 0 : class_id = get_mangled_id (TYPE_NAME (class_type));
5153 : 0 : vtbl_register_mangled_name (TYPE_NAME (class_type), class_id);
5154 : : }
5155 : :
5156 : 6 : unsigned int len = strlen (IDENTIFIER_POINTER (class_id)) +
5157 : : strlen (prefix) +
5158 : 6 : strlen (postfix) + 1;
5159 : :
5160 : 6 : var_name = (char *) xmalloc (len);
5161 : :
5162 : 6 : sprintf (var_name, "%s%s%s", prefix, IDENTIFIER_POINTER (class_id), postfix);
5163 : :
5164 : 6 : return var_name;
5165 : : }
5166 : :
5167 : : #include "gt-cp-mangle.h"
|