1 //===--- MicrosoftMangle.cpp - Microsoft Visual C++ Name Mangling ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides C++ name mangling targeting the Microsoft Visual C++ ABI.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/AST/Mangle.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/CharUnits.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/ExprCXX.h"
22 #include "clang/Basic/ABI.h"
23
24 using namespace clang;
25
26 namespace {
27
28 /// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
29 /// Microsoft Visual C++ ABI.
30 class MicrosoftCXXNameMangler {
31 MangleContext &Context;
32 llvm::raw_ostream &Out;
33
getASTContext() const34 ASTContext &getASTContext() const { return Context.getASTContext(); }
35
36 public:
MicrosoftCXXNameMangler(MangleContext & C,llvm::raw_ostream & Out_)37 MicrosoftCXXNameMangler(MangleContext &C, llvm::raw_ostream &Out_)
38 : Context(C), Out(Out_) { }
39
40 void mangle(const NamedDecl *D, llvm::StringRef Prefix = "?");
41 void mangleName(const NamedDecl *ND);
42 void mangleFunctionEncoding(const FunctionDecl *FD);
43 void mangleVariableEncoding(const VarDecl *VD);
44 void mangleNumber(int64_t Number);
45 void mangleType(QualType T);
46
47 private:
mangleUnqualifiedName(const NamedDecl * ND)48 void mangleUnqualifiedName(const NamedDecl *ND) {
49 mangleUnqualifiedName(ND, ND->getDeclName());
50 }
51 void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name);
52 void mangleSourceName(const IdentifierInfo *II);
53 void manglePostfix(const DeclContext *DC, bool NoFunction=false);
54 void mangleOperatorName(OverloadedOperatorKind OO);
55 void mangleQualifiers(Qualifiers Quals, bool IsMember);
56
57 void mangleObjCMethodName(const ObjCMethodDecl *MD);
58
59 // Declare manglers for every type class.
60 #define ABSTRACT_TYPE(CLASS, PARENT)
61 #define NON_CANONICAL_TYPE(CLASS, PARENT)
62 #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
63 #include "clang/AST/TypeNodes.def"
64
65 void mangleType(const TagType*);
66 void mangleType(const FunctionType *T, const FunctionDecl *D,
67 bool IsStructor, bool IsInstMethod);
68 void mangleType(const ArrayType *T, bool IsGlobal);
69 void mangleExtraDimensions(QualType T);
70 void mangleFunctionClass(const FunctionDecl *FD);
71 void mangleCallingConvention(const FunctionType *T, bool IsInstMethod = false);
72 void mangleThrowSpecification(const FunctionProtoType *T);
73
74 };
75
76 /// MicrosoftMangleContext - Overrides the default MangleContext for the
77 /// Microsoft Visual C++ ABI.
78 class MicrosoftMangleContext : public MangleContext {
79 public:
MicrosoftMangleContext(ASTContext & Context,Diagnostic & Diags)80 MicrosoftMangleContext(ASTContext &Context,
81 Diagnostic &Diags) : MangleContext(Context, Diags) { }
82 virtual bool shouldMangleDeclName(const NamedDecl *D);
83 virtual void mangleName(const NamedDecl *D, llvm::raw_ostream &Out);
84 virtual void mangleThunk(const CXXMethodDecl *MD,
85 const ThunkInfo &Thunk,
86 llvm::raw_ostream &);
87 virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
88 const ThisAdjustment &ThisAdjustment,
89 llvm::raw_ostream &);
90 virtual void mangleCXXVTable(const CXXRecordDecl *RD,
91 llvm::raw_ostream &);
92 virtual void mangleCXXVTT(const CXXRecordDecl *RD,
93 llvm::raw_ostream &);
94 virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
95 const CXXRecordDecl *Type,
96 llvm::raw_ostream &);
97 virtual void mangleCXXRTTI(QualType T, llvm::raw_ostream &);
98 virtual void mangleCXXRTTIName(QualType T, llvm::raw_ostream &);
99 virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
100 llvm::raw_ostream &);
101 virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
102 llvm::raw_ostream &);
103 virtual void mangleReferenceTemporary(const clang::VarDecl *,
104 llvm::raw_ostream &);
105 };
106
107 }
108
isInCLinkageSpecification(const Decl * D)109 static bool isInCLinkageSpecification(const Decl *D) {
110 D = D->getCanonicalDecl();
111 for (const DeclContext *DC = D->getDeclContext();
112 !DC->isTranslationUnit(); DC = DC->getParent()) {
113 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
114 return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
115 }
116
117 return false;
118 }
119
shouldMangleDeclName(const NamedDecl * D)120 bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) {
121 // In C, functions with no attributes never need to be mangled. Fastpath them.
122 if (!getASTContext().getLangOptions().CPlusPlus && !D->hasAttrs())
123 return false;
124
125 // Any decl can be declared with __asm("foo") on it, and this takes precedence
126 // over all other naming in the .o file.
127 if (D->hasAttr<AsmLabelAttr>())
128 return true;
129
130 // Clang's "overloadable" attribute extension to C/C++ implies name mangling
131 // (always) as does passing a C++ member function and a function
132 // whose name is not a simple identifier.
133 const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
134 if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) ||
135 !FD->getDeclName().isIdentifier()))
136 return true;
137
138 // Otherwise, no mangling is done outside C++ mode.
139 if (!getASTContext().getLangOptions().CPlusPlus)
140 return false;
141
142 // Variables at global scope with internal linkage are not mangled.
143 if (!FD) {
144 const DeclContext *DC = D->getDeclContext();
145 if (DC->isTranslationUnit() && D->getLinkage() == InternalLinkage)
146 return false;
147 }
148
149 // C functions and "main" are not mangled.
150 if ((FD && FD->isMain()) || isInCLinkageSpecification(D))
151 return false;
152
153 return true;
154 }
155
mangle(const NamedDecl * D,llvm::StringRef Prefix)156 void MicrosoftCXXNameMangler::mangle(const NamedDecl *D,
157 llvm::StringRef Prefix) {
158 // MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
159 // Therefore it's really important that we don't decorate the
160 // name with leading underscores or leading/trailing at signs. So, emit a
161 // asm marker at the start so we get the name right.
162 Out << '\01'; // LLVM IR Marker for __asm("foo")
163
164 // Any decl can be declared with __asm("foo") on it, and this takes precedence
165 // over all other naming in the .o file.
166 if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
167 // If we have an asm name, then we use it as the mangling.
168 Out << ALA->getLabel();
169 return;
170 }
171
172 // <mangled-name> ::= ? <name> <type-encoding>
173 Out << Prefix;
174 mangleName(D);
175 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
176 mangleFunctionEncoding(FD);
177 else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
178 mangleVariableEncoding(VD);
179 // TODO: Fields? Can MSVC even mangle them?
180 }
181
mangleFunctionEncoding(const FunctionDecl * FD)182 void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
183 // <type-encoding> ::= <function-class> <function-type>
184
185 // Don't mangle in the type if this isn't a decl we should typically mangle.
186 if (!Context.shouldMangleDeclName(FD))
187 return;
188
189 // We should never ever see a FunctionNoProtoType at this point.
190 // We don't even know how to mangle their types anyway :).
191 const FunctionProtoType *FT = cast<FunctionProtoType>(FD->getType());
192
193 bool InStructor = false, InInstMethod = false;
194 const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
195 if (MD) {
196 if (MD->isInstance())
197 InInstMethod = true;
198 if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD))
199 InStructor = true;
200 }
201
202 // First, the function class.
203 mangleFunctionClass(FD);
204
205 mangleType(FT, FD, InStructor, InInstMethod);
206 }
207
mangleVariableEncoding(const VarDecl * VD)208 void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) {
209 // <type-encoding> ::= <storage-class> <variable-type>
210 // <storage-class> ::= 0 # private static member
211 // ::= 1 # protected static member
212 // ::= 2 # public static member
213 // ::= 3 # global
214 // ::= 4 # static local
215
216 // The first character in the encoding (after the name) is the storage class.
217 if (VD->isStaticDataMember()) {
218 // If it's a static member, it also encodes the access level.
219 switch (VD->getAccess()) {
220 default:
221 case AS_private: Out << '0'; break;
222 case AS_protected: Out << '1'; break;
223 case AS_public: Out << '2'; break;
224 }
225 }
226 else if (!VD->isStaticLocal())
227 Out << '3';
228 else
229 Out << '4';
230 // Now mangle the type.
231 // <variable-type> ::= <type> <cvr-qualifiers>
232 // ::= <type> A # pointers, references, arrays
233 // Pointers and references are odd. The type of 'int * const foo;' gets
234 // mangled as 'QAHA' instead of 'PAHB', for example.
235 QualType Ty = VD->getType();
236 if (Ty->isPointerType() || Ty->isReferenceType()) {
237 mangleType(Ty);
238 Out << 'A';
239 } else if (Ty->isArrayType()) {
240 // Global arrays are funny, too.
241 mangleType(cast<ArrayType>(Ty.getTypePtr()), true);
242 Out << 'A';
243 } else {
244 mangleType(Ty.getLocalUnqualifiedType());
245 mangleQualifiers(Ty.getLocalQualifiers(), false);
246 }
247 }
248
mangleName(const NamedDecl * ND)249 void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {
250 // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @
251 const DeclContext *DC = ND->getDeclContext();
252
253 // Always start with the unqualified name.
254 mangleUnqualifiedName(ND);
255
256 // If this is an extern variable declared locally, the relevant DeclContext
257 // is that of the containing namespace, or the translation unit.
258 if (isa<FunctionDecl>(DC) && ND->hasLinkage())
259 while (!DC->isNamespace() && !DC->isTranslationUnit())
260 DC = DC->getParent();
261
262 manglePostfix(DC);
263
264 // Terminate the whole name with an '@'.
265 Out << '@';
266 }
267
mangleNumber(int64_t Number)268 void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
269 // <number> ::= [?] <decimal digit> # <= 9
270 // ::= [?] <hex digit>+ @ # > 9; A = 0, B = 1, etc...
271 if (Number < 0) {
272 Out << '?';
273 Number = -Number;
274 }
275 if (Number >= 1 && Number <= 10) {
276 Out << Number-1;
277 } else {
278 // We have to build up the encoding in reverse order, so it will come
279 // out right when we write it out.
280 char Encoding[16];
281 char *EndPtr = Encoding+sizeof(Encoding);
282 char *CurPtr = EndPtr;
283 while (Number) {
284 *--CurPtr = 'A' + (Number % 16);
285 Number /= 16;
286 }
287 Out.write(CurPtr, EndPtr-CurPtr);
288 Out << '@';
289 }
290 }
291
292 void
mangleUnqualifiedName(const NamedDecl * ND,DeclarationName Name)293 MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
294 DeclarationName Name) {
295 // <unqualified-name> ::= <operator-name>
296 // ::= <ctor-dtor-name>
297 // ::= <source-name>
298 switch (Name.getNameKind()) {
299 case DeclarationName::Identifier: {
300 if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
301 mangleSourceName(II);
302 break;
303 }
304
305 // Otherwise, an anonymous entity. We must have a declaration.
306 assert(ND && "mangling empty name without declaration");
307
308 if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
309 if (NS->isAnonymousNamespace()) {
310 Out << "?A";
311 break;
312 }
313 }
314
315 // We must have an anonymous struct.
316 const TagDecl *TD = cast<TagDecl>(ND);
317 if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) {
318 assert(TD->getDeclContext() == D->getDeclContext() &&
319 "Typedef should not be in another decl context!");
320 assert(D->getDeclName().getAsIdentifierInfo() &&
321 "Typedef was not named!");
322 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
323 break;
324 }
325
326 // When VC encounters an anonymous type with no tag and no typedef,
327 // it literally emits '<unnamed-tag>'.
328 Out << "<unnamed-tag>";
329 break;
330 }
331
332 case DeclarationName::ObjCZeroArgSelector:
333 case DeclarationName::ObjCOneArgSelector:
334 case DeclarationName::ObjCMultiArgSelector:
335 assert(false && "Can't mangle Objective-C selector names here!");
336 break;
337
338 case DeclarationName::CXXConstructorName:
339 assert(false && "Can't mangle constructors yet!");
340 break;
341
342 case DeclarationName::CXXDestructorName:
343 assert(false && "Can't mangle destructors yet!");
344 break;
345
346 case DeclarationName::CXXConversionFunctionName:
347 // <operator-name> ::= ?B # (cast)
348 // The target type is encoded as the return type.
349 Out << "?B";
350 break;
351
352 case DeclarationName::CXXOperatorName:
353 mangleOperatorName(Name.getCXXOverloadedOperator());
354 break;
355
356 case DeclarationName::CXXLiteralOperatorName:
357 // FIXME: Was this added in VS2010? Does MS even know how to mangle this?
358 assert(false && "Don't know how to mangle literal operators yet!");
359 break;
360
361 case DeclarationName::CXXUsingDirective:
362 assert(false && "Can't mangle a using directive name!");
363 break;
364 }
365 }
366
manglePostfix(const DeclContext * DC,bool NoFunction)367 void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC,
368 bool NoFunction) {
369 // <postfix> ::= <unqualified-name> [<postfix>]
370 // ::= <template-postfix> <template-args> [<postfix>]
371 // ::= <template-param>
372 // ::= <substitution> [<postfix>]
373
374 if (!DC) return;
375
376 while (isa<LinkageSpecDecl>(DC))
377 DC = DC->getParent();
378
379 if (DC->isTranslationUnit())
380 return;
381
382 if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
383 Context.mangleBlock(BD, Out);
384 Out << '@';
385 return manglePostfix(DC->getParent(), NoFunction);
386 }
387
388 if (NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)))
389 return;
390 else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC))
391 mangleObjCMethodName(Method);
392 else {
393 mangleUnqualifiedName(cast<NamedDecl>(DC));
394 manglePostfix(DC->getParent(), NoFunction);
395 }
396 }
397
mangleOperatorName(OverloadedOperatorKind OO)398 void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO) {
399 switch (OO) {
400 // ?0 # constructor
401 // ?1 # destructor
402 // <operator-name> ::= ?2 # new
403 case OO_New: Out << "?2"; break;
404 // <operator-name> ::= ?3 # delete
405 case OO_Delete: Out << "?3"; break;
406 // <operator-name> ::= ?4 # =
407 case OO_Equal: Out << "?4"; break;
408 // <operator-name> ::= ?5 # >>
409 case OO_GreaterGreater: Out << "?5"; break;
410 // <operator-name> ::= ?6 # <<
411 case OO_LessLess: Out << "?6"; break;
412 // <operator-name> ::= ?7 # !
413 case OO_Exclaim: Out << "?7"; break;
414 // <operator-name> ::= ?8 # ==
415 case OO_EqualEqual: Out << "?8"; break;
416 // <operator-name> ::= ?9 # !=
417 case OO_ExclaimEqual: Out << "?9"; break;
418 // <operator-name> ::= ?A # []
419 case OO_Subscript: Out << "?A"; break;
420 // ?B # conversion
421 // <operator-name> ::= ?C # ->
422 case OO_Arrow: Out << "?C"; break;
423 // <operator-name> ::= ?D # *
424 case OO_Star: Out << "?D"; break;
425 // <operator-name> ::= ?E # ++
426 case OO_PlusPlus: Out << "?E"; break;
427 // <operator-name> ::= ?F # --
428 case OO_MinusMinus: Out << "?F"; break;
429 // <operator-name> ::= ?G # -
430 case OO_Minus: Out << "?G"; break;
431 // <operator-name> ::= ?H # +
432 case OO_Plus: Out << "?H"; break;
433 // <operator-name> ::= ?I # &
434 case OO_Amp: Out << "?I"; break;
435 // <operator-name> ::= ?J # ->*
436 case OO_ArrowStar: Out << "?J"; break;
437 // <operator-name> ::= ?K # /
438 case OO_Slash: Out << "?K"; break;
439 // <operator-name> ::= ?L # %
440 case OO_Percent: Out << "?L"; break;
441 // <operator-name> ::= ?M # <
442 case OO_Less: Out << "?M"; break;
443 // <operator-name> ::= ?N # <=
444 case OO_LessEqual: Out << "?N"; break;
445 // <operator-name> ::= ?O # >
446 case OO_Greater: Out << "?O"; break;
447 // <operator-name> ::= ?P # >=
448 case OO_GreaterEqual: Out << "?P"; break;
449 // <operator-name> ::= ?Q # ,
450 case OO_Comma: Out << "?Q"; break;
451 // <operator-name> ::= ?R # ()
452 case OO_Call: Out << "?R"; break;
453 // <operator-name> ::= ?S # ~
454 case OO_Tilde: Out << "?S"; break;
455 // <operator-name> ::= ?T # ^
456 case OO_Caret: Out << "?T"; break;
457 // <operator-name> ::= ?U # |
458 case OO_Pipe: Out << "?U"; break;
459 // <operator-name> ::= ?V # &&
460 case OO_AmpAmp: Out << "?V"; break;
461 // <operator-name> ::= ?W # ||
462 case OO_PipePipe: Out << "?W"; break;
463 // <operator-name> ::= ?X # *=
464 case OO_StarEqual: Out << "?X"; break;
465 // <operator-name> ::= ?Y # +=
466 case OO_PlusEqual: Out << "?Y"; break;
467 // <operator-name> ::= ?Z # -=
468 case OO_MinusEqual: Out << "?Z"; break;
469 // <operator-name> ::= ?_0 # /=
470 case OO_SlashEqual: Out << "?_0"; break;
471 // <operator-name> ::= ?_1 # %=
472 case OO_PercentEqual: Out << "?_1"; break;
473 // <operator-name> ::= ?_2 # >>=
474 case OO_GreaterGreaterEqual: Out << "?_2"; break;
475 // <operator-name> ::= ?_3 # <<=
476 case OO_LessLessEqual: Out << "?_3"; break;
477 // <operator-name> ::= ?_4 # &=
478 case OO_AmpEqual: Out << "?_4"; break;
479 // <operator-name> ::= ?_5 # |=
480 case OO_PipeEqual: Out << "?_5"; break;
481 // <operator-name> ::= ?_6 # ^=
482 case OO_CaretEqual: Out << "?_6"; break;
483 // ?_7 # vftable
484 // ?_8 # vbtable
485 // ?_9 # vcall
486 // ?_A # typeof
487 // ?_B # local static guard
488 // ?_C # string
489 // ?_D # vbase destructor
490 // ?_E # vector deleting destructor
491 // ?_F # default constructor closure
492 // ?_G # scalar deleting destructor
493 // ?_H # vector constructor iterator
494 // ?_I # vector destructor iterator
495 // ?_J # vector vbase constructor iterator
496 // ?_K # virtual displacement map
497 // ?_L # eh vector constructor iterator
498 // ?_M # eh vector destructor iterator
499 // ?_N # eh vector vbase constructor iterator
500 // ?_O # copy constructor closure
501 // ?_P<name> # udt returning <name>
502 // ?_Q # <unknown>
503 // ?_R0 # RTTI Type Descriptor
504 // ?_R1 # RTTI Base Class Descriptor at (a,b,c,d)
505 // ?_R2 # RTTI Base Class Array
506 // ?_R3 # RTTI Class Hierarchy Descriptor
507 // ?_R4 # RTTI Complete Object Locator
508 // ?_S # local vftable
509 // ?_T # local vftable constructor closure
510 // <operator-name> ::= ?_U # new[]
511 case OO_Array_New: Out << "?_U"; break;
512 // <operator-name> ::= ?_V # delete[]
513 case OO_Array_Delete: Out << "?_V"; break;
514
515 case OO_Conditional:
516 assert(false && "Don't know how to mangle ?:");
517 break;
518
519 case OO_None:
520 case NUM_OVERLOADED_OPERATORS:
521 assert(false && "Not an overloaded operator");
522 break;
523 }
524 }
525
mangleSourceName(const IdentifierInfo * II)526 void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
527 // <source name> ::= <identifier> @
528 Out << II->getName() << '@';
529 }
530
mangleObjCMethodName(const ObjCMethodDecl * MD)531 void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
532 Context.mangleObjCMethodName(MD, Out);
533 }
534
mangleQualifiers(Qualifiers Quals,bool IsMember)535 void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
536 bool IsMember) {
537 // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
538 // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
539 // 'I' means __restrict (32/64-bit).
540 // Note that the MSVC __restrict keyword isn't the same as the C99 restrict
541 // keyword!
542 // <base-cvr-qualifiers> ::= A # near
543 // ::= B # near const
544 // ::= C # near volatile
545 // ::= D # near const volatile
546 // ::= E # far (16-bit)
547 // ::= F # far const (16-bit)
548 // ::= G # far volatile (16-bit)
549 // ::= H # far const volatile (16-bit)
550 // ::= I # huge (16-bit)
551 // ::= J # huge const (16-bit)
552 // ::= K # huge volatile (16-bit)
553 // ::= L # huge const volatile (16-bit)
554 // ::= M <basis> # based
555 // ::= N <basis> # based const
556 // ::= O <basis> # based volatile
557 // ::= P <basis> # based const volatile
558 // ::= Q # near member
559 // ::= R # near const member
560 // ::= S # near volatile member
561 // ::= T # near const volatile member
562 // ::= U # far member (16-bit)
563 // ::= V # far const member (16-bit)
564 // ::= W # far volatile member (16-bit)
565 // ::= X # far const volatile member (16-bit)
566 // ::= Y # huge member (16-bit)
567 // ::= Z # huge const member (16-bit)
568 // ::= 0 # huge volatile member (16-bit)
569 // ::= 1 # huge const volatile member (16-bit)
570 // ::= 2 <basis> # based member
571 // ::= 3 <basis> # based const member
572 // ::= 4 <basis> # based volatile member
573 // ::= 5 <basis> # based const volatile member
574 // ::= 6 # near function (pointers only)
575 // ::= 7 # far function (pointers only)
576 // ::= 8 # near method (pointers only)
577 // ::= 9 # far method (pointers only)
578 // ::= _A <basis> # based function (pointers only)
579 // ::= _B <basis> # based function (far?) (pointers only)
580 // ::= _C <basis> # based method (pointers only)
581 // ::= _D <basis> # based method (far?) (pointers only)
582 // ::= _E # block (Clang)
583 // <basis> ::= 0 # __based(void)
584 // ::= 1 # __based(segment)?
585 // ::= 2 <name> # __based(name)
586 // ::= 3 # ?
587 // ::= 4 # ?
588 // ::= 5 # not really based
589 if (!IsMember) {
590 if (!Quals.hasVolatile()) {
591 if (!Quals.hasConst())
592 Out << 'A';
593 else
594 Out << 'B';
595 } else {
596 if (!Quals.hasConst())
597 Out << 'C';
598 else
599 Out << 'D';
600 }
601 } else {
602 if (!Quals.hasVolatile()) {
603 if (!Quals.hasConst())
604 Out << 'Q';
605 else
606 Out << 'R';
607 } else {
608 if (!Quals.hasConst())
609 Out << 'S';
610 else
611 Out << 'T';
612 }
613 }
614
615 // FIXME: For now, just drop all extension qualifiers on the floor.
616 }
617
mangleType(QualType T)618 void MicrosoftCXXNameMangler::mangleType(QualType T) {
619 // Only operate on the canonical type!
620 T = getASTContext().getCanonicalType(T);
621
622 Qualifiers Quals = T.getLocalQualifiers();
623 if (Quals) {
624 // We have to mangle these now, while we still have enough information.
625 // <pointer-cvr-qualifiers> ::= P # pointer
626 // ::= Q # const pointer
627 // ::= R # volatile pointer
628 // ::= S # const volatile pointer
629 if (T->isAnyPointerType() || T->isMemberPointerType() ||
630 T->isBlockPointerType()) {
631 if (!Quals.hasVolatile())
632 Out << 'Q';
633 else {
634 if (!Quals.hasConst())
635 Out << 'R';
636 else
637 Out << 'S';
638 }
639 } else
640 // Just emit qualifiers like normal.
641 // NB: When we mangle a pointer/reference type, and the pointee
642 // type has no qualifiers, the lack of qualifier gets mangled
643 // in there.
644 mangleQualifiers(Quals, false);
645 } else if (T->isAnyPointerType() || T->isMemberPointerType() ||
646 T->isBlockPointerType()) {
647 Out << 'P';
648 }
649 switch (T->getTypeClass()) {
650 #define ABSTRACT_TYPE(CLASS, PARENT)
651 #define NON_CANONICAL_TYPE(CLASS, PARENT) \
652 case Type::CLASS: \
653 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
654 return;
655 #define TYPE(CLASS, PARENT) \
656 case Type::CLASS: \
657 mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \
658 break;
659 #include "clang/AST/TypeNodes.def"
660 }
661 }
662
mangleType(const BuiltinType * T)663 void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T) {
664 // <type> ::= <builtin-type>
665 // <builtin-type> ::= X # void
666 // ::= C # signed char
667 // ::= D # char
668 // ::= E # unsigned char
669 // ::= F # short
670 // ::= G # unsigned short (or wchar_t if it's not a builtin)
671 // ::= H # int
672 // ::= I # unsigned int
673 // ::= J # long
674 // ::= K # unsigned long
675 // L # <none>
676 // ::= M # float
677 // ::= N # double
678 // ::= O # long double (__float80 is mangled differently)
679 // ::= _J # long long, __int64
680 // ::= _K # unsigned long long, __int64
681 // ::= _L # __int128
682 // ::= _M # unsigned __int128
683 // ::= _N # bool
684 // _O # <array in parameter>
685 // ::= _T # __float80 (Intel)
686 // ::= _W # wchar_t
687 // ::= _Z # __float80 (Digital Mars)
688 switch (T->getKind()) {
689 case BuiltinType::Void: Out << 'X'; break;
690 case BuiltinType::SChar: Out << 'C'; break;
691 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break;
692 case BuiltinType::UChar: Out << 'E'; break;
693 case BuiltinType::Short: Out << 'F'; break;
694 case BuiltinType::UShort: Out << 'G'; break;
695 case BuiltinType::Int: Out << 'H'; break;
696 case BuiltinType::UInt: Out << 'I'; break;
697 case BuiltinType::Long: Out << 'J'; break;
698 case BuiltinType::ULong: Out << 'K'; break;
699 case BuiltinType::Float: Out << 'M'; break;
700 case BuiltinType::Double: Out << 'N'; break;
701 // TODO: Determine size and mangle accordingly
702 case BuiltinType::LongDouble: Out << 'O'; break;
703 case BuiltinType::LongLong: Out << "_J"; break;
704 case BuiltinType::ULongLong: Out << "_K"; break;
705 case BuiltinType::Int128: Out << "_L"; break;
706 case BuiltinType::UInt128: Out << "_M"; break;
707 case BuiltinType::Bool: Out << "_N"; break;
708 case BuiltinType::WChar_S:
709 case BuiltinType::WChar_U: Out << "_W"; break;
710
711 case BuiltinType::Overload:
712 case BuiltinType::Dependent:
713 case BuiltinType::UnknownAny:
714 case BuiltinType::BoundMember:
715 assert(false &&
716 "Overloaded and dependent types shouldn't get to name mangling");
717 break;
718 case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break;
719 case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break;
720 case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break;
721
722 case BuiltinType::Char16:
723 case BuiltinType::Char32:
724 case BuiltinType::NullPtr:
725 assert(false && "Don't know how to mangle this type");
726 break;
727 }
728 }
729
730 // <type> ::= <function-type>
mangleType(const FunctionProtoType * T)731 void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T) {
732 // Structors only appear in decls, so at this point we know it's not a
733 // structor type.
734 // I'll probably have mangleType(MemberPointerType) call the mangleType()
735 // method directly.
736 mangleType(T, NULL, false, false);
737 }
mangleType(const FunctionNoProtoType * T)738 void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T) {
739 llvm_unreachable("Can't mangle K&R function prototypes");
740 }
741
mangleType(const FunctionType * T,const FunctionDecl * D,bool IsStructor,bool IsInstMethod)742 void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
743 const FunctionDecl *D,
744 bool IsStructor,
745 bool IsInstMethod) {
746 // <function-type> ::= <this-cvr-qualifiers> <calling-convention>
747 // <return-type> <argument-list> <throw-spec>
748 const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
749
750 // If this is a C++ instance method, mangle the CVR qualifiers for the
751 // this pointer.
752 if (IsInstMethod)
753 mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
754
755 mangleCallingConvention(T, IsInstMethod);
756
757 // <return-type> ::= <type>
758 // ::= @ # structors (they have no declared return type)
759 if (IsStructor)
760 Out << '@';
761 else
762 mangleType(Proto->getResultType());
763
764 // <argument-list> ::= X # void
765 // ::= <type>+ @
766 // ::= <type>* Z # varargs
767 if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
768 Out << 'X';
769 } else {
770 if (D) {
771 // If we got a decl, use the "types-as-written" to make sure arrays
772 // get mangled right.
773 for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
774 ParmEnd = D->param_end();
775 Parm != ParmEnd; ++Parm)
776 mangleType((*Parm)->getTypeSourceInfo()->getType());
777 } else {
778 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
779 ArgEnd = Proto->arg_type_end();
780 Arg != ArgEnd; ++Arg)
781 mangleType(*Arg);
782 }
783 // <builtin-type> ::= Z # ellipsis
784 if (Proto->isVariadic())
785 Out << 'Z';
786 else
787 Out << '@';
788 }
789
790 mangleThrowSpecification(Proto);
791 }
792
mangleFunctionClass(const FunctionDecl * FD)793 void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
794 // <function-class> ::= A # private: near
795 // ::= B # private: far
796 // ::= C # private: static near
797 // ::= D # private: static far
798 // ::= E # private: virtual near
799 // ::= F # private: virtual far
800 // ::= G # private: thunk near
801 // ::= H # private: thunk far
802 // ::= I # protected: near
803 // ::= J # protected: far
804 // ::= K # protected: static near
805 // ::= L # protected: static far
806 // ::= M # protected: virtual near
807 // ::= N # protected: virtual far
808 // ::= O # protected: thunk near
809 // ::= P # protected: thunk far
810 // ::= Q # public: near
811 // ::= R # public: far
812 // ::= S # public: static near
813 // ::= T # public: static far
814 // ::= U # public: virtual near
815 // ::= V # public: virtual far
816 // ::= W # public: thunk near
817 // ::= X # public: thunk far
818 // ::= Y # global near
819 // ::= Z # global far
820 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
821 switch (MD->getAccess()) {
822 default:
823 case AS_private:
824 if (MD->isStatic())
825 Out << 'C';
826 else if (MD->isVirtual())
827 Out << 'E';
828 else
829 Out << 'A';
830 break;
831 case AS_protected:
832 if (MD->isStatic())
833 Out << 'K';
834 else if (MD->isVirtual())
835 Out << 'M';
836 else
837 Out << 'I';
838 break;
839 case AS_public:
840 if (MD->isStatic())
841 Out << 'S';
842 else if (MD->isVirtual())
843 Out << 'U';
844 else
845 Out << 'Q';
846 }
847 } else
848 Out << 'Y';
849 }
mangleCallingConvention(const FunctionType * T,bool IsInstMethod)850 void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T,
851 bool IsInstMethod) {
852 // <calling-convention> ::= A # __cdecl
853 // ::= B # __export __cdecl
854 // ::= C # __pascal
855 // ::= D # __export __pascal
856 // ::= E # __thiscall
857 // ::= F # __export __thiscall
858 // ::= G # __stdcall
859 // ::= H # __export __stdcall
860 // ::= I # __fastcall
861 // ::= J # __export __fastcall
862 // The 'export' calling conventions are from a bygone era
863 // (*cough*Win16*cough*) when functions were declared for export with
864 // that keyword. (It didn't actually export them, it just made them so
865 // that they could be in a DLL and somebody from another module could call
866 // them.)
867 CallingConv CC = T->getCallConv();
868 if (CC == CC_Default)
869 CC = IsInstMethod ? getASTContext().getDefaultMethodCallConv() : CC_C;
870 switch (CC) {
871 default:
872 assert(0 && "Unsupported CC for mangling");
873 case CC_Default:
874 case CC_C: Out << 'A'; break;
875 case CC_X86Pascal: Out << 'C'; break;
876 case CC_X86ThisCall: Out << 'E'; break;
877 case CC_X86StdCall: Out << 'G'; break;
878 case CC_X86FastCall: Out << 'I'; break;
879 }
880 }
mangleThrowSpecification(const FunctionProtoType * FT)881 void MicrosoftCXXNameMangler::mangleThrowSpecification(
882 const FunctionProtoType *FT) {
883 // <throw-spec> ::= Z # throw(...) (default)
884 // ::= @ # throw() or __declspec/__attribute__((nothrow))
885 // ::= <type>+
886 // NOTE: Since the Microsoft compiler ignores throw specifications, they are
887 // all actually mangled as 'Z'. (They're ignored because their associated
888 // functionality isn't implemented, and probably never will be.)
889 Out << 'Z';
890 }
891
mangleType(const UnresolvedUsingType * T)892 void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T) {
893 assert(false && "Don't know how to mangle UnresolvedUsingTypes yet!");
894 }
895
896 // <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
897 // <union-type> ::= T <name>
898 // <struct-type> ::= U <name>
899 // <class-type> ::= V <name>
900 // <enum-type> ::= W <size> <name>
mangleType(const EnumType * T)901 void MicrosoftCXXNameMangler::mangleType(const EnumType *T) {
902 mangleType(static_cast<const TagType*>(T));
903 }
mangleType(const RecordType * T)904 void MicrosoftCXXNameMangler::mangleType(const RecordType *T) {
905 mangleType(static_cast<const TagType*>(T));
906 }
mangleType(const TagType * T)907 void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
908 switch (T->getDecl()->getTagKind()) {
909 case TTK_Union:
910 Out << 'T';
911 break;
912 case TTK_Struct:
913 Out << 'U';
914 break;
915 case TTK_Class:
916 Out << 'V';
917 break;
918 case TTK_Enum:
919 Out << 'W';
920 Out << getASTContext().getTypeSizeInChars(
921 cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity();
922 break;
923 }
924 mangleName(T->getDecl());
925 }
926
927 // <type> ::= <array-type>
928 // <array-type> ::= P <cvr-qualifiers> [Y <dimension-count> <dimension>+]
929 // <element-type> # as global
930 // ::= Q <cvr-qualifiers> [Y <dimension-count> <dimension>+]
931 // <element-type> # as param
932 // It's supposed to be the other way around, but for some strange reason, it
933 // isn't. Today this behavior is retained for the sole purpose of backwards
934 // compatibility.
mangleType(const ArrayType * T,bool IsGlobal)935 void MicrosoftCXXNameMangler::mangleType(const ArrayType *T, bool IsGlobal) {
936 // This isn't a recursive mangling, so now we have to do it all in this
937 // one call.
938 if (IsGlobal)
939 Out << 'P';
940 else
941 Out << 'Q';
942 mangleExtraDimensions(T->getElementType());
943 }
mangleType(const ConstantArrayType * T)944 void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T) {
945 mangleType(static_cast<const ArrayType *>(T), false);
946 }
mangleType(const VariableArrayType * T)947 void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T) {
948 mangleType(static_cast<const ArrayType *>(T), false);
949 }
mangleType(const DependentSizedArrayType * T)950 void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T) {
951 mangleType(static_cast<const ArrayType *>(T), false);
952 }
mangleType(const IncompleteArrayType * T)953 void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T) {
954 mangleType(static_cast<const ArrayType *>(T), false);
955 }
mangleExtraDimensions(QualType ElementTy)956 void MicrosoftCXXNameMangler::mangleExtraDimensions(QualType ElementTy) {
957 llvm::SmallVector<llvm::APInt, 3> Dimensions;
958 for (;;) {
959 if (ElementTy->isConstantArrayType()) {
960 const ConstantArrayType *CAT =
961 static_cast<const ConstantArrayType *>(ElementTy.getTypePtr());
962 Dimensions.push_back(CAT->getSize());
963 ElementTy = CAT->getElementType();
964 } else if (ElementTy->isVariableArrayType()) {
965 assert(false && "Don't know how to mangle VLAs!");
966 } else if (ElementTy->isDependentSizedArrayType()) {
967 // The dependent expression has to be folded into a constant (TODO).
968 assert(false && "Don't know how to mangle dependent-sized arrays!");
969 } else if (ElementTy->isIncompleteArrayType()) continue;
970 else break;
971 }
972 mangleQualifiers(ElementTy.getQualifiers(), false);
973 // If there are any additional dimensions, mangle them now.
974 if (Dimensions.size() > 0) {
975 Out << 'Y';
976 // <dimension-count> ::= <number> # number of extra dimensions
977 mangleNumber(Dimensions.size());
978 for (unsigned Dim = 0; Dim < Dimensions.size(); ++Dim) {
979 mangleNumber(Dimensions[Dim].getLimitedValue());
980 }
981 }
982 mangleType(ElementTy.getLocalUnqualifiedType());
983 }
984
985 // <type> ::= <pointer-to-member-type>
986 // <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
987 // <class name> <type>
mangleType(const MemberPointerType * T)988 void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T) {
989 QualType PointeeType = T->getPointeeType();
990 if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
991 Out << '8';
992 mangleName(cast<RecordType>(T->getClass())->getDecl());
993 mangleType(FPT, NULL, false, true);
994 } else {
995 mangleQualifiers(PointeeType.getQualifiers(), true);
996 mangleName(cast<RecordType>(T->getClass())->getDecl());
997 mangleType(PointeeType.getLocalUnqualifiedType());
998 }
999 }
1000
mangleType(const TemplateTypeParmType * T)1001 void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T) {
1002 assert(false && "Don't know how to mangle TemplateTypeParmTypes yet!");
1003 }
1004
mangleType(const SubstTemplateTypeParmPackType * T)1005 void MicrosoftCXXNameMangler::mangleType(
1006 const SubstTemplateTypeParmPackType *T) {
1007 assert(false &&
1008 "Don't know how to mangle SubstTemplateTypeParmPackTypes yet!");
1009 }
1010
1011 // <type> ::= <pointer-type>
1012 // <pointer-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
mangleType(const PointerType * T)1013 void MicrosoftCXXNameMangler::mangleType(const PointerType *T) {
1014 QualType PointeeTy = T->getPointeeType();
1015 if (PointeeTy->isArrayType()) {
1016 // Pointers to arrays are mangled like arrays.
1017 mangleExtraDimensions(T->getPointeeType());
1018 } else if (PointeeTy->isFunctionType()) {
1019 // Function pointers are special.
1020 Out << '6';
1021 mangleType(static_cast<const FunctionType *>(PointeeTy.getTypePtr()),
1022 NULL, false, false);
1023 } else {
1024 if (!PointeeTy.hasQualifiers())
1025 // Lack of qualifiers is mangled as 'A'.
1026 Out << 'A';
1027 mangleType(PointeeTy);
1028 }
1029 }
mangleType(const ObjCObjectPointerType * T)1030 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
1031 // Object pointers never have qualifiers.
1032 Out << 'A';
1033 mangleType(T->getPointeeType());
1034 }
1035
1036 // <type> ::= <reference-type>
1037 // <reference-type> ::= A <cvr-qualifiers> <type>
mangleType(const LValueReferenceType * T)1038 void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T) {
1039 Out << 'A';
1040 QualType PointeeTy = T->getPointeeType();
1041 if (!PointeeTy.hasQualifiers())
1042 // Lack of qualifiers is mangled as 'A'.
1043 Out << 'A';
1044 mangleType(PointeeTy);
1045 }
1046
mangleType(const RValueReferenceType * T)1047 void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T) {
1048 assert(false && "Don't know how to mangle RValueReferenceTypes yet!");
1049 }
1050
mangleType(const ComplexType * T)1051 void MicrosoftCXXNameMangler::mangleType(const ComplexType *T) {
1052 assert(false && "Don't know how to mangle ComplexTypes yet!");
1053 }
1054
mangleType(const VectorType * T)1055 void MicrosoftCXXNameMangler::mangleType(const VectorType *T) {
1056 assert(false && "Don't know how to mangle VectorTypes yet!");
1057 }
mangleType(const ExtVectorType * T)1058 void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T) {
1059 assert(false && "Don't know how to mangle ExtVectorTypes yet!");
1060 }
mangleType(const DependentSizedExtVectorType * T)1061 void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
1062 assert(false && "Don't know how to mangle DependentSizedExtVectorTypes yet!");
1063 }
1064
mangleType(const ObjCInterfaceType * T)1065 void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T) {
1066 // ObjC interfaces have structs underlying them.
1067 Out << 'U';
1068 mangleName(T->getDecl());
1069 }
1070
mangleType(const ObjCObjectType * T)1071 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T) {
1072 // We don't allow overloading by different protocol qualification,
1073 // so mangling them isn't necessary.
1074 mangleType(T->getBaseType());
1075 }
1076
mangleType(const BlockPointerType * T)1077 void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T) {
1078 Out << "_E";
1079 mangleType(T->getPointeeType());
1080 }
1081
mangleType(const InjectedClassNameType * T)1082 void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T) {
1083 assert(false && "Don't know how to mangle InjectedClassNameTypes yet!");
1084 }
1085
mangleType(const TemplateSpecializationType * T)1086 void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T) {
1087 assert(false && "Don't know how to mangle TemplateSpecializationTypes yet!");
1088 }
1089
mangleType(const DependentNameType * T)1090 void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T) {
1091 assert(false && "Don't know how to mangle DependentNameTypes yet!");
1092 }
1093
mangleType(const DependentTemplateSpecializationType * T)1094 void MicrosoftCXXNameMangler::mangleType(
1095 const DependentTemplateSpecializationType *T) {
1096 assert(false &&
1097 "Don't know how to mangle DependentTemplateSpecializationTypes yet!");
1098 }
1099
mangleType(const PackExpansionType * T)1100 void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T) {
1101 assert(false && "Don't know how to mangle PackExpansionTypes yet!");
1102 }
1103
mangleType(const TypeOfType * T)1104 void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T) {
1105 assert(false && "Don't know how to mangle TypeOfTypes yet!");
1106 }
1107
mangleType(const TypeOfExprType * T)1108 void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T) {
1109 assert(false && "Don't know how to mangle TypeOfExprTypes yet!");
1110 }
1111
mangleType(const DecltypeType * T)1112 void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T) {
1113 assert(false && "Don't know how to mangle DecltypeTypes yet!");
1114 }
1115
mangleType(const UnaryTransformType * T)1116 void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T) {
1117 assert(false && "Don't know how to mangle UnaryTransformationTypes yet!");
1118 }
1119
mangleType(const AutoType * T)1120 void MicrosoftCXXNameMangler::mangleType(const AutoType *T) {
1121 assert(false && "Don't know how to mangle AutoTypes yet!");
1122 }
1123
mangleName(const NamedDecl * D,llvm::raw_ostream & Out)1124 void MicrosoftMangleContext::mangleName(const NamedDecl *D,
1125 llvm::raw_ostream &Out) {
1126 assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
1127 "Invalid mangleName() call, argument is not a variable or function!");
1128 assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
1129 "Invalid mangleName() call on 'structor decl!");
1130
1131 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
1132 getASTContext().getSourceManager(),
1133 "Mangling declaration");
1134
1135 MicrosoftCXXNameMangler Mangler(*this, Out);
1136 return Mangler.mangle(D);
1137 }
mangleThunk(const CXXMethodDecl * MD,const ThunkInfo & Thunk,llvm::raw_ostream &)1138 void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD,
1139 const ThunkInfo &Thunk,
1140 llvm::raw_ostream &) {
1141 assert(false && "Can't yet mangle thunks!");
1142 }
mangleCXXDtorThunk(const CXXDestructorDecl * DD,CXXDtorType Type,const ThisAdjustment &,llvm::raw_ostream &)1143 void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
1144 CXXDtorType Type,
1145 const ThisAdjustment &,
1146 llvm::raw_ostream &) {
1147 assert(false && "Can't yet mangle destructor thunks!");
1148 }
mangleCXXVTable(const CXXRecordDecl * RD,llvm::raw_ostream &)1149 void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
1150 llvm::raw_ostream &) {
1151 assert(false && "Can't yet mangle virtual tables!");
1152 }
mangleCXXVTT(const CXXRecordDecl * RD,llvm::raw_ostream &)1153 void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
1154 llvm::raw_ostream &) {
1155 llvm_unreachable("The MS C++ ABI does not have virtual table tables!");
1156 }
mangleCXXCtorVTable(const CXXRecordDecl * RD,int64_t Offset,const CXXRecordDecl * Type,llvm::raw_ostream &)1157 void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
1158 int64_t Offset,
1159 const CXXRecordDecl *Type,
1160 llvm::raw_ostream &) {
1161 llvm_unreachable("The MS C++ ABI does not have constructor vtables!");
1162 }
mangleCXXRTTI(QualType T,llvm::raw_ostream &)1163 void MicrosoftMangleContext::mangleCXXRTTI(QualType T,
1164 llvm::raw_ostream &) {
1165 assert(false && "Can't yet mangle RTTI!");
1166 }
mangleCXXRTTIName(QualType T,llvm::raw_ostream &)1167 void MicrosoftMangleContext::mangleCXXRTTIName(QualType T,
1168 llvm::raw_ostream &) {
1169 assert(false && "Can't yet mangle RTTI names!");
1170 }
mangleCXXCtor(const CXXConstructorDecl * D,CXXCtorType Type,llvm::raw_ostream &)1171 void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
1172 CXXCtorType Type,
1173 llvm::raw_ostream &) {
1174 assert(false && "Can't yet mangle constructors!");
1175 }
mangleCXXDtor(const CXXDestructorDecl * D,CXXDtorType Type,llvm::raw_ostream &)1176 void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
1177 CXXDtorType Type,
1178 llvm::raw_ostream &) {
1179 assert(false && "Can't yet mangle destructors!");
1180 }
mangleReferenceTemporary(const clang::VarDecl *,llvm::raw_ostream &)1181 void MicrosoftMangleContext::mangleReferenceTemporary(const clang::VarDecl *,
1182 llvm::raw_ostream &) {
1183 assert(false && "Can't yet mangle reference temporaries!");
1184 }
1185
createMicrosoftMangleContext(ASTContext & Context,Diagnostic & Diags)1186 MangleContext *clang::createMicrosoftMangleContext(ASTContext &Context,
1187 Diagnostic &Diags) {
1188 return new MicrosoftMangleContext(Context, Diags);
1189 }
1190