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 *DTST =
1315 type->getAs<DependentTemplateSpecializationType>()) {
1316 if (!mangleSubstitution(QualType(DTST, 0))) {
1318 DTST->getDependentTemplateName());
1324 mangleTemplateArgs(
Template, DTST->template_arguments());
1325 addSubstitution(QualType(DTST, 0));
1327 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1329 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1330 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1335 assert(DNT->getQualifier());
1336 manglePrefix(DNT->getQualifier());
1338 mangleSourceName(DNT->getIdentifier());
1341 addSubstitution(QualType(DNT, 0));
1353void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1371 case NestedNameSpecifier::Kind::Null:
1372 llvm_unreachable(
"unexpected null nested name specifier");
1374 case NestedNameSpecifier::Kind::Global:
1384 case NestedNameSpecifier::Kind::MicrosoftSuper:
1385 llvm_unreachable(
"Can't mangle __super specifier");
1387 case NestedNameSpecifier::Kind::Namespace: {
1390 mangleUnresolvedPrefix(Prefix,
1394 mangleSourceNameWithAbiTags(Namespace);
1398 case NestedNameSpecifier::Kind::Type: {
1406 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1407 mangleUnresolvedPrefix(Prefix,
1414 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1429void CXXNameMangler::mangleUnresolvedName(
1430 NestedNameSpecifier Qualifier, DeclarationName name,
1431 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1432 unsigned knownArity) {
1434 mangleUnresolvedPrefix(Qualifier);
1435 switch (
name.getNameKind()) {
1438 mangleSourceName(
name.getAsIdentifierInfo());
1443 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1450 mangleOperatorName(name, knownArity);
1453 llvm_unreachable(
"Can't mangle a constructor name!");
1455 llvm_unreachable(
"Can't mangle a using directive name!");
1457 llvm_unreachable(
"Can't mangle a deduction guide name!");
1461 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1467 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1470void CXXNameMangler::mangleUnqualifiedName(
1471 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1472 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1473 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1480 mangleModuleName(ND);
1484 auto *FD = dyn_cast<FunctionDecl>(ND);
1485 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1487 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1488 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1492 unsigned Arity = KnownArity;
1498 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1505 for (
auto *BD : DD->bindings())
1506 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1508 writeAbiTags(ND, AdditionalAbiTags);
1512 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1515 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1516 llvm::raw_svector_ostream GUIDOS(GUID);
1517 Context.mangleMSGuidDecl(GD, GUIDOS);
1518 Out << GUID.size() << GUID;
1522 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1525 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1526 TPO->getValue(),
true);
1544 if (Context.isInternalLinkageDecl(ND))
1547 bool IsRegCall = FD &&
1551 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1553 bool IsOCLDeviceStub =
1555 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1558 mangleDeviceStubName(II);
1559 else if (IsOCLDeviceStub)
1560 mangleOCLDeviceStubName(II);
1562 mangleRegCallName(II);
1564 mangleSourceName(II);
1566 writeAbiTags(ND, AdditionalAbiTags);
1571 assert(ND &&
"mangling empty name without declaration");
1573 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1576 Out <<
"12_GLOBAL__N_1";
1581 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1583 const auto *RD = VD->getType()->castAsRecordDecl();
1594 assert(RD->isAnonymousStructOrUnion()
1595 &&
"Expected anonymous struct or union!");
1596 const FieldDecl *FD = RD->findFirstNamedDataMember();
1602 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1622 "Typedef should not be in another decl context!");
1623 assert(D->getDeclName().getAsIdentifierInfo() &&
1624 "Typedef was not named!");
1625 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1626 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1629 writeAbiTags(TD,
nullptr);
1638 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1639 UnsignedOrNone DeviceNumber =
1640 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1646 if (
Record->isLambda() &&
1647 ((DeviceNumber && *DeviceNumber > 0) ||
1648 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1649 assert(!AdditionalAbiTags &&
1650 "Lambda type cannot have additional abi tags");
1657 unsigned UnnamedMangle =
1658 getASTContext().getManglingNumber(TD, Context.isAux());
1660 if (UnnamedMangle > 1)
1661 Out << UnnamedMangle - 2;
1663 writeAbiTags(TD, AdditionalAbiTags);
1669 unsigned AnonStructId =
1671 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1678 Str += llvm::utostr(AnonStructId);
1688 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1691 const CXXRecordDecl *InheritedFrom =
nullptr;
1693 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1694 if (
auto Inherited =
1696 InheritedFrom = Inherited.getConstructor()->
getParent();
1697 InheritedTemplateName =
1698 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1699 InheritedTemplateArgs =
1700 Inherited.getConstructor()->getTemplateSpecializationArgs();
1706 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1714 if (InheritedTemplateArgs)
1715 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1717 writeAbiTags(ND, AdditionalAbiTags);
1725 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1731 writeAbiTags(ND, AdditionalAbiTags);
1735 if (ND && Arity == UnknownArity) {
1739 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1740 if (MD->isImplicitObjectMemberFunction())
1746 mangleOperatorName(Name, Arity);
1747 writeAbiTags(ND, AdditionalAbiTags);
1751 llvm_unreachable(
"Can't mangle a deduction guide name!");
1754 llvm_unreachable(
"Can't mangle a using directive name!");
1758void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1762 if (getASTContext().getLangOpts().RegCall4)
1763 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1766 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1770void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1774 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1778void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1782 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1783 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1784 << OCLDeviceStubNamePrefix << II->
getName();
1787void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1794void CXXNameMangler::mangleNestedName(GlobalDecl GD,
1795 const DeclContext *DC,
1796 const AbiTagList *AdditionalAbiTags,
1805 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1806 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1809 if (
Method->isExplicitObjectMemberFunction())
1812 mangleQualifiers(MethodQuals);
1813 mangleRefQualifier(
Method->getRefQualifier());
1817 const TemplateArgumentList *TemplateArgs =
nullptr;
1818 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1819 mangleTemplatePrefix(TD, NoFunction);
1822 manglePrefix(DC, NoFunction);
1823 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1828void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1829 ArrayRef<TemplateArgument> Args) {
1834 mangleTemplatePrefix(TD);
1840void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1841 GlobalDecl GD,
const NamedDecl *PrefixND,
1842 const AbiTagList *AdditionalAbiTags) {
1851 mangleClosurePrefix(PrefixND);
1852 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1863 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1865 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1872void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1873 const AbiTagList *AdditionalAbiTags) {
1881 const RecordDecl *RD = GetLocalClassDecl(D);
1882 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1887 AbiTagState LocalAbiTags(AbiTags);
1889 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC))
1891 else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
1892 mangleBlockForPrefix(BD);
1898 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1912 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1914 if (
const ParmVarDecl *Parm
1916 if (
const FunctionDecl *
Func
1921 mangleNumber(
Num - 2);
1930 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1931 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1932 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1933 mangleClosurePrefix(PrefixND,
true );
1935 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1936 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1937 mangleUnqualifiedBlock(BD);
1940 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1941 AdditionalAbiTags,
true );
1943 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1946 if (
const ParmVarDecl *Parm
1947 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1948 if (
const FunctionDecl *
Func
1953 mangleNumber(
Num - 2);
1958 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1959 mangleUnqualifiedBlock(BD);
1961 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1964 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1966 if (Context.getNextDiscriminator(ND, disc)) {
1970 Out <<
"__" << disc <<
'_';
1975void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1976 if (GetLocalClassDecl(
Block)) {
1977 mangleLocalName(
Block,
nullptr);
1980 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
1981 if (isLocalContainerContext(DC)) {
1982 mangleLocalName(
Block,
nullptr);
1985 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
1986 mangleClosurePrefix(PrefixND);
1989 mangleUnqualifiedBlock(
Block);
1992void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
1995 if (Decl *Context =
Block->getBlockManglingContextDecl()) {
1996 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
1998 Context->getDeclContext()->isRecord()) {
2001 mangleSourceNameWithAbiTags(ND);
2008 unsigned Number =
Block->getBlockManglingNumber();
2012 Number = Context.getBlockId(
Block,
false);
2030void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2032 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2033 if (Ty->isParameterPack())
2035 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2036 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2039 mangleTypeConstraint(Constraint);
2043 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2044 if (Tn->isExpandedParameterPack()) {
2045 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2047 mangleType(Tn->getExpansionType(I));
2050 QualType
T = Tn->getType();
2051 if (Tn->isParameterPack()) {
2053 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2054 T = PackExpansion->getPattern();
2059 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2060 if (Tt->isExpandedParameterPack()) {
2061 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2063 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2065 if (Tt->isParameterPack())
2067 mangleTemplateParameterList(Tt->getTemplateParameters());
2072void CXXNameMangler::mangleTemplateParameterList(
2073 const TemplateParameterList *Params) {
2075 for (
auto *Param : *Params)
2076 mangleTemplateParamDecl(Param);
2077 mangleRequiresClause(Params->getRequiresClause());
2081void CXXNameMangler::mangleTypeConstraint(
2082 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2083 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2085 mangleTemplateName(
Concept, Arguments);
2087 mangleUnscopedName(
Concept, DC,
nullptr);
2089 mangleNestedName(
Concept, DC,
nullptr);
2092void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2093 llvm::SmallVector<TemplateArgument, 8> Args;
2095 for (
const TemplateArgumentLoc &ArgLoc :
2097 Args.push_back(ArgLoc.getArgument());
2102void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2104 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2106 mangleExpression(RequiresClause);
2110void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2114 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2117 if (
const IdentifierInfo *Name
2119 mangleSourceName(Name);
2120 const TemplateArgumentList *TemplateArgs =
nullptr;
2129 mangleLambdaSig(Lambda);
2143 UnsignedOrNone DeviceNumber =
2144 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2148 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2150 mangleNumber(Number - 2);
2154void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2157 mangleTemplateParamDecl(D);
2161 mangleRequiresClause(TPL->getRequiresClause());
2165 mangleBareFunctionType(Proto,
false,
2169void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2171 case NestedNameSpecifier::Kind::Null:
2172 case NestedNameSpecifier::Kind::Global:
2176 case NestedNameSpecifier::Kind::MicrosoftSuper:
2177 llvm_unreachable(
"Can't mangle __super specifier");
2179 case NestedNameSpecifier::Kind::Namespace:
2180 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2183 case NestedNameSpecifier::Kind::Type:
2184 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2188 llvm_unreachable(
"unexpected nested name specifier");
2191void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2204 if (NoFunction && isLocalContainerContext(DC))
2208 if (mangleSubstitution(ND))
2212 const TemplateArgumentList *TemplateArgs =
nullptr;
2213 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2214 mangleTemplatePrefix(TD);
2216 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2217 mangleClosurePrefix(PrefixND, NoFunction);
2218 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2220 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2221 manglePrefix(DC, NoFunction);
2222 mangleUnqualifiedName(ND, DC,
nullptr);
2225 addSubstitution(ND);
2232 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2233 return mangleTemplatePrefix(TD);
2236 assert(
Dependent &&
"unexpected template name kind");
2240 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2241 if (!Clang11Compat && mangleSubstitution(
Template))
2244 manglePrefix(
Dependent->getQualifier());
2246 if (Clang11Compat && mangleSubstitution(
Template))
2249 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2250 const IdentifierInfo *Id = Name.getIdentifier())
2251 mangleSourceName(Id);
2253 mangleOperatorName(Name.getOperator(), UnknownArity);
2258void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2267 if (mangleSubstitution(ND))
2271 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2272 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2274 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2275 manglePrefix(DC, NoFunction);
2277 mangleUnqualifiedName(GD, DC,
nullptr);
2283 addSubstitution(ND);
2286const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2287 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2290 const NamedDecl *Context =
nullptr;
2291 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2292 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2293 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2295 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2309void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2312 if (mangleSubstitution(ND))
2315 const TemplateArgumentList *TemplateArgs =
nullptr;
2316 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2317 mangleTemplatePrefix(TD, NoFunction);
2320 const auto *DC = Context.getEffectiveDeclContext(ND);
2321 manglePrefix(DC, NoFunction);
2322 mangleUnqualifiedName(ND, DC,
nullptr);
2327 addSubstitution(ND);
2336 if (mangleSubstitution(TN))
2339 TemplateDecl *TD =
nullptr;
2349 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2350 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2357 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2366 mangleUnresolvedPrefix(
Dependent->getQualifier());
2367 mangleSourceName(II);
2376 SubstTemplateTemplateParmStorage *subst
2387 Out <<
"_SUBSTPACK_";
2391 llvm_unreachable(
"Unexpected DeducedTemplate");
2394 addSubstitution(TN);
2397bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2403 case Type::Adjusted:
2405 case Type::ArrayParameter:
2407 case Type::BlockPointer:
2408 case Type::LValueReference:
2409 case Type::RValueReference:
2410 case Type::MemberPointer:
2411 case Type::ConstantArray:
2412 case Type::IncompleteArray:
2413 case Type::VariableArray:
2414 case Type::DependentSizedArray:
2415 case Type::DependentAddressSpace:
2416 case Type::DependentVector:
2417 case Type::DependentSizedExtVector:
2419 case Type::ExtVector:
2420 case Type::ConstantMatrix:
2421 case Type::DependentSizedMatrix:
2422 case Type::FunctionProto:
2423 case Type::FunctionNoProto:
2425 case Type::Attributed:
2426 case Type::BTFTagAttributed:
2427 case Type::HLSLAttributedResource:
2428 case Type::HLSLInlineSpirv:
2430 case Type::DeducedTemplateSpecialization:
2431 case Type::PackExpansion:
2432 case Type::ObjCObject:
2433 case Type::ObjCInterface:
2434 case Type::ObjCObjectPointer:
2435 case Type::ObjCTypeParam:
2438 case Type::MacroQualified:
2440 case Type::DependentBitInt:
2441 case Type::CountAttributed:
2442 llvm_unreachable(
"type is illegal as a nested name specifier");
2444 case Type::SubstBuiltinTemplatePack:
2449 Out <<
"_SUBSTBUILTINPACK_";
2451 case Type::SubstTemplateTypeParmPack:
2456 Out <<
"_SUBSTPACK_";
2463 case Type::TypeOfExpr:
2465 case Type::Decltype:
2466 case Type::PackIndexing:
2467 case Type::TemplateTypeParm:
2468 case Type::UnaryTransform:
2481 case Type::SubstTemplateTypeParm: {
2485 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2487 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2488 goto unresolvedType;
2495 case Type::PredefinedSugar:
2499 case Type::UnresolvedUsing:
2500 mangleSourceNameWithAbiTags(
2506 mangleSourceNameWithAbiTags(
2510 case Type::TemplateSpecialization: {
2511 const TemplateSpecializationType *TST =
2521 assert(TD &&
"no template for template specialization type");
2523 goto unresolvedType;
2525 mangleSourceNameWithAbiTags(TD);
2533 llvm_unreachable(
"invalid base for a template specialization type");
2536 SubstTemplateTemplateParmStorage *subst =
2547 Out <<
"_SUBSTPACK_";
2553 mangleSourceNameWithAbiTags(TD);
2563 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2567 case Type::InjectedClassName:
2573 case Type::DependentName:
2577 case Type::DependentTemplateSpecialization: {
2578 const DependentTemplateSpecializationType *DTST =
2581 DTST->getDependentTemplateName());
2582 const DependentTemplateStorage &S = DTST->getDependentTemplateName();
2584 mangleTemplateArgs(
Template, DTST->template_arguments());
2596void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2606 llvm_unreachable(
"Not an operator name");
2629 case OO_New:
Out <<
"nw";
break;
2631 case OO_Array_New:
Out <<
"na";
break;
2633 case OO_Delete:
Out <<
"dl";
break;
2635 case OO_Array_Delete:
Out <<
"da";
break;
2639 Out << (Arity == 1?
"ps" :
"pl");
break;
2643 Out << (Arity == 1?
"ng" :
"mi");
break;
2647 Out << (Arity == 1?
"ad" :
"an");
break;
2652 Out << (Arity == 1?
"de" :
"ml");
break;
2654 case OO_Tilde:
Out <<
"co";
break;
2656 case OO_Slash:
Out <<
"dv";
break;
2658 case OO_Percent:
Out <<
"rm";
break;
2660 case OO_Pipe:
Out <<
"or";
break;
2662 case OO_Caret:
Out <<
"eo";
break;
2664 case OO_Equal:
Out <<
"aS";
break;
2666 case OO_PlusEqual:
Out <<
"pL";
break;
2668 case OO_MinusEqual:
Out <<
"mI";
break;
2670 case OO_StarEqual:
Out <<
"mL";
break;
2672 case OO_SlashEqual:
Out <<
"dV";
break;
2674 case OO_PercentEqual:
Out <<
"rM";
break;
2676 case OO_AmpEqual:
Out <<
"aN";
break;
2678 case OO_PipeEqual:
Out <<
"oR";
break;
2680 case OO_CaretEqual:
Out <<
"eO";
break;
2682 case OO_LessLess:
Out <<
"ls";
break;
2684 case OO_GreaterGreater:
Out <<
"rs";
break;
2686 case OO_LessLessEqual:
Out <<
"lS";
break;
2688 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2690 case OO_EqualEqual:
Out <<
"eq";
break;
2692 case OO_ExclaimEqual:
Out <<
"ne";
break;
2694 case OO_Less:
Out <<
"lt";
break;
2696 case OO_Greater:
Out <<
"gt";
break;
2698 case OO_LessEqual:
Out <<
"le";
break;
2700 case OO_GreaterEqual:
Out <<
"ge";
break;
2702 case OO_Exclaim:
Out <<
"nt";
break;
2704 case OO_AmpAmp:
Out <<
"aa";
break;
2706 case OO_PipePipe:
Out <<
"oo";
break;
2708 case OO_PlusPlus:
Out <<
"pp";
break;
2710 case OO_MinusMinus:
Out <<
"mm";
break;
2712 case OO_Comma:
Out <<
"cm";
break;
2714 case OO_ArrowStar:
Out <<
"pm";
break;
2716 case OO_Arrow:
Out <<
"pt";
break;
2718 case OO_Call:
Out <<
"cl";
break;
2720 case OO_Subscript:
Out <<
"ix";
break;
2725 case OO_Conditional:
Out <<
"qu";
break;
2728 case OO_Coawait:
Out <<
"aw";
break;
2731 case OO_Spaceship:
Out <<
"ss";
break;
2735 llvm_unreachable(
"Not an overloaded operator");
2739void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2758 SmallString<64> ASString;
2764 if (TargetAS != 0 ||
2766 ASString =
"AS" + llvm::utostr(TargetAS);
2769 default: llvm_unreachable(
"Not a language specific address space");
2773 case LangAS::opencl_global:
2774 ASString =
"CLglobal";
2776 case LangAS::opencl_global_device:
2777 ASString =
"CLdevice";
2779 case LangAS::opencl_global_host:
2780 ASString =
"CLhost";
2782 case LangAS::opencl_local:
2783 ASString =
"CLlocal";
2785 case LangAS::opencl_constant:
2786 ASString =
"CLconstant";
2788 case LangAS::opencl_private:
2789 ASString =
"CLprivate";
2791 case LangAS::opencl_generic:
2792 ASString =
"CLgeneric";
2796 case LangAS::sycl_global:
2797 ASString =
"SYglobal";
2799 case LangAS::sycl_global_device:
2800 ASString =
"SYdevice";
2802 case LangAS::sycl_global_host:
2803 ASString =
"SYhost";
2805 case LangAS::sycl_local:
2806 ASString =
"SYlocal";
2808 case LangAS::sycl_private:
2809 ASString =
"SYprivate";
2812 case LangAS::cuda_device:
2813 ASString =
"CUdevice";
2815 case LangAS::cuda_constant:
2816 ASString =
"CUconstant";
2818 case LangAS::cuda_shared:
2819 ASString =
"CUshared";
2822 case LangAS::ptr32_sptr:
2823 ASString =
"ptr32_sptr";
2825 case LangAS::ptr32_uptr:
2829 if (!getASTContext().getTargetInfo().getTriple().isOSzOS())
2830 ASString =
"ptr32_uptr";
2837 if (!ASString.empty())
2838 mangleVendorQualifier(ASString);
2851 mangleVendorQualifier(
"__weak");
2855 mangleVendorQualifier(
"__unaligned");
2859 mangleVendorQualifier(
"__ptrauth");
2869 << unsigned(PtrAuth.isAddressDiscriminated())
2872 << PtrAuth.getExtraDiscriminator()
2887 mangleVendorQualifier(
"__strong");
2891 mangleVendorQualifier(
"__autoreleasing");
2914void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2918void CXXNameMangler::mangleVendorType(StringRef name) {
2925 switch (RefQualifier) {
2939void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2940 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2953 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2959 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2965 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
2966 if (DeducedTST->getDeducedType().isNull())
2971void CXXNameMangler::mangleType(QualType
T) {
3005 T =
T.getCanonicalType();
3011 if (
const TemplateSpecializationType *TST
3012 = dyn_cast<TemplateSpecializationType>(
T))
3013 if (!TST->isTypeAlias())
3021 =
T.getSingleStepDesugaredType(Context.getASTContext());
3028 SplitQualType split =
T.split();
3029 Qualifiers quals = split.
Quals;
3030 const Type *ty = split.
Ty;
3032 bool isSubstitutable =
3034 if (isSubstitutable && mangleSubstitution(
T))
3041 quals = Qualifiers();
3048 if (
const DependentAddressSpaceType *DAST =
3049 dyn_cast<DependentAddressSpaceType>(ty)) {
3051 mangleQualifiers(splitDAST.
Quals, DAST);
3052 mangleType(QualType(splitDAST.
Ty, 0));
3054 mangleQualifiers(quals);
3058 mangleType(QualType(ty, 0));
3062#define ABSTRACT_TYPE(CLASS, PARENT)
3063#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3065 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3067#define TYPE(CLASS, PARENT) \
3069 mangleType(static_cast<const CLASS##Type*>(ty)); \
3071#include "clang/AST/TypeNodes.inc"
3076 if (isSubstitutable)
3080void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3081 bool SuppressSubstitution) {
3082 if (mangleSubstitution(
Record))
3085 if (SuppressSubstitution)
3090void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3132 std::string type_name;
3136 if (NormalizeIntegers &&
T->isInteger()) {
3137 if (
T->isSignedInteger()) {
3138 switch (getASTContext().getTypeSize(
T)) {
3142 if (mangleSubstitution(BuiltinType::SChar))
3145 addSubstitution(BuiltinType::SChar);
3148 if (mangleSubstitution(BuiltinType::Short))
3151 addSubstitution(BuiltinType::Short);
3154 if (mangleSubstitution(BuiltinType::Int))
3157 addSubstitution(BuiltinType::Int);
3160 if (mangleSubstitution(BuiltinType::Long))
3163 addSubstitution(BuiltinType::Long);
3166 if (mangleSubstitution(BuiltinType::Int128))
3169 addSubstitution(BuiltinType::Int128);
3172 llvm_unreachable(
"Unknown integer size for normalization");
3175 switch (getASTContext().getTypeSize(
T)) {
3177 if (mangleSubstitution(BuiltinType::UChar))
3180 addSubstitution(BuiltinType::UChar);
3183 if (mangleSubstitution(BuiltinType::UShort))
3186 addSubstitution(BuiltinType::UShort);
3189 if (mangleSubstitution(BuiltinType::UInt))
3192 addSubstitution(BuiltinType::UInt);
3195 if (mangleSubstitution(BuiltinType::ULong))
3198 addSubstitution(BuiltinType::ULong);
3201 if (mangleSubstitution(BuiltinType::UInt128))
3204 addSubstitution(BuiltinType::UInt128);
3207 llvm_unreachable(
"Unknown integer size for normalization");
3212 switch (
T->getKind()) {
3213 case BuiltinType::Void:
3216 case BuiltinType::Bool:
3219 case BuiltinType::Char_U:
3220 case BuiltinType::Char_S:
3223 case BuiltinType::UChar:
3226 case BuiltinType::UShort:
3229 case BuiltinType::UInt:
3232 case BuiltinType::ULong:
3235 case BuiltinType::ULongLong:
3238 case BuiltinType::UInt128:
3241 case BuiltinType::SChar:
3244 case BuiltinType::WChar_S:
3245 case BuiltinType::WChar_U:
3248 case BuiltinType::Char8:
3251 case BuiltinType::Char16:
3254 case BuiltinType::Char32:
3257 case BuiltinType::Short:
3260 case BuiltinType::Int:
3263 case BuiltinType::Long:
3266 case BuiltinType::LongLong:
3269 case BuiltinType::Int128:
3272 case BuiltinType::Float16:
3275 case BuiltinType::ShortAccum:
3278 case BuiltinType::Accum:
3281 case BuiltinType::LongAccum:
3284 case BuiltinType::UShortAccum:
3287 case BuiltinType::UAccum:
3290 case BuiltinType::ULongAccum:
3293 case BuiltinType::ShortFract:
3296 case BuiltinType::Fract:
3299 case BuiltinType::LongFract:
3302 case BuiltinType::UShortFract:
3305 case BuiltinType::UFract:
3308 case BuiltinType::ULongFract:
3311 case BuiltinType::SatShortAccum:
3314 case BuiltinType::SatAccum:
3317 case BuiltinType::SatLongAccum:
3320 case BuiltinType::SatUShortAccum:
3323 case BuiltinType::SatUAccum:
3326 case BuiltinType::SatULongAccum:
3329 case BuiltinType::SatShortFract:
3332 case BuiltinType::SatFract:
3335 case BuiltinType::SatLongFract:
3338 case BuiltinType::SatUShortFract:
3341 case BuiltinType::SatUFract:
3344 case BuiltinType::SatULongFract:
3347 case BuiltinType::Half:
3350 case BuiltinType::Float:
3353 case BuiltinType::Double:
3356 case BuiltinType::LongDouble: {
3357 const TargetInfo *TI =
3358 getASTContext().getLangOpts().OpenMP &&
3359 getASTContext().getLangOpts().OpenMPIsTargetDevice
3360 ? getASTContext().getAuxTargetInfo()
3361 : &getASTContext().getTargetInfo();
3365 case BuiltinType::Float128: {
3366 const TargetInfo *TI =
3367 getASTContext().getLangOpts().OpenMP &&
3368 getASTContext().getLangOpts().OpenMPIsTargetDevice
3369 ? getASTContext().getAuxTargetInfo()
3370 : &getASTContext().getTargetInfo();
3374 case BuiltinType::BFloat16: {
3375 const TargetInfo *TI =
3376 ((getASTContext().getLangOpts().OpenMP &&
3377 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3378 getASTContext().getLangOpts().SYCLIsDevice)
3379 ? getASTContext().getAuxTargetInfo()
3380 : &getASTContext().getTargetInfo();
3384 case BuiltinType::Ibm128: {
3385 const TargetInfo *TI = &getASTContext().getTargetInfo();
3389 case BuiltinType::NullPtr:
3393#define BUILTIN_TYPE(Id, SingletonId)
3394#define PLACEHOLDER_TYPE(Id, SingletonId) \
3395 case BuiltinType::Id:
3396#include "clang/AST/BuiltinTypes.def"
3397 case BuiltinType::Dependent:
3399 llvm_unreachable(
"mangling a placeholder type");
3401 case BuiltinType::ObjCId:
3402 Out <<
"11objc_object";
3404 case BuiltinType::ObjCClass:
3405 Out <<
"10objc_class";
3407 case BuiltinType::ObjCSel:
3408 Out <<
"13objc_selector";
3410#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3411 case BuiltinType::Id: \
3412 type_name = "ocl_" #ImgType "_" #Suffix; \
3413 Out << type_name.size() << type_name; \
3415#include "clang/Basic/OpenCLImageTypes.def"
3416 case BuiltinType::OCLSampler:
3417 Out <<
"11ocl_sampler";
3419 case BuiltinType::OCLEvent:
3420 Out <<
"9ocl_event";
3422 case BuiltinType::OCLClkEvent:
3423 Out <<
"12ocl_clkevent";
3425 case BuiltinType::OCLQueue:
3426 Out <<
"9ocl_queue";
3428 case BuiltinType::OCLReserveID:
3429 Out <<
"13ocl_reserveid";
3431#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3432 case BuiltinType::Id: \
3433 type_name = "ocl_" #ExtType; \
3434 Out << type_name.size() << type_name; \
3436#include "clang/Basic/OpenCLExtensionTypes.def"
3440#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3441 case BuiltinType::Id: \
3442 if (T->getKind() == BuiltinType::SveBFloat16 && \
3443 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3445 mangleVendorType("__SVBFloat16_t"); \
3447 type_name = #MangledName; \
3448 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3451#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3452 case BuiltinType::Id: \
3453 type_name = #MangledName; \
3454 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3456#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3457 case BuiltinType::Id: \
3458 type_name = #MangledName; \
3459 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3461#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3462 case BuiltinType::Id: \
3463 type_name = #MangledName; \
3464 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3466#include "clang/Basic/AArch64ACLETypes.def"
3467#define PPC_VECTOR_TYPE(Name, Id, Size) \
3468 case BuiltinType::Id: \
3469 mangleVendorType(#Name); \
3471#include "clang/Basic/PPCTypes.def"
3473#define RVV_TYPE(Name, Id, SingletonId) \
3474 case BuiltinType::Id: \
3475 mangleVendorType(Name); \
3477#include "clang/Basic/RISCVVTypes.def"
3478#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3479 case BuiltinType::Id: \
3480 mangleVendorType(MangledName); \
3482#include "clang/Basic/WebAssemblyReferenceTypes.def"
3483#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3484 case BuiltinType::Id: \
3485 mangleVendorType(Name); \
3487#include "clang/Basic/AMDGPUTypes.def"
3488#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3489 case BuiltinType::Id: \
3490 mangleVendorType(#Name); \
3492#include "clang/Basic/HLSLIntangibleTypes.def"
3496StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3516#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3552 return "swiftasynccall";
3554 llvm_unreachable(
"bad calling convention");
3557void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3566 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3567 if (!CCQualifier.empty())
3568 mangleVendorQualifier(CCQualifier);
3601 llvm_unreachable(
"Unrecognised SME attribute");
3616void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3636 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3640CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3647 case ParameterABI::Ordinary:
3651 case ParameterABI::HLSLOut:
3652 case ParameterABI::HLSLInOut:
3657 case ParameterABI::SwiftContext:
3658 case ParameterABI::SwiftAsyncContext:
3659 case ParameterABI::SwiftErrorResult:
3660 case ParameterABI::SwiftIndirectResult:
3666 mangleVendorQualifier(
"ns_consumed");
3669 mangleVendorQualifier(
"noescape");
3675void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3679 Out <<
"11__SME_ATTRSI";
3681 mangleExtFunctionInfo(
T);
3698 mangleType(ExceptTy);
3709 mangleBareFunctionType(
T,
true);
3716 mangleSMEAttrs(SMEAttrs);
3719void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3725 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3727 FunctionTypeDepth.enterResultType();
3729 FunctionTypeDepth.leaveResultType();
3731 FunctionTypeDepth.pop(saved);
3735void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3736 bool MangleReturnType,
3737 const FunctionDecl *FD) {
3740 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3743 if (MangleReturnType) {
3744 FunctionTypeDepth.enterResultType();
3748 mangleVendorQualifier(
"ns_returns_retained");
3753 auto SplitReturnTy = ReturnTy.
split();
3755 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3757 mangleType(ReturnTy);
3759 FunctionTypeDepth.leaveResultType();
3767 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3781 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3782 if (Attr->isDynamic())
3783 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3785 Out <<
"U17pass_object_size" << Attr->getType();
3796 FunctionTypeDepth.enterResultType();
3800 FunctionTypeDepth.pop(saved);
3805void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3806 mangleName(
T->getDecl());
3811void CXXNameMangler::mangleType(
const EnumType *
T) {
3812 mangleType(
static_cast<const TagType*
>(
T));
3814void CXXNameMangler::mangleType(
const RecordType *
T) {
3815 mangleType(
static_cast<const TagType*
>(
T));
3817void CXXNameMangler::mangleType(
const TagType *
T) {
3818 mangleName(
T->getOriginalDecl()->getDefinitionOrSelf());
3824void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3825 Out <<
'A' <<
T->getSize() <<
'_';
3826 mangleType(
T->getElementType());
3828void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3831 if (
T->getSizeExpr())
3832 mangleExpression(
T->getSizeExpr());
3834 mangleType(
T->getElementType());
3836void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3841 if (
T->getSizeExpr())
3842 mangleExpression(
T->getSizeExpr());
3844 mangleType(
T->getElementType());
3846void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3848 mangleType(
T->getElementType());
3853void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
3855 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
3856 mangleCXXRecordDecl(RD);
3858 mangleType(QualType(
T->getQualifier().getAsType(), 0));
3860 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3881 mangleType(PointeeType);
3885void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
3886 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3890void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
3895 Out <<
"_SUBSTPACK_";
3898void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
3903 Out <<
"_SUBSTBUILTINPACK_";
3907void CXXNameMangler::mangleType(
const PointerType *
T) {
3911void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
3917void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
3923void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
3929void CXXNameMangler::mangleType(
const ComplexType *
T) {
3931 mangleType(
T->getElementType());
3937void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
3938 QualType EltType =
T->getElementType();
3939 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3940 const char *EltName =
nullptr;
3941 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3943 case BuiltinType::SChar:
3944 case BuiltinType::UChar:
3945 EltName =
"poly8_t";
3947 case BuiltinType::Short:
3948 case BuiltinType::UShort:
3949 EltName =
"poly16_t";
3951 case BuiltinType::LongLong:
3952 case BuiltinType::ULongLong:
3953 EltName =
"poly64_t";
3955 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3959 case BuiltinType::SChar: EltName =
"int8_t";
break;
3960 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3961 case BuiltinType::Short: EltName =
"int16_t";
break;
3962 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3963 case BuiltinType::Int: EltName =
"int32_t";
break;
3964 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3965 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3966 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3967 case BuiltinType::Double: EltName =
"float64_t";
break;
3968 case BuiltinType::Float: EltName =
"float32_t";
break;
3969 case BuiltinType::Half: EltName =
"float16_t";
break;
3970 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3971 case BuiltinType::MFloat8:
3972 EltName =
"mfloat8_t";
3975 llvm_unreachable(
"unexpected Neon vector element type");
3978 const char *BaseName =
nullptr;
3979 unsigned BitSize = (
T->getNumElements() *
3980 getASTContext().getTypeSize(EltType));
3982 BaseName =
"__simd64_";
3984 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
3985 BaseName =
"__simd128_";
3987 Out << strlen(BaseName) + strlen(EltName);
3988 Out << BaseName << EltName;
3991void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
3992 DiagnosticsEngine &Diags = Context.getDiags();
3995 "cannot mangle this dependent neon vector type yet");
3996 Diags.
Report(
T->getAttributeLoc(), DiagID);
4001 case BuiltinType::SChar:
4003 case BuiltinType::Short:
4005 case BuiltinType::Int:
4007 case BuiltinType::Long:
4008 case BuiltinType::LongLong:
4010 case BuiltinType::UChar:
4012 case BuiltinType::UShort:
4014 case BuiltinType::UInt:
4016 case BuiltinType::ULong:
4017 case BuiltinType::ULongLong:
4019 case BuiltinType::Half:
4021 case BuiltinType::Float:
4023 case BuiltinType::Double:
4025 case BuiltinType::BFloat16:
4027 case BuiltinType::MFloat8:
4030 llvm_unreachable(
"Unexpected vector element base type");
4037void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4038 QualType EltType =
T->getElementType();
4039 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4041 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4044 assert((BitSize == 64 || BitSize == 128) &&
4045 "Neon vector type not 64 or 128 bits");
4048 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4050 case BuiltinType::UChar:
4053 case BuiltinType::UShort:
4056 case BuiltinType::ULong:
4057 case BuiltinType::ULongLong:
4061 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4067 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4070void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4071 DiagnosticsEngine &Diags = Context.getDiags();
4074 "cannot mangle this dependent neon vector type yet");
4075 Diags.
Report(
T->getAttributeLoc(), DiagID);
4102void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4103 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4104 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4105 "expected fixed-length SVE vector!");
4107 QualType EltType =
T->getElementType();
4109 "expected builtin type for fixed-length SVE vector!");
4113 case BuiltinType::SChar:
4116 case BuiltinType::UChar: {
4117 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4123 case BuiltinType::Short:
4126 case BuiltinType::UShort:
4129 case BuiltinType::Int:
4132 case BuiltinType::UInt:
4135 case BuiltinType::Long:
4138 case BuiltinType::ULong:
4141 case BuiltinType::Half:
4144 case BuiltinType::Float:
4147 case BuiltinType::Double:
4150 case BuiltinType::BFloat16:
4154 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4157 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4159 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4162 Out <<
"9__SVE_VLSI";
4163 mangleVendorType(TypeName);
4164 Out <<
"Lj" << VecSizeInBits <<
"EE";
4167void CXXNameMangler::mangleAArch64FixedSveVectorType(
4168 const DependentVectorType *
T) {
4169 DiagnosticsEngine &Diags = Context.getDiags();
4172 "cannot mangle this dependent fixed-length SVE vector type yet");
4173 Diags.
Report(
T->getAttributeLoc(), DiagID);
4176void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4177 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4178 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4179 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4180 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4181 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4182 "expected fixed-length RVV vector!");
4184 QualType EltType =
T->getElementType();
4186 "expected builtin type for fixed-length RVV vector!");
4188 SmallString<20> TypeNameStr;
4189 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4190 TypeNameOS <<
"__rvv_";
4192 case BuiltinType::SChar:
4193 TypeNameOS <<
"int8";
4195 case BuiltinType::UChar:
4196 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4197 TypeNameOS <<
"uint8";
4199 TypeNameOS <<
"bool";
4201 case BuiltinType::Short:
4202 TypeNameOS <<
"int16";
4204 case BuiltinType::UShort:
4205 TypeNameOS <<
"uint16";
4207 case BuiltinType::Int:
4208 TypeNameOS <<
"int32";
4210 case BuiltinType::UInt:
4211 TypeNameOS <<
"uint32";
4213 case BuiltinType::Long:
4214 TypeNameOS <<
"int64";
4216 case BuiltinType::ULong:
4217 TypeNameOS <<
"uint64";
4219 case BuiltinType::Float16:
4220 TypeNameOS <<
"float16";
4222 case BuiltinType::Float:
4223 TypeNameOS <<
"float32";
4225 case BuiltinType::Double:
4226 TypeNameOS <<
"float64";
4229 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4232 unsigned VecSizeInBits;
4233 switch (
T->getVectorKind()) {
4234 case VectorKind::RVVFixedLengthMask_1:
4237 case VectorKind::RVVFixedLengthMask_2:
4240 case VectorKind::RVVFixedLengthMask_4:
4244 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4249 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4250 getASTContext().getLangOpts(),
4251 TargetInfo::ArmStreamingKind::NotStreaming);
4252 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4254 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4256 if (VecSizeInBits >= VLen)
4257 TypeNameOS << (VecSizeInBits / VLen);
4259 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4261 TypeNameOS << (VLen / VecSizeInBits);
4265 Out <<
"9__RVV_VLSI";
4266 mangleVendorType(TypeNameStr);
4267 Out <<
"Lj" << VecSizeInBits <<
"EE";
4270void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4271 const DependentVectorType *
T) {
4272 DiagnosticsEngine &Diags = Context.getDiags();
4275 "cannot mangle this dependent fixed-length RVV vector type yet");
4276 Diags.
Report(
T->getAttributeLoc(), DiagID);
4287void CXXNameMangler::mangleType(
const VectorType *
T) {
4288 if ((
T->getVectorKind() == VectorKind::Neon ||
4289 T->getVectorKind() == VectorKind::NeonPoly)) {
4290 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4291 llvm::Triple::ArchType
Arch =
4292 getASTContext().getTargetInfo().getTriple().getArch();
4293 if ((
Arch == llvm::Triple::aarch64 ||
4294 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4295 mangleAArch64NeonVectorType(
T);
4297 mangleNeonVectorType(
T);
4299 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4300 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4301 mangleAArch64FixedSveVectorType(
T);
4303 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4304 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4305 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4306 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4307 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4308 mangleRISCVFixedRVVVectorType(
T);
4311 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4312 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4314 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4317 mangleType(
T->getElementType());
4320void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4321 if ((
T->getVectorKind() == VectorKind::Neon ||
4322 T->getVectorKind() == VectorKind::NeonPoly)) {
4323 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4324 llvm::Triple::ArchType
Arch =
4325 getASTContext().getTargetInfo().getTriple().getArch();
4326 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4328 mangleAArch64NeonVectorType(
T);
4330 mangleNeonVectorType(
T);
4332 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4333 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4334 mangleAArch64FixedSveVectorType(
T);
4336 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4337 mangleRISCVFixedRVVVectorType(
T);
4342 mangleExpression(
T->getSizeExpr());
4344 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4346 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4349 mangleType(
T->getElementType());
4352void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4353 mangleType(
static_cast<const VectorType*
>(
T));
4355void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4357 mangleExpression(
T->getSizeExpr());
4359 mangleType(
T->getElementType());
4362void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4366 mangleVendorType(
"matrix_type");
4369 auto &ASTCtx = getASTContext();
4370 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4371 llvm::APSInt Rows(BitWidth);
4372 Rows =
T->getNumRows();
4373 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4374 llvm::APSInt Columns(BitWidth);
4375 Columns =
T->getNumColumns();
4376 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4377 mangleType(
T->getElementType());
4381void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4384 mangleVendorType(
"matrix_type");
4387 mangleTemplateArgExpr(
T->getRowExpr());
4388 mangleTemplateArgExpr(
T->getColumnExpr());
4389 mangleType(
T->getElementType());
4393void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4395 mangleQualifiers(split.
Quals,
T);
4396 mangleType(QualType(split.
Ty, 0));
4399void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4402 mangleType(
T->getPattern());
4405void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4406 if (!
T->hasSelectedType())
4407 mangleType(
T->getPattern());
4409 mangleType(
T->getSelectedType());
4412void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4413 mangleSourceName(
T->getDecl()->getIdentifier());
4416void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4418 if (
T->isKindOfType())
4419 Out <<
"U8__kindof";
4421 if (!
T->qual_empty()) {
4423 SmallString<64> QualStr;
4424 llvm::raw_svector_ostream QualOS(QualStr);
4425 QualOS <<
"objcproto";
4426 for (
const auto *I :
T->quals()) {
4427 StringRef
name = I->getName();
4430 mangleVendorQualifier(QualStr);
4433 mangleType(
T->getBaseType());
4435 if (
T->isSpecialized()) {
4438 for (
auto typeArg :
T->getTypeArgs())
4439 mangleType(typeArg);
4444void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4445 Out <<
"U13block_pointer";
4449void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4453 mangleType(
T->getOriginalDecl()->getCanonicalTemplateSpecializationType(
4457void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4458 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4459 mangleTemplateName(TD,
T->template_arguments());
4461 if (mangleSubstitution(QualType(
T, 0)))
4464 mangleTemplatePrefix(
T->getTemplateName());
4469 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4470 addSubstitution(QualType(
T, 0));
4474void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4485 switch (
T->getKeyword()) {
4486 case ElaboratedTypeKeyword::None:
4487 case ElaboratedTypeKeyword::Typename:
4489 case ElaboratedTypeKeyword::Struct:
4490 case ElaboratedTypeKeyword::Class:
4491 case ElaboratedTypeKeyword::Interface:
4494 case ElaboratedTypeKeyword::Union:
4497 case ElaboratedTypeKeyword::Enum:
4503 manglePrefix(
T->getQualifier());
4504 mangleSourceName(
T->getIdentifier());
4508void CXXNameMangler::mangleType(
const DependentTemplateSpecializationType *
T) {
4513 getASTContext().getDependentTemplateName(
T->getDependentTemplateName());
4514 mangleTemplatePrefix(Prefix);
4519 mangleTemplateArgs(Prefix,
T->template_arguments());
4523void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4529void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4535void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4536 Expr *E =
T->getUnderlyingExpr();
4555 mangleExpression(E);
4559void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4563 StringRef BuiltinName;
4564 switch (
T->getUTTKind()) {
4565#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4566 case UnaryTransformType::Enum: \
4567 BuiltinName = "__" #Trait; \
4569#include "clang/Basic/TransformTypeTraits.def"
4571 mangleVendorType(BuiltinName);
4575 mangleType(
T->getBaseType());
4579void CXXNameMangler::mangleType(
const AutoType *
T) {
4580 assert(
T->getDeducedType().isNull() &&
4581 "Deduced AutoType shouldn't be handled here!");
4582 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4583 "shouldn't need to mangle __auto_type!");
4588 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4589 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4590 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4591 T->getTypeConstraintArguments());
4593 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4597void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4598 QualType Deduced =
T->getDeducedType();
4600 return mangleType(Deduced);
4604 "shouldn't form deduced TST unless we know we have a template");
4608void CXXNameMangler::mangleType(
const AtomicType *
T) {
4612 mangleType(
T->getValueType());
4615void CXXNameMangler::mangleType(
const PipeType *
T) {
4622void CXXNameMangler::mangleType(
const BitIntType *
T) {
4626 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4629void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4633 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4634 mangleExpression(
T->getNumBitsExpr());
4638void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4642void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4643 llvm::SmallString<64> Str(
"_Res");
4644 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4646 switch (Attrs.ResourceClass) {
4647 case llvm::dxil::ResourceClass::UAV:
4650 case llvm::dxil::ResourceClass::SRV:
4653 case llvm::dxil::ResourceClass::CBuffer:
4656 case llvm::dxil::ResourceClass::Sampler:
4662 if (Attrs.RawBuffer)
4664 if (
T->hasContainedType())
4666 mangleVendorQualifier(Str);
4668 if (
T->hasContainedType()) {
4669 mangleType(
T->getContainedType());
4671 mangleType(
T->getWrappedType());
4674void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4675 SmallString<20> TypeNameStr;
4676 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4678 TypeNameOS <<
"spirv_type";
4680 TypeNameOS <<
"_" <<
T->getOpcode();
4681 TypeNameOS <<
"_" <<
T->getSize();
4682 TypeNameOS <<
"_" <<
T->getAlignment();
4684 mangleVendorType(TypeNameStr);
4686 for (
auto &Operand :
T->getOperands()) {
4687 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4690 case SpirvOperandKind::ConstantId:
4691 mangleVendorQualifier(
"_Const");
4692 mangleIntegerLiteral(
Operand.getResultType(),
4693 llvm::APSInt(
Operand.getValue()));
4695 case SpirvOperandKind::Literal:
4696 mangleVendorQualifier(
"_Lit");
4697 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4698 llvm::APSInt(
Operand.getValue()));
4700 case SpirvOperandKind::TypeId:
4701 mangleVendorQualifier(
"_Type");
4702 mangleType(
Operand.getResultType());
4705 llvm_unreachable(
"Invalid SpirvOperand kind");
4708 TypeNameOS <<
Operand.getKind();
4712void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4713 const llvm::APSInt &
Value) {
4720 Out << (
Value.getBoolValue() ?
'1' :
'0');
4722 mangleNumber(
Value);
4727void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4729 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4730 if (!RT->getOriginalDecl()->isAnonymousStructOrUnion())
4732 const auto *ME = dyn_cast<MemberExpr>(Base);
4735 Base = ME->getBase();
4736 IsArrow = ME->isArrow();
4739 if (
Base->isImplicitCXXThis()) {
4745 Out << (IsArrow ?
"pt" :
"dt");
4746 mangleExpression(Base);
4751void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4752 NestedNameSpecifier Qualifier,
4753 NamedDecl *firstQualifierLookup,
4754 DeclarationName member,
4755 const TemplateArgumentLoc *TemplateArgs,
4756 unsigned NumTemplateArgs,
4761 mangleMemberExprBase(base, isArrow);
4762 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4775 if (callee == fn)
return false;
4779 if (!lookup)
return false;
4796void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4798 Out << CastEncoding;
4803void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4805 InitList = Syntactic;
4806 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4807 mangleExpression(InitList->
getInit(i));
4810void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4811 const concepts::Requirement *Req) {
4812 using concepts::Requirement;
4817 auto HandleSubstitutionFailure =
4818 [&](SourceLocation Loc) {
4819 DiagnosticsEngine &Diags = Context.getDiags();
4822 "containing a substitution failure");
4823 Diags.
Report(Loc, DiagID);
4828 case Requirement::RK_Type: {
4830 if (TR->isSubstitutionFailure())
4831 return HandleSubstitutionFailure(
4832 TR->getSubstitutionDiagnostic()->DiagLoc);
4835 mangleType(TR->getType()->getType());
4839 case Requirement::RK_Simple:
4840 case Requirement::RK_Compound: {
4842 if (ER->isExprSubstitutionFailure())
4843 return HandleSubstitutionFailure(
4844 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4847 mangleExpression(ER->getExpr());
4849 if (ER->hasNoexceptRequirement())
4852 if (!ER->getReturnTypeRequirement().isEmpty()) {
4853 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4854 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4855 .getSubstitutionDiagnostic()
4859 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4864 case Requirement::RK_Nested:
4866 if (NR->hasInvalidConstraint()) {
4869 return HandleSubstitutionFailure(RequiresExprLoc);
4873 mangleExpression(NR->getConstraintExpr());
4878void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4879 bool AsTemplateArg) {
4908 QualType ImplicitlyConvertedToType;
4912 bool IsPrimaryExpr =
true;
4913 auto NotPrimaryExpr = [&] {
4914 if (AsTemplateArg && IsPrimaryExpr)
4916 IsPrimaryExpr =
false;
4919 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4920 switch (D->getKind()) {
4933 case Decl::EnumConstant: {
4940 case Decl::NonTypeTemplateParm:
4953 case Expr::NoStmtClass:
4954#define ABSTRACT_STMT(Type)
4955#define EXPR(Type, Base)
4956#define STMT(Type, Base) \
4957 case Expr::Type##Class:
4958#include "clang/AST/StmtNodes.inc"
4963 case Expr::AddrLabelExprClass:
4964 case Expr::DesignatedInitUpdateExprClass:
4965 case Expr::ImplicitValueInitExprClass:
4966 case Expr::ArrayInitLoopExprClass:
4967 case Expr::ArrayInitIndexExprClass:
4968 case Expr::NoInitExprClass:
4969 case Expr::ParenListExprClass:
4970 case Expr::MSPropertyRefExprClass:
4971 case Expr::MSPropertySubscriptExprClass:
4972 case Expr::RecoveryExprClass:
4973 case Expr::ArraySectionExprClass:
4974 case Expr::OMPArrayShapingExprClass:
4975 case Expr::OMPIteratorExprClass:
4976 case Expr::CXXInheritedCtorInitExprClass:
4977 case Expr::CXXParenListInitExprClass:
4978 case Expr::PackIndexingExprClass:
4979 llvm_unreachable(
"unexpected statement kind");
4981 case Expr::ConstantExprClass:
4986 case Expr::BlockExprClass:
4987 case Expr::ChooseExprClass:
4988 case Expr::CompoundLiteralExprClass:
4989 case Expr::ExtVectorElementExprClass:
4990 case Expr::GenericSelectionExprClass:
4991 case Expr::ObjCEncodeExprClass:
4992 case Expr::ObjCIsaExprClass:
4993 case Expr::ObjCIvarRefExprClass:
4994 case Expr::ObjCMessageExprClass:
4995 case Expr::ObjCPropertyRefExprClass:
4996 case Expr::ObjCProtocolExprClass:
4997 case Expr::ObjCSelectorExprClass:
4998 case Expr::ObjCStringLiteralClass:
4999 case Expr::ObjCBoxedExprClass:
5000 case Expr::ObjCArrayLiteralClass:
5001 case Expr::ObjCDictionaryLiteralClass:
5002 case Expr::ObjCSubscriptRefExprClass:
5003 case Expr::ObjCIndirectCopyRestoreExprClass:
5004 case Expr::ObjCAvailabilityCheckExprClass:
5005 case Expr::OffsetOfExprClass:
5006 case Expr::PredefinedExprClass:
5007 case Expr::ShuffleVectorExprClass:
5008 case Expr::ConvertVectorExprClass:
5009 case Expr::StmtExprClass:
5010 case Expr::ArrayTypeTraitExprClass:
5011 case Expr::ExpressionTraitExprClass:
5012 case Expr::VAArgExprClass:
5013 case Expr::CUDAKernelCallExprClass:
5014 case Expr::AsTypeExprClass:
5015 case Expr::PseudoObjectExprClass:
5016 case Expr::AtomicExprClass:
5017 case Expr::SourceLocExprClass:
5018 case Expr::EmbedExprClass:
5019 case Expr::BuiltinBitCastExprClass: {
5023 DiagnosticsEngine &Diags = Context.getDiags();
5025 "cannot yet mangle expression type %0");
5033 case Expr::CXXUuidofExprClass: {
5038 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5039 Out <<
"u8__uuidof";
5048 Out <<
"u8__uuidoft";
5052 Out <<
"u8__uuidofz";
5053 mangleExpression(UuidExp);
5060 case Expr::BinaryConditionalOperatorClass: {
5062 DiagnosticsEngine &Diags = Context.getDiags();
5065 "?: operator with omitted middle operand cannot be mangled");
5072 case Expr::OpaqueValueExprClass:
5073 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5075 case Expr::InitListExprClass: {
5083 case Expr::DesignatedInitExprClass: {
5086 for (
const auto &Designator : DIE->designators()) {
5087 if (Designator.isFieldDesignator()) {
5089 mangleSourceName(Designator.getFieldName());
5090 }
else if (Designator.isArrayDesignator()) {
5092 mangleExpression(DIE->getArrayIndex(Designator));
5094 assert(Designator.isArrayRangeDesignator() &&
5095 "unknown designator kind");
5097 mangleExpression(DIE->getArrayRangeStart(Designator));
5098 mangleExpression(DIE->getArrayRangeEnd(Designator));
5101 mangleExpression(DIE->getInit());
5105 case Expr::CXXDefaultArgExprClass:
5109 case Expr::CXXDefaultInitExprClass:
5113 case Expr::CXXStdInitializerListExprClass:
5117 case Expr::SubstNonTypeTemplateParmExprClass: {
5121 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5123 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5124 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5125 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5135 case Expr::UserDefinedLiteralClass:
5138 case Expr::CXXMemberCallExprClass:
5139 case Expr::CallExprClass: {
5161 CallArity = UnknownArity;
5163 mangleExpression(CE->
getCallee(), CallArity);
5165 mangleExpression(Arg);
5170 case Expr::CXXNewExprClass: {
5173 if (
New->isGlobalNew())
Out <<
"gs";
5174 Out << (
New->isArray() ?
"na" :
"nw");
5176 E =
New->placement_arg_end(); I != E; ++I)
5177 mangleExpression(*I);
5179 mangleType(
New->getAllocatedType());
5180 if (
New->hasInitializer()) {
5181 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5185 const Expr *
Init =
New->getInitializer();
5186 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5191 mangleExpression(*I);
5192 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5193 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5194 mangleExpression(PLE->getExpr(i));
5195 }
else if (
New->getInitializationStyle() ==
5196 CXXNewInitializationStyle::Braces &&
5201 mangleExpression(
Init);
5207 case Expr::CXXPseudoDestructorExprClass: {
5210 if (
const Expr *Base = PDE->getBase())
5211 mangleMemberExprBase(Base, PDE->isArrow());
5212 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5213 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5215 mangleUnresolvedPrefix(Qualifier,
5217 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5221 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5224 }
else if (Qualifier) {
5225 mangleUnresolvedPrefix(Qualifier);
5229 QualType DestroyedType = PDE->getDestroyedType();
5230 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5234 case Expr::MemberExprClass: {
5245 case Expr::UnresolvedMemberExprClass: {
5256 case Expr::CXXDependentScopeMemberExprClass: {
5258 const CXXDependentScopeMemberExpr *ME
5269 case Expr::UnresolvedLookupExprClass: {
5278 case Expr::CXXUnresolvedConstructExprClass: {
5284 assert(N == 1 &&
"unexpected form for list initialization");
5288 mangleInitListElements(IL);
5295 if (N != 1)
Out <<
'_';
5296 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5297 if (N != 1)
Out <<
'E';
5301 case Expr::CXXConstructExprClass: {
5308 "implicit CXXConstructExpr must have one argument");
5315 mangleExpression(E);
5320 case Expr::CXXTemporaryObjectExprClass: {
5331 if (!List && N != 1)
5333 if (CE->isStdInitListInitialization()) {
5340 mangleInitListElements(ILE);
5343 mangleExpression(E);
5350 case Expr::CXXScalarValueInitExprClass:
5357 case Expr::CXXNoexceptExprClass:
5363 case Expr::UnaryExprOrTypeTraitExprClass: {
5380 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5382 : ImplicitlyConvertedToType;
5384 mangleIntegerLiteral(
T,
V);
5390 auto MangleAlignofSizeofArg = [&] {
5400 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5401 StringRef Name = {}) {
5404 mangleVendorType(Name);
5415 MangleAlignofSizeofArg();
5417 case UETT_PreferredAlignOf:
5421 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5422 MangleExtensionBuiltin(SAE,
"__alignof__");
5428 MangleAlignofSizeofArg();
5432 case UETT_VectorElements:
5433 case UETT_OpenMPRequiredSimdAlign:
5435 case UETT_PtrAuthTypeDiscriminator:
5436 case UETT_DataSizeOf: {
5437 DiagnosticsEngine &Diags = Context.getDiags();
5447 case Expr::TypeTraitExprClass: {
5452 mangleVendorType(Spelling);
5453 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5454 mangleType(TSI->getType());
5460 case Expr::CXXThrowExprClass: {
5474 case Expr::CXXTypeidExprClass: {
5489 case Expr::CXXDeleteExprClass: {
5500 case Expr::UnaryOperatorClass: {
5509 case Expr::ArraySubscriptExprClass: {
5516 mangleExpression(AE->
getLHS());
5517 mangleExpression(AE->
getRHS());
5521 case Expr::MatrixSubscriptExprClass: {
5525 mangleExpression(ME->
getBase());
5531 case Expr::CompoundAssignOperatorClass:
5532 case Expr::BinaryOperatorClass: {
5540 mangleExpression(BO->
getLHS());
5541 mangleExpression(BO->
getRHS());
5545 case Expr::CXXRewrittenBinaryOperatorClass: {
5548 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5552 mangleExpression(Decomposed.
LHS);
5553 mangleExpression(Decomposed.
RHS);
5557 case Expr::ConditionalOperatorClass: {
5560 mangleOperatorName(OO_Conditional, 3);
5561 mangleExpression(CO->
getCond());
5562 mangleExpression(CO->
getLHS(), Arity);
5563 mangleExpression(CO->
getRHS(), Arity);
5567 case Expr::ImplicitCastExprClass: {
5568 ImplicitlyConvertedToType = E->
getType();
5573 case Expr::ObjCBridgedCastExprClass: {
5579 mangleCastExpression(E,
"cv");
5583 case Expr::CStyleCastExprClass:
5585 mangleCastExpression(E,
"cv");
5588 case Expr::CXXFunctionalCastExprClass: {
5592 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5593 if (CCE->getParenOrBraceRange().isInvalid())
5594 Sub = CCE->getArg(0)->IgnoreImplicit();
5595 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5596 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5597 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5600 mangleInitListElements(IL);
5603 mangleCastExpression(E,
"cv");
5608 case Expr::CXXStaticCastExprClass:
5610 mangleCastExpression(E,
"sc");
5612 case Expr::CXXDynamicCastExprClass:
5614 mangleCastExpression(E,
"dc");
5616 case Expr::CXXReinterpretCastExprClass:
5618 mangleCastExpression(E,
"rc");
5620 case Expr::CXXConstCastExprClass:
5622 mangleCastExpression(E,
"cc");
5624 case Expr::CXXAddrspaceCastExprClass:
5626 mangleCastExpression(E,
"ac");
5629 case Expr::CXXOperatorCallExprClass: {
5638 for (
unsigned i = 0; i != NumArgs; ++i)
5639 mangleExpression(CE->
getArg(i));
5643 case Expr::ParenExprClass:
5647 case Expr::ConceptSpecializationExprClass: {
5649 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5654 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5660 mangleUnresolvedName(
5661 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5662 CSE->getConceptNameInfo().getName(),
5663 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5664 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5668 case Expr::RequiresExprClass: {
5674 if (RE->getLParenLoc().isValid()) {
5676 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5677 if (RE->getLocalParameters().empty()) {
5680 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5688 FunctionTypeDepth.enterResultType();
5689 for (
const concepts::Requirement *Req : RE->getRequirements())
5690 mangleRequirement(RE->getExprLoc(), Req);
5691 FunctionTypeDepth.pop(saved);
5695 for (
const concepts::Requirement *Req : RE->getRequirements())
5696 mangleRequirement(RE->getExprLoc(), Req);
5702 case Expr::DeclRefExprClass:
5707 case Expr::SubstNonTypeTemplateParmPackExprClass:
5713 Out <<
"_SUBSTPACK_";
5716 case Expr::FunctionParmPackExprClass: {
5720 Out <<
"v110_SUBSTPACK";
5725 case Expr::DependentScopeDeclRefExprClass: {
5734 case Expr::CXXBindTemporaryExprClass:
5738 case Expr::ExprWithCleanupsClass:
5742 case Expr::FloatingLiteralClass: {
5749 case Expr::FixedPointLiteralClass:
5751 mangleFixedPointLiteral();
5754 case Expr::CharacterLiteralClass:
5758 Out << cast<CharacterLiteral>(E)->getValue();
5763 case Expr::ObjCBoolLiteralExprClass:
5766 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5770 case Expr::CXXBoolLiteralExprClass:
5773 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5777 case Expr::IntegerLiteralClass: {
5781 Value.setIsSigned(
true);
5786 case Expr::ImaginaryLiteralClass: {
5793 if (
const FloatingLiteral *Imag =
5794 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5796 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5798 mangleFloat(Imag->getValue());
5803 Value.setIsSigned(
true);
5804 mangleNumber(
Value);
5810 case Expr::StringLiteralClass: {
5820 case Expr::GNUNullExprClass:
5823 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5826 case Expr::CXXNullPtrLiteralExprClass: {
5832 case Expr::LambdaExprClass: {
5843 case Expr::PackExpansionExprClass:
5849 case Expr::SizeOfPackExprClass: {
5852 if (SPE->isPartiallySubstituted()) {
5854 for (
const auto &A : SPE->getPartialArguments())
5855 mangleTemplateArg(A,
false);
5861 const NamedDecl *Pack = SPE->getPack();
5862 if (
const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
5863 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5864 else if (
const NonTypeTemplateParmDecl *NTTP
5865 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5866 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5867 else if (
const TemplateTemplateParmDecl *TempTP
5868 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5869 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5875 case Expr::MaterializeTemporaryExprClass:
5879 case Expr::CXXFoldExprClass: {
5882 if (FE->isLeftFold())
5883 Out << (FE->getInit() ?
"fL" :
"fl");
5885 Out << (FE->getInit() ?
"fR" :
"fr");
5887 if (FE->getOperator() == BO_PtrMemD)
5895 mangleExpression(FE->getLHS());
5897 mangleExpression(FE->getRHS());
5901 case Expr::CXXThisExprClass:
5906 case Expr::CoawaitExprClass:
5909 Out <<
"v18co_await";
5913 case Expr::DependentCoawaitExprClass:
5916 Out <<
"v18co_await";
5920 case Expr::CoyieldExprClass:
5923 Out <<
"v18co_yield";
5926 case Expr::SYCLUniqueStableNameExprClass: {
5930 Out <<
"u33__builtin_sycl_unique_stable_name";
5931 mangleType(USN->getTypeSourceInfo()->getType());
5936 case Expr::HLSLOutArgExprClass:
5938 "cannot mangle hlsl temporary value; mangling wrong thing?");
5939 case Expr::OpenACCAsteriskSizeExprClass: {
5941 DiagnosticsEngine &Diags = Context.getDiags();
5944 "cannot yet mangle OpenACC Asterisk Size expression");
5950 if (AsTemplateArg && !IsPrimaryExpr)
5982void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
5989 assert(parmDepth < FunctionTypeDepth.getDepth());
5990 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
5991 if (FunctionTypeDepth.isInResultType())
5994 if (nestingDepth == 0) {
5997 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6005 &&
"parameter's type is still an array type?");
6007 if (
const DependentAddressSpaceType *DAST =
6008 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6015 if (parmIndex != 0) {
6016 Out << (parmIndex - 1);
6022 const CXXRecordDecl *InheritedFrom) {
6049 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6052 mangleName(InheritedFrom);
6111 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6112 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6113 if (!RD || !RD->isGenericLambda())
6129 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6130 return TTP->hasTypeConstraint();
6147 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6148 return NTTP->getType()->isInstantiationDependentType() ||
6149 NTTP->getType()->getContainedDeducedType();
6156 "A DeducedTemplateName shouldn't escape partial ordering");
6167 auto MangleTemplateParamListToString =
6169 unsigned DepthOffset) {
6170 llvm::raw_svector_ostream Stream(Buffer);
6171 CXXNameMangler(
Mangler.Context, Stream,
6172 WithTemplateDepthOffset{DepthOffset})
6173 .mangleTemplateParameterList(Params);
6176 MangleTemplateParamListToString(ParamTemplateHead,
6177 TTP->getTemplateParameters(), 0);
6181 MangleTemplateParamListToString(ArgTemplateHead,
6183 TTP->getTemplateParameters()->
getDepth());
6184 return ParamTemplateHead != ArgTemplateHead;
6194 return {
true,
nullptr};
6199 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6200 "no parameter for argument");
6221 return {
true,
nullptr};
6236 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6237 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6238 return {NeedExactType,
nullptr};
6250void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6252 unsigned NumTemplateArgs) {
6255 TemplateArgManglingInfo Info(*
this, TN);
6256 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6257 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6259 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6263void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6264 const TemplateArgumentList &AL) {
6267 TemplateArgManglingInfo Info(*
this, TN);
6268 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6269 mangleTemplateArg(Info, i, AL[i]);
6271 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6275void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6276 ArrayRef<TemplateArgument> Args) {
6279 TemplateArgManglingInfo Info(*
this, TN);
6280 for (
unsigned i = 0; i != Args.size(); ++i) {
6281 mangleTemplateArg(Info, i, Args[i]);
6283 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6287void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6288 unsigned Index, TemplateArgument A) {
6289 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6292 if (ArgInfo.TemplateParameterToMangle &&
6293 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6300 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6303 mangleTemplateArg(A, ArgInfo.NeedExactType);
6306void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6316 llvm_unreachable(
"Cannot mangle NULL template argument");
6344 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6345 TPO->getValue(),
true,
6350 ASTContext &Ctx = Context.getASTContext();
6358 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6366 ArrayRef<APValue::LValuePathEntry>(),
6379 true, NeedExactType);
6385 mangleTemplateArg(P, NeedExactType);
6391void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6392 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6393 mangleExpression(E, UnknownArity,
true);
6408 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6409 const ValueDecl *D = DRE->getDecl();
6418 mangleExpression(E);
6431 switch (
V.getKind()) {
6439 assert(RD &&
"unexpected type for record value");
6448 if (!FD->isUnnamedBitField() &&
6458 assert(RD &&
"unexpected type for union value");
6461 if (!FD->isUnnamedBitField())
6471 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6472 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6480 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6490 return V.getFloat().isPosZero();
6493 return !
V.getFixedPoint().getValue();
6496 return V.getComplexFloatReal().isPosZero() &&
6497 V.getComplexFloatImag().isPosZero();
6500 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6503 return V.isNullPointer();
6506 return !
V.getMemberPointerDecl();
6509 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6516 T = AT->getElementType();
6518 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6563 Diags.
Report(UnionLoc, DiagID);
6568void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6570 bool NeedExactType) {
6573 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6576 bool IsPrimaryExpr =
true;
6577 auto NotPrimaryExpr = [&] {
6578 if (TopLevel && IsPrimaryExpr)
6580 IsPrimaryExpr =
false;
6584 switch (
V.getKind()) {
6593 llvm_unreachable(
"unexpected value kind in template argument");
6597 assert(RD &&
"unexpected type for record value");
6600 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6603 (Fields.back()->isUnnamedBitField() ||
6605 V.getStructField(Fields.back()->getFieldIndex())))) {
6609 if (Fields.empty()) {
6610 while (!Bases.empty() &&
6612 V.getStructBase(Bases.size() - 1)))
6613 Bases = Bases.drop_back();
6620 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6621 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6622 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6623 if (Fields[I]->isUnnamedBitField())
6625 mangleValueInTemplateArg(Fields[I]->
getType(),
6626 V.getStructField(Fields[I]->getFieldIndex()),
6635 const FieldDecl *FD =
V.getUnionField();
6653 mangleSourceName(II);
6654 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6668 unsigned N =
V.getArraySize();
6670 N =
V.getArrayInitializedElts();
6675 for (
unsigned I = 0; I != N; ++I) {
6676 const APValue &Elem = I <
V.getArrayInitializedElts()
6677 ?
V.getArrayInitializedElt(I)
6678 :
V.getArrayFiller();
6679 mangleValueInTemplateArg(ElemT, Elem,
false);
6686 const VectorType *VT =
T->
castAs<VectorType>();
6691 unsigned N =
V.getVectorLength();
6694 for (
unsigned I = 0; I != N; ++I)
6695 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6701 mangleIntegerLiteral(
T,
V.getInt());
6705 mangleFloatLiteral(
T,
V.getFloat());
6709 mangleFixedPointLiteral();
6713 const ComplexType *CT =
T->
castAs<ComplexType>();
6717 if (!
V.getComplexFloatReal().isPosZero() ||
6718 !
V.getComplexFloatImag().isPosZero())
6720 if (!
V.getComplexFloatImag().isPosZero())
6727 const ComplexType *CT =
T->
castAs<ComplexType>();
6731 if (
V.getComplexIntReal().getBoolValue() ||
6732 V.getComplexIntImag().getBoolValue())
6734 if (
V.getComplexIntImag().getBoolValue())
6743 "unexpected type for LValue template arg");
6745 if (
V.isNullPointer()) {
6746 mangleNullPointer(
T);
6750 APValue::LValueBase B =
V.getLValueBase();
6754 CharUnits Offset =
V.getLValueOffset();
6772 ASTContext &Ctx = Context.getASTContext();
6775 if (!
V.hasLValuePath()) {
6791 bool IsArrayToPointerDecayMangledAsDecl =
false;
6792 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6793 LangOptions::ClangABI::Ver11) {
6795 IsArrayToPointerDecayMangledAsDecl =
6796 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6797 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6801 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6802 !IsArrayToPointerDecayMangledAsDecl) {
6819 if (NeedExactType &&
6821 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6834 QualType TypeSoFar = B.
getType();
6835 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6839 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6841 mangleExpression(E);
6842 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6845 mangleType(QualType(TI.getType(), 0));
6848 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6858 mangleNumber(
V.getLValueOffset().getQuantity());
6865 if (!
V.getLValueOffset().isZero())
6866 mangleNumber(
V.getLValueOffset().getQuantity());
6870 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6872 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6874 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6875 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6876 TypeSoFar = AT->getElementType();
6878 const Decl *D = E.getAsBaseOrMember().getPointer();
6879 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6904 if (!
V.getMemberPointerDecl()) {
6905 mangleNullPointer(
T);
6909 ASTContext &Ctx = Context.getASTContext();
6912 if (!
V.getMemberPointerPath().empty()) {
6915 }
else if (NeedExactType &&
6917 T->
castAs<MemberPointerType>()->getPointeeType(),
6918 V.getMemberPointerDecl()->getType()) &&
6919 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6924 mangle(
V.getMemberPointerDecl());
6926 if (!
V.getMemberPointerPath().empty()) {
6936 if (TopLevel && !IsPrimaryExpr)
6940void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6950 Depth += TemplateDepthOffset;
6952 Out <<
'L' << (Depth - 1) <<
'_';
6958void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6961 }
else if (SeqID == 1) {
6968 MutableArrayRef<char> BufferRef(Buffer);
6969 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
6971 for (; SeqID != 0; SeqID /= 36) {
6972 unsigned C = SeqID % 36;
6973 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
6976 Out.write(I.base(), I - BufferRef.rbegin());
6981void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
6982 bool result = mangleSubstitution(tname);
6983 assert(result &&
"no existing substitution for template name");
6989bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
6991 if (mangleStandardSubstitution(ND))
6995 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7005bool CXXNameMangler::mangleSubstitution(QualType
T) {
7008 return mangleSubstitution(RD);
7013 return mangleSubstitution(TypePtr);
7017 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7018 return mangleSubstitution(TD);
7021 return mangleSubstitution(
7025bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7026 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7027 if (I == Substitutions.end())
7030 unsigned SeqID = I->second;
7039bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7048 const ClassTemplateSpecializationDecl *SD =
7049 dyn_cast<ClassTemplateSpecializationDecl>(RT->getOriginalDecl());
7053 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7057 if (TemplateArgs.
size() != 1)
7060 if (TemplateArgs[0].getAsType() != A)
7072bool CXXNameMangler::isStdCharSpecialization(
7073 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7074 bool HasAllocator) {
7079 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7082 QualType A = TemplateArgs[0].getAsType();
7090 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7094 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7103bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7105 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7113 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7114 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7134 if (
const ClassTemplateSpecializationDecl *SD =
7135 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7136 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7145 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7152 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7159 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7166 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7176void CXXNameMangler::addSubstitution(QualType
T) {
7179 addSubstitution(RD);
7185 addSubstitution(TypePtr);
7189 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7190 return addSubstitution(TD);
7196void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7197 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7198 Substitutions[Ptr] = SeqID++;
7201void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7202 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7203 if (
Other->SeqID > SeqID) {
7204 Substitutions.swap(
Other->Substitutions);
7205 SeqID =
Other->SeqID;
7209CXXNameMangler::AbiTagList
7210CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7212 if (DisableDerivedAbiTags)
7213 return AbiTagList();
7215 llvm::raw_null_ostream NullOutStream;
7216 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7217 TrackReturnTypeTags.disableDerivedAbiTags();
7219 const FunctionProtoType *Proto =
7221 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7222 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
7224 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
7225 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7227 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7230CXXNameMangler::AbiTagList
7231CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7233 if (DisableDerivedAbiTags)
7234 return AbiTagList();
7236 llvm::raw_null_ostream NullOutStream;
7237 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7238 TrackVariableType.disableDerivedAbiTags();
7240 TrackVariableType.mangleType(VD->
getType());
7242 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7245bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7246 const VarDecl *VD) {
7247 llvm::raw_null_ostream NullOutStream;
7248 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7249 TrackAbiTags.mangle(VD);
7250 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7263void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7267 "Invalid mangleName() call, argument is not a variable or function!");
7269 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7270 getASTContext().getSourceManager(),
7271 "Mangling declaration");
7273 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7275 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7276 return Mangler.mangle(GlobalDecl(CD,
Type));
7279 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7281 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7282 return Mangler.mangle(GlobalDecl(DD,
Type));
7285 CXXNameMangler Mangler(*
this, Out, D);
7289void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7291 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7295void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7297 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7319 auto &LangOpts = Context.getLangOpts();
7322 Context.baseForVTableAuthentication(ThisRD);
7323 unsigned TypedDiscriminator =
7324 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7325 Mangler.mangleVendorQualifier(
"__vtptrauth");
7326 auto &ManglerStream = Mangler.getStream();
7327 ManglerStream <<
"I";
7328 if (
const auto *ExplicitAuth =
7329 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7330 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7332 if (ExplicitAuth->getAddressDiscrimination() ==
7333 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7334 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7336 ManglerStream <<
"Lb"
7337 << (ExplicitAuth->getAddressDiscrimination() ==
7338 VTablePointerAuthenticationAttr::AddressDiscrimination);
7340 switch (ExplicitAuth->getExtraDiscrimination()) {
7341 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7342 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7343 ManglerStream <<
"Lj" << TypedDiscriminator;
7345 ManglerStream <<
"Lj" << 0;
7348 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7349 ManglerStream <<
"Lj" << TypedDiscriminator;
7351 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7352 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7354 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7355 ManglerStream <<
"Lj" << 0;
7359 ManglerStream <<
"Lj"
7360 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7361 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7362 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7363 ManglerStream <<
"Lj" << TypedDiscriminator;
7365 ManglerStream <<
"Lj" << 0;
7367 ManglerStream <<
"E";
7370void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7371 const ThunkInfo &Thunk,
7372 bool ElideOverrideInfo,
7382 "Use mangleCXXDtor for destructor decls!");
7383 CXXNameMangler Mangler(*
this, Out);
7384 Mangler.getStream() <<
"_ZT";
7386 Mangler.getStream() <<
'c';
7397 Mangler.mangleFunctionEncoding(MD);
7398 if (!ElideOverrideInfo)
7402void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7404 const ThunkInfo &Thunk,
7405 bool ElideOverrideInfo,
7409 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7410 Mangler.getStream() <<
"_ZT";
7412 auto &ThisAdjustment = Thunk.
This;
7414 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7415 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7417 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7418 if (!ElideOverrideInfo)
7423void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7427 CXXNameMangler Mangler(*
this, Out);
7430 Mangler.getStream() <<
"_ZGV";
7431 Mangler.mangleName(D);
7434void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7439 Out <<
"__cxx_global_var_init";
7442void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7445 CXXNameMangler Mangler(*
this, Out);
7446 Mangler.getStream() <<
"__dtor_";
7447 if (shouldMangleDeclName(D))
7450 Mangler.getStream() << D->
getName();
7453void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7457 CXXNameMangler Mangler(*
this, Out);
7458 Mangler.getStream() <<
"__finalize_";
7459 if (shouldMangleDeclName(D))
7462 Mangler.getStream() << D->
getName();
7465void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7466 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7467 CXXNameMangler Mangler(*
this, Out);
7468 Mangler.getStream() <<
"__filt_";
7470 if (shouldMangleDeclName(EnclosingFD))
7471 Mangler.mangle(EnclosingDecl);
7473 Mangler.getStream() << EnclosingFD->getName();
7476void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7477 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7478 CXXNameMangler Mangler(*
this, Out);
7479 Mangler.getStream() <<
"__fin_";
7481 if (shouldMangleDeclName(EnclosingFD))
7482 Mangler.mangle(EnclosingDecl);
7484 Mangler.getStream() << EnclosingFD->getName();
7487void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7490 CXXNameMangler Mangler(*
this, Out);
7491 Mangler.getStream() <<
"_ZTH";
7492 Mangler.mangleName(D);
7496ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7499 CXXNameMangler Mangler(*
this, Out);
7500 Mangler.getStream() <<
"_ZTW";
7501 Mangler.mangleName(D);
7504void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7505 unsigned ManglingNumber,
7509 CXXNameMangler Mangler(*
this, Out);
7510 Mangler.getStream() <<
"_ZGR";
7511 Mangler.mangleName(D);
7512 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7513 Mangler.mangleSeqID(ManglingNumber - 1);
7516void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7519 CXXNameMangler Mangler(*
this, Out);
7520 Mangler.getStream() <<
"_ZTV";
7521 Mangler.mangleCXXRecordDecl(RD);
7524void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7527 CXXNameMangler Mangler(*
this, Out);
7528 Mangler.getStream() <<
"_ZTT";
7529 Mangler.mangleCXXRecordDecl(RD);
7532void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7534 const CXXRecordDecl *
Type,
7537 CXXNameMangler Mangler(*
this, Out);
7538 Mangler.getStream() <<
"_ZTC";
7541 bool SuppressSubstitution =
7542 getASTContext().getLangOpts().getClangABICompat() <=
7543 LangOptions::ClangABI::Ver19;
7544 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7545 Mangler.getStream() << Offset;
7546 Mangler.getStream() <<
'_';
7547 Mangler.mangleCXXRecordDecl(
Type);
7550void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7552 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7553 CXXNameMangler Mangler(*
this, Out);
7554 Mangler.getStream() <<
"_ZTI";
7555 Mangler.mangleType(Ty);
7558void ItaniumMangleContextImpl::mangleCXXRTTIName(
7559 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7561 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7562 Mangler.getStream() <<
"_ZTS";
7563 Mangler.mangleType(Ty);
7566void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7567 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7568 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7571void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7572 llvm_unreachable(
"Can't mangle string literals");
7575void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7577 CXXNameMangler Mangler(*
this, Out);
7578 Mangler.mangleLambdaSig(Lambda);
7581void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7584 CXXNameMangler Mangler(*
this, Out);
7585 Mangler.getStream() <<
"_ZGI";
7589 auto Partition = M->
Name.find(
':');
7590 Mangler.mangleModuleNamePrefix(
7591 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7599 return new ItaniumMangleContextImpl(
7602 return std::nullopt;
7611 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.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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.
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, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) 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.
@ 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.
std::pair< TemplateDecl *, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template declaration that this template name refers to, along with the deduc...
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...
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.
const FunctionProtoType * T
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.