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";
4208 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4211 unsigned VecSizeInBits;
4212 switch (
T->getVectorKind()) {
4213 case VectorKind::RVVFixedLengthMask_1:
4216 case VectorKind::RVVFixedLengthMask_2:
4219 case VectorKind::RVVFixedLengthMask_4:
4223 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4228 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4229 getASTContext().getLangOpts(),
4230 TargetInfo::ArmStreamingKind::NotStreaming);
4231 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4233 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4235 if (VecSizeInBits >= VLen)
4236 TypeNameOS << (VecSizeInBits / VLen);
4238 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4240 TypeNameOS << (VLen / VecSizeInBits);
4244 Out <<
"9__RVV_VLSI";
4245 mangleVendorType(TypeNameStr);
4246 Out <<
"Lj" << VecSizeInBits <<
"EE";
4249void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4250 const DependentVectorType *
T) {
4251 DiagnosticsEngine &Diags = Context.getDiags();
4254 "cannot mangle this dependent fixed-length RVV vector type yet");
4255 Diags.
Report(
T->getAttributeLoc(), DiagID);
4266void CXXNameMangler::mangleType(
const VectorType *
T) {
4267 if ((
T->getVectorKind() == VectorKind::Neon ||
4268 T->getVectorKind() == VectorKind::NeonPoly)) {
4269 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4270 llvm::Triple::ArchType
Arch =
4271 getASTContext().getTargetInfo().getTriple().getArch();
4272 if ((
Arch == llvm::Triple::aarch64 ||
4273 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4274 mangleAArch64NeonVectorType(
T);
4276 mangleNeonVectorType(
T);
4278 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4279 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4280 mangleAArch64FixedSveVectorType(
T);
4282 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4283 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4284 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4285 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4286 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4287 mangleRISCVFixedRVVVectorType(
T);
4290 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4291 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4293 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4296 mangleType(
T->getElementType());
4299void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4300 if ((
T->getVectorKind() == VectorKind::Neon ||
4301 T->getVectorKind() == VectorKind::NeonPoly)) {
4302 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4303 llvm::Triple::ArchType
Arch =
4304 getASTContext().getTargetInfo().getTriple().getArch();
4305 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4307 mangleAArch64NeonVectorType(
T);
4309 mangleNeonVectorType(
T);
4311 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4312 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4313 mangleAArch64FixedSveVectorType(
T);
4315 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4316 mangleRISCVFixedRVVVectorType(
T);
4321 mangleExpression(
T->getSizeExpr());
4323 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4325 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4328 mangleType(
T->getElementType());
4331void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4332 mangleType(
static_cast<const VectorType*
>(
T));
4334void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4336 mangleExpression(
T->getSizeExpr());
4338 mangleType(
T->getElementType());
4341void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4345 mangleVendorType(
"matrix_type");
4348 auto &ASTCtx = getASTContext();
4349 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4350 llvm::APSInt Rows(BitWidth);
4351 Rows =
T->getNumRows();
4352 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4353 llvm::APSInt Columns(BitWidth);
4354 Columns =
T->getNumColumns();
4355 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4356 mangleType(
T->getElementType());
4360void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4363 mangleVendorType(
"matrix_type");
4366 mangleTemplateArgExpr(
T->getRowExpr());
4367 mangleTemplateArgExpr(
T->getColumnExpr());
4368 mangleType(
T->getElementType());
4372void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4374 mangleQualifiers(split.
Quals,
T);
4375 mangleType(QualType(split.
Ty, 0));
4378void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4381 mangleType(
T->getPattern());
4384void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4385 if (!
T->hasSelectedType())
4386 mangleType(
T->getPattern());
4388 mangleType(
T->getSelectedType());
4391void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4392 mangleSourceName(
T->getDecl()->getIdentifier());
4395void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4397 if (
T->isKindOfType())
4398 Out <<
"U8__kindof";
4400 if (!
T->qual_empty()) {
4402 SmallString<64> QualStr;
4403 llvm::raw_svector_ostream QualOS(QualStr);
4404 QualOS <<
"objcproto";
4405 for (
const auto *I :
T->quals()) {
4406 StringRef
name = I->getName();
4409 mangleVendorQualifier(QualStr);
4412 mangleType(
T->getBaseType());
4414 if (
T->isSpecialized()) {
4417 for (
auto typeArg :
T->getTypeArgs())
4418 mangleType(typeArg);
4423void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4424 Out <<
"U13block_pointer";
4428void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4433 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4436void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4437 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4438 mangleTemplateName(TD,
T->template_arguments());
4441 mangleTemplatePrefix(
T->getTemplateName());
4446 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4451void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4462 switch (
T->getKeyword()) {
4463 case ElaboratedTypeKeyword::None:
4464 case ElaboratedTypeKeyword::Typename:
4466 case ElaboratedTypeKeyword::Struct:
4467 case ElaboratedTypeKeyword::Class:
4468 case ElaboratedTypeKeyword::Interface:
4471 case ElaboratedTypeKeyword::Union:
4474 case ElaboratedTypeKeyword::Enum:
4480 manglePrefix(
T->getQualifier());
4481 mangleSourceName(
T->getIdentifier());
4485void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4491void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4497void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4498 Expr *E =
T->getUnderlyingExpr();
4517 mangleExpression(E);
4521void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4525 StringRef BuiltinName;
4526 switch (
T->getUTTKind()) {
4527#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4528 case UnaryTransformType::Enum: \
4529 BuiltinName = "__" #Trait; \
4531#include "clang/Basic/TransformTypeTraits.def"
4533 mangleVendorType(BuiltinName);
4537 mangleType(
T->getBaseType());
4541void CXXNameMangler::mangleType(
const AutoType *
T) {
4542 assert(
T->getDeducedType().isNull() &&
4543 "Deduced AutoType shouldn't be handled here!");
4544 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4545 "shouldn't need to mangle __auto_type!");
4550 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4551 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4552 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4553 T->getTypeConstraintArguments());
4555 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4559void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4560 QualType Deduced =
T->getDeducedType();
4562 return mangleType(Deduced);
4566 "shouldn't form deduced TST unless we know we have a template");
4570void CXXNameMangler::mangleType(
const AtomicType *
T) {
4574 mangleType(
T->getValueType());
4577void CXXNameMangler::mangleType(
const PipeType *
T) {
4584void CXXNameMangler::mangleType(
const BitIntType *
T) {
4588 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4591void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4595 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4596 mangleExpression(
T->getNumBitsExpr());
4600void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4604void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4605 llvm::SmallString<64> Str(
"_Res");
4606 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4608 switch (Attrs.ResourceClass) {
4609 case llvm::dxil::ResourceClass::UAV:
4612 case llvm::dxil::ResourceClass::SRV:
4615 case llvm::dxil::ResourceClass::CBuffer:
4618 case llvm::dxil::ResourceClass::Sampler:
4624 if (Attrs.RawBuffer)
4626 if (Attrs.IsCounter)
4628 if (
T->hasContainedType())
4630 mangleVendorQualifier(Str);
4632 if (
T->hasContainedType()) {
4633 mangleType(
T->getContainedType());
4635 mangleType(
T->getWrappedType());
4638void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4639 SmallString<20> TypeNameStr;
4640 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4642 TypeNameOS <<
"spirv_type";
4644 TypeNameOS <<
"_" <<
T->getOpcode();
4645 TypeNameOS <<
"_" <<
T->getSize();
4646 TypeNameOS <<
"_" <<
T->getAlignment();
4648 mangleVendorType(TypeNameStr);
4650 for (
auto &Operand :
T->getOperands()) {
4651 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4654 case SpirvOperandKind::ConstantId:
4655 mangleVendorQualifier(
"_Const");
4656 mangleIntegerLiteral(
Operand.getResultType(),
4657 llvm::APSInt(
Operand.getValue()));
4659 case SpirvOperandKind::Literal:
4660 mangleVendorQualifier(
"_Lit");
4661 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4662 llvm::APSInt(
Operand.getValue()));
4664 case SpirvOperandKind::TypeId:
4665 mangleVendorQualifier(
"_Type");
4666 mangleType(
Operand.getResultType());
4669 llvm_unreachable(
"Invalid SpirvOperand kind");
4672 TypeNameOS <<
Operand.getKind();
4676void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4677 const llvm::APSInt &
Value) {
4684 Out << (
Value.getBoolValue() ?
'1' :
'0');
4686 mangleNumber(
Value);
4691void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4693 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4694 if (!RT->getDecl()->isAnonymousStructOrUnion())
4696 const auto *ME = dyn_cast<MemberExpr>(Base);
4699 Base = ME->getBase();
4700 IsArrow = ME->isArrow();
4703 if (
Base->isImplicitCXXThis()) {
4709 Out << (IsArrow ?
"pt" :
"dt");
4710 mangleExpression(Base);
4715void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4716 NestedNameSpecifier Qualifier,
4717 NamedDecl *firstQualifierLookup,
4718 DeclarationName member,
4719 const TemplateArgumentLoc *TemplateArgs,
4720 unsigned NumTemplateArgs,
4725 mangleMemberExprBase(base, isArrow);
4726 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4739 if (callee == fn)
return false;
4743 if (!lookup)
return false;
4760void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4762 Out << CastEncoding;
4767void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4769 InitList = Syntactic;
4770 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4771 mangleExpression(InitList->
getInit(i));
4774void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4775 const concepts::Requirement *Req) {
4776 using concepts::Requirement;
4781 auto HandleSubstitutionFailure =
4782 [&](SourceLocation Loc) {
4783 DiagnosticsEngine &Diags = Context.getDiags();
4786 "containing a substitution failure");
4787 Diags.
Report(Loc, DiagID);
4792 case Requirement::RK_Type: {
4794 if (TR->isSubstitutionFailure())
4795 return HandleSubstitutionFailure(
4796 TR->getSubstitutionDiagnostic()->DiagLoc);
4799 mangleType(TR->getType()->getType());
4803 case Requirement::RK_Simple:
4804 case Requirement::RK_Compound: {
4806 if (ER->isExprSubstitutionFailure())
4807 return HandleSubstitutionFailure(
4808 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4811 mangleExpression(ER->getExpr());
4813 if (ER->hasNoexceptRequirement())
4816 if (!ER->getReturnTypeRequirement().isEmpty()) {
4817 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4818 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4819 .getSubstitutionDiagnostic()
4823 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4828 case Requirement::RK_Nested:
4830 if (NR->hasInvalidConstraint()) {
4833 return HandleSubstitutionFailure(RequiresExprLoc);
4837 mangleExpression(NR->getConstraintExpr());
4842void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4843 bool AsTemplateArg) {
4872 QualType ImplicitlyConvertedToType;
4876 bool IsPrimaryExpr =
true;
4877 auto NotPrimaryExpr = [&] {
4878 if (AsTemplateArg && IsPrimaryExpr)
4880 IsPrimaryExpr =
false;
4883 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4884 switch (D->getKind()) {
4897 case Decl::EnumConstant: {
4904 case Decl::NonTypeTemplateParm:
4917 case Expr::NoStmtClass:
4918#define ABSTRACT_STMT(Type)
4919#define EXPR(Type, Base)
4920#define STMT(Type, Base) \
4921 case Expr::Type##Class:
4922#include "clang/AST/StmtNodes.inc"
4927 case Expr::AddrLabelExprClass:
4928 case Expr::DesignatedInitUpdateExprClass:
4929 case Expr::ImplicitValueInitExprClass:
4930 case Expr::ArrayInitLoopExprClass:
4931 case Expr::ArrayInitIndexExprClass:
4932 case Expr::NoInitExprClass:
4933 case Expr::ParenListExprClass:
4934 case Expr::MSPropertyRefExprClass:
4935 case Expr::MSPropertySubscriptExprClass:
4936 case Expr::RecoveryExprClass:
4937 case Expr::ArraySectionExprClass:
4938 case Expr::OMPArrayShapingExprClass:
4939 case Expr::OMPIteratorExprClass:
4940 case Expr::CXXInheritedCtorInitExprClass:
4941 case Expr::CXXParenListInitExprClass:
4942 case Expr::PackIndexingExprClass:
4943 llvm_unreachable(
"unexpected statement kind");
4945 case Expr::ConstantExprClass:
4950 case Expr::BlockExprClass:
4951 case Expr::ChooseExprClass:
4952 case Expr::CompoundLiteralExprClass:
4953 case Expr::ExtVectorElementExprClass:
4954 case Expr::GenericSelectionExprClass:
4955 case Expr::ObjCEncodeExprClass:
4956 case Expr::ObjCIsaExprClass:
4957 case Expr::ObjCIvarRefExprClass:
4958 case Expr::ObjCMessageExprClass:
4959 case Expr::ObjCPropertyRefExprClass:
4960 case Expr::ObjCProtocolExprClass:
4961 case Expr::ObjCSelectorExprClass:
4962 case Expr::ObjCStringLiteralClass:
4963 case Expr::ObjCBoxedExprClass:
4964 case Expr::ObjCArrayLiteralClass:
4965 case Expr::ObjCDictionaryLiteralClass:
4966 case Expr::ObjCSubscriptRefExprClass:
4967 case Expr::ObjCIndirectCopyRestoreExprClass:
4968 case Expr::ObjCAvailabilityCheckExprClass:
4969 case Expr::OffsetOfExprClass:
4970 case Expr::PredefinedExprClass:
4971 case Expr::ShuffleVectorExprClass:
4972 case Expr::ConvertVectorExprClass:
4973 case Expr::StmtExprClass:
4974 case Expr::ArrayTypeTraitExprClass:
4975 case Expr::ExpressionTraitExprClass:
4976 case Expr::VAArgExprClass:
4977 case Expr::CUDAKernelCallExprClass:
4978 case Expr::AsTypeExprClass:
4979 case Expr::PseudoObjectExprClass:
4980 case Expr::AtomicExprClass:
4981 case Expr::SourceLocExprClass:
4982 case Expr::EmbedExprClass:
4983 case Expr::BuiltinBitCastExprClass: {
4987 DiagnosticsEngine &Diags = Context.getDiags();
4989 "cannot yet mangle expression type %0");
4997 case Expr::CXXUuidofExprClass: {
5002 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5003 Out <<
"u8__uuidof";
5012 Out <<
"u8__uuidoft";
5016 Out <<
"u8__uuidofz";
5017 mangleExpression(UuidExp);
5024 case Expr::BinaryConditionalOperatorClass: {
5026 DiagnosticsEngine &Diags = Context.getDiags();
5029 "?: operator with omitted middle operand cannot be mangled");
5036 case Expr::OpaqueValueExprClass:
5037 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5039 case Expr::InitListExprClass: {
5047 case Expr::DesignatedInitExprClass: {
5050 for (
const auto &Designator : DIE->designators()) {
5051 if (Designator.isFieldDesignator()) {
5053 mangleSourceName(Designator.getFieldName());
5054 }
else if (Designator.isArrayDesignator()) {
5056 mangleExpression(DIE->getArrayIndex(Designator));
5058 assert(Designator.isArrayRangeDesignator() &&
5059 "unknown designator kind");
5061 mangleExpression(DIE->getArrayRangeStart(Designator));
5062 mangleExpression(DIE->getArrayRangeEnd(Designator));
5065 mangleExpression(DIE->getInit());
5069 case Expr::CXXDefaultArgExprClass:
5073 case Expr::CXXDefaultInitExprClass:
5077 case Expr::CXXStdInitializerListExprClass:
5081 case Expr::SubstNonTypeTemplateParmExprClass: {
5085 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5087 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5088 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5089 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5099 case Expr::UserDefinedLiteralClass:
5102 case Expr::CXXMemberCallExprClass:
5103 case Expr::CallExprClass: {
5125 CallArity = UnknownArity;
5127 mangleExpression(CE->
getCallee(), CallArity);
5129 mangleExpression(Arg);
5134 case Expr::CXXNewExprClass: {
5137 if (
New->isGlobalNew())
Out <<
"gs";
5138 Out << (
New->isArray() ?
"na" :
"nw");
5140 E =
New->placement_arg_end(); I != E; ++I)
5141 mangleExpression(*I);
5143 mangleType(
New->getAllocatedType());
5144 if (
New->hasInitializer()) {
5145 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5149 const Expr *
Init =
New->getInitializer();
5150 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5155 mangleExpression(*I);
5156 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5157 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5158 mangleExpression(PLE->getExpr(i));
5159 }
else if (
New->getInitializationStyle() ==
5160 CXXNewInitializationStyle::Braces &&
5165 mangleExpression(
Init);
5171 case Expr::CXXPseudoDestructorExprClass: {
5174 if (
const Expr *Base = PDE->getBase())
5175 mangleMemberExprBase(Base, PDE->isArrow());
5176 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5177 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5179 mangleUnresolvedPrefix(Qualifier,
5181 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5185 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5188 }
else if (Qualifier) {
5189 mangleUnresolvedPrefix(Qualifier);
5193 QualType DestroyedType = PDE->getDestroyedType();
5194 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5198 case Expr::MemberExprClass: {
5209 case Expr::UnresolvedMemberExprClass: {
5220 case Expr::CXXDependentScopeMemberExprClass: {
5222 const CXXDependentScopeMemberExpr *ME
5233 case Expr::UnresolvedLookupExprClass: {
5242 case Expr::CXXUnresolvedConstructExprClass: {
5248 assert(N == 1 &&
"unexpected form for list initialization");
5252 mangleInitListElements(IL);
5259 if (N != 1)
Out <<
'_';
5260 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5261 if (N != 1)
Out <<
'E';
5265 case Expr::CXXConstructExprClass: {
5272 "implicit CXXConstructExpr must have one argument");
5279 mangleExpression(E);
5284 case Expr::CXXTemporaryObjectExprClass: {
5295 if (!List && N != 1)
5297 if (CE->isStdInitListInitialization()) {
5304 mangleInitListElements(ILE);
5307 mangleExpression(E);
5314 case Expr::CXXScalarValueInitExprClass:
5321 case Expr::CXXNoexceptExprClass:
5327 case Expr::UnaryExprOrTypeTraitExprClass: {
5344 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5346 : ImplicitlyConvertedToType;
5348 mangleIntegerLiteral(
T,
V);
5354 auto MangleAlignofSizeofArg = [&] {
5364 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5365 StringRef Name = {}) {
5368 mangleVendorType(Name);
5379 MangleAlignofSizeofArg();
5381 case UETT_PreferredAlignOf:
5385 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5386 MangleExtensionBuiltin(SAE,
"__alignof__");
5392 MangleAlignofSizeofArg();
5396 case UETT_VectorElements:
5397 case UETT_OpenMPRequiredSimdAlign:
5399 case UETT_PtrAuthTypeDiscriminator:
5400 case UETT_DataSizeOf: {
5401 DiagnosticsEngine &Diags = Context.getDiags();
5411 case Expr::TypeTraitExprClass: {
5416 mangleVendorType(Spelling);
5417 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5418 mangleType(TSI->getType());
5424 case Expr::CXXThrowExprClass: {
5438 case Expr::CXXTypeidExprClass: {
5453 case Expr::CXXDeleteExprClass: {
5464 case Expr::UnaryOperatorClass: {
5473 case Expr::ArraySubscriptExprClass: {
5480 mangleExpression(AE->
getLHS());
5481 mangleExpression(AE->
getRHS());
5485 case Expr::MatrixSubscriptExprClass: {
5489 mangleExpression(ME->
getBase());
5495 case Expr::CompoundAssignOperatorClass:
5496 case Expr::BinaryOperatorClass: {
5504 mangleExpression(BO->
getLHS());
5505 mangleExpression(BO->
getRHS());
5509 case Expr::CXXRewrittenBinaryOperatorClass: {
5512 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5516 mangleExpression(Decomposed.
LHS);
5517 mangleExpression(Decomposed.
RHS);
5521 case Expr::ConditionalOperatorClass: {
5524 mangleOperatorName(OO_Conditional, 3);
5525 mangleExpression(CO->
getCond());
5526 mangleExpression(CO->
getLHS(), Arity);
5527 mangleExpression(CO->
getRHS(), Arity);
5531 case Expr::ImplicitCastExprClass: {
5532 ImplicitlyConvertedToType = E->
getType();
5537 case Expr::ObjCBridgedCastExprClass: {
5543 mangleCastExpression(E,
"cv");
5547 case Expr::CStyleCastExprClass:
5549 mangleCastExpression(E,
"cv");
5552 case Expr::CXXFunctionalCastExprClass: {
5556 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5557 if (CCE->getParenOrBraceRange().isInvalid())
5558 Sub = CCE->getArg(0)->IgnoreImplicit();
5559 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5560 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5561 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5564 mangleInitListElements(IL);
5567 mangleCastExpression(E,
"cv");
5572 case Expr::CXXStaticCastExprClass:
5574 mangleCastExpression(E,
"sc");
5576 case Expr::CXXDynamicCastExprClass:
5578 mangleCastExpression(E,
"dc");
5580 case Expr::CXXReinterpretCastExprClass:
5582 mangleCastExpression(E,
"rc");
5584 case Expr::CXXConstCastExprClass:
5586 mangleCastExpression(E,
"cc");
5588 case Expr::CXXAddrspaceCastExprClass:
5590 mangleCastExpression(E,
"ac");
5593 case Expr::CXXOperatorCallExprClass: {
5602 for (
unsigned i = 0; i != NumArgs; ++i)
5603 mangleExpression(CE->
getArg(i));
5607 case Expr::ParenExprClass:
5611 case Expr::ConceptSpecializationExprClass: {
5613 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5618 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5624 mangleUnresolvedName(
5625 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5626 CSE->getConceptNameInfo().getName(),
5627 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5628 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5632 case Expr::RequiresExprClass: {
5638 if (RE->getLParenLoc().isValid()) {
5640 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5641 if (RE->getLocalParameters().empty()) {
5644 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5652 FunctionTypeDepth.enterResultType();
5653 for (
const concepts::Requirement *Req : RE->getRequirements())
5654 mangleRequirement(RE->getExprLoc(), Req);
5655 FunctionTypeDepth.pop(saved);
5659 for (
const concepts::Requirement *Req : RE->getRequirements())
5660 mangleRequirement(RE->getExprLoc(), Req);
5666 case Expr::DeclRefExprClass:
5671 case Expr::SubstNonTypeTemplateParmPackExprClass:
5677 Out <<
"_SUBSTPACK_";
5680 case Expr::FunctionParmPackExprClass: {
5684 Out <<
"v110_SUBSTPACK";
5689 case Expr::DependentScopeDeclRefExprClass: {
5698 case Expr::CXXBindTemporaryExprClass:
5702 case Expr::ExprWithCleanupsClass:
5706 case Expr::FloatingLiteralClass: {
5713 case Expr::FixedPointLiteralClass:
5715 mangleFixedPointLiteral();
5718 case Expr::CharacterLiteralClass:
5722 Out << cast<CharacterLiteral>(E)->getValue();
5727 case Expr::ObjCBoolLiteralExprClass:
5730 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5734 case Expr::CXXBoolLiteralExprClass:
5737 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5741 case Expr::IntegerLiteralClass: {
5745 Value.setIsSigned(
true);
5750 case Expr::ImaginaryLiteralClass: {
5757 if (
const FloatingLiteral *Imag =
5758 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5760 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5762 mangleFloat(Imag->getValue());
5767 Value.setIsSigned(
true);
5768 mangleNumber(
Value);
5774 case Expr::StringLiteralClass: {
5784 case Expr::GNUNullExprClass:
5787 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5790 case Expr::CXXNullPtrLiteralExprClass: {
5796 case Expr::LambdaExprClass: {
5807 case Expr::PackExpansionExprClass:
5813 case Expr::SizeOfPackExprClass: {
5816 if (SPE->isPartiallySubstituted()) {
5818 for (
const auto &A : SPE->getPartialArguments())
5819 mangleTemplateArg(A,
false);
5825 const NamedDecl *Pack = SPE->getPack();
5826 if (
const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
5827 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5828 else if (
const NonTypeTemplateParmDecl *NTTP
5829 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5830 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5831 else if (
const TemplateTemplateParmDecl *TempTP
5832 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5833 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5839 case Expr::MaterializeTemporaryExprClass:
5843 case Expr::CXXFoldExprClass: {
5846 if (FE->isLeftFold())
5847 Out << (FE->getInit() ?
"fL" :
"fl");
5849 Out << (FE->getInit() ?
"fR" :
"fr");
5851 if (FE->getOperator() == BO_PtrMemD)
5859 mangleExpression(FE->getLHS());
5861 mangleExpression(FE->getRHS());
5865 case Expr::CXXThisExprClass:
5870 case Expr::CoawaitExprClass:
5873 Out <<
"v18co_await";
5877 case Expr::DependentCoawaitExprClass:
5880 Out <<
"v18co_await";
5884 case Expr::CoyieldExprClass:
5887 Out <<
"v18co_yield";
5890 case Expr::SYCLUniqueStableNameExprClass: {
5894 Out <<
"u33__builtin_sycl_unique_stable_name";
5895 mangleType(USN->getTypeSourceInfo()->getType());
5900 case Expr::HLSLOutArgExprClass:
5902 "cannot mangle hlsl temporary value; mangling wrong thing?");
5903 case Expr::OpenACCAsteriskSizeExprClass: {
5905 DiagnosticsEngine &Diags = Context.getDiags();
5908 "cannot yet mangle OpenACC Asterisk Size expression");
5914 if (AsTemplateArg && !IsPrimaryExpr)
5946void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
5953 assert(parmDepth < FunctionTypeDepth.getDepth());
5954 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
5955 if (FunctionTypeDepth.isInResultType())
5958 if (nestingDepth == 0) {
5961 Out <<
"fL" << (nestingDepth - 1) <<
'p';
5969 &&
"parameter's type is still an array type?");
5971 if (
const DependentAddressSpaceType *DAST =
5972 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
5979 if (parmIndex != 0) {
5980 Out << (parmIndex - 1);
5986 const CXXRecordDecl *InheritedFrom) {
6013 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6016 mangleName(InheritedFrom);
6075 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6076 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6077 if (!RD || !RD->isGenericLambda())
6093 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6094 return TTP->hasTypeConstraint();
6111 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6112 return NTTP->getType()->isInstantiationDependentType() ||
6113 NTTP->getType()->getContainedDeducedType();
6120 "A DeducedTemplateName shouldn't escape partial ordering");
6131 auto MangleTemplateParamListToString =
6133 unsigned DepthOffset) {
6134 llvm::raw_svector_ostream Stream(Buffer);
6135 CXXNameMangler(
Mangler.Context, Stream,
6136 WithTemplateDepthOffset{DepthOffset})
6137 .mangleTemplateParameterList(Params);
6140 MangleTemplateParamListToString(ParamTemplateHead,
6141 TTP->getTemplateParameters(), 0);
6145 MangleTemplateParamListToString(ArgTemplateHead,
6147 TTP->getTemplateParameters()->
getDepth());
6148 return ParamTemplateHead != ArgTemplateHead;
6158 return {
true,
nullptr};
6163 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6164 "no parameter for argument");
6185 return {
true,
nullptr};
6200 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6201 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6202 return {NeedExactType,
nullptr};
6214void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6216 unsigned NumTemplateArgs) {
6219 TemplateArgManglingInfo Info(*
this, TN);
6220 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6221 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6223 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6227void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6228 const TemplateArgumentList &AL) {
6231 TemplateArgManglingInfo Info(*
this, TN);
6232 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6233 mangleTemplateArg(Info, i, AL[i]);
6235 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6239void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6240 ArrayRef<TemplateArgument> Args) {
6243 TemplateArgManglingInfo Info(*
this, TN);
6244 for (
unsigned i = 0; i != Args.size(); ++i) {
6245 mangleTemplateArg(Info, i, Args[i]);
6247 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6251void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6252 unsigned Index, TemplateArgument A) {
6253 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6256 if (ArgInfo.TemplateParameterToMangle &&
6257 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6264 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6267 mangleTemplateArg(A, ArgInfo.NeedExactType);
6270void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6280 llvm_unreachable(
"Cannot mangle NULL template argument");
6308 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6309 TPO->getValue(),
true,
6314 ASTContext &Ctx = Context.getASTContext();
6322 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6330 ArrayRef<APValue::LValuePathEntry>(),
6343 true, NeedExactType);
6349 mangleTemplateArg(P, NeedExactType);
6355void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6356 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6357 mangleExpression(E, UnknownArity,
true);
6372 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6373 const ValueDecl *D = DRE->getDecl();
6382 mangleExpression(E);
6395 switch (
V.getKind()) {
6403 assert(RD &&
"unexpected type for record value");
6412 if (!FD->isUnnamedBitField() &&
6422 assert(RD &&
"unexpected type for union value");
6425 if (!FD->isUnnamedBitField())
6435 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6436 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6444 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6454 return V.getFloat().isPosZero();
6457 return !
V.getFixedPoint().getValue();
6460 return V.getComplexFloatReal().isPosZero() &&
6461 V.getComplexFloatImag().isPosZero();
6464 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6467 return V.isNullPointer();
6470 return !
V.getMemberPointerDecl();
6473 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6480 T = AT->getElementType();
6482 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6527 Diags.
Report(UnionLoc, DiagID);
6532void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6534 bool NeedExactType) {
6537 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6540 bool IsPrimaryExpr =
true;
6541 auto NotPrimaryExpr = [&] {
6542 if (TopLevel && IsPrimaryExpr)
6544 IsPrimaryExpr =
false;
6548 switch (
V.getKind()) {
6557 llvm_unreachable(
"unexpected value kind in template argument");
6561 assert(RD &&
"unexpected type for record value");
6564 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6567 (Fields.back()->isUnnamedBitField() ||
6569 V.getStructField(Fields.back()->getFieldIndex())))) {
6573 if (Fields.empty()) {
6574 while (!Bases.empty() &&
6576 V.getStructBase(Bases.size() - 1)))
6577 Bases = Bases.drop_back();
6584 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6585 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6586 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6587 if (Fields[I]->isUnnamedBitField())
6589 mangleValueInTemplateArg(Fields[I]->
getType(),
6590 V.getStructField(Fields[I]->getFieldIndex()),
6599 const FieldDecl *FD =
V.getUnionField();
6617 mangleSourceName(II);
6618 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6632 unsigned N =
V.getArraySize();
6634 N =
V.getArrayInitializedElts();
6639 for (
unsigned I = 0; I != N; ++I) {
6640 const APValue &Elem = I <
V.getArrayInitializedElts()
6641 ?
V.getArrayInitializedElt(I)
6642 :
V.getArrayFiller();
6643 mangleValueInTemplateArg(ElemT, Elem,
false);
6650 const VectorType *VT =
T->
castAs<VectorType>();
6655 unsigned N =
V.getVectorLength();
6658 for (
unsigned I = 0; I != N; ++I)
6659 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6665 mangleIntegerLiteral(
T,
V.getInt());
6669 mangleFloatLiteral(
T,
V.getFloat());
6673 mangleFixedPointLiteral();
6677 const ComplexType *CT =
T->
castAs<ComplexType>();
6681 if (!
V.getComplexFloatReal().isPosZero() ||
6682 !
V.getComplexFloatImag().isPosZero())
6684 if (!
V.getComplexFloatImag().isPosZero())
6691 const ComplexType *CT =
T->
castAs<ComplexType>();
6695 if (
V.getComplexIntReal().getBoolValue() ||
6696 V.getComplexIntImag().getBoolValue())
6698 if (
V.getComplexIntImag().getBoolValue())
6707 "unexpected type for LValue template arg");
6709 if (
V.isNullPointer()) {
6710 mangleNullPointer(
T);
6714 APValue::LValueBase B =
V.getLValueBase();
6718 CharUnits Offset =
V.getLValueOffset();
6736 ASTContext &Ctx = Context.getASTContext();
6739 if (!
V.hasLValuePath()) {
6755 bool IsArrayToPointerDecayMangledAsDecl =
false;
6756 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6757 LangOptions::ClangABI::Ver11) {
6759 IsArrayToPointerDecayMangledAsDecl =
6760 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6761 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6765 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6766 !IsArrayToPointerDecayMangledAsDecl) {
6783 if (NeedExactType &&
6785 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6798 QualType TypeSoFar = B.
getType();
6799 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6803 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6805 mangleExpression(E);
6806 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6809 mangleType(QualType(TI.getType(), 0));
6812 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6822 mangleNumber(
V.getLValueOffset().getQuantity());
6829 if (!
V.getLValueOffset().isZero())
6830 mangleNumber(
V.getLValueOffset().getQuantity());
6834 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6836 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6838 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6839 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6840 TypeSoFar = AT->getElementType();
6842 const Decl *D = E.getAsBaseOrMember().getPointer();
6843 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6868 if (!
V.getMemberPointerDecl()) {
6869 mangleNullPointer(
T);
6873 ASTContext &Ctx = Context.getASTContext();
6876 if (!
V.getMemberPointerPath().empty()) {
6879 }
else if (NeedExactType &&
6881 T->
castAs<MemberPointerType>()->getPointeeType(),
6882 V.getMemberPointerDecl()->getType()) &&
6883 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6888 mangle(
V.getMemberPointerDecl());
6890 if (!
V.getMemberPointerPath().empty()) {
6900 if (TopLevel && !IsPrimaryExpr)
6904void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6914 Depth += TemplateDepthOffset;
6916 Out <<
'L' << (Depth - 1) <<
'_';
6922void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6925 }
else if (SeqID == 1) {
6932 MutableArrayRef<char> BufferRef(Buffer);
6933 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
6935 for (; SeqID != 0; SeqID /= 36) {
6936 unsigned C = SeqID % 36;
6937 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
6940 Out.write(I.base(), I - BufferRef.rbegin());
6945void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
6946 bool result = mangleSubstitution(tname);
6947 assert(result &&
"no existing substitution for template name");
6953bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
6955 if (mangleStandardSubstitution(ND))
6959 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
6969bool CXXNameMangler::mangleSubstitution(QualType
T) {
6972 return mangleSubstitution(RD);
6977 return mangleSubstitution(TypePtr);
6981 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
6982 return mangleSubstitution(TD);
6985 return mangleSubstitution(
6989bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
6990 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
6991 if (I == Substitutions.end())
6994 unsigned SeqID = I->second;
7003bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7012 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7013 if (!SD || !SD->getIdentifier()->isStr(Name))
7016 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7019 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7020 if (TemplateArgs.
size() != 1)
7023 if (TemplateArgs[0].getAsType() != A)
7026 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7035bool CXXNameMangler::isStdCharSpecialization(
7036 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7037 bool HasAllocator) {
7042 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7045 QualType A = TemplateArgs[0].getAsType();
7053 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7057 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7066bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7068 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7076 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7077 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7097 if (
const ClassTemplateSpecializationDecl *SD =
7098 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7099 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7108 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7115 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7122 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7129 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7139void CXXNameMangler::addSubstitution(QualType
T) {
7142 addSubstitution(RD);
7148 addSubstitution(TypePtr);
7152 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7153 return addSubstitution(TD);
7159void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7160 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7161 Substitutions[Ptr] = SeqID++;
7164void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7165 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7166 if (
Other->SeqID > SeqID) {
7167 Substitutions.swap(
Other->Substitutions);
7168 SeqID =
Other->SeqID;
7172CXXNameMangler::AbiTagList
7173CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7175 if (DisableDerivedAbiTags)
7176 return AbiTagList();
7178 llvm::raw_null_ostream NullOutStream;
7179 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7180 TrackReturnTypeTags.disableDerivedAbiTags();
7182 const FunctionProtoType *Proto =
7184 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7185 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
7187 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
7188 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7190 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7193CXXNameMangler::AbiTagList
7194CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7196 if (DisableDerivedAbiTags)
7197 return AbiTagList();
7199 llvm::raw_null_ostream NullOutStream;
7200 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7201 TrackVariableType.disableDerivedAbiTags();
7203 TrackVariableType.mangleType(VD->
getType());
7205 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7208bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7209 const VarDecl *VD) {
7210 llvm::raw_null_ostream NullOutStream;
7211 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7212 TrackAbiTags.mangle(VD);
7213 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7226void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7230 "Invalid mangleName() call, argument is not a variable or function!");
7232 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7233 getASTContext().getSourceManager(),
7234 "Mangling declaration");
7236 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7238 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7239 return Mangler.mangle(GlobalDecl(CD,
Type));
7242 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7244 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7245 return Mangler.mangle(GlobalDecl(DD,
Type));
7248 CXXNameMangler Mangler(*
this, Out, D);
7252void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7254 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7258void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7260 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7282 auto &LangOpts = Context.getLangOpts();
7285 Context.baseForVTableAuthentication(ThisRD);
7286 unsigned TypedDiscriminator =
7287 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7288 Mangler.mangleVendorQualifier(
"__vtptrauth");
7289 auto &ManglerStream = Mangler.getStream();
7290 ManglerStream <<
"I";
7291 if (
const auto *ExplicitAuth =
7292 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7293 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7295 if (ExplicitAuth->getAddressDiscrimination() ==
7296 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7297 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7299 ManglerStream <<
"Lb"
7300 << (ExplicitAuth->getAddressDiscrimination() ==
7301 VTablePointerAuthenticationAttr::AddressDiscrimination);
7303 switch (ExplicitAuth->getExtraDiscrimination()) {
7304 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7305 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7306 ManglerStream <<
"Lj" << TypedDiscriminator;
7308 ManglerStream <<
"Lj" << 0;
7311 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7312 ManglerStream <<
"Lj" << TypedDiscriminator;
7314 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7315 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7317 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7318 ManglerStream <<
"Lj" << 0;
7322 ManglerStream <<
"Lj"
7323 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7324 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7325 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7326 ManglerStream <<
"Lj" << TypedDiscriminator;
7328 ManglerStream <<
"Lj" << 0;
7330 ManglerStream <<
"E";
7333void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7334 const ThunkInfo &Thunk,
7335 bool ElideOverrideInfo,
7345 "Use mangleCXXDtor for destructor decls!");
7346 CXXNameMangler Mangler(*
this, Out);
7347 Mangler.getStream() <<
"_ZT";
7349 Mangler.getStream() <<
'c';
7360 Mangler.mangleFunctionEncoding(MD);
7361 if (!ElideOverrideInfo)
7365void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7367 const ThunkInfo &Thunk,
7368 bool ElideOverrideInfo,
7372 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7373 Mangler.getStream() <<
"_ZT";
7375 auto &ThisAdjustment = Thunk.
This;
7377 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7378 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7380 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7381 if (!ElideOverrideInfo)
7386void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7390 CXXNameMangler Mangler(*
this, Out);
7393 Mangler.getStream() <<
"_ZGV";
7394 Mangler.mangleName(D);
7397void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7402 Out <<
"__cxx_global_var_init";
7405void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7408 CXXNameMangler Mangler(*
this, Out);
7409 Mangler.getStream() <<
"__dtor_";
7410 if (shouldMangleDeclName(D))
7413 Mangler.getStream() << D->
getName();
7416void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7420 CXXNameMangler Mangler(*
this, Out);
7421 Mangler.getStream() <<
"__finalize_";
7422 if (shouldMangleDeclName(D))
7425 Mangler.getStream() << D->
getName();
7428void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7429 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7430 CXXNameMangler Mangler(*
this, Out);
7431 Mangler.getStream() <<
"__filt_";
7433 if (shouldMangleDeclName(EnclosingFD))
7434 Mangler.mangle(EnclosingDecl);
7436 Mangler.getStream() << EnclosingFD->getName();
7439void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7440 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7441 CXXNameMangler Mangler(*
this, Out);
7442 Mangler.getStream() <<
"__fin_";
7444 if (shouldMangleDeclName(EnclosingFD))
7445 Mangler.mangle(EnclosingDecl);
7447 Mangler.getStream() << EnclosingFD->getName();
7450void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7453 CXXNameMangler Mangler(*
this, Out);
7454 Mangler.getStream() <<
"_ZTH";
7455 Mangler.mangleName(D);
7459ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7462 CXXNameMangler Mangler(*
this, Out);
7463 Mangler.getStream() <<
"_ZTW";
7464 Mangler.mangleName(D);
7467void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7468 unsigned ManglingNumber,
7472 CXXNameMangler Mangler(*
this, Out);
7473 Mangler.getStream() <<
"_ZGR";
7474 Mangler.mangleName(D);
7475 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7476 Mangler.mangleSeqID(ManglingNumber - 1);
7479void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7482 CXXNameMangler Mangler(*
this, Out);
7483 Mangler.getStream() <<
"_ZTV";
7484 Mangler.mangleCXXRecordDecl(RD);
7487void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7490 CXXNameMangler Mangler(*
this, Out);
7491 Mangler.getStream() <<
"_ZTT";
7492 Mangler.mangleCXXRecordDecl(RD);
7495void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7497 const CXXRecordDecl *
Type,
7500 CXXNameMangler Mangler(*
this, Out);
7501 Mangler.getStream() <<
"_ZTC";
7504 bool SuppressSubstitution =
7505 getASTContext().getLangOpts().getClangABICompat() <=
7506 LangOptions::ClangABI::Ver19;
7507 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7508 Mangler.getStream() << Offset;
7509 Mangler.getStream() <<
'_';
7510 Mangler.mangleCXXRecordDecl(
Type);
7513void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7515 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7516 CXXNameMangler Mangler(*
this, Out);
7517 Mangler.getStream() <<
"_ZTI";
7518 Mangler.mangleType(Ty);
7521void ItaniumMangleContextImpl::mangleCXXRTTIName(
7522 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7524 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7525 Mangler.getStream() <<
"_ZTS";
7526 Mangler.mangleType(Ty);
7529void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7530 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7531 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7534void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7535 llvm_unreachable(
"Can't mangle string literals");
7538void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7540 CXXNameMangler Mangler(*
this, Out);
7541 Mangler.mangleLambdaSig(Lambda);
7544void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7547 CXXNameMangler Mangler(*
this, Out);
7548 Mangler.getStream() <<
"_ZGI";
7552 auto Partition = M->
Name.find(
':');
7553 Mangler.mangleModuleNamePrefix(
7554 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7562 return new ItaniumMangleContextImpl(
7565 return std::nullopt;
7574 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_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.