35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#include "llvm/TargetParser/RISCVTargetParser.h"
42namespace UnsupportedItaniumManglingKind =
43 clang::diag::UnsupportedItaniumManglingKind;
47static bool isLocalContainerContext(
const DeclContext *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);
443 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
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 mangleTemplateParamDecl(
const NamedDecl *Decl);
520 void mangleTemplateParameterList(
const TemplateParameterList *Params);
521 void mangleTypeConstraint(
const TemplateDecl *
Concept,
522 ArrayRef<TemplateArgument> Arguments);
523 void mangleTypeConstraint(
const TypeConstraint *Constraint);
524 void mangleRequiresClause(
const Expr *RequiresClause);
525 void mangleLambda(
const CXXRecordDecl *Lambda);
526 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
527 ArrayRef<StringRef> AdditionalAbiTags = {},
528 bool NoFunction =
false);
529 void mangleNestedName(
const TemplateDecl *TD,
530 ArrayRef<TemplateArgument> Args);
531 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
532 const NamedDecl *PrefixND,
533 ArrayRef<StringRef> AdditionalAbiTags,
534 bool NoFunction =
false);
535 void manglePrefix(NestedNameSpecifier Qualifier);
536 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
537 void manglePrefix(QualType
type);
538 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
540 const NamedDecl *getClosurePrefix(
const Decl *ND);
541 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
542 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
543 StringRef Prefix =
"");
544 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
546 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
552#define ABSTRACT_TYPE(CLASS, PARENT)
553#define NON_CANONICAL_TYPE(CLASS, PARENT)
554#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
555#include "clang/AST/TypeNodes.inc"
557 void mangleType(
const TagType*);
559 static StringRef getCallingConvQualifierName(
CallingConv CC);
562 void mangleSMEAttrs(
unsigned SMEAttrs);
567 void mangleAArch64NeonVectorType(
const VectorType *
T);
569 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
571 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
575 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
576 void mangleFixedPointLiteral();
579 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
580 void mangleMemberExpr(
const Expr *base,
bool isArrow,
584 unsigned NumTemplateArgs,
unsigned knownArity);
585 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
586 void mangleInitListElements(
const InitListExpr *InitList);
589 void mangleReferenceToPack(
const NamedDecl *ND);
590 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
591 bool AsTemplateArg =
false);
595 struct TemplateArgManglingInfo;
598 unsigned NumTemplateArgs);
601 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
604 void mangleTemplateArgExpr(
const Expr *E);
606 bool NeedExactType =
false);
608 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
616 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
618 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
626 getASTContext(), getASTContext().getTranslationUnitDecl(),
627 false, SourceLocation(), SourceLocation(),
628 &getASTContext().Idents.get(
"std"),
651ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
658 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
660 if (ParmVarDecl *ContextParam =
661 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
662 return ContextParam->getDeclContext();
666 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
667 if (ParmVarDecl *ContextParam =
668 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
669 return ContextParam->getDeclContext();
677 if (D == getASTContext().getVaListTagDecl()) {
678 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
679 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
680 return getStdNamespace();
686 return getEffectiveDeclContext(
cast<Decl>(DC));
689 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
691 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
695 if (isLocalContainerContext(ParentDC))
699 return getASTContext().getTranslationUnitDecl();
702 if (
const auto *FD = !getASTContext().getLangOpts().isCompatibleWith(
703 LangOptions::ClangABI::Ver19)
705 : dyn_cast<FunctionDecl>(D)) {
707 return getASTContext().getTranslationUnitDecl();
710 if (FD->isMemberLikeConstrainedFriend() &&
711 !getASTContext().getLangOpts().isCompatibleWith(
712 LangOptions::ClangABI::Ver17))
719bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
722 getEffectiveDeclContext(ND)->isFileContext() &&
729bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
730 const NamedDecl *ND) {
731 if (!NeedsUniqueInternalLinkageNames || !ND)
734 const auto *FD = dyn_cast<FunctionDecl>(ND);
740 if (!FD->getType()->getAs<FunctionProtoType>())
743 if (isInternalLinkageDecl(ND))
749bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
750 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
753 if (FD->hasAttr<OverloadableAttr>())
769 if (FD->isMSVCRTEntryPoint())
783 if (!getASTContext().getLangOpts().
CPlusPlus)
786 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
797 const DeclContext *DC = getEffectiveDeclContext(D);
799 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
801 !VD->getOwningModuleForLinkage())
808void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
809 ArrayRef<StringRef> AdditionalAbiTags) {
810 assert(AbiTags &&
"require AbiTagState");
811 AbiTags->write(Out, ND,
812 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
813 : AdditionalAbiTags);
816void CXXNameMangler::mangleSourceNameWithAbiTags(
817 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
819 writeAbiTags(ND, AdditionalAbiTags);
822void CXXNameMangler::mangle(GlobalDecl GD) {
828 mangleFunctionEncoding(GD);
829 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
832 else if (
const IndirectFieldDecl *IFD =
833 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
834 mangleName(IFD->getAnonField());
836 llvm_unreachable(
"unexpected kind of global decl");
839void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
844 if (!Context.shouldMangleDeclName(FD)) {
849 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
850 if (ReturnTypeAbiTags.empty()) {
859 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
861 FunctionTypeDepth.pop(Saved);
862 mangleFunctionEncodingBareType(FD);
869 SmallString<256> FunctionEncodingBuf;
870 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
871 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
873 FunctionEncodingMangler.disableDerivedAbiTags();
875 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
876 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
877 FunctionTypeDepth.pop(Saved);
880 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
881 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
885 const AbiTagList &UsedAbiTags =
886 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
887 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
888 AdditionalAbiTags.erase(
889 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
890 UsedAbiTags.begin(), UsedAbiTags.end(),
891 AdditionalAbiTags.begin()),
892 AdditionalAbiTags.end());
895 Saved = FunctionTypeDepth.push();
896 mangleNameWithAbiTags(FD, AdditionalAbiTags);
897 FunctionTypeDepth.pop(Saved);
898 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
902 extendSubstitutions(&FunctionEncodingMangler);
905void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
906 if (FD->
hasAttr<EnableIfAttr>()) {
907 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
908 Out <<
"Ua9enable_ifI";
909 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
912 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
915 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
920 mangleExpression(EIA->getCond());
923 mangleTemplateArgExpr(EIA->getCond());
927 FunctionTypeDepth.pop(Saved);
932 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
933 if (
auto Inherited = CD->getInheritedConstructor())
934 FD = Inherited.getConstructor();
952 bool MangleReturnType =
false;
956 MangleReturnType =
true;
959 FD = PrimaryTemplate->getTemplatedDecl();
962 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
963 MangleReturnType, FD);
967bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
968 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
972 return II && II->
isStr(
"std");
977bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
984static const GlobalDecl
988 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
997 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
998 TemplateArgs = &Spec->getTemplateArgs();
999 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1004 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1005 TemplateArgs = &Spec->getTemplateArgs();
1006 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1017void CXXNameMangler::mangleName(GlobalDecl GD) {
1019 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1021 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1022 if (VariableTypeAbiTags.empty()) {
1024 mangleNameWithAbiTags(VD);
1029 llvm::raw_null_ostream NullOutStream;
1030 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1031 VariableNameMangler.disableDerivedAbiTags();
1032 VariableNameMangler.mangleNameWithAbiTags(VD);
1035 const AbiTagList &UsedAbiTags =
1036 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1037 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1038 AdditionalAbiTags.erase(
1039 std::set_difference(VariableTypeAbiTags.begin(),
1040 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1041 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1042 AdditionalAbiTags.end());
1045 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1047 mangleNameWithAbiTags(GD);
1051const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1052 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1054 if (isLocalContainerContext(DC))
1055 return dyn_cast<RecordDecl>(D);
1057 DC = Context.getEffectiveDeclContext(D);
1062void CXXNameMangler::mangleNameWithAbiTags(
1063 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1070 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1072 if (GetLocalClassDecl(ND) &&
1073 (!isLambda(ND) || isCompatibleWith(LangOptions::ClangABI::Ver18) ||
1074 !isCompatibleWith(LangOptions::ClangABI::Ver22))) {
1075 mangleLocalName(GD, AdditionalAbiTags);
1083 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1084 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1088 if (isLocalContainerContext(DC)) {
1089 mangleLocalName(GD, AdditionalAbiTags);
1098 const TemplateArgumentList *TemplateArgs =
nullptr;
1099 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1100 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1105 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1109 mangleNestedName(GD, DC, AdditionalAbiTags);
1112void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1115 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1123void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1125 if (
auto It = ModuleSubstitutions.find(Name);
1126 It != ModuleSubstitutions.end()) {
1128 mangleSeqID(It->second);
1134 auto [Prefix, SubName] = Name.rsplit(
'.');
1135 if (SubName.empty())
1138 mangleModuleNamePrefix(Prefix, IsPartition);
1139 IsPartition =
false;
1145 Out << SubName.size() << SubName;
1146 ModuleSubstitutions.insert({Name, SeqID++});
1149void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1150 ArrayRef<TemplateArgument> Args) {
1151 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1154 mangleUnscopedTemplateName(TD, DC);
1157 mangleNestedName(TD, Args);
1161void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1162 ArrayRef<StringRef> AdditionalAbiTags) {
1167 if (isStdNamespace(DC)) {
1168 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1170 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1175 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1177 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1187 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1190void CXXNameMangler::mangleUnscopedTemplateName(
1191 GlobalDecl GD,
const DeclContext *DC,
1192 ArrayRef<StringRef> AdditionalAbiTags) {
1196 if (mangleSubstitution(ND))
1200 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1201 assert(AdditionalAbiTags.empty() &&
1202 "template template param cannot have abi tags");
1203 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1205 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1211 addSubstitution(ND);
1214void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1228 llvm::APInt valueBits = f.bitcastToAPInt();
1229 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1230 assert(numCharacters != 0);
1233 SmallVector<char, 20> buffer(numCharacters);
1236 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1238 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1241 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1242 hexDigit >>= (digitBitIndex % 64);
1246 static const char charForHex[16] = {
1247 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1248 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1250 buffer[stringIndex] = charForHex[hexDigit];
1253 Out.write(buffer.data(), numCharacters);
1256void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1263void CXXNameMangler::mangleFixedPointLiteral() {
1264 DiagnosticsEngine &Diags = Context.getDiags();
1265 Diags.
Report(diag::err_unsupported_itanium_mangling)
1266 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1269void CXXNameMangler::mangleNullPointer(QualType
T) {
1276void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1277 if (
Value.isSigned() &&
Value.isNegative()) {
1279 Value.abs().print(Out,
false);
1281 Value.print(Out,
false);
1285void CXXNameMangler::mangleNumber(int64_t Number) {
1295void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1303 mangleNumber(NonVirtual);
1309 mangleNumber(NonVirtual);
1315void CXXNameMangler::manglePrefix(QualType
type) {
1316 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1317 if (!mangleSubstitution(QualType(TST, 0))) {
1318 mangleTemplatePrefix(TST->getTemplateName());
1323 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1324 addSubstitution(QualType(TST, 0));
1326 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1328 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1329 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1334 assert(DNT->getQualifier());
1335 manglePrefix(DNT->getQualifier());
1337 mangleSourceName(DNT->getIdentifier());
1340 addSubstitution(QualType(DNT, 0));
1352void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1370 case NestedNameSpecifier::Kind::Null:
1371 llvm_unreachable(
"unexpected null nested name specifier");
1373 case NestedNameSpecifier::Kind::Global:
1383 case NestedNameSpecifier::Kind::MicrosoftSuper:
1384 llvm_unreachable(
"Can't mangle __super specifier");
1386 case NestedNameSpecifier::Kind::Namespace: {
1389 mangleUnresolvedPrefix(Prefix,
1393 mangleSourceNameWithAbiTags(Namespace);
1397 case NestedNameSpecifier::Kind::Type: {
1405 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1406 mangleUnresolvedPrefix(Prefix,
1413 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1428void CXXNameMangler::mangleUnresolvedName(
1429 NestedNameSpecifier Qualifier, DeclarationName name,
1430 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1431 unsigned knownArity) {
1433 mangleUnresolvedPrefix(Qualifier);
1434 switch (
name.getNameKind()) {
1437 mangleSourceName(
name.getAsIdentifierInfo());
1442 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1449 mangleOperatorName(name, knownArity);
1452 llvm_unreachable(
"Can't mangle a constructor name!");
1454 llvm_unreachable(
"Can't mangle a using directive name!");
1456 llvm_unreachable(
"Can't mangle a deduction guide name!");
1460 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1466 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1469void CXXNameMangler::mangleUnqualifiedName(
1470 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1471 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1472 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1479 mangleModuleName(ND);
1483 auto *FD = dyn_cast<FunctionDecl>(ND);
1484 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1486 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1487 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1491 unsigned Arity = KnownArity;
1497 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1504 for (
auto *BD : DD->bindings())
1505 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1507 writeAbiTags(ND, AdditionalAbiTags);
1511 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1514 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1515 llvm::raw_svector_ostream GUIDOS(GUID);
1516 Context.mangleMSGuidDecl(GD, GUIDOS);
1517 Out << GUID.size() << GUID;
1521 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1524 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1525 TPO->getValue(),
true);
1543 if (Context.isInternalLinkageDecl(ND))
1546 bool IsRegCall = FD &&
1550 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1552 bool IsOCLDeviceStub =
1554 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1557 mangleDeviceStubName(II);
1558 else if (IsOCLDeviceStub)
1559 mangleOCLDeviceStubName(II);
1561 mangleRegCallName(II);
1563 mangleSourceName(II);
1565 writeAbiTags(ND, AdditionalAbiTags);
1570 assert(ND &&
"mangling empty name without declaration");
1572 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1575 Out <<
"12_GLOBAL__N_1";
1580 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1582 const auto *RD = VD->getType()->castAsRecordDecl();
1593 assert(RD->isAnonymousStructOrUnion()
1594 &&
"Expected anonymous struct or union!");
1595 const FieldDecl *FD = RD->findFirstNamedDataMember();
1601 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1621 "Typedef should not be in another decl context!");
1622 assert(D->getDeclName().getAsIdentifierInfo() &&
1623 "Typedef was not named!");
1624 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1625 assert(AdditionalAbiTags.empty() &&
1626 "Type cannot have additional abi tags");
1638 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1640 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1646 if (
Record->isLambda() &&
1647 ((DeviceNumber && *DeviceNumber > 0) ||
1648 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1649 assert(AdditionalAbiTags.empty() &&
1650 "Lambda type cannot have additional abi tags");
1657 unsigned UnnamedMangle =
1658 getASTContext().getManglingNumber(TD, Context.isAux());
1660 if (UnnamedMangle > 1)
1661 Out << UnnamedMangle - 2;
1663 writeAbiTags(TD, AdditionalAbiTags);
1669 unsigned AnonStructId =
1671 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1678 Str += llvm::utostr(AnonStructId);
1688 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1699 if (ND && Arity == UnknownArity) {
1703 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1704 if (MD->isImplicitObjectMemberFunction())
1710 mangleOperatorName(Name, Arity);
1711 writeAbiTags(ND, AdditionalAbiTags);
1715 llvm_unreachable(
"Can't mangle a deduction guide name!");
1718 llvm_unreachable(
"Can't mangle a using directive name!");
1722void CXXNameMangler::mangleConstructorName(
1723 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1724 const CXXRecordDecl *InheritedFrom =
nullptr;
1726 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1728 InheritedFrom = Inherited.getConstructor()->
getParent();
1729 InheritedTemplateName =
1730 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1731 InheritedTemplateArgs =
1732 Inherited.getConstructor()->getTemplateSpecializationArgs();
1735 if (CCD == Structor)
1738 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1746 if (InheritedTemplateArgs)
1747 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1749 writeAbiTags(CCD, AdditionalAbiTags);
1752void CXXNameMangler::mangleDestructorName(
1753 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1754 if (CDD == Structor)
1757 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1763 writeAbiTags(CDD, AdditionalAbiTags);
1766void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1770 if (getASTContext().getLangOpts().RegCall4)
1771 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1774 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1778void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1782 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1786void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1790 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1791 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1792 << OCLDeviceStubNamePrefix << II->
getName();
1795void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1802void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1803 ArrayRef<StringRef> AdditionalAbiTags,
1812 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1813 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1816 if (
Method->isExplicitObjectMemberFunction())
1819 mangleQualifiers(MethodQuals);
1820 mangleRefQualifier(
Method->getRefQualifier());
1824 const TemplateArgumentList *TemplateArgs =
nullptr;
1825 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1826 mangleTemplatePrefix(TD, NoFunction);
1829 manglePrefix(DC, NoFunction);
1830 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1835void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1836 ArrayRef<TemplateArgument> Args) {
1841 mangleTemplatePrefix(TD);
1847void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1848 GlobalDecl GD,
const NamedDecl *PrefixND,
1849 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1858 mangleClosurePrefix(PrefixND, NoFunction);
1859 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1870 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1872 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1881void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1882 ArrayRef<StringRef> AdditionalAbiTags) {
1890 const RecordDecl *RD = GetLocalClassDecl(D);
1891 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1896 AbiTagState LocalAbiTags(AbiTags);
1898 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1900 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1901 mangleBlockForPrefix(BD);
1908 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1922 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1924 if (
const ParmVarDecl *Parm
1926 if (
const FunctionDecl *
Func
1931 mangleNumber(
Num - 2);
1940 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1941 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1942 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1943 mangleClosurePrefix(PrefixND,
true );
1945 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1946 assert(AdditionalAbiTags.empty() &&
1947 "Block cannot have additional abi tags");
1948 mangleUnqualifiedBlock(BD);
1951 const NamedDecl *PrefixND = getClosurePrefix(ND);
1952 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
1953 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
1956 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1957 AdditionalAbiTags,
true);
1959 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1962 if (
const ParmVarDecl *Parm
1963 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1964 if (
const FunctionDecl *
Func
1969 mangleNumber(
Num - 2);
1974 assert(AdditionalAbiTags.empty() &&
1975 "Block cannot have additional abi tags");
1976 mangleUnqualifiedBlock(BD);
1978 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1981 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1983 if (Context.getNextDiscriminator(ND, disc)) {
1987 Out <<
"__" << disc <<
'_';
1992void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1993 if (GetLocalClassDecl(
Block)) {
1994 mangleLocalName(
Block);
1997 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
1998 if (isLocalContainerContext(DC)) {
1999 mangleLocalName(
Block);
2002 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2003 mangleClosurePrefix(PrefixND);
2006 mangleUnqualifiedBlock(
Block);
2009void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2012 if (Decl *Context =
Block->getBlockManglingContextDecl();
2013 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2015 Context->getDeclContext()->isRecord()) {
2018 mangleSourceNameWithAbiTags(ND);
2024 unsigned Number =
Block->getBlockManglingNumber();
2046void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2048 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2049 if (Ty->isParameterPack())
2051 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2052 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2055 mangleTypeConstraint(Constraint);
2059 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2060 if (Tn->isExpandedParameterPack()) {
2061 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2063 mangleType(Tn->getExpansionType(I));
2066 QualType
T = Tn->getType();
2067 if (Tn->isParameterPack()) {
2069 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2070 T = PackExpansion->getPattern();
2075 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2076 if (Tt->isExpandedParameterPack()) {
2077 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2079 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2081 if (Tt->isParameterPack())
2083 mangleTemplateParameterList(Tt->getTemplateParameters());
2088void CXXNameMangler::mangleTemplateParameterList(
2089 const TemplateParameterList *Params) {
2091 for (
auto *Param : *Params)
2092 mangleTemplateParamDecl(Param);
2093 mangleRequiresClause(Params->getRequiresClause());
2097void CXXNameMangler::mangleTypeConstraint(
2098 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2099 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2101 mangleTemplateName(
Concept, Arguments);
2103 mangleUnscopedName(
Concept, DC);
2105 mangleNestedName(
Concept, DC);
2108void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2109 llvm::SmallVector<TemplateArgument, 8> Args;
2111 for (
const TemplateArgumentLoc &ArgLoc :
2113 Args.push_back(ArgLoc.getArgument());
2118void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2120 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2122 mangleExpression(RequiresClause);
2126void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2130 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2133 if (
const IdentifierInfo *Name =
2135 mangleSourceName(Name);
2136 const TemplateArgumentList *TemplateArgs =
nullptr;
2144 mangleLambdaSig(Lambda);
2159 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2163 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2165 mangleNumber(Number - 2);
2169void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2172 mangleTemplateParamDecl(D);
2176 mangleRequiresClause(TPL->getRequiresClause());
2180 mangleBareFunctionType(Proto,
false,
2184void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2186 case NestedNameSpecifier::Kind::Null:
2187 case NestedNameSpecifier::Kind::Global:
2191 case NestedNameSpecifier::Kind::MicrosoftSuper:
2192 llvm_unreachable(
"Can't mangle __super specifier");
2194 case NestedNameSpecifier::Kind::Namespace:
2195 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2198 case NestedNameSpecifier::Kind::Type:
2199 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2203 llvm_unreachable(
"unexpected nested name specifier");
2206void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2219 if (NoFunction && isLocalContainerContext(DC))
2226 if (mangleSubstitution(ND))
2232 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2233 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2234 mangleTemplatePrefix(TD);
2236 *FD->getTemplateSpecializationArgs());
2238 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2241 addSubstitution(ND);
2246 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2248 addSubstitution(ND);
2253 const TemplateArgumentList *TemplateArgs =
nullptr;
2254 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2255 mangleTemplatePrefix(TD);
2257 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2258 mangleClosurePrefix(PrefixND, NoFunction);
2259 mangleUnqualifiedName(ND,
nullptr);
2261 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2262 manglePrefix(DC, NoFunction);
2263 mangleUnqualifiedName(ND, DC);
2266 addSubstitution(ND);
2273 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2274 return mangleTemplatePrefix(TD);
2277 assert(
Dependent &&
"unexpected template name kind");
2281 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2282 if (!Clang11Compat && mangleSubstitution(
Template))
2285 manglePrefix(
Dependent->getQualifier());
2287 if (Clang11Compat && mangleSubstitution(
Template))
2290 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2291 const IdentifierInfo *Id = Name.getIdentifier())
2292 mangleSourceName(Id);
2294 mangleOperatorName(Name.getOperator(), UnknownArity);
2299void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2308 if (mangleSubstitution(ND))
2312 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2313 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2315 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2316 manglePrefix(DC, NoFunction);
2318 mangleUnqualifiedName(GD, DC);
2323 addSubstitution(ND);
2326const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2327 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2330 const NamedDecl *Context =
nullptr;
2331 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2332 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2333 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2336 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2338 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2352void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2355 if (mangleSubstitution(ND))
2358 const TemplateArgumentList *TemplateArgs =
nullptr;
2359 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2360 mangleTemplatePrefix(TD, NoFunction);
2363 const auto *DC = Context.getEffectiveDeclContext(ND);
2364 manglePrefix(DC, NoFunction);
2365 mangleUnqualifiedName(ND, DC);
2370 addSubstitution(ND);
2379 if (mangleSubstitution(TN))
2382 TemplateDecl *TD =
nullptr;
2392 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2393 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2400 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2409 mangleUnresolvedPrefix(
Dependent->getQualifier());
2410 mangleSourceName(II);
2419 SubstTemplateTemplateParmStorage *subst
2430 Out <<
"_SUBSTPACK_";
2434 llvm_unreachable(
"Unexpected DeducedTemplate");
2437 addSubstitution(TN);
2440bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2446 case Type::Adjusted:
2448 case Type::ArrayParameter:
2450 case Type::BlockPointer:
2451 case Type::LValueReference:
2452 case Type::RValueReference:
2453 case Type::MemberPointer:
2454 case Type::ConstantArray:
2455 case Type::IncompleteArray:
2456 case Type::VariableArray:
2457 case Type::DependentSizedArray:
2458 case Type::DependentAddressSpace:
2459 case Type::DependentVector:
2460 case Type::DependentSizedExtVector:
2462 case Type::ExtVector:
2463 case Type::ConstantMatrix:
2464 case Type::DependentSizedMatrix:
2465 case Type::FunctionProto:
2466 case Type::FunctionNoProto:
2468 case Type::Attributed:
2469 case Type::BTFTagAttributed:
2470 case Type::OverflowBehavior:
2471 case Type::HLSLAttributedResource:
2472 case Type::HLSLInlineSpirv:
2474 case Type::DeducedTemplateSpecialization:
2475 case Type::PackExpansion:
2476 case Type::ObjCObject:
2477 case Type::ObjCInterface:
2478 case Type::ObjCObjectPointer:
2479 case Type::ObjCTypeParam:
2482 case Type::MacroQualified:
2484 case Type::DependentBitInt:
2485 case Type::CountAttributed:
2486 case Type::LateParsedAttr:
2487 llvm_unreachable(
"type is illegal as a nested name specifier");
2489 case Type::SubstBuiltinTemplatePack:
2494 Out <<
"_SUBSTBUILTINPACK_";
2496 case Type::SubstTemplateTypeParmPack:
2501 Out <<
"_SUBSTPACK_";
2508 case Type::TypeOfExpr:
2510 case Type::Decltype:
2511 case Type::PackIndexing:
2512 case Type::TemplateTypeParm:
2513 case Type::UnaryTransform:
2526 case Type::SubstTemplateTypeParm: {
2530 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2532 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2533 goto unresolvedType;
2540 case Type::PredefinedSugar:
2544 case Type::UnresolvedUsing:
2545 mangleSourceNameWithAbiTags(
2551 mangleSourceNameWithAbiTags(
2555 case Type::TemplateSpecialization: {
2556 const TemplateSpecializationType *TST =
2566 assert(TD &&
"no template for template specialization type");
2568 goto unresolvedType;
2570 mangleSourceNameWithAbiTags(TD);
2582 llvm_unreachable(
"invalid base for a template specialization type");
2585 SubstTemplateTemplateParmStorage *subst =
2596 Out <<
"_SUBSTPACK_";
2602 mangleSourceNameWithAbiTags(TD);
2612 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2616 case Type::InjectedClassName:
2617 mangleSourceNameWithAbiTags(
2621 case Type::DependentName:
2633void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2643 llvm_unreachable(
"Not an operator name");
2666 case OO_New:
Out <<
"nw";
break;
2668 case OO_Array_New:
Out <<
"na";
break;
2670 case OO_Delete:
Out <<
"dl";
break;
2672 case OO_Array_Delete:
Out <<
"da";
break;
2676 Out << (Arity == 1?
"ps" :
"pl");
break;
2680 Out << (Arity == 1?
"ng" :
"mi");
break;
2684 Out << (Arity == 1?
"ad" :
"an");
break;
2689 Out << (Arity == 1?
"de" :
"ml");
break;
2691 case OO_Tilde:
Out <<
"co";
break;
2693 case OO_Slash:
Out <<
"dv";
break;
2695 case OO_Percent:
Out <<
"rm";
break;
2697 case OO_Pipe:
Out <<
"or";
break;
2699 case OO_Caret:
Out <<
"eo";
break;
2701 case OO_Equal:
Out <<
"aS";
break;
2703 case OO_PlusEqual:
Out <<
"pL";
break;
2705 case OO_MinusEqual:
Out <<
"mI";
break;
2707 case OO_StarEqual:
Out <<
"mL";
break;
2709 case OO_SlashEqual:
Out <<
"dV";
break;
2711 case OO_PercentEqual:
Out <<
"rM";
break;
2713 case OO_AmpEqual:
Out <<
"aN";
break;
2715 case OO_PipeEqual:
Out <<
"oR";
break;
2717 case OO_CaretEqual:
Out <<
"eO";
break;
2719 case OO_LessLess:
Out <<
"ls";
break;
2721 case OO_GreaterGreater:
Out <<
"rs";
break;
2723 case OO_LessLessEqual:
Out <<
"lS";
break;
2725 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2727 case OO_EqualEqual:
Out <<
"eq";
break;
2729 case OO_ExclaimEqual:
Out <<
"ne";
break;
2731 case OO_Less:
Out <<
"lt";
break;
2733 case OO_Greater:
Out <<
"gt";
break;
2735 case OO_LessEqual:
Out <<
"le";
break;
2737 case OO_GreaterEqual:
Out <<
"ge";
break;
2739 case OO_Exclaim:
Out <<
"nt";
break;
2741 case OO_AmpAmp:
Out <<
"aa";
break;
2743 case OO_PipePipe:
Out <<
"oo";
break;
2745 case OO_PlusPlus:
Out <<
"pp";
break;
2747 case OO_MinusMinus:
Out <<
"mm";
break;
2749 case OO_Comma:
Out <<
"cm";
break;
2751 case OO_ArrowStar:
Out <<
"pm";
break;
2753 case OO_Arrow:
Out <<
"pt";
break;
2755 case OO_Call:
Out <<
"cl";
break;
2757 case OO_Subscript:
Out <<
"ix";
break;
2762 case OO_Conditional:
Out <<
"qu";
break;
2765 case OO_Coawait:
Out <<
"aw";
break;
2768 case OO_Spaceship:
Out <<
"ss";
break;
2772 llvm_unreachable(
"Not an overloaded operator");
2776void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2795 SmallString<64> ASString;
2801 if (TargetAS != 0 ||
2803 ASString =
"AS" + llvm::utostr(TargetAS);
2806 default: llvm_unreachable(
"Not a language specific address space");
2810 case LangAS::opencl_global:
2811 ASString =
"CLglobal";
2813 case LangAS::opencl_global_device:
2814 ASString =
"CLdevice";
2816 case LangAS::opencl_global_host:
2817 ASString =
"CLhost";
2819 case LangAS::opencl_local:
2820 ASString =
"CLlocal";
2822 case LangAS::opencl_constant:
2823 ASString =
"CLconstant";
2825 case LangAS::opencl_private:
2826 ASString =
"CLprivate";
2828 case LangAS::opencl_generic:
2829 ASString =
"CLgeneric";
2833 case LangAS::sycl_global:
2834 ASString =
"SYglobal";
2836 case LangAS::sycl_global_device:
2837 ASString =
"SYdevice";
2839 case LangAS::sycl_global_host:
2840 ASString =
"SYhost";
2842 case LangAS::sycl_local:
2843 ASString =
"SYlocal";
2845 case LangAS::sycl_private:
2846 ASString =
"SYprivate";
2849 case LangAS::cuda_device:
2850 ASString =
"CUdevice";
2852 case LangAS::cuda_constant:
2853 ASString =
"CUconstant";
2855 case LangAS::cuda_shared:
2856 ASString =
"CUshared";
2859 case LangAS::ptr32_sptr:
2860 ASString =
"ptr32_sptr";
2862 case LangAS::ptr32_uptr:
2866 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2867 ASString =
"ptr32_uptr";
2874 if (!ASString.empty())
2875 mangleVendorQualifier(ASString);
2888 mangleVendorQualifier(
"__weak");
2892 mangleVendorQualifier(
"__unaligned");
2896 mangleVendorQualifier(
"__ptrauth");
2906 << unsigned(PtrAuth.isAddressDiscriminated())
2909 << PtrAuth.getExtraDiscriminator()
2924 mangleVendorQualifier(
"__strong");
2928 mangleVendorQualifier(
"__autoreleasing");
2951void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2955void CXXNameMangler::mangleVendorType(StringRef name) {
2962 switch (RefQualifier) {
2976void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2977 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3002 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3003 if (DeducedTST->getDeducedType().isNull())
3008void CXXNameMangler::mangleType(QualType
T) {
3042 T =
T.getCanonicalType();
3048 if (
const TemplateSpecializationType *TST
3049 = dyn_cast<TemplateSpecializationType>(
T))
3050 if (!TST->isTypeAlias())
3058 =
T.getSingleStepDesugaredType(Context.getASTContext());
3065 auto [ty, quals] =
T.split();
3067 bool isSubstitutable =
3069 if (isSubstitutable && mangleSubstitution(
T))
3076 quals = Qualifiers();
3082 if (quals || ty->isDependentAddressSpaceType()) {
3083 if (
const DependentAddressSpaceType *DAST =
3084 dyn_cast<DependentAddressSpaceType>(ty)) {
3086 mangleQualifiers(Quals, DAST);
3087 mangleType(QualType(Ty, 0));
3089 mangleQualifiers(quals);
3093 mangleType(QualType(ty, 0));
3096 switch (ty->getTypeClass()) {
3097#define ABSTRACT_TYPE(CLASS, PARENT)
3098#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3100 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3102#define TYPE(CLASS, PARENT) \
3104 mangleType(static_cast<const CLASS##Type*>(ty)); \
3106#include "clang/AST/TypeNodes.inc"
3111 if (isSubstitutable)
3115void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3116 bool SuppressSubstitution) {
3117 if (mangleSubstitution(
Record))
3120 if (SuppressSubstitution)
3125void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3167 std::string type_name;
3171 if (NormalizeIntegers &&
T->isInteger()) {
3172 if (
T->isSignedInteger()) {
3173 switch (getASTContext().getTypeSize(
T)) {
3177 if (mangleSubstitution(BuiltinType::SChar))
3180 addSubstitution(BuiltinType::SChar);
3183 if (mangleSubstitution(BuiltinType::Short))
3186 addSubstitution(BuiltinType::Short);
3189 if (mangleSubstitution(BuiltinType::Int))
3192 addSubstitution(BuiltinType::Int);
3195 if (mangleSubstitution(BuiltinType::Long))
3198 addSubstitution(BuiltinType::Long);
3201 if (mangleSubstitution(BuiltinType::Int128))
3204 addSubstitution(BuiltinType::Int128);
3207 llvm_unreachable(
"Unknown integer size for normalization");
3210 switch (getASTContext().getTypeSize(
T)) {
3212 if (mangleSubstitution(BuiltinType::UChar))
3215 addSubstitution(BuiltinType::UChar);
3218 if (mangleSubstitution(BuiltinType::UShort))
3221 addSubstitution(BuiltinType::UShort);
3224 if (mangleSubstitution(BuiltinType::UInt))
3227 addSubstitution(BuiltinType::UInt);
3230 if (mangleSubstitution(BuiltinType::ULong))
3233 addSubstitution(BuiltinType::ULong);
3236 if (mangleSubstitution(BuiltinType::UInt128))
3239 addSubstitution(BuiltinType::UInt128);
3242 llvm_unreachable(
"Unknown integer size for normalization");
3247 switch (
T->getKind()) {
3248 case BuiltinType::Void:
3251 case BuiltinType::Bool:
3254 case BuiltinType::Char_U:
3255 case BuiltinType::Char_S:
3258 case BuiltinType::UChar:
3261 case BuiltinType::UShort:
3264 case BuiltinType::UInt:
3267 case BuiltinType::ULong:
3270 case BuiltinType::ULongLong:
3273 case BuiltinType::UInt128:
3276 case BuiltinType::SChar:
3279 case BuiltinType::WChar_S:
3280 case BuiltinType::WChar_U:
3283 case BuiltinType::Char8:
3286 case BuiltinType::Char16:
3289 case BuiltinType::Char32:
3292 case BuiltinType::Short:
3295 case BuiltinType::Int:
3298 case BuiltinType::Long:
3301 case BuiltinType::LongLong:
3304 case BuiltinType::Int128:
3307 case BuiltinType::Float16:
3310 case BuiltinType::ShortAccum:
3313 case BuiltinType::Accum:
3316 case BuiltinType::LongAccum:
3319 case BuiltinType::UShortAccum:
3322 case BuiltinType::UAccum:
3325 case BuiltinType::ULongAccum:
3328 case BuiltinType::ShortFract:
3331 case BuiltinType::Fract:
3334 case BuiltinType::LongFract:
3337 case BuiltinType::UShortFract:
3340 case BuiltinType::UFract:
3343 case BuiltinType::ULongFract:
3346 case BuiltinType::SatShortAccum:
3349 case BuiltinType::SatAccum:
3352 case BuiltinType::SatLongAccum:
3355 case BuiltinType::SatUShortAccum:
3358 case BuiltinType::SatUAccum:
3361 case BuiltinType::SatULongAccum:
3364 case BuiltinType::SatShortFract:
3367 case BuiltinType::SatFract:
3370 case BuiltinType::SatLongFract:
3373 case BuiltinType::SatUShortFract:
3376 case BuiltinType::SatUFract:
3379 case BuiltinType::SatULongFract:
3382 case BuiltinType::Half:
3385 case BuiltinType::Float:
3388 case BuiltinType::Double:
3391 case BuiltinType::LongDouble: {
3392 const TargetInfo *TI =
3393 getASTContext().getLangOpts().OpenMP &&
3394 getASTContext().getLangOpts().OpenMPIsTargetDevice
3395 ? getASTContext().getAuxTargetInfo()
3396 : &getASTContext().getTargetInfo();
3400 case BuiltinType::Float128: {
3401 const TargetInfo *TI =
3402 getASTContext().getLangOpts().OpenMP &&
3403 getASTContext().getLangOpts().OpenMPIsTargetDevice
3404 ? getASTContext().getAuxTargetInfo()
3405 : &getASTContext().getTargetInfo();
3409 case BuiltinType::BFloat16: {
3410 const TargetInfo *TI =
3411 ((getASTContext().getLangOpts().OpenMP &&
3412 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3413 getASTContext().getLangOpts().SYCLIsDevice)
3414 ? getASTContext().getAuxTargetInfo()
3415 : &getASTContext().getTargetInfo();
3419 case BuiltinType::Ibm128: {
3420 const TargetInfo *TI = &getASTContext().getTargetInfo();
3424 case BuiltinType::NullPtr:
3428#define BUILTIN_TYPE(Id, SingletonId)
3429#define PLACEHOLDER_TYPE(Id, SingletonId) \
3430 case BuiltinType::Id:
3431#include "clang/AST/BuiltinTypes.def"
3432 case BuiltinType::Dependent:
3434 llvm_unreachable(
"mangling a placeholder type");
3436 case BuiltinType::ObjCId:
3437 Out <<
"11objc_object";
3439 case BuiltinType::ObjCClass:
3440 Out <<
"10objc_class";
3442 case BuiltinType::ObjCSel:
3443 Out <<
"13objc_selector";
3445#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3446 case BuiltinType::Id: \
3447 type_name = "ocl_" #ImgType "_" #Suffix; \
3448 Out << type_name.size() << type_name; \
3450#include "clang/Basic/OpenCLImageTypes.def"
3451 case BuiltinType::OCLSampler:
3452 Out <<
"11ocl_sampler";
3454 case BuiltinType::OCLEvent:
3455 Out <<
"9ocl_event";
3457 case BuiltinType::OCLClkEvent:
3458 Out <<
"12ocl_clkevent";
3460 case BuiltinType::OCLQueue:
3461 Out <<
"9ocl_queue";
3463 case BuiltinType::OCLReserveID:
3464 Out <<
"13ocl_reserveid";
3466#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3467 case BuiltinType::Id: \
3468 type_name = "ocl_" #ExtType; \
3469 Out << type_name.size() << type_name; \
3471#include "clang/Basic/OpenCLExtensionTypes.def"
3475#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3476 case BuiltinType::Id: \
3477 if (T->getKind() == BuiltinType::SveBFloat16 && \
3478 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3480 mangleVendorType("__SVBFloat16_t"); \
3482 type_name = #MangledName; \
3483 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3486#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3487 case BuiltinType::Id: \
3488 type_name = #MangledName; \
3489 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3491#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3492 case BuiltinType::Id: \
3493 type_name = #MangledName; \
3494 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3496#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3497 case BuiltinType::Id: \
3498 type_name = #MangledName; \
3499 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3501#include "clang/Basic/AArch64ACLETypes.def"
3502#define PPC_VECTOR_TYPE(Name, Id, Size) \
3503 case BuiltinType::Id: \
3504 mangleVendorType(#Name); \
3506#include "clang/Basic/PPCTypes.def"
3508#define RVV_TYPE(Name, Id, SingletonId) \
3509 case BuiltinType::Id: \
3510 mangleVendorType(Name); \
3512#include "clang/Basic/RISCVVTypes.def"
3513#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3514 case BuiltinType::Id: \
3515 mangleVendorType(MangledName); \
3517#include "clang/Basic/WebAssemblyReferenceTypes.def"
3518#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3519 case BuiltinType::Id: \
3520 mangleVendorType(Name); \
3522#include "clang/Basic/AMDGPUTypes.def"
3523#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3524 case BuiltinType::Id: \
3525 mangleVendorType(#Name); \
3527#include "clang/Basic/HLSLIntangibleTypes.def"
3528#define SPIRV_TYPE(Name, Id, SingletonId) \
3529 case BuiltinType::Id: \
3530 mangleVendorType(Name); \
3532#include "clang/Basic/SPIRVTypes.def"
3536StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3556#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3592 return "swiftasynccall";
3594 llvm_unreachable(
"bad calling convention");
3597void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3606 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3607 if (!CCQualifier.empty())
3608 mangleVendorQualifier(CCQualifier);
3641 llvm_unreachable(
"Unrecognised SME attribute");
3656void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3676 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3680CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3687 case ParameterABI::Ordinary:
3691 case ParameterABI::HLSLOut:
3692 case ParameterABI::HLSLInOut:
3697 case ParameterABI::SwiftContext:
3698 case ParameterABI::SwiftAsyncContext:
3699 case ParameterABI::SwiftErrorResult:
3700 case ParameterABI::SwiftIndirectResult:
3706 mangleVendorQualifier(
"ns_consumed");
3709 mangleVendorQualifier(
"noescape");
3715void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3719 Out <<
"11__SME_ATTRSI";
3721 mangleExtFunctionInfo(
T);
3738 mangleType(ExceptTy);
3749 mangleBareFunctionType(
T,
true);
3756 mangleSMEAttrs(SMEAttrs);
3759void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3765 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3767 FunctionTypeDepth.enterFunctionDeclSuffix();
3769 FunctionTypeDepth.leaveFunctionDeclSuffix();
3771 FunctionTypeDepth.pop(saved);
3775void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3776 bool MangleReturnType,
3777 const FunctionDecl *FD) {
3780 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3783 if (MangleReturnType) {
3784 FunctionTypeDepth.enterFunctionDeclSuffix();
3788 mangleVendorQualifier(
"ns_returns_retained");
3793 auto SplitReturnTy = ReturnTy.
split();
3795 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3797 mangleType(ReturnTy);
3799 FunctionTypeDepth.leaveFunctionDeclSuffix();
3807 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3821 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3822 if (Attr->isDynamic())
3823 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3825 Out <<
"U17pass_object_size" << Attr->getType();
3836 FunctionTypeDepth.enterFunctionDeclSuffix();
3840 FunctionTypeDepth.pop(saved);
3845void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3846 mangleName(
T->getDecl());
3851void CXXNameMangler::mangleType(
const EnumType *
T) {
3852 mangleType(
static_cast<const TagType*
>(
T));
3854void CXXNameMangler::mangleType(
const RecordType *
T) {
3855 mangleType(
static_cast<const TagType*
>(
T));
3857void CXXNameMangler::mangleType(
const TagType *
T) {
3858 mangleName(
T->getDecl()->getDefinitionOrSelf());
3864void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3865 Out <<
'A' <<
T->getSize() <<
'_';
3866 mangleType(
T->getElementType());
3868void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3871 if (
T->getSizeExpr())
3872 mangleExpression(
T->getSizeExpr());
3874 mangleType(
T->getElementType());
3876void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3881 if (
T->getSizeExpr())
3882 mangleExpression(
T->getSizeExpr());
3884 mangleType(
T->getElementType());
3886void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3888 mangleType(
T->getElementType());
3893void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
3895 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
3896 mangleCXXRecordDecl(RD);
3898 mangleType(QualType(
T->getQualifier().getAsType(), 0));
3900 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3921 mangleType(PointeeType);
3925void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
3926 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3930void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
3935 Out <<
"_SUBSTPACK_";
3938void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
3943 Out <<
"_SUBSTBUILTINPACK_";
3947void CXXNameMangler::mangleType(
const PointerType *
T) {
3951void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
3957void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
3963void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
3969void CXXNameMangler::mangleType(
const ComplexType *
T) {
3971 mangleType(
T->getElementType());
3977void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
3978 QualType EltType =
T->getElementType();
3979 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3980 const char *EltName =
nullptr;
3981 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3983 case BuiltinType::SChar:
3984 case BuiltinType::UChar:
3985 EltName =
"poly8_t";
3987 case BuiltinType::Short:
3988 case BuiltinType::UShort:
3989 EltName =
"poly16_t";
3991 case BuiltinType::LongLong:
3992 case BuiltinType::ULongLong:
3993 EltName =
"poly64_t";
3995 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3999 case BuiltinType::SChar: EltName =
"int8_t";
break;
4000 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4001 case BuiltinType::Short: EltName =
"int16_t";
break;
4002 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4003 case BuiltinType::Int: EltName =
"int32_t";
break;
4004 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4005 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4006 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4007 case BuiltinType::Double: EltName =
"float64_t";
break;
4008 case BuiltinType::Float: EltName =
"float32_t";
break;
4009 case BuiltinType::Half: EltName =
"float16_t";
break;
4010 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4011 case BuiltinType::MFloat8:
4012 EltName =
"mfloat8_t";
4015 llvm_unreachable(
"unexpected Neon vector element type");
4018 const char *BaseName =
nullptr;
4019 unsigned BitSize = (
T->getNumElements() *
4020 getASTContext().getTypeSize(EltType));
4022 BaseName =
"__simd64_";
4024 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4025 BaseName =
"__simd128_";
4027 Out << strlen(BaseName) + strlen(EltName);
4028 Out << BaseName << EltName;
4031void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4032 DiagnosticsEngine &Diags = Context.getDiags();
4033 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4034 << UnsupportedItaniumManglingKind::DependentNeonVector;
4039 case BuiltinType::SChar:
4041 case BuiltinType::Short:
4043 case BuiltinType::Int:
4045 case BuiltinType::Long:
4046 case BuiltinType::LongLong:
4048 case BuiltinType::UChar:
4050 case BuiltinType::UShort:
4052 case BuiltinType::UInt:
4054 case BuiltinType::ULong:
4055 case BuiltinType::ULongLong:
4057 case BuiltinType::Half:
4059 case BuiltinType::Float:
4061 case BuiltinType::Double:
4063 case BuiltinType::BFloat16:
4065 case BuiltinType::MFloat8:
4068 llvm_unreachable(
"Unexpected vector element base type");
4075void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4076 QualType EltType =
T->getElementType();
4077 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4079 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4082 assert((BitSize == 64 || BitSize == 128) &&
4083 "Neon vector type not 64 or 128 bits");
4086 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4088 case BuiltinType::UChar:
4091 case BuiltinType::UShort:
4094 case BuiltinType::ULong:
4095 case BuiltinType::ULongLong:
4099 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4105 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4108void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4109 DiagnosticsEngine &Diags = Context.getDiags();
4110 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4111 << UnsupportedItaniumManglingKind::DependentNeonVector;
4138void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4139 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4140 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4141 "expected fixed-length SVE vector!");
4143 QualType EltType =
T->getElementType();
4145 "expected builtin type for fixed-length SVE vector!");
4149 case BuiltinType::SChar:
4152 case BuiltinType::UChar: {
4153 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4159 case BuiltinType::Short:
4162 case BuiltinType::UShort:
4165 case BuiltinType::Int:
4168 case BuiltinType::UInt:
4171 case BuiltinType::Long:
4174 case BuiltinType::ULong:
4177 case BuiltinType::Half:
4180 case BuiltinType::Float:
4183 case BuiltinType::Double:
4186 case BuiltinType::BFloat16:
4190 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4193 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4195 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4198 Out <<
"9__SVE_VLSI";
4199 mangleVendorType(TypeName);
4200 Out <<
"Lj" << VecSizeInBits <<
"EE";
4203void CXXNameMangler::mangleAArch64FixedSveVectorType(
4204 const DependentVectorType *
T) {
4205 DiagnosticsEngine &Diags = Context.getDiags();
4206 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4207 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4210void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4211 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4212 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4213 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4214 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4215 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4216 "expected fixed-length RVV vector!");
4218 QualType EltType =
T->getElementType();
4220 "expected builtin type for fixed-length RVV vector!");
4222 SmallString<20> TypeNameStr;
4223 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4224 TypeNameOS <<
"__rvv_";
4226 case BuiltinType::SChar:
4227 TypeNameOS <<
"int8";
4229 case BuiltinType::UChar:
4230 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4231 TypeNameOS <<
"uint8";
4233 TypeNameOS <<
"bool";
4235 case BuiltinType::Short:
4236 TypeNameOS <<
"int16";
4238 case BuiltinType::UShort:
4239 TypeNameOS <<
"uint16";
4241 case BuiltinType::Int:
4242 TypeNameOS <<
"int32";
4244 case BuiltinType::UInt:
4245 TypeNameOS <<
"uint32";
4247 case BuiltinType::Long:
4248 case BuiltinType::LongLong:
4249 TypeNameOS <<
"int64";
4251 case BuiltinType::ULong:
4252 case BuiltinType::ULongLong:
4253 TypeNameOS <<
"uint64";
4255 case BuiltinType::Float16:
4256 TypeNameOS <<
"float16";
4258 case BuiltinType::Float:
4259 TypeNameOS <<
"float32";
4261 case BuiltinType::Double:
4262 TypeNameOS <<
"float64";
4264 case BuiltinType::BFloat16:
4265 TypeNameOS <<
"bfloat16";
4268 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4271 unsigned VecSizeInBits;
4272 switch (
T->getVectorKind()) {
4273 case VectorKind::RVVFixedLengthMask_1:
4276 case VectorKind::RVVFixedLengthMask_2:
4279 case VectorKind::RVVFixedLengthMask_4:
4283 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4288 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4289 getASTContext().getLangOpts(),
4290 TargetInfo::ArmStreamingKind::NotStreaming);
4291 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4293 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4295 if (VecSizeInBits >= VLen)
4296 TypeNameOS << (VecSizeInBits / VLen);
4298 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4300 TypeNameOS << (VLen / VecSizeInBits);
4304 Out <<
"9__RVV_VLSI";
4305 mangleVendorType(TypeNameStr);
4306 Out <<
"Lj" << VecSizeInBits <<
"EE";
4309void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4310 const DependentVectorType *
T) {
4311 DiagnosticsEngine &Diags = Context.getDiags();
4312 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4313 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4324void CXXNameMangler::mangleType(
const VectorType *
T) {
4325 if ((
T->getVectorKind() == VectorKind::Neon ||
4326 T->getVectorKind() == VectorKind::NeonPoly)) {
4327 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4328 llvm::Triple::ArchType
Arch =
4329 getASTContext().getTargetInfo().getTriple().getArch();
4330 if ((
Arch == llvm::Triple::aarch64 ||
4331 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4332 mangleAArch64NeonVectorType(
T);
4334 mangleNeonVectorType(
T);
4336 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4337 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4338 mangleAArch64FixedSveVectorType(
T);
4340 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4341 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4342 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4343 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4344 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4345 mangleRISCVFixedRVVVectorType(
T);
4348 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4349 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4351 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4354 mangleType(
T->getElementType());
4357void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4358 if ((
T->getVectorKind() == VectorKind::Neon ||
4359 T->getVectorKind() == VectorKind::NeonPoly)) {
4360 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4361 llvm::Triple::ArchType
Arch =
4362 getASTContext().getTargetInfo().getTriple().getArch();
4363 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4365 mangleAArch64NeonVectorType(
T);
4367 mangleNeonVectorType(
T);
4369 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4370 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4371 mangleAArch64FixedSveVectorType(
T);
4373 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4374 mangleRISCVFixedRVVVectorType(
T);
4379 mangleExpression(
T->getSizeExpr());
4381 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4383 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4386 mangleType(
T->getElementType());
4389void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4390 mangleType(
static_cast<const VectorType*
>(
T));
4392void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4394 mangleExpression(
T->getSizeExpr());
4396 mangleType(
T->getElementType());
4399void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4403 mangleVendorType(
"matrix_type");
4406 auto &ASTCtx = getASTContext();
4407 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4408 llvm::APSInt Rows(BitWidth);
4409 Rows =
T->getNumRows();
4410 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4411 llvm::APSInt Columns(BitWidth);
4412 Columns =
T->getNumColumns();
4413 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4414 mangleType(
T->getElementType());
4418void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4421 mangleVendorType(
"matrix_type");
4424 mangleTemplateArgExpr(
T->getRowExpr());
4425 mangleTemplateArgExpr(
T->getColumnExpr());
4426 mangleType(
T->getElementType());
4430void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4432 mangleQualifiers(split.
Quals,
T);
4433 mangleType(QualType(split.
Ty, 0));
4436void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4439 mangleType(
T->getPattern());
4442void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4445 mangleType(
T->getPattern());
4446 mangleExpression(
T->getIndexExpr());
4449void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4450 mangleSourceName(
T->getDecl()->getIdentifier());
4453void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4455 if (
T->isKindOfType())
4456 Out <<
"U8__kindof";
4458 if (!
T->qual_empty()) {
4460 SmallString<64> QualStr;
4461 llvm::raw_svector_ostream QualOS(QualStr);
4462 QualOS <<
"objcproto";
4463 for (
const auto *I :
T->quals()) {
4464 StringRef
name = I->getName();
4467 mangleVendorQualifier(QualStr);
4470 mangleType(
T->getBaseType());
4472 if (
T->isSpecialized()) {
4475 for (
auto typeArg :
T->getTypeArgs())
4476 mangleType(typeArg);
4481void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4482 Out <<
"U13block_pointer";
4486void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4491 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4494void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4495 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4496 mangleTemplateName(TD,
T->template_arguments());
4499 mangleTemplatePrefix(
T->getTemplateName());
4504 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4509void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4520 switch (
T->getKeyword()) {
4521 case ElaboratedTypeKeyword::None:
4522 case ElaboratedTypeKeyword::Typename:
4524 case ElaboratedTypeKeyword::Struct:
4525 case ElaboratedTypeKeyword::Class:
4526 case ElaboratedTypeKeyword::Interface:
4529 case ElaboratedTypeKeyword::Union:
4532 case ElaboratedTypeKeyword::Enum:
4538 manglePrefix(
T->getQualifier());
4539 mangleSourceName(
T->getIdentifier());
4543void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4549void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4555void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4556 Expr *E =
T->getUnderlyingExpr();
4575 mangleExpression(E);
4579void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4583 StringRef BuiltinName;
4584 switch (
T->getUTTKind()) {
4585#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4586 case UnaryTransformType::Enum: \
4587 BuiltinName = "__" #Trait; \
4589#include "clang/Basic/BuiltinTraits.inc"
4591 mangleVendorType(BuiltinName);
4595 mangleType(
T->getBaseType());
4599void CXXNameMangler::mangleType(
const AutoType *
T) {
4600 assert(
T->getDeducedType().isNull() &&
4601 "Deduced AutoType shouldn't be handled here!");
4602 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4603 "shouldn't need to mangle __auto_type!");
4608 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4609 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4610 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4611 T->getTypeConstraintArguments());
4613 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4617void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4618 QualType
Deduced =
T->getDeducedType();
4624 "shouldn't form deduced TST unless we know we have a template");
4628void CXXNameMangler::mangleType(
const AtomicType *
T) {
4632 mangleType(
T->getValueType());
4635void CXXNameMangler::mangleType(
const PipeType *
T) {
4642void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4645 if (
T->isWrapKind()) {
4646 Out <<
"U8ObtWrap_";
4648 Out <<
"U8ObtTrap_";
4650 mangleType(
T->getUnderlyingType());
4653void CXXNameMangler::mangleType(
const BitIntType *
T) {
4657 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4660void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4664 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4665 mangleExpression(
T->getNumBitsExpr());
4669void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4673void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4674 llvm::SmallString<64> Str(
"_Res");
4675 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4677 switch (Attrs.ResourceClass) {
4678 case llvm::dxil::ResourceClass::UAV:
4681 case llvm::dxil::ResourceClass::SRV:
4684 case llvm::dxil::ResourceClass::CBuffer:
4687 case llvm::dxil::ResourceClass::Sampler:
4693 if (Attrs.RawBuffer)
4695 if (Attrs.IsCounter)
4699 if (Attrs.IsMultiSampled)
4701 if (
T->hasContainedType())
4703 mangleVendorQualifier(Str);
4705 if (
T->hasContainedType()) {
4706 mangleType(
T->getContainedType());
4708 mangleType(
T->getWrappedType());
4711void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4712 SmallString<20> TypeNameStr;
4713 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4715 TypeNameOS <<
"spirv_type";
4717 TypeNameOS <<
"_" <<
T->getOpcode();
4718 TypeNameOS <<
"_" <<
T->getSize();
4719 TypeNameOS <<
"_" <<
T->getAlignment();
4721 mangleVendorType(TypeNameStr);
4723 for (
auto &Operand :
T->getOperands()) {
4724 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4727 case SpirvOperandKind::ConstantId:
4728 mangleVendorQualifier(
"_Const");
4729 mangleIntegerLiteral(
Operand.getResultType(),
4730 llvm::APSInt(
Operand.getValue()));
4732 case SpirvOperandKind::Literal:
4733 mangleVendorQualifier(
"_Lit");
4734 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4735 llvm::APSInt(
Operand.getValue()));
4737 case SpirvOperandKind::TypeId:
4738 mangleVendorQualifier(
"_Type");
4739 mangleType(
Operand.getResultType());
4742 llvm_unreachable(
"Invalid SpirvOperand kind");
4745 TypeNameOS <<
Operand.getKind();
4749void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4750 const llvm::APSInt &
Value) {
4757 Out << (
Value.getBoolValue() ?
'1' :
'0');
4759 mangleNumber(
Value);
4764void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4766 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4767 if (!RT->getDecl()->isAnonymousStructOrUnion())
4769 const auto *ME = dyn_cast<MemberExpr>(Base);
4772 Base = ME->getBase();
4773 IsArrow = ME->isArrow();
4776 if (
Base->isImplicitCXXThis()) {
4782 Out << (IsArrow ?
"pt" :
"dt");
4783 mangleExpression(Base);
4788void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4789 NestedNameSpecifier Qualifier,
4790 NamedDecl *firstQualifierLookup,
4791 DeclarationName member,
4792 const TemplateArgumentLoc *TemplateArgs,
4793 unsigned NumTemplateArgs,
4798 mangleMemberExprBase(base, isArrow);
4799 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4812 if (callee == fn)
return false;
4816 if (!lookup)
return false;
4833void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4835 Out << CastEncoding;
4840void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4842 InitList = Syntactic;
4843 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4844 mangleExpression(InitList->
getInit(i));
4847void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4848 const concepts::Requirement *Req) {
4849 using concepts::Requirement;
4854 auto HandleSubstitutionFailure =
4855 [&](SourceLocation Loc) {
4856 DiagnosticsEngine &Diags = Context.getDiags();
4857 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4858 << UnsupportedItaniumManglingKind::
4859 RequiresExprWithSubstitutionFailure;
4864 case Requirement::RK_Type: {
4866 if (TR->isSubstitutionFailure())
4867 return HandleSubstitutionFailure(
4868 TR->getSubstitutionDiagnostic()->DiagLoc);
4871 mangleType(TR->getType()->getType());
4875 case Requirement::RK_Simple:
4876 case Requirement::RK_Compound: {
4878 if (ER->isExprSubstitutionFailure())
4879 return HandleSubstitutionFailure(
4880 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4883 mangleExpression(ER->getExpr());
4885 if (ER->hasNoexceptRequirement())
4888 if (!ER->getReturnTypeRequirement().isEmpty()) {
4889 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4890 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4891 .getSubstitutionDiagnostic()
4895 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4900 case Requirement::RK_Nested:
4902 if (NR->hasInvalidConstraint()) {
4905 return HandleSubstitutionFailure(RequiresExprLoc);
4909 mangleExpression(NR->getConstraintExpr());
4914void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4915 bool AsTemplateArg) {
4948 QualType ImplicitlyConvertedToType;
4952 bool IsPrimaryExpr =
true;
4953 auto NotPrimaryExpr = [&] {
4954 if (AsTemplateArg && IsPrimaryExpr)
4956 IsPrimaryExpr =
false;
4959 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4960 switch (D->getKind()) {
4973 case Decl::EnumConstant: {
4980 case Decl::NonTypeTemplateParm:
4993 case Expr::NoStmtClass:
4994#define ABSTRACT_STMT(Type)
4995#define EXPR(Type, Base)
4996#define STMT(Type, Base) \
4997 case Expr::Type##Class:
4998#include "clang/AST/StmtNodes.inc"
5003 case Expr::AddrLabelExprClass:
5004 case Expr::DesignatedInitUpdateExprClass:
5005 case Expr::ImplicitValueInitExprClass:
5006 case Expr::ArrayInitLoopExprClass:
5007 case Expr::ArrayInitIndexExprClass:
5008 case Expr::NoInitExprClass:
5009 case Expr::ParenListExprClass:
5010 case Expr::MSPropertyRefExprClass:
5011 case Expr::MSPropertySubscriptExprClass:
5012 case Expr::RecoveryExprClass:
5013 case Expr::ArraySectionExprClass:
5014 case Expr::OMPArrayShapingExprClass:
5015 case Expr::OMPIteratorExprClass:
5016 case Expr::CXXInheritedCtorInitExprClass:
5017 case Expr::CXXParenListInitExprClass:
5018 case Expr::CXXExpansionSelectExprClass:
5019 llvm_unreachable(
"unexpected statement kind");
5021 case Expr::ConstantExprClass:
5025 case Expr::CXXReflectExprClass: {
5027 assert(
false &&
"unimplemented");
5032 case Expr::BlockExprClass:
5033 case Expr::ChooseExprClass:
5034 case Expr::CompoundLiteralExprClass:
5035 case Expr::ExtVectorElementExprClass:
5036 case Expr::MatrixElementExprClass:
5037 case Expr::GenericSelectionExprClass:
5038 case Expr::ObjCEncodeExprClass:
5039 case Expr::ObjCIsaExprClass:
5040 case Expr::ObjCIvarRefExprClass:
5041 case Expr::ObjCMessageExprClass:
5042 case Expr::ObjCPropertyRefExprClass:
5043 case Expr::ObjCProtocolExprClass:
5044 case Expr::ObjCSelectorExprClass:
5045 case Expr::ObjCStringLiteralClass:
5046 case Expr::ObjCBoxedExprClass:
5047 case Expr::ObjCArrayLiteralClass:
5048 case Expr::ObjCDictionaryLiteralClass:
5049 case Expr::ObjCSubscriptRefExprClass:
5050 case Expr::ObjCIndirectCopyRestoreExprClass:
5051 case Expr::ObjCAvailabilityCheckExprClass:
5052 case Expr::OffsetOfExprClass:
5053 case Expr::PredefinedExprClass:
5054 case Expr::ShuffleVectorExprClass:
5055 case Expr::ConvertVectorExprClass:
5056 case Expr::StmtExprClass:
5057 case Expr::ArrayTypeTraitExprClass:
5058 case Expr::ExpressionTraitExprClass:
5059 case Expr::VAArgExprClass:
5060 case Expr::CUDAKernelCallExprClass:
5061 case Expr::AsTypeExprClass:
5062 case Expr::PseudoObjectExprClass:
5063 case Expr::AtomicExprClass:
5064 case Expr::SourceLocExprClass:
5065 case Expr::EmbedExprClass:
5066 case Expr::BuiltinBitCastExprClass: {
5070 DiagnosticsEngine &Diags = Context.getDiags();
5078 case Expr::CXXUuidofExprClass: {
5083 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5084 Out <<
"u8__uuidof";
5093 Out <<
"u8__uuidoft";
5097 Out <<
"u8__uuidofz";
5098 mangleExpression(UuidExp);
5105 case Expr::BinaryConditionalOperatorClass: {
5107 DiagnosticsEngine &Diags = Context.getDiags();
5109 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5115 case Expr::OpaqueValueExprClass:
5116 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5118 case Expr::InitListExprClass: {
5126 case Expr::DesignatedInitExprClass: {
5129 for (
const auto &Designator : DIE->designators()) {
5130 if (Designator.isFieldDesignator()) {
5132 mangleSourceName(Designator.getFieldName());
5133 }
else if (Designator.isArrayDesignator()) {
5135 mangleExpression(DIE->getArrayIndex(Designator));
5137 assert(Designator.isArrayRangeDesignator() &&
5138 "unknown designator kind");
5140 mangleExpression(DIE->getArrayRangeStart(Designator));
5141 mangleExpression(DIE->getArrayRangeEnd(Designator));
5144 mangleExpression(DIE->getInit());
5148 case Expr::CXXDefaultArgExprClass:
5152 case Expr::CXXDefaultInitExprClass:
5156 case Expr::CXXStdInitializerListExprClass:
5160 case Expr::SubstNonTypeTemplateParmExprClass: {
5164 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5166 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5167 mangleValueInTemplateArg(SNTTPE->getParameterType(),
5168 CE->getAPValueResult(),
false,
5178 case Expr::UserDefinedLiteralClass:
5181 case Expr::CXXMemberCallExprClass:
5182 case Expr::CallExprClass: {
5204 CallArity = UnknownArity;
5206 mangleExpression(CE->
getCallee(), CallArity);
5208 mangleExpression(Arg);
5213 case Expr::CXXNewExprClass: {
5216 if (
New->isGlobalNew())
Out <<
"gs";
5217 Out << (
New->isArray() ?
"na" :
"nw");
5219 E =
New->placement_arg_end(); I != E; ++I)
5220 mangleExpression(*I);
5222 mangleType(
New->getAllocatedType());
5223 if (
New->hasInitializer()) {
5224 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5228 const Expr *
Init =
New->getInitializer();
5229 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5234 mangleExpression(*I);
5235 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5236 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5237 mangleExpression(PLE->getExpr(i));
5238 }
else if (
New->getInitializationStyle() ==
5239 CXXNewInitializationStyle::Braces &&
5244 mangleExpression(
Init);
5250 case Expr::CXXPseudoDestructorExprClass: {
5253 if (
const Expr *Base = PDE->getBase())
5254 mangleMemberExprBase(Base, PDE->isArrow());
5255 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5256 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5258 mangleUnresolvedPrefix(Qualifier,
5260 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5264 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5267 }
else if (Qualifier) {
5268 mangleUnresolvedPrefix(Qualifier);
5272 QualType DestroyedType = PDE->getDestroyedType();
5273 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5277 case Expr::MemberExprClass: {
5288 case Expr::UnresolvedMemberExprClass: {
5299 case Expr::CXXDependentScopeMemberExprClass: {
5301 const CXXDependentScopeMemberExpr *ME
5312 case Expr::UnresolvedLookupExprClass: {
5321 case Expr::CXXUnresolvedConstructExprClass: {
5327 assert(N == 1 &&
"unexpected form for list initialization");
5331 mangleInitListElements(IL);
5338 if (N != 1)
Out <<
'_';
5339 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5340 if (N != 1)
Out <<
'E';
5344 case Expr::CXXConstructExprClass: {
5351 "implicit CXXConstructExpr must have one argument");
5358 mangleExpression(E);
5363 case Expr::CXXTemporaryObjectExprClass: {
5374 if (!List && N != 1)
5376 if (CE->isStdInitListInitialization()) {
5383 mangleInitListElements(ILE);
5386 mangleExpression(E);
5393 case Expr::CXXScalarValueInitExprClass:
5400 case Expr::CXXNoexceptExprClass:
5406 case Expr::UnaryExprOrTypeTraitExprClass: {
5423 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5425 : ImplicitlyConvertedToType;
5427 mangleIntegerLiteral(
T,
V);
5433 auto MangleAlignofSizeofArg = [&] {
5443 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5444 StringRef Name = {}) {
5447 mangleVendorType(Name);
5458 MangleAlignofSizeofArg();
5460 case UETT_PreferredAlignOf:
5464 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5465 MangleExtensionBuiltin(SAE,
"__alignof__");
5471 MangleAlignofSizeofArg();
5475 case UETT_VectorElements:
5476 case UETT_OpenMPRequiredSimdAlign:
5478 case UETT_PtrAuthTypeDiscriminator:
5479 case UETT_DataSizeOf: {
5480 DiagnosticsEngine &Diags = Context.getDiags();
5489 case Expr::TypeTraitExprClass: {
5494 mangleVendorType(Spelling);
5495 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5496 mangleType(TSI->getType());
5502 case Expr::CXXThrowExprClass: {
5516 case Expr::CXXTypeidExprClass: {
5531 case Expr::CXXDeleteExprClass: {
5542 case Expr::UnaryOperatorClass: {
5551 case Expr::ArraySubscriptExprClass: {
5558 mangleExpression(AE->
getLHS());
5559 mangleExpression(AE->
getRHS());
5563 case Expr::MatrixSingleSubscriptExprClass: {
5567 mangleExpression(ME->
getBase());
5572 case Expr::MatrixSubscriptExprClass: {
5576 mangleExpression(ME->
getBase());
5582 case Expr::CompoundAssignOperatorClass:
5583 case Expr::BinaryOperatorClass: {
5591 mangleExpression(BO->
getLHS());
5592 mangleExpression(BO->
getRHS());
5596 case Expr::CXXRewrittenBinaryOperatorClass: {
5599 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5603 mangleExpression(Decomposed.
LHS);
5604 mangleExpression(Decomposed.
RHS);
5608 case Expr::ConditionalOperatorClass: {
5611 mangleOperatorName(OO_Conditional, 3);
5612 mangleExpression(CO->
getCond());
5613 mangleExpression(CO->
getLHS(), Arity);
5614 mangleExpression(CO->
getRHS(), Arity);
5618 case Expr::ImplicitCastExprClass: {
5619 ImplicitlyConvertedToType = E->
getType();
5624 case Expr::ObjCBridgedCastExprClass: {
5630 mangleCastExpression(E,
"cv");
5634 case Expr::CStyleCastExprClass:
5636 mangleCastExpression(E,
"cv");
5639 case Expr::CXXFunctionalCastExprClass: {
5643 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5644 if (CCE->getParenOrBraceRange().isInvalid())
5645 Sub = CCE->getArg(0)->IgnoreImplicit();
5646 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5647 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5648 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5651 mangleInitListElements(IL);
5654 mangleCastExpression(E,
"cv");
5659 case Expr::CXXStaticCastExprClass:
5661 mangleCastExpression(E,
"sc");
5663 case Expr::CXXDynamicCastExprClass:
5665 mangleCastExpression(E,
"dc");
5667 case Expr::CXXReinterpretCastExprClass:
5669 mangleCastExpression(E,
"rc");
5671 case Expr::CXXConstCastExprClass:
5673 mangleCastExpression(E,
"cc");
5675 case Expr::CXXAddrspaceCastExprClass:
5677 mangleCastExpression(E,
"ac");
5680 case Expr::CXXOperatorCallExprClass: {
5689 for (
unsigned i = 0; i != NumArgs; ++i)
5690 mangleExpression(CE->
getArg(i));
5694 case Expr::ParenExprClass:
5698 case Expr::ConceptSpecializationExprClass: {
5700 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5705 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5711 mangleUnresolvedName(
5712 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5713 CSE->getConceptNameInfo().getName(),
5714 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5715 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5719 case Expr::RequiresExprClass: {
5725 if (RE->getLParenLoc().isValid()) {
5727 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5728 if (RE->getLocalParameters().empty()) {
5731 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5739 FunctionTypeDepth.enterFunctionDeclSuffix();
5740 for (
const concepts::Requirement *Req : RE->getRequirements())
5741 mangleRequirement(RE->getExprLoc(), Req);
5742 FunctionTypeDepth.pop(saved);
5746 for (
const concepts::Requirement *Req : RE->getRequirements())
5747 mangleRequirement(RE->getExprLoc(), Req);
5753 case Expr::DeclRefExprClass:
5758 case Expr::SubstNonTypeTemplateParmPackExprClass:
5764 Out <<
"_SUBSTPACK_";
5767 case Expr::FunctionParmPackExprClass: {
5771 Out <<
"v110_SUBSTPACK";
5776 case Expr::DependentScopeDeclRefExprClass: {
5785 case Expr::CXXBindTemporaryExprClass:
5789 case Expr::ExprWithCleanupsClass:
5793 case Expr::FloatingLiteralClass: {
5800 case Expr::FixedPointLiteralClass:
5802 mangleFixedPointLiteral();
5805 case Expr::CharacterLiteralClass:
5809 Out << cast<CharacterLiteral>(E)->getValue();
5814 case Expr::ObjCBoolLiteralExprClass:
5817 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5821 case Expr::CXXBoolLiteralExprClass:
5824 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5828 case Expr::IntegerLiteralClass: {
5832 Value.setIsSigned(
true);
5837 case Expr::ImaginaryLiteralClass: {
5844 if (
const FloatingLiteral *Imag =
5845 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5847 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5849 mangleFloat(Imag->getValue());
5854 Value.setIsSigned(
true);
5855 mangleNumber(
Value);
5861 case Expr::StringLiteralClass: {
5871 case Expr::GNUNullExprClass:
5874 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5877 case Expr::CXXNullPtrLiteralExprClass: {
5883 case Expr::LambdaExprClass: {
5894 case Expr::PackExpansionExprClass:
5900 case Expr::SizeOfPackExprClass: {
5903 if (SPE->isPartiallySubstituted()) {
5905 for (
const auto &A : SPE->getPartialArguments())
5906 mangleTemplateArg(A,
false);
5912 mangleReferenceToPack(SPE->getPack());
5916 case Expr::MaterializeTemporaryExprClass:
5920 case Expr::CXXFoldExprClass: {
5923 if (FE->isLeftFold())
5924 Out << (FE->getInit() ?
"fL" :
"fl");
5926 Out << (FE->getInit() ?
"fR" :
"fr");
5928 if (FE->getOperator() == BO_PtrMemD)
5936 mangleExpression(FE->getLHS());
5938 mangleExpression(FE->getRHS());
5942 case Expr::PackIndexingExprClass: {
5946 mangleReferenceToPack(PE->getPackDecl());
5947 mangleExpression(PE->getIndexExpr());
5951 case Expr::CXXThisExprClass:
5956 case Expr::CoawaitExprClass:
5959 Out <<
"v18co_await";
5963 case Expr::DependentCoawaitExprClass:
5966 Out <<
"v18co_await";
5970 case Expr::CoyieldExprClass:
5973 Out <<
"v18co_yield";
5976 case Expr::SYCLUniqueStableNameExprClass: {
5980 Out <<
"u33__builtin_sycl_unique_stable_name";
5981 mangleType(USN->getTypeSourceInfo()->getType());
5986 case Expr::HLSLOutArgExprClass:
5988 "cannot mangle hlsl temporary value; mangling wrong thing?");
5989 case Expr::OpenACCAsteriskSizeExprClass: {
5991 DiagnosticsEngine &Diags = Context.getDiags();
5992 Diags.
Report(diag::err_unsupported_itanium_mangling)
5993 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
5998 if (AsTemplateArg && !IsPrimaryExpr)
6030void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6035 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6036 nestingDepth == 0) {
6039 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6047 &&
"parameter's type is still an array type?");
6049 if (
const DependentAddressSpaceType *DAST =
6050 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6057 if (parmIndex != 0) {
6058 Out << (parmIndex - 1);
6064 const CXXRecordDecl *InheritedFrom) {
6091 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6094 mangleName(InheritedFrom);
6122 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6126void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6127 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6128 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6129 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6130 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6131 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6132 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6166 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6167 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6168 if (!RD || !RD->isGenericLambda())
6184 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6185 return TTP->hasTypeConstraint();
6202 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6203 return NTTP->getType()->isInstantiationDependentType() ||
6204 NTTP->getType()->getContainedDeducedType();
6211 "A DeducedTemplateName shouldn't escape partial ordering");
6222 auto MangleTemplateParamListToString =
6224 unsigned DepthOffset) {
6225 llvm::raw_svector_ostream Stream(Buffer);
6226 CXXNameMangler(
Mangler.Context, Stream,
6227 WithTemplateDepthOffset{DepthOffset})
6228 .mangleTemplateParameterList(Params);
6231 MangleTemplateParamListToString(ParamTemplateHead,
6232 TTP->getTemplateParameters(), 0);
6236 MangleTemplateParamListToString(ArgTemplateHead,
6238 TTP->getTemplateParameters()->
getDepth());
6239 return ParamTemplateHead != ArgTemplateHead;
6249 return {
true,
nullptr};
6254 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6255 "no parameter for argument");
6276 return {
true,
nullptr};
6291 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6292 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6293 return {NeedExactType,
nullptr};
6305void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6307 unsigned NumTemplateArgs) {
6310 TemplateArgManglingInfo Info(*
this, TN);
6311 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6312 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6314 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6318void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6319 const TemplateArgumentList &AL) {
6322 TemplateArgManglingInfo Info(*
this, TN);
6323 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6324 mangleTemplateArg(Info, i, AL[i]);
6326 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6330void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6331 ArrayRef<TemplateArgument> Args) {
6334 TemplateArgManglingInfo Info(*
this, TN);
6335 for (
unsigned i = 0; i != Args.size(); ++i) {
6336 mangleTemplateArg(Info, i, Args[i]);
6338 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6342void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6343 unsigned Index, TemplateArgument A) {
6344 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6347 if (ArgInfo.TemplateParameterToMangle &&
6348 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6355 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6358 mangleTemplateArg(A, ArgInfo.NeedExactType);
6361void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6371 llvm_unreachable(
"Cannot mangle NULL template argument");
6399 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6400 TPO->getValue(),
true,
6405 ASTContext &Ctx = Context.getASTContext();
6413 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6421 ArrayRef<APValue::LValuePathEntry>(),
6434 true, NeedExactType);
6440 mangleTemplateArg(P, NeedExactType);
6446void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6447 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6448 mangleExpression(E, UnknownArity,
true);
6463 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6464 const ValueDecl *D = DRE->getDecl();
6473 mangleExpression(E);
6486 switch (
V.getKind()) {
6494 assert(RD &&
"unexpected type for record value");
6503 if (!FD->isUnnamedBitField() &&
6513 assert(RD &&
"unexpected type for union value");
6516 if (!FD->isUnnamedBitField())
6526 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6527 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6535 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6542 llvm_unreachable(
"Matrix APValues not yet supported");
6548 return V.getFloat().isPosZero();
6551 return !
V.getFixedPoint().getValue();
6554 return V.getComplexFloatReal().isPosZero() &&
6555 V.getComplexFloatImag().isPosZero();
6558 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6561 return V.isNullPointer();
6564 return !
V.getMemberPointerDecl();
6567 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6574 T = AT->getElementType();
6576 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6619 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6620 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6625void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6627 bool NeedExactType) {
6630 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6633 bool IsPrimaryExpr =
true;
6634 auto NotPrimaryExpr = [&] {
6635 if (TopLevel && IsPrimaryExpr)
6637 IsPrimaryExpr =
false;
6641 switch (
V.getKind()) {
6650 llvm_unreachable(
"unexpected value kind in template argument");
6654 assert(RD &&
"unexpected type for record value");
6657 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6660 (Fields.back()->isUnnamedBitField() ||
6662 V.getStructField(Fields.back()->getFieldIndex())))) {
6666 if (Fields.empty()) {
6667 while (!Bases.empty() &&
6669 V.getStructBase(Bases.size() - 1)))
6670 Bases = Bases.drop_back();
6677 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6678 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6679 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6680 if (Fields[I]->isUnnamedBitField())
6682 mangleValueInTemplateArg(Fields[I]->
getType(),
6683 V.getStructField(Fields[I]->getFieldIndex()),
6692 const FieldDecl *FD =
V.getUnionField();
6710 mangleSourceName(II);
6711 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6725 unsigned N =
V.getArraySize();
6727 N =
V.getArrayInitializedElts();
6732 for (
unsigned I = 0; I != N; ++I) {
6733 const APValue &Elem = I <
V.getArrayInitializedElts()
6734 ?
V.getArrayInitializedElt(I)
6735 :
V.getArrayFiller();
6736 mangleValueInTemplateArg(ElemT, Elem,
false);
6743 const VectorType *VT =
T->
castAs<VectorType>();
6748 unsigned N =
V.getVectorLength();
6751 for (
unsigned I = 0; I != N; ++I)
6752 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6758 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6761 mangleIntegerLiteral(
T,
V.getInt());
6765 mangleFloatLiteral(
T,
V.getFloat());
6769 mangleFixedPointLiteral();
6773 const ComplexType *CT =
T->
castAs<ComplexType>();
6777 if (!
V.getComplexFloatReal().isPosZero() ||
6778 !
V.getComplexFloatImag().isPosZero())
6780 if (!
V.getComplexFloatImag().isPosZero())
6787 const ComplexType *CT =
T->
castAs<ComplexType>();
6791 if (
V.getComplexIntReal().getBoolValue() ||
6792 V.getComplexIntImag().getBoolValue())
6794 if (
V.getComplexIntImag().getBoolValue())
6803 "unexpected type for LValue template arg");
6805 if (
V.isNullPointer()) {
6806 mangleNullPointer(
T);
6810 APValue::LValueBase B =
V.getLValueBase();
6814 CharUnits Offset =
V.getLValueOffset();
6832 ASTContext &Ctx = Context.getASTContext();
6835 if (!
V.hasLValuePath()) {
6851 bool IsArrayToPointerDecayMangledAsDecl =
false;
6852 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6854 IsArrayToPointerDecayMangledAsDecl =
6855 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6856 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6860 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6861 !IsArrayToPointerDecayMangledAsDecl) {
6878 if (NeedExactType &&
6880 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6893 QualType TypeSoFar = B.
getType();
6894 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6898 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6900 mangleExpression(E);
6901 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6904 mangleType(QualType(TI.getType(), 0));
6907 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6917 mangleNumber(
V.getLValueOffset().getQuantity());
6924 if (!
V.getLValueOffset().isZero())
6925 mangleNumber(
V.getLValueOffset().getQuantity());
6929 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6931 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6933 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6934 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6935 TypeSoFar = AT->getElementType();
6937 const Decl *D = E.getAsBaseOrMember().getPointer();
6938 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6963 if (!
V.getMemberPointerDecl()) {
6964 mangleNullPointer(
T);
6968 ASTContext &Ctx = Context.getASTContext();
6971 if (!
V.getMemberPointerPath().empty()) {
6974 }
else if (NeedExactType &&
6976 T->
castAs<MemberPointerType>()->getPointeeType(),
6977 V.getMemberPointerDecl()->getType()) &&
6978 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6983 mangle(
V.getMemberPointerDecl());
6985 if (!
V.getMemberPointerPath().empty()) {
6995 if (TopLevel && !IsPrimaryExpr)
6999void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7009 Depth += TemplateDepthOffset;
7011 Out <<
'L' << (Depth - 1) <<
'_';
7017void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7020 }
else if (SeqID == 1) {
7027 MutableArrayRef<char> BufferRef(Buffer);
7028 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7030 for (; SeqID != 0; SeqID /= 36) {
7031 unsigned C = SeqID % 36;
7032 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7035 Out.write(I.base(), I - BufferRef.rbegin());
7040void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7041 bool result = mangleSubstitution(tname);
7042 assert(result &&
"no existing substitution for template name");
7048bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7050 if (mangleStandardSubstitution(ND))
7054 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7064bool CXXNameMangler::mangleSubstitution(QualType
T) {
7067 return mangleSubstitution(RD);
7072 return mangleSubstitution(TypePtr);
7076 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7077 return mangleSubstitution(TD);
7080 return mangleSubstitution(
7084bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7085 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7086 if (I == Substitutions.end())
7089 unsigned SeqID = I->second;
7098bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7107 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7108 if (!SD || !SD->getIdentifier()->isStr(Name))
7111 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7114 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7115 if (TemplateArgs.
size() != 1)
7118 if (TemplateArgs[0].getAsType() != A)
7121 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7130bool CXXNameMangler::isStdCharSpecialization(
7131 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7132 bool HasAllocator) {
7137 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7140 QualType A = TemplateArgs[0].getAsType();
7148 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7152 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7161bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7163 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7171 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7172 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7192 if (
const ClassTemplateSpecializationDecl *SD =
7193 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7194 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7203 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7210 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7217 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7224 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7234void CXXNameMangler::addSubstitution(QualType
T) {
7237 addSubstitution(RD);
7243 addSubstitution(TypePtr);
7247 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7248 return addSubstitution(TD);
7254void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7255 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7256 Substitutions[Ptr] = SeqID++;
7259void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7260 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7261 if (
Other->SeqID > SeqID) {
7262 Substitutions.swap(
Other->Substitutions);
7263 SeqID =
Other->SeqID;
7267CXXNameMangler::AbiTagList
7268CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7270 if (DisableDerivedAbiTags)
7271 return AbiTagList();
7273 llvm::raw_null_ostream NullOutStream;
7274 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7275 TrackReturnTypeTags.disableDerivedAbiTags();
7277 const FunctionProtoType *Proto =
7279 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7280 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7282 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7283 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7285 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7288CXXNameMangler::AbiTagList
7289CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7291 if (DisableDerivedAbiTags)
7292 return AbiTagList();
7294 llvm::raw_null_ostream NullOutStream;
7295 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7296 TrackVariableType.disableDerivedAbiTags();
7298 TrackVariableType.mangleType(VD->
getType());
7300 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7303bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7304 const VarDecl *VD) {
7305 llvm::raw_null_ostream NullOutStream;
7306 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7307 TrackAbiTags.mangle(VD);
7308 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7313void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7317 "Invalid mangleName() call, argument is not a variable or function!");
7319 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7320 getASTContext().getSourceManager(),
7321 "Mangling declaration");
7323 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7325 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7326 return Mangler.mangle(GlobalDecl(CD,
Type));
7329 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7331 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7332 return Mangler.mangle(GlobalDecl(DD,
Type));
7335 CXXNameMangler Mangler(*
this, Out, D);
7339void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7341 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7345void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7347 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7369 auto &LangOpts = Context.getLangOpts();
7372 Context.baseForVTableAuthentication(ThisRD);
7373 unsigned TypedDiscriminator =
7374 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7376 Mangler.mangleVendorQualifier(
"__vtptrauth");
7377 auto &ManglerStream = Mangler.getStream();
7378 ManglerStream <<
"I";
7379 if (
const auto *ExplicitAuth =
7380 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7381 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7383 if (ExplicitAuth->getAddressDiscrimination() ==
7384 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7385 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7387 ManglerStream <<
"Lb"
7388 << (ExplicitAuth->getAddressDiscrimination() ==
7389 VTablePointerAuthenticationAttr::AddressDiscrimination);
7391 switch (ExplicitAuth->getExtraDiscrimination()) {
7392 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7393 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7394 ManglerStream <<
"Lj" << TypedDiscriminator;
7396 ManglerStream <<
"Lj" << 0;
7399 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7400 ManglerStream <<
"Lj" << TypedDiscriminator;
7402 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7403 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7405 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7406 ManglerStream <<
"Lj" << 0;
7410 ManglerStream <<
"Lj"
7411 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7412 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7413 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7414 ManglerStream <<
"Lj" << TypedDiscriminator;
7416 ManglerStream <<
"Lj" << 0;
7418 ManglerStream <<
"E";
7421void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7422 const ThunkInfo &Thunk,
7423 bool ElideOverrideInfo,
7433 "Use mangleCXXDtor for destructor decls!");
7434 CXXNameMangler Mangler(*
this, Out);
7435 Mangler.getStream() <<
"_ZT";
7437 Mangler.getStream() <<
'c';
7448 Mangler.mangleFunctionEncoding(MD);
7449 if (!ElideOverrideInfo)
7453void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7455 const ThunkInfo &Thunk,
7456 bool ElideOverrideInfo,
7460 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7461 Mangler.getStream() <<
"_ZT";
7463 auto &ThisAdjustment = Thunk.
This;
7465 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7466 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7468 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7469 if (!ElideOverrideInfo)
7474void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7478 CXXNameMangler Mangler(*
this, Out);
7481 Mangler.getStream() <<
"_ZGV";
7482 Mangler.mangleName(D);
7485void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7490 Out <<
"__cxx_global_var_init";
7493void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7496 CXXNameMangler Mangler(*
this, Out);
7497 Mangler.getStream() <<
"__dtor_";
7498 if (shouldMangleDeclName(D))
7501 Mangler.getStream() << D->
getName();
7504void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7508 CXXNameMangler Mangler(*
this, Out);
7509 Mangler.getStream() <<
"__finalize_";
7510 if (shouldMangleDeclName(D))
7513 Mangler.getStream() << D->
getName();
7516void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7517 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7518 CXXNameMangler Mangler(*
this, Out);
7519 Mangler.getStream() <<
"__filt_";
7521 if (shouldMangleDeclName(EnclosingFD))
7522 Mangler.mangle(EnclosingDecl);
7524 Mangler.getStream() << EnclosingFD->getName();
7527void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7528 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7529 CXXNameMangler Mangler(*
this, Out);
7530 Mangler.getStream() <<
"__fin_";
7532 if (shouldMangleDeclName(EnclosingFD))
7533 Mangler.mangle(EnclosingDecl);
7535 Mangler.getStream() << EnclosingFD->getName();
7538void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7541 CXXNameMangler Mangler(*
this, Out);
7542 Mangler.getStream() <<
"_ZTH";
7543 Mangler.mangleName(D);
7547ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7550 CXXNameMangler Mangler(*
this, Out);
7551 Mangler.getStream() <<
"_ZTW";
7552 Mangler.mangleName(D);
7555void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7556 unsigned ManglingNumber,
7560 CXXNameMangler Mangler(*
this, Out);
7561 Mangler.getStream() <<
"_ZGR";
7562 Mangler.mangleName(D);
7563 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7564 Mangler.mangleSeqID(ManglingNumber - 1);
7567void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7570 CXXNameMangler Mangler(*
this, Out);
7571 Mangler.getStream() <<
"_ZTV";
7572 Mangler.mangleCXXRecordDecl(RD);
7575void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7578 CXXNameMangler Mangler(*
this, Out);
7579 Mangler.getStream() <<
"_ZTT";
7580 Mangler.mangleCXXRecordDecl(RD);
7583void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7585 const CXXRecordDecl *
Type,
7588 CXXNameMangler Mangler(*
this, Out);
7589 Mangler.getStream() <<
"_ZTC";
7592 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7593 LangOptions::ClangABI::Ver19);
7594 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7595 Mangler.getStream() << Offset;
7596 Mangler.getStream() <<
'_';
7597 Mangler.mangleCXXRecordDecl(
Type);
7600void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7602 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7603 CXXNameMangler Mangler(*
this, Out);
7604 Mangler.getStream() <<
"_ZTI";
7605 Mangler.mangleType(Ty);
7608void ItaniumMangleContextImpl::mangleCXXRTTIName(
7609 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7611 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7612 Mangler.getStream() <<
"_ZTS";
7613 Mangler.mangleType(Ty);
7616void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7617 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7618 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7621void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7622 llvm_unreachable(
"Can't mangle string literals");
7625void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7627 CXXNameMangler Mangler(*
this, Out);
7628 Mangler.mangleLambdaSig(Lambda);
7631void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7634 CXXNameMangler Mangler(*
this, Out);
7635 Mangler.getStream() <<
"_ZGI";
7639 auto Partition = M->
Name.find(
':');
7640 Mangler.mangleModuleNamePrefix(
7641 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7649 return new ItaniumMangleContextImpl(
7652 return std::nullopt;
7661 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
@ LLVM_MARK_AS_BITMASK_ENUM
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,...
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
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits Zero()
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.
@ 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.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateDecl * 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)
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.
@ 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.
@ Type
The name was classified as a type.
@ 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.
@ EST_Dynamic
throw(T1, T2)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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.