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 typedef std::pair<const DeclContext*, IdentifierInfo*> DiscriminatorKeyTy;
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 TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
147 if (
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
153 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
154 if (discriminator == 1)
156 disc = discriminator - 2;
161 unsigned &discriminator = Uniquifier[ND];
162 if (!discriminator) {
163 const DeclContext *DC = getEffectiveDeclContext(ND);
164 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
166 if (discriminator == 1)
168 disc = discriminator-2;
172 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
175 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
176 std::string Name(
"<lambda");
180 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
181 const FunctionDecl *
Func =
185 unsigned DefaultArgNo =
187 Name += llvm::utostr(DefaultArgNo);
191 if (LambdaManglingNumber)
192 LambdaId = LambdaManglingNumber;
194 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
196 Name += llvm::utostr(LambdaId);
201 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
202 return DiscriminatorOverride;
205 NamespaceDecl *getStdNamespace();
207 const DeclContext *getEffectiveDeclContext(
const Decl *D);
208 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
209 return getEffectiveDeclContext(
cast<Decl>(DC));
212 bool isInternalLinkageDecl(
const NamedDecl *ND);
218class CXXNameMangler {
219 ItaniumMangleContextImpl &Context;
223 bool NormalizeIntegers =
false;
225 bool NullOut =
false;
230 bool DisableDerivedAbiTags =
false;
235 const NamedDecl *Structor;
236 unsigned StructorType = 0;
241 unsigned TemplateDepthOffset = 0;
246 class FunctionTypeDepthState {
249 enum { InResultTypeMask = 1 };
252 FunctionTypeDepthState() =
default;
255 unsigned getDepth()
const {
260 bool isInResultType()
const {
261 return Bits & InResultTypeMask;
264 FunctionTypeDepthState push() {
265 FunctionTypeDepthState tmp = *
this;
266 Bits = (Bits & ~InResultTypeMask) + 2;
270 void enterResultType() {
271 Bits |= InResultTypeMask;
274 void leaveResultType() {
275 Bits &= ~InResultTypeMask;
278 void pop(FunctionTypeDepthState saved) {
279 assert(getDepth() == saved.getDepth() + 1);
289 typedef SmallVector<StringRef, 4> AbiTagList;
294 class AbiTagState final {
296 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
302 AbiTagState(
const AbiTagState &) =
delete;
303 AbiTagState &operator=(
const AbiTagState &) =
delete;
305 ~AbiTagState() { pop(); }
307 void write(raw_ostream &Out,
const NamedDecl *ND,
308 const AbiTagList *AdditionalAbiTags) {
312 !AdditionalAbiTags &&
313 "only function and variables need a list of additional abi tags");
314 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
315 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
316 llvm::append_range(UsedAbiTags, AbiTag->tags());
323 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
324 llvm::append_range(UsedAbiTags, AbiTag->tags());
325 llvm::append_range(TagList, AbiTag->tags());
328 if (AdditionalAbiTags) {
329 llvm::append_range(UsedAbiTags, *AdditionalAbiTags);
330 llvm::append_range(TagList, *AdditionalAbiTags);
334 TagList.erase(llvm::unique(TagList), TagList.end());
336 writeSortedUniqueAbiTags(Out, TagList);
339 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
340 void setUsedAbiTags(
const AbiTagList &AbiTags) {
341 UsedAbiTags = AbiTags;
344 const AbiTagList &getEmittedAbiTags()
const {
345 return EmittedAbiTags;
348 const AbiTagList &getSortedUniqueUsedAbiTags() {
349 llvm::sort(UsedAbiTags);
350 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
356 AbiTagList UsedAbiTags;
358 AbiTagList EmittedAbiTags;
360 AbiTagState *&LinkHead;
361 AbiTagState *Parent =
nullptr;
364 assert(LinkHead ==
this &&
365 "abi tag link head must point to us on destruction");
367 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
368 UsedAbiTags.begin(), UsedAbiTags.end());
369 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
370 EmittedAbiTags.begin(),
371 EmittedAbiTags.end());
376 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
377 for (
const auto &Tag : AbiTags) {
378 EmittedAbiTags.push_back(Tag);
386 AbiTagState *AbiTags =
nullptr;
387 AbiTagState AbiTagsRoot;
389 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
390 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
392 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
394 bool isCompatibleWith(LangOptions::ClangABI Ver) {
395 return Context.getASTContext().
getLangOpts().getClangABICompat() <= Ver;
398 bool isStd(
const NamespaceDecl *NS);
399 bool isStdNamespace(
const DeclContext *DC);
401 const RecordDecl *GetLocalClassDecl(
const Decl *D);
402 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
403 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
404 llvm::StringRef Name,
bool HasAllocator);
407 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
408 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
409 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
410 AbiTagsRoot(AbiTags) {
415 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
417 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
418 AbiTagsRoot(AbiTags) {}
419 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
421 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
422 AbiTagsRoot(AbiTags) {}
424 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
425 bool NormalizeIntegers_)
426 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
427 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
428 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
429 : Context(Outer.Context),
Out(Out_),
430 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
431 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
432 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
433 Substitutions(Outer.Substitutions),
434 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
436 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
437 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
441 struct WithTemplateDepthOffset {
unsigned Offset; };
442 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
443 WithTemplateDepthOffset Offset)
444 : CXXNameMangler(
C,
Out) {
445 TemplateDepthOffset = Offset.Offset;
448 raw_ostream &getStream() {
return Out; }
450 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
451 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
453 void mangle(GlobalDecl GD);
454 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
455 void mangleNumber(
const llvm::APSInt &I);
456 void mangleNumber(int64_t Number);
457 void mangleFloat(
const llvm::APFloat &F);
458 void mangleFunctionEncoding(GlobalDecl GD);
459 void mangleSeqID(
unsigned SeqID);
460 void mangleName(GlobalDecl GD);
461 void mangleType(QualType T);
462 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
463 bool SuppressSubstitution =
false);
464 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
465 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
466 void mangleVendorQualifier(StringRef Name);
467 void mangleVendorType(StringRef Name);
470 bool mangleSubstitution(
const NamedDecl *ND);
471 bool mangleSubstitution(QualType T);
477 bool mangleStandardSubstitution(
const NamedDecl *ND);
479 void addSubstitution(
const NamedDecl *ND) {
482 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
484 void addSubstitution(QualType T);
488 void extendSubstitutions(CXXNameMangler*
Other);
490 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
491 bool recursive =
false);
492 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
493 const TemplateArgumentLoc *TemplateArgs,
494 unsigned NumTemplateArgs,
495 unsigned KnownArity = UnknownArity);
497 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
499 void mangleNameWithAbiTags(GlobalDecl GD,
500 const AbiTagList *AdditionalAbiTags);
501 void mangleModuleName(
const NamedDecl *ND);
502 void mangleTemplateName(
const TemplateDecl *TD,
503 ArrayRef<TemplateArgument> Args);
504 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
505 const AbiTagList *AdditionalAbiTags) {
507 UnknownArity, AdditionalAbiTags);
509 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
510 const DeclContext *DC,
unsigned KnownArity,
511 const AbiTagList *AdditionalAbiTags);
512 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
513 const AbiTagList *AdditionalAbiTags);
514 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
515 const AbiTagList *AdditionalAbiTags);
516 void mangleSourceName(
const IdentifierInfo *II);
517 void mangleRegCallName(
const IdentifierInfo *II);
518 void mangleDeviceStubName(
const IdentifierInfo *II);
519 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
520 void mangleSourceNameWithAbiTags(
521 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags =
nullptr);
522 void mangleLocalName(GlobalDecl GD,
523 const AbiTagList *AdditionalAbiTags);
524 void mangleBlockForPrefix(
const BlockDecl *
Block);
525 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
526 void mangleTemplateParamDecl(
const NamedDecl *Decl);
527 void mangleTemplateParameterList(
const TemplateParameterList *Params);
528 void mangleTypeConstraint(
const TemplateDecl *
Concept,
529 ArrayRef<TemplateArgument> Arguments);
530 void mangleTypeConstraint(
const TypeConstraint *Constraint);
531 void mangleRequiresClause(
const Expr *RequiresClause);
532 void mangleLambda(
const CXXRecordDecl *Lambda);
533 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
534 const AbiTagList *AdditionalAbiTags,
535 bool NoFunction=
false);
536 void mangleNestedName(
const TemplateDecl *TD,
537 ArrayRef<TemplateArgument> Args);
538 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
539 const NamedDecl *PrefixND,
540 const AbiTagList *AdditionalAbiTags);
541 void manglePrefix(NestedNameSpecifier Qualifier);
542 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
543 void manglePrefix(QualType
type);
544 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
546 const NamedDecl *getClosurePrefix(
const Decl *ND);
547 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
548 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
549 StringRef Prefix =
"");
550 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
552 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
558#define ABSTRACT_TYPE(CLASS, PARENT)
559#define NON_CANONICAL_TYPE(CLASS, PARENT)
560#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
561#include "clang/AST/TypeNodes.inc"
563 void mangleType(
const TagType*);
565 static StringRef getCallingConvQualifierName(
CallingConv CC);
568 void mangleSMEAttrs(
unsigned SMEAttrs);
571 void mangleNeonVectorType(
const VectorType *T);
573 void mangleAArch64NeonVectorType(
const VectorType *T);
575 void mangleAArch64FixedSveVectorType(
const VectorType *T);
577 void mangleRISCVFixedRVVVectorType(
const VectorType *T);
580 void mangleIntegerLiteral(
QualType T,
const llvm::APSInt &
Value);
581 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
582 void mangleFixedPointLiteral();
585 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
586 void mangleMemberExpr(
const Expr *base,
bool isArrow,
590 unsigned NumTemplateArgs,
unsigned knownArity);
591 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
592 void mangleInitListElements(
const InitListExpr *InitList);
595 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
596 bool AsTemplateArg =
false);
600 struct TemplateArgManglingInfo;
603 unsigned NumTemplateArgs);
606 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
609 void mangleTemplateArgExpr(
const Expr *E);
611 bool NeedExactType =
false);
613 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
618 const AbiTagList *AdditionalAbiTags);
621 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
623 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
631 getASTContext(), getASTContext().getTranslationUnitDecl(),
632 false, SourceLocation(), SourceLocation(),
633 &getASTContext().Idents.get(
"std"),
646 const auto *Lambda = dyn_cast<CXXRecordDecl>(Method->getParent());
656ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
663 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
665 if (ParmVarDecl *ContextParam =
666 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
667 return ContextParam->getDeclContext();
671 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
672 if (ParmVarDecl *ContextParam =
673 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
674 return ContextParam->getDeclContext();
682 if (D == getASTContext().getVaListTagDecl()) {
683 const llvm::Triple &T = getASTContext().getTargetInfo().getTriple();
684 if (T.isARM() || T.isThumb() || T.isAArch64())
685 return getStdNamespace();
691 return getEffectiveDeclContext(
cast<Decl>(DC));
694 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
696 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
700 if (isLocalContainerContext(ParentDC))
704 return getASTContext().getTranslationUnitDecl();
707 if (
const auto *FD = getASTContext().getLangOpts().getClangABICompat() >
708 LangOptions::ClangABI::Ver19
710 : dyn_cast<FunctionDecl>(D)) {
712 return getASTContext().getTranslationUnitDecl();
715 if (FD->isMemberLikeConstrainedFriend() &&
716 getASTContext().getLangOpts().getClangABICompat() >
717 LangOptions::ClangABI::Ver17)
724bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
727 getEffectiveDeclContext(ND)->isFileContext() &&
734bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
735 const NamedDecl *ND) {
736 if (!NeedsUniqueInternalLinkageNames || !ND)
739 const auto *FD = dyn_cast<FunctionDecl>(ND);
745 if (!FD->getType()->getAs<FunctionProtoType>())
748 if (isInternalLinkageDecl(ND))
754bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
755 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
758 if (FD->hasAttr<OverloadableAttr>())
774 if (FD->isMSVCRTEntryPoint())
788 if (!getASTContext().getLangOpts().
CPlusPlus)
791 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
802 const DeclContext *DC = getEffectiveDeclContext(D);
806 DC = getEffectiveParentContext(DC);
808 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
810 !VD->getOwningModuleForLinkage())
817void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
818 const AbiTagList *AdditionalAbiTags) {
819 assert(AbiTags &&
"require AbiTagState");
820 AbiTags->write(Out, ND, DisableDerivedAbiTags ?
nullptr : AdditionalAbiTags);
823void CXXNameMangler::mangleSourceNameWithAbiTags(
824 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags) {
826 writeAbiTags(ND, AdditionalAbiTags);
829void CXXNameMangler::mangle(GlobalDecl GD) {
835 mangleFunctionEncoding(GD);
836 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
839 else if (
const IndirectFieldDecl *IFD =
840 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
841 mangleName(IFD->getAnonField());
843 llvm_unreachable(
"unexpected kind of global decl");
846void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
851 if (!Context.shouldMangleDeclName(FD)) {
856 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
857 if (ReturnTypeAbiTags.empty()) {
866 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
868 FunctionTypeDepth.pop(Saved);
869 mangleFunctionEncodingBareType(FD);
876 SmallString<256> FunctionEncodingBuf;
877 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
878 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
880 FunctionEncodingMangler.disableDerivedAbiTags();
882 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
883 FunctionEncodingMangler.mangleNameWithAbiTags(FD,
nullptr);
884 FunctionTypeDepth.pop(Saved);
887 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
888 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
892 const AbiTagList &UsedAbiTags =
893 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
894 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
895 AdditionalAbiTags.erase(
896 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
897 UsedAbiTags.begin(), UsedAbiTags.end(),
898 AdditionalAbiTags.begin()),
899 AdditionalAbiTags.end());
902 Saved = FunctionTypeDepth.push();
903 mangleNameWithAbiTags(FD, &AdditionalAbiTags);
904 FunctionTypeDepth.pop(Saved);
905 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
909 extendSubstitutions(&FunctionEncodingMangler);
912void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
913 if (FD->
hasAttr<EnableIfAttr>()) {
914 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
915 Out <<
"Ua9enable_ifI";
916 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
919 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
922 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
927 mangleExpression(EIA->getCond());
930 mangleTemplateArgExpr(EIA->getCond());
934 FunctionTypeDepth.pop(Saved);
939 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
940 if (
auto Inherited = CD->getInheritedConstructor())
941 FD = Inherited.getConstructor();
959 bool MangleReturnType =
false;
963 MangleReturnType =
true;
966 FD = PrimaryTemplate->getTemplatedDecl();
969 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
970 MangleReturnType, FD);
974bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
975 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
979 return II && II->
isStr(
"std");
984bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
991static const GlobalDecl
995 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1004 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1005 TemplateArgs = &Spec->getTemplateArgs();
1006 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1011 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1012 TemplateArgs = &Spec->getTemplateArgs();
1013 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1024void CXXNameMangler::mangleName(GlobalDecl GD) {
1026 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1028 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1029 if (VariableTypeAbiTags.empty()) {
1031 mangleNameWithAbiTags(VD,
nullptr);
1036 llvm::raw_null_ostream NullOutStream;
1037 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1038 VariableNameMangler.disableDerivedAbiTags();
1039 VariableNameMangler.mangleNameWithAbiTags(VD,
nullptr);
1042 const AbiTagList &UsedAbiTags =
1043 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1044 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1045 AdditionalAbiTags.erase(
1046 std::set_difference(VariableTypeAbiTags.begin(),
1047 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1048 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1049 AdditionalAbiTags.end());
1052 mangleNameWithAbiTags(VD, &AdditionalAbiTags);
1054 mangleNameWithAbiTags(GD,
nullptr);
1058const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1059 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1061 if (isLocalContainerContext(DC))
1062 return dyn_cast<RecordDecl>(D);
1064 DC = Context.getEffectiveDeclContext(D);
1069void CXXNameMangler::mangleNameWithAbiTags(GlobalDecl GD,
1070 const AbiTagList *AdditionalAbiTags) {
1077 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1078 bool IsLambda = isLambda(ND);
1084 if (isLocalContainerContext(DC) && ND->
hasLinkage() && !IsLambda)
1086 DC = Context.getEffectiveParentContext(DC);
1087 else if (GetLocalClassDecl(ND) &&
1088 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1089 mangleLocalName(GD, AdditionalAbiTags);
1097 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1098 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1102 if (isLocalContainerContext(DC)) {
1103 mangleLocalName(GD, AdditionalAbiTags);
1112 const TemplateArgumentList *TemplateArgs =
nullptr;
1113 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1114 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1119 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1123 mangleNestedName(GD, DC, AdditionalAbiTags);
1126void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1129 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1137void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1139 auto It = ModuleSubstitutions.find(Name);
1140 if (It != ModuleSubstitutions.end()) {
1142 mangleSeqID(It->second);
1148 auto Parts = Name.rsplit(
'.');
1149 if (Parts.second.empty())
1150 Parts.second = Parts.first;
1152 mangleModuleNamePrefix(Parts.first, IsPartition);
1153 IsPartition =
false;
1159 Out << Parts.second.size() << Parts.second;
1160 ModuleSubstitutions.insert({Name, SeqID++});
1163void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1164 ArrayRef<TemplateArgument> Args) {
1165 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1168 mangleUnscopedTemplateName(TD, DC,
nullptr);
1171 mangleNestedName(TD, Args);
1175void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1176 const AbiTagList *AdditionalAbiTags) {
1181 if (isStdNamespace(DC)) {
1182 if (getASTContext().getTargetInfo().getTriple().isOSSolaris()) {
1184 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1189 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1191 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1201 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1204void CXXNameMangler::mangleUnscopedTemplateName(
1205 GlobalDecl GD,
const DeclContext *DC,
const AbiTagList *AdditionalAbiTags) {
1209 if (mangleSubstitution(ND))
1213 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1214 assert(!AdditionalAbiTags &&
1215 "template template param cannot have abi tags");
1216 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1218 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1224 addSubstitution(ND);
1227void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1241 llvm::APInt valueBits = f.bitcastToAPInt();
1242 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1243 assert(numCharacters != 0);
1246 SmallVector<char, 20> buffer(numCharacters);
1249 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1251 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1254 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1255 hexDigit >>= (digitBitIndex % 64);
1259 static const char charForHex[16] = {
1260 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1261 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1263 buffer[stringIndex] = charForHex[hexDigit];
1266 Out.write(buffer.data(), numCharacters);
1269void CXXNameMangler::mangleFloatLiteral(QualType T,
const llvm::APFloat &
V) {
1276void CXXNameMangler::mangleFixedPointLiteral() {
1277 DiagnosticsEngine &Diags = Context.getDiags();
1278 Diags.
Report(diag::err_unsupported_itanium_mangling)
1279 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1282void CXXNameMangler::mangleNullPointer(QualType T) {
1289void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1290 if (
Value.isSigned() &&
Value.isNegative()) {
1292 Value.abs().print(Out,
false);
1294 Value.print(Out,
false);
1298void CXXNameMangler::mangleNumber(int64_t Number) {
1308void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1316 mangleNumber(NonVirtual);
1322 mangleNumber(NonVirtual);
1328void CXXNameMangler::manglePrefix(QualType
type) {
1329 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1330 if (!mangleSubstitution(QualType(TST, 0))) {
1331 mangleTemplatePrefix(TST->getTemplateName());
1336 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1337 addSubstitution(QualType(TST, 0));
1339 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1341 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1342 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1347 assert(DNT->getQualifier());
1348 manglePrefix(DNT->getQualifier());
1350 mangleSourceName(DNT->getIdentifier());
1353 addSubstitution(QualType(DNT, 0));
1365void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1383 case NestedNameSpecifier::Kind::Null:
1384 llvm_unreachable(
"unexpected null nested name specifier");
1386 case NestedNameSpecifier::Kind::Global:
1396 case NestedNameSpecifier::Kind::MicrosoftSuper:
1397 llvm_unreachable(
"Can't mangle __super specifier");
1399 case NestedNameSpecifier::Kind::Namespace: {
1402 mangleUnresolvedPrefix(Prefix,
1406 mangleSourceNameWithAbiTags(Namespace);
1410 case NestedNameSpecifier::Kind::Type: {
1418 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1419 mangleUnresolvedPrefix(Prefix,
1426 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1441void CXXNameMangler::mangleUnresolvedName(
1442 NestedNameSpecifier Qualifier, DeclarationName name,
1443 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1444 unsigned knownArity) {
1446 mangleUnresolvedPrefix(Qualifier);
1447 switch (
name.getNameKind()) {
1450 mangleSourceName(
name.getAsIdentifierInfo());
1455 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1462 mangleOperatorName(name, knownArity);
1465 llvm_unreachable(
"Can't mangle a constructor name!");
1467 llvm_unreachable(
"Can't mangle a using directive name!");
1469 llvm_unreachable(
"Can't mangle a deduction guide name!");
1473 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1479 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1482void CXXNameMangler::mangleUnqualifiedName(
1483 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1484 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1485 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1492 mangleModuleName(ND);
1496 auto *FD = dyn_cast<FunctionDecl>(ND);
1497 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1499 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1500 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1504 unsigned Arity = KnownArity;
1510 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1517 for (
auto *BD : DD->bindings())
1518 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1520 writeAbiTags(ND, AdditionalAbiTags);
1524 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1527 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1528 llvm::raw_svector_ostream GUIDOS(GUID);
1529 Context.mangleMSGuidDecl(GD, GUIDOS);
1530 Out << GUID.size() << GUID;
1534 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1537 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1538 TPO->getValue(),
true);
1556 if (Context.isInternalLinkageDecl(ND))
1559 bool IsRegCall = FD &&
1563 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1565 bool IsOCLDeviceStub =
1567 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1570 mangleDeviceStubName(II);
1571 else if (IsOCLDeviceStub)
1572 mangleOCLDeviceStubName(II);
1574 mangleRegCallName(II);
1576 mangleSourceName(II);
1578 writeAbiTags(ND, AdditionalAbiTags);
1583 assert(ND &&
"mangling empty name without declaration");
1585 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1588 Out <<
"12_GLOBAL__N_1";
1593 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1595 const auto *RD = VD->getType()->castAsRecordDecl();
1606 assert(RD->isAnonymousStructOrUnion()
1607 &&
"Expected anonymous struct or union!");
1608 const FieldDecl *FD = RD->findFirstNamedDataMember();
1614 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1634 "Typedef should not be in another decl context!");
1635 assert(D->getDeclName().getAsIdentifierInfo() &&
1636 "Typedef was not named!");
1637 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1638 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1641 writeAbiTags(TD,
nullptr);
1650 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1651 UnsignedOrNone DeviceNumber =
1652 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1658 if (
Record->isLambda() &&
1659 ((DeviceNumber && *DeviceNumber > 0) ||
1660 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1661 assert(!AdditionalAbiTags &&
1662 "Lambda type cannot have additional abi tags");
1669 unsigned UnnamedMangle =
1670 getASTContext().getManglingNumber(TD, Context.isAux());
1672 if (UnnamedMangle > 1)
1673 Out << UnnamedMangle - 2;
1675 writeAbiTags(TD, AdditionalAbiTags);
1681 unsigned AnonStructId =
1683 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1690 Str += llvm::utostr(AnonStructId);
1700 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1703 const CXXRecordDecl *InheritedFrom =
nullptr;
1705 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1706 if (
auto Inherited =
1708 InheritedFrom = Inherited.getConstructor()->
getParent();
1709 InheritedTemplateName =
1710 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1711 InheritedTemplateArgs =
1712 Inherited.getConstructor()->getTemplateSpecializationArgs();
1718 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1726 if (InheritedTemplateArgs)
1727 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1729 writeAbiTags(ND, AdditionalAbiTags);
1737 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1743 writeAbiTags(ND, AdditionalAbiTags);
1747 if (ND && Arity == UnknownArity) {
1751 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1752 if (MD->isImplicitObjectMemberFunction())
1758 mangleOperatorName(Name, Arity);
1759 writeAbiTags(ND, AdditionalAbiTags);
1763 llvm_unreachable(
"Can't mangle a deduction guide name!");
1766 llvm_unreachable(
"Can't mangle a using directive name!");
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 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2011 Context->getDeclContext()->isRecord()) {
2014 mangleSourceNameWithAbiTags(ND);
2021 unsigned Number =
Block->getBlockManglingNumber();
2025 Number = Context.getBlockId(
Block,
false);
2043void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2045 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2046 if (Ty->isParameterPack())
2048 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2049 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2052 mangleTypeConstraint(Constraint);
2056 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2057 if (Tn->isExpandedParameterPack()) {
2058 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2060 mangleType(Tn->getExpansionType(I));
2063 QualType T = Tn->getType();
2064 if (Tn->isParameterPack()) {
2066 if (
auto *PackExpansion = T->
getAs<PackExpansionType>())
2067 T = PackExpansion->getPattern();
2072 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2073 if (Tt->isExpandedParameterPack()) {
2074 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2076 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2078 if (Tt->isParameterPack())
2080 mangleTemplateParameterList(Tt->getTemplateParameters());
2085void CXXNameMangler::mangleTemplateParameterList(
2086 const TemplateParameterList *Params) {
2088 for (
auto *Param : *Params)
2089 mangleTemplateParamDecl(Param);
2090 mangleRequiresClause(Params->getRequiresClause());
2094void CXXNameMangler::mangleTypeConstraint(
2095 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2096 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2098 mangleTemplateName(
Concept, Arguments);
2100 mangleUnscopedName(
Concept, DC,
nullptr);
2102 mangleNestedName(
Concept, DC,
nullptr);
2105void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2106 llvm::SmallVector<TemplateArgument, 8> Args;
2108 for (
const TemplateArgumentLoc &ArgLoc :
2110 Args.push_back(ArgLoc.getArgument());
2115void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2117 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2119 mangleExpression(RequiresClause);
2123void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2127 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2130 if (
const IdentifierInfo *Name
2132 mangleSourceName(Name);
2133 const TemplateArgumentList *TemplateArgs =
nullptr;
2142 mangleLambdaSig(Lambda);
2156 UnsignedOrNone DeviceNumber =
2157 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2161 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2163 mangleNumber(Number - 2);
2167void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2170 mangleTemplateParamDecl(D);
2174 mangleRequiresClause(TPL->getRequiresClause());
2178 mangleBareFunctionType(Proto,
false,
2182void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2184 case NestedNameSpecifier::Kind::Null:
2185 case NestedNameSpecifier::Kind::Global:
2189 case NestedNameSpecifier::Kind::MicrosoftSuper:
2190 llvm_unreachable(
"Can't mangle __super specifier");
2192 case NestedNameSpecifier::Kind::Namespace:
2193 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2196 case NestedNameSpecifier::Kind::Type:
2197 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2201 llvm_unreachable(
"unexpected nested name specifier");
2204void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2217 if (NoFunction && isLocalContainerContext(DC))
2221 if (mangleSubstitution(ND))
2225 const TemplateArgumentList *TemplateArgs =
nullptr;
2226 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2227 mangleTemplatePrefix(TD);
2229 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2230 mangleClosurePrefix(PrefixND, NoFunction);
2231 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2233 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2234 manglePrefix(DC, NoFunction);
2235 mangleUnqualifiedName(ND, DC,
nullptr);
2238 addSubstitution(ND);
2245 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2246 return mangleTemplatePrefix(TD);
2249 assert(
Dependent &&
"unexpected template name kind");
2253 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2254 if (!Clang11Compat && mangleSubstitution(
Template))
2257 manglePrefix(
Dependent->getQualifier());
2259 if (Clang11Compat && mangleSubstitution(
Template))
2262 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2263 const IdentifierInfo *Id = Name.getIdentifier())
2264 mangleSourceName(Id);
2266 mangleOperatorName(Name.getOperator(), UnknownArity);
2271void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2280 if (mangleSubstitution(ND))
2284 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2285 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2287 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2288 manglePrefix(DC, NoFunction);
2290 mangleUnqualifiedName(GD, DC,
nullptr);
2296 addSubstitution(ND);
2299const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2300 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2303 const NamedDecl *Context =
nullptr;
2304 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2305 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2306 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2309 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2311 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2325void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2328 if (mangleSubstitution(ND))
2331 const TemplateArgumentList *TemplateArgs =
nullptr;
2332 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2333 mangleTemplatePrefix(TD, NoFunction);
2336 const auto *DC = Context.getEffectiveDeclContext(ND);
2337 manglePrefix(DC, NoFunction);
2338 mangleUnqualifiedName(ND, DC,
nullptr);
2343 addSubstitution(ND);
2352 if (mangleSubstitution(TN))
2355 TemplateDecl *TD =
nullptr;
2365 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2366 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2373 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2382 mangleUnresolvedPrefix(
Dependent->getQualifier());
2383 mangleSourceName(II);
2392 SubstTemplateTemplateParmStorage *subst
2403 Out <<
"_SUBSTPACK_";
2407 llvm_unreachable(
"Unexpected DeducedTemplate");
2410 addSubstitution(TN);
2413bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2419 case Type::Adjusted:
2421 case Type::ArrayParameter:
2423 case Type::BlockPointer:
2424 case Type::LValueReference:
2425 case Type::RValueReference:
2426 case Type::MemberPointer:
2427 case Type::ConstantArray:
2428 case Type::IncompleteArray:
2429 case Type::VariableArray:
2430 case Type::DependentSizedArray:
2431 case Type::DependentAddressSpace:
2432 case Type::DependentVector:
2433 case Type::DependentSizedExtVector:
2435 case Type::ExtVector:
2436 case Type::ConstantMatrix:
2437 case Type::DependentSizedMatrix:
2438 case Type::FunctionProto:
2439 case Type::FunctionNoProto:
2441 case Type::Attributed:
2442 case Type::BTFTagAttributed:
2443 case Type::OverflowBehavior:
2444 case Type::HLSLAttributedResource:
2445 case Type::HLSLInlineSpirv:
2447 case Type::DeducedTemplateSpecialization:
2448 case Type::PackExpansion:
2449 case Type::ObjCObject:
2450 case Type::ObjCInterface:
2451 case Type::ObjCObjectPointer:
2452 case Type::ObjCTypeParam:
2455 case Type::MacroQualified:
2457 case Type::DependentBitInt:
2458 case Type::CountAttributed:
2459 llvm_unreachable(
"type is illegal as a nested name specifier");
2461 case Type::SubstBuiltinTemplatePack:
2466 Out <<
"_SUBSTBUILTINPACK_";
2468 case Type::SubstTemplateTypeParmPack:
2473 Out <<
"_SUBSTPACK_";
2480 case Type::TypeOfExpr:
2482 case Type::Decltype:
2483 case Type::PackIndexing:
2484 case Type::TemplateTypeParm:
2485 case Type::UnaryTransform:
2498 case Type::SubstTemplateTypeParm: {
2502 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2504 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2505 goto unresolvedType;
2512 case Type::PredefinedSugar:
2516 case Type::UnresolvedUsing:
2517 mangleSourceNameWithAbiTags(
2523 mangleSourceNameWithAbiTags(
2527 case Type::TemplateSpecialization: {
2528 const TemplateSpecializationType *TST =
2538 assert(TD &&
"no template for template specialization type");
2540 goto unresolvedType;
2542 mangleSourceNameWithAbiTags(TD);
2554 llvm_unreachable(
"invalid base for a template specialization type");
2557 SubstTemplateTemplateParmStorage *subst =
2568 Out <<
"_SUBSTPACK_";
2574 mangleSourceNameWithAbiTags(TD);
2584 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2588 case Type::InjectedClassName:
2589 mangleSourceNameWithAbiTags(
2593 case Type::DependentName:
2605void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2615 llvm_unreachable(
"Not an operator name");
2638 case OO_New:
Out <<
"nw";
break;
2640 case OO_Array_New:
Out <<
"na";
break;
2642 case OO_Delete:
Out <<
"dl";
break;
2644 case OO_Array_Delete:
Out <<
"da";
break;
2648 Out << (Arity == 1?
"ps" :
"pl");
break;
2652 Out << (Arity == 1?
"ng" :
"mi");
break;
2656 Out << (Arity == 1?
"ad" :
"an");
break;
2661 Out << (Arity == 1?
"de" :
"ml");
break;
2663 case OO_Tilde:
Out <<
"co";
break;
2665 case OO_Slash:
Out <<
"dv";
break;
2667 case OO_Percent:
Out <<
"rm";
break;
2669 case OO_Pipe:
Out <<
"or";
break;
2671 case OO_Caret:
Out <<
"eo";
break;
2673 case OO_Equal:
Out <<
"aS";
break;
2675 case OO_PlusEqual:
Out <<
"pL";
break;
2677 case OO_MinusEqual:
Out <<
"mI";
break;
2679 case OO_StarEqual:
Out <<
"mL";
break;
2681 case OO_SlashEqual:
Out <<
"dV";
break;
2683 case OO_PercentEqual:
Out <<
"rM";
break;
2685 case OO_AmpEqual:
Out <<
"aN";
break;
2687 case OO_PipeEqual:
Out <<
"oR";
break;
2689 case OO_CaretEqual:
Out <<
"eO";
break;
2691 case OO_LessLess:
Out <<
"ls";
break;
2693 case OO_GreaterGreater:
Out <<
"rs";
break;
2695 case OO_LessLessEqual:
Out <<
"lS";
break;
2697 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2699 case OO_EqualEqual:
Out <<
"eq";
break;
2701 case OO_ExclaimEqual:
Out <<
"ne";
break;
2703 case OO_Less:
Out <<
"lt";
break;
2705 case OO_Greater:
Out <<
"gt";
break;
2707 case OO_LessEqual:
Out <<
"le";
break;
2709 case OO_GreaterEqual:
Out <<
"ge";
break;
2711 case OO_Exclaim:
Out <<
"nt";
break;
2713 case OO_AmpAmp:
Out <<
"aa";
break;
2715 case OO_PipePipe:
Out <<
"oo";
break;
2717 case OO_PlusPlus:
Out <<
"pp";
break;
2719 case OO_MinusMinus:
Out <<
"mm";
break;
2721 case OO_Comma:
Out <<
"cm";
break;
2723 case OO_ArrowStar:
Out <<
"pm";
break;
2725 case OO_Arrow:
Out <<
"pt";
break;
2727 case OO_Call:
Out <<
"cl";
break;
2729 case OO_Subscript:
Out <<
"ix";
break;
2734 case OO_Conditional:
Out <<
"qu";
break;
2737 case OO_Coawait:
Out <<
"aw";
break;
2740 case OO_Spaceship:
Out <<
"ss";
break;
2744 llvm_unreachable(
"Not an overloaded operator");
2748void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2767 SmallString<64> ASString;
2773 if (TargetAS != 0 ||
2775 ASString =
"AS" + llvm::utostr(TargetAS);
2778 default: llvm_unreachable(
"Not a language specific address space");
2782 case LangAS::opencl_global:
2783 ASString =
"CLglobal";
2785 case LangAS::opencl_global_device:
2786 ASString =
"CLdevice";
2788 case LangAS::opencl_global_host:
2789 ASString =
"CLhost";
2791 case LangAS::opencl_local:
2792 ASString =
"CLlocal";
2794 case LangAS::opencl_constant:
2795 ASString =
"CLconstant";
2797 case LangAS::opencl_private:
2798 ASString =
"CLprivate";
2800 case LangAS::opencl_generic:
2801 ASString =
"CLgeneric";
2805 case LangAS::sycl_global:
2806 ASString =
"SYglobal";
2808 case LangAS::sycl_global_device:
2809 ASString =
"SYdevice";
2811 case LangAS::sycl_global_host:
2812 ASString =
"SYhost";
2814 case LangAS::sycl_local:
2815 ASString =
"SYlocal";
2817 case LangAS::sycl_private:
2818 ASString =
"SYprivate";
2821 case LangAS::cuda_device:
2822 ASString =
"CUdevice";
2824 case LangAS::cuda_constant:
2825 ASString =
"CUconstant";
2827 case LangAS::cuda_shared:
2828 ASString =
"CUshared";
2831 case LangAS::ptr32_sptr:
2832 ASString =
"ptr32_sptr";
2834 case LangAS::ptr32_uptr:
2838 if (!getASTContext().getTargetInfo().getTriple().isOSzOS())
2839 ASString =
"ptr32_uptr";
2846 if (!ASString.empty())
2847 mangleVendorQualifier(ASString);
2860 mangleVendorQualifier(
"__weak");
2864 mangleVendorQualifier(
"__unaligned");
2868 mangleVendorQualifier(
"__ptrauth");
2878 << unsigned(PtrAuth.isAddressDiscriminated())
2881 << PtrAuth.getExtraDiscriminator()
2896 mangleVendorQualifier(
"__strong");
2900 mangleVendorQualifier(
"__autoreleasing");
2923void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2927void CXXNameMangler::mangleVendorType(StringRef name) {
2934 switch (RefQualifier) {
2948void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2949 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2962 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2968 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2974 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
2975 if (DeducedTST->getDeducedType().isNull())
2980void CXXNameMangler::mangleType(QualType T) {
3020 if (
const TemplateSpecializationType *TST
3021 = dyn_cast<TemplateSpecializationType>(T))
3022 if (!TST->isTypeAlias())
3037 SplitQualType split = T.
split();
3038 Qualifiers quals = split.
Quals;
3039 const Type *ty = split.
Ty;
3041 bool isSubstitutable =
3043 if (isSubstitutable && mangleSubstitution(T))
3050 quals = Qualifiers();
3057 if (
const DependentAddressSpaceType *DAST =
3058 dyn_cast<DependentAddressSpaceType>(ty)) {
3060 mangleQualifiers(splitDAST.
Quals, DAST);
3061 mangleType(QualType(splitDAST.
Ty, 0));
3063 mangleQualifiers(quals);
3067 mangleType(QualType(ty, 0));
3071#define ABSTRACT_TYPE(CLASS, PARENT)
3072#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3074 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3076#define TYPE(CLASS, PARENT) \
3078 mangleType(static_cast<const CLASS##Type*>(ty)); \
3080#include "clang/AST/TypeNodes.inc"
3085 if (isSubstitutable)
3089void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3090 bool SuppressSubstitution) {
3091 if (mangleSubstitution(
Record))
3094 if (SuppressSubstitution)
3099void CXXNameMangler::mangleType(
const BuiltinType *T) {
3141 std::string type_name;
3145 if (NormalizeIntegers && T->
isInteger()) {
3147 switch (getASTContext().getTypeSize(T)) {
3151 if (mangleSubstitution(BuiltinType::SChar))
3154 addSubstitution(BuiltinType::SChar);
3157 if (mangleSubstitution(BuiltinType::Short))
3160 addSubstitution(BuiltinType::Short);
3163 if (mangleSubstitution(BuiltinType::Int))
3166 addSubstitution(BuiltinType::Int);
3169 if (mangleSubstitution(BuiltinType::Long))
3172 addSubstitution(BuiltinType::Long);
3175 if (mangleSubstitution(BuiltinType::Int128))
3178 addSubstitution(BuiltinType::Int128);
3181 llvm_unreachable(
"Unknown integer size for normalization");
3184 switch (getASTContext().getTypeSize(T)) {
3186 if (mangleSubstitution(BuiltinType::UChar))
3189 addSubstitution(BuiltinType::UChar);
3192 if (mangleSubstitution(BuiltinType::UShort))
3195 addSubstitution(BuiltinType::UShort);
3198 if (mangleSubstitution(BuiltinType::UInt))
3201 addSubstitution(BuiltinType::UInt);
3204 if (mangleSubstitution(BuiltinType::ULong))
3207 addSubstitution(BuiltinType::ULong);
3210 if (mangleSubstitution(BuiltinType::UInt128))
3213 addSubstitution(BuiltinType::UInt128);
3216 llvm_unreachable(
"Unknown integer size for normalization");
3222 case BuiltinType::Void:
3225 case BuiltinType::Bool:
3228 case BuiltinType::Char_U:
3229 case BuiltinType::Char_S:
3232 case BuiltinType::UChar:
3235 case BuiltinType::UShort:
3238 case BuiltinType::UInt:
3241 case BuiltinType::ULong:
3244 case BuiltinType::ULongLong:
3247 case BuiltinType::UInt128:
3250 case BuiltinType::SChar:
3253 case BuiltinType::WChar_S:
3254 case BuiltinType::WChar_U:
3257 case BuiltinType::Char8:
3260 case BuiltinType::Char16:
3263 case BuiltinType::Char32:
3266 case BuiltinType::Short:
3269 case BuiltinType::Int:
3272 case BuiltinType::Long:
3275 case BuiltinType::LongLong:
3278 case BuiltinType::Int128:
3281 case BuiltinType::Float16:
3284 case BuiltinType::ShortAccum:
3287 case BuiltinType::Accum:
3290 case BuiltinType::LongAccum:
3293 case BuiltinType::UShortAccum:
3296 case BuiltinType::UAccum:
3299 case BuiltinType::ULongAccum:
3302 case BuiltinType::ShortFract:
3305 case BuiltinType::Fract:
3308 case BuiltinType::LongFract:
3311 case BuiltinType::UShortFract:
3314 case BuiltinType::UFract:
3317 case BuiltinType::ULongFract:
3320 case BuiltinType::SatShortAccum:
3323 case BuiltinType::SatAccum:
3326 case BuiltinType::SatLongAccum:
3329 case BuiltinType::SatUShortAccum:
3332 case BuiltinType::SatUAccum:
3335 case BuiltinType::SatULongAccum:
3338 case BuiltinType::SatShortFract:
3341 case BuiltinType::SatFract:
3344 case BuiltinType::SatLongFract:
3347 case BuiltinType::SatUShortFract:
3350 case BuiltinType::SatUFract:
3353 case BuiltinType::SatULongFract:
3356 case BuiltinType::Half:
3359 case BuiltinType::Float:
3362 case BuiltinType::Double:
3365 case BuiltinType::LongDouble: {
3366 const TargetInfo *TI =
3367 getASTContext().getLangOpts().OpenMP &&
3368 getASTContext().getLangOpts().OpenMPIsTargetDevice
3369 ? getASTContext().getAuxTargetInfo()
3370 : &getASTContext().getTargetInfo();
3374 case BuiltinType::Float128: {
3375 const TargetInfo *TI =
3376 getASTContext().getLangOpts().OpenMP &&
3377 getASTContext().getLangOpts().OpenMPIsTargetDevice
3378 ? getASTContext().getAuxTargetInfo()
3379 : &getASTContext().getTargetInfo();
3383 case BuiltinType::BFloat16: {
3384 const TargetInfo *TI =
3385 ((getASTContext().getLangOpts().OpenMP &&
3386 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3387 getASTContext().getLangOpts().SYCLIsDevice)
3388 ? getASTContext().getAuxTargetInfo()
3389 : &getASTContext().getTargetInfo();
3393 case BuiltinType::Ibm128: {
3394 const TargetInfo *TI = &getASTContext().getTargetInfo();
3398 case BuiltinType::NullPtr:
3402#define BUILTIN_TYPE(Id, SingletonId)
3403#define PLACEHOLDER_TYPE(Id, SingletonId) \
3404 case BuiltinType::Id:
3405#include "clang/AST/BuiltinTypes.def"
3406 case BuiltinType::Dependent:
3408 llvm_unreachable(
"mangling a placeholder type");
3410 case BuiltinType::ObjCId:
3411 Out <<
"11objc_object";
3413 case BuiltinType::ObjCClass:
3414 Out <<
"10objc_class";
3416 case BuiltinType::ObjCSel:
3417 Out <<
"13objc_selector";
3419#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3420 case BuiltinType::Id: \
3421 type_name = "ocl_" #ImgType "_" #Suffix; \
3422 Out << type_name.size() << type_name; \
3424#include "clang/Basic/OpenCLImageTypes.def"
3425 case BuiltinType::OCLSampler:
3426 Out <<
"11ocl_sampler";
3428 case BuiltinType::OCLEvent:
3429 Out <<
"9ocl_event";
3431 case BuiltinType::OCLClkEvent:
3432 Out <<
"12ocl_clkevent";
3434 case BuiltinType::OCLQueue:
3435 Out <<
"9ocl_queue";
3437 case BuiltinType::OCLReserveID:
3438 Out <<
"13ocl_reserveid";
3440#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3441 case BuiltinType::Id: \
3442 type_name = "ocl_" #ExtType; \
3443 Out << type_name.size() << type_name; \
3445#include "clang/Basic/OpenCLExtensionTypes.def"
3449#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3450 case BuiltinType::Id: \
3451 if (T->getKind() == BuiltinType::SveBFloat16 && \
3452 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3454 mangleVendorType("__SVBFloat16_t"); \
3456 type_name = #MangledName; \
3457 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3460#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3461 case BuiltinType::Id: \
3462 type_name = #MangledName; \
3463 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3465#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3466 case BuiltinType::Id: \
3467 type_name = #MangledName; \
3468 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3470#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3471 case BuiltinType::Id: \
3472 type_name = #MangledName; \
3473 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3475#include "clang/Basic/AArch64ACLETypes.def"
3476#define PPC_VECTOR_TYPE(Name, Id, Size) \
3477 case BuiltinType::Id: \
3478 mangleVendorType(#Name); \
3480#include "clang/Basic/PPCTypes.def"
3482#define RVV_TYPE(Name, Id, SingletonId) \
3483 case BuiltinType::Id: \
3484 mangleVendorType(Name); \
3486#include "clang/Basic/RISCVVTypes.def"
3487#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3488 case BuiltinType::Id: \
3489 mangleVendorType(MangledName); \
3491#include "clang/Basic/WebAssemblyReferenceTypes.def"
3492#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3493 case BuiltinType::Id: \
3494 mangleVendorType(Name); \
3496#include "clang/Basic/AMDGPUTypes.def"
3497#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3498 case BuiltinType::Id: \
3499 mangleVendorType(#Name); \
3501#include "clang/Basic/HLSLIntangibleTypes.def"
3505StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3525#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3561 return "swiftasynccall";
3563 llvm_unreachable(
"bad calling convention");
3566void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *T) {
3568 if (T->
getExtInfo() == FunctionType::ExtInfo())
3575 StringRef CCQualifier = getCallingConvQualifierName(T->
getExtInfo().
getCC());
3576 if (!CCQualifier.empty())
3577 mangleVendorQualifier(CCQualifier);
3610 llvm_unreachable(
"Unrecognised SME attribute");
3625void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3645 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3649CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3656 case ParameterABI::Ordinary:
3660 case ParameterABI::HLSLOut:
3661 case ParameterABI::HLSLInOut:
3666 case ParameterABI::SwiftContext:
3667 case ParameterABI::SwiftAsyncContext:
3668 case ParameterABI::SwiftErrorResult:
3669 case ParameterABI::SwiftIndirectResult:
3675 mangleVendorQualifier(
"ns_consumed");
3678 mangleVendorQualifier(
"noescape");
3684void CXXNameMangler::mangleType(
const FunctionProtoType *T) {
3688 Out <<
"11__SME_ATTRSI";
3690 mangleExtFunctionInfo(T);
3707 mangleType(ExceptTy);
3718 mangleBareFunctionType(T,
true);
3725 mangleSMEAttrs(SMEAttrs);
3728void CXXNameMangler::mangleType(
const FunctionNoProtoType *T) {
3734 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3736 FunctionTypeDepth.enterResultType();
3738 FunctionTypeDepth.leaveResultType();
3740 FunctionTypeDepth.pop(saved);
3744void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3745 bool MangleReturnType,
3746 const FunctionDecl *FD) {
3749 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3752 if (MangleReturnType) {
3753 FunctionTypeDepth.enterResultType();
3757 mangleVendorQualifier(
"ns_returns_retained");
3762 auto SplitReturnTy = ReturnTy.
split();
3764 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3766 mangleType(ReturnTy);
3768 FunctionTypeDepth.leaveResultType();
3776 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3790 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3791 if (Attr->isDynamic())
3792 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3794 Out <<
"U17pass_object_size" << Attr->getType();
3805 FunctionTypeDepth.enterResultType();
3809 FunctionTypeDepth.pop(saved);
3814void CXXNameMangler::mangleType(
const UnresolvedUsingType *T) {
3820void CXXNameMangler::mangleType(
const EnumType *T) {
3821 mangleType(
static_cast<const TagType*
>(T));
3823void CXXNameMangler::mangleType(
const RecordType *T) {
3824 mangleType(
static_cast<const TagType*
>(T));
3826void CXXNameMangler::mangleType(
const TagType *T) {
3827 mangleName(T->getDecl()->getDefinitionOrSelf());
3833void CXXNameMangler::mangleType(
const ConstantArrayType *T) {
3837void CXXNameMangler::mangleType(
const VariableArrayType *T) {
3845void CXXNameMangler::mangleType(
const DependentSizedArrayType *T) {
3855void CXXNameMangler::mangleType(
const IncompleteArrayType *T) {
3862void CXXNameMangler::mangleType(
const MemberPointerType *T) {
3865 mangleCXXRecordDecl(RD);
3869 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3890 mangleType(PointeeType);
3894void CXXNameMangler::mangleType(
const TemplateTypeParmType *T) {
3895 mangleTemplateParameter(T->getDepth(), T->getIndex());
3899void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *T) {
3904 Out <<
"_SUBSTPACK_";
3907void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *T) {
3912 Out <<
"_SUBSTBUILTINPACK_";
3916void CXXNameMangler::mangleType(
const PointerType *T) {
3920void CXXNameMangler::mangleType(
const ObjCObjectPointerType *T) {
3926void CXXNameMangler::mangleType(
const LValueReferenceType *T) {
3932void CXXNameMangler::mangleType(
const RValueReferenceType *T) {
3938void CXXNameMangler::mangleType(
const ComplexType *T) {
3946void CXXNameMangler::mangleNeonVectorType(
const VectorType *T) {
3948 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3949 const char *EltName =
nullptr;
3952 case BuiltinType::SChar:
3953 case BuiltinType::UChar:
3954 EltName =
"poly8_t";
3956 case BuiltinType::Short:
3957 case BuiltinType::UShort:
3958 EltName =
"poly16_t";
3960 case BuiltinType::LongLong:
3961 case BuiltinType::ULongLong:
3962 EltName =
"poly64_t";
3964 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3968 case BuiltinType::SChar: EltName =
"int8_t";
break;
3969 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3970 case BuiltinType::Short: EltName =
"int16_t";
break;
3971 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3972 case BuiltinType::Int: EltName =
"int32_t";
break;
3973 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3974 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3975 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3976 case BuiltinType::Double: EltName =
"float64_t";
break;
3977 case BuiltinType::Float: EltName =
"float32_t";
break;
3978 case BuiltinType::Half: EltName =
"float16_t";
break;
3979 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3980 case BuiltinType::MFloat8:
3981 EltName =
"mfloat8_t";
3984 llvm_unreachable(
"unexpected Neon vector element type");
3987 const char *BaseName =
nullptr;
3989 getASTContext().getTypeSize(EltType));
3991 BaseName =
"__simd64_";
3993 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
3994 BaseName =
"__simd128_";
3996 Out << strlen(BaseName) + strlen(EltName);
3997 Out << BaseName << EltName;
4000void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *T) {
4001 DiagnosticsEngine &Diags = Context.getDiags();
4003 << UnsupportedItaniumManglingKind::DependentNeonVector;
4008 case BuiltinType::SChar:
4010 case BuiltinType::Short:
4012 case BuiltinType::Int:
4014 case BuiltinType::Long:
4015 case BuiltinType::LongLong:
4017 case BuiltinType::UChar:
4019 case BuiltinType::UShort:
4021 case BuiltinType::UInt:
4023 case BuiltinType::ULong:
4024 case BuiltinType::ULongLong:
4026 case BuiltinType::Half:
4028 case BuiltinType::Float:
4030 case BuiltinType::Double:
4032 case BuiltinType::BFloat16:
4034 case BuiltinType::MFloat8:
4037 llvm_unreachable(
"Unexpected vector element base type");
4044void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *T) {
4046 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4051 assert((BitSize == 64 || BitSize == 128) &&
4052 "Neon vector type not 64 or 128 bits");
4057 case BuiltinType::UChar:
4060 case BuiltinType::UShort:
4063 case BuiltinType::ULong:
4064 case BuiltinType::ULongLong:
4068 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4074 (
"__" + EltName +
"x" + Twine(T->
getNumElements()) +
"_t").str();
4077void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *T) {
4078 DiagnosticsEngine &Diags = Context.getDiags();
4080 << UnsupportedItaniumManglingKind::DependentNeonVector;
4107void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *T) {
4108 assert((T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4109 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4110 "expected fixed-length SVE vector!");
4114 "expected builtin type for fixed-length SVE vector!");
4118 case BuiltinType::SChar:
4121 case BuiltinType::UChar: {
4128 case BuiltinType::Short:
4131 case BuiltinType::UShort:
4134 case BuiltinType::Int:
4137 case BuiltinType::UInt:
4140 case BuiltinType::Long:
4143 case BuiltinType::ULong:
4146 case BuiltinType::Half:
4149 case BuiltinType::Float:
4152 case BuiltinType::Double:
4155 case BuiltinType::BFloat16:
4159 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4162 unsigned VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4164 if (T->
getVectorKind() == VectorKind::SveFixedLengthPredicate)
4167 Out <<
"9__SVE_VLSI";
4168 mangleVendorType(TypeName);
4169 Out <<
"Lj" << VecSizeInBits <<
"EE";
4172void CXXNameMangler::mangleAArch64FixedSveVectorType(
4173 const DependentVectorType *T) {
4174 DiagnosticsEngine &Diags = Context.getDiags();
4176 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4179void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *T) {
4180 assert((T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4185 "expected fixed-length RVV vector!");
4189 "expected builtin type for fixed-length RVV vector!");
4191 SmallString<20> TypeNameStr;
4192 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4193 TypeNameOS <<
"__rvv_";
4195 case BuiltinType::SChar:
4196 TypeNameOS <<
"int8";
4198 case BuiltinType::UChar:
4200 TypeNameOS <<
"uint8";
4202 TypeNameOS <<
"bool";
4204 case BuiltinType::Short:
4205 TypeNameOS <<
"int16";
4207 case BuiltinType::UShort:
4208 TypeNameOS <<
"uint16";
4210 case BuiltinType::Int:
4211 TypeNameOS <<
"int32";
4213 case BuiltinType::UInt:
4214 TypeNameOS <<
"uint32";
4216 case BuiltinType::Long:
4217 case BuiltinType::LongLong:
4218 TypeNameOS <<
"int64";
4220 case BuiltinType::ULong:
4221 case BuiltinType::ULongLong:
4222 TypeNameOS <<
"uint64";
4224 case BuiltinType::Float16:
4225 TypeNameOS <<
"float16";
4227 case BuiltinType::Float:
4228 TypeNameOS <<
"float32";
4230 case BuiltinType::Double:
4231 TypeNameOS <<
"float64";
4233 case BuiltinType::BFloat16:
4234 TypeNameOS <<
"bfloat16";
4237 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4240 unsigned VecSizeInBits;
4242 case VectorKind::RVVFixedLengthMask_1:
4245 case VectorKind::RVVFixedLengthMask_2:
4248 case VectorKind::RVVFixedLengthMask_4:
4252 VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4257 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4258 getASTContext().getLangOpts(),
4259 TargetInfo::ArmStreamingKind::NotStreaming);
4260 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4264 if (VecSizeInBits >= VLen)
4265 TypeNameOS << (VecSizeInBits / VLen);
4267 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4269 TypeNameOS << (VLen / VecSizeInBits);
4273 Out <<
"9__RVV_VLSI";
4274 mangleVendorType(TypeNameStr);
4275 Out <<
"Lj" << VecSizeInBits <<
"EE";
4278void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4279 const DependentVectorType *T) {
4280 DiagnosticsEngine &Diags = Context.getDiags();
4282 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4293void CXXNameMangler::mangleType(
const VectorType *T) {
4296 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4297 llvm::Triple::ArchType
Arch =
4298 getASTContext().getTargetInfo().getTriple().getArch();
4299 if ((
Arch == llvm::Triple::aarch64 ||
4300 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4301 mangleAArch64NeonVectorType(T);
4303 mangleNeonVectorType(T);
4305 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4306 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4307 mangleAArch64FixedSveVectorType(T);
4309 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4314 mangleRISCVFixedRVVVectorType(T);
4326void CXXNameMangler::mangleType(
const DependentVectorType *T) {
4329 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4330 llvm::Triple::ArchType
Arch =
4331 getASTContext().getTargetInfo().getTriple().getArch();
4332 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4334 mangleAArch64NeonVectorType(T);
4336 mangleNeonVectorType(T);
4338 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4339 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4340 mangleAArch64FixedSveVectorType(T);
4342 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData) {
4343 mangleRISCVFixedRVVVectorType(T);
4358void CXXNameMangler::mangleType(
const ExtVectorType *T) {
4359 mangleType(
static_cast<const VectorType*
>(T));
4361void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *T) {
4368void CXXNameMangler::mangleType(
const ConstantMatrixType *T) {
4372 mangleVendorType(
"matrix_type");
4375 auto &ASTCtx = getASTContext();
4376 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4377 llvm::APSInt Rows(BitWidth);
4379 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4380 llvm::APSInt Columns(BitWidth);
4382 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4387void CXXNameMangler::mangleType(
const DependentSizedMatrixType *T) {
4390 mangleVendorType(
"matrix_type");
4399void CXXNameMangler::mangleType(
const DependentAddressSpaceType *T) {
4401 mangleQualifiers(split.
Quals, T);
4402 mangleType(QualType(split.
Ty, 0));
4405void CXXNameMangler::mangleType(
const PackExpansionType *T) {
4408 mangleType(T->getPattern());
4411void CXXNameMangler::mangleType(
const PackIndexingType *T) {
4412 if (!T->hasSelectedType())
4413 mangleType(T->getPattern());
4415 mangleType(T->getSelectedType());
4418void CXXNameMangler::mangleType(
const ObjCInterfaceType *T) {
4422void CXXNameMangler::mangleType(
const ObjCObjectType *T) {
4424 if (T->isKindOfType())
4425 Out <<
"U8__kindof";
4427 if (!T->qual_empty()) {
4429 SmallString<64> QualStr;
4430 llvm::raw_svector_ostream QualOS(QualStr);
4431 QualOS <<
"objcproto";
4432 for (
const auto *I : T->quals()) {
4433 StringRef
name = I->getName();
4436 mangleVendorQualifier(QualStr);
4439 mangleType(T->getBaseType());
4441 if (T->isSpecialized()) {
4444 for (
auto typeArg : T->getTypeArgs())
4445 mangleType(typeArg);
4450void CXXNameMangler::mangleType(
const BlockPointerType *T) {
4451 Out <<
"U13block_pointer";
4455void CXXNameMangler::mangleType(
const InjectedClassNameType *T) {
4460 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4463void CXXNameMangler::mangleType(
const TemplateSpecializationType *T) {
4464 if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) {
4465 mangleTemplateName(TD, T->template_arguments());
4468 mangleTemplatePrefix(T->getTemplateName());
4473 mangleTemplateArgs(T->getTemplateName(), T->template_arguments());
4478void CXXNameMangler::mangleType(
const DependentNameType *T) {
4489 switch (T->getKeyword()) {
4490 case ElaboratedTypeKeyword::None:
4491 case ElaboratedTypeKeyword::Typename:
4493 case ElaboratedTypeKeyword::Struct:
4494 case ElaboratedTypeKeyword::Class:
4495 case ElaboratedTypeKeyword::Interface:
4498 case ElaboratedTypeKeyword::Union:
4501 case ElaboratedTypeKeyword::Enum:
4507 manglePrefix(T->getQualifier());
4508 mangleSourceName(T->getIdentifier());
4512void CXXNameMangler::mangleType(
const TypeOfType *T) {
4518void CXXNameMangler::mangleType(
const TypeOfExprType *T) {
4524void CXXNameMangler::mangleType(
const DecltypeType *T) {
4525 Expr *E = T->getUnderlyingExpr();
4544 mangleExpression(E);
4548void CXXNameMangler::mangleType(
const UnaryTransformType *T) {
4551 if (T->isDependentType()) {
4552 StringRef BuiltinName;
4553 switch (T->getUTTKind()) {
4554#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4555 case UnaryTransformType::Enum: \
4556 BuiltinName = "__" #Trait; \
4558#include "clang/Basic/TransformTypeTraits.def"
4560 mangleVendorType(BuiltinName);
4564 mangleType(T->getBaseType());
4568void CXXNameMangler::mangleType(
const AutoType *T) {
4569 assert(T->getDeducedType().isNull() &&
4570 "Deduced AutoType shouldn't be handled here!");
4571 assert(T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4572 "shouldn't need to mangle __auto_type!");
4577 if (T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4578 Out << (T->isDecltypeAuto() ?
"DK" :
"Dk");
4579 mangleTypeConstraint(T->getTypeConstraintConcept(),
4580 T->getTypeConstraintArguments());
4582 Out << (T->isDecltypeAuto() ?
"Dc" :
"Da");
4586void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *T) {
4587 QualType Deduced = T->getDeducedType();
4589 return mangleType(Deduced);
4593 "shouldn't form deduced TST unless we know we have a template");
4597void CXXNameMangler::mangleType(
const AtomicType *T) {
4604void CXXNameMangler::mangleType(
const PipeType *T) {
4611void CXXNameMangler::mangleType(
const OverflowBehaviorType *T) {
4614 if (T->isWrapKind()) {
4615 Out <<
"U8ObtWrap_";
4617 Out <<
"U8ObtTrap_";
4619 mangleType(T->getUnderlyingType());
4622void CXXNameMangler::mangleType(
const BitIntType *T) {
4629void CXXNameMangler::mangleType(
const DependentBitIntType *T) {
4638void CXXNameMangler::mangleType(
const ArrayParameterType *T) {
4642void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *T) {
4643 llvm::SmallString<64> Str(
"_Res");
4644 const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
4646 switch (Attrs.ResourceClass) {
4647 case llvm::dxil::ResourceClass::UAV:
4650 case llvm::dxil::ResourceClass::SRV:
4653 case llvm::dxil::ResourceClass::CBuffer:
4656 case llvm::dxil::ResourceClass::Sampler:
4662 if (Attrs.RawBuffer)
4664 if (Attrs.IsCounter)
4666 if (T->hasContainedType())
4668 mangleVendorQualifier(Str);
4670 if (T->hasContainedType()) {
4671 mangleType(T->getContainedType());
4673 mangleType(T->getWrappedType());
4676void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *T) {
4677 SmallString<20> TypeNameStr;
4678 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4680 TypeNameOS <<
"spirv_type";
4682 TypeNameOS <<
"_" << T->getOpcode();
4683 TypeNameOS <<
"_" << T->getSize();
4684 TypeNameOS <<
"_" << T->getAlignment();
4686 mangleVendorType(TypeNameStr);
4688 for (
auto &Operand : T->getOperands()) {
4689 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4692 case SpirvOperandKind::ConstantId:
4693 mangleVendorQualifier(
"_Const");
4694 mangleIntegerLiteral(
Operand.getResultType(),
4695 llvm::APSInt(
Operand.getValue()));
4697 case SpirvOperandKind::Literal:
4698 mangleVendorQualifier(
"_Lit");
4699 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4700 llvm::APSInt(
Operand.getValue()));
4702 case SpirvOperandKind::TypeId:
4703 mangleVendorQualifier(
"_Type");
4704 mangleType(
Operand.getResultType());
4707 llvm_unreachable(
"Invalid SpirvOperand kind");
4710 TypeNameOS <<
Operand.getKind();
4714void CXXNameMangler::mangleIntegerLiteral(QualType T,
4715 const llvm::APSInt &
Value) {
4722 Out << (
Value.getBoolValue() ?
'1' :
'0');
4724 mangleNumber(
Value);
4729void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4731 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4732 if (!RT->getDecl()->isAnonymousStructOrUnion())
4734 const auto *ME = dyn_cast<MemberExpr>(Base);
4737 Base = ME->getBase();
4738 IsArrow = ME->isArrow();
4741 if (
Base->isImplicitCXXThis()) {
4747 Out << (IsArrow ?
"pt" :
"dt");
4748 mangleExpression(Base);
4753void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4754 NestedNameSpecifier Qualifier,
4755 NamedDecl *firstQualifierLookup,
4756 DeclarationName member,
4757 const TemplateArgumentLoc *TemplateArgs,
4758 unsigned NumTemplateArgs,
4763 mangleMemberExprBase(base, isArrow);
4764 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4777 if (callee == fn)
return false;
4781 if (!lookup)
return false;
4798void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4800 Out << CastEncoding;
4805void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4807 InitList = Syntactic;
4808 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4809 mangleExpression(InitList->
getInit(i));
4812void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4813 const concepts::Requirement *Req) {
4814 using concepts::Requirement;
4819 auto HandleSubstitutionFailure =
4820 [&](SourceLocation Loc) {
4821 DiagnosticsEngine &Diags = Context.getDiags();
4822 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4823 << UnsupportedItaniumManglingKind::
4824 RequiresExprWithSubstitutionFailure;
4829 case Requirement::RK_Type: {
4831 if (TR->isSubstitutionFailure())
4832 return HandleSubstitutionFailure(
4833 TR->getSubstitutionDiagnostic()->DiagLoc);
4836 mangleType(TR->getType()->getType());
4840 case Requirement::RK_Simple:
4841 case Requirement::RK_Compound: {
4843 if (ER->isExprSubstitutionFailure())
4844 return HandleSubstitutionFailure(
4845 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4848 mangleExpression(ER->getExpr());
4850 if (ER->hasNoexceptRequirement())
4853 if (!ER->getReturnTypeRequirement().isEmpty()) {
4854 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4855 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4856 .getSubstitutionDiagnostic()
4860 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4865 case Requirement::RK_Nested:
4867 if (NR->hasInvalidConstraint()) {
4870 return HandleSubstitutionFailure(RequiresExprLoc);
4874 mangleExpression(NR->getConstraintExpr());
4879void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4880 bool AsTemplateArg) {
4909 QualType ImplicitlyConvertedToType;
4913 bool IsPrimaryExpr =
true;
4914 auto NotPrimaryExpr = [&] {
4915 if (AsTemplateArg && IsPrimaryExpr)
4917 IsPrimaryExpr =
false;
4920 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4921 switch (D->getKind()) {
4934 case Decl::EnumConstant: {
4941 case Decl::NonTypeTemplateParm:
4954 case Expr::NoStmtClass:
4955#define ABSTRACT_STMT(Type)
4956#define EXPR(Type, Base)
4957#define STMT(Type, Base) \
4958 case Expr::Type##Class:
4959#include "clang/AST/StmtNodes.inc"
4964 case Expr::AddrLabelExprClass:
4965 case Expr::DesignatedInitUpdateExprClass:
4966 case Expr::ImplicitValueInitExprClass:
4967 case Expr::ArrayInitLoopExprClass:
4968 case Expr::ArrayInitIndexExprClass:
4969 case Expr::NoInitExprClass:
4970 case Expr::ParenListExprClass:
4971 case Expr::MSPropertyRefExprClass:
4972 case Expr::MSPropertySubscriptExprClass:
4973 case Expr::RecoveryExprClass:
4974 case Expr::ArraySectionExprClass:
4975 case Expr::OMPArrayShapingExprClass:
4976 case Expr::OMPIteratorExprClass:
4977 case Expr::CXXInheritedCtorInitExprClass:
4978 case Expr::CXXParenListInitExprClass:
4979 case Expr::PackIndexingExprClass:
4980 llvm_unreachable(
"unexpected statement kind");
4982 case Expr::ConstantExprClass:
4986 case Expr::CXXReflectExprClass: {
4988 assert(
false &&
"unimplemented");
4993 case Expr::BlockExprClass:
4994 case Expr::ChooseExprClass:
4995 case Expr::CompoundLiteralExprClass:
4996 case Expr::ExtVectorElementExprClass:
4997 case Expr::MatrixElementExprClass:
4998 case Expr::GenericSelectionExprClass:
4999 case Expr::ObjCEncodeExprClass:
5000 case Expr::ObjCIsaExprClass:
5001 case Expr::ObjCIvarRefExprClass:
5002 case Expr::ObjCMessageExprClass:
5003 case Expr::ObjCPropertyRefExprClass:
5004 case Expr::ObjCProtocolExprClass:
5005 case Expr::ObjCSelectorExprClass:
5006 case Expr::ObjCStringLiteralClass:
5007 case Expr::ObjCBoxedExprClass:
5008 case Expr::ObjCArrayLiteralClass:
5009 case Expr::ObjCDictionaryLiteralClass:
5010 case Expr::ObjCSubscriptRefExprClass:
5011 case Expr::ObjCIndirectCopyRestoreExprClass:
5012 case Expr::ObjCAvailabilityCheckExprClass:
5013 case Expr::OffsetOfExprClass:
5014 case Expr::PredefinedExprClass:
5015 case Expr::ShuffleVectorExprClass:
5016 case Expr::ConvertVectorExprClass:
5017 case Expr::StmtExprClass:
5018 case Expr::ArrayTypeTraitExprClass:
5019 case Expr::ExpressionTraitExprClass:
5020 case Expr::VAArgExprClass:
5021 case Expr::CUDAKernelCallExprClass:
5022 case Expr::AsTypeExprClass:
5023 case Expr::PseudoObjectExprClass:
5024 case Expr::AtomicExprClass:
5025 case Expr::SourceLocExprClass:
5026 case Expr::EmbedExprClass:
5027 case Expr::BuiltinBitCastExprClass: {
5031 DiagnosticsEngine &Diags = Context.getDiags();
5039 case Expr::CXXUuidofExprClass: {
5044 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5045 Out <<
"u8__uuidof";
5054 Out <<
"u8__uuidoft";
5058 Out <<
"u8__uuidofz";
5059 mangleExpression(UuidExp);
5066 case Expr::BinaryConditionalOperatorClass: {
5068 DiagnosticsEngine &Diags = Context.getDiags();
5070 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5076 case Expr::OpaqueValueExprClass:
5077 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5079 case Expr::InitListExprClass: {
5087 case Expr::DesignatedInitExprClass: {
5090 for (
const auto &Designator : DIE->designators()) {
5091 if (Designator.isFieldDesignator()) {
5093 mangleSourceName(Designator.getFieldName());
5094 }
else if (Designator.isArrayDesignator()) {
5096 mangleExpression(DIE->getArrayIndex(Designator));
5098 assert(Designator.isArrayRangeDesignator() &&
5099 "unknown designator kind");
5101 mangleExpression(DIE->getArrayRangeStart(Designator));
5102 mangleExpression(DIE->getArrayRangeEnd(Designator));
5105 mangleExpression(DIE->getInit());
5109 case Expr::CXXDefaultArgExprClass:
5113 case Expr::CXXDefaultInitExprClass:
5117 case Expr::CXXStdInitializerListExprClass:
5121 case Expr::SubstNonTypeTemplateParmExprClass: {
5125 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5127 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5128 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5129 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5139 case Expr::UserDefinedLiteralClass:
5142 case Expr::CXXMemberCallExprClass:
5143 case Expr::CallExprClass: {
5165 CallArity = UnknownArity;
5167 mangleExpression(CE->
getCallee(), CallArity);
5169 mangleExpression(Arg);
5174 case Expr::CXXNewExprClass: {
5177 if (
New->isGlobalNew())
Out <<
"gs";
5178 Out << (
New->isArray() ?
"na" :
"nw");
5180 E =
New->placement_arg_end(); I != E; ++I)
5181 mangleExpression(*I);
5183 mangleType(
New->getAllocatedType());
5184 if (
New->hasInitializer()) {
5185 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5189 const Expr *
Init =
New->getInitializer();
5190 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5195 mangleExpression(*I);
5196 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5197 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5198 mangleExpression(PLE->getExpr(i));
5199 }
else if (
New->getInitializationStyle() ==
5200 CXXNewInitializationStyle::Braces &&
5205 mangleExpression(
Init);
5211 case Expr::CXXPseudoDestructorExprClass: {
5214 if (
const Expr *Base = PDE->getBase())
5215 mangleMemberExprBase(Base, PDE->isArrow());
5216 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5217 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5219 mangleUnresolvedPrefix(Qualifier,
5221 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5225 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5228 }
else if (Qualifier) {
5229 mangleUnresolvedPrefix(Qualifier);
5233 QualType DestroyedType = PDE->getDestroyedType();
5234 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5238 case Expr::MemberExprClass: {
5249 case Expr::UnresolvedMemberExprClass: {
5260 case Expr::CXXDependentScopeMemberExprClass: {
5262 const CXXDependentScopeMemberExpr *ME
5273 case Expr::UnresolvedLookupExprClass: {
5282 case Expr::CXXUnresolvedConstructExprClass: {
5288 assert(N == 1 &&
"unexpected form for list initialization");
5292 mangleInitListElements(IL);
5299 if (N != 1)
Out <<
'_';
5300 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5301 if (N != 1)
Out <<
'E';
5305 case Expr::CXXConstructExprClass: {
5312 "implicit CXXConstructExpr must have one argument");
5319 mangleExpression(E);
5324 case Expr::CXXTemporaryObjectExprClass: {
5335 if (!List && N != 1)
5337 if (CE->isStdInitListInitialization()) {
5344 mangleInitListElements(ILE);
5347 mangleExpression(E);
5354 case Expr::CXXScalarValueInitExprClass:
5361 case Expr::CXXNoexceptExprClass:
5367 case Expr::UnaryExprOrTypeTraitExprClass: {
5384 QualType T = (ImplicitlyConvertedToType.
isNull() ||
5386 : ImplicitlyConvertedToType;
5388 mangleIntegerLiteral(T,
V);
5394 auto MangleAlignofSizeofArg = [&] {
5404 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5405 StringRef Name = {}) {
5408 mangleVendorType(Name);
5419 MangleAlignofSizeofArg();
5421 case UETT_PreferredAlignOf:
5425 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5426 MangleExtensionBuiltin(SAE,
"__alignof__");
5432 MangleAlignofSizeofArg();
5436 case UETT_VectorElements:
5437 case UETT_OpenMPRequiredSimdAlign:
5439 case UETT_PtrAuthTypeDiscriminator:
5440 case UETT_DataSizeOf: {
5441 DiagnosticsEngine &Diags = Context.getDiags();
5450 case Expr::TypeTraitExprClass: {
5455 mangleVendorType(Spelling);
5456 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5457 mangleType(TSI->getType());
5463 case Expr::CXXThrowExprClass: {
5477 case Expr::CXXTypeidExprClass: {
5492 case Expr::CXXDeleteExprClass: {
5503 case Expr::UnaryOperatorClass: {
5512 case Expr::ArraySubscriptExprClass: {
5519 mangleExpression(AE->
getLHS());
5520 mangleExpression(AE->
getRHS());
5524 case Expr::MatrixSingleSubscriptExprClass: {
5528 mangleExpression(ME->
getBase());
5533 case Expr::MatrixSubscriptExprClass: {
5537 mangleExpression(ME->
getBase());
5543 case Expr::CompoundAssignOperatorClass:
5544 case Expr::BinaryOperatorClass: {
5552 mangleExpression(BO->
getLHS());
5553 mangleExpression(BO->
getRHS());
5557 case Expr::CXXRewrittenBinaryOperatorClass: {
5560 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5564 mangleExpression(Decomposed.
LHS);
5565 mangleExpression(Decomposed.
RHS);
5569 case Expr::ConditionalOperatorClass: {
5572 mangleOperatorName(OO_Conditional, 3);
5573 mangleExpression(CO->
getCond());
5574 mangleExpression(CO->
getLHS(), Arity);
5575 mangleExpression(CO->
getRHS(), Arity);
5579 case Expr::ImplicitCastExprClass: {
5580 ImplicitlyConvertedToType = E->
getType();
5585 case Expr::ObjCBridgedCastExprClass: {
5591 mangleCastExpression(E,
"cv");
5595 case Expr::CStyleCastExprClass:
5597 mangleCastExpression(E,
"cv");
5600 case Expr::CXXFunctionalCastExprClass: {
5604 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5605 if (CCE->getParenOrBraceRange().isInvalid())
5606 Sub = CCE->getArg(0)->IgnoreImplicit();
5607 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5608 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5609 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5612 mangleInitListElements(IL);
5615 mangleCastExpression(E,
"cv");
5620 case Expr::CXXStaticCastExprClass:
5622 mangleCastExpression(E,
"sc");
5624 case Expr::CXXDynamicCastExprClass:
5626 mangleCastExpression(E,
"dc");
5628 case Expr::CXXReinterpretCastExprClass:
5630 mangleCastExpression(E,
"rc");
5632 case Expr::CXXConstCastExprClass:
5634 mangleCastExpression(E,
"cc");
5636 case Expr::CXXAddrspaceCastExprClass:
5638 mangleCastExpression(E,
"ac");
5641 case Expr::CXXOperatorCallExprClass: {
5650 for (
unsigned i = 0; i != NumArgs; ++i)
5651 mangleExpression(CE->
getArg(i));
5655 case Expr::ParenExprClass:
5659 case Expr::ConceptSpecializationExprClass: {
5661 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5666 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5672 mangleUnresolvedName(
5673 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5674 CSE->getConceptNameInfo().getName(),
5675 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5676 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5680 case Expr::RequiresExprClass: {
5686 if (RE->getLParenLoc().isValid()) {
5688 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5689 if (RE->getLocalParameters().empty()) {
5692 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5700 FunctionTypeDepth.enterResultType();
5701 for (
const concepts::Requirement *Req : RE->getRequirements())
5702 mangleRequirement(RE->getExprLoc(), Req);
5703 FunctionTypeDepth.pop(saved);
5707 for (
const concepts::Requirement *Req : RE->getRequirements())
5708 mangleRequirement(RE->getExprLoc(), Req);
5714 case Expr::DeclRefExprClass:
5719 case Expr::SubstNonTypeTemplateParmPackExprClass:
5725 Out <<
"_SUBSTPACK_";
5728 case Expr::FunctionParmPackExprClass: {
5732 Out <<
"v110_SUBSTPACK";
5737 case Expr::DependentScopeDeclRefExprClass: {
5746 case Expr::CXXBindTemporaryExprClass:
5750 case Expr::ExprWithCleanupsClass:
5754 case Expr::FloatingLiteralClass: {
5761 case Expr::FixedPointLiteralClass:
5763 mangleFixedPointLiteral();
5766 case Expr::CharacterLiteralClass:
5770 Out << cast<CharacterLiteral>(E)->getValue();
5775 case Expr::ObjCBoolLiteralExprClass:
5778 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5782 case Expr::CXXBoolLiteralExprClass:
5785 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5789 case Expr::IntegerLiteralClass: {
5793 Value.setIsSigned(
true);
5798 case Expr::ImaginaryLiteralClass: {
5805 if (
const FloatingLiteral *Imag =
5806 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5808 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5810 mangleFloat(Imag->getValue());
5815 Value.setIsSigned(
true);
5816 mangleNumber(
Value);
5822 case Expr::StringLiteralClass: {
5832 case Expr::GNUNullExprClass:
5835 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5838 case Expr::CXXNullPtrLiteralExprClass: {
5844 case Expr::LambdaExprClass: {
5855 case Expr::PackExpansionExprClass:
5861 case Expr::SizeOfPackExprClass: {
5864 if (SPE->isPartiallySubstituted()) {
5866 for (
const auto &A : SPE->getPartialArguments())
5867 mangleTemplateArg(A,
false);
5873 const NamedDecl *Pack = SPE->getPack();
5874 if (
const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
5875 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5876 else if (
const NonTypeTemplateParmDecl *NTTP
5877 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5878 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5879 else if (
const TemplateTemplateParmDecl *TempTP
5880 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5881 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5887 case Expr::MaterializeTemporaryExprClass:
5891 case Expr::CXXFoldExprClass: {
5894 if (FE->isLeftFold())
5895 Out << (FE->getInit() ?
"fL" :
"fl");
5897 Out << (FE->getInit() ?
"fR" :
"fr");
5899 if (FE->getOperator() == BO_PtrMemD)
5907 mangleExpression(FE->getLHS());
5909 mangleExpression(FE->getRHS());
5913 case Expr::CXXThisExprClass:
5918 case Expr::CoawaitExprClass:
5921 Out <<
"v18co_await";
5925 case Expr::DependentCoawaitExprClass:
5928 Out <<
"v18co_await";
5932 case Expr::CoyieldExprClass:
5935 Out <<
"v18co_yield";
5938 case Expr::SYCLUniqueStableNameExprClass: {
5942 Out <<
"u33__builtin_sycl_unique_stable_name";
5943 mangleType(USN->getTypeSourceInfo()->getType());
5948 case Expr::HLSLOutArgExprClass:
5950 "cannot mangle hlsl temporary value; mangling wrong thing?");
5951 case Expr::OpenACCAsteriskSizeExprClass: {
5953 DiagnosticsEngine &Diags = Context.getDiags();
5954 Diags.
Report(diag::err_unsupported_itanium_mangling)
5955 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
5960 if (AsTemplateArg && !IsPrimaryExpr)
5992void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
5999 assert(parmDepth < FunctionTypeDepth.getDepth());
6000 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
6001 if (FunctionTypeDepth.isInResultType())
6004 if (nestingDepth == 0) {
6007 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6015 &&
"parameter's type is still an array type?");
6017 if (
const DependentAddressSpaceType *DAST =
6018 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6025 if (parmIndex != 0) {
6026 Out << (parmIndex - 1);
6031void CXXNameMangler::mangleCXXCtorType(
CXXCtorType T,
6032 const CXXRecordDecl *InheritedFrom) {
6059 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6062 mangleName(InheritedFrom);
6065void CXXNameMangler::mangleCXXDtorType(
CXXDtorType T) {
6090 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6123 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6124 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6125 if (!RD || !RD->isGenericLambda())
6141 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6142 return TTP->hasTypeConstraint();
6159 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6160 return NTTP->getType()->isInstantiationDependentType() ||
6161 NTTP->getType()->getContainedDeducedType();
6168 "A DeducedTemplateName shouldn't escape partial ordering");
6179 auto MangleTemplateParamListToString =
6181 unsigned DepthOffset) {
6182 llvm::raw_svector_ostream Stream(Buffer);
6183 CXXNameMangler(
Mangler.Context, Stream,
6184 WithTemplateDepthOffset{DepthOffset})
6185 .mangleTemplateParameterList(Params);
6188 MangleTemplateParamListToString(ParamTemplateHead,
6189 TTP->getTemplateParameters(), 0);
6193 MangleTemplateParamListToString(ArgTemplateHead,
6195 TTP->getTemplateParameters()->
getDepth());
6196 return ParamTemplateHead != ArgTemplateHead;
6206 return {
true,
nullptr};
6211 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6212 "no parameter for argument");
6233 return {
true,
nullptr};
6248 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6249 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6250 return {NeedExactType,
nullptr};
6262void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6264 unsigned NumTemplateArgs) {
6267 TemplateArgManglingInfo Info(*
this, TN);
6268 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6269 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6271 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6275void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6276 const TemplateArgumentList &AL) {
6279 TemplateArgManglingInfo Info(*
this, TN);
6280 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6281 mangleTemplateArg(Info, i, AL[i]);
6283 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6287void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6288 ArrayRef<TemplateArgument> Args) {
6291 TemplateArgManglingInfo Info(*
this, TN);
6292 for (
unsigned i = 0; i != Args.size(); ++i) {
6293 mangleTemplateArg(Info, i, Args[i]);
6295 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6299void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6300 unsigned Index, TemplateArgument A) {
6301 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6304 if (ArgInfo.TemplateParameterToMangle &&
6305 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6312 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6315 mangleTemplateArg(A, ArgInfo.NeedExactType);
6318void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6328 llvm_unreachable(
"Cannot mangle NULL template argument");
6356 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6357 TPO->getValue(),
true,
6362 ASTContext &Ctx = Context.getASTContext();
6370 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6378 ArrayRef<APValue::LValuePathEntry>(),
6391 true, NeedExactType);
6397 mangleTemplateArg(P, NeedExactType);
6403void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6404 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6405 mangleExpression(E, UnknownArity,
true);
6420 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6421 const ValueDecl *D = DRE->getDecl();
6430 mangleExpression(E);
6443 switch (
V.getKind()) {
6451 assert(RD &&
"unexpected type for record value");
6460 if (!FD->isUnnamedBitField() &&
6470 assert(RD &&
"unexpected type for union value");
6473 if (!FD->isUnnamedBitField())
6483 QualType ElemT(T->getArrayElementTypeNoTypeQual(), 0);
6484 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6492 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6499 llvm_unreachable(
"Matrix APValues not yet supported");
6505 return V.getFloat().isPosZero();
6508 return !
V.getFixedPoint().getValue();
6511 return V.getComplexFloatReal().isPosZero() &&
6512 V.getComplexFloatImag().isPosZero();
6515 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6518 return V.isNullPointer();
6521 return !
V.getMemberPointerDecl();
6524 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6531 T = AT->getElementType();
6533 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6576 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6577 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6582void CXXNameMangler::mangleValueInTemplateArg(QualType T,
const APValue &
V,
6584 bool NeedExactType) {
6587 T = getASTContext().getUnqualifiedArrayType(T, Quals);
6590 bool IsPrimaryExpr =
true;
6591 auto NotPrimaryExpr = [&] {
6592 if (TopLevel && IsPrimaryExpr)
6594 IsPrimaryExpr =
false;
6598 switch (
V.getKind()) {
6607 llvm_unreachable(
"unexpected value kind in template argument");
6611 assert(RD &&
"unexpected type for record value");
6614 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6617 (Fields.back()->isUnnamedBitField() ||
6619 V.getStructField(Fields.back()->getFieldIndex())))) {
6623 if (Fields.empty()) {
6624 while (!Bases.empty() &&
6626 V.getStructBase(Bases.size() - 1)))
6627 Bases = Bases.drop_back();
6634 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6635 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6636 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6637 if (Fields[I]->isUnnamedBitField())
6639 mangleValueInTemplateArg(Fields[I]->
getType(),
6640 V.getStructField(Fields[I]->getFieldIndex()),
6649 const FieldDecl *FD =
V.getUnionField();
6667 mangleSourceName(II);
6668 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6682 unsigned N =
V.getArraySize();
6684 N =
V.getArrayInitializedElts();
6689 for (
unsigned I = 0; I != N; ++I) {
6690 const APValue &Elem = I <
V.getArrayInitializedElts()
6691 ?
V.getArrayInitializedElt(I)
6692 :
V.getArrayFiller();
6693 mangleValueInTemplateArg(ElemT, Elem,
false);
6700 const VectorType *VT = T->
castAs<VectorType>();
6705 unsigned N =
V.getVectorLength();
6708 for (
unsigned I = 0; I != N; ++I)
6709 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6715 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6718 mangleIntegerLiteral(T,
V.getInt());
6722 mangleFloatLiteral(T,
V.getFloat());
6726 mangleFixedPointLiteral();
6730 const ComplexType *CT = T->
castAs<ComplexType>();
6734 if (!
V.getComplexFloatReal().isPosZero() ||
6735 !
V.getComplexFloatImag().isPosZero())
6737 if (!
V.getComplexFloatImag().isPosZero())
6744 const ComplexType *CT = T->
castAs<ComplexType>();
6748 if (
V.getComplexIntReal().getBoolValue() ||
6749 V.getComplexIntImag().getBoolValue())
6751 if (
V.getComplexIntImag().getBoolValue())
6760 "unexpected type for LValue template arg");
6762 if (
V.isNullPointer()) {
6763 mangleNullPointer(T);
6767 APValue::LValueBase B =
V.getLValueBase();
6771 CharUnits Offset =
V.getLValueOffset();
6789 ASTContext &Ctx = Context.getASTContext();
6792 if (!
V.hasLValuePath()) {
6808 bool IsArrayToPointerDecayMangledAsDecl =
false;
6809 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6810 LangOptions::ClangABI::Ver11) {
6812 IsArrayToPointerDecayMangledAsDecl =
6813 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6814 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6818 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6819 !IsArrayToPointerDecayMangledAsDecl) {
6836 if (NeedExactType &&
6838 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6851 QualType TypeSoFar = B.
getType();
6852 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6856 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6858 mangleExpression(E);
6859 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6862 mangleType(QualType(TI.getType(), 0));
6865 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6875 mangleNumber(
V.getLValueOffset().getQuantity());
6882 if (!
V.getLValueOffset().isZero())
6883 mangleNumber(
V.getLValueOffset().getQuantity());
6887 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6889 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6891 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6892 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6893 TypeSoFar = AT->getElementType();
6895 const Decl *D = E.getAsBaseOrMember().getPointer();
6896 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6921 if (!
V.getMemberPointerDecl()) {
6922 mangleNullPointer(T);
6926 ASTContext &Ctx = Context.getASTContext();
6929 if (!
V.getMemberPointerPath().empty()) {
6932 }
else if (NeedExactType &&
6934 T->
castAs<MemberPointerType>()->getPointeeType(),
6935 V.getMemberPointerDecl()->getType()) &&
6936 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6941 mangle(
V.getMemberPointerDecl());
6943 if (!
V.getMemberPointerPath().empty()) {
6953 if (TopLevel && !IsPrimaryExpr)
6957void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6967 Depth += TemplateDepthOffset;
6969 Out <<
'L' << (Depth - 1) <<
'_';
6975void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6978 }
else if (SeqID == 1) {
6985 MutableArrayRef<char> BufferRef(Buffer);
6986 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
6988 for (; SeqID != 0; SeqID /= 36) {
6989 unsigned C = SeqID % 36;
6990 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
6993 Out.write(I.base(), I - BufferRef.rbegin());
6998void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
6999 bool result = mangleSubstitution(tname);
7000 assert(result &&
"no existing substitution for template name");
7006bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7008 if (mangleStandardSubstitution(ND))
7012 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7022bool CXXNameMangler::mangleSubstitution(QualType T) {
7025 return mangleSubstitution(RD);
7030 return mangleSubstitution(TypePtr);
7034 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7035 return mangleSubstitution(TD);
7038 return mangleSubstitution(
7042bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7043 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7044 if (I == Substitutions.end())
7047 unsigned SeqID = I->second;
7056bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7065 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7066 if (!SD || !SD->getIdentifier()->isStr(Name))
7069 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7072 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7073 if (TemplateArgs.
size() != 1)
7076 if (TemplateArgs[0].getAsType() != A)
7079 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7088bool CXXNameMangler::isStdCharSpecialization(
7089 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7090 bool HasAllocator) {
7095 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7098 QualType A = TemplateArgs[0].getAsType();
7106 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7110 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7119bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7121 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7129 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7130 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7150 if (
const ClassTemplateSpecializationDecl *SD =
7151 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7152 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7161 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7168 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7175 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7182 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7192void CXXNameMangler::addSubstitution(QualType T) {
7195 addSubstitution(RD);
7201 addSubstitution(TypePtr);
7205 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7206 return addSubstitution(TD);
7212void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7213 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7214 Substitutions[Ptr] = SeqID++;
7217void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7218 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7219 if (
Other->SeqID > SeqID) {
7220 Substitutions.swap(
Other->Substitutions);
7221 SeqID =
Other->SeqID;
7225CXXNameMangler::AbiTagList
7226CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7228 if (DisableDerivedAbiTags)
7229 return AbiTagList();
7231 llvm::raw_null_ostream NullOutStream;
7232 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7233 TrackReturnTypeTags.disableDerivedAbiTags();
7235 const FunctionProtoType *Proto =
7237 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7238 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
7240 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
7241 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7243 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7246CXXNameMangler::AbiTagList
7247CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7249 if (DisableDerivedAbiTags)
7250 return AbiTagList();
7252 llvm::raw_null_ostream NullOutStream;
7253 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7254 TrackVariableType.disableDerivedAbiTags();
7256 TrackVariableType.mangleType(VD->
getType());
7258 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7261bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7262 const VarDecl *VD) {
7263 llvm::raw_null_ostream NullOutStream;
7264 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7265 TrackAbiTags.mangle(VD);
7266 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7279void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7283 "Invalid mangleName() call, argument is not a variable or function!");
7285 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7286 getASTContext().getSourceManager(),
7287 "Mangling declaration");
7289 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7291 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7292 return Mangler.mangle(GlobalDecl(CD,
Type));
7295 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7297 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7298 return Mangler.mangle(GlobalDecl(DD,
Type));
7301 CXXNameMangler Mangler(*
this, Out, D);
7305void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7307 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7311void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7313 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7335 auto &LangOpts = Context.getLangOpts();
7338 Context.baseForVTableAuthentication(ThisRD);
7339 unsigned TypedDiscriminator =
7340 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7341 Mangler.mangleVendorQualifier(
"__vtptrauth");
7342 auto &ManglerStream = Mangler.getStream();
7343 ManglerStream <<
"I";
7344 if (
const auto *ExplicitAuth =
7345 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7346 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7348 if (ExplicitAuth->getAddressDiscrimination() ==
7349 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7350 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7352 ManglerStream <<
"Lb"
7353 << (ExplicitAuth->getAddressDiscrimination() ==
7354 VTablePointerAuthenticationAttr::AddressDiscrimination);
7356 switch (ExplicitAuth->getExtraDiscrimination()) {
7357 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7358 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7359 ManglerStream <<
"Lj" << TypedDiscriminator;
7361 ManglerStream <<
"Lj" << 0;
7364 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7365 ManglerStream <<
"Lj" << TypedDiscriminator;
7367 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7368 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7370 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7371 ManglerStream <<
"Lj" << 0;
7375 ManglerStream <<
"Lj"
7376 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7377 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7378 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7379 ManglerStream <<
"Lj" << TypedDiscriminator;
7381 ManglerStream <<
"Lj" << 0;
7383 ManglerStream <<
"E";
7386void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7387 const ThunkInfo &Thunk,
7388 bool ElideOverrideInfo,
7398 "Use mangleCXXDtor for destructor decls!");
7399 CXXNameMangler Mangler(*
this, Out);
7400 Mangler.getStream() <<
"_ZT";
7402 Mangler.getStream() <<
'c';
7413 Mangler.mangleFunctionEncoding(MD);
7414 if (!ElideOverrideInfo)
7418void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7420 const ThunkInfo &Thunk,
7421 bool ElideOverrideInfo,
7425 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7426 Mangler.getStream() <<
"_ZT";
7428 auto &ThisAdjustment = Thunk.
This;
7430 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7431 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7433 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7434 if (!ElideOverrideInfo)
7439void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7443 CXXNameMangler Mangler(*
this, Out);
7446 Mangler.getStream() <<
"_ZGV";
7447 Mangler.mangleName(D);
7450void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7455 Out <<
"__cxx_global_var_init";
7458void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7461 CXXNameMangler Mangler(*
this, Out);
7462 Mangler.getStream() <<
"__dtor_";
7463 if (shouldMangleDeclName(D))
7466 Mangler.getStream() << D->
getName();
7469void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7473 CXXNameMangler Mangler(*
this, Out);
7474 Mangler.getStream() <<
"__finalize_";
7475 if (shouldMangleDeclName(D))
7478 Mangler.getStream() << D->
getName();
7481void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7482 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7483 CXXNameMangler Mangler(*
this, Out);
7484 Mangler.getStream() <<
"__filt_";
7486 if (shouldMangleDeclName(EnclosingFD))
7487 Mangler.mangle(EnclosingDecl);
7489 Mangler.getStream() << EnclosingFD->getName();
7492void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7493 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7494 CXXNameMangler Mangler(*
this, Out);
7495 Mangler.getStream() <<
"__fin_";
7497 if (shouldMangleDeclName(EnclosingFD))
7498 Mangler.mangle(EnclosingDecl);
7500 Mangler.getStream() << EnclosingFD->getName();
7503void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7506 CXXNameMangler Mangler(*
this, Out);
7507 Mangler.getStream() <<
"_ZTH";
7508 Mangler.mangleName(D);
7512ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7515 CXXNameMangler Mangler(*
this, Out);
7516 Mangler.getStream() <<
"_ZTW";
7517 Mangler.mangleName(D);
7520void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7521 unsigned ManglingNumber,
7525 CXXNameMangler Mangler(*
this, Out);
7526 Mangler.getStream() <<
"_ZGR";
7527 Mangler.mangleName(D);
7528 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7529 Mangler.mangleSeqID(ManglingNumber - 1);
7532void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7535 CXXNameMangler Mangler(*
this, Out);
7536 Mangler.getStream() <<
"_ZTV";
7537 Mangler.mangleCXXRecordDecl(RD);
7540void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7543 CXXNameMangler Mangler(*
this, Out);
7544 Mangler.getStream() <<
"_ZTT";
7545 Mangler.mangleCXXRecordDecl(RD);
7548void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7550 const CXXRecordDecl *
Type,
7553 CXXNameMangler Mangler(*
this, Out);
7554 Mangler.getStream() <<
"_ZTC";
7557 bool SuppressSubstitution =
7558 getASTContext().getLangOpts().getClangABICompat() <=
7559 LangOptions::ClangABI::Ver19;
7560 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7561 Mangler.getStream() << Offset;
7562 Mangler.getStream() <<
'_';
7563 Mangler.mangleCXXRecordDecl(
Type);
7566void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7568 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7569 CXXNameMangler Mangler(*
this, Out);
7570 Mangler.getStream() <<
"_ZTI";
7571 Mangler.mangleType(Ty);
7574void ItaniumMangleContextImpl::mangleCXXRTTIName(
7575 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7577 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7578 Mangler.getStream() <<
"_ZTS";
7579 Mangler.mangleType(Ty);
7582void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7583 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7584 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7587void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7588 llvm_unreachable(
"Can't mangle string literals");
7591void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7593 CXXNameMangler Mangler(*
this, Out);
7594 Mangler.mangleLambdaSig(Lambda);
7597void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7600 CXXNameMangler Mangler(*
this, Out);
7601 Mangler.getStream() <<
"_ZGI";
7605 auto Partition = M->
Name.find(
':');
7606 Mangler.mangleModuleNamePrefix(
7607 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7615 return new ItaniumMangleContextImpl(
7618 return std::nullopt;
7627 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 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
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 ...
bool isFunctionOrMethod() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
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 hasLinkage() const
Determine whether this declaration has linkage.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
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,...
bool isDependentAddressSpaceType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
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)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ Type
The name was classified as a type.
@ Concept
The name was classified as a concept name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
@ Other
Other implicit parameter.
@ EST_Dynamic
throw(T1, T2)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Information about how to mangle a template argument.
bool NeedExactType
Do we need to mangle the template argument with an exactly correct type?
const NamedDecl * TemplateParameterToMangle
If we need to prefix the mangling with a mangling of the template parameter, the corresponding parame...
bool isOverloadable()
Determine whether the resolved template might be overloaded on its template parameter list.
TemplateArgManglingInfo(const CXXNameMangler &Mangler, TemplateName TN)
bool needToMangleTemplateParam(const NamedDecl *Param, const TemplateArgument &Arg)
Determine whether we need to prefix this <template-arg> mangling with a <template-param-decl>.
const NamedDecl * UnresolvedExpandedPack
const CXXNameMangler & Mangler
TemplateDecl * ResolvedTemplate
Info getArgInfo(unsigned ParamIdx, const TemplateArgument &Arg)
Determine information about how this template argument should be mangled.
const Expr * getTrailingRequiresClauseToMangle()
Determine if we should mangle a requires-clause after the template argument list.
bool SeenPackExpansionIntoNonPack
ArrayRef< TemplateArgumentLoc > arguments() const
const Expr * ConstraintExpr
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
The this pointer adjustment as well as an optional return adjustment for a thunk.
ThisAdjustment This
The this pointer adjustment.
ReturnAdjustment Return
The return adjustment.
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.