MicrosoftMangle.cpp revision e0a22d06888c13989b3f72db319f1d498bf69153
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
24using namespace clang;
25
26namespace {
27
28/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
29/// Microsoft Visual C++ ABI.
30class MicrosoftCXXNameMangler {
31  MangleContext &Context;
32  raw_ostream &Out;
33
34  ASTContext &getASTContext() const { return Context.getASTContext(); }
35
36public:
37  MicrosoftCXXNameMangler(MangleContext &C, raw_ostream &Out_)
38  : Context(C), Out(Out_) { }
39
40  void mangle(const NamedDecl *D, 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
47private:
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.
78class MicrosoftMangleContext : public MangleContext {
79public:
80  MicrosoftMangleContext(ASTContext &Context,
81                   DiagnosticsEngine &Diags) : MangleContext(Context, Diags) { }
82  virtual bool shouldMangleDeclName(const NamedDecl *D);
83  virtual void mangleName(const NamedDecl *D, raw_ostream &Out);
84  virtual void mangleThunk(const CXXMethodDecl *MD,
85                           const ThunkInfo &Thunk,
86                           raw_ostream &);
87  virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
88                                  const ThisAdjustment &ThisAdjustment,
89                                  raw_ostream &);
90  virtual void mangleCXXVTable(const CXXRecordDecl *RD,
91                               raw_ostream &);
92  virtual void mangleCXXVTT(const CXXRecordDecl *RD,
93                            raw_ostream &);
94  virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
95                                   const CXXRecordDecl *Type,
96                                   raw_ostream &);
97  virtual void mangleCXXRTTI(QualType T, raw_ostream &);
98  virtual void mangleCXXRTTIName(QualType T, raw_ostream &);
99  virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
100                             raw_ostream &);
101  virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
102                             raw_ostream &);
103  virtual void mangleReferenceTemporary(const clang::VarDecl *,
104                                        raw_ostream &);
105};
106
107}
108
109static 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
120bool 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
156void MicrosoftCXXNameMangler::mangle(const NamedDecl *D,
157                                     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
182void 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
208void 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
249void 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
268void 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
292void
293MicrosoftCXXNameMangler::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      llvm_unreachable("Can't mangle Objective-C selector names here!");
336
337    case DeclarationName::CXXConstructorName:
338      llvm_unreachable("Can't mangle constructors yet!");
339
340    case DeclarationName::CXXDestructorName:
341      llvm_unreachable("Can't mangle destructors yet!");
342
343    case DeclarationName::CXXConversionFunctionName:
344      // <operator-name> ::= ?B # (cast)
345      // The target type is encoded as the return type.
346      Out << "?B";
347      break;
348
349    case DeclarationName::CXXOperatorName:
350      mangleOperatorName(Name.getCXXOverloadedOperator());
351      break;
352
353    case DeclarationName::CXXLiteralOperatorName:
354      // FIXME: Was this added in VS2010? Does MS even know how to mangle this?
355      llvm_unreachable("Don't know how to mangle literal operators yet!");
356
357    case DeclarationName::CXXUsingDirective:
358      llvm_unreachable("Can't mangle a using directive name!");
359  }
360}
361
362void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC,
363                                            bool NoFunction) {
364  // <postfix> ::= <unqualified-name> [<postfix>]
365  //           ::= <template-postfix> <template-args> [<postfix>]
366  //           ::= <template-param>
367  //           ::= <substitution> [<postfix>]
368
369  if (!DC) return;
370
371  while (isa<LinkageSpecDecl>(DC))
372    DC = DC->getParent();
373
374  if (DC->isTranslationUnit())
375    return;
376
377  if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
378    Context.mangleBlock(BD, Out);
379    Out << '@';
380    return manglePostfix(DC->getParent(), NoFunction);
381  }
382
383  if (NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)))
384    return;
385  else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC))
386    mangleObjCMethodName(Method);
387  else {
388    mangleUnqualifiedName(cast<NamedDecl>(DC));
389    manglePostfix(DC->getParent(), NoFunction);
390  }
391}
392
393void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO) {
394  switch (OO) {
395  //                     ?0 # constructor
396  //                     ?1 # destructor
397  // <operator-name> ::= ?2 # new
398  case OO_New: Out << "?2"; break;
399  // <operator-name> ::= ?3 # delete
400  case OO_Delete: Out << "?3"; break;
401  // <operator-name> ::= ?4 # =
402  case OO_Equal: Out << "?4"; break;
403  // <operator-name> ::= ?5 # >>
404  case OO_GreaterGreater: Out << "?5"; break;
405  // <operator-name> ::= ?6 # <<
406  case OO_LessLess: Out << "?6"; break;
407  // <operator-name> ::= ?7 # !
408  case OO_Exclaim: Out << "?7"; break;
409  // <operator-name> ::= ?8 # ==
410  case OO_EqualEqual: Out << "?8"; break;
411  // <operator-name> ::= ?9 # !=
412  case OO_ExclaimEqual: Out << "?9"; break;
413  // <operator-name> ::= ?A # []
414  case OO_Subscript: Out << "?A"; break;
415  //                     ?B # conversion
416  // <operator-name> ::= ?C # ->
417  case OO_Arrow: Out << "?C"; break;
418  // <operator-name> ::= ?D # *
419  case OO_Star: Out << "?D"; break;
420  // <operator-name> ::= ?E # ++
421  case OO_PlusPlus: Out << "?E"; break;
422  // <operator-name> ::= ?F # --
423  case OO_MinusMinus: Out << "?F"; break;
424  // <operator-name> ::= ?G # -
425  case OO_Minus: Out << "?G"; break;
426  // <operator-name> ::= ?H # +
427  case OO_Plus: Out << "?H"; break;
428  // <operator-name> ::= ?I # &
429  case OO_Amp: Out << "?I"; break;
430  // <operator-name> ::= ?J # ->*
431  case OO_ArrowStar: Out << "?J"; break;
432  // <operator-name> ::= ?K # /
433  case OO_Slash: Out << "?K"; break;
434  // <operator-name> ::= ?L # %
435  case OO_Percent: Out << "?L"; break;
436  // <operator-name> ::= ?M # <
437  case OO_Less: Out << "?M"; break;
438  // <operator-name> ::= ?N # <=
439  case OO_LessEqual: Out << "?N"; break;
440  // <operator-name> ::= ?O # >
441  case OO_Greater: Out << "?O"; break;
442  // <operator-name> ::= ?P # >=
443  case OO_GreaterEqual: Out << "?P"; break;
444  // <operator-name> ::= ?Q # ,
445  case OO_Comma: Out << "?Q"; break;
446  // <operator-name> ::= ?R # ()
447  case OO_Call: Out << "?R"; break;
448  // <operator-name> ::= ?S # ~
449  case OO_Tilde: Out << "?S"; break;
450  // <operator-name> ::= ?T # ^
451  case OO_Caret: Out << "?T"; break;
452  // <operator-name> ::= ?U # |
453  case OO_Pipe: Out << "?U"; break;
454  // <operator-name> ::= ?V # &&
455  case OO_AmpAmp: Out << "?V"; break;
456  // <operator-name> ::= ?W # ||
457  case OO_PipePipe: Out << "?W"; break;
458  // <operator-name> ::= ?X # *=
459  case OO_StarEqual: Out << "?X"; break;
460  // <operator-name> ::= ?Y # +=
461  case OO_PlusEqual: Out << "?Y"; break;
462  // <operator-name> ::= ?Z # -=
463  case OO_MinusEqual: Out << "?Z"; break;
464  // <operator-name> ::= ?_0 # /=
465  case OO_SlashEqual: Out << "?_0"; break;
466  // <operator-name> ::= ?_1 # %=
467  case OO_PercentEqual: Out << "?_1"; break;
468  // <operator-name> ::= ?_2 # >>=
469  case OO_GreaterGreaterEqual: Out << "?_2"; break;
470  // <operator-name> ::= ?_3 # <<=
471  case OO_LessLessEqual: Out << "?_3"; break;
472  // <operator-name> ::= ?_4 # &=
473  case OO_AmpEqual: Out << "?_4"; break;
474  // <operator-name> ::= ?_5 # |=
475  case OO_PipeEqual: Out << "?_5"; break;
476  // <operator-name> ::= ?_6 # ^=
477  case OO_CaretEqual: Out << "?_6"; break;
478  //                     ?_7 # vftable
479  //                     ?_8 # vbtable
480  //                     ?_9 # vcall
481  //                     ?_A # typeof
482  //                     ?_B # local static guard
483  //                     ?_C # string
484  //                     ?_D # vbase destructor
485  //                     ?_E # vector deleting destructor
486  //                     ?_F # default constructor closure
487  //                     ?_G # scalar deleting destructor
488  //                     ?_H # vector constructor iterator
489  //                     ?_I # vector destructor iterator
490  //                     ?_J # vector vbase constructor iterator
491  //                     ?_K # virtual displacement map
492  //                     ?_L # eh vector constructor iterator
493  //                     ?_M # eh vector destructor iterator
494  //                     ?_N # eh vector vbase constructor iterator
495  //                     ?_O # copy constructor closure
496  //                     ?_P<name> # udt returning <name>
497  //                     ?_Q # <unknown>
498  //                     ?_R0 # RTTI Type Descriptor
499  //                     ?_R1 # RTTI Base Class Descriptor at (a,b,c,d)
500  //                     ?_R2 # RTTI Base Class Array
501  //                     ?_R3 # RTTI Class Hierarchy Descriptor
502  //                     ?_R4 # RTTI Complete Object Locator
503  //                     ?_S # local vftable
504  //                     ?_T # local vftable constructor closure
505  // <operator-name> ::= ?_U # new[]
506  case OO_Array_New: Out << "?_U"; break;
507  // <operator-name> ::= ?_V # delete[]
508  case OO_Array_Delete: Out << "?_V"; break;
509
510  case OO_Conditional:
511    llvm_unreachable("Don't know how to mangle ?:");
512
513  case OO_None:
514  case NUM_OVERLOADED_OPERATORS:
515    llvm_unreachable("Not an overloaded operator");
516  }
517}
518
519void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
520  // <source name> ::= <identifier> @
521  Out << II->getName() << '@';
522}
523
524void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
525  Context.mangleObjCMethodName(MD, Out);
526}
527
528void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
529                                               bool IsMember) {
530  // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
531  // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
532  // 'I' means __restrict (32/64-bit).
533  // Note that the MSVC __restrict keyword isn't the same as the C99 restrict
534  // keyword!
535  // <base-cvr-qualifiers> ::= A  # near
536  //                       ::= B  # near const
537  //                       ::= C  # near volatile
538  //                       ::= D  # near const volatile
539  //                       ::= E  # far (16-bit)
540  //                       ::= F  # far const (16-bit)
541  //                       ::= G  # far volatile (16-bit)
542  //                       ::= H  # far const volatile (16-bit)
543  //                       ::= I  # huge (16-bit)
544  //                       ::= J  # huge const (16-bit)
545  //                       ::= K  # huge volatile (16-bit)
546  //                       ::= L  # huge const volatile (16-bit)
547  //                       ::= M <basis> # based
548  //                       ::= N <basis> # based const
549  //                       ::= O <basis> # based volatile
550  //                       ::= P <basis> # based const volatile
551  //                       ::= Q  # near member
552  //                       ::= R  # near const member
553  //                       ::= S  # near volatile member
554  //                       ::= T  # near const volatile member
555  //                       ::= U  # far member (16-bit)
556  //                       ::= V  # far const member (16-bit)
557  //                       ::= W  # far volatile member (16-bit)
558  //                       ::= X  # far const volatile member (16-bit)
559  //                       ::= Y  # huge member (16-bit)
560  //                       ::= Z  # huge const member (16-bit)
561  //                       ::= 0  # huge volatile member (16-bit)
562  //                       ::= 1  # huge const volatile member (16-bit)
563  //                       ::= 2 <basis> # based member
564  //                       ::= 3 <basis> # based const member
565  //                       ::= 4 <basis> # based volatile member
566  //                       ::= 5 <basis> # based const volatile member
567  //                       ::= 6  # near function (pointers only)
568  //                       ::= 7  # far function (pointers only)
569  //                       ::= 8  # near method (pointers only)
570  //                       ::= 9  # far method (pointers only)
571  //                       ::= _A <basis> # based function (pointers only)
572  //                       ::= _B <basis> # based function (far?) (pointers only)
573  //                       ::= _C <basis> # based method (pointers only)
574  //                       ::= _D <basis> # based method (far?) (pointers only)
575  //                       ::= _E # block (Clang)
576  // <basis> ::= 0 # __based(void)
577  //         ::= 1 # __based(segment)?
578  //         ::= 2 <name> # __based(name)
579  //         ::= 3 # ?
580  //         ::= 4 # ?
581  //         ::= 5 # not really based
582  if (!IsMember) {
583    if (!Quals.hasVolatile()) {
584      if (!Quals.hasConst())
585        Out << 'A';
586      else
587        Out << 'B';
588    } else {
589      if (!Quals.hasConst())
590        Out << 'C';
591      else
592        Out << 'D';
593    }
594  } else {
595    if (!Quals.hasVolatile()) {
596      if (!Quals.hasConst())
597        Out << 'Q';
598      else
599        Out << 'R';
600    } else {
601      if (!Quals.hasConst())
602        Out << 'S';
603      else
604        Out << 'T';
605    }
606  }
607
608  // FIXME: For now, just drop all extension qualifiers on the floor.
609}
610
611void MicrosoftCXXNameMangler::mangleType(QualType T) {
612  // Only operate on the canonical type!
613  T = getASTContext().getCanonicalType(T);
614
615  Qualifiers Quals = T.getLocalQualifiers();
616  if (Quals) {
617    // We have to mangle these now, while we still have enough information.
618    // <pointer-cvr-qualifiers> ::= P  # pointer
619    //                          ::= Q  # const pointer
620    //                          ::= R  # volatile pointer
621    //                          ::= S  # const volatile pointer
622    if (T->isAnyPointerType() || T->isMemberPointerType() ||
623        T->isBlockPointerType()) {
624      if (!Quals.hasVolatile())
625        Out << 'Q';
626      else {
627        if (!Quals.hasConst())
628          Out << 'R';
629        else
630          Out << 'S';
631      }
632    } else
633      // Just emit qualifiers like normal.
634      // NB: When we mangle a pointer/reference type, and the pointee
635      // type has no qualifiers, the lack of qualifier gets mangled
636      // in there.
637      mangleQualifiers(Quals, false);
638  } else if (T->isAnyPointerType() || T->isMemberPointerType() ||
639             T->isBlockPointerType()) {
640    Out << 'P';
641  }
642  switch (T->getTypeClass()) {
643#define ABSTRACT_TYPE(CLASS, PARENT)
644#define NON_CANONICAL_TYPE(CLASS, PARENT) \
645case Type::CLASS: \
646llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
647return;
648#define TYPE(CLASS, PARENT) \
649case Type::CLASS: \
650mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \
651break;
652#include "clang/AST/TypeNodes.def"
653  }
654}
655
656void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T) {
657  //  <type>         ::= <builtin-type>
658  //  <builtin-type> ::= X  # void
659  //                 ::= C  # signed char
660  //                 ::= D  # char
661  //                 ::= E  # unsigned char
662  //                 ::= F  # short
663  //                 ::= G  # unsigned short (or wchar_t if it's not a builtin)
664  //                 ::= H  # int
665  //                 ::= I  # unsigned int
666  //                 ::= J  # long
667  //                 ::= K  # unsigned long
668  //                     L  # <none>
669  //                 ::= M  # float
670  //                 ::= N  # double
671  //                 ::= O  # long double (__float80 is mangled differently)
672  //                 ::= _J # long long, __int64
673  //                 ::= _K # unsigned long long, __int64
674  //                 ::= _L # __int128
675  //                 ::= _M # unsigned __int128
676  //                 ::= _N # bool
677  //                     _O # <array in parameter>
678  //                 ::= _T # __float80 (Intel)
679  //                 ::= _W # wchar_t
680  //                 ::= _Z # __float80 (Digital Mars)
681  switch (T->getKind()) {
682  case BuiltinType::Void: Out << 'X'; break;
683  case BuiltinType::SChar: Out << 'C'; break;
684  case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break;
685  case BuiltinType::UChar: Out << 'E'; break;
686  case BuiltinType::Short: Out << 'F'; break;
687  case BuiltinType::UShort: Out << 'G'; break;
688  case BuiltinType::Int: Out << 'H'; break;
689  case BuiltinType::UInt: Out << 'I'; break;
690  case BuiltinType::Long: Out << 'J'; break;
691  case BuiltinType::ULong: Out << 'K'; break;
692  case BuiltinType::Float: Out << 'M'; break;
693  case BuiltinType::Double: Out << 'N'; break;
694  // TODO: Determine size and mangle accordingly
695  case BuiltinType::LongDouble: Out << 'O'; break;
696  case BuiltinType::LongLong: Out << "_J"; break;
697  case BuiltinType::ULongLong: Out << "_K"; break;
698  case BuiltinType::Int128: Out << "_L"; break;
699  case BuiltinType::UInt128: Out << "_M"; break;
700  case BuiltinType::Bool: Out << "_N"; break;
701  case BuiltinType::WChar_S:
702  case BuiltinType::WChar_U: Out << "_W"; break;
703
704#define BUILTIN_TYPE(Id, SingletonId)
705#define PLACEHOLDER_TYPE(Id, SingletonId) \
706  case BuiltinType::Id:
707#include "clang/AST/BuiltinTypes.def"
708  case BuiltinType::Dependent:
709    llvm_unreachable("placeholder types shouldn't get to name mangling");
710
711  case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break;
712  case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break;
713  case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break;
714
715  case BuiltinType::Char16:
716  case BuiltinType::Char32:
717  case BuiltinType::Half:
718  case BuiltinType::NullPtr:
719    assert(0 && "Don't know how to mangle this type yet");
720  }
721}
722
723// <type>          ::= <function-type>
724void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T) {
725  // Structors only appear in decls, so at this point we know it's not a
726  // structor type.
727  // I'll probably have mangleType(MemberPointerType) call the mangleType()
728  // method directly.
729  mangleType(T, NULL, false, false);
730}
731void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T) {
732  llvm_unreachable("Can't mangle K&R function prototypes");
733}
734
735void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
736                                         const FunctionDecl *D,
737                                         bool IsStructor,
738                                         bool IsInstMethod) {
739  // <function-type> ::= <this-cvr-qualifiers> <calling-convention>
740  //                     <return-type> <argument-list> <throw-spec>
741  const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
742
743  // If this is a C++ instance method, mangle the CVR qualifiers for the
744  // this pointer.
745  if (IsInstMethod)
746    mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
747
748  mangleCallingConvention(T, IsInstMethod);
749
750  // <return-type> ::= <type>
751  //               ::= @ # structors (they have no declared return type)
752  if (IsStructor)
753    Out << '@';
754  else
755    mangleType(Proto->getResultType());
756
757  // <argument-list> ::= X # void
758  //                 ::= <type>+ @
759  //                 ::= <type>* Z # varargs
760  if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
761    Out << 'X';
762  } else {
763    if (D) {
764      // If we got a decl, use the "types-as-written" to make sure arrays
765      // get mangled right.
766      for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
767           ParmEnd = D->param_end();
768           Parm != ParmEnd; ++Parm)
769        mangleType((*Parm)->getTypeSourceInfo()->getType());
770    } else {
771      for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
772           ArgEnd = Proto->arg_type_end();
773           Arg != ArgEnd; ++Arg)
774        mangleType(*Arg);
775    }
776    // <builtin-type>      ::= Z  # ellipsis
777    if (Proto->isVariadic())
778      Out << 'Z';
779    else
780      Out << '@';
781  }
782
783  mangleThrowSpecification(Proto);
784}
785
786void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
787  // <function-class> ::= A # private: near
788  //                  ::= B # private: far
789  //                  ::= C # private: static near
790  //                  ::= D # private: static far
791  //                  ::= E # private: virtual near
792  //                  ::= F # private: virtual far
793  //                  ::= G # private: thunk near
794  //                  ::= H # private: thunk far
795  //                  ::= I # protected: near
796  //                  ::= J # protected: far
797  //                  ::= K # protected: static near
798  //                  ::= L # protected: static far
799  //                  ::= M # protected: virtual near
800  //                  ::= N # protected: virtual far
801  //                  ::= O # protected: thunk near
802  //                  ::= P # protected: thunk far
803  //                  ::= Q # public: near
804  //                  ::= R # public: far
805  //                  ::= S # public: static near
806  //                  ::= T # public: static far
807  //                  ::= U # public: virtual near
808  //                  ::= V # public: virtual far
809  //                  ::= W # public: thunk near
810  //                  ::= X # public: thunk far
811  //                  ::= Y # global near
812  //                  ::= Z # global far
813  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
814    switch (MD->getAccess()) {
815      default:
816      case AS_private:
817        if (MD->isStatic())
818          Out << 'C';
819        else if (MD->isVirtual())
820          Out << 'E';
821        else
822          Out << 'A';
823        break;
824      case AS_protected:
825        if (MD->isStatic())
826          Out << 'K';
827        else if (MD->isVirtual())
828          Out << 'M';
829        else
830          Out << 'I';
831        break;
832      case AS_public:
833        if (MD->isStatic())
834          Out << 'S';
835        else if (MD->isVirtual())
836          Out << 'U';
837        else
838          Out << 'Q';
839    }
840  } else
841    Out << 'Y';
842}
843void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T,
844                                                      bool IsInstMethod) {
845  // <calling-convention> ::= A # __cdecl
846  //                      ::= B # __export __cdecl
847  //                      ::= C # __pascal
848  //                      ::= D # __export __pascal
849  //                      ::= E # __thiscall
850  //                      ::= F # __export __thiscall
851  //                      ::= G # __stdcall
852  //                      ::= H # __export __stdcall
853  //                      ::= I # __fastcall
854  //                      ::= J # __export __fastcall
855  // The 'export' calling conventions are from a bygone era
856  // (*cough*Win16*cough*) when functions were declared for export with
857  // that keyword. (It didn't actually export them, it just made them so
858  // that they could be in a DLL and somebody from another module could call
859  // them.)
860  CallingConv CC = T->getCallConv();
861  if (CC == CC_Default)
862    CC = IsInstMethod ? getASTContext().getDefaultMethodCallConv() : CC_C;
863  switch (CC) {
864    default:
865      llvm_unreachable("Unsupported CC for mangling");
866    case CC_Default:
867    case CC_C: Out << 'A'; break;
868    case CC_X86Pascal: Out << 'C'; break;
869    case CC_X86ThisCall: Out << 'E'; break;
870    case CC_X86StdCall: Out << 'G'; break;
871    case CC_X86FastCall: Out << 'I'; break;
872  }
873}
874void MicrosoftCXXNameMangler::mangleThrowSpecification(
875                                                const FunctionProtoType *FT) {
876  // <throw-spec> ::= Z # throw(...) (default)
877  //              ::= @ # throw() or __declspec/__attribute__((nothrow))
878  //              ::= <type>+
879  // NOTE: Since the Microsoft compiler ignores throw specifications, they are
880  // all actually mangled as 'Z'. (They're ignored because their associated
881  // functionality isn't implemented, and probably never will be.)
882  Out << 'Z';
883}
884
885void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T) {
886  llvm_unreachable("Don't know how to mangle UnresolvedUsingTypes yet!");
887}
888
889// <type>        ::= <union-type> | <struct-type> | <class-type> | <enum-type>
890// <union-type>  ::= T <name>
891// <struct-type> ::= U <name>
892// <class-type>  ::= V <name>
893// <enum-type>   ::= W <size> <name>
894void MicrosoftCXXNameMangler::mangleType(const EnumType *T) {
895  mangleType(static_cast<const TagType*>(T));
896}
897void MicrosoftCXXNameMangler::mangleType(const RecordType *T) {
898  mangleType(static_cast<const TagType*>(T));
899}
900void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
901  switch (T->getDecl()->getTagKind()) {
902    case TTK_Union:
903      Out << 'T';
904      break;
905    case TTK_Struct:
906      Out << 'U';
907      break;
908    case TTK_Class:
909      Out << 'V';
910      break;
911    case TTK_Enum:
912      Out << 'W';
913      Out << getASTContext().getTypeSizeInChars(
914                cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity();
915      break;
916  }
917  mangleName(T->getDecl());
918}
919
920// <type>       ::= <array-type>
921// <array-type> ::= P <cvr-qualifiers> [Y <dimension-count> <dimension>+]
922//                                                  <element-type> # as global
923//              ::= Q <cvr-qualifiers> [Y <dimension-count> <dimension>+]
924//                                                  <element-type> # as param
925// It's supposed to be the other way around, but for some strange reason, it
926// isn't. Today this behavior is retained for the sole purpose of backwards
927// compatibility.
928void MicrosoftCXXNameMangler::mangleType(const ArrayType *T, bool IsGlobal) {
929  // This isn't a recursive mangling, so now we have to do it all in this
930  // one call.
931  if (IsGlobal)
932    Out << 'P';
933  else
934    Out << 'Q';
935  mangleExtraDimensions(T->getElementType());
936}
937void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T) {
938  mangleType(static_cast<const ArrayType *>(T), false);
939}
940void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T) {
941  mangleType(static_cast<const ArrayType *>(T), false);
942}
943void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T) {
944  mangleType(static_cast<const ArrayType *>(T), false);
945}
946void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T) {
947  mangleType(static_cast<const ArrayType *>(T), false);
948}
949void MicrosoftCXXNameMangler::mangleExtraDimensions(QualType ElementTy) {
950  SmallVector<llvm::APInt, 3> Dimensions;
951  for (;;) {
952    if (ElementTy->isConstantArrayType()) {
953      const ConstantArrayType *CAT =
954      static_cast<const ConstantArrayType *>(ElementTy.getTypePtr());
955      Dimensions.push_back(CAT->getSize());
956      ElementTy = CAT->getElementType();
957    } else if (ElementTy->isVariableArrayType()) {
958      llvm_unreachable("Don't know how to mangle VLAs!");
959    } else if (ElementTy->isDependentSizedArrayType()) {
960      // The dependent expression has to be folded into a constant (TODO).
961      llvm_unreachable("Don't know how to mangle dependent-sized arrays!");
962    } else if (ElementTy->isIncompleteArrayType()) continue;
963    else break;
964  }
965  mangleQualifiers(ElementTy.getQualifiers(), false);
966  // If there are any additional dimensions, mangle them now.
967  if (Dimensions.size() > 0) {
968    Out << 'Y';
969    // <dimension-count> ::= <number> # number of extra dimensions
970    mangleNumber(Dimensions.size());
971    for (unsigned Dim = 0; Dim < Dimensions.size(); ++Dim) {
972      mangleNumber(Dimensions[Dim].getLimitedValue());
973    }
974  }
975  mangleType(ElementTy.getLocalUnqualifiedType());
976}
977
978// <type>                   ::= <pointer-to-member-type>
979// <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
980//                                                          <class name> <type>
981void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T) {
982  QualType PointeeType = T->getPointeeType();
983  if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
984    Out << '8';
985    mangleName(cast<RecordType>(T->getClass())->getDecl());
986    mangleType(FPT, NULL, false, true);
987  } else {
988    mangleQualifiers(PointeeType.getQualifiers(), true);
989    mangleName(cast<RecordType>(T->getClass())->getDecl());
990    mangleType(PointeeType.getLocalUnqualifiedType());
991  }
992}
993
994void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T) {
995  llvm_unreachable("Don't know how to mangle TemplateTypeParmTypes yet!");
996}
997
998void MicrosoftCXXNameMangler::mangleType(
999                                       const SubstTemplateTypeParmPackType *T) {
1000  llvm_unreachable(
1001         "Don't know how to mangle SubstTemplateTypeParmPackTypes yet!");
1002}
1003
1004// <type> ::= <pointer-type>
1005// <pointer-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
1006void MicrosoftCXXNameMangler::mangleType(const PointerType *T) {
1007  QualType PointeeTy = T->getPointeeType();
1008  if (PointeeTy->isArrayType()) {
1009    // Pointers to arrays are mangled like arrays.
1010    mangleExtraDimensions(T->getPointeeType());
1011  } else if (PointeeTy->isFunctionType()) {
1012    // Function pointers are special.
1013    Out << '6';
1014    mangleType(static_cast<const FunctionType *>(PointeeTy.getTypePtr()),
1015               NULL, false, false);
1016  } else {
1017    if (!PointeeTy.hasQualifiers())
1018      // Lack of qualifiers is mangled as 'A'.
1019      Out << 'A';
1020    mangleType(PointeeTy);
1021  }
1022}
1023void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
1024  // Object pointers never have qualifiers.
1025  Out << 'A';
1026  mangleType(T->getPointeeType());
1027}
1028
1029// <type> ::= <reference-type>
1030// <reference-type> ::= A <cvr-qualifiers> <type>
1031void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T) {
1032  Out << 'A';
1033  QualType PointeeTy = T->getPointeeType();
1034  if (!PointeeTy.hasQualifiers())
1035    // Lack of qualifiers is mangled as 'A'.
1036    Out << 'A';
1037  mangleType(PointeeTy);
1038}
1039
1040void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T) {
1041  llvm_unreachable("Don't know how to mangle RValueReferenceTypes yet!");
1042}
1043
1044void MicrosoftCXXNameMangler::mangleType(const ComplexType *T) {
1045  llvm_unreachable("Don't know how to mangle ComplexTypes yet!");
1046}
1047
1048void MicrosoftCXXNameMangler::mangleType(const VectorType *T) {
1049  llvm_unreachable("Don't know how to mangle VectorTypes yet!");
1050}
1051void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T) {
1052  llvm_unreachable("Don't know how to mangle ExtVectorTypes yet!");
1053}
1054void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
1055  llvm_unreachable(
1056                  "Don't know how to mangle DependentSizedExtVectorTypes yet!");
1057}
1058
1059void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T) {
1060  // ObjC interfaces have structs underlying them.
1061  Out << 'U';
1062  mangleName(T->getDecl());
1063}
1064
1065void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T) {
1066  // We don't allow overloading by different protocol qualification,
1067  // so mangling them isn't necessary.
1068  mangleType(T->getBaseType());
1069}
1070
1071void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T) {
1072  Out << "_E";
1073  mangleType(T->getPointeeType());
1074}
1075
1076void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T) {
1077  llvm_unreachable("Don't know how to mangle InjectedClassNameTypes yet!");
1078}
1079
1080void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T) {
1081  llvm_unreachable("Don't know how to mangle TemplateSpecializationTypes yet!");
1082}
1083
1084void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T) {
1085  llvm_unreachable("Don't know how to mangle DependentNameTypes yet!");
1086}
1087
1088void MicrosoftCXXNameMangler::mangleType(
1089                                 const DependentTemplateSpecializationType *T) {
1090  llvm_unreachable(
1091         "Don't know how to mangle DependentTemplateSpecializationTypes yet!");
1092}
1093
1094void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T) {
1095  llvm_unreachable("Don't know how to mangle PackExpansionTypes yet!");
1096}
1097
1098void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T) {
1099  llvm_unreachable("Don't know how to mangle TypeOfTypes yet!");
1100}
1101
1102void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T) {
1103  llvm_unreachable("Don't know how to mangle TypeOfExprTypes yet!");
1104}
1105
1106void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T) {
1107  llvm_unreachable("Don't know how to mangle DecltypeTypes yet!");
1108}
1109
1110void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T) {
1111  llvm_unreachable("Don't know how to mangle UnaryTransformationTypes yet!");
1112}
1113
1114void MicrosoftCXXNameMangler::mangleType(const AutoType *T) {
1115  llvm_unreachable("Don't know how to mangle AutoTypes yet!");
1116}
1117
1118void MicrosoftCXXNameMangler::mangleType(const AtomicType *T) {
1119  llvm_unreachable("Don't know how to mangle AtomicTypes yet!");
1120}
1121
1122void MicrosoftMangleContext::mangleName(const NamedDecl *D,
1123                                        raw_ostream &Out) {
1124  assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
1125         "Invalid mangleName() call, argument is not a variable or function!");
1126  assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
1127         "Invalid mangleName() call on 'structor decl!");
1128
1129  PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
1130                                 getASTContext().getSourceManager(),
1131                                 "Mangling declaration");
1132
1133  MicrosoftCXXNameMangler Mangler(*this, Out);
1134  return Mangler.mangle(D);
1135}
1136void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD,
1137                                         const ThunkInfo &Thunk,
1138                                         raw_ostream &) {
1139  llvm_unreachable("Can't yet mangle thunks!");
1140}
1141void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
1142                                                CXXDtorType Type,
1143                                                const ThisAdjustment &,
1144                                                raw_ostream &) {
1145  llvm_unreachable("Can't yet mangle destructor thunks!");
1146}
1147void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
1148                                             raw_ostream &) {
1149  llvm_unreachable("Can't yet mangle virtual tables!");
1150}
1151void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
1152                                          raw_ostream &) {
1153  llvm_unreachable("The MS C++ ABI does not have virtual table tables!");
1154}
1155void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
1156                                                 int64_t Offset,
1157                                                 const CXXRecordDecl *Type,
1158                                                 raw_ostream &) {
1159  llvm_unreachable("The MS C++ ABI does not have constructor vtables!");
1160}
1161void MicrosoftMangleContext::mangleCXXRTTI(QualType T,
1162                                           raw_ostream &) {
1163  llvm_unreachable("Can't yet mangle RTTI!");
1164}
1165void MicrosoftMangleContext::mangleCXXRTTIName(QualType T,
1166                                               raw_ostream &) {
1167  llvm_unreachable("Can't yet mangle RTTI names!");
1168}
1169void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
1170                                           CXXCtorType Type,
1171                                           raw_ostream &) {
1172  llvm_unreachable("Can't yet mangle constructors!");
1173}
1174void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
1175                                           CXXDtorType Type,
1176                                           raw_ostream &) {
1177  llvm_unreachable("Can't yet mangle destructors!");
1178}
1179void MicrosoftMangleContext::mangleReferenceTemporary(const clang::VarDecl *,
1180                                                      raw_ostream &) {
1181  llvm_unreachable("Can't yet mangle reference temporaries!");
1182}
1183
1184MangleContext *clang::createMicrosoftMangleContext(ASTContext &Context,
1185                                                   DiagnosticsEngine &Diags) {
1186  return new MicrosoftMangleContext(Context, Diags);
1187}
1188