35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
41namespace UnsupportedItaniumManglingKind =
42 clang::diag::UnsupportedItaniumManglingKind;
46static bool isLocalContainerContext(
const DeclContext *DC) {
47 return isa<FunctionDecl, ObjCMethodDecl, BlockDecl, CXXExpansionStmtDecl,
48 TopLevelStmtDecl>(DC);
51static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
53 return ftd->getTemplatedDecl();
58static const NamedDecl *getStructor(
const NamedDecl *
decl) {
59 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
60 return (fn ? getStructor(fn) :
decl);
63static bool isLambda(
const NamedDecl *ND) {
64 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
71static const unsigned UnknownArity = ~0U;
73class ItaniumMangleContextImpl :
public ItaniumMangleContext {
74 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
75 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
76 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
77 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
78 NamespaceDecl *StdNamespace =
nullptr;
80 bool NeedsUniqueInternalLinkageNames =
false;
83 explicit ItaniumMangleContextImpl(
84 ASTContext &Context, DiagnosticsEngine &Diags,
85 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 : ItaniumMangleContext(Context, Diags, IsAux),
87 DiscriminatorOverride(DiscriminatorOverride) {}
92 bool shouldMangleCXXName(
const NamedDecl *D)
override;
93 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
98 void needsUniqueInternalLinkageNames()
override {
99 NeedsUniqueInternalLinkageNames =
true;
102 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
103 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
104 raw_ostream &)
override;
106 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
107 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
108 raw_ostream &)
override;
109 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
110 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXCtorVTable(
const CXXRecordDecl *RD,
int64_t Offset,
112 const CXXRecordDecl *
Type, raw_ostream &)
override;
113 void mangleCXXRTTI(QualType
T, raw_ostream &)
override;
114 void mangleCXXRTTIName(QualType
T, raw_ostream &,
115 bool NormalizeIntegers)
override;
116 void mangleCanonicalTypeName(QualType
T, raw_ostream &,
117 bool NormalizeIntegers)
override;
119 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
120 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
121 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
122 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
123 void mangleDynamicAtExitDestructor(
const VarDecl *D,
124 raw_ostream &Out)
override;
125 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
126 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
127 raw_ostream &Out)
override;
128 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
129 raw_ostream &Out)
override;
130 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
131 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
132 raw_ostream &)
override;
134 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
136 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
138 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
140 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
146 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
147 Tag &&
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
152 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
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;
171 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
174 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
175 std::string Name(
"<lambda");
179 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
180 const FunctionDecl *
Func =
184 unsigned DefaultArgNo =
186 Name += llvm::utostr(DefaultArgNo);
190 if (LambdaManglingNumber)
191 LambdaId = LambdaManglingNumber;
193 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
195 Name += llvm::utostr(LambdaId);
200 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
201 return DiscriminatorOverride;
204 NamespaceDecl *getStdNamespace();
206 const DeclContext *getEffectiveDeclContext(
const Decl *D);
207 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
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;
234 const NamedDecl *Structor;
235 unsigned StructorType = 0;
240 unsigned TemplateDepthOffset = 0;
245 class FunctionTypeDepthState {
247 unsigned InFunctionDeclSuffix : 1;
250 FunctionTypeDepthState() : Depth(0), InFunctionDeclSuffix(0) {}
252 unsigned getNestingDepth(
unsigned ParmDepth)
const {
255 assert(ParmDepth < Depth &&
256 "ParmVarDecl is not visible in current parameter environment");
257 return Depth - ParmDepth - InFunctionDeclSuffix;
260 FunctionTypeDepthState push() {
261 FunctionTypeDepthState Saved = *
this;
263 InFunctionDeclSuffix = 0;
267 void pop(FunctionTypeDepthState Saved) {
268 assert(Depth == Saved.Depth + 1 &&
"unbalanced function type depth pop");
272 void enterFunctionDeclSuffix() { InFunctionDeclSuffix = 1; }
273 void leaveFunctionDeclSuffix() { InFunctionDeclSuffix = 0; }
280 using AbiTagList = SmallVector<StringRef, 4>;
285 class AbiTagState final {
287 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
293 AbiTagState(
const AbiTagState &) =
delete;
294 AbiTagState &operator=(
const AbiTagState &) =
delete;
296 ~AbiTagState() { pop(); }
298 void write(raw_ostream &Out,
const NamedDecl *ND,
299 ArrayRef<StringRef> AdditionalAbiTags) {
303 AdditionalAbiTags.empty() &&
304 "only function and variables need a list of additional abi tags");
305 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
306 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
307 llvm::append_range(UsedAbiTags, AbiTag->tags());
314 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
315 llvm::append_range(UsedAbiTags, AbiTag->tags());
316 llvm::append_range(TagList, AbiTag->tags());
319 llvm::append_range(UsedAbiTags, AdditionalAbiTags);
320 llvm::append_range(TagList, AdditionalAbiTags);
323 TagList.erase(llvm::unique(TagList), TagList.end());
325 writeSortedUniqueAbiTags(Out, TagList);
328 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
329 void setUsedAbiTags(
const AbiTagList &AbiTags) {
330 UsedAbiTags = AbiTags;
333 const AbiTagList &getEmittedAbiTags()
const {
334 return EmittedAbiTags;
337 const AbiTagList &getSortedUniqueUsedAbiTags() {
338 llvm::sort(UsedAbiTags);
339 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
345 AbiTagList UsedAbiTags;
347 AbiTagList EmittedAbiTags;
349 AbiTagState *&LinkHead;
350 AbiTagState *Parent =
nullptr;
353 assert(LinkHead ==
this &&
354 "abi tag link head must point to us on destruction");
356 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
357 UsedAbiTags.begin(), UsedAbiTags.end());
358 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
359 EmittedAbiTags.begin(),
360 EmittedAbiTags.end());
365 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
366 for (
const auto &Tag : AbiTags) {
367 EmittedAbiTags.push_back(Tag);
375 AbiTagState *AbiTags =
nullptr;
376 AbiTagState AbiTagsRoot;
378 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
379 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
381 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
383 bool isCompatibleWith(LangOptions::ClangABI Ver) {
387 bool isStd(
const NamespaceDecl *NS);
388 bool isStdNamespace(
const DeclContext *DC);
390 const RecordDecl *GetLocalClassDecl(
const Decl *D);
391 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
392 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
393 llvm::StringRef Name,
bool HasAllocator);
396 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
397 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
398 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
399 AbiTagsRoot(AbiTags) {
404 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
406 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
407 AbiTagsRoot(AbiTags) {}
408 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
410 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
411 AbiTagsRoot(AbiTags) {}
413 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
414 bool NormalizeIntegers_)
415 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
416 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
417 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
418 : Context(Outer.Context),
Out(Out_),
419 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
420 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
421 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
422 Substitutions(Outer.Substitutions),
423 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
425 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
426 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
430 struct WithTemplateDepthOffset {
unsigned Offset; };
431 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
432 WithTemplateDepthOffset Offset)
433 : CXXNameMangler(
C,
Out) {
434 TemplateDepthOffset = Offset.Offset;
437 raw_ostream &getStream() {
return Out; }
439 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
440 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
442 void mangle(GlobalDecl GD);
444 void mangleNumber(
const llvm::APSInt &I);
445 void mangleNumber(
int64_t Number);
446 void mangleFloat(
const llvm::APFloat &F);
447 void mangleFunctionEncoding(GlobalDecl GD);
448 void mangleSeqID(
unsigned SeqID);
449 void mangleName(GlobalDecl GD);
450 void mangleType(QualType
T);
451 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
452 bool SuppressSubstitution =
false);
453 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
454 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
455 void mangleVendorQualifier(StringRef Name);
456 void mangleVendorType(StringRef Name);
459 bool mangleSubstitution(
const NamedDecl *ND);
460 bool mangleSubstitution(QualType
T);
466 bool mangleStandardSubstitution(
const NamedDecl *ND);
468 void addSubstitution(
const NamedDecl *ND) {
471 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
473 void addSubstitution(QualType
T);
477 void extendSubstitutions(CXXNameMangler*
Other);
479 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
480 bool recursive =
false);
481 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
482 const TemplateArgumentLoc *TemplateArgs,
483 unsigned NumTemplateArgs,
484 unsigned KnownArity = UnknownArity);
486 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
488 void mangleNameWithAbiTags(GlobalDecl GD,
489 ArrayRef<StringRef> AdditionalAbiTags = {});
490 void mangleModuleName(
const NamedDecl *ND);
491 void mangleTemplateName(
const TemplateDecl *TD,
492 ArrayRef<TemplateArgument> Args);
493 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
494 ArrayRef<StringRef> AdditionalAbiTags = {}) {
496 UnknownArity, AdditionalAbiTags);
498 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
499 const DeclContext *DC,
unsigned KnownArity,
500 ArrayRef<StringRef> AdditionalAbiTags);
501 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
502 ArrayRef<StringRef> AdditionalAbiTags = {});
503 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
504 ArrayRef<StringRef> AdditionalAbiTags = {});
505 void mangleSourceName(
const IdentifierInfo *II);
506 void mangleConstructorName(
const CXXConstructorDecl *CCD,
507 ArrayRef<StringRef> AdditionalAbiTags = {});
508 void mangleDestructorName(
const CXXDestructorDecl *CDD,
509 ArrayRef<StringRef> AdditionalAbiTags = {});
510 void mangleRegCallName(
const IdentifierInfo *II);
511 void mangleDeviceStubName(
const IdentifierInfo *II);
512 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
513 void mangleSourceNameWithAbiTags(
const NamedDecl *ND,
514 ArrayRef<StringRef> AdditionalAbiTags = {});
515 void mangleLocalName(GlobalDecl GD,
516 ArrayRef<StringRef> AdditionalAbiTags = {});
517 void mangleBlockForPrefix(
const BlockDecl *
Block);
518 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
519 void mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D);
520 void mangleTemplateParamDecl(
const NamedDecl *Decl);
521 void mangleTemplateParameterList(
const TemplateParameterList *Params);
523 ArrayRef<TemplateArgument> Arguments);
524 void mangleTypeConstraint(
const TypeConstraint *Constraint);
525 void mangleRequiresClause(
const Expr *RequiresClause);
526 void mangleLambda(
const CXXRecordDecl *Lambda);
527 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
528 ArrayRef<StringRef> AdditionalAbiTags = {},
529 bool NoFunction =
false);
530 void mangleNestedName(
const TemplateDecl *TD,
531 ArrayRef<TemplateArgument> Args);
532 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
533 const NamedDecl *PrefixND,
534 ArrayRef<StringRef> AdditionalAbiTags,
535 bool NoFunction =
false);
536 void manglePrefix(NestedNameSpecifier Qualifier);
537 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
538 void manglePrefix(QualType
type);
539 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
541 void DiagnoseUnsupportedPackIndexTemplateName();
542 const NamedDecl *getClosurePrefix(
const Decl *ND);
543 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
544 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
545 StringRef Prefix =
"");
546 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
548 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
554#define ABSTRACT_TYPE(CLASS, PARENT)
555#define NON_CANONICAL_TYPE(CLASS, PARENT)
556#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
557#include "clang/AST/TypeNodes.inc"
559 void mangleType(
const TagType*);
561 static StringRef getCallingConvQualifierName(
CallingConv CC);
564 void mangleSMEAttrs(
unsigned SMEAttrs);
569 void mangleAArch64NeonVectorType(
const VectorType *
T);
571 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
573 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
577 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
578 void mangleFixedPointLiteral();
580 void mangleReflection(
ReflectionKind Kind,
const void *OpaqueOperand);
582 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
583 void mangleMemberExpr(
const Expr *base,
bool isArrow,
587 unsigned NumTemplateArgs,
unsigned knownArity);
588 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
589 void mangleInitListElements(
const InitListExpr *InitList);
592 void mangleReferenceToPack(
const NamedDecl *ND);
593 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
594 bool AsTemplateArg =
false);
598 struct TemplateArgManglingInfo;
601 unsigned NumTemplateArgs);
604 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
607 void mangleTemplateArgExpr(
const Expr *E);
609 bool NeedExactType =
false);
611 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
619 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
621 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
629 getASTContext(), getASTContext().getTranslationUnitDecl(),
630 false, SourceLocation(), SourceLocation(),
631 &getASTContext().Idents.get(
"std"),
654ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
661 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
663 if (ParmVarDecl *ContextParam =
664 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
665 return ContextParam->getDeclContext();
669 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
670 if (ParmVarDecl *ContextParam =
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();
689 return getEffectiveDeclContext(
cast<Decl>(DC));
692 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
694 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
698 if (isLocalContainerContext(ParentDC))
702 return getASTContext().getTranslationUnitDecl();
705 if (
const auto *FD = !getASTContext().getLangOpts().isCompatibleWith(
706 LangOptions::ClangABI::Ver19)
708 : dyn_cast<FunctionDecl>(D)) {
710 return getASTContext().getTranslationUnitDecl();
713 if (FD->isMemberLikeConstrainedFriend() &&
714 !getASTContext().getLangOpts().isCompatibleWith(
715 LangOptions::ClangABI::Ver17))
722bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
725 getEffectiveDeclContext(ND)->isFileContext() &&
732bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
733 const NamedDecl *ND) {
734 if (!NeedsUniqueInternalLinkageNames || !ND)
737 const auto *FD = dyn_cast<FunctionDecl>(ND);
743 if (!FD->getType()->getAs<FunctionProtoType>())
746 if (isInternalLinkageDecl(ND))
752bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
753 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
756 if (FD->hasAttr<OverloadableAttr>())
772 if (FD->isMSVCRTEntryPoint())
786 if (!getASTContext().getLangOpts().
CPlusPlus)
789 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
800 const DeclContext *DC = getEffectiveDeclContext(D);
802 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
804 !VD->getOwningModuleForLinkage())
811void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
812 ArrayRef<StringRef> AdditionalAbiTags) {
813 assert(AbiTags &&
"require AbiTagState");
814 AbiTags->write(Out, ND,
815 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
816 : AdditionalAbiTags);
819void CXXNameMangler::mangleSourceNameWithAbiTags(
820 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
822 writeAbiTags(ND, AdditionalAbiTags);
825void CXXNameMangler::mangle(GlobalDecl GD) {
831 mangleFunctionEncoding(GD);
832 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
835 else if (
const IndirectFieldDecl *IFD =
836 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
837 mangleName(IFD->getAnonField());
839 llvm_unreachable(
"unexpected kind of global decl");
842void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
847 if (!Context.shouldMangleDeclName(FD)) {
852 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
853 if (ReturnTypeAbiTags.empty()) {
862 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
864 FunctionTypeDepth.pop(Saved);
865 mangleFunctionEncodingBareType(FD);
872 SmallString<256> FunctionEncodingBuf;
873 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
874 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
876 FunctionEncodingMangler.disableDerivedAbiTags();
878 FunctionTypeDepthState EncodingSaved =
879 FunctionEncodingMangler.FunctionTypeDepth.push();
880 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
881 FunctionEncodingMangler.FunctionTypeDepth.pop(EncodingSaved);
884 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
885 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
889 const AbiTagList &UsedAbiTags =
890 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
891 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
892 AdditionalAbiTags.erase(
893 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
894 UsedAbiTags.begin(), UsedAbiTags.end(),
895 AdditionalAbiTags.begin()),
896 AdditionalAbiTags.end());
899 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
900 mangleNameWithAbiTags(FD, AdditionalAbiTags);
901 FunctionTypeDepth.pop(Saved);
902 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
906 extendSubstitutions(&FunctionEncodingMangler);
909void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
910 if (FD->
hasAttr<EnableIfAttr>()) {
911 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
912 Out <<
"Ua9enable_ifI";
913 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
916 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
919 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
924 mangleExpression(EIA->getCond());
927 mangleTemplateArgExpr(EIA->getCond());
931 FunctionTypeDepth.pop(Saved);
936 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
937 if (
auto Inherited = CD->getInheritedConstructor())
938 FD = Inherited.getConstructor();
956 bool MangleReturnType =
false;
960 MangleReturnType =
true;
963 FD = PrimaryTemplate->getTemplatedDecl();
966 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
967 MangleReturnType, FD);
971bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
972 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
976 return II && II->
isStr(
"std");
981bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
988static const GlobalDecl
992 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1001 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1002 TemplateArgs = &Spec->getTemplateArgs();
1003 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1008 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1009 TemplateArgs = &Spec->getTemplateArgs();
1010 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1021void CXXNameMangler::mangleName(GlobalDecl GD) {
1023 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1025 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1026 if (VariableTypeAbiTags.empty()) {
1028 mangleNameWithAbiTags(VD);
1033 llvm::raw_null_ostream NullOutStream;
1034 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1035 VariableNameMangler.disableDerivedAbiTags();
1036 VariableNameMangler.mangleNameWithAbiTags(VD);
1039 const AbiTagList &UsedAbiTags =
1040 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1041 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1042 AdditionalAbiTags.erase(
1043 std::set_difference(VariableTypeAbiTags.begin(),
1044 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1045 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1046 AdditionalAbiTags.end());
1049 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1051 mangleNameWithAbiTags(GD);
1055const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1056 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1058 if (isLocalContainerContext(DC))
1059 return dyn_cast<RecordDecl>(D);
1061 DC = Context.getEffectiveDeclContext(D);
1066void CXXNameMangler::mangleNameWithAbiTags(
1067 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1074 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1076 if (GetLocalClassDecl(ND) &&
1077 (!isLambda(ND) || isCompatibleWith(LangOptions::ClangABI::Ver18) ||
1078 !isCompatibleWith(LangOptions::ClangABI::Ver22))) {
1079 mangleLocalName(GD, AdditionalAbiTags);
1087 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1088 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1092 if (isLocalContainerContext(DC)) {
1093 mangleLocalName(GD, AdditionalAbiTags);
1102 const TemplateArgumentList *TemplateArgs =
nullptr;
1103 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1104 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1109 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1113 mangleNestedName(GD, DC, AdditionalAbiTags);
1116void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1119 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1127void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1129 if (
auto It = ModuleSubstitutions.find(Name);
1130 It != ModuleSubstitutions.end()) {
1132 mangleSeqID(It->second);
1138 auto [Prefix, SubName] = Name.rsplit(
'.');
1139 if (SubName.empty())
1142 mangleModuleNamePrefix(Prefix, IsPartition);
1143 IsPartition =
false;
1149 Out << SubName.size() << SubName;
1150 ModuleSubstitutions.insert({Name, SeqID++});
1153void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1154 ArrayRef<TemplateArgument> Args) {
1155 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1158 mangleUnscopedTemplateName(TD, DC);
1161 mangleNestedName(TD, Args);
1165void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1166 ArrayRef<StringRef> AdditionalAbiTags) {
1171 if (isStdNamespace(DC)) {
1172 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1174 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1179 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1181 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1191 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1194void CXXNameMangler::mangleUnscopedTemplateName(
1195 GlobalDecl GD,
const DeclContext *DC,
1196 ArrayRef<StringRef> AdditionalAbiTags) {
1200 if (mangleSubstitution(ND))
1204 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1205 assert(AdditionalAbiTags.empty() &&
1206 "template template param cannot have abi tags");
1207 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1209 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1215 addSubstitution(ND);
1218void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1232 llvm::APInt valueBits = f.bitcastToAPInt();
1233 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1234 assert(numCharacters != 0);
1237 SmallVector<char, 20> buffer(numCharacters);
1240 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1242 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1245 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1246 hexDigit >>= (digitBitIndex % 64);
1250 static const char charForHex[16] = {
1251 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1252 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1254 buffer[stringIndex] = charForHex[hexDigit];
1257 Out.write(buffer.data(), numCharacters);
1260void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1267void CXXNameMangler::mangleFixedPointLiteral() {
1268 DiagnosticsEngine &Diags = Context.getDiags();
1269 Diags.
Report(diag::err_unsupported_itanium_mangling)
1270 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1273void CXXNameMangler::DiagnoseUnsupportedPackIndexTemplateName() {
1274 DiagnosticsEngine &Diags = Context.getDiags();
1275 Diags.
Report(diag::err_unsupported_itanium_mangling)
1276 << UnsupportedItaniumManglingKind::PackIndexTemplateName;
1279void CXXNameMangler::mangleNullPointer(QualType
T) {
1287 const void *OpaqueOperand) {
1323 case ReflectionKind::Null:
1326 case ReflectionKind::Type: {
1327 const auto *TSI =
static_cast<const TypeSourceInfo *
>(OpaqueOperand);
1328 QualType QT = TSI->getType();
1331 if (
const auto *TDT = QT->
getAs<TypedefType>()) {
1333 mangleName(TDT->getDecl()->getCanonicalDecl());
1346void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1347 if (
Value.isSigned() &&
Value.isNegative()) {
1349 Value.abs().print(Out,
false);
1351 Value.print(Out,
false);
1355void CXXNameMangler::mangleNumber(
int64_t Number) {
1373 mangleNumber(NonVirtual);
1379 mangleNumber(NonVirtual);
1385void CXXNameMangler::manglePrefix(QualType
type) {
1386 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1387 if (!mangleSubstitution(QualType(TST, 0))) {
1388 mangleTemplatePrefix(TST->getTemplateName());
1393 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1394 addSubstitution(QualType(TST, 0));
1396 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1398 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1399 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1404 assert(DNT->getQualifier());
1405 manglePrefix(DNT->getQualifier());
1407 mangleSourceName(DNT->getIdentifier());
1410 addSubstitution(QualType(DNT, 0));
1422void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1440 case NestedNameSpecifier::Kind::Null:
1441 llvm_unreachable(
"unexpected null nested name specifier");
1443 case NestedNameSpecifier::Kind::Global:
1453 case NestedNameSpecifier::Kind::MicrosoftSuper:
1454 llvm_unreachable(
"Can't mangle __super specifier");
1456 case NestedNameSpecifier::Kind::Namespace: {
1459 mangleUnresolvedPrefix(Prefix,
1463 mangleSourceNameWithAbiTags(Namespace);
1467 case NestedNameSpecifier::Kind::Type: {
1475 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1476 mangleUnresolvedPrefix(Prefix,
1483 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1498void CXXNameMangler::mangleUnresolvedName(
1499 NestedNameSpecifier Qualifier, DeclarationName name,
1500 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1501 unsigned knownArity) {
1503 mangleUnresolvedPrefix(Qualifier);
1504 switch (
name.getNameKind()) {
1507 mangleSourceName(
name.getAsIdentifierInfo());
1512 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1519 mangleOperatorName(name, knownArity);
1522 llvm_unreachable(
"Can't mangle a constructor name!");
1524 llvm_unreachable(
"Can't mangle a using directive name!");
1526 llvm_unreachable(
"Can't mangle a deduction guide name!");
1530 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1536 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1539void CXXNameMangler::mangleUnqualifiedName(
1540 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1541 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1542 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1549 mangleModuleName(ND);
1553 auto *FD = dyn_cast<FunctionDecl>(ND);
1554 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1556 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1557 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1561 unsigned Arity = KnownArity;
1567 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1574 for (
auto *BD : DD->bindings())
1575 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1577 writeAbiTags(ND, AdditionalAbiTags);
1581 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1584 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1585 llvm::raw_svector_ostream GUIDOS(GUID);
1586 Context.mangleMSGuidDecl(GD, GUIDOS);
1587 Out << GUID.size() << GUID;
1591 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1594 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1595 TPO->getValue(),
true);
1613 if (Context.isInternalLinkageDecl(ND))
1616 bool IsRegCall = FD &&
1620 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1622 bool IsOCLDeviceStub =
1624 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1627 mangleDeviceStubName(II);
1628 else if (IsOCLDeviceStub)
1629 mangleOCLDeviceStubName(II);
1631 mangleRegCallName(II);
1633 mangleSourceName(II);
1635 writeAbiTags(ND, AdditionalAbiTags);
1640 assert(ND &&
"mangling empty name without declaration");
1642 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1645 Out <<
"12_GLOBAL__N_1";
1650 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1652 const auto *RD = VD->getType()->castAsRecordDecl();
1663 assert(RD->isAnonymousStructOrUnion()
1664 &&
"Expected anonymous struct or union!");
1665 const FieldDecl *FD = RD->findFirstNamedDataMember();
1671 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1691 "Typedef should not be in another decl context!");
1692 assert(D->getDeclName().getAsIdentifierInfo() &&
1693 "Typedef was not named!");
1694 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1695 assert(AdditionalAbiTags.empty() &&
1696 "Type cannot have additional abi tags");
1708 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1710 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1716 if (
Record->isLambda() &&
1717 ((DeviceNumber && *DeviceNumber > 0) ||
1718 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1719 assert(AdditionalAbiTags.empty() &&
1720 "Lambda type cannot have additional abi tags");
1727 unsigned UnnamedMangle =
1728 getASTContext().getManglingNumber(TD, Context.isAux());
1730 if (UnnamedMangle > 1)
1731 Out << UnnamedMangle - 2;
1733 writeAbiTags(TD, AdditionalAbiTags);
1739 unsigned AnonStructId =
1741 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1748 Str += llvm::utostr(AnonStructId);
1758 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1769 if (ND && Arity == UnknownArity)
1774 mangleOperatorName(Name, Arity);
1775 writeAbiTags(ND, AdditionalAbiTags);
1779 llvm_unreachable(
"Can't mangle a deduction guide name!");
1782 llvm_unreachable(
"Can't mangle a using directive name!");
1786void CXXNameMangler::mangleConstructorName(
1787 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1788 const CXXRecordDecl *InheritedFrom =
nullptr;
1790 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1792 InheritedFrom = Inherited.getConstructor()->
getParent();
1793 InheritedTemplateName =
1794 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1795 InheritedTemplateArgs =
1796 Inherited.getConstructor()->getTemplateSpecializationArgs();
1799 if (CCD == Structor)
1802 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1810 if (InheritedTemplateArgs)
1811 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1813 writeAbiTags(CCD, AdditionalAbiTags);
1816void CXXNameMangler::mangleDestructorName(
1817 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1818 if (CDD == Structor)
1821 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1827 writeAbiTags(CDD, AdditionalAbiTags);
1830void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1834 if (getASTContext().getLangOpts().RegCall4)
1835 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1838 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1842void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1846 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1850void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1854 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1855 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1856 << OCLDeviceStubNamePrefix << II->
getName();
1859void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1866void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1867 ArrayRef<StringRef> AdditionalAbiTags,
1876 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1877 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1880 if (
Method->isExplicitObjectMemberFunction())
1883 mangleQualifiers(MethodQuals);
1884 mangleRefQualifier(
Method->getRefQualifier());
1888 const TemplateArgumentList *TemplateArgs =
nullptr;
1889 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1890 mangleTemplatePrefix(TD, NoFunction);
1893 manglePrefix(DC, NoFunction);
1894 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1899void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1900 ArrayRef<TemplateArgument> Args) {
1905 mangleTemplatePrefix(TD);
1911void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1912 GlobalDecl GD,
const NamedDecl *PrefixND,
1913 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1922 mangleClosurePrefix(PrefixND, NoFunction);
1923 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1934 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1936 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1945void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1946 ArrayRef<StringRef> AdditionalAbiTags) {
1954 const RecordDecl *RD = GetLocalClassDecl(D);
1955 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1960 AbiTagState LocalAbiTags(AbiTags);
1962 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1964 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1965 mangleBlockForPrefix(BD);
1966 }
else if (
const auto *TLSD = dyn_cast<TopLevelStmtDecl>(DC)) {
1967 mangleTopLevelStmtEncoding(TLSD);
1974 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1988 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1990 if (
const ParmVarDecl *Parm
1992 if (
const FunctionDecl *
Func
1997 mangleNumber(
Num - 2);
2006 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
2007 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2008 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
2009 mangleClosurePrefix(PrefixND,
true );
2011 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
2012 assert(AdditionalAbiTags.empty() &&
2013 "Block cannot have additional abi tags");
2014 mangleUnqualifiedBlock(BD);
2017 const NamedDecl *PrefixND = getClosurePrefix(ND);
2018 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
2019 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
2022 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
2023 AdditionalAbiTags,
true);
2025 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2028 if (
const ParmVarDecl *Parm
2029 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
2030 if (
const FunctionDecl *
Func
2035 mangleNumber(
Num - 2);
2040 assert(AdditionalAbiTags.empty() &&
2041 "Block cannot have additional abi tags");
2042 mangleUnqualifiedBlock(BD);
2044 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
2047 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
2049 if (Context.getNextDiscriminator(ND, disc)) {
2053 Out <<
"__" << disc <<
'_';
2058void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
2059 if (GetLocalClassDecl(
Block)) {
2060 mangleLocalName(
Block);
2063 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
2064 if (isLocalContainerContext(DC)) {
2065 mangleLocalName(
Block);
2068 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2069 mangleClosurePrefix(PrefixND);
2072 mangleUnqualifiedBlock(
Block);
2075void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2078 if (Decl *Context =
Block->getBlockManglingContextDecl();
2079 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2081 Context->getDeclContext()->isRecord()) {
2084 mangleSourceNameWithAbiTags(ND);
2090 unsigned Number =
Block->getBlockManglingNumber();
2105void CXXNameMangler::mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D) {
2107 SmallString<16> Name(
"__stmt__");
2109 Out <<
'L' << Name.size() << Name <<
'v';
2119void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2121 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2122 if (Ty->isParameterPack())
2124 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2125 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2128 mangleTypeConstraint(Constraint);
2132 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2133 if (Tn->isExpandedParameterPack()) {
2134 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2136 mangleType(Tn->getExpansionType(I));
2139 QualType
T = Tn->getType();
2140 if (Tn->isParameterPack()) {
2142 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2143 T = PackExpansion->getPattern();
2148 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2149 if (Tt->isExpandedParameterPack()) {
2150 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2152 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2154 if (Tt->isParameterPack())
2156 mangleTemplateParameterList(Tt->getTemplateParameters());
2161void CXXNameMangler::mangleTemplateParameterList(
2162 const TemplateParameterList *Params) {
2164 for (
auto *Param : *Params)
2165 mangleTemplateParamDecl(Param);
2166 mangleRequiresClause(Params->getRequiresClause());
2170void CXXNameMangler::mangleTypeConstraint(
2172 const TemplateDecl *TD =
Concept.getAsTemplateDecl();
2174 DiagnoseUnsupportedPackIndexTemplateName();
2177 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
2179 mangleTemplateName(TD, Arguments);
2181 mangleUnscopedName(TD, DC);
2183 mangleNestedName(TD, DC);
2186void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2187 llvm::SmallVector<TemplateArgument, 8> Args;
2189 for (
const TemplateArgumentLoc &ArgLoc :
2191 Args.push_back(ArgLoc.getArgument());
2196void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2198 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2200 mangleExpression(RequiresClause);
2204void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2208 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2211 if (
const IdentifierInfo *Name =
2213 mangleSourceName(Name);
2214 const TemplateArgumentList *TemplateArgs =
nullptr;
2222 mangleLambdaSig(Lambda);
2237 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2241 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2243 mangleNumber(Number - 2);
2247void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2250 mangleTemplateParamDecl(D);
2254 mangleRequiresClause(TPL->getRequiresClause());
2258 mangleBareFunctionType(Proto,
false,
2262void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2264 case NestedNameSpecifier::Kind::Null:
2265 case NestedNameSpecifier::Kind::Global:
2269 case NestedNameSpecifier::Kind::MicrosoftSuper:
2270 llvm_unreachable(
"Can't mangle __super specifier");
2272 case NestedNameSpecifier::Kind::Namespace:
2273 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2276 case NestedNameSpecifier::Kind::Type:
2277 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2281 llvm_unreachable(
"unexpected nested name specifier");
2284void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2297 if (NoFunction && isLocalContainerContext(DC))
2304 if (mangleSubstitution(ND))
2310 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2311 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2312 mangleTemplatePrefix(TD);
2314 *FD->getTemplateSpecializationArgs());
2316 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2319 addSubstitution(ND);
2324 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2326 addSubstitution(ND);
2331 const TemplateArgumentList *TemplateArgs =
nullptr;
2332 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2333 mangleTemplatePrefix(TD);
2335 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2336 mangleClosurePrefix(PrefixND, NoFunction);
2337 mangleUnqualifiedName(ND,
nullptr);
2339 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2340 manglePrefix(DC, NoFunction);
2341 mangleUnqualifiedName(ND, DC);
2344 addSubstitution(ND);
2351 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2352 return mangleTemplatePrefix(TD);
2354 if (
Template.getAsPackIndexingTemplate()) {
2355 DiagnoseUnsupportedPackIndexTemplateName();
2360 assert(
Dependent &&
"unexpected template name kind");
2364 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2365 if (!Clang11Compat && mangleSubstitution(
Template))
2368 manglePrefix(
Dependent->getQualifier());
2370 if (Clang11Compat && mangleSubstitution(
Template))
2373 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2374 const IdentifierInfo *Id = Name.getIdentifier())
2375 mangleSourceName(Id);
2377 mangleOperatorName(Name.getOperator(), UnknownArity);
2382void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2391 if (mangleSubstitution(ND))
2395 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2396 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2398 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2399 manglePrefix(DC, NoFunction);
2401 mangleUnqualifiedName(GD, DC);
2406 addSubstitution(ND);
2409const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2410 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2413 const NamedDecl *Context =
nullptr;
2414 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2415 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2416 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2419 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2421 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2435void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2438 if (mangleSubstitution(ND))
2441 const TemplateArgumentList *TemplateArgs =
nullptr;
2442 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2443 mangleTemplatePrefix(TD, NoFunction);
2446 const auto *DC = Context.getEffectiveDeclContext(ND);
2447 manglePrefix(DC, NoFunction);
2448 mangleUnqualifiedName(ND, DC);
2453 addSubstitution(ND);
2462 if (mangleSubstitution(TN))
2465 TemplateDecl *TD =
nullptr;
2475 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2476 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2483 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2492 mangleUnresolvedPrefix(
Dependent->getQualifier());
2493 mangleSourceName(II);
2502 SubstTemplateTemplateParmStorage *subst
2513 Out <<
"_SUBSTPACK_";
2518 DiagnoseUnsupportedPackIndexTemplateName();
2522 llvm_unreachable(
"Unexpected DeducedTemplate");
2525 addSubstitution(TN);
2528bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2534 case Type::Adjusted:
2536 case Type::ArrayParameter:
2538 case Type::BlockPointer:
2539 case Type::LValueReference:
2540 case Type::RValueReference:
2541 case Type::MemberPointer:
2542 case Type::ConstantArray:
2543 case Type::IncompleteArray:
2544 case Type::VariableArray:
2545 case Type::DependentSizedArray:
2546 case Type::DependentAddressSpace:
2547 case Type::DependentVector:
2548 case Type::DependentSizedExtVector:
2550 case Type::ExtVector:
2551 case Type::ConstantMatrix:
2552 case Type::DependentSizedMatrix:
2553 case Type::FunctionProto:
2554 case Type::FunctionNoProto:
2556 case Type::Attributed:
2557 case Type::BTFTagAttributed:
2558 case Type::OverflowBehavior:
2559 case Type::HLSLAttributedResource:
2560 case Type::HLSLInlineSpirv:
2562 case Type::DeducedTemplateSpecialization:
2563 case Type::PackExpansion:
2564 case Type::ObjCObject:
2565 case Type::ObjCInterface:
2566 case Type::ObjCObjectPointer:
2567 case Type::ObjCTypeParam:
2570 case Type::MacroQualified:
2572 case Type::DependentBitInt:
2573 case Type::CountAttributed:
2574 case Type::LateParsedAttr:
2575 llvm_unreachable(
"type is illegal as a nested name specifier");
2577 case Type::SubstBuiltinTemplatePack:
2582 Out <<
"_SUBSTBUILTINPACK_";
2584 case Type::SubstTemplateTypeParmPack:
2589 Out <<
"_SUBSTPACK_";
2596 case Type::TypeOfExpr:
2598 case Type::Decltype:
2599 case Type::PackIndexing:
2600 case Type::TemplateTypeParm:
2601 case Type::UnaryTransform:
2614 case Type::SubstTemplateTypeParm: {
2618 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2620 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2621 goto unresolvedType;
2628 case Type::PredefinedSugar:
2632 case Type::UnresolvedUsing:
2633 mangleSourceNameWithAbiTags(
2639 mangleSourceNameWithAbiTags(
2643 case Type::TemplateSpecialization: {
2644 const TemplateSpecializationType *TST =
2646 TemplateName TN = mangleExistingSubstitution(TST->getTemplateName());
2654 assert(TD &&
"no template for template specialization type");
2656 goto unresolvedType;
2658 mangleSourceNameWithAbiTags(TD);
2670 llvm_unreachable(
"invalid base for a template specialization type");
2681 Out <<
"_SUBSTPACK_";
2686 DiagnoseUnsupportedPackIndexTemplateName();
2692 mangleSourceNameWithAbiTags(TD);
2702 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2706 case Type::InjectedClassName:
2707 mangleSourceNameWithAbiTags(
2711 case Type::DependentName:
2723void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2733 llvm_unreachable(
"Not an operator name");
2756 case OO_New:
Out <<
"nw";
break;
2758 case OO_Array_New:
Out <<
"na";
break;
2760 case OO_Delete:
Out <<
"dl";
break;
2762 case OO_Array_Delete:
Out <<
"da";
break;
2766 Out << (Arity == 1?
"ps" :
"pl");
break;
2770 Out << (Arity == 1?
"ng" :
"mi");
break;
2774 Out << (Arity == 1?
"ad" :
"an");
break;
2779 Out << (Arity == 1?
"de" :
"ml");
break;
2781 case OO_Tilde:
Out <<
"co";
break;
2783 case OO_Slash:
Out <<
"dv";
break;
2785 case OO_Percent:
Out <<
"rm";
break;
2787 case OO_Pipe:
Out <<
"or";
break;
2789 case OO_Caret:
Out <<
"eo";
break;
2791 case OO_Equal:
Out <<
"aS";
break;
2793 case OO_PlusEqual:
Out <<
"pL";
break;
2795 case OO_MinusEqual:
Out <<
"mI";
break;
2797 case OO_StarEqual:
Out <<
"mL";
break;
2799 case OO_SlashEqual:
Out <<
"dV";
break;
2801 case OO_PercentEqual:
Out <<
"rM";
break;
2803 case OO_AmpEqual:
Out <<
"aN";
break;
2805 case OO_PipeEqual:
Out <<
"oR";
break;
2807 case OO_CaretEqual:
Out <<
"eO";
break;
2809 case OO_LessLess:
Out <<
"ls";
break;
2811 case OO_GreaterGreater:
Out <<
"rs";
break;
2813 case OO_LessLessEqual:
Out <<
"lS";
break;
2815 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2817 case OO_EqualEqual:
Out <<
"eq";
break;
2819 case OO_ExclaimEqual:
Out <<
"ne";
break;
2821 case OO_Less:
Out <<
"lt";
break;
2823 case OO_Greater:
Out <<
"gt";
break;
2825 case OO_LessEqual:
Out <<
"le";
break;
2827 case OO_GreaterEqual:
Out <<
"ge";
break;
2829 case OO_Exclaim:
Out <<
"nt";
break;
2831 case OO_AmpAmp:
Out <<
"aa";
break;
2833 case OO_PipePipe:
Out <<
"oo";
break;
2835 case OO_PlusPlus:
Out <<
"pp";
break;
2837 case OO_MinusMinus:
Out <<
"mm";
break;
2839 case OO_Comma:
Out <<
"cm";
break;
2841 case OO_ArrowStar:
Out <<
"pm";
break;
2843 case OO_Arrow:
Out <<
"pt";
break;
2845 case OO_Call:
Out <<
"cl";
break;
2847 case OO_Subscript:
Out <<
"ix";
break;
2852 case OO_Conditional:
Out <<
"qu";
break;
2855 case OO_Coawait:
Out <<
"aw";
break;
2858 case OO_Spaceship:
Out <<
"ss";
break;
2862 llvm_unreachable(
"Not an overloaded operator");
2866void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2885 SmallString<64> ASString;
2891 if (TargetAS != 0 ||
2893 ASString =
"AS" + llvm::utostr(TargetAS);
2896 default: llvm_unreachable(
"Not a language specific address space");
2900 case LangAS::opencl_global:
2901 ASString =
"CLglobal";
2903 case LangAS::opencl_global_device:
2904 ASString =
"CLdevice";
2906 case LangAS::opencl_global_host:
2907 ASString =
"CLhost";
2909 case LangAS::opencl_local:
2910 ASString =
"CLlocal";
2912 case LangAS::opencl_constant:
2913 ASString =
"CLconstant";
2915 case LangAS::opencl_private:
2916 ASString =
"CLprivate";
2918 case LangAS::opencl_generic:
2919 ASString =
"CLgeneric";
2924 case LangAS::sycl_global:
2925 ASString =
"SYglobal";
2927 case LangAS::sycl_global_device:
2928 ASString =
"SYdevice";
2930 case LangAS::sycl_global_host:
2931 ASString =
"SYhost";
2933 case LangAS::sycl_local:
2934 ASString =
"SYlocal";
2936 case LangAS::sycl_private:
2937 ASString =
"SYprivate";
2939 case LangAS::sycl_generic:
2940 ASString =
"SYgeneric";
2942 case LangAS::sycl_constant:
2943 ASString =
"SYconstant";
2946 case LangAS::cuda_device:
2947 ASString =
"CUdevice";
2949 case LangAS::cuda_constant:
2950 ASString =
"CUconstant";
2952 case LangAS::cuda_shared:
2953 ASString =
"CUshared";
2956 case LangAS::ptr32_sptr:
2957 ASString =
"ptr32_sptr";
2959 case LangAS::ptr32_uptr:
2963 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2964 ASString =
"ptr32_uptr";
2971 if (!ASString.empty())
2972 mangleVendorQualifier(ASString);
2985 mangleVendorQualifier(
"__weak");
2989 mangleVendorQualifier(
"__unaligned");
2993 mangleVendorQualifier(
"__ptrauth");
3003 << unsigned(PtrAuth.isAddressDiscriminated())
3006 << PtrAuth.getExtraDiscriminator()
3021 mangleVendorQualifier(
"__strong");
3025 mangleVendorQualifier(
"__autoreleasing");
3048void CXXNameMangler::mangleVendorQualifier(StringRef name) {
3052void CXXNameMangler::mangleVendorType(StringRef name) {
3059 switch (RefQualifier) {
3073void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
3074 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3099 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3100 if (DeducedTST->getDeducedType().isNull())
3105void CXXNameMangler::mangleType(QualType
T) {
3139 T =
T.getCanonicalType();
3145 if (
const TemplateSpecializationType *TST
3146 = dyn_cast<TemplateSpecializationType>(
T))
3147 if (!TST->isTypeAlias())
3155 =
T.getSingleStepDesugaredType(Context.getASTContext());
3162 auto [ty, quals] =
T.split();
3164 bool isSubstitutable =
3166 if (isSubstitutable && mangleSubstitution(
T))
3173 quals = Qualifiers();
3179 if (quals || ty->isDependentAddressSpaceType()) {
3180 if (
const DependentAddressSpaceType *DAST =
3181 dyn_cast<DependentAddressSpaceType>(ty)) {
3183 mangleQualifiers(Quals, DAST);
3184 mangleType(QualType(Ty, 0));
3186 mangleQualifiers(quals);
3190 mangleType(QualType(ty, 0));
3193 switch (ty->getTypeClass()) {
3194#define ABSTRACT_TYPE(CLASS, PARENT)
3195#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3197 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3199#define TYPE(CLASS, PARENT) \
3201 mangleType(static_cast<const CLASS##Type*>(ty)); \
3203#include "clang/AST/TypeNodes.inc"
3208 if (isSubstitutable)
3212void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3213 bool SuppressSubstitution) {
3214 if (mangleSubstitution(
Record))
3217 if (SuppressSubstitution)
3222void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3266 std::string type_name;
3270 if (NormalizeIntegers &&
T->isInteger()) {
3271 if (
T->isSignedInteger()) {
3272 switch (getASTContext().getTypeSize(
T)) {
3276 if (mangleSubstitution(BuiltinType::SChar))
3279 addSubstitution(BuiltinType::SChar);
3282 if (mangleSubstitution(BuiltinType::Short))
3285 addSubstitution(BuiltinType::Short);
3288 if (mangleSubstitution(BuiltinType::Int))
3291 addSubstitution(BuiltinType::Int);
3294 if (mangleSubstitution(BuiltinType::Long))
3297 addSubstitution(BuiltinType::Long);
3300 if (mangleSubstitution(BuiltinType::Int128))
3303 addSubstitution(BuiltinType::Int128);
3306 llvm_unreachable(
"Unknown integer size for normalization");
3309 switch (getASTContext().getTypeSize(
T)) {
3311 if (mangleSubstitution(BuiltinType::UChar))
3314 addSubstitution(BuiltinType::UChar);
3317 if (mangleSubstitution(BuiltinType::UShort))
3320 addSubstitution(BuiltinType::UShort);
3323 if (mangleSubstitution(BuiltinType::UInt))
3326 addSubstitution(BuiltinType::UInt);
3329 if (mangleSubstitution(BuiltinType::ULong))
3332 addSubstitution(BuiltinType::ULong);
3335 if (mangleSubstitution(BuiltinType::UInt128))
3338 addSubstitution(BuiltinType::UInt128);
3341 llvm_unreachable(
"Unknown integer size for normalization");
3346 switch (
T->getKind()) {
3347 case BuiltinType::Void:
3350 case BuiltinType::Bool:
3353 case BuiltinType::Char_U:
3354 case BuiltinType::Char_S:
3357 case BuiltinType::UChar:
3360 case BuiltinType::UShort:
3363 case BuiltinType::UInt:
3366 case BuiltinType::ULong:
3369 case BuiltinType::ULongLong:
3372 case BuiltinType::UInt128:
3375 case BuiltinType::SChar:
3378 case BuiltinType::WChar_S:
3379 case BuiltinType::WChar_U:
3382 case BuiltinType::Char8:
3385 case BuiltinType::Char16:
3388 case BuiltinType::Char32:
3391 case BuiltinType::Short:
3394 case BuiltinType::Int:
3397 case BuiltinType::Long:
3400 case BuiltinType::LongLong:
3403 case BuiltinType::Int128:
3406 case BuiltinType::Float16:
3409 case BuiltinType::ShortAccum:
3412 case BuiltinType::Accum:
3415 case BuiltinType::LongAccum:
3418 case BuiltinType::UShortAccum:
3421 case BuiltinType::UAccum:
3424 case BuiltinType::ULongAccum:
3427 case BuiltinType::ShortFract:
3430 case BuiltinType::Fract:
3433 case BuiltinType::LongFract:
3436 case BuiltinType::UShortFract:
3439 case BuiltinType::UFract:
3442 case BuiltinType::ULongFract:
3445 case BuiltinType::SatShortAccum:
3448 case BuiltinType::SatAccum:
3451 case BuiltinType::SatLongAccum:
3454 case BuiltinType::SatUShortAccum:
3457 case BuiltinType::SatUAccum:
3460 case BuiltinType::SatULongAccum:
3463 case BuiltinType::SatShortFract:
3466 case BuiltinType::SatFract:
3469 case BuiltinType::SatLongFract:
3472 case BuiltinType::SatUShortFract:
3475 case BuiltinType::SatUFract:
3478 case BuiltinType::SatULongFract:
3481 case BuiltinType::Half:
3484 case BuiltinType::Float:
3487 case BuiltinType::Double:
3490 case BuiltinType::LongDouble: {
3491 const TargetInfo *TI =
3492 getASTContext().getLangOpts().OpenMP &&
3493 getASTContext().getLangOpts().OpenMPIsTargetDevice
3494 ? getASTContext().getAuxTargetInfo()
3495 : &getASTContext().getTargetInfo();
3499 case BuiltinType::Float128: {
3500 const TargetInfo *TI =
3501 getASTContext().getLangOpts().OpenMP &&
3502 getASTContext().getLangOpts().OpenMPIsTargetDevice
3503 ? getASTContext().getAuxTargetInfo()
3504 : &getASTContext().getTargetInfo();
3508 case BuiltinType::BFloat16: {
3509 const TargetInfo *TI =
3510 ((getASTContext().getLangOpts().OpenMP &&
3511 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3512 getASTContext().getLangOpts().SYCLIsDevice)
3513 ? getASTContext().getAuxTargetInfo()
3514 : &getASTContext().getTargetInfo();
3518 case BuiltinType::Ibm128: {
3519 const TargetInfo *TI = &getASTContext().getTargetInfo();
3523 case BuiltinType::MetaInfo:
3527 case BuiltinType::NullPtr:
3531#define BUILTIN_TYPE(Id, SingletonId)
3532#define PLACEHOLDER_TYPE(Id, SingletonId) \
3533 case BuiltinType::Id:
3534#include "clang/AST/BuiltinTypes.def"
3535 case BuiltinType::Dependent:
3537 llvm_unreachable(
"mangling a placeholder type");
3539 case BuiltinType::ObjCId:
3540 Out <<
"11objc_object";
3542 case BuiltinType::ObjCClass:
3543 Out <<
"10objc_class";
3545 case BuiltinType::ObjCSel:
3546 Out <<
"13objc_selector";
3548#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3549 case BuiltinType::Id: \
3550 type_name = "ocl_" #ImgType "_" #Suffix; \
3551 Out << type_name.size() << type_name; \
3553#include "clang/Basic/OpenCLImageTypes.def"
3554 case BuiltinType::OCLSampler:
3555 Out <<
"11ocl_sampler";
3557 case BuiltinType::OCLEvent:
3558 Out <<
"9ocl_event";
3560 case BuiltinType::OCLClkEvent:
3561 Out <<
"12ocl_clkevent";
3563 case BuiltinType::OCLQueue:
3564 Out <<
"9ocl_queue";
3566 case BuiltinType::OCLReserveID:
3567 Out <<
"13ocl_reserveid";
3569#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3570 case BuiltinType::Id: \
3571 type_name = "ocl_" #ExtType; \
3572 Out << type_name.size() << type_name; \
3574#include "clang/Basic/OpenCLExtensionTypes.def"
3578#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3579 case BuiltinType::Id: \
3580 if (T->getKind() == BuiltinType::SveBFloat16 && \
3581 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3583 mangleVendorType("__SVBFloat16_t"); \
3585 type_name = #MangledName; \
3586 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3589#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3590 case BuiltinType::Id: \
3591 type_name = #MangledName; \
3592 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3594#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3595 case BuiltinType::Id: \
3596 type_name = #MangledName; \
3597 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3599#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3600 case BuiltinType::Id: \
3601 type_name = #MangledName; \
3602 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3604#include "clang/Basic/AArch64ACLETypes.def"
3605#define PPC_VECTOR_TYPE(Name, Id, Size) \
3606 case BuiltinType::Id: \
3607 mangleVendorType(#Name); \
3609#include "clang/Basic/PPCTypes.def"
3611#define RVV_TYPE(Name, Id, SingletonId) \
3612 case BuiltinType::Id: \
3613 mangleVendorType(Name); \
3615#include "clang/Basic/RISCVVTypes.def"
3616#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3617 case BuiltinType::Id: \
3618 mangleVendorType(MangledName); \
3620#include "clang/Basic/WebAssemblyReferenceTypes.def"
3621#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3622 case BuiltinType::Id: \
3623 mangleVendorType(Name); \
3625#include "clang/Basic/AMDGPUTypes.def"
3626#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3627 case BuiltinType::Id: \
3628 mangleVendorType(#Name); \
3630#include "clang/Basic/HLSLIntangibleTypes.def"
3631#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
3632 case BuiltinType::Id: \
3633 mangleVendorType(#Name); \
3635#include "clang/Basic/HLSLPackedTypes.def"
3636#define SPIRV_TYPE(Name, Id, SingletonId) \
3637 case BuiltinType::Id: \
3638 mangleVendorType(Name); \
3640#include "clang/Basic/SPIRVTypes.def"
3644StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3663#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3699 return "swiftasynccall";
3701 llvm_unreachable(
"bad calling convention");
3704void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3713 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3714 if (!CCQualifier.empty())
3715 mangleVendorQualifier(CCQualifier);
3748 llvm_unreachable(
"Unrecognised SME attribute");
3763void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3783 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3787CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3794 case ParameterABI::Ordinary:
3798 case ParameterABI::HLSLOut:
3799 case ParameterABI::HLSLInOut:
3804 case ParameterABI::SwiftContext:
3805 case ParameterABI::SwiftAsyncContext:
3806 case ParameterABI::SwiftErrorResult:
3807 case ParameterABI::SwiftIndirectResult:
3813 mangleVendorQualifier(
"ns_consumed");
3816 mangleVendorQualifier(
"noescape");
3822void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3826 Out <<
"11__SME_ATTRSI";
3828 mangleExtFunctionInfo(
T);
3845 mangleType(ExceptTy);
3856 mangleBareFunctionType(
T,
true);
3863 mangleSMEAttrs(SMEAttrs);
3866void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3872 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3874 FunctionTypeDepth.enterFunctionDeclSuffix();
3876 FunctionTypeDepth.leaveFunctionDeclSuffix();
3878 FunctionTypeDepth.pop(saved);
3882void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3883 bool MangleReturnType,
3884 const FunctionDecl *FD) {
3887 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3890 if (MangleReturnType) {
3891 FunctionTypeDepth.enterFunctionDeclSuffix();
3895 mangleVendorQualifier(
"ns_returns_retained");
3900 auto SplitReturnTy = ReturnTy.
split();
3902 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3904 mangleType(ReturnTy);
3906 FunctionTypeDepth.leaveFunctionDeclSuffix();
3914 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3928 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3929 if (Attr->isDynamic())
3930 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3932 Out <<
"U17pass_object_size" << Attr->getType();
3943 FunctionTypeDepth.enterFunctionDeclSuffix();
3947 FunctionTypeDepth.pop(saved);
3952void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3953 mangleName(
T->getDecl());
3958void CXXNameMangler::mangleType(
const EnumType *
T) {
3959 mangleType(
static_cast<const TagType*
>(
T));
3961void CXXNameMangler::mangleType(
const RecordType *
T) {
3962 mangleType(
static_cast<const TagType*
>(
T));
3964void CXXNameMangler::mangleType(
const TagType *
T) {
3965 mangleName(
T->getDecl()->getDefinitionOrSelf());
3971void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3972 Out <<
'A' <<
T->getSize() <<
'_';
3973 mangleType(
T->getElementType());
3975void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3978 if (
T->getSizeExpr())
3979 mangleExpression(
T->getSizeExpr());
3981 mangleType(
T->getElementType());
3983void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3988 if (
T->getSizeExpr())
3989 mangleExpression(
T->getSizeExpr());
3991 mangleType(
T->getElementType());
3993void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3995 mangleType(
T->getElementType());
4000void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
4002 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
4003 mangleCXXRecordDecl(RD);
4005 mangleType(QualType(
T->getQualifier().getAsType(), 0));
4007 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
4028 mangleType(PointeeType);
4032void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
4033 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
4037void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
4042 Out <<
"_SUBSTPACK_";
4045void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
4050 Out <<
"_SUBSTBUILTINPACK_";
4054void CXXNameMangler::mangleType(
const PointerType *
T) {
4058void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
4064void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
4070void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
4076void CXXNameMangler::mangleType(
const ComplexType *
T) {
4078 mangleType(
T->getElementType());
4084void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
4085 QualType EltType =
T->getElementType();
4086 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4087 const char *EltName =
nullptr;
4088 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4090 case BuiltinType::SChar:
4091 case BuiltinType::UChar:
4092 EltName =
"poly8_t";
4094 case BuiltinType::Short:
4095 case BuiltinType::UShort:
4096 EltName =
"poly16_t";
4098 case BuiltinType::LongLong:
4099 case BuiltinType::ULongLong:
4100 EltName =
"poly64_t";
4102 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
4106 case BuiltinType::SChar: EltName =
"int8_t";
break;
4107 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4108 case BuiltinType::Short: EltName =
"int16_t";
break;
4109 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4110 case BuiltinType::Int: EltName =
"int32_t";
break;
4111 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4112 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4113 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4114 case BuiltinType::Double: EltName =
"float64_t";
break;
4115 case BuiltinType::Float: EltName =
"float32_t";
break;
4116 case BuiltinType::Half: EltName =
"float16_t";
break;
4117 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4118 case BuiltinType::MFloat8:
4119 EltName =
"mfloat8_t";
4122 llvm_unreachable(
"unexpected Neon vector element type");
4125 const char *BaseName =
nullptr;
4126 unsigned BitSize = (
T->getNumElements() *
4127 getASTContext().getTypeSize(EltType));
4129 BaseName =
"__simd64_";
4131 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4132 BaseName =
"__simd128_";
4134 Out << strlen(BaseName) + strlen(EltName);
4135 Out << BaseName << EltName;
4138void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4139 DiagnosticsEngine &Diags = Context.getDiags();
4140 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4141 << UnsupportedItaniumManglingKind::DependentNeonVector;
4146 case BuiltinType::SChar:
4148 case BuiltinType::Short:
4150 case BuiltinType::Int:
4152 case BuiltinType::Long:
4153 case BuiltinType::LongLong:
4155 case BuiltinType::UChar:
4157 case BuiltinType::UShort:
4159 case BuiltinType::UInt:
4161 case BuiltinType::ULong:
4162 case BuiltinType::ULongLong:
4164 case BuiltinType::Half:
4166 case BuiltinType::Float:
4168 case BuiltinType::Double:
4170 case BuiltinType::BFloat16:
4172 case BuiltinType::MFloat8:
4175 llvm_unreachable(
"Unexpected vector element base type");
4182void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4183 QualType EltType =
T->getElementType();
4184 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4186 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4189 assert((BitSize == 64 || BitSize == 128) &&
4190 "Neon vector type not 64 or 128 bits");
4193 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4195 case BuiltinType::UChar:
4198 case BuiltinType::UShort:
4201 case BuiltinType::ULong:
4202 case BuiltinType::ULongLong:
4206 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4212 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4215void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4216 DiagnosticsEngine &Diags = Context.getDiags();
4217 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4218 << UnsupportedItaniumManglingKind::DependentNeonVector;
4245void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4246 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4247 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4248 "expected fixed-length SVE vector!");
4250 QualType EltType =
T->getElementType();
4252 "expected builtin type for fixed-length SVE vector!");
4256 case BuiltinType::SChar:
4259 case BuiltinType::UChar: {
4260 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4266 case BuiltinType::Short:
4269 case BuiltinType::UShort:
4272 case BuiltinType::Int:
4275 case BuiltinType::UInt:
4278 case BuiltinType::Long:
4281 case BuiltinType::ULong:
4284 case BuiltinType::Half:
4287 case BuiltinType::Float:
4290 case BuiltinType::Double:
4293 case BuiltinType::BFloat16:
4297 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4300 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4302 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4305 Out <<
"9__SVE_VLSI";
4306 mangleVendorType(TypeName);
4307 Out <<
"Lj" << VecSizeInBits <<
"EE";
4310void CXXNameMangler::mangleAArch64FixedSveVectorType(
4311 const DependentVectorType *
T) {
4312 DiagnosticsEngine &Diags = Context.getDiags();
4313 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4314 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4317void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4319 "expected fixed-length RVV vector!");
4321 QualType EltType =
T->getElementType();
4323 "expected builtin type for fixed-length RVV vector!");
4325 SmallString<20> TypeNameStr;
4326 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4327 TypeNameOS <<
"__rvv_";
4329 case BuiltinType::SChar:
4330 TypeNameOS <<
"int8";
4332 case BuiltinType::UChar:
4334 TypeNameOS <<
"uint8";
4336 TypeNameOS <<
"bool";
4338 case BuiltinType::Short:
4339 TypeNameOS <<
"int16";
4341 case BuiltinType::UShort:
4342 TypeNameOS <<
"uint16";
4344 case BuiltinType::Int:
4345 TypeNameOS <<
"int32";
4347 case BuiltinType::UInt:
4348 TypeNameOS <<
"uint32";
4350 case BuiltinType::Long:
4351 case BuiltinType::LongLong:
4352 TypeNameOS <<
"int64";
4354 case BuiltinType::ULong:
4355 case BuiltinType::ULongLong:
4356 TypeNameOS <<
"uint64";
4358 case BuiltinType::Float16:
4359 TypeNameOS <<
"float16";
4361 case BuiltinType::Float:
4362 TypeNameOS <<
"float32";
4364 case BuiltinType::Double:
4365 TypeNameOS <<
"float64";
4367 case BuiltinType::BFloat16:
4368 TypeNameOS <<
"bfloat16";
4371 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4377 ?
T->getRVVFixedLengthMaskLanes()
4378 : getASTContext().getTypeInfo(
T).Width;
4385 Out <<
"9__RVV_VLSI";
4386 mangleVendorType(TypeNameStr);
4387 Out <<
"Lj" << VecSizeInBits <<
"EE";
4390void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4391 const DependentVectorType *
T) {
4392 DiagnosticsEngine &Diags = Context.getDiags();
4393 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4394 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4405void CXXNameMangler::mangleType(
const VectorType *
T) {
4406 if ((
T->getVectorKind() == VectorKind::Neon ||
4407 T->getVectorKind() == VectorKind::NeonPoly)) {
4408 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4409 llvm::Triple::ArchType
Arch =
4410 getASTContext().getTargetInfo().getTriple().getArch();
4411 if ((
Arch == llvm::Triple::aarch64 ||
4412 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4413 mangleAArch64NeonVectorType(
T);
4415 mangleNeonVectorType(
T);
4417 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4418 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4419 mangleAArch64FixedSveVectorType(
T);
4422 mangleRISCVFixedRVVVectorType(
T);
4425 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4426 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4428 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4431 mangleType(
T->getElementType());
4434void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4435 if ((
T->getVectorKind() == VectorKind::Neon ||
4436 T->getVectorKind() == VectorKind::NeonPoly)) {
4437 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4438 llvm::Triple::ArchType
Arch =
4439 getASTContext().getTargetInfo().getTriple().getArch();
4440 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4442 mangleAArch64NeonVectorType(
T);
4444 mangleNeonVectorType(
T);
4446 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4447 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4448 mangleAArch64FixedSveVectorType(
T);
4451 mangleRISCVFixedRVVVectorType(
T);
4456 mangleExpression(
T->getSizeExpr());
4458 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4460 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4463 mangleType(
T->getElementType());
4466void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4467 mangleType(
static_cast<const VectorType*
>(
T));
4469void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4471 mangleExpression(
T->getSizeExpr());
4473 mangleType(
T->getElementType());
4476void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4480 mangleVendorType(
"matrix_type");
4483 auto &ASTCtx = getASTContext();
4484 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4485 llvm::APSInt Rows(BitWidth);
4486 Rows =
T->getNumRows();
4487 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4488 llvm::APSInt Columns(BitWidth);
4489 Columns =
T->getNumColumns();
4490 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4491 mangleType(
T->getElementType());
4495void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4498 mangleVendorType(
"matrix_type");
4501 mangleTemplateArgExpr(
T->getRowExpr());
4502 mangleTemplateArgExpr(
T->getColumnExpr());
4503 mangleType(
T->getElementType());
4507void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4509 mangleQualifiers(split.
Quals,
T);
4510 mangleType(QualType(split.
Ty, 0));
4513void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4516 mangleType(
T->getPattern());
4519void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4522 mangleType(
T->getPattern());
4523 mangleExpression(
T->getIndexExpr());
4526void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4527 mangleSourceName(
T->getDecl()->getIdentifier());
4530void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4532 if (
T->isKindOfType())
4533 Out <<
"U8__kindof";
4535 if (!
T->qual_empty()) {
4537 SmallString<64> QualStr;
4538 llvm::raw_svector_ostream QualOS(QualStr);
4539 QualOS <<
"objcproto";
4540 for (
const auto *I :
T->quals()) {
4541 StringRef
name = I->getName();
4544 mangleVendorQualifier(QualStr);
4547 mangleType(
T->getBaseType());
4549 if (
T->isSpecialized()) {
4552 for (
auto typeArg :
T->getTypeArgs())
4553 mangleType(typeArg);
4558void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4559 Out <<
"U13block_pointer";
4563void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4568 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4571void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4572 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4573 mangleTemplateName(TD,
T->template_arguments());
4576 mangleTemplatePrefix(
T->getTemplateName());
4581 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4586void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4597 switch (
T->getKeyword()) {
4598 case ElaboratedTypeKeyword::None:
4599 case ElaboratedTypeKeyword::Typename:
4601 case ElaboratedTypeKeyword::Struct:
4602 case ElaboratedTypeKeyword::Class:
4603 case ElaboratedTypeKeyword::Interface:
4606 case ElaboratedTypeKeyword::Union:
4609 case ElaboratedTypeKeyword::Enum:
4615 manglePrefix(
T->getQualifier());
4616 mangleSourceName(
T->getIdentifier());
4620void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4626void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4632void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4633 Expr *E =
T->getUnderlyingExpr();
4652 mangleExpression(E);
4656void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4660 StringRef BuiltinName;
4661 switch (
T->getUTTKind()) {
4662#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4663 case UnaryTransformType::Enum: \
4664 BuiltinName = "__" #Trait; \
4666#include "clang/Basic/BuiltinTraits.inc"
4668 mangleVendorType(BuiltinName);
4672 mangleType(
T->getBaseType());
4676void CXXNameMangler::mangleType(
const AutoType *
T) {
4677 assert(
T->getDeducedType().isNull() &&
4678 "Deduced AutoType shouldn't be handled here!");
4679 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4680 "shouldn't need to mangle __auto_type!");
4685 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4686 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4687 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4688 T->getTypeConstraintArguments());
4690 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4694void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4695 QualType
Deduced =
T->getDeducedType();
4701 "shouldn't form deduced TST unless we know we have a template");
4705void CXXNameMangler::mangleType(
const AtomicType *
T) {
4709 mangleType(
T->getValueType());
4712void CXXNameMangler::mangleType(
const PipeType *
T) {
4719void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4722 if (
T->isWrapKind()) {
4723 Out <<
"U8ObtWrap_";
4725 Out <<
"U8ObtTrap_";
4727 mangleType(
T->getUnderlyingType());
4730void CXXNameMangler::mangleType(
const BitIntType *
T) {
4734 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4737void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4741 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4742 mangleExpression(
T->getNumBitsExpr());
4746void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4750void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4751 llvm::SmallString<64> Str(
"_Res");
4752 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4754 switch (Attrs.ResourceClass) {
4755 case llvm::dxil::ResourceClass::UAV:
4758 case llvm::dxil::ResourceClass::SRV:
4761 case llvm::dxil::ResourceClass::CBuffer:
4764 case llvm::dxil::ResourceClass::Sampler:
4770 if (Attrs.RawBuffer)
4772 if (Attrs.IsCounter)
4776 if (Attrs.isMultiSampled())
4778 if (
T->hasContainedType())
4780 mangleVendorQualifier(Str);
4782 if (
T->hasContainedType()) {
4783 mangleType(
T->getContainedType());
4785 mangleType(
T->getWrappedType());
4788void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4789 SmallString<20> TypeNameStr;
4790 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4792 TypeNameOS <<
"spirv_type";
4794 TypeNameOS <<
"_" <<
T->getOpcode();
4795 TypeNameOS <<
"_" <<
T->getSize();
4796 TypeNameOS <<
"_" <<
T->getAlignment();
4798 mangleVendorType(TypeNameStr);
4800 for (
auto &Operand :
T->getOperands()) {
4801 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4804 case SpirvOperandKind::ConstantId:
4805 mangleVendorQualifier(
"_Const");
4806 mangleIntegerLiteral(
Operand.getResultType(),
4807 llvm::APSInt(
Operand.getValue()));
4809 case SpirvOperandKind::Literal:
4810 mangleVendorQualifier(
"_Lit");
4811 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4812 llvm::APSInt(
Operand.getValue()));
4814 case SpirvOperandKind::TypeId:
4815 mangleVendorQualifier(
"_Type");
4816 mangleType(
Operand.getResultType());
4819 llvm_unreachable(
"Invalid SpirvOperand kind");
4822 TypeNameOS <<
Operand.getKind();
4826void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4827 const llvm::APSInt &
Value) {
4834 Out << (
Value.getBoolValue() ?
'1' :
'0');
4836 mangleNumber(
Value);
4841void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4843 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4844 if (!RT->getDecl()->isAnonymousStructOrUnion())
4846 const auto *ME = dyn_cast<MemberExpr>(Base);
4849 Base = ME->getBase();
4850 IsArrow = ME->isArrow();
4853 if (
Base->isImplicitCXXThis()) {
4859 Out << (IsArrow ?
"pt" :
"dt");
4860 mangleExpression(Base);
4865void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4866 NestedNameSpecifier Qualifier,
4867 NamedDecl *firstQualifierLookup,
4868 DeclarationName member,
4869 const TemplateArgumentLoc *TemplateArgs,
4870 unsigned NumTemplateArgs,
4875 mangleMemberExprBase(base, isArrow);
4876 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4889 if (callee == fn)
return false;
4893 if (!lookup)
return false;
4910void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4912 Out << CastEncoding;
4914 if (
const auto *PLIE = dyn_cast<CXXParenListInitExpr>(ECE->
getSubExpr())) {
4915 ArrayRef<Expr *>
Inits = PLIE->getUserSpecifiedInitExprs();
4916 assert(
Inits.size() == 1 &&
"cast must have exactly one operand");
4917 mangleExpression(
Inits.front());
4923void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4925 InitList = Syntactic;
4926 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4927 mangleExpression(InitList->
getInit(i));
4930void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4931 const concepts::Requirement *Req) {
4932 using concepts::Requirement;
4937 auto HandleSubstitutionFailure =
4938 [&](SourceLocation Loc) {
4939 DiagnosticsEngine &Diags = Context.getDiags();
4940 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4941 << UnsupportedItaniumManglingKind::
4942 RequiresExprWithSubstitutionFailure;
4947 case Requirement::RK_Type: {
4949 if (TR->isSubstitutionFailure())
4950 return HandleSubstitutionFailure(
4951 TR->getSubstitutionDiagnostic()->DiagLoc);
4954 mangleType(TR->getType()->getType());
4958 case Requirement::RK_Simple:
4959 case Requirement::RK_Compound: {
4961 if (ER->isExprSubstitutionFailure())
4962 return HandleSubstitutionFailure(
4963 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4966 mangleExpression(ER->getExpr());
4968 if (ER->hasNoexceptRequirement())
4971 if (!ER->getReturnTypeRequirement().isEmpty()) {
4972 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4973 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4974 .getSubstitutionDiagnostic()
4978 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4983 case Requirement::RK_Nested:
4985 if (NR->hasInvalidConstraint()) {
4988 return HandleSubstitutionFailure(RequiresExprLoc);
4992 mangleExpression(NR->getConstraintExpr());
4997void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4998 bool AsTemplateArg) {
5032 QualType ImplicitlyConvertedToType;
5036 bool IsPrimaryExpr =
true;
5037 auto NotPrimaryExpr = [&] {
5038 if (AsTemplateArg && IsPrimaryExpr)
5040 IsPrimaryExpr =
false;
5043 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
5057 case Decl::EnumConstant: {
5064 case Decl::NonTypeTemplateParm:
5077 case Expr::NoStmtClass:
5078#define ABSTRACT_STMT(Type)
5079#define EXPR(Type, Base)
5080#define STMT(Type, Base) \
5081 case Expr::Type##Class:
5082#include "clang/AST/StmtNodes.inc"
5087 case Expr::AddrLabelExprClass:
5088 case Expr::DesignatedInitUpdateExprClass:
5089 case Expr::ImplicitValueInitExprClass:
5090 case Expr::ArrayInitLoopExprClass:
5091 case Expr::ArrayInitIndexExprClass:
5092 case Expr::NoInitExprClass:
5093 case Expr::ParenListExprClass:
5094 case Expr::MSPropertyRefExprClass:
5095 case Expr::MSPropertySubscriptExprClass:
5096 case Expr::RecoveryExprClass:
5097 case Expr::ArraySectionExprClass:
5098 case Expr::OMPArrayShapingExprClass:
5099 case Expr::OMPIteratorExprClass:
5100 case Expr::CXXInheritedCtorInitExprClass:
5101 case Expr::CXXParenListInitExprClass:
5102 case Expr::CXXExpansionSelectExprClass:
5103 llvm_unreachable(
"unexpected statement kind");
5105 case Expr::ConstantExprClass:
5109 case Expr::CXXReflectExprClass: {
5116 case Expr::BlockExprClass:
5117 case Expr::ChooseExprClass:
5118 case Expr::CompoundLiteralExprClass:
5119 case Expr::ExtVectorElementExprClass:
5120 case Expr::MatrixElementExprClass:
5121 case Expr::GenericSelectionExprClass:
5122 case Expr::ObjCEncodeExprClass:
5123 case Expr::ObjCIsaExprClass:
5124 case Expr::ObjCIvarRefExprClass:
5125 case Expr::ObjCMessageExprClass:
5126 case Expr::ObjCPropertyRefExprClass:
5127 case Expr::ObjCProtocolExprClass:
5128 case Expr::ObjCSelectorExprClass:
5129 case Expr::ObjCStringLiteralClass:
5130 case Expr::ObjCBoxedExprClass:
5131 case Expr::ObjCArrayLiteralClass:
5132 case Expr::ObjCDictionaryLiteralClass:
5133 case Expr::ObjCSubscriptRefExprClass:
5134 case Expr::ObjCIndirectCopyRestoreExprClass:
5135 case Expr::ObjCAvailabilityCheckExprClass:
5136 case Expr::OffsetOfExprClass:
5137 case Expr::PredefinedExprClass:
5138 case Expr::ShuffleVectorExprClass:
5139 case Expr::ConvertVectorExprClass:
5140 case Expr::StmtExprClass:
5141 case Expr::ArrayTypeTraitExprClass:
5142 case Expr::ExpressionTraitExprClass:
5143 case Expr::VAArgExprClass:
5144 case Expr::CUDAKernelCallExprClass:
5145 case Expr::AsTypeExprClass:
5146 case Expr::PseudoObjectExprClass:
5147 case Expr::AtomicExprClass:
5148 case Expr::SourceLocExprClass:
5149 case Expr::EmbedExprClass:
5150 case Expr::BuiltinBitCastExprClass: {
5154 DiagnosticsEngine &Diags = Context.getDiags();
5162 case Expr::CXXUuidofExprClass: {
5167 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5168 Out <<
"u8__uuidof";
5177 Out <<
"u8__uuidoft";
5181 Out <<
"u8__uuidofz";
5182 mangleExpression(UuidExp);
5189 case Expr::BinaryConditionalOperatorClass: {
5191 DiagnosticsEngine &Diags = Context.getDiags();
5193 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5199 case Expr::OpaqueValueExprClass:
5200 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5202 case Expr::InitListExprClass: {
5210 case Expr::DesignatedInitExprClass: {
5213 for (
const auto &Designator : DIE->designators()) {
5214 if (Designator.isFieldDesignator()) {
5216 mangleSourceName(Designator.getFieldName());
5217 }
else if (Designator.isArrayDesignator()) {
5219 mangleExpression(DIE->getArrayIndex(Designator));
5221 assert(Designator.isArrayRangeDesignator() &&
5222 "unknown designator kind");
5224 mangleExpression(DIE->getArrayRangeStart(Designator));
5225 mangleExpression(DIE->getArrayRangeEnd(Designator));
5228 mangleExpression(DIE->getInit());
5232 case Expr::CXXDefaultArgExprClass:
5236 case Expr::CXXDefaultInitExprClass:
5240 case Expr::CXXStdInitializerListExprClass:
5244 case Expr::SubstNonTypeTemplateParmExprClass: {
5248 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5250 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5251 mangleValueInTemplateArg(SNTTPE->getParameterType(),
5252 CE->getAPValueResult(),
false,
5262 case Expr::UserDefinedLiteralClass:
5265 case Expr::CXXMemberCallExprClass:
5266 case Expr::CallExprClass: {
5288 CallArity = UnknownArity;
5290 mangleExpression(CE->
getCallee(), CallArity);
5292 mangleExpression(Arg);
5297 case Expr::CXXNewExprClass: {
5300 if (
New->isGlobalNew())
Out <<
"gs";
5301 Out << (
New->isArray() ?
"na" :
"nw");
5303 E =
New->placement_arg_end(); I != E; ++I)
5304 mangleExpression(*I);
5306 mangleType(
New->getAllocatedType());
5307 if (
New->hasInitializer()) {
5308 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5312 const Expr *
Init =
New->getInitializer();
5313 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5318 mangleExpression(*I);
5319 }
else if (
const auto *PLE = dyn_cast<CXXParenListInitExpr>(
Init)) {
5320 for (
const Expr *Arg : PLE->getUserSpecifiedInitExprs())
5321 mangleExpression(Arg);
5322 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5323 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5324 mangleExpression(PLE->getExpr(i));
5325 }
else if (
New->getInitializationStyle() ==
5326 CXXNewInitializationStyle::Braces &&
5331 mangleExpression(
Init);
5337 case Expr::CXXPseudoDestructorExprClass: {
5340 if (
const Expr *Base = PDE->getBase())
5341 mangleMemberExprBase(Base, PDE->isArrow());
5342 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5343 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5345 mangleUnresolvedPrefix(Qualifier,
5347 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5351 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5354 }
else if (Qualifier) {
5355 mangleUnresolvedPrefix(Qualifier);
5359 QualType DestroyedType = PDE->getDestroyedType();
5360 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5364 case Expr::MemberExprClass: {
5375 case Expr::UnresolvedMemberExprClass: {
5386 case Expr::CXXDependentScopeMemberExprClass: {
5388 const CXXDependentScopeMemberExpr *ME
5399 case Expr::UnresolvedLookupExprClass: {
5408 case Expr::DependentTemplateIdExprClass: {
5411 if (DTI->getTemplateName().getAsPackIndexingTemplate()) {
5412 DiagnoseUnsupportedPackIndexTemplateName();
5415 mangleUnresolvedName(std::nullopt, DTI->getName(),
5416 DTI->template_arguments().data(),
5417 DTI->getNumTemplateArgs(), Arity);
5421 case Expr::CXXUnresolvedConstructExprClass: {
5427 assert(N == 1 &&
"unexpected form for list initialization");
5431 mangleInitListElements(IL);
5438 if (N != 1)
Out <<
'_';
5439 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5440 if (N != 1)
Out <<
'E';
5444 case Expr::CXXConstructExprClass: {
5451 "implicit CXXConstructExpr must have one argument");
5458 mangleExpression(E);
5463 case Expr::CXXTemporaryObjectExprClass: {
5474 if (!List && N != 1)
5476 if (CE->isStdInitListInitialization()) {
5483 mangleInitListElements(ILE);
5486 mangleExpression(E);
5493 case Expr::CXXScalarValueInitExprClass:
5500 case Expr::CXXNoexceptExprClass:
5506 case Expr::UnaryExprOrTypeTraitExprClass: {
5523 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5525 : ImplicitlyConvertedToType;
5527 mangleIntegerLiteral(
T,
V);
5533 auto MangleAlignofSizeofArg = [&] {
5543 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5544 StringRef Name = {}) {
5547 mangleVendorType(Name);
5558 MangleAlignofSizeofArg();
5560 case UETT_PreferredAlignOf:
5564 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5565 MangleExtensionBuiltin(SAE,
"__alignof__");
5571 MangleAlignofSizeofArg();
5575 case UETT_VectorElements:
5576 case UETT_OpenMPRequiredSimdAlign:
5578 case UETT_PtrAuthTypeDiscriminator:
5579 case UETT_DataSizeOf: {
5580 DiagnosticsEngine &Diags = Context.getDiags();
5589 case Expr::TypeTraitExprClass: {
5594 mangleVendorType(Spelling);
5595 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5596 mangleType(TSI->getType());
5602 case Expr::CXXThrowExprClass: {
5616 case Expr::CXXTypeidExprClass: {
5631 case Expr::CXXDeleteExprClass: {
5642 case Expr::UnaryOperatorClass: {
5651 case Expr::ArraySubscriptExprClass: {
5658 mangleExpression(AE->
getLHS());
5659 mangleExpression(AE->
getRHS());
5663 case Expr::MatrixSingleSubscriptExprClass: {
5667 mangleExpression(ME->
getBase());
5672 case Expr::MatrixSubscriptExprClass: {
5676 mangleExpression(ME->
getBase());
5682 case Expr::CompoundAssignOperatorClass:
5683 case Expr::BinaryOperatorClass: {
5691 mangleExpression(BO->
getLHS());
5692 mangleExpression(BO->
getRHS());
5696 case Expr::CXXRewrittenBinaryOperatorClass: {
5699 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5703 mangleExpression(Decomposed.
LHS);
5704 mangleExpression(Decomposed.
RHS);
5708 case Expr::ConditionalOperatorClass: {
5711 mangleOperatorName(OO_Conditional, 3);
5712 mangleExpression(CO->
getCond());
5713 mangleExpression(CO->
getLHS(), Arity);
5714 mangleExpression(CO->
getRHS(), Arity);
5718 case Expr::ImplicitCastExprClass: {
5719 ImplicitlyConvertedToType = E->
getType();
5724 case Expr::ObjCBridgedCastExprClass: {
5730 mangleCastExpression(E,
"cv");
5734 case Expr::CStyleCastExprClass:
5736 mangleCastExpression(E,
"cv");
5739 case Expr::CXXFunctionalCastExprClass: {
5743 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5744 if (CCE->getParenOrBraceRange().isInvalid())
5745 Sub = CCE->getArg(0)->IgnoreImplicit();
5746 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5747 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5748 if (
auto *PLIE = dyn_cast<CXXParenListInitExpr>(Sub)) {
5749 ArrayRef<Expr *>
Inits = PLIE->getUserSpecifiedInitExprs();
5752 if (
Inits.size() != 1)
5755 mangleExpression(
Init);
5756 if (
Inits.size() != 1)
5758 }
else if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5761 mangleInitListElements(IL);
5764 mangleCastExpression(E,
"cv");
5769 case Expr::CXXStaticCastExprClass:
5771 mangleCastExpression(E,
"sc");
5773 case Expr::CXXDynamicCastExprClass:
5775 mangleCastExpression(E,
"dc");
5777 case Expr::CXXReinterpretCastExprClass:
5779 mangleCastExpression(E,
"rc");
5781 case Expr::CXXConstCastExprClass:
5783 mangleCastExpression(E,
"cc");
5785 case Expr::CXXAddrspaceCastExprClass:
5787 mangleCastExpression(E,
"ac");
5790 case Expr::CXXOperatorCallExprClass: {
5799 for (
unsigned i = 0; i != NumArgs; ++i)
5800 mangleExpression(CE->
getArg(i));
5804 case Expr::ParenExprClass:
5808 case Expr::ConceptSpecializationExprClass: {
5810 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5815 mangleTemplateName(CSE->getConceptDecl(), CSE->getTemplateArguments());
5821 mangleUnresolvedName(
5822 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5823 CSE->getConceptNameInfo().getName(),
5824 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5825 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5829 case Expr::RequiresExprClass: {
5835 if (RE->getLParenLoc().isValid()) {
5837 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5838 if (RE->getLocalParameters().empty()) {
5841 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5849 FunctionTypeDepth.enterFunctionDeclSuffix();
5850 for (
const concepts::Requirement *Req : RE->getRequirements())
5851 mangleRequirement(RE->getExprLoc(), Req);
5852 FunctionTypeDepth.pop(saved);
5856 for (
const concepts::Requirement *Req : RE->getRequirements())
5857 mangleRequirement(RE->getExprLoc(), Req);
5863 case Expr::DeclRefExprClass:
5868 case Expr::SubstNonTypeTemplateParmPackExprClass:
5874 Out <<
"_SUBSTPACK_";
5877 case Expr::FunctionParmPackExprClass: {
5881 Out <<
"v110_SUBSTPACK";
5886 case Expr::DependentScopeDeclRefExprClass: {
5895 case Expr::CXXBindTemporaryExprClass:
5899 case Expr::ExprWithCleanupsClass:
5903 case Expr::FloatingLiteralClass: {
5910 case Expr::FixedPointLiteralClass:
5912 mangleFixedPointLiteral();
5915 case Expr::CharacterLiteralClass:
5919 Out << cast<CharacterLiteral>(E)->getValue();
5924 case Expr::ObjCBoolLiteralExprClass:
5927 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5931 case Expr::CXXBoolLiteralExprClass:
5934 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5938 case Expr::IntegerLiteralClass: {
5942 Value.setIsSigned(
true);
5947 case Expr::ImaginaryLiteralClass: {
5954 if (
const FloatingLiteral *Imag =
5955 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5957 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5959 mangleFloat(Imag->getValue());
5964 Value.setIsSigned(
true);
5965 mangleNumber(
Value);
5971 case Expr::StringLiteralClass: {
5981 case Expr::GNUNullExprClass:
5984 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5987 case Expr::CXXNullPtrLiteralExprClass: {
5993 case Expr::LambdaExprClass: {
6004 case Expr::PackExpansionExprClass:
6010 case Expr::SizeOfPackExprClass: {
6013 if (SPE->isPartiallySubstituted()) {
6015 for (
const auto &A : SPE->getPartialArguments())
6016 mangleTemplateArg(A,
false);
6022 mangleReferenceToPack(SPE->getPack());
6026 case Expr::MaterializeTemporaryExprClass:
6030 case Expr::CXXFoldExprClass: {
6033 if (FE->isLeftFold())
6034 Out << (FE->getInit() ?
"fL" :
"fl");
6036 Out << (FE->getInit() ?
"fR" :
"fr");
6038 if (FE->getOperator() == BO_PtrMemD)
6046 mangleExpression(FE->getLHS());
6048 mangleExpression(FE->getRHS());
6052 case Expr::PackIndexingExprClass: {
6056 mangleReferenceToPack(PE->getPackDecl());
6057 mangleExpression(PE->getIndexExpr());
6061 case Expr::CXXThisExprClass:
6066 case Expr::CoawaitExprClass:
6069 Out <<
"v18co_await";
6073 case Expr::DependentCoawaitExprClass:
6076 Out <<
"v18co_await";
6080 case Expr::CoyieldExprClass:
6083 Out <<
"v18co_yield";
6086 case Expr::SYCLUniqueStableNameExprClass: {
6090 Out <<
"u33__builtin_sycl_unique_stable_name";
6091 mangleType(USN->getTypeSourceInfo()->getType());
6096 case Expr::HLSLOutArgExprClass:
6098 "cannot mangle hlsl temporary value; mangling wrong thing?");
6099 case Expr::OpenACCAsteriskSizeExprClass: {
6101 DiagnosticsEngine &Diags = Context.getDiags();
6102 Diags.
Report(diag::err_unsupported_itanium_mangling)
6103 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
6108 if (AsTemplateArg && !IsPrimaryExpr)
6140void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6145 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6146 nestingDepth == 0) {
6149 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6157 &&
"parameter's type is still an array type?");
6159 if (
const DependentAddressSpaceType *DAST =
6160 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6167 if (parmIndex != 0) {
6168 Out << (parmIndex - 1);
6174 const CXXRecordDecl *InheritedFrom) {
6201 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6204 mangleName(InheritedFrom);
6232 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6236void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6237 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6238 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6239 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6240 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6241 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6242 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6276 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6277 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6278 if (!RD || !RD->isGenericLambda())
6294 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6295 return TTP->hasTypeConstraint();
6312 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6313 return NTTP->getType()->isInstantiationDependentType() ||
6314 NTTP->getType()->getContainedDeducedType();
6321 "A DeducedTemplateName shouldn't escape partial ordering");
6332 auto MangleTemplateParamListToString =
6334 unsigned DepthOffset) {
6335 llvm::raw_svector_ostream Stream(Buffer);
6336 CXXNameMangler(
Mangler.Context, Stream,
6337 WithTemplateDepthOffset{DepthOffset})
6338 .mangleTemplateParameterList(Params);
6341 MangleTemplateParamListToString(ParamTemplateHead,
6342 TTP->getTemplateParameters(), 0);
6346 MangleTemplateParamListToString(ArgTemplateHead,
6348 TTP->getTemplateParameters()->
getDepth());
6349 return ParamTemplateHead != ArgTemplateHead;
6359 return {
true,
nullptr};
6364 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6365 "no parameter for argument");
6386 return {
true,
nullptr};
6401 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6402 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6403 return {NeedExactType,
nullptr};
6415void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6417 unsigned NumTemplateArgs) {
6420 TemplateArgManglingInfo Info(*
this, TN);
6421 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6422 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6424 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6428void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6429 const TemplateArgumentList &AL) {
6432 TemplateArgManglingInfo Info(*
this, TN);
6433 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6434 mangleTemplateArg(Info, i, AL[i]);
6436 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6440void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6441 ArrayRef<TemplateArgument> Args) {
6444 TemplateArgManglingInfo Info(*
this, TN);
6445 for (
unsigned i = 0; i != Args.size(); ++i) {
6446 mangleTemplateArg(Info, i, Args[i]);
6448 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6452void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6453 unsigned Index, TemplateArgument A) {
6454 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6457 if (ArgInfo.TemplateParameterToMangle &&
6458 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6465 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6468 mangleTemplateArg(A, ArgInfo.NeedExactType);
6471void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6481 llvm_unreachable(
"Cannot mangle NULL template argument");
6509 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6510 TPO->getValue(),
true,
6515 ASTContext &Ctx = Context.getASTContext();
6523 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6531 ArrayRef<APValue::LValuePathEntry>(),
6544 true, NeedExactType);
6550 mangleTemplateArg(P, NeedExactType);
6556void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6557 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6558 mangleExpression(E, UnknownArity,
true);
6573 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6574 const ValueDecl *D = DRE->getDecl();
6583 mangleExpression(E);
6596 switch (
V.getKind()) {
6604 assert(RD &&
"unexpected type for record value");
6613 if (!FD->isUnnamedBitField() &&
6623 assert(RD &&
"unexpected type for union value");
6626 if (!FD->isUnnamedBitField())
6636 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6637 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6645 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6652 llvm_unreachable(
"Matrix APValues not yet supported");
6658 return V.getFloat().isPosZero();
6661 return !
V.getFixedPoint().getValue();
6664 return V.getComplexFloatReal().isPosZero() &&
6665 V.getComplexFloatImag().isPosZero();
6668 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6671 return V.isNullPointer();
6674 return !
V.getMemberPointerDecl();
6677 return !
V.getReflectionOpaqueOperand();
6680 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6687 T = AT->getElementType();
6689 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6732 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6733 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6738void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6740 bool NeedExactType) {
6743 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6746 bool IsPrimaryExpr =
true;
6747 auto NotPrimaryExpr = [&] {
6748 if (TopLevel && IsPrimaryExpr)
6750 IsPrimaryExpr =
false;
6754 switch (
V.getKind()) {
6763 llvm_unreachable(
"unexpected value kind in template argument");
6767 assert(RD &&
"unexpected type for record value");
6770 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6773 (Fields.back()->isUnnamedBitField() ||
6775 V.getStructField(Fields.back()->getFieldIndex())))) {
6779 if (Fields.empty()) {
6780 while (!Bases.empty() &&
6782 V.getStructBase(Bases.size() - 1)))
6783 Bases = Bases.drop_back();
6790 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6791 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6792 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6793 if (Fields[I]->isUnnamedBitField())
6795 mangleValueInTemplateArg(Fields[I]->
getType(),
6796 V.getStructField(Fields[I]->getFieldIndex()),
6805 const FieldDecl *FD =
V.getUnionField();
6823 mangleSourceName(II);
6824 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6838 unsigned N =
V.getArraySize();
6840 N =
V.getArrayInitializedElts();
6845 for (
unsigned I = 0; I != N; ++I) {
6846 const APValue &Elem = I <
V.getArrayInitializedElts()
6847 ?
V.getArrayInitializedElt(I)
6848 :
V.getArrayFiller();
6849 mangleValueInTemplateArg(ElemT, Elem,
false);
6856 const VectorType *VT =
T->
castAs<VectorType>();
6861 unsigned N =
V.getVectorLength();
6864 for (
unsigned I = 0; I != N; ++I)
6865 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6871 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6874 mangleIntegerLiteral(
T,
V.getInt());
6878 mangleFloatLiteral(
T,
V.getFloat());
6882 mangleFixedPointLiteral();
6886 const ComplexType *CT =
T->
castAs<ComplexType>();
6890 if (!
V.getComplexFloatReal().isPosZero() ||
6891 !
V.getComplexFloatImag().isPosZero())
6893 if (!
V.getComplexFloatImag().isPosZero())
6900 const ComplexType *CT =
T->
castAs<ComplexType>();
6904 if (
V.getComplexIntReal().getBoolValue() ||
6905 V.getComplexIntImag().getBoolValue())
6907 if (
V.getComplexIntImag().getBoolValue())
6916 "unexpected type for LValue template arg");
6918 if (
V.isNullPointer()) {
6919 mangleNullPointer(
T);
6923 APValue::LValueBase B =
V.getLValueBase();
6927 CharUnits Offset =
V.getLValueOffset();
6945 ASTContext &Ctx = Context.getASTContext();
6948 if (!
V.hasLValuePath()) {
6964 bool IsArrayToPointerDecayMangledAsDecl =
false;
6965 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6967 IsArrayToPointerDecayMangledAsDecl =
6968 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6969 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6973 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6974 !IsArrayToPointerDecayMangledAsDecl) {
6991 if (NeedExactType &&
6993 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7006 QualType TypeSoFar = B.
getType();
7007 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
7011 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
7013 mangleExpression(E);
7014 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
7017 mangleType(QualType(TI.getType(), 0));
7020 llvm_unreachable(
"unexpected lvalue base kind in template argument");
7030 mangleNumber(
V.getLValueOffset().getQuantity());
7037 if (!
V.getLValueOffset().isZero())
7038 mangleNumber(
V.getLValueOffset().getQuantity());
7042 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
7044 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
7046 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
7047 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
7048 TypeSoFar = AT->getElementType();
7050 const Decl *D = E.getAsBaseOrMember().getPointer();
7051 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
7075 mangleReflection(
V.getReflectionOperandKind(),
7076 V.getReflectionOpaqueOperand());
7082 if (!
V.getMemberPointerDecl()) {
7083 mangleNullPointer(
T);
7087 ASTContext &Ctx = Context.getASTContext();
7090 if (!
V.getMemberPointerPath().empty()) {
7093 }
else if (NeedExactType &&
7095 T->
castAs<MemberPointerType>()->getPointeeType(),
7096 V.getMemberPointerDecl()->getType()) &&
7097 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7102 mangle(
V.getMemberPointerDecl());
7104 if (!
V.getMemberPointerPath().empty()) {
7114 if (TopLevel && !IsPrimaryExpr)
7118void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7128 Depth += TemplateDepthOffset;
7130 Out <<
'L' << (Depth - 1) <<
'_';
7136void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7139 }
else if (SeqID == 1) {
7146 MutableArrayRef<char> BufferRef(Buffer);
7147 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7149 for (; SeqID != 0; SeqID /= 36) {
7150 unsigned C = SeqID % 36;
7151 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7154 Out.write(I.base(), I - BufferRef.rbegin());
7160 while (SubstTemplateTemplateParmStorage *subst =
7162 if (mangleSubstitution(subst->getReplacement()))
7164 if (isCompatibleWith(LangOptions::ClangABI::Ver23))
7166 tname = subst->getReplacement();
7173bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7175 if (mangleStandardSubstitution(ND))
7179 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7189bool CXXNameMangler::mangleSubstitution(QualType
T) {
7192 return mangleSubstitution(RD);
7197 return mangleSubstitution(TypePtr);
7201 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7202 return mangleSubstitution(TD);
7205 return mangleSubstitution(
7209bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7210 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7211 if (I == Substitutions.end())
7214 unsigned SeqID = I->second;
7223bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7232 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7233 if (!SD || !SD->getIdentifier()->isStr(Name))
7236 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7239 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7240 if (TemplateArgs.
size() != 1)
7243 if (TemplateArgs[0].getAsType() != A)
7246 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7255bool CXXNameMangler::isStdCharSpecialization(
7256 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7257 bool HasAllocator) {
7262 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7265 QualType A = TemplateArgs[0].getAsType();
7273 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7277 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7286bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7288 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7296 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7297 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7317 if (
const ClassTemplateSpecializationDecl *SD =
7318 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7319 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7328 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7335 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7342 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7349 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7359void CXXNameMangler::addSubstitution(QualType
T) {
7362 addSubstitution(RD);
7368 addSubstitution(TypePtr);
7372 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7373 return addSubstitution(TD);
7379void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7380 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7381 Substitutions[
Ptr] = SeqID++;
7384void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7385 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7386 if (
Other->SeqID > SeqID) {
7387 Substitutions.swap(
Other->Substitutions);
7388 SeqID =
Other->SeqID;
7392CXXNameMangler::AbiTagList
7393CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7395 if (DisableDerivedAbiTags)
7396 return AbiTagList();
7398 llvm::raw_null_ostream NullOutStream;
7399 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7400 TrackReturnTypeTags.disableDerivedAbiTags();
7402 const FunctionProtoType *Proto =
7404 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7405 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7407 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7408 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7410 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7413CXXNameMangler::AbiTagList
7414CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7416 if (DisableDerivedAbiTags)
7417 return AbiTagList();
7419 llvm::raw_null_ostream NullOutStream;
7420 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7421 TrackVariableType.disableDerivedAbiTags();
7423 TrackVariableType.mangleType(VD->
getType());
7425 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7428bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7429 const VarDecl *VD) {
7430 llvm::raw_null_ostream NullOutStream;
7431 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7432 TrackAbiTags.mangle(VD);
7433 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7438void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7442 "Invalid mangleName() call, argument is not a variable or function!");
7444 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7445 getASTContext().getSourceManager(),
7446 "Mangling declaration");
7448 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7450 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7451 return Mangler.mangle(GlobalDecl(CD,
Type));
7454 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7456 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7457 return Mangler.mangle(GlobalDecl(DD,
Type));
7460 CXXNameMangler Mangler(*
this, Out, D);
7464void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7466 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7470void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7472 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7494 auto &LangOpts = Context.getLangOpts();
7497 Context.baseForVTableAuthentication(ThisRD);
7498 unsigned TypedDiscriminator =
7499 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7501 Mangler.mangleVendorQualifier(
"__vtptrauth");
7502 auto &ManglerStream = Mangler.getStream();
7503 ManglerStream <<
"I";
7504 if (
const auto *ExplicitAuth =
7505 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7506 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7508 if (ExplicitAuth->getAddressDiscrimination() ==
7509 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7510 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7512 ManglerStream <<
"Lb"
7513 << (ExplicitAuth->getAddressDiscrimination() ==
7514 VTablePointerAuthenticationAttr::AddressDiscrimination);
7516 switch (ExplicitAuth->getExtraDiscrimination()) {
7517 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7518 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7519 ManglerStream <<
"Lj" << TypedDiscriminator;
7521 ManglerStream <<
"Lj" << 0;
7524 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7525 ManglerStream <<
"Lj" << TypedDiscriminator;
7527 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7528 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7530 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7531 ManglerStream <<
"Lj" << 0;
7535 ManglerStream <<
"Lj"
7536 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7537 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7538 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7539 ManglerStream <<
"Lj" << TypedDiscriminator;
7541 ManglerStream <<
"Lj" << 0;
7543 ManglerStream <<
"E";
7546void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7547 const ThunkInfo &Thunk,
7548 bool ElideOverrideInfo,
7558 "Use mangleCXXDtor for destructor decls!");
7559 CXXNameMangler Mangler(*
this, Out);
7560 Mangler.getStream() <<
"_ZT";
7562 Mangler.getStream() <<
'c';
7573 Mangler.mangleFunctionEncoding(MD);
7574 if (!ElideOverrideInfo)
7578void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7580 const ThunkInfo &Thunk,
7581 bool ElideOverrideInfo,
7585 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7586 Mangler.getStream() <<
"_ZT";
7588 auto &ThisAdjustment = Thunk.
This;
7590 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7591 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7593 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7594 if (!ElideOverrideInfo)
7599void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7603 CXXNameMangler Mangler(*
this, Out);
7606 Mangler.getStream() <<
"_ZGV";
7607 Mangler.mangleName(D);
7610void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7615 Out <<
"__cxx_global_var_init";
7618void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7621 CXXNameMangler Mangler(*
this, Out);
7622 Mangler.getStream() <<
"__dtor_";
7623 if (shouldMangleDeclName(D))
7626 Mangler.getStream() << D->
getName();
7629void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7633 CXXNameMangler Mangler(*
this, Out);
7634 Mangler.getStream() <<
"__finalize_";
7635 if (shouldMangleDeclName(D))
7638 Mangler.getStream() << D->
getName();
7641void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7642 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7643 CXXNameMangler Mangler(*
this, Out);
7644 Mangler.getStream() <<
"__filt_";
7646 if (shouldMangleDeclName(EnclosingFD))
7647 Mangler.mangle(EnclosingDecl);
7649 Mangler.getStream() << EnclosingFD->getName();
7652void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7653 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7654 CXXNameMangler Mangler(*
this, Out);
7655 Mangler.getStream() <<
"__fin_";
7657 if (shouldMangleDeclName(EnclosingFD))
7658 Mangler.mangle(EnclosingDecl);
7660 Mangler.getStream() << EnclosingFD->getName();
7663void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7666 CXXNameMangler Mangler(*
this, Out);
7667 Mangler.getStream() <<
"_ZTH";
7668 Mangler.mangleName(D);
7672ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7675 CXXNameMangler Mangler(*
this, Out);
7676 Mangler.getStream() <<
"_ZTW";
7677 Mangler.mangleName(D);
7680void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7681 unsigned ManglingNumber,
7685 CXXNameMangler Mangler(*
this, Out);
7686 Mangler.getStream() <<
"_ZGR";
7687 Mangler.mangleName(D);
7688 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7689 Mangler.mangleSeqID(ManglingNumber - 1);
7692void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7695 CXXNameMangler Mangler(*
this, Out);
7696 Mangler.getStream() <<
"_ZTV";
7697 Mangler.mangleCXXRecordDecl(RD);
7700void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7703 CXXNameMangler Mangler(*
this, Out);
7704 Mangler.getStream() <<
"_ZTT";
7705 Mangler.mangleCXXRecordDecl(RD);
7708void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7710 const CXXRecordDecl *
Type,
7713 CXXNameMangler Mangler(*
this, Out);
7714 Mangler.getStream() <<
"_ZTC";
7717 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7718 LangOptions::ClangABI::Ver19);
7719 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7720 Mangler.getStream() << Offset;
7721 Mangler.getStream() <<
'_';
7722 Mangler.mangleCXXRecordDecl(
Type);
7725void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7727 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7728 CXXNameMangler Mangler(*
this, Out);
7729 Mangler.getStream() <<
"_ZTI";
7730 Mangler.mangleType(Ty);
7733void ItaniumMangleContextImpl::mangleCXXRTTIName(
7734 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7736 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7737 Mangler.getStream() <<
"_ZTS";
7738 Mangler.mangleType(Ty);
7741void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7742 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7743 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7746void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7747 llvm_unreachable(
"Can't mangle string literals");
7750void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7752 CXXNameMangler Mangler(*
this, Out);
7753 Mangler.mangleLambdaSig(Lambda);
7756void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7759 CXXNameMangler Mangler(*
this, Out);
7760 Mangler.getStream() <<
"_ZGI";
7764 auto Partition = M->
Name.find(
':');
7765 Mangler.mangleModuleNamePrefix(
7766 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7774 return new ItaniumMangleContextImpl(
7777 return std::nullopt;
7786 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
static bool isUniqueInternalLinkageDecl(GlobalDecl GD, CodeGenModule &CGM)
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
static bool isTypeSubstitutable(Qualifiers Quals, const Type *Ty, ASTContext &Ctx)
static IdentifierInfo * getUnionInitName(SourceLocation UnionLoc, DiagnosticsEngine &Diags, const FieldDecl *FD)
static bool hasMangledSubstitutionQualifiers(QualType T)
Determine whether the given type has any qualifiers that are relevant for substitutions.
#define CC_VLS_CASE(ABI_VLEN)
static GlobalDecl getParentOfLocalEntity(const DeclContext *DC)
@ ArmAgnosticSMEZAStateBit
@ ArmStreamingCompatibleBit
static AAPCSBitmaskSME encodeAAPCSZAState(unsigned SMEAttrs)
static StringRef mangleAArch64VectorBase(const BuiltinType *EltType)
static const CXXRecordDecl * getLambdaForInitCapture(const VarDecl *VD)
Retrieve the lambda associated with an init-capture variable.
static void mangleOverrideDiscrimination(CXXNameMangler &Mangler, ASTContext &Context, const ThunkInfo &Thunk)
Mangles the pointer authentication override attribute for classes that have explicit overrides for th...
static bool isZeroInitialized(QualType T, const APValue &V)
Determine whether a given value is equivalent to zero-initialization for the purpose of discarding a ...
static const GlobalDecl isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs)
static bool isParenthesizedADLCallee(const CallExpr *call)
Look at the callee of the given call expression and determine if it's a parenthesized id-expression w...
static TemplateName asTemplateName(GlobalDecl GD)
static QualType getLValueType(ASTContext &Ctx, const APValue &LV)
llvm::MachO::Target Target
llvm::MachO::Record Record
Defines the clang::Module class, which describes a module in the source code.
static StringRef getTriple(const Command &Job)
static StringRef getIdentifier(const Token &Tok)
Enums/classes describing THUNK related information about constructors, destructors and thunks.
Defines the clang::TypeLoc interface and its subclasses.
static const TemplateArgument & getArgument(const TemplateArgument &A)
A non-discriminated union of a base, field, or array index.
static LValuePathEntry ArrayIndex(uint64_t Index)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
ArrayRef< LValuePathEntry > getLValuePath() const
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
@ None
There is no such object (it's outside its lifetime).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
TemplateName getCanonicalTemplateName(TemplateName Name, bool IgnoreDeduced=false) const
Retrieves the "canonical" template name that refers to a given template.
const LangOptions & getLangOpts() const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
QualType getSignatureParameterType(QualType T) const
Retrieve the parameter type as adjusted for use in the signature of a function, decaying array and fu...
bool addressSpaceMapManglingFor(LangAS AS) const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
ConstExprIterator const_arg_iterator
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
bool isGlobalDelete() const
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the member name.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e.
ConstExprIterator const_arg_iterator
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
base_class_iterator bases_end()
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
base_class_iterator bases_begin()
TypeSourceInfo * getLambdaTypeInfo() const
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
ReflectionKind getKind() const
const void * getOpaqueValue() const
const Expr * getSubExpr() const
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isListInitialization() const
Determine whether this expression models list-initialization.
Expr * getArg(unsigned I)
unsigned getNumArgs() const
Retrieve the number of arguments.
Expr * getExprOperand() const
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
bool isTypeOperand() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool isZero() const
Test whether the quantity equals zero.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
QualType getElementType() const
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isRequiresExprBody() const
bool isFileContext() const
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
bool isExpansionStmt() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
unsigned getNumTemplateArgs() const
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
TemplateArgumentLoc const * getTemplateArgs() const
IdentifierOrOverloadedOperator getName() const
Represents a vector type where either the type or size is dependent.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
llvm::APSInt getInitVal() const
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APFloat getValue() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
ArrayRef< QualType > exceptions() const
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
CallingConv getCC() const
bool getProducesResult() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC?
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
QualType getReturnType() const
GlobalDecl - represents a global declaration.
CXXCtorType getCtorType() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
CXXDtorType getDtorType() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
const Expr * getSubExpr() const
Describes an C or C++ initializer list.
unsigned getNumInits() const
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
ItaniumMangleContext(ASTContext &C, DiagnosticsEngine &D, bool IsAux=false)
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
UnsignedOrNone(*)(ASTContext &, const NamedDecl *) DiscriminatorOverrideTy
bool isCompatibleWith(ClangABI Version) const
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
std::string Name
The name of this module.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NestedNameSpecifier getQualifier() const
Fetches the nested-name qualifier, if one was given.
decls_iterator decls_begin() const
unsigned getNumDecls() const
Gets the number of declarations in the unresolved set.
TemplateArgumentLoc const * getTemplateArgs() const
unsigned getNumTemplateArgs() const
DeclarationName getName() const
Gets the name looked up.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
unsigned getFunctionScopeDepth() const
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool hasUnaligned() const
bool hasAddressSpace() const
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Encodes a location in the source.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
TemplateName getReplacement() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
virtual const char * getFloat128Mangling() const
Return the mangled code of __float128.
virtual const char * getIbm128Mangling() const
Return the mangled code of __ibm128.
virtual const char * getLongDoubleMangling() const
Return the mangled code of long double.
virtual const char * getBFloat16Mangling() const
Return the mangled code of bfloat.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
std::pair< TemplateName, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template name that this template name refers to, along with the deduced defa...
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ PackIndexingTemplate
A pack-index-template-name.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
unsigned getOrdinal() const
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateName getNamedConcept() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
TypeTrait getTrait() const
Determine which type trait this expression uses.
The base class of the type hierarchy.
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents a GCC generic vector type.
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
@ Number
Just a number, nothing else.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Top level wrappers for InstallAPI frontend operations.
const char * getTraitSpelling(TypeTrait T) LLVM_READONLY
Return the spelling of the trait T. Never null.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
bool isRVVFixedLengthDataVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length data vector kinds, i.e.
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName, bool useDirectABI)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
StringRef getRVVFixedLengthString(VectorKind VK)
Return the LMUL of an RVV fixed-length data vector kind, "mf8" .
bool isRVVFixedLengthVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length data or mask vector kinds.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ Concept
The name was classified as a concept name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ Deduced
The normal deduced case.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.
bool isTypeAliasAsReflectionName(QualType QT)
[expr.reflect] p5, if a reflect-expression R matches the form ^^reflection-name it is interpreted as ...
@ EST_Dynamic
throw(T1, T2)
bool isRVVFixedLengthMaskVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length mask vector kinds, i.e.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 int64_t
Information about how to mangle a template argument.
bool NeedExactType
Do we need to mangle the template argument with an exactly correct type?
const NamedDecl * TemplateParameterToMangle
If we need to prefix the mangling with a mangling of the template parameter, the corresponding parame...
bool isOverloadable()
Determine whether the resolved template might be overloaded on its template parameter list.
TemplateArgManglingInfo(const CXXNameMangler &Mangler, TemplateName TN)
bool needToMangleTemplateParam(const NamedDecl *Param, const TemplateArgument &Arg)
Determine whether we need to prefix this <template-arg> mangling with a <template-param-decl>.
const NamedDecl * UnresolvedExpandedPack
const CXXNameMangler & Mangler
TemplateDecl * ResolvedTemplate
Info getArgInfo(unsigned ParamIdx, const TemplateArgument &Arg)
Determine information about how this template argument should be mangled.
const Expr * getTrailingRequiresClauseToMangle()
Determine if we should mangle a requires-clause after the template argument list.
bool SeenPackExpansionIntoNonPack
ArrayRef< TemplateArgumentLoc > arguments() const
const Expr * ConstraintExpr
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
The this pointer adjustment as well as an optional return adjustment for a thunk.
ThisAdjustment This
The this pointer adjustment.
ReturnAdjustment Return
The return adjustment.
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.