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