35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#include "llvm/TargetParser/RISCVTargetParser.h"
42namespace UnsupportedItaniumManglingKind =
43 clang::diag::UnsupportedItaniumManglingKind;
47static bool isLocalContainerContext(
const DeclContext *DC) {
51static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
53 return ftd->getTemplatedDecl();
58static const NamedDecl *getStructor(
const NamedDecl *
decl) {
59 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
60 return (fn ? getStructor(fn) :
decl);
63static bool isLambda(
const NamedDecl *ND) {
64 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
71static const unsigned UnknownArity = ~0U;
73class ItaniumMangleContextImpl :
public ItaniumMangleContext {
74 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
75 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
76 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
77 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
78 NamespaceDecl *StdNamespace =
nullptr;
80 bool NeedsUniqueInternalLinkageNames =
false;
83 explicit ItaniumMangleContextImpl(
84 ASTContext &Context, DiagnosticsEngine &Diags,
85 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 : ItaniumMangleContext(Context, Diags, IsAux),
87 DiscriminatorOverride(DiscriminatorOverride) {}
92 bool shouldMangleCXXName(
const NamedDecl *D)
override;
93 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
98 void needsUniqueInternalLinkageNames()
override {
99 NeedsUniqueInternalLinkageNames =
true;
102 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
103 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
104 raw_ostream &)
override;
106 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
107 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
108 raw_ostream &)
override;
109 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
110 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
112 const CXXRecordDecl *
Type, raw_ostream &)
override;
113 void mangleCXXRTTI(QualType
T, raw_ostream &)
override;
114 void mangleCXXRTTIName(QualType
T, raw_ostream &,
115 bool NormalizeIntegers)
override;
116 void mangleCanonicalTypeName(QualType
T, raw_ostream &,
117 bool NormalizeIntegers)
override;
119 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
120 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
121 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
122 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
123 void mangleDynamicAtExitDestructor(
const VarDecl *D,
124 raw_ostream &Out)
override;
125 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
126 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
127 raw_ostream &Out)
override;
128 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
129 raw_ostream &Out)
override;
130 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
131 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
132 raw_ostream &)
override;
134 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
136 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
138 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
140 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
146 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
147 Tag &&
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
152 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
153 if (discriminator == 1)
155 disc = discriminator - 2;
160 unsigned &discriminator = Uniquifier[ND];
161 if (!discriminator) {
162 const DeclContext *DC = getEffectiveDeclContext(ND);
163 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
165 if (discriminator == 1)
167 disc = discriminator-2;
171 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
174 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
175 std::string Name(
"<lambda");
179 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
180 const FunctionDecl *
Func =
184 unsigned DefaultArgNo =
186 Name += llvm::utostr(DefaultArgNo);
190 if (LambdaManglingNumber)
191 LambdaId = LambdaManglingNumber;
193 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
195 Name += llvm::utostr(LambdaId);
200 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
201 return DiscriminatorOverride;
204 NamespaceDecl *getStdNamespace();
206 const DeclContext *getEffectiveDeclContext(
const Decl *D);
207 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
208 return getEffectiveDeclContext(
cast<Decl>(DC));
211 bool isInternalLinkageDecl(
const NamedDecl *ND);
217class CXXNameMangler {
218 ItaniumMangleContextImpl &Context;
222 bool NormalizeIntegers =
false;
224 bool NullOut =
false;
229 bool DisableDerivedAbiTags =
false;
234 const NamedDecl *Structor;
235 unsigned StructorType = 0;
240 unsigned TemplateDepthOffset = 0;
245 class FunctionTypeDepthState {
247 unsigned InFunctionDeclSuffix : 1;
250 FunctionTypeDepthState() : Depth(0), InFunctionDeclSuffix(0) {}
252 unsigned getNestingDepth(
unsigned ParmDepth)
const {
255 assert(ParmDepth < Depth &&
256 "ParmVarDecl is not visible in current parameter environment");
257 return Depth - ParmDepth - InFunctionDeclSuffix;
260 FunctionTypeDepthState push() {
261 FunctionTypeDepthState Saved = *
this;
263 InFunctionDeclSuffix = 0;
267 void pop(FunctionTypeDepthState Saved) {
268 assert(Depth == Saved.Depth + 1 &&
"unbalanced function type depth pop");
272 void enterFunctionDeclSuffix() { InFunctionDeclSuffix = 1; }
273 void leaveFunctionDeclSuffix() { InFunctionDeclSuffix = 0; }
280 using AbiTagList = SmallVector<StringRef, 4>;
285 class AbiTagState final {
287 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
293 AbiTagState(
const AbiTagState &) =
delete;
294 AbiTagState &operator=(
const AbiTagState &) =
delete;
296 ~AbiTagState() { pop(); }
298 void write(raw_ostream &Out,
const NamedDecl *ND,
299 ArrayRef<StringRef> AdditionalAbiTags) {
303 AdditionalAbiTags.empty() &&
304 "only function and variables need a list of additional abi tags");
305 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
306 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
307 llvm::append_range(UsedAbiTags, AbiTag->tags());
314 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
315 llvm::append_range(UsedAbiTags, AbiTag->tags());
316 llvm::append_range(TagList, AbiTag->tags());
319 llvm::append_range(UsedAbiTags, AdditionalAbiTags);
320 llvm::append_range(TagList, AdditionalAbiTags);
323 TagList.erase(llvm::unique(TagList), TagList.end());
325 writeSortedUniqueAbiTags(Out, TagList);
328 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
329 void setUsedAbiTags(
const AbiTagList &AbiTags) {
330 UsedAbiTags = AbiTags;
333 const AbiTagList &getEmittedAbiTags()
const {
334 return EmittedAbiTags;
337 const AbiTagList &getSortedUniqueUsedAbiTags() {
338 llvm::sort(UsedAbiTags);
339 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
345 AbiTagList UsedAbiTags;
347 AbiTagList EmittedAbiTags;
349 AbiTagState *&LinkHead;
350 AbiTagState *Parent =
nullptr;
353 assert(LinkHead ==
this &&
354 "abi tag link head must point to us on destruction");
356 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
357 UsedAbiTags.begin(), UsedAbiTags.end());
358 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
359 EmittedAbiTags.begin(),
360 EmittedAbiTags.end());
365 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
366 for (
const auto &Tag : AbiTags) {
367 EmittedAbiTags.push_back(Tag);
375 AbiTagState *AbiTags =
nullptr;
376 AbiTagState AbiTagsRoot;
378 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
379 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
381 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
383 bool isCompatibleWith(LangOptions::ClangABI Ver) {
387 bool isStd(
const NamespaceDecl *NS);
388 bool isStdNamespace(
const DeclContext *DC);
390 const RecordDecl *GetLocalClassDecl(
const Decl *D);
391 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
392 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
393 llvm::StringRef Name,
bool HasAllocator);
396 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
397 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
398 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
399 AbiTagsRoot(AbiTags) {
404 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
406 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
407 AbiTagsRoot(AbiTags) {}
408 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
410 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
411 AbiTagsRoot(AbiTags) {}
413 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
414 bool NormalizeIntegers_)
415 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
416 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
417 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
418 : Context(Outer.Context),
Out(Out_),
419 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
420 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
421 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
422 Substitutions(Outer.Substitutions),
423 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
425 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
426 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
430 struct WithTemplateDepthOffset {
unsigned Offset; };
431 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
432 WithTemplateDepthOffset Offset)
433 : CXXNameMangler(
C,
Out) {
434 TemplateDepthOffset = Offset.Offset;
437 raw_ostream &getStream() {
return Out; }
439 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
440 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
442 void mangle(GlobalDecl GD);
443 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
444 void mangleNumber(
const llvm::APSInt &I);
445 void mangleNumber(int64_t Number);
446 void mangleFloat(
const llvm::APFloat &F);
447 void mangleFunctionEncoding(GlobalDecl GD);
448 void mangleSeqID(
unsigned SeqID);
449 void mangleName(GlobalDecl GD);
450 void mangleType(QualType
T);
451 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
452 bool SuppressSubstitution =
false);
453 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
454 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
455 void mangleVendorQualifier(StringRef Name);
456 void mangleVendorType(StringRef Name);
459 bool mangleSubstitution(
const NamedDecl *ND);
460 bool mangleSubstitution(QualType
T);
466 bool mangleStandardSubstitution(
const NamedDecl *ND);
468 void addSubstitution(
const NamedDecl *ND) {
471 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
473 void addSubstitution(QualType
T);
477 void extendSubstitutions(CXXNameMangler*
Other);
479 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
480 bool recursive =
false);
481 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
482 const TemplateArgumentLoc *TemplateArgs,
483 unsigned NumTemplateArgs,
484 unsigned KnownArity = UnknownArity);
486 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
488 void mangleNameWithAbiTags(GlobalDecl GD,
489 ArrayRef<StringRef> AdditionalAbiTags = {});
490 void mangleModuleName(
const NamedDecl *ND);
491 void mangleTemplateName(
const TemplateDecl *TD,
492 ArrayRef<TemplateArgument> Args);
493 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
494 ArrayRef<StringRef> AdditionalAbiTags = {}) {
496 UnknownArity, AdditionalAbiTags);
498 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
499 const DeclContext *DC,
unsigned KnownArity,
500 ArrayRef<StringRef> AdditionalAbiTags);
501 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
502 ArrayRef<StringRef> AdditionalAbiTags = {});
503 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
504 ArrayRef<StringRef> AdditionalAbiTags = {});
505 void mangleSourceName(
const IdentifierInfo *II);
506 void mangleConstructorName(
const CXXConstructorDecl *CCD,
507 ArrayRef<StringRef> AdditionalAbiTags = {});
508 void mangleDestructorName(
const CXXDestructorDecl *CDD,
509 ArrayRef<StringRef> AdditionalAbiTags = {});
510 void mangleRegCallName(
const IdentifierInfo *II);
511 void mangleDeviceStubName(
const IdentifierInfo *II);
512 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
513 void mangleSourceNameWithAbiTags(
const NamedDecl *ND,
514 ArrayRef<StringRef> AdditionalAbiTags = {});
515 void mangleLocalName(GlobalDecl GD,
516 ArrayRef<StringRef> AdditionalAbiTags = {});
517 void mangleBlockForPrefix(
const BlockDecl *
Block);
518 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
519 void mangleTemplateParamDecl(
const NamedDecl *Decl);
520 void mangleTemplateParameterList(
const TemplateParameterList *Params);
522 ArrayRef<TemplateArgument> Arguments);
523 void mangleTypeConstraint(
const TypeConstraint *Constraint);
524 void mangleRequiresClause(
const Expr *RequiresClause);
525 void mangleLambda(
const CXXRecordDecl *Lambda);
526 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
527 ArrayRef<StringRef> AdditionalAbiTags = {},
528 bool NoFunction =
false);
529 void mangleNestedName(
const TemplateDecl *TD,
530 ArrayRef<TemplateArgument> Args);
531 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
532 const NamedDecl *PrefixND,
533 ArrayRef<StringRef> AdditionalAbiTags,
534 bool NoFunction =
false);
535 void manglePrefix(NestedNameSpecifier Qualifier);
536 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
537 void manglePrefix(QualType
type);
538 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
540 void DiagnoseUnsupportedPackIndexTemplateName();
541 const NamedDecl *getClosurePrefix(
const Decl *ND);
542 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
543 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
544 StringRef Prefix =
"");
545 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
547 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
553#define ABSTRACT_TYPE(CLASS, PARENT)
554#define NON_CANONICAL_TYPE(CLASS, PARENT)
555#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
556#include "clang/AST/TypeNodes.inc"
558 void mangleType(
const TagType*);
560 static StringRef getCallingConvQualifierName(
CallingConv CC);
563 void mangleSMEAttrs(
unsigned SMEAttrs);
568 void mangleAArch64NeonVectorType(
const VectorType *
T);
570 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
572 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
576 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
577 void mangleFixedPointLiteral();
580 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
581 void mangleMemberExpr(
const Expr *base,
bool isArrow,
585 unsigned NumTemplateArgs,
unsigned knownArity);
586 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
587 void mangleInitListElements(
const InitListExpr *InitList);
590 void mangleReferenceToPack(
const NamedDecl *ND);
591 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
592 bool AsTemplateArg =
false);
596 struct TemplateArgManglingInfo;
599 unsigned NumTemplateArgs);
602 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
605 void mangleTemplateArgExpr(
const Expr *E);
607 bool NeedExactType =
false);
609 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
617 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
619 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
627 getASTContext(), getASTContext().getTranslationUnitDecl(),
628 false, SourceLocation(), SourceLocation(),
629 &getASTContext().Idents.get(
"std"),
652ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
659 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
661 if (ParmVarDecl *ContextParam =
662 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
663 return ContextParam->getDeclContext();
667 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
668 if (ParmVarDecl *ContextParam =
669 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
670 return ContextParam->getDeclContext();
678 if (D == getASTContext().getVaListTagDecl()) {
679 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
680 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
681 return getStdNamespace();
687 return getEffectiveDeclContext(
cast<Decl>(DC));
690 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
692 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
696 if (isLocalContainerContext(ParentDC))
700 return getASTContext().getTranslationUnitDecl();
703 if (
const auto *FD = !getASTContext().getLangOpts().isCompatibleWith(
704 LangOptions::ClangABI::Ver19)
706 : dyn_cast<FunctionDecl>(D)) {
708 return getASTContext().getTranslationUnitDecl();
711 if (FD->isMemberLikeConstrainedFriend() &&
712 !getASTContext().getLangOpts().isCompatibleWith(
713 LangOptions::ClangABI::Ver17))
720bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
723 getEffectiveDeclContext(ND)->isFileContext() &&
730bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
731 const NamedDecl *ND) {
732 if (!NeedsUniqueInternalLinkageNames || !ND)
737 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
738 if (!FD->getType()->getAs<FunctionProtoType>())
742 if (isInternalLinkageDecl(ND))
748bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
749 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
752 if (FD->hasAttr<OverloadableAttr>())
768 if (FD->isMSVCRTEntryPoint())
782 if (!getASTContext().getLangOpts().
CPlusPlus)
785 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
796 const DeclContext *DC = getEffectiveDeclContext(D);
798 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
800 !VD->getOwningModuleForLinkage())
807void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
808 ArrayRef<StringRef> AdditionalAbiTags) {
809 assert(AbiTags &&
"require AbiTagState");
810 AbiTags->write(Out, ND,
811 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
812 : AdditionalAbiTags);
815void CXXNameMangler::mangleSourceNameWithAbiTags(
816 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
818 writeAbiTags(ND, AdditionalAbiTags);
821void CXXNameMangler::mangle(GlobalDecl GD) {
827 mangleFunctionEncoding(GD);
828 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
831 else if (
const IndirectFieldDecl *IFD =
832 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
833 mangleName(IFD->getAnonField());
835 llvm_unreachable(
"unexpected kind of global decl");
838void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
843 if (!Context.shouldMangleDeclName(FD)) {
848 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
849 if (ReturnTypeAbiTags.empty()) {
858 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
860 FunctionTypeDepth.pop(Saved);
861 mangleFunctionEncodingBareType(FD);
868 SmallString<256> FunctionEncodingBuf;
869 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
870 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
872 FunctionEncodingMangler.disableDerivedAbiTags();
874 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
875 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
876 FunctionTypeDepth.pop(Saved);
879 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
880 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
884 const AbiTagList &UsedAbiTags =
885 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
886 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
887 AdditionalAbiTags.erase(
888 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
889 UsedAbiTags.begin(), UsedAbiTags.end(),
890 AdditionalAbiTags.begin()),
891 AdditionalAbiTags.end());
894 Saved = FunctionTypeDepth.push();
895 mangleNameWithAbiTags(FD, AdditionalAbiTags);
896 FunctionTypeDepth.pop(Saved);
897 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
901 extendSubstitutions(&FunctionEncodingMangler);
904void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
905 if (FD->
hasAttr<EnableIfAttr>()) {
906 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
907 Out <<
"Ua9enable_ifI";
908 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
911 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
914 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
919 mangleExpression(EIA->getCond());
922 mangleTemplateArgExpr(EIA->getCond());
926 FunctionTypeDepth.pop(Saved);
931 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
932 if (
auto Inherited = CD->getInheritedConstructor())
933 FD = Inherited.getConstructor();
951 bool MangleReturnType =
false;
955 MangleReturnType =
true;
958 FD = PrimaryTemplate->getTemplatedDecl();
961 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
962 MangleReturnType, FD);
966bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
967 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
971 return II && II->
isStr(
"std");
976bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
983static const GlobalDecl
987 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
996 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
997 TemplateArgs = &Spec->getTemplateArgs();
998 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1003 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1004 TemplateArgs = &Spec->getTemplateArgs();
1005 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1016void CXXNameMangler::mangleName(GlobalDecl GD) {
1018 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1020 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1021 if (VariableTypeAbiTags.empty()) {
1023 mangleNameWithAbiTags(VD);
1028 llvm::raw_null_ostream NullOutStream;
1029 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1030 VariableNameMangler.disableDerivedAbiTags();
1031 VariableNameMangler.mangleNameWithAbiTags(VD);
1034 const AbiTagList &UsedAbiTags =
1035 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1036 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1037 AdditionalAbiTags.erase(
1038 std::set_difference(VariableTypeAbiTags.begin(),
1039 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1040 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1041 AdditionalAbiTags.end());
1044 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1046 mangleNameWithAbiTags(GD);
1050const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1051 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1053 if (isLocalContainerContext(DC))
1054 return dyn_cast<RecordDecl>(D);
1056 DC = Context.getEffectiveDeclContext(D);
1061void CXXNameMangler::mangleNameWithAbiTags(
1062 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1069 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1071 if (GetLocalClassDecl(ND) &&
1072 (!isLambda(ND) || isCompatibleWith(LangOptions::ClangABI::Ver18) ||
1073 !isCompatibleWith(LangOptions::ClangABI::Ver22))) {
1074 mangleLocalName(GD, AdditionalAbiTags);
1082 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1083 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1087 if (isLocalContainerContext(DC)) {
1088 mangleLocalName(GD, AdditionalAbiTags);
1097 const TemplateArgumentList *TemplateArgs =
nullptr;
1098 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1099 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1104 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1108 mangleNestedName(GD, DC, AdditionalAbiTags);
1111void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1114 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1122void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1124 if (
auto It = ModuleSubstitutions.find(Name);
1125 It != ModuleSubstitutions.end()) {
1127 mangleSeqID(It->second);
1133 auto [Prefix, SubName] = Name.rsplit(
'.');
1134 if (SubName.empty())
1137 mangleModuleNamePrefix(Prefix, IsPartition);
1138 IsPartition =
false;
1144 Out << SubName.size() << SubName;
1145 ModuleSubstitutions.insert({Name, SeqID++});
1148void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1149 ArrayRef<TemplateArgument> Args) {
1150 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1153 mangleUnscopedTemplateName(TD, DC);
1156 mangleNestedName(TD, Args);
1160void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1161 ArrayRef<StringRef> AdditionalAbiTags) {
1166 if (isStdNamespace(DC)) {
1167 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1169 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1174 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1176 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1186 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1189void CXXNameMangler::mangleUnscopedTemplateName(
1190 GlobalDecl GD,
const DeclContext *DC,
1191 ArrayRef<StringRef> AdditionalAbiTags) {
1195 if (mangleSubstitution(ND))
1199 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1200 assert(AdditionalAbiTags.empty() &&
1201 "template template param cannot have abi tags");
1202 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1204 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1210 addSubstitution(ND);
1213void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1227 llvm::APInt valueBits = f.bitcastToAPInt();
1228 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1229 assert(numCharacters != 0);
1232 SmallVector<char, 20> buffer(numCharacters);
1235 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1237 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1240 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1241 hexDigit >>= (digitBitIndex % 64);
1245 static const char charForHex[16] = {
1246 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1247 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1249 buffer[stringIndex] = charForHex[hexDigit];
1252 Out.write(buffer.data(), numCharacters);
1255void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1262void CXXNameMangler::mangleFixedPointLiteral() {
1263 DiagnosticsEngine &Diags = Context.getDiags();
1264 Diags.
Report(diag::err_unsupported_itanium_mangling)
1265 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1268void CXXNameMangler::DiagnoseUnsupportedPackIndexTemplateName() {
1269 DiagnosticsEngine &Diags = Context.getDiags();
1270 Diags.
Report(diag::err_unsupported_itanium_mangling)
1271 << UnsupportedItaniumManglingKind::PackIndexTemplateName;
1274void CXXNameMangler::mangleNullPointer(QualType
T) {
1281void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1282 if (
Value.isSigned() &&
Value.isNegative()) {
1284 Value.abs().print(Out,
false);
1286 Value.print(Out,
false);
1290void CXXNameMangler::mangleNumber(int64_t Number) {
1300void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1308 mangleNumber(NonVirtual);
1314 mangleNumber(NonVirtual);
1320void CXXNameMangler::manglePrefix(QualType
type) {
1321 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1322 if (!mangleSubstitution(QualType(TST, 0))) {
1323 mangleTemplatePrefix(TST->getTemplateName());
1328 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1329 addSubstitution(QualType(TST, 0));
1331 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1333 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1334 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1339 assert(DNT->getQualifier());
1340 manglePrefix(DNT->getQualifier());
1342 mangleSourceName(DNT->getIdentifier());
1345 addSubstitution(QualType(DNT, 0));
1357void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1375 case NestedNameSpecifier::Kind::Null:
1376 llvm_unreachable(
"unexpected null nested name specifier");
1378 case NestedNameSpecifier::Kind::Global:
1388 case NestedNameSpecifier::Kind::MicrosoftSuper:
1389 llvm_unreachable(
"Can't mangle __super specifier");
1391 case NestedNameSpecifier::Kind::Namespace: {
1394 mangleUnresolvedPrefix(Prefix,
1398 mangleSourceNameWithAbiTags(Namespace);
1402 case NestedNameSpecifier::Kind::Type: {
1410 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1411 mangleUnresolvedPrefix(Prefix,
1418 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1433void CXXNameMangler::mangleUnresolvedName(
1434 NestedNameSpecifier Qualifier, DeclarationName name,
1435 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1436 unsigned knownArity) {
1438 mangleUnresolvedPrefix(Qualifier);
1439 switch (
name.getNameKind()) {
1442 mangleSourceName(
name.getAsIdentifierInfo());
1447 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1454 mangleOperatorName(name, knownArity);
1457 llvm_unreachable(
"Can't mangle a constructor name!");
1459 llvm_unreachable(
"Can't mangle a using directive name!");
1461 llvm_unreachable(
"Can't mangle a deduction guide name!");
1465 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1471 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1474void CXXNameMangler::mangleUnqualifiedName(
1475 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1476 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1477 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1484 mangleModuleName(ND);
1488 auto *FD = dyn_cast<FunctionDecl>(ND);
1489 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1491 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1492 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1496 unsigned Arity = KnownArity;
1502 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1509 for (
auto *BD : DD->bindings())
1510 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1512 writeAbiTags(ND, AdditionalAbiTags);
1516 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1519 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1520 llvm::raw_svector_ostream GUIDOS(GUID);
1521 Context.mangleMSGuidDecl(GD, GUIDOS);
1522 Out << GUID.size() << GUID;
1526 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1529 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1530 TPO->getValue(),
true);
1548 if (Context.isInternalLinkageDecl(ND))
1551 bool IsRegCall = FD &&
1555 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1557 bool IsOCLDeviceStub =
1559 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1562 mangleDeviceStubName(II);
1563 else if (IsOCLDeviceStub)
1564 mangleOCLDeviceStubName(II);
1566 mangleRegCallName(II);
1568 mangleSourceName(II);
1570 writeAbiTags(ND, AdditionalAbiTags);
1575 assert(ND &&
"mangling empty name without declaration");
1577 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1580 Out <<
"12_GLOBAL__N_1";
1585 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1587 const auto *RD = VD->getType()->castAsRecordDecl();
1598 assert(RD->isAnonymousStructOrUnion()
1599 &&
"Expected anonymous struct or union!");
1600 const FieldDecl *FD = RD->findFirstNamedDataMember();
1606 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1626 "Typedef should not be in another decl context!");
1627 assert(D->getDeclName().getAsIdentifierInfo() &&
1628 "Typedef was not named!");
1629 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1630 assert(AdditionalAbiTags.empty() &&
1631 "Type cannot have additional abi tags");
1643 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1645 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1651 if (
Record->isLambda() &&
1652 ((DeviceNumber && *DeviceNumber > 0) ||
1653 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1654 assert(AdditionalAbiTags.empty() &&
1655 "Lambda type cannot have additional abi tags");
1662 unsigned UnnamedMangle =
1663 getASTContext().getManglingNumber(TD, Context.isAux());
1665 if (UnnamedMangle > 1)
1666 Out << UnnamedMangle - 2;
1668 writeAbiTags(TD, AdditionalAbiTags);
1674 unsigned AnonStructId =
1676 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1683 Str += llvm::utostr(AnonStructId);
1693 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1704 if (ND && Arity == UnknownArity) {
1708 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1709 if (MD->isImplicitObjectMemberFunction())
1715 mangleOperatorName(Name, Arity);
1716 writeAbiTags(ND, AdditionalAbiTags);
1720 llvm_unreachable(
"Can't mangle a deduction guide name!");
1723 llvm_unreachable(
"Can't mangle a using directive name!");
1727void CXXNameMangler::mangleConstructorName(
1728 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1729 const CXXRecordDecl *InheritedFrom =
nullptr;
1731 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1733 InheritedFrom = Inherited.getConstructor()->
getParent();
1734 InheritedTemplateName =
1735 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1736 InheritedTemplateArgs =
1737 Inherited.getConstructor()->getTemplateSpecializationArgs();
1740 if (CCD == Structor)
1743 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1751 if (InheritedTemplateArgs)
1752 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1754 writeAbiTags(CCD, AdditionalAbiTags);
1757void CXXNameMangler::mangleDestructorName(
1758 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1759 if (CDD == Structor)
1762 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1768 writeAbiTags(CDD, AdditionalAbiTags);
1771void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1775 if (getASTContext().getLangOpts().RegCall4)
1776 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1779 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1783void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1787 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1791void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1795 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1796 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1797 << OCLDeviceStubNamePrefix << II->
getName();
1800void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1807void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1808 ArrayRef<StringRef> AdditionalAbiTags,
1817 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1818 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1821 if (
Method->isExplicitObjectMemberFunction())
1824 mangleQualifiers(MethodQuals);
1825 mangleRefQualifier(
Method->getRefQualifier());
1829 const TemplateArgumentList *TemplateArgs =
nullptr;
1830 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1831 mangleTemplatePrefix(TD, NoFunction);
1834 manglePrefix(DC, NoFunction);
1835 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1840void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1841 ArrayRef<TemplateArgument> Args) {
1846 mangleTemplatePrefix(TD);
1852void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1853 GlobalDecl GD,
const NamedDecl *PrefixND,
1854 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1863 mangleClosurePrefix(PrefixND, NoFunction);
1864 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1875 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1877 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1886void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1887 ArrayRef<StringRef> AdditionalAbiTags) {
1895 const RecordDecl *RD = GetLocalClassDecl(D);
1896 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1901 AbiTagState LocalAbiTags(AbiTags);
1903 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1905 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1906 mangleBlockForPrefix(BD);
1913 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1927 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1929 if (
const ParmVarDecl *Parm
1931 if (
const FunctionDecl *
Func
1936 mangleNumber(
Num - 2);
1945 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1946 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1947 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1948 mangleClosurePrefix(PrefixND,
true );
1950 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1951 assert(AdditionalAbiTags.empty() &&
1952 "Block cannot have additional abi tags");
1953 mangleUnqualifiedBlock(BD);
1956 const NamedDecl *PrefixND = getClosurePrefix(ND);
1957 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
1958 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
1961 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1962 AdditionalAbiTags,
true);
1964 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1967 if (
const ParmVarDecl *Parm
1968 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1969 if (
const FunctionDecl *
Func
1974 mangleNumber(
Num - 2);
1979 assert(AdditionalAbiTags.empty() &&
1980 "Block cannot have additional abi tags");
1981 mangleUnqualifiedBlock(BD);
1983 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1986 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1988 if (Context.getNextDiscriminator(ND, disc)) {
1992 Out <<
"__" << disc <<
'_';
1997void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1998 if (GetLocalClassDecl(
Block)) {
1999 mangleLocalName(
Block);
2002 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
2003 if (isLocalContainerContext(DC)) {
2004 mangleLocalName(
Block);
2007 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2008 mangleClosurePrefix(PrefixND);
2011 mangleUnqualifiedBlock(
Block);
2014void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2017 if (Decl *Context =
Block->getBlockManglingContextDecl();
2018 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2020 Context->getDeclContext()->isRecord()) {
2023 mangleSourceNameWithAbiTags(ND);
2029 unsigned Number =
Block->getBlockManglingNumber();
2051void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2053 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2054 if (Ty->isParameterPack())
2056 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2057 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2060 mangleTypeConstraint(Constraint);
2064 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2065 if (Tn->isExpandedParameterPack()) {
2066 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2068 mangleType(Tn->getExpansionType(I));
2071 QualType
T = Tn->getType();
2072 if (Tn->isParameterPack()) {
2074 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2075 T = PackExpansion->getPattern();
2080 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2081 if (Tt->isExpandedParameterPack()) {
2082 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2084 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2086 if (Tt->isParameterPack())
2088 mangleTemplateParameterList(Tt->getTemplateParameters());
2093void CXXNameMangler::mangleTemplateParameterList(
2094 const TemplateParameterList *Params) {
2096 for (
auto *Param : *Params)
2097 mangleTemplateParamDecl(Param);
2098 mangleRequiresClause(Params->getRequiresClause());
2102void CXXNameMangler::mangleTypeConstraint(
2104 const TemplateDecl *TD =
Concept.getAsTemplateDecl();
2106 DiagnoseUnsupportedPackIndexTemplateName();
2109 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
2111 mangleTemplateName(TD, Arguments);
2113 mangleUnscopedName(TD, DC);
2115 mangleNestedName(TD, DC);
2118void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2119 llvm::SmallVector<TemplateArgument, 8> Args;
2121 for (
const TemplateArgumentLoc &ArgLoc :
2123 Args.push_back(ArgLoc.getArgument());
2128void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2130 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2132 mangleExpression(RequiresClause);
2136void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2140 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2143 if (
const IdentifierInfo *Name =
2145 mangleSourceName(Name);
2146 const TemplateArgumentList *TemplateArgs =
nullptr;
2154 mangleLambdaSig(Lambda);
2169 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2173 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2175 mangleNumber(Number - 2);
2179void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2182 mangleTemplateParamDecl(D);
2186 mangleRequiresClause(TPL->getRequiresClause());
2190 mangleBareFunctionType(Proto,
false,
2194void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2196 case NestedNameSpecifier::Kind::Null:
2197 case NestedNameSpecifier::Kind::Global:
2201 case NestedNameSpecifier::Kind::MicrosoftSuper:
2202 llvm_unreachable(
"Can't mangle __super specifier");
2204 case NestedNameSpecifier::Kind::Namespace:
2205 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2208 case NestedNameSpecifier::Kind::Type:
2209 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2213 llvm_unreachable(
"unexpected nested name specifier");
2216void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2229 if (NoFunction && isLocalContainerContext(DC))
2236 if (mangleSubstitution(ND))
2242 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2243 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2244 mangleTemplatePrefix(TD);
2246 *FD->getTemplateSpecializationArgs());
2248 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2251 addSubstitution(ND);
2256 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2258 addSubstitution(ND);
2263 const TemplateArgumentList *TemplateArgs =
nullptr;
2264 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2265 mangleTemplatePrefix(TD);
2267 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2268 mangleClosurePrefix(PrefixND, NoFunction);
2269 mangleUnqualifiedName(ND,
nullptr);
2271 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2272 manglePrefix(DC, NoFunction);
2273 mangleUnqualifiedName(ND, DC);
2276 addSubstitution(ND);
2283 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2284 return mangleTemplatePrefix(TD);
2286 if (
Template.getAsPackIndexingTemplate()) {
2287 DiagnoseUnsupportedPackIndexTemplateName();
2292 assert(
Dependent &&
"unexpected template name kind");
2296 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2297 if (!Clang11Compat && mangleSubstitution(
Template))
2300 manglePrefix(
Dependent->getQualifier());
2302 if (Clang11Compat && mangleSubstitution(
Template))
2305 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2306 const IdentifierInfo *Id = Name.getIdentifier())
2307 mangleSourceName(Id);
2309 mangleOperatorName(Name.getOperator(), UnknownArity);
2314void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2323 if (mangleSubstitution(ND))
2327 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2328 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2330 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2331 manglePrefix(DC, NoFunction);
2333 mangleUnqualifiedName(GD, DC);
2338 addSubstitution(ND);
2341const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2342 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2345 const NamedDecl *Context =
nullptr;
2346 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2347 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2348 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2351 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2353 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2367void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2370 if (mangleSubstitution(ND))
2373 const TemplateArgumentList *TemplateArgs =
nullptr;
2374 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2375 mangleTemplatePrefix(TD, NoFunction);
2378 const auto *DC = Context.getEffectiveDeclContext(ND);
2379 manglePrefix(DC, NoFunction);
2380 mangleUnqualifiedName(ND, DC);
2385 addSubstitution(ND);
2394 if (mangleSubstitution(TN))
2397 TemplateDecl *TD =
nullptr;
2407 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2408 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2415 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2424 mangleUnresolvedPrefix(
Dependent->getQualifier());
2425 mangleSourceName(II);
2434 SubstTemplateTemplateParmStorage *subst
2445 Out <<
"_SUBSTPACK_";
2450 DiagnoseUnsupportedPackIndexTemplateName();
2454 llvm_unreachable(
"Unexpected DeducedTemplate");
2457 addSubstitution(TN);
2460bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2466 case Type::Adjusted:
2468 case Type::ArrayParameter:
2470 case Type::BlockPointer:
2471 case Type::LValueReference:
2472 case Type::RValueReference:
2473 case Type::MemberPointer:
2474 case Type::ConstantArray:
2475 case Type::IncompleteArray:
2476 case Type::VariableArray:
2477 case Type::DependentSizedArray:
2478 case Type::DependentAddressSpace:
2479 case Type::DependentVector:
2480 case Type::DependentSizedExtVector:
2482 case Type::ExtVector:
2483 case Type::ConstantMatrix:
2484 case Type::DependentSizedMatrix:
2485 case Type::FunctionProto:
2486 case Type::FunctionNoProto:
2488 case Type::Attributed:
2489 case Type::BTFTagAttributed:
2490 case Type::OverflowBehavior:
2491 case Type::HLSLAttributedResource:
2492 case Type::HLSLInlineSpirv:
2494 case Type::DeducedTemplateSpecialization:
2495 case Type::PackExpansion:
2496 case Type::ObjCObject:
2497 case Type::ObjCInterface:
2498 case Type::ObjCObjectPointer:
2499 case Type::ObjCTypeParam:
2502 case Type::MacroQualified:
2504 case Type::DependentBitInt:
2505 case Type::CountAttributed:
2506 case Type::LateParsedAttr:
2507 llvm_unreachable(
"type is illegal as a nested name specifier");
2509 case Type::SubstBuiltinTemplatePack:
2514 Out <<
"_SUBSTBUILTINPACK_";
2516 case Type::SubstTemplateTypeParmPack:
2521 Out <<
"_SUBSTPACK_";
2528 case Type::TypeOfExpr:
2530 case Type::Decltype:
2531 case Type::PackIndexing:
2532 case Type::TemplateTypeParm:
2533 case Type::UnaryTransform:
2546 case Type::SubstTemplateTypeParm: {
2550 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2552 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2553 goto unresolvedType;
2560 case Type::PredefinedSugar:
2564 case Type::UnresolvedUsing:
2565 mangleSourceNameWithAbiTags(
2571 mangleSourceNameWithAbiTags(
2575 case Type::TemplateSpecialization: {
2576 const TemplateSpecializationType *TST =
2586 assert(TD &&
"no template for template specialization type");
2588 goto unresolvedType;
2590 mangleSourceNameWithAbiTags(TD);
2602 llvm_unreachable(
"invalid base for a template specialization type");
2605 SubstTemplateTemplateParmStorage *subst =
2616 Out <<
"_SUBSTPACK_";
2621 DiagnoseUnsupportedPackIndexTemplateName();
2627 mangleSourceNameWithAbiTags(TD);
2637 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2641 case Type::InjectedClassName:
2642 mangleSourceNameWithAbiTags(
2646 case Type::DependentName:
2658void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2668 llvm_unreachable(
"Not an operator name");
2691 case OO_New:
Out <<
"nw";
break;
2693 case OO_Array_New:
Out <<
"na";
break;
2695 case OO_Delete:
Out <<
"dl";
break;
2697 case OO_Array_Delete:
Out <<
"da";
break;
2701 Out << (Arity == 1?
"ps" :
"pl");
break;
2705 Out << (Arity == 1?
"ng" :
"mi");
break;
2709 Out << (Arity == 1?
"ad" :
"an");
break;
2714 Out << (Arity == 1?
"de" :
"ml");
break;
2716 case OO_Tilde:
Out <<
"co";
break;
2718 case OO_Slash:
Out <<
"dv";
break;
2720 case OO_Percent:
Out <<
"rm";
break;
2722 case OO_Pipe:
Out <<
"or";
break;
2724 case OO_Caret:
Out <<
"eo";
break;
2726 case OO_Equal:
Out <<
"aS";
break;
2728 case OO_PlusEqual:
Out <<
"pL";
break;
2730 case OO_MinusEqual:
Out <<
"mI";
break;
2732 case OO_StarEqual:
Out <<
"mL";
break;
2734 case OO_SlashEqual:
Out <<
"dV";
break;
2736 case OO_PercentEqual:
Out <<
"rM";
break;
2738 case OO_AmpEqual:
Out <<
"aN";
break;
2740 case OO_PipeEqual:
Out <<
"oR";
break;
2742 case OO_CaretEqual:
Out <<
"eO";
break;
2744 case OO_LessLess:
Out <<
"ls";
break;
2746 case OO_GreaterGreater:
Out <<
"rs";
break;
2748 case OO_LessLessEqual:
Out <<
"lS";
break;
2750 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2752 case OO_EqualEqual:
Out <<
"eq";
break;
2754 case OO_ExclaimEqual:
Out <<
"ne";
break;
2756 case OO_Less:
Out <<
"lt";
break;
2758 case OO_Greater:
Out <<
"gt";
break;
2760 case OO_LessEqual:
Out <<
"le";
break;
2762 case OO_GreaterEqual:
Out <<
"ge";
break;
2764 case OO_Exclaim:
Out <<
"nt";
break;
2766 case OO_AmpAmp:
Out <<
"aa";
break;
2768 case OO_PipePipe:
Out <<
"oo";
break;
2770 case OO_PlusPlus:
Out <<
"pp";
break;
2772 case OO_MinusMinus:
Out <<
"mm";
break;
2774 case OO_Comma:
Out <<
"cm";
break;
2776 case OO_ArrowStar:
Out <<
"pm";
break;
2778 case OO_Arrow:
Out <<
"pt";
break;
2780 case OO_Call:
Out <<
"cl";
break;
2782 case OO_Subscript:
Out <<
"ix";
break;
2787 case OO_Conditional:
Out <<
"qu";
break;
2790 case OO_Coawait:
Out <<
"aw";
break;
2793 case OO_Spaceship:
Out <<
"ss";
break;
2797 llvm_unreachable(
"Not an overloaded operator");
2801void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2820 SmallString<64> ASString;
2826 if (TargetAS != 0 ||
2828 ASString =
"AS" + llvm::utostr(TargetAS);
2831 default: llvm_unreachable(
"Not a language specific address space");
2835 case LangAS::opencl_global:
2836 ASString =
"CLglobal";
2838 case LangAS::opencl_global_device:
2839 ASString =
"CLdevice";
2841 case LangAS::opencl_global_host:
2842 ASString =
"CLhost";
2844 case LangAS::opencl_local:
2845 ASString =
"CLlocal";
2847 case LangAS::opencl_constant:
2848 ASString =
"CLconstant";
2850 case LangAS::opencl_private:
2851 ASString =
"CLprivate";
2853 case LangAS::opencl_generic:
2854 ASString =
"CLgeneric";
2858 case LangAS::sycl_global:
2859 ASString =
"SYglobal";
2861 case LangAS::sycl_global_device:
2862 ASString =
"SYdevice";
2864 case LangAS::sycl_global_host:
2865 ASString =
"SYhost";
2867 case LangAS::sycl_local:
2868 ASString =
"SYlocal";
2870 case LangAS::sycl_private:
2871 ASString =
"SYprivate";
2874 case LangAS::cuda_device:
2875 ASString =
"CUdevice";
2877 case LangAS::cuda_constant:
2878 ASString =
"CUconstant";
2880 case LangAS::cuda_shared:
2881 ASString =
"CUshared";
2884 case LangAS::ptr32_sptr:
2885 ASString =
"ptr32_sptr";
2887 case LangAS::ptr32_uptr:
2891 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2892 ASString =
"ptr32_uptr";
2899 if (!ASString.empty())
2900 mangleVendorQualifier(ASString);
2913 mangleVendorQualifier(
"__weak");
2917 mangleVendorQualifier(
"__unaligned");
2921 mangleVendorQualifier(
"__ptrauth");
2931 << unsigned(PtrAuth.isAddressDiscriminated())
2934 << PtrAuth.getExtraDiscriminator()
2949 mangleVendorQualifier(
"__strong");
2953 mangleVendorQualifier(
"__autoreleasing");
2976void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2980void CXXNameMangler::mangleVendorType(StringRef name) {
2987 switch (RefQualifier) {
3001void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
3002 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3027 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3028 if (DeducedTST->getDeducedType().isNull())
3033void CXXNameMangler::mangleType(QualType
T) {
3067 T =
T.getCanonicalType();
3073 if (
const TemplateSpecializationType *TST
3074 = dyn_cast<TemplateSpecializationType>(
T))
3075 if (!TST->isTypeAlias())
3083 =
T.getSingleStepDesugaredType(Context.getASTContext());
3090 auto [ty, quals] =
T.split();
3092 bool isSubstitutable =
3094 if (isSubstitutable && mangleSubstitution(
T))
3101 quals = Qualifiers();
3107 if (quals || ty->isDependentAddressSpaceType()) {
3108 if (
const DependentAddressSpaceType *DAST =
3109 dyn_cast<DependentAddressSpaceType>(ty)) {
3111 mangleQualifiers(Quals, DAST);
3112 mangleType(QualType(Ty, 0));
3114 mangleQualifiers(quals);
3118 mangleType(QualType(ty, 0));
3121 switch (ty->getTypeClass()) {
3122#define ABSTRACT_TYPE(CLASS, PARENT)
3123#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3125 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3127#define TYPE(CLASS, PARENT) \
3129 mangleType(static_cast<const CLASS##Type*>(ty)); \
3131#include "clang/AST/TypeNodes.inc"
3136 if (isSubstitutable)
3140void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3141 bool SuppressSubstitution) {
3142 if (mangleSubstitution(
Record))
3145 if (SuppressSubstitution)
3150void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3192 std::string type_name;
3196 if (NormalizeIntegers &&
T->isInteger()) {
3197 if (
T->isSignedInteger()) {
3198 switch (getASTContext().getTypeSize(
T)) {
3202 if (mangleSubstitution(BuiltinType::SChar))
3205 addSubstitution(BuiltinType::SChar);
3208 if (mangleSubstitution(BuiltinType::Short))
3211 addSubstitution(BuiltinType::Short);
3214 if (mangleSubstitution(BuiltinType::Int))
3217 addSubstitution(BuiltinType::Int);
3220 if (mangleSubstitution(BuiltinType::Long))
3223 addSubstitution(BuiltinType::Long);
3226 if (mangleSubstitution(BuiltinType::Int128))
3229 addSubstitution(BuiltinType::Int128);
3232 llvm_unreachable(
"Unknown integer size for normalization");
3235 switch (getASTContext().getTypeSize(
T)) {
3237 if (mangleSubstitution(BuiltinType::UChar))
3240 addSubstitution(BuiltinType::UChar);
3243 if (mangleSubstitution(BuiltinType::UShort))
3246 addSubstitution(BuiltinType::UShort);
3249 if (mangleSubstitution(BuiltinType::UInt))
3252 addSubstitution(BuiltinType::UInt);
3255 if (mangleSubstitution(BuiltinType::ULong))
3258 addSubstitution(BuiltinType::ULong);
3261 if (mangleSubstitution(BuiltinType::UInt128))
3264 addSubstitution(BuiltinType::UInt128);
3267 llvm_unreachable(
"Unknown integer size for normalization");
3272 switch (
T->getKind()) {
3273 case BuiltinType::Void:
3276 case BuiltinType::Bool:
3279 case BuiltinType::Char_U:
3280 case BuiltinType::Char_S:
3283 case BuiltinType::UChar:
3286 case BuiltinType::UShort:
3289 case BuiltinType::UInt:
3292 case BuiltinType::ULong:
3295 case BuiltinType::ULongLong:
3298 case BuiltinType::UInt128:
3301 case BuiltinType::SChar:
3304 case BuiltinType::WChar_S:
3305 case BuiltinType::WChar_U:
3308 case BuiltinType::Char8:
3311 case BuiltinType::Char16:
3314 case BuiltinType::Char32:
3317 case BuiltinType::Short:
3320 case BuiltinType::Int:
3323 case BuiltinType::Long:
3326 case BuiltinType::LongLong:
3329 case BuiltinType::Int128:
3332 case BuiltinType::Float16:
3335 case BuiltinType::ShortAccum:
3338 case BuiltinType::Accum:
3341 case BuiltinType::LongAccum:
3344 case BuiltinType::UShortAccum:
3347 case BuiltinType::UAccum:
3350 case BuiltinType::ULongAccum:
3353 case BuiltinType::ShortFract:
3356 case BuiltinType::Fract:
3359 case BuiltinType::LongFract:
3362 case BuiltinType::UShortFract:
3365 case BuiltinType::UFract:
3368 case BuiltinType::ULongFract:
3371 case BuiltinType::SatShortAccum:
3374 case BuiltinType::SatAccum:
3377 case BuiltinType::SatLongAccum:
3380 case BuiltinType::SatUShortAccum:
3383 case BuiltinType::SatUAccum:
3386 case BuiltinType::SatULongAccum:
3389 case BuiltinType::SatShortFract:
3392 case BuiltinType::SatFract:
3395 case BuiltinType::SatLongFract:
3398 case BuiltinType::SatUShortFract:
3401 case BuiltinType::SatUFract:
3404 case BuiltinType::SatULongFract:
3407 case BuiltinType::Half:
3410 case BuiltinType::Float:
3413 case BuiltinType::Double:
3416 case BuiltinType::LongDouble: {
3417 const TargetInfo *TI =
3418 getASTContext().getLangOpts().OpenMP &&
3419 getASTContext().getLangOpts().OpenMPIsTargetDevice
3420 ? getASTContext().getAuxTargetInfo()
3421 : &getASTContext().getTargetInfo();
3425 case BuiltinType::Float128: {
3426 const TargetInfo *TI =
3427 getASTContext().getLangOpts().OpenMP &&
3428 getASTContext().getLangOpts().OpenMPIsTargetDevice
3429 ? getASTContext().getAuxTargetInfo()
3430 : &getASTContext().getTargetInfo();
3434 case BuiltinType::BFloat16: {
3435 const TargetInfo *TI =
3436 ((getASTContext().getLangOpts().OpenMP &&
3437 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3438 getASTContext().getLangOpts().SYCLIsDevice)
3439 ? getASTContext().getAuxTargetInfo()
3440 : &getASTContext().getTargetInfo();
3444 case BuiltinType::Ibm128: {
3445 const TargetInfo *TI = &getASTContext().getTargetInfo();
3449 case BuiltinType::NullPtr:
3453#define BUILTIN_TYPE(Id, SingletonId)
3454#define PLACEHOLDER_TYPE(Id, SingletonId) \
3455 case BuiltinType::Id:
3456#include "clang/AST/BuiltinTypes.def"
3457 case BuiltinType::Dependent:
3459 llvm_unreachable(
"mangling a placeholder type");
3461 case BuiltinType::ObjCId:
3462 Out <<
"11objc_object";
3464 case BuiltinType::ObjCClass:
3465 Out <<
"10objc_class";
3467 case BuiltinType::ObjCSel:
3468 Out <<
"13objc_selector";
3470#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3471 case BuiltinType::Id: \
3472 type_name = "ocl_" #ImgType "_" #Suffix; \
3473 Out << type_name.size() << type_name; \
3475#include "clang/Basic/OpenCLImageTypes.def"
3476 case BuiltinType::OCLSampler:
3477 Out <<
"11ocl_sampler";
3479 case BuiltinType::OCLEvent:
3480 Out <<
"9ocl_event";
3482 case BuiltinType::OCLClkEvent:
3483 Out <<
"12ocl_clkevent";
3485 case BuiltinType::OCLQueue:
3486 Out <<
"9ocl_queue";
3488 case BuiltinType::OCLReserveID:
3489 Out <<
"13ocl_reserveid";
3491#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3492 case BuiltinType::Id: \
3493 type_name = "ocl_" #ExtType; \
3494 Out << type_name.size() << type_name; \
3496#include "clang/Basic/OpenCLExtensionTypes.def"
3500#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3501 case BuiltinType::Id: \
3502 if (T->getKind() == BuiltinType::SveBFloat16 && \
3503 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3505 mangleVendorType("__SVBFloat16_t"); \
3507 type_name = #MangledName; \
3508 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3511#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3512 case BuiltinType::Id: \
3513 type_name = #MangledName; \
3514 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3516#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3517 case BuiltinType::Id: \
3518 type_name = #MangledName; \
3519 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3521#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3522 case BuiltinType::Id: \
3523 type_name = #MangledName; \
3524 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3526#include "clang/Basic/AArch64ACLETypes.def"
3527#define PPC_VECTOR_TYPE(Name, Id, Size) \
3528 case BuiltinType::Id: \
3529 mangleVendorType(#Name); \
3531#include "clang/Basic/PPCTypes.def"
3533#define RVV_TYPE(Name, Id, SingletonId) \
3534 case BuiltinType::Id: \
3535 mangleVendorType(Name); \
3537#include "clang/Basic/RISCVVTypes.def"
3538#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3539 case BuiltinType::Id: \
3540 mangleVendorType(MangledName); \
3542#include "clang/Basic/WebAssemblyReferenceTypes.def"
3543#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3544 case BuiltinType::Id: \
3545 mangleVendorType(Name); \
3547#include "clang/Basic/AMDGPUTypes.def"
3548#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3549 case BuiltinType::Id: \
3550 mangleVendorType(#Name); \
3552#include "clang/Basic/HLSLIntangibleTypes.def"
3553#define SPIRV_TYPE(Name, Id, SingletonId) \
3554 case BuiltinType::Id: \
3555 mangleVendorType(Name); \
3557#include "clang/Basic/SPIRVTypes.def"
3561StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3580#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3616 return "swiftasynccall";
3618 llvm_unreachable(
"bad calling convention");
3621void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3630 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3631 if (!CCQualifier.empty())
3632 mangleVendorQualifier(CCQualifier);
3665 llvm_unreachable(
"Unrecognised SME attribute");
3680void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3700 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3704CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3711 case ParameterABI::Ordinary:
3715 case ParameterABI::HLSLOut:
3716 case ParameterABI::HLSLInOut:
3721 case ParameterABI::SwiftContext:
3722 case ParameterABI::SwiftAsyncContext:
3723 case ParameterABI::SwiftErrorResult:
3724 case ParameterABI::SwiftIndirectResult:
3730 mangleVendorQualifier(
"ns_consumed");
3733 mangleVendorQualifier(
"noescape");
3739void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3743 Out <<
"11__SME_ATTRSI";
3745 mangleExtFunctionInfo(
T);
3762 mangleType(ExceptTy);
3773 mangleBareFunctionType(
T,
true);
3780 mangleSMEAttrs(SMEAttrs);
3783void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3789 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3791 FunctionTypeDepth.enterFunctionDeclSuffix();
3793 FunctionTypeDepth.leaveFunctionDeclSuffix();
3795 FunctionTypeDepth.pop(saved);
3799void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3800 bool MangleReturnType,
3801 const FunctionDecl *FD) {
3804 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3807 if (MangleReturnType) {
3808 FunctionTypeDepth.enterFunctionDeclSuffix();
3812 mangleVendorQualifier(
"ns_returns_retained");
3817 auto SplitReturnTy = ReturnTy.
split();
3819 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3821 mangleType(ReturnTy);
3823 FunctionTypeDepth.leaveFunctionDeclSuffix();
3831 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3845 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3846 if (Attr->isDynamic())
3847 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3849 Out <<
"U17pass_object_size" << Attr->getType();
3860 FunctionTypeDepth.enterFunctionDeclSuffix();
3864 FunctionTypeDepth.pop(saved);
3869void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3870 mangleName(
T->getDecl());
3875void CXXNameMangler::mangleType(
const EnumType *
T) {
3876 mangleType(
static_cast<const TagType*
>(
T));
3878void CXXNameMangler::mangleType(
const RecordType *
T) {
3879 mangleType(
static_cast<const TagType*
>(
T));
3881void CXXNameMangler::mangleType(
const TagType *
T) {
3882 mangleName(
T->getDecl()->getDefinitionOrSelf());
3888void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3889 Out <<
'A' <<
T->getSize() <<
'_';
3890 mangleType(
T->getElementType());
3892void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3895 if (
T->getSizeExpr())
3896 mangleExpression(
T->getSizeExpr());
3898 mangleType(
T->getElementType());
3900void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3905 if (
T->getSizeExpr())
3906 mangleExpression(
T->getSizeExpr());
3908 mangleType(
T->getElementType());
3910void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3912 mangleType(
T->getElementType());
3917void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
3919 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
3920 mangleCXXRecordDecl(RD);
3922 mangleType(QualType(
T->getQualifier().getAsType(), 0));
3924 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3945 mangleType(PointeeType);
3949void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
3950 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3954void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
3959 Out <<
"_SUBSTPACK_";
3962void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
3967 Out <<
"_SUBSTBUILTINPACK_";
3971void CXXNameMangler::mangleType(
const PointerType *
T) {
3975void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
3981void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
3987void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
3993void CXXNameMangler::mangleType(
const ComplexType *
T) {
3995 mangleType(
T->getElementType());
4001void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
4002 QualType EltType =
T->getElementType();
4003 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4004 const char *EltName =
nullptr;
4005 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4007 case BuiltinType::SChar:
4008 case BuiltinType::UChar:
4009 EltName =
"poly8_t";
4011 case BuiltinType::Short:
4012 case BuiltinType::UShort:
4013 EltName =
"poly16_t";
4015 case BuiltinType::LongLong:
4016 case BuiltinType::ULongLong:
4017 EltName =
"poly64_t";
4019 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
4023 case BuiltinType::SChar: EltName =
"int8_t";
break;
4024 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4025 case BuiltinType::Short: EltName =
"int16_t";
break;
4026 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4027 case BuiltinType::Int: EltName =
"int32_t";
break;
4028 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4029 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4030 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4031 case BuiltinType::Double: EltName =
"float64_t";
break;
4032 case BuiltinType::Float: EltName =
"float32_t";
break;
4033 case BuiltinType::Half: EltName =
"float16_t";
break;
4034 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4035 case BuiltinType::MFloat8:
4036 EltName =
"mfloat8_t";
4039 llvm_unreachable(
"unexpected Neon vector element type");
4042 const char *BaseName =
nullptr;
4043 unsigned BitSize = (
T->getNumElements() *
4044 getASTContext().getTypeSize(EltType));
4046 BaseName =
"__simd64_";
4048 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4049 BaseName =
"__simd128_";
4051 Out << strlen(BaseName) + strlen(EltName);
4052 Out << BaseName << EltName;
4055void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4056 DiagnosticsEngine &Diags = Context.getDiags();
4057 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4058 << UnsupportedItaniumManglingKind::DependentNeonVector;
4063 case BuiltinType::SChar:
4065 case BuiltinType::Short:
4067 case BuiltinType::Int:
4069 case BuiltinType::Long:
4070 case BuiltinType::LongLong:
4072 case BuiltinType::UChar:
4074 case BuiltinType::UShort:
4076 case BuiltinType::UInt:
4078 case BuiltinType::ULong:
4079 case BuiltinType::ULongLong:
4081 case BuiltinType::Half:
4083 case BuiltinType::Float:
4085 case BuiltinType::Double:
4087 case BuiltinType::BFloat16:
4089 case BuiltinType::MFloat8:
4092 llvm_unreachable(
"Unexpected vector element base type");
4099void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4100 QualType EltType =
T->getElementType();
4101 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4103 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4106 assert((BitSize == 64 || BitSize == 128) &&
4107 "Neon vector type not 64 or 128 bits");
4110 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4112 case BuiltinType::UChar:
4115 case BuiltinType::UShort:
4118 case BuiltinType::ULong:
4119 case BuiltinType::ULongLong:
4123 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4129 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4132void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4133 DiagnosticsEngine &Diags = Context.getDiags();
4134 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4135 << UnsupportedItaniumManglingKind::DependentNeonVector;
4162void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4163 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4164 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4165 "expected fixed-length SVE vector!");
4167 QualType EltType =
T->getElementType();
4169 "expected builtin type for fixed-length SVE vector!");
4173 case BuiltinType::SChar:
4176 case BuiltinType::UChar: {
4177 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4183 case BuiltinType::Short:
4186 case BuiltinType::UShort:
4189 case BuiltinType::Int:
4192 case BuiltinType::UInt:
4195 case BuiltinType::Long:
4198 case BuiltinType::ULong:
4201 case BuiltinType::Half:
4204 case BuiltinType::Float:
4207 case BuiltinType::Double:
4210 case BuiltinType::BFloat16:
4214 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4217 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4219 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4222 Out <<
"9__SVE_VLSI";
4223 mangleVendorType(TypeName);
4224 Out <<
"Lj" << VecSizeInBits <<
"EE";
4227void CXXNameMangler::mangleAArch64FixedSveVectorType(
4228 const DependentVectorType *
T) {
4229 DiagnosticsEngine &Diags = Context.getDiags();
4230 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4231 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4234void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4235 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4236 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4237 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4238 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4239 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4240 "expected fixed-length RVV vector!");
4242 QualType EltType =
T->getElementType();
4244 "expected builtin type for fixed-length RVV vector!");
4246 SmallString<20> TypeNameStr;
4247 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4248 TypeNameOS <<
"__rvv_";
4250 case BuiltinType::SChar:
4251 TypeNameOS <<
"int8";
4253 case BuiltinType::UChar:
4254 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4255 TypeNameOS <<
"uint8";
4257 TypeNameOS <<
"bool";
4259 case BuiltinType::Short:
4260 TypeNameOS <<
"int16";
4262 case BuiltinType::UShort:
4263 TypeNameOS <<
"uint16";
4265 case BuiltinType::Int:
4266 TypeNameOS <<
"int32";
4268 case BuiltinType::UInt:
4269 TypeNameOS <<
"uint32";
4271 case BuiltinType::Long:
4272 case BuiltinType::LongLong:
4273 TypeNameOS <<
"int64";
4275 case BuiltinType::ULong:
4276 case BuiltinType::ULongLong:
4277 TypeNameOS <<
"uint64";
4279 case BuiltinType::Float16:
4280 TypeNameOS <<
"float16";
4282 case BuiltinType::Float:
4283 TypeNameOS <<
"float32";
4285 case BuiltinType::Double:
4286 TypeNameOS <<
"float64";
4288 case BuiltinType::BFloat16:
4289 TypeNameOS <<
"bfloat16";
4292 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4295 unsigned VecSizeInBits;
4296 switch (
T->getVectorKind()) {
4297 case VectorKind::RVVFixedLengthMask_1:
4300 case VectorKind::RVVFixedLengthMask_2:
4303 case VectorKind::RVVFixedLengthMask_4:
4307 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4312 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4313 getASTContext().getLangOpts(),
4314 TargetInfo::ArmStreamingKind::NotStreaming);
4315 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4317 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4319 if (VecSizeInBits >= VLen)
4320 TypeNameOS << (VecSizeInBits / VLen);
4322 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4324 TypeNameOS << (VLen / VecSizeInBits);
4328 Out <<
"9__RVV_VLSI";
4329 mangleVendorType(TypeNameStr);
4330 Out <<
"Lj" << VecSizeInBits <<
"EE";
4333void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4334 const DependentVectorType *
T) {
4335 DiagnosticsEngine &Diags = Context.getDiags();
4336 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4337 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4348void CXXNameMangler::mangleType(
const VectorType *
T) {
4349 if ((
T->getVectorKind() == VectorKind::Neon ||
4350 T->getVectorKind() == VectorKind::NeonPoly)) {
4351 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4352 llvm::Triple::ArchType
Arch =
4353 getASTContext().getTargetInfo().getTriple().getArch();
4354 if ((
Arch == llvm::Triple::aarch64 ||
4355 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4356 mangleAArch64NeonVectorType(
T);
4358 mangleNeonVectorType(
T);
4360 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4361 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4362 mangleAArch64FixedSveVectorType(
T);
4364 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4365 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4366 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4367 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4368 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4369 mangleRISCVFixedRVVVectorType(
T);
4372 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4373 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4375 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4378 mangleType(
T->getElementType());
4381void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4382 if ((
T->getVectorKind() == VectorKind::Neon ||
4383 T->getVectorKind() == VectorKind::NeonPoly)) {
4384 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4385 llvm::Triple::ArchType
Arch =
4386 getASTContext().getTargetInfo().getTriple().getArch();
4387 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4389 mangleAArch64NeonVectorType(
T);
4391 mangleNeonVectorType(
T);
4393 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4394 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4395 mangleAArch64FixedSveVectorType(
T);
4397 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4398 mangleRISCVFixedRVVVectorType(
T);
4403 mangleExpression(
T->getSizeExpr());
4405 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4407 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4410 mangleType(
T->getElementType());
4413void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4414 mangleType(
static_cast<const VectorType*
>(
T));
4416void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4418 mangleExpression(
T->getSizeExpr());
4420 mangleType(
T->getElementType());
4423void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4427 mangleVendorType(
"matrix_type");
4430 auto &ASTCtx = getASTContext();
4431 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4432 llvm::APSInt Rows(BitWidth);
4433 Rows =
T->getNumRows();
4434 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4435 llvm::APSInt Columns(BitWidth);
4436 Columns =
T->getNumColumns();
4437 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4438 mangleType(
T->getElementType());
4442void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4445 mangleVendorType(
"matrix_type");
4448 mangleTemplateArgExpr(
T->getRowExpr());
4449 mangleTemplateArgExpr(
T->getColumnExpr());
4450 mangleType(
T->getElementType());
4454void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4456 mangleQualifiers(split.
Quals,
T);
4457 mangleType(QualType(split.
Ty, 0));
4460void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4463 mangleType(
T->getPattern());
4466void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4469 mangleType(
T->getPattern());
4470 mangleExpression(
T->getIndexExpr());
4473void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4474 mangleSourceName(
T->getDecl()->getIdentifier());
4477void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4479 if (
T->isKindOfType())
4480 Out <<
"U8__kindof";
4482 if (!
T->qual_empty()) {
4484 SmallString<64> QualStr;
4485 llvm::raw_svector_ostream QualOS(QualStr);
4486 QualOS <<
"objcproto";
4487 for (
const auto *I :
T->quals()) {
4488 StringRef
name = I->getName();
4491 mangleVendorQualifier(QualStr);
4494 mangleType(
T->getBaseType());
4496 if (
T->isSpecialized()) {
4499 for (
auto typeArg :
T->getTypeArgs())
4500 mangleType(typeArg);
4505void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4506 Out <<
"U13block_pointer";
4510void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4515 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4518void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4519 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4520 mangleTemplateName(TD,
T->template_arguments());
4523 mangleTemplatePrefix(
T->getTemplateName());
4528 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4533void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4544 switch (
T->getKeyword()) {
4545 case ElaboratedTypeKeyword::None:
4546 case ElaboratedTypeKeyword::Typename:
4548 case ElaboratedTypeKeyword::Struct:
4549 case ElaboratedTypeKeyword::Class:
4550 case ElaboratedTypeKeyword::Interface:
4553 case ElaboratedTypeKeyword::Union:
4556 case ElaboratedTypeKeyword::Enum:
4562 manglePrefix(
T->getQualifier());
4563 mangleSourceName(
T->getIdentifier());
4567void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4573void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4579void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4580 Expr *E =
T->getUnderlyingExpr();
4599 mangleExpression(E);
4603void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4607 StringRef BuiltinName;
4608 switch (
T->getUTTKind()) {
4609#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4610 case UnaryTransformType::Enum: \
4611 BuiltinName = "__" #Trait; \
4613#include "clang/Basic/BuiltinTraits.inc"
4615 mangleVendorType(BuiltinName);
4619 mangleType(
T->getBaseType());
4623void CXXNameMangler::mangleType(
const AutoType *
T) {
4624 assert(
T->getDeducedType().isNull() &&
4625 "Deduced AutoType shouldn't be handled here!");
4626 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4627 "shouldn't need to mangle __auto_type!");
4632 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4633 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4634 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4635 T->getTypeConstraintArguments());
4637 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4641void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4642 QualType
Deduced =
T->getDeducedType();
4648 "shouldn't form deduced TST unless we know we have a template");
4652void CXXNameMangler::mangleType(
const AtomicType *
T) {
4656 mangleType(
T->getValueType());
4659void CXXNameMangler::mangleType(
const PipeType *
T) {
4666void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4669 if (
T->isWrapKind()) {
4670 Out <<
"U8ObtWrap_";
4672 Out <<
"U8ObtTrap_";
4674 mangleType(
T->getUnderlyingType());
4677void CXXNameMangler::mangleType(
const BitIntType *
T) {
4681 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4684void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4688 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4689 mangleExpression(
T->getNumBitsExpr());
4693void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4697void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4698 llvm::SmallString<64> Str(
"_Res");
4699 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4701 switch (Attrs.ResourceClass) {
4702 case llvm::dxil::ResourceClass::UAV:
4705 case llvm::dxil::ResourceClass::SRV:
4708 case llvm::dxil::ResourceClass::CBuffer:
4711 case llvm::dxil::ResourceClass::Sampler:
4717 if (Attrs.RawBuffer)
4719 if (Attrs.IsCounter)
4723 if (Attrs.isMultiSampled())
4725 if (
T->hasContainedType())
4727 mangleVendorQualifier(Str);
4729 if (
T->hasContainedType()) {
4730 mangleType(
T->getContainedType());
4732 mangleType(
T->getWrappedType());
4735void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4736 SmallString<20> TypeNameStr;
4737 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4739 TypeNameOS <<
"spirv_type";
4741 TypeNameOS <<
"_" <<
T->getOpcode();
4742 TypeNameOS <<
"_" <<
T->getSize();
4743 TypeNameOS <<
"_" <<
T->getAlignment();
4745 mangleVendorType(TypeNameStr);
4747 for (
auto &Operand :
T->getOperands()) {
4748 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4751 case SpirvOperandKind::ConstantId:
4752 mangleVendorQualifier(
"_Const");
4753 mangleIntegerLiteral(
Operand.getResultType(),
4754 llvm::APSInt(
Operand.getValue()));
4756 case SpirvOperandKind::Literal:
4757 mangleVendorQualifier(
"_Lit");
4758 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4759 llvm::APSInt(
Operand.getValue()));
4761 case SpirvOperandKind::TypeId:
4762 mangleVendorQualifier(
"_Type");
4763 mangleType(
Operand.getResultType());
4766 llvm_unreachable(
"Invalid SpirvOperand kind");
4769 TypeNameOS <<
Operand.getKind();
4773void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4774 const llvm::APSInt &
Value) {
4781 Out << (
Value.getBoolValue() ?
'1' :
'0');
4783 mangleNumber(
Value);
4788void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4790 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4791 if (!RT->getDecl()->isAnonymousStructOrUnion())
4793 const auto *ME = dyn_cast<MemberExpr>(Base);
4796 Base = ME->getBase();
4797 IsArrow = ME->isArrow();
4800 if (
Base->isImplicitCXXThis()) {
4806 Out << (IsArrow ?
"pt" :
"dt");
4807 mangleExpression(Base);
4812void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4813 NestedNameSpecifier Qualifier,
4814 NamedDecl *firstQualifierLookup,
4815 DeclarationName member,
4816 const TemplateArgumentLoc *TemplateArgs,
4817 unsigned NumTemplateArgs,
4822 mangleMemberExprBase(base, isArrow);
4823 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4836 if (callee == fn)
return false;
4840 if (!lookup)
return false;
4857void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4859 Out << CastEncoding;
4864void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4866 InitList = Syntactic;
4867 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4868 mangleExpression(InitList->
getInit(i));
4871void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4872 const concepts::Requirement *Req) {
4873 using concepts::Requirement;
4878 auto HandleSubstitutionFailure =
4879 [&](SourceLocation Loc) {
4880 DiagnosticsEngine &Diags = Context.getDiags();
4881 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4882 << UnsupportedItaniumManglingKind::
4883 RequiresExprWithSubstitutionFailure;
4888 case Requirement::RK_Type: {
4890 if (TR->isSubstitutionFailure())
4891 return HandleSubstitutionFailure(
4892 TR->getSubstitutionDiagnostic()->DiagLoc);
4895 mangleType(TR->getType()->getType());
4899 case Requirement::RK_Simple:
4900 case Requirement::RK_Compound: {
4902 if (ER->isExprSubstitutionFailure())
4903 return HandleSubstitutionFailure(
4904 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4907 mangleExpression(ER->getExpr());
4909 if (ER->hasNoexceptRequirement())
4912 if (!ER->getReturnTypeRequirement().isEmpty()) {
4913 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4914 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4915 .getSubstitutionDiagnostic()
4919 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4924 case Requirement::RK_Nested:
4926 if (NR->hasInvalidConstraint()) {
4929 return HandleSubstitutionFailure(RequiresExprLoc);
4933 mangleExpression(NR->getConstraintExpr());
4938void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4939 bool AsTemplateArg) {
4972 QualType ImplicitlyConvertedToType;
4976 bool IsPrimaryExpr =
true;
4977 auto NotPrimaryExpr = [&] {
4978 if (AsTemplateArg && IsPrimaryExpr)
4980 IsPrimaryExpr =
false;
4983 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4984 switch (D->getKind()) {
4997 case Decl::EnumConstant: {
5004 case Decl::NonTypeTemplateParm:
5017 case Expr::NoStmtClass:
5018#define ABSTRACT_STMT(Type)
5019#define EXPR(Type, Base)
5020#define STMT(Type, Base) \
5021 case Expr::Type##Class:
5022#include "clang/AST/StmtNodes.inc"
5027 case Expr::AddrLabelExprClass:
5028 case Expr::DesignatedInitUpdateExprClass:
5029 case Expr::ImplicitValueInitExprClass:
5030 case Expr::ArrayInitLoopExprClass:
5031 case Expr::ArrayInitIndexExprClass:
5032 case Expr::NoInitExprClass:
5033 case Expr::ParenListExprClass:
5034 case Expr::MSPropertyRefExprClass:
5035 case Expr::MSPropertySubscriptExprClass:
5036 case Expr::RecoveryExprClass:
5037 case Expr::ArraySectionExprClass:
5038 case Expr::OMPArrayShapingExprClass:
5039 case Expr::OMPIteratorExprClass:
5040 case Expr::CXXInheritedCtorInitExprClass:
5041 case Expr::CXXParenListInitExprClass:
5042 case Expr::CXXExpansionSelectExprClass:
5043 llvm_unreachable(
"unexpected statement kind");
5045 case Expr::ConstantExprClass:
5049 case Expr::CXXReflectExprClass: {
5051 assert(
false &&
"unimplemented");
5056 case Expr::BlockExprClass:
5057 case Expr::ChooseExprClass:
5058 case Expr::CompoundLiteralExprClass:
5059 case Expr::ExtVectorElementExprClass:
5060 case Expr::MatrixElementExprClass:
5061 case Expr::GenericSelectionExprClass:
5062 case Expr::ObjCEncodeExprClass:
5063 case Expr::ObjCIsaExprClass:
5064 case Expr::ObjCIvarRefExprClass:
5065 case Expr::ObjCMessageExprClass:
5066 case Expr::ObjCPropertyRefExprClass:
5067 case Expr::ObjCProtocolExprClass:
5068 case Expr::ObjCSelectorExprClass:
5069 case Expr::ObjCStringLiteralClass:
5070 case Expr::ObjCBoxedExprClass:
5071 case Expr::ObjCArrayLiteralClass:
5072 case Expr::ObjCDictionaryLiteralClass:
5073 case Expr::ObjCSubscriptRefExprClass:
5074 case Expr::ObjCIndirectCopyRestoreExprClass:
5075 case Expr::ObjCAvailabilityCheckExprClass:
5076 case Expr::OffsetOfExprClass:
5077 case Expr::PredefinedExprClass:
5078 case Expr::ShuffleVectorExprClass:
5079 case Expr::ConvertVectorExprClass:
5080 case Expr::StmtExprClass:
5081 case Expr::ArrayTypeTraitExprClass:
5082 case Expr::ExpressionTraitExprClass:
5083 case Expr::VAArgExprClass:
5084 case Expr::CUDAKernelCallExprClass:
5085 case Expr::AsTypeExprClass:
5086 case Expr::PseudoObjectExprClass:
5087 case Expr::AtomicExprClass:
5088 case Expr::SourceLocExprClass:
5089 case Expr::EmbedExprClass:
5090 case Expr::BuiltinBitCastExprClass: {
5094 DiagnosticsEngine &Diags = Context.getDiags();
5102 case Expr::CXXUuidofExprClass: {
5107 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5108 Out <<
"u8__uuidof";
5117 Out <<
"u8__uuidoft";
5121 Out <<
"u8__uuidofz";
5122 mangleExpression(UuidExp);
5129 case Expr::BinaryConditionalOperatorClass: {
5131 DiagnosticsEngine &Diags = Context.getDiags();
5133 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5139 case Expr::OpaqueValueExprClass:
5140 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5142 case Expr::InitListExprClass: {
5150 case Expr::DesignatedInitExprClass: {
5153 for (
const auto &Designator : DIE->designators()) {
5154 if (Designator.isFieldDesignator()) {
5156 mangleSourceName(Designator.getFieldName());
5157 }
else if (Designator.isArrayDesignator()) {
5159 mangleExpression(DIE->getArrayIndex(Designator));
5161 assert(Designator.isArrayRangeDesignator() &&
5162 "unknown designator kind");
5164 mangleExpression(DIE->getArrayRangeStart(Designator));
5165 mangleExpression(DIE->getArrayRangeEnd(Designator));
5168 mangleExpression(DIE->getInit());
5172 case Expr::CXXDefaultArgExprClass:
5176 case Expr::CXXDefaultInitExprClass:
5180 case Expr::CXXStdInitializerListExprClass:
5184 case Expr::SubstNonTypeTemplateParmExprClass: {
5188 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5190 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5191 mangleValueInTemplateArg(SNTTPE->getParameterType(),
5192 CE->getAPValueResult(),
false,
5202 case Expr::UserDefinedLiteralClass:
5205 case Expr::CXXMemberCallExprClass:
5206 case Expr::CallExprClass: {
5228 CallArity = UnknownArity;
5230 mangleExpression(CE->
getCallee(), CallArity);
5232 mangleExpression(Arg);
5237 case Expr::CXXNewExprClass: {
5240 if (
New->isGlobalNew())
Out <<
"gs";
5241 Out << (
New->isArray() ?
"na" :
"nw");
5243 E =
New->placement_arg_end(); I != E; ++I)
5244 mangleExpression(*I);
5246 mangleType(
New->getAllocatedType());
5247 if (
New->hasInitializer()) {
5248 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5252 const Expr *
Init =
New->getInitializer();
5253 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5258 mangleExpression(*I);
5259 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5260 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5261 mangleExpression(PLE->getExpr(i));
5262 }
else if (
New->getInitializationStyle() ==
5263 CXXNewInitializationStyle::Braces &&
5268 mangleExpression(
Init);
5274 case Expr::CXXPseudoDestructorExprClass: {
5277 if (
const Expr *Base = PDE->getBase())
5278 mangleMemberExprBase(Base, PDE->isArrow());
5279 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5280 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5282 mangleUnresolvedPrefix(Qualifier,
5284 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5288 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5291 }
else if (Qualifier) {
5292 mangleUnresolvedPrefix(Qualifier);
5296 QualType DestroyedType = PDE->getDestroyedType();
5297 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5301 case Expr::MemberExprClass: {
5312 case Expr::UnresolvedMemberExprClass: {
5323 case Expr::CXXDependentScopeMemberExprClass: {
5325 const CXXDependentScopeMemberExpr *ME
5336 case Expr::UnresolvedLookupExprClass: {
5345 case Expr::DependentTemplateIdExprClass: {
5348 if (DTI->getTemplateName().getAsPackIndexingTemplate()) {
5349 DiagnoseUnsupportedPackIndexTemplateName();
5352 mangleUnresolvedName(std::nullopt, DTI->getName(),
5353 DTI->template_arguments().data(),
5354 DTI->getNumTemplateArgs(), Arity);
5358 case Expr::CXXUnresolvedConstructExprClass: {
5364 assert(N == 1 &&
"unexpected form for list initialization");
5368 mangleInitListElements(IL);
5375 if (N != 1)
Out <<
'_';
5376 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5377 if (N != 1)
Out <<
'E';
5381 case Expr::CXXConstructExprClass: {
5388 "implicit CXXConstructExpr must have one argument");
5395 mangleExpression(E);
5400 case Expr::CXXTemporaryObjectExprClass: {
5411 if (!List && N != 1)
5413 if (CE->isStdInitListInitialization()) {
5420 mangleInitListElements(ILE);
5423 mangleExpression(E);
5430 case Expr::CXXScalarValueInitExprClass:
5437 case Expr::CXXNoexceptExprClass:
5443 case Expr::UnaryExprOrTypeTraitExprClass: {
5460 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5462 : ImplicitlyConvertedToType;
5464 mangleIntegerLiteral(
T,
V);
5470 auto MangleAlignofSizeofArg = [&] {
5480 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5481 StringRef Name = {}) {
5484 mangleVendorType(Name);
5495 MangleAlignofSizeofArg();
5497 case UETT_PreferredAlignOf:
5501 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5502 MangleExtensionBuiltin(SAE,
"__alignof__");
5508 MangleAlignofSizeofArg();
5512 case UETT_VectorElements:
5513 case UETT_OpenMPRequiredSimdAlign:
5515 case UETT_PtrAuthTypeDiscriminator:
5516 case UETT_DataSizeOf: {
5517 DiagnosticsEngine &Diags = Context.getDiags();
5526 case Expr::TypeTraitExprClass: {
5531 mangleVendorType(Spelling);
5532 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5533 mangleType(TSI->getType());
5539 case Expr::CXXThrowExprClass: {
5553 case Expr::CXXTypeidExprClass: {
5568 case Expr::CXXDeleteExprClass: {
5579 case Expr::UnaryOperatorClass: {
5588 case Expr::ArraySubscriptExprClass: {
5595 mangleExpression(AE->
getLHS());
5596 mangleExpression(AE->
getRHS());
5600 case Expr::MatrixSingleSubscriptExprClass: {
5604 mangleExpression(ME->
getBase());
5609 case Expr::MatrixSubscriptExprClass: {
5613 mangleExpression(ME->
getBase());
5619 case Expr::CompoundAssignOperatorClass:
5620 case Expr::BinaryOperatorClass: {
5628 mangleExpression(BO->
getLHS());
5629 mangleExpression(BO->
getRHS());
5633 case Expr::CXXRewrittenBinaryOperatorClass: {
5636 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5640 mangleExpression(Decomposed.
LHS);
5641 mangleExpression(Decomposed.
RHS);
5645 case Expr::ConditionalOperatorClass: {
5648 mangleOperatorName(OO_Conditional, 3);
5649 mangleExpression(CO->
getCond());
5650 mangleExpression(CO->
getLHS(), Arity);
5651 mangleExpression(CO->
getRHS(), Arity);
5655 case Expr::ImplicitCastExprClass: {
5656 ImplicitlyConvertedToType = E->
getType();
5661 case Expr::ObjCBridgedCastExprClass: {
5667 mangleCastExpression(E,
"cv");
5671 case Expr::CStyleCastExprClass:
5673 mangleCastExpression(E,
"cv");
5676 case Expr::CXXFunctionalCastExprClass: {
5680 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5681 if (CCE->getParenOrBraceRange().isInvalid())
5682 Sub = CCE->getArg(0)->IgnoreImplicit();
5683 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5684 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5685 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5688 mangleInitListElements(IL);
5691 mangleCastExpression(E,
"cv");
5696 case Expr::CXXStaticCastExprClass:
5698 mangleCastExpression(E,
"sc");
5700 case Expr::CXXDynamicCastExprClass:
5702 mangleCastExpression(E,
"dc");
5704 case Expr::CXXReinterpretCastExprClass:
5706 mangleCastExpression(E,
"rc");
5708 case Expr::CXXConstCastExprClass:
5710 mangleCastExpression(E,
"cc");
5712 case Expr::CXXAddrspaceCastExprClass:
5714 mangleCastExpression(E,
"ac");
5717 case Expr::CXXOperatorCallExprClass: {
5726 for (
unsigned i = 0; i != NumArgs; ++i)
5727 mangleExpression(CE->
getArg(i));
5731 case Expr::ParenExprClass:
5735 case Expr::ConceptSpecializationExprClass: {
5737 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5742 mangleTemplateName(CSE->getConceptDecl(), CSE->getTemplateArguments());
5748 mangleUnresolvedName(
5749 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5750 CSE->getConceptNameInfo().getName(),
5751 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5752 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5756 case Expr::RequiresExprClass: {
5762 if (RE->getLParenLoc().isValid()) {
5764 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5765 if (RE->getLocalParameters().empty()) {
5768 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5776 FunctionTypeDepth.enterFunctionDeclSuffix();
5777 for (
const concepts::Requirement *Req : RE->getRequirements())
5778 mangleRequirement(RE->getExprLoc(), Req);
5779 FunctionTypeDepth.pop(saved);
5783 for (
const concepts::Requirement *Req : RE->getRequirements())
5784 mangleRequirement(RE->getExprLoc(), Req);
5790 case Expr::DeclRefExprClass:
5795 case Expr::SubstNonTypeTemplateParmPackExprClass:
5801 Out <<
"_SUBSTPACK_";
5804 case Expr::FunctionParmPackExprClass: {
5808 Out <<
"v110_SUBSTPACK";
5813 case Expr::DependentScopeDeclRefExprClass: {
5822 case Expr::CXXBindTemporaryExprClass:
5826 case Expr::ExprWithCleanupsClass:
5830 case Expr::FloatingLiteralClass: {
5837 case Expr::FixedPointLiteralClass:
5839 mangleFixedPointLiteral();
5842 case Expr::CharacterLiteralClass:
5846 Out << cast<CharacterLiteral>(E)->getValue();
5851 case Expr::ObjCBoolLiteralExprClass:
5854 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5858 case Expr::CXXBoolLiteralExprClass:
5861 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5865 case Expr::IntegerLiteralClass: {
5869 Value.setIsSigned(
true);
5874 case Expr::ImaginaryLiteralClass: {
5881 if (
const FloatingLiteral *Imag =
5882 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5884 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5886 mangleFloat(Imag->getValue());
5891 Value.setIsSigned(
true);
5892 mangleNumber(
Value);
5898 case Expr::StringLiteralClass: {
5908 case Expr::GNUNullExprClass:
5911 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5914 case Expr::CXXNullPtrLiteralExprClass: {
5920 case Expr::LambdaExprClass: {
5931 case Expr::PackExpansionExprClass:
5937 case Expr::SizeOfPackExprClass: {
5940 if (SPE->isPartiallySubstituted()) {
5942 for (
const auto &A : SPE->getPartialArguments())
5943 mangleTemplateArg(A,
false);
5949 mangleReferenceToPack(SPE->getPack());
5953 case Expr::MaterializeTemporaryExprClass:
5957 case Expr::CXXFoldExprClass: {
5960 if (FE->isLeftFold())
5961 Out << (FE->getInit() ?
"fL" :
"fl");
5963 Out << (FE->getInit() ?
"fR" :
"fr");
5965 if (FE->getOperator() == BO_PtrMemD)
5973 mangleExpression(FE->getLHS());
5975 mangleExpression(FE->getRHS());
5979 case Expr::PackIndexingExprClass: {
5983 mangleReferenceToPack(PE->getPackDecl());
5984 mangleExpression(PE->getIndexExpr());
5988 case Expr::CXXThisExprClass:
5993 case Expr::CoawaitExprClass:
5996 Out <<
"v18co_await";
6000 case Expr::DependentCoawaitExprClass:
6003 Out <<
"v18co_await";
6007 case Expr::CoyieldExprClass:
6010 Out <<
"v18co_yield";
6013 case Expr::SYCLUniqueStableNameExprClass: {
6017 Out <<
"u33__builtin_sycl_unique_stable_name";
6018 mangleType(USN->getTypeSourceInfo()->getType());
6023 case Expr::HLSLOutArgExprClass:
6025 "cannot mangle hlsl temporary value; mangling wrong thing?");
6026 case Expr::OpenACCAsteriskSizeExprClass: {
6028 DiagnosticsEngine &Diags = Context.getDiags();
6029 Diags.
Report(diag::err_unsupported_itanium_mangling)
6030 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
6035 if (AsTemplateArg && !IsPrimaryExpr)
6067void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6072 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6073 nestingDepth == 0) {
6076 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6084 &&
"parameter's type is still an array type?");
6086 if (
const DependentAddressSpaceType *DAST =
6087 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6094 if (parmIndex != 0) {
6095 Out << (parmIndex - 1);
6101 const CXXRecordDecl *InheritedFrom) {
6128 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6131 mangleName(InheritedFrom);
6159 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6163void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6164 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6165 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6166 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6167 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6168 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6169 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6203 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6204 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6205 if (!RD || !RD->isGenericLambda())
6221 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6222 return TTP->hasTypeConstraint();
6239 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6240 return NTTP->getType()->isInstantiationDependentType() ||
6241 NTTP->getType()->getContainedDeducedType();
6248 "A DeducedTemplateName shouldn't escape partial ordering");
6259 auto MangleTemplateParamListToString =
6261 unsigned DepthOffset) {
6262 llvm::raw_svector_ostream Stream(Buffer);
6263 CXXNameMangler(
Mangler.Context, Stream,
6264 WithTemplateDepthOffset{DepthOffset})
6265 .mangleTemplateParameterList(Params);
6268 MangleTemplateParamListToString(ParamTemplateHead,
6269 TTP->getTemplateParameters(), 0);
6273 MangleTemplateParamListToString(ArgTemplateHead,
6275 TTP->getTemplateParameters()->
getDepth());
6276 return ParamTemplateHead != ArgTemplateHead;
6286 return {
true,
nullptr};
6291 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6292 "no parameter for argument");
6313 return {
true,
nullptr};
6328 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6329 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6330 return {NeedExactType,
nullptr};
6342void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6344 unsigned NumTemplateArgs) {
6347 TemplateArgManglingInfo Info(*
this, TN);
6348 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6349 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6351 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6355void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6356 const TemplateArgumentList &AL) {
6359 TemplateArgManglingInfo Info(*
this, TN);
6360 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6361 mangleTemplateArg(Info, i, AL[i]);
6363 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6367void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6368 ArrayRef<TemplateArgument> Args) {
6371 TemplateArgManglingInfo Info(*
this, TN);
6372 for (
unsigned i = 0; i != Args.size(); ++i) {
6373 mangleTemplateArg(Info, i, Args[i]);
6375 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6379void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6380 unsigned Index, TemplateArgument A) {
6381 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6384 if (ArgInfo.TemplateParameterToMangle &&
6385 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6392 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6395 mangleTemplateArg(A, ArgInfo.NeedExactType);
6398void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6408 llvm_unreachable(
"Cannot mangle NULL template argument");
6436 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6437 TPO->getValue(),
true,
6442 ASTContext &Ctx = Context.getASTContext();
6450 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6458 ArrayRef<APValue::LValuePathEntry>(),
6471 true, NeedExactType);
6477 mangleTemplateArg(P, NeedExactType);
6483void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6484 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6485 mangleExpression(E, UnknownArity,
true);
6500 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6501 const ValueDecl *D = DRE->getDecl();
6510 mangleExpression(E);
6523 switch (
V.getKind()) {
6531 assert(RD &&
"unexpected type for record value");
6540 if (!FD->isUnnamedBitField() &&
6550 assert(RD &&
"unexpected type for union value");
6553 if (!FD->isUnnamedBitField())
6563 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6564 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6572 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6579 llvm_unreachable(
"Matrix APValues not yet supported");
6585 return V.getFloat().isPosZero();
6588 return !
V.getFixedPoint().getValue();
6591 return V.getComplexFloatReal().isPosZero() &&
6592 V.getComplexFloatImag().isPosZero();
6595 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6598 return V.isNullPointer();
6601 return !
V.getMemberPointerDecl();
6604 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6611 T = AT->getElementType();
6613 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6656 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6657 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6662void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6664 bool NeedExactType) {
6667 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6670 bool IsPrimaryExpr =
true;
6671 auto NotPrimaryExpr = [&] {
6672 if (TopLevel && IsPrimaryExpr)
6674 IsPrimaryExpr =
false;
6678 switch (
V.getKind()) {
6687 llvm_unreachable(
"unexpected value kind in template argument");
6691 assert(RD &&
"unexpected type for record value");
6694 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6697 (Fields.back()->isUnnamedBitField() ||
6699 V.getStructField(Fields.back()->getFieldIndex())))) {
6703 if (Fields.empty()) {
6704 while (!Bases.empty() &&
6706 V.getStructBase(Bases.size() - 1)))
6707 Bases = Bases.drop_back();
6714 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6715 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6716 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6717 if (Fields[I]->isUnnamedBitField())
6719 mangleValueInTemplateArg(Fields[I]->
getType(),
6720 V.getStructField(Fields[I]->getFieldIndex()),
6729 const FieldDecl *FD =
V.getUnionField();
6747 mangleSourceName(II);
6748 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6762 unsigned N =
V.getArraySize();
6764 N =
V.getArrayInitializedElts();
6769 for (
unsigned I = 0; I != N; ++I) {
6770 const APValue &Elem = I <
V.getArrayInitializedElts()
6771 ?
V.getArrayInitializedElt(I)
6772 :
V.getArrayFiller();
6773 mangleValueInTemplateArg(ElemT, Elem,
false);
6780 const VectorType *VT =
T->
castAs<VectorType>();
6785 unsigned N =
V.getVectorLength();
6788 for (
unsigned I = 0; I != N; ++I)
6789 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6795 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6798 mangleIntegerLiteral(
T,
V.getInt());
6802 mangleFloatLiteral(
T,
V.getFloat());
6806 mangleFixedPointLiteral();
6810 const ComplexType *CT =
T->
castAs<ComplexType>();
6814 if (!
V.getComplexFloatReal().isPosZero() ||
6815 !
V.getComplexFloatImag().isPosZero())
6817 if (!
V.getComplexFloatImag().isPosZero())
6824 const ComplexType *CT =
T->
castAs<ComplexType>();
6828 if (
V.getComplexIntReal().getBoolValue() ||
6829 V.getComplexIntImag().getBoolValue())
6831 if (
V.getComplexIntImag().getBoolValue())
6840 "unexpected type for LValue template arg");
6842 if (
V.isNullPointer()) {
6843 mangleNullPointer(
T);
6847 APValue::LValueBase B =
V.getLValueBase();
6851 CharUnits Offset =
V.getLValueOffset();
6869 ASTContext &Ctx = Context.getASTContext();
6872 if (!
V.hasLValuePath()) {
6888 bool IsArrayToPointerDecayMangledAsDecl =
false;
6889 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6891 IsArrayToPointerDecayMangledAsDecl =
6892 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6893 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6897 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6898 !IsArrayToPointerDecayMangledAsDecl) {
6915 if (NeedExactType &&
6917 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6930 QualType TypeSoFar = B.
getType();
6931 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6935 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6937 mangleExpression(E);
6938 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6941 mangleType(QualType(TI.getType(), 0));
6944 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6954 mangleNumber(
V.getLValueOffset().getQuantity());
6961 if (!
V.getLValueOffset().isZero())
6962 mangleNumber(
V.getLValueOffset().getQuantity());
6966 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6968 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6970 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6971 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6972 TypeSoFar = AT->getElementType();
6974 const Decl *D = E.getAsBaseOrMember().getPointer();
6975 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
7000 if (!
V.getMemberPointerDecl()) {
7001 mangleNullPointer(
T);
7005 ASTContext &Ctx = Context.getASTContext();
7008 if (!
V.getMemberPointerPath().empty()) {
7011 }
else if (NeedExactType &&
7013 T->
castAs<MemberPointerType>()->getPointeeType(),
7014 V.getMemberPointerDecl()->getType()) &&
7015 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7020 mangle(
V.getMemberPointerDecl());
7022 if (!
V.getMemberPointerPath().empty()) {
7032 if (TopLevel && !IsPrimaryExpr)
7036void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7046 Depth += TemplateDepthOffset;
7048 Out <<
'L' << (Depth - 1) <<
'_';
7054void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7057 }
else if (SeqID == 1) {
7064 MutableArrayRef<char> BufferRef(Buffer);
7065 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7067 for (; SeqID != 0; SeqID /= 36) {
7068 unsigned C = SeqID % 36;
7069 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7072 Out.write(I.base(), I - BufferRef.rbegin());
7077void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7078 bool result = mangleSubstitution(tname);
7079 assert(result &&
"no existing substitution for template name");
7085bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7087 if (mangleStandardSubstitution(ND))
7091 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7101bool CXXNameMangler::mangleSubstitution(QualType
T) {
7104 return mangleSubstitution(RD);
7109 return mangleSubstitution(TypePtr);
7113 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7114 return mangleSubstitution(TD);
7117 return mangleSubstitution(
7121bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7122 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7123 if (I == Substitutions.end())
7126 unsigned SeqID = I->second;
7135bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7144 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7145 if (!SD || !SD->getIdentifier()->isStr(Name))
7148 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7151 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7152 if (TemplateArgs.
size() != 1)
7155 if (TemplateArgs[0].getAsType() != A)
7158 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7167bool CXXNameMangler::isStdCharSpecialization(
7168 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7169 bool HasAllocator) {
7174 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7177 QualType A = TemplateArgs[0].getAsType();
7185 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7189 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7198bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7200 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7208 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7209 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7229 if (
const ClassTemplateSpecializationDecl *SD =
7230 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7231 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7240 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7247 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7254 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7261 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7271void CXXNameMangler::addSubstitution(QualType
T) {
7274 addSubstitution(RD);
7280 addSubstitution(TypePtr);
7284 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7285 return addSubstitution(TD);
7291void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7292 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7293 Substitutions[
Ptr] = SeqID++;
7296void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7297 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7298 if (
Other->SeqID > SeqID) {
7299 Substitutions.swap(
Other->Substitutions);
7300 SeqID =
Other->SeqID;
7304CXXNameMangler::AbiTagList
7305CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7307 if (DisableDerivedAbiTags)
7308 return AbiTagList();
7310 llvm::raw_null_ostream NullOutStream;
7311 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7312 TrackReturnTypeTags.disableDerivedAbiTags();
7314 const FunctionProtoType *Proto =
7316 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7317 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7319 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7320 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7322 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7325CXXNameMangler::AbiTagList
7326CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7328 if (DisableDerivedAbiTags)
7329 return AbiTagList();
7331 llvm::raw_null_ostream NullOutStream;
7332 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7333 TrackVariableType.disableDerivedAbiTags();
7335 TrackVariableType.mangleType(VD->
getType());
7337 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7340bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7341 const VarDecl *VD) {
7342 llvm::raw_null_ostream NullOutStream;
7343 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7344 TrackAbiTags.mangle(VD);
7345 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7350void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7354 "Invalid mangleName() call, argument is not a variable or function!");
7356 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7357 getASTContext().getSourceManager(),
7358 "Mangling declaration");
7360 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7362 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7363 return Mangler.mangle(GlobalDecl(CD,
Type));
7366 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7368 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7369 return Mangler.mangle(GlobalDecl(DD,
Type));
7372 CXXNameMangler Mangler(*
this, Out, D);
7376void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7378 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7382void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7384 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7406 auto &LangOpts = Context.getLangOpts();
7409 Context.baseForVTableAuthentication(ThisRD);
7410 unsigned TypedDiscriminator =
7411 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7413 Mangler.mangleVendorQualifier(
"__vtptrauth");
7414 auto &ManglerStream = Mangler.getStream();
7415 ManglerStream <<
"I";
7416 if (
const auto *ExplicitAuth =
7417 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7418 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7420 if (ExplicitAuth->getAddressDiscrimination() ==
7421 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7422 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7424 ManglerStream <<
"Lb"
7425 << (ExplicitAuth->getAddressDiscrimination() ==
7426 VTablePointerAuthenticationAttr::AddressDiscrimination);
7428 switch (ExplicitAuth->getExtraDiscrimination()) {
7429 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7430 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7431 ManglerStream <<
"Lj" << TypedDiscriminator;
7433 ManglerStream <<
"Lj" << 0;
7436 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7437 ManglerStream <<
"Lj" << TypedDiscriminator;
7439 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7440 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7442 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7443 ManglerStream <<
"Lj" << 0;
7447 ManglerStream <<
"Lj"
7448 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7449 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7450 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7451 ManglerStream <<
"Lj" << TypedDiscriminator;
7453 ManglerStream <<
"Lj" << 0;
7455 ManglerStream <<
"E";
7458void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7459 const ThunkInfo &Thunk,
7460 bool ElideOverrideInfo,
7470 "Use mangleCXXDtor for destructor decls!");
7471 CXXNameMangler Mangler(*
this, Out);
7472 Mangler.getStream() <<
"_ZT";
7474 Mangler.getStream() <<
'c';
7485 Mangler.mangleFunctionEncoding(MD);
7486 if (!ElideOverrideInfo)
7490void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7492 const ThunkInfo &Thunk,
7493 bool ElideOverrideInfo,
7497 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7498 Mangler.getStream() <<
"_ZT";
7500 auto &ThisAdjustment = Thunk.
This;
7502 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7503 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7505 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7506 if (!ElideOverrideInfo)
7511void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7515 CXXNameMangler Mangler(*
this, Out);
7518 Mangler.getStream() <<
"_ZGV";
7519 Mangler.mangleName(D);
7522void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7527 Out <<
"__cxx_global_var_init";
7530void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7533 CXXNameMangler Mangler(*
this, Out);
7534 Mangler.getStream() <<
"__dtor_";
7535 if (shouldMangleDeclName(D))
7538 Mangler.getStream() << D->
getName();
7541void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7545 CXXNameMangler Mangler(*
this, Out);
7546 Mangler.getStream() <<
"__finalize_";
7547 if (shouldMangleDeclName(D))
7550 Mangler.getStream() << D->
getName();
7553void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7554 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7555 CXXNameMangler Mangler(*
this, Out);
7556 Mangler.getStream() <<
"__filt_";
7558 if (shouldMangleDeclName(EnclosingFD))
7559 Mangler.mangle(EnclosingDecl);
7561 Mangler.getStream() << EnclosingFD->getName();
7564void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7565 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7566 CXXNameMangler Mangler(*
this, Out);
7567 Mangler.getStream() <<
"__fin_";
7569 if (shouldMangleDeclName(EnclosingFD))
7570 Mangler.mangle(EnclosingDecl);
7572 Mangler.getStream() << EnclosingFD->getName();
7575void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7578 CXXNameMangler Mangler(*
this, Out);
7579 Mangler.getStream() <<
"_ZTH";
7580 Mangler.mangleName(D);
7584ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7587 CXXNameMangler Mangler(*
this, Out);
7588 Mangler.getStream() <<
"_ZTW";
7589 Mangler.mangleName(D);
7592void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7593 unsigned ManglingNumber,
7597 CXXNameMangler Mangler(*
this, Out);
7598 Mangler.getStream() <<
"_ZGR";
7599 Mangler.mangleName(D);
7600 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7601 Mangler.mangleSeqID(ManglingNumber - 1);
7604void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7607 CXXNameMangler Mangler(*
this, Out);
7608 Mangler.getStream() <<
"_ZTV";
7609 Mangler.mangleCXXRecordDecl(RD);
7612void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7615 CXXNameMangler Mangler(*
this, Out);
7616 Mangler.getStream() <<
"_ZTT";
7617 Mangler.mangleCXXRecordDecl(RD);
7620void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7622 const CXXRecordDecl *
Type,
7625 CXXNameMangler Mangler(*
this, Out);
7626 Mangler.getStream() <<
"_ZTC";
7629 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7630 LangOptions::ClangABI::Ver19);
7631 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7632 Mangler.getStream() << Offset;
7633 Mangler.getStream() <<
'_';
7634 Mangler.mangleCXXRecordDecl(
Type);
7637void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7639 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7640 CXXNameMangler Mangler(*
this, Out);
7641 Mangler.getStream() <<
"_ZTI";
7642 Mangler.mangleType(Ty);
7645void ItaniumMangleContextImpl::mangleCXXRTTIName(
7646 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7648 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7649 Mangler.getStream() <<
"_ZTS";
7650 Mangler.mangleType(Ty);
7653void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7654 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7655 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7658void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7659 llvm_unreachable(
"Can't mangle string literals");
7662void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7664 CXXNameMangler Mangler(*
this, Out);
7665 Mangler.mangleLambdaSig(Lambda);
7668void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7671 CXXNameMangler Mangler(*
this, Out);
7672 Mangler.getStream() <<
"_ZGI";
7676 auto Partition = M->
Name.find(
':');
7677 Mangler.mangleModuleNamePrefix(
7678 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7686 return new ItaniumMangleContextImpl(
7689 return std::nullopt;
7698 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.
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.