36#include "llvm/ADT/StringExtras.h"
37#include "llvm/Support/ErrorHandling.h"
38#include "llvm/Support/raw_ostream.h"
39#include "llvm/TargetParser/RISCVTargetParser.h"
46static bool isLocalContainerContext(
const DeclContext *DC) {
47 return isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC) || isa<BlockDecl>(DC);
52 return ftd->getTemplatedDecl();
59 return (fn ? getStructor(fn) :
decl);
62static bool isLambda(
const NamedDecl *ND) {
70static const unsigned UnknownArity = ~0
U;
73 typedef std::pair<const DeclContext*, IdentifierInfo*> DiscriminatorKeyTy;
74 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
75 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
76 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
79 bool NeedsUniqueInternalLinkageNames =
false;
82 explicit ItaniumMangleContextImpl(
84 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 DiscriminatorOverride(DiscriminatorOverride) {}
98 NeedsUniqueInternalLinkageNames =
true;
103 raw_ostream &)
override;
105 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
107 raw_ostream &)
override;
114 bool NormalizeIntegers)
override;
116 bool NormalizeIntegers)
override;
123 raw_ostream &Out)
override;
126 raw_ostream &Out)
override;
128 raw_ostream &Out)
override;
131 raw_ostream &)
override;
139 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
145 if (
const TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
146 if (
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
153 if (discriminator == 1)
155 disc = discriminator - 2;
160 unsigned &discriminator = Uniquifier[ND];
161 if (!discriminator) {
162 const DeclContext *DC = getEffectiveDeclContext(ND);
163 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
165 if (discriminator == 1)
167 disc = discriminator-2;
174 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
175 std::string Name(
"<lambda");
179 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
184 unsigned DefaultArgNo =
186 Name += llvm::utostr(DefaultArgNo);
190 if (LambdaManglingNumber)
191 LambdaId = LambdaManglingNumber;
195 Name += llvm::utostr(LambdaId);
201 return DiscriminatorOverride;
208 return getEffectiveDeclContext(cast<Decl>(DC));
211 bool isInternalLinkageDecl(
const NamedDecl *ND);
217class CXXNameMangler {
218 ItaniumMangleContextImpl &Context;
222 bool NormalizeIntegers =
false;
224 bool NullOut =
false;
229 bool DisableDerivedAbiTags =
false;
235 unsigned StructorType = 0;
240 unsigned TemplateDepthOffset = 0;
245 class FunctionTypeDepthState {
248 enum { InResultTypeMask = 1 };
251 FunctionTypeDepthState() =
default;
254 unsigned getDepth()
const {
259 bool isInResultType()
const {
260 return Bits & InResultTypeMask;
263 FunctionTypeDepthState push() {
264 FunctionTypeDepthState tmp = *
this;
265 Bits = (Bits & ~InResultTypeMask) + 2;
269 void enterResultType() {
270 Bits |= InResultTypeMask;
273 void leaveResultType() {
274 Bits &= ~InResultTypeMask;
277 void pop(FunctionTypeDepthState saved) {
278 assert(getDepth() == saved.getDepth() + 1);
293 class AbiTagState final {
295 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
301 AbiTagState(
const AbiTagState &) =
delete;
302 AbiTagState &operator=(
const AbiTagState &) =
delete;
304 ~AbiTagState() { pop(); }
306 void write(raw_ostream &Out,
const NamedDecl *ND,
307 const AbiTagList *AdditionalAbiTags) {
309 if (!isa<FunctionDecl>(ND) && !isa<VarDecl>(ND)) {
311 !AdditionalAbiTags &&
312 "only function and variables need a list of additional abi tags");
313 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
314 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>()) {
315 UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
316 AbiTag->tags().end());
324 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
325 UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
326 AbiTag->tags().end());
327 TagList.insert(TagList.end(), AbiTag->tags().begin(),
328 AbiTag->tags().end());
331 if (AdditionalAbiTags) {
332 UsedAbiTags.insert(UsedAbiTags.end(), AdditionalAbiTags->begin(),
333 AdditionalAbiTags->end());
334 TagList.insert(TagList.end(), AdditionalAbiTags->begin(),
335 AdditionalAbiTags->end());
339 TagList.erase(std::unique(TagList.begin(), TagList.end()), TagList.end());
341 writeSortedUniqueAbiTags(Out, TagList);
344 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
345 void setUsedAbiTags(
const AbiTagList &AbiTags) {
346 UsedAbiTags = AbiTags;
349 const AbiTagList &getEmittedAbiTags()
const {
350 return EmittedAbiTags;
353 const AbiTagList &getSortedUniqueUsedAbiTags() {
354 llvm::sort(UsedAbiTags);
355 UsedAbiTags.erase(std::unique(UsedAbiTags.begin(), UsedAbiTags.end()),
362 AbiTagList UsedAbiTags;
364 AbiTagList EmittedAbiTags;
366 AbiTagState *&LinkHead;
367 AbiTagState *
Parent =
nullptr;
370 assert(LinkHead ==
this &&
371 "abi tag link head must point to us on destruction");
374 UsedAbiTags.begin(), UsedAbiTags.end());
375 Parent->EmittedAbiTags.insert(
Parent->EmittedAbiTags.end(),
376 EmittedAbiTags.begin(),
377 EmittedAbiTags.end());
382 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
383 for (
const auto &Tag : AbiTags) {
384 EmittedAbiTags.push_back(Tag);
392 AbiTagState *AbiTags =
nullptr;
393 AbiTagState AbiTagsRoot;
395 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
396 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
398 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
401 return Context.getASTContext().
getLangOpts().getClangABICompat() <= Ver;
410 llvm::StringRef Name,
bool HasAllocator);
413 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
414 const NamedDecl *
D =
nullptr,
bool NullOut_ =
false)
415 : Context(
C), Out(Out_), NullOut(NullOut_), Structor(getStructor(
D)),
416 AbiTagsRoot(AbiTags) {
418 assert(!
D || (!isa<CXXDestructorDecl>(
D) &&
419 !isa<CXXConstructorDecl>(
D)));
421 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
423 : Context(
C), Out(Out_), Structor(getStructor(
D)), StructorType(
Type),
424 AbiTagsRoot(AbiTags) {}
425 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
427 : Context(
C), Out(Out_), Structor(getStructor(
D)), StructorType(
Type),
428 AbiTagsRoot(AbiTags) {}
430 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
431 bool NormalizeIntegers_)
432 : Context(
C), Out(Out_), NormalizeIntegers(NormalizeIntegers_),
433 NullOut(
false), Structor(nullptr), AbiTagsRoot(AbiTags) {}
434 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
435 : Context(Outer.Context), Out(Out_), Structor(Outer.Structor),
436 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
437 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
438 Substitutions(Outer.Substitutions),
439 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
441 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
442 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
446 struct WithTemplateDepthOffset {
unsigned Offset; };
447 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
448 WithTemplateDepthOffset Offset)
449 : CXXNameMangler(
C, Out) {
450 TemplateDepthOffset = Offset.Offset;
453 raw_ostream &getStream() {
return Out; }
455 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
456 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
459 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
460 void mangleNumber(
const llvm::APSInt &I);
461 void mangleNumber(int64_t Number);
462 void mangleFloat(
const llvm::APFloat &F);
464 void mangleSeqID(
unsigned SeqID);
467 void mangleNameOrStandardSubstitution(
const NamedDecl *ND);
469 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
470 void mangleVendorQualifier(StringRef Name);
474 bool mangleSubstitution(
const NamedDecl *ND);
482 bool mangleStandardSubstitution(
const NamedDecl *ND);
484 void addSubstitution(
const NamedDecl *ND) {
487 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
492 addSubstitution(
reinterpret_cast<uintptr_t>(NNS));
498 void extendSubstitutions(CXXNameMangler*
Other);
501 bool recursive =
false);
505 unsigned NumTemplateArgs,
506 unsigned KnownArity = UnknownArity);
508 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
511 const AbiTagList *AdditionalAbiTags);
512 void mangleModuleName(
const NamedDecl *ND);
516 const AbiTagList *AdditionalAbiTags) {
517 mangleUnqualifiedName(GD, cast<NamedDecl>(GD.
getDecl())->getDeclName(), DC,
518 UnknownArity, AdditionalAbiTags);
522 const AbiTagList *AdditionalAbiTags);
524 const AbiTagList *AdditionalAbiTags);
526 const AbiTagList *AdditionalAbiTags);
530 void mangleSourceNameWithAbiTags(
531 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags =
nullptr);
533 const AbiTagList *AdditionalAbiTags);
538 void mangleTypeConstraint(
const ConceptDecl *Concept,
541 void mangleRequiresClause(
const Expr *RequiresClause);
544 const AbiTagList *AdditionalAbiTags,
545 bool NoFunction=
false);
548 void mangleNestedNameWithClosurePrefix(
GlobalDecl GD,
550 const AbiTagList *AdditionalAbiTags);
552 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
554 void mangleTemplatePrefix(
GlobalDecl GD,
bool NoFunction=
false);
557 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
558 bool mangleUnresolvedTypeOrSimpleId(
QualType DestroyedType,
559 StringRef Prefix =
"");
568#define ABSTRACT_TYPE(CLASS, PARENT)
569#define NON_CANONICAL_TYPE(CLASS, PARENT)
570#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
571#include "clang/AST/TypeNodes.inc"
573 void mangleType(
const TagType*);
575 static StringRef getCallingConvQualifierName(
CallingConv CC);
582 void mangleAArch64NeonVectorType(
const VectorType *
T);
584 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
586 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
590 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
591 void mangleFixedPointLiteral();
594 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
595 void mangleMemberExpr(
const Expr *base,
bool isArrow,
600 unsigned NumTemplateArgs,
601 unsigned knownArity);
602 void mangleCastExpression(
const Expr *
E, StringRef CastEncoding);
603 void mangleInitListElements(
const InitListExpr *InitList);
606 void mangleExpression(
const Expr *
E,
unsigned Arity = UnknownArity,
607 bool AsTemplateArg =
false);
611 struct TemplateArgManglingInfo;
614 unsigned NumTemplateArgs);
617 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
620 void mangleTemplateArgExpr(
const Expr *
E);
622 bool NeedExactType =
false);
624 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
629 const AbiTagList *AdditionalAbiTags);
632 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
634 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
642 getASTContext(), getASTContext().getTranslationUnitDecl(),
644 &getASTContext().Idents.get(
"std"),
654ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *
D) {
664 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
665 return ContextParam->getDeclContext();
669 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(
D)) {
671 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
672 return ContextParam->getDeclContext();
680 if (
D == getASTContext().getVaListTagDecl()) {
681 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
682 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
683 return getStdNamespace();
687 if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC) ||
688 isa<OMPDeclareMapperDecl>(DC)) {
689 return getEffectiveDeclContext(cast<Decl>(DC));
692 if (
const auto *VD = dyn_cast<VarDecl>(
D))
694 return getASTContext().getTranslationUnitDecl();
696 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
698 return getASTContext().getTranslationUnitDecl();
701 if (FD->isMemberLikeConstrainedFriend() &&
702 getASTContext().getLangOpts().getClangABICompat() >
703 LangOptions::ClangABI::Ver17)
710bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
713 getEffectiveDeclContext(ND)->isFileContext() &&
720bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
722 if (!NeedsUniqueInternalLinkageNames || !ND)
725 const auto *FD = dyn_cast<FunctionDecl>(ND);
734 if (isInternalLinkageDecl(ND))
740bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *
D) {
741 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
744 if (FD->hasAttr<OverloadableAttr>())
760 if (FD->isMSVCRTEntryPoint())
774 if (!getASTContext().getLangOpts().
CPlusPlus)
777 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
779 if (isa<DecompositionDecl>(VD))
792 DC = getEffectiveParentContext(DC);
794 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
795 !isa<VarTemplateSpecializationDecl>(VD) &&
803void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
804 const AbiTagList *AdditionalAbiTags) {
805 assert(AbiTags &&
"require AbiTagState");
806 AbiTags->write(Out, ND, DisableDerivedAbiTags ?
nullptr : AdditionalAbiTags);
809void CXXNameMangler::mangleSourceNameWithAbiTags(
810 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags) {
812 writeAbiTags(ND, AdditionalAbiTags);
820 if (isa<FunctionDecl>(GD.
getDecl()))
821 mangleFunctionEncoding(GD);
826 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
827 mangleName(IFD->getAnonField());
829 llvm_unreachable(
"unexpected kind of global decl");
832void CXXNameMangler::mangleFunctionEncoding(
GlobalDecl GD) {
837 if (!Context.shouldMangleDeclName(FD)) {
842 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
843 if (ReturnTypeAbiTags.empty()) {
852 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
854 FunctionTypeDepth.pop(Saved);
855 mangleFunctionEncodingBareType(FD);
863 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
864 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
866 FunctionEncodingMangler.disableDerivedAbiTags();
868 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
869 FunctionEncodingMangler.mangleNameWithAbiTags(FD,
nullptr);
870 FunctionTypeDepth.pop(Saved);
873 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
874 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
878 const AbiTagList &UsedAbiTags =
879 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
880 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
881 AdditionalAbiTags.erase(
882 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
883 UsedAbiTags.begin(), UsedAbiTags.end(),
884 AdditionalAbiTags.begin()),
885 AdditionalAbiTags.end());
888 Saved = FunctionTypeDepth.push();
889 mangleNameWithAbiTags(FD, &AdditionalAbiTags);
890 FunctionTypeDepth.pop(Saved);
891 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
895 extendSubstitutions(&FunctionEncodingMangler);
898void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
899 if (FD->
hasAttr<EnableIfAttr>()) {
900 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
901 Out <<
"Ua9enable_ifI";
902 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
905 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
908 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
913 mangleExpression(EIA->getCond());
916 mangleTemplateArgExpr(EIA->getCond());
920 FunctionTypeDepth.pop(Saved);
925 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
926 if (
auto Inherited = CD->getInheritedConstructor())
927 FD = Inherited.getConstructor();
945 bool MangleReturnType =
false;
947 if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
948 isa<CXXConversionDecl>(FD)))
949 MangleReturnType =
true;
952 FD = PrimaryTemplate->getTemplatedDecl();
956 MangleReturnType, FD);
961 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
965 return II && II->
isStr(
"std");
970bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
974 return isStd(cast<NamespaceDecl>(DC));
981 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
990 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
991 TemplateArgs = &Spec->getTemplateArgs();
992 return GD.
getWithDecl(Spec->getSpecializedTemplate());
997 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
998 TemplateArgs = &Spec->getTemplateArgs();
999 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1010void CXXNameMangler::mangleName(
GlobalDecl GD) {
1012 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1014 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1015 if (VariableTypeAbiTags.empty()) {
1017 mangleNameWithAbiTags(VD,
nullptr);
1022 llvm::raw_null_ostream NullOutStream;
1023 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1024 VariableNameMangler.disableDerivedAbiTags();
1025 VariableNameMangler.mangleNameWithAbiTags(VD,
nullptr);
1028 const AbiTagList &UsedAbiTags =
1029 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1030 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1031 AdditionalAbiTags.erase(
1032 std::set_difference(VariableTypeAbiTags.begin(),
1033 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1034 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1035 AdditionalAbiTags.end());
1038 mangleNameWithAbiTags(VD, &AdditionalAbiTags);
1040 mangleNameWithAbiTags(GD,
nullptr);
1045 const DeclContext *DC = Context.getEffectiveDeclContext(
D);
1047 if (isLocalContainerContext(DC))
1048 return dyn_cast<RecordDecl>(
D);
1050 DC = Context.getEffectiveDeclContext(
D);
1055void CXXNameMangler::mangleNameWithAbiTags(
GlobalDecl GD,
1056 const AbiTagList *AdditionalAbiTags) {
1063 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1064 bool IsLambda = isLambda(ND);
1070 if (isLocalContainerContext(DC) && ND->
hasLinkage() && !IsLambda)
1072 DC = Context.getEffectiveParentContext(DC);
1073 else if (GetLocalClassDecl(ND) &&
1074 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1075 mangleLocalName(GD, AdditionalAbiTags);
1079 assert(!isa<LinkageSpecDecl>(DC) &&
"context cannot be LinkageSpecDecl");
1083 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1084 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1088 if (isLocalContainerContext(DC)) {
1089 mangleLocalName(GD, AdditionalAbiTags);
1097 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1102 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1106 mangleNestedName(GD, DC, AdditionalAbiTags);
1109void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1112 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1120void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1122 auto It = ModuleSubstitutions.find(Name);
1123 if (It != ModuleSubstitutions.end()) {
1125 mangleSeqID(It->second);
1131 auto Parts = Name.rsplit(
'.');
1132 if (Parts.second.empty())
1133 Parts.second = Parts.first;
1135 mangleModuleNamePrefix(Parts.first, IsPartition);
1136 IsPartition =
false;
1142 Out << Parts.second.size() << Parts.second;
1143 ModuleSubstitutions.insert({Name, SeqID++});
1146void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1148 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1151 mangleUnscopedTemplateName(TD, DC,
nullptr);
1154 mangleNestedName(TD, Args);
1159 const AbiTagList *AdditionalAbiTags) {
1163 assert(!isa<LinkageSpecDecl>(DC) &&
"unskipped LinkageSpecDecl");
1164 if (isStdNamespace(DC))
1167 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1170void CXXNameMangler::mangleUnscopedTemplateName(
1175 if (mangleSubstitution(ND))
1179 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1180 assert(!AdditionalAbiTags &&
1181 "template template param cannot have abi tags");
1182 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1183 }
else if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND)) {
1184 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1190 addSubstitution(ND);
1193void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1207 llvm::APInt valueBits = f.bitcastToAPInt();
1208 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1209 assert(numCharacters != 0);
1215 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1217 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1220 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1221 hexDigit >>= (digitBitIndex % 64);
1225 static const char charForHex[16] = {
1226 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1227 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1229 buffer[stringIndex] = charForHex[hexDigit];
1232 Out.write(buffer.data(), numCharacters);
1235void CXXNameMangler::mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V) {
1242void CXXNameMangler::mangleFixedPointLiteral() {
1249void CXXNameMangler::mangleNullPointer(
QualType T) {
1256void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1257 if (
Value.isSigned() &&
Value.isNegative()) {
1265void CXXNameMangler::mangleNumber(int64_t Number) {
1275void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1283 mangleNumber(NonVirtual);
1289 mangleNumber(NonVirtual);
1297 if (!mangleSubstitution(
QualType(TST, 0))) {
1298 mangleTemplatePrefix(TST->getTemplateName());
1303 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1306 }
else if (
const auto *DTST =
1308 if (!mangleSubstitution(
QualType(DTST, 0))) {
1309 TemplateName Template = getASTContext().getDependentTemplateName(
1310 DTST->getQualifier(), DTST->getIdentifier());
1311 mangleTemplatePrefix(Template);
1316 mangleTemplateArgs(Template, DTST->template_arguments());
1317 addSubstitution(
QualType(DTST, 0));
1347 switch (qualifier->
getKind()) {
1359 llvm_unreachable(
"Can't mangle __super specifier");
1363 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1371 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1388 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1395 if (mangleUnresolvedTypeOrSimpleId(
QualType(
type, 0), recursive ?
"N" :
""))
1404 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1422void CXXNameMangler::mangleUnresolvedName(
1425 unsigned knownArity) {
1426 if (qualifier) mangleUnresolvedPrefix(qualifier);
1427 switch (
name.getNameKind()) {
1430 mangleSourceName(
name.getAsIdentifierInfo());
1435 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1442 mangleOperatorName(name, knownArity);
1445 llvm_unreachable(
"Can't mangle a constructor name!");
1447 llvm_unreachable(
"Can't mangle a using directive name!");
1449 llvm_unreachable(
"Can't mangle a deduction guide name!");
1453 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1459 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1462void CXXNameMangler::mangleUnqualifiedName(
1464 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1472 mangleModuleName(ND);
1476 auto *FD = dyn_cast<FunctionDecl>(ND);
1477 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1479 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1480 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1484 unsigned Arity = KnownArity;
1485 switch (Name.getNameKind()) {
1490 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1497 for (
auto *BD : DD->bindings())
1498 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1500 writeAbiTags(ND, AdditionalAbiTags);
1504 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1507 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1508 llvm::raw_svector_ostream GUIDOS(GUID);
1509 Context.mangleMSGuidDecl(GD, GUIDOS);
1510 Out << GUID.size() << GUID;
1514 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1517 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1518 TPO->getValue(),
true);
1536 if (Context.isInternalLinkageDecl(ND))
1539 bool IsRegCall = FD &&
1543 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1546 mangleDeviceStubName(II);
1548 mangleRegCallName(II);
1550 mangleSourceName(II);
1552 writeAbiTags(ND, AdditionalAbiTags);
1557 assert(ND &&
"mangling empty name without declaration");
1559 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1562 Out <<
"12_GLOBAL__N_1";
1567 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1581 &&
"Expected anonymous struct or union!");
1588 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1601 if (isa<ObjCContainerDecl>(ND))
1605 const TagDecl *TD = cast<TagDecl>(ND);
1608 "Typedef should not be in another decl context!");
1609 assert(
D->getDeclName().getAsIdentifierInfo() &&
1610 "Typedef was not named!");
1611 mangleSourceName(
D->getDeclName().getAsIdentifierInfo());
1612 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1615 writeAbiTags(TD,
nullptr);
1625 std::optional<unsigned> DeviceNumber =
1626 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1632 if (
Record->isLambda() &&
1633 ((DeviceNumber && *DeviceNumber > 0) ||
1634 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1635 assert(!AdditionalAbiTags &&
1636 "Lambda type cannot have additional abi tags");
1643 unsigned UnnamedMangle =
1644 getASTContext().getManglingNumber(TD, Context.isAux());
1646 if (UnnamedMangle > 1)
1647 Out << UnnamedMangle - 2;
1649 writeAbiTags(TD, AdditionalAbiTags);
1655 unsigned AnonStructId =
1657 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1664 Str += llvm::utostr(AnonStructId);
1674 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1680 if (
auto Inherited =
1681 cast<CXXConstructorDecl>(ND)->getInheritedConstructor()) {
1682 InheritedFrom = Inherited.getConstructor()->
getParent();
1683 InheritedTemplateName =
1684 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1685 InheritedTemplateArgs =
1686 Inherited.getConstructor()->getTemplateSpecializationArgs();
1692 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1700 if (InheritedTemplateArgs)
1701 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1703 writeAbiTags(ND, AdditionalAbiTags);
1711 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1717 writeAbiTags(ND, AdditionalAbiTags);
1721 if (ND && Arity == UnknownArity) {
1722 Arity = cast<FunctionDecl>(ND)->getNumParams();
1725 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1726 if (MD->isImplicitObjectMemberFunction())
1732 mangleOperatorName(Name, Arity);
1733 writeAbiTags(ND, AdditionalAbiTags);
1737 llvm_unreachable(
"Can't mangle a deduction guide name!");
1740 llvm_unreachable(
"Can't mangle a using directive name!");
1744void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1748 if (getASTContext().getLangOpts().RegCall4)
1749 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1752 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1756void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1760 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1771void CXXNameMangler::mangleNestedName(
GlobalDecl GD,
1773 const AbiTagList *AdditionalAbiTags,
1782 if (
const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
1783 Qualifiers MethodQuals = Method->getMethodQualifiers();
1786 if (Method->isExplicitObjectMemberFunction())
1789 mangleQualifiers(MethodQuals);
1790 mangleRefQualifier(Method->getRefQualifier());
1796 mangleTemplatePrefix(TD, NoFunction);
1799 manglePrefix(DC, NoFunction);
1800 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1805void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1811 mangleTemplatePrefix(TD);
1817void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1819 const AbiTagList *AdditionalAbiTags) {
1828 mangleClosurePrefix(PrefixND);
1829 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1840 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1842 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1849void CXXNameMangler::mangleLocalName(
GlobalDecl GD,
1850 const AbiTagList *AdditionalAbiTags) {
1857 assert(isa<NamedDecl>(
D) || isa<BlockDecl>(
D));
1859 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD :
D);
1864 AbiTagState LocalAbiTags(AbiTags);
1867 mangleObjCMethodName(MD);
1868 else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
1869 mangleBlockForPrefix(BD);
1875 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1898 mangleNumber(Num - 2);
1907 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1908 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(
D)) {
1909 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1910 mangleClosurePrefix(PrefixND,
true );
1912 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1913 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1914 mangleUnqualifiedBlock(BD);
1917 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1918 AdditionalAbiTags,
true );
1920 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(
D)) {
1924 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1930 mangleNumber(Num - 2);
1935 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1936 mangleUnqualifiedBlock(BD);
1938 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1941 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD :
D)) {
1943 if (Context.getNextDiscriminator(ND, disc)) {
1947 Out <<
"__" << disc <<
'_';
1952void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1953 if (GetLocalClassDecl(
Block)) {
1954 mangleLocalName(
Block,
nullptr);
1958 if (isLocalContainerContext(DC)) {
1959 mangleLocalName(
Block,
nullptr);
1963 mangleClosurePrefix(PrefixND);
1966 mangleUnqualifiedBlock(
Block);
1969void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
1972 if (
Decl *Context =
Block->getBlockManglingContextDecl()) {
1973 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
1974 (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) &&
1975 Context->getDeclContext()->isRecord()) {
1976 const auto *ND = cast<NamedDecl>(Context);
1978 mangleSourceNameWithAbiTags(ND);
1985 unsigned Number =
Block->getBlockManglingNumber();
1989 Number = Context.getBlockId(
Block,
false);
2007void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *
Decl) {
2009 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(
Decl)) {
2010 if (Ty->isParameterPack())
2013 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2016 mangleTypeConstraint(Constraint);
2020 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(
Decl)) {
2021 if (Tn->isExpandedParameterPack()) {
2022 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2024 mangleType(Tn->getExpansionType(I));
2028 if (Tn->isParameterPack()) {
2031 T = PackExpansion->getPattern();
2036 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(
Decl)) {
2037 if (Tt->isExpandedParameterPack()) {
2038 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2040 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2042 if (Tt->isParameterPack())
2044 mangleTemplateParameterList(Tt->getTemplateParameters());
2049void CXXNameMangler::mangleTemplateParameterList(
2052 for (
auto *Param : *Params)
2053 mangleTemplateParamDecl(Param);
2054 mangleRequiresClause(Params->getRequiresClause());
2058void CXXNameMangler::mangleTypeConstraint(
2060 const DeclContext *DC = Context.getEffectiveDeclContext(Concept);
2062 mangleTemplateName(Concept, Arguments);
2064 mangleUnscopedName(Concept, DC,
nullptr);
2066 mangleNestedName(Concept, DC,
nullptr);
2069void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2074 Args.push_back(ArgLoc.getArgument());
2079void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2081 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2083 mangleExpression(RequiresClause);
2087void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2091 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2092 (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) &&
2093 !isa<ParmVarDecl>(Context)) {
2096 mangleSourceName(Name);
2106 mangleLambdaSig(Lambda);
2120 std::optional<unsigned> DeviceNumber =
2121 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2125 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2127 mangleNumber(Number - 2);
2131void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2134 mangleTemplateParamDecl(
D);
2138 mangleRequiresClause(TPL->getRequiresClause());
2142 mangleBareFunctionType(Proto,
false,
2147 switch (qualifier->
getKind()) {
2153 llvm_unreachable(
"Can't mangle __super specifier");
2170 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
2171 if (!Clang14Compat && mangleSubstitution(qualifier))
2182 addSubstitution(qualifier);
2186 llvm_unreachable(
"unexpected nested name specifier");
2189void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2197 assert(!isa<LinkageSpecDecl>(DC) &&
"prefix cannot be LinkageSpecDecl");
2202 if (NoFunction && isLocalContainerContext(DC))
2205 const NamedDecl *ND = cast<NamedDecl>(DC);
2206 if (mangleSubstitution(ND))
2212 mangleTemplatePrefix(TD);
2214 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2215 mangleClosurePrefix(PrefixND, NoFunction);
2216 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2218 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2219 manglePrefix(DC, NoFunction);
2220 mangleUnqualifiedName(ND, DC,
nullptr);
2223 addSubstitution(ND);
2226void CXXNameMangler::mangleTemplatePrefix(
TemplateName Template) {
2231 return mangleTemplatePrefix(TD);
2234 assert(
Dependent &&
"unexpected template name kind");
2238 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2239 if (!Clang11Compat && mangleSubstitution(Template))
2243 manglePrefix(Qualifier);
2245 if (Clang11Compat && mangleSubstitution(Template))
2249 mangleSourceName(
Id);
2251 mangleOperatorName(
Dependent->getOperator(), UnknownArity);
2253 addSubstitution(Template);
2256void CXXNameMangler::mangleTemplatePrefix(
GlobalDecl GD,
2265 if (mangleSubstitution(ND))
2269 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2270 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2272 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2273 manglePrefix(DC, NoFunction);
2274 if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND))
2275 mangleUnqualifiedName(GD, DC,
nullptr);
2281 addSubstitution(ND);
2284const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2285 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2289 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2290 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2291 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2293 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2300 if ((isa<VarDecl>(Context) && cast<VarDecl>(Context)->hasGlobalStorage()) ||
2301 isa<FieldDecl>(Context))
2307void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2310 if (mangleSubstitution(ND))
2315 mangleTemplatePrefix(TD, NoFunction);
2318 const auto *DC = Context.getEffectiveDeclContext(ND);
2319 manglePrefix(DC, NoFunction);
2320 mangleUnqualifiedName(ND, DC,
nullptr);
2325 addSubstitution(ND);
2334 if (mangleSubstitution(TN))
2347 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2348 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2355 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2363 mangleUnresolvedPrefix(
Dependent->getQualifier());
2364 mangleSourceName(
Dependent->getIdentifier());
2384 Out <<
"_SUBSTPACK_";
2389 addSubstitution(TN);
2392bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(
QualType Ty,
2398 case Type::Adjusted:
2400 case Type::ArrayParameter:
2402 case Type::BlockPointer:
2403 case Type::LValueReference:
2404 case Type::RValueReference:
2405 case Type::MemberPointer:
2406 case Type::ConstantArray:
2407 case Type::IncompleteArray:
2408 case Type::VariableArray:
2409 case Type::DependentSizedArray:
2410 case Type::DependentAddressSpace:
2411 case Type::DependentVector:
2412 case Type::DependentSizedExtVector:
2414 case Type::ExtVector:
2415 case Type::ConstantMatrix:
2416 case Type::DependentSizedMatrix:
2417 case Type::FunctionProto:
2418 case Type::FunctionNoProto:
2420 case Type::Attributed:
2421 case Type::BTFTagAttributed:
2423 case Type::DeducedTemplateSpecialization:
2424 case Type::PackExpansion:
2425 case Type::ObjCObject:
2426 case Type::ObjCInterface:
2427 case Type::ObjCObjectPointer:
2428 case Type::ObjCTypeParam:
2431 case Type::MacroQualified:
2433 case Type::DependentBitInt:
2434 case Type::CountAttributed:
2435 llvm_unreachable(
"type is illegal as a nested name specifier");
2437 case Type::SubstTemplateTypeParmPack:
2442 Out <<
"_SUBSTPACK_";
2449 case Type::TypeOfExpr:
2451 case Type::Decltype:
2452 case Type::PackIndexing:
2453 case Type::TemplateTypeParm:
2454 case Type::UnaryTransform:
2455 case Type::SubstTemplateTypeParm:
2469 mangleSourceNameWithAbiTags(cast<TypedefType>(Ty)->getDecl());
2472 case Type::UnresolvedUsing:
2473 mangleSourceNameWithAbiTags(
2474 cast<UnresolvedUsingType>(Ty)->getDecl());
2479 mangleSourceNameWithAbiTags(cast<TagType>(Ty)->getDecl());
2482 case Type::TemplateSpecialization: {
2484 cast<TemplateSpecializationType>(Ty);
2493 assert(TD &&
"no template for template specialization type");
2494 if (isa<TemplateTemplateParmDecl>(TD))
2495 goto unresolvedType;
2497 mangleSourceNameWithAbiTags(TD);
2504 llvm_unreachable(
"invalid base for a template specialization type");
2518 Out <<
"_SUBSTPACK_";
2523 assert(TD && !isa<TemplateTemplateParmDecl>(TD));
2524 mangleSourceNameWithAbiTags(TD);
2538 case Type::InjectedClassName:
2539 mangleSourceNameWithAbiTags(
2540 cast<InjectedClassNameType>(Ty)->getDecl());
2543 case Type::DependentName:
2544 mangleSourceName(cast<DependentNameType>(Ty)->
getIdentifier());
2547 case Type::DependentTemplateSpecialization: {
2549 cast<DependentTemplateSpecializationType>(Ty);
2550 TemplateName Template = getASTContext().getDependentTemplateName(
2558 return mangleUnresolvedTypeOrSimpleId(cast<UsingType>(Ty)->desugar(),
2560 case Type::Elaborated:
2561 return mangleUnresolvedTypeOrSimpleId(
2562 cast<ElaboratedType>(Ty)->getNamedType(), Prefix);
2568void CXXNameMangler::mangleOperatorName(
DeclarationName Name,
unsigned Arity) {
2569 switch (Name.getNameKind()) {
2578 llvm_unreachable(
"Not an operator name");
2583 mangleType(Name.getCXXNameType());
2588 mangleSourceName(Name.getCXXLiteralIdentifier());
2592 mangleOperatorName(Name.getCXXOverloadedOperator(), Arity);
2601 case OO_New: Out <<
"nw";
break;
2603 case OO_Array_New: Out <<
"na";
break;
2605 case OO_Delete: Out <<
"dl";
break;
2607 case OO_Array_Delete: Out <<
"da";
break;
2611 Out << (Arity == 1?
"ps" :
"pl");
break;
2615 Out << (Arity == 1?
"ng" :
"mi");
break;
2619 Out << (Arity == 1?
"ad" :
"an");
break;
2624 Out << (Arity == 1?
"de" :
"ml");
break;
2626 case OO_Tilde: Out <<
"co";
break;
2628 case OO_Slash: Out <<
"dv";
break;
2630 case OO_Percent: Out <<
"rm";
break;
2632 case OO_Pipe: Out <<
"or";
break;
2634 case OO_Caret: Out <<
"eo";
break;
2636 case OO_Equal: Out <<
"aS";
break;
2638 case OO_PlusEqual: Out <<
"pL";
break;
2640 case OO_MinusEqual: Out <<
"mI";
break;
2642 case OO_StarEqual: Out <<
"mL";
break;
2644 case OO_SlashEqual: Out <<
"dV";
break;
2646 case OO_PercentEqual: Out <<
"rM";
break;
2648 case OO_AmpEqual: Out <<
"aN";
break;
2650 case OO_PipeEqual: Out <<
"oR";
break;
2652 case OO_CaretEqual: Out <<
"eO";
break;
2654 case OO_LessLess: Out <<
"ls";
break;
2656 case OO_GreaterGreater: Out <<
"rs";
break;
2658 case OO_LessLessEqual: Out <<
"lS";
break;
2660 case OO_GreaterGreaterEqual: Out <<
"rS";
break;
2662 case OO_EqualEqual: Out <<
"eq";
break;
2664 case OO_ExclaimEqual: Out <<
"ne";
break;
2666 case OO_Less: Out <<
"lt";
break;
2668 case OO_Greater: Out <<
"gt";
break;
2670 case OO_LessEqual: Out <<
"le";
break;
2672 case OO_GreaterEqual: Out <<
"ge";
break;
2674 case OO_Exclaim: Out <<
"nt";
break;
2676 case OO_AmpAmp: Out <<
"aa";
break;
2678 case OO_PipePipe: Out <<
"oo";
break;
2680 case OO_PlusPlus: Out <<
"pp";
break;
2682 case OO_MinusMinus: Out <<
"mm";
break;
2684 case OO_Comma: Out <<
"cm";
break;
2686 case OO_ArrowStar: Out <<
"pm";
break;
2688 case OO_Arrow: Out <<
"pt";
break;
2690 case OO_Call: Out <<
"cl";
break;
2692 case OO_Subscript: Out <<
"ix";
break;
2697 case OO_Conditional: Out <<
"qu";
break;
2700 case OO_Coawait: Out <<
"aw";
break;
2703 case OO_Spaceship: Out <<
"ss";
break;
2707 llvm_unreachable(
"Not an overloaded operator");
2736 if (TargetAS != 0 ||
2738 ASString =
"AS" + llvm::utostr(TargetAS);
2741 default: llvm_unreachable(
"Not a language specific address space");
2745 case LangAS::opencl_global:
2746 ASString =
"CLglobal";
2748 case LangAS::opencl_global_device:
2749 ASString =
"CLdevice";
2751 case LangAS::opencl_global_host:
2752 ASString =
"CLhost";
2754 case LangAS::opencl_local:
2755 ASString =
"CLlocal";
2757 case LangAS::opencl_constant:
2758 ASString =
"CLconstant";
2760 case LangAS::opencl_private:
2761 ASString =
"CLprivate";
2763 case LangAS::opencl_generic:
2764 ASString =
"CLgeneric";
2768 case LangAS::sycl_global:
2769 ASString =
"SYglobal";
2771 case LangAS::sycl_global_device:
2772 ASString =
"SYdevice";
2774 case LangAS::sycl_global_host:
2775 ASString =
"SYhost";
2777 case LangAS::sycl_local:
2778 ASString =
"SYlocal";
2780 case LangAS::sycl_private:
2781 ASString =
"SYprivate";
2784 case LangAS::cuda_device:
2785 ASString =
"CUdevice";
2787 case LangAS::cuda_constant:
2788 ASString =
"CUconstant";
2790 case LangAS::cuda_shared:
2791 ASString =
"CUshared";
2794 case LangAS::ptr32_sptr:
2795 ASString =
"ptr32_sptr";
2797 case LangAS::ptr32_uptr:
2801 if (!getASTContext().getTargetInfo().getTriple().isOSzOS())
2802 ASString =
"ptr32_uptr";
2809 if (!ASString.empty())
2810 mangleVendorQualifier(ASString);
2823 mangleVendorQualifier(
"__weak");
2827 mangleVendorQualifier(
"__unaligned");
2839 mangleVendorQualifier(
"__strong");
2843 mangleVendorQualifier(
"__autoreleasing");
2866void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2873 switch (RefQualifier) {
2887void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2888 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2901 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2907 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2914 if (DeducedTST->getDeducedType().isNull())
2919void CXXNameMangler::mangleType(
QualType T) {
2953 T =
T.getCanonicalType();
2960 = dyn_cast<TemplateSpecializationType>(
T))
2969 =
T.getSingleStepDesugaredType(Context.getASTContext());
2978 const Type *ty = split.
Ty;
2980 bool isSubstitutable =
2982 if (isSubstitutable && mangleSubstitution(
T))
2987 if (quals && isa<ArrayType>(
T)) {
2997 dyn_cast<DependentAddressSpaceType>(ty)) {
2999 mangleQualifiers(splitDAST.
Quals, DAST);
3002 mangleQualifiers(quals);
3010#define ABSTRACT_TYPE(CLASS, PARENT)
3011#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3013 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3015#define TYPE(CLASS, PARENT) \
3017 mangleType(static_cast<const CLASS##Type*>(ty)); \
3019#include "clang/AST/TypeNodes.inc"
3024 if (isSubstitutable)
3028void CXXNameMangler::mangleNameOrStandardSubstitution(
const NamedDecl *ND) {
3029 if (!mangleStandardSubstitution(ND))
3075 std::string type_name;
3079 if (NormalizeIntegers &&
T->isInteger()) {
3080 if (
T->isSignedInteger()) {
3081 switch (getASTContext().getTypeSize(
T)) {
3085 if (mangleSubstitution(BuiltinType::SChar))
3088 addSubstitution(BuiltinType::SChar);
3091 if (mangleSubstitution(BuiltinType::Short))
3094 addSubstitution(BuiltinType::Short);
3097 if (mangleSubstitution(BuiltinType::Int))
3100 addSubstitution(BuiltinType::Int);
3103 if (mangleSubstitution(BuiltinType::Long))
3106 addSubstitution(BuiltinType::Long);
3109 if (mangleSubstitution(BuiltinType::Int128))
3112 addSubstitution(BuiltinType::Int128);
3115 llvm_unreachable(
"Unknown integer size for normalization");
3118 switch (getASTContext().getTypeSize(
T)) {
3120 if (mangleSubstitution(BuiltinType::UChar))
3123 addSubstitution(BuiltinType::UChar);
3126 if (mangleSubstitution(BuiltinType::UShort))
3129 addSubstitution(BuiltinType::UShort);
3132 if (mangleSubstitution(BuiltinType::UInt))
3135 addSubstitution(BuiltinType::UInt);
3138 if (mangleSubstitution(BuiltinType::ULong))
3141 addSubstitution(BuiltinType::ULong);
3144 if (mangleSubstitution(BuiltinType::UInt128))
3147 addSubstitution(BuiltinType::UInt128);
3150 llvm_unreachable(
"Unknown integer size for normalization");
3155 switch (
T->getKind()) {
3156 case BuiltinType::Void:
3159 case BuiltinType::Bool:
3162 case BuiltinType::Char_U:
3163 case BuiltinType::Char_S:
3166 case BuiltinType::UChar:
3169 case BuiltinType::UShort:
3172 case BuiltinType::UInt:
3175 case BuiltinType::ULong:
3178 case BuiltinType::ULongLong:
3181 case BuiltinType::UInt128:
3184 case BuiltinType::SChar:
3187 case BuiltinType::WChar_S:
3188 case BuiltinType::WChar_U:
3191 case BuiltinType::Char8:
3194 case BuiltinType::Char16:
3197 case BuiltinType::Char32:
3200 case BuiltinType::Short:
3203 case BuiltinType::Int:
3206 case BuiltinType::Long:
3209 case BuiltinType::LongLong:
3212 case BuiltinType::Int128:
3215 case BuiltinType::Float16:
3218 case BuiltinType::ShortAccum:
3221 case BuiltinType::Accum:
3224 case BuiltinType::LongAccum:
3227 case BuiltinType::UShortAccum:
3230 case BuiltinType::UAccum:
3233 case BuiltinType::ULongAccum:
3236 case BuiltinType::ShortFract:
3239 case BuiltinType::Fract:
3242 case BuiltinType::LongFract:
3245 case BuiltinType::UShortFract:
3248 case BuiltinType::UFract:
3251 case BuiltinType::ULongFract:
3254 case BuiltinType::SatShortAccum:
3257 case BuiltinType::SatAccum:
3260 case BuiltinType::SatLongAccum:
3263 case BuiltinType::SatUShortAccum:
3266 case BuiltinType::SatUAccum:
3269 case BuiltinType::SatULongAccum:
3272 case BuiltinType::SatShortFract:
3275 case BuiltinType::SatFract:
3278 case BuiltinType::SatLongFract:
3281 case BuiltinType::SatUShortFract:
3284 case BuiltinType::SatUFract:
3287 case BuiltinType::SatULongFract:
3290 case BuiltinType::Half:
3293 case BuiltinType::Float:
3296 case BuiltinType::Double:
3299 case BuiltinType::LongDouble: {
3301 getASTContext().getLangOpts().OpenMP &&
3302 getASTContext().getLangOpts().OpenMPIsTargetDevice
3303 ? getASTContext().getAuxTargetInfo()
3304 : &getASTContext().getTargetInfo();
3308 case BuiltinType::Float128: {
3310 getASTContext().getLangOpts().OpenMP &&
3311 getASTContext().getLangOpts().OpenMPIsTargetDevice
3312 ? getASTContext().getAuxTargetInfo()
3313 : &getASTContext().getTargetInfo();
3317 case BuiltinType::BFloat16: {
3319 ((getASTContext().getLangOpts().OpenMP &&
3320 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3321 getASTContext().getLangOpts().SYCLIsDevice)
3322 ? getASTContext().getAuxTargetInfo()
3323 : &getASTContext().getTargetInfo();
3327 case BuiltinType::Ibm128: {
3328 const TargetInfo *TI = &getASTContext().getTargetInfo();
3332 case BuiltinType::NullPtr:
3336#define BUILTIN_TYPE(Id, SingletonId)
3337#define PLACEHOLDER_TYPE(Id, SingletonId) \
3338 case BuiltinType::Id:
3339#include "clang/AST/BuiltinTypes.def"
3340 case BuiltinType::Dependent:
3342 llvm_unreachable(
"mangling a placeholder type");
3344 case BuiltinType::ObjCId:
3345 Out <<
"11objc_object";
3347 case BuiltinType::ObjCClass:
3348 Out <<
"10objc_class";
3350 case BuiltinType::ObjCSel:
3351 Out <<
"13objc_selector";
3353#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3354 case BuiltinType::Id: \
3355 type_name = "ocl_" #ImgType "_" #Suffix; \
3356 Out << type_name.size() << type_name; \
3358#include "clang/Basic/OpenCLImageTypes.def"
3359 case BuiltinType::OCLSampler:
3360 Out <<
"11ocl_sampler";
3362 case BuiltinType::OCLEvent:
3363 Out <<
"9ocl_event";
3365 case BuiltinType::OCLClkEvent:
3366 Out <<
"12ocl_clkevent";
3368 case BuiltinType::OCLQueue:
3369 Out <<
"9ocl_queue";
3371 case BuiltinType::OCLReserveID:
3372 Out <<
"13ocl_reserveid";
3374#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3375 case BuiltinType::Id: \
3376 type_name = "ocl_" #ExtType; \
3377 Out << type_name.size() << type_name; \
3379#include "clang/Basic/OpenCLExtensionTypes.def"
3383#define SVE_VECTOR_TYPE(InternalName, MangledName, Id, SingletonId, NumEls, \
3384 ElBits, IsSigned, IsFP, IsBF) \
3385 case BuiltinType::Id: \
3386 if (T->getKind() == BuiltinType::SveBFloat16 && \
3387 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3389 type_name = "__SVBFloat16_t"; \
3390 Out << "u" << type_name.size() << type_name; \
3392 type_name = MangledName; \
3393 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3397#define SVE_PREDICATE_TYPE(InternalName, MangledName, Id, SingletonId, NumEls) \
3398 case BuiltinType::Id: \
3399 type_name = MangledName; \
3400 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3403#define SVE_OPAQUE_TYPE(InternalName, MangledName, Id, SingletonId) \
3404 case BuiltinType::Id: \
3405 type_name = MangledName; \
3406 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3409#include "clang/Basic/AArch64SVEACLETypes.def"
3410#define PPC_VECTOR_TYPE(Name, Id, Size) \
3411 case BuiltinType::Id: \
3412 type_name = #Name; \
3413 Out << 'u' << type_name.size() << type_name; \
3415#include "clang/Basic/PPCTypes.def"
3417#define RVV_TYPE(Name, Id, SingletonId) \
3418 case BuiltinType::Id: \
3420 Out << 'u' << type_name.size() << type_name; \
3422#include "clang/Basic/RISCVVTypes.def"
3423#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3424 case BuiltinType::Id: \
3425 type_name = MangledName; \
3426 Out << 'u' << type_name.size() << type_name; \
3428#include "clang/Basic/WebAssemblyReferenceTypes.def"
3429#define AMDGPU_TYPE(Name, Id, SingletonId) \
3430 case BuiltinType::Id: \
3432 Out << 'u' << type_name.size() << type_name; \
3434#include "clang/Basic/AMDGPUTypes.def"
3435#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3436 case BuiltinType::Id: \
3437 type_name = #Name; \
3438 Out << 'u' << type_name.size() << type_name; \
3440#include "clang/Basic/HLSLIntangibleTypes.def"
3444StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3487 return "swiftasynccall";
3489 llvm_unreachable(
"bad calling convention");
3492void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3501 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3502 if (!CCQualifier.empty())
3503 mangleVendorQualifier(CCQualifier);
3517 case ParameterABI::Ordinary:
3521 case ParameterABI::SwiftContext:
3522 case ParameterABI::SwiftAsyncContext:
3523 case ParameterABI::SwiftErrorResult:
3524 case ParameterABI::SwiftIndirectResult:
3530 mangleVendorQualifier(
"ns_consumed");
3533 mangleVendorQualifier(
"noescape");
3540 mangleExtFunctionInfo(
T);
3557 mangleType(ExceptTy);
3568 mangleBareFunctionType(
T,
true);
3582 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3584 FunctionTypeDepth.enterResultType();
3586 FunctionTypeDepth.leaveResultType();
3588 FunctionTypeDepth.pop(saved);
3593 bool MangleReturnType,
3597 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3600 if (MangleReturnType) {
3601 FunctionTypeDepth.enterResultType();
3605 mangleVendorQualifier(
"ns_returns_retained");
3610 auto SplitReturnTy = ReturnTy.
split();
3612 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3614 mangleType(ReturnTy);
3616 FunctionTypeDepth.leaveResultType();
3638 assert(
Attr->getType() <= 9 &&
Attr->getType() >= 0);
3639 if (
Attr->isDynamic())
3640 Out <<
"U25pass_dynamic_object_size" <<
Attr->getType();
3642 Out <<
"U17pass_object_size" <<
Attr->getType();
3653 FunctionTypeDepth.enterResultType();
3657 FunctionTypeDepth.pop(saved);
3663 mangleName(
T->getDecl());
3668void CXXNameMangler::mangleType(
const EnumType *
T) {
3669 mangleType(
static_cast<const TagType*
>(
T));
3671void CXXNameMangler::mangleType(
const RecordType *
T) {
3672 mangleType(
static_cast<const TagType*
>(
T));
3674void CXXNameMangler::mangleType(
const TagType *
T) {
3675 mangleName(
T->getDecl());
3682 Out <<
'A' <<
T->getSize() <<
'_';
3683 mangleType(
T->getElementType());
3688 if (
T->getSizeExpr())
3689 mangleExpression(
T->getSizeExpr());
3691 mangleType(
T->getElementType());
3698 if (
T->getSizeExpr())
3699 mangleExpression(
T->getSizeExpr());
3701 mangleType(
T->getElementType());
3705 mangleType(
T->getElementType());
3735 mangleType(PointeeType);
3740 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3749 Out <<
"_SUBSTPACK_";
3777 mangleType(
T->getElementType());
3783void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
3785 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3786 const char *EltName =
nullptr;
3787 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3788 switch (cast<BuiltinType>(EltType)->
getKind()) {
3789 case BuiltinType::SChar:
3790 case BuiltinType::UChar:
3791 EltName =
"poly8_t";
3793 case BuiltinType::Short:
3794 case BuiltinType::UShort:
3795 EltName =
"poly16_t";
3797 case BuiltinType::LongLong:
3798 case BuiltinType::ULongLong:
3799 EltName =
"poly64_t";
3801 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3804 switch (cast<BuiltinType>(EltType)->
getKind()) {
3805 case BuiltinType::SChar: EltName =
"int8_t";
break;
3806 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3807 case BuiltinType::Short: EltName =
"int16_t";
break;
3808 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3809 case BuiltinType::Int: EltName =
"int32_t";
break;
3810 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3811 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3812 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3813 case BuiltinType::Double: EltName =
"float64_t";
break;
3814 case BuiltinType::Float: EltName =
"float32_t";
break;
3815 case BuiltinType::Half: EltName =
"float16_t";
break;
3816 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3818 llvm_unreachable(
"unexpected Neon vector element type");
3821 const char *BaseName =
nullptr;
3822 unsigned BitSize = (
T->getNumElements() *
3823 getASTContext().getTypeSize(EltType));
3825 BaseName =
"__simd64_";
3827 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
3828 BaseName =
"__simd128_";
3830 Out << strlen(BaseName) + strlen(EltName);
3831 Out << BaseName << EltName;
3838 "cannot mangle this dependent neon vector type yet");
3839 Diags.
Report(
T->getAttributeLoc(), DiagID);
3844 case BuiltinType::SChar:
3846 case BuiltinType::Short:
3848 case BuiltinType::Int:
3850 case BuiltinType::Long:
3851 case BuiltinType::LongLong:
3853 case BuiltinType::UChar:
3855 case BuiltinType::UShort:
3857 case BuiltinType::UInt:
3859 case BuiltinType::ULong:
3860 case BuiltinType::ULongLong:
3862 case BuiltinType::Half:
3864 case BuiltinType::Float:
3866 case BuiltinType::Double:
3868 case BuiltinType::BFloat16:
3871 llvm_unreachable(
"Unexpected vector element base type");
3878void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
3880 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3882 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
3885 assert((BitSize == 64 || BitSize == 128) &&
3886 "Neon vector type not 64 or 128 bits");
3889 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3890 switch (cast<BuiltinType>(EltType)->
getKind()) {
3891 case BuiltinType::UChar:
3894 case BuiltinType::UShort:
3897 case BuiltinType::ULong:
3898 case BuiltinType::ULongLong:
3902 llvm_unreachable(
"unexpected Neon polynomial vector element type");
3908 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
3915 "cannot mangle this dependent neon vector type yet");
3916 Diags.
Report(
T->getAttributeLoc(), DiagID);
3943void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
3944 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
3945 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
3946 "expected fixed-length SVE vector!");
3950 "expected builtin type for fixed-length SVE vector!");
3953 switch (cast<BuiltinType>(EltType)->
getKind()) {
3954 case BuiltinType::SChar:
3957 case BuiltinType::UChar: {
3958 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
3964 case BuiltinType::Short:
3967 case BuiltinType::UShort:
3970 case BuiltinType::Int:
3973 case BuiltinType::UInt:
3976 case BuiltinType::Long:
3979 case BuiltinType::ULong:
3982 case BuiltinType::Half:
3985 case BuiltinType::Float:
3988 case BuiltinType::Double:
3991 case BuiltinType::BFloat16:
3995 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
3998 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4000 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4004 << VecSizeInBits <<
"EE";
4007void CXXNameMangler::mangleAArch64FixedSveVectorType(
4012 "cannot mangle this dependent fixed-length SVE vector type yet");
4013 Diags.
Report(
T->getAttributeLoc(), DiagID);
4016void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4017 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4018 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4019 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4020 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4021 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4022 "expected fixed-length RVV vector!");
4026 "expected builtin type for fixed-length RVV vector!");
4029 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4030 TypeNameOS <<
"__rvv_";
4031 switch (cast<BuiltinType>(EltType)->
getKind()) {
4032 case BuiltinType::SChar:
4033 TypeNameOS <<
"int8";
4035 case BuiltinType::UChar:
4036 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4037 TypeNameOS <<
"uint8";
4039 TypeNameOS <<
"bool";
4041 case BuiltinType::Short:
4042 TypeNameOS <<
"int16";
4044 case BuiltinType::UShort:
4045 TypeNameOS <<
"uint16";
4047 case BuiltinType::Int:
4048 TypeNameOS <<
"int32";
4050 case BuiltinType::UInt:
4051 TypeNameOS <<
"uint32";
4053 case BuiltinType::Long:
4054 TypeNameOS <<
"int64";
4056 case BuiltinType::ULong:
4057 TypeNameOS <<
"uint64";
4059 case BuiltinType::Float16:
4060 TypeNameOS <<
"float16";
4062 case BuiltinType::Float:
4063 TypeNameOS <<
"float32";
4065 case BuiltinType::Double:
4066 TypeNameOS <<
"float64";
4069 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4072 unsigned VecSizeInBits;
4073 switch (
T->getVectorKind()) {
4074 case VectorKind::RVVFixedLengthMask_1:
4077 case VectorKind::RVVFixedLengthMask_2:
4080 case VectorKind::RVVFixedLengthMask_4:
4084 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4089 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4090 getASTContext().getLangOpts());
4091 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4093 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4095 if (VecSizeInBits >= VLen)
4096 TypeNameOS << (VecSizeInBits / VLen);
4098 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4100 TypeNameOS << (VLen / VecSizeInBits);
4104 Out <<
"9__RVV_VLSI" <<
'u' << TypeNameStr.size() << TypeNameStr <<
"Lj"
4105 << VecSizeInBits <<
"EE";
4108void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4113 "cannot mangle this dependent fixed-length RVV vector type yet");
4114 Diags.
Report(
T->getAttributeLoc(), DiagID);
4125void CXXNameMangler::mangleType(
const VectorType *
T) {
4126 if ((
T->getVectorKind() == VectorKind::Neon ||
4127 T->getVectorKind() == VectorKind::NeonPoly)) {
4128 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4129 llvm::Triple::ArchType Arch =
4130 getASTContext().getTargetInfo().getTriple().getArch();
4131 if ((Arch == llvm::Triple::aarch64 ||
4132 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4133 mangleAArch64NeonVectorType(
T);
4135 mangleNeonVectorType(
T);
4137 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4138 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4139 mangleAArch64FixedSveVectorType(
T);
4141 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4142 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4143 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4144 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4145 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4146 mangleRISCVFixedRVVVectorType(
T);
4149 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4150 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4152 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4155 mangleType(
T->getElementType());
4159 if ((
T->getVectorKind() == VectorKind::Neon ||
4160 T->getVectorKind() == VectorKind::NeonPoly)) {
4161 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4162 llvm::Triple::ArchType Arch =
4163 getASTContext().getTargetInfo().getTriple().getArch();
4164 if ((Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be) &&
4166 mangleAArch64NeonVectorType(
T);
4168 mangleNeonVectorType(
T);
4170 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4171 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4172 mangleAArch64FixedSveVectorType(
T);
4174 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4175 mangleRISCVFixedRVVVectorType(
T);
4180 mangleExpression(
T->getSizeExpr());
4182 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4184 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4187 mangleType(
T->getElementType());
4195 mangleExpression(
T->getSizeExpr());
4197 mangleType(
T->getElementType());
4204 StringRef VendorQualifier =
"matrix_type";
4205 Out <<
"u" << VendorQualifier.size() << VendorQualifier;
4208 auto &ASTCtx = getASTContext();
4209 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4210 llvm::APSInt Rows(BitWidth);
4211 Rows =
T->getNumRows();
4212 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4213 llvm::APSInt Columns(BitWidth);
4214 Columns =
T->getNumColumns();
4215 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4216 mangleType(
T->getElementType());
4223 StringRef VendorQualifier =
"matrix_type";
4224 Out <<
"u" << VendorQualifier.size() << VendorQualifier;
4227 mangleTemplateArgExpr(
T->getRowExpr());
4228 mangleTemplateArgExpr(
T->getColumnExpr());
4229 mangleType(
T->getElementType());
4235 mangleQualifiers(split.
Quals,
T);
4242 mangleType(
T->getPattern());
4246 if (!
T->hasSelectedType())
4247 mangleType(
T->getPattern());
4249 mangleType(
T->getSelectedType());
4253 mangleSourceName(
T->getDecl()->getIdentifier());
4258 if (
T->isKindOfType())
4259 Out <<
"U8__kindof";
4261 if (!
T->qual_empty()) {
4264 llvm::raw_svector_ostream QualOS(QualStr);
4265 QualOS <<
"objcproto";
4266 for (
const auto *I :
T->quals()) {
4267 StringRef
name = I->getName();
4270 Out <<
'U' << QualStr.size() << QualStr;
4273 mangleType(
T->getBaseType());
4275 if (
T->isSpecialized()) {
4278 for (
auto typeArg :
T->getTypeArgs())
4279 mangleType(typeArg);
4285 Out <<
"U13block_pointer";
4293 mangleType(
T->getInjectedSpecializationType());
4297 if (
TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4298 mangleTemplateName(TD,
T->template_arguments());
4303 mangleTemplatePrefix(
T->getTemplateName());
4308 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4324 switch (
T->getKeyword()) {
4325 case ElaboratedTypeKeyword::None:
4326 case ElaboratedTypeKeyword::Typename:
4328 case ElaboratedTypeKeyword::Struct:
4329 case ElaboratedTypeKeyword::Class:
4330 case ElaboratedTypeKeyword::Interface:
4333 case ElaboratedTypeKeyword::Union:
4336 case ElaboratedTypeKeyword::Enum:
4342 manglePrefix(
T->getQualifier());
4343 mangleSourceName(
T->getIdentifier());
4353 getASTContext().getDependentTemplateName(
T->getQualifier(),
4354 T->getIdentifier());
4355 mangleTemplatePrefix(Prefix);
4360 mangleTemplateArgs(Prefix,
T->template_arguments());
4364void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4377 Expr *
E =
T->getUnderlyingExpr();
4387 if (isa<DeclRefExpr>(
E) ||
4388 isa<MemberExpr>(
E) ||
4389 isa<UnresolvedLookupExpr>(
E) ||
4390 isa<DependentScopeDeclRefExpr>(
E) ||
4391 isa<CXXDependentScopeMemberExpr>(
E) ||
4392 isa<UnresolvedMemberExpr>(
E))
4396 mangleExpression(
E);
4406 StringRef BuiltinName;
4407 switch (
T->getUTTKind()) {
4408#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4409 case UnaryTransformType::Enum: \
4410 BuiltinName = "__" #Trait; \
4412#include "clang/Basic/TransformTypeTraits.def"
4414 Out << BuiltinName.size() << BuiltinName;
4418 mangleType(
T->getBaseType());
4422void CXXNameMangler::mangleType(
const AutoType *
T) {
4423 assert(
T->getDeducedType().isNull() &&
4424 "Deduced AutoType shouldn't be handled here!");
4425 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4426 "shouldn't need to mangle __auto_type!");
4431 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4432 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4433 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4434 T->getTypeConstraintArguments());
4436 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4443 return mangleType(Deduced);
4445 TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl();
4446 assert(TD &&
"shouldn't form deduced TST unless we know we have a template");
4448 if (mangleSubstitution(TD))
4452 addSubstitution(TD);
4455void CXXNameMangler::mangleType(
const AtomicType *
T) {
4459 mangleType(
T->getValueType());
4462void CXXNameMangler::mangleType(
const PipeType *
T) {
4469void CXXNameMangler::mangleType(
const BitIntType *
T) {
4473 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4480 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4481 mangleExpression(
T->getNumBitsExpr());
4486 mangleType(cast<ConstantArrayType>(
T));
4489void CXXNameMangler::mangleIntegerLiteral(
QualType T,
4490 const llvm::APSInt &
Value) {
4497 Out << (
Value.getBoolValue() ?
'1' :
'0');
4499 mangleNumber(
Value);
4505void CXXNameMangler::mangleMemberExprBase(
const Expr *
Base,
bool IsArrow) {
4508 if (!RT->getDecl()->isAnonymousStructOrUnion())
4510 const auto *ME = dyn_cast<MemberExpr>(
Base);
4513 Base = ME->getBase();
4514 IsArrow = ME->isArrow();
4517 if (
Base->isImplicitCXXThis()) {
4523 Out << (IsArrow ?
"pt" :
"dt");
4524 mangleExpression(
Base);
4529void CXXNameMangler::mangleMemberExpr(
const Expr *base,
4535 unsigned NumTemplateArgs,
4540 mangleMemberExprBase(base, isArrow);
4541 mangleUnresolvedName(qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4554 if (callee == fn)
return false;
4558 if (!lookup)
return false;
4575void CXXNameMangler::mangleCastExpression(
const Expr *
E, StringRef CastEncoding) {
4577 Out << CastEncoding;
4582void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4584 InitList = Syntactic;
4585 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4586 mangleExpression(InitList->
getInit(i));
4589void CXXNameMangler::mangleRequirement(
SourceLocation RequiresExprLoc,
4596 auto HandleSubstitutionFailure =
4601 "containing a substitution failure");
4607 case Requirement::RK_Type: {
4608 const auto *TR = cast<concepts::TypeRequirement>(Req);
4609 if (TR->isSubstitutionFailure())
4610 return HandleSubstitutionFailure(
4611 TR->getSubstitutionDiagnostic()->DiagLoc);
4614 mangleType(TR->getType()->getType());
4618 case Requirement::RK_Simple:
4619 case Requirement::RK_Compound: {
4620 const auto *ER = cast<concepts::ExprRequirement>(Req);
4621 if (ER->isExprSubstitutionFailure())
4622 return HandleSubstitutionFailure(
4623 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4626 mangleExpression(ER->getExpr());
4628 if (ER->hasNoexceptRequirement())
4631 if (!ER->getReturnTypeRequirement().isEmpty()) {
4632 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4633 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4634 .getSubstitutionDiagnostic()
4638 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4643 case Requirement::RK_Nested:
4644 const auto *NR = cast<concepts::NestedRequirement>(Req);
4645 if (NR->hasInvalidConstraint()) {
4648 return HandleSubstitutionFailure(RequiresExprLoc);
4652 mangleExpression(NR->getConstraintExpr());
4657void CXXNameMangler::mangleExpression(
const Expr *
E,
unsigned Arity,
4658 bool AsTemplateArg) {
4687 QualType ImplicitlyConvertedToType;
4691 bool IsPrimaryExpr =
true;
4692 auto NotPrimaryExpr = [&] {
4693 if (AsTemplateArg && IsPrimaryExpr)
4695 IsPrimaryExpr =
false;
4698 auto MangleDeclRefExpr = [&](
const NamedDecl *
D) {
4709 mangleFunctionParam(cast<ParmVarDecl>(
D));
4712 case Decl::EnumConstant: {
4719 case Decl::NonTypeTemplateParm:
4732 case Expr::NoStmtClass:
4733#define ABSTRACT_STMT(Type)
4734#define EXPR(Type, Base)
4735#define STMT(Type, Base) \
4736 case Expr::Type##Class:
4737#include "clang/AST/StmtNodes.inc"
4742 case Expr::AddrLabelExprClass:
4743 case Expr::DesignatedInitUpdateExprClass:
4744 case Expr::ImplicitValueInitExprClass:
4745 case Expr::ArrayInitLoopExprClass:
4746 case Expr::ArrayInitIndexExprClass:
4747 case Expr::NoInitExprClass:
4748 case Expr::ParenListExprClass:
4749 case Expr::MSPropertyRefExprClass:
4750 case Expr::MSPropertySubscriptExprClass:
4751 case Expr::TypoExprClass:
4752 case Expr::RecoveryExprClass:
4753 case Expr::ArraySectionExprClass:
4754 case Expr::OMPArrayShapingExprClass:
4755 case Expr::OMPIteratorExprClass:
4756 case Expr::CXXInheritedCtorInitExprClass:
4757 case Expr::CXXParenListInitExprClass:
4758 case Expr::PackIndexingExprClass:
4759 llvm_unreachable(
"unexpected statement kind");
4761 case Expr::ConstantExprClass:
4762 E = cast<ConstantExpr>(
E)->getSubExpr();
4766 case Expr::BlockExprClass:
4767 case Expr::ChooseExprClass:
4768 case Expr::CompoundLiteralExprClass:
4769 case Expr::ExtVectorElementExprClass:
4770 case Expr::GenericSelectionExprClass:
4771 case Expr::ObjCEncodeExprClass:
4772 case Expr::ObjCIsaExprClass:
4773 case Expr::ObjCIvarRefExprClass:
4774 case Expr::ObjCMessageExprClass:
4775 case Expr::ObjCPropertyRefExprClass:
4776 case Expr::ObjCProtocolExprClass:
4777 case Expr::ObjCSelectorExprClass:
4778 case Expr::ObjCStringLiteralClass:
4779 case Expr::ObjCBoxedExprClass:
4780 case Expr::ObjCArrayLiteralClass:
4781 case Expr::ObjCDictionaryLiteralClass:
4782 case Expr::ObjCSubscriptRefExprClass:
4783 case Expr::ObjCIndirectCopyRestoreExprClass:
4784 case Expr::ObjCAvailabilityCheckExprClass:
4785 case Expr::OffsetOfExprClass:
4786 case Expr::PredefinedExprClass:
4787 case Expr::ShuffleVectorExprClass:
4788 case Expr::ConvertVectorExprClass:
4789 case Expr::StmtExprClass:
4790 case Expr::ArrayTypeTraitExprClass:
4791 case Expr::ExpressionTraitExprClass:
4792 case Expr::VAArgExprClass:
4793 case Expr::CUDAKernelCallExprClass:
4794 case Expr::AsTypeExprClass:
4795 case Expr::PseudoObjectExprClass:
4796 case Expr::AtomicExprClass:
4797 case Expr::SourceLocExprClass:
4798 case Expr::EmbedExprClass:
4799 case Expr::BuiltinBitCastExprClass:
4806 "cannot yet mangle expression type %0");
4814 case Expr::CXXUuidofExprClass: {
4819 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
4820 Out <<
"u8__uuidof";
4829 Out <<
"u8__uuidoft";
4833 Out <<
"u8__uuidofz";
4834 mangleExpression(UuidExp);
4841 case Expr::BinaryConditionalOperatorClass: {
4846 "?: operator with omitted middle operand cannot be mangled");
4853 case Expr::OpaqueValueExprClass:
4854 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
4856 case Expr::InitListExprClass: {
4859 mangleInitListElements(cast<InitListExpr>(
E));
4864 case Expr::DesignatedInitExprClass: {
4866 auto *DIE = cast<DesignatedInitExpr>(
E);
4867 for (
const auto &
Designator : DIE->designators()) {
4873 mangleExpression(DIE->getArrayIndex(
Designator));
4876 "unknown designator kind");
4878 mangleExpression(DIE->getArrayRangeStart(
Designator));
4879 mangleExpression(DIE->getArrayRangeEnd(
Designator));
4882 mangleExpression(DIE->getInit());
4886 case Expr::CXXDefaultArgExprClass:
4887 E = cast<CXXDefaultArgExpr>(
E)->getExpr();
4890 case Expr::CXXDefaultInitExprClass:
4891 E = cast<CXXDefaultInitExpr>(
E)->getExpr();
4894 case Expr::CXXStdInitializerListExprClass:
4895 E = cast<CXXStdInitializerListExpr>(
E)->getSubExpr();
4898 case Expr::SubstNonTypeTemplateParmExprClass: {
4901 auto *SNTTPE = cast<SubstNonTypeTemplateParmExpr>(
E);
4902 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
4904 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
4905 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
4906 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
4912 E = cast<SubstNonTypeTemplateParmExpr>(
E)->getReplacement();
4916 case Expr::UserDefinedLiteralClass:
4919 case Expr::CXXMemberCallExprClass:
4920 case Expr::CallExprClass: {
4941 if (isa<PackExpansionExpr>(Arg))
4942 CallArity = UnknownArity;
4944 mangleExpression(CE->
getCallee(), CallArity);
4946 mangleExpression(Arg);
4951 case Expr::CXXNewExprClass: {
4955 Out << (New->
isArray() ?
"na" :
"nw");
4958 mangleExpression(*I);
4972 mangleExpression(*I);
4974 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
4975 mangleExpression(PLE->getExpr(i));
4977 CXXNewInitializationStyle::Braces &&
4978 isa<InitListExpr>(
Init)) {
4980 mangleInitListElements(cast<InitListExpr>(
Init));
4982 mangleExpression(
Init);
4988 case Expr::CXXPseudoDestructorExprClass: {
4990 const auto *PDE = cast<CXXPseudoDestructorExpr>(
E);
4991 if (
const Expr *
Base = PDE->getBase())
4992 mangleMemberExprBase(
Base, PDE->isArrow());
4996 mangleUnresolvedPrefix(Qualifier,
4998 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5002 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5005 }
else if (Qualifier) {
5006 mangleUnresolvedPrefix(Qualifier);
5010 QualType DestroyedType = PDE->getDestroyedType();
5011 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5015 case Expr::MemberExprClass: {
5026 case Expr::UnresolvedMemberExprClass: {
5037 case Expr::CXXDependentScopeMemberExprClass: {
5040 = cast<CXXDependentScopeMemberExpr>(
E);
5050 case Expr::UnresolvedLookupExprClass: {
5059 case Expr::CXXUnresolvedConstructExprClass: {
5065 assert(N == 1 &&
"unexpected form for list initialization");
5066 auto *IL = cast<InitListExpr>(CE->
getArg(0));
5069 mangleInitListElements(IL);
5076 if (N != 1) Out <<
'_';
5077 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5078 if (N != 1) Out <<
'E';
5082 case Expr::CXXConstructExprClass: {
5084 const auto *CE = cast<CXXConstructExpr>(
E);
5089 "implicit CXXConstructExpr must have one argument");
5090 E = cast<CXXConstructExpr>(
E)->getArg(0);
5096 mangleExpression(
E);
5101 case Expr::CXXTemporaryObjectExprClass: {
5103 const auto *CE = cast<CXXTemporaryObjectExpr>(
E);
5112 if (!List && N != 1)
5114 if (CE->isStdInitListInitialization()) {
5120 auto *ILE = cast<InitListExpr>(SILE->getSubExpr()->IgnoreImplicit());
5121 mangleInitListElements(ILE);
5124 mangleExpression(
E);
5131 case Expr::CXXScalarValueInitExprClass:
5138 case Expr::CXXNoexceptExprClass:
5141 mangleExpression(cast<CXXNoexceptExpr>(
E)->getOperand());
5144 case Expr::UnaryExprOrTypeTraitExprClass: {
5163 : ImplicitlyConvertedToType;
5165 mangleIntegerLiteral(
T,
V);
5171 auto MangleAlignofSizeofArg = [&] {
5184 MangleAlignofSizeofArg();
5186 case UETT_PreferredAlignOf:
5190 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5191 Out <<
"u11__alignof__";
5202 MangleAlignofSizeofArg();
5204 case UETT_DataSizeOf: {
5208 "cannot yet mangle __datasizeof expression");
5212 case UETT_PtrAuthTypeDiscriminator: {
5216 "cannot yet mangle __builtin_ptrauth_type_discriminator expression");
5220 case UETT_VecStep: {
5223 "cannot yet mangle vec_step expression");
5227 case UETT_OpenMPRequiredSimdAlign: {
5231 "cannot yet mangle __builtin_omp_required_simd_align expression");
5235 case UETT_VectorElements: {
5239 "cannot yet mangle __builtin_vectorelements expression");
5247 case Expr::TypeTraitExprClass: {
5253 Out << Spelling.size() << Spelling;
5255 mangleType(TSI->getType());
5261 case Expr::CXXThrowExprClass: {
5275 case Expr::CXXTypeidExprClass: {
5290 case Expr::CXXDeleteExprClass: {
5301 case Expr::UnaryOperatorClass: {
5310 case Expr::ArraySubscriptExprClass: {
5317 mangleExpression(AE->
getLHS());
5318 mangleExpression(AE->
getRHS());
5322 case Expr::MatrixSubscriptExprClass: {
5326 mangleExpression(ME->
getBase());
5332 case Expr::CompoundAssignOperatorClass:
5333 case Expr::BinaryOperatorClass: {
5341 mangleExpression(BO->
getLHS());
5342 mangleExpression(BO->
getRHS());
5346 case Expr::CXXRewrittenBinaryOperatorClass: {
5350 cast<CXXRewrittenBinaryOperator>(
E)->getDecomposedForm();
5353 mangleExpression(Decomposed.
LHS);
5354 mangleExpression(Decomposed.
RHS);
5358 case Expr::ConditionalOperatorClass: {
5361 mangleOperatorName(OO_Conditional, 3);
5362 mangleExpression(CO->
getCond());
5363 mangleExpression(CO->
getLHS(), Arity);
5364 mangleExpression(CO->
getRHS(), Arity);
5368 case Expr::ImplicitCastExprClass: {
5369 ImplicitlyConvertedToType =
E->
getType();
5370 E = cast<ImplicitCastExpr>(
E)->getSubExpr();
5374 case Expr::ObjCBridgedCastExprClass: {
5378 StringRef
Kind = cast<ObjCBridgedCastExpr>(
E)->getBridgeKindName();
5379 Out <<
"v1U" <<
Kind.size() <<
Kind;
5380 mangleCastExpression(
E,
"cv");
5384 case Expr::CStyleCastExprClass:
5386 mangleCastExpression(
E,
"cv");
5389 case Expr::CXXFunctionalCastExprClass: {
5391 auto *
Sub = cast<ExplicitCastExpr>(
E)->getSubExpr()->IgnoreImplicit();
5393 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5394 if (CCE->getParenOrBraceRange().isInvalid())
5395 Sub = CCE->getArg(0)->IgnoreImplicit();
5396 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5397 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5398 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5401 mangleInitListElements(IL);
5404 mangleCastExpression(
E,
"cv");
5409 case Expr::CXXStaticCastExprClass:
5411 mangleCastExpression(
E,
"sc");
5413 case Expr::CXXDynamicCastExprClass:
5415 mangleCastExpression(
E,
"dc");
5417 case Expr::CXXReinterpretCastExprClass:
5419 mangleCastExpression(
E,
"rc");
5421 case Expr::CXXConstCastExprClass:
5423 mangleCastExpression(
E,
"cc");
5425 case Expr::CXXAddrspaceCastExprClass:
5427 mangleCastExpression(
E,
"ac");
5430 case Expr::CXXOperatorCallExprClass: {
5439 for (
unsigned i = 0; i != NumArgs; ++i)
5440 mangleExpression(CE->
getArg(i));
5444 case Expr::ParenExprClass:
5445 E = cast<ParenExpr>(
E)->getSubExpr();
5448 case Expr::ConceptSpecializationExprClass: {
5449 auto *CSE = cast<ConceptSpecializationExpr>(
E);
5450 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5455 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5461 mangleUnresolvedName(
5462 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5463 CSE->getConceptNameInfo().getName(),
5464 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5465 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5469 case Expr::RequiresExprClass: {
5471 auto *RE = cast<RequiresExpr>(
E);
5475 if (RE->getLParenLoc().isValid()) {
5477 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5478 if (RE->getLocalParameters().empty()) {
5481 for (
ParmVarDecl *Param : RE->getLocalParameters()) {
5489 FunctionTypeDepth.enterResultType();
5491 mangleRequirement(RE->getExprLoc(), Req);
5492 FunctionTypeDepth.pop(saved);
5497 mangleRequirement(RE->getExprLoc(), Req);
5503 case Expr::DeclRefExprClass:
5505 MangleDeclRefExpr(cast<DeclRefExpr>(
E)->getDecl());
5508 case Expr::SubstNonTypeTemplateParmPackExprClass:
5514 Out <<
"_SUBSTPACK_";
5517 case Expr::FunctionParmPackExprClass: {
5521 Out <<
"v110_SUBSTPACK";
5526 case Expr::DependentScopeDeclRefExprClass: {
5535 case Expr::CXXBindTemporaryExprClass:
5536 E = cast<CXXBindTemporaryExpr>(
E)->getSubExpr();
5539 case Expr::ExprWithCleanupsClass:
5540 E = cast<ExprWithCleanups>(
E)->getSubExpr();
5543 case Expr::FloatingLiteralClass: {
5550 case Expr::FixedPointLiteralClass:
5552 mangleFixedPointLiteral();
5555 case Expr::CharacterLiteralClass:
5559 Out << cast<CharacterLiteral>(
E)->getValue();
5564 case Expr::ObjCBoolLiteralExprClass:
5567 Out << (cast<ObjCBoolLiteralExpr>(
E)->getValue() ?
'1' :
'0');
5571 case Expr::CXXBoolLiteralExprClass:
5574 Out << (cast<CXXBoolLiteralExpr>(
E)->getValue() ?
'1' :
'0');
5578 case Expr::IntegerLiteralClass: {
5580 llvm::APSInt
Value(cast<IntegerLiteral>(
E)->getValue());
5582 Value.setIsSigned(
true);
5587 case Expr::ImaginaryLiteralClass: {
5595 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5597 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5599 mangleFloat(Imag->getValue());
5602 llvm::APSInt
Value(cast<IntegerLiteral>(IE->
getSubExpr())->getValue());
5604 Value.setIsSigned(
true);
5605 mangleNumber(
Value);
5611 case Expr::StringLiteralClass: {
5615 assert(isa<ConstantArrayType>(
E->
getType()));
5621 case Expr::GNUNullExprClass:
5624 mangleIntegerLiteral(
E->
getType(), llvm::APSInt(32));
5627 case Expr::CXXNullPtrLiteralExprClass: {
5633 case Expr::LambdaExprClass: {
5638 mangleType(Context.getASTContext().
getRecordType(cast<LambdaExpr>(
E)->getLambdaClass()));
5643 case Expr::PackExpansionExprClass:
5646 mangleExpression(cast<PackExpansionExpr>(
E)->getPattern());
5649 case Expr::SizeOfPackExprClass: {
5651 auto *SPE = cast<SizeOfPackExpr>(
E);
5652 if (SPE->isPartiallySubstituted()) {
5654 for (
const auto &A : SPE->getPartialArguments())
5655 mangleTemplateArg(A,
false);
5663 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5665 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5666 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5668 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5669 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5671 mangleFunctionParam(cast<ParmVarDecl>(Pack));
5675 case Expr::MaterializeTemporaryExprClass:
5676 E = cast<MaterializeTemporaryExpr>(
E)->getSubExpr();
5679 case Expr::CXXFoldExprClass: {
5681 auto *FE = cast<CXXFoldExpr>(
E);
5682 if (FE->isLeftFold())
5683 Out << (FE->getInit() ?
"fL" :
"fl");
5685 Out << (FE->getInit() ?
"fR" :
"fr");
5687 if (FE->getOperator() == BO_PtrMemD)
5695 mangleExpression(FE->getLHS());
5697 mangleExpression(FE->getRHS());
5701 case Expr::CXXThisExprClass: