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) {
48 return isa<FunctionDecl, ObjCMethodDecl, BlockDecl, CXXExpansionStmtDecl,
49 TopLevelStmtDecl>(DC);
52static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
54 return ftd->getTemplatedDecl();
59static const NamedDecl *getStructor(
const NamedDecl *
decl) {
60 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
61 return (fn ? getStructor(fn) :
decl);
64static bool isLambda(
const NamedDecl *ND) {
65 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
72static const unsigned UnknownArity = ~0U;
74class ItaniumMangleContextImpl :
public ItaniumMangleContext {
75 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
76 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
77 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
78 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
79 NamespaceDecl *StdNamespace =
nullptr;
81 bool NeedsUniqueInternalLinkageNames =
false;
84 explicit ItaniumMangleContextImpl(
85 ASTContext &Context, DiagnosticsEngine &Diags,
86 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
87 : ItaniumMangleContext(Context, Diags, IsAux),
88 DiscriminatorOverride(DiscriminatorOverride) {}
93 bool shouldMangleCXXName(
const NamedDecl *D)
override;
94 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
99 void needsUniqueInternalLinkageNames()
override {
100 NeedsUniqueInternalLinkageNames =
true;
103 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
104 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
105 raw_ostream &)
override;
107 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
108 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
109 raw_ostream &)
override;
110 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
112 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
113 const CXXRecordDecl *
Type, raw_ostream &)
override;
114 void mangleCXXRTTI(QualType
T, raw_ostream &)
override;
115 void mangleCXXRTTIName(QualType
T, raw_ostream &,
116 bool NormalizeIntegers)
override;
117 void mangleCanonicalTypeName(QualType
T, raw_ostream &,
118 bool NormalizeIntegers)
override;
120 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
121 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
122 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
123 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
124 void mangleDynamicAtExitDestructor(
const VarDecl *D,
125 raw_ostream &Out)
override;
126 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
127 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
128 raw_ostream &Out)
override;
129 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
130 raw_ostream &Out)
override;
131 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
132 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
133 raw_ostream &)
override;
135 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
137 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
139 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
141 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
147 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
148 Tag &&
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 {
248 unsigned InFunctionDeclSuffix : 1;
251 FunctionTypeDepthState() : Depth(0), InFunctionDeclSuffix(0) {}
253 unsigned getNestingDepth(
unsigned ParmDepth)
const {
256 assert(ParmDepth < Depth &&
257 "ParmVarDecl is not visible in current parameter environment");
258 return Depth - ParmDepth - InFunctionDeclSuffix;
261 FunctionTypeDepthState push() {
262 FunctionTypeDepthState Saved = *
this;
264 InFunctionDeclSuffix = 0;
268 void pop(FunctionTypeDepthState Saved) {
269 assert(Depth == Saved.Depth + 1 &&
"unbalanced function type depth pop");
273 void enterFunctionDeclSuffix() { InFunctionDeclSuffix = 1; }
274 void leaveFunctionDeclSuffix() { InFunctionDeclSuffix = 0; }
281 using AbiTagList = SmallVector<StringRef, 4>;
286 class AbiTagState final {
288 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
294 AbiTagState(
const AbiTagState &) =
delete;
295 AbiTagState &operator=(
const AbiTagState &) =
delete;
297 ~AbiTagState() { pop(); }
299 void write(raw_ostream &Out,
const NamedDecl *ND,
300 ArrayRef<StringRef> AdditionalAbiTags) {
304 AdditionalAbiTags.empty() &&
305 "only function and variables need a list of additional abi tags");
306 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
307 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
308 llvm::append_range(UsedAbiTags, AbiTag->tags());
315 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
316 llvm::append_range(UsedAbiTags, AbiTag->tags());
317 llvm::append_range(TagList, AbiTag->tags());
320 llvm::append_range(UsedAbiTags, AdditionalAbiTags);
321 llvm::append_range(TagList, AdditionalAbiTags);
324 TagList.erase(llvm::unique(TagList), TagList.end());
326 writeSortedUniqueAbiTags(Out, TagList);
329 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
330 void setUsedAbiTags(
const AbiTagList &AbiTags) {
331 UsedAbiTags = AbiTags;
334 const AbiTagList &getEmittedAbiTags()
const {
335 return EmittedAbiTags;
338 const AbiTagList &getSortedUniqueUsedAbiTags() {
339 llvm::sort(UsedAbiTags);
340 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
346 AbiTagList UsedAbiTags;
348 AbiTagList EmittedAbiTags;
350 AbiTagState *&LinkHead;
351 AbiTagState *Parent =
nullptr;
354 assert(LinkHead ==
this &&
355 "abi tag link head must point to us on destruction");
357 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
358 UsedAbiTags.begin(), UsedAbiTags.end());
359 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
360 EmittedAbiTags.begin(),
361 EmittedAbiTags.end());
366 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
367 for (
const auto &Tag : AbiTags) {
368 EmittedAbiTags.push_back(Tag);
376 AbiTagState *AbiTags =
nullptr;
377 AbiTagState AbiTagsRoot;
379 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
380 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
382 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
384 bool isCompatibleWith(LangOptions::ClangABI Ver) {
388 bool isStd(
const NamespaceDecl *NS);
389 bool isStdNamespace(
const DeclContext *DC);
391 const RecordDecl *GetLocalClassDecl(
const Decl *D);
392 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
393 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
394 llvm::StringRef Name,
bool HasAllocator);
397 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
398 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
399 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
400 AbiTagsRoot(AbiTags) {
405 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
407 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
408 AbiTagsRoot(AbiTags) {}
409 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
411 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
412 AbiTagsRoot(AbiTags) {}
414 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
415 bool NormalizeIntegers_)
416 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
417 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
418 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
419 : Context(Outer.Context),
Out(Out_),
420 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
421 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
422 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
423 Substitutions(Outer.Substitutions),
424 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
426 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
427 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
431 struct WithTemplateDepthOffset {
unsigned Offset; };
432 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
433 WithTemplateDepthOffset Offset)
434 : CXXNameMangler(
C,
Out) {
435 TemplateDepthOffset = Offset.Offset;
438 raw_ostream &getStream() {
return Out; }
440 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
441 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
443 void mangle(GlobalDecl GD);
444 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
445 void mangleNumber(
const llvm::APSInt &I);
446 void mangleNumber(int64_t Number);
447 void mangleFloat(
const llvm::APFloat &F);
448 void mangleFunctionEncoding(GlobalDecl GD);
449 void mangleSeqID(
unsigned SeqID);
450 void mangleName(GlobalDecl GD);
451 void mangleType(QualType
T);
452 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
453 bool SuppressSubstitution =
false);
454 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
455 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
456 void mangleVendorQualifier(StringRef Name);
457 void mangleVendorType(StringRef Name);
460 bool mangleSubstitution(
const NamedDecl *ND);
461 bool mangleSubstitution(QualType
T);
467 bool mangleStandardSubstitution(
const NamedDecl *ND);
469 void addSubstitution(
const NamedDecl *ND) {
472 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
474 void addSubstitution(QualType
T);
478 void extendSubstitutions(CXXNameMangler*
Other);
480 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
481 bool recursive =
false);
482 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
483 const TemplateArgumentLoc *TemplateArgs,
484 unsigned NumTemplateArgs,
485 unsigned KnownArity = UnknownArity);
487 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
489 void mangleNameWithAbiTags(GlobalDecl GD,
490 ArrayRef<StringRef> AdditionalAbiTags = {});
491 void mangleModuleName(
const NamedDecl *ND);
492 void mangleTemplateName(
const TemplateDecl *TD,
493 ArrayRef<TemplateArgument> Args);
494 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
495 ArrayRef<StringRef> AdditionalAbiTags = {}) {
497 UnknownArity, AdditionalAbiTags);
499 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
500 const DeclContext *DC,
unsigned KnownArity,
501 ArrayRef<StringRef> AdditionalAbiTags);
502 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
503 ArrayRef<StringRef> AdditionalAbiTags = {});
504 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
505 ArrayRef<StringRef> AdditionalAbiTags = {});
506 void mangleSourceName(
const IdentifierInfo *II);
507 void mangleConstructorName(
const CXXConstructorDecl *CCD,
508 ArrayRef<StringRef> AdditionalAbiTags = {});
509 void mangleDestructorName(
const CXXDestructorDecl *CDD,
510 ArrayRef<StringRef> AdditionalAbiTags = {});
511 void mangleRegCallName(
const IdentifierInfo *II);
512 void mangleDeviceStubName(
const IdentifierInfo *II);
513 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
514 void mangleSourceNameWithAbiTags(
const NamedDecl *ND,
515 ArrayRef<StringRef> AdditionalAbiTags = {});
516 void mangleLocalName(GlobalDecl GD,
517 ArrayRef<StringRef> AdditionalAbiTags = {});
518 void mangleBlockForPrefix(
const BlockDecl *
Block);
519 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
520 void mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D);
521 void mangleTemplateParamDecl(
const NamedDecl *Decl);
522 void mangleTemplateParameterList(
const TemplateParameterList *Params);
524 ArrayRef<TemplateArgument> Arguments);
525 void mangleTypeConstraint(
const TypeConstraint *Constraint);
526 void mangleRequiresClause(
const Expr *RequiresClause);
527 void mangleLambda(
const CXXRecordDecl *Lambda);
528 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
529 ArrayRef<StringRef> AdditionalAbiTags = {},
530 bool NoFunction =
false);
531 void mangleNestedName(
const TemplateDecl *TD,
532 ArrayRef<TemplateArgument> Args);
533 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
534 const NamedDecl *PrefixND,
535 ArrayRef<StringRef> AdditionalAbiTags,
536 bool NoFunction =
false);
537 void manglePrefix(NestedNameSpecifier Qualifier);
538 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
539 void manglePrefix(QualType
type);
540 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
542 void DiagnoseUnsupportedPackIndexTemplateName();
543 const NamedDecl *getClosurePrefix(
const Decl *ND);
544 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
545 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
546 StringRef Prefix =
"");
547 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
549 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
555#define ABSTRACT_TYPE(CLASS, PARENT)
556#define NON_CANONICAL_TYPE(CLASS, PARENT)
557#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
558#include "clang/AST/TypeNodes.inc"
560 void mangleType(
const TagType*);
562 static StringRef getCallingConvQualifierName(
CallingConv CC);
565 void mangleSMEAttrs(
unsigned SMEAttrs);
570 void mangleAArch64NeonVectorType(
const VectorType *
T);
572 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
574 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
578 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
579 void mangleFixedPointLiteral();
582 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
583 void mangleMemberExpr(
const Expr *base,
bool isArrow,
587 unsigned NumTemplateArgs,
unsigned knownArity);
588 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
589 void mangleInitListElements(
const InitListExpr *InitList);
592 void mangleReferenceToPack(
const NamedDecl *ND);
593 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
594 bool AsTemplateArg =
false);
598 struct TemplateArgManglingInfo;
601 unsigned NumTemplateArgs);
604 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
607 void mangleTemplateArgExpr(
const Expr *E);
609 bool NeedExactType =
false);
611 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
619 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
621 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
629 getASTContext(), getASTContext().getTranslationUnitDecl(),
630 false, SourceLocation(), SourceLocation(),
631 &getASTContext().Idents.get(
"std"),
654ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
661 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
663 if (ParmVarDecl *ContextParam =
664 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
665 return ContextParam->getDeclContext();
669 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
670 if (ParmVarDecl *ContextParam =
671 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
672 return ContextParam->getDeclContext();
680 if (D == getASTContext().getVaListTagDecl()) {
681 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
682 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
683 return getStdNamespace();
689 return getEffectiveDeclContext(
cast<Decl>(DC));
692 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
694 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
698 if (isLocalContainerContext(ParentDC))
702 return getASTContext().getTranslationUnitDecl();
705 if (
const auto *FD = !getASTContext().getLangOpts().isCompatibleWith(
706 LangOptions::ClangABI::Ver19)
708 : dyn_cast<FunctionDecl>(D)) {
710 return getASTContext().getTranslationUnitDecl();
713 if (FD->isMemberLikeConstrainedFriend() &&
714 !getASTContext().getLangOpts().isCompatibleWith(
715 LangOptions::ClangABI::Ver17))
722bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
725 getEffectiveDeclContext(ND)->isFileContext() &&
732bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
733 const NamedDecl *ND) {
734 if (!NeedsUniqueInternalLinkageNames || !ND)
737 const auto *FD = dyn_cast<FunctionDecl>(ND);
743 if (!FD->getType()->getAs<FunctionProtoType>())
746 if (isInternalLinkageDecl(ND))
752bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
753 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
756 if (FD->hasAttr<OverloadableAttr>())
772 if (FD->isMSVCRTEntryPoint())
786 if (!getASTContext().getLangOpts().
CPlusPlus)
789 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
800 const DeclContext *DC = getEffectiveDeclContext(D);
802 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
804 !VD->getOwningModuleForLinkage())
811void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
812 ArrayRef<StringRef> AdditionalAbiTags) {
813 assert(AbiTags &&
"require AbiTagState");
814 AbiTags->write(Out, ND,
815 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
816 : AdditionalAbiTags);
819void CXXNameMangler::mangleSourceNameWithAbiTags(
820 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
822 writeAbiTags(ND, AdditionalAbiTags);
825void CXXNameMangler::mangle(GlobalDecl GD) {
831 mangleFunctionEncoding(GD);
832 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
835 else if (
const IndirectFieldDecl *IFD =
836 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
837 mangleName(IFD->getAnonField());
839 llvm_unreachable(
"unexpected kind of global decl");
842void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
847 if (!Context.shouldMangleDeclName(FD)) {
852 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
853 if (ReturnTypeAbiTags.empty()) {
862 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
864 FunctionTypeDepth.pop(Saved);
865 mangleFunctionEncodingBareType(FD);
872 SmallString<256> FunctionEncodingBuf;
873 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
874 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
876 FunctionEncodingMangler.disableDerivedAbiTags();
878 FunctionTypeDepthState EncodingSaved =
879 FunctionEncodingMangler.FunctionTypeDepth.push();
880 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
881 FunctionEncodingMangler.FunctionTypeDepth.pop(EncodingSaved);
884 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
885 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
889 const AbiTagList &UsedAbiTags =
890 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
891 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
892 AdditionalAbiTags.erase(
893 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
894 UsedAbiTags.begin(), UsedAbiTags.end(),
895 AdditionalAbiTags.begin()),
896 AdditionalAbiTags.end());
899 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
900 mangleNameWithAbiTags(FD, AdditionalAbiTags);
901 FunctionTypeDepth.pop(Saved);
902 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
906 extendSubstitutions(&FunctionEncodingMangler);
909void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
910 if (FD->
hasAttr<EnableIfAttr>()) {
911 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
912 Out <<
"Ua9enable_ifI";
913 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
916 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
919 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
924 mangleExpression(EIA->getCond());
927 mangleTemplateArgExpr(EIA->getCond());
931 FunctionTypeDepth.pop(Saved);
936 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
937 if (
auto Inherited = CD->getInheritedConstructor())
938 FD = Inherited.getConstructor();
956 bool MangleReturnType =
false;
960 MangleReturnType =
true;
963 FD = PrimaryTemplate->getTemplatedDecl();
966 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
967 MangleReturnType, FD);
971bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
972 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
976 return II && II->
isStr(
"std");
981bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
988static const GlobalDecl
992 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1001 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1002 TemplateArgs = &Spec->getTemplateArgs();
1003 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1008 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1009 TemplateArgs = &Spec->getTemplateArgs();
1010 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1021void CXXNameMangler::mangleName(GlobalDecl GD) {
1023 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1025 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1026 if (VariableTypeAbiTags.empty()) {
1028 mangleNameWithAbiTags(VD);
1033 llvm::raw_null_ostream NullOutStream;
1034 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1035 VariableNameMangler.disableDerivedAbiTags();
1036 VariableNameMangler.mangleNameWithAbiTags(VD);
1039 const AbiTagList &UsedAbiTags =
1040 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1041 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1042 AdditionalAbiTags.erase(
1043 std::set_difference(VariableTypeAbiTags.begin(),
1044 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1045 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1046 AdditionalAbiTags.end());
1049 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1051 mangleNameWithAbiTags(GD);
1055const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1056 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1058 if (isLocalContainerContext(DC))
1059 return dyn_cast<RecordDecl>(D);
1061 DC = Context.getEffectiveDeclContext(D);
1066void CXXNameMangler::mangleNameWithAbiTags(
1067 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1074 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1076 if (GetLocalClassDecl(ND) &&
1077 (!isLambda(ND) || isCompatibleWith(LangOptions::ClangABI::Ver18) ||
1078 !isCompatibleWith(LangOptions::ClangABI::Ver22))) {
1079 mangleLocalName(GD, AdditionalAbiTags);
1087 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1088 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1092 if (isLocalContainerContext(DC)) {
1093 mangleLocalName(GD, AdditionalAbiTags);
1102 const TemplateArgumentList *TemplateArgs =
nullptr;
1103 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1104 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1109 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1113 mangleNestedName(GD, DC, AdditionalAbiTags);
1116void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1119 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1127void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1129 if (
auto It = ModuleSubstitutions.find(Name);
1130 It != ModuleSubstitutions.end()) {
1132 mangleSeqID(It->second);
1138 auto [Prefix, SubName] = Name.rsplit(
'.');
1139 if (SubName.empty())
1142 mangleModuleNamePrefix(Prefix, IsPartition);
1143 IsPartition =
false;
1149 Out << SubName.size() << SubName;
1150 ModuleSubstitutions.insert({Name, SeqID++});
1153void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1154 ArrayRef<TemplateArgument> Args) {
1155 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1158 mangleUnscopedTemplateName(TD, DC);
1161 mangleNestedName(TD, Args);
1165void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1166 ArrayRef<StringRef> AdditionalAbiTags) {
1171 if (isStdNamespace(DC)) {
1172 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1174 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1179 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1181 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1191 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1194void CXXNameMangler::mangleUnscopedTemplateName(
1195 GlobalDecl GD,
const DeclContext *DC,
1196 ArrayRef<StringRef> AdditionalAbiTags) {
1200 if (mangleSubstitution(ND))
1204 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1205 assert(AdditionalAbiTags.empty() &&
1206 "template template param cannot have abi tags");
1207 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1209 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1215 addSubstitution(ND);
1218void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1232 llvm::APInt valueBits = f.bitcastToAPInt();
1233 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1234 assert(numCharacters != 0);
1237 SmallVector<char, 20> buffer(numCharacters);
1240 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1242 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1245 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1246 hexDigit >>= (digitBitIndex % 64);
1250 static const char charForHex[16] = {
1251 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1252 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1254 buffer[stringIndex] = charForHex[hexDigit];
1257 Out.write(buffer.data(), numCharacters);
1260void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1267void CXXNameMangler::mangleFixedPointLiteral() {
1268 DiagnosticsEngine &Diags = Context.getDiags();
1269 Diags.
Report(diag::err_unsupported_itanium_mangling)
1270 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1273void CXXNameMangler::DiagnoseUnsupportedPackIndexTemplateName() {
1274 DiagnosticsEngine &Diags = Context.getDiags();
1275 Diags.
Report(diag::err_unsupported_itanium_mangling)
1276 << UnsupportedItaniumManglingKind::PackIndexTemplateName;
1279void CXXNameMangler::mangleNullPointer(QualType
T) {
1286void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1287 if (
Value.isSigned() &&
Value.isNegative()) {
1289 Value.abs().print(Out,
false);
1291 Value.print(Out,
false);
1295void CXXNameMangler::mangleNumber(int64_t Number) {
1305void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1313 mangleNumber(NonVirtual);
1319 mangleNumber(NonVirtual);
1325void CXXNameMangler::manglePrefix(QualType
type) {
1326 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1327 if (!mangleSubstitution(QualType(TST, 0))) {
1328 mangleTemplatePrefix(TST->getTemplateName());
1333 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1334 addSubstitution(QualType(TST, 0));
1336 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1338 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1339 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1344 assert(DNT->getQualifier());
1345 manglePrefix(DNT->getQualifier());
1347 mangleSourceName(DNT->getIdentifier());
1350 addSubstitution(QualType(DNT, 0));
1362void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1380 case NestedNameSpecifier::Kind::Null:
1381 llvm_unreachable(
"unexpected null nested name specifier");
1383 case NestedNameSpecifier::Kind::Global:
1393 case NestedNameSpecifier::Kind::MicrosoftSuper:
1394 llvm_unreachable(
"Can't mangle __super specifier");
1396 case NestedNameSpecifier::Kind::Namespace: {
1399 mangleUnresolvedPrefix(Prefix,
1403 mangleSourceNameWithAbiTags(Namespace);
1407 case NestedNameSpecifier::Kind::Type: {
1415 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1416 mangleUnresolvedPrefix(Prefix,
1423 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1438void CXXNameMangler::mangleUnresolvedName(
1439 NestedNameSpecifier Qualifier, DeclarationName name,
1440 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1441 unsigned knownArity) {
1443 mangleUnresolvedPrefix(Qualifier);
1444 switch (
name.getNameKind()) {
1447 mangleSourceName(
name.getAsIdentifierInfo());
1452 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1459 mangleOperatorName(name, knownArity);
1462 llvm_unreachable(
"Can't mangle a constructor name!");
1464 llvm_unreachable(
"Can't mangle a using directive name!");
1466 llvm_unreachable(
"Can't mangle a deduction guide name!");
1470 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1476 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1479void CXXNameMangler::mangleUnqualifiedName(
1480 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1481 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1482 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1489 mangleModuleName(ND);
1493 auto *FD = dyn_cast<FunctionDecl>(ND);
1494 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1496 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1497 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1501 unsigned Arity = KnownArity;
1507 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1514 for (
auto *BD : DD->bindings())
1515 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1517 writeAbiTags(ND, AdditionalAbiTags);
1521 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1524 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1525 llvm::raw_svector_ostream GUIDOS(GUID);
1526 Context.mangleMSGuidDecl(GD, GUIDOS);
1527 Out << GUID.size() << GUID;
1531 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1534 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1535 TPO->getValue(),
true);
1553 if (Context.isInternalLinkageDecl(ND))
1556 bool IsRegCall = FD &&
1560 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1562 bool IsOCLDeviceStub =
1564 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1567 mangleDeviceStubName(II);
1568 else if (IsOCLDeviceStub)
1569 mangleOCLDeviceStubName(II);
1571 mangleRegCallName(II);
1573 mangleSourceName(II);
1575 writeAbiTags(ND, AdditionalAbiTags);
1580 assert(ND &&
"mangling empty name without declaration");
1582 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1585 Out <<
"12_GLOBAL__N_1";
1590 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1592 const auto *RD = VD->getType()->castAsRecordDecl();
1603 assert(RD->isAnonymousStructOrUnion()
1604 &&
"Expected anonymous struct or union!");
1605 const FieldDecl *FD = RD->findFirstNamedDataMember();
1611 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1631 "Typedef should not be in another decl context!");
1632 assert(D->getDeclName().getAsIdentifierInfo() &&
1633 "Typedef was not named!");
1634 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1635 assert(AdditionalAbiTags.empty() &&
1636 "Type cannot have additional abi tags");
1648 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1650 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1656 if (
Record->isLambda() &&
1657 ((DeviceNumber && *DeviceNumber > 0) ||
1658 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1659 assert(AdditionalAbiTags.empty() &&
1660 "Lambda type cannot have additional abi tags");
1667 unsigned UnnamedMangle =
1668 getASTContext().getManglingNumber(TD, Context.isAux());
1670 if (UnnamedMangle > 1)
1671 Out << UnnamedMangle - 2;
1673 writeAbiTags(TD, AdditionalAbiTags);
1679 unsigned AnonStructId =
1681 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1688 Str += llvm::utostr(AnonStructId);
1698 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1709 if (ND && Arity == UnknownArity) {
1713 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1714 if (MD->isImplicitObjectMemberFunction())
1720 mangleOperatorName(Name, Arity);
1721 writeAbiTags(ND, AdditionalAbiTags);
1725 llvm_unreachable(
"Can't mangle a deduction guide name!");
1728 llvm_unreachable(
"Can't mangle a using directive name!");
1732void CXXNameMangler::mangleConstructorName(
1733 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1734 const CXXRecordDecl *InheritedFrom =
nullptr;
1736 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1738 InheritedFrom = Inherited.getConstructor()->
getParent();
1739 InheritedTemplateName =
1740 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1741 InheritedTemplateArgs =
1742 Inherited.getConstructor()->getTemplateSpecializationArgs();
1745 if (CCD == Structor)
1748 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1756 if (InheritedTemplateArgs)
1757 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1759 writeAbiTags(CCD, AdditionalAbiTags);
1762void CXXNameMangler::mangleDestructorName(
1763 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1764 if (CDD == Structor)
1767 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1773 writeAbiTags(CDD, AdditionalAbiTags);
1776void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1780 if (getASTContext().getLangOpts().RegCall4)
1781 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1784 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1788void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1792 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1796void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1800 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1801 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1802 << OCLDeviceStubNamePrefix << II->
getName();
1805void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1812void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1813 ArrayRef<StringRef> AdditionalAbiTags,
1822 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1823 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1826 if (
Method->isExplicitObjectMemberFunction())
1829 mangleQualifiers(MethodQuals);
1830 mangleRefQualifier(
Method->getRefQualifier());
1834 const TemplateArgumentList *TemplateArgs =
nullptr;
1835 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1836 mangleTemplatePrefix(TD, NoFunction);
1839 manglePrefix(DC, NoFunction);
1840 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1845void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1846 ArrayRef<TemplateArgument> Args) {
1851 mangleTemplatePrefix(TD);
1857void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1858 GlobalDecl GD,
const NamedDecl *PrefixND,
1859 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1868 mangleClosurePrefix(PrefixND, NoFunction);
1869 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1880 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1882 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1891void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1892 ArrayRef<StringRef> AdditionalAbiTags) {
1900 const RecordDecl *RD = GetLocalClassDecl(D);
1901 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1906 AbiTagState LocalAbiTags(AbiTags);
1908 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1910 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1911 mangleBlockForPrefix(BD);
1912 }
else if (
const auto *TLSD = dyn_cast<TopLevelStmtDecl>(DC)) {
1913 mangleTopLevelStmtEncoding(TLSD);
1920 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1934 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1936 if (
const ParmVarDecl *Parm
1938 if (
const FunctionDecl *
Func
1943 mangleNumber(
Num - 2);
1952 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1953 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1954 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1955 mangleClosurePrefix(PrefixND,
true );
1957 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1958 assert(AdditionalAbiTags.empty() &&
1959 "Block cannot have additional abi tags");
1960 mangleUnqualifiedBlock(BD);
1963 const NamedDecl *PrefixND = getClosurePrefix(ND);
1964 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
1965 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
1968 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1969 AdditionalAbiTags,
true);
1971 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1974 if (
const ParmVarDecl *Parm
1975 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1976 if (
const FunctionDecl *
Func
1981 mangleNumber(
Num - 2);
1986 assert(AdditionalAbiTags.empty() &&
1987 "Block cannot have additional abi tags");
1988 mangleUnqualifiedBlock(BD);
1990 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1993 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1995 if (Context.getNextDiscriminator(ND, disc)) {
1999 Out <<
"__" << disc <<
'_';
2004void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
2005 if (GetLocalClassDecl(
Block)) {
2006 mangleLocalName(
Block);
2009 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
2010 if (isLocalContainerContext(DC)) {
2011 mangleLocalName(
Block);
2014 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2015 mangleClosurePrefix(PrefixND);
2018 mangleUnqualifiedBlock(
Block);
2021void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2024 if (Decl *Context =
Block->getBlockManglingContextDecl();
2025 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2027 Context->getDeclContext()->isRecord()) {
2030 mangleSourceNameWithAbiTags(ND);
2036 unsigned Number =
Block->getBlockManglingNumber();
2051void CXXNameMangler::mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D) {
2053 SmallString<16> Name(
"__stmt__");
2055 Out <<
'L' << Name.size() << Name <<
'v';
2065void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2067 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2068 if (Ty->isParameterPack())
2070 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2071 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2074 mangleTypeConstraint(Constraint);
2078 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2079 if (Tn->isExpandedParameterPack()) {
2080 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2082 mangleType(Tn->getExpansionType(I));
2085 QualType
T = Tn->getType();
2086 if (Tn->isParameterPack()) {
2088 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2089 T = PackExpansion->getPattern();
2094 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2095 if (Tt->isExpandedParameterPack()) {
2096 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2098 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2100 if (Tt->isParameterPack())
2102 mangleTemplateParameterList(Tt->getTemplateParameters());
2107void CXXNameMangler::mangleTemplateParameterList(
2108 const TemplateParameterList *Params) {
2110 for (
auto *Param : *Params)
2111 mangleTemplateParamDecl(Param);
2112 mangleRequiresClause(Params->getRequiresClause());
2116void CXXNameMangler::mangleTypeConstraint(
2118 const TemplateDecl *TD =
Concept.getAsTemplateDecl();
2120 DiagnoseUnsupportedPackIndexTemplateName();
2123 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
2125 mangleTemplateName(TD, Arguments);
2127 mangleUnscopedName(TD, DC);
2129 mangleNestedName(TD, DC);
2132void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2133 llvm::SmallVector<TemplateArgument, 8> Args;
2135 for (
const TemplateArgumentLoc &ArgLoc :
2137 Args.push_back(ArgLoc.getArgument());
2142void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2144 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2146 mangleExpression(RequiresClause);
2150void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2154 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2157 if (
const IdentifierInfo *Name =
2159 mangleSourceName(Name);
2160 const TemplateArgumentList *TemplateArgs =
nullptr;
2168 mangleLambdaSig(Lambda);
2183 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2187 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2189 mangleNumber(Number - 2);
2193void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2196 mangleTemplateParamDecl(D);
2200 mangleRequiresClause(TPL->getRequiresClause());
2204 mangleBareFunctionType(Proto,
false,
2208void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2210 case NestedNameSpecifier::Kind::Null:
2211 case NestedNameSpecifier::Kind::Global:
2215 case NestedNameSpecifier::Kind::MicrosoftSuper:
2216 llvm_unreachable(
"Can't mangle __super specifier");
2218 case NestedNameSpecifier::Kind::Namespace:
2219 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2222 case NestedNameSpecifier::Kind::Type:
2223 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2227 llvm_unreachable(
"unexpected nested name specifier");
2230void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2243 if (NoFunction && isLocalContainerContext(DC))
2250 if (mangleSubstitution(ND))
2256 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2257 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2258 mangleTemplatePrefix(TD);
2260 *FD->getTemplateSpecializationArgs());
2262 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2265 addSubstitution(ND);
2270 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2272 addSubstitution(ND);
2277 const TemplateArgumentList *TemplateArgs =
nullptr;
2278 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2279 mangleTemplatePrefix(TD);
2281 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2282 mangleClosurePrefix(PrefixND, NoFunction);
2283 mangleUnqualifiedName(ND,
nullptr);
2285 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2286 manglePrefix(DC, NoFunction);
2287 mangleUnqualifiedName(ND, DC);
2290 addSubstitution(ND);
2297 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2298 return mangleTemplatePrefix(TD);
2300 if (
Template.getAsPackIndexingTemplate()) {
2301 DiagnoseUnsupportedPackIndexTemplateName();
2306 assert(
Dependent &&
"unexpected template name kind");
2310 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2311 if (!Clang11Compat && mangleSubstitution(
Template))
2314 manglePrefix(
Dependent->getQualifier());
2316 if (Clang11Compat && mangleSubstitution(
Template))
2319 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2320 const IdentifierInfo *Id = Name.getIdentifier())
2321 mangleSourceName(Id);
2323 mangleOperatorName(Name.getOperator(), UnknownArity);
2328void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2337 if (mangleSubstitution(ND))
2341 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2342 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2344 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2345 manglePrefix(DC, NoFunction);
2347 mangleUnqualifiedName(GD, DC);
2352 addSubstitution(ND);
2355const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2356 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2359 const NamedDecl *Context =
nullptr;
2360 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2361 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2362 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2365 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2367 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2381void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2384 if (mangleSubstitution(ND))
2387 const TemplateArgumentList *TemplateArgs =
nullptr;
2388 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2389 mangleTemplatePrefix(TD, NoFunction);
2392 const auto *DC = Context.getEffectiveDeclContext(ND);
2393 manglePrefix(DC, NoFunction);
2394 mangleUnqualifiedName(ND, DC);
2399 addSubstitution(ND);
2408 if (mangleSubstitution(TN))
2411 TemplateDecl *TD =
nullptr;
2421 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2422 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2429 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2438 mangleUnresolvedPrefix(
Dependent->getQualifier());
2439 mangleSourceName(II);
2448 SubstTemplateTemplateParmStorage *subst
2459 Out <<
"_SUBSTPACK_";
2464 DiagnoseUnsupportedPackIndexTemplateName();
2468 llvm_unreachable(
"Unexpected DeducedTemplate");
2471 addSubstitution(TN);
2474bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2480 case Type::Adjusted:
2482 case Type::ArrayParameter:
2484 case Type::BlockPointer:
2485 case Type::LValueReference:
2486 case Type::RValueReference:
2487 case Type::MemberPointer:
2488 case Type::ConstantArray:
2489 case Type::IncompleteArray:
2490 case Type::VariableArray:
2491 case Type::DependentSizedArray:
2492 case Type::DependentAddressSpace:
2493 case Type::DependentVector:
2494 case Type::DependentSizedExtVector:
2496 case Type::ExtVector:
2497 case Type::ConstantMatrix:
2498 case Type::DependentSizedMatrix:
2499 case Type::FunctionProto:
2500 case Type::FunctionNoProto:
2502 case Type::Attributed:
2503 case Type::BTFTagAttributed:
2504 case Type::OverflowBehavior:
2505 case Type::HLSLAttributedResource:
2506 case Type::HLSLInlineSpirv:
2508 case Type::DeducedTemplateSpecialization:
2509 case Type::PackExpansion:
2510 case Type::ObjCObject:
2511 case Type::ObjCInterface:
2512 case Type::ObjCObjectPointer:
2513 case Type::ObjCTypeParam:
2516 case Type::MacroQualified:
2518 case Type::DependentBitInt:
2519 case Type::CountAttributed:
2520 case Type::LateParsedAttr:
2521 llvm_unreachable(
"type is illegal as a nested name specifier");
2523 case Type::SubstBuiltinTemplatePack:
2528 Out <<
"_SUBSTBUILTINPACK_";
2530 case Type::SubstTemplateTypeParmPack:
2535 Out <<
"_SUBSTPACK_";
2542 case Type::TypeOfExpr:
2544 case Type::Decltype:
2545 case Type::PackIndexing:
2546 case Type::TemplateTypeParm:
2547 case Type::UnaryTransform:
2560 case Type::SubstTemplateTypeParm: {
2564 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2566 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2567 goto unresolvedType;
2574 case Type::PredefinedSugar:
2578 case Type::UnresolvedUsing:
2579 mangleSourceNameWithAbiTags(
2585 mangleSourceNameWithAbiTags(
2589 case Type::TemplateSpecialization: {
2590 const TemplateSpecializationType *TST =
2600 assert(TD &&
"no template for template specialization type");
2602 goto unresolvedType;
2604 mangleSourceNameWithAbiTags(TD);
2616 llvm_unreachable(
"invalid base for a template specialization type");
2619 SubstTemplateTemplateParmStorage *subst =
2630 Out <<
"_SUBSTPACK_";
2635 DiagnoseUnsupportedPackIndexTemplateName();
2641 mangleSourceNameWithAbiTags(TD);
2651 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2655 case Type::InjectedClassName:
2656 mangleSourceNameWithAbiTags(
2660 case Type::DependentName:
2672void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2682 llvm_unreachable(
"Not an operator name");
2705 case OO_New:
Out <<
"nw";
break;
2707 case OO_Array_New:
Out <<
"na";
break;
2709 case OO_Delete:
Out <<
"dl";
break;
2711 case OO_Array_Delete:
Out <<
"da";
break;
2715 Out << (Arity == 1?
"ps" :
"pl");
break;
2719 Out << (Arity == 1?
"ng" :
"mi");
break;
2723 Out << (Arity == 1?
"ad" :
"an");
break;
2728 Out << (Arity == 1?
"de" :
"ml");
break;
2730 case OO_Tilde:
Out <<
"co";
break;
2732 case OO_Slash:
Out <<
"dv";
break;
2734 case OO_Percent:
Out <<
"rm";
break;
2736 case OO_Pipe:
Out <<
"or";
break;
2738 case OO_Caret:
Out <<
"eo";
break;
2740 case OO_Equal:
Out <<
"aS";
break;
2742 case OO_PlusEqual:
Out <<
"pL";
break;
2744 case OO_MinusEqual:
Out <<
"mI";
break;
2746 case OO_StarEqual:
Out <<
"mL";
break;
2748 case OO_SlashEqual:
Out <<
"dV";
break;
2750 case OO_PercentEqual:
Out <<
"rM";
break;
2752 case OO_AmpEqual:
Out <<
"aN";
break;
2754 case OO_PipeEqual:
Out <<
"oR";
break;
2756 case OO_CaretEqual:
Out <<
"eO";
break;
2758 case OO_LessLess:
Out <<
"ls";
break;
2760 case OO_GreaterGreater:
Out <<
"rs";
break;
2762 case OO_LessLessEqual:
Out <<
"lS";
break;
2764 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2766 case OO_EqualEqual:
Out <<
"eq";
break;
2768 case OO_ExclaimEqual:
Out <<
"ne";
break;
2770 case OO_Less:
Out <<
"lt";
break;
2772 case OO_Greater:
Out <<
"gt";
break;
2774 case OO_LessEqual:
Out <<
"le";
break;
2776 case OO_GreaterEqual:
Out <<
"ge";
break;
2778 case OO_Exclaim:
Out <<
"nt";
break;
2780 case OO_AmpAmp:
Out <<
"aa";
break;
2782 case OO_PipePipe:
Out <<
"oo";
break;
2784 case OO_PlusPlus:
Out <<
"pp";
break;
2786 case OO_MinusMinus:
Out <<
"mm";
break;
2788 case OO_Comma:
Out <<
"cm";
break;
2790 case OO_ArrowStar:
Out <<
"pm";
break;
2792 case OO_Arrow:
Out <<
"pt";
break;
2794 case OO_Call:
Out <<
"cl";
break;
2796 case OO_Subscript:
Out <<
"ix";
break;
2801 case OO_Conditional:
Out <<
"qu";
break;
2804 case OO_Coawait:
Out <<
"aw";
break;
2807 case OO_Spaceship:
Out <<
"ss";
break;
2811 llvm_unreachable(
"Not an overloaded operator");
2815void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2834 SmallString<64> ASString;
2840 if (TargetAS != 0 ||
2842 ASString =
"AS" + llvm::utostr(TargetAS);
2845 default: llvm_unreachable(
"Not a language specific address space");
2849 case LangAS::opencl_global:
2850 ASString =
"CLglobal";
2852 case LangAS::opencl_global_device:
2853 ASString =
"CLdevice";
2855 case LangAS::opencl_global_host:
2856 ASString =
"CLhost";
2858 case LangAS::opencl_local:
2859 ASString =
"CLlocal";
2861 case LangAS::opencl_constant:
2862 ASString =
"CLconstant";
2864 case LangAS::opencl_private:
2865 ASString =
"CLprivate";
2867 case LangAS::opencl_generic:
2868 ASString =
"CLgeneric";
2873 case LangAS::sycl_global:
2874 ASString =
"SYglobal";
2876 case LangAS::sycl_global_device:
2877 ASString =
"SYdevice";
2879 case LangAS::sycl_global_host:
2880 ASString =
"SYhost";
2882 case LangAS::sycl_local:
2883 ASString =
"SYlocal";
2885 case LangAS::sycl_private:
2886 ASString =
"SYprivate";
2888 case LangAS::sycl_generic:
2889 ASString =
"SYgeneric";
2891 case LangAS::sycl_constant:
2892 ASString =
"SYconstant";
2895 case LangAS::cuda_device:
2896 ASString =
"CUdevice";
2898 case LangAS::cuda_constant:
2899 ASString =
"CUconstant";
2901 case LangAS::cuda_shared:
2902 ASString =
"CUshared";
2905 case LangAS::ptr32_sptr:
2906 ASString =
"ptr32_sptr";
2908 case LangAS::ptr32_uptr:
2912 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2913 ASString =
"ptr32_uptr";
2920 if (!ASString.empty())
2921 mangleVendorQualifier(ASString);
2934 mangleVendorQualifier(
"__weak");
2938 mangleVendorQualifier(
"__unaligned");
2942 mangleVendorQualifier(
"__ptrauth");
2952 << unsigned(PtrAuth.isAddressDiscriminated())
2955 << PtrAuth.getExtraDiscriminator()
2970 mangleVendorQualifier(
"__strong");
2974 mangleVendorQualifier(
"__autoreleasing");
2997void CXXNameMangler::mangleVendorQualifier(StringRef name) {
3001void CXXNameMangler::mangleVendorType(StringRef name) {
3008 switch (RefQualifier) {
3022void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
3023 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3048 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3049 if (DeducedTST->getDeducedType().isNull())
3054void CXXNameMangler::mangleType(QualType
T) {
3088 T =
T.getCanonicalType();
3094 if (
const TemplateSpecializationType *TST
3095 = dyn_cast<TemplateSpecializationType>(
T))
3096 if (!TST->isTypeAlias())
3104 =
T.getSingleStepDesugaredType(Context.getASTContext());
3111 auto [ty, quals] =
T.split();
3113 bool isSubstitutable =
3115 if (isSubstitutable && mangleSubstitution(
T))
3122 quals = Qualifiers();
3128 if (quals || ty->isDependentAddressSpaceType()) {
3129 if (
const DependentAddressSpaceType *DAST =
3130 dyn_cast<DependentAddressSpaceType>(ty)) {
3132 mangleQualifiers(Quals, DAST);
3133 mangleType(QualType(Ty, 0));
3135 mangleQualifiers(quals);
3139 mangleType(QualType(ty, 0));
3142 switch (ty->getTypeClass()) {
3143#define ABSTRACT_TYPE(CLASS, PARENT)
3144#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3146 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3148#define TYPE(CLASS, PARENT) \
3150 mangleType(static_cast<const CLASS##Type*>(ty)); \
3152#include "clang/AST/TypeNodes.inc"
3157 if (isSubstitutable)
3161void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3162 bool SuppressSubstitution) {
3163 if (mangleSubstitution(
Record))
3166 if (SuppressSubstitution)
3171void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3213 std::string type_name;
3217 if (NormalizeIntegers &&
T->isInteger()) {
3218 if (
T->isSignedInteger()) {
3219 switch (getASTContext().getTypeSize(
T)) {
3223 if (mangleSubstitution(BuiltinType::SChar))
3226 addSubstitution(BuiltinType::SChar);
3229 if (mangleSubstitution(BuiltinType::Short))
3232 addSubstitution(BuiltinType::Short);
3235 if (mangleSubstitution(BuiltinType::Int))
3238 addSubstitution(BuiltinType::Int);
3241 if (mangleSubstitution(BuiltinType::Long))
3244 addSubstitution(BuiltinType::Long);
3247 if (mangleSubstitution(BuiltinType::Int128))
3250 addSubstitution(BuiltinType::Int128);
3253 llvm_unreachable(
"Unknown integer size for normalization");
3256 switch (getASTContext().getTypeSize(
T)) {
3258 if (mangleSubstitution(BuiltinType::UChar))
3261 addSubstitution(BuiltinType::UChar);
3264 if (mangleSubstitution(BuiltinType::UShort))
3267 addSubstitution(BuiltinType::UShort);
3270 if (mangleSubstitution(BuiltinType::UInt))
3273 addSubstitution(BuiltinType::UInt);
3276 if (mangleSubstitution(BuiltinType::ULong))
3279 addSubstitution(BuiltinType::ULong);
3282 if (mangleSubstitution(BuiltinType::UInt128))
3285 addSubstitution(BuiltinType::UInt128);
3288 llvm_unreachable(
"Unknown integer size for normalization");
3293 switch (
T->getKind()) {
3294 case BuiltinType::Void:
3297 case BuiltinType::Bool:
3300 case BuiltinType::Char_U:
3301 case BuiltinType::Char_S:
3304 case BuiltinType::UChar:
3307 case BuiltinType::UShort:
3310 case BuiltinType::UInt:
3313 case BuiltinType::ULong:
3316 case BuiltinType::ULongLong:
3319 case BuiltinType::UInt128:
3322 case BuiltinType::SChar:
3325 case BuiltinType::WChar_S:
3326 case BuiltinType::WChar_U:
3329 case BuiltinType::Char8:
3332 case BuiltinType::Char16:
3335 case BuiltinType::Char32:
3338 case BuiltinType::Short:
3341 case BuiltinType::Int:
3344 case BuiltinType::Long:
3347 case BuiltinType::LongLong:
3350 case BuiltinType::Int128:
3353 case BuiltinType::Float16:
3356 case BuiltinType::ShortAccum:
3359 case BuiltinType::Accum:
3362 case BuiltinType::LongAccum:
3365 case BuiltinType::UShortAccum:
3368 case BuiltinType::UAccum:
3371 case BuiltinType::ULongAccum:
3374 case BuiltinType::ShortFract:
3377 case BuiltinType::Fract:
3380 case BuiltinType::LongFract:
3383 case BuiltinType::UShortFract:
3386 case BuiltinType::UFract:
3389 case BuiltinType::ULongFract:
3392 case BuiltinType::SatShortAccum:
3395 case BuiltinType::SatAccum:
3398 case BuiltinType::SatLongAccum:
3401 case BuiltinType::SatUShortAccum:
3404 case BuiltinType::SatUAccum:
3407 case BuiltinType::SatULongAccum:
3410 case BuiltinType::SatShortFract:
3413 case BuiltinType::SatFract:
3416 case BuiltinType::SatLongFract:
3419 case BuiltinType::SatUShortFract:
3422 case BuiltinType::SatUFract:
3425 case BuiltinType::SatULongFract:
3428 case BuiltinType::Half:
3431 case BuiltinType::Float:
3434 case BuiltinType::Double:
3437 case BuiltinType::LongDouble: {
3438 const TargetInfo *TI =
3439 getASTContext().getLangOpts().OpenMP &&
3440 getASTContext().getLangOpts().OpenMPIsTargetDevice
3441 ? getASTContext().getAuxTargetInfo()
3442 : &getASTContext().getTargetInfo();
3446 case BuiltinType::Float128: {
3447 const TargetInfo *TI =
3448 getASTContext().getLangOpts().OpenMP &&
3449 getASTContext().getLangOpts().OpenMPIsTargetDevice
3450 ? getASTContext().getAuxTargetInfo()
3451 : &getASTContext().getTargetInfo();
3455 case BuiltinType::BFloat16: {
3456 const TargetInfo *TI =
3457 ((getASTContext().getLangOpts().OpenMP &&
3458 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3459 getASTContext().getLangOpts().SYCLIsDevice)
3460 ? getASTContext().getAuxTargetInfo()
3461 : &getASTContext().getTargetInfo();
3465 case BuiltinType::Ibm128: {
3466 const TargetInfo *TI = &getASTContext().getTargetInfo();
3470 case BuiltinType::NullPtr:
3474#define BUILTIN_TYPE(Id, SingletonId)
3475#define PLACEHOLDER_TYPE(Id, SingletonId) \
3476 case BuiltinType::Id:
3477#include "clang/AST/BuiltinTypes.def"
3478 case BuiltinType::Dependent:
3480 llvm_unreachable(
"mangling a placeholder type");
3482 case BuiltinType::ObjCId:
3483 Out <<
"11objc_object";
3485 case BuiltinType::ObjCClass:
3486 Out <<
"10objc_class";
3488 case BuiltinType::ObjCSel:
3489 Out <<
"13objc_selector";
3491#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3492 case BuiltinType::Id: \
3493 type_name = "ocl_" #ImgType "_" #Suffix; \
3494 Out << type_name.size() << type_name; \
3496#include "clang/Basic/OpenCLImageTypes.def"
3497 case BuiltinType::OCLSampler:
3498 Out <<
"11ocl_sampler";
3500 case BuiltinType::OCLEvent:
3501 Out <<
"9ocl_event";
3503 case BuiltinType::OCLClkEvent:
3504 Out <<
"12ocl_clkevent";
3506 case BuiltinType::OCLQueue:
3507 Out <<
"9ocl_queue";
3509 case BuiltinType::OCLReserveID:
3510 Out <<
"13ocl_reserveid";
3512#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3513 case BuiltinType::Id: \
3514 type_name = "ocl_" #ExtType; \
3515 Out << type_name.size() << type_name; \
3517#include "clang/Basic/OpenCLExtensionTypes.def"
3521#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3522 case BuiltinType::Id: \
3523 if (T->getKind() == BuiltinType::SveBFloat16 && \
3524 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3526 mangleVendorType("__SVBFloat16_t"); \
3528 type_name = #MangledName; \
3529 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3532#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3533 case BuiltinType::Id: \
3534 type_name = #MangledName; \
3535 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3537#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3538 case BuiltinType::Id: \
3539 type_name = #MangledName; \
3540 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3542#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3543 case BuiltinType::Id: \
3544 type_name = #MangledName; \
3545 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3547#include "clang/Basic/AArch64ACLETypes.def"
3548#define PPC_VECTOR_TYPE(Name, Id, Size) \
3549 case BuiltinType::Id: \
3550 mangleVendorType(#Name); \
3552#include "clang/Basic/PPCTypes.def"
3554#define RVV_TYPE(Name, Id, SingletonId) \
3555 case BuiltinType::Id: \
3556 mangleVendorType(Name); \
3558#include "clang/Basic/RISCVVTypes.def"
3559#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3560 case BuiltinType::Id: \
3561 mangleVendorType(MangledName); \
3563#include "clang/Basic/WebAssemblyReferenceTypes.def"
3564#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3565 case BuiltinType::Id: \
3566 mangleVendorType(Name); \
3568#include "clang/Basic/AMDGPUTypes.def"
3569#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3570 case BuiltinType::Id: \
3571 mangleVendorType(#Name); \
3573#include "clang/Basic/HLSLIntangibleTypes.def"
3574#define SPIRV_TYPE(Name, Id, SingletonId) \
3575 case BuiltinType::Id: \
3576 mangleVendorType(Name); \
3578#include "clang/Basic/SPIRVTypes.def"
3582StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3601#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3637 return "swiftasynccall";
3639 llvm_unreachable(
"bad calling convention");
3642void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3651 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3652 if (!CCQualifier.empty())
3653 mangleVendorQualifier(CCQualifier);
3686 llvm_unreachable(
"Unrecognised SME attribute");
3701void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3721 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3725CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3732 case ParameterABI::Ordinary:
3736 case ParameterABI::HLSLOut:
3737 case ParameterABI::HLSLInOut:
3742 case ParameterABI::SwiftContext:
3743 case ParameterABI::SwiftAsyncContext:
3744 case ParameterABI::SwiftErrorResult:
3745 case ParameterABI::SwiftIndirectResult:
3751 mangleVendorQualifier(
"ns_consumed");
3754 mangleVendorQualifier(
"noescape");
3760void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3764 Out <<
"11__SME_ATTRSI";
3766 mangleExtFunctionInfo(
T);
3783 mangleType(ExceptTy);
3794 mangleBareFunctionType(
T,
true);
3801 mangleSMEAttrs(SMEAttrs);
3804void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3810 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3812 FunctionTypeDepth.enterFunctionDeclSuffix();
3814 FunctionTypeDepth.leaveFunctionDeclSuffix();
3816 FunctionTypeDepth.pop(saved);
3820void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3821 bool MangleReturnType,
3822 const FunctionDecl *FD) {
3825 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3828 if (MangleReturnType) {
3829 FunctionTypeDepth.enterFunctionDeclSuffix();
3833 mangleVendorQualifier(
"ns_returns_retained");
3838 auto SplitReturnTy = ReturnTy.
split();
3840 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3842 mangleType(ReturnTy);
3844 FunctionTypeDepth.leaveFunctionDeclSuffix();
3852 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3866 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3867 if (Attr->isDynamic())
3868 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3870 Out <<
"U17pass_object_size" << Attr->getType();
3881 FunctionTypeDepth.enterFunctionDeclSuffix();
3885 FunctionTypeDepth.pop(saved);
3890void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3891 mangleName(
T->getDecl());
3896void CXXNameMangler::mangleType(
const EnumType *
T) {
3897 mangleType(
static_cast<const TagType*
>(
T));
3899void CXXNameMangler::mangleType(
const RecordType *
T) {
3900 mangleType(
static_cast<const TagType*
>(
T));
3902void CXXNameMangler::mangleType(
const TagType *
T) {
3903 mangleName(
T->getDecl()->getDefinitionOrSelf());
3909void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3910 Out <<
'A' <<
T->getSize() <<
'_';
3911 mangleType(
T->getElementType());
3913void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3916 if (
T->getSizeExpr())
3917 mangleExpression(
T->getSizeExpr());
3919 mangleType(
T->getElementType());
3921void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3926 if (
T->getSizeExpr())
3927 mangleExpression(
T->getSizeExpr());
3929 mangleType(
T->getElementType());
3931void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3933 mangleType(
T->getElementType());
3938void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
3940 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
3941 mangleCXXRecordDecl(RD);
3943 mangleType(QualType(
T->getQualifier().getAsType(), 0));
3945 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3966 mangleType(PointeeType);
3970void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
3971 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3975void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
3980 Out <<
"_SUBSTPACK_";
3983void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
3988 Out <<
"_SUBSTBUILTINPACK_";
3992void CXXNameMangler::mangleType(
const PointerType *
T) {
3996void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
4002void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
4008void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
4014void CXXNameMangler::mangleType(
const ComplexType *
T) {
4016 mangleType(
T->getElementType());
4022void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
4023 QualType EltType =
T->getElementType();
4024 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4025 const char *EltName =
nullptr;
4026 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4028 case BuiltinType::SChar:
4029 case BuiltinType::UChar:
4030 EltName =
"poly8_t";
4032 case BuiltinType::Short:
4033 case BuiltinType::UShort:
4034 EltName =
"poly16_t";
4036 case BuiltinType::LongLong:
4037 case BuiltinType::ULongLong:
4038 EltName =
"poly64_t";
4040 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
4044 case BuiltinType::SChar: EltName =
"int8_t";
break;
4045 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4046 case BuiltinType::Short: EltName =
"int16_t";
break;
4047 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4048 case BuiltinType::Int: EltName =
"int32_t";
break;
4049 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4050 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4051 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4052 case BuiltinType::Double: EltName =
"float64_t";
break;
4053 case BuiltinType::Float: EltName =
"float32_t";
break;
4054 case BuiltinType::Half: EltName =
"float16_t";
break;
4055 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4056 case BuiltinType::MFloat8:
4057 EltName =
"mfloat8_t";
4060 llvm_unreachable(
"unexpected Neon vector element type");
4063 const char *BaseName =
nullptr;
4064 unsigned BitSize = (
T->getNumElements() *
4065 getASTContext().getTypeSize(EltType));
4067 BaseName =
"__simd64_";
4069 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4070 BaseName =
"__simd128_";
4072 Out << strlen(BaseName) + strlen(EltName);
4073 Out << BaseName << EltName;
4076void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4077 DiagnosticsEngine &Diags = Context.getDiags();
4078 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4079 << UnsupportedItaniumManglingKind::DependentNeonVector;
4084 case BuiltinType::SChar:
4086 case BuiltinType::Short:
4088 case BuiltinType::Int:
4090 case BuiltinType::Long:
4091 case BuiltinType::LongLong:
4093 case BuiltinType::UChar:
4095 case BuiltinType::UShort:
4097 case BuiltinType::UInt:
4099 case BuiltinType::ULong:
4100 case BuiltinType::ULongLong:
4102 case BuiltinType::Half:
4104 case BuiltinType::Float:
4106 case BuiltinType::Double:
4108 case BuiltinType::BFloat16:
4110 case BuiltinType::MFloat8:
4113 llvm_unreachable(
"Unexpected vector element base type");
4120void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4121 QualType EltType =
T->getElementType();
4122 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4124 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4127 assert((BitSize == 64 || BitSize == 128) &&
4128 "Neon vector type not 64 or 128 bits");
4131 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4133 case BuiltinType::UChar:
4136 case BuiltinType::UShort:
4139 case BuiltinType::ULong:
4140 case BuiltinType::ULongLong:
4144 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4150 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4153void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4154 DiagnosticsEngine &Diags = Context.getDiags();
4155 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4156 << UnsupportedItaniumManglingKind::DependentNeonVector;
4183void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4184 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4185 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4186 "expected fixed-length SVE vector!");
4188 QualType EltType =
T->getElementType();
4190 "expected builtin type for fixed-length SVE vector!");
4194 case BuiltinType::SChar:
4197 case BuiltinType::UChar: {
4198 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4204 case BuiltinType::Short:
4207 case BuiltinType::UShort:
4210 case BuiltinType::Int:
4213 case BuiltinType::UInt:
4216 case BuiltinType::Long:
4219 case BuiltinType::ULong:
4222 case BuiltinType::Half:
4225 case BuiltinType::Float:
4228 case BuiltinType::Double:
4231 case BuiltinType::BFloat16:
4235 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4238 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4240 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4243 Out <<
"9__SVE_VLSI";
4244 mangleVendorType(TypeName);
4245 Out <<
"Lj" << VecSizeInBits <<
"EE";
4248void CXXNameMangler::mangleAArch64FixedSveVectorType(
4249 const DependentVectorType *
T) {
4250 DiagnosticsEngine &Diags = Context.getDiags();
4251 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4252 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4255void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4256 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4257 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4258 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4259 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4260 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4261 "expected fixed-length RVV vector!");
4263 QualType EltType =
T->getElementType();
4265 "expected builtin type for fixed-length RVV vector!");
4267 SmallString<20> TypeNameStr;
4268 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4269 TypeNameOS <<
"__rvv_";
4271 case BuiltinType::SChar:
4272 TypeNameOS <<
"int8";
4274 case BuiltinType::UChar:
4275 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4276 TypeNameOS <<
"uint8";
4278 TypeNameOS <<
"bool";
4280 case BuiltinType::Short:
4281 TypeNameOS <<
"int16";
4283 case BuiltinType::UShort:
4284 TypeNameOS <<
"uint16";
4286 case BuiltinType::Int:
4287 TypeNameOS <<
"int32";
4289 case BuiltinType::UInt:
4290 TypeNameOS <<
"uint32";
4292 case BuiltinType::Long:
4293 case BuiltinType::LongLong:
4294 TypeNameOS <<
"int64";
4296 case BuiltinType::ULong:
4297 case BuiltinType::ULongLong:
4298 TypeNameOS <<
"uint64";
4300 case BuiltinType::Float16:
4301 TypeNameOS <<
"float16";
4303 case BuiltinType::Float:
4304 TypeNameOS <<
"float32";
4306 case BuiltinType::Double:
4307 TypeNameOS <<
"float64";
4309 case BuiltinType::BFloat16:
4310 TypeNameOS <<
"bfloat16";
4313 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4316 unsigned VecSizeInBits;
4317 switch (
T->getVectorKind()) {
4318 case VectorKind::RVVFixedLengthMask_1:
4321 case VectorKind::RVVFixedLengthMask_2:
4324 case VectorKind::RVVFixedLengthMask_4:
4328 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4333 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4334 getASTContext().getLangOpts(),
4335 TargetInfo::ArmStreamingKind::NotStreaming);
4336 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4338 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4340 if (VecSizeInBits >= VLen)
4341 TypeNameOS << (VecSizeInBits / VLen);
4343 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4345 TypeNameOS << (VLen / VecSizeInBits);
4349 Out <<
"9__RVV_VLSI";
4350 mangleVendorType(TypeNameStr);
4351 Out <<
"Lj" << VecSizeInBits <<
"EE";
4354void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4355 const DependentVectorType *
T) {
4356 DiagnosticsEngine &Diags = Context.getDiags();
4357 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4358 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4369void CXXNameMangler::mangleType(
const VectorType *
T) {
4370 if ((
T->getVectorKind() == VectorKind::Neon ||
4371 T->getVectorKind() == VectorKind::NeonPoly)) {
4372 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4373 llvm::Triple::ArchType
Arch =
4374 getASTContext().getTargetInfo().getTriple().getArch();
4375 if ((
Arch == llvm::Triple::aarch64 ||
4376 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4377 mangleAArch64NeonVectorType(
T);
4379 mangleNeonVectorType(
T);
4381 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4382 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4383 mangleAArch64FixedSveVectorType(
T);
4385 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4386 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4387 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4388 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4389 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4390 mangleRISCVFixedRVVVectorType(
T);
4393 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4394 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4396 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4399 mangleType(
T->getElementType());
4402void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4403 if ((
T->getVectorKind() == VectorKind::Neon ||
4404 T->getVectorKind() == VectorKind::NeonPoly)) {
4405 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4406 llvm::Triple::ArchType
Arch =
4407 getASTContext().getTargetInfo().getTriple().getArch();
4408 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4410 mangleAArch64NeonVectorType(
T);
4412 mangleNeonVectorType(
T);
4414 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4415 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4416 mangleAArch64FixedSveVectorType(
T);
4418 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4419 mangleRISCVFixedRVVVectorType(
T);
4424 mangleExpression(
T->getSizeExpr());
4426 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4428 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4431 mangleType(
T->getElementType());
4434void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4435 mangleType(
static_cast<const VectorType*
>(
T));
4437void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4439 mangleExpression(
T->getSizeExpr());
4441 mangleType(
T->getElementType());
4444void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4448 mangleVendorType(
"matrix_type");
4451 auto &ASTCtx = getASTContext();
4452 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4453 llvm::APSInt Rows(BitWidth);
4454 Rows =
T->getNumRows();
4455 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4456 llvm::APSInt Columns(BitWidth);
4457 Columns =
T->getNumColumns();
4458 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4459 mangleType(
T->getElementType());
4463void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4466 mangleVendorType(
"matrix_type");
4469 mangleTemplateArgExpr(
T->getRowExpr());
4470 mangleTemplateArgExpr(
T->getColumnExpr());
4471 mangleType(
T->getElementType());
4475void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4477 mangleQualifiers(split.
Quals,
T);
4478 mangleType(QualType(split.
Ty, 0));
4481void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4484 mangleType(
T->getPattern());
4487void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4490 mangleType(
T->getPattern());
4491 mangleExpression(
T->getIndexExpr());
4494void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4495 mangleSourceName(
T->getDecl()->getIdentifier());
4498void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4500 if (
T->isKindOfType())
4501 Out <<
"U8__kindof";
4503 if (!
T->qual_empty()) {
4505 SmallString<64> QualStr;
4506 llvm::raw_svector_ostream QualOS(QualStr);
4507 QualOS <<
"objcproto";
4508 for (
const auto *I :
T->quals()) {
4509 StringRef
name = I->getName();
4512 mangleVendorQualifier(QualStr);
4515 mangleType(
T->getBaseType());
4517 if (
T->isSpecialized()) {
4520 for (
auto typeArg :
T->getTypeArgs())
4521 mangleType(typeArg);
4526void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4527 Out <<
"U13block_pointer";
4531void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4536 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4539void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4540 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4541 mangleTemplateName(TD,
T->template_arguments());
4544 mangleTemplatePrefix(
T->getTemplateName());
4549 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4554void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4565 switch (
T->getKeyword()) {
4566 case ElaboratedTypeKeyword::None:
4567 case ElaboratedTypeKeyword::Typename:
4569 case ElaboratedTypeKeyword::Struct:
4570 case ElaboratedTypeKeyword::Class:
4571 case ElaboratedTypeKeyword::Interface:
4574 case ElaboratedTypeKeyword::Union:
4577 case ElaboratedTypeKeyword::Enum:
4583 manglePrefix(
T->getQualifier());
4584 mangleSourceName(
T->getIdentifier());
4588void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4594void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4600void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4601 Expr *E =
T->getUnderlyingExpr();
4620 mangleExpression(E);
4624void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4628 StringRef BuiltinName;
4629 switch (
T->getUTTKind()) {
4630#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4631 case UnaryTransformType::Enum: \
4632 BuiltinName = "__" #Trait; \
4634#include "clang/Basic/BuiltinTraits.inc"
4636 mangleVendorType(BuiltinName);
4640 mangleType(
T->getBaseType());
4644void CXXNameMangler::mangleType(
const AutoType *
T) {
4645 assert(
T->getDeducedType().isNull() &&
4646 "Deduced AutoType shouldn't be handled here!");
4647 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4648 "shouldn't need to mangle __auto_type!");
4653 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4654 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4655 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4656 T->getTypeConstraintArguments());
4658 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4662void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4663 QualType
Deduced =
T->getDeducedType();
4669 "shouldn't form deduced TST unless we know we have a template");
4673void CXXNameMangler::mangleType(
const AtomicType *
T) {
4677 mangleType(
T->getValueType());
4680void CXXNameMangler::mangleType(
const PipeType *
T) {
4687void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4690 if (
T->isWrapKind()) {
4691 Out <<
"U8ObtWrap_";
4693 Out <<
"U8ObtTrap_";
4695 mangleType(
T->getUnderlyingType());
4698void CXXNameMangler::mangleType(
const BitIntType *
T) {
4702 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4705void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4709 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4710 mangleExpression(
T->getNumBitsExpr());
4714void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4718void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4719 llvm::SmallString<64> Str(
"_Res");
4720 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4722 switch (Attrs.ResourceClass) {
4723 case llvm::dxil::ResourceClass::UAV:
4726 case llvm::dxil::ResourceClass::SRV:
4729 case llvm::dxil::ResourceClass::CBuffer:
4732 case llvm::dxil::ResourceClass::Sampler:
4738 if (Attrs.RawBuffer)
4740 if (Attrs.IsCounter)
4744 if (Attrs.isMultiSampled())
4746 if (
T->hasContainedType())
4748 mangleVendorQualifier(Str);
4750 if (
T->hasContainedType()) {
4751 mangleType(
T->getContainedType());
4753 mangleType(
T->getWrappedType());
4756void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4757 SmallString<20> TypeNameStr;
4758 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4760 TypeNameOS <<
"spirv_type";
4762 TypeNameOS <<
"_" <<
T->getOpcode();
4763 TypeNameOS <<
"_" <<
T->getSize();
4764 TypeNameOS <<
"_" <<
T->getAlignment();
4766 mangleVendorType(TypeNameStr);
4768 for (
auto &Operand :
T->getOperands()) {
4769 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4772 case SpirvOperandKind::ConstantId:
4773 mangleVendorQualifier(
"_Const");
4774 mangleIntegerLiteral(
Operand.getResultType(),
4775 llvm::APSInt(
Operand.getValue()));
4777 case SpirvOperandKind::Literal:
4778 mangleVendorQualifier(
"_Lit");
4779 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4780 llvm::APSInt(
Operand.getValue()));
4782 case SpirvOperandKind::TypeId:
4783 mangleVendorQualifier(
"_Type");
4784 mangleType(
Operand.getResultType());
4787 llvm_unreachable(
"Invalid SpirvOperand kind");
4790 TypeNameOS <<
Operand.getKind();
4794void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4795 const llvm::APSInt &
Value) {
4802 Out << (
Value.getBoolValue() ?
'1' :
'0');
4804 mangleNumber(
Value);
4809void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4811 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4812 if (!RT->getDecl()->isAnonymousStructOrUnion())
4814 const auto *ME = dyn_cast<MemberExpr>(Base);
4817 Base = ME->getBase();
4818 IsArrow = ME->isArrow();
4821 if (
Base->isImplicitCXXThis()) {
4827 Out << (IsArrow ?
"pt" :
"dt");
4828 mangleExpression(Base);
4833void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4834 NestedNameSpecifier Qualifier,
4835 NamedDecl *firstQualifierLookup,
4836 DeclarationName member,
4837 const TemplateArgumentLoc *TemplateArgs,
4838 unsigned NumTemplateArgs,
4843 mangleMemberExprBase(base, isArrow);
4844 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4857 if (callee == fn)
return false;
4861 if (!lookup)
return false;
4878void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4880 Out << CastEncoding;
4885void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4887 InitList = Syntactic;
4888 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4889 mangleExpression(InitList->
getInit(i));
4892void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4893 const concepts::Requirement *Req) {
4894 using concepts::Requirement;
4899 auto HandleSubstitutionFailure =
4900 [&](SourceLocation Loc) {
4901 DiagnosticsEngine &Diags = Context.getDiags();
4902 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4903 << UnsupportedItaniumManglingKind::
4904 RequiresExprWithSubstitutionFailure;
4909 case Requirement::RK_Type: {
4911 if (TR->isSubstitutionFailure())
4912 return HandleSubstitutionFailure(
4913 TR->getSubstitutionDiagnostic()->DiagLoc);
4916 mangleType(TR->getType()->getType());
4920 case Requirement::RK_Simple:
4921 case Requirement::RK_Compound: {
4923 if (ER->isExprSubstitutionFailure())
4924 return HandleSubstitutionFailure(
4925 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4928 mangleExpression(ER->getExpr());
4930 if (ER->hasNoexceptRequirement())
4933 if (!ER->getReturnTypeRequirement().isEmpty()) {
4934 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4935 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4936 .getSubstitutionDiagnostic()
4940 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4945 case Requirement::RK_Nested:
4947 if (NR->hasInvalidConstraint()) {
4950 return HandleSubstitutionFailure(RequiresExprLoc);
4954 mangleExpression(NR->getConstraintExpr());
4959void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4960 bool AsTemplateArg) {
4993 QualType ImplicitlyConvertedToType;
4997 bool IsPrimaryExpr =
true;
4998 auto NotPrimaryExpr = [&] {
4999 if (AsTemplateArg && IsPrimaryExpr)
5001 IsPrimaryExpr =
false;
5004 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
5018 case Decl::EnumConstant: {
5025 case Decl::NonTypeTemplateParm:
5038 case Expr::NoStmtClass:
5039#define ABSTRACT_STMT(Type)
5040#define EXPR(Type, Base)
5041#define STMT(Type, Base) \
5042 case Expr::Type##Class:
5043#include "clang/AST/StmtNodes.inc"
5048 case Expr::AddrLabelExprClass:
5049 case Expr::DesignatedInitUpdateExprClass:
5050 case Expr::ImplicitValueInitExprClass:
5051 case Expr::ArrayInitLoopExprClass:
5052 case Expr::ArrayInitIndexExprClass:
5053 case Expr::NoInitExprClass:
5054 case Expr::ParenListExprClass:
5055 case Expr::MSPropertyRefExprClass:
5056 case Expr::MSPropertySubscriptExprClass:
5057 case Expr::RecoveryExprClass:
5058 case Expr::ArraySectionExprClass:
5059 case Expr::OMPArrayShapingExprClass:
5060 case Expr::OMPIteratorExprClass:
5061 case Expr::CXXInheritedCtorInitExprClass:
5062 case Expr::CXXParenListInitExprClass:
5063 case Expr::CXXExpansionSelectExprClass:
5064 llvm_unreachable(
"unexpected statement kind");
5066 case Expr::ConstantExprClass:
5070 case Expr::CXXReflectExprClass: {
5072 assert(
false &&
"unimplemented");
5077 case Expr::BlockExprClass:
5078 case Expr::ChooseExprClass:
5079 case Expr::CompoundLiteralExprClass:
5080 case Expr::ExtVectorElementExprClass:
5081 case Expr::MatrixElementExprClass:
5082 case Expr::GenericSelectionExprClass:
5083 case Expr::ObjCEncodeExprClass:
5084 case Expr::ObjCIsaExprClass:
5085 case Expr::ObjCIvarRefExprClass:
5086 case Expr::ObjCMessageExprClass:
5087 case Expr::ObjCPropertyRefExprClass:
5088 case Expr::ObjCProtocolExprClass:
5089 case Expr::ObjCSelectorExprClass:
5090 case Expr::ObjCStringLiteralClass:
5091 case Expr::ObjCBoxedExprClass:
5092 case Expr::ObjCArrayLiteralClass:
5093 case Expr::ObjCDictionaryLiteralClass:
5094 case Expr::ObjCSubscriptRefExprClass:
5095 case Expr::ObjCIndirectCopyRestoreExprClass:
5096 case Expr::ObjCAvailabilityCheckExprClass:
5097 case Expr::OffsetOfExprClass:
5098 case Expr::PredefinedExprClass:
5099 case Expr::ShuffleVectorExprClass:
5100 case Expr::ConvertVectorExprClass:
5101 case Expr::StmtExprClass:
5102 case Expr::ArrayTypeTraitExprClass:
5103 case Expr::ExpressionTraitExprClass:
5104 case Expr::VAArgExprClass:
5105 case Expr::CUDAKernelCallExprClass:
5106 case Expr::AsTypeExprClass:
5107 case Expr::PseudoObjectExprClass:
5108 case Expr::AtomicExprClass:
5109 case Expr::SourceLocExprClass:
5110 case Expr::EmbedExprClass:
5111 case Expr::BuiltinBitCastExprClass: {
5115 DiagnosticsEngine &Diags = Context.getDiags();
5123 case Expr::CXXUuidofExprClass: {
5128 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5129 Out <<
"u8__uuidof";
5138 Out <<
"u8__uuidoft";
5142 Out <<
"u8__uuidofz";
5143 mangleExpression(UuidExp);
5150 case Expr::BinaryConditionalOperatorClass: {
5152 DiagnosticsEngine &Diags = Context.getDiags();
5154 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5160 case Expr::OpaqueValueExprClass:
5161 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5163 case Expr::InitListExprClass: {
5171 case Expr::DesignatedInitExprClass: {
5174 for (
const auto &Designator : DIE->designators()) {
5175 if (Designator.isFieldDesignator()) {
5177 mangleSourceName(Designator.getFieldName());
5178 }
else if (Designator.isArrayDesignator()) {
5180 mangleExpression(DIE->getArrayIndex(Designator));
5182 assert(Designator.isArrayRangeDesignator() &&
5183 "unknown designator kind");
5185 mangleExpression(DIE->getArrayRangeStart(Designator));
5186 mangleExpression(DIE->getArrayRangeEnd(Designator));
5189 mangleExpression(DIE->getInit());
5193 case Expr::CXXDefaultArgExprClass:
5197 case Expr::CXXDefaultInitExprClass:
5201 case Expr::CXXStdInitializerListExprClass:
5205 case Expr::SubstNonTypeTemplateParmExprClass: {
5209 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5211 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5212 mangleValueInTemplateArg(SNTTPE->getParameterType(),
5213 CE->getAPValueResult(),
false,
5223 case Expr::UserDefinedLiteralClass:
5226 case Expr::CXXMemberCallExprClass:
5227 case Expr::CallExprClass: {
5249 CallArity = UnknownArity;
5251 mangleExpression(CE->
getCallee(), CallArity);
5253 mangleExpression(Arg);
5258 case Expr::CXXNewExprClass: {
5261 if (
New->isGlobalNew())
Out <<
"gs";
5262 Out << (
New->isArray() ?
"na" :
"nw");
5264 E =
New->placement_arg_end(); I != E; ++I)
5265 mangleExpression(*I);
5267 mangleType(
New->getAllocatedType());
5268 if (
New->hasInitializer()) {
5269 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5273 const Expr *
Init =
New->getInitializer();
5274 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5279 mangleExpression(*I);
5280 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5281 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5282 mangleExpression(PLE->getExpr(i));
5283 }
else if (
New->getInitializationStyle() ==
5284 CXXNewInitializationStyle::Braces &&
5289 mangleExpression(
Init);
5295 case Expr::CXXPseudoDestructorExprClass: {
5298 if (
const Expr *Base = PDE->getBase())
5299 mangleMemberExprBase(Base, PDE->isArrow());
5300 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5301 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5303 mangleUnresolvedPrefix(Qualifier,
5305 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5309 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5312 }
else if (Qualifier) {
5313 mangleUnresolvedPrefix(Qualifier);
5317 QualType DestroyedType = PDE->getDestroyedType();
5318 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5322 case Expr::MemberExprClass: {
5333 case Expr::UnresolvedMemberExprClass: {
5344 case Expr::CXXDependentScopeMemberExprClass: {
5346 const CXXDependentScopeMemberExpr *ME
5357 case Expr::UnresolvedLookupExprClass: {
5366 case Expr::DependentTemplateIdExprClass: {
5369 if (DTI->getTemplateName().getAsPackIndexingTemplate()) {
5370 DiagnoseUnsupportedPackIndexTemplateName();
5373 mangleUnresolvedName(std::nullopt, DTI->getName(),
5374 DTI->template_arguments().data(),
5375 DTI->getNumTemplateArgs(), Arity);
5379 case Expr::CXXUnresolvedConstructExprClass: {
5385 assert(N == 1 &&
"unexpected form for list initialization");
5389 mangleInitListElements(IL);
5396 if (N != 1)
Out <<
'_';
5397 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5398 if (N != 1)
Out <<
'E';
5402 case Expr::CXXConstructExprClass: {
5409 "implicit CXXConstructExpr must have one argument");
5416 mangleExpression(E);
5421 case Expr::CXXTemporaryObjectExprClass: {
5432 if (!List && N != 1)
5434 if (CE->isStdInitListInitialization()) {
5441 mangleInitListElements(ILE);
5444 mangleExpression(E);
5451 case Expr::CXXScalarValueInitExprClass:
5458 case Expr::CXXNoexceptExprClass:
5464 case Expr::UnaryExprOrTypeTraitExprClass: {
5481 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5483 : ImplicitlyConvertedToType;
5485 mangleIntegerLiteral(
T,
V);
5491 auto MangleAlignofSizeofArg = [&] {
5501 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5502 StringRef Name = {}) {
5505 mangleVendorType(Name);
5516 MangleAlignofSizeofArg();
5518 case UETT_PreferredAlignOf:
5522 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5523 MangleExtensionBuiltin(SAE,
"__alignof__");
5529 MangleAlignofSizeofArg();
5533 case UETT_VectorElements:
5534 case UETT_OpenMPRequiredSimdAlign:
5536 case UETT_PtrAuthTypeDiscriminator:
5537 case UETT_DataSizeOf: {
5538 DiagnosticsEngine &Diags = Context.getDiags();
5547 case Expr::TypeTraitExprClass: {
5552 mangleVendorType(Spelling);
5553 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5554 mangleType(TSI->getType());
5560 case Expr::CXXThrowExprClass: {
5574 case Expr::CXXTypeidExprClass: {
5589 case Expr::CXXDeleteExprClass: {
5600 case Expr::UnaryOperatorClass: {
5609 case Expr::ArraySubscriptExprClass: {
5616 mangleExpression(AE->
getLHS());
5617 mangleExpression(AE->
getRHS());
5621 case Expr::MatrixSingleSubscriptExprClass: {
5625 mangleExpression(ME->
getBase());
5630 case Expr::MatrixSubscriptExprClass: {
5634 mangleExpression(ME->
getBase());
5640 case Expr::CompoundAssignOperatorClass:
5641 case Expr::BinaryOperatorClass: {
5649 mangleExpression(BO->
getLHS());
5650 mangleExpression(BO->
getRHS());
5654 case Expr::CXXRewrittenBinaryOperatorClass: {
5657 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5661 mangleExpression(Decomposed.
LHS);
5662 mangleExpression(Decomposed.
RHS);
5666 case Expr::ConditionalOperatorClass: {
5669 mangleOperatorName(OO_Conditional, 3);
5670 mangleExpression(CO->
getCond());
5671 mangleExpression(CO->
getLHS(), Arity);
5672 mangleExpression(CO->
getRHS(), Arity);
5676 case Expr::ImplicitCastExprClass: {
5677 ImplicitlyConvertedToType = E->
getType();
5682 case Expr::ObjCBridgedCastExprClass: {
5688 mangleCastExpression(E,
"cv");
5692 case Expr::CStyleCastExprClass:
5694 mangleCastExpression(E,
"cv");
5697 case Expr::CXXFunctionalCastExprClass: {
5701 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5702 if (CCE->getParenOrBraceRange().isInvalid())
5703 Sub = CCE->getArg(0)->IgnoreImplicit();
5704 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5705 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5706 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5709 mangleInitListElements(IL);
5712 mangleCastExpression(E,
"cv");
5717 case Expr::CXXStaticCastExprClass:
5719 mangleCastExpression(E,
"sc");
5721 case Expr::CXXDynamicCastExprClass:
5723 mangleCastExpression(E,
"dc");
5725 case Expr::CXXReinterpretCastExprClass:
5727 mangleCastExpression(E,
"rc");
5729 case Expr::CXXConstCastExprClass:
5731 mangleCastExpression(E,
"cc");
5733 case Expr::CXXAddrspaceCastExprClass:
5735 mangleCastExpression(E,
"ac");
5738 case Expr::CXXOperatorCallExprClass: {
5747 for (
unsigned i = 0; i != NumArgs; ++i)
5748 mangleExpression(CE->
getArg(i));
5752 case Expr::ParenExprClass:
5756 case Expr::ConceptSpecializationExprClass: {
5758 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5763 mangleTemplateName(CSE->getConceptDecl(), CSE->getTemplateArguments());
5769 mangleUnresolvedName(
5770 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5771 CSE->getConceptNameInfo().getName(),
5772 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5773 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5777 case Expr::RequiresExprClass: {
5783 if (RE->getLParenLoc().isValid()) {
5785 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5786 if (RE->getLocalParameters().empty()) {
5789 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5797 FunctionTypeDepth.enterFunctionDeclSuffix();
5798 for (
const concepts::Requirement *Req : RE->getRequirements())
5799 mangleRequirement(RE->getExprLoc(), Req);
5800 FunctionTypeDepth.pop(saved);
5804 for (
const concepts::Requirement *Req : RE->getRequirements())
5805 mangleRequirement(RE->getExprLoc(), Req);
5811 case Expr::DeclRefExprClass:
5816 case Expr::SubstNonTypeTemplateParmPackExprClass:
5822 Out <<
"_SUBSTPACK_";
5825 case Expr::FunctionParmPackExprClass: {
5829 Out <<
"v110_SUBSTPACK";
5834 case Expr::DependentScopeDeclRefExprClass: {
5843 case Expr::CXXBindTemporaryExprClass:
5847 case Expr::ExprWithCleanupsClass:
5851 case Expr::FloatingLiteralClass: {
5858 case Expr::FixedPointLiteralClass:
5860 mangleFixedPointLiteral();
5863 case Expr::CharacterLiteralClass:
5867 Out << cast<CharacterLiteral>(E)->getValue();
5872 case Expr::ObjCBoolLiteralExprClass:
5875 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5879 case Expr::CXXBoolLiteralExprClass:
5882 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5886 case Expr::IntegerLiteralClass: {
5890 Value.setIsSigned(
true);
5895 case Expr::ImaginaryLiteralClass: {
5902 if (
const FloatingLiteral *Imag =
5903 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5905 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5907 mangleFloat(Imag->getValue());
5912 Value.setIsSigned(
true);
5913 mangleNumber(
Value);
5919 case Expr::StringLiteralClass: {
5929 case Expr::GNUNullExprClass:
5932 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5935 case Expr::CXXNullPtrLiteralExprClass: {
5941 case Expr::LambdaExprClass: {
5952 case Expr::PackExpansionExprClass:
5958 case Expr::SizeOfPackExprClass: {
5961 if (SPE->isPartiallySubstituted()) {
5963 for (
const auto &A : SPE->getPartialArguments())
5964 mangleTemplateArg(A,
false);
5970 mangleReferenceToPack(SPE->getPack());
5974 case Expr::MaterializeTemporaryExprClass:
5978 case Expr::CXXFoldExprClass: {
5981 if (FE->isLeftFold())
5982 Out << (FE->getInit() ?
"fL" :
"fl");
5984 Out << (FE->getInit() ?
"fR" :
"fr");
5986 if (FE->getOperator() == BO_PtrMemD)
5994 mangleExpression(FE->getLHS());
5996 mangleExpression(FE->getRHS());
6000 case Expr::PackIndexingExprClass: {
6004 mangleReferenceToPack(PE->getPackDecl());
6005 mangleExpression(PE->getIndexExpr());
6009 case Expr::CXXThisExprClass:
6014 case Expr::CoawaitExprClass:
6017 Out <<
"v18co_await";
6021 case Expr::DependentCoawaitExprClass:
6024 Out <<
"v18co_await";
6028 case Expr::CoyieldExprClass:
6031 Out <<
"v18co_yield";
6034 case Expr::SYCLUniqueStableNameExprClass: {
6038 Out <<
"u33__builtin_sycl_unique_stable_name";
6039 mangleType(USN->getTypeSourceInfo()->getType());
6044 case Expr::HLSLOutArgExprClass:
6046 "cannot mangle hlsl temporary value; mangling wrong thing?");
6047 case Expr::OpenACCAsteriskSizeExprClass: {
6049 DiagnosticsEngine &Diags = Context.getDiags();
6050 Diags.
Report(diag::err_unsupported_itanium_mangling)
6051 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
6056 if (AsTemplateArg && !IsPrimaryExpr)
6088void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6093 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6094 nestingDepth == 0) {
6097 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6105 &&
"parameter's type is still an array type?");
6107 if (
const DependentAddressSpaceType *DAST =
6108 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6115 if (parmIndex != 0) {
6116 Out << (parmIndex - 1);
6122 const CXXRecordDecl *InheritedFrom) {
6149 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6152 mangleName(InheritedFrom);
6180 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6184void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6185 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6186 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6187 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6188 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6189 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6190 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6224 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6225 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6226 if (!RD || !RD->isGenericLambda())
6242 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6243 return TTP->hasTypeConstraint();
6260 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6261 return NTTP->getType()->isInstantiationDependentType() ||
6262 NTTP->getType()->getContainedDeducedType();
6269 "A DeducedTemplateName shouldn't escape partial ordering");
6280 auto MangleTemplateParamListToString =
6282 unsigned DepthOffset) {
6283 llvm::raw_svector_ostream Stream(Buffer);
6284 CXXNameMangler(
Mangler.Context, Stream,
6285 WithTemplateDepthOffset{DepthOffset})
6286 .mangleTemplateParameterList(Params);
6289 MangleTemplateParamListToString(ParamTemplateHead,
6290 TTP->getTemplateParameters(), 0);
6294 MangleTemplateParamListToString(ArgTemplateHead,
6296 TTP->getTemplateParameters()->
getDepth());
6297 return ParamTemplateHead != ArgTemplateHead;
6307 return {
true,
nullptr};
6312 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6313 "no parameter for argument");
6334 return {
true,
nullptr};
6349 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6350 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6351 return {NeedExactType,
nullptr};
6363void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6365 unsigned NumTemplateArgs) {
6368 TemplateArgManglingInfo Info(*
this, TN);
6369 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6370 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6372 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6376void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6377 const TemplateArgumentList &AL) {
6380 TemplateArgManglingInfo Info(*
this, TN);
6381 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6382 mangleTemplateArg(Info, i, AL[i]);
6384 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6388void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6389 ArrayRef<TemplateArgument> Args) {
6392 TemplateArgManglingInfo Info(*
this, TN);
6393 for (
unsigned i = 0; i != Args.size(); ++i) {
6394 mangleTemplateArg(Info, i, Args[i]);
6396 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6400void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6401 unsigned Index, TemplateArgument A) {
6402 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6405 if (ArgInfo.TemplateParameterToMangle &&
6406 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6413 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6416 mangleTemplateArg(A, ArgInfo.NeedExactType);
6419void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6429 llvm_unreachable(
"Cannot mangle NULL template argument");
6457 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6458 TPO->getValue(),
true,
6463 ASTContext &Ctx = Context.getASTContext();
6471 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6479 ArrayRef<APValue::LValuePathEntry>(),
6492 true, NeedExactType);
6498 mangleTemplateArg(P, NeedExactType);
6504void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6505 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6506 mangleExpression(E, UnknownArity,
true);
6521 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6522 const ValueDecl *D = DRE->getDecl();
6531 mangleExpression(E);
6544 switch (
V.getKind()) {
6552 assert(RD &&
"unexpected type for record value");
6561 if (!FD->isUnnamedBitField() &&
6571 assert(RD &&
"unexpected type for union value");
6574 if (!FD->isUnnamedBitField())
6584 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6585 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6593 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6600 llvm_unreachable(
"Matrix APValues not yet supported");
6606 return V.getFloat().isPosZero();
6609 return !
V.getFixedPoint().getValue();
6612 return V.getComplexFloatReal().isPosZero() &&
6613 V.getComplexFloatImag().isPosZero();
6616 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6619 return V.isNullPointer();
6622 return !
V.getMemberPointerDecl();
6625 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6632 T = AT->getElementType();
6634 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6677 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6678 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6683void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6685 bool NeedExactType) {
6688 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6691 bool IsPrimaryExpr =
true;
6692 auto NotPrimaryExpr = [&] {
6693 if (TopLevel && IsPrimaryExpr)
6695 IsPrimaryExpr =
false;
6699 switch (
V.getKind()) {
6708 llvm_unreachable(
"unexpected value kind in template argument");
6712 assert(RD &&
"unexpected type for record value");
6715 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6718 (Fields.back()->isUnnamedBitField() ||
6720 V.getStructField(Fields.back()->getFieldIndex())))) {
6724 if (Fields.empty()) {
6725 while (!Bases.empty() &&
6727 V.getStructBase(Bases.size() - 1)))
6728 Bases = Bases.drop_back();
6735 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6736 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6737 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6738 if (Fields[I]->isUnnamedBitField())
6740 mangleValueInTemplateArg(Fields[I]->
getType(),
6741 V.getStructField(Fields[I]->getFieldIndex()),
6750 const FieldDecl *FD =
V.getUnionField();
6768 mangleSourceName(II);
6769 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6783 unsigned N =
V.getArraySize();
6785 N =
V.getArrayInitializedElts();
6790 for (
unsigned I = 0; I != N; ++I) {
6791 const APValue &Elem = I <
V.getArrayInitializedElts()
6792 ?
V.getArrayInitializedElt(I)
6793 :
V.getArrayFiller();
6794 mangleValueInTemplateArg(ElemT, Elem,
false);
6801 const VectorType *VT =
T->
castAs<VectorType>();
6806 unsigned N =
V.getVectorLength();
6809 for (
unsigned I = 0; I != N; ++I)
6810 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6816 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6819 mangleIntegerLiteral(
T,
V.getInt());
6823 mangleFloatLiteral(
T,
V.getFloat());
6827 mangleFixedPointLiteral();
6831 const ComplexType *CT =
T->
castAs<ComplexType>();
6835 if (!
V.getComplexFloatReal().isPosZero() ||
6836 !
V.getComplexFloatImag().isPosZero())
6838 if (!
V.getComplexFloatImag().isPosZero())
6845 const ComplexType *CT =
T->
castAs<ComplexType>();
6849 if (
V.getComplexIntReal().getBoolValue() ||
6850 V.getComplexIntImag().getBoolValue())
6852 if (
V.getComplexIntImag().getBoolValue())
6861 "unexpected type for LValue template arg");
6863 if (
V.isNullPointer()) {
6864 mangleNullPointer(
T);
6868 APValue::LValueBase B =
V.getLValueBase();
6872 CharUnits Offset =
V.getLValueOffset();
6890 ASTContext &Ctx = Context.getASTContext();
6893 if (!
V.hasLValuePath()) {
6909 bool IsArrayToPointerDecayMangledAsDecl =
false;
6910 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6912 IsArrayToPointerDecayMangledAsDecl =
6913 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6914 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6918 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6919 !IsArrayToPointerDecayMangledAsDecl) {
6936 if (NeedExactType &&
6938 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6951 QualType TypeSoFar = B.
getType();
6952 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6956 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6958 mangleExpression(E);
6959 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6962 mangleType(QualType(TI.getType(), 0));
6965 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6975 mangleNumber(
V.getLValueOffset().getQuantity());
6982 if (!
V.getLValueOffset().isZero())
6983 mangleNumber(
V.getLValueOffset().getQuantity());
6987 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6989 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6991 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6992 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6993 TypeSoFar = AT->getElementType();
6995 const Decl *D = E.getAsBaseOrMember().getPointer();
6996 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
7021 if (!
V.getMemberPointerDecl()) {
7022 mangleNullPointer(
T);
7026 ASTContext &Ctx = Context.getASTContext();
7029 if (!
V.getMemberPointerPath().empty()) {
7032 }
else if (NeedExactType &&
7034 T->
castAs<MemberPointerType>()->getPointeeType(),
7035 V.getMemberPointerDecl()->getType()) &&
7036 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7041 mangle(
V.getMemberPointerDecl());
7043 if (!
V.getMemberPointerPath().empty()) {
7053 if (TopLevel && !IsPrimaryExpr)
7057void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7067 Depth += TemplateDepthOffset;
7069 Out <<
'L' << (Depth - 1) <<
'_';
7075void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7078 }
else if (SeqID == 1) {
7085 MutableArrayRef<char> BufferRef(Buffer);
7086 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7088 for (; SeqID != 0; SeqID /= 36) {
7089 unsigned C = SeqID % 36;
7090 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7093 Out.write(I.base(), I - BufferRef.rbegin());
7098void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7099 bool result = mangleSubstitution(tname);
7100 assert(result &&
"no existing substitution for template name");
7106bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7108 if (mangleStandardSubstitution(ND))
7112 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7122bool CXXNameMangler::mangleSubstitution(QualType
T) {
7125 return mangleSubstitution(RD);
7130 return mangleSubstitution(TypePtr);
7134 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7135 return mangleSubstitution(TD);
7138 return mangleSubstitution(
7142bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7143 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7144 if (I == Substitutions.end())
7147 unsigned SeqID = I->second;
7156bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7165 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7166 if (!SD || !SD->getIdentifier()->isStr(Name))
7169 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7172 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7173 if (TemplateArgs.
size() != 1)
7176 if (TemplateArgs[0].getAsType() != A)
7179 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7188bool CXXNameMangler::isStdCharSpecialization(
7189 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7190 bool HasAllocator) {
7195 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7198 QualType A = TemplateArgs[0].getAsType();
7206 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7210 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7219bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7221 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7229 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7230 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7250 if (
const ClassTemplateSpecializationDecl *SD =
7251 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7252 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7261 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7268 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7275 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7282 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7292void CXXNameMangler::addSubstitution(QualType
T) {
7295 addSubstitution(RD);
7301 addSubstitution(TypePtr);
7305 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7306 return addSubstitution(TD);
7312void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7313 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7314 Substitutions[
Ptr] = SeqID++;
7317void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7318 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7319 if (
Other->SeqID > SeqID) {
7320 Substitutions.swap(
Other->Substitutions);
7321 SeqID =
Other->SeqID;
7325CXXNameMangler::AbiTagList
7326CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7328 if (DisableDerivedAbiTags)
7329 return AbiTagList();
7331 llvm::raw_null_ostream NullOutStream;
7332 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7333 TrackReturnTypeTags.disableDerivedAbiTags();
7335 const FunctionProtoType *Proto =
7337 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7338 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7340 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7341 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7343 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7346CXXNameMangler::AbiTagList
7347CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7349 if (DisableDerivedAbiTags)
7350 return AbiTagList();
7352 llvm::raw_null_ostream NullOutStream;
7353 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7354 TrackVariableType.disableDerivedAbiTags();
7356 TrackVariableType.mangleType(VD->
getType());
7358 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7361bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7362 const VarDecl *VD) {
7363 llvm::raw_null_ostream NullOutStream;
7364 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7365 TrackAbiTags.mangle(VD);
7366 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7371void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7375 "Invalid mangleName() call, argument is not a variable or function!");
7377 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7378 getASTContext().getSourceManager(),
7379 "Mangling declaration");
7381 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7383 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7384 return Mangler.mangle(GlobalDecl(CD,
Type));
7387 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7389 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7390 return Mangler.mangle(GlobalDecl(DD,
Type));
7393 CXXNameMangler Mangler(*
this, Out, D);
7397void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7399 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7403void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7405 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7427 auto &LangOpts = Context.getLangOpts();
7430 Context.baseForVTableAuthentication(ThisRD);
7431 unsigned TypedDiscriminator =
7432 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7434 Mangler.mangleVendorQualifier(
"__vtptrauth");
7435 auto &ManglerStream = Mangler.getStream();
7436 ManglerStream <<
"I";
7437 if (
const auto *ExplicitAuth =
7438 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7439 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7441 if (ExplicitAuth->getAddressDiscrimination() ==
7442 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7443 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7445 ManglerStream <<
"Lb"
7446 << (ExplicitAuth->getAddressDiscrimination() ==
7447 VTablePointerAuthenticationAttr::AddressDiscrimination);
7449 switch (ExplicitAuth->getExtraDiscrimination()) {
7450 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7451 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7452 ManglerStream <<
"Lj" << TypedDiscriminator;
7454 ManglerStream <<
"Lj" << 0;
7457 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7458 ManglerStream <<
"Lj" << TypedDiscriminator;
7460 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7461 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7463 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7464 ManglerStream <<
"Lj" << 0;
7468 ManglerStream <<
"Lj"
7469 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7470 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7471 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7472 ManglerStream <<
"Lj" << TypedDiscriminator;
7474 ManglerStream <<
"Lj" << 0;
7476 ManglerStream <<
"E";
7479void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7480 const ThunkInfo &Thunk,
7481 bool ElideOverrideInfo,
7491 "Use mangleCXXDtor for destructor decls!");
7492 CXXNameMangler Mangler(*
this, Out);
7493 Mangler.getStream() <<
"_ZT";
7495 Mangler.getStream() <<
'c';
7506 Mangler.mangleFunctionEncoding(MD);
7507 if (!ElideOverrideInfo)
7511void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7513 const ThunkInfo &Thunk,
7514 bool ElideOverrideInfo,
7518 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7519 Mangler.getStream() <<
"_ZT";
7521 auto &ThisAdjustment = Thunk.
This;
7523 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7524 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7526 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7527 if (!ElideOverrideInfo)
7532void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7536 CXXNameMangler Mangler(*
this, Out);
7539 Mangler.getStream() <<
"_ZGV";
7540 Mangler.mangleName(D);
7543void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7548 Out <<
"__cxx_global_var_init";
7551void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7554 CXXNameMangler Mangler(*
this, Out);
7555 Mangler.getStream() <<
"__dtor_";
7556 if (shouldMangleDeclName(D))
7559 Mangler.getStream() << D->
getName();
7562void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7566 CXXNameMangler Mangler(*
this, Out);
7567 Mangler.getStream() <<
"__finalize_";
7568 if (shouldMangleDeclName(D))
7571 Mangler.getStream() << D->
getName();
7574void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7575 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7576 CXXNameMangler Mangler(*
this, Out);
7577 Mangler.getStream() <<
"__filt_";
7579 if (shouldMangleDeclName(EnclosingFD))
7580 Mangler.mangle(EnclosingDecl);
7582 Mangler.getStream() << EnclosingFD->getName();
7585void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7586 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7587 CXXNameMangler Mangler(*
this, Out);
7588 Mangler.getStream() <<
"__fin_";
7590 if (shouldMangleDeclName(EnclosingFD))
7591 Mangler.mangle(EnclosingDecl);
7593 Mangler.getStream() << EnclosingFD->getName();
7596void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7599 CXXNameMangler Mangler(*
this, Out);
7600 Mangler.getStream() <<
"_ZTH";
7601 Mangler.mangleName(D);
7605ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7608 CXXNameMangler Mangler(*
this, Out);
7609 Mangler.getStream() <<
"_ZTW";
7610 Mangler.mangleName(D);
7613void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7614 unsigned ManglingNumber,
7618 CXXNameMangler Mangler(*
this, Out);
7619 Mangler.getStream() <<
"_ZGR";
7620 Mangler.mangleName(D);
7621 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7622 Mangler.mangleSeqID(ManglingNumber - 1);
7625void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7628 CXXNameMangler Mangler(*
this, Out);
7629 Mangler.getStream() <<
"_ZTV";
7630 Mangler.mangleCXXRecordDecl(RD);
7633void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7636 CXXNameMangler Mangler(*
this, Out);
7637 Mangler.getStream() <<
"_ZTT";
7638 Mangler.mangleCXXRecordDecl(RD);
7641void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7643 const CXXRecordDecl *
Type,
7646 CXXNameMangler Mangler(*
this, Out);
7647 Mangler.getStream() <<
"_ZTC";
7650 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7651 LangOptions::ClangABI::Ver19);
7652 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7653 Mangler.getStream() << Offset;
7654 Mangler.getStream() <<
'_';
7655 Mangler.mangleCXXRecordDecl(
Type);
7658void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7660 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7661 CXXNameMangler Mangler(*
this, Out);
7662 Mangler.getStream() <<
"_ZTI";
7663 Mangler.mangleType(Ty);
7666void ItaniumMangleContextImpl::mangleCXXRTTIName(
7667 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7669 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7670 Mangler.getStream() <<
"_ZTS";
7671 Mangler.mangleType(Ty);
7674void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7675 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7676 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7679void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7680 llvm_unreachable(
"Can't mangle string literals");
7683void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7685 CXXNameMangler Mangler(*
this, Out);
7686 Mangler.mangleLambdaSig(Lambda);
7689void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7692 CXXNameMangler Mangler(*
this, Out);
7693 Mangler.getStream() <<
"_ZGI";
7697 auto Partition = M->
Name.find(
':');
7698 Mangler.mangleModuleNamePrefix(
7699 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7707 return new ItaniumMangleContextImpl(
7710 return std::nullopt;
7719 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
@ LLVM_MARK_AS_BITMASK_ENUM
static bool isUniqueInternalLinkageDecl(GlobalDecl GD, CodeGenModule &CGM)
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.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
static bool isTypeSubstitutable(Qualifiers Quals, const Type *Ty, ASTContext &Ctx)
static IdentifierInfo * getUnionInitName(SourceLocation UnionLoc, DiagnosticsEngine &Diags, const FieldDecl *FD)
static bool hasMangledSubstitutionQualifiers(QualType T)
Determine whether the given type has any qualifiers that are relevant for substitutions.
#define CC_VLS_CASE(ABI_VLEN)
static GlobalDecl getParentOfLocalEntity(const DeclContext *DC)
@ ArmAgnosticSMEZAStateBit
@ ArmStreamingCompatibleBit
static AAPCSBitmaskSME encodeAAPCSZAState(unsigned SMEAttrs)
static StringRef mangleAArch64VectorBase(const BuiltinType *EltType)
static const CXXRecordDecl * getLambdaForInitCapture(const VarDecl *VD)
Retrieve the lambda associated with an init-capture variable.
static void mangleOverrideDiscrimination(CXXNameMangler &Mangler, ASTContext &Context, const ThunkInfo &Thunk)
Mangles the pointer authentication override attribute for classes that have explicit overrides for th...
static bool isZeroInitialized(QualType T, const APValue &V)
Determine whether a given value is equivalent to zero-initialization for the purpose of discarding a ...
static const GlobalDecl isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs)
static bool isParenthesizedADLCallee(const CallExpr *call)
Look at the callee of the given call expression and determine if it's a parenthesized id-expression w...
static TemplateName asTemplateName(GlobalDecl GD)
static QualType getLValueType(ASTContext &Ctx, const APValue &LV)
llvm::MachO::Target Target
llvm::MachO::Record Record
Defines the clang::Module class, which describes a module in the source code.
static StringRef getTriple(const Command &Job)
static StringRef getIdentifier(const Token &Tok)
Enums/classes describing THUNK related information about constructors, destructors and thunks.
Defines the clang::TypeLoc interface and its subclasses.
static const TemplateArgument & getArgument(const TemplateArgument &A)
A non-discriminated union of a base, field, or array index.
static LValuePathEntry ArrayIndex(uint64_t Index)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
const LValueBase getLValueBase() const
ArrayRef< LValuePathEntry > getLValuePath() const
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
@ None
There is no such object (it's outside its lifetime).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
TemplateName getCanonicalTemplateName(TemplateName Name, bool IgnoreDeduced=false) const
Retrieves the "canonical" template name that refers to a given template.
const LangOptions & getLangOpts() const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
QualType getSignatureParameterType(QualType T) const
Retrieve the parameter type as adjusted for use in the signature of a function, decaying array and fu...
bool addressSpaceMapManglingFor(LangAS AS) const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
bool hasSimilarType(QualType T1, QualType T2) const
Determine if two types are similar, according to the C++ rules.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
ConstExprIterator const_arg_iterator
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
bool isGlobalDelete() const
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the member name.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e.
ConstExprIterator const_arg_iterator
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
base_class_iterator bases_end()
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
base_class_iterator bases_begin()
TypeSourceInfo * getLambdaTypeInfo() const
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
const Expr * getSubExpr() const
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isListInitialization() const
Determine whether this expression models list-initialization.
Expr * getArg(unsigned I)
unsigned getNumArgs() const
Retrieve the number of arguments.
Expr * getExprOperand() const
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
bool isTypeOperand() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
QualType getElementType() const
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
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 ...
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
bool isExpansionStmt() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
unsigned getNumTemplateArgs() const
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
TemplateArgumentLoc const * getTemplateArgs() const
IdentifierOrOverloadedOperator getName() const
Represents a vector type where either the type or size is dependent.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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
bool isCompatibleWith(ClangABI Version) const
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
std::string Name
The name of this module.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NestedNameSpecifier getQualifier() const
Fetches the nested-name qualifier, if one was given.
decls_iterator decls_begin() const
unsigned getNumDecls() const
Gets the number of declarations in the unresolved set.
TemplateArgumentLoc const * getTemplateArgs() const
unsigned getNumTemplateArgs() const
DeclarationName getName() const
Gets the name looked up.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
unsigned getFunctionScopeDepth() const
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool hasUnaligned() const
bool hasAddressSpace() const
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Encodes a location in the source.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
TemplateName getReplacement() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
virtual const char * getFloat128Mangling() const
Return the mangled code of __float128.
virtual const char * getIbm128Mangling() const
Return the mangled code of __ibm128.
virtual const char * getLongDoubleMangling() const
Return the mangled code of long double.
virtual const char * getBFloat16Mangling() const
Return the mangled code of bfloat.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
std::pair< TemplateName, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template name that this template name refers to, along with the deduced defa...
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ PackIndexingTemplate
A pack-index-template-name.
@ 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.
unsigned getOrdinal() const
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateName getNamedConcept() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
TypeTrait getTrait() const
Determine which type trait this expression uses.
The base class of the type hierarchy.
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
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...
Represents a GCC generic vector type.
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
@ Number
Just a number, nothing else.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Top level wrappers for InstallAPI frontend operations.
const char * getTraitSpelling(TypeTrait T) LLVM_READONLY
Return the spelling of the trait T. Never null.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName, bool useDirectABI)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ Type
The name was classified as a type.
@ Concept
The name was classified as a concept name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ Deduced
The normal deduced case.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.
@ EST_Dynamic
throw(T1, T2)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Information about how to mangle a template argument.
bool NeedExactType
Do we need to mangle the template argument with an exactly correct type?
const NamedDecl * TemplateParameterToMangle
If we need to prefix the mangling with a mangling of the template parameter, the corresponding parame...
bool isOverloadable()
Determine whether the resolved template might be overloaded on its template parameter list.
TemplateArgManglingInfo(const CXXNameMangler &Mangler, TemplateName TN)
bool needToMangleTemplateParam(const NamedDecl *Param, const TemplateArgument &Arg)
Determine whether we need to prefix this <template-arg> mangling with a <template-param-decl>.
const NamedDecl * UnresolvedExpandedPack
const CXXNameMangler & Mangler
TemplateDecl * ResolvedTemplate
Info getArgInfo(unsigned ParamIdx, const TemplateArgument &Arg)
Determine information about how this template argument should be mangled.
const Expr * getTrailingRequiresClauseToMangle()
Determine if we should mangle a requires-clause after the template argument list.
bool SeenPackExpansionIntoNonPack
ArrayRef< TemplateArgumentLoc > arguments() const
const Expr * ConstraintExpr
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
The this pointer adjustment as well as an optional return adjustment for a thunk.
ThisAdjustment This
The this pointer adjustment.
ReturnAdjustment Return
The return adjustment.
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.