29 #include "llvm/ADT/StringExtras.h"
30 #include "llvm/Support/MathExtras.h"
32 using namespace clang;
48 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
49 return ContextParam->getDeclContext();
53 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
55 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
56 return ContextParam->getDeclContext();
61 return getEffectiveDeclContext(CD);
67 return getEffectiveDeclContext(cast<Decl>(DC));
71 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND))
72 return FTD->getTemplatedDecl();
74 const auto *FD = cast<FunctionDecl>(ND);
75 if (
const auto *FTD = FD->getPrimaryTemplate())
76 return FTD->getTemplatedDecl();
81 static bool isLambda(
const NamedDecl *ND) {
92 typedef std::pair<const DeclContext *, IdentifierInfo *> DiscriminatorKeyTy;
93 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
94 llvm::DenseMap<const NamedDecl *, unsigned> Uniquifier;
95 llvm::DenseMap<const CXXRecordDecl *, unsigned> LambdaIds;
96 llvm::DenseMap<const NamedDecl *, unsigned> SEHFilterIds;
97 llvm::DenseMap<const NamedDecl *, unsigned> SEHFinallyIds;
102 bool shouldMangleCXXName(
const NamedDecl *D)
override;
103 bool shouldMangleStringLiteral(
const StringLiteral *SL)
override;
104 void mangleCXXName(
const NamedDecl *D, raw_ostream &Out)
override;
106 raw_ostream &)
override;
108 raw_ostream &)
override;
111 raw_ostream &)
override;
114 raw_ostream &Out)
override;
117 raw_ostream &Out)
override;
118 void mangleCXXVirtualDisplacementMap(
const CXXRecordDecl *SrcRD,
120 raw_ostream &Out)
override;
121 void mangleCXXThrowInfo(
QualType T,
bool IsConst,
bool IsVolatile,
122 uint32_t NumEntries, raw_ostream &Out)
override;
123 void mangleCXXCatchableTypeArray(
QualType T, uint32_t NumEntries,
124 raw_ostream &Out)
override;
127 int32_t VBPtrOffset, uint32_t VBIndex,
128 raw_ostream &Out)
override;
129 void mangleCXXCatchHandlerType(
QualType T, uint32_t Flags,
130 raw_ostream &Out)
override;
131 void mangleCXXRTTI(
QualType T, raw_ostream &Out)
override;
132 void mangleCXXRTTIName(
QualType T, raw_ostream &Out)
override;
133 void mangleCXXRTTIBaseClassDescriptor(
const CXXRecordDecl *Derived,
134 uint32_t NVOffset, int32_t VBPtrOffset,
135 uint32_t VBTableOffset, uint32_t Flags,
136 raw_ostream &Out)
override;
137 void mangleCXXRTTIBaseClassArray(
const CXXRecordDecl *Derived,
138 raw_ostream &Out)
override;
139 void mangleCXXRTTIClassHierarchyDescriptor(
const CXXRecordDecl *Derived,
140 raw_ostream &Out)
override;
142 mangleCXXRTTICompleteObjectLocator(
const CXXRecordDecl *Derived,
144 raw_ostream &Out)
override;
145 void mangleTypeName(
QualType T, raw_ostream &)
override;
147 raw_ostream &)
override;
149 raw_ostream &)
override;
150 void mangleReferenceTemporary(
const VarDecl *,
unsigned ManglingNumber,
151 raw_ostream &)
override;
152 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &Out)
override;
153 void mangleThreadSafeStaticGuardVariable(
const VarDecl *D,
unsigned GuardNum,
154 raw_ostream &Out)
override;
155 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
156 void mangleDynamicAtExitDestructor(
const VarDecl *D,
157 raw_ostream &Out)
override;
158 void mangleSEHFilterExpression(
const NamedDecl *EnclosingDecl,
159 raw_ostream &Out)
override;
160 void mangleSEHFinallyBlock(
const NamedDecl *EnclosingDecl,
161 raw_ostream &Out)
override;
162 void mangleStringLiteral(
const StringLiteral *SL, raw_ostream &Out)
override;
164 raw_ostream &Out)
override;
165 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
170 const DeclContext *DC = getEffectiveDeclContext(ND);
176 disc = getASTContext().getManglingNumber(ND);
181 if (
const TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
182 if (Tag->getName().empty() && !Tag->getTypedefNameForAnonDecl())
187 unsigned &discriminator = Uniquifier[ND];
189 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
190 disc = discriminator + 1;
195 assert(RD->
isLambda() &&
"RD must be a lambda!");
198 "RD must not have a mangling number!");
199 std::pair<llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator,
bool>
200 Result = LambdaIds.insert(std::make_pair(RD, LambdaIds.size()));
201 return Result.first->second;
205 void mangleInitFiniStub(
const VarDecl *D, raw_ostream &Out,
char CharCode);
210 class MicrosoftCXXNameMangler {
211 MicrosoftMangleContextImpl &
Context;
221 BackRefVec NameBackReferences;
223 typedef llvm::DenseMap<void *, unsigned> ArgBackRefMap;
224 ArgBackRefMap TypeBackReferences;
230 const bool PointersAre64Bit;
233 enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result };
235 MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &
C, raw_ostream &Out_)
237 PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
240 MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &
C, raw_ostream &Out_,
243 PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
246 MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &
C, raw_ostream &Out_,
249 PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
252 raw_ostream &getStream()
const {
return Out; }
254 void mangle(
const NamedDecl *D, StringRef Prefix =
"\01?");
256 void mangleFunctionEncoding(
const FunctionDecl *FD,
bool ShouldMangle);
257 void mangleVariableEncoding(
const VarDecl *VD);
261 void mangleVirtualMemPtrThunk(
264 void mangleNumber(int64_t Number);
266 QualifierMangleMode QMM = QMM_Mangle);
269 bool ForceThisQuals =
false);
270 void mangleNestedName(
const NamedDecl *ND);
273 void mangleUnqualifiedName(
const NamedDecl *ND) {
277 void mangleSourceName(StringRef Name);
280 void mangleQualifiers(
Qualifiers Quals,
bool IsMember);
282 void manglePointerCVQualifiers(
Qualifiers Quals);
285 void mangleUnscopedTemplateName(
const TemplateDecl *ND);
294 #define ABSTRACT_TYPE(CLASS, PARENT)
295 #define NON_CANONICAL_TYPE(CLASS, PARENT)
296 #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \
299 #include "clang/AST/TypeNodes.def"
301 #undef NON_CANONICAL_TYPE
304 void mangleType(
const TagDecl *TD);
305 void mangleDecayedArrayType(
const ArrayType *T);
306 void mangleArrayType(
const ArrayType *T);
310 void mangleIntegerLiteral(
const llvm::APSInt &Number,
bool IsBoolean);
311 void mangleExpression(
const Expr *E);
321 bool MicrosoftMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
322 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
325 if (FD->hasAttr<OverloadableAttr>())
337 if (FD->isMSVCRTEntryPoint())
351 if (!getASTContext().getLangOpts().CPlusPlus)
354 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
360 const DeclContext *DC = getEffectiveDeclContext(D);
364 DC = getEffectiveParentContext(DC);
367 !isa<VarTemplateSpecializationDecl>(D))
375 MicrosoftMangleContextImpl::shouldMangleStringLiteral(
const StringLiteral *SL) {
379 void MicrosoftCXXNameMangler::mangle(
const NamedDecl *D, StringRef Prefix) {
390 mangleFunctionEncoding(FD,
Context.shouldMangleDeclName(FD));
391 else if (
const VarDecl *VD = dyn_cast<VarDecl>(D))
392 mangleVariableEncoding(VD);
403 void MicrosoftCXXNameMangler::mangleFunctionEncoding(
const FunctionDecl *FD,
427 mangleFunctionClass(FD);
429 mangleFunctionType(FT, FD);
435 void MicrosoftCXXNameMangler::mangleVariableEncoding(
const VarDecl *VD) {
466 mangleType(Ty, SR, QMM_Drop);
467 manglePointerExtQualifiers(
470 mangleQualifiers(MPT->getPointeeType().getQualifiers(),
true);
473 mangleName(MPT->getClass()->getAsCXXRecordDecl());
476 }
else if (
const ArrayType *AT = getASTContext().getAsArrayType(Ty)) {
478 mangleDecayedArrayType(AT);
479 if (AT->getElementType()->isArrayType())
484 mangleType(Ty, SR, QMM_Drop);
489 void MicrosoftCXXNameMangler::mangleMemberDataPointer(
const CXXRecordDecl *RD,
496 int64_t VBTableOffset;
499 FieldOffset = getASTContext().getFieldOffset(VD);
500 assert(FieldOffset % getASTContext().
getCharWidth() == 0 &&
501 "cannot take address of bitfield");
502 FieldOffset /= getASTContext().getCharWidth();
506 if (IM == MSInheritanceAttr::Keyword_virtual_inheritance)
507 FieldOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity();
516 case MSInheritanceAttr::Keyword_single_inheritance: Code =
'0';
break;
517 case MSInheritanceAttr::Keyword_multiple_inheritance: Code =
'0';
break;
518 case MSInheritanceAttr::Keyword_virtual_inheritance: Code =
'F';
break;
519 case MSInheritanceAttr::Keyword_unspecified_inheritance: Code =
'G';
break;
524 mangleNumber(FieldOffset);
529 if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
531 if (MSInheritanceAttr::hasVBTableOffsetField(IM))
532 mangleNumber(VBTableOffset);
536 MicrosoftCXXNameMangler::mangleMemberFunctionPointer(
const CXXRecordDecl *RD,
547 case MSInheritanceAttr::Keyword_single_inheritance: Code =
'1';
break;
548 case MSInheritanceAttr::Keyword_multiple_inheritance: Code =
'H';
break;
549 case MSInheritanceAttr::Keyword_virtual_inheritance: Code =
'I';
break;
550 case MSInheritanceAttr::Keyword_unspecified_inheritance: Code =
'J';
break;
555 uint64_t NVOffset = 0;
556 uint64_t VBTableOffset = 0;
557 uint64_t VBPtrOffset = 0;
559 Out <<
'$' << Code <<
'?';
562 cast<MicrosoftVTableContext>(getASTContext().getVTableContext());
565 mangleVirtualMemPtrThunk(MD, ML);
566 NVOffset = ML.VFPtrOffset.getQuantity();
567 VBTableOffset = ML.VBTableIndex * 4;
569 const ASTRecordLayout &Layout = getASTContext().getASTRecordLayout(RD);
574 mangleFunctionEncoding(MD,
true);
577 if (VBTableOffset == 0 &&
578 IM == MSInheritanceAttr::Keyword_virtual_inheritance)
579 NVOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity();
582 if (IM == MSInheritanceAttr::Keyword_single_inheritance) {
586 if (IM == MSInheritanceAttr::Keyword_unspecified_inheritance)
591 if (MSInheritanceAttr::hasNVOffsetField(
true, IM))
592 mangleNumber(static_cast<uint32_t>(NVOffset));
593 if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
594 mangleNumber(VBPtrOffset);
595 if (MSInheritanceAttr::hasVBTableOffsetField(IM))
596 mangleNumber(VBTableOffset);
599 void MicrosoftCXXNameMangler::mangleVirtualMemPtrThunk(
603 CharUnits PointerWidth = getASTContext().toCharUnitsFromBits(
604 getASTContext().getTargetInfo().getPointerWidth(0));
610 mangleNumber(OffsetInVFTable);
615 void MicrosoftCXXNameMangler::mangleName(
const NamedDecl *ND) {
619 mangleUnqualifiedName(ND);
621 mangleNestedName(ND);
627 void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
634 uint64_t
Value =
static_cast<uint64_t
>(Number);
642 else if (Value >= 1 && Value <= 10)
648 char EncodedNumberBuffer[
sizeof(uint64_t) * 2];
651 for (; Value != 0; Value >>= 4)
652 *I++ =
'A' + (Value & 0xf);
653 Out.write(I.base(), I - BufferRef.rbegin());
661 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
670 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
671 TemplateArgs = &Spec->getTemplateArgs();
672 return Spec->getSpecializedTemplate();
677 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
678 TemplateArgs = &Spec->getTemplateArgs();
679 return Spec->getSpecializedTemplate();
685 void MicrosoftCXXNameMangler::mangleUnqualifiedName(
const NamedDecl *ND,
699 if (!isa<ClassTemplateDecl>(TD)) {
700 mangleTemplateInstantiationName(TD, *TemplateArgs);
721 llvm::raw_svector_ostream Stream(TemplateMangling);
722 MicrosoftCXXNameMangler Extra(
Context, Stream);
723 Extra.mangleTemplateInstantiationName(TD, *TemplateArgs);
726 mangleSourceName(TemplateMangling);
733 mangleSourceName(II->getName());
738 assert(ND &&
"mangling empty name without declaration");
741 if (NS->isAnonymousNamespace()) {
747 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
750 assert(RD &&
"expected variable decl to have a record type");
756 Name += llvm::utostr(
Context.getAnonymousStructId(RD) + 1);
757 mangleSourceName(Name.str());
762 const TagDecl *TD = cast<TagDecl>(ND);
765 "Typedef should not be in another decl context!");
767 "Typedef was not named!");
772 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) {
779 LambdaId =
Context.getLambdaId(Record);
781 Name += llvm::utostr(LambdaId);
784 mangleSourceName(Name);
797 Name += llvm::utostr(
Context.getAnonymousStructId(TD));
800 mangleSourceName(Name.str());
807 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
810 if (Structor == getStructor(ND)) {
827 mangleCXXDtorType(static_cast<CXXDtorType>(
StructorType));
851 llvm_unreachable(
"Can't mangle a using directive name!");
855 void MicrosoftCXXNameMangler::mangleNestedName(
const NamedDecl *ND) {
858 const DeclContext *DC = getEffectiveDeclContext(ND);
861 if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) {
863 if (
Context.getNextDiscriminator(ND, Disc)) {
870 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
874 "cannot mangle a local inside this block yet");
875 Diags.
Report(BD->getLocation(), DiagID);
879 Out <<
"__block_invoke" <<
Context.getBlockId(BD,
false);
882 }
else if (
const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) {
883 mangleObjCMethodName(Method);
884 }
else if (isa<NamedDecl>(DC)) {
885 ND = cast<NamedDecl>(DC);
886 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
890 mangleUnqualifiedName(ND);
896 void MicrosoftCXXNameMangler::mangleCXXDtorType(
CXXDtorType T) {
911 llvm_unreachable(
"not expecting a COMDAT");
913 llvm_unreachable(
"Unsupported dtor type?");
922 case OO_New: Out <<
"?2";
break;
924 case OO_Delete: Out <<
"?3";
break;
926 case OO_Equal: Out <<
"?4";
break;
928 case OO_GreaterGreater: Out <<
"?5";
break;
930 case OO_LessLess: Out <<
"?6";
break;
932 case OO_Exclaim: Out <<
"?7";
break;
934 case OO_EqualEqual: Out <<
"?8";
break;
936 case OO_ExclaimEqual: Out <<
"?9";
break;
938 case OO_Subscript: Out <<
"?A";
break;
941 case OO_Arrow: Out <<
"?C";
break;
943 case OO_Star: Out <<
"?D";
break;
945 case OO_PlusPlus: Out <<
"?E";
break;
947 case OO_MinusMinus: Out <<
"?F";
break;
949 case OO_Minus: Out <<
"?G";
break;
951 case OO_Plus: Out <<
"?H";
break;
953 case OO_Amp: Out <<
"?I";
break;
955 case OO_ArrowStar: Out <<
"?J";
break;
957 case OO_Slash: Out <<
"?K";
break;
959 case OO_Percent: Out <<
"?L";
break;
961 case OO_Less: Out <<
"?M";
break;
963 case OO_LessEqual: Out <<
"?N";
break;
965 case OO_Greater: Out <<
"?O";
break;
967 case OO_GreaterEqual: Out <<
"?P";
break;
969 case OO_Comma: Out <<
"?Q";
break;
971 case OO_Call: Out <<
"?R";
break;
973 case OO_Tilde: Out <<
"?S";
break;
975 case OO_Caret: Out <<
"?T";
break;
977 case OO_Pipe: Out <<
"?U";
break;
979 case OO_AmpAmp: Out <<
"?V";
break;
981 case OO_PipePipe: Out <<
"?W";
break;
983 case OO_StarEqual: Out <<
"?X";
break;
985 case OO_PlusEqual: Out <<
"?Y";
break;
987 case OO_MinusEqual: Out <<
"?Z";
break;
989 case OO_SlashEqual: Out <<
"?_0";
break;
991 case OO_PercentEqual: Out <<
"?_1";
break;
993 case OO_GreaterGreaterEqual: Out <<
"?_2";
break;
995 case OO_LessLessEqual: Out <<
"?_3";
break;
997 case OO_AmpEqual: Out <<
"?_4";
break;
999 case OO_PipeEqual: Out <<
"?_5";
break;
1001 case OO_CaretEqual: Out <<
"?_6";
break;
1030 case OO_Array_New: Out <<
"?_U";
break;
1032 case OO_Array_Delete: Out <<
"?_V";
break;
1034 case OO_Conditional: {
1037 "cannot mangle this conditional operator yet");
1038 Diags.
Report(Loc, DiagID);
1044 llvm_unreachable(
"Not an overloaded operator");
1048 void MicrosoftCXXNameMangler::mangleSourceName(StringRef Name) {
1050 BackRefVec::iterator Found =
1051 std::find(NameBackReferences.begin(), NameBackReferences.end(), Name);
1052 if (Found == NameBackReferences.end()) {
1053 if (NameBackReferences.size() < 10)
1054 NameBackReferences.push_back(Name);
1057 Out << (Found - NameBackReferences.begin());
1061 void MicrosoftCXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
1062 Context.mangleObjCMethodName(MD, Out);
1065 void MicrosoftCXXNameMangler::mangleTemplateInstantiationName(
1072 ArgBackRefMap OuterArgsContext;
1073 BackRefVec OuterTemplateContext;
1074 NameBackReferences.swap(OuterTemplateContext);
1075 TypeBackReferences.swap(OuterArgsContext);
1077 mangleUnscopedTemplateName(TD);
1078 mangleTemplateArgs(TD, TemplateArgs);
1081 NameBackReferences.swap(OuterTemplateContext);
1082 TypeBackReferences.swap(OuterArgsContext);
1086 MicrosoftCXXNameMangler::mangleUnscopedTemplateName(
const TemplateDecl *TD) {
1089 mangleUnqualifiedName(TD);
1092 void MicrosoftCXXNameMangler::mangleIntegerLiteral(
const llvm::APSInt &Value,
1097 if (IsBoolean && Value.getBoolValue())
1099 else if (Value.isSigned())
1100 mangleNumber(Value.getSExtValue());
1102 mangleNumber(Value.getZExtValue());
1105 void MicrosoftCXXNameMangler::mangleExpression(
const Expr *E) {
1119 UE = dyn_cast<CXXUuidofExpr>(UO->getSubExpr());
1127 std::string Name =
"_GUID_" + Uuid.lower();
1128 std::replace(Name.begin(), Name.end(),
'-',
'_');
1139 Out << Name <<
"@@3U__s_GUID@@B";
1148 << E->getSourceRange();
1151 void MicrosoftCXXNameMangler::mangleTemplateArgs(
1155 assert(TPL->
size() == TemplateArgs.
size() &&
1156 "size mismatch between args and parms!");
1160 mangleTemplateArg(TD, TA, TPL->
getParam(Idx++));
1163 void MicrosoftCXXNameMangler::mangleTemplateArg(
const TemplateDecl *TD,
1177 llvm_unreachable(
"Can't mangle null template arguments!");
1179 llvm_unreachable(
"Can't mangle template expansion arguments!");
1187 if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) {
1188 mangleMemberDataPointer(
1190 cast<ValueDecl>(ND));
1191 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1198 mangleFunctionEncoding(FD,
true);
1212 const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
1213 if (MPT->isMemberFunctionPointerType() && isa<ClassTemplateDecl>(TD)) {
1214 mangleMemberFunctionPointer(RD,
nullptr);
1217 if (MPT->isMemberDataPointer()) {
1218 if (isa<ClassTemplateDecl>(TD)) {
1219 mangleMemberDataPointer(RD,
nullptr);
1229 mangleIntegerLiteral(llvm::APSInt::get(-1),
false);
1234 mangleIntegerLiteral(llvm::APSInt::getUnsigned(0),
false);
1242 if (TemplateArgs.empty()) {
1243 if (isa<TemplateTypeParmDecl>(Parm) ||
1244 isa<TemplateTemplateParmDecl>(Parm))
1251 else if (isa<NonTypeTemplateParmDecl>(Parm))
1254 llvm_unreachable(
"unexpected template parameter decl!");
1257 mangleTemplateArg(TD, PA, Parm);
1264 if (
const auto *TD = dyn_cast<TagDecl>(ND)) {
1266 }
else if (isa<TypeAliasDecl>(ND)) {
1270 llvm_unreachable(
"unexpected template template NamedDecl!");
1277 void MicrosoftCXXNameMangler::mangleQualifiers(
Qualifiers Quals,
1335 if (HasConst && HasVolatile) {
1337 }
else if (HasVolatile) {
1339 }
else if (HasConst) {
1345 if (HasConst && HasVolatile) {
1347 }
else if (HasVolatile) {
1349 }
else if (HasConst) {
1360 MicrosoftCXXNameMangler::mangleRefQualifier(
RefQualifierKind RefQualifier) {
1363 switch (RefQualifier) {
1377 void MicrosoftCXXNameMangler::manglePointerExtQualifiers(
Qualifiers Quals,
1380 if (PointersAre64Bit &&
1388 void MicrosoftCXXNameMangler::manglePointerCVQualifiers(
Qualifiers Quals) {
1396 if (HasConst && HasVolatile) {
1398 }
else if (HasVolatile) {
1400 }
else if (HasConst) {
1407 void MicrosoftCXXNameMangler::mangleArgumentType(
QualType T,
1418 QualType OriginalType = DT->getOriginalType();
1421 if (
const auto *AT = getASTContext().getAsArrayType(OriginalType))
1422 OriginalType = getASTContext().getIncompleteArrayType(
1423 AT->getElementType(), AT->getSizeModifier(),
1424 AT->getIndexTypeCVRQualifiers());
1438 ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr);
1440 if (Found == TypeBackReferences.end()) {
1441 size_t OutSizeBefore = Out.tell();
1443 mangleType(T, Range, QMM_Drop);
1448 bool LongerThanOneChar = (Out.tell() - OutSizeBefore > 1);
1449 if (LongerThanOneChar && TypeBackReferences.size() < 10) {
1450 size_t Size = TypeBackReferences.size();
1451 TypeBackReferences[TypePtr] = Size;
1454 Out << Found->second;
1459 QualifierMangleMode QMM) {
1464 if (
const ArrayType *AT = getASTContext().getAsArrayType(T)) {
1467 if (QMM == QMM_Mangle)
1469 else if (QMM == QMM_Escape || QMM == QMM_Result)
1471 mangleArrayType(AT);
1482 if (
const FunctionType *FT = dyn_cast<FunctionType>(T)) {
1484 mangleFunctionType(FT);
1487 mangleQualifiers(Quals,
false);
1490 if (!IsPointer && Quals) {
1492 mangleQualifiers(Quals,
false);
1496 if ((!IsPointer && Quals) || isa<TagType>(T)) {
1498 mangleQualifiers(Quals,
false);
1506 #define ABSTRACT_TYPE(CLASS, PARENT)
1507 #define NON_CANONICAL_TYPE(CLASS, PARENT) \
1509 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
1511 #define TYPE(CLASS, PARENT) \
1513 mangleType(cast<CLASS##Type>(ty), Quals, Range); \
1515 #include "clang/AST/TypeNodes.def"
1516 #undef ABSTRACT_TYPE
1517 #undef NON_CANONICAL_TYPE
1549 case BuiltinType::Void: Out <<
'X';
break;
1550 case BuiltinType::SChar: Out <<
'C';
break;
1551 case BuiltinType::Char_U:
case BuiltinType::Char_S: Out <<
'D';
break;
1552 case BuiltinType::UChar: Out <<
'E';
break;
1553 case BuiltinType::Short: Out <<
'F';
break;
1554 case BuiltinType::UShort: Out <<
'G';
break;
1555 case BuiltinType::Int: Out <<
'H';
break;
1556 case BuiltinType::UInt: Out <<
'I';
break;
1557 case BuiltinType::Long: Out <<
'J';
break;
1558 case BuiltinType::ULong: Out <<
'K';
break;
1559 case BuiltinType::Float: Out <<
'M';
break;
1560 case BuiltinType::Double: Out <<
'N';
break;
1562 case BuiltinType::LongDouble: Out <<
'O';
break;
1563 case BuiltinType::LongLong: Out <<
"_J";
break;
1564 case BuiltinType::ULongLong: Out <<
"_K";
break;
1565 case BuiltinType::Int128: Out <<
"_L";
break;
1566 case BuiltinType::UInt128: Out <<
"_M";
break;
1567 case BuiltinType::Bool: Out <<
"_N";
break;
1568 case BuiltinType::Char16: Out <<
"_S";
break;
1569 case BuiltinType::Char32: Out <<
"_U";
break;
1570 case BuiltinType::WChar_S:
1571 case BuiltinType::WChar_U: Out <<
"_W";
break;
1573 #define BUILTIN_TYPE(Id, SingletonId)
1574 #define PLACEHOLDER_TYPE(Id, SingletonId) \
1575 case BuiltinType::Id:
1576 #include "clang/AST/BuiltinTypes.def"
1577 case BuiltinType::Dependent:
1578 llvm_unreachable(
"placeholder types shouldn't get to name mangling");
1580 case BuiltinType::ObjCId: Out <<
"PAUobjc_object@@";
break;
1581 case BuiltinType::ObjCClass: Out <<
"PAUobjc_class@@";
break;
1582 case BuiltinType::ObjCSel: Out <<
"PAUobjc_selector@@";
break;
1584 case BuiltinType::OCLImage1d: Out <<
"PAUocl_image1d@@";
break;
1585 case BuiltinType::OCLImage1dArray: Out <<
"PAUocl_image1darray@@";
break;
1586 case BuiltinType::OCLImage1dBuffer: Out <<
"PAUocl_image1dbuffer@@";
break;
1587 case BuiltinType::OCLImage2d: Out <<
"PAUocl_image2d@@";
break;
1588 case BuiltinType::OCLImage2dArray: Out <<
"PAUocl_image2darray@@";
break;
1589 case BuiltinType::OCLImage3d: Out <<
"PAUocl_image3d@@";
break;
1590 case BuiltinType::OCLSampler: Out <<
"PAUocl_sampler@@";
break;
1591 case BuiltinType::OCLEvent: Out <<
"PAUocl_event@@";
break;
1593 case BuiltinType::NullPtr: Out <<
"$$T";
break;
1595 case BuiltinType::Half: {
1598 "cannot mangle this built-in %0 type yet");
1615 mangleFunctionType(T,
nullptr,
true);
1618 mangleFunctionType(T);
1623 llvm_unreachable(
"Can't mangle K&R function prototypes");
1626 void MicrosoftCXXNameMangler::mangleFunctionType(
const FunctionType *T,
1628 bool ForceThisQuals) {
1636 bool IsStructor =
false, HasThisQuals = ForceThisQuals, IsCtorClosure =
false;
1638 if (
const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(D)) {
1640 HasThisQuals =
true;
1641 if (isa<CXXDestructorDecl>(MD)) {
1643 }
else if (isa<CXXConstructorDecl>(MD)) {
1647 getStructor(MD) == Structor;
1649 CC = getASTContext().getDefaultCallingConvention(
1658 manglePointerExtQualifiers(Quals,
QualType());
1660 mangleQualifiers(Quals,
false);
1663 mangleCallingConvention(CC);
1668 if (isa<CXXDestructorDecl>(D) && D == Structor &&
1674 Out << (PointersAre64Bit ?
"PEAXI@Z" :
"PAXI@Z");
1677 if (IsCtorClosure) {
1687 mangleArgumentType(getASTContext().getLValueReferenceType(
1695 llvm_unreachable(
"unexpected constructor closure!");
1703 if (
const auto *AT =
1708 mangleSourceName(AT->isDecltypeAuto() ?
"<decltype-auto>" :
"<auto>");
1713 mangleType(ResultType, Range, QMM_Result);
1725 mangleArgumentType(Arg, Range);
1733 mangleThrowSpecification(Proto);
1736 void MicrosoftCXXNameMangler::mangleFunctionClass(
const FunctionDecl *FD) {
1761 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1764 llvm_unreachable(
"Unsupported access specifier");
1793 void MicrosoftCXXNameMangler::mangleCallingConvention(
CallingConv CC) {
1813 llvm_unreachable(
"Unsupported CC for mangling");
1816 case CC_C: Out <<
'A';
break;
1824 void MicrosoftCXXNameMangler::mangleCallingConvention(
const FunctionType *T) {
1827 void MicrosoftCXXNameMangler::mangleThrowSpecification(
1844 "cannot mangle this unresolved dependent type yet");
1856 mangleType(cast<TagType>(T)->getDecl());
1860 mangleType(cast<TagType>(T)->getDecl());
1862 void MicrosoftCXXNameMangler::mangleType(
const TagDecl *TD) {
1888 void MicrosoftCXXNameMangler::mangleDecayedArrayType(
const ArrayType *T) {
1896 llvm_unreachable(
"Should have been special cased");
1900 llvm_unreachable(
"Should have been special cased");
1904 llvm_unreachable(
"Should have been special cased");
1908 llvm_unreachable(
"Should have been special cased");
1910 void MicrosoftCXXNameMangler::mangleArrayType(
const ArrayType *T) {
1914 if (ElementTy->isConstantArrayType()) {
1916 getASTContext().getAsConstantArrayType(ElementTy);
1917 Dimensions.push_back(CAT->
getSize());
1919 }
else if (ElementTy->isIncompleteArrayType()) {
1921 getASTContext().getAsIncompleteArrayType(ElementTy);
1922 Dimensions.push_back(llvm::APInt(32, 0));
1924 }
else if (ElementTy->isVariableArrayType()) {
1926 getASTContext().getAsVariableArrayType(ElementTy);
1927 Dimensions.push_back(llvm::APInt(32, 0));
1929 }
else if (ElementTy->isDependentSizedArrayType()) {
1932 getASTContext().getAsDependentSizedArrayType(ElementTy);
1935 "cannot mangle this dependent-length array yet");
1945 mangleNumber(Dimensions.size());
1946 for (
const llvm::APInt &Dimension : Dimensions)
1947 mangleNumber(Dimension.getLimitedValue());
1957 manglePointerCVQualifiers(Quals);
1958 manglePointerExtQualifiers(Quals, PointeeType);
1962 mangleFunctionType(FPT,
nullptr,
true);
1966 mangleType(PointeeType, Range, QMM_Drop);
1974 "cannot mangle this template type parameter type yet");
1983 "cannot mangle this substituted parameter pack yet");
1994 manglePointerCVQualifiers(Quals);
1995 manglePointerExtQualifiers(Quals, PointeeType);
1996 mangleType(PointeeType, Range);
2001 manglePointerCVQualifiers(Quals);
2002 manglePointerExtQualifiers(Quals, PointeeType);
2005 mangleType(PointeeType, Range);
2015 manglePointerExtQualifiers(Quals, PointeeType);
2016 mangleType(PointeeType, Range);
2026 manglePointerExtQualifiers(Quals, PointeeType);
2027 mangleType(PointeeType, Range);
2034 "cannot mangle this complex number type yet");
2042 assert(ET &&
"vectors with non-builtin elements are unsupported");
2043 uint64_t Width = getASTContext().getTypeSize(T);
2046 bool IsBuiltin =
true;
2047 llvm::Triple::ArchType AT =
2048 getASTContext().getTargetInfo().getTriple().getArch();
2049 if (AT == llvm::Triple::x86 || AT == llvm::Triple::x86_64) {
2050 if (Width == 64 && ET->
getKind() == BuiltinType::LongLong) {
2052 }
else if (Width >= 128) {
2053 if (ET->
getKind() == BuiltinType::Float)
2054 Out <<
"T__m" << Width;
2055 else if (ET->
getKind() == BuiltinType::LongLong)
2056 Out <<
"T__m" << Width <<
'i';
2057 else if (ET->
getKind() == BuiltinType::Double)
2058 Out <<
"U__m" << Width <<
'd';
2073 mangleType(ET, Quals, Range);
2083 "cannot mangle this extended vector type yet");
2091 "cannot mangle this dependent-sized extended vector type yet");
2113 manglePointerCVQualifiers(Quals);
2114 manglePointerExtQualifiers(Quals, PointeeType);
2123 llvm_unreachable(
"Cannot mangle injected class name type.");
2130 "cannot mangle this template specialization type yet");
2139 "cannot mangle this dependent name type yet");
2144 void MicrosoftCXXNameMangler::mangleType(
2149 "cannot mangle this dependent template specialization type yet");
2158 "cannot mangle this pack expansion yet");
2167 "cannot mangle this typeof(type) yet");
2176 "cannot mangle this typeof(expression) yet");
2185 "cannot mangle this decltype() yet");
2194 "cannot mangle this unary transform type yet");
2205 "cannot mangle this 'auto' type yet");
2206 Diags.Report(Range.
getBegin(), DiagID)
2214 "cannot mangle this C11 atomic type yet");
2219 void MicrosoftMangleContextImpl::mangleCXXName(
const NamedDecl *D,
2221 assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
2222 "Invalid mangleName() call, argument is not a variable or function!");
2223 assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
2224 "Invalid mangleName() call on 'structor decl!");
2227 getASTContext().getSourceManager(),
2228 "Mangling declaration");
2230 MicrosoftCXXNameMangler Mangler(*
this, Out);
2231 return Mangler.mangle(D);
2260 MicrosoftCXXNameMangler &Mangler,
2267 llvm_unreachable(
"Unsupported access specifier");
2278 Out <<
'R' << AccessSpec;
2279 Mangler.mangleNumber(
2281 Mangler.mangleNumber(
2283 Mangler.mangleNumber(
2285 Mangler.mangleNumber(static_cast<uint32_t>(Adjustment.
NonVirtual));
2288 Mangler.mangleNumber(
2290 Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.
NonVirtual));
2295 llvm_unreachable(
"Unsupported access specifier");
2305 Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.
NonVirtual));
2309 llvm_unreachable(
"Unsupported access specifier");
2323 MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk(
const CXXMethodDecl *MD,
2326 cast<MicrosoftVTableContext>(getASTContext().getVTableContext());
2330 MicrosoftCXXNameMangler Mangler(*
this, Out);
2331 Mangler.getStream() <<
"\01?";
2332 Mangler.mangleVirtualMemPtrThunk(MD, ML);
2335 void MicrosoftMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
2338 MicrosoftCXXNameMangler Mangler(*
this, Out);
2340 Mangler.mangleName(MD);
2343 assert(Thunk.
Method !=
nullptr &&
2344 "Thunk info should hold the overridee decl");
2347 Mangler.mangleFunctionType(
2351 void MicrosoftMangleContextImpl::mangleCXXDtorThunk(
2358 MicrosoftCXXNameMangler Mangler(*
this, Out, DD, Type);
2365 void MicrosoftMangleContextImpl::mangleCXXVFTable(
2372 MicrosoftCXXNameMangler Mangler(*
this, Out);
2373 Mangler.getStream() <<
"\01??_7";
2374 Mangler.mangleName(Derived);
2375 Mangler.getStream() <<
"6B";
2377 Mangler.mangleName(RD);
2378 Mangler.getStream() <<
'@';
2381 void MicrosoftMangleContextImpl::mangleCXXVBTable(
2388 MicrosoftCXXNameMangler Mangler(*
this, Out);
2389 Mangler.getStream() <<
"\01??_8";
2390 Mangler.mangleName(Derived);
2391 Mangler.getStream() <<
"7B";
2393 Mangler.mangleName(RD);
2394 Mangler.getStream() <<
'@';
2397 void MicrosoftMangleContextImpl::mangleCXXRTTI(
QualType T, raw_ostream &Out) {
2398 MicrosoftCXXNameMangler Mangler(*
this, Out);
2399 Mangler.getStream() <<
"\01??_R0";
2400 Mangler.mangleType(T,
SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
2401 Mangler.getStream() <<
"@8";
2404 void MicrosoftMangleContextImpl::mangleCXXRTTIName(
QualType T,
2406 MicrosoftCXXNameMangler Mangler(*
this, Out);
2407 Mangler.getStream() <<
'.';
2408 Mangler.mangleType(T,
SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
2411 void MicrosoftMangleContextImpl::mangleCXXCatchHandlerType(
QualType T,
2414 MicrosoftCXXNameMangler Mangler(*
this, Out);
2415 Mangler.getStream() <<
"llvm.eh.handlertype.";
2416 Mangler.mangleType(T,
SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
2417 Mangler.getStream() <<
'.' << Flags;
2420 void MicrosoftMangleContextImpl::mangleCXXVirtualDisplacementMap(
2422 MicrosoftCXXNameMangler Mangler(*
this, Out);
2423 Mangler.getStream() <<
"\01??_K";
2424 Mangler.mangleName(SrcRD);
2425 Mangler.getStream() <<
"$C";
2426 Mangler.mangleName(DstRD);
2429 void MicrosoftMangleContextImpl::mangleCXXThrowInfo(
QualType T,
2432 uint32_t NumEntries,
2434 MicrosoftCXXNameMangler Mangler(*
this, Out);
2435 Mangler.getStream() <<
"_TI";
2437 Mangler.getStream() <<
'C';
2439 Mangler.getStream() <<
'V';
2440 Mangler.getStream() << NumEntries;
2441 Mangler.mangleType(T,
SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
2444 void MicrosoftMangleContextImpl::mangleCXXCatchableTypeArray(
2445 QualType T, uint32_t NumEntries, raw_ostream &Out) {
2446 MicrosoftCXXNameMangler Mangler(*
this, Out);
2447 Mangler.getStream() <<
"_CTA";
2448 Mangler.getStream() << NumEntries;
2449 Mangler.mangleType(T,
SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
2452 void MicrosoftMangleContextImpl::mangleCXXCatchableType(
2454 uint32_t NVOffset, int32_t VBPtrOffset, uint32_t VBIndex,
2456 MicrosoftCXXNameMangler Mangler(*
this, Out);
2457 Mangler.getStream() <<
"_CT";
2461 llvm::raw_svector_ostream Stream(RTTIMangling);
2462 mangleCXXRTTI(T, Stream);
2464 Mangler.getStream() << RTTIMangling.substr(1);
2471 llvm::raw_svector_ostream Stream(CopyCtorMangling);
2472 mangleCXXCtor(CD, CT, Stream);
2474 Mangler.getStream() << CopyCtorMangling.substr(1);
2476 Mangler.getStream() << Size;
2477 if (VBPtrOffset == -1) {
2479 Mangler.getStream() << NVOffset;
2482 Mangler.getStream() << NVOffset;
2483 Mangler.getStream() << VBPtrOffset;
2484 Mangler.getStream() << VBIndex;
2488 void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassDescriptor(
2489 const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset,
2490 uint32_t VBTableOffset, uint32_t Flags, raw_ostream &Out) {
2491 MicrosoftCXXNameMangler Mangler(*
this, Out);
2492 Mangler.getStream() <<
"\01??_R1";
2493 Mangler.mangleNumber(NVOffset);
2494 Mangler.mangleNumber(VBPtrOffset);
2495 Mangler.mangleNumber(VBTableOffset);
2496 Mangler.mangleNumber(Flags);
2497 Mangler.mangleName(Derived);
2498 Mangler.getStream() <<
"8";
2501 void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassArray(
2503 MicrosoftCXXNameMangler Mangler(*
this, Out);
2504 Mangler.getStream() <<
"\01??_R2";
2505 Mangler.mangleName(Derived);
2506 Mangler.getStream() <<
"8";
2509 void MicrosoftMangleContextImpl::mangleCXXRTTIClassHierarchyDescriptor(
2511 MicrosoftCXXNameMangler Mangler(*
this, Out);
2512 Mangler.getStream() <<
"\01??_R3";
2513 Mangler.mangleName(Derived);
2514 Mangler.getStream() <<
"8";
2517 void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator(
2524 MicrosoftCXXNameMangler Mangler(*
this, Out);
2525 Mangler.getStream() <<
"\01??_R4";
2526 Mangler.mangleName(Derived);
2527 Mangler.getStream() <<
"6B";
2529 Mangler.mangleName(RD);
2530 Mangler.getStream() <<
'@';
2533 void MicrosoftMangleContextImpl::mangleSEHFilterExpression(
2534 const NamedDecl *EnclosingDecl, raw_ostream &Out) {
2535 MicrosoftCXXNameMangler Mangler(*
this, Out);
2540 Mangler.getStream() <<
"\01?filt$" << SEHFilterIds[EnclosingDecl]++ <<
"@0@";
2541 Mangler.mangleName(EnclosingDecl);
2544 void MicrosoftMangleContextImpl::mangleSEHFinallyBlock(
2545 const NamedDecl *EnclosingDecl, raw_ostream &Out) {
2546 MicrosoftCXXNameMangler Mangler(*
this, Out);
2551 Mangler.getStream() <<
"\01?fin$" << SEHFinallyIds[EnclosingDecl]++ <<
"@0@";
2552 Mangler.mangleName(EnclosingDecl);
2555 void MicrosoftMangleContextImpl::mangleTypeName(
QualType T, raw_ostream &Out) {
2558 MicrosoftCXXNameMangler Mangler(*
this, Out);
2559 Mangler.getStream() <<
'?';
2566 MicrosoftCXXNameMangler mangler(*
this, Out, D, Type);
2573 MicrosoftCXXNameMangler mangler(*
this, Out, D, Type);
2577 void MicrosoftMangleContextImpl::mangleReferenceTemporary(
const VarDecl *VD,
2581 "cannot mangle this reference temporary yet");
2585 void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable(
2586 const VarDecl *VD,
unsigned GuardNum, raw_ostream &Out) {
2587 MicrosoftCXXNameMangler Mangler(*
this, Out);
2589 Mangler.getStream() <<
"\01?$TSS" << GuardNum <<
'@';
2590 Mangler.mangleNestedName(VD);
2593 void MicrosoftMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *VD,
2605 MicrosoftCXXNameMangler Mangler(*
this, Out);
2609 Mangler.getStream() << (VD->
getTLSKind() ?
"\01??__J" :
"\01??_B");
2611 Mangler.getStream() <<
"\01?$S1@";
2613 unsigned ScopeDepth = 0;
2614 if (Visible && !getNextDiscriminator(VD, ScopeDepth))
2618 Mangler.mangle(VD,
"");
2620 Mangler.mangleNestedName(VD);
2621 Mangler.getStream() << (Visible ?
"@5" :
"@4IA");
2623 Mangler.mangleNumber(ScopeDepth);
2626 void MicrosoftMangleContextImpl::mangleInitFiniStub(
const VarDecl *D,
2629 MicrosoftCXXNameMangler Mangler(*
this, Out);
2630 Mangler.getStream() <<
"\01??__" << CharCode;
2631 Mangler.mangleName(D);
2633 Mangler.mangleVariableEncoding(D);
2634 Mangler.getStream() <<
'@';
2638 Mangler.getStream() <<
"YAXXZ";
2641 void MicrosoftMangleContextImpl::mangleDynamicInitializer(
const VarDecl *D,
2644 mangleInitFiniStub(D, Out,
'E');
2648 MicrosoftMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
2651 mangleInitFiniStub(D, Out,
'F');
2654 void MicrosoftMangleContextImpl::mangleStringLiteral(
const StringLiteral *SL,
2675 MicrosoftCXXNameMangler Mangler(*
this, Out);
2676 Mangler.getStream() <<
"\01??_C@_";
2680 Mangler.getStream() <<
'1';
2682 Mangler.getStream() <<
'0';
2700 uint32_t CRC = 0xFFFFFFFFU;
2702 auto UpdateCRC = [&CRC](
char Byte) {
2703 for (
unsigned i = 0; i < 8; ++i) {
2704 bool Bit = CRC & 0x80000000U;
2705 if (Byte & (1U << i))
2713 auto GetLittleEndianByte = [&Mangler, &SL](
unsigned Index) {
2715 uint32_t CodeUnit = SL->
getCodeUnit(Index / CharByteWidth);
2716 unsigned OffsetInCodeUnit = Index % CharByteWidth;
2717 return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
2720 auto GetBigEndianByte = [&Mangler, &SL](
unsigned Index) {
2722 uint32_t CodeUnit = SL->
getCodeUnit(Index / CharByteWidth);
2723 unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth);
2724 return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
2729 UpdateCRC(GetLittleEndianByte(I));
2739 CRC = llvm::reverseBits(CRC);
2743 Mangler.mangleNumber(CRC);
2749 auto MangleByte = [&Mangler](
char Byte) {
2757 Mangler.getStream() << Byte;
2758 }
else if (
isLetter(Byte & 0x7f)) {
2759 Mangler.getStream() <<
'?' <<
static_cast<char>(Byte & 0x7f);
2761 const char SpecialChars[] = {
',',
'/',
'\\',
':',
'.',
2762 ' ',
'\n',
'\t',
'\'',
'-'};
2764 std::find(std::begin(SpecialChars), std::end(SpecialChars), Byte);
2765 if (Pos != std::end(SpecialChars)) {
2766 Mangler.getStream() <<
'?' << (Pos - std::begin(SpecialChars));
2768 Mangler.getStream() <<
"?$";
2769 Mangler.getStream() <<
static_cast<char>(
'A' + ((Byte >> 4) & 0xf));
2770 Mangler.getStream() <<
static_cast<char>(
'A' + (Byte & 0xf));
2776 unsigned NumCharsToMangle = std::min(32U, SL->
getLength());
2777 for (
unsigned I = 0, E = NumCharsToMangle * SL->
getCharByteWidth(); I != E;
2780 MangleByte(GetBigEndianByte(I));
2782 MangleByte(GetLittleEndianByte(I));
2785 if (NumCharsToMangle < 32)
2790 Mangler.getStream() <<
'@';
2793 void MicrosoftMangleContextImpl::mangleCXXVTableBitSet(
const CXXRecordDecl *RD,
2804 MicrosoftCXXNameMangler mangler(*
this, Out);
2805 mangler.mangleName(RD);
2810 return new MicrosoftMangleContextImpl(Context, Diags);
unsigned getNumElements() const
Defines the clang::ASTContext interface.
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
ObjCInterfaceDecl * getDecl() const
getDecl - Get the declaration of this interface.
StringRef getName() const
Represents the dependent type named by a dependently-scoped typename using declaration, e.g. using typename Base<T>::foo; Template instantiation turns these into the underlying type.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
bool isMemberPointerType() const
IdentifierInfo * getIdentifier() const
static MicrosoftMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags)
MSInheritanceAttr::Spelling getMSInheritanceModel() const
Returns the inheritance model used for this record.
StringRef getUuidAsStringRef(ASTContext &Context) const
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
IdentifierInfo * getCXXLiteralIdentifier() const
Represents a qualified type name for which the type name is dependent.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++1y decltype(auto) type.
QualType getPointeeType() const
IdentifierInfo * getAsIdentifierInfo() const
bool hasLinkage() const
Determine whether this declaration has linkage.
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
NamespaceDecl - Represent a C++ namespace.
NamedDecl * getParam(unsigned Idx)
bool isBooleanType() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isBlockPointerType() const
Represents a C++ constructor within a class.
Default closure variant of a ctor.
const llvm::APInt & getSize() const
void * getAsOpaquePtr() const
TLSKind getTLSKind() const
Represents an empty template argument, e.g., one that has not been deduced.
AccessSpecifier getAccess() const
CallingConv getCallConv() const
A this pointer adjustment.
The "__interface" keyword.
Represents a variable template specialization, which refers to a variable template with a given set o...
const CXXMethodDecl * Method
Holds a pointer to the overridden method this thunk is for, if needed by the ABI to distinguish diffe...
Stores a list of template parameters for a TemplateDecl and its derived classes.
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
unsigned getNumParams() const
int32_t VBOffsetOffset
The offset (in bytes) of the vbase offset in the vbtable.
bool isExternC() const
Determines whether this function is a function with external, C linkage.
Represents a class template specialization, which refers to a class template with a given set of temp...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isReferenceType() const
bool isAnyPointerType() const
bool isTranslationUnit() const
unsigned size() const
Retrieve the number of template arguments in this template argument list.
TagKind getTagKind() const
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Represents the result of substituting a set of types for a template type parameter pack...
The this pointer adjustment as well as an optional return adjustment for a thunk. ...
uint32_t getCodeUnit(size_t i) const
param_type_range param_types() const
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
An lvalue ref-qualifier was provided (&).
const LangOptions & getLangOpts() const
unsigned getLength() const
QualType getBaseType() const
QualType getReturnType() const
const CXXRecordDecl * getParent() const
Concrete class used by the front-end to report problems and issues.
TypeOfExprType (GCC extension).
Enums/classes describing ABI related information about constructors, destructors and thunks...
TypeClass getTypeClass() const
bool isStaticLocal() const
This represents the body of a CapturedStmt, and serves as its DeclContext.
CXXRecordDecl * getMostRecentDecl()
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
QualType getParamType(unsigned i) const
Expr * IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
QualType getPointeeType() const
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
CXXDtorType
C++ destructor types.
bool hasDeclaratorForAnonDecl() const
QualType getPointeeType() const
StringRef getName() const
Return the actual identifier string.
Represents a C++ destructor within a class.
ArgKind getKind() const
Return the kind of stored template argument.
DeclContext * getDeclContext()
QualType getDesugaredType(const ASTContext &Context) const
bool isFunctionOrMethod() const
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isExternallyVisible() const
CharUnits getVBPtrOffset() const
DeclarationName getDeclName() const
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view. Entities in anonymous namespaces are external (in c++9...
QualType getElementType() const
static const TemplateDecl * isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs)
The result type of a method or function.
The COMDAT used for dtors.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
TypedefNameDecl * getTypedefNameForAnonDecl() const
const clang::PrintingPolicy & getPrintingPolicy() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
SourceRange getBracketsRange() const
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const Type * getTypePtr() const
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
TypeOfType (GCC extension).
OverloadedOperatorKind getCXXOverloadedOperator() const
TagDecl - Represents the declaration of a struct/union/class/enum.
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have...
QualType withConst() const
Represents a static or instance method of a struct/union/class.
struct clang::ThisAdjustment::VirtualAdjustment::@116 Microsoft
No ref-qualifier was provided.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
unsigned getCharByteWidth() const
RefQualifierKind
The kind of C++0x ref-qualifier associated with a function type, which determines whether a member fu...
SourceLocation getBegin() const
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
FileID getMainFileID() const
Returns the FileID of the main source file.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
An rvalue ref-qualifier was provided (&&).
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Represents a pointer type decayed from an array or function type.
CXXCtorType
C++ constructor types.
SourceLocation getExprLoc() const LLVM_READONLY
The injected class name of a C++ class template or class template partial specialization. Used to record that a type was spelled with a bare identifier rather than as a template-id; the equivalent for non-templated classes is just RecordType.
QualType getPointeeType() const
Represents a pack expansion of types.
static void mangleThunkThisAdjustment(const CXXMethodDecl *MD, const ThisAdjustment &Adjustment, MicrosoftCXXNameMangler &Mangler, raw_ostream &Out)
Expr * getSizeExpr() const
Base class for declarations which introduce a typedef-name.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
ThisAdjustment This
The this pointer adjustment.
unsigned getByteLength() const
The base class of all kinds of template declarations (e.g., class, function, etc.).
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isLambda() const
Determine whether this class describes a lambda function object.
union clang::ThisAdjustment::VirtualAdjustment Virtual
QualType getPointeeType() const
Not an overloaded operator.
unsigned getTypeQuals() const
QualType getCanonicalType() const
QualType getIntegralType() const
Retrieve the type of the integral value.
bool isFunctionType() const
ReturnAdjustment Return
The return adjustment.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
The template argument is a type.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
bool isStaticDataMember() const
Determines whether this is a static data member.
QualType getPointeeType() const
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
A template argument list.
static LLVM_READONLY bool isIdentifierBody(unsigned char c, bool AllowDollar=false)
const Type * getClass() const
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
int32_t VtordispOffset
The offset of the vtordisp (in bytes), relative to the ECX.
DeclaratorDecl * getDeclaratorForAnonDecl() const
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getParamTypeForDecl() const
Copying closure variant of a ctor.
Defines the clang::TargetInfo interface.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
uint64_t Index
Method's index in the vftable.
static Qualifiers fromCVRMask(unsigned CVR)
Represents a type template specialization; the template must be a class template, a type alias templa...
QualType getElementType() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
StringRef getName(const PrintingPolicy &Policy) const
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
bool nullFieldOffsetIsZero() const
int32_t VBPtrOffset
The offset of the vbptr of the derived class (in bytes), relative to the ECX after vtordisp adjustmen...
This class handles loading and caching of source files into memory.
const MethodVFTableLocation & getMethodVFTableLocation(GlobalDecl GD)
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const
QualType getDeducedType() const
Get the type deduced for this auto type, or null if it's either not been deduced or was deduced to a ...