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_closure_type_name (const tree);
207 : : static int hwint_to_ascii (unsigned HOST_WIDE_INT, const unsigned int, char *,
208 : : const unsigned int);
209 : : static void write_number (unsigned HOST_WIDE_INT, const int,
210 : : const unsigned int);
211 : : static void write_compact_number (int num);
212 : : static void write_integer_cst (const tree);
213 : : static void write_real_cst (const tree);
214 : : static void write_identifier (const char *);
215 : : static void write_special_name_constructor (const tree);
216 : : static void write_special_name_destructor (const tree);
217 : : static void write_type (tree);
218 : : static int write_CV_qualifiers_for_type (const tree);
219 : : static void write_builtin_type (tree);
220 : : static void write_function_type (const tree);
221 : : static void write_bare_function_type (const tree, const int, const tree);
222 : : static void write_method_parms (tree, const int, const tree);
223 : : static void write_class_enum_type (const tree);
224 : : static void write_template_args (tree, tree = NULL_TREE);
225 : : static void write_expression (tree);
226 : : static void write_template_arg_literal (const tree);
227 : : static void write_template_arg (tree);
228 : : static void write_template_template_arg (const tree);
229 : : static void write_array_type (const tree);
230 : : static void write_pointer_to_member_type (const tree);
231 : : static void write_template_param (const tree);
232 : : static void write_template_template_param (const tree);
233 : : static void write_substitution (const int);
234 : : static int discriminator_for_local_entity (tree);
235 : : static int discriminator_for_string_literal (tree, tree);
236 : : static void write_discriminator (const int);
237 : : static void write_local_name (tree, const tree, const tree);
238 : : static void dump_substitution_candidates (void);
239 : : static tree mangle_decl_string (const tree);
240 : : static void maybe_check_abi_tags (tree, tree = NULL_TREE, int = 10);
241 : : static bool equal_abi_tags (tree, tree);
242 : :
243 : : /* Control functions. */
244 : :
245 : : static inline void start_mangling (const tree);
246 : : static tree mangle_special_for_type (const tree, const char *);
247 : :
248 : : /* Append a single character to the end of the mangled
249 : : representation. */
250 : : #define write_char(CHAR) \
251 : : obstack_1grow (mangle_obstack, (CHAR))
252 : :
253 : : /* Append a sized buffer to the end of the mangled representation. */
254 : : #define write_chars(CHAR, LEN) \
255 : : obstack_grow (mangle_obstack, (CHAR), (LEN))
256 : :
257 : : /* Append a NUL-terminated string to the end of the mangled
258 : : representation. */
259 : : #define write_string(STRING) \
260 : : obstack_grow (mangle_obstack, (STRING), strlen (STRING))
261 : :
262 : : /* Nonzero if NODE1 and NODE2 are both TREE_LIST nodes and have the
263 : : same purpose (context, which may be a type) and value (template
264 : : decl). See write_template_prefix for more information on what this
265 : : is used for. */
266 : : #define NESTED_TEMPLATE_MATCH(NODE1, NODE2) \
267 : : (TREE_CODE (NODE1) == TREE_LIST \
268 : : && TREE_CODE (NODE2) == TREE_LIST \
269 : : && ((TYPE_P (TREE_PURPOSE (NODE1)) \
270 : : && same_type_p (TREE_PURPOSE (NODE1), TREE_PURPOSE (NODE2))) \
271 : : || TREE_PURPOSE (NODE1) == TREE_PURPOSE (NODE2)) \
272 : : && TREE_VALUE (NODE1) == TREE_VALUE (NODE2))
273 : :
274 : : /* Write out an unsigned quantity in base 10. */
275 : : #define write_unsigned_number(NUMBER) \
276 : : write_number ((NUMBER), /*unsigned_p=*/1, 10)
277 : :
278 : : /* Check for -fabi-version dependent mangling and also set the need_abi_warning
279 : : flag as appropriate. */
280 : :
281 : : static bool
282 : 7546602 : abi_check (int ver)
283 : : {
284 : 36557901 : if (abi_warn_or_compat_version_crosses (ver))
285 : 856087 : G.need_abi_warning = true;
286 : 7546602 : 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 : 752140134 : maybe_template_info (const tree decl)
294 : : {
295 : 752140134 : 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 : 287577690 : const tree type = TREE_TYPE (decl);
300 : :
301 : 287577690 : if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_ID_P (type))
302 : 227067952 : return TYPE_TEMPLATE_INFO (type);
303 : : }
304 : : else
305 : : {
306 : : /* Check if the template is a primary template. */
307 : 464562444 : if (DECL_LANG_SPECIFIC (decl) != NULL
308 : 463406246 : && VAR_OR_FUNCTION_DECL_P (decl)
309 : 395836407 : && DECL_TEMPLATE_INFO (decl)
310 : 744467408 : && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
311 : 58090679 : 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 : 2780717 : write_exception_spec (tree spec)
363 : : {
364 : :
365 : 2780717 : if (!spec || spec == noexcept_false_spec)
366 : : /* Nothing. */
367 : : return;
368 : :
369 : 15168 : if (!flag_noexcept_type)
370 : : {
371 : 17 : G.need_cxx17_warning = true;
372 : 17 : return;
373 : : }
374 : :
375 : 15151 : if (spec == noexcept_true_spec || spec == empty_except_spec)
376 : 15136 : 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 : 2678752820 : canonicalize_for_substitution (tree node)
404 : : {
405 : : /* For a TYPE_DECL, use the type instead. */
406 : 2678752820 : if (TREE_CODE (node) == TYPE_DECL)
407 : 458 : node = TREE_TYPE (node);
408 : 2678752820 : if (TYPE_P (node)
409 : 1990805706 : && TYPE_CANONICAL (node) != node
410 : 2939569798 : && TYPE_MAIN_VARIANT (node) != node)
411 : : {
412 : 60469285 : 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 : 60469285 : 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 : 6541 : node = build_qualified_type (TYPE_MAIN_VARIANT (node),
420 : 6541 : TYPE_QUALS (node));
421 : : else
422 : 60462744 : node = cp_build_qualified_type (TYPE_MAIN_VARIANT (node),
423 : : cp_type_quals (node));
424 : 60469285 : if (FUNC_OR_METHOD_TYPE_P (node))
425 : : {
426 : 6550 : node = build_ref_qualified_type (node, type_memfn_rqual (orig));
427 : 6550 : tree r = canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (orig));
428 : 6550 : if (flag_noexcept_type)
429 : 6506 : node = build_exception_variant (node, r);
430 : : else
431 : : /* Set the warning flag if appropriate. */
432 : 44 : write_exception_spec (r);
433 : : }
434 : : }
435 : 2678752820 : 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 : 695603940 : add_substitution (tree node)
443 : : {
444 : 695603940 : tree c;
445 : :
446 : 695603940 : 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 : 695603940 : c = canonicalize_for_substitution (node);
452 : 695603940 : 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 : 695603940 : node = c;
456 : :
457 : : /* Make sure NODE isn't already a candidate. */
458 : 695603940 : if (flag_checking)
459 : : {
460 : : int i;
461 : : tree candidate;
462 : :
463 : 3855802268 : FOR_EACH_VEC_SAFE_ELT (G.substitutions, i, candidate)
464 : 3160198448 : if (candidate)
465 : : {
466 : 3160193457 : gcc_assert (!(DECL_P (node) && node == candidate));
467 : 3160193457 : 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 : 695603940 : vec_safe_push (G.substitutions, node);
474 : :
475 : 695603940 : if (DEBUG_MANGLE)
476 : : dump_substitution_candidates ();
477 : 695603940 : }
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 : 2336466701 : is_std_substitution (const tree node,
486 : : const substitution_identifier_index_t index)
487 : : {
488 : 2336466701 : tree type = NULL;
489 : 2336466701 : tree decl = NULL;
490 : :
491 : 2336466701 : if (DECL_P (node))
492 : : {
493 : 2315580561 : type = TREE_TYPE (node);
494 : 2315580561 : decl = node;
495 : : }
496 : 20886140 : else if (CLASS_TYPE_P (node))
497 : : {
498 : 3416375 : type = node;
499 : 3416375 : decl = TYPE_NAME (node);
500 : : }
501 : : else
502 : : /* These are not the droids you're looking for. */
503 : : return false;
504 : :
505 : 2318996936 : if (!DECL_NAMESPACE_STD_P (CP_DECL_CONTEXT (decl)))
506 : : return false;
507 : :
508 : 886924355 : if (!(TYPE_LANG_SPECIFIC (type) && TYPE_TEMPLATE_INFO (type)))
509 : : return false;
510 : :
511 : 668556199 : tree tmpl = TYPE_TI_TEMPLATE (type);
512 : 668556199 : if (DECL_NAME (tmpl) != subst_identifiers[index])
513 : : return false;
514 : :
515 : 79698032 : 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 : 1024727934 : get_abi_tags (tree t)
526 : : {
527 : 1024727934 : if (!t || TREE_CODE (t) == NAMESPACE_DECL)
528 : : return NULL_TREE;
529 : :
530 : 957460974 : if (DECL_P (t) && DECL_DECLARES_TYPE_P (t))
531 : 261146975 : t = TREE_TYPE (t);
532 : :
533 : 957460974 : if (TREE_CODE (t) == TEMPLATE_DECL && DECL_TEMPLATE_RESULT (t))
534 : : {
535 : 6796721 : tree tags = get_abi_tags (DECL_TEMPLATE_RESULT (t));
536 : : /* We used to overlook abi_tag on function and variable templates. */
537 : 6796721 : if (tags && abi_check (19))
538 : : return tags;
539 : : else
540 : 6796711 : return NULL_TREE;
541 : : }
542 : :
543 : 950664253 : tree attrs;
544 : 950664253 : if (TYPE_P (t))
545 : 825677782 : attrs = TYPE_ATTRIBUTES (t);
546 : : else
547 : 124986471 : attrs = DECL_ATTRIBUTES (t);
548 : :
549 : 950664253 : tree tags = lookup_attribute ("abi_tag", attrs);
550 : 950664253 : if (tags)
551 : 7645994 : 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 : 4581512 : is_std_substitution_char (const tree node,
562 : : const substitution_identifier_index_t index)
563 : : {
564 : 4581512 : tree args;
565 : : /* Check NODE's name is ::std::identifier. */
566 : 4581512 : if (!is_std_substitution (node, index))
567 : : return 0;
568 : : /* Figure out its template args. */
569 : 3090269 : if (DECL_P (node))
570 : 0 : args = DECL_TI_ARGS (node);
571 : 3090269 : else if (CLASS_TYPE_P (node))
572 : 3090269 : 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 : 3090269 : return
578 : 3090269 : TREE_VEC_LENGTH (args) == 1
579 : 3090269 : && 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 : 1273998407 : find_substitution (tree node)
618 : : {
619 : 1273998407 : int i;
620 : 1273998407 : const int size = vec_safe_length (G.substitutions);
621 : 1273998407 : tree decl;
622 : 1273998407 : tree type;
623 : 1273998407 : const char *abbr = NULL;
624 : :
625 : 1273998407 : 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 : 1273998407 : node = canonicalize_for_substitution (node);
632 : :
633 : : /* Check for builtin substitutions. */
634 : :
635 : 1273998407 : decl = TYPE_P (node) ? TYPE_NAME (node) : node;
636 : 1273998407 : type = TYPE_P (node) ? node : TREE_TYPE (node);
637 : :
638 : : /* Check for std::allocator. */
639 : 1273998407 : if (decl
640 : 1178784385 : && is_std_substitution (decl, SUBID_ALLOCATOR)
641 : 1349651778 : && !CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
642 : : abbr = "Sa";
643 : :
644 : : /* Check for std::basic_string. */
645 : 1240141089 : else if (decl && is_std_substitution (decl, SUBID_BASIC_STRING))
646 : : {
647 : 133848 : 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 : 95023 : if (cp_type_quals (type) == TYPE_UNQUALIFIED
655 : 95023 : && CLASSTYPE_USE_TEMPLATE (type))
656 : : {
657 : 84660 : tree args = CLASSTYPE_TI_ARGS (type);
658 : 84660 : if (TREE_VEC_LENGTH (args) == 3
659 : 84642 : && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
660 : 37007 : && is_std_substitution_char (TREE_VEC_ELT (args, 1),
661 : : SUBID_CHAR_TRAITS)
662 : 121656 : && 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 : 1240007241 : else if (TYPE_P (node)
674 : 834714891 : && cp_type_quals (type) == TYPE_UNQUALIFIED
675 : 790852595 : && CLASS_TYPE_P (type)
676 : 330516068 : && CLASSTYPE_USE_TEMPLATE (type)
677 : 1478209307 : && CLASSTYPE_TEMPLATE_INFO (type) != NULL)
678 : : {
679 : : /* First, check for the template
680 : : args <char, std::char_traits<char> > . */
681 : 238202066 : tree args = CLASSTYPE_TI_ARGS (type);
682 : 238202066 : if (TREE_VEC_LENGTH (args) == 2
683 : 69468065 : && template_args_equal (TREE_VEC_ELT (args, 0), char_type_node)
684 : 242709575 : && is_std_substitution_char (TREE_VEC_ELT (args, 1),
685 : : SUBID_CHAR_TRAITS))
686 : : {
687 : : /* Got them. Is this basic_istream? */
688 : 3016273 : if (is_std_substitution (decl, SUBID_BASIC_ISTREAM))
689 : : abbr = "Si";
690 : : /* Or basic_ostream? */
691 : 2746411 : else if (is_std_substitution (decl, SUBID_BASIC_OSTREAM))
692 : : abbr = "So";
693 : : /* Or basic_iostream? */
694 : 2411053 : else if (is_std_substitution (decl, SUBID_BASIC_IOSTREAM))
695 : 1153900114 : abbr = "Sd";
696 : : }
697 : : }
698 : :
699 : : /* Check for namespace std. */
700 : 1001805175 : else if (decl && DECL_NAMESPACE_STD_P (decl))
701 : : {
702 : 120098293 : write_string ("St");
703 : 120098293 : return 1;
704 : : }
705 : :
706 : 1153900114 : tree tags = NULL_TREE;
707 : 1153900114 : if (OVERLOAD_TYPE_P (node) || DECL_CLASS_TEMPLATE_P (node))
708 : 564530807 : tags = get_abi_tags (type);
709 : : /* Now check the list of available substitutions for this mangling
710 : : operation. */
711 : 1153900114 : if (!abbr || tags)
712 : 5294122971 : for (i = 0; i < size; ++i)
713 : 4273036032 : 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 : 4273029003 : if (decl == candidate
718 : 4239557405 : || (TYPE_P (candidate) && type && TYPE_P (node)
719 : 1968519708 : && same_type_p (type, candidate))
720 : 8448657784 : || NESTED_TEMPLATE_MATCH (node, candidate))
721 : : {
722 : 98059528 : write_substitution (i);
723 : 98059528 : return 1;
724 : : }
725 : : }
726 : :
727 : 1021086939 : if (!abbr)
728 : : /* No substitution found. */
729 : : return 0;
730 : :
731 : 34753653 : write_string (abbr);
732 : 34753653 : 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 : 121095008 : unmangled_name_p (const tree decl)
747 : : {
748 : 121095008 : if (TREE_CODE (decl) == FUNCTION_DECL)
749 : : {
750 : : /* The names of `extern "C"' functions are not mangled. */
751 : 106041650 : return (DECL_EXTERN_C_FUNCTION_P (decl)
752 : : /* But overloaded operator names *are* mangled. */
753 : 2172841 : && !DECL_OVERLOADED_OPERATOR_P (decl));
754 : : }
755 : 15053358 : else if (VAR_P (decl))
756 : : {
757 : : /* static variables are mangled. */
758 : 15050247 : if (!DECL_EXTERNAL_LINKAGE_P (decl))
759 : : return false;
760 : :
761 : : /* extern "C" declarations aren't mangled. */
762 : 14849126 : if (DECL_EXTERN_C_P (decl))
763 : : return true;
764 : :
765 : : /* Other variables at non-global scope are mangled. */
766 : 14640489 : if (CP_DECL_CONTEXT (decl) != global_namespace)
767 : : return false;
768 : :
769 : : /* Variable template instantiations are mangled. */
770 : 103302 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
771 : 101951 : && variable_template_p (DECL_TI_TEMPLATE (decl)))
772 : : return false;
773 : :
774 : : /* Declarations with ABI tags are mangled. */
775 : 99339 : if (get_abi_tags (decl))
776 : : return false;
777 : :
778 : : // Declarations attached to a named module are mangled
779 : 99000 : 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 : 121095008 : write_mangled_name (const tree decl, bool top_level)
797 : : {
798 : 121095008 : MANGLE_TRACE_TREE ("mangled-name", decl);
799 : :
800 : 121095008 : check_abi_tags (decl);
801 : :
802 : 121095008 : if (unmangled_name_p (decl))
803 : : {
804 : 2480153 : if (top_level)
805 : 2479992 : 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 : 118614855 : write_string ("_Z");
820 : 118614855 : 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 : 121095008 : if (DECL_IS_PRE_FN_P (decl))
826 : 287 : write_string (".pre");
827 : 121094721 : else if (DECL_IS_POST_FN_P (decl))
828 : 61 : write_string (".post");
829 : :
830 : : /* If this is a coroutine helper, then append an appropriate string to
831 : : identify which. */
832 : 121095008 : if (tree ramp = DECL_RAMP_FN (decl))
833 : : {
834 : 2672 : if (DECL_ACTOR_FN (ramp) == decl)
835 : 1336 : write_string (JOIN_STR "actor");
836 : 1336 : else if (DECL_DESTROY_FN (ramp) == decl)
837 : 1336 : write_string (JOIN_STR "destroy");
838 : : else
839 : 0 : gcc_unreachable ();
840 : : }
841 : 121095008 : }
842 : :
843 : : /* Returns true if the return type of DECL is part of its signature, and
844 : : therefore its mangling. */
845 : :
846 : : bool
847 : 213615015 : mangle_return_type_p (tree decl)
848 : : {
849 : 213615015 : return (!DECL_CONSTRUCTOR_P (decl)
850 : 165913742 : && !DECL_DESTRUCTOR_P (decl)
851 : 153773925 : && !DECL_CONV_FN_P (decl)
852 : 366411799 : && maybe_template_info (decl));
853 : : }
854 : :
855 : : /* <constraint-expression> ::= <expression> */
856 : :
857 : : static void
858 : 663735 : write_constraint_expression (tree expr)
859 : : {
860 : 0 : write_expression (expr);
861 : 44311 : }
862 : :
863 : : /* Mangle a requires-clause following a template-head, if any.
864 : :
865 : : Q <constraint_expression> E */
866 : :
867 : : static void
868 : 222297478 : 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 : 222297478 : if (constraints && abi_check (19))
881 : : {
882 : : tree probe = constraints;
883 : : while (probe
884 : 49378 : && !EXPR_LOCATION (probe)
885 : 54448 : && 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 : 49320 : if (probe && EXPR_LOCATION (probe))
892 : : {
893 : 44308 : write_char ('Q');
894 : 44308 : write_constraint_expression (probe);
895 : : }
896 : : }
897 : 222297478 : }
898 : :
899 : : /* <type-constraint> ::= <name> */
900 : :
901 : : static void
902 : 31754 : write_type_constraint (tree cnst)
903 : : {
904 : 31754 : if (!cnst)
905 : : return;
906 : :
907 : 31754 : gcc_checking_assert (TREE_CODE (cnst) == TEMPLATE_ID_EXPR);
908 : :
909 : 31754 : tree concept_decl = get_concept_check_template (cnst);
910 : 31754 : write_name (concept_decl, 0);
911 : 31754 : tree args = TREE_OPERAND (cnst, 1);
912 : 31754 : if (TREE_VEC_LENGTH (args) > 1)
913 : : {
914 : 13497 : TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args) = true;
915 : 13497 : write_template_args (args);
916 : : }
917 : : }
918 : :
919 : : /* <encoding> ::= <function name> <bare-function-type>
920 : : ::= <data name> */
921 : :
922 : : static void
923 : 123219070 : write_encoding (const tree decl)
924 : : {
925 : 123219070 : MANGLE_TRACE_TREE ("encoding", decl);
926 : :
927 : 123219070 : 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 : 10917 : if (DECL_OVERLOADED_OPERATOR_P (decl))
932 : 3 : write_name (decl, /*ignore_local_scope=*/0);
933 : : else
934 : 10914 : write_source_name (DECL_NAME (decl));
935 : 10917 : return;
936 : : }
937 : :
938 : 123208153 : write_name (decl, /*ignore_local_scope=*/0);
939 : 123208153 : if (TREE_CODE (decl) == FUNCTION_DECL)
940 : : {
941 : 108461918 : tree fn_type;
942 : 108461918 : tree d;
943 : :
944 : 108461918 : if (maybe_template_info (decl))
945 : : {
946 : 12736828 : 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 : 12736828 : d = NULL_TREE;
952 : : }
953 : : else
954 : : {
955 : 95725090 : fn_type = TREE_TYPE (decl);
956 : 95725090 : d = decl;
957 : : }
958 : :
959 : 108461918 : write_bare_function_type (fn_type,
960 : 108461918 : mangle_return_type_p (decl),
961 : : d);
962 : :
963 : 108461918 : if (tree c = get_trailing_function_requirements (decl))
964 : 717090 : if (abi_check (19))
965 : : {
966 : 619424 : ++G.parm_depth;
967 : 619424 : write_char ('Q');
968 : 619424 : write_constraint_expression (c);
969 : 619424 : --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 : 185 : mangle_module_substitution (int v)
979 : : {
980 : 185 : write_substitution (v - 1);
981 : 185 : }
982 : :
983 : : int
984 : 6466 : mangle_module_component (tree comp, bool partition_p)
985 : : {
986 : 6466 : write_char ('W');
987 : 6466 : if (partition_p)
988 : 157 : write_char ('P');
989 : 6466 : write_source_name (comp);
990 : :
991 : : // Module substitutions use the same number-space as entity
992 : : // substitutions, but are orthogonal.
993 : 6466 : vec_safe_push (G.substitutions, NULL_TREE);
994 : 6466 : 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 : 6050 : write_module (int m, bool include_partition)
1009 : : {
1010 : 6050 : G.mod = true;
1011 : 0 : mangle_module (m, include_partition);
1012 : 4459 : }
1013 : :
1014 : : static void
1015 : 773186 : maybe_write_module (tree decl)
1016 : : {
1017 : 773186 : if (!DECL_NAMESPACE_SCOPE_P (decl))
1018 : : return;
1019 : :
1020 : 556139 : if (!TREE_PUBLIC (STRIP_TEMPLATE (decl)))
1021 : : return;
1022 : :
1023 : 550124 : if (TREE_CODE (decl) == NAMESPACE_DECL)
1024 : : return;
1025 : :
1026 : 408442 : int m = get_originating_module (decl, true);
1027 : 408442 : if (m >= 0)
1028 : 4459 : 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 : 1137216169 : decl_mangling_context (tree decl)
1036 : : {
1037 : 1137216257 : tree tcontext = targetm.cxx.decl_mangling_context (decl);
1038 : :
1039 : 1137216257 : if (tcontext != NULL_TREE)
1040 : : return tcontext;
1041 : :
1042 : 1137216257 : if (TREE_CODE (decl) == TEMPLATE_DECL
1043 : 1137216257 : && DECL_TEMPLATE_RESULT (decl))
1044 : : decl = DECL_TEMPLATE_RESULT (decl);
1045 : :
1046 : 1137216257 : if (TREE_CODE (decl) == TYPE_DECL
1047 : 1681573538 : && LAMBDA_TYPE_P (TREE_TYPE (decl)))
1048 : : {
1049 : 4330175 : tree extra = LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl));
1050 : 4330175 : if (extra)
1051 : : return extra;
1052 : : }
1053 : 1132886082 : else if (template_type_parameter_p (decl))
1054 : : /* template type parms have no mangling context. */
1055 : : return NULL_TREE;
1056 : :
1057 : 1132885866 : tcontext = CP_DECL_CONTEXT (decl);
1058 : :
1059 : 1132885866 : if (member_like_constrained_friend_p (decl))
1060 : 61900 : tcontext = DECL_FRIEND_CONTEXT (decl);
1061 : :
1062 : : /* Ignore the artificial declare reduction functions. */
1063 : 1132885866 : if (tcontext
1064 : 1132885866 : && TREE_CODE (tcontext) == FUNCTION_DECL
1065 : 1137982529 : && DECL_OMP_DECLARE_REDUCTION_P (tcontext))
1066 : : return decl_mangling_context (tcontext);
1067 : :
1068 : : return tcontext;
1069 : : }
1070 : :
1071 : : /* <name> ::= <unscoped-name>
1072 : : ::= <unscoped-template-name> <template-args>
1073 : : ::= <nested-name>
1074 : : ::= <local-name>
1075 : :
1076 : : If IGNORE_LOCAL_SCOPE is nonzero, this production of <name> is
1077 : : called from <local-name>, which mangles the enclosing scope
1078 : : elsewhere and then uses this function to mangle just the part
1079 : : underneath the function scope. So don't use the <local-name>
1080 : : production, to avoid an infinite recursion. */
1081 : :
1082 : : static void
1083 : 304947669 : write_name (tree decl, const int ignore_local_scope)
1084 : : {
1085 : 304947669 : tree context;
1086 : :
1087 : 304947669 : MANGLE_TRACE_TREE ("name", decl);
1088 : :
1089 : 304947669 : if (TREE_CODE (decl) == TYPE_DECL)
1090 : : {
1091 : : /* In case this is a typedef, fish out the corresponding
1092 : : TYPE_DECL for the main variant. */
1093 : 178312792 : decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)));
1094 : : }
1095 : :
1096 : 304947669 : context = decl_mangling_context (decl);
1097 : :
1098 : 304947669 : gcc_assert (context != NULL_TREE);
1099 : :
1100 : 1524257686 : if (abi_warn_or_compat_version_crosses (7)
1101 : 159965 : && ignore_local_scope
1102 : 44 : && TREE_CODE (context) == PARM_DECL)
1103 : 0 : G.need_abi_warning = 1;
1104 : :
1105 : : /* A decl in :: or ::std scope is treated specially. The former is
1106 : : mangled using <unscoped-name> or <unscoped-template-name>, the
1107 : : latter with a special substitution. Also, a name that is
1108 : : directly in a local function scope is also mangled with
1109 : : <unscoped-name> rather than a full <nested-name>. */
1110 : 304947669 : if (context == global_namespace
1111 : 296110544 : || DECL_NAMESPACE_STD_P (context)
1112 : 177602271 : || (ignore_local_scope
1113 : 4119566 : && (TREE_CODE (context) == FUNCTION_DECL
1114 : 2956139 : || (abi_version_at_least (7)
1115 : 2956139 : && TREE_CODE (context) == PARM_DECL))))
1116 : : {
1117 : : /* Is this a template instance? */
1118 : 128508855 : if (tree info = maybe_template_info (decl))
1119 : : {
1120 : : /* Yes: use <unscoped-template-name>. */
1121 : 103049695 : write_unscoped_template_name (TI_TEMPLATE (info));
1122 : : /* Pass down the parms of a function template in case we need to
1123 : : mangle them; we don't mangle the parms of a non-overloadable
1124 : : template. */
1125 : 103049695 : tree parms = (TREE_CODE (decl) == FUNCTION_DECL
1126 : 106686793 : ? DECL_TEMPLATE_PARMS (TI_TEMPLATE (info))
1127 : 103049695 : : NULL_TREE);
1128 : 103049695 : write_template_args (TI_ARGS (info), parms);
1129 : : }
1130 : : else
1131 : : /* Everything else gets an <unqualified-name>. */
1132 : 25459160 : write_unscoped_name (decl);
1133 : : }
1134 : : else
1135 : : {
1136 : : /* Handle local names, unless we asked not to (that is, invoked
1137 : : under <local-name>, to handle only the part of the name under
1138 : : the local scope). */
1139 : 176438814 : if (!ignore_local_scope)
1140 : : {
1141 : : /* Scan up the list of scope context, looking for a
1142 : : function. If we find one, this entity is in local
1143 : : function scope. local_entity tracks context one scope
1144 : : level down, so it will contain the element that's
1145 : : directly in that function's scope, either decl or one of
1146 : : its enclosing scopes. */
1147 : : tree local_entity = decl;
1148 : 550087067 : while (context != global_namespace)
1149 : : {
1150 : : /* Make sure we're always dealing with decls. */
1151 : 380723928 : if (TYPE_P (context))
1152 : 125896818 : context = TYPE_NAME (context);
1153 : : /* Is this a function? */
1154 : 380723928 : if (TREE_CODE (context) == FUNCTION_DECL
1155 : 376604734 : || TREE_CODE (context) == PARM_DECL)
1156 : : {
1157 : : /* Yes, we have local scope. Use the <local-name>
1158 : : production for the innermost function scope. */
1159 : 4119566 : write_local_name (context, local_entity, decl);
1160 : 4119566 : return;
1161 : : }
1162 : : /* Up one scope level. */
1163 : 376604362 : local_entity = context;
1164 : 376604362 : context = decl_mangling_context (context);
1165 : : }
1166 : :
1167 : : /* No local scope found? Fall through to <nested-name>. */
1168 : : }
1169 : :
1170 : : /* Other decls get a <nested-name> to encode their scope. */
1171 : 172319248 : write_nested_name (decl);
1172 : : }
1173 : : }
1174 : :
1175 : : /* <unscoped-name> ::= <unqualified-name>
1176 : : ::= St <unqualified-name> # ::std:: */
1177 : :
1178 : : static void
1179 : 92655166 : write_unscoped_name (const tree decl)
1180 : : {
1181 : 92655166 : tree context = decl_mangling_context (decl);
1182 : :
1183 : 92655166 : MANGLE_TRACE_TREE ("unscoped-name", decl);
1184 : :
1185 : : /* Is DECL in ::std? */
1186 : 92655166 : if (DECL_NAMESPACE_STD_P (context))
1187 : : {
1188 : 84870328 : write_string ("St");
1189 : 84870328 : write_unqualified_name (decl);
1190 : : }
1191 : : else
1192 : : {
1193 : : /* If not, it should be either in the global namespace, or directly
1194 : : in a local function scope. A lambda can also be mangled in the
1195 : : scope of a default argument. */
1196 : 7784838 : gcc_assert (context == global_namespace
1197 : : || TREE_CODE (context) == PARM_DECL
1198 : : || TREE_CODE (context) == FUNCTION_DECL);
1199 : :
1200 : 7784838 : write_unqualified_name (decl);
1201 : : }
1202 : 92655166 : }
1203 : :
1204 : : /* <unscoped-template-name> ::= <unscoped-name>
1205 : : ::= <substitution> */
1206 : :
1207 : : static void
1208 : 103049695 : write_unscoped_template_name (const tree decl)
1209 : : {
1210 : 103049695 : MANGLE_TRACE_TREE ("unscoped-template-name", decl);
1211 : :
1212 : 103049695 : if (find_substitution (decl))
1213 : : return;
1214 : 67196006 : write_unscoped_name (decl);
1215 : 67196006 : add_substitution (decl);
1216 : : }
1217 : :
1218 : : /* Write the nested name, including CV-qualifiers, of DECL.
1219 : :
1220 : : <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1221 : : ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1222 : :
1223 : : <ref-qualifier> ::= R # & ref-qualifier
1224 : : ::= O # && ref-qualifier
1225 : : <CV-qualifiers> ::= [r] [V] [K] */
1226 : :
1227 : : static void
1228 : 174425494 : write_nested_name (const tree decl)
1229 : : {
1230 : 174425494 : MANGLE_TRACE_TREE ("nested-name", decl);
1231 : :
1232 : 174425494 : write_char ('N');
1233 : :
1234 : : /* Write CV-qualifiers, if this is an iobj member function. */
1235 : 174425494 : if (TREE_CODE (decl) == FUNCTION_DECL
1236 : 174425494 : && DECL_IOBJ_MEMBER_FUNCTION_P (decl))
1237 : : {
1238 : 81599620 : if (DECL_VOLATILE_MEMFUNC_P (decl))
1239 : 3917333 : write_char ('V');
1240 : 81599620 : if (DECL_CONST_MEMFUNC_P (decl))
1241 : 21028550 : write_char ('K');
1242 : 81599620 : if (FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)))
1243 : : {
1244 : 57556 : if (FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl)))
1245 : 33476 : write_char ('O');
1246 : : else
1247 : 24080 : write_char ('R');
1248 : : }
1249 : : }
1250 : 75789549 : else if (DECL_DECLARES_FUNCTION_P (decl)
1251 : 92825874 : && DECL_XOBJ_MEMBER_FUNCTION_P (decl))
1252 : 3272 : write_char ('H');
1253 : :
1254 : : /* Is this a template instance? */
1255 : 174425494 : if (tree info = maybe_template_info (decl))
1256 : : {
1257 : : /* Yes, use <template-prefix>. */
1258 : 32524112 : write_template_prefix (decl);
1259 : 32524112 : write_template_args (TI_ARGS (info));
1260 : : }
1261 : 141901382 : else if ((!abi_version_at_least (10) || TREE_CODE (decl) == TYPE_DECL)
1262 : 183718187 : && TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
1263 : : {
1264 : 2106243 : tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
1265 : 2106243 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1266 : : {
1267 : 27936 : write_template_prefix (decl);
1268 : 27936 : write_template_args (TREE_OPERAND (name, 1));
1269 : : }
1270 : : else
1271 : : {
1272 : 2078307 : write_prefix (decl_mangling_context (decl));
1273 : 2078307 : write_unqualified_name (decl);
1274 : : }
1275 : : }
1276 : : else
1277 : : {
1278 : : /* No, just use <prefix> */
1279 : 139795139 : write_prefix (decl_mangling_context (decl));
1280 : 139795139 : write_unqualified_name (decl);
1281 : : }
1282 : 174425494 : write_char ('E');
1283 : 174425494 : }
1284 : :
1285 : : /* <prefix> ::= <prefix> <unqualified-name>
1286 : : ::= <template-param>
1287 : : ::= <template-prefix> <template-args>
1288 : : ::= <decltype>
1289 : : ::= # empty
1290 : : ::= <substitution> */
1291 : :
1292 : : static void
1293 : 359015788 : write_prefix (const tree node)
1294 : : {
1295 : 359015788 : tree decl;
1296 : :
1297 : 359015788 : if (node == NULL
1298 : 359015788 : || node == global_namespace)
1299 : : return;
1300 : :
1301 : 343496428 : MANGLE_TRACE_TREE ("prefix", node);
1302 : :
1303 : 343496428 : if (TREE_CODE (node) == DECLTYPE_TYPE
1304 : 343496416 : || TREE_CODE (node) == TRAIT_TYPE)
1305 : : {
1306 : 15 : write_type (node);
1307 : 15 : return;
1308 : : }
1309 : :
1310 : 343496413 : if (find_substitution (node))
1311 : : return;
1312 : :
1313 : 191556473 : tree template_info = NULL_TREE;
1314 : 191556473 : if (DECL_P (node))
1315 : : {
1316 : : /* If this is a function or parm decl, that means we've hit function
1317 : : scope, so this prefix must be for a local name. In this
1318 : : case, we're under the <local-name> production, which encodes
1319 : : the enclosing function scope elsewhere. So don't continue
1320 : : here. */
1321 : 70234460 : if (TREE_CODE (node) == FUNCTION_DECL
1322 : 67279101 : || TREE_CODE (node) == PARM_DECL)
1323 : : return;
1324 : :
1325 : 67278759 : decl = node;
1326 : 67278759 : template_info = maybe_template_info (decl);
1327 : : }
1328 : : else
1329 : : {
1330 : : /* Node is a type. */
1331 : 121322013 : decl = TYPE_NAME (node);
1332 : : /* The DECL might not point at the node. */
1333 : 121322013 : if (CLASSTYPE_TEMPLATE_ID_P (node))
1334 : 85430593 : template_info = TYPE_TEMPLATE_INFO (node);
1335 : : }
1336 : :
1337 : 188600772 : if (TREE_CODE (node) == TEMPLATE_TYPE_PARM)
1338 : 17671 : write_template_param (node);
1339 : 188583101 : else if (template_info)
1340 : : /* Templated. */
1341 : : {
1342 : 85431930 : write_template_prefix (decl);
1343 : 85431930 : write_template_args (TI_ARGS (template_info));
1344 : : }
1345 : 103151171 : else if (TREE_CODE (TREE_TYPE (decl)) == TYPENAME_TYPE)
1346 : : {
1347 : 31467 : tree name = TYPENAME_TYPE_FULLNAME (TREE_TYPE (decl));
1348 : 31467 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
1349 : : {
1350 : 25232 : write_template_prefix (decl);
1351 : 25232 : write_template_args (TREE_OPERAND (name, 1));
1352 : : }
1353 : : else
1354 : : {
1355 : 6235 : write_prefix (decl_mangling_context (decl));
1356 : 6235 : write_unqualified_name (decl);
1357 : : }
1358 : : }
1359 : : else
1360 : : /* Not templated. */
1361 : : {
1362 : 103119704 : write_prefix (decl_mangling_context (decl));
1363 : 103119704 : write_unqualified_name (decl);
1364 : 103119704 : if (VAR_P (decl)
1365 : 103119704 : || TREE_CODE (decl) == FIELD_DECL)
1366 : : {
1367 : : /* <data-member-prefix> := <member source-name> M */
1368 : 10326 : write_char ('M');
1369 : :
1370 : : /* Before ABI 18, we did not count these as substitution
1371 : : candidates. This leads to incorrect demanglings (and
1372 : : ABI divergence to other compilers). */
1373 : 10326 : if (!abi_check (18))
1374 : : return;
1375 : : }
1376 : : }
1377 : :
1378 : 188596067 : add_substitution (node);
1379 : : }
1380 : :
1381 : : /* <template-prefix> ::= <prefix> <template component>
1382 : : ::= <template-param>
1383 : : ::= <substitution> */
1384 : :
1385 : : static void
1386 : 118009210 : write_template_prefix (const tree node)
1387 : : {
1388 : 118009210 : tree decl = DECL_P (node) ? node : TYPE_NAME (node);
1389 : 118009210 : tree type = DECL_P (node) ? TREE_TYPE (node) : node;
1390 : 118009210 : tree context = decl_mangling_context (decl);
1391 : 118009210 : tree templ;
1392 : 118009210 : tree substitution;
1393 : :
1394 : 118009210 : MANGLE_TRACE_TREE ("template-prefix", node);
1395 : :
1396 : : /* Find the template decl. */
1397 : 118009210 : if (tree info = maybe_template_info (decl))
1398 : 117955056 : templ = TI_TEMPLATE (info);
1399 : 54154 : else if (TREE_CODE (type) == TYPENAME_TYPE)
1400 : : /* For a typename type, all we have is the name. */
1401 : 53168 : templ = DECL_NAME (decl);
1402 : : else
1403 : : {
1404 : 986 : gcc_assert (CLASSTYPE_TEMPLATE_ID_P (type));
1405 : :
1406 : 986 : templ = TYPE_TI_TEMPLATE (type);
1407 : : }
1408 : :
1409 : : /* For a member template, though, the template name for the
1410 : : innermost name must have all the outer template levels
1411 : : instantiated. For instance, consider
1412 : :
1413 : : template<typename T> struct Outer {
1414 : : template<typename U> struct Inner {};
1415 : : };
1416 : :
1417 : : The template name for `Inner' in `Outer<int>::Inner<float>' is
1418 : : `Outer<int>::Inner<U>'. In g++, we don't instantiate the template
1419 : : levels separately, so there's no TEMPLATE_DECL available for this
1420 : : (there's only `Outer<T>::Inner<U>').
1421 : :
1422 : : In order to get the substitutions right, we create a special
1423 : : TREE_LIST to represent the substitution candidate for a nested
1424 : : template. The TREE_PURPOSE is the template's context, fully
1425 : : instantiated, and the TREE_VALUE is the TEMPLATE_DECL for the inner
1426 : : template.
1427 : :
1428 : : So, for the example above, `Outer<int>::Inner' is represented as a
1429 : : substitution candidate by a TREE_LIST whose purpose is `Outer<int>'
1430 : : and whose value is `Outer<T>::Inner<U>'. */
1431 : 118009210 : if (context && TYPE_P (context))
1432 : 8154340 : substitution = build_tree_list (context, templ);
1433 : : else
1434 : : substitution = templ;
1435 : :
1436 : 118009210 : if (find_substitution (substitution))
1437 : : return;
1438 : :
1439 : 114017322 : if (TREE_TYPE (templ)
1440 : 114017322 : && TREE_CODE (TREE_TYPE (templ)) == TEMPLATE_TEMPLATE_PARM)
1441 : 986 : write_template_param (TREE_TYPE (templ));
1442 : : else
1443 : : {
1444 : 114016336 : write_prefix (context);
1445 : 114016336 : write_unqualified_name (decl);
1446 : : }
1447 : :
1448 : 114017322 : add_substitution (substitution);
1449 : : }
1450 : :
1451 : : /* "For the purposes of mangling, the name of an anonymous union is considered
1452 : : to be the name of the first named data member found by a pre-order,
1453 : : depth-first, declaration-order walk of the data members of the anonymous
1454 : : union. If there is no such data member (i.e., if all of the data members in
1455 : : the union are unnamed), then there is no way for a program to refer to the
1456 : : anonymous union, and there is therefore no need to mangle its name." */
1457 : :
1458 : : static tree
1459 : 21 : anon_aggr_naming_decl (tree type)
1460 : : {
1461 : 21 : tree field = next_aggregate_field (TYPE_FIELDS (type));
1462 : 21 : for (; field; field = next_aggregate_field (DECL_CHAIN (field)))
1463 : : {
1464 : 21 : if (DECL_NAME (field))
1465 : : return field;
1466 : 0 : if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
1467 : 0 : if (tree sub = anon_aggr_naming_decl (TREE_TYPE (field)))
1468 : : return sub;
1469 : : }
1470 : : return NULL_TREE;
1471 : : }
1472 : :
1473 : : /* We don't need to handle thunks, vtables, or VTTs here. Those are
1474 : : mangled through special entry points.
1475 : :
1476 : : <unqualified-name> ::= [<module-name>] <operator-name>
1477 : : ::= <special-name>
1478 : : ::= [<module-name>] <source-name>
1479 : : ::= [<module-name>] <unnamed-type-name>
1480 : : ::= <local-source-name>
1481 : : ::= F <source-name> # member-like constrained friend
1482 : :
1483 : : <local-source-name> ::= L <source-name> <discriminator> */
1484 : :
1485 : : static void
1486 : 1252400 : write_unqualified_id (tree identifier)
1487 : : {
1488 : 1252400 : if (IDENTIFIER_CONV_OP_P (identifier))
1489 : 15 : write_conversion_operator_name (TREE_TYPE (identifier));
1490 : 1252385 : else if (IDENTIFIER_OVL_OP_P (identifier))
1491 : : {
1492 : 7346 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (identifier);
1493 : 7346 : write_string (ovl_op->mangled_name);
1494 : 7346 : }
1495 : 1245039 : else if (UDLIT_OPER_P (identifier))
1496 : 0 : write_literal_operator_name (identifier);
1497 : : else
1498 : 1245039 : write_source_name (identifier);
1499 : 1252400 : }
1500 : :
1501 : : static void
1502 : 451672702 : write_unqualified_name (tree decl)
1503 : : {
1504 : 451672702 : MANGLE_TRACE_TREE ("unqualified-name", decl);
1505 : :
1506 : 451672702 : if (modules_p ())
1507 : 773186 : maybe_write_module (decl);
1508 : :
1509 : 451672702 : if (identifier_p (decl))
1510 : : {
1511 : 0 : write_unqualified_id (decl);
1512 : 0 : return;
1513 : : }
1514 : :
1515 : 451672702 : bool found = false;
1516 : :
1517 : 451672702 : if (DECL_NAME (decl) == NULL_TREE
1518 : 451672702 : && ANON_AGGR_TYPE_P (TREE_TYPE (decl)))
1519 : 21 : decl = anon_aggr_naming_decl (TREE_TYPE (decl));
1520 : 451672681 : else if (DECL_NAME (decl) == NULL_TREE)
1521 : : {
1522 : 10149 : found = true;
1523 : 10149 : gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
1524 : 10149 : write_source_name (DECL_ASSEMBLER_NAME (decl));
1525 : : }
1526 : 451662532 : else if (DECL_DECLARES_FUNCTION_P (decl))
1527 : : {
1528 : 108460673 : found = true;
1529 : :
1530 : : /* A constrained hidden friend is mangled like a member function, with
1531 : : the name prefixed by 'F'. */
1532 : 108460673 : if (member_like_constrained_friend_p (decl))
1533 : 15475 : write_char ('F');
1534 : :
1535 : 216921346 : if (DECL_CONSTRUCTOR_P (decl))
1536 : 23876099 : write_special_name_constructor (decl);
1537 : 84584574 : else if (DECL_DESTRUCTOR_P (decl))
1538 : 6310427 : write_special_name_destructor (decl);
1539 : 78274147 : else if (DECL_CONV_FN_P (decl))
1540 : : {
1541 : : /* Conversion operator. Handle it right here.
1542 : : <operator> ::= cv <type> */
1543 : 971860 : tree type;
1544 : 971860 : if (maybe_template_info (decl))
1545 : : {
1546 : 493 : tree fn_type;
1547 : 493 : fn_type = get_mostly_instantiated_function_type (decl);
1548 : 493 : type = TREE_TYPE (fn_type);
1549 : : }
1550 : 971367 : else if (FNDECL_USED_AUTO (decl))
1551 : 42 : type = DECL_SAVED_AUTO_RETURN_TYPE (decl);
1552 : : else
1553 : 971325 : type = DECL_CONV_FN_TYPE (decl);
1554 : 971860 : write_conversion_operator_name (type);
1555 : : }
1556 : 77302287 : else if (DECL_OVERLOADED_OPERATOR_P (decl))
1557 : : {
1558 : 15953165 : tree t;
1559 : 15953165 : if (!(t = DECL_RAMP_FN (decl)))
1560 : 15952823 : t = decl;
1561 : 15953165 : const char *mangled_name
1562 : 15953165 : = (ovl_op_info[DECL_ASSIGNMENT_OPERATOR_P (t)]
1563 : 15953165 : [DECL_OVERLOADED_OPERATOR_CODE_RAW (t)].mangled_name);
1564 : 15953165 : write_string (mangled_name);
1565 : : }
1566 : 61349122 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
1567 : 240265 : write_literal_operator_name (DECL_NAME (decl));
1568 : : else
1569 : : found = false;
1570 : : }
1571 : :
1572 : 47361986 : if (found)
1573 : : /* OK */;
1574 : 404310737 : else if (VAR_OR_FUNCTION_DECL_P (decl) && ! TREE_PUBLIC (decl)
1575 : 122373 : && DECL_NAMESPACE_SCOPE_P (decl)
1576 : 404381816 : && decl_linkage (decl) == lk_internal)
1577 : : {
1578 : 58639 : MANGLE_TRACE_TREE ("local-source-name", decl);
1579 : 58639 : write_char ('L');
1580 : 58639 : write_source_name (DECL_NAME (decl));
1581 : : /* The default discriminator is 1, and that's all we ever use,
1582 : : so there's no code to output one here. */
1583 : : }
1584 : : else
1585 : : {
1586 : 404252098 : tree type = TREE_TYPE (decl);
1587 : :
1588 : 404252098 : if (TREE_CODE (decl) == TYPE_DECL
1589 : 606385500 : && TYPE_UNNAMED_P (type))
1590 : 1280 : write_unnamed_type_name (type);
1591 : 590995596 : else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (type))
1592 : 1687254 : write_closure_type_name (type);
1593 : : else
1594 : 402563564 : write_source_name (DECL_NAME (decl));
1595 : : }
1596 : :
1597 : : /* We use the ABI tags from the primary class template, ignoring tags on any
1598 : : specializations. This is necessary because C++ doesn't require a
1599 : : specialization to be declared before it is used unless the use requires a
1600 : : complete type, but we need to get the tags right on incomplete types as
1601 : : well. */
1602 : 451672702 : if (tree tmpl = most_general_template (decl))
1603 : : {
1604 : 252008141 : tree res = DECL_TEMPLATE_RESULT (tmpl);
1605 : 252008141 : if (res == NULL_TREE)
1606 : : /* UNBOUND_CLASS_TEMPLATE. */;
1607 : 252008138 : else if (DECL_DECLARES_TYPE_P (decl))
1608 : : decl = res;
1609 : 82510019 : else if (any_abi_below (11))
1610 : : {
1611 : : /* ABI v10 implicit tags on the template. */
1612 : 81556 : tree mtags = missing_abi_tags (res);
1613 : : /* Explicit tags on the template. */
1614 : 81556 : tree ttags = get_abi_tags (res);
1615 : : /* Tags on the instantiation. */
1616 : 81556 : tree dtags = get_abi_tags (decl);
1617 : :
1618 : 81634 : if (mtags && abi_warn_or_compat_version_crosses (10))
1619 : 6 : G.need_abi_warning = 1;
1620 : :
1621 : : /* Add the v10 tags to the explicit tags now. */
1622 : 81556 : mtags = chainon (mtags, ttags);
1623 : :
1624 : 81556 : if (!G.need_abi_warning
1625 : 163014 : && abi_warn_or_compat_version_crosses (11)
1626 : 163018 : && !equal_abi_tags (dtags, mtags))
1627 : 6 : G.need_abi_warning = 1;
1628 : :
1629 : 81556 : if (!abi_version_at_least (10))
1630 : : /* In abi <10, we only got the explicit tags. */
1631 : : decl = res;
1632 : 900 : else if (flag_abi_version == 10)
1633 : : {
1634 : : /* In ABI 10, we want explict and implicit tags. */
1635 : 72 : write_abi_tags (mtags);
1636 : 72 : return;
1637 : : }
1638 : : }
1639 : : }
1640 : :
1641 : 451672630 : tree tags = get_abi_tags (decl);
1642 : 104824068 : if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CONV_FN_P (decl)
1643 : 452644490 : && any_abi_below (11))
1644 : 2731 : if (tree mtags = missing_abi_tags (decl))
1645 : : {
1646 : 9 : if (!abi_check (11))
1647 : 6 : tags = chainon (mtags, tags);
1648 : : }
1649 : 451672630 : write_abi_tags (tags);
1650 : : }
1651 : :
1652 : : /* Write the unqualified-name for a conversion operator to TYPE. */
1653 : :
1654 : : static void
1655 : 971875 : write_conversion_operator_name (const tree type)
1656 : : {
1657 : 971875 : write_string ("cv");
1658 : 971875 : write_type (type);
1659 : 971875 : }
1660 : :
1661 : : /* Non-terminal <source-name>. IDENTIFIER is an IDENTIFIER_NODE.
1662 : :
1663 : : <source-name> ::= </length/ number> <identifier> */
1664 : :
1665 : : static void
1666 : 403895239 : write_source_name (tree identifier)
1667 : : {
1668 : 403895239 : MANGLE_TRACE_TREE ("source-name", identifier);
1669 : :
1670 : 403895239 : write_unsigned_number (IDENTIFIER_LENGTH (identifier));
1671 : 403895239 : write_identifier (IDENTIFIER_POINTER (identifier));
1672 : 403895239 : }
1673 : :
1674 : : /* Compare two TREE_STRINGs like strcmp. */
1675 : :
1676 : : int
1677 : 114 : tree_string_cmp (const void *p1, const void *p2)
1678 : : {
1679 : 114 : if (p1 == p2)
1680 : : return 0;
1681 : 108 : tree s1 = *(const tree*)p1;
1682 : 108 : tree s2 = *(const tree*)p2;
1683 : 108 : return strcmp (TREE_STRING_POINTER (s1),
1684 : 108 : TREE_STRING_POINTER (s2));
1685 : : }
1686 : :
1687 : : /* Return the TREE_LIST of TAGS as a sorted VEC. */
1688 : :
1689 : : static vec<tree, va_gc> *
1690 : 406352 : sorted_abi_tags (tree tags)
1691 : : {
1692 : 406352 : vec<tree, va_gc> * vec = make_tree_vector();
1693 : :
1694 : 649825 : for (tree t = tags; t; t = TREE_CHAIN (t))
1695 : : {
1696 : 243473 : if (ABI_TAG_IMPLICIT (t))
1697 : 0 : continue;
1698 : 243473 : tree str = TREE_VALUE (t);
1699 : 243473 : vec_safe_push (vec, str);
1700 : : }
1701 : :
1702 : 406352 : vec->qsort (tree_string_cmp);
1703 : :
1704 : 406352 : return vec;
1705 : : }
1706 : :
1707 : : /* ID is the name of a function or type with abi_tags attribute TAGS.
1708 : : Write out the name, suitably decorated. */
1709 : :
1710 : : static void
1711 : 451672738 : write_abi_tags (tree tags)
1712 : : {
1713 : 451672738 : if (tags == NULL_TREE)
1714 : 451672738 : return;
1715 : :
1716 : 243428 : vec<tree, va_gc> * vec = sorted_abi_tags (tags);
1717 : :
1718 : 243428 : unsigned i; tree str;
1719 : 486883 : FOR_EACH_VEC_ELT (*vec, i, str)
1720 : : {
1721 : 243455 : write_string ("B");
1722 : 243455 : write_unsigned_number (TREE_STRING_LENGTH (str) - 1);
1723 : 243455 : write_identifier (TREE_STRING_POINTER (str));
1724 : : }
1725 : :
1726 : 243428 : release_tree_vector (vec);
1727 : : }
1728 : :
1729 : : /* True iff the TREE_LISTS T1 and T2 of ABI tags are equivalent. */
1730 : :
1731 : : static bool
1732 : 81462 : equal_abi_tags (tree t1, tree t2)
1733 : : {
1734 : 81462 : releasing_vec v1 = sorted_abi_tags (t1);
1735 : 81462 : releasing_vec v2 = sorted_abi_tags (t2);
1736 : :
1737 : 81462 : unsigned len1 = v1->length();
1738 : 81462 : if (len1 != v2->length())
1739 : : return false;
1740 : 81462 : for (unsigned i = 0; i < len1; ++i)
1741 : 6 : if (tree_string_cmp (v1[i], v2[i]) != 0)
1742 : : return false;
1743 : : return true;
1744 : 81462 : }
1745 : :
1746 : : /* Write a user-defined literal operator.
1747 : : ::= li <source-name> # "" <source-name>
1748 : : IDENTIFIER is an LITERAL_IDENTIFIER_NODE. */
1749 : :
1750 : : static void
1751 : 240265 : write_literal_operator_name (tree identifier)
1752 : : {
1753 : 240265 : const char* suffix = UDLIT_OP_SUFFIX (identifier);
1754 : 240265 : write_identifier (UDLIT_OP_MANGLED_PREFIX);
1755 : 240265 : write_unsigned_number (strlen (suffix));
1756 : 240265 : write_identifier (suffix);
1757 : 240265 : }
1758 : :
1759 : : /* Encode 0 as _, and 1+ as n-1_. */
1760 : :
1761 : : static void
1762 : 22271052 : write_compact_number (int num)
1763 : : {
1764 : 22271052 : gcc_checking_assert (num >= 0);
1765 : 22271052 : if (num > 0)
1766 : 9024144 : write_unsigned_number (num - 1);
1767 : 22271052 : write_char ('_');
1768 : 22271052 : }
1769 : :
1770 : : /* Return how many unnamed types precede TYPE in its enclosing class. */
1771 : :
1772 : : static int
1773 : 646 : nested_anon_class_index (tree type)
1774 : : {
1775 : 646 : int index = 0;
1776 : 646 : tree member = TYPE_FIELDS (TYPE_CONTEXT (type));
1777 : 21367 : for (; member; member = DECL_CHAIN (member))
1778 : 21367 : if (DECL_IMPLICIT_TYPEDEF_P (member))
1779 : : {
1780 : 1077 : tree memtype = TREE_TYPE (member);
1781 : 1077 : if (memtype == type)
1782 : : return index;
1783 : 1062 : else if (TYPE_UNNAMED_P (memtype))
1784 : 200 : ++index;
1785 : : }
1786 : :
1787 : 0 : if (seen_error ())
1788 : : return -1;
1789 : :
1790 : 0 : gcc_unreachable ();
1791 : : }
1792 : :
1793 : : /* <unnamed-type-name> ::= Ut [ <nonnegative number> ] _ */
1794 : :
1795 : : static void
1796 : 1280 : write_unnamed_type_name (const tree type)
1797 : : {
1798 : 1280 : int discriminator;
1799 : 1280 : MANGLE_TRACE_TREE ("unnamed-type-name", type);
1800 : :
1801 : 1280 : if (TYPE_FUNCTION_SCOPE_P (type))
1802 : 327 : discriminator = discriminator_for_local_entity (TYPE_NAME (type));
1803 : 953 : else if (TYPE_CLASS_SCOPE_P (type))
1804 : 646 : discriminator = nested_anon_class_index (type);
1805 : : else
1806 : : {
1807 : 307 : gcc_assert (no_linkage_check (type, /*relaxed_p=*/true));
1808 : : /* Just use the old mangling at namespace scope. */
1809 : 307 : write_source_name (TYPE_IDENTIFIER (type));
1810 : 307 : return;
1811 : : }
1812 : :
1813 : 973 : write_string ("Ut");
1814 : 973 : write_compact_number (discriminator);
1815 : : }
1816 : :
1817 : : /* ABI issue #47: if a function template parameter is not "natural" for its
1818 : : argument we must mangle the parameter. */
1819 : :
1820 : : static bool
1821 : 5798042 : template_parm_natural_p (tree arg, tree parm)
1822 : : {
1823 : 5798042 : tree decl = TREE_VALUE (parm);
1824 : :
1825 : : /* A template parameter is "natural" if: */
1826 : :
1827 : 5798042 : if (template_parameter_pack_p (decl))
1828 : : {
1829 : 684767 : tree args = ARGUMENT_PACK_ARGS (arg);
1830 : 684767 : if (TREE_VEC_LENGTH (args) == 0)
1831 : : {
1832 : : #if 0
1833 : : /* the argument is an empty pack and the parameter is an
1834 : : unconstrained template type parameter pack; */
1835 : : if (TREE_CODE (decl) != TYPE_DECL)
1836 : : return false;
1837 : : #else
1838 : : /* Defer changing the mangling of C++11 code like
1839 : : template <int i> int max();
1840 : : template <int i, int j, int... rest> int max(); */
1841 : : return true;
1842 : : #endif
1843 : : }
1844 : : else
1845 : : /* the argument is a non-empty pack and a non-pack variant of the
1846 : : parameter would be natural for the first element of the pack; */
1847 : 523553 : arg = TREE_VEC_ELT (args, 0);
1848 : : }
1849 : :
1850 : : /* the argument is a template and the parameter has the exact
1851 : : same template head; */
1852 : 5636828 : if (TREE_CODE (decl) == TEMPLATE_DECL)
1853 : 10121 : return template_heads_equivalent_p (arg, decl);
1854 : :
1855 : : /* the argument is a type and the parameter is unconstrained; or */
1856 : 5626707 : else if (TREE_CODE (decl) == TYPE_DECL)
1857 : 4754834 : return !TEMPLATE_PARM_CONSTRAINTS (parm);
1858 : :
1859 : : /* the argument is a non-type template argument and the declared parameter
1860 : : type neither is instantiation dependent nor contains deduced types. */
1861 : 871873 : else if (TREE_CODE (decl) == PARM_DECL)
1862 : : {
1863 : : #if 0
1864 : : return !uses_template_parms (TREE_TYPE (decl));
1865 : : #else
1866 : : /* Defer changing the mangling of C++98 code like
1867 : : template <class T, T V> .... */
1868 : 871873 : return !type_uses_auto (TREE_TYPE (decl));
1869 : : #endif
1870 : : }
1871 : :
1872 : 0 : gcc_unreachable ();
1873 : : }
1874 : :
1875 : : /* Used for lambda template head and non-natural function template parameters.
1876 : :
1877 : : <template-param-decl> ::= Ty # template type parameter
1878 : : ::= Tk <type-constraint> # constrained type parameter
1879 : : ::= Tn <type> # template non-type parameter
1880 : : ::= Tt <template-param-decl>* [Q <constraint-expression] E # ttp
1881 : : ::= Tp <non-pack template-param-decl> # template parameter pack */
1882 : :
1883 : : static void
1884 : 38021 : write_template_param_decl (tree parm)
1885 : : {
1886 : 38021 : tree decl = TREE_VALUE (parm);
1887 : :
1888 : 38021 : if (template_parameter_pack_p (decl))
1889 : 16558 : write_string ("Tp");
1890 : :
1891 : 38021 : switch (TREE_CODE (decl))
1892 : : {
1893 : 8491 : case PARM_DECL:
1894 : 8491 : {
1895 : 8491 : write_string ("Tn");
1896 : :
1897 : 8491 : tree type = TREE_TYPE (decl);
1898 : 8491 : if (tree c = (is_auto (type)
1899 : 11778 : ? PLACEHOLDER_TYPE_CONSTRAINTS (type)
1900 : 19 : : NULL_TREE))
1901 : : {
1902 : 19 : if (AUTO_IS_DECLTYPE (type))
1903 : 0 : write_string ("DK");
1904 : : else
1905 : 19 : write_string ("Dk");
1906 : 19 : write_type_constraint (c);
1907 : : }
1908 : : else
1909 : 8472 : write_type (type);
1910 : : }
1911 : : break;
1912 : :
1913 : 170 : case TEMPLATE_DECL:
1914 : 170 : {
1915 : 170 : write_string ("Tt");
1916 : 170 : tree parms = DECL_INNERMOST_TEMPLATE_PARMS (decl);
1917 : 376 : for (tree node : tree_vec_range (parms))
1918 : 206 : write_template_param_decl (node);
1919 : 170 : write_char ('E');
1920 : : }
1921 : 170 : break;
1922 : :
1923 : 29360 : case TYPE_DECL:
1924 : 29360 : if (tree c = TEMPLATE_PARM_CONSTRAINTS (parm))
1925 : : {
1926 : 5014 : if (TREE_CODE (c) == UNARY_LEFT_FOLD_EXPR)
1927 : : {
1928 : 42 : c = FOLD_EXPR_PACK (c);
1929 : 42 : c = PACK_EXPANSION_PATTERN (c);
1930 : : }
1931 : 5014 : if (TREE_CODE (decl) == TYPE_DECL)
1932 : : {
1933 : 5014 : write_string ("Tk");
1934 : 5014 : write_type_constraint (c);
1935 : : }
1936 : : }
1937 : : else
1938 : 24346 : write_string ("Ty");
1939 : : break;
1940 : :
1941 : 0 : default:
1942 : 0 : gcc_unreachable ();
1943 : : }
1944 : 38021 : }
1945 : :
1946 : : // A template head, for templated lambdas.
1947 : : // New in ABI=18. Returns true iff we emitted anything -- used for ABI
1948 : : // version warning.
1949 : :
1950 : : static bool
1951 : 317842 : write_closure_template_head (tree tmpl)
1952 : : {
1953 : 317842 : bool any = false;
1954 : :
1955 : : // We only need one level of template parms
1956 : 317842 : tree parms = DECL_TEMPLATE_PARMS (tmpl);
1957 : 317842 : tree inner = INNERMOST_TEMPLATE_PARMS (parms);
1958 : :
1959 : 372503 : for (int ix = 0, len = TREE_VEC_LENGTH (inner); ix != len; ix++)
1960 : : {
1961 : 319346 : tree parm = TREE_VEC_ELT (inner, ix);
1962 : 319346 : if (parm == error_mark_node)
1963 : 0 : continue;
1964 : :
1965 : 319346 : if (DECL_IMPLICIT_TEMPLATE_PARM_P (TREE_VALUE (parm)))
1966 : : // A synthetic parm, we're done.
1967 : : break;
1968 : :
1969 : 54661 : any = true;
1970 : 54661 : if (abi_version_at_least (18))
1971 : 29419 : write_template_param_decl (parm);
1972 : : }
1973 : :
1974 : 317842 : write_tparms_constraints (TEMPLATE_PARMS_CONSTRAINTS (parms));
1975 : :
1976 : 317842 : return any;
1977 : : }
1978 : :
1979 : : /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _
1980 : : <lambda-sig> ::= <parameter type>+ # Parameter types or "v" if the lambda has no parameters */
1981 : :
1982 : : static void
1983 : 1687254 : write_closure_type_name (const tree type)
1984 : : {
1985 : 1687254 : tree fn = lambda_function (type);
1986 : 1687254 : tree lambda = CLASSTYPE_LAMBDA_EXPR (type);
1987 : 1687254 : tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
1988 : :
1989 : 1687254 : MANGLE_TRACE_TREE ("closure-type-name", type);
1990 : :
1991 : 1687254 : write_string ("Ul");
1992 : :
1993 : 1687254 : if (auto ti = maybe_template_info (fn))
1994 : 317842 : if (write_closure_template_head (TI_TEMPLATE (ti)))
1995 : : // If there were any explicit template parms, we may need to
1996 : : // issue a mangling diagnostic.
1997 : 164282 : if (abi_warn_or_compat_version_crosses (18))
1998 : 53188 : G.need_abi_warning = true;
1999 : :
2000 : 1687254 : write_method_parms (parms, TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE, fn);
2001 : 1687254 : write_char ('E');
2002 : 1687254 : if ((LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
2003 : 1687254 : != LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda))
2004 : 2378215 : && abi_warn_or_compat_version_crosses (18))
2005 : 300729 : G.need_abi_warning = true;
2006 : 3374508 : write_compact_number (abi_version_at_least (18)
2007 : 1534838 : ? LAMBDA_EXPR_SCOPE_SIG_DISCRIMINATOR (lambda)
2008 : 152416 : : LAMBDA_EXPR_SCOPE_ONLY_DISCRIMINATOR (lambda));
2009 : 1687254 : }
2010 : :
2011 : : /* Convert NUMBER to ascii using base BASE and generating at least
2012 : : MIN_DIGITS characters. BUFFER points to the _end_ of the buffer
2013 : : into which to store the characters. Returns the number of
2014 : : characters generated (these will be laid out in advance of where
2015 : : BUFFER points). */
2016 : :
2017 : : static int
2018 : 546978024 : hwint_to_ascii (unsigned HOST_WIDE_INT number, const unsigned int base,
2019 : : char *buffer, const unsigned int min_digits)
2020 : : {
2021 : 546978024 : static const char base_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
2022 : 546978024 : unsigned digits = 0;
2023 : :
2024 : 1339262897 : while (number)
2025 : : {
2026 : 792284873 : unsigned HOST_WIDE_INT d = number / base;
2027 : :
2028 : 792284873 : *--buffer = base_digits[number - d * base];
2029 : 792284873 : digits++;
2030 : 792284873 : number = d;
2031 : : }
2032 : 578178866 : while (digits < min_digits)
2033 : : {
2034 : 31200842 : *--buffer = base_digits[0];
2035 : 31200842 : digits++;
2036 : : }
2037 : 546978024 : return digits;
2038 : : }
2039 : :
2040 : : /* Non-terminal <number>.
2041 : :
2042 : : <number> ::= [n] </decimal integer/> */
2043 : :
2044 : : static void
2045 : 546978024 : write_number (unsigned HOST_WIDE_INT number, const int unsigned_p,
2046 : : const unsigned int base)
2047 : : {
2048 : 546978024 : char buffer[sizeof (HOST_WIDE_INT) * 8];
2049 : 546978024 : unsigned count = 0;
2050 : :
2051 : 546978024 : if (!unsigned_p && (HOST_WIDE_INT) number < 0)
2052 : : {
2053 : 0 : write_char ('n');
2054 : 0 : number = -((HOST_WIDE_INT) number);
2055 : : }
2056 : 546978024 : count = hwint_to_ascii (number, base, buffer + sizeof (buffer), 1);
2057 : 546978024 : write_chars (buffer + sizeof (buffer) - count, count);
2058 : 546978024 : }
2059 : :
2060 : : /* Write out an integral CST in decimal. Most numbers are small, and
2061 : : representable in a HOST_WIDE_INT. Occasionally we'll have numbers
2062 : : bigger than that, which we must deal with. */
2063 : :
2064 : : static inline void
2065 : 46706467 : write_integer_cst (const tree cst)
2066 : : {
2067 : 46706467 : int sign = tree_int_cst_sgn (cst);
2068 : 46706467 : widest_int abs_value = wi::abs (wi::to_widest (cst));
2069 : 46706467 : if (!wi::fits_uhwi_p (abs_value))
2070 : : {
2071 : : /* A bignum. We do this in chunks, each of which fits in a
2072 : : HOST_WIDE_INT. */
2073 : 0 : char buffer[sizeof (HOST_WIDE_INT) * 8 * 2];
2074 : 0 : unsigned HOST_WIDE_INT chunk;
2075 : 0 : unsigned chunk_digits;
2076 : 0 : char *ptr = buffer + sizeof (buffer);
2077 : 0 : unsigned count = 0;
2078 : 0 : tree n, base, type;
2079 : 0 : int done;
2080 : :
2081 : : /* HOST_WIDE_INT must be at least 32 bits, so 10^9 is
2082 : : representable. */
2083 : 0 : chunk = 1000000000;
2084 : 0 : chunk_digits = 9;
2085 : :
2086 : 0 : if (sizeof (HOST_WIDE_INT) >= 8)
2087 : : {
2088 : : /* It is at least 64 bits, so 10^18 is representable. */
2089 : 0 : chunk_digits = 18;
2090 : 0 : chunk *= chunk;
2091 : : }
2092 : :
2093 : 0 : type = c_common_signed_or_unsigned_type (1, TREE_TYPE (cst));
2094 : 0 : base = build_int_cstu (type, chunk);
2095 : 0 : n = wide_int_to_tree (type, wi::to_wide (cst));
2096 : :
2097 : 0 : if (sign < 0)
2098 : : {
2099 : 0 : write_char ('n');
2100 : 0 : n = fold_build1_loc (input_location, NEGATE_EXPR, type, n);
2101 : : }
2102 : 0 : do
2103 : : {
2104 : 0 : tree d = fold_build2_loc (input_location, FLOOR_DIV_EXPR, type, n, base);
2105 : 0 : tree tmp = fold_build2_loc (input_location, MULT_EXPR, type, d, base);
2106 : 0 : unsigned c;
2107 : :
2108 : 0 : done = integer_zerop (d);
2109 : 0 : tmp = fold_build2_loc (input_location, MINUS_EXPR, type, n, tmp);
2110 : 0 : c = hwint_to_ascii (TREE_INT_CST_LOW (tmp), 10, ptr,
2111 : : done ? 1 : chunk_digits);
2112 : 0 : ptr -= c;
2113 : 0 : count += c;
2114 : 0 : n = d;
2115 : : }
2116 : 0 : while (!done);
2117 : 0 : write_chars (ptr, count);
2118 : : }
2119 : : else
2120 : : {
2121 : : /* A small num. */
2122 : 46706467 : if (sign < 0)
2123 : 486319 : write_char ('n');
2124 : 46706467 : write_unsigned_number (abs_value.to_uhwi ());
2125 : : }
2126 : 46706467 : }
2127 : :
2128 : : /* Write out a floating-point literal.
2129 : :
2130 : : "Floating-point literals are encoded using the bit pattern of the
2131 : : target processor's internal representation of that number, as a
2132 : : fixed-length lowercase hexadecimal string, high-order bytes first
2133 : : (even if the target processor would store low-order bytes first).
2134 : : The "n" prefix is not used for floating-point literals; the sign
2135 : : bit is encoded with the rest of the number.
2136 : :
2137 : : Here are some examples, assuming the IEEE standard representation
2138 : : for floating point numbers. (Spaces are for readability, not
2139 : : part of the encoding.)
2140 : :
2141 : : 1.0f Lf 3f80 0000 E
2142 : : -1.0f Lf bf80 0000 E
2143 : : 1.17549435e-38f Lf 0080 0000 E
2144 : : 1.40129846e-45f Lf 0000 0001 E
2145 : : 0.0f Lf 0000 0000 E"
2146 : :
2147 : : Caller is responsible for the Lx and the E. */
2148 : : static void
2149 : 111 : write_real_cst (const tree value)
2150 : : {
2151 : 111 : long target_real[4]; /* largest supported float */
2152 : : /* Buffer for eight hex digits in a 32-bit number but big enough
2153 : : even for 64-bit long to avoid warnings. */
2154 : 111 : char buffer[17];
2155 : 111 : int i, limit, dir;
2156 : :
2157 : 111 : tree type = TREE_TYPE (value);
2158 : 111 : int words = GET_MODE_BITSIZE (SCALAR_FLOAT_TYPE_MODE (type)) / 32;
2159 : :
2160 : 111 : real_to_target (target_real, &TREE_REAL_CST (value),
2161 : 111 : TYPE_MODE (type));
2162 : :
2163 : : /* The value in target_real is in the target word order,
2164 : : so we must write it out backward if that happens to be
2165 : : little-endian. write_number cannot be used, it will
2166 : : produce uppercase. */
2167 : 111 : if (FLOAT_WORDS_BIG_ENDIAN)
2168 : : i = 0, limit = words, dir = 1;
2169 : : else
2170 : 111 : i = words - 1, limit = -1, dir = -1;
2171 : :
2172 : 343 : for (; i != limit; i += dir)
2173 : : {
2174 : 232 : sprintf (buffer, "%08lx", (unsigned long) target_real[i]);
2175 : 232 : write_chars (buffer, 8);
2176 : : }
2177 : 111 : }
2178 : :
2179 : : /* Non-terminal <identifier>.
2180 : :
2181 : : <identifier> ::= </unqualified source code identifier> */
2182 : :
2183 : : static void
2184 : 405029707 : write_identifier (const char *identifier)
2185 : : {
2186 : 405029707 : MANGLE_TRACE ("identifier", identifier);
2187 : 405029707 : write_string (identifier);
2188 : 405029707 : }
2189 : :
2190 : : /* Handle constructor productions of non-terminal <special-name>.
2191 : : CTOR is a constructor FUNCTION_DECL.
2192 : :
2193 : : <special-name> ::= C1 # complete object constructor
2194 : : ::= C2 # base object constructor
2195 : : ::= C3 # complete object allocating constructor
2196 : :
2197 : : Currently, allocating constructors are never used. */
2198 : :
2199 : : static void
2200 : 23876099 : write_special_name_constructor (const tree ctor)
2201 : : {
2202 : 23876099 : write_char ('C');
2203 : 23876099 : bool new_inh = (flag_new_inheriting_ctors
2204 : 47736471 : && DECL_INHERITED_CTOR (ctor));
2205 : 108331 : if (new_inh)
2206 : 108331 : write_char ('I');
2207 : 23876099 : if (DECL_BASE_CONSTRUCTOR_P (ctor))
2208 : 4887211 : write_char ('2');
2209 : : /* This is the old-style "[unified]" constructor.
2210 : : In some cases, we may emit this function and call
2211 : : it from the clones in order to share code and save space. */
2212 : 18988888 : else if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor))
2213 : 14102770 : write_char ('4');
2214 : : else
2215 : : {
2216 : 4886118 : gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (ctor));
2217 : 4886118 : write_char ('1');
2218 : : }
2219 : 23876099 : if (new_inh)
2220 : 216662 : write_type (DECL_INHERITED_CTOR_BASE (ctor));
2221 : 23876099 : }
2222 : :
2223 : : /* Handle destructor productions of non-terminal <special-name>.
2224 : : DTOR is a destructor FUNCTION_DECL.
2225 : :
2226 : : <special-name> ::= D0 # deleting (in-charge) destructor
2227 : : ::= D1 # complete object (in-charge) destructor
2228 : : ::= D2 # base object (not-in-charge) destructor */
2229 : :
2230 : : static void
2231 : 6310427 : write_special_name_destructor (const tree dtor)
2232 : : {
2233 : 6310427 : if (DECL_DELETING_DESTRUCTOR_P (dtor))
2234 : 441147 : write_string ("D0");
2235 : 5869280 : else if (DECL_BASE_DESTRUCTOR_P (dtor))
2236 : 1409439 : write_string ("D2");
2237 : 4459841 : else if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor))
2238 : : /* This is the old-style "[unified]" destructor.
2239 : : In some cases, we may emit this function and call
2240 : : it from the clones in order to share code and save space. */
2241 : 2627479 : write_string ("D4");
2242 : : else
2243 : : {
2244 : 1832362 : gcc_assert (DECL_COMPLETE_DESTRUCTOR_P (dtor));
2245 : 1832362 : write_string ("D1");
2246 : : }
2247 : 6310427 : }
2248 : :
2249 : : /* Return the discriminator for ENTITY appearing inside
2250 : : FUNCTION. The discriminator is the lexical ordinal of VAR or TYPE among
2251 : : entities with the same name and kind in the same FUNCTION. */
2252 : :
2253 : : static int
2254 : 2444209 : discriminator_for_local_entity (tree entity)
2255 : : {
2256 : 2444209 : if (!DECL_LANG_SPECIFIC (entity))
2257 : : {
2258 : : /* Some decls, like __FUNCTION__, don't need a discriminator. */
2259 : 29310 : gcc_checking_assert (DECL_ARTIFICIAL (entity));
2260 : : return 0;
2261 : : }
2262 : 4697350 : else if (tree disc = DECL_DISCRIMINATOR (entity))
2263 : 304 : return TREE_INT_CST_LOW (disc);
2264 : : else
2265 : : /* The first entity with a particular name doesn't get
2266 : : DECL_DISCRIMINATOR set up. */
2267 : : return 0;
2268 : : }
2269 : :
2270 : : /* Return the discriminator for STRING, a string literal used inside
2271 : : FUNCTION. The discriminator is the lexical ordinal of STRING among
2272 : : string literals used in FUNCTION. */
2273 : :
2274 : : static int
2275 : 0 : discriminator_for_string_literal (tree /*function*/,
2276 : : tree /*string*/)
2277 : : {
2278 : : /* For now, we don't discriminate amongst string literals. */
2279 : 0 : return 0;
2280 : : }
2281 : :
2282 : : /* <discriminator> := _ <number> # when number < 10
2283 : : := __ <number> _ # when number >= 10
2284 : :
2285 : : The discriminator is used only for the second and later occurrences
2286 : : of the same name within a single function. In this case <number> is
2287 : : n - 2, if this is the nth occurrence, in lexical order. */
2288 : :
2289 : : static void
2290 : 2443882 : write_discriminator (const int discriminator)
2291 : : {
2292 : : /* If discriminator is zero, don't write anything. Otherwise... */
2293 : 2443882 : if (discriminator > 0)
2294 : : {
2295 : 286 : write_char ('_');
2296 : 286 : if (discriminator - 1 >= 10)
2297 : : {
2298 : 6 : if (abi_check (11))
2299 : 6 : write_char ('_');
2300 : : }
2301 : 286 : write_unsigned_number (discriminator - 1);
2302 : 286 : if (abi_version_at_least (11) && discriminator - 1 >= 10)
2303 : 6 : write_char ('_');
2304 : : }
2305 : 2443882 : }
2306 : :
2307 : : /* Mangle the name of a function-scope entity. FUNCTION is the
2308 : : FUNCTION_DECL for the enclosing function, or a PARM_DECL for lambdas in
2309 : : default argument scope. ENTITY is the decl for the entity itself.
2310 : : LOCAL_ENTITY is the entity that's directly scoped in FUNCTION_DECL,
2311 : : either ENTITY itself or an enclosing scope of ENTITY.
2312 : :
2313 : : <local-name> := Z <function encoding> E <entity name> [<discriminator>]
2314 : : := Z <function encoding> E s [<discriminator>]
2315 : : := Z <function encoding> Ed [ <parameter number> ] _ <entity name> */
2316 : :
2317 : : static void
2318 : 4119566 : write_local_name (tree function, const tree local_entity,
2319 : : const tree entity)
2320 : : {
2321 : 4119566 : tree parm = NULL_TREE;
2322 : :
2323 : 4119566 : MANGLE_TRACE_TREE ("local-name", entity);
2324 : :
2325 : 4119566 : if (TREE_CODE (function) == PARM_DECL)
2326 : : {
2327 : 372 : parm = function;
2328 : 372 : function = DECL_CONTEXT (parm);
2329 : : }
2330 : :
2331 : 4119566 : write_char ('Z');
2332 : 4119566 : write_encoding (function);
2333 : 4119566 : write_char ('E');
2334 : :
2335 : : /* For this purpose, parameters are numbered from right-to-left. */
2336 : 4119566 : if (parm)
2337 : : {
2338 : 372 : int i = list_length (parm);
2339 : 372 : write_char ('d');
2340 : 372 : write_compact_number (i - 1);
2341 : : }
2342 : :
2343 : 4119566 : if (TREE_CODE (entity) == STRING_CST)
2344 : : {
2345 : 0 : write_char ('s');
2346 : 0 : write_discriminator (discriminator_for_string_literal (function,
2347 : : entity));
2348 : : }
2349 : : else
2350 : : {
2351 : : /* Now the <entity name>. Let write_name know its being called
2352 : : from <local-name>, so it doesn't try to process the enclosing
2353 : : function scope again. */
2354 : 4119566 : write_name (entity, /*ignore_local_scope=*/1);
2355 : 4119566 : if (DECL_DISCRIMINATOR_P (local_entity)
2356 : 12196249 : && !(TREE_CODE (local_entity) == TYPE_DECL
2357 : 11872572 : && TYPE_ANON_P (TREE_TYPE (local_entity))))
2358 : 2443759 : write_discriminator (discriminator_for_local_entity (local_entity));
2359 : : }
2360 : 4119566 : }
2361 : :
2362 : : /* Non-terminals <type> and <CV-qualifier>.
2363 : :
2364 : : <type> ::= <builtin-type>
2365 : : ::= <function-type>
2366 : : ::= <class-enum-type>
2367 : : ::= <array-type>
2368 : : ::= <pointer-to-member-type>
2369 : : ::= <template-param>
2370 : : ::= <substitution>
2371 : : ::= <CV-qualifier>
2372 : : ::= P <type> # pointer-to
2373 : : ::= R <type> # reference-to
2374 : : ::= C <type> # complex pair (C 2000)
2375 : : ::= G <type> # imaginary (C 2000) [not supported]
2376 : : ::= U <source-name> <type> # vendor extended type qualifier
2377 : :
2378 : : C++0x extensions
2379 : :
2380 : : <type> ::= RR <type> # rvalue reference-to
2381 : : <type> ::= Dt <expression> # decltype of an id-expression or
2382 : : # class member access
2383 : : <type> ::= DT <expression> # decltype of an expression
2384 : : <type> ::= Dn # decltype of nullptr
2385 : :
2386 : : TYPE is a type node. */
2387 : :
2388 : : static void
2389 : 709150479 : write_type (tree type)
2390 : : {
2391 : : /* This gets set to nonzero if TYPE turns out to be a (possibly
2392 : : CV-qualified) builtin type. */
2393 : 709150488 : int is_builtin_type = 0;
2394 : :
2395 : 709150488 : MANGLE_TRACE_TREE ("type", type);
2396 : :
2397 : 709150488 : if (type == error_mark_node)
2398 : : return;
2399 : :
2400 : 709150473 : type = canonicalize_for_substitution (type);
2401 : 709150473 : if (find_substitution (type))
2402 : : return;
2403 : :
2404 : :
2405 : 648045667 : if (write_CV_qualifiers_for_type (type) > 0)
2406 : : /* If TYPE was CV-qualified, we just wrote the qualifiers; now
2407 : : mangle the unqualified type. The recursive call is needed here
2408 : : since both the qualified and unqualified types are substitution
2409 : : candidates. */
2410 : : {
2411 : 42418479 : tree t = TYPE_MAIN_VARIANT (type);
2412 : 42418479 : if (TYPE_ATTRIBUTES (t) && !OVERLOAD_TYPE_P (t))
2413 : : {
2414 : 92 : tree attrs = NULL_TREE;
2415 : 92 : if (tx_safe_fn_type_p (type))
2416 : 3 : attrs = tree_cons (get_identifier ("transaction_safe"),
2417 : : NULL_TREE, attrs);
2418 : 92 : t = cp_build_type_attribute_variant (t, attrs);
2419 : : }
2420 : 42418479 : gcc_assert (t != type);
2421 : 42418479 : if (FUNC_OR_METHOD_TYPE_P (t))
2422 : : {
2423 : 639 : t = build_ref_qualified_type (t, type_memfn_rqual (type));
2424 : 639 : if (flag_noexcept_type)
2425 : : {
2426 : 619 : tree r = TYPE_RAISES_EXCEPTIONS (type);
2427 : 619 : t = build_exception_variant (t, r);
2428 : : }
2429 : 639 : if (abi_version_at_least (8)
2430 : 663 : || type == TYPE_MAIN_VARIANT (type))
2431 : : /* Avoid adding the unqualified function type as a substitution. */
2432 : 615 : write_function_type (t);
2433 : : else
2434 : 24 : write_type (t);
2435 : 3078 : if (abi_warn_or_compat_version_crosses (8))
2436 : 39 : G.need_abi_warning = 1;
2437 : : }
2438 : : else
2439 : 42417840 : write_type (t);
2440 : : }
2441 : 605627188 : else if (TREE_CODE (type) == ARRAY_TYPE)
2442 : : /* It is important not to use the TYPE_MAIN_VARIANT of TYPE here
2443 : : so that the cv-qualification of the element type is available
2444 : : in write_array_type. */
2445 : 245782 : write_array_type (type);
2446 : : else
2447 : : {
2448 : 605381406 : tree type_orig = type;
2449 : :
2450 : : /* See through any typedefs. */
2451 : 605381406 : type = TYPE_MAIN_VARIANT (type);
2452 : 605381406 : if (FUNC_OR_METHOD_TYPE_P (type))
2453 : 2780058 : type = cxx_copy_lang_qualifiers (type, type_orig);
2454 : :
2455 : : /* According to the C++ ABI, some library classes are passed the
2456 : : same as the scalar type of their single member and use the same
2457 : : mangling. */
2458 : 605381406 : if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
2459 : 16206 : type = TREE_TYPE (first_field (type));
2460 : :
2461 : 605381406 : if (TYPE_PTRDATAMEM_P (type))
2462 : 8295 : write_pointer_to_member_type (type);
2463 : : else
2464 : : {
2465 : : /* Handle any target-specific fundamental types. */
2466 : 605373111 : const char *target_mangling
2467 : 605373111 : = targetm.mangle_type (type_orig);
2468 : :
2469 : 605373111 : if (target_mangling)
2470 : : {
2471 : 6679552 : write_string (target_mangling);
2472 : : /* Add substitutions for types other than fundamental
2473 : : types. */
2474 : 6679552 : if (!VOID_TYPE_P (type)
2475 : : && TREE_CODE (type) != INTEGER_TYPE
2476 : : && TREE_CODE (type) != REAL_TYPE
2477 : : && TREE_CODE (type) != BOOLEAN_TYPE)
2478 : 0 : add_substitution (type);
2479 : 6679552 : return;
2480 : : }
2481 : :
2482 : 598693559 : switch (TREE_CODE (type))
2483 : : {
2484 : 314981025 : case VOID_TYPE:
2485 : 314981025 : case BOOLEAN_TYPE:
2486 : 314981025 : case INTEGER_TYPE: /* Includes wchar_t. */
2487 : 314981025 : case REAL_TYPE:
2488 : 314981025 : case FIXED_POINT_TYPE:
2489 : 314981025 : {
2490 : : /* If this is a typedef, TYPE may not be one of
2491 : : the standard builtin type nodes, but an alias of one. Use
2492 : : TYPE_MAIN_VARIANT to get to the underlying builtin type. */
2493 : 314981025 : write_builtin_type (TYPE_MAIN_VARIANT (type));
2494 : 314981025 : ++is_builtin_type;
2495 : : }
2496 : 314981025 : break;
2497 : :
2498 : 717489 : case COMPLEX_TYPE:
2499 : 717489 : write_char ('C');
2500 : 717489 : write_type (TREE_TYPE (type));
2501 : 717489 : break;
2502 : :
2503 : 2780058 : case FUNCTION_TYPE:
2504 : 2780058 : case METHOD_TYPE:
2505 : 2780058 : write_function_type (type);
2506 : 2780058 : break;
2507 : :
2508 : 177594010 : case UNION_TYPE:
2509 : 177594010 : case RECORD_TYPE:
2510 : 177594010 : case ENUMERAL_TYPE:
2511 : : /* A pointer-to-member function is represented as a special
2512 : : RECORD_TYPE, so check for this first. */
2513 : 177594010 : if (TYPE_PTRMEMFUNC_P (type))
2514 : 283515 : write_pointer_to_member_type (type);
2515 : : else
2516 : 177310495 : write_class_enum_type (type);
2517 : : break;
2518 : :
2519 : 2106246 : case TYPENAME_TYPE:
2520 : 2106246 : case UNBOUND_CLASS_TEMPLATE:
2521 : : /* We handle TYPENAME_TYPEs and UNBOUND_CLASS_TEMPLATEs like
2522 : : ordinary nested names. */
2523 : 2106246 : write_nested_name (TYPE_STUB_DECL (type));
2524 : 2106246 : break;
2525 : :
2526 : 76708765 : case POINTER_TYPE:
2527 : 76708765 : case REFERENCE_TYPE:
2528 : 76708765 : if (TYPE_PTR_P (type))
2529 : 33325213 : write_char ('P');
2530 : 43383552 : else if (TYPE_REF_IS_RVALUE (type))
2531 : 8377473 : write_char ('O');
2532 : : else
2533 : 35006079 : write_char ('R');
2534 : 76708765 : {
2535 : 76708765 : tree target = TREE_TYPE (type);
2536 : : /* Attribute const/noreturn are not reflected in mangling.
2537 : : We strip them here rather than at a lower level because
2538 : : a typedef or template argument can have function type
2539 : : with function-cv-quals (that use the same representation),
2540 : : but you can't have a pointer/reference to such a type. */
2541 : 76708765 : if (TREE_CODE (target) == FUNCTION_TYPE)
2542 : : {
2543 : 9414695 : if (abi_warn_or_compat_version_crosses (5)
2544 : 1883293 : && TYPE_QUALS (target) != TYPE_UNQUALIFIED)
2545 : 3 : G.need_abi_warning = 1;
2546 : 1883287 : if (abi_version_at_least (5))
2547 : 1882858 : target = build_qualified_type (target, TYPE_UNQUALIFIED);
2548 : : }
2549 : 76708765 : write_type (target);
2550 : : }
2551 : 76708765 : break;
2552 : :
2553 : 20488565 : case TEMPLATE_TYPE_PARM:
2554 : 20488565 : if (is_auto (type))
2555 : : {
2556 : 410510 : if (template_placeholder_p (type)
2557 : 410510 : && abi_check (19))
2558 : : {
2559 : : /* ABI #109: placeholder is mangled as its template. */
2560 : 27 : type = CLASS_PLACEHOLDER_TEMPLATE (type);
2561 : 27 : if (find_substitution (type))
2562 : : return;
2563 : 27 : write_name (type, 0);
2564 : 27 : break;
2565 : : }
2566 : 410483 : if (AUTO_IS_DECLTYPE (type))
2567 : 36119 : write_identifier ("Dc");
2568 : : else
2569 : 374364 : write_identifier ("Da");
2570 : : ++is_builtin_type;
2571 : : break;
2572 : : }
2573 : : /* fall through. */
2574 : 20078055 : case TEMPLATE_PARM_INDEX:
2575 : 20078055 : write_template_param (type);
2576 : 20078055 : break;
2577 : :
2578 : 102 : case TEMPLATE_TEMPLATE_PARM:
2579 : 102 : write_template_template_param (type);
2580 : 102 : break;
2581 : :
2582 : 535 : case BOUND_TEMPLATE_TEMPLATE_PARM:
2583 : 535 : write_template_template_param (type);
2584 : 535 : write_template_args
2585 : 535 : (TI_ARGS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (type)));
2586 : 535 : break;
2587 : :
2588 : 8441 : case VECTOR_TYPE:
2589 : 8441 : if (abi_version_at_least (4))
2590 : : {
2591 : 8426 : write_string ("Dv");
2592 : : /* Non-constant vector size would be encoded with
2593 : : _ expression, but we don't support that yet. */
2594 : 8426 : write_unsigned_number (TYPE_VECTOR_SUBPARTS (type)
2595 : : .to_constant ());
2596 : 8426 : write_char ('_');
2597 : 8426 : }
2598 : : else
2599 : 15 : write_string ("U8__vector");
2600 : 42160 : if (abi_warn_or_compat_version_crosses (4))
2601 : 15 : G.need_abi_warning = 1;
2602 : 8441 : write_type (TREE_TYPE (type));
2603 : 8441 : break;
2604 : :
2605 : 2735228 : case TYPE_PACK_EXPANSION:
2606 : 2735228 : write_string ("Dp");
2607 : 2735228 : write_type (PACK_EXPANSION_PATTERN (type));
2608 : 2735228 : break;
2609 : :
2610 : 121567 : case DECLTYPE_TYPE:
2611 : : /* These shouldn't make it into mangling. */
2612 : 121567 : gcc_assert (!DECLTYPE_FOR_LAMBDA_CAPTURE (type)
2613 : : && !DECLTYPE_FOR_LAMBDA_PROXY (type));
2614 : :
2615 : : /* In ABI <5, we stripped decltype of a plain decl. */
2616 : 121567 : if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
2617 : : {
2618 : 156 : tree expr = DECLTYPE_TYPE_EXPR (type);
2619 : 156 : tree etype = NULL_TREE;
2620 : 156 : switch (TREE_CODE (expr))
2621 : : {
2622 : 108 : case VAR_DECL:
2623 : 108 : case PARM_DECL:
2624 : 108 : case RESULT_DECL:
2625 : 108 : case FUNCTION_DECL:
2626 : 108 : case CONST_DECL:
2627 : 108 : case TEMPLATE_PARM_INDEX:
2628 : 108 : etype = TREE_TYPE (expr);
2629 : 108 : break;
2630 : :
2631 : : default:
2632 : : break;
2633 : : }
2634 : :
2635 : 108 : if (etype && !type_uses_auto (etype))
2636 : : {
2637 : 108 : if (!abi_check (5))
2638 : : {
2639 : : write_type (etype);
2640 : : return;
2641 : : }
2642 : : }
2643 : : }
2644 : :
2645 : 121558 : write_char ('D');
2646 : 121558 : if (DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type))
2647 : 147 : write_char ('t');
2648 : : else
2649 : 121411 : write_char ('T');
2650 : 121558 : ++cp_unevaluated_operand;
2651 : 121558 : write_expression (DECLTYPE_TYPE_EXPR (type));
2652 : 121558 : --cp_unevaluated_operand;
2653 : 121558 : write_char ('E');
2654 : 121558 : break;
2655 : :
2656 : 451499 : case NULLPTR_TYPE:
2657 : 451499 : write_string ("Dn");
2658 : 451499 : if (abi_check (7))
2659 : : ++is_builtin_type;
2660 : : break;
2661 : :
2662 : 3 : case TYPEOF_TYPE:
2663 : 3 : sorry ("mangling %<typeof%>, use %<decltype%> instead");
2664 : 3 : break;
2665 : :
2666 : 21 : case TRAIT_TYPE:
2667 : 21 : error ("use of built-in trait %qT in function signature; "
2668 : : "use library traits instead", type);
2669 : 21 : break;
2670 : :
2671 : 5 : case PACK_INDEX_TYPE:
2672 : : /* TODO Mangle pack indexing
2673 : : <https://github.com/itanium-cxx-abi/cxx-abi/issues/175>. */
2674 : 5 : sorry ("mangling type pack index");
2675 : 5 : break;
2676 : :
2677 : 0 : case LANG_TYPE:
2678 : : /* fall through. */
2679 : :
2680 : 0 : default:
2681 : 0 : gcc_unreachable ();
2682 : : }
2683 : : }
2684 : : }
2685 : :
2686 : : /* Types other than builtin types are substitution candidates. */
2687 : 640503524 : if (!is_builtin_type)
2688 : 325523101 : add_substitution (type);
2689 : : }
2690 : :
2691 : : /* qsort callback for sorting a vector of attribute entries. */
2692 : :
2693 : : static int
2694 : 0 : attr_strcmp (const void *p1, const void *p2)
2695 : : {
2696 : 0 : tree a1 = *(const tree*)p1;
2697 : 0 : tree a2 = *(const tree*)p2;
2698 : :
2699 : 0 : const attribute_spec *as1 = lookup_attribute_spec (get_attribute_name (a1));
2700 : 0 : const attribute_spec *as2 = lookup_attribute_spec (get_attribute_name (a2));
2701 : :
2702 : 0 : return strcmp (as1->name, as2->name);
2703 : : }
2704 : :
2705 : : /* Return true if we should mangle a type attribute with name NAME. */
2706 : :
2707 : : static bool
2708 : 11652 : mangle_type_attribute_p (tree name)
2709 : : {
2710 : 11652 : const attribute_spec *as = lookup_attribute_spec (name);
2711 : 11652 : if (!as || !as->affects_type_identity)
2712 : : return false;
2713 : :
2714 : : /* Skip internal-only attributes, which are distinguished from others
2715 : : by having a space. At present, all internal-only attributes that
2716 : : affect type identity are target-specific and are handled by
2717 : : targetm.mangle_type instead.
2718 : :
2719 : : Another reason to do this is that a space isn't a valid identifier
2720 : : character for most file formats. */
2721 : 56 : if (strchr (IDENTIFIER_POINTER (name), ' '))
2722 : : return false;
2723 : :
2724 : : /* The following attributes are mangled specially. */
2725 : 56 : if (is_attribute_p ("transaction_safe", name))
2726 : : return false;
2727 : 31 : if (is_attribute_p ("abi_tag", name))
2728 : 0 : return false;
2729 : :
2730 : : return true;
2731 : : }
2732 : :
2733 : : /* Non-terminal <CV-qualifiers> for type nodes. Returns the number of
2734 : : CV-qualifiers written for TYPE.
2735 : :
2736 : : <CV-qualifiers> ::= [r] [V] [K] */
2737 : :
2738 : : static int
2739 : 648329182 : write_CV_qualifiers_for_type (const tree type)
2740 : : {
2741 : 648329182 : int num_qualifiers = 0;
2742 : :
2743 : : /* The order is specified by:
2744 : :
2745 : : "In cases where multiple order-insensitive qualifiers are
2746 : : present, they should be ordered 'K' (closest to the base type),
2747 : : 'V', 'r', and 'U' (farthest from the base type) ..." */
2748 : :
2749 : : /* Mangle attributes that affect type identity as extended qualifiers.
2750 : :
2751 : : We don't do this with classes and enums because their attributes
2752 : : are part of their definitions, not something added on. */
2753 : :
2754 : 648329182 : if (!OVERLOAD_TYPE_P (type))
2755 : : {
2756 : 451219090 : auto_vec<tree> vec;
2757 : 451230742 : for (tree a = TYPE_ATTRIBUTES (type); a; a = TREE_CHAIN (a))
2758 : 11652 : if (mangle_type_attribute_p (get_attribute_name (a)))
2759 : 31 : vec.safe_push (a);
2760 : 2255335647 : if (abi_warn_or_compat_version_crosses (10) && !vec.is_empty ())
2761 : 0 : G.need_abi_warning = true;
2762 : 451219090 : if (abi_version_at_least (10))
2763 : : {
2764 : 450970497 : vec.qsort (attr_strcmp);
2765 : 451219152 : while (!vec.is_empty())
2766 : : {
2767 : 31 : tree a = vec.pop();
2768 : 31 : const attribute_spec *as
2769 : 31 : = lookup_attribute_spec (get_attribute_name (a));
2770 : :
2771 : 31 : write_char ('U');
2772 : 31 : write_unsigned_number (strlen (as->name));
2773 : 31 : write_string (as->name);
2774 : 31 : if (TREE_VALUE (a))
2775 : : {
2776 : 3 : write_char ('I');
2777 : 6 : for (tree args = TREE_VALUE (a); args;
2778 : 3 : args = TREE_CHAIN (args))
2779 : : {
2780 : 3 : tree arg = TREE_VALUE (args);
2781 : 3 : write_template_arg (arg);
2782 : : }
2783 : 3 : write_char ('E');
2784 : : }
2785 : :
2786 : 31 : ++num_qualifiers;
2787 : : }
2788 : : }
2789 : 451219090 : }
2790 : :
2791 : : /* Note that we do not use cp_type_quals below; given "const
2792 : : int[3]", the "const" is emitted with the "int", not with the
2793 : : array. */
2794 : 648329182 : cp_cv_quals quals = TYPE_QUALS (type);
2795 : :
2796 : 648329182 : if (quals & TYPE_QUAL_RESTRICT)
2797 : : {
2798 : 39 : write_char ('r');
2799 : 39 : ++num_qualifiers;
2800 : : }
2801 : 648329182 : if (quals & TYPE_QUAL_VOLATILE)
2802 : : {
2803 : 205694 : write_char ('V');
2804 : 205694 : ++num_qualifiers;
2805 : : }
2806 : 648329182 : if (quals & TYPE_QUAL_CONST)
2807 : : {
2808 : 42361613 : write_char ('K');
2809 : 42361613 : ++num_qualifiers;
2810 : : }
2811 : :
2812 : 648329182 : return num_qualifiers;
2813 : : }
2814 : :
2815 : : /* Non-terminal <builtin-type>.
2816 : :
2817 : : <builtin-type> ::= v # void
2818 : : ::= b # bool
2819 : : ::= w # wchar_t
2820 : : ::= c # char
2821 : : ::= a # signed char
2822 : : ::= h # unsigned char
2823 : : ::= s # short
2824 : : ::= t # unsigned short
2825 : : ::= i # int
2826 : : ::= j # unsigned int
2827 : : ::= l # long
2828 : : ::= m # unsigned long
2829 : : ::= x # long long, __int64
2830 : : ::= y # unsigned long long, __int64
2831 : : ::= n # __int128
2832 : : ::= o # unsigned __int128
2833 : : ::= f # float
2834 : : ::= d # double
2835 : : ::= e # long double, __float80
2836 : : ::= g # __float128 [not supported]
2837 : : ::= u <source-name> # vendor extended type */
2838 : :
2839 : : static void
2840 : 314981025 : write_builtin_type (tree type)
2841 : : {
2842 : 314981025 : if (TYPE_CANONICAL (type))
2843 : 314981025 : type = TYPE_CANONICAL (type);
2844 : :
2845 : 314981025 : switch (TREE_CODE (type))
2846 : : {
2847 : 46729293 : case VOID_TYPE:
2848 : 46729293 : write_char ('v');
2849 : 46729293 : break;
2850 : :
2851 : 28317775 : case BOOLEAN_TYPE:
2852 : 28317775 : write_char ('b');
2853 : 28317775 : break;
2854 : :
2855 : 227657174 : case INTEGER_TYPE:
2856 : : /* TYPE may still be wchar_t, char8_t, char16_t, or char32_t, since that
2857 : : isn't in integer_type_nodes. */
2858 : 227657174 : if (type == wchar_type_node)
2859 : 23782851 : write_char ('w');
2860 : 203874323 : else if (type == char8_type_node)
2861 : 3182248 : write_string ("Du");
2862 : 200692075 : else if (type == char16_type_node)
2863 : 13788395 : write_string ("Ds");
2864 : 186903680 : else if (type == char32_type_node)
2865 : 14674094 : write_string ("Di");
2866 : : else
2867 : : {
2868 : 172229586 : size_t itk;
2869 : : /* Assume TYPE is one of the shared integer type nodes. Find
2870 : : it in the array of these nodes. */
2871 : 172229586 : iagain:
2872 : 1051529641 : for (itk = 0; itk < itk_none; ++itk)
2873 : 1050334694 : if (integer_types[itk] != NULL_TREE
2874 : 1043165012 : && integer_type_codes[itk] != '\0'
2875 : 1040775118 : && type == integer_types[itk])
2876 : : {
2877 : : /* Print the corresponding single-letter code. */
2878 : 171034639 : write_char (integer_type_codes[itk]);
2879 : 171034639 : break;
2880 : : }
2881 : :
2882 : 172229586 : if (itk == itk_none)
2883 : : {
2884 : 1194947 : tree t = c_common_type_for_mode (TYPE_MODE (type),
2885 : 1194947 : TYPE_UNSIGNED (type));
2886 : 1194947 : if (type != t)
2887 : : {
2888 : 0 : type = t;
2889 : 0 : goto iagain;
2890 : : }
2891 : :
2892 : 1194947 : if (TYPE_PRECISION (type) == 128)
2893 : 1705688 : write_char (TYPE_UNSIGNED (type) ? 'o' : 'n');
2894 : : else
2895 : : {
2896 : : /* Allow for cases where TYPE is not one of the shared
2897 : : integer type nodes and write a "vendor extended builtin
2898 : : type" with a name the form intN or uintN, respectively.
2899 : : Situations like this can happen if you have an
2900 : : __attribute__((__mode__(__SI__))) type and use exotic
2901 : : switches like '-mint8' on AVR. Of course, this is
2902 : : undefined by the C++ ABI (and '-mint8' is not even
2903 : : Standard C conforming), but when using such special
2904 : : options you're pretty much in nowhere land anyway. */
2905 : 0 : const char *prefix;
2906 : 0 : char prec[11]; /* up to ten digits for an unsigned */
2907 : :
2908 : 0 : prefix = TYPE_UNSIGNED (type) ? "uint" : "int";
2909 : 0 : sprintf (prec, "%u", (unsigned) TYPE_PRECISION (type));
2910 : 0 : write_char ('u'); /* "vendor extended builtin type" */
2911 : 0 : write_unsigned_number (strlen (prefix) + strlen (prec));
2912 : 0 : write_string (prefix);
2913 : 0 : write_string (prec);
2914 : : }
2915 : : }
2916 : : }
2917 : : break;
2918 : :
2919 : 12276783 : case REAL_TYPE:
2920 : 12276783 : if (type == float_type_node)
2921 : 4322976 : write_char ('f');
2922 : 7953807 : else if (type == double_type_node)
2923 : 5781223 : write_char ('d');
2924 : 2172584 : else if (type == long_double_type_node)
2925 : 0 : write_char ('e');
2926 : 2172584 : else if (type == dfloat32_type_node)
2927 : 6152 : write_string ("Df");
2928 : 2166432 : else if (type == dfloat64_type_node)
2929 : 6041 : write_string ("Dd");
2930 : 2160391 : else if (type == dfloat128_type_node)
2931 : 6005 : write_string ("De");
2932 : 2154386 : else if (type == float16_type_node)
2933 : 0 : write_string ("DF16_");
2934 : 2154386 : else if (type == float32_type_node)
2935 : 636440 : write_string ("DF32_");
2936 : 1517946 : else if (type == float64_type_node)
2937 : 636440 : write_string ("DF64_");
2938 : 881506 : else if (type == float128_type_node)
2939 : 821904 : write_string ("DF128_");
2940 : 59602 : else if (type == float32x_type_node)
2941 : 29801 : write_string ("DF32x");
2942 : 29801 : else if (type == float64x_type_node)
2943 : 29801 : write_string ("DF64x");
2944 : 0 : else if (type == float128x_type_node)
2945 : 0 : write_string ("DF128x");
2946 : 0 : else if (type == bfloat16_type_node)
2947 : 0 : write_string ("DF16b");
2948 : : else
2949 : 0 : gcc_unreachable ();
2950 : : break;
2951 : :
2952 : 0 : default:
2953 : 0 : gcc_unreachable ();
2954 : : }
2955 : 314981025 : }
2956 : :
2957 : : /* Non-terminal <function-type>. NODE is a FUNCTION_TYPE or
2958 : : METHOD_TYPE. The return type is mangled before the parameter
2959 : : types.
2960 : :
2961 : : <function-type> ::= F [Y] <bare-function-type> [<ref-qualifier>] E */
2962 : :
2963 : : static void
2964 : 2780673 : write_function_type (const tree type)
2965 : : {
2966 : 2780673 : MANGLE_TRACE_TREE ("function-type", type);
2967 : :
2968 : : /* For a pointer to member function, the function type may have
2969 : : cv-qualifiers, indicating the quals for the artificial 'this'
2970 : : parameter. */
2971 : 2780673 : if (TREE_CODE (type) == METHOD_TYPE)
2972 : : {
2973 : : /* The first parameter must be a POINTER_TYPE pointing to the
2974 : : `this' parameter. */
2975 : 283515 : tree this_type = class_of_this_parm (type);
2976 : 283515 : write_CV_qualifiers_for_type (this_type);
2977 : : }
2978 : :
2979 : 2780673 : write_exception_spec (TYPE_RAISES_EXCEPTIONS (type));
2980 : :
2981 : 2780673 : if (tx_safe_fn_type_p (type))
2982 : 25 : write_string ("Dx");
2983 : :
2984 : 2780673 : write_char ('F');
2985 : : /* We don't track whether or not a type is `extern "C"'. Note that
2986 : : you can have an `extern "C"' function that does not have
2987 : : `extern "C"' type, and vice versa:
2988 : :
2989 : : extern "C" typedef void function_t();
2990 : : function_t f; // f has C++ linkage, but its type is
2991 : : // `extern "C"'
2992 : :
2993 : : typedef void function_t();
2994 : : extern "C" function_t f; // Vice versa.
2995 : :
2996 : : See [dcl.link]. */
2997 : 2780673 : write_bare_function_type (type, /*include_return_type_p=*/1,
2998 : : /*decl=*/NULL);
2999 : 2780673 : if (FUNCTION_REF_QUALIFIED (type))
3000 : : {
3001 : 748 : if (FUNCTION_RVALUE_QUALIFIED (type))
3002 : 264 : write_char ('O');
3003 : : else
3004 : 484 : write_char ('R');
3005 : : }
3006 : 2780673 : write_char ('E');
3007 : 2780673 : }
3008 : :
3009 : : /* Non-terminal <bare-function-type>. TYPE is a FUNCTION_TYPE or
3010 : : METHOD_TYPE. If INCLUDE_RETURN_TYPE is nonzero, the return value
3011 : : is mangled before the parameter types. If non-NULL, DECL is
3012 : : FUNCTION_DECL for the function whose type is being emitted. */
3013 : :
3014 : : static void
3015 : 111242591 : write_bare_function_type (const tree type, const int include_return_type_p,
3016 : : const tree decl)
3017 : : {
3018 : 111242591 : MANGLE_TRACE_TREE ("bare-function-type", type);
3019 : :
3020 : : /* Mangle the return type, if requested. */
3021 : 111242591 : if (include_return_type_p)
3022 : 13595622 : write_type (TREE_TYPE (type));
3023 : :
3024 : : /* Now mangle the types of the arguments. */
3025 : 111242591 : ++G.parm_depth;
3026 : 111242591 : write_method_parms (TYPE_ARG_TYPES (type),
3027 : 111242591 : TREE_CODE (type) == METHOD_TYPE,
3028 : : decl);
3029 : 111242591 : --G.parm_depth;
3030 : 111242591 : }
3031 : :
3032 : : /* Write the mangled representation of a method parameter list of
3033 : : types given in PARM_TYPES. If METHOD_P is nonzero, the function is
3034 : : considered a non-static method, and the this parameter is omitted.
3035 : : If non-NULL, DECL is the FUNCTION_DECL for the function whose
3036 : : parameters are being emitted. */
3037 : :
3038 : : static void
3039 : 112929845 : write_method_parms (tree parm_types, const int method_p, const tree decl)
3040 : : {
3041 : 112929845 : tree first_parm_type;
3042 : 210342189 : tree parm_decl = decl ? DECL_ARGUMENTS (decl) : NULL_TREE;
3043 : :
3044 : : /* Assume this parameter type list is variable-length. If it ends
3045 : : with a void type, then it's not. */
3046 : 112929845 : int varargs_p = 1;
3047 : :
3048 : : /* If this is a member function, skip the first arg, which is the
3049 : : this pointer.
3050 : : "Member functions do not encode the type of their implicit this
3051 : : parameter."
3052 : :
3053 : : Similarly, there's no need to mangle artificial parameters, like
3054 : : the VTT parameters for constructors and destructors. */
3055 : 112929845 : if (method_p)
3056 : : {
3057 : 83569515 : parm_types = TREE_CHAIN (parm_types);
3058 : 83569515 : parm_decl = parm_decl ? DECL_CHAIN (parm_decl) : NULL_TREE;
3059 : :
3060 : 83607471 : while (parm_decl && DECL_ARTIFICIAL (parm_decl))
3061 : : {
3062 : 37956 : parm_types = TREE_CHAIN (parm_types);
3063 : 37956 : parm_decl = DECL_CHAIN (parm_decl);
3064 : : }
3065 : :
3066 : 83569515 : if (decl && ctor_omit_inherited_parms (decl))
3067 : : /* Bring back parameters omitted from an inherited ctor. */
3068 : 54 : parm_types = FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (decl));
3069 : : }
3070 : :
3071 : 112929845 : for (first_parm_type = parm_types;
3072 : 356541088 : parm_types;
3073 : 243611243 : parm_types = TREE_CHAIN (parm_types))
3074 : : {
3075 : 243611243 : tree parm = TREE_VALUE (parm_types);
3076 : 243611243 : if (parm == void_type_node)
3077 : : {
3078 : : /* "Empty parameter lists, whether declared as () or
3079 : : conventionally as (void), are encoded with a void parameter
3080 : : (v)." */
3081 : 112879783 : if (parm_types == first_parm_type)
3082 : 37427439 : write_type (parm);
3083 : : /* If the parm list is terminated with a void type, it's
3084 : : fixed-length. */
3085 : 112879783 : varargs_p = 0;
3086 : : /* A void type better be the last one. */
3087 : 112879783 : gcc_assert (TREE_CHAIN (parm_types) == NULL);
3088 : : }
3089 : : else
3090 : 130731460 : write_type (parm);
3091 : : }
3092 : :
3093 : 112929845 : if (varargs_p)
3094 : : /* <builtin-type> ::= z # ellipsis */
3095 : 50062 : write_char ('z');
3096 : 112929845 : }
3097 : :
3098 : : /* <class-enum-type> ::= <name> */
3099 : :
3100 : : static void
3101 : 177310495 : write_class_enum_type (const tree type)
3102 : : {
3103 : 177310495 : write_name (TYPE_NAME (type), /*ignore_local_scope=*/0);
3104 : 177310495 : }
3105 : :
3106 : : /* Mangle a requirement REQ in a requires-expression. */
3107 : :
3108 : : static void
3109 : 103844 : write_requirement (tree req)
3110 : : {
3111 : 103844 : tree op = TREE_OPERAND (req, 0);
3112 : :
3113 : 103844 : switch (tree_code code = TREE_CODE (req))
3114 : : {
3115 : : /* # simple-requirement or compound-requirement
3116 : : <requirement> ::= X <expression> [ N ] [ R <type-constraint> ] */
3117 : 103751 : case SIMPLE_REQ:
3118 : 103751 : case COMPOUND_REQ:
3119 : 103751 : write_char ('X');
3120 : 103751 : write_expression (op);
3121 : 103751 : if (code == SIMPLE_REQ)
3122 : : break;
3123 : 26724 : if (COMPOUND_REQ_NOEXCEPT_P (req))
3124 : 3 : write_char ('N');
3125 : 26724 : if (tree constr = TREE_OPERAND (req, 1))
3126 : : {
3127 : 26721 : write_char ('R');
3128 : 26721 : write_type_constraint (PLACEHOLDER_TYPE_CONSTRAINTS (constr));
3129 : : }
3130 : : break;
3131 : :
3132 : : /* <requirement> ::= T <type> # type-requirement */
3133 : 90 : case TYPE_REQ:
3134 : 90 : write_char ('T');
3135 : 90 : write_type (op);
3136 : 90 : break;
3137 : :
3138 : : /* <requirement> ::= Q <constraint-expression> # nested-requirement */
3139 : 3 : case NESTED_REQ:
3140 : 3 : write_char ('Q');
3141 : 3 : write_constraint_expression (op);
3142 : 3 : break;
3143 : :
3144 : 0 : default:
3145 : 0 : gcc_unreachable ();
3146 : : }
3147 : 103844 : }
3148 : :
3149 : : /* # requires { ... }
3150 : : <expression> ::= rq <requirement>+ E
3151 : : # requires (...) { ... }
3152 : : <expression> ::= rQ <bare-function-type> _ <requirement>+ E */
3153 : :
3154 : : static void
3155 : 97150 : write_requires_expr (tree expr)
3156 : : {
3157 : 97150 : tree parms = REQUIRES_EXPR_PARMS (expr);
3158 : 97150 : if (parms)
3159 : : {
3160 : 12466 : write_string ("rQ");
3161 : 12466 : ++G.parm_depth;
3162 : 25159 : for (; parms; parms = DECL_CHAIN (parms))
3163 : 12693 : write_type (cv_unqualified (TREE_TYPE (parms)));
3164 : 12466 : --G.parm_depth;
3165 : 12466 : write_char ('_');
3166 : : }
3167 : : else
3168 : 84684 : write_string ("rq");
3169 : :
3170 : 200994 : for (tree reqs = REQUIRES_EXPR_REQS (expr); reqs;
3171 : 103844 : reqs = TREE_CHAIN (reqs))
3172 : 103844 : write_requirement (TREE_VALUE (reqs));
3173 : :
3174 : 97150 : write_char ('E');
3175 : 97150 : }
3176 : :
3177 : : /* Non-terminal <template-args>. ARGS is a TREE_VEC of template
3178 : : arguments.
3179 : :
3180 : : <template-args> ::= I <template-arg>* [Q <constraint-expr>] E */
3181 : :
3182 : : static void
3183 : 221979636 : write_template_args (tree args, tree parms /*= NULL_TREE*/)
3184 : : {
3185 : 221979636 : int i;
3186 : 221979636 : int length = 0;
3187 : :
3188 : 221979636 : MANGLE_TRACE_TREE ("template-args", args);
3189 : :
3190 : 221979636 : write_char ('I');
3191 : :
3192 : 221979636 : if (args)
3193 : 221979636 : length = TREE_VEC_LENGTH (args);
3194 : :
3195 : 221979636 : tree constraints = NULL_TREE;
3196 : 221979636 : if (parms)
3197 : : {
3198 : 3637098 : constraints = TEMPLATE_PARMS_CONSTRAINTS (parms);
3199 : 3637098 : parms = INNERMOST_TEMPLATE_PARMS (parms);
3200 : : }
3201 : :
3202 : 221979636 : if (args && length && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
3203 : : {
3204 : : /* We have nested template args. We want the innermost template
3205 : : argument list. */
3206 : 4565840 : args = TREE_VEC_ELT (args, length - 1);
3207 : 4565840 : length = TREE_VEC_LENGTH (args);
3208 : : }
3209 : 221979636 : if (TEMPLATE_ARGS_TYPE_CONSTRAINT_P (args))
3210 : : /* Skip the constrained type. */
3211 : : i = 1;
3212 : : else
3213 : 221966139 : i = 0;
3214 : : bool implicit_parm_scope = false;
3215 : 617115484 : for (; i < length; ++i)
3216 : : {
3217 : 395135848 : tree arg = TREE_VEC_ELT (args, i);
3218 : 395135848 : if (parms)
3219 : : {
3220 : 5798042 : tree parm = TREE_VEC_ELT (parms, i);
3221 : 5798042 : tree decl = TREE_VALUE (parm);
3222 : 5798042 : if (DECL_IMPLICIT_TEMPLATE_PARM_P (decl)
3223 : 5798042 : && !implicit_parm_scope)
3224 : : {
3225 : : /* The rest of the template parameters are based on generic
3226 : : function parameters, so any expressions in their
3227 : : type-constraints are in parameter scope. */
3228 : 472 : implicit_parm_scope = true;
3229 : 472 : ++G.parm_depth;
3230 : : }
3231 : 5798042 : if (!template_parm_natural_p (arg, parm)
3232 : 5798042 : && abi_check (19))
3233 : 8396 : write_template_param_decl (parm);
3234 : : }
3235 : 395135848 : write_template_arg (arg);
3236 : : }
3237 : 221979636 : if (implicit_parm_scope)
3238 : 472 : --G.parm_depth;
3239 : :
3240 : 221979636 : write_tparms_constraints (constraints);
3241 : :
3242 : 221979636 : write_char ('E');
3243 : 221979636 : }
3244 : :
3245 : : /* Write out the
3246 : : <unqualified-name>
3247 : : <unqualified-name> <template-args>
3248 : : part of SCOPE_REF or COMPONENT_REF mangling. */
3249 : :
3250 : : static void
3251 : 272363 : write_member_name (tree member)
3252 : : {
3253 : 272363 : if (identifier_p (member))
3254 : : {
3255 : 239969 : if (IDENTIFIER_ANY_OP_P (member))
3256 : : {
3257 : 7345 : if (abi_check (11))
3258 : 7321 : write_string ("on");
3259 : : }
3260 : 239969 : write_unqualified_id (member);
3261 : : }
3262 : 32394 : else if (DECL_P (member))
3263 : : {
3264 : 811 : if (ANON_AGGR_TYPE_P (TREE_TYPE (member)))
3265 : : ;
3266 : 805 : else if (DECL_OVERLOADED_OPERATOR_P (member))
3267 : : {
3268 : 18 : if (abi_check (16))
3269 : 9 : write_string ("on");
3270 : : }
3271 : 811 : write_unqualified_name (member);
3272 : : }
3273 : 31583 : else if (TREE_CODE (member) == TEMPLATE_ID_EXPR)
3274 : : {
3275 : 416 : tree name = TREE_OPERAND (member, 0);
3276 : 416 : name = OVL_FIRST (name);
3277 : 416 : write_member_name (name);
3278 : 416 : write_template_args (TREE_OPERAND (member, 1));
3279 : : }
3280 : : else
3281 : 31167 : write_expression (member);
3282 : 272363 : }
3283 : :
3284 : : /* EXPR is a base COMPONENT_REF; write the minimized base conversion path for
3285 : : converting to BASE, or just the conversion of EXPR if BASE is null.
3286 : :
3287 : : "Given a fully explicit base path P := C_n -> ... -> C_0, the minimized base
3288 : : path Min(P) is defined as follows: let C_i be the last element for which the
3289 : : conversion to C_0 is unambiguous; if that element is C_n, the minimized path
3290 : : is C_n -> C_0; otherwise, the minimized path is Min(C_n -> ... -> C_i) ->
3291 : : C_0."
3292 : :
3293 : : We mangle the conversion to C_i if it's different from C_n. */
3294 : :
3295 : : static bool
3296 : 51723 : write_base_ref (tree expr, tree base = NULL_TREE)
3297 : : {
3298 : 51723 : if (TREE_CODE (expr) != COMPONENT_REF)
3299 : : return false;
3300 : :
3301 : 51717 : tree field = TREE_OPERAND (expr, 1);
3302 : :
3303 : 51717 : if (TREE_CODE (field) != FIELD_DECL || !DECL_FIELD_IS_BASE (field))
3304 : : return false;
3305 : :
3306 : 18 : tree object = TREE_OPERAND (expr, 0);
3307 : :
3308 : 18 : tree binfo = NULL_TREE;
3309 : 18 : if (base)
3310 : : {
3311 : 9 : tree cur = TREE_TYPE (object);
3312 : 9 : binfo = lookup_base (cur, base, ba_unique, NULL, tf_none);
3313 : : }
3314 : : else
3315 : : /* We're at the end of the base conversion chain, so it can't be
3316 : : ambiguous. */
3317 : 9 : base = TREE_TYPE (field);
3318 : :
3319 : 18 : if (binfo == error_mark_node)
3320 : : {
3321 : : /* cur->base is ambiguous, so make the conversion to
3322 : : last explicit, expressed as a cast (last&)object. */
3323 : 3 : tree last = TREE_TYPE (expr);
3324 : 3 : write_string (OVL_OP_INFO (false, CAST_EXPR)->mangled_name);
3325 : 3 : write_type (build_reference_type (last));
3326 : 3 : write_expression (object);
3327 : : }
3328 : 15 : else if (write_base_ref (object, base))
3329 : : /* cur->base is unambiguous, but we had another base conversion
3330 : : underneath and wrote it out. */;
3331 : : else
3332 : : /* No more base conversions, just write out the object. */
3333 : 6 : write_expression (object);
3334 : :
3335 : : return true;
3336 : : }
3337 : :
3338 : : /* The number of elements spanned by a RANGE_EXPR. */
3339 : :
3340 : : unsigned HOST_WIDE_INT
3341 : 9 : range_expr_nelts (tree expr)
3342 : : {
3343 : 9 : tree lo = TREE_OPERAND (expr, 0);
3344 : 9 : tree hi = TREE_OPERAND (expr, 1);
3345 : 9 : return tree_to_uhwi (hi) - tree_to_uhwi (lo) + 1;
3346 : : }
3347 : :
3348 : : /* <expression> ::= <unary operator-name> <expression>
3349 : : ::= <binary operator-name> <expression> <expression>
3350 : : ::= <expr-primary>
3351 : :
3352 : : <expr-primary> ::= <template-param>
3353 : : ::= L <type> <value number> E # literal
3354 : : ::= L <mangled-name> E # external name
3355 : : ::= st <type> # sizeof
3356 : : ::= sr <type> <unqualified-name> # dependent name
3357 : : ::= sr <type> <unqualified-name> <template-args> */
3358 : :
3359 : : static void
3360 : 3058053 : write_expression (tree expr)
3361 : : {
3362 : 3150955 : enum tree_code code = TREE_CODE (expr);
3363 : :
3364 : 3150955 : if (TREE_CODE (expr) == TARGET_EXPR)
3365 : : {
3366 : 0 : expr = TARGET_EXPR_INITIAL (expr);
3367 : 0 : code = TREE_CODE (expr);
3368 : : }
3369 : :
3370 : : /* Skip NOP_EXPR and CONVERT_EXPR. They can occur when (say) a pointer
3371 : : argument is converted (via qualification conversions) to another type. */
3372 : 3288004 : while (CONVERT_EXPR_CODE_P (code)
3373 : 3255314 : || code == IMPLICIT_CONV_EXPR
3374 : 3255282 : || location_wrapper_p (expr)
3375 : : /* Parentheses aren't mangled. */
3376 : 3150967 : || code == PAREN_EXPR
3377 : 3150967 : || code == NON_LVALUE_EXPR
3378 : 6438971 : || (code == VIEW_CONVERT_EXPR
3379 : 12 : && TREE_CODE (TREE_OPERAND (expr, 0)) == TEMPLATE_PARM_INDEX))
3380 : : {
3381 : 137049 : expr = TREE_OPERAND (expr, 0);
3382 : 137049 : code = TREE_CODE (expr);
3383 : : }
3384 : :
3385 : 3150955 : if (code == BASELINK
3386 : 3150955 : && (!type_unknown_p (expr)
3387 : 139131 : || !BASELINK_QUALIFIED_P (expr)))
3388 : : {
3389 : 139124 : expr = BASELINK_FUNCTIONS (expr);
3390 : 139124 : code = TREE_CODE (expr);
3391 : : }
3392 : :
3393 : : /* Handle pointers-to-members by making them look like expression
3394 : : nodes. */
3395 : 3150955 : if (code == PTRMEM_CST)
3396 : : {
3397 : 6606 : expr = build_nt (ADDR_EXPR,
3398 : : build_qualified_name (/*type=*/NULL_TREE,
3399 : 3303 : PTRMEM_CST_CLASS (expr),
3400 : 3303 : PTRMEM_CST_MEMBER (expr),
3401 : : /*template_p=*/false));
3402 : 3303 : code = TREE_CODE (expr);
3403 : : }
3404 : :
3405 : : /* Handle template parameters. */
3406 : 3150955 : if (code == TEMPLATE_TYPE_PARM
3407 : 3150955 : || code == TEMPLATE_TEMPLATE_PARM
3408 : 3150955 : || code == BOUND_TEMPLATE_TEMPLATE_PARM
3409 : 3148282 : || code == TEMPLATE_PARM_INDEX)
3410 : 398636 : write_template_param (expr);
3411 : : /* Handle literals. */
3412 : 2752319 : else if (TREE_CODE_CLASS (code) == tcc_constant
3413 : 2692910 : || code == CONST_DECL)
3414 : 64884 : write_template_arg_literal (expr);
3415 : 2687435 : else if (code == EXCESS_PRECISION_EXPR
3416 : 2687435 : && TREE_CODE (TREE_OPERAND (expr, 0)) == REAL_CST)
3417 : 0 : write_template_arg_literal (fold_convert (TREE_TYPE (expr),
3418 : : TREE_OPERAND (expr, 0)));
3419 : 2687435 : else if (code == PARM_DECL && DECL_ARTIFICIAL (expr))
3420 : : {
3421 : 31755 : gcc_assert (id_equal (DECL_NAME (expr), "this"));
3422 : 31755 : write_string ("fpT");
3423 : : }
3424 : 2655680 : else if (code == PARM_DECL)
3425 : : {
3426 : : /* A function parameter used in a late-specified return type. */
3427 : 68673 : int index = DECL_PARM_INDEX (expr);
3428 : 68673 : int level = DECL_PARM_LEVEL (expr);
3429 : 68673 : int delta = G.parm_depth - level + 1;
3430 : 68673 : gcc_assert (index >= 1);
3431 : 68673 : write_char ('f');
3432 : 68673 : if (delta != 0)
3433 : : {
3434 : 43310 : gcc_checking_assert (delta > 0);
3435 : 43310 : if (abi_check (5))
3436 : : {
3437 : : /* Let L be the number of function prototype scopes from the
3438 : : innermost one (in which the parameter reference occurs) up
3439 : : to (and including) the one containing the declaration of
3440 : : the referenced parameter. If the parameter declaration
3441 : : clause of the innermost function prototype scope has been
3442 : : completely seen, it is not counted (in that case -- which
3443 : : is perhaps the most common -- L can be zero). */
3444 : 43307 : write_char ('L');
3445 : 43307 : write_unsigned_number (delta - 1);
3446 : : }
3447 : : }
3448 : 68673 : write_char ('p');
3449 : 68673 : write_compact_number (index - 1);
3450 : : }
3451 : 2587007 : else if (DECL_P (expr))
3452 : : {
3453 : 100114 : write_char ('L');
3454 : 100114 : write_mangled_name (expr, false);
3455 : 100114 : write_char ('E');
3456 : : }
3457 : 2486893 : else if (TREE_CODE (expr) == SIZEOF_EXPR)
3458 : : {
3459 : 3962 : tree op = TREE_OPERAND (expr, 0);
3460 : :
3461 : 3962 : if (PACK_EXPANSION_P (op))
3462 : : {
3463 : 2786 : sizeof_pack:
3464 : 2789 : if (abi_check (11))
3465 : : {
3466 : : /* sZ rather than szDp. */
3467 : 2780 : write_string ("sZ");
3468 : 2780 : write_expression (PACK_EXPANSION_PATTERN (op));
3469 : 2780 : return;
3470 : : }
3471 : : }
3472 : :
3473 : 1185 : if (SIZEOF_EXPR_TYPE_P (expr))
3474 : : {
3475 : 0 : write_string ("st");
3476 : 0 : write_type (TREE_TYPE (op));
3477 : : }
3478 : 1185 : else if (ARGUMENT_PACK_P (op))
3479 : : {
3480 : 15 : tree args = ARGUMENT_PACK_ARGS (op);
3481 : 15 : int length = TREE_VEC_LENGTH (args);
3482 : 15 : if (abi_check (10))
3483 : : {
3484 : : /* Before v19 we wrongly mangled all single pack expansions with
3485 : : sZ, but now only for expressions, as types ICEd (95298). */
3486 : 12 : if (length == 1)
3487 : : {
3488 : 9 : tree arg = TREE_VEC_ELT (args, 0);
3489 : 9 : if (TREE_CODE (arg) == EXPR_PACK_EXPANSION
3490 : 9 : && !abi_check (19))
3491 : : {
3492 : 3 : op = arg;
3493 : 3 : goto sizeof_pack;
3494 : : }
3495 : : }
3496 : :
3497 : : /* sP <template-arg>* E # sizeof...(T), size of a captured
3498 : : template parameter pack from an alias template */
3499 : 9 : write_string ("sP");
3500 : 24 : for (int i = 0; i < length; ++i)
3501 : 15 : write_template_arg (TREE_VEC_ELT (args, i));
3502 : 9 : write_char ('E');
3503 : : }
3504 : : else
3505 : : {
3506 : : /* In GCC 5 we represented this sizeof wrong, with the effect
3507 : : that we mangled it as the last element of the pack. */
3508 : 3 : tree arg = TREE_VEC_ELT (args, length-1);
3509 : 3 : if (TYPE_P (op))
3510 : : {
3511 : 3 : write_string ("st");
3512 : 3 : write_type (arg);
3513 : : }
3514 : : else
3515 : : {
3516 : 0 : write_string ("sz");
3517 : 0 : write_expression (arg);
3518 : : }
3519 : : }
3520 : : }
3521 : 1170 : else if (TYPE_P (TREE_OPERAND (expr, 0)))
3522 : : {
3523 : 1056 : write_string ("st");
3524 : 1056 : write_type (TREE_OPERAND (expr, 0));
3525 : : }
3526 : : else
3527 : 114 : goto normal_expr;
3528 : : }
3529 : 2482931 : else if (TREE_CODE (expr) == ALIGNOF_EXPR)
3530 : : {
3531 : 36 : if (!ALIGNOF_EXPR_STD_P (expr))
3532 : : {
3533 : 24 : if (abi_check (16))
3534 : : {
3535 : : /* We used to mangle __alignof__ like alignof. */
3536 : 12 : write_string ("u11__alignof__");
3537 : 12 : write_template_arg (TREE_OPERAND (expr, 0));
3538 : 12 : write_char ('E');
3539 : 12 : return;
3540 : : }
3541 : : }
3542 : 24 : if (TYPE_P (TREE_OPERAND (expr, 0)))
3543 : : {
3544 : 12 : write_string ("at");
3545 : 12 : write_type (TREE_OPERAND (expr, 0));
3546 : : }
3547 : : else
3548 : 12 : goto normal_expr;
3549 : : }
3550 : 2482895 : else if (code == SCOPE_REF
3551 : 2482895 : || code == BASELINK)
3552 : : {
3553 : 223518 : tree scope, member;
3554 : 223518 : if (code == SCOPE_REF)
3555 : : {
3556 : 223485 : scope = TREE_OPERAND (expr, 0);
3557 : 223485 : member = TREE_OPERAND (expr, 1);
3558 : 223485 : if (BASELINK_P (member))
3559 : 21 : member = BASELINK_FUNCTIONS (member);
3560 : : }
3561 : : else
3562 : : {
3563 : 33 : scope = BINFO_TYPE (BASELINK_ACCESS_BINFO (expr));
3564 : 33 : member = BASELINK_FUNCTIONS (expr);
3565 : : }
3566 : :
3567 : : /* If the MEMBER is a real declaration, then the qualifying
3568 : : scope was not dependent. Ideally, we would not have a
3569 : : SCOPE_REF in those cases, but sometimes we do. If the second
3570 : : argument is a DECL, then the name must not have been
3571 : : dependent. */
3572 : 223518 : if (DECL_P (member))
3573 : : write_expression (member);
3574 : : else
3575 : : {
3576 : 220041 : gcc_assert (code != BASELINK || BASELINK_QUALIFIED_P (expr));
3577 : 220008 : write_string ("sr");
3578 : 220008 : write_type (scope);
3579 : 220008 : write_member_name (member);
3580 : : }
3581 : : }
3582 : 2259377 : else if (INDIRECT_REF_P (expr)
3583 : 84782 : && TREE_TYPE (TREE_OPERAND (expr, 0))
3584 : 2343060 : && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (expr, 0))))
3585 : : {
3586 : 51020 : write_expression (TREE_OPERAND (expr, 0));
3587 : : }
3588 : 2208357 : else if (identifier_p (expr))
3589 : : {
3590 : : /* An operator name appearing as a dependent name needs to be
3591 : : specially marked to disambiguate between a use of the operator
3592 : : name and a use of the operator in an expression. */
3593 : 74997 : if (IDENTIFIER_ANY_OP_P (expr))
3594 : 4 : write_string ("on");
3595 : 74997 : write_unqualified_id (expr);
3596 : : }
3597 : 2133360 : else if (TREE_CODE (expr) == TEMPLATE_ID_EXPR)
3598 : : {
3599 : 906283 : tree fn = TREE_OPERAND (expr, 0);
3600 : 1163021 : if (!identifier_p (fn))
3601 : 906280 : fn = OVL_NAME (fn);
3602 : 906283 : if (IDENTIFIER_ANY_OP_P (fn))
3603 : 3 : write_string ("on");
3604 : 906283 : write_unqualified_id (fn);
3605 : 906283 : write_template_args (TREE_OPERAND (expr, 1));
3606 : : }
3607 : 1227077 : else if (TREE_CODE (expr) == MODOP_EXPR)
3608 : : {
3609 : 3 : enum tree_code subop = TREE_CODE (TREE_OPERAND (expr, 1));
3610 : 3 : const char *name = OVL_OP_INFO (true, subop)->mangled_name;
3611 : :
3612 : 3 : write_string (name);
3613 : 3 : write_expression (TREE_OPERAND (expr, 0));
3614 : 3 : write_expression (TREE_OPERAND (expr, 2));
3615 : : }
3616 : 1227074 : else if (code == NEW_EXPR || code == VEC_NEW_EXPR)
3617 : : {
3618 : : /* ::= [gs] nw <expression>* _ <type> E
3619 : : ::= [gs] nw <expression>* _ <type> <initializer>
3620 : : ::= [gs] na <expression>* _ <type> E
3621 : : ::= [gs] na <expression>* _ <type> <initializer>
3622 : : <initializer> ::= pi <expression>* E */
3623 : 33505 : tree placement = TREE_OPERAND (expr, 0);
3624 : 33505 : tree type = TREE_OPERAND (expr, 1);
3625 : 33505 : tree nelts = TREE_OPERAND (expr, 2);
3626 : 33505 : tree init = TREE_OPERAND (expr, 3);
3627 : 33505 : tree t;
3628 : :
3629 : 33505 : gcc_assert (code == NEW_EXPR);
3630 : 33505 : if (TREE_OPERAND (expr, 2))
3631 : 12 : code = VEC_NEW_EXPR;
3632 : :
3633 : 33505 : if (NEW_EXPR_USE_GLOBAL (expr))
3634 : 33480 : write_string ("gs");
3635 : :
3636 : 33505 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3637 : :
3638 : 66985 : for (t = placement; t; t = TREE_CHAIN (t))
3639 : 33480 : write_expression (TREE_VALUE (t));
3640 : :
3641 : 33505 : write_char ('_');
3642 : :
3643 : 33505 : if (nelts)
3644 : : {
3645 : 12 : ++processing_template_decl;
3646 : : /* Avoid compute_array_index_type complaints about
3647 : : non-constant nelts. */
3648 : 12 : tree max = cp_build_binary_op (input_location, MINUS_EXPR,
3649 : : fold_convert (sizetype, nelts),
3650 : : size_one_node,
3651 : : tf_warning_or_error);
3652 : 12 : max = maybe_constant_value (max);
3653 : 12 : tree domain = build_index_type (max);
3654 : 12 : type = build_cplus_array_type (type, domain);
3655 : 12 : --processing_template_decl;
3656 : : }
3657 : 33505 : write_type (type);
3658 : :
3659 : 33493 : if (init && TREE_CODE (init) == TREE_LIST
3660 : 66992 : && DIRECT_LIST_INIT_P (TREE_VALUE (init)))
3661 : : write_expression (TREE_VALUE (init));
3662 : : else
3663 : : {
3664 : 33502 : if (init)
3665 : 33490 : write_string ("pi");
3666 : 33490 : if (init && init != void_node)
3667 : 66968 : for (t = init; t; t = TREE_CHAIN (t))
3668 : 33484 : write_expression (TREE_VALUE (t));
3669 : 33502 : write_char ('E');
3670 : : }
3671 : : }
3672 : : else if (code == DELETE_EXPR || code == VEC_DELETE_EXPR)
3673 : : {
3674 : 12 : gcc_assert (code == DELETE_EXPR);
3675 : 12 : if (DELETE_EXPR_USE_VEC (expr))
3676 : 6 : code = VEC_DELETE_EXPR;
3677 : :
3678 : 12 : if (DELETE_EXPR_USE_GLOBAL (expr))
3679 : 6 : write_string ("gs");
3680 : :
3681 : 12 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3682 : :
3683 : 12 : write_expression (TREE_OPERAND (expr, 0));
3684 : : }
3685 : : else if (code == THROW_EXPR)
3686 : : {
3687 : 7 : tree op = TREE_OPERAND (expr, 0);
3688 : 7 : if (op)
3689 : : {
3690 : 4 : write_string ("tw");
3691 : 4 : write_expression (op);
3692 : : }
3693 : : else
3694 : 3 : write_string ("tr");
3695 : : }
3696 : : else if (code == NOEXCEPT_EXPR)
3697 : : {
3698 : 6 : write_string ("nx");
3699 : 6 : write_expression (TREE_OPERAND (expr, 0));
3700 : : }
3701 : : else if (code == CONSTRUCTOR)
3702 : : {
3703 : 8211 : bool braced_init = BRACE_ENCLOSED_INITIALIZER_P (expr);
3704 : 8211 : tree etype = TREE_TYPE (expr);
3705 : :
3706 : 8211 : if (braced_init)
3707 : 77 : write_string ("il");
3708 : : else
3709 : : {
3710 : 8134 : write_string ("tl");
3711 : 8134 : write_type (etype);
3712 : : }
3713 : :
3714 : : /* If this is an undigested initializer, mangle it as written.
3715 : : COMPOUND_LITERAL_P doesn't actually distinguish between digested and
3716 : : undigested braced casts, but it should work to use it to distinguish
3717 : : between braced casts in a template signature (undigested) and template
3718 : : parm object values (digested), and all CONSTRUCTORS that get here
3719 : : should be one of those two cases. */
3720 : 8211 : bool undigested = braced_init || COMPOUND_LITERAL_P (expr);
3721 : 7890 : if (undigested || !zero_init_expr_p (expr))
3722 : : {
3723 : : /* Convert braced initializer lists to STRING_CSTs so that
3724 : : A<"Foo"> mangles the same as A<{'F', 'o', 'o', 0}> while
3725 : : still using the latter mangling for strings that
3726 : : originated as braced initializer lists. */
3727 : 1792 : expr = braced_lists_to_strings (etype, expr);
3728 : :
3729 : 1792 : if (TREE_CODE (expr) == CONSTRUCTOR)
3730 : : {
3731 : 1792 : vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (expr);
3732 : 1792 : unsigned last_nonzero = UINT_MAX;
3733 : 1792 : constructor_elt *ce;
3734 : :
3735 : 1792 : if (!undigested)
3736 : 4954 : for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
3737 : 3483 : if ((TREE_CODE (etype) == UNION_TYPE
3738 : 33 : && ce->index != first_field (etype))
3739 : 3507 : || !zero_init_expr_p (ce->value))
3740 : : last_nonzero = i;
3741 : :
3742 : 1792 : if (undigested || last_nonzero != UINT_MAX)
3743 : 5012 : for (HOST_WIDE_INT i = 0; vec_safe_iterate (elts, i, &ce); ++i)
3744 : : {
3745 : 3443 : if (i > last_nonzero)
3746 : : break;
3747 : 3220 : if (!undigested && TREE_CODE (etype) == UNION_TYPE)
3748 : : {
3749 : : /* Express the active member as a designator. */
3750 : 33 : write_string ("di");
3751 : 33 : write_unqualified_name (ce->index);
3752 : : }
3753 : 3220 : unsigned reps = 1;
3754 : 3220 : if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
3755 : 6 : reps = range_expr_nelts (ce->index);
3756 : 3220 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
3757 : : {
3758 : 30 : gcc_assert (reps == 1);
3759 : 30 : unsigned int len = RAW_DATA_LENGTH (ce->value);
3760 : : /* If this is the last non-zero element, skip
3761 : : zeros at the end. */
3762 : 30 : if (i == last_nonzero)
3763 : 282 : while (len)
3764 : : {
3765 : 282 : if (RAW_DATA_POINTER (ce->value)[len - 1])
3766 : : break;
3767 : : --len;
3768 : : }
3769 : 30 : tree valtype = TREE_TYPE (ce->value);
3770 : 3906 : for (unsigned int i = 0; i < len; ++i)
3771 : : {
3772 : 3876 : write_char ('L');
3773 : 3876 : write_type (valtype);
3774 : 3876 : unsigned HOST_WIDE_INT v;
3775 : 3876 : if (!TYPE_UNSIGNED (valtype)
3776 : 780 : && TYPE_PRECISION (valtype) == BITS_PER_UNIT
3777 : 4656 : && RAW_DATA_SCHAR_ELT (ce->value, i) < 0)
3778 : : {
3779 : 0 : write_char ('n');
3780 : 0 : v = -RAW_DATA_SCHAR_ELT (ce->value, i);
3781 : : }
3782 : : else
3783 : 3876 : v = RAW_DATA_UCHAR_ELT (ce->value, i);
3784 : 3876 : write_unsigned_number (v);
3785 : 3876 : write_char ('E');
3786 : : }
3787 : : }
3788 : : else
3789 : 6389 : for (unsigned j = 0; j < reps; ++j)
3790 : 3199 : write_expression (ce->value);
3791 : : }
3792 : : }
3793 : : else
3794 : : {
3795 : 0 : gcc_assert (TREE_CODE (expr) == STRING_CST);
3796 : 0 : write_expression (expr);
3797 : : }
3798 : : }
3799 : 8211 : write_char ('E');
3800 : : }
3801 : : else if (code == LAMBDA_EXPR)
3802 : : {
3803 : : /* [temp.over.link] Two lambda-expressions are never considered
3804 : : equivalent.
3805 : :
3806 : : So just use the closure type mangling. */
3807 : 34 : write_char ('L');
3808 : 34 : write_type (LAMBDA_EXPR_CLOSURE (expr));
3809 : 34 : write_char ('E');
3810 : : }
3811 : : else if (code == REQUIRES_EXPR)
3812 : 97150 : write_requires_expr (expr);
3813 : 1088149 : else if (dependent_name (expr))
3814 : : {
3815 : 31151 : tree name = dependent_name (expr);
3816 : 31151 : if (IDENTIFIER_ANY_OP_P (name))
3817 : : {
3818 : 9 : if (abi_check (16))
3819 : 6 : write_string ("on");
3820 : : }
3821 : 31151 : write_unqualified_id (name);
3822 : : }
3823 : : else
3824 : : {
3825 : 1056998 : normal_expr:
3826 : 1057124 : int i, len;
3827 : 1057124 : const char *name;
3828 : :
3829 : : /* When we bind a variable or function to a non-type template
3830 : : argument with reference type, we create an ADDR_EXPR to show
3831 : : the fact that the entity's address has been taken. But, we
3832 : : don't actually want to output a mangling code for the `&'. */
3833 : 1057124 : if (TREE_CODE (expr) == ADDR_EXPR
3834 : 3924 : && TREE_TYPE (expr)
3835 : 1057745 : && TYPE_REF_P (TREE_TYPE (expr)))
3836 : : {
3837 : 0 : expr = TREE_OPERAND (expr, 0);
3838 : 0 : if (DECL_P (expr))
3839 : : {
3840 : : write_expression (expr);
3841 : : return;
3842 : : }
3843 : :
3844 : 0 : code = TREE_CODE (expr);
3845 : : }
3846 : :
3847 : 1057124 : if (code == COMPONENT_REF)
3848 : : {
3849 : 51948 : tree ob = TREE_OPERAND (expr, 0);
3850 : :
3851 : 51948 : if (TREE_CODE (ob) == ARROW_EXPR)
3852 : : {
3853 : 240 : write_string (OVL_OP_INFO (false, code)->mangled_name);
3854 : 240 : ob = TREE_OPERAND (ob, 0);
3855 : 240 : write_expression (ob);
3856 : : }
3857 : 51708 : else if (write_base_ref (expr))
3858 : : return;
3859 : 51699 : else if (!is_dummy_object (ob))
3860 : : {
3861 : 51696 : write_string ("dt");
3862 : 51696 : write_expression (ob);
3863 : : }
3864 : : /* else, for a non-static data member with no associated object (in
3865 : : unevaluated context), use the unresolved-name mangling. */
3866 : :
3867 : 51939 : write_member_name (TREE_OPERAND (expr, 1));
3868 : 51939 : return;
3869 : : }
3870 : :
3871 : : /* If it wasn't any of those, recursively expand the expression. */
3872 : 1005176 : name = OVL_OP_INFO (false, code)->mangled_name;
3873 : :
3874 : : /* We used to mangle const_cast and static_cast like a C cast. */
3875 : 1005176 : if (code == CONST_CAST_EXPR
3876 : 1005176 : || code == STATIC_CAST_EXPR)
3877 : : {
3878 : 421 : if (!abi_check (6))
3879 : 15 : name = OVL_OP_INFO (false, CAST_EXPR)->mangled_name;
3880 : : }
3881 : :
3882 : 1005176 : if (name == NULL)
3883 : : {
3884 : 5 : switch (code)
3885 : : {
3886 : 3 : case TRAIT_EXPR:
3887 : 3 : error ("use of built-in trait %qE in function signature; "
3888 : : "use library traits instead", expr);
3889 : 3 : break;
3890 : :
3891 : 2 : default:
3892 : 2 : sorry ("mangling %C", code);
3893 : 2 : break;
3894 : : }
3895 : 5 : return;
3896 : : }
3897 : : else
3898 : 1005171 : write_string (name);
3899 : :
3900 : 1005171 : switch (code)
3901 : : {
3902 : 457827 : case CALL_EXPR:
3903 : 457827 : {
3904 : 457827 : tree fn = CALL_EXPR_FN (expr);
3905 : :
3906 : 457827 : if (TREE_CODE (fn) == ADDR_EXPR)
3907 : 0 : fn = TREE_OPERAND (fn, 0);
3908 : :
3909 : : /* Mangle a dependent name as the name, not whatever happens to
3910 : : be the first function in the overload set. */
3911 : 457594 : if (OVL_P (fn)
3912 : 532792 : && type_dependent_expression_p_push (expr))
3913 : 74994 : fn = OVL_NAME (fn);
3914 : :
3915 : 457827 : write_expression (fn);
3916 : : }
3917 : :
3918 : 1071801 : for (i = 0; i < call_expr_nargs (expr); ++i)
3919 : 156147 : write_expression (CALL_EXPR_ARG (expr, i));
3920 : 457827 : write_char ('E');
3921 : 457827 : break;
3922 : :
3923 : 35270 : case CAST_EXPR:
3924 : 35270 : write_type (TREE_TYPE (expr));
3925 : 35270 : if (list_length (TREE_OPERAND (expr, 0)) == 1)
3926 : 35137 : write_expression (TREE_VALUE (TREE_OPERAND (expr, 0)));
3927 : : else
3928 : : {
3929 : 133 : tree args = TREE_OPERAND (expr, 0);
3930 : 133 : write_char ('_');
3931 : 145 : for (; args; args = TREE_CHAIN (args))
3932 : 12 : write_expression (TREE_VALUE (args));
3933 : 133 : write_char ('E');
3934 : : }
3935 : : break;
3936 : :
3937 : 427 : case DYNAMIC_CAST_EXPR:
3938 : 427 : case REINTERPRET_CAST_EXPR:
3939 : 427 : case STATIC_CAST_EXPR:
3940 : 427 : case CONST_CAST_EXPR:
3941 : 427 : write_type (TREE_TYPE (expr));
3942 : 427 : write_expression (TREE_OPERAND (expr, 0));
3943 : 427 : break;
3944 : :
3945 : 23 : case PREINCREMENT_EXPR:
3946 : 23 : case PREDECREMENT_EXPR:
3947 : 23 : if (abi_check (6))
3948 : 14 : write_char ('_');
3949 : : /* Fall through. */
3950 : :
3951 : 511647 : default:
3952 : : /* In the middle-end, some expressions have more operands than
3953 : : they do in templates (and mangling). */
3954 : 511647 : len = cp_tree_operand_length (expr);
3955 : :
3956 : 1328732 : for (i = 0; i < len; ++i)
3957 : : {
3958 : 817085 : tree operand = TREE_OPERAND (expr, i);
3959 : : /* As a GNU extension, the middle operand of a
3960 : : conditional may be omitted. Since expression
3961 : : manglings are supposed to represent the input token
3962 : : stream, there's no good way to mangle such an
3963 : : expression without extending the C++ ABI. */
3964 : 817085 : if (code == COND_EXPR && i == 1 && !operand)
3965 : : {
3966 : 3 : error ("omitted middle operand to %<?:%> operand "
3967 : : "cannot be mangled");
3968 : 3 : continue;
3969 : : }
3970 : 817082 : else if (FOLD_EXPR_P (expr))
3971 : : {
3972 : : /* The first 'operand' of a fold-expression is the operator
3973 : : that it folds over. */
3974 : 74938 : if (i == 0)
3975 : : {
3976 : 37416 : int fcode = TREE_INT_CST_LOW (operand);
3977 : 37416 : write_string (OVL_OP_INFO (false, fcode)->mangled_name);
3978 : 37416 : continue;
3979 : 37416 : }
3980 : 37522 : else if (code == BINARY_LEFT_FOLD_EXPR)
3981 : : {
3982 : : /* The order of operands of the binary left and right
3983 : : folds is the same, but we want to mangle them in
3984 : : lexical order, i.e. non-pack first. */
3985 : 206 : if (i == 1)
3986 : 103 : operand = FOLD_EXPR_INIT (expr);
3987 : : else
3988 : 103 : operand = FOLD_EXPR_PACK (expr);
3989 : : }
3990 : 37522 : if (PACK_EXPANSION_P (operand))
3991 : 37416 : operand = PACK_EXPANSION_PATTERN (operand);
3992 : : }
3993 : 779666 : write_expression (operand);
3994 : : }
3995 : : }
3996 : : }
3997 : : }
3998 : :
3999 : : /* Literal subcase of non-terminal <template-arg>.
4000 : :
4001 : : "Literal arguments, e.g. "A<42L>", are encoded with their type
4002 : : and value. Negative integer values are preceded with "n"; for
4003 : : example, "A<-42L>" becomes "1AILln42EE". The bool value false is
4004 : : encoded as 0, true as 1." */
4005 : :
4006 : : static void
4007 : 45606123 : write_template_arg_literal (const tree value)
4008 : : {
4009 : 45606123 : if (TREE_CODE (value) == STRING_CST)
4010 : : /* Temporarily mangle strings as braced initializer lists. */
4011 : 1071 : write_string ("tl");
4012 : : else
4013 : 45605052 : write_char ('L');
4014 : :
4015 : 45606123 : tree valtype = TREE_TYPE (value);
4016 : 45606123 : write_type (valtype);
4017 : :
4018 : : /* Write a null member pointer value as (type)0, regardless of its
4019 : : real representation. */
4020 : 45606123 : if (null_member_pointer_value_p (value))
4021 : 118 : write_integer_cst (integer_zero_node);
4022 : : else
4023 : 45606005 : switch (TREE_CODE (value))
4024 : : {
4025 : 5475 : case CONST_DECL:
4026 : 5475 : write_integer_cst (DECL_INITIAL (value));
4027 : 5475 : break;
4028 : :
4029 : 45599348 : case INTEGER_CST:
4030 : 45599348 : gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node)
4031 : : || integer_zerop (value) || integer_onep (value));
4032 : 45599348 : if (!(abi_version_at_least (14)
4033 : 45519084 : && NULLPTR_TYPE_P (TREE_TYPE (value))))
4034 : 45599297 : write_integer_cst (value);
4035 : : break;
4036 : :
4037 : 105 : case REAL_CST:
4038 : 105 : write_real_cst (value);
4039 : 105 : break;
4040 : :
4041 : 6 : case COMPLEX_CST:
4042 : 6 : if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST
4043 : 6 : && TREE_CODE (TREE_IMAGPART (value)) == INTEGER_CST)
4044 : : {
4045 : 3 : write_integer_cst (TREE_REALPART (value));
4046 : 3 : write_char ('_');
4047 : 3 : write_integer_cst (TREE_IMAGPART (value));
4048 : : }
4049 : 3 : else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST
4050 : 3 : && TREE_CODE (TREE_IMAGPART (value)) == REAL_CST)
4051 : : {
4052 : 3 : write_real_cst (TREE_REALPART (value));
4053 : 3 : write_char ('_');
4054 : 3 : write_real_cst (TREE_IMAGPART (value));
4055 : : }
4056 : : else
4057 : 0 : gcc_unreachable ();
4058 : : break;
4059 : :
4060 : 1071 : case STRING_CST:
4061 : 1071 : {
4062 : : /* Mangle strings the same as braced initializer lists. */
4063 : 1071 : unsigned n = TREE_STRING_LENGTH (value);
4064 : 1071 : const char *str = TREE_STRING_POINTER (value);
4065 : :
4066 : : /* Count the number of trailing nuls and subtract them from
4067 : : STRSIZE because they don't need to be mangled. */
4068 : 2763 : for (const char *p = str + n - 1; ; --p)
4069 : : {
4070 : 2763 : if (*p || p == str)
4071 : : {
4072 : 1071 : n -= str + n - !!*p - p;
4073 : 1071 : break;
4074 : : }
4075 : : }
4076 : 1071 : tree eltype = TREE_TYPE (valtype);
4077 : 3208 : for (const char *p = str; n--; ++p)
4078 : : {
4079 : 2137 : write_char ('L');
4080 : 2137 : write_type (eltype);
4081 : 2137 : write_unsigned_number (*(const unsigned char*)p);
4082 : 2137 : write_string ("E");
4083 : : }
4084 : : break;
4085 : : }
4086 : :
4087 : 0 : default:
4088 : 0 : gcc_unreachable ();
4089 : : }
4090 : :
4091 : 45606123 : write_char ('E');
4092 : 45606123 : }
4093 : :
4094 : : /* Non-terminal <template-arg>.
4095 : :
4096 : : <template-arg> ::= <type> # type
4097 : : ::= L <type> </value/ number> E # literal
4098 : : ::= LZ <name> E # external name
4099 : : ::= X <expression> E # expression */
4100 : :
4101 : : static void
4102 : 403152917 : write_template_arg (tree node)
4103 : : {
4104 : 403152917 : enum tree_code code = TREE_CODE (node);
4105 : :
4106 : 403152917 : MANGLE_TRACE_TREE ("template-arg", node);
4107 : :
4108 : : /* A template template parameter's argument list contains TREE_LIST
4109 : : nodes of which the value field is the actual argument. */
4110 : 403152917 : if (code == TREE_LIST)
4111 : : {
4112 : 0 : node = TREE_VALUE (node);
4113 : : /* If it's a decl, deal with its type instead. */
4114 : 0 : if (DECL_P (node))
4115 : : {
4116 : 0 : node = TREE_TYPE (node);
4117 : 0 : code = TREE_CODE (node);
4118 : : }
4119 : : }
4120 : :
4121 : 403152917 : if (VAR_P (node) && DECL_NTTP_OBJECT_P (node))
4122 : : /* We want to mangle the argument, not the var we stored it in. */
4123 : 5716 : node = tparm_object_argument (node);
4124 : :
4125 : : /* Strip a conversion added by convert_nontype_argument. */
4126 : 403152917 : if (TREE_CODE (node) == IMPLICIT_CONV_EXPR)
4127 : 54 : node = TREE_OPERAND (node, 0);
4128 : 403152917 : if (REFERENCE_REF_P (node))
4129 : 256 : node = TREE_OPERAND (node, 0);
4130 : 403152917 : if (TREE_CODE (node) == NOP_EXPR
4131 : 403152917 : && TYPE_REF_P (TREE_TYPE (node)))
4132 : : {
4133 : : /* Template parameters can be of reference type. To maintain
4134 : : internal consistency, such arguments use a conversion from
4135 : : address of object to reference type. */
4136 : 256 : gcc_assert (TREE_CODE (TREE_OPERAND (node, 0)) == ADDR_EXPR);
4137 : 256 : node = TREE_OPERAND (TREE_OPERAND (node, 0), 0);
4138 : : }
4139 : :
4140 : 403152917 : if (TREE_CODE (node) == BASELINK
4141 : 403152917 : && !type_unknown_p (node))
4142 : : {
4143 : : /* Before v6 we wrongly wrapped a class-scope function in X/E. */
4144 : 21 : if (abi_check (6))
4145 : 15 : node = BASELINK_FUNCTIONS (node);
4146 : : }
4147 : :
4148 : 403152917 : if (ARGUMENT_PACK_P (node))
4149 : : {
4150 : : /* Expand the template argument pack. */
4151 : 6181810 : tree args = ARGUMENT_PACK_ARGS (node);
4152 : 6181810 : int i, length = TREE_VEC_LENGTH (args);
4153 : 6181810 : if (abi_check (6))
4154 : 6181792 : write_char ('J');
4155 : : else
4156 : 18 : write_char ('I');
4157 : 14198849 : for (i = 0; i < length; ++i)
4158 : 8017039 : write_template_arg (TREE_VEC_ELT (args, i));
4159 : 6181810 : write_char ('E');
4160 : : }
4161 : 396971107 : else if (TYPE_P (node))
4162 : 350556874 : write_type (node);
4163 : 46414233 : else if (code == TEMPLATE_DECL)
4164 : : /* A template appearing as a template arg is a template template arg. */
4165 : 292054 : write_template_template_arg (node);
4166 : 45544354 : else if ((TREE_CODE_CLASS (code) == tcc_constant && code != PTRMEM_CST)
4167 : 577825 : || code == CONST_DECL
4168 : 46703165 : || null_member_pointer_value_p (node))
4169 : 45541239 : write_template_arg_literal (node);
4170 : 580940 : else if (code == EXCESS_PRECISION_EXPR
4171 : 580940 : && TREE_CODE (TREE_OPERAND (node, 0)) == REAL_CST)
4172 : 0 : write_template_arg_literal (fold_convert (TREE_TYPE (node),
4173 : : TREE_OPERAND (node, 0)));
4174 : 580940 : else if (DECL_P (node))
4175 : : {
4176 : 280 : write_char ('L');
4177 : : /* Until ABI version 3, the underscore before the mangled name
4178 : : was incorrectly omitted. */
4179 : 280 : if (!abi_check (3))
4180 : 21 : write_char ('Z');
4181 : : else
4182 : 259 : write_string ("_Z");
4183 : 280 : write_encoding (node);
4184 : 280 : write_char ('E');
4185 : : }
4186 : : else
4187 : : {
4188 : : /* Template arguments may be expressions. */
4189 : 580660 : write_char ('X');
4190 : 580660 : write_expression (node);
4191 : 580660 : write_char ('E');
4192 : : }
4193 : 403152917 : }
4194 : :
4195 : : /* <template-template-arg>
4196 : : ::= <name>
4197 : : ::= <substitution> */
4198 : :
4199 : : static void
4200 : 292054 : write_template_template_arg (const tree decl)
4201 : : {
4202 : 292054 : MANGLE_TRACE_TREE ("template-template-arg", decl);
4203 : :
4204 : 292054 : if (find_substitution (decl))
4205 : : return;
4206 : 270903 : write_name (decl, /*ignore_local_scope=*/0);
4207 : 270903 : add_substitution (decl);
4208 : : }
4209 : :
4210 : :
4211 : : /* Non-terminal <array-type>. TYPE is an ARRAY_TYPE.
4212 : :
4213 : : <array-type> ::= A [</dimension/ number>] _ </element/ type>
4214 : : ::= A <expression> _ </element/ type>
4215 : :
4216 : : "Array types encode the dimension (number of elements) and the
4217 : : element type. For variable length arrays, the dimension (but not
4218 : : the '_' separator) is omitted."
4219 : : Note that for flexible array members, like for other arrays of
4220 : : unspecified size, the dimension is also omitted. */
4221 : :
4222 : : static void
4223 : 245782 : write_array_type (const tree type)
4224 : : {
4225 : 245782 : write_char ('A');
4226 : 245782 : if (TYPE_DOMAIN (type))
4227 : : {
4228 : 228760 : tree index_type;
4229 : :
4230 : 228760 : index_type = TYPE_DOMAIN (type);
4231 : : /* The INDEX_TYPE gives the upper and lower bounds of the array.
4232 : : It's null for flexible array members which have no upper bound
4233 : : (this is a change from GCC 5 and prior where such members were
4234 : : incorrectly mangled as zero-length arrays). */
4235 : 228760 : if (tree max = TYPE_MAX_VALUE (index_type))
4236 : : {
4237 : 228760 : if (TREE_CODE (max) == INTEGER_CST)
4238 : : {
4239 : : /* The ABI specifies that we should mangle the number of
4240 : : elements in the array, not the largest allowed index. */
4241 : 189133 : offset_int wmax = wi::to_offset (max) + 1;
4242 : : /* Truncate the result - this will mangle [0, SIZE_INT_MAX]
4243 : : number of elements as zero. */
4244 : 189133 : wmax = wi::zext (wmax, TYPE_PRECISION (TREE_TYPE (max)));
4245 : 189133 : gcc_assert (wi::fits_uhwi_p (wmax));
4246 : 189133 : write_unsigned_number (wmax.to_uhwi ());
4247 : : }
4248 : : else
4249 : : {
4250 : 39627 : gcc_checking_assert (TREE_CODE (max) == MINUS_EXPR
4251 : : && integer_onep (TREE_OPERAND (max, 1)));
4252 : 39627 : max = TREE_OPERAND (max, 0);
4253 : 39627 : write_expression (max);
4254 : : }
4255 : : }
4256 : : }
4257 : 245782 : write_char ('_');
4258 : 245782 : write_type (TREE_TYPE (type));
4259 : 245782 : }
4260 : :
4261 : : /* Non-terminal <pointer-to-member-type> for pointer-to-member
4262 : : variables. TYPE is a pointer-to-member POINTER_TYPE.
4263 : :
4264 : : <pointer-to-member-type> ::= M </class/ type> </member/ type> */
4265 : :
4266 : : static void
4267 : 291810 : write_pointer_to_member_type (const tree type)
4268 : : {
4269 : 291810 : write_char ('M');
4270 : 291810 : write_type (TYPE_PTRMEM_CLASS_TYPE (type));
4271 : 291810 : write_type (TYPE_PTRMEM_POINTED_TO_TYPE (type));
4272 : 291810 : }
4273 : :
4274 : : /* Non-terminal <template-param>. PARM is a TEMPLATE_TYPE_PARM,
4275 : : TEMPLATE_TEMPLATE_PARM, BOUND_TEMPLATE_TEMPLATE_PARM or a
4276 : : TEMPLATE_PARM_INDEX.
4277 : :
4278 : : <template-param> ::= T </parameter/ number> _ */
4279 : :
4280 : : static void
4281 : 20495985 : write_template_param (const tree parm)
4282 : : {
4283 : 20495985 : int parm_index;
4284 : 20495985 : int level;
4285 : :
4286 : 20495985 : MANGLE_TRACE_TREE ("template-parm", parm);
4287 : :
4288 : 20495985 : switch (TREE_CODE (parm))
4289 : : {
4290 : 20100022 : case TEMPLATE_TYPE_PARM:
4291 : 20100022 : case TEMPLATE_TEMPLATE_PARM:
4292 : 20100022 : case BOUND_TEMPLATE_TEMPLATE_PARM:
4293 : 20100022 : parm_index = TEMPLATE_TYPE_IDX (parm);
4294 : 20100022 : level = TEMPLATE_TYPE_LEVEL (parm);
4295 : 20100022 : break;
4296 : :
4297 : 395963 : case TEMPLATE_PARM_INDEX:
4298 : 395963 : parm_index = TEMPLATE_PARM_IDX (parm);
4299 : 395963 : level = TEMPLATE_PARM_LEVEL (parm);
4300 : 395963 : break;
4301 : :
4302 : 0 : default:
4303 : 0 : gcc_unreachable ();
4304 : : }
4305 : :
4306 : 20495985 : write_char ('T');
4307 : 20495985 : if (level > 1)
4308 : : {
4309 : 17052 : if (abi_check (19))
4310 : : {
4311 : 17046 : write_char ('L');
4312 : 17046 : write_compact_number (level - 1);
4313 : : }
4314 : : }
4315 : : /* NUMBER as it appears in the mangling is (-1)-indexed, with the
4316 : : earliest template param denoted by `_'. */
4317 : 20495985 : write_compact_number (parm_index);
4318 : 20495985 : }
4319 : :
4320 : : /* <template-template-param>
4321 : : ::= <template-param>
4322 : : ::= <substitution> */
4323 : :
4324 : : static void
4325 : 637 : write_template_template_param (const tree parm)
4326 : : {
4327 : 637 : tree templ = NULL_TREE;
4328 : :
4329 : : /* PARM, a TEMPLATE_TEMPLATE_PARM, is an instantiation of the
4330 : : template template parameter. The substitution candidate here is
4331 : : only the template. */
4332 : 637 : if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
4333 : : {
4334 : 535 : templ
4335 : 535 : = TI_TEMPLATE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (parm));
4336 : 535 : if (find_substitution (templ))
4337 : : return;
4338 : : }
4339 : :
4340 : : /* <template-param> encodes only the template parameter position,
4341 : : not its template arguments, which is fine here. */
4342 : 637 : write_template_param (parm);
4343 : 637 : if (templ)
4344 : 535 : add_substitution (templ);
4345 : : }
4346 : :
4347 : : /* Non-terminal <substitution>.
4348 : :
4349 : : <substitution> ::= S <seq-id> _
4350 : : ::= S_ */
4351 : :
4352 : : static void
4353 : 98059713 : write_substitution (const int seq_id)
4354 : : {
4355 : 98059713 : MANGLE_TRACE ("substitution", "");
4356 : :
4357 : 98059713 : write_char ('S');
4358 : 98059713 : if (seq_id > 0)
4359 : 86621258 : write_number (seq_id - 1, /*unsigned=*/1, 36);
4360 : 98059713 : write_char ('_');
4361 : 98059713 : }
4362 : :
4363 : : /* Start mangling ENTITY. */
4364 : :
4365 : : static inline void
4366 : 127645632 : start_mangling (const tree entity)
4367 : : {
4368 : 127645632 : G = {};
4369 : 127645632 : G.entity = entity;
4370 : 127645632 : obstack_free (&name_obstack, name_base);
4371 : 127645632 : mangle_obstack = &name_obstack;
4372 : 127645632 : name_base = obstack_alloc (&name_obstack, 0);
4373 : 127645632 : }
4374 : :
4375 : : /* Done with mangling. Release the data. */
4376 : :
4377 : : static void
4378 : 127645632 : finish_mangling_internal (void)
4379 : : {
4380 : : /* Clear all the substitutions. */
4381 : 127645632 : vec_safe_truncate (G.substitutions, 0);
4382 : :
4383 : 127645632 : if (G.mod)
4384 : 5829 : mangle_module_fini ();
4385 : :
4386 : : /* Null-terminate the string. */
4387 : 127645632 : write_char ('\0');
4388 : 127645632 : }
4389 : :
4390 : :
4391 : : /* Like finish_mangling_internal, but return the mangled string. */
4392 : :
4393 : : static inline const char *
4394 : 363017 : finish_mangling (void)
4395 : : {
4396 : 363017 : finish_mangling_internal ();
4397 : 363017 : return (const char *) obstack_finish (mangle_obstack);
4398 : : }
4399 : :
4400 : : /* Like finish_mangling_internal, but return an identifier. */
4401 : :
4402 : : static tree
4403 : 127282615 : finish_mangling_get_identifier (void)
4404 : : {
4405 : 127282615 : finish_mangling_internal ();
4406 : : /* Don't obstack_finish here, and the next start_mangling will
4407 : : remove the identifier. */
4408 : 127282615 : return get_identifier ((const char *) obstack_base (mangle_obstack));
4409 : : }
4410 : :
4411 : : /* Initialize data structures for mangling. */
4412 : :
4413 : : void
4414 : 93374 : init_mangle (void)
4415 : : {
4416 : 93374 : gcc_obstack_init (&name_obstack);
4417 : 93374 : name_base = obstack_alloc (&name_obstack, 0);
4418 : 93374 : vec_alloc (G.substitutions, 0);
4419 : :
4420 : : /* Cache these identifiers for quick comparison when checking for
4421 : : standard substitutions. */
4422 : 93374 : subst_identifiers[SUBID_ALLOCATOR] = get_identifier ("allocator");
4423 : 93374 : subst_identifiers[SUBID_BASIC_STRING] = get_identifier ("basic_string");
4424 : 93374 : subst_identifiers[SUBID_CHAR_TRAITS] = get_identifier ("char_traits");
4425 : 93374 : subst_identifiers[SUBID_BASIC_ISTREAM] = get_identifier ("basic_istream");
4426 : 93374 : subst_identifiers[SUBID_BASIC_OSTREAM] = get_identifier ("basic_ostream");
4427 : 93374 : subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream");
4428 : 93374 : }
4429 : :
4430 : : /* Generate a mangling for MODULE's global initializer fn. */
4431 : :
4432 : : tree
4433 : 1591 : mangle_module_global_init (int module)
4434 : : {
4435 : 1591 : start_mangling (NULL_TREE);
4436 : :
4437 : 1591 : write_string ("_ZGI");
4438 : 1591 : write_module (module, true);
4439 : :
4440 : 1591 : return finish_mangling_get_identifier ();
4441 : : }
4442 : :
4443 : : /* Generate the mangled name of DECL. */
4444 : :
4445 : : static tree
4446 : 121337684 : mangle_decl_string (const tree decl)
4447 : : {
4448 : 121337684 : tree result;
4449 : 121337684 : tree saved_fn = NULL_TREE;
4450 : 121337684 : bool template_p = false;
4451 : :
4452 : : /* We shouldn't be trying to mangle an uninstantiated template. */
4453 : 121337684 : gcc_assert (!type_dependent_expression_p (decl));
4454 : :
4455 : 121337684 : if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
4456 : : {
4457 : 78553306 : struct tinst_level *tl = current_instantiation ();
4458 : 7143087 : if ((!tl || tl->maybe_get_node () != decl)
4459 : 85694050 : && push_tinst_level (decl))
4460 : : {
4461 : 78550090 : template_p = true;
4462 : 78550090 : saved_fn = current_function_decl;
4463 : 78550090 : current_function_decl = NULL_TREE;
4464 : : }
4465 : : }
4466 : 121337684 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
4467 : :
4468 : 121337684 : start_mangling (decl);
4469 : :
4470 : 121337684 : if (TREE_CODE (decl) == TYPE_DECL)
4471 : 342790 : write_type (TREE_TYPE (decl));
4472 : : else
4473 : 120994894 : write_mangled_name (decl, true);
4474 : :
4475 : 121337684 : result = finish_mangling_get_identifier ();
4476 : 121337684 : if (DEBUG_MANGLE)
4477 : : fprintf (stderr, "mangle_decl_string = '%s'\n\n",
4478 : : IDENTIFIER_POINTER (result));
4479 : :
4480 : 121337684 : if (template_p)
4481 : : {
4482 : 78550090 : pop_tinst_level ();
4483 : 78550090 : current_function_decl = saved_fn;
4484 : : }
4485 : :
4486 : 121337684 : return result;
4487 : 121337684 : }
4488 : :
4489 : : /* Return an identifier for the external mangled name of DECL. */
4490 : :
4491 : : static tree
4492 : 120844293 : get_mangled_id (tree decl)
4493 : : {
4494 : 120844293 : tree id = mangle_decl_string (decl);
4495 : 120844293 : return targetm.mangle_decl_assembler_name (decl, id);
4496 : : }
4497 : :
4498 : : /* Create an identifier for the external mangled name of DECL. */
4499 : :
4500 : : void
4501 : 120850759 : mangle_decl (const tree decl)
4502 : : {
4503 : 120850759 : tree id;
4504 : 120850759 : bool dep;
4505 : :
4506 : : /* Don't bother mangling uninstantiated templates. */
4507 : 120850759 : ++processing_template_decl;
4508 : 120850759 : if (TREE_CODE (decl) == TYPE_DECL)
4509 : 343374 : dep = dependent_type_p (TREE_TYPE (decl));
4510 : : else
4511 : 239775326 : dep = (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
4512 : 198674326 : && any_dependent_template_arguments_p (DECL_TI_ARGS (decl)));
4513 : 120850759 : --processing_template_decl;
4514 : 120850759 : if (dep)
4515 : : return;
4516 : :
4517 : : /* During LTO we keep mangled names of TYPE_DECLs for ODR type merging.
4518 : : It is not needed to assign names to anonymous namespace, but we use the
4519 : : "<anon>" marker to be able to tell if type is C++ ODR type or type
4520 : : produced by other language. */
4521 : 120844877 : if (TREE_CODE (decl) == TYPE_DECL
4522 : 343374 : && TYPE_STUB_DECL (TREE_TYPE (decl))
4523 : 121169285 : && !TREE_PUBLIC (TYPE_STUB_DECL (TREE_TYPE (decl))))
4524 : 584 : id = get_identifier ("<anon>");
4525 : : else
4526 : : {
4527 : 120844293 : gcc_assert (TREE_CODE (decl) != TYPE_DECL
4528 : : || !no_linkage_check (TREE_TYPE (decl), true));
4529 : 120844293 : if (abi_version_at_least (10))
4530 : 120726255 : if (tree fn = decl_function_context (decl))
4531 : 3042207 : maybe_check_abi_tags (fn, decl);
4532 : 120844293 : id = get_mangled_id (decl);
4533 : : }
4534 : 120844877 : SET_DECL_ASSEMBLER_NAME (decl, id);
4535 : :
4536 : 120844877 : if (G.need_cxx17_warning
4537 : 120844877 : && (TREE_PUBLIC (decl) || DECL_REALLY_EXTERN (decl)))
4538 : 10 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wnoexcept_type,
4539 : : "mangled name for %qD will change in C++17 because the "
4540 : : "exception specification is part of a function type",
4541 : : decl);
4542 : :
4543 : 120844877 : if (id != DECL_NAME (decl)
4544 : : /* Don't do this for a fake symbol we aren't going to emit anyway. */
4545 : 118364919 : && TREE_CODE (decl) != TYPE_DECL
4546 : 238866422 : && !DECL_MAYBE_IN_CHARGE_CDTOR_P (decl))
4547 : : {
4548 : 101349877 : int save_ver = flag_abi_version;
4549 : 101349877 : tree id2 = NULL_TREE;
4550 : :
4551 : 101349877 : if (!DECL_REALLY_EXTERN (decl))
4552 : : {
4553 : 56113603 : record_mangling (decl, G.need_abi_warning);
4554 : :
4555 : 56113603 : if (!G.need_abi_warning)
4556 : : return;
4557 : :
4558 : 278072 : flag_abi_version = flag_abi_compat_version;
4559 : 278072 : id2 = mangle_decl_string (decl);
4560 : 278072 : id2 = targetm.mangle_decl_assembler_name (decl, id2);
4561 : 278072 : flag_abi_version = save_ver;
4562 : :
4563 : 278072 : if (id2 != id)
4564 : 276524 : note_mangling_alias (decl, id2);
4565 : : }
4566 : :
4567 : 45514346 : if (warn_abi)
4568 : : {
4569 : 215520 : const char fabi_version[] = "-fabi-version";
4570 : :
4571 : 215520 : if (flag_abi_compat_version != warn_abi_version
4572 : 214887 : || id2 == NULL_TREE)
4573 : : {
4574 : 215319 : flag_abi_version = warn_abi_version;
4575 : 215319 : id2 = mangle_decl_string (decl);
4576 : 215319 : id2 = targetm.mangle_decl_assembler_name (decl, id2);
4577 : : }
4578 : 215520 : flag_abi_version = save_ver;
4579 : :
4580 : 215520 : if (id2 == id)
4581 : : /* OK. */;
4582 : 266 : else if (warn_abi_version != 0
4583 : 266 : && abi_version_at_least (warn_abi_version))
4584 : 222 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4585 : : "the mangled name of %qD changed between "
4586 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4587 : : G.entity, fabi_version, warn_abi_version, id2,
4588 : : fabi_version, save_ver, id);
4589 : : else
4590 : 44 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4591 : : "the mangled name of %qD changes between "
4592 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4593 : : G.entity, fabi_version, save_ver, id,
4594 : : fabi_version, warn_abi_version, id2);
4595 : : }
4596 : :
4597 : 45514346 : flag_abi_version = save_ver;
4598 : : }
4599 : : }
4600 : :
4601 : : /* Generate the mangled representation of TYPE. */
4602 : :
4603 : : const char *
4604 : 363017 : mangle_type_string (const tree type)
4605 : : {
4606 : 363017 : const char *result;
4607 : :
4608 : 363017 : start_mangling (type);
4609 : 363017 : write_type (type);
4610 : 363017 : result = finish_mangling ();
4611 : 363017 : if (DEBUG_MANGLE)
4612 : : fprintf (stderr, "mangle_type_string = '%s'\n\n", result);
4613 : 363017 : return result;
4614 : : }
4615 : :
4616 : : /* Create an identifier for the mangled name of a special component
4617 : : for belonging to TYPE. CODE is the ABI-specified code for this
4618 : : component. */
4619 : :
4620 : : static tree
4621 : 5195914 : mangle_special_for_type (const tree type, const char *code)
4622 : : {
4623 : 5195914 : tree result;
4624 : :
4625 : : /* We don't have an actual decl here for the special component, so
4626 : : we can't just process the <encoded-name>. Instead, fake it. */
4627 : 5195914 : start_mangling (type);
4628 : :
4629 : : /* Start the mangling. */
4630 : 5195914 : write_string ("_Z");
4631 : 5195914 : write_string (code);
4632 : :
4633 : : /* Add the type. */
4634 : 5195914 : write_type (type);
4635 : 5195914 : result = finish_mangling_get_identifier ();
4636 : :
4637 : 5195914 : if (DEBUG_MANGLE)
4638 : : fprintf (stderr, "mangle_special_for_type = %s\n\n",
4639 : : IDENTIFIER_POINTER (result));
4640 : :
4641 : 5195914 : return result;
4642 : : }
4643 : :
4644 : : /* Create an identifier for the mangled representation of the typeinfo
4645 : : structure for TYPE. */
4646 : :
4647 : : tree
4648 : 2991686 : mangle_typeinfo_for_type (const tree type)
4649 : : {
4650 : 2991686 : return mangle_special_for_type (type, "TI");
4651 : : }
4652 : :
4653 : : /* Create an identifier for the mangled name of the NTBS containing
4654 : : the mangled name of TYPE. */
4655 : :
4656 : : tree
4657 : 359665 : mangle_typeinfo_string_for_type (const tree type)
4658 : : {
4659 : 359665 : return mangle_special_for_type (type, "TS");
4660 : : }
4661 : :
4662 : : /* Create an identifier for the mangled name of the vtable for TYPE. */
4663 : :
4664 : : tree
4665 : 1659858 : mangle_vtbl_for_type (const tree type)
4666 : : {
4667 : 1659858 : return mangle_special_for_type (type, "TV");
4668 : : }
4669 : :
4670 : : /* Returns an identifier for the mangled name of the VTT for TYPE. */
4671 : :
4672 : : tree
4673 : 184705 : mangle_vtt_for_type (const tree type)
4674 : : {
4675 : 184705 : return mangle_special_for_type (type, "TT");
4676 : : }
4677 : :
4678 : : /* Returns an identifier for the mangled name of the decomposition
4679 : : artificial variable DECL. DECLS is the vector of the VAR_DECLs
4680 : : for the identifier-list. */
4681 : :
4682 : : tree
4683 : 377 : mangle_decomp (const tree decl, vec<tree> &decls)
4684 : : {
4685 : 377 : gcc_assert (!type_dependent_expression_p (decl));
4686 : :
4687 : 377 : location_t saved_loc = input_location;
4688 : 377 : input_location = DECL_SOURCE_LOCATION (decl);
4689 : :
4690 : 377 : check_abi_tags (decl);
4691 : 377 : start_mangling (decl);
4692 : 377 : write_string ("_Z");
4693 : :
4694 : 377 : tree context = decl_mangling_context (decl);
4695 : 377 : gcc_assert (context != NULL_TREE);
4696 : :
4697 : 377 : bool nested = false;
4698 : 377 : bool local = false;
4699 : 377 : if (DECL_NAMESPACE_STD_P (context))
4700 : 9 : write_string ("St");
4701 : 368 : else if (TREE_CODE (context) == FUNCTION_DECL)
4702 : : {
4703 : 123 : local = true;
4704 : 123 : write_char ('Z');
4705 : 123 : write_encoding (context);
4706 : 123 : write_char ('E');
4707 : : }
4708 : 245 : else if (context != global_namespace)
4709 : : {
4710 : 67 : nested = true;
4711 : 67 : write_char ('N');
4712 : 67 : write_prefix (context);
4713 : : }
4714 : :
4715 : 377 : write_string ("DC");
4716 : 377 : unsigned int i;
4717 : 377 : tree d;
4718 : 1348 : FOR_EACH_VEC_ELT (decls, i, d)
4719 : 971 : write_unqualified_name (d);
4720 : 377 : write_char ('E');
4721 : :
4722 : 377 : if (tree tags = get_abi_tags (decl))
4723 : : {
4724 : : /* We didn't emit ABI tags for structured bindings before ABI 19. */
4725 : 30 : if (!G.need_abi_warning
4726 : 30 : && TREE_PUBLIC (decl)
4727 : 120 : && abi_warn_or_compat_version_crosses (19))
4728 : 30 : G.need_abi_warning = 1;
4729 : :
4730 : 30 : if (abi_version_at_least (19))
4731 : 30 : write_abi_tags (tags);
4732 : : }
4733 : :
4734 : 377 : if (nested)
4735 : 67 : write_char ('E');
4736 : 310 : else if (local && DECL_DISCRIMINATOR_P (decl))
4737 : 123 : write_discriminator (discriminator_for_local_entity (decl));
4738 : :
4739 : 377 : tree id = finish_mangling_get_identifier ();
4740 : 377 : if (DEBUG_MANGLE)
4741 : : fprintf (stderr, "mangle_decomp = '%s'\n\n",
4742 : : IDENTIFIER_POINTER (id));
4743 : :
4744 : 377 : input_location = saved_loc;
4745 : :
4746 : 377 : if (warn_abi && G.need_abi_warning)
4747 : : {
4748 : 0 : const char fabi_version[] = "-fabi-version";
4749 : 0 : tree id2 = id;
4750 : 0 : int save_ver = flag_abi_version;
4751 : :
4752 : 0 : if (flag_abi_version != warn_abi_version)
4753 : : {
4754 : 0 : flag_abi_version = warn_abi_version;
4755 : 0 : id2 = mangle_decomp (decl, decls);
4756 : 0 : flag_abi_version = save_ver;
4757 : : }
4758 : :
4759 : 0 : if (id2 == id)
4760 : : /* OK. */;
4761 : 0 : else if (warn_abi_version != 0
4762 : 0 : && abi_version_at_least (warn_abi_version))
4763 : 0 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4764 : : "the mangled name of %qD changed between "
4765 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4766 : : G.entity, fabi_version, warn_abi_version, id2,
4767 : : fabi_version, save_ver, id);
4768 : : else
4769 : 0 : warning_at (DECL_SOURCE_LOCATION (G.entity), OPT_Wabi,
4770 : : "the mangled name of %qD changes between "
4771 : : "%<%s=%d%> (%qD) and %<%s=%d%> (%qD)",
4772 : : G.entity, fabi_version, save_ver, id,
4773 : : fabi_version, warn_abi_version, id2);
4774 : : }
4775 : :
4776 : 377 : return id;
4777 : : }
4778 : :
4779 : : /* Return an identifier for a construction vtable group. TYPE is
4780 : : the most derived class in the hierarchy; BINFO is the base
4781 : : subobject for which this construction vtable group will be used.
4782 : :
4783 : : This mangling isn't part of the ABI specification; in the ABI
4784 : : specification, the vtable group is dumped in the same COMDAT as the
4785 : : main vtable, and is referenced only from that vtable, so it doesn't
4786 : : need an external name. For binary formats without COMDAT sections,
4787 : : though, we need external names for the vtable groups.
4788 : :
4789 : : We use the production
4790 : :
4791 : : <special-name> ::= CT <type> <offset number> _ <base type> */
4792 : :
4793 : : tree
4794 : 254055 : mangle_ctor_vtbl_for_type (const tree type, const tree binfo)
4795 : : {
4796 : 254055 : tree result;
4797 : :
4798 : 254055 : start_mangling (type);
4799 : :
4800 : 254055 : write_string ("_Z");
4801 : 254055 : write_string ("TC");
4802 : 254055 : write_type (type);
4803 : 254055 : write_integer_cst (BINFO_OFFSET (binfo));
4804 : 254055 : write_char ('_');
4805 : 254055 : write_type (BINFO_TYPE (binfo));
4806 : :
4807 : 254055 : result = finish_mangling_get_identifier ();
4808 : 254055 : if (DEBUG_MANGLE)
4809 : : fprintf (stderr, "mangle_ctor_vtbl_for_type = %s\n\n",
4810 : : IDENTIFIER_POINTER (result));
4811 : 254055 : return result;
4812 : : }
4813 : :
4814 : : /* Mangle a this pointer or result pointer adjustment.
4815 : :
4816 : : <call-offset> ::= h <fixed offset number> _
4817 : : ::= v <fixed offset number> _ <virtual offset number> _ */
4818 : :
4819 : : static void
4820 : 484627 : mangle_call_offset (const tree fixed_offset, const tree virtual_offset)
4821 : : {
4822 : 484627 : write_char (virtual_offset ? 'v' : 'h');
4823 : :
4824 : : /* For either flavor, write the fixed offset. */
4825 : 484627 : write_integer_cst (fixed_offset);
4826 : 484627 : write_char ('_');
4827 : :
4828 : : /* For a virtual thunk, add the virtual offset. */
4829 : 484627 : if (virtual_offset)
4830 : : {
4831 : 362889 : write_integer_cst (virtual_offset);
4832 : 362889 : write_char ('_');
4833 : : }
4834 : 484627 : }
4835 : :
4836 : : /* Return an identifier for the mangled name of a this-adjusting or
4837 : : covariant thunk to FN_DECL. FIXED_OFFSET is the initial adjustment
4838 : : to this used to find the vptr. If VIRTUAL_OFFSET is non-NULL, this
4839 : : is a virtual thunk, and it is the vtbl offset in
4840 : : bytes. THIS_ADJUSTING is nonzero for a this adjusting thunk and
4841 : : zero for a covariant thunk. Note, that FN_DECL might be a covariant
4842 : : thunk itself. A covariant thunk name always includes the adjustment
4843 : : for the this pointer, even if there is none.
4844 : :
4845 : : <special-name> ::= T <call-offset> <base encoding>
4846 : : ::= Tc <this_adjust call-offset> <result_adjust call-offset>
4847 : : <base encoding> */
4848 : :
4849 : : tree
4850 : 484246 : mangle_thunk (tree fn_decl, const int this_adjusting, tree fixed_offset,
4851 : : tree virtual_offset, tree thunk)
4852 : : {
4853 : 484246 : tree result;
4854 : :
4855 : 484246 : if (abi_version_at_least (11))
4856 : 484243 : maybe_check_abi_tags (fn_decl, thunk, 11);
4857 : :
4858 : 484246 : start_mangling (fn_decl);
4859 : :
4860 : 484246 : write_string ("_Z");
4861 : 484246 : write_char ('T');
4862 : :
4863 : 484246 : if (!this_adjusting)
4864 : : {
4865 : : /* Covariant thunk with no this adjustment */
4866 : 214 : write_char ('c');
4867 : 214 : mangle_call_offset (integer_zero_node, NULL_TREE);
4868 : 214 : mangle_call_offset (fixed_offset, virtual_offset);
4869 : : }
4870 : 484032 : else if (!DECL_THUNK_P (fn_decl))
4871 : : /* Plain this adjusting thunk. */
4872 : 483865 : mangle_call_offset (fixed_offset, virtual_offset);
4873 : : else
4874 : : {
4875 : : /* This adjusting thunk to covariant thunk. */
4876 : 167 : write_char ('c');
4877 : 167 : mangle_call_offset (fixed_offset, virtual_offset);
4878 : 167 : fixed_offset = ssize_int (THUNK_FIXED_OFFSET (fn_decl));
4879 : 167 : virtual_offset = THUNK_VIRTUAL_OFFSET (fn_decl);
4880 : 167 : if (virtual_offset)
4881 : 124 : virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
4882 : 167 : mangle_call_offset (fixed_offset, virtual_offset);
4883 : 167 : fn_decl = THUNK_TARGET (fn_decl);
4884 : : }
4885 : :
4886 : : /* Scoped name. */
4887 : 484246 : write_encoding (fn_decl);
4888 : :
4889 : 484246 : result = finish_mangling_get_identifier ();
4890 : 484246 : if (DEBUG_MANGLE)
4891 : : fprintf (stderr, "mangle_thunk = %s\n\n", IDENTIFIER_POINTER (result));
4892 : 484246 : return result;
4893 : : }
4894 : :
4895 : : /* Handle ABI backwards compatibility for past bugs where we didn't call
4896 : : check_abi_tags in places where it's needed: call check_abi_tags and warn if
4897 : : it makes a difference. If FOR_DECL is non-null, it's the declaration
4898 : : that we're actually trying to mangle; if it's null, we're mangling the
4899 : : guard variable for T. */
4900 : :
4901 : : static void
4902 : 3530759 : maybe_check_abi_tags (tree t, tree for_decl, int ver)
4903 : : {
4904 : 3530759 : if (DECL_ASSEMBLER_NAME_SET_P (t))
4905 : : return;
4906 : :
4907 : 732474 : tree oldtags = get_abi_tags (t);
4908 : :
4909 : 732474 : mangle_decl (t);
4910 : :
4911 : 732474 : tree newtags = get_abi_tags (t);
4912 : 732474 : if (newtags && newtags != oldtags
4913 : 24 : && abi_version_crosses (ver))
4914 : : {
4915 : 12 : if (for_decl && DECL_THUNK_P (for_decl))
4916 : 3 : warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
4917 : : "the mangled name of a thunk for %qD changes between "
4918 : : "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
4919 : : t, flag_abi_version, warn_abi_version);
4920 : 9 : else if (for_decl)
4921 : 6 : warning_at (DECL_SOURCE_LOCATION (for_decl), OPT_Wabi,
4922 : : "the mangled name of %qD changes between "
4923 : : "%<-fabi-version=%d%> and %<-fabi-version=%d%>",
4924 : : for_decl, flag_abi_version, warn_abi_version);
4925 : : else
4926 : 3 : warning_at (DECL_SOURCE_LOCATION (t), OPT_Wabi,
4927 : : "the mangled name of the initialization guard variable "
4928 : : "for %qD changes between %<-fabi-version=%d%> and "
4929 : : "%<-fabi-version=%d%>",
4930 : : t, flag_abi_version, warn_abi_version);
4931 : : }
4932 : : }
4933 : :
4934 : : /* Write out the appropriate string for this variable when generating
4935 : : another mangled name based on this one. */
4936 : :
4937 : : static void
4938 : 6971 : write_guarded_var_name (const tree variable)
4939 : : {
4940 : 6971 : if (DECL_NAME (variable)
4941 : 6971 : && startswith (IDENTIFIER_POINTER (DECL_NAME (variable)), "_ZGR"))
4942 : : /* The name of a guard variable for a reference temporary should refer
4943 : : to the reference, not the temporary. */
4944 : 18 : write_string (IDENTIFIER_POINTER (DECL_NAME (variable)) + 4);
4945 : 6953 : else if (DECL_DECOMPOSITION_P (variable)
4946 : 621 : && DECL_NAME (variable) == NULL_TREE
4947 : 7138 : && startswith (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)),
4948 : : "_Z"))
4949 : : /* The name of a guard variable for a structured binding needs special
4950 : : casing. */
4951 : 185 : write_string (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (variable)) + 2);
4952 : : else
4953 : 6768 : write_name (variable, /*ignore_local_scope=*/0);
4954 : 6971 : }
4955 : :
4956 : : /* Return an identifier for the name of an initialization guard
4957 : : variable for indicated VARIABLE. */
4958 : :
4959 : : tree
4960 : 4315 : mangle_guard_variable (const tree variable)
4961 : : {
4962 : 4315 : if (abi_version_at_least (10))
4963 : 4309 : maybe_check_abi_tags (variable);
4964 : 4315 : start_mangling (variable);
4965 : 4315 : write_string ("_ZGV");
4966 : 4315 : write_guarded_var_name (variable);
4967 : 4315 : return finish_mangling_get_identifier ();
4968 : : }
4969 : :
4970 : : /* Return an identifier for the name of a thread_local initialization
4971 : : function for VARIABLE. */
4972 : :
4973 : : tree
4974 : 1193 : mangle_tls_init_fn (const tree variable)
4975 : : {
4976 : 1193 : check_abi_tags (variable);
4977 : 1193 : start_mangling (variable);
4978 : 1193 : write_string ("_ZTH");
4979 : 1193 : write_guarded_var_name (variable);
4980 : 1193 : return finish_mangling_get_identifier ();
4981 : : }
4982 : :
4983 : : /* Return an identifier for the name of a thread_local wrapper
4984 : : function for VARIABLE. */
4985 : :
4986 : : #define TLS_WRAPPER_PREFIX "_ZTW"
4987 : :
4988 : : tree
4989 : 714 : mangle_tls_wrapper_fn (const tree variable)
4990 : : {
4991 : 714 : check_abi_tags (variable);
4992 : 714 : start_mangling (variable);
4993 : 714 : write_string (TLS_WRAPPER_PREFIX);
4994 : 714 : write_guarded_var_name (variable);
4995 : 714 : return finish_mangling_get_identifier ();
4996 : : }
4997 : :
4998 : : /* Return true iff FN is a thread_local wrapper function. */
4999 : :
5000 : : bool
5001 : 1515219 : decl_tls_wrapper_p (const tree fn)
5002 : : {
5003 : 1515219 : if (TREE_CODE (fn) != FUNCTION_DECL)
5004 : : return false;
5005 : 1226093 : tree name = DECL_NAME (fn);
5006 : 1226093 : return startswith (IDENTIFIER_POINTER (name), TLS_WRAPPER_PREFIX);
5007 : : }
5008 : :
5009 : : /* Return an identifier for the name of a temporary variable used to
5010 : : initialize a static reference. This is now part of the ABI. */
5011 : :
5012 : : tree
5013 : 749 : mangle_ref_init_variable (const tree variable)
5014 : : {
5015 : 749 : start_mangling (variable);
5016 : 749 : write_string ("_ZGR");
5017 : 749 : check_abi_tags (variable);
5018 : 749 : write_guarded_var_name (variable);
5019 : : /* Avoid name clashes with aggregate initialization of multiple
5020 : : references at once. */
5021 : 749 : write_compact_number (current_ref_temp_count++);
5022 : 749 : return finish_mangling_get_identifier ();
5023 : : }
5024 : :
5025 : : /* Return an identifier for the mangled name of a C++20 template parameter
5026 : : object for template argument EXPR. */
5027 : :
5028 : : tree
5029 : 1777 : mangle_template_parm_object (tree expr)
5030 : : {
5031 : 1777 : start_mangling (expr);
5032 : 1777 : write_string ("_ZTAX");
5033 : 1777 : write_expression (expr);
5034 : 1777 : write_char ('E');
5035 : 1777 : return finish_mangling_get_identifier ();
5036 : : }
5037 : :
5038 : : /* Given a CLASS_TYPE, such as a record for std::bad_exception this
5039 : : function generates a mangled name for the vtable map variable of
5040 : : the class type. For example, if the class type is
5041 : : "std::bad_exception", the mangled name for the class is
5042 : : "St13bad_exception". This function would generate the name
5043 : : "_ZN4_VTVISt13bad_exceptionE12__vtable_mapE", which unmangles as:
5044 : : "_VTV<std::bad_exception>::__vtable_map". */
5045 : :
5046 : :
5047 : : char *
5048 : 6 : get_mangled_vtable_map_var_name (tree class_type)
5049 : : {
5050 : 6 : char *var_name = NULL;
5051 : 6 : const char *prefix = "_ZN4_VTVI";
5052 : 6 : const char *postfix = "E12__vtable_mapE";
5053 : :
5054 : 6 : gcc_assert (TREE_CODE (class_type) == RECORD_TYPE);
5055 : :
5056 : 6 : tree class_id = DECL_ASSEMBLER_NAME (TYPE_NAME (class_type));
5057 : :
5058 : 6 : if (strstr (IDENTIFIER_POINTER (class_id), "<anon>") != NULL)
5059 : : {
5060 : 0 : class_id = get_mangled_id (TYPE_NAME (class_type));
5061 : 0 : vtbl_register_mangled_name (TYPE_NAME (class_type), class_id);
5062 : : }
5063 : :
5064 : 6 : unsigned int len = strlen (IDENTIFIER_POINTER (class_id)) +
5065 : : strlen (prefix) +
5066 : 6 : strlen (postfix) + 1;
5067 : :
5068 : 6 : var_name = (char *) xmalloc (len);
5069 : :
5070 : 6 : sprintf (var_name, "%s%s%s", prefix, IDENTIFIER_POINTER (class_id), postfix);
5071 : :
5072 : 6 : return var_name;
5073 : : }
5074 : :
5075 : : #include "gt-cp-mangle.h"
|