34#include "llvm/ADT/StringExtras.h"
35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37#include "llvm/TargetParser/RISCVTargetParser.h"
44static bool isLocalContainerContext(
const DeclContext *DC) {
50 return ftd->getTemplatedDecl();
57 return (fn ? getStructor(fn) :
decl);
60static bool isLambda(
const NamedDecl *ND) {
68static const unsigned UnknownArity = ~0
U;
71 typedef std::pair<const DeclContext*, IdentifierInfo*> DiscriminatorKeyTy;
72 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
73 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
74 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
75 NamespaceDecl *StdNamespace =
nullptr;
77 bool NeedsUniqueInternalLinkageNames =
false;
80 explicit ItaniumMangleContextImpl(
81 ASTContext &Context, DiagnosticsEngine &Diags,
82 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
83 : ItaniumMangleContext(Context, Diags, IsAux),
84 DiscriminatorOverride(DiscriminatorOverride) {}
89 bool shouldMangleCXXName(
const NamedDecl *D)
override;
90 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
95 void needsUniqueInternalLinkageNames()
override {
96 NeedsUniqueInternalLinkageNames =
true;
99 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
100 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
101 raw_ostream &)
override;
103 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
104 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
105 raw_ostream &)
override;
106 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
107 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
108 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
109 const CXXRecordDecl *
Type, raw_ostream &)
override;
110 void mangleCXXRTTI(QualType
T, raw_ostream &)
override;
111 void mangleCXXRTTIName(QualType
T, raw_ostream &,
112 bool NormalizeIntegers)
override;
113 void mangleCanonicalTypeName(QualType
T, raw_ostream &,
114 bool NormalizeIntegers)
override;
116 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
117 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
118 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
119 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
120 void mangleDynamicAtExitDestructor(
const VarDecl *D,
121 raw_ostream &Out)
override;
122 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
123 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
124 raw_ostream &Out)
override;
125 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
126 raw_ostream &Out)
override;
127 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
128 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
129 raw_ostream &)
override;
131 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
133 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
135 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
137 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
143 if (
const TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
144 if (
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
150 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
151 if (discriminator == 1)
153 disc = discriminator - 2;
158 unsigned &discriminator = Uniquifier[ND];
159 if (!discriminator) {
160 const DeclContext *DC = getEffectiveDeclContext(ND);
161 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
163 if (discriminator == 1)
165 disc = discriminator-2;
169 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
172 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
173 std::string Name(
"<lambda");
177 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
178 const FunctionDecl *
Func =
182 unsigned DefaultArgNo =
184 Name += llvm::utostr(DefaultArgNo);
188 if (LambdaManglingNumber)
189 LambdaId = LambdaManglingNumber;
191 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
193 Name += llvm::utostr(LambdaId);
198 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
199 return DiscriminatorOverride;
202 NamespaceDecl *getStdNamespace();
204 const DeclContext *getEffectiveDeclContext(
const Decl *D);
205 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
206 return getEffectiveDeclContext(
cast<Decl>(DC));
209 bool isInternalLinkageDecl(
const NamedDecl *ND);
215class CXXNameMangler {
216 ItaniumMangleContextImpl &Context;
220 bool NormalizeIntegers =
false;
222 bool NullOut =
false;
227 bool DisableDerivedAbiTags =
false;
232 const NamedDecl *Structor;
233 unsigned StructorType = 0;
238 unsigned TemplateDepthOffset = 0;
243 class FunctionTypeDepthState {
246 enum { InResultTypeMask = 1 };
249 FunctionTypeDepthState() =
default;
252 unsigned getDepth()
const {
257 bool isInResultType()
const {
258 return Bits & InResultTypeMask;
261 FunctionTypeDepthState push() {
262 FunctionTypeDepthState tmp = *
this;
263 Bits = (Bits & ~InResultTypeMask) + 2;
267 void enterResultType() {
268 Bits |= InResultTypeMask;
271 void leaveResultType() {
272 Bits &= ~InResultTypeMask;
275 void pop(FunctionTypeDepthState saved) {
276 assert(getDepth() == saved.getDepth() + 1);
286 typedef SmallVector<StringRef, 4> AbiTagList;
291 class AbiTagState final {
293 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
299 AbiTagState(
const AbiTagState &) =
delete;
300 AbiTagState &operator=(
const AbiTagState &) =
delete;
302 ~AbiTagState() { pop(); }
304 void write(raw_ostream &Out,
const NamedDecl *ND,
305 const AbiTagList *AdditionalAbiTags) {
309 !AdditionalAbiTags &&
310 "only function and variables need a list of additional abi tags");
311 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
312 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
313 llvm::append_range(UsedAbiTags, AbiTag->tags());
320 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
321 llvm::append_range(UsedAbiTags, AbiTag->tags());
322 llvm::append_range(TagList, AbiTag->tags());
325 if (AdditionalAbiTags) {
326 llvm::append_range(UsedAbiTags, *AdditionalAbiTags);
327 llvm::append_range(TagList, *AdditionalAbiTags);
331 TagList.erase(llvm::unique(TagList), TagList.end());
333 writeSortedUniqueAbiTags(Out, TagList);
336 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
337 void setUsedAbiTags(
const AbiTagList &AbiTags) {
338 UsedAbiTags = AbiTags;
341 const AbiTagList &getEmittedAbiTags()
const {
342 return EmittedAbiTags;
345 const AbiTagList &getSortedUniqueUsedAbiTags() {
346 llvm::sort(UsedAbiTags);
347 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
353 AbiTagList UsedAbiTags;
355 AbiTagList EmittedAbiTags;
357 AbiTagState *&LinkHead;
358 AbiTagState *Parent =
nullptr;
361 assert(LinkHead ==
this &&
362 "abi tag link head must point to us on destruction");
364 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
365 UsedAbiTags.begin(), UsedAbiTags.end());
366 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
367 EmittedAbiTags.begin(),
368 EmittedAbiTags.end());
373 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
374 for (
const auto &Tag : AbiTags) {
375 EmittedAbiTags.push_back(Tag);
383 AbiTagState *AbiTags =
nullptr;
384 AbiTagState AbiTagsRoot;
386 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
387 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
389 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
391 bool isCompatibleWith(LangOptions::ClangABI Ver) {
392 return Context.getASTContext().getLangOpts().getClangABICompat() <= Ver;
395 bool isStd(
const NamespaceDecl *NS);
396 bool isStdNamespace(
const DeclContext *DC);
398 const RecordDecl *GetLocalClassDecl(
const Decl *D);
399 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
400 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
401 llvm::StringRef Name,
bool HasAllocator);
404 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
405 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
406 : Context(
C), Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
407 AbiTagsRoot(AbiTags) {
412 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
414 : Context(
C), Out(Out_), Structor(getStructor(D)), StructorType(
Type),
415 AbiTagsRoot(AbiTags) {}
416 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
418 : Context(
C), Out(Out_), Structor(getStructor(D)), StructorType(
Type),
419 AbiTagsRoot(AbiTags) {}
421 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
422 bool NormalizeIntegers_)
423 : Context(
C), Out(Out_), NormalizeIntegers(NormalizeIntegers_),
424 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
425 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
426 : Context(Outer.Context), Out(Out_), Structor(Outer.Structor),
427 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
428 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
429 Substitutions(Outer.Substitutions),
430 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
432 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
433 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
437 struct WithTemplateDepthOffset {
unsigned Offset; };
438 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
439 WithTemplateDepthOffset Offset)
440 : CXXNameMangler(
C, Out) {
441 TemplateDepthOffset = Offset.Offset;
444 raw_ostream &getStream() {
return Out; }
446 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
447 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
449 void mangle(GlobalDecl GD);
450 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
451 void mangleNumber(
const llvm::APSInt &I);
452 void mangleNumber(int64_t Number);
453 void mangleFloat(
const llvm::APFloat &F);
454 void mangleFunctionEncoding(GlobalDecl GD);
455 void mangleSeqID(
unsigned SeqID);
456 void mangleName(GlobalDecl GD);
457 void mangleType(QualType
T);
458 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
459 bool SuppressSubstitution =
false);
460 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
461 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
462 void mangleVendorQualifier(StringRef Name);
463 void mangleVendorType(StringRef Name);
466 bool mangleSubstitution(
const NamedDecl *ND);
467 bool mangleSubstitution(QualType
T);
473 bool mangleStandardSubstitution(
const NamedDecl *ND);
475 void addSubstitution(
const NamedDecl *ND) {
478 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
480 void addSubstitution(QualType
T);
484 void extendSubstitutions(CXXNameMangler*
Other);
486 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
487 bool recursive =
false);
488 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
489 const TemplateArgumentLoc *TemplateArgs,
490 unsigned NumTemplateArgs,
491 unsigned KnownArity = UnknownArity);
493 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
495 void mangleNameWithAbiTags(GlobalDecl GD,
496 const AbiTagList *AdditionalAbiTags);
497 void mangleModuleName(
const NamedDecl *ND);
498 void mangleTemplateName(
const TemplateDecl *TD,
499 ArrayRef<TemplateArgument> Args);
500 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
501 const AbiTagList *AdditionalAbiTags) {
503 UnknownArity, AdditionalAbiTags);
505 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
506 const DeclContext *DC,
unsigned KnownArity,
507 const AbiTagList *AdditionalAbiTags);
508 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
509 const AbiTagList *AdditionalAbiTags);
510 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
511 const AbiTagList *AdditionalAbiTags);
512 void mangleSourceName(
const IdentifierInfo *II);
513 void mangleRegCallName(
const IdentifierInfo *II);
514 void mangleDeviceStubName(
const IdentifierInfo *II);
515 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
516 void mangleSourceNameWithAbiTags(
517 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags =
nullptr);
518 void mangleLocalName(GlobalDecl GD,
519 const AbiTagList *AdditionalAbiTags);
520 void mangleBlockForPrefix(
const BlockDecl *
Block);
521 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
522 void mangleTemplateParamDecl(
const NamedDecl *Decl);
523 void mangleTemplateParameterList(
const TemplateParameterList *Params);
524 void mangleTypeConstraint(
const TemplateDecl *
Concept,
525 ArrayRef<TemplateArgument> Arguments);
526 void mangleTypeConstraint(
const TypeConstraint *Constraint);
527 void mangleRequiresClause(
const Expr *RequiresClause);
528 void mangleLambda(
const CXXRecordDecl *Lambda);
529 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
530 const AbiTagList *AdditionalAbiTags,
531 bool NoFunction=
false);
532 void mangleNestedName(
const TemplateDecl *TD,
533 ArrayRef<TemplateArgument> Args);
534 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
535 const NamedDecl *PrefixND,
536 const AbiTagList *AdditionalAbiTags);
537 void manglePrefix(NestedNameSpecifier Qualifier);
538 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
539 void manglePrefix(QualType
type);
540 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
542 const NamedDecl *getClosurePrefix(
const Decl *ND);
543 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
544 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
545 StringRef Prefix =
"");
546 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
548 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
554#define ABSTRACT_TYPE(CLASS, PARENT)
555#define NON_CANONICAL_TYPE(CLASS, PARENT)
556#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
557#include "clang/AST/TypeNodes.inc"
559 void mangleType(
const TagType*);
561 static StringRef getCallingConvQualifierName(
CallingConv CC);
564 void mangleSMEAttrs(
unsigned SMEAttrs);
569 void mangleAArch64NeonVectorType(
const VectorType *
T);
571 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
573 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
577 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
578 void mangleFixedPointLiteral();
581 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
582 void mangleMemberExpr(
const Expr *base,
bool isArrow,
586 unsigned NumTemplateArgs,
unsigned knownArity);
587 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
588 void mangleInitListElements(
const InitListExpr *InitList);
591 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
592 bool AsTemplateArg =
false);
596 struct TemplateArgManglingInfo;
599 unsigned NumTemplateArgs);
602 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
605 void mangleTemplateArgExpr(
const Expr *E);
607 bool NeedExactType =
false);
609 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
614 const AbiTagList *AdditionalAbiTags);
617 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
619 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
627 getASTContext(), getASTContext().getTranslationUnitDecl(),
628 false, SourceLocation(), SourceLocation(),
629 &getASTContext().Idents.get(
"std"),
639ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
646 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
648 if (ParmVarDecl *ContextParam =
649 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
650 return ContextParam->getDeclContext();
654 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
655 if (ParmVarDecl *ContextParam =
656 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
657 return ContextParam->getDeclContext();
665 if (D == getASTContext().getVaListTagDecl()) {
666 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
667 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
668 return getStdNamespace();
674 return getEffectiveDeclContext(
cast<Decl>(DC));
677 if (
const auto *VD = dyn_cast<VarDecl>(D))
679 return getASTContext().getTranslationUnitDecl();
681 if (
const auto *FD = getASTContext().getLangOpts().getClangABICompat() >
682 LangOptions::ClangABI::Ver19
684 : dyn_cast<FunctionDecl>(D)) {
686 return getASTContext().getTranslationUnitDecl();
689 if (FD->isMemberLikeConstrainedFriend() &&
690 getASTContext().getLangOpts().getClangABICompat() >
691 LangOptions::ClangABI::Ver17)
698bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
701 getEffectiveDeclContext(ND)->isFileContext() &&
708bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
709 const NamedDecl *ND) {
710 if (!NeedsUniqueInternalLinkageNames || !ND)
713 const auto *FD = dyn_cast<FunctionDecl>(ND);
719 if (!FD->getType()->getAs<FunctionProtoType>())
722 if (isInternalLinkageDecl(ND))
728bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
729 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
732 if (FD->hasAttr<OverloadableAttr>())
748 if (FD->isMSVCRTEntryPoint())
762 if (!getASTContext().getLangOpts().
CPlusPlus)
765 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
776 const DeclContext *DC = getEffectiveDeclContext(D);
780 DC = getEffectiveParentContext(DC);
782 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
784 !VD->getOwningModuleForLinkage())
791void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
792 const AbiTagList *AdditionalAbiTags) {
793 assert(AbiTags &&
"require AbiTagState");
794 AbiTags->write(Out, ND, DisableDerivedAbiTags ?
nullptr : AdditionalAbiTags);
797void CXXNameMangler::mangleSourceNameWithAbiTags(
798 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags) {
800 writeAbiTags(ND, AdditionalAbiTags);
803void CXXNameMangler::mangle(GlobalDecl GD) {
809 mangleFunctionEncoding(GD);
810 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
813 else if (
const IndirectFieldDecl *IFD =
814 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
815 mangleName(IFD->getAnonField());
817 llvm_unreachable(
"unexpected kind of global decl");
820void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
825 if (!Context.shouldMangleDeclName(FD)) {
830 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
831 if (ReturnTypeAbiTags.empty()) {
840 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
842 FunctionTypeDepth.pop(Saved);
843 mangleFunctionEncodingBareType(FD);
850 SmallString<256> FunctionEncodingBuf;
851 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
852 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
854 FunctionEncodingMangler.disableDerivedAbiTags();
856 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
857 FunctionEncodingMangler.mangleNameWithAbiTags(FD,
nullptr);
858 FunctionTypeDepth.pop(Saved);
861 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
862 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
866 const AbiTagList &UsedAbiTags =
867 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
868 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
869 AdditionalAbiTags.erase(
870 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
871 UsedAbiTags.begin(), UsedAbiTags.end(),
872 AdditionalAbiTags.begin()),
873 AdditionalAbiTags.end());
876 Saved = FunctionTypeDepth.push();
877 mangleNameWithAbiTags(FD, &AdditionalAbiTags);
878 FunctionTypeDepth.pop(Saved);
879 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
883 extendSubstitutions(&FunctionEncodingMangler);
886void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
887 if (FD->
hasAttr<EnableIfAttr>()) {
888 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
889 Out <<
"Ua9enable_ifI";
890 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
893 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
896 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
901 mangleExpression(EIA->getCond());
904 mangleTemplateArgExpr(EIA->getCond());
908 FunctionTypeDepth.pop(Saved);
913 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
914 if (
auto Inherited = CD->getInheritedConstructor())
915 FD = Inherited.getConstructor();
933 bool MangleReturnType =
false;
937 MangleReturnType =
true;
940 FD = PrimaryTemplate->getTemplatedDecl();
943 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
944 MangleReturnType, FD);
948bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
949 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
953 return II && II->
isStr(
"std");
958bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
965static const GlobalDecl
969 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
978 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
979 TemplateArgs = &Spec->getTemplateArgs();
980 return GD.
getWithDecl(Spec->getSpecializedTemplate());
985 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
986 TemplateArgs = &Spec->getTemplateArgs();
987 return GD.
getWithDecl(Spec->getSpecializedTemplate());
998void CXXNameMangler::mangleName(GlobalDecl GD) {
1000 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1002 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1003 if (VariableTypeAbiTags.empty()) {
1005 mangleNameWithAbiTags(VD,
nullptr);
1010 llvm::raw_null_ostream NullOutStream;
1011 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1012 VariableNameMangler.disableDerivedAbiTags();
1013 VariableNameMangler.mangleNameWithAbiTags(VD,
nullptr);
1016 const AbiTagList &UsedAbiTags =
1017 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1018 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1019 AdditionalAbiTags.erase(
1020 std::set_difference(VariableTypeAbiTags.begin(),
1021 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1022 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1023 AdditionalAbiTags.end());
1026 mangleNameWithAbiTags(VD, &AdditionalAbiTags);
1028 mangleNameWithAbiTags(GD,
nullptr);
1032const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1033 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1035 if (isLocalContainerContext(DC))
1036 return dyn_cast<RecordDecl>(D);
1038 DC = Context.getEffectiveDeclContext(D);
1043void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
1044 const AbiTagList *AdditionalAbiTags) {
1051 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1052 bool IsLambda = isLambda(ND);
1058 if (isLocalContainerContext(DC) && ND->
hasLinkage() && !IsLambda)
1060 DC = Context.getEffectiveParentContext(DC);
1061 else if (GetLocalClassDecl(ND) &&
1062 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1063 mangleLocalName(GD, AdditionalAbiTags);
1071 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1072 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1076 if (isLocalContainerContext(DC)) {
1077 mangleLocalName(GD, AdditionalAbiTags);
1086 const TemplateArgumentList *TemplateArgs =
nullptr;
1087 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1088 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1093 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1097 mangleNestedName(GD, DC, AdditionalAbiTags);
1100void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1103 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1111void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1113 auto It = ModuleSubstitutions.find(Name);
1114 if (It != ModuleSubstitutions.end()) {
1116 mangleSeqID(It->second);
1122 auto Parts = Name.rsplit(
'.');
1123 if (Parts.second.empty())
1124 Parts.second = Parts.first;
1126 mangleModuleNamePrefix(Parts.first, IsPartition);
1127 IsPartition =
false;
1133 Out << Parts.second.size() << Parts.second;
1134 ModuleSubstitutions.insert({Name, SeqID++});
1137void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1138 ArrayRef<TemplateArgument> Args) {
1139 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1142 mangleUnscopedTemplateName(TD, DC,
nullptr);
1145 mangleNestedName(TD, Args);
1149void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1150 const AbiTagList *AdditionalAbiTags) {
1155 if (isStdNamespace(DC)) {
1156 if (getASTContext().getTargetInfo().getTriple().isOSSolaris()) {
1158 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1163 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1165 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1175 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1178void CXXNameMangler::mangleUnscopedTemplateName(
1179 GlobalDecl GD,
const DeclContext *DC,
const AbiTagList *AdditionalAbiTags) {
1183 if (mangleSubstitution(ND))
1187 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1188 assert(!AdditionalAbiTags &&
1189 "template template param cannot have abi tags");
1190 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1192 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1198 addSubstitution(ND);
1201void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1215 llvm::APInt valueBits = f.bitcastToAPInt();
1216 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1217 assert(numCharacters != 0);
1220 SmallVector<char, 20> buffer(numCharacters);
1223 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1225 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1228 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1229 hexDigit >>= (digitBitIndex % 64);
1233 static const char charForHex[16] = {
1234 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1235 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1237 buffer[stringIndex] = charForHex[hexDigit];
1240 Out.write(buffer.data(), numCharacters);
1243void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1250void CXXNameMangler::mangleFixedPointLiteral() {
1251 DiagnosticsEngine &Diags = Context.getDiags();
1257void CXXNameMangler::mangleNullPointer(QualType
T) {
1264void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1265 if (
Value.isSigned() &&
Value.isNegative()) {
1267 Value.abs().print(Out,
false);
1269 Value.print(Out,
false);
1273void CXXNameMangler::mangleNumber(int64_t Number) {
1283void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1291 mangleNumber(NonVirtual);
1297 mangleNumber(NonVirtual);
1303void CXXNameMangler::manglePrefix(QualType
type) {
1304 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1305 if (!mangleSubstitution(QualType(TST, 0))) {
1306 mangleTemplatePrefix(TST->getTemplateName());
1311 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1312 addSubstitution(QualType(TST, 0));
1314 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1316 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1317 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1322 assert(DNT->getQualifier());
1323 manglePrefix(DNT->getQualifier());
1325 mangleSourceName(DNT->getIdentifier());
1328 addSubstitution(QualType(DNT, 0));
1340void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1358 case NestedNameSpecifier::Kind::Null:
1359 llvm_unreachable(
"unexpected null nested name specifier");
1361 case NestedNameSpecifier::Kind::Global:
1371 case NestedNameSpecifier::Kind::MicrosoftSuper:
1372 llvm_unreachable(
"Can't mangle __super specifier");
1374 case NestedNameSpecifier::Kind::Namespace: {
1377 mangleUnresolvedPrefix(Prefix,
1381 mangleSourceNameWithAbiTags(Namespace);
1385 case NestedNameSpecifier::Kind::Type: {
1393 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1394 mangleUnresolvedPrefix(Prefix,
1401 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1416void CXXNameMangler::mangleUnresolvedName(
1417 NestedNameSpecifier Qualifier, DeclarationName name,
1418 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1419 unsigned knownArity) {
1421 mangleUnresolvedPrefix(Qualifier);
1422 switch (
name.getNameKind()) {
1425 mangleSourceName(
name.getAsIdentifierInfo());
1430 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1437 mangleOperatorName(name, knownArity);
1440 llvm_unreachable(
"Can't mangle a constructor name!");
1442 llvm_unreachable(
"Can't mangle a using directive name!");
1444 llvm_unreachable(
"Can't mangle a deduction guide name!");
1448 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1454 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1457void CXXNameMangler::mangleUnqualifiedName(
1458 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1459 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1460 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1467 mangleModuleName(ND);
1471 auto *FD = dyn_cast<FunctionDecl>(ND);
1472 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1474 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1475 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1479 unsigned Arity = KnownArity;
1485 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1492 for (
auto *BD : DD->bindings())
1493 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1495 writeAbiTags(ND, AdditionalAbiTags);
1499 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1502 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1503 llvm::raw_svector_ostream GUIDOS(GUID);
1504 Context.mangleMSGuidDecl(GD, GUIDOS);
1505 Out << GUID.size() << GUID;
1509 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1512 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1513 TPO->getValue(),
true);
1531 if (Context.isInternalLinkageDecl(ND))
1534 bool IsRegCall = FD &&
1538 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1540 bool IsOCLDeviceStub =
1542 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1545 mangleDeviceStubName(II);
1546 else if (IsOCLDeviceStub)
1547 mangleOCLDeviceStubName(II);
1549 mangleRegCallName(II);
1551 mangleSourceName(II);
1553 writeAbiTags(ND, AdditionalAbiTags);
1558 assert(ND &&
"mangling empty name without declaration");
1560 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1563 Out <<
"12_GLOBAL__N_1";
1568 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1570 const auto *RD = VD->getType()->castAsRecordDecl();
1581 assert(RD->isAnonymousStructOrUnion()
1582 &&
"Expected anonymous struct or union!");
1583 const FieldDecl *FD = RD->findFirstNamedDataMember();
1589 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1609 "Typedef should not be in another decl context!");
1610 assert(D->getDeclName().getAsIdentifierInfo() &&
1611 "Typedef was not named!");
1612 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1613 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1616 writeAbiTags(TD,
nullptr);
1625 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1626 UnsignedOrNone DeviceNumber =
1627 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1633 if (
Record->isLambda() &&
1634 ((DeviceNumber && *DeviceNumber > 0) ||
1635 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1636 assert(!AdditionalAbiTags &&
1637 "Lambda type cannot have additional abi tags");
1644 unsigned UnnamedMangle =
1645 getASTContext().getManglingNumber(TD, Context.isAux());
1647 if (UnnamedMangle > 1)
1648 Out << UnnamedMangle - 2;
1650 writeAbiTags(TD, AdditionalAbiTags);
1656 unsigned AnonStructId =
1658 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1665 Str += llvm::utostr(AnonStructId);
1675 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1678 const CXXRecordDecl *InheritedFrom =
nullptr;
1680 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1681 if (
auto Inherited =
1683 InheritedFrom = Inherited.getConstructor()->
getParent();
1684 InheritedTemplateName =
1685 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1686 InheritedTemplateArgs =
1687 Inherited.getConstructor()->getTemplateSpecializationArgs();
1693 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1701 if (InheritedTemplateArgs)
1702 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1704 writeAbiTags(ND, AdditionalAbiTags);
1712 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1718 writeAbiTags(ND, AdditionalAbiTags);
1722 if (ND && Arity == UnknownArity) {
1726 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1727 if (MD->isImplicitObjectMemberFunction())
1733 mangleOperatorName(Name, Arity);
1734 writeAbiTags(ND, AdditionalAbiTags);
1738 llvm_unreachable(
"Can't mangle a deduction guide name!");
1741 llvm_unreachable(
"Can't mangle a using directive name!");
1745void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1749 if (getASTContext().getLangOpts().RegCall4)
1750 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1753 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1757void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1761 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1765void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1769 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1770 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1771 << OCLDeviceStubNamePrefix << II->
getName();
1774void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1781void CXXNameMangler::mangleNestedName(GlobalDecl GD,
1782 const DeclContext *DC,
1783 const AbiTagList *AdditionalAbiTags,
1792 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1793 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1796 if (
Method->isExplicitObjectMemberFunction())
1799 mangleQualifiers(MethodQuals);
1800 mangleRefQualifier(
Method->getRefQualifier());
1804 const TemplateArgumentList *TemplateArgs =
nullptr;
1805 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1806 mangleTemplatePrefix(TD, NoFunction);
1809 manglePrefix(DC, NoFunction);
1810 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1815void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1816 ArrayRef<TemplateArgument> Args) {
1821 mangleTemplatePrefix(TD);
1827void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1828 GlobalDecl GD,
const NamedDecl *PrefixND,
1829 const AbiTagList *AdditionalAbiTags) {
1838 mangleClosurePrefix(PrefixND);
1839 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1850 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1852 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1859void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1860 const AbiTagList *AdditionalAbiTags) {
1868 const RecordDecl *RD = GetLocalClassDecl(D);
1869 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1874 AbiTagState LocalAbiTags(AbiTags);
1876 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
1878 else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
1879 mangleBlockForPrefix(BD);
1885 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1899 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1901 if (
const ParmVarDecl *Parm
1903 if (
const FunctionDecl *
Func
1908 mangleNumber(
Num - 2);
1917 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1918 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1919 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1920 mangleClosurePrefix(PrefixND,
true );
1922 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1923 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1924 mangleUnqualifiedBlock(BD);
1927 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1928 AdditionalAbiTags,
true );
1930 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1933 if (
const ParmVarDecl *Parm
1934 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1935 if (
const FunctionDecl *
Func
1940 mangleNumber(
Num - 2);
1945 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1946 mangleUnqualifiedBlock(BD);
1948 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1951 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1953 if (Context.getNextDiscriminator(ND, disc)) {
1957 Out <<
"__" << disc <<
'_';
1962void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1963 if (GetLocalClassDecl(
Block)) {
1964 mangleLocalName(
Block,
nullptr);
1967 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
1968 if (isLocalContainerContext(DC)) {
1969 mangleLocalName(
Block,
nullptr);
1972 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
1973 mangleClosurePrefix(PrefixND);
1976 mangleUnqualifiedBlock(
Block);
1979void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
1982 if (Decl *Context =
Block->getBlockManglingContextDecl()) {
1983 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
1985 Context->getDeclContext()->isRecord()) {
1988 mangleSourceNameWithAbiTags(ND);
1995 unsigned Number =
Block->getBlockManglingNumber();
1999 Number = Context.getBlockId(
Block,
false);
2017void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2019 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2020 if (Ty->isParameterPack())
2022 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2023 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2026 mangleTypeConstraint(Constraint);
2030 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2031 if (Tn->isExpandedParameterPack()) {
2032 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2034 mangleType(Tn->getExpansionType(I));
2037 QualType
T = Tn->getType();
2038 if (Tn->isParameterPack()) {
2040 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2041 T = PackExpansion->getPattern();
2046 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2047 if (Tt->isExpandedParameterPack()) {
2048 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2050 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2052 if (Tt->isParameterPack())
2054 mangleTemplateParameterList(Tt->getTemplateParameters());
2059void CXXNameMangler::mangleTemplateParameterList(
2060 const TemplateParameterList *Params) {
2062 for (
auto *Param : *Params)
2063 mangleTemplateParamDecl(Param);
2064 mangleRequiresClause(Params->getRequiresClause());
2068void CXXNameMangler::mangleTypeConstraint(
2069 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2070 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2072 mangleTemplateName(
Concept, Arguments);
2074 mangleUnscopedName(
Concept, DC,
nullptr);
2076 mangleNestedName(
Concept, DC,
nullptr);
2079void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2080 llvm::SmallVector<TemplateArgument, 8> Args;
2082 for (
const TemplateArgumentLoc &ArgLoc :
2084 Args.push_back(ArgLoc.getArgument());
2089void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2091 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2093 mangleExpression(RequiresClause);
2097void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2101 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2104 if (
const IdentifierInfo *Name
2106 mangleSourceName(Name);
2107 const TemplateArgumentList *TemplateArgs =
nullptr;
2116 mangleLambdaSig(Lambda);
2130 UnsignedOrNone DeviceNumber =
2131 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2135 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2137 mangleNumber(Number - 2);
2141void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2144 mangleTemplateParamDecl(D);
2148 mangleRequiresClause(TPL->getRequiresClause());
2152 mangleBareFunctionType(Proto,
false,
2156void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2158 case NestedNameSpecifier::Kind::Null:
2159 case NestedNameSpecifier::Kind::Global:
2163 case NestedNameSpecifier::Kind::MicrosoftSuper:
2164 llvm_unreachable(
"Can't mangle __super specifier");
2166 case NestedNameSpecifier::Kind::Namespace:
2167 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2170 case NestedNameSpecifier::Kind::Type:
2171 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2175 llvm_unreachable(
"unexpected nested name specifier");
2178void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2191 if (NoFunction && isLocalContainerContext(DC))
2195 if (mangleSubstitution(ND))
2199 const TemplateArgumentList *TemplateArgs =
nullptr;
2200 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2201 mangleTemplatePrefix(TD);
2203 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2204 mangleClosurePrefix(PrefixND, NoFunction);
2205 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2207 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2208 manglePrefix(DC, NoFunction);
2209 mangleUnqualifiedName(ND, DC,
nullptr);
2212 addSubstitution(ND);
2219 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2220 return mangleTemplatePrefix(TD);
2223 assert(
Dependent &&
"unexpected template name kind");
2227 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2228 if (!Clang11Compat && mangleSubstitution(
Template))
2231 manglePrefix(
Dependent->getQualifier());
2233 if (Clang11Compat && mangleSubstitution(
Template))
2236 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2237 const IdentifierInfo *Id = Name.getIdentifier())
2238 mangleSourceName(Id);
2240 mangleOperatorName(Name.getOperator(), UnknownArity);
2245void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2254 if (mangleSubstitution(ND))
2258 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2259 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2261 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2262 manglePrefix(DC, NoFunction);
2264 mangleUnqualifiedName(GD, DC,
nullptr);
2270 addSubstitution(ND);
2273const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2274 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2277 const NamedDecl *Context =
nullptr;
2278 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2279 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2280 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2282 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2296void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2299 if (mangleSubstitution(ND))
2302 const TemplateArgumentList *TemplateArgs =
nullptr;
2303 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2304 mangleTemplatePrefix(TD, NoFunction);
2307 const auto *DC = Context.getEffectiveDeclContext(ND);
2308 manglePrefix(DC, NoFunction);
2309 mangleUnqualifiedName(ND, DC,
nullptr);
2314 addSubstitution(ND);
2323 if (mangleSubstitution(TN))
2326 TemplateDecl *TD =
nullptr;
2336 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2337 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2344 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2353 mangleUnresolvedPrefix(
Dependent->getQualifier());
2354 mangleSourceName(II);
2363 SubstTemplateTemplateParmStorage *subst
2374 Out <<
"_SUBSTPACK_";
2378 llvm_unreachable(
"Unexpected DeducedTemplate");
2381 addSubstitution(TN);
2384bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2390 case Type::Adjusted:
2392 case Type::ArrayParameter:
2394 case Type::BlockPointer:
2395 case Type::LValueReference:
2396 case Type::RValueReference:
2397 case Type::MemberPointer:
2398 case Type::ConstantArray:
2399 case Type::IncompleteArray:
2400 case Type::VariableArray:
2401 case Type::DependentSizedArray:
2402 case Type::DependentAddressSpace:
2403 case Type::DependentVector:
2404 case Type::DependentSizedExtVector:
2406 case Type::ExtVector:
2407 case Type::ConstantMatrix:
2408 case Type::DependentSizedMatrix:
2409 case Type::FunctionProto:
2410 case Type::FunctionNoProto:
2412 case Type::Attributed:
2413 case Type::BTFTagAttributed:
2414 case Type::HLSLAttributedResource:
2415 case Type::HLSLInlineSpirv:
2417 case Type::DeducedTemplateSpecialization:
2418 case Type::PackExpansion:
2419 case Type::ObjCObject:
2420 case Type::ObjCInterface:
2421 case Type::ObjCObjectPointer:
2422 case Type::ObjCTypeParam:
2425 case Type::MacroQualified:
2427 case Type::DependentBitInt:
2428 case Type::CountAttributed:
2429 llvm_unreachable(
"type is illegal as a nested name specifier");
2431 case Type::SubstBuiltinTemplatePack:
2436 Out <<
"_SUBSTBUILTINPACK_";
2438 case Type::SubstTemplateTypeParmPack:
2443 Out <<
"_SUBSTPACK_";
2450 case Type::TypeOfExpr:
2452 case Type::Decltype:
2453 case Type::PackIndexing:
2454 case Type::TemplateTypeParm:
2455 case Type::UnaryTransform:
2468 case Type::SubstTemplateTypeParm: {
2472 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2474 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2475 goto unresolvedType;
2482 case Type::PredefinedSugar:
2486 case Type::UnresolvedUsing:
2487 mangleSourceNameWithAbiTags(
2493 mangleSourceNameWithAbiTags(
2497 case Type::TemplateSpecialization: {
2498 const TemplateSpecializationType *TST =
2508 assert(TD &&
"no template for template specialization type");
2510 goto unresolvedType;
2512 mangleSourceNameWithAbiTags(TD);
2524 llvm_unreachable(
"invalid base for a template specialization type");
2527 SubstTemplateTemplateParmStorage *subst =
2538 Out <<
"_SUBSTPACK_";
2544 mangleSourceNameWithAbiTags(TD);
2554 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2558 case Type::InjectedClassName:
2559 mangleSourceNameWithAbiTags(
2563 case Type::DependentName:
2575void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2585 llvm_unreachable(
"Not an operator name");
2608 case OO_New:
Out <<
"nw";
break;
2610 case OO_Array_New:
Out <<
"na";
break;
2612 case OO_Delete:
Out <<
"dl";
break;
2614 case OO_Array_Delete:
Out <<
"da";
break;
2618 Out << (Arity == 1?
"ps" :
"pl");
break;
2622 Out << (Arity == 1?
"ng" :
"mi");
break;
2626 Out << (Arity == 1?
"ad" :
"an");
break;
2631 Out << (Arity == 1?
"de" :
"ml");
break;
2633 case OO_Tilde:
Out <<
"co";
break;
2635 case OO_Slash:
Out <<
"dv";
break;
2637 case OO_Percent:
Out <<
"rm";
break;
2639 case OO_Pipe:
Out <<
"or";
break;
2641 case OO_Caret:
Out <<
"eo";
break;
2643 case OO_Equal:
Out <<
"aS";
break;
2645 case OO_PlusEqual:
Out <<
"pL";
break;
2647 case OO_MinusEqual:
Out <<
"mI";
break;
2649 case OO_StarEqual:
Out <<
"mL";
break;
2651 case OO_SlashEqual:
Out <<
"dV";
break;
2653 case OO_PercentEqual:
Out <<
"rM";
break;
2655 case OO_AmpEqual:
Out <<
"aN";
break;
2657 case OO_PipeEqual:
Out <<
"oR";
break;
2659 case OO_CaretEqual:
Out <<
"eO";
break;
2661 case OO_LessLess:
Out <<
"ls";
break;
2663 case OO_GreaterGreater:
Out <<
"rs";
break;
2665 case OO_LessLessEqual:
Out <<
"lS";
break;
2667 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2669 case OO_EqualEqual:
Out <<
"eq";
break;
2671 case OO_ExclaimEqual:
Out <<
"ne";
break;
2673 case OO_Less:
Out <<
"lt";
break;
2675 case OO_Greater:
Out <<
"gt";
break;
2677 case OO_LessEqual:
Out <<
"le";
break;
2679 case OO_GreaterEqual:
Out <<
"ge";
break;
2681 case OO_Exclaim:
Out <<
"nt";
break;
2683 case OO_AmpAmp:
Out <<
"aa";
break;
2685 case OO_PipePipe:
Out <<
"oo";
break;
2687 case OO_PlusPlus:
Out <<
"pp";
break;
2689 case OO_MinusMinus:
Out <<
"mm";
break;
2691 case OO_Comma:
Out <<
"cm";
break;
2693 case OO_ArrowStar:
Out <<
"pm";
break;
2695 case OO_Arrow:
Out <<
"pt";
break;
2697 case OO_Call:
Out <<
"cl";
break;
2699 case OO_Subscript:
Out <<
"ix";
break;
2704 case OO_Conditional:
Out <<
"qu";
break;
2707 case OO_Coawait:
Out <<
"aw";
break;
2710 case OO_Spaceship:
Out <<
"ss";
break;
2714 llvm_unreachable(
"Not an overloaded operator");
2718void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2737 SmallString<64> ASString;
2743 if (TargetAS != 0 ||
2745 ASString =
"AS" + llvm::utostr(TargetAS);
2748 default: llvm_unreachable(
"Not a language specific address space");
2752 case LangAS::opencl_global:
2753 ASString =
"CLglobal";
2755 case LangAS::opencl_global_device:
2756 ASString =
"CLdevice";
2758 case LangAS::opencl_global_host:
2759 ASString =
"CLhost";
2761 case LangAS::opencl_local:
2762 ASString =
"CLlocal";
2764 case LangAS::opencl_constant:
2765 ASString =
"CLconstant";
2767 case LangAS::opencl_private:
2768 ASString =
"CLprivate";
2770 case LangAS::opencl_generic:
2771 ASString =
"CLgeneric";
2775 case LangAS::sycl_global:
2776 ASString =
"SYglobal";
2778 case LangAS::sycl_global_device:
2779 ASString =
"SYdevice";
2781 case LangAS::sycl_global_host:
2782 ASString =
"SYhost";
2784 case LangAS::sycl_local:
2785 ASString =
"SYlocal";
2787 case LangAS::sycl_private:
2788 ASString =
"SYprivate";
2791 case LangAS::cuda_device:
2792 ASString =
"CUdevice";
2794 case LangAS::cuda_constant:
2795 ASString =
"CUconstant";
2797 case LangAS::cuda_shared:
2798 ASString =
"CUshared";
2801 case LangAS::ptr32_sptr:
2802 ASString =
"ptr32_sptr";
2804 case LangAS::ptr32_uptr:
2808 if (!getASTContext().getTargetInfo().getTriple().isOSzOS())
2809 ASString =
"ptr32_uptr";
2816 if (!ASString.empty())
2817 mangleVendorQualifier(ASString);
2830 mangleVendorQualifier(
"__weak");
2834 mangleVendorQualifier(
"__unaligned");
2838 mangleVendorQualifier(
"__ptrauth");
2848 << unsigned(PtrAuth.isAddressDiscriminated())
2851 << PtrAuth.getExtraDiscriminator()
2866 mangleVendorQualifier(
"__strong");
2870 mangleVendorQualifier(
"__autoreleasing");
2893void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2897void CXXNameMangler::mangleVendorType(StringRef name) {
2904 switch (RefQualifier) {
2918void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2919 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2932 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2938 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2944 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
2945 if (DeducedTST->getDeducedType().isNull())
2950void CXXNameMangler::mangleType(QualType
T) {
2984 T =
T.getCanonicalType();
2990 if (
const TemplateSpecializationType *TST
2991 = dyn_cast<TemplateSpecializationType>(
T))
2992 if (!TST->isTypeAlias())
3000 =
T.getSingleStepDesugaredType(Context.getASTContext());
3007 SplitQualType split =
T.split();
3008 Qualifiers quals = split.
Quals;
3009 const Type *ty = split.
Ty;
3011 bool isSubstitutable =
3013 if (isSubstitutable && mangleSubstitution(
T))
3020 quals = Qualifiers();
3027 if (
const DependentAddressSpaceType *DAST =
3028 dyn_cast<DependentAddressSpaceType>(ty)) {
3030 mangleQualifiers(splitDAST.
Quals, DAST);
3031 mangleType(QualType(splitDAST.
Ty, 0));
3033 mangleQualifiers(quals);
3037 mangleType(QualType(ty, 0));
3041#define ABSTRACT_TYPE(CLASS, PARENT)
3042#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3044 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3046#define TYPE(CLASS, PARENT) \
3048 mangleType(static_cast<const CLASS##Type*>(ty)); \
3050#include "clang/AST/TypeNodes.inc"
3055 if (isSubstitutable)
3059void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3060 bool SuppressSubstitution) {
3061 if (mangleSubstitution(
Record))
3064 if (SuppressSubstitution)
3069void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3111 std::string type_name;
3115 if (NormalizeIntegers &&
T->isInteger()) {
3116 if (
T->isSignedInteger()) {
3117 switch (getASTContext().getTypeSize(
T)) {
3121 if (mangleSubstitution(BuiltinType::SChar))
3124 addSubstitution(BuiltinType::SChar);
3127 if (mangleSubstitution(BuiltinType::Short))
3130 addSubstitution(BuiltinType::Short);
3133 if (mangleSubstitution(BuiltinType::Int))
3136 addSubstitution(BuiltinType::Int);
3139 if (mangleSubstitution(BuiltinType::Long))
3142 addSubstitution(BuiltinType::Long);
3145 if (mangleSubstitution(BuiltinType::Int128))
3148 addSubstitution(BuiltinType::Int128);
3151 llvm_unreachable(
"Unknown integer size for normalization");
3154 switch (getASTContext().getTypeSize(
T)) {
3156 if (mangleSubstitution(BuiltinType::UChar))
3159 addSubstitution(BuiltinType::UChar);
3162 if (mangleSubstitution(BuiltinType::UShort))
3165 addSubstitution(BuiltinType::UShort);
3168 if (mangleSubstitution(BuiltinType::UInt))
3171 addSubstitution(BuiltinType::UInt);
3174 if (mangleSubstitution(BuiltinType::ULong))
3177 addSubstitution(BuiltinType::ULong);
3180 if (mangleSubstitution(BuiltinType::UInt128))
3183 addSubstitution(BuiltinType::UInt128);
3186 llvm_unreachable(
"Unknown integer size for normalization");
3191 switch (
T->getKind()) {
3192 case BuiltinType::Void:
3195 case BuiltinType::Bool:
3198 case BuiltinType::Char_U:
3199 case BuiltinType::Char_S:
3202 case BuiltinType::UChar:
3205 case BuiltinType::UShort:
3208 case BuiltinType::UInt:
3211 case BuiltinType::ULong:
3214 case BuiltinType::ULongLong:
3217 case BuiltinType::UInt128:
3220 case BuiltinType::SChar:
3223 case BuiltinType::WChar_S:
3224 case BuiltinType::WChar_U:
3227 case BuiltinType::Char8:
3230 case BuiltinType::Char16:
3233 case BuiltinType::Char32:
3236 case BuiltinType::Short:
3239 case BuiltinType::Int:
3242 case BuiltinType::Long:
3245 case BuiltinType::LongLong:
3248 case BuiltinType::Int128:
3251 case BuiltinType::Float16:
3254 case BuiltinType::ShortAccum:
3257 case BuiltinType::Accum:
3260 case BuiltinType::LongAccum:
3263 case BuiltinType::UShortAccum:
3266 case BuiltinType::UAccum:
3269 case BuiltinType::ULongAccum:
3272 case BuiltinType::ShortFract:
3275 case BuiltinType::Fract:
3278 case BuiltinType::LongFract:
3281 case BuiltinType::UShortFract:
3284 case BuiltinType::UFract:
3287 case BuiltinType::ULongFract:
3290 case BuiltinType::SatShortAccum:
3293 case BuiltinType::SatAccum:
3296 case BuiltinType::SatLongAccum:
3299 case BuiltinType::SatUShortAccum:
3302 case BuiltinType::SatUAccum:
3305 case BuiltinType::SatULongAccum:
3308 case BuiltinType::SatShortFract:
3311 case BuiltinType::SatFract:
3314 case BuiltinType::SatLongFract:
3317 case BuiltinType::SatUShortFract:
3320 case BuiltinType::SatUFract:
3323 case BuiltinType::SatULongFract:
3326 case BuiltinType::Half:
3329 case BuiltinType::Float:
3332 case BuiltinType::Double:
3335 case BuiltinType::LongDouble: {
3336 const TargetInfo *TI =
3337 getASTContext().getLangOpts().OpenMP &&
3338 getASTContext().getLangOpts().OpenMPIsTargetDevice
3339 ? getASTContext().getAuxTargetInfo()
3340 : &getASTContext().getTargetInfo();
3344 case BuiltinType::Float128: {
3345 const TargetInfo *TI =
3346 getASTContext().getLangOpts().OpenMP &&
3347 getASTContext().getLangOpts().OpenMPIsTargetDevice
3348 ? getASTContext().getAuxTargetInfo()
3349 : &getASTContext().getTargetInfo();
3353 case BuiltinType::BFloat16: {
3354 const TargetInfo *TI =
3355 ((getASTContext().getLangOpts().OpenMP &&
3356 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3357 getASTContext().getLangOpts().SYCLIsDevice)
3358 ? getASTContext().getAuxTargetInfo()
3359 : &getASTContext().getTargetInfo();
3363 case BuiltinType::Ibm128: {
3364 const TargetInfo *TI = &getASTContext().getTargetInfo();
3368 case BuiltinType::NullPtr:
3372#define BUILTIN_TYPE(Id, SingletonId)
3373#define PLACEHOLDER_TYPE(Id, SingletonId) \
3374 case BuiltinType::Id:
3375#include "clang/AST/BuiltinTypes.def"
3376 case BuiltinType::Dependent:
3378 llvm_unreachable(
"mangling a placeholder type");
3380 case BuiltinType::ObjCId:
3381 Out <<
"11objc_object";
3383 case BuiltinType::ObjCClass:
3384 Out <<
"10objc_class";
3386 case BuiltinType::ObjCSel:
3387 Out <<
"13objc_selector";
3389#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3390 case BuiltinType::Id: \
3391 type_name = "ocl_" #ImgType "_" #Suffix; \
3392 Out << type_name.size() << type_name; \
3394#include "clang/Basic/OpenCLImageTypes.def"
3395 case BuiltinType::OCLSampler:
3396 Out <<
"11ocl_sampler";
3398 case BuiltinType::OCLEvent:
3399 Out <<
"9ocl_event";
3401 case BuiltinType::OCLClkEvent:
3402 Out <<
"12ocl_clkevent";
3404 case BuiltinType::OCLQueue:
3405 Out <<
"9ocl_queue";
3407 case BuiltinType::OCLReserveID:
3408 Out <<
"13ocl_reserveid";
3410#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3411 case BuiltinType::Id: \
3412 type_name = "ocl_" #ExtType; \
3413 Out << type_name.size() << type_name; \
3415#include "clang/Basic/OpenCLExtensionTypes.def"
3419#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3420 case BuiltinType::Id: \
3421 if (T->getKind() == BuiltinType::SveBFloat16 && \
3422 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3424 mangleVendorType("__SVBFloat16_t"); \
3426 type_name = #MangledName; \
3427 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3430#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3431 case BuiltinType::Id: \
3432 type_name = #MangledName; \
3433 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3435#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3436 case BuiltinType::Id: \
3437 type_name = #MangledName; \
3438 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3440#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3441 case BuiltinType::Id: \
3442 type_name = #MangledName; \
3443 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3445#include "clang/Basic/AArch64ACLETypes.def"
3446#define PPC_VECTOR_TYPE(Name, Id, Size) \
3447 case BuiltinType::Id: \
3448 mangleVendorType(#Name); \
3450#include "clang/Basic/PPCTypes.def"
3452#define RVV_TYPE(Name, Id, SingletonId) \
3453 case BuiltinType::Id: \
3454 mangleVendorType(Name); \
3456#include "clang/Basic/RISCVVTypes.def"
3457#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3458 case BuiltinType::Id: \
3459 mangleVendorType(MangledName); \
3461#include "clang/Basic/WebAssemblyReferenceTypes.def"
3462#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3463 case BuiltinType::Id: \
3464 mangleVendorType(Name); \
3466#include "clang/Basic/AMDGPUTypes.def"
3467#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3468 case BuiltinType::Id: \
3469 mangleVendorType(#Name); \
3471#include "clang/Basic/HLSLIntangibleTypes.def"
3475StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3495#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3531 return "swiftasynccall";
3533 llvm_unreachable(
"bad calling convention");
3536void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3545 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3546 if (!CCQualifier.empty())
3547 mangleVendorQualifier(CCQualifier);
3580 llvm_unreachable(
"Unrecognised SME attribute");
3595void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3615 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3619CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3626 case ParameterABI::Ordinary:
3630 case ParameterABI::HLSLOut:
3631 case ParameterABI::HLSLInOut:
3636 case ParameterABI::SwiftContext:
3637 case ParameterABI::SwiftAsyncContext:
3638 case ParameterABI::SwiftErrorResult:
3639 case ParameterABI::SwiftIndirectResult:
3645 mangleVendorQualifier(
"ns_consumed");
3648 mangleVendorQualifier(
"noescape");
3654void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3658 Out <<
"11__SME_ATTRSI";
3660 mangleExtFunctionInfo(
T);
3677 mangleType(ExceptTy);
3688 mangleBareFunctionType(
T,
true);
3695 mangleSMEAttrs(SMEAttrs);
3698void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3704 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3706 FunctionTypeDepth.enterResultType();
3708 FunctionTypeDepth.leaveResultType();
3710 FunctionTypeDepth.pop(saved);
3714void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3715 bool MangleReturnType,
3716 const FunctionDecl *FD) {
3719 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3722 if (MangleReturnType) {
3723 FunctionTypeDepth.enterResultType();
3727 mangleVendorQualifier(
"ns_returns_retained");
3732 auto SplitReturnTy = ReturnTy.
split();
3734 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3736 mangleType(ReturnTy);
3738 FunctionTypeDepth.leaveResultType();
3746 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3760 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3761 if (Attr->isDynamic())
3762 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3764 Out <<
"U17pass_object_size" << Attr->getType();
3775 FunctionTypeDepth.enterResultType();
3779 FunctionTypeDepth.pop(saved);
3784void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3785 mangleName(
T->getDecl());
3790void CXXNameMangler::mangleType(
const EnumType *
T) {
3791 mangleType(
static_cast<const TagType*
>(
T));
3793void CXXNameMangler::mangleType(
const RecordType *
T) {
3794 mangleType(
static_cast<const TagType*
>(
T));
3796void CXXNameMangler::mangleType(
const TagType *
T) {
3797 mangleName(
T->getDecl()->getDefinitionOrSelf());
3803void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3804 Out <<
'A' <<
T->getSize() <<
'_';
3805 mangleType(
T->getElementType());
3807void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3810 if (
T->getSizeExpr())
3811 mangleExpression(
T->getSizeExpr());
3813 mangleType(
T->getElementType());
3815void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3820 if (
T->getSizeExpr())
3821 mangleExpression(
T->getSizeExpr());
3823 mangleType(
T->getElementType());
3825void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3827 mangleType(
T->getElementType());
3832void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
3834 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
3835 mangleCXXRecordDecl(RD);
3837 mangleType(QualType(
T->getQualifier().getAsType(), 0));
3839 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3860 mangleType(PointeeType);
3864void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
3865 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3869void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
3874 Out <<
"_SUBSTPACK_";
3877void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
3882 Out <<
"_SUBSTBUILTINPACK_";
3886void CXXNameMangler::mangleType(
const PointerType *
T) {
3890void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
3896void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
3902void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
3908void CXXNameMangler::mangleType(
const ComplexType *
T) {
3910 mangleType(
T->getElementType());
3916void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
3917 QualType EltType =
T->getElementType();
3918 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3919 const char *EltName =
nullptr;
3920 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3922 case BuiltinType::SChar:
3923 case BuiltinType::UChar:
3924 EltName =
"poly8_t";
3926 case BuiltinType::Short:
3927 case BuiltinType::UShort:
3928 EltName =
"poly16_t";
3930 case BuiltinType::LongLong:
3931 case BuiltinType::ULongLong:
3932 EltName =
"poly64_t";
3934 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3938 case BuiltinType::SChar: EltName =
"int8_t";
break;
3939 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3940 case BuiltinType::Short: EltName =
"int16_t";
break;
3941 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3942 case BuiltinType::Int: EltName =
"int32_t";
break;
3943 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3944 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3945 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3946 case BuiltinType::Double: EltName =
"float64_t";
break;
3947 case BuiltinType::Float: EltName =
"float32_t";
break;
3948 case BuiltinType::Half: EltName =
"float16_t";
break;
3949 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3950 case BuiltinType::MFloat8:
3951 EltName =
"mfloat8_t";
3954 llvm_unreachable(
"unexpected Neon vector element type");
3957 const char *BaseName =
nullptr;
3958 unsigned BitSize = (
T->getNumElements() *
3959 getASTContext().getTypeSize(EltType));
3961 BaseName =
"__simd64_";
3963 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
3964 BaseName =
"__simd128_";
3966 Out << strlen(BaseName) + strlen(EltName);
3967 Out << BaseName << EltName;
3970void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
3971 DiagnosticsEngine &Diags = Context.getDiags();
3974 "cannot mangle this dependent neon vector type yet");
3975 Diags.
Report(
T->getAttributeLoc(), DiagID);
3980 case BuiltinType::SChar:
3982 case BuiltinType::Short:
3984 case BuiltinType::Int:
3986 case BuiltinType::Long:
3987 case BuiltinType::LongLong:
3989 case BuiltinType::UChar:
3991 case BuiltinType::UShort:
3993 case BuiltinType::UInt:
3995 case BuiltinType::ULong:
3996 case BuiltinType::ULongLong:
3998 case BuiltinType::Half:
4000 case BuiltinType::Float:
4002 case BuiltinType::Double:
4004 case BuiltinType::BFloat16:
4006 case BuiltinType::MFloat8:
4009 llvm_unreachable(
"Unexpected vector element base type");
4016void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4017 QualType EltType =
T->getElementType();
4018 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4020 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4023 assert((BitSize == 64 || BitSize == 128) &&
4024 "Neon vector type not 64 or 128 bits");
4027 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4029 case BuiltinType::UChar:
4032 case BuiltinType::UShort:
4035 case BuiltinType::ULong:
4036 case BuiltinType::ULongLong:
4040 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4046 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4049void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4050 DiagnosticsEngine &Diags = Context.getDiags();
4053 "cannot mangle this dependent neon vector type yet");
4054 Diags.
Report(
T->getAttributeLoc(), DiagID);
4081void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4082 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4083 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4084 "expected fixed-length SVE vector!");
4086 QualType EltType =
T->getElementType();
4088 "expected builtin type for fixed-length SVE vector!");
4092 case BuiltinType::SChar:
4095 case BuiltinType::UChar: {
4096 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4102 case BuiltinType::Short:
4105 case BuiltinType::UShort:
4108 case BuiltinType::Int:
4111 case BuiltinType::UInt:
4114 case BuiltinType::Long:
4117 case BuiltinType::ULong:
4120 case BuiltinType::Half:
4123 case BuiltinType::Float:
4126 case BuiltinType::Double:
4129 case BuiltinType::BFloat16:
4133 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4136 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4138 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4141 Out <<
"9__SVE_VLSI";
4142 mangleVendorType(TypeName);
4143 Out <<
"Lj" << VecSizeInBits <<
"EE";
4146void CXXNameMangler::mangleAArch64FixedSveVectorType(
4147 const DependentVectorType *
T) {
4148 DiagnosticsEngine &Diags = Context.getDiags();
4151 "cannot mangle this dependent fixed-length SVE vector type yet");
4152 Diags.
Report(
T->getAttributeLoc(), DiagID);
4155void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4156 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4157 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4158 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4159 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4160 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4161 "expected fixed-length RVV vector!");
4163 QualType EltType =
T->getElementType();
4165 "expected builtin type for fixed-length RVV vector!");
4167 SmallString<20> TypeNameStr;
4168 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4169 TypeNameOS <<
"__rvv_";
4171 case BuiltinType::SChar:
4172 TypeNameOS <<
"int8";
4174 case BuiltinType::UChar:
4175 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4176 TypeNameOS <<
"uint8";
4178 TypeNameOS <<
"bool";
4180 case BuiltinType::Short:
4181 TypeNameOS <<
"int16";
4183 case BuiltinType::UShort:
4184 TypeNameOS <<
"uint16";
4186 case BuiltinType::Int:
4187 TypeNameOS <<
"int32";
4189 case BuiltinType::UInt:
4190 TypeNameOS <<
"uint32";
4192 case BuiltinType::Long:
4193 TypeNameOS <<
"int64";
4195 case BuiltinType::ULong:
4196 TypeNameOS <<
"uint64";
4198 case BuiltinType::Float16:
4199 TypeNameOS <<
"float16";
4201 case BuiltinType::Float:
4202 TypeNameOS <<
"float32";
4204 case BuiltinType::Double:
4205 TypeNameOS <<
"float64";
4207 case BuiltinType::BFloat16:
4208 TypeNameOS <<
"bfloat16";
4211 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4214 unsigned VecSizeInBits;
4215 switch (
T->getVectorKind()) {
4216 case VectorKind::RVVFixedLengthMask_1:
4219 case VectorKind::RVVFixedLengthMask_2:
4222 case VectorKind::RVVFixedLengthMask_4:
4226 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4231 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4232 getASTContext().getLangOpts(),
4233 TargetInfo::ArmStreamingKind::NotStreaming);
4234 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4236 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4238 if (VecSizeInBits >= VLen)
4239 TypeNameOS << (VecSizeInBits / VLen);
4241 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4243 TypeNameOS << (VLen / VecSizeInBits);
4247 Out <<
"9__RVV_VLSI";
4248 mangleVendorType(TypeNameStr);
4249 Out <<
"Lj" << VecSizeInBits <<
"EE";
4252void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4253 const DependentVectorType *
T) {
4254 DiagnosticsEngine &Diags = Context.getDiags();
4257 "cannot mangle this dependent fixed-length RVV vector type yet");
4258 Diags.
Report(
T->getAttributeLoc(), DiagID);
4269void CXXNameMangler::mangleType(
const VectorType *
T) {
4270 if ((
T->getVectorKind() == VectorKind::Neon ||
4271 T->getVectorKind() == VectorKind::NeonPoly)) {
4272 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4273 llvm::Triple::ArchType
Arch =
4274 getASTContext().getTargetInfo().getTriple().getArch();
4275 if ((
Arch == llvm::Triple::aarch64 ||
4276 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4277 mangleAArch64NeonVectorType(
T);
4279 mangleNeonVectorType(
T);
4281 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4282 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4283 mangleAArch64FixedSveVectorType(
T);
4285 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4286 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4287 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4288 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4289 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4290 mangleRISCVFixedRVVVectorType(
T);
4293 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4294 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4296 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4299 mangleType(
T->getElementType());
4302void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4303 if ((
T->getVectorKind() == VectorKind::Neon ||
4304 T->getVectorKind() == VectorKind::NeonPoly)) {
4305 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4306 llvm::Triple::ArchType
Arch =
4307 getASTContext().getTargetInfo().getTriple().getArch();
4308 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4310 mangleAArch64NeonVectorType(
T);
4312 mangleNeonVectorType(
T);
4314 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4315 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4316 mangleAArch64FixedSveVectorType(
T);
4318 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4319 mangleRISCVFixedRVVVectorType(
T);
4324 mangleExpression(
T->getSizeExpr());
4326 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4328 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4331 mangleType(
T->getElementType());
4334void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4335 mangleType(
static_cast<const VectorType*
>(
T));
4337void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4339 mangleExpression(
T->getSizeExpr());
4341 mangleType(
T->getElementType());
4344void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4348 mangleVendorType(
"matrix_type");
4351 auto &ASTCtx = getASTContext();
4352 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4353 llvm::APSInt Rows(BitWidth);
4354 Rows =
T->getNumRows();
4355 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4356 llvm::APSInt Columns(BitWidth);
4357 Columns =
T->getNumColumns();
4358 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4359 mangleType(
T->getElementType());
4363void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4366 mangleVendorType(
"matrix_type");
4369 mangleTemplateArgExpr(
T->getRowExpr());
4370 mangleTemplateArgExpr(
T->getColumnExpr());
4371 mangleType(
T->getElementType());
4375void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4377 mangleQualifiers(split.
Quals,
T);
4378 mangleType(QualType(split.
Ty, 0));
4381void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4384 mangleType(
T->getPattern());
4387void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4388 if (!
T->hasSelectedType())
4389 mangleType(
T->getPattern());
4391 mangleType(
T->getSelectedType());
4394void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4395 mangleSourceName(
T->getDecl()->getIdentifier());
4398void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4400 if (
T->isKindOfType())
4401 Out <<
"U8__kindof";
4403 if (!
T->qual_empty()) {
4405 SmallString<64> QualStr;
4406 llvm::raw_svector_ostream QualOS(QualStr);
4407 QualOS <<
"objcproto";
4408 for (
const auto *I :
T->quals()) {
4409 StringRef
name = I->getName();
4412 mangleVendorQualifier(QualStr);
4415 mangleType(
T->getBaseType());
4417 if (
T->isSpecialized()) {
4420 for (
auto typeArg :
T->getTypeArgs())
4421 mangleType(typeArg);
4426void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4427 Out <<
"U13block_pointer";
4431void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4436 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4439void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4440 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4441 mangleTemplateName(TD,
T->template_arguments());
4444 mangleTemplatePrefix(
T->getTemplateName());
4449 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4454void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4465 switch (
T->getKeyword()) {
4466 case ElaboratedTypeKeyword::None:
4467 case ElaboratedTypeKeyword::Typename:
4469 case ElaboratedTypeKeyword::Struct:
4470 case ElaboratedTypeKeyword::Class:
4471 case ElaboratedTypeKeyword::Interface:
4474 case ElaboratedTypeKeyword::Union:
4477 case ElaboratedTypeKeyword::Enum:
4483 manglePrefix(
T->getQualifier());
4484 mangleSourceName(
T->getIdentifier());
4488void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4494void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4500void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4501 Expr *E =
T->getUnderlyingExpr();
4520 mangleExpression(E);
4524void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4528 StringRef BuiltinName;
4529 switch (
T->getUTTKind()) {
4530#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4531 case UnaryTransformType::Enum: \
4532 BuiltinName = "__" #Trait; \
4534#include "clang/Basic/TransformTypeTraits.def"
4536 mangleVendorType(BuiltinName);
4540 mangleType(
T->getBaseType());
4544void CXXNameMangler::mangleType(
const AutoType *
T) {
4545 assert(
T->getDeducedType().isNull() &&
4546 "Deduced AutoType shouldn't be handled here!");
4547 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4548 "shouldn't need to mangle __auto_type!");
4553 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4554 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4555 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4556 T->getTypeConstraintArguments());
4558 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4562void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4563 QualType Deduced =
T->getDeducedType();
4565 return mangleType(Deduced);
4569 "shouldn't form deduced TST unless we know we have a template");
4573void CXXNameMangler::mangleType(
const AtomicType *
T) {
4577 mangleType(
T->getValueType());
4580void CXXNameMangler::mangleType(
const PipeType *
T) {
4587void CXXNameMangler::mangleType(
const BitIntType *
T) {
4591 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4594void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4598 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4599 mangleExpression(
T->getNumBitsExpr());
4603void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4607void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4608 llvm::SmallString<64> Str(
"_Res");
4609 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4611 switch (Attrs.ResourceClass) {
4612 case llvm::dxil::ResourceClass::UAV:
4615 case llvm::dxil::ResourceClass::SRV:
4618 case llvm::dxil::ResourceClass::CBuffer:
4621 case llvm::dxil::ResourceClass::Sampler:
4627 if (Attrs.RawBuffer)
4629 if (Attrs.IsCounter)
4631 if (
T->hasContainedType())
4633 mangleVendorQualifier(Str);
4635 if (
T->hasContainedType()) {
4636 mangleType(
T->getContainedType());
4638 mangleType(
T->getWrappedType());
4641void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4642 SmallString<20> TypeNameStr;
4643 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4645 TypeNameOS <<
"spirv_type";
4647 TypeNameOS <<
"_" <<
T->getOpcode();
4648 TypeNameOS <<
"_" <<
T->getSize();
4649 TypeNameOS <<
"_" <<
T->getAlignment();
4651 mangleVendorType(TypeNameStr);
4653 for (
auto &Operand :
T->getOperands()) {
4654 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4657 case SpirvOperandKind::ConstantId:
4658 mangleVendorQualifier(
"_Const");
4659 mangleIntegerLiteral(
Operand.getResultType(),
4660 llvm::APSInt(
Operand.getValue()));
4662 case SpirvOperandKind::Literal:
4663 mangleVendorQualifier(
"_Lit");
4664 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4665 llvm::APSInt(
Operand.getValue()));
4667 case SpirvOperandKind::TypeId:
4668 mangleVendorQualifier(
"_Type");
4669 mangleType(
Operand.getResultType());
4672 llvm_unreachable(
"Invalid SpirvOperand kind");
4675 TypeNameOS <<
Operand.getKind();
4679void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4680 const llvm::APSInt &
Value) {
4687 Out << (
Value.getBoolValue() ?
'1' :
'0');
4689 mangleNumber(
Value);
4694void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4696 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4697 if (!RT->getDecl()->isAnonymousStructOrUnion())
4699 const auto *ME = dyn_cast<MemberExpr>(Base);
4702 Base = ME->getBase();
4703 IsArrow = ME->isArrow();
4706 if (
Base->isImplicitCXXThis()) {
4712 Out << (IsArrow ?
"pt" :
"dt");
4713 mangleExpression(Base);
4718void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4719 NestedNameSpecifier Qualifier,
4720 NamedDecl *firstQualifierLookup,
4721 DeclarationName member,
4722 const TemplateArgumentLoc *TemplateArgs,
4723 unsigned NumTemplateArgs,
4728 mangleMemberExprBase(base, isArrow);
4729 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4742 if (callee == fn)
return false;
4746 if (!lookup)
return false;
4763void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4765 Out << CastEncoding;
4770void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4772 InitList = Syntactic;
4773 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4774 mangleExpression(InitList->
getInit(i));
4777void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4778 const concepts::Requirement *Req) {
4779 using concepts::Requirement;
4784 auto HandleSubstitutionFailure =
4785 [&](SourceLocation Loc) {
4786 DiagnosticsEngine &Diags = Context.getDiags();
4789 "containing a substitution failure");
4790 Diags.
Report(Loc, DiagID);
4795 case Requirement::RK_Type: {
4797 if (TR->isSubstitutionFailure())
4798 return HandleSubstitutionFailure(
4799 TR->getSubstitutionDiagnostic()->DiagLoc);
4802 mangleType(TR->getType()->getType());
4806 case Requirement::RK_Simple:
4807 case Requirement::RK_Compound: {
4809 if (ER->isExprSubstitutionFailure())
4810 return HandleSubstitutionFailure(
4811 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4814 mangleExpression(ER->getExpr());
4816 if (ER->hasNoexceptRequirement())
4819 if (!ER->getReturnTypeRequirement().isEmpty()) {
4820 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4821 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4822 .getSubstitutionDiagnostic()
4826 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4831 case Requirement::RK_Nested:
4833 if (NR->hasInvalidConstraint()) {
4836 return HandleSubstitutionFailure(RequiresExprLoc);
4840 mangleExpression(NR->getConstraintExpr());
4845void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4846 bool AsTemplateArg) {
4875 QualType ImplicitlyConvertedToType;
4879 bool IsPrimaryExpr =
true;
4880 auto NotPrimaryExpr = [&] {
4881 if (AsTemplateArg && IsPrimaryExpr)
4883 IsPrimaryExpr =
false;
4886 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4887 switch (D->getKind()) {
4900 case Decl::EnumConstant: {
4907 case Decl::NonTypeTemplateParm:
4920 case Expr::NoStmtClass:
4921#define ABSTRACT_STMT(Type)
4922#define EXPR(Type, Base)
4923#define STMT(Type, Base) \
4924 case Expr::Type##Class:
4925#include "clang/AST/StmtNodes.inc"
4930 case Expr::AddrLabelExprClass:
4931 case Expr::DesignatedInitUpdateExprClass:
4932 case Expr::ImplicitValueInitExprClass:
4933 case Expr::ArrayInitLoopExprClass:
4934 case Expr::ArrayInitIndexExprClass:
4935 case Expr::NoInitExprClass:
4936 case Expr::ParenListExprClass:
4937 case Expr::MSPropertyRefExprClass:
4938 case Expr::MSPropertySubscriptExprClass:
4939 case Expr::RecoveryExprClass:
4940 case Expr::ArraySectionExprClass:
4941 case Expr::OMPArrayShapingExprClass:
4942 case Expr::OMPIteratorExprClass:
4943 case Expr::CXXInheritedCtorInitExprClass:
4944 case Expr::CXXParenListInitExprClass:
4945 case Expr::PackIndexingExprClass:
4946 llvm_unreachable(
"unexpected statement kind");
4948 case Expr::ConstantExprClass:
4953 case Expr::BlockExprClass:
4954 case Expr::ChooseExprClass:
4955 case Expr::CompoundLiteralExprClass:
4956 case Expr::ExtVectorElementExprClass:
4957 case Expr::GenericSelectionExprClass:
4958 case Expr::ObjCEncodeExprClass:
4959 case Expr::ObjCIsaExprClass:
4960 case Expr::ObjCIvarRefExprClass:
4961 case Expr::ObjCMessageExprClass:
4962 case Expr::ObjCPropertyRefExprClass:
4963 case Expr::ObjCProtocolExprClass:
4964 case Expr::ObjCSelectorExprClass:
4965 case Expr::ObjCStringLiteralClass:
4966 case Expr::ObjCBoxedExprClass:
4967 case Expr::ObjCArrayLiteralClass:
4968 case Expr::ObjCDictionaryLiteralClass:
4969 case Expr::ObjCSubscriptRefExprClass:
4970 case Expr::ObjCIndirectCopyRestoreExprClass:
4971 case Expr::ObjCAvailabilityCheckExprClass:
4972 case Expr::OffsetOfExprClass:
4973 case Expr::PredefinedExprClass:
4974 case Expr::ShuffleVectorExprClass:
4975 case Expr::ConvertVectorExprClass:
4976 case Expr::StmtExprClass:
4977 case Expr::ArrayTypeTraitExprClass:
4978 case Expr::ExpressionTraitExprClass:
4979 case Expr::VAArgExprClass:
4980 case Expr::CUDAKernelCallExprClass:
4981 case Expr::AsTypeExprClass:
4982 case Expr::PseudoObjectExprClass:
4983 case Expr::AtomicExprClass:
4984 case Expr::SourceLocExprClass:
4985 case Expr::EmbedExprClass:
4986 case Expr::BuiltinBitCastExprClass: {
4990 DiagnosticsEngine &Diags = Context.getDiags();
4992 "cannot yet mangle expression type %0");
5000 case Expr::CXXUuidofExprClass: {
5005 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5006 Out <<
"u8__uuidof";
5015 Out <<
"u8__uuidoft";
5019 Out <<
"u8__uuidofz";
5020 mangleExpression(UuidExp);
5027 case Expr::BinaryConditionalOperatorClass: {
5029 DiagnosticsEngine &Diags = Context.getDiags();
5032 "?: operator with omitted middle operand cannot be mangled");
5039 case Expr::OpaqueValueExprClass:
5040 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5042 case Expr::InitListExprClass: {
5050 case Expr::DesignatedInitExprClass: {
5053 for (
const auto &Designator : DIE->designators()) {
5054 if (Designator.isFieldDesignator()) {
5056 mangleSourceName(Designator.getFieldName());
5057 }
else if (Designator.isArrayDesignator()) {
5059 mangleExpression(DIE->getArrayIndex(Designator));
5061 assert(Designator.isArrayRangeDesignator() &&
5062 "unknown designator kind");
5064 mangleExpression(DIE->getArrayRangeStart(Designator));
5065 mangleExpression(DIE->getArrayRangeEnd(Designator));
5068 mangleExpression(DIE->getInit());
5072 case Expr::CXXDefaultArgExprClass:
5076 case Expr::CXXDefaultInitExprClass:
5080 case Expr::CXXStdInitializerListExprClass:
5084 case Expr::SubstNonTypeTemplateParmExprClass: {
5088 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5090 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5091 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5092 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5102 case Expr::UserDefinedLiteralClass:
5105 case Expr::CXXMemberCallExprClass:
5106 case Expr::CallExprClass: {
5128 CallArity = UnknownArity;
5130 mangleExpression(CE->
getCallee(), CallArity);
5132 mangleExpression(Arg);
5137 case Expr::CXXNewExprClass: {
5140 if (
New->isGlobalNew())
Out <<
"gs";
5141 Out << (
New->isArray() ?
"na" :
"nw");
5143 E =
New->placement_arg_end(); I != E; ++I)
5144 mangleExpression(*I);
5146 mangleType(
New->getAllocatedType());
5147 if (
New->hasInitializer()) {
5148 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5152 const Expr *
Init =
New->getInitializer();
5153 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5158 mangleExpression(*I);
5159 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5160 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5161 mangleExpression(PLE->getExpr(i));
5162 }
else if (
New->getInitializationStyle() ==
5163 CXXNewInitializationStyle::Braces &&
5168 mangleExpression(
Init);
5174 case Expr::CXXPseudoDestructorExprClass: {
5177 if (
const Expr *Base = PDE->getBase())
5178 mangleMemberExprBase(Base, PDE->isArrow());
5179 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5180 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5182 mangleUnresolvedPrefix(Qualifier,
5184 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5188 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5191 }
else if (Qualifier) {
5192 mangleUnresolvedPrefix(Qualifier);
5196 QualType DestroyedType = PDE->getDestroyedType();
5197 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5201 case Expr::MemberExprClass: {
5212 case Expr::UnresolvedMemberExprClass: {
5223 case Expr::CXXDependentScopeMemberExprClass: {
5225 const CXXDependentScopeMemberExpr *ME
5236 case Expr::UnresolvedLookupExprClass: {
5245 case Expr::CXXUnresolvedConstructExprClass: {
5251 assert(N == 1 &&
"unexpected form for list initialization");
5255 mangleInitListElements(IL);
5262 if (N != 1)
Out <<
'_';
5263 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5264 if (N != 1)
Out <<
'E';
5268 case Expr::CXXConstructExprClass: {
5275 "implicit CXXConstructExpr must have one argument");
5282 mangleExpression(E);
5287 case Expr::CXXTemporaryObjectExprClass: {
5298 if (!List && N != 1)
5300 if (CE->isStdInitListInitialization()) {
5307 mangleInitListElements(ILE);
5310 mangleExpression(E);
5317 case Expr::CXXScalarValueInitExprClass:
5324 case Expr::CXXNoexceptExprClass:
5330 case Expr::UnaryExprOrTypeTraitExprClass: {
5347 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5349 : ImplicitlyConvertedToType;
5351 mangleIntegerLiteral(
T,
V);
5357 auto MangleAlignofSizeofArg = [&] {
5367 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5368 StringRef Name = {}) {
5371 mangleVendorType(Name);
5382 MangleAlignofSizeofArg();
5384 case UETT_PreferredAlignOf:
5388 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5389 MangleExtensionBuiltin(SAE,
"__alignof__");
5395 MangleAlignofSizeofArg();
5399 case UETT_VectorElements:
5400 case UETT_OpenMPRequiredSimdAlign:
5402 case UETT_PtrAuthTypeDiscriminator:
5403 case UETT_DataSizeOf: {
5404 DiagnosticsEngine &Diags = Context.getDiags();
5414 case Expr::TypeTraitExprClass: {
5419 mangleVendorType(Spelling);
5420 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5421 mangleType(TSI->getType());
5427 case Expr::CXXThrowExprClass: {
5441 case Expr::CXXTypeidExprClass: {
5456 case Expr::CXXDeleteExprClass: {
5467 case Expr::UnaryOperatorClass: {
5476 case Expr::ArraySubscriptExprClass: {
5483 mangleExpression(AE->
getLHS());
5484 mangleExpression(AE->
getRHS());
5488 case Expr::MatrixSubscriptExprClass: {
5492 mangleExpression(ME->
getBase());
5498 case Expr::CompoundAssignOperatorClass:
5499 case Expr::BinaryOperatorClass: {
5507 mangleExpression(BO->
getLHS());
5508 mangleExpression(BO->
getRHS());
5512 case Expr::CXXRewrittenBinaryOperatorClass: {
5515 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5519 mangleExpression(Decomposed.
LHS);
5520 mangleExpression(Decomposed.
RHS);
5524 case Expr::ConditionalOperatorClass: {
5527 mangleOperatorName(OO_Conditional, 3);
5528 mangleExpression(CO->
getCond());
5529 mangleExpression(CO->
getLHS(), Arity);
5530 mangleExpression(CO->
getRHS(), Arity);
5534 case Expr::ImplicitCastExprClass: {
5535 ImplicitlyConvertedToType = E->
getType();
5540 case Expr::ObjCBridgedCastExprClass: {
5546 mangleCastExpression(E,
"cv");
5550 case Expr::CStyleCastExprClass:
5552 mangleCastExpression(E,
"cv");
5555 case Expr::CXXFunctionalCastExprClass: {
5559 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5560 if (CCE->getParenOrBraceRange().isInvalid())
5561 Sub = CCE->getArg(0)->IgnoreImplicit();
5562 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5563 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5564 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5567 mangleInitListElements(IL);
5570 mangleCastExpression(E,
"cv");
5575 case Expr::CXXStaticCastExprClass:
5577 mangleCastExpression(E,
"sc");
5579 case Expr::CXXDynamicCastExprClass:
5581 mangleCastExpression(E,
"dc");
5583 case Expr::CXXReinterpretCastExprClass:
5585 mangleCastExpression(E,
"rc");
5587 case Expr::CXXConstCastExprClass:
5589 mangleCastExpression(E,
"cc");
5591 case Expr::CXXAddrspaceCastExprClass:
5593 mangleCastExpression(E,
"ac");
5596 case Expr::CXXOperatorCallExprClass: {
5605 for (
unsigned i = 0; i != NumArgs; ++i)
5606 mangleExpression(CE->
getArg(i));
5610 case Expr::ParenExprClass:
5614 case Expr::ConceptSpecializationExprClass: {
5616 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5621 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5627 mangleUnresolvedName(
5628 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5629 CSE->getConceptNameInfo().getName(),
5630 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5631 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5635 case Expr::RequiresExprClass: {
5641 if (RE->getLParenLoc().isValid()) {
5643 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5644 if (RE->getLocalParameters().empty()) {
5647 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5655 FunctionTypeDepth.enterResultType();
5656 for (
const concepts::Requirement *Req : RE->getRequirements())
5657 mangleRequirement(RE->getExprLoc(), Req);
5658 FunctionTypeDepth.pop(saved);
5662 for (
const concepts::Requirement *Req : RE->getRequirements())
5663 mangleRequirement(RE->getExprLoc(), Req);
5669 case Expr::DeclRefExprClass:
5674 case Expr::SubstNonTypeTemplateParmPackExprClass:
5680 Out <<
"_SUBSTPACK_";
5683 case Expr::FunctionParmPackExprClass: {
5687 Out <<
"v110_SUBSTPACK";
5692 case Expr::DependentScopeDeclRefExprClass: {
5701 case Expr::CXXBindTemporaryExprClass:
5705 case Expr::ExprWithCleanupsClass:
5709 case Expr::FloatingLiteralClass: {
5716 case Expr::FixedPointLiteralClass:
5718 mangleFixedPointLiteral();
5721 case Expr::CharacterLiteralClass:
5725 Out << cast<CharacterLiteral>(E)->getValue();
5730 case Expr::ObjCBoolLiteralExprClass:
5733 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5737 case Expr::CXXBoolLiteralExprClass:
5740 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5744 case Expr::IntegerLiteralClass: {
5748 Value.setIsSigned(
true);
5753 case Expr::ImaginaryLiteralClass: {
5760 if (
const FloatingLiteral *Imag =
5761 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5763 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5765 mangleFloat(Imag->getValue());
5770 Value.setIsSigned(
true);
5771 mangleNumber(
Value);
5777 case Expr::StringLiteralClass: {
5787 case Expr::GNUNullExprClass:
5790 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5793 case Expr::CXXNullPtrLiteralExprClass: {
5799 case Expr::LambdaExprClass: {
5810 case Expr::PackExpansionExprClass:
5816 case Expr::SizeOfPackExprClass: {
5819 if (SPE->isPartiallySubstituted()) {
5821 for (
const auto &A : SPE->getPartialArguments())
5822 mangleTemplateArg(A,
false);
5828 const NamedDecl *Pack = SPE->getPack();
5829 if (
const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
5830 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5831 else if (
const NonTypeTemplateParmDecl *NTTP
5832 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5833 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5834 else if (
const TemplateTemplateParmDecl *TempTP
5835 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5836 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5842 case Expr::MaterializeTemporaryExprClass:
5846 case Expr::CXXFoldExprClass: {
5849 if (FE->isLeftFold())
5850 Out << (FE->getInit() ?
"fL" :
"fl");
5852 Out << (FE->getInit() ?
"fR" :
"fr");
5854 if (FE->getOperator() == BO_PtrMemD)
5862 mangleExpression(FE->getLHS());
5864 mangleExpression(FE->getRHS());
5868 case Expr::CXXThisExprClass:
5873 case Expr::CoawaitExprClass:
5876 Out <<
"v18co_await";
5880 case Expr::DependentCoawaitExprClass:
5883 Out <<
"v18co_await";
5887 case Expr::CoyieldExprClass:
5890 Out <<
"v18co_yield";
5893 case Expr::SYCLUniqueStableNameExprClass: {
5897 Out <<
"u33__builtin_sycl_unique_stable_name";
5898 mangleType(USN->getTypeSourceInfo()->getType());
5903 case Expr::HLSLOutArgExprClass:
5905 "cannot mangle hlsl temporary value; mangling wrong thing?");
5906 case Expr::OpenACCAsteriskSizeExprClass: {
5908 DiagnosticsEngine &Diags = Context.getDiags();
5911 "cannot yet mangle OpenACC Asterisk Size expression");
5917 if (AsTemplateArg && !IsPrimaryExpr)
5949void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
5956 assert(parmDepth < FunctionTypeDepth.getDepth());
5957 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
5958 if (FunctionTypeDepth.isInResultType())
5961 if (nestingDepth == 0) {
5964 Out <<
"fL" << (nestingDepth - 1) <<
'p';
5972 &&
"parameter's type is still an array type?");
5974 if (
const DependentAddressSpaceType *DAST =
5975 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
5982 if (parmIndex != 0) {
5983 Out << (parmIndex - 1);
5989 const CXXRecordDecl *InheritedFrom) {
6016 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6019 mangleName(InheritedFrom);
6047 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6080 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6081 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6082 if (!RD || !RD->isGenericLambda())
6098 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6099 return TTP->hasTypeConstraint();
6116 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6117 return NTTP->getType()->isInstantiationDependentType() ||
6118 NTTP->getType()->getContainedDeducedType();
6125 "A DeducedTemplateName shouldn't escape partial ordering");
6136 auto MangleTemplateParamListToString =
6138 unsigned DepthOffset) {
6139 llvm::raw_svector_ostream Stream(Buffer);
6140 CXXNameMangler(
Mangler.Context, Stream,
6141 WithTemplateDepthOffset{DepthOffset})
6142 .mangleTemplateParameterList(Params);
6145 MangleTemplateParamListToString(ParamTemplateHead,
6146 TTP->getTemplateParameters(), 0);
6150 MangleTemplateParamListToString(ArgTemplateHead,
6152 TTP->getTemplateParameters()->
getDepth());
6153 return ParamTemplateHead != ArgTemplateHead;
6163 return {
true,
nullptr};
6168 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6169 "no parameter for argument");
6190 return {
true,
nullptr};
6205 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6206 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6207 return {NeedExactType,
nullptr};
6219void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6221 unsigned NumTemplateArgs) {
6224 TemplateArgManglingInfo Info(*
this, TN);
6225 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6226 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6228 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6232void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6233 const TemplateArgumentList &AL) {
6236 TemplateArgManglingInfo Info(*
this, TN);
6237 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6238 mangleTemplateArg(Info, i, AL[i]);
6240 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6244void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6245 ArrayRef<TemplateArgument> Args) {
6248 TemplateArgManglingInfo Info(*
this, TN);
6249 for (
unsigned i = 0; i != Args.size(); ++i) {
6250 mangleTemplateArg(Info, i, Args[i]);
6252 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6256void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6257 unsigned Index, TemplateArgument A) {
6258 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6261 if (ArgInfo.TemplateParameterToMangle &&
6262 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6269 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6272 mangleTemplateArg(A, ArgInfo.NeedExactType);
6275void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6285 llvm_unreachable(
"Cannot mangle NULL template argument");
6313 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6314 TPO->getValue(),
true,
6319 ASTContext &Ctx = Context.getASTContext();
6327 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6335 ArrayRef<APValue::LValuePathEntry>(),
6348 true, NeedExactType);
6354 mangleTemplateArg(P, NeedExactType);
6360void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6361 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6362 mangleExpression(E, UnknownArity,
true);
6377 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6378 const ValueDecl *D = DRE->getDecl();
6387 mangleExpression(E);
6400 switch (
V.getKind()) {
6408 assert(RD &&
"unexpected type for record value");
6417 if (!FD->isUnnamedBitField() &&
6427 assert(RD &&
"unexpected type for union value");
6430 if (!FD->isUnnamedBitField())
6440 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6441 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6449 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6459 return V.getFloat().isPosZero();
6462 return !
V.getFixedPoint().getValue();
6465 return V.getComplexFloatReal().isPosZero() &&
6466 V.getComplexFloatImag().isPosZero();
6469 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6472 return V.isNullPointer();
6475 return !
V.getMemberPointerDecl();
6478 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6485 T = AT->getElementType();
6487 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6532 Diags.
Report(UnionLoc, DiagID);
6537void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6539 bool NeedExactType) {
6542 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6545 bool IsPrimaryExpr =
true;
6546 auto NotPrimaryExpr = [&] {
6547 if (TopLevel && IsPrimaryExpr)
6549 IsPrimaryExpr =
false;
6553 switch (
V.getKind()) {
6562 llvm_unreachable(
"unexpected value kind in template argument");
6566 assert(RD &&
"unexpected type for record value");
6569 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6572 (Fields.back()->isUnnamedBitField() ||
6574 V.getStructField(Fields.back()->getFieldIndex())))) {
6578 if (Fields.empty()) {
6579 while (!Bases.empty() &&
6581 V.getStructBase(Bases.size() - 1)))
6582 Bases = Bases.drop_back();
6589 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6590 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6591 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6592 if (Fields[I]->isUnnamedBitField())
6594 mangleValueInTemplateArg(Fields[I]->
getType(),
6595 V.getStructField(Fields[I]->getFieldIndex()),
6604 const FieldDecl *FD =
V.getUnionField();
6622 mangleSourceName(II);
6623 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6637 unsigned N =
V.getArraySize();
6639 N =
V.getArrayInitializedElts();
6644 for (
unsigned I = 0; I != N; ++I) {
6645 const APValue &Elem = I <
V.getArrayInitializedElts()
6646 ?
V.getArrayInitializedElt(I)
6647 :
V.getArrayFiller();
6648 mangleValueInTemplateArg(ElemT, Elem,
false);
6655 const VectorType *VT =
T->
castAs<VectorType>();
6660 unsigned N =
V.getVectorLength();
6663 for (
unsigned I = 0; I != N; ++I)
6664 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6670 mangleIntegerLiteral(
T,
V.getInt());
6674 mangleFloatLiteral(
T,
V.getFloat());
6678 mangleFixedPointLiteral();
6682 const ComplexType *CT =
T->
castAs<ComplexType>();
6686 if (!
V.getComplexFloatReal().isPosZero() ||
6687 !
V.getComplexFloatImag().isPosZero())
6689 if (!
V.getComplexFloatImag().isPosZero())
6696 const ComplexType *CT =
T->
castAs<ComplexType>();
6700 if (
V.getComplexIntReal().getBoolValue() ||
6701 V.getComplexIntImag().getBoolValue())
6703 if (
V.getComplexIntImag().getBoolValue())
6712 "unexpected type for LValue template arg");
6714 if (
V.isNullPointer()) {
6715 mangleNullPointer(
T);
6719 APValue::LValueBase B =
V.getLValueBase();
6723 CharUnits Offset =
V.getLValueOffset();
6741 ASTContext &Ctx = Context.getASTContext();
6744 if (!
V.hasLValuePath()) {
6760 bool IsArrayToPointerDecayMangledAsDecl =
false;
6761 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6762 LangOptions::ClangABI::Ver11) {
6764 IsArrayToPointerDecayMangledAsDecl =
6765 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6766 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6770 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6771 !IsArrayToPointerDecayMangledAsDecl) {
6788 if (NeedExactType &&
6790 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6803 QualType TypeSoFar = B.
getType();
6804 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6808 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6810 mangleExpression(E);
6811 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6814 mangleType(QualType(TI.getType(), 0));
6817 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6827 mangleNumber(
V.getLValueOffset().getQuantity());
6834 if (!
V.getLValueOffset().isZero())
6835 mangleNumber(
V.getLValueOffset().getQuantity());
6839 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6841 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6843 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6844 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6845 TypeSoFar = AT->getElementType();
6847 const Decl *D = E.getAsBaseOrMember().getPointer();
6848 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6873 if (!
V.getMemberPointerDecl()) {
6874 mangleNullPointer(
T);
6878 ASTContext &Ctx = Context.getASTContext();
6881 if (!
V.getMemberPointerPath().empty()) {
6884 }
else if (NeedExactType &&
6886 T->
castAs<MemberPointerType>()->getPointeeType(),
6887 V.getMemberPointerDecl()->getType()) &&
6888 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6893 mangle(
V.getMemberPointerDecl());
6895 if (!
V.getMemberPointerPath().empty()) {
6905 if (TopLevel && !IsPrimaryExpr)
6909void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6919 Depth += TemplateDepthOffset;
6921 Out <<
'L' << (Depth - 1) <<
'_';
6927void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6930 }
else if (SeqID == 1) {
6937 MutableArrayRef<char> BufferRef(Buffer);
6938 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
6940 for (; SeqID != 0; SeqID /= 36) {
6941 unsigned C = SeqID % 36;
6942 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
6945 Out.write(I.base(), I - BufferRef.rbegin());
6950void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
6951 bool result = mangleSubstitution(tname);
6952 assert(result &&
"no existing substitution for template name");
6958bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
6960 if (mangleStandardSubstitution(ND))
6964 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
6974bool CXXNameMangler::mangleSubstitution(QualType
T) {
6977 return mangleSubstitution(RD);
6982 return mangleSubstitution(TypePtr);
6986 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
6987 return mangleSubstitution(TD);
6990 return mangleSubstitution(
6994bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
6995 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
6996 if (I == Substitutions.end())
6999 unsigned SeqID = I->second;
7008bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7017 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7018 if (!SD || !SD->getIdentifier()->isStr(Name))
7021 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7024 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7025 if (TemplateArgs.
size() != 1)
7028 if (TemplateArgs[0].getAsType() != A)
7031 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7040bool CXXNameMangler::isStdCharSpecialization(
7041 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7042 bool HasAllocator) {
7047 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7050 QualType A = TemplateArgs[0].getAsType();
7058 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7062 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7071bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7073 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7081 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7082 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7102 if (
const ClassTemplateSpecializationDecl *SD =
7103 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7104 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7113 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7120 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7127 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7134 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7144void CXXNameMangler::addSubstitution(QualType
T) {
7147 addSubstitution(RD);
7153 addSubstitution(TypePtr);
7157 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7158 return addSubstitution(TD);
7164void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7165 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7166 Substitutions[Ptr] = SeqID++;
7169void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7170 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7171 if (
Other->SeqID > SeqID) {
7172 Substitutions.swap(
Other->Substitutions);
7173 SeqID =
Other->SeqID;
7177CXXNameMangler::AbiTagList
7178CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7180 if (DisableDerivedAbiTags)
7181 return AbiTagList();
7183 llvm::raw_null_ostream NullOutStream;
7184 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7185 TrackReturnTypeTags.disableDerivedAbiTags();
7187 const FunctionProtoType *Proto =
7189 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7190 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
7192 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
7193 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7195 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7198CXXNameMangler::AbiTagList
7199CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7201 if (DisableDerivedAbiTags)
7202 return AbiTagList();
7204 llvm::raw_null_ostream NullOutStream;
7205 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7206 TrackVariableType.disableDerivedAbiTags();
7208 TrackVariableType.mangleType(VD->
getType());
7210 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7213bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7214 const VarDecl *VD) {
7215 llvm::raw_null_ostream NullOutStream;
7216 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7217 TrackAbiTags.mangle(VD);
7218 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7231void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7235 "Invalid mangleName() call, argument is not a variable or function!");
7237 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7238 getASTContext().getSourceManager(),
7239 "Mangling declaration");
7241 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7243 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7244 return Mangler.mangle(GlobalDecl(CD,
Type));
7247 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7249 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7250 return Mangler.mangle(GlobalDecl(DD,
Type));
7253 CXXNameMangler Mangler(*
this, Out, D);
7257void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7259 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7263void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7265 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7287 auto &LangOpts = Context.getLangOpts();
7290 Context.baseForVTableAuthentication(ThisRD);
7291 unsigned TypedDiscriminator =
7292 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7293 Mangler.mangleVendorQualifier(
"__vtptrauth");
7294 auto &ManglerStream = Mangler.getStream();
7295 ManglerStream <<
"I";
7296 if (
const auto *ExplicitAuth =
7297 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7298 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7300 if (ExplicitAuth->getAddressDiscrimination() ==
7301 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7302 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7304 ManglerStream <<
"Lb"
7305 << (ExplicitAuth->getAddressDiscrimination() ==
7306 VTablePointerAuthenticationAttr::AddressDiscrimination);
7308 switch (ExplicitAuth->getExtraDiscrimination()) {
7309 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7310 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7311 ManglerStream <<
"Lj" << TypedDiscriminator;
7313 ManglerStream <<
"Lj" << 0;
7316 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7317 ManglerStream <<
"Lj" << TypedDiscriminator;
7319 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7320 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7322 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7323 ManglerStream <<
"Lj" << 0;
7327 ManglerStream <<
"Lj"
7328 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7329 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7330 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7331 ManglerStream <<
"Lj" << TypedDiscriminator;
7333 ManglerStream <<
"Lj" << 0;
7335 ManglerStream <<
"E";
7338void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7339 const ThunkInfo &Thunk,
7340 bool ElideOverrideInfo,
7350 "Use mangleCXXDtor for destructor decls!");
7351 CXXNameMangler Mangler(*
this, Out);
7352 Mangler.getStream() <<
"_ZT";
7354 Mangler.getStream() <<
'c';
7365 Mangler.mangleFunctionEncoding(MD);
7366 if (!ElideOverrideInfo)
7370void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7372 const ThunkInfo &Thunk,
7373 bool ElideOverrideInfo,
7377 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7378 Mangler.getStream() <<
"_ZT";
7380 auto &ThisAdjustment = Thunk.
This;
7382 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7383 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7385 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7386 if (!ElideOverrideInfo)
7391void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7395 CXXNameMangler Mangler(*
this, Out);
7398 Mangler.getStream() <<
"_ZGV";
7399 Mangler.mangleName(D);
7402void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7407 Out <<
"__cxx_global_var_init";
7410void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7413 CXXNameMangler Mangler(*
this, Out);
7414 Mangler.getStream() <<
"__dtor_";
7415 if (shouldMangleDeclName(D))
7418 Mangler.getStream() << D->
getName();
7421void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7425 CXXNameMangler Mangler(*
this, Out);
7426 Mangler.getStream() <<
"__finalize_";
7427 if (shouldMangleDeclName(D))
7430 Mangler.getStream() << D->
getName();
7433void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7434 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7435 CXXNameMangler Mangler(*
this, Out);
7436 Mangler.getStream() <<
"__filt_";
7438 if (shouldMangleDeclName(EnclosingFD))
7439 Mangler.mangle(EnclosingDecl);
7441 Mangler.getStream() << EnclosingFD->getName();
7444void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7445 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7446 CXXNameMangler Mangler(*
this, Out);
7447 Mangler.getStream() <<
"__fin_";
7449 if (shouldMangleDeclName(EnclosingFD))
7450 Mangler.mangle(EnclosingDecl);
7452 Mangler.getStream() << EnclosingFD->getName();
7455void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7458 CXXNameMangler Mangler(*
this, Out);
7459 Mangler.getStream() <<
"_ZTH";
7460 Mangler.mangleName(D);
7464ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7467 CXXNameMangler Mangler(*
this, Out);
7468 Mangler.getStream() <<
"_ZTW";
7469 Mangler.mangleName(D);
7472void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7473 unsigned ManglingNumber,
7477 CXXNameMangler Mangler(*
this, Out);
7478 Mangler.getStream() <<
"_ZGR";
7479 Mangler.mangleName(D);
7480 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7481 Mangler.mangleSeqID(ManglingNumber - 1);
7484void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7487 CXXNameMangler Mangler(*
this, Out);
7488 Mangler.getStream() <<
"_ZTV";
7489 Mangler.mangleCXXRecordDecl(RD);
7492void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7495 CXXNameMangler Mangler(*
this, Out);
7496 Mangler.getStream() <<
"_ZTT";
7497 Mangler.mangleCXXRecordDecl(RD);
7500void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7502 const CXXRecordDecl *
Type,
7505 CXXNameMangler Mangler(*
this, Out);
7506 Mangler.getStream() <<
"_ZTC";
7509 bool SuppressSubstitution =
7510 getASTContext().getLangOpts().getClangABICompat() <=
7511 LangOptions::ClangABI::Ver19;
7512 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7513 Mangler.getStream() << Offset;
7514 Mangler.getStream() <<
'_';
7515 Mangler.mangleCXXRecordDecl(
Type);
7518void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7520 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7521 CXXNameMangler Mangler(*
this, Out);
7522 Mangler.getStream() <<
"_ZTI";
7523 Mangler.mangleType(Ty);
7526void ItaniumMangleContextImpl::mangleCXXRTTIName(
7527 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7529 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7530 Mangler.getStream() <<
"_ZTS";
7531 Mangler.mangleType(Ty);
7534void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7535 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7536 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7539void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7540 llvm_unreachable(
"Can't mangle string literals");
7543void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7545 CXXNameMangler Mangler(*
this, Out);
7546 Mangler.mangleLambdaSig(Lambda);
7549void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7552 CXXNameMangler Mangler(*
this, Out);
7553 Mangler.getStream() <<
"_ZGI";
7557 auto Partition = M->
Name.find(
':');
7558 Mangler.mangleModuleNamePrefix(
7559 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7567 return new ItaniumMangleContextImpl(
7570 return std::nullopt;
7579 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
static bool isUniqueInternalLinkageDecl(GlobalDecl GD, CodeGenModule &CGM)
@ LLVM_MARK_AS_BITMASK_ENUM
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.
static DeclT * getDefinitionOrSelf(DeclT *D)
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 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 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
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 ...
bool isFunctionOrMethod() 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.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
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.
Declaration of a template function.
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
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 hasLinkage() const
Determine whether this declaration has linkage.
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,...
bool isDependentAddressSpaceType() const
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.
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)
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.
The JSON file list parser is used to communicate input to InstallAPI.
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.
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...
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.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
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)
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
@ 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.