35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#include "llvm/TargetParser/RISCVTargetParser.h"
42namespace UnsupportedItaniumManglingKind =
43 clang::diag::UnsupportedItaniumManglingKind;
47static bool isLocalContainerContext(
const DeclContext *DC) {
51static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
53 return ftd->getTemplatedDecl();
58static const NamedDecl *getStructor(
const NamedDecl *
decl) {
59 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
60 return (fn ? getStructor(fn) :
decl);
63static bool isLambda(
const NamedDecl *ND) {
64 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
71static const unsigned UnknownArity = ~0U;
73class ItaniumMangleContextImpl :
public ItaniumMangleContext {
74 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
75 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
76 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
77 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
78 NamespaceDecl *StdNamespace =
nullptr;
80 bool NeedsUniqueInternalLinkageNames =
false;
83 explicit ItaniumMangleContextImpl(
84 ASTContext &Context, DiagnosticsEngine &Diags,
85 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 : ItaniumMangleContext(Context, Diags, IsAux),
87 DiscriminatorOverride(DiscriminatorOverride) {}
92 bool shouldMangleCXXName(
const NamedDecl *D)
override;
93 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
98 void needsUniqueInternalLinkageNames()
override {
99 NeedsUniqueInternalLinkageNames =
true;
102 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
103 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
104 raw_ostream &)
override;
106 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
107 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
108 raw_ostream &)
override;
109 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
110 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
112 const CXXRecordDecl *
Type, raw_ostream &)
override;
113 void mangleCXXRTTI(QualType T, raw_ostream &)
override;
114 void mangleCXXRTTIName(QualType T, raw_ostream &,
115 bool NormalizeIntegers)
override;
116 void mangleCanonicalTypeName(QualType T, raw_ostream &,
117 bool NormalizeIntegers)
override;
119 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
120 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
121 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
122 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
123 void mangleDynamicAtExitDestructor(
const VarDecl *D,
124 raw_ostream &Out)
override;
125 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
126 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
127 raw_ostream &Out)
override;
128 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
129 raw_ostream &Out)
override;
130 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
131 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
132 raw_ostream &)
override;
134 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
136 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
138 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
140 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
146 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
147 Tag &&
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
152 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
153 if (discriminator == 1)
155 disc = discriminator - 2;
160 unsigned &discriminator = Uniquifier[ND];
161 if (!discriminator) {
162 const DeclContext *DC = getEffectiveDeclContext(ND);
163 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
165 if (discriminator == 1)
167 disc = discriminator-2;
171 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
174 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
175 std::string Name(
"<lambda");
179 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
180 const FunctionDecl *
Func =
184 unsigned DefaultArgNo =
186 Name += llvm::utostr(DefaultArgNo);
190 if (LambdaManglingNumber)
191 LambdaId = LambdaManglingNumber;
193 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
195 Name += llvm::utostr(LambdaId);
200 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
201 return DiscriminatorOverride;
204 NamespaceDecl *getStdNamespace();
206 const DeclContext *getEffectiveDeclContext(
const Decl *D);
207 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
208 return getEffectiveDeclContext(
cast<Decl>(DC));
211 bool isInternalLinkageDecl(
const NamedDecl *ND);
217class CXXNameMangler {
218 ItaniumMangleContextImpl &Context;
222 bool NormalizeIntegers =
false;
224 bool NullOut =
false;
229 bool DisableDerivedAbiTags =
false;
234 const NamedDecl *Structor;
235 unsigned StructorType = 0;
240 unsigned TemplateDepthOffset = 0;
245 class FunctionTypeDepthState {
248 enum { InResultTypeMask = 1 };
251 FunctionTypeDepthState() =
default;
254 unsigned getDepth()
const {
259 bool isInResultType()
const {
260 return Bits & InResultTypeMask;
263 FunctionTypeDepthState push() {
264 FunctionTypeDepthState tmp = *
this;
265 Bits = (Bits & ~InResultTypeMask) + 2;
269 void enterResultType() {
270 Bits |= InResultTypeMask;
273 void leaveResultType() {
274 Bits &= ~InResultTypeMask;
277 void pop(FunctionTypeDepthState saved) {
278 assert(getDepth() == saved.getDepth() + 1);
288 using AbiTagList = SmallVector<StringRef, 4>;
293 class AbiTagState final {
295 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
301 AbiTagState(
const AbiTagState &) =
delete;
302 AbiTagState &operator=(
const AbiTagState &) =
delete;
304 ~AbiTagState() { pop(); }
306 void write(raw_ostream &Out,
const NamedDecl *ND,
307 const AbiTagList *AdditionalAbiTags) {
311 !AdditionalAbiTags &&
312 "only function and variables need a list of additional abi tags");
313 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
314 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
315 llvm::append_range(UsedAbiTags, AbiTag->tags());
322 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
323 llvm::append_range(UsedAbiTags, AbiTag->tags());
324 llvm::append_range(TagList, AbiTag->tags());
327 if (AdditionalAbiTags) {
328 llvm::append_range(UsedAbiTags, *AdditionalAbiTags);
329 llvm::append_range(TagList, *AdditionalAbiTags);
333 TagList.erase(llvm::unique(TagList), TagList.end());
335 writeSortedUniqueAbiTags(Out, TagList);
338 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
339 void setUsedAbiTags(
const AbiTagList &AbiTags) {
340 UsedAbiTags = AbiTags;
343 const AbiTagList &getEmittedAbiTags()
const {
344 return EmittedAbiTags;
347 const AbiTagList &getSortedUniqueUsedAbiTags() {
348 llvm::sort(UsedAbiTags);
349 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
355 AbiTagList UsedAbiTags;
357 AbiTagList EmittedAbiTags;
359 AbiTagState *&LinkHead;
360 AbiTagState *Parent =
nullptr;
363 assert(LinkHead ==
this &&
364 "abi tag link head must point to us on destruction");
366 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
367 UsedAbiTags.begin(), UsedAbiTags.end());
368 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
369 EmittedAbiTags.begin(),
370 EmittedAbiTags.end());
375 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
376 for (
const auto &Tag : AbiTags) {
377 EmittedAbiTags.push_back(Tag);
385 AbiTagState *AbiTags =
nullptr;
386 AbiTagState AbiTagsRoot;
388 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
389 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
391 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
393 bool isCompatibleWith(LangOptions::ClangABI Ver) {
394 return Context.getASTContext().
getLangOpts().getClangABICompat() <= Ver;
397 bool isStd(
const NamespaceDecl *NS);
398 bool isStdNamespace(
const DeclContext *DC);
400 const RecordDecl *GetLocalClassDecl(
const Decl *D);
401 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
402 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
403 llvm::StringRef Name,
bool HasAllocator);
406 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
407 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
408 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
409 AbiTagsRoot(AbiTags) {
414 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
416 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
417 AbiTagsRoot(AbiTags) {}
418 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
420 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
421 AbiTagsRoot(AbiTags) {}
423 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
424 bool NormalizeIntegers_)
425 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
426 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
427 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
428 : Context(Outer.Context),
Out(Out_),
429 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
430 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
431 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
432 Substitutions(Outer.Substitutions),
433 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
435 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
436 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
440 struct WithTemplateDepthOffset {
unsigned Offset; };
441 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
442 WithTemplateDepthOffset Offset)
443 : CXXNameMangler(
C,
Out) {
444 TemplateDepthOffset = Offset.Offset;
447 raw_ostream &getStream() {
return Out; }
449 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
450 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
452 void mangle(GlobalDecl GD);
453 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
454 void mangleNumber(
const llvm::APSInt &I);
455 void mangleNumber(int64_t Number);
456 void mangleFloat(
const llvm::APFloat &F);
457 void mangleFunctionEncoding(GlobalDecl GD);
458 void mangleSeqID(
unsigned SeqID);
459 void mangleName(GlobalDecl GD);
460 void mangleType(QualType T);
461 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
462 bool SuppressSubstitution =
false);
463 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
464 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
465 void mangleVendorQualifier(StringRef Name);
466 void mangleVendorType(StringRef Name);
469 bool mangleSubstitution(
const NamedDecl *ND);
470 bool mangleSubstitution(QualType T);
476 bool mangleStandardSubstitution(
const NamedDecl *ND);
478 void addSubstitution(
const NamedDecl *ND) {
481 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
483 void addSubstitution(QualType T);
487 void extendSubstitutions(CXXNameMangler*
Other);
489 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
490 bool recursive =
false);
491 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
492 const TemplateArgumentLoc *TemplateArgs,
493 unsigned NumTemplateArgs,
494 unsigned KnownArity = UnknownArity);
496 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
498 void mangleNameWithAbiTags(GlobalDecl GD,
499 const AbiTagList *AdditionalAbiTags);
500 void mangleModuleName(
const NamedDecl *ND);
501 void mangleTemplateName(
const TemplateDecl *TD,
502 ArrayRef<TemplateArgument> Args);
503 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
504 const AbiTagList *AdditionalAbiTags) {
506 UnknownArity, AdditionalAbiTags);
508 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
509 const DeclContext *DC,
unsigned KnownArity,
510 const AbiTagList *AdditionalAbiTags);
511 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
512 const AbiTagList *AdditionalAbiTags);
513 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
514 const AbiTagList *AdditionalAbiTags);
515 void mangleSourceName(
const IdentifierInfo *II);
516 void mangleConstructorName(
const CXXConstructorDecl *CCD,
517 const AbiTagList *AdditionalAbiTags);
518 void mangleDestructorName(
const CXXDestructorDecl *CDD,
519 const AbiTagList *AdditionalAbiTags);
520 void mangleRegCallName(
const IdentifierInfo *II);
521 void mangleDeviceStubName(
const IdentifierInfo *II);
522 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
523 void mangleSourceNameWithAbiTags(
524 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags =
nullptr);
525 void mangleLocalName(GlobalDecl GD,
526 const AbiTagList *AdditionalAbiTags);
527 void mangleBlockForPrefix(
const BlockDecl *
Block);
528 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
529 void mangleTemplateParamDecl(
const NamedDecl *Decl);
530 void mangleTemplateParameterList(
const TemplateParameterList *Params);
531 void mangleTypeConstraint(
const TemplateDecl *
Concept,
532 ArrayRef<TemplateArgument> Arguments);
533 void mangleTypeConstraint(
const TypeConstraint *Constraint);
534 void mangleRequiresClause(
const Expr *RequiresClause);
535 void mangleLambda(
const CXXRecordDecl *Lambda);
536 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
537 const AbiTagList *AdditionalAbiTags,
538 bool NoFunction=
false);
539 void mangleNestedName(
const TemplateDecl *TD,
540 ArrayRef<TemplateArgument> Args);
541 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
542 const NamedDecl *PrefixND,
543 const AbiTagList *AdditionalAbiTags);
544 void manglePrefix(NestedNameSpecifier Qualifier);
545 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
546 void manglePrefix(QualType
type);
547 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
549 const NamedDecl *getClosurePrefix(
const Decl *ND);
550 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
551 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
552 StringRef Prefix =
"");
553 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
555 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
561#define ABSTRACT_TYPE(CLASS, PARENT)
562#define NON_CANONICAL_TYPE(CLASS, PARENT)
563#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
564#include "clang/AST/TypeNodes.inc"
566 void mangleType(
const TagType*);
568 static StringRef getCallingConvQualifierName(
CallingConv CC);
571 void mangleSMEAttrs(
unsigned SMEAttrs);
574 void mangleNeonVectorType(
const VectorType *T);
576 void mangleAArch64NeonVectorType(
const VectorType *T);
578 void mangleAArch64FixedSveVectorType(
const VectorType *T);
580 void mangleRISCVFixedRVVVectorType(
const VectorType *T);
583 void mangleIntegerLiteral(
QualType T,
const llvm::APSInt &
Value);
584 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
585 void mangleFixedPointLiteral();
588 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
589 void mangleMemberExpr(
const Expr *base,
bool isArrow,
593 unsigned NumTemplateArgs,
unsigned knownArity);
594 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
595 void mangleInitListElements(
const InitListExpr *InitList);
598 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
599 bool AsTemplateArg =
false);
603 struct TemplateArgManglingInfo;
606 unsigned NumTemplateArgs);
609 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
612 void mangleTemplateArgExpr(
const Expr *E);
614 bool NeedExactType =
false);
616 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
621 const AbiTagList *AdditionalAbiTags);
624 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
626 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
634 getASTContext(), getASTContext().getTranslationUnitDecl(),
635 false, SourceLocation(), SourceLocation(),
636 &getASTContext().Idents.get(
"std"),
659ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
666 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
668 if (ParmVarDecl *ContextParam =
669 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
670 return ContextParam->getDeclContext();
674 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
675 if (ParmVarDecl *ContextParam =
676 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
677 return ContextParam->getDeclContext();
685 if (D == getASTContext().getVaListTagDecl()) {
686 const llvm::Triple &T = getASTContext().getTargetInfo().getTriple();
687 if (T.isARM() || T.isThumb() || T.isAArch64())
688 return getStdNamespace();
694 return getEffectiveDeclContext(
cast<Decl>(DC));
697 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
699 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
703 if (isLocalContainerContext(ParentDC))
707 return getASTContext().getTranslationUnitDecl();
710 if (
const auto *FD = getASTContext().getLangOpts().getClangABICompat() >
711 LangOptions::ClangABI::Ver19
713 : dyn_cast<FunctionDecl>(D)) {
715 return getASTContext().getTranslationUnitDecl();
718 if (FD->isMemberLikeConstrainedFriend() &&
719 getASTContext().getLangOpts().getClangABICompat() >
720 LangOptions::ClangABI::Ver17)
727bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
730 getEffectiveDeclContext(ND)->isFileContext() &&
737bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
738 const NamedDecl *ND) {
739 if (!NeedsUniqueInternalLinkageNames || !ND)
742 const auto *FD = dyn_cast<FunctionDecl>(ND);
748 if (!FD->getType()->getAs<FunctionProtoType>())
751 if (isInternalLinkageDecl(ND))
757bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
758 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
761 if (FD->hasAttr<OverloadableAttr>())
777 if (FD->isMSVCRTEntryPoint())
791 if (!getASTContext().getLangOpts().
CPlusPlus)
794 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
805 const DeclContext *DC = getEffectiveDeclContext(D);
807 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
809 !VD->getOwningModuleForLinkage())
816void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
817 const AbiTagList *AdditionalAbiTags) {
818 assert(AbiTags &&
"require AbiTagState");
819 AbiTags->write(Out, ND, DisableDerivedAbiTags ?
nullptr : AdditionalAbiTags);
822void CXXNameMangler::mangleSourceNameWithAbiTags(
823 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags) {
825 writeAbiTags(ND, AdditionalAbiTags);
828void CXXNameMangler::mangle(GlobalDecl GD) {
834 mangleFunctionEncoding(GD);
835 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
838 else if (
const IndirectFieldDecl *IFD =
839 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
840 mangleName(IFD->getAnonField());
842 llvm_unreachable(
"unexpected kind of global decl");
845void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
850 if (!Context.shouldMangleDeclName(FD)) {
855 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
856 if (ReturnTypeAbiTags.empty()) {
865 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
867 FunctionTypeDepth.pop(Saved);
868 mangleFunctionEncodingBareType(FD);
875 SmallString<256> FunctionEncodingBuf;
876 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
877 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
879 FunctionEncodingMangler.disableDerivedAbiTags();
881 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
882 FunctionEncodingMangler.mangleNameWithAbiTags(FD,
nullptr);
883 FunctionTypeDepth.pop(Saved);
886 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
887 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
891 const AbiTagList &UsedAbiTags =
892 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
893 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
894 AdditionalAbiTags.erase(
895 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
896 UsedAbiTags.begin(), UsedAbiTags.end(),
897 AdditionalAbiTags.begin()),
898 AdditionalAbiTags.end());
901 Saved = FunctionTypeDepth.push();
902 mangleNameWithAbiTags(FD, &AdditionalAbiTags);
903 FunctionTypeDepth.pop(Saved);
904 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
908 extendSubstitutions(&FunctionEncodingMangler);
911void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
912 if (FD->
hasAttr<EnableIfAttr>()) {
913 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
914 Out <<
"Ua9enable_ifI";
915 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
918 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
921 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
926 mangleExpression(EIA->getCond());
929 mangleTemplateArgExpr(EIA->getCond());
933 FunctionTypeDepth.pop(Saved);
938 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
939 if (
auto Inherited = CD->getInheritedConstructor())
940 FD = Inherited.getConstructor();
958 bool MangleReturnType =
false;
962 MangleReturnType =
true;
965 FD = PrimaryTemplate->getTemplatedDecl();
968 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
969 MangleReturnType, FD);
973bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
974 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
978 return II && II->
isStr(
"std");
983bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
990static const GlobalDecl
994 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1003 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1004 TemplateArgs = &Spec->getTemplateArgs();
1005 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1010 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1011 TemplateArgs = &Spec->getTemplateArgs();
1012 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1023void CXXNameMangler::mangleName(GlobalDecl GD) {
1025 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1027 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1028 if (VariableTypeAbiTags.empty()) {
1030 mangleNameWithAbiTags(VD,
nullptr);
1035 llvm::raw_null_ostream NullOutStream;
1036 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1037 VariableNameMangler.disableDerivedAbiTags();
1038 VariableNameMangler.mangleNameWithAbiTags(VD,
nullptr);
1041 const AbiTagList &UsedAbiTags =
1042 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1043 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1044 AdditionalAbiTags.erase(
1045 std::set_difference(VariableTypeAbiTags.begin(),
1046 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1047 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1048 AdditionalAbiTags.end());
1051 mangleNameWithAbiTags(VD, &AdditionalAbiTags);
1053 mangleNameWithAbiTags(GD,
nullptr);
1057const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1058 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1060 if (isLocalContainerContext(DC))
1061 return dyn_cast<RecordDecl>(D);
1063 DC = Context.getEffectiveDeclContext(D);
1068void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
1069 const AbiTagList *AdditionalAbiTags) {
1076 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1077 bool IsLambda = isLambda(ND);
1079 if (GetLocalClassDecl(ND) &&
1080 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1081 mangleLocalName(GD, AdditionalAbiTags);
1089 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1090 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1094 if (isLocalContainerContext(DC)) {
1095 mangleLocalName(GD, AdditionalAbiTags);
1104 const TemplateArgumentList *TemplateArgs =
nullptr;
1105 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1106 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1111 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1115 mangleNestedName(GD, DC, AdditionalAbiTags);
1118void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1121 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1129void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1131 if (
auto It = ModuleSubstitutions.find(Name);
1132 It != ModuleSubstitutions.end()) {
1134 mangleSeqID(It->second);
1140 auto [Prefix, SubName] = Name.rsplit(
'.');
1141 if (SubName.empty())
1144 mangleModuleNamePrefix(Prefix, IsPartition);
1145 IsPartition =
false;
1151 Out << SubName.size() << SubName;
1152 ModuleSubstitutions.insert({Name, SeqID++});
1155void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1156 ArrayRef<TemplateArgument> Args) {
1157 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1160 mangleUnscopedTemplateName(TD, DC,
nullptr);
1163 mangleNestedName(TD, Args);
1167void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1168 const AbiTagList *AdditionalAbiTags) {
1173 if (isStdNamespace(DC)) {
1174 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1176 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1181 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1183 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1193 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1196void CXXNameMangler::mangleUnscopedTemplateName(
1197 GlobalDecl GD,
const DeclContext *DC,
const AbiTagList *AdditionalAbiTags) {
1201 if (mangleSubstitution(ND))
1205 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1206 assert(!AdditionalAbiTags &&
1207 "template template param cannot have abi tags");
1208 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1210 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1216 addSubstitution(ND);
1219void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1233 llvm::APInt valueBits = f.bitcastToAPInt();
1234 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1235 assert(numCharacters != 0);
1238 SmallVector<char, 20> buffer(numCharacters);
1241 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1243 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1246 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1247 hexDigit >>= (digitBitIndex % 64);
1251 static const char charForHex[16] = {
1252 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1253 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1255 buffer[stringIndex] = charForHex[hexDigit];
1258 Out.write(buffer.data(), numCharacters);
1261void CXXNameMangler::mangleFloatLiteral(QualType T,
const llvm::APFloat &
V) {
1268void CXXNameMangler::mangleFixedPointLiteral() {
1269 DiagnosticsEngine &Diags = Context.getDiags();
1270 Diags.
Report(diag::err_unsupported_itanium_mangling)
1271 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1274void CXXNameMangler::mangleNullPointer(QualType T) {
1281void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1282 if (
Value.isSigned() &&
Value.isNegative()) {
1284 Value.abs().print(Out,
false);
1286 Value.print(Out,
false);
1290void CXXNameMangler::mangleNumber(int64_t Number) {
1300void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1308 mangleNumber(NonVirtual);
1314 mangleNumber(NonVirtual);
1320void CXXNameMangler::manglePrefix(QualType
type) {
1321 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1322 if (!mangleSubstitution(QualType(TST, 0))) {
1323 mangleTemplatePrefix(TST->getTemplateName());
1328 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1329 addSubstitution(QualType(TST, 0));
1331 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1333 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1334 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1339 assert(DNT->getQualifier());
1340 manglePrefix(DNT->getQualifier());
1342 mangleSourceName(DNT->getIdentifier());
1345 addSubstitution(QualType(DNT, 0));
1357void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1375 case NestedNameSpecifier::Kind::Null:
1376 llvm_unreachable(
"unexpected null nested name specifier");
1378 case NestedNameSpecifier::Kind::Global:
1388 case NestedNameSpecifier::Kind::MicrosoftSuper:
1389 llvm_unreachable(
"Can't mangle __super specifier");
1391 case NestedNameSpecifier::Kind::Namespace: {
1394 mangleUnresolvedPrefix(Prefix,
1398 mangleSourceNameWithAbiTags(Namespace);
1402 case NestedNameSpecifier::Kind::Type: {
1410 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1411 mangleUnresolvedPrefix(Prefix,
1418 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1433void CXXNameMangler::mangleUnresolvedName(
1434 NestedNameSpecifier Qualifier, DeclarationName name,
1435 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1436 unsigned knownArity) {
1438 mangleUnresolvedPrefix(Qualifier);
1439 switch (
name.getNameKind()) {
1442 mangleSourceName(
name.getAsIdentifierInfo());
1447 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1454 mangleOperatorName(name, knownArity);
1457 llvm_unreachable(
"Can't mangle a constructor name!");
1459 llvm_unreachable(
"Can't mangle a using directive name!");
1461 llvm_unreachable(
"Can't mangle a deduction guide name!");
1465 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1471 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1474void CXXNameMangler::mangleUnqualifiedName(
1475 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1476 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1477 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1484 mangleModuleName(ND);
1488 auto *FD = dyn_cast<FunctionDecl>(ND);
1489 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1491 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1492 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1496 unsigned Arity = KnownArity;
1502 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1509 for (
auto *BD : DD->bindings())
1510 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1512 writeAbiTags(ND, AdditionalAbiTags);
1516 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1519 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1520 llvm::raw_svector_ostream GUIDOS(GUID);
1521 Context.mangleMSGuidDecl(GD, GUIDOS);
1522 Out << GUID.size() << GUID;
1526 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1529 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1530 TPO->getValue(),
true);
1548 if (Context.isInternalLinkageDecl(ND))
1551 bool IsRegCall = FD &&
1555 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1557 bool IsOCLDeviceStub =
1559 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1562 mangleDeviceStubName(II);
1563 else if (IsOCLDeviceStub)
1564 mangleOCLDeviceStubName(II);
1566 mangleRegCallName(II);
1568 mangleSourceName(II);
1570 writeAbiTags(ND, AdditionalAbiTags);
1575 assert(ND &&
"mangling empty name without declaration");
1577 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1580 Out <<
"12_GLOBAL__N_1";
1585 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1587 const auto *RD = VD->getType()->castAsRecordDecl();
1598 assert(RD->isAnonymousStructOrUnion()
1599 &&
"Expected anonymous struct or union!");
1600 const FieldDecl *FD = RD->findFirstNamedDataMember();
1606 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1626 "Typedef should not be in another decl context!");
1627 assert(D->getDeclName().getAsIdentifierInfo() &&
1628 "Typedef was not named!");
1629 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1630 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1633 writeAbiTags(TD,
nullptr);
1642 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1644 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1650 if (
Record->isLambda() &&
1651 ((DeviceNumber && *DeviceNumber > 0) ||
1652 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1653 assert(!AdditionalAbiTags &&
1654 "Lambda type cannot have additional abi tags");
1661 unsigned UnnamedMangle =
1662 getASTContext().getManglingNumber(TD, Context.isAux());
1664 if (UnnamedMangle > 1)
1665 Out << UnnamedMangle - 2;
1667 writeAbiTags(TD, AdditionalAbiTags);
1673 unsigned AnonStructId =
1675 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1682 Str += llvm::utostr(AnonStructId);
1692 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1703 if (ND && Arity == UnknownArity) {
1707 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1708 if (MD->isImplicitObjectMemberFunction())
1714 mangleOperatorName(Name, Arity);
1715 writeAbiTags(ND, AdditionalAbiTags);
1719 llvm_unreachable(
"Can't mangle a deduction guide name!");
1722 llvm_unreachable(
"Can't mangle a using directive name!");
1726void CXXNameMangler::mangleConstructorName(
1727 const CXXConstructorDecl *CCD,
const AbiTagList *AdditionalAbiTags) {
1728 const CXXRecordDecl *InheritedFrom =
nullptr;
1730 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1732 InheritedFrom = Inherited.getConstructor()->
getParent();
1733 InheritedTemplateName =
1734 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1735 InheritedTemplateArgs =
1736 Inherited.getConstructor()->getTemplateSpecializationArgs();
1739 if (CCD == Structor)
1742 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1750 if (InheritedTemplateArgs)
1751 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1753 writeAbiTags(CCD, AdditionalAbiTags);
1756void CXXNameMangler::mangleDestructorName(
const CXXDestructorDecl *CDD,
1757 const AbiTagList *AdditionalAbiTags) {
1758 if (CDD == Structor)
1761 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1767 writeAbiTags(CDD, AdditionalAbiTags);
1770void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1774 if (getASTContext().getLangOpts().RegCall4)
1775 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1778 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1782void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1786 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1790void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1794 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1795 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1796 << OCLDeviceStubNamePrefix << II->
getName();
1799void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1806void CXXNameMangler::mangleNestedName(GlobalDecl GD,
1807 const DeclContext *DC,
1808 const AbiTagList *AdditionalAbiTags,
1817 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1818 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1821 if (
Method->isExplicitObjectMemberFunction())
1824 mangleQualifiers(MethodQuals);
1825 mangleRefQualifier(
Method->getRefQualifier());
1829 const TemplateArgumentList *TemplateArgs =
nullptr;
1830 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1831 mangleTemplatePrefix(TD, NoFunction);
1834 manglePrefix(DC, NoFunction);
1835 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1840void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1841 ArrayRef<TemplateArgument> Args) {
1846 mangleTemplatePrefix(TD);
1852void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1853 GlobalDecl GD,
const NamedDecl *PrefixND,
1854 const AbiTagList *AdditionalAbiTags) {
1863 mangleClosurePrefix(PrefixND);
1864 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1875 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1877 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1884void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1885 const AbiTagList *AdditionalAbiTags) {
1893 const RecordDecl *RD = GetLocalClassDecl(D);
1894 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1899 AbiTagState LocalAbiTags(AbiTags);
1901 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1903 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1904 mangleBlockForPrefix(BD);
1911 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1925 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1927 if (
const ParmVarDecl *Parm
1929 if (
const FunctionDecl *
Func
1934 mangleNumber(
Num - 2);
1943 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1944 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1945 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1946 mangleClosurePrefix(PrefixND,
true );
1948 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1949 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1950 mangleUnqualifiedBlock(BD);
1953 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1954 AdditionalAbiTags,
true );
1956 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1959 if (
const ParmVarDecl *Parm
1960 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1961 if (
const FunctionDecl *
Func
1966 mangleNumber(
Num - 2);
1971 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1972 mangleUnqualifiedBlock(BD);
1974 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1977 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1979 if (Context.getNextDiscriminator(ND, disc)) {
1983 Out <<
"__" << disc <<
'_';
1988void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1989 if (GetLocalClassDecl(
Block)) {
1990 mangleLocalName(
Block,
nullptr);
1993 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
1994 if (isLocalContainerContext(DC)) {
1995 mangleLocalName(
Block,
nullptr);
1998 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
1999 mangleClosurePrefix(PrefixND);
2002 mangleUnqualifiedBlock(
Block);
2005void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2008 if (Decl *Context =
Block->getBlockManglingContextDecl();
2009 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2011 Context->getDeclContext()->isRecord()) {
2014 mangleSourceNameWithAbiTags(ND);
2020 unsigned Number =
Block->getBlockManglingNumber();
2042void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2044 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2045 if (Ty->isParameterPack())
2047 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2048 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2051 mangleTypeConstraint(Constraint);
2055 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2056 if (Tn->isExpandedParameterPack()) {
2057 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2059 mangleType(Tn->getExpansionType(I));
2062 QualType T = Tn->getType();
2063 if (Tn->isParameterPack()) {
2065 if (
auto *PackExpansion = T->
getAs<PackExpansionType>())
2066 T = PackExpansion->getPattern();
2071 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2072 if (Tt->isExpandedParameterPack()) {
2073 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2075 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2077 if (Tt->isParameterPack())
2079 mangleTemplateParameterList(Tt->getTemplateParameters());
2084void CXXNameMangler::mangleTemplateParameterList(
2085 const TemplateParameterList *Params) {
2087 for (
auto *Param : *Params)
2088 mangleTemplateParamDecl(Param);
2089 mangleRequiresClause(Params->getRequiresClause());
2093void CXXNameMangler::mangleTypeConstraint(
2094 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2095 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2097 mangleTemplateName(
Concept, Arguments);
2099 mangleUnscopedName(
Concept, DC,
nullptr);
2101 mangleNestedName(
Concept, DC,
nullptr);
2104void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2105 llvm::SmallVector<TemplateArgument, 8> Args;
2107 for (
const TemplateArgumentLoc &ArgLoc :
2109 Args.push_back(ArgLoc.getArgument());
2114void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2116 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2118 mangleExpression(RequiresClause);
2122void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2126 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2129 if (
const IdentifierInfo *Name =
2131 mangleSourceName(Name);
2132 const TemplateArgumentList *TemplateArgs =
nullptr;
2140 mangleLambdaSig(Lambda);
2155 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2159 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2161 mangleNumber(Number - 2);
2165void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2168 mangleTemplateParamDecl(D);
2172 mangleRequiresClause(TPL->getRequiresClause());
2176 mangleBareFunctionType(Proto,
false,
2180void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2182 case NestedNameSpecifier::Kind::Null:
2183 case NestedNameSpecifier::Kind::Global:
2187 case NestedNameSpecifier::Kind::MicrosoftSuper:
2188 llvm_unreachable(
"Can't mangle __super specifier");
2190 case NestedNameSpecifier::Kind::Namespace:
2191 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2194 case NestedNameSpecifier::Kind::Type:
2195 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2199 llvm_unreachable(
"unexpected nested name specifier");
2202void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2215 if (NoFunction && isLocalContainerContext(DC))
2219 if (mangleSubstitution(ND))
2225 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2226 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2227 mangleTemplatePrefix(TD);
2229 *FD->getTemplateSpecializationArgs());
2231 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2234 addSubstitution(ND);
2239 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2241 addSubstitution(ND);
2246 const TemplateArgumentList *TemplateArgs =
nullptr;
2247 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2248 mangleTemplatePrefix(TD);
2250 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2251 mangleClosurePrefix(PrefixND, NoFunction);
2252 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2254 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2255 manglePrefix(DC, NoFunction);
2256 mangleUnqualifiedName(ND, DC,
nullptr);
2259 addSubstitution(ND);
2266 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2267 return mangleTemplatePrefix(TD);
2270 assert(
Dependent &&
"unexpected template name kind");
2274 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2275 if (!Clang11Compat && mangleSubstitution(
Template))
2278 manglePrefix(
Dependent->getQualifier());
2280 if (Clang11Compat && mangleSubstitution(
Template))
2283 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2284 const IdentifierInfo *Id = Name.getIdentifier())
2285 mangleSourceName(Id);
2287 mangleOperatorName(Name.getOperator(), UnknownArity);
2292void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2301 if (mangleSubstitution(ND))
2305 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2306 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2308 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2309 manglePrefix(DC, NoFunction);
2311 mangleUnqualifiedName(GD, DC,
nullptr);
2317 addSubstitution(ND);
2320const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2321 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2324 const NamedDecl *Context =
nullptr;
2325 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2326 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2327 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2330 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2332 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2346void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2349 if (mangleSubstitution(ND))
2352 const TemplateArgumentList *TemplateArgs =
nullptr;
2353 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2354 mangleTemplatePrefix(TD, NoFunction);
2357 const auto *DC = Context.getEffectiveDeclContext(ND);
2358 manglePrefix(DC, NoFunction);
2359 mangleUnqualifiedName(ND, DC,
nullptr);
2364 addSubstitution(ND);
2373 if (mangleSubstitution(TN))
2376 TemplateDecl *TD =
nullptr;
2386 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2387 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2394 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2403 mangleUnresolvedPrefix(
Dependent->getQualifier());
2404 mangleSourceName(II);
2413 SubstTemplateTemplateParmStorage *subst
2424 Out <<
"_SUBSTPACK_";
2428 llvm_unreachable(
"Unexpected DeducedTemplate");
2431 addSubstitution(TN);
2434bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2440 case Type::Adjusted:
2442 case Type::ArrayParameter:
2444 case Type::BlockPointer:
2445 case Type::LValueReference:
2446 case Type::RValueReference:
2447 case Type::MemberPointer:
2448 case Type::ConstantArray:
2449 case Type::IncompleteArray:
2450 case Type::VariableArray:
2451 case Type::DependentSizedArray:
2452 case Type::DependentAddressSpace:
2453 case Type::DependentVector:
2454 case Type::DependentSizedExtVector:
2456 case Type::ExtVector:
2457 case Type::ConstantMatrix:
2458 case Type::DependentSizedMatrix:
2459 case Type::FunctionProto:
2460 case Type::FunctionNoProto:
2462 case Type::Attributed:
2463 case Type::BTFTagAttributed:
2464 case Type::OverflowBehavior:
2465 case Type::HLSLAttributedResource:
2466 case Type::HLSLInlineSpirv:
2468 case Type::DeducedTemplateSpecialization:
2469 case Type::PackExpansion:
2470 case Type::ObjCObject:
2471 case Type::ObjCInterface:
2472 case Type::ObjCObjectPointer:
2473 case Type::ObjCTypeParam:
2476 case Type::MacroQualified:
2478 case Type::DependentBitInt:
2479 case Type::CountAttributed:
2480 llvm_unreachable(
"type is illegal as a nested name specifier");
2482 case Type::SubstBuiltinTemplatePack:
2487 Out <<
"_SUBSTBUILTINPACK_";
2489 case Type::SubstTemplateTypeParmPack:
2494 Out <<
"_SUBSTPACK_";
2501 case Type::TypeOfExpr:
2503 case Type::Decltype:
2504 case Type::PackIndexing:
2505 case Type::TemplateTypeParm:
2506 case Type::UnaryTransform:
2519 case Type::SubstTemplateTypeParm: {
2523 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2525 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2526 goto unresolvedType;
2533 case Type::PredefinedSugar:
2537 case Type::UnresolvedUsing:
2538 mangleSourceNameWithAbiTags(
2544 mangleSourceNameWithAbiTags(
2548 case Type::TemplateSpecialization: {
2549 const TemplateSpecializationType *TST =
2559 assert(TD &&
"no template for template specialization type");
2561 goto unresolvedType;
2563 mangleSourceNameWithAbiTags(TD);
2575 llvm_unreachable(
"invalid base for a template specialization type");
2578 SubstTemplateTemplateParmStorage *subst =
2589 Out <<
"_SUBSTPACK_";
2595 mangleSourceNameWithAbiTags(TD);
2605 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2609 case Type::InjectedClassName:
2610 mangleSourceNameWithAbiTags(
2614 case Type::DependentName:
2626void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2636 llvm_unreachable(
"Not an operator name");
2659 case OO_New:
Out <<
"nw";
break;
2661 case OO_Array_New:
Out <<
"na";
break;
2663 case OO_Delete:
Out <<
"dl";
break;
2665 case OO_Array_Delete:
Out <<
"da";
break;
2669 Out << (Arity == 1?
"ps" :
"pl");
break;
2673 Out << (Arity == 1?
"ng" :
"mi");
break;
2677 Out << (Arity == 1?
"ad" :
"an");
break;
2682 Out << (Arity == 1?
"de" :
"ml");
break;
2684 case OO_Tilde:
Out <<
"co";
break;
2686 case OO_Slash:
Out <<
"dv";
break;
2688 case OO_Percent:
Out <<
"rm";
break;
2690 case OO_Pipe:
Out <<
"or";
break;
2692 case OO_Caret:
Out <<
"eo";
break;
2694 case OO_Equal:
Out <<
"aS";
break;
2696 case OO_PlusEqual:
Out <<
"pL";
break;
2698 case OO_MinusEqual:
Out <<
"mI";
break;
2700 case OO_StarEqual:
Out <<
"mL";
break;
2702 case OO_SlashEqual:
Out <<
"dV";
break;
2704 case OO_PercentEqual:
Out <<
"rM";
break;
2706 case OO_AmpEqual:
Out <<
"aN";
break;
2708 case OO_PipeEqual:
Out <<
"oR";
break;
2710 case OO_CaretEqual:
Out <<
"eO";
break;
2712 case OO_LessLess:
Out <<
"ls";
break;
2714 case OO_GreaterGreater:
Out <<
"rs";
break;
2716 case OO_LessLessEqual:
Out <<
"lS";
break;
2718 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2720 case OO_EqualEqual:
Out <<
"eq";
break;
2722 case OO_ExclaimEqual:
Out <<
"ne";
break;
2724 case OO_Less:
Out <<
"lt";
break;
2726 case OO_Greater:
Out <<
"gt";
break;
2728 case OO_LessEqual:
Out <<
"le";
break;
2730 case OO_GreaterEqual:
Out <<
"ge";
break;
2732 case OO_Exclaim:
Out <<
"nt";
break;
2734 case OO_AmpAmp:
Out <<
"aa";
break;
2736 case OO_PipePipe:
Out <<
"oo";
break;
2738 case OO_PlusPlus:
Out <<
"pp";
break;
2740 case OO_MinusMinus:
Out <<
"mm";
break;
2742 case OO_Comma:
Out <<
"cm";
break;
2744 case OO_ArrowStar:
Out <<
"pm";
break;
2746 case OO_Arrow:
Out <<
"pt";
break;
2748 case OO_Call:
Out <<
"cl";
break;
2750 case OO_Subscript:
Out <<
"ix";
break;
2755 case OO_Conditional:
Out <<
"qu";
break;
2758 case OO_Coawait:
Out <<
"aw";
break;
2761 case OO_Spaceship:
Out <<
"ss";
break;
2765 llvm_unreachable(
"Not an overloaded operator");
2769void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2788 SmallString<64> ASString;
2794 if (TargetAS != 0 ||
2796 ASString =
"AS" + llvm::utostr(TargetAS);
2799 default: llvm_unreachable(
"Not a language specific address space");
2803 case LangAS::opencl_global:
2804 ASString =
"CLglobal";
2806 case LangAS::opencl_global_device:
2807 ASString =
"CLdevice";
2809 case LangAS::opencl_global_host:
2810 ASString =
"CLhost";
2812 case LangAS::opencl_local:
2813 ASString =
"CLlocal";
2815 case LangAS::opencl_constant:
2816 ASString =
"CLconstant";
2818 case LangAS::opencl_private:
2819 ASString =
"CLprivate";
2821 case LangAS::opencl_generic:
2822 ASString =
"CLgeneric";
2826 case LangAS::sycl_global:
2827 ASString =
"SYglobal";
2829 case LangAS::sycl_global_device:
2830 ASString =
"SYdevice";
2832 case LangAS::sycl_global_host:
2833 ASString =
"SYhost";
2835 case LangAS::sycl_local:
2836 ASString =
"SYlocal";
2838 case LangAS::sycl_private:
2839 ASString =
"SYprivate";
2842 case LangAS::cuda_device:
2843 ASString =
"CUdevice";
2845 case LangAS::cuda_constant:
2846 ASString =
"CUconstant";
2848 case LangAS::cuda_shared:
2849 ASString =
"CUshared";
2852 case LangAS::ptr32_sptr:
2853 ASString =
"ptr32_sptr";
2855 case LangAS::ptr32_uptr:
2859 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2860 ASString =
"ptr32_uptr";
2867 if (!ASString.empty())
2868 mangleVendorQualifier(ASString);
2881 mangleVendorQualifier(
"__weak");
2885 mangleVendorQualifier(
"__unaligned");
2889 mangleVendorQualifier(
"__ptrauth");
2899 << unsigned(PtrAuth.isAddressDiscriminated())
2902 << PtrAuth.getExtraDiscriminator()
2917 mangleVendorQualifier(
"__strong");
2921 mangleVendorQualifier(
"__autoreleasing");
2944void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2948void CXXNameMangler::mangleVendorType(StringRef name) {
2955 switch (RefQualifier) {
2969void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2970 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2983 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2989 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2995 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
2996 if (DeducedTST->getDeducedType().isNull())
3001void CXXNameMangler::mangleType(QualType T) {
3041 if (
const TemplateSpecializationType *TST
3042 = dyn_cast<TemplateSpecializationType>(T))
3043 if (!TST->isTypeAlias())
3058 auto [ty, quals] = T.
split();
3060 bool isSubstitutable =
3062 if (isSubstitutable && mangleSubstitution(T))
3069 quals = Qualifiers();
3075 if (quals || ty->isDependentAddressSpaceType()) {
3076 if (
const DependentAddressSpaceType *DAST =
3077 dyn_cast<DependentAddressSpaceType>(ty)) {
3079 mangleQualifiers(Quals, DAST);
3080 mangleType(QualType(Ty, 0));
3082 mangleQualifiers(quals);
3086 mangleType(QualType(ty, 0));
3089 switch (ty->getTypeClass()) {
3090#define ABSTRACT_TYPE(CLASS, PARENT)
3091#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3093 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3095#define TYPE(CLASS, PARENT) \
3097 mangleType(static_cast<const CLASS##Type*>(ty)); \
3099#include "clang/AST/TypeNodes.inc"
3104 if (isSubstitutable)
3108void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3109 bool SuppressSubstitution) {
3110 if (mangleSubstitution(
Record))
3113 if (SuppressSubstitution)
3118void CXXNameMangler::mangleType(
const BuiltinType *T) {
3160 std::string type_name;
3164 if (NormalizeIntegers && T->
isInteger()) {
3166 switch (getASTContext().getTypeSize(T)) {
3170 if (mangleSubstitution(BuiltinType::SChar))
3173 addSubstitution(BuiltinType::SChar);
3176 if (mangleSubstitution(BuiltinType::Short))
3179 addSubstitution(BuiltinType::Short);
3182 if (mangleSubstitution(BuiltinType::Int))
3185 addSubstitution(BuiltinType::Int);
3188 if (mangleSubstitution(BuiltinType::Long))
3191 addSubstitution(BuiltinType::Long);
3194 if (mangleSubstitution(BuiltinType::Int128))
3197 addSubstitution(BuiltinType::Int128);
3200 llvm_unreachable(
"Unknown integer size for normalization");
3203 switch (getASTContext().getTypeSize(T)) {
3205 if (mangleSubstitution(BuiltinType::UChar))
3208 addSubstitution(BuiltinType::UChar);
3211 if (mangleSubstitution(BuiltinType::UShort))
3214 addSubstitution(BuiltinType::UShort);
3217 if (mangleSubstitution(BuiltinType::UInt))
3220 addSubstitution(BuiltinType::UInt);
3223 if (mangleSubstitution(BuiltinType::ULong))
3226 addSubstitution(BuiltinType::ULong);
3229 if (mangleSubstitution(BuiltinType::UInt128))
3232 addSubstitution(BuiltinType::UInt128);
3235 llvm_unreachable(
"Unknown integer size for normalization");
3241 case BuiltinType::Void:
3244 case BuiltinType::Bool:
3247 case BuiltinType::Char_U:
3248 case BuiltinType::Char_S:
3251 case BuiltinType::UChar:
3254 case BuiltinType::UShort:
3257 case BuiltinType::UInt:
3260 case BuiltinType::ULong:
3263 case BuiltinType::ULongLong:
3266 case BuiltinType::UInt128:
3269 case BuiltinType::SChar:
3272 case BuiltinType::WChar_S:
3273 case BuiltinType::WChar_U:
3276 case BuiltinType::Char8:
3279 case BuiltinType::Char16:
3282 case BuiltinType::Char32:
3285 case BuiltinType::Short:
3288 case BuiltinType::Int:
3291 case BuiltinType::Long:
3294 case BuiltinType::LongLong:
3297 case BuiltinType::Int128:
3300 case BuiltinType::Float16:
3303 case BuiltinType::ShortAccum:
3306 case BuiltinType::Accum:
3309 case BuiltinType::LongAccum:
3312 case BuiltinType::UShortAccum:
3315 case BuiltinType::UAccum:
3318 case BuiltinType::ULongAccum:
3321 case BuiltinType::ShortFract:
3324 case BuiltinType::Fract:
3327 case BuiltinType::LongFract:
3330 case BuiltinType::UShortFract:
3333 case BuiltinType::UFract:
3336 case BuiltinType::ULongFract:
3339 case BuiltinType::SatShortAccum:
3342 case BuiltinType::SatAccum:
3345 case BuiltinType::SatLongAccum:
3348 case BuiltinType::SatUShortAccum:
3351 case BuiltinType::SatUAccum:
3354 case BuiltinType::SatULongAccum:
3357 case BuiltinType::SatShortFract:
3360 case BuiltinType::SatFract:
3363 case BuiltinType::SatLongFract:
3366 case BuiltinType::SatUShortFract:
3369 case BuiltinType::SatUFract:
3372 case BuiltinType::SatULongFract:
3375 case BuiltinType::Half:
3378 case BuiltinType::Float:
3381 case BuiltinType::Double:
3384 case BuiltinType::LongDouble: {
3385 const TargetInfo *TI =
3386 getASTContext().getLangOpts().OpenMP &&
3387 getASTContext().getLangOpts().OpenMPIsTargetDevice
3388 ? getASTContext().getAuxTargetInfo()
3389 : &getASTContext().getTargetInfo();
3393 case BuiltinType::Float128: {
3394 const TargetInfo *TI =
3395 getASTContext().getLangOpts().OpenMP &&
3396 getASTContext().getLangOpts().OpenMPIsTargetDevice
3397 ? getASTContext().getAuxTargetInfo()
3398 : &getASTContext().getTargetInfo();
3402 case BuiltinType::BFloat16: {
3403 const TargetInfo *TI =
3404 ((getASTContext().getLangOpts().OpenMP &&
3405 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3406 getASTContext().getLangOpts().SYCLIsDevice)
3407 ? getASTContext().getAuxTargetInfo()
3408 : &getASTContext().getTargetInfo();
3412 case BuiltinType::Ibm128: {
3413 const TargetInfo *TI = &getASTContext().getTargetInfo();
3417 case BuiltinType::NullPtr:
3421#define BUILTIN_TYPE(Id, SingletonId)
3422#define PLACEHOLDER_TYPE(Id, SingletonId) \
3423 case BuiltinType::Id:
3424#include "clang/AST/BuiltinTypes.def"
3425 case BuiltinType::Dependent:
3427 llvm_unreachable(
"mangling a placeholder type");
3429 case BuiltinType::ObjCId:
3430 Out <<
"11objc_object";
3432 case BuiltinType::ObjCClass:
3433 Out <<
"10objc_class";
3435 case BuiltinType::ObjCSel:
3436 Out <<
"13objc_selector";
3438#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3439 case BuiltinType::Id: \
3440 type_name = "ocl_" #ImgType "_" #Suffix; \
3441 Out << type_name.size() << type_name; \
3443#include "clang/Basic/OpenCLImageTypes.def"
3444 case BuiltinType::OCLSampler:
3445 Out <<
"11ocl_sampler";
3447 case BuiltinType::OCLEvent:
3448 Out <<
"9ocl_event";
3450 case BuiltinType::OCLClkEvent:
3451 Out <<
"12ocl_clkevent";
3453 case BuiltinType::OCLQueue:
3454 Out <<
"9ocl_queue";
3456 case BuiltinType::OCLReserveID:
3457 Out <<
"13ocl_reserveid";
3459#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3460 case BuiltinType::Id: \
3461 type_name = "ocl_" #ExtType; \
3462 Out << type_name.size() << type_name; \
3464#include "clang/Basic/OpenCLExtensionTypes.def"
3468#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3469 case BuiltinType::Id: \
3470 if (T->getKind() == BuiltinType::SveBFloat16 && \
3471 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3473 mangleVendorType("__SVBFloat16_t"); \
3475 type_name = #MangledName; \
3476 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3479#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3480 case BuiltinType::Id: \
3481 type_name = #MangledName; \
3482 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3484#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3485 case BuiltinType::Id: \
3486 type_name = #MangledName; \
3487 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3489#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3490 case BuiltinType::Id: \
3491 type_name = #MangledName; \
3492 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3494#include "clang/Basic/AArch64ACLETypes.def"
3495#define PPC_VECTOR_TYPE(Name, Id, Size) \
3496 case BuiltinType::Id: \
3497 mangleVendorType(#Name); \
3499#include "clang/Basic/PPCTypes.def"
3501#define RVV_TYPE(Name, Id, SingletonId) \
3502 case BuiltinType::Id: \
3503 mangleVendorType(Name); \
3505#include "clang/Basic/RISCVVTypes.def"
3506#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3507 case BuiltinType::Id: \
3508 mangleVendorType(MangledName); \
3510#include "clang/Basic/WebAssemblyReferenceTypes.def"
3511#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3512 case BuiltinType::Id: \
3513 mangleVendorType(Name); \
3515#include "clang/Basic/AMDGPUTypes.def"
3516#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3517 case BuiltinType::Id: \
3518 mangleVendorType(#Name); \
3520#include "clang/Basic/HLSLIntangibleTypes.def"
3524StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3544#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3580 return "swiftasynccall";
3582 llvm_unreachable(
"bad calling convention");
3585void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *T) {
3587 if (T->
getExtInfo() == FunctionType::ExtInfo())
3594 StringRef CCQualifier = getCallingConvQualifierName(T->
getExtInfo().
getCC());
3595 if (!CCQualifier.empty())
3596 mangleVendorQualifier(CCQualifier);
3629 llvm_unreachable(
"Unrecognised SME attribute");
3644void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3664 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3668CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3675 case ParameterABI::Ordinary:
3679 case ParameterABI::HLSLOut:
3680 case ParameterABI::HLSLInOut:
3685 case ParameterABI::SwiftContext:
3686 case ParameterABI::SwiftAsyncContext:
3687 case ParameterABI::SwiftErrorResult:
3688 case ParameterABI::SwiftIndirectResult:
3694 mangleVendorQualifier(
"ns_consumed");
3697 mangleVendorQualifier(
"noescape");
3703void CXXNameMangler::mangleType(
const FunctionProtoType *T) {
3707 Out <<
"11__SME_ATTRSI";
3709 mangleExtFunctionInfo(T);
3726 mangleType(ExceptTy);
3737 mangleBareFunctionType(T,
true);
3744 mangleSMEAttrs(SMEAttrs);
3747void CXXNameMangler::mangleType(
const FunctionNoProtoType *T) {
3753 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3755 FunctionTypeDepth.enterResultType();
3757 FunctionTypeDepth.leaveResultType();
3759 FunctionTypeDepth.pop(saved);
3763void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3764 bool MangleReturnType,
3765 const FunctionDecl *FD) {
3768 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3771 if (MangleReturnType) {
3772 FunctionTypeDepth.enterResultType();
3776 mangleVendorQualifier(
"ns_returns_retained");
3781 auto SplitReturnTy = ReturnTy.
split();
3783 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3785 mangleType(ReturnTy);
3787 FunctionTypeDepth.leaveResultType();
3795 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3809 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3810 if (Attr->isDynamic())
3811 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3813 Out <<
"U17pass_object_size" << Attr->getType();
3824 FunctionTypeDepth.enterResultType();
3828 FunctionTypeDepth.pop(saved);
3833void CXXNameMangler::mangleType(
const UnresolvedUsingType *T) {
3839void CXXNameMangler::mangleType(
const EnumType *T) {
3840 mangleType(
static_cast<const TagType*
>(T));
3842void CXXNameMangler::mangleType(
const RecordType *T) {
3843 mangleType(
static_cast<const TagType*
>(T));
3845void CXXNameMangler::mangleType(
const TagType *T) {
3846 mangleName(T->getDecl()->getDefinitionOrSelf());
3852void CXXNameMangler::mangleType(
const ConstantArrayType *T) {
3856void CXXNameMangler::mangleType(
const VariableArrayType *T) {
3864void CXXNameMangler::mangleType(
const DependentSizedArrayType *T) {
3874void CXXNameMangler::mangleType(
const IncompleteArrayType *T) {
3881void CXXNameMangler::mangleType(
const MemberPointerType *T) {
3884 mangleCXXRecordDecl(RD);
3888 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3909 mangleType(PointeeType);
3913void CXXNameMangler::mangleType(
const TemplateTypeParmType *T) {
3914 mangleTemplateParameter(T->getDepth(), T->getIndex());
3918void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *T) {
3923 Out <<
"_SUBSTPACK_";
3926void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *T) {
3931 Out <<
"_SUBSTBUILTINPACK_";
3935void CXXNameMangler::mangleType(
const PointerType *T) {
3939void CXXNameMangler::mangleType(
const ObjCObjectPointerType *T) {
3945void CXXNameMangler::mangleType(
const LValueReferenceType *T) {
3951void CXXNameMangler::mangleType(
const RValueReferenceType *T) {
3957void CXXNameMangler::mangleType(
const ComplexType *T) {
3965void CXXNameMangler::mangleNeonVectorType(
const VectorType *T) {
3967 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3968 const char *EltName =
nullptr;
3971 case BuiltinType::SChar:
3972 case BuiltinType::UChar:
3973 EltName =
"poly8_t";
3975 case BuiltinType::Short:
3976 case BuiltinType::UShort:
3977 EltName =
"poly16_t";
3979 case BuiltinType::LongLong:
3980 case BuiltinType::ULongLong:
3981 EltName =
"poly64_t";
3983 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3987 case BuiltinType::SChar: EltName =
"int8_t";
break;
3988 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3989 case BuiltinType::Short: EltName =
"int16_t";
break;
3990 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3991 case BuiltinType::Int: EltName =
"int32_t";
break;
3992 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3993 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3994 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3995 case BuiltinType::Double: EltName =
"float64_t";
break;
3996 case BuiltinType::Float: EltName =
"float32_t";
break;
3997 case BuiltinType::Half: EltName =
"float16_t";
break;
3998 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3999 case BuiltinType::MFloat8:
4000 EltName =
"mfloat8_t";
4003 llvm_unreachable(
"unexpected Neon vector element type");
4006 const char *BaseName =
nullptr;
4008 getASTContext().getTypeSize(EltType));
4010 BaseName =
"__simd64_";
4012 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4013 BaseName =
"__simd128_";
4015 Out << strlen(BaseName) + strlen(EltName);
4016 Out << BaseName << EltName;
4019void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *T) {
4020 DiagnosticsEngine &Diags = Context.getDiags();
4022 << UnsupportedItaniumManglingKind::DependentNeonVector;
4027 case BuiltinType::SChar:
4029 case BuiltinType::Short:
4031 case BuiltinType::Int:
4033 case BuiltinType::Long:
4034 case BuiltinType::LongLong:
4036 case BuiltinType::UChar:
4038 case BuiltinType::UShort:
4040 case BuiltinType::UInt:
4042 case BuiltinType::ULong:
4043 case BuiltinType::ULongLong:
4045 case BuiltinType::Half:
4047 case BuiltinType::Float:
4049 case BuiltinType::Double:
4051 case BuiltinType::BFloat16:
4053 case BuiltinType::MFloat8:
4056 llvm_unreachable(
"Unexpected vector element base type");
4063void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *T) {
4065 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4070 assert((BitSize == 64 || BitSize == 128) &&
4071 "Neon vector type not 64 or 128 bits");
4076 case BuiltinType::UChar:
4079 case BuiltinType::UShort:
4082 case BuiltinType::ULong:
4083 case BuiltinType::ULongLong:
4087 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4093 (
"__" + EltName +
"x" + Twine(T->
getNumElements()) +
"_t").str();
4096void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *T) {
4097 DiagnosticsEngine &Diags = Context.getDiags();
4099 << UnsupportedItaniumManglingKind::DependentNeonVector;
4126void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *T) {
4127 assert((T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4128 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4129 "expected fixed-length SVE vector!");
4133 "expected builtin type for fixed-length SVE vector!");
4137 case BuiltinType::SChar:
4140 case BuiltinType::UChar: {
4147 case BuiltinType::Short:
4150 case BuiltinType::UShort:
4153 case BuiltinType::Int:
4156 case BuiltinType::UInt:
4159 case BuiltinType::Long:
4162 case BuiltinType::ULong:
4165 case BuiltinType::Half:
4168 case BuiltinType::Float:
4171 case BuiltinType::Double:
4174 case BuiltinType::BFloat16:
4178 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4181 unsigned VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4183 if (T->
getVectorKind() == VectorKind::SveFixedLengthPredicate)
4186 Out <<
"9__SVE_VLSI";
4187 mangleVendorType(TypeName);
4188 Out <<
"Lj" << VecSizeInBits <<
"EE";
4191void CXXNameMangler::mangleAArch64FixedSveVectorType(
4192 const DependentVectorType *T) {
4193 DiagnosticsEngine &Diags = Context.getDiags();
4195 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4198void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *T) {
4199 assert((T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4204 "expected fixed-length RVV vector!");
4208 "expected builtin type for fixed-length RVV vector!");
4210 SmallString<20> TypeNameStr;
4211 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4212 TypeNameOS <<
"__rvv_";
4214 case BuiltinType::SChar:
4215 TypeNameOS <<
"int8";
4217 case BuiltinType::UChar:
4219 TypeNameOS <<
"uint8";
4221 TypeNameOS <<
"bool";
4223 case BuiltinType::Short:
4224 TypeNameOS <<
"int16";
4226 case BuiltinType::UShort:
4227 TypeNameOS <<
"uint16";
4229 case BuiltinType::Int:
4230 TypeNameOS <<
"int32";
4232 case BuiltinType::UInt:
4233 TypeNameOS <<
"uint32";
4235 case BuiltinType::Long:
4236 case BuiltinType::LongLong:
4237 TypeNameOS <<
"int64";
4239 case BuiltinType::ULong:
4240 case BuiltinType::ULongLong:
4241 TypeNameOS <<
"uint64";
4243 case BuiltinType::Float16:
4244 TypeNameOS <<
"float16";
4246 case BuiltinType::Float:
4247 TypeNameOS <<
"float32";
4249 case BuiltinType::Double:
4250 TypeNameOS <<
"float64";
4252 case BuiltinType::BFloat16:
4253 TypeNameOS <<
"bfloat16";
4256 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4259 unsigned VecSizeInBits;
4261 case VectorKind::RVVFixedLengthMask_1:
4264 case VectorKind::RVVFixedLengthMask_2:
4267 case VectorKind::RVVFixedLengthMask_4:
4271 VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4276 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4277 getASTContext().getLangOpts(),
4278 TargetInfo::ArmStreamingKind::NotStreaming);
4279 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4283 if (VecSizeInBits >= VLen)
4284 TypeNameOS << (VecSizeInBits / VLen);
4286 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4288 TypeNameOS << (VLen / VecSizeInBits);
4292 Out <<
"9__RVV_VLSI";
4293 mangleVendorType(TypeNameStr);
4294 Out <<
"Lj" << VecSizeInBits <<
"EE";
4297void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4298 const DependentVectorType *T) {
4299 DiagnosticsEngine &Diags = Context.getDiags();
4301 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4312void CXXNameMangler::mangleType(
const VectorType *T) {
4315 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4316 llvm::Triple::ArchType
Arch =
4317 getASTContext().getTargetInfo().getTriple().getArch();
4318 if ((
Arch == llvm::Triple::aarch64 ||
4319 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4320 mangleAArch64NeonVectorType(T);
4322 mangleNeonVectorType(T);
4324 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4325 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4326 mangleAArch64FixedSveVectorType(T);
4328 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4333 mangleRISCVFixedRVVVectorType(T);
4345void CXXNameMangler::mangleType(
const DependentVectorType *T) {
4348 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4349 llvm::Triple::ArchType
Arch =
4350 getASTContext().getTargetInfo().getTriple().getArch();
4351 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4353 mangleAArch64NeonVectorType(T);
4355 mangleNeonVectorType(T);
4357 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4358 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4359 mangleAArch64FixedSveVectorType(T);
4361 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData) {
4362 mangleRISCVFixedRVVVectorType(T);
4377void CXXNameMangler::mangleType(
const ExtVectorType *T) {
4378 mangleType(
static_cast<const VectorType*
>(T));
4380void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *T) {
4387void CXXNameMangler::mangleType(
const ConstantMatrixType *T) {
4391 mangleVendorType(
"matrix_type");
4394 auto &ASTCtx = getASTContext();
4395 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4396 llvm::APSInt Rows(BitWidth);
4398 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4399 llvm::APSInt Columns(BitWidth);
4401 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4406void CXXNameMangler::mangleType(
const DependentSizedMatrixType *T) {
4409 mangleVendorType(
"matrix_type");
4418void CXXNameMangler::mangleType(
const DependentAddressSpaceType *T) {
4420 mangleQualifiers(split.
Quals, T);
4421 mangleType(QualType(split.
Ty, 0));
4424void CXXNameMangler::mangleType(
const PackExpansionType *T) {
4427 mangleType(T->getPattern());
4430void CXXNameMangler::mangleType(
const PackIndexingType *T) {
4431 if (!T->hasSelectedType())
4432 mangleType(T->getPattern());
4434 mangleType(T->getSelectedType());
4437void CXXNameMangler::mangleType(
const ObjCInterfaceType *T) {
4441void CXXNameMangler::mangleType(
const ObjCObjectType *T) {
4443 if (T->isKindOfType())
4444 Out <<
"U8__kindof";
4446 if (!T->qual_empty()) {
4448 SmallString<64> QualStr;
4449 llvm::raw_svector_ostream QualOS(QualStr);
4450 QualOS <<
"objcproto";
4451 for (
const auto *I : T->quals()) {
4452 StringRef
name = I->getName();
4455 mangleVendorQualifier(QualStr);
4458 mangleType(T->getBaseType());
4460 if (T->isSpecialized()) {
4463 for (
auto typeArg : T->getTypeArgs())
4464 mangleType(typeArg);
4469void CXXNameMangler::mangleType(
const BlockPointerType *T) {
4470 Out <<
"U13block_pointer";
4474void CXXNameMangler::mangleType(
const InjectedClassNameType *T) {
4479 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4482void CXXNameMangler::mangleType(
const TemplateSpecializationType *T) {
4483 if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) {
4484 mangleTemplateName(TD, T->template_arguments());
4487 mangleTemplatePrefix(T->getTemplateName());
4492 mangleTemplateArgs(T->getTemplateName(), T->template_arguments());
4497void CXXNameMangler::mangleType(
const DependentNameType *T) {
4508 switch (T->getKeyword()) {
4509 case ElaboratedTypeKeyword::None:
4510 case ElaboratedTypeKeyword::Typename:
4512 case ElaboratedTypeKeyword::Struct:
4513 case ElaboratedTypeKeyword::Class:
4514 case ElaboratedTypeKeyword::Interface:
4517 case ElaboratedTypeKeyword::Union:
4520 case ElaboratedTypeKeyword::Enum:
4526 manglePrefix(T->getQualifier());
4527 mangleSourceName(T->getIdentifier());
4531void CXXNameMangler::mangleType(
const TypeOfType *T) {
4537void CXXNameMangler::mangleType(
const TypeOfExprType *T) {
4543void CXXNameMangler::mangleType(
const DecltypeType *T) {
4544 Expr *E = T->getUnderlyingExpr();
4563 mangleExpression(E);
4567void CXXNameMangler::mangleType(
const UnaryTransformType *T) {
4570 if (T->isDependentType()) {
4571 StringRef BuiltinName;
4572 switch (T->getUTTKind()) {
4573#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4574 case UnaryTransformType::Enum: \
4575 BuiltinName = "__" #Trait; \
4577#include "clang/Basic/TransformTypeTraits.def"
4579 mangleVendorType(BuiltinName);
4583 mangleType(T->getBaseType());
4587void CXXNameMangler::mangleType(
const AutoType *T) {
4588 assert(T->getDeducedType().isNull() &&
4589 "Deduced AutoType shouldn't be handled here!");
4590 assert(T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4591 "shouldn't need to mangle __auto_type!");
4596 if (T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4597 Out << (T->isDecltypeAuto() ?
"DK" :
"Dk");
4598 mangleTypeConstraint(T->getTypeConstraintConcept(),
4599 T->getTypeConstraintArguments());
4601 Out << (T->isDecltypeAuto() ?
"Dc" :
"Da");
4605void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *T) {
4606 QualType
Deduced = T->getDeducedType();
4612 "shouldn't form deduced TST unless we know we have a template");
4616void CXXNameMangler::mangleType(
const AtomicType *T) {
4623void CXXNameMangler::mangleType(
const PipeType *T) {
4630void CXXNameMangler::mangleType(
const OverflowBehaviorType *T) {
4633 if (T->isWrapKind()) {
4634 Out <<
"U8ObtWrap_";
4636 Out <<
"U8ObtTrap_";
4638 mangleType(T->getUnderlyingType());
4641void CXXNameMangler::mangleType(
const BitIntType *T) {
4648void CXXNameMangler::mangleType(
const DependentBitIntType *T) {
4657void CXXNameMangler::mangleType(
const ArrayParameterType *T) {
4661void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *T) {
4662 llvm::SmallString<64> Str(
"_Res");
4663 const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
4665 switch (Attrs.ResourceClass) {
4666 case llvm::dxil::ResourceClass::UAV:
4669 case llvm::dxil::ResourceClass::SRV:
4672 case llvm::dxil::ResourceClass::CBuffer:
4675 case llvm::dxil::ResourceClass::Sampler:
4681 if (Attrs.RawBuffer)
4683 if (Attrs.IsCounter)
4685 if (T->hasContainedType())
4687 mangleVendorQualifier(Str);
4689 if (T->hasContainedType()) {
4690 mangleType(T->getContainedType());
4692 mangleType(T->getWrappedType());
4695void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *T) {
4696 SmallString<20> TypeNameStr;
4697 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4699 TypeNameOS <<
"spirv_type";
4701 TypeNameOS <<
"_" << T->getOpcode();
4702 TypeNameOS <<
"_" << T->getSize();
4703 TypeNameOS <<
"_" << T->getAlignment();
4705 mangleVendorType(TypeNameStr);
4707 for (
auto &Operand : T->getOperands()) {
4708 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4711 case SpirvOperandKind::ConstantId:
4712 mangleVendorQualifier(
"_Const");
4713 mangleIntegerLiteral(
Operand.getResultType(),
4714 llvm::APSInt(
Operand.getValue()));
4716 case SpirvOperandKind::Literal:
4717 mangleVendorQualifier(
"_Lit");
4718 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4719 llvm::APSInt(
Operand.getValue()));
4721 case SpirvOperandKind::TypeId:
4722 mangleVendorQualifier(
"_Type");
4723 mangleType(
Operand.getResultType());
4726 llvm_unreachable(
"Invalid SpirvOperand kind");
4729 TypeNameOS <<
Operand.getKind();
4733void CXXNameMangler::mangleIntegerLiteral(QualType T,
4734 const llvm::APSInt &
Value) {
4741 Out << (
Value.getBoolValue() ?
'1' :
'0');
4743 mangleNumber(
Value);
4748void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4750 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4751 if (!RT->getDecl()->isAnonymousStructOrUnion())
4753 const auto *ME = dyn_cast<MemberExpr>(Base);
4756 Base = ME->getBase();
4757 IsArrow = ME->isArrow();
4760 if (
Base->isImplicitCXXThis()) {
4766 Out << (IsArrow ?
"pt" :
"dt");
4767 mangleExpression(Base);
4772void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4773 NestedNameSpecifier Qualifier,
4774 NamedDecl *firstQualifierLookup,
4775 DeclarationName member,
4776 const TemplateArgumentLoc *TemplateArgs,
4777 unsigned NumTemplateArgs,
4782 mangleMemberExprBase(base, isArrow);
4783 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4796 if (callee == fn)
return false;
4800 if (!lookup)
return false;
4817void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4819 Out << CastEncoding;
4824void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4826 InitList = Syntactic;
4827 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4828 mangleExpression(InitList->
getInit(i));
4831void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4832 const concepts::Requirement *Req) {
4833 using concepts::Requirement;
4838 auto HandleSubstitutionFailure =
4839 [&](SourceLocation Loc) {
4840 DiagnosticsEngine &Diags = Context.getDiags();
4841 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4842 << UnsupportedItaniumManglingKind::
4843 RequiresExprWithSubstitutionFailure;
4848 case Requirement::RK_Type: {
4850 if (TR->isSubstitutionFailure())
4851 return HandleSubstitutionFailure(
4852 TR->getSubstitutionDiagnostic()->DiagLoc);
4855 mangleType(TR->getType()->getType());
4859 case Requirement::RK_Simple:
4860 case Requirement::RK_Compound: {
4862 if (ER->isExprSubstitutionFailure())
4863 return HandleSubstitutionFailure(
4864 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4867 mangleExpression(ER->getExpr());
4869 if (ER->hasNoexceptRequirement())
4872 if (!ER->getReturnTypeRequirement().isEmpty()) {
4873 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4874 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4875 .getSubstitutionDiagnostic()
4879 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4884 case Requirement::RK_Nested:
4886 if (NR->hasInvalidConstraint()) {
4889 return HandleSubstitutionFailure(RequiresExprLoc);
4893 mangleExpression(NR->getConstraintExpr());
4898void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4899 bool AsTemplateArg) {
4928 QualType ImplicitlyConvertedToType;
4932 bool IsPrimaryExpr =
true;
4933 auto NotPrimaryExpr = [&] {
4934 if (AsTemplateArg && IsPrimaryExpr)
4936 IsPrimaryExpr =
false;
4939 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4940 switch (D->getKind()) {
4953 case Decl::EnumConstant: {
4960 case Decl::NonTypeTemplateParm:
4973 case Expr::NoStmtClass:
4974#define ABSTRACT_STMT(Type)
4975#define EXPR(Type, Base)
4976#define STMT(Type, Base) \
4977 case Expr::Type##Class:
4978#include "clang/AST/StmtNodes.inc"
4983 case Expr::AddrLabelExprClass:
4984 case Expr::DesignatedInitUpdateExprClass:
4985 case Expr::ImplicitValueInitExprClass:
4986 case Expr::ArrayInitLoopExprClass:
4987 case Expr::ArrayInitIndexExprClass:
4988 case Expr::NoInitExprClass:
4989 case Expr::ParenListExprClass:
4990 case Expr::MSPropertyRefExprClass:
4991 case Expr::MSPropertySubscriptExprClass:
4992 case Expr::RecoveryExprClass:
4993 case Expr::ArraySectionExprClass:
4994 case Expr::OMPArrayShapingExprClass:
4995 case Expr::OMPIteratorExprClass:
4996 case Expr::CXXInheritedCtorInitExprClass:
4997 case Expr::CXXParenListInitExprClass:
4998 case Expr::PackIndexingExprClass:
4999 llvm_unreachable(
"unexpected statement kind");
5001 case Expr::ConstantExprClass:
5005 case Expr::CXXReflectExprClass: {
5007 assert(
false &&
"unimplemented");
5012 case Expr::BlockExprClass:
5013 case Expr::ChooseExprClass:
5014 case Expr::CompoundLiteralExprClass:
5015 case Expr::ExtVectorElementExprClass:
5016 case Expr::MatrixElementExprClass:
5017 case Expr::GenericSelectionExprClass:
5018 case Expr::ObjCEncodeExprClass:
5019 case Expr::ObjCIsaExprClass:
5020 case Expr::ObjCIvarRefExprClass:
5021 case Expr::ObjCMessageExprClass:
5022 case Expr::ObjCPropertyRefExprClass:
5023 case Expr::ObjCProtocolExprClass:
5024 case Expr::ObjCSelectorExprClass:
5025 case Expr::ObjCStringLiteralClass:
5026 case Expr::ObjCBoxedExprClass:
5027 case Expr::ObjCArrayLiteralClass:
5028 case Expr::ObjCDictionaryLiteralClass:
5029 case Expr::ObjCSubscriptRefExprClass:
5030 case Expr::ObjCIndirectCopyRestoreExprClass:
5031 case Expr::ObjCAvailabilityCheckExprClass:
5032 case Expr::OffsetOfExprClass:
5033 case Expr::PredefinedExprClass:
5034 case Expr::ShuffleVectorExprClass:
5035 case Expr::ConvertVectorExprClass:
5036 case Expr::StmtExprClass:
5037 case Expr::ArrayTypeTraitExprClass:
5038 case Expr::ExpressionTraitExprClass:
5039 case Expr::VAArgExprClass:
5040 case Expr::CUDAKernelCallExprClass:
5041 case Expr::AsTypeExprClass:
5042 case Expr::PseudoObjectExprClass:
5043 case Expr::AtomicExprClass:
5044 case Expr::SourceLocExprClass:
5045 case Expr::EmbedExprClass:
5046 case Expr::BuiltinBitCastExprClass: {
5050 DiagnosticsEngine &Diags = Context.getDiags();
5058 case Expr::CXXUuidofExprClass: {
5063 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5064 Out <<
"u8__uuidof";
5073 Out <<
"u8__uuidoft";
5077 Out <<
"u8__uuidofz";
5078 mangleExpression(UuidExp);
5085 case Expr::BinaryConditionalOperatorClass: {
5087 DiagnosticsEngine &Diags = Context.getDiags();
5089 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5095 case Expr::OpaqueValueExprClass:
5096 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5098 case Expr::InitListExprClass: {
5106 case Expr::DesignatedInitExprClass: {
5109 for (
const auto &Designator : DIE->designators()) {
5110 if (Designator.isFieldDesignator()) {
5112 mangleSourceName(Designator.getFieldName());
5113 }
else if (Designator.isArrayDesignator()) {
5115 mangleExpression(DIE->getArrayIndex(Designator));
5117 assert(Designator.isArrayRangeDesignator() &&
5118 "unknown designator kind");
5120 mangleExpression(DIE->getArrayRangeStart(Designator));
5121 mangleExpression(DIE->getArrayRangeEnd(Designator));
5124 mangleExpression(DIE->getInit());
5128 case Expr::CXXDefaultArgExprClass:
5132 case Expr::CXXDefaultInitExprClass:
5136 case Expr::CXXStdInitializerListExprClass:
5140 case Expr::SubstNonTypeTemplateParmExprClass: {
5144 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5146 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5147 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5148 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5158 case Expr::UserDefinedLiteralClass:
5161 case Expr::CXXMemberCallExprClass:
5162 case Expr::CallExprClass: {
5184 CallArity = UnknownArity;
5186 mangleExpression(CE->
getCallee(), CallArity);
5188 mangleExpression(Arg);
5193 case Expr::CXXNewExprClass: {
5196 if (
New->isGlobalNew())
Out <<
"gs";
5197 Out << (
New->isArray() ?
"na" :
"nw");
5199 E =
New->placement_arg_end(); I != E; ++I)
5200 mangleExpression(*I);
5202 mangleType(
New->getAllocatedType());
5203 if (
New->hasInitializer()) {
5204 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5208 const Expr *
Init =
New->getInitializer();
5209 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5214 mangleExpression(*I);
5215 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5216 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5217 mangleExpression(PLE->getExpr(i));
5218 }
else if (
New->getInitializationStyle() ==
5219 CXXNewInitializationStyle::Braces &&
5224 mangleExpression(
Init);
5230 case Expr::CXXPseudoDestructorExprClass: {
5233 if (
const Expr *Base = PDE->getBase())
5234 mangleMemberExprBase(Base, PDE->isArrow());
5235 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5236 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5238 mangleUnresolvedPrefix(Qualifier,
5240 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5244 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5247 }
else if (Qualifier) {
5248 mangleUnresolvedPrefix(Qualifier);
5252 QualType DestroyedType = PDE->getDestroyedType();
5253 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5257 case Expr::MemberExprClass: {
5268 case Expr::UnresolvedMemberExprClass: {
5279 case Expr::CXXDependentScopeMemberExprClass: {
5281 const CXXDependentScopeMemberExpr *ME
5292 case Expr::UnresolvedLookupExprClass: {
5301 case Expr::CXXUnresolvedConstructExprClass: {
5307 assert(N == 1 &&
"unexpected form for list initialization");
5311 mangleInitListElements(IL);
5318 if (N != 1)
Out <<
'_';
5319 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5320 if (N != 1)
Out <<
'E';
5324 case Expr::CXXConstructExprClass: {
5331 "implicit CXXConstructExpr must have one argument");
5338 mangleExpression(E);
5343 case Expr::CXXTemporaryObjectExprClass: {
5354 if (!List && N != 1)
5356 if (CE->isStdInitListInitialization()) {
5363 mangleInitListElements(ILE);
5366 mangleExpression(E);
5373 case Expr::CXXScalarValueInitExprClass:
5380 case Expr::CXXNoexceptExprClass:
5386 case Expr::UnaryExprOrTypeTraitExprClass: {
5403 QualType T = (ImplicitlyConvertedToType.
isNull() ||
5405 : ImplicitlyConvertedToType;
5407 mangleIntegerLiteral(T,
V);
5413 auto MangleAlignofSizeofArg = [&] {
5423 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5424 StringRef Name = {}) {
5427 mangleVendorType(Name);
5438 MangleAlignofSizeofArg();
5440 case UETT_PreferredAlignOf:
5444 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5445 MangleExtensionBuiltin(SAE,
"__alignof__");
5451 MangleAlignofSizeofArg();
5455 case UETT_VectorElements:
5456 case UETT_OpenMPRequiredSimdAlign:
5458 case UETT_PtrAuthTypeDiscriminator:
5459 case UETT_DataSizeOf: {
5460 DiagnosticsEngine &Diags = Context.getDiags();
5469 case Expr::TypeTraitExprClass: {
5474 mangleVendorType(Spelling);
5475 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5476 mangleType(TSI->getType());
5482 case Expr::CXXThrowExprClass: {
5496 case Expr::CXXTypeidExprClass: {
5511 case Expr::CXXDeleteExprClass: {
5522 case Expr::UnaryOperatorClass: {
5531 case Expr::ArraySubscriptExprClass: {
5538 mangleExpression(AE->
getLHS());
5539 mangleExpression(AE->
getRHS());
5543 case Expr::MatrixSingleSubscriptExprClass: {
5547 mangleExpression(ME->
getBase());
5552 case Expr::MatrixSubscriptExprClass: {
5556 mangleExpression(ME->
getBase());
5562 case Expr::CompoundAssignOperatorClass:
5563 case Expr::BinaryOperatorClass: {
5571 mangleExpression(BO->
getLHS());
5572 mangleExpression(BO->
getRHS());
5576 case Expr::CXXRewrittenBinaryOperatorClass: {
5579 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5583 mangleExpression(Decomposed.
LHS);
5584 mangleExpression(Decomposed.
RHS);
5588 case Expr::ConditionalOperatorClass: {
5591 mangleOperatorName(OO_Conditional, 3);
5592 mangleExpression(CO->
getCond());
5593 mangleExpression(CO->
getLHS(), Arity);
5594 mangleExpression(CO->
getRHS(), Arity);
5598 case Expr::ImplicitCastExprClass: {
5599 ImplicitlyConvertedToType = E->
getType();
5604 case Expr::ObjCBridgedCastExprClass: {
5610 mangleCastExpression(E,
"cv");
5614 case Expr::CStyleCastExprClass:
5616 mangleCastExpression(E,
"cv");
5619 case Expr::CXXFunctionalCastExprClass: {
5623 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5624 if (CCE->getParenOrBraceRange().isInvalid())
5625 Sub = CCE->getArg(0)->IgnoreImplicit();
5626 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5627 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5628 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5631 mangleInitListElements(IL);
5634 mangleCastExpression(E,
"cv");
5639 case Expr::CXXStaticCastExprClass:
5641 mangleCastExpression(E,
"sc");
5643 case Expr::CXXDynamicCastExprClass:
5645 mangleCastExpression(E,
"dc");
5647 case Expr::CXXReinterpretCastExprClass:
5649 mangleCastExpression(E,
"rc");
5651 case Expr::CXXConstCastExprClass:
5653 mangleCastExpression(E,
"cc");
5655 case Expr::CXXAddrspaceCastExprClass:
5657 mangleCastExpression(E,
"ac");
5660 case Expr::CXXOperatorCallExprClass: {
5669 for (
unsigned i = 0; i != NumArgs; ++i)
5670 mangleExpression(CE->
getArg(i));
5674 case Expr::ParenExprClass:
5678 case Expr::ConceptSpecializationExprClass: {
5680 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5685 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5691 mangleUnresolvedName(
5692 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5693 CSE->getConceptNameInfo().getName(),
5694 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5695 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5699 case Expr::RequiresExprClass: {
5705 if (RE->getLParenLoc().isValid()) {
5707 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5708 if (RE->getLocalParameters().empty()) {
5711 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5719 FunctionTypeDepth.enterResultType();
5720 for (
const concepts::Requirement *Req : RE->getRequirements())
5721 mangleRequirement(RE->getExprLoc(), Req);
5722 FunctionTypeDepth.pop(saved);
5726 for (
const concepts::Requirement *Req : RE->getRequirements())
5727 mangleRequirement(RE->getExprLoc(), Req);
5733 case Expr::DeclRefExprClass:
5738 case Expr::SubstNonTypeTemplateParmPackExprClass:
5744 Out <<
"_SUBSTPACK_";
5747 case Expr::FunctionParmPackExprClass: {
5751 Out <<
"v110_SUBSTPACK";
5756 case Expr::DependentScopeDeclRefExprClass: {
5765 case Expr::CXXBindTemporaryExprClass:
5769 case Expr::ExprWithCleanupsClass:
5773 case Expr::FloatingLiteralClass: {
5780 case Expr::FixedPointLiteralClass:
5782 mangleFixedPointLiteral();
5785 case Expr::CharacterLiteralClass:
5789 Out << cast<CharacterLiteral>(E)->getValue();
5794 case Expr::ObjCBoolLiteralExprClass:
5797 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5801 case Expr::CXXBoolLiteralExprClass:
5804 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5808 case Expr::IntegerLiteralClass: {
5812 Value.setIsSigned(
true);
5817 case Expr::ImaginaryLiteralClass: {
5824 if (
const FloatingLiteral *Imag =
5825 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5827 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5829 mangleFloat(Imag->getValue());
5834 Value.setIsSigned(
true);
5835 mangleNumber(
Value);
5841 case Expr::StringLiteralClass: {
5851 case Expr::GNUNullExprClass:
5854 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5857 case Expr::CXXNullPtrLiteralExprClass: {
5863 case Expr::LambdaExprClass: {
5874 case Expr::PackExpansionExprClass:
5880 case Expr::SizeOfPackExprClass: {
5883 if (SPE->isPartiallySubstituted()) {
5885 for (
const auto &A : SPE->getPartialArguments())
5886 mangleTemplateArg(A,
false);
5892 const NamedDecl *Pack = SPE->getPack();
5893 if (
const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
5894 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5895 else if (
const NonTypeTemplateParmDecl *NTTP
5896 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5897 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5898 else if (
const TemplateTemplateParmDecl *TempTP
5899 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5900 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5906 case Expr::MaterializeTemporaryExprClass:
5910 case Expr::CXXFoldExprClass: {
5913 if (FE->isLeftFold())
5914 Out << (FE->getInit() ?
"fL" :
"fl");
5916 Out << (FE->getInit() ?
"fR" :
"fr");
5918 if (FE->getOperator() == BO_PtrMemD)
5926 mangleExpression(FE->getLHS());
5928 mangleExpression(FE->getRHS());
5932 case Expr::CXXThisExprClass:
5937 case Expr::CoawaitExprClass:
5940 Out <<
"v18co_await";
5944 case Expr::DependentCoawaitExprClass:
5947 Out <<
"v18co_await";
5951 case Expr::CoyieldExprClass:
5954 Out <<
"v18co_yield";
5957 case Expr::SYCLUniqueStableNameExprClass: {
5961 Out <<
"u33__builtin_sycl_unique_stable_name";
5962 mangleType(USN->getTypeSourceInfo()->getType());
5967 case Expr::HLSLOutArgExprClass:
5969 "cannot mangle hlsl temporary value; mangling wrong thing?");
5970 case Expr::OpenACCAsteriskSizeExprClass: {
5972 DiagnosticsEngine &Diags = Context.getDiags();
5973 Diags.
Report(diag::err_unsupported_itanium_mangling)
5974 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
5979 if (AsTemplateArg && !IsPrimaryExpr)
6011void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6018 assert(parmDepth < FunctionTypeDepth.getDepth());
6019 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
6020 if (FunctionTypeDepth.isInResultType())
6023 if (nestingDepth == 0) {
6026 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6034 &&
"parameter's type is still an array type?");
6036 if (
const DependentAddressSpaceType *DAST =
6037 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6044 if (parmIndex != 0) {
6045 Out << (parmIndex - 1);
6050void CXXNameMangler::mangleCXXCtorType(
CXXCtorType T,
6051 const CXXRecordDecl *InheritedFrom) {
6078 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6081 mangleName(InheritedFrom);
6084void CXXNameMangler::mangleCXXDtorType(
CXXDtorType T) {
6109 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6142 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6143 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6144 if (!RD || !RD->isGenericLambda())
6160 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6161 return TTP->hasTypeConstraint();
6178 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6179 return NTTP->getType()->isInstantiationDependentType() ||
6180 NTTP->getType()->getContainedDeducedType();
6187 "A DeducedTemplateName shouldn't escape partial ordering");
6198 auto MangleTemplateParamListToString =
6200 unsigned DepthOffset) {
6201 llvm::raw_svector_ostream Stream(Buffer);
6202 CXXNameMangler(
Mangler.Context, Stream,
6203 WithTemplateDepthOffset{DepthOffset})
6204 .mangleTemplateParameterList(Params);
6207 MangleTemplateParamListToString(ParamTemplateHead,
6208 TTP->getTemplateParameters(), 0);
6212 MangleTemplateParamListToString(ArgTemplateHead,
6214 TTP->getTemplateParameters()->
getDepth());
6215 return ParamTemplateHead != ArgTemplateHead;
6225 return {
true,
nullptr};
6230 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6231 "no parameter for argument");
6252 return {
true,
nullptr};
6267 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6268 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6269 return {NeedExactType,
nullptr};
6281void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6283 unsigned NumTemplateArgs) {
6286 TemplateArgManglingInfo Info(*
this, TN);
6287 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6288 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6290 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6294void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6295 const TemplateArgumentList &AL) {
6298 TemplateArgManglingInfo Info(*
this, TN);
6299 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6300 mangleTemplateArg(Info, i, AL[i]);
6302 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6306void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6307 ArrayRef<TemplateArgument> Args) {
6310 TemplateArgManglingInfo Info(*
this, TN);
6311 for (
unsigned i = 0; i != Args.size(); ++i) {
6312 mangleTemplateArg(Info, i, Args[i]);
6314 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6318void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6319 unsigned Index, TemplateArgument A) {
6320 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6323 if (ArgInfo.TemplateParameterToMangle &&
6324 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6331 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6334 mangleTemplateArg(A, ArgInfo.NeedExactType);
6337void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6347 llvm_unreachable(
"Cannot mangle NULL template argument");
6375 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6376 TPO->getValue(),
true,
6381 ASTContext &Ctx = Context.getASTContext();
6389 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6397 ArrayRef<APValue::LValuePathEntry>(),
6410 true, NeedExactType);
6416 mangleTemplateArg(P, NeedExactType);
6422void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6423 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6424 mangleExpression(E, UnknownArity,
true);
6439 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6440 const ValueDecl *D = DRE->getDecl();
6449 mangleExpression(E);
6462 switch (
V.getKind()) {
6470 assert(RD &&
"unexpected type for record value");
6479 if (!FD->isUnnamedBitField() &&
6489 assert(RD &&
"unexpected type for union value");
6492 if (!FD->isUnnamedBitField())
6502 QualType ElemT(T->getArrayElementTypeNoTypeQual(), 0);
6503 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6511 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6518 llvm_unreachable(
"Matrix APValues not yet supported");
6524 return V.getFloat().isPosZero();
6527 return !
V.getFixedPoint().getValue();
6530 return V.getComplexFloatReal().isPosZero() &&
6531 V.getComplexFloatImag().isPosZero();
6534 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6537 return V.isNullPointer();
6540 return !
V.getMemberPointerDecl();
6543 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6550 T = AT->getElementType();
6552 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6595 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6596 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6601void CXXNameMangler::mangleValueInTemplateArg(QualType T,
const APValue &
V,
6603 bool NeedExactType) {
6606 T = getASTContext().getUnqualifiedArrayType(T, Quals);
6609 bool IsPrimaryExpr =
true;
6610 auto NotPrimaryExpr = [&] {
6611 if (TopLevel && IsPrimaryExpr)
6613 IsPrimaryExpr =
false;
6617 switch (
V.getKind()) {
6626 llvm_unreachable(
"unexpected value kind in template argument");
6630 assert(RD &&
"unexpected type for record value");
6633 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6636 (Fields.back()->isUnnamedBitField() ||
6638 V.getStructField(Fields.back()->getFieldIndex())))) {
6642 if (Fields.empty()) {
6643 while (!Bases.empty() &&
6645 V.getStructBase(Bases.size() - 1)))
6646 Bases = Bases.drop_back();
6653 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6654 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6655 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6656 if (Fields[I]->isUnnamedBitField())
6658 mangleValueInTemplateArg(Fields[I]->
getType(),
6659 V.getStructField(Fields[I]->getFieldIndex()),
6668 const FieldDecl *FD =
V.getUnionField();
6686 mangleSourceName(II);
6687 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6701 unsigned N =
V.getArraySize();
6703 N =
V.getArrayInitializedElts();
6708 for (
unsigned I = 0; I != N; ++I) {
6709 const APValue &Elem = I <
V.getArrayInitializedElts()
6710 ?
V.getArrayInitializedElt(I)
6711 :
V.getArrayFiller();
6712 mangleValueInTemplateArg(ElemT, Elem,
false);
6719 const VectorType *VT = T->
castAs<VectorType>();
6724 unsigned N =
V.getVectorLength();
6727 for (
unsigned I = 0; I != N; ++I)
6728 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6734 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6737 mangleIntegerLiteral(T,
V.getInt());
6741 mangleFloatLiteral(T,
V.getFloat());
6745 mangleFixedPointLiteral();
6749 const ComplexType *CT = T->
castAs<ComplexType>();
6753 if (!
V.getComplexFloatReal().isPosZero() ||
6754 !
V.getComplexFloatImag().isPosZero())
6756 if (!
V.getComplexFloatImag().isPosZero())
6763 const ComplexType *CT = T->
castAs<ComplexType>();
6767 if (
V.getComplexIntReal().getBoolValue() ||
6768 V.getComplexIntImag().getBoolValue())
6770 if (
V.getComplexIntImag().getBoolValue())
6779 "unexpected type for LValue template arg");
6781 if (
V.isNullPointer()) {
6782 mangleNullPointer(T);
6786 APValue::LValueBase B =
V.getLValueBase();
6790 CharUnits Offset =
V.getLValueOffset();
6808 ASTContext &Ctx = Context.getASTContext();
6811 if (!
V.hasLValuePath()) {
6827 bool IsArrayToPointerDecayMangledAsDecl =
false;
6828 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6829 LangOptions::ClangABI::Ver11) {
6831 IsArrayToPointerDecayMangledAsDecl =
6832 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6833 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6837 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6838 !IsArrayToPointerDecayMangledAsDecl) {
6855 if (NeedExactType &&
6857 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6870 QualType TypeSoFar = B.
getType();
6871 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6875 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6877 mangleExpression(E);
6878 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6881 mangleType(QualType(TI.getType(), 0));
6884 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6894 mangleNumber(
V.getLValueOffset().getQuantity());
6901 if (!
V.getLValueOffset().isZero())
6902 mangleNumber(
V.getLValueOffset().getQuantity());
6906 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6908 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6910 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6911 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6912 TypeSoFar = AT->getElementType();
6914 const Decl *D = E.getAsBaseOrMember().getPointer();
6915 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6940 if (!
V.getMemberPointerDecl()) {
6941 mangleNullPointer(T);
6945 ASTContext &Ctx = Context.getASTContext();
6948 if (!
V.getMemberPointerPath().empty()) {
6951 }
else if (NeedExactType &&
6953 T->
castAs<MemberPointerType>()->getPointeeType(),
6954 V.getMemberPointerDecl()->getType()) &&
6955 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6960 mangle(
V.getMemberPointerDecl());
6962 if (!
V.getMemberPointerPath().empty()) {
6972 if (TopLevel && !IsPrimaryExpr)
6976void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6986 Depth += TemplateDepthOffset;
6988 Out <<
'L' << (Depth - 1) <<
'_';
6994void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6997 }
else if (SeqID == 1) {
7004 MutableArrayRef<char> BufferRef(Buffer);
7005 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7007 for (; SeqID != 0; SeqID /= 36) {
7008 unsigned C = SeqID % 36;
7009 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7012 Out.write(I.base(), I - BufferRef.rbegin());
7017void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7018 bool result = mangleSubstitution(tname);
7019 assert(result &&
"no existing substitution for template name");
7025bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7027 if (mangleStandardSubstitution(ND))
7031 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7041bool CXXNameMangler::mangleSubstitution(QualType T) {
7044 return mangleSubstitution(RD);
7049 return mangleSubstitution(TypePtr);
7053 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7054 return mangleSubstitution(TD);
7057 return mangleSubstitution(
7061bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7062 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7063 if (I == Substitutions.end())
7066 unsigned SeqID = I->second;
7075bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7084 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7085 if (!SD || !SD->getIdentifier()->isStr(Name))
7088 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7091 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7092 if (TemplateArgs.
size() != 1)
7095 if (TemplateArgs[0].getAsType() != A)
7098 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7107bool CXXNameMangler::isStdCharSpecialization(
7108 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7109 bool HasAllocator) {
7114 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7117 QualType A = TemplateArgs[0].getAsType();
7125 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7129 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7138bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7140 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7148 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7149 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7169 if (
const ClassTemplateSpecializationDecl *SD =
7170 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7171 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7180 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7187 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7194 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7201 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7211void CXXNameMangler::addSubstitution(QualType T) {
7214 addSubstitution(RD);
7220 addSubstitution(TypePtr);
7224 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7225 return addSubstitution(TD);
7231void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7232 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7233 Substitutions[Ptr] = SeqID++;
7236void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7237 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7238 if (
Other->SeqID > SeqID) {
7239 Substitutions.swap(
Other->Substitutions);
7240 SeqID =
Other->SeqID;
7244CXXNameMangler::AbiTagList
7245CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7247 if (DisableDerivedAbiTags)
7248 return AbiTagList();
7250 llvm::raw_null_ostream NullOutStream;
7251 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7252 TrackReturnTypeTags.disableDerivedAbiTags();
7254 const FunctionProtoType *Proto =
7256 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7257 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
7259 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
7260 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7262 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7265CXXNameMangler::AbiTagList
7266CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7268 if (DisableDerivedAbiTags)
7269 return AbiTagList();
7271 llvm::raw_null_ostream NullOutStream;
7272 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7273 TrackVariableType.disableDerivedAbiTags();
7275 TrackVariableType.mangleType(VD->
getType());
7277 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7280bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7281 const VarDecl *VD) {
7282 llvm::raw_null_ostream NullOutStream;
7283 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7284 TrackAbiTags.mangle(VD);
7285 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7290void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7294 "Invalid mangleName() call, argument is not a variable or function!");
7296 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7297 getASTContext().getSourceManager(),
7298 "Mangling declaration");
7300 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7302 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7303 return Mangler.mangle(GlobalDecl(CD,
Type));
7306 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7308 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7309 return Mangler.mangle(GlobalDecl(DD,
Type));
7312 CXXNameMangler Mangler(*
this, Out, D);
7316void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7318 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7322void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7324 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7346 auto &LangOpts = Context.getLangOpts();
7349 Context.baseForVTableAuthentication(ThisRD);
7350 unsigned TypedDiscriminator =
7351 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7352 Mangler.mangleVendorQualifier(
"__vtptrauth");
7353 auto &ManglerStream = Mangler.getStream();
7354 ManglerStream <<
"I";
7355 if (
const auto *ExplicitAuth =
7356 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7357 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7359 if (ExplicitAuth->getAddressDiscrimination() ==
7360 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7361 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7363 ManglerStream <<
"Lb"
7364 << (ExplicitAuth->getAddressDiscrimination() ==
7365 VTablePointerAuthenticationAttr::AddressDiscrimination);
7367 switch (ExplicitAuth->getExtraDiscrimination()) {
7368 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7369 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7370 ManglerStream <<
"Lj" << TypedDiscriminator;
7372 ManglerStream <<
"Lj" << 0;
7375 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7376 ManglerStream <<
"Lj" << TypedDiscriminator;
7378 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7379 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7381 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7382 ManglerStream <<
"Lj" << 0;
7386 ManglerStream <<
"Lj"
7387 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7388 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7389 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7390 ManglerStream <<
"Lj" << TypedDiscriminator;
7392 ManglerStream <<
"Lj" << 0;
7394 ManglerStream <<
"E";
7397void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7398 const ThunkInfo &Thunk,
7399 bool ElideOverrideInfo,
7409 "Use mangleCXXDtor for destructor decls!");
7410 CXXNameMangler Mangler(*
this, Out);
7411 Mangler.getStream() <<
"_ZT";
7413 Mangler.getStream() <<
'c';
7424 Mangler.mangleFunctionEncoding(MD);
7425 if (!ElideOverrideInfo)
7429void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7431 const ThunkInfo &Thunk,
7432 bool ElideOverrideInfo,
7436 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7437 Mangler.getStream() <<
"_ZT";
7439 auto &ThisAdjustment = Thunk.
This;
7441 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7442 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7444 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7445 if (!ElideOverrideInfo)
7450void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7454 CXXNameMangler Mangler(*
this, Out);
7457 Mangler.getStream() <<
"_ZGV";
7458 Mangler.mangleName(D);
7461void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7466 Out <<
"__cxx_global_var_init";
7469void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7472 CXXNameMangler Mangler(*
this, Out);
7473 Mangler.getStream() <<
"__dtor_";
7474 if (shouldMangleDeclName(D))
7477 Mangler.getStream() << D->
getName();
7480void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7484 CXXNameMangler Mangler(*
this, Out);
7485 Mangler.getStream() <<
"__finalize_";
7486 if (shouldMangleDeclName(D))
7489 Mangler.getStream() << D->
getName();
7492void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7493 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7494 CXXNameMangler Mangler(*
this, Out);
7495 Mangler.getStream() <<
"__filt_";
7497 if (shouldMangleDeclName(EnclosingFD))
7498 Mangler.mangle(EnclosingDecl);
7500 Mangler.getStream() << EnclosingFD->getName();
7503void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7504 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7505 CXXNameMangler Mangler(*
this, Out);
7506 Mangler.getStream() <<
"__fin_";
7508 if (shouldMangleDeclName(EnclosingFD))
7509 Mangler.mangle(EnclosingDecl);
7511 Mangler.getStream() << EnclosingFD->getName();
7514void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7517 CXXNameMangler Mangler(*
this, Out);
7518 Mangler.getStream() <<
"_ZTH";
7519 Mangler.mangleName(D);
7523ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7526 CXXNameMangler Mangler(*
this, Out);
7527 Mangler.getStream() <<
"_ZTW";
7528 Mangler.mangleName(D);
7531void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7532 unsigned ManglingNumber,
7536 CXXNameMangler Mangler(*
this, Out);
7537 Mangler.getStream() <<
"_ZGR";
7538 Mangler.mangleName(D);
7539 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7540 Mangler.mangleSeqID(ManglingNumber - 1);
7543void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7546 CXXNameMangler Mangler(*
this, Out);
7547 Mangler.getStream() <<
"_ZTV";
7548 Mangler.mangleCXXRecordDecl(RD);
7551void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7554 CXXNameMangler Mangler(*
this, Out);
7555 Mangler.getStream() <<
"_ZTT";
7556 Mangler.mangleCXXRecordDecl(RD);
7559void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7561 const CXXRecordDecl *
Type,
7564 CXXNameMangler Mangler(*
this, Out);
7565 Mangler.getStream() <<
"_ZTC";
7568 bool SuppressSubstitution =
7569 getASTContext().getLangOpts().getClangABICompat() <=
7570 LangOptions::ClangABI::Ver19;
7571 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7572 Mangler.getStream() << Offset;
7573 Mangler.getStream() <<
'_';
7574 Mangler.mangleCXXRecordDecl(
Type);
7577void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7579 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7580 CXXNameMangler Mangler(*
this, Out);
7581 Mangler.getStream() <<
"_ZTI";
7582 Mangler.mangleType(Ty);
7585void ItaniumMangleContextImpl::mangleCXXRTTIName(
7586 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7588 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7589 Mangler.getStream() <<
"_ZTS";
7590 Mangler.mangleType(Ty);
7593void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7594 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7595 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7598void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7599 llvm_unreachable(
"Can't mangle string literals");
7602void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7604 CXXNameMangler Mangler(*
this, Out);
7605 Mangler.mangleLambdaSig(Lambda);
7608void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7611 CXXNameMangler Mangler(*
this, Out);
7612 Mangler.getStream() <<
"_ZGI";
7616 auto Partition = M->
Name.find(
':');
7617 Mangler.mangleModuleNamePrefix(
7618 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7626 return new ItaniumMangleContextImpl(
7629 return std::nullopt;
7638 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 const CXXRecordDecl * getLambdaForInitCapture(const VarDecl *VD)
Retrieve the lambda associated with an init-capture variable.
static void mangleOverrideDiscrimination(CXXNameMangler &Mangler, ASTContext &Context, const ThunkInfo &Thunk)
Mangles the pointer authentication override attribute for classes that have explicit overrides for th...
static bool isZeroInitialized(QualType T, const APValue &V)
Determine whether a given value is equivalent to zero-initialization for the purpose of discarding a ...
static const GlobalDecl isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs)
static bool isParenthesizedADLCallee(const CallExpr *call)
Look at the callee of the given call expression and determine if it's a parenthesized id-expression w...
static TemplateName asTemplateName(GlobalDecl GD)
static QualType getLValueType(ASTContext &Ctx, const APValue &LV)
llvm::MachO::Target Target
llvm::MachO::Record Record
Defines the clang::Module class, which describes a module in the source code.
static StringRef getTriple(const Command &Job)
static StringRef getIdentifier(const Token &Tok)
Enums/classes describing THUNK related information about constructors, destructors and thunks.
Defines the clang::TypeLoc interface and its subclasses.
static const TemplateArgument & getArgument(const TemplateArgument &A)
A non-discriminated union of a base, field, or array index.
static LValuePathEntry ArrayIndex(uint64_t Index)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
ArrayRef< LValuePathEntry > getLValuePath() const
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
@ None
There is no such object (it's outside its lifetime).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
TemplateName getCanonicalTemplateName(TemplateName Name, bool IgnoreDeduced=false) const
Retrieves the "canonical" template name that refers to a given template.
const LangOptions & getLangOpts() const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
QualType getSignatureParameterType(QualType T) const
Retrieve the parameter type as adjusted for use in the signature of a function, decaying array and fu...
bool addressSpaceMapManglingFor(LangAS AS) const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
unsigned getNumBits() const
QualType getPointeeType() const
This class is used for builtin types like 'int'.
bool isSignedInteger() const
Represents a base class of a C++ class.
ConstExprIterator const_arg_iterator
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
bool isGlobalDelete() const
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the member name.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e.
ConstExprIterator const_arg_iterator
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
base_class_iterator bases_end()
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
base_class_iterator bases_begin()
TypeSourceInfo * getLambdaTypeInfo() const
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
const Expr * getSubExpr() const
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isListInitialization() const
Determine whether this expression models list-initialization.
Expr * getArg(unsigned I)
unsigned getNumArgs() const
Retrieve the number of arguments.
Expr * getExprOperand() const
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
bool isTypeOperand() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
QualType getElementType() const
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
llvm::APInt getSize() const
Return the constant array size as an APInt.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
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 ...
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
Expr * getNumBitsExpr() 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
Expr * getSizeExpr() const
Expr * getSizeExpr() const
QualType getElementType() const
Expr * getColumnExpr() const
Expr * getRowExpr() const
IdentifierOrOverloadedOperator getName() const
Represents a vector type where either the type or size is dependent.
Expr * getSizeExpr() const
VectorKind getVectorKind() const
SourceLocation getAttributeLoc() const
QualType getElementType() const
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
llvm::APSInt getInitVal() const
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APFloat getValue() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
ArrayRef< QualType > exceptions() const
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
CallingConv getCC() const
bool getProducesResult() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC?
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
QualType getReturnType() const
GlobalDecl - represents a global declaration.
CXXCtorType getCtorType() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
CXXDtorType getDtorType() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
const Expr * getSubExpr() const
Describes an C or C++ initializer list.
unsigned getNumInits() const
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
ItaniumMangleContext(ASTContext &C, DiagnosticsEngine &D, bool IsAux=false)
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
UnsignedOrNone(*)(ASTContext &, const NamedDecl *) DiscriminatorOverrideTy
QualType getElementType() const
Returns type of the elements being stored in the matrix.
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.
NestedNameSpecifier getQualifier() const
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
std::string Name
The name of this module.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const Type * getAsType() const
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.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
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
QualType getPointeeType() 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.
QualType getCanonicalType() const
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
void * getAsOpaquePtr() const
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
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.
QualType getPointeeType() const
Encodes a location in the source.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
TemplateName getReplacement() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
virtual const char * getFloat128Mangling() const
Return the mangled code of __float128.
virtual const char * getIbm128Mangling() const
Return the mangled code of __ibm128.
virtual const char * getLongDoubleMangling() const
Return the mangled code of long double.
virtual const char * getBFloat16Mangling() const
Return the mangled code of bfloat.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
std::pair< TemplateName, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template name that this template name refers to, along with the deduced defa...
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateDecl * getNamedConcept() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
TypeTrait getTrait() const
Determine which type trait this expression uses.
The base class of the type hierarchy.
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
UnresolvedUsingTypenameDecl * getDecl() const
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable template specialization, which refers to a variable template with a given set o...
Expr * getSizeExpr() const
Represents a GCC generic vector type.
unsigned getNumElements() const
VectorKind getVectorKind() const
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
@ Number
Just a number, nothing else.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
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.
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName, bool useDirectABI)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
OptionalUnsigned< unsigned > UnsignedOrNone
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ Type
The name was classified as a type.
@ Concept
The name was classified as a concept name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ Deduced
The normal deduced case.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ 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.