35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#include "llvm/TargetParser/RISCVTargetParser.h"
42namespace UnsupportedItaniumManglingKind =
43 clang::diag::UnsupportedItaniumManglingKind;
47static bool isLocalContainerContext(
const DeclContext *DC) {
48 return isa<FunctionDecl, ObjCMethodDecl, BlockDecl, CXXExpansionStmtDecl,
49 TopLevelStmtDecl>(DC);
52static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
54 return ftd->getTemplatedDecl();
59static const NamedDecl *getStructor(
const NamedDecl *
decl) {
60 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
61 return (fn ? getStructor(fn) :
decl);
64static bool isLambda(
const NamedDecl *ND) {
65 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
72static const unsigned UnknownArity = ~0U;
74class ItaniumMangleContextImpl :
public ItaniumMangleContext {
75 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
76 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
77 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
78 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
79 NamespaceDecl *StdNamespace =
nullptr;
81 bool NeedsUniqueInternalLinkageNames =
false;
84 explicit ItaniumMangleContextImpl(
85 ASTContext &Context, DiagnosticsEngine &Diags,
86 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
87 : ItaniumMangleContext(Context, Diags, IsAux),
88 DiscriminatorOverride(DiscriminatorOverride) {}
93 bool shouldMangleCXXName(
const NamedDecl *D)
override;
94 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
99 void needsUniqueInternalLinkageNames()
override {
100 NeedsUniqueInternalLinkageNames =
true;
103 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
104 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
105 raw_ostream &)
override;
107 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
108 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
109 raw_ostream &)
override;
110 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
112 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
113 const CXXRecordDecl *
Type, raw_ostream &)
override;
114 void mangleCXXRTTI(QualType
T, raw_ostream &)
override;
115 void mangleCXXRTTIName(QualType
T, raw_ostream &,
116 bool NormalizeIntegers)
override;
117 void mangleCanonicalTypeName(QualType
T, raw_ostream &,
118 bool NormalizeIntegers)
override;
120 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
121 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
122 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
123 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
124 void mangleDynamicAtExitDestructor(
const VarDecl *D,
125 raw_ostream &Out)
override;
126 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
127 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
128 raw_ostream &Out)
override;
129 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
130 raw_ostream &Out)
override;
131 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
132 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
133 raw_ostream &)
override;
135 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
137 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
139 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
141 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
147 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
148 Tag &&
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
153 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
154 if (discriminator == 1)
156 disc = discriminator - 2;
161 unsigned &discriminator = Uniquifier[ND];
162 if (!discriminator) {
163 const DeclContext *DC = getEffectiveDeclContext(ND);
164 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
166 if (discriminator == 1)
168 disc = discriminator-2;
172 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
175 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
176 std::string Name(
"<lambda");
180 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
181 const FunctionDecl *
Func =
185 unsigned DefaultArgNo =
187 Name += llvm::utostr(DefaultArgNo);
191 if (LambdaManglingNumber)
192 LambdaId = LambdaManglingNumber;
194 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
196 Name += llvm::utostr(LambdaId);
201 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
202 return DiscriminatorOverride;
205 NamespaceDecl *getStdNamespace();
207 const DeclContext *getEffectiveDeclContext(
const Decl *D);
208 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
209 return getEffectiveDeclContext(
cast<Decl>(DC));
212 bool isInternalLinkageDecl(
const NamedDecl *ND);
218class CXXNameMangler {
219 ItaniumMangleContextImpl &Context;
223 bool NormalizeIntegers =
false;
225 bool NullOut =
false;
230 bool DisableDerivedAbiTags =
false;
235 const NamedDecl *Structor;
236 unsigned StructorType = 0;
241 unsigned TemplateDepthOffset = 0;
246 class FunctionTypeDepthState {
248 unsigned InFunctionDeclSuffix : 1;
251 FunctionTypeDepthState() : Depth(0), InFunctionDeclSuffix(0) {}
253 unsigned getNestingDepth(
unsigned ParmDepth)
const {
256 assert(ParmDepth < Depth &&
257 "ParmVarDecl is not visible in current parameter environment");
258 return Depth - ParmDepth - InFunctionDeclSuffix;
261 FunctionTypeDepthState push() {
262 FunctionTypeDepthState Saved = *
this;
264 InFunctionDeclSuffix = 0;
268 void pop(FunctionTypeDepthState Saved) {
269 assert(Depth == Saved.Depth + 1 &&
"unbalanced function type depth pop");
273 void enterFunctionDeclSuffix() { InFunctionDeclSuffix = 1; }
274 void leaveFunctionDeclSuffix() { InFunctionDeclSuffix = 0; }
281 using AbiTagList = SmallVector<StringRef, 4>;
286 class AbiTagState final {
288 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
294 AbiTagState(
const AbiTagState &) =
delete;
295 AbiTagState &operator=(
const AbiTagState &) =
delete;
297 ~AbiTagState() { pop(); }
299 void write(raw_ostream &Out,
const NamedDecl *ND,
300 ArrayRef<StringRef> AdditionalAbiTags) {
304 AdditionalAbiTags.empty() &&
305 "only function and variables need a list of additional abi tags");
306 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
307 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
308 llvm::append_range(UsedAbiTags, AbiTag->tags());
315 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
316 llvm::append_range(UsedAbiTags, AbiTag->tags());
317 llvm::append_range(TagList, AbiTag->tags());
320 llvm::append_range(UsedAbiTags, AdditionalAbiTags);
321 llvm::append_range(TagList, AdditionalAbiTags);
324 TagList.erase(llvm::unique(TagList), TagList.end());
326 writeSortedUniqueAbiTags(Out, TagList);
329 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
330 void setUsedAbiTags(
const AbiTagList &AbiTags) {
331 UsedAbiTags = AbiTags;
334 const AbiTagList &getEmittedAbiTags()
const {
335 return EmittedAbiTags;
338 const AbiTagList &getSortedUniqueUsedAbiTags() {
339 llvm::sort(UsedAbiTags);
340 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
346 AbiTagList UsedAbiTags;
348 AbiTagList EmittedAbiTags;
350 AbiTagState *&LinkHead;
351 AbiTagState *Parent =
nullptr;
354 assert(LinkHead ==
this &&
355 "abi tag link head must point to us on destruction");
357 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
358 UsedAbiTags.begin(), UsedAbiTags.end());
359 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
360 EmittedAbiTags.begin(),
361 EmittedAbiTags.end());
366 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
367 for (
const auto &Tag : AbiTags) {
368 EmittedAbiTags.push_back(Tag);
376 AbiTagState *AbiTags =
nullptr;
377 AbiTagState AbiTagsRoot;
379 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
380 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
382 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
384 bool isCompatibleWith(LangOptions::ClangABI Ver) {
388 bool isStd(
const NamespaceDecl *NS);
389 bool isStdNamespace(
const DeclContext *DC);
391 const RecordDecl *GetLocalClassDecl(
const Decl *D);
392 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
393 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
394 llvm::StringRef Name,
bool HasAllocator);
397 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
398 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
399 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
400 AbiTagsRoot(AbiTags) {
405 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
407 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
408 AbiTagsRoot(AbiTags) {}
409 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
411 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
412 AbiTagsRoot(AbiTags) {}
414 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
415 bool NormalizeIntegers_)
416 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
417 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
418 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
419 : Context(Outer.Context),
Out(Out_),
420 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
421 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
422 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
423 Substitutions(Outer.Substitutions),
424 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
426 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
427 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
431 struct WithTemplateDepthOffset {
unsigned Offset; };
432 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
433 WithTemplateDepthOffset Offset)
434 : CXXNameMangler(
C,
Out) {
435 TemplateDepthOffset = Offset.Offset;
438 raw_ostream &getStream() {
return Out; }
440 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
441 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
443 void mangle(GlobalDecl GD);
444 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
445 void mangleNumber(
const llvm::APSInt &I);
446 void mangleNumber(int64_t Number);
447 void mangleFloat(
const llvm::APFloat &F);
448 void mangleFunctionEncoding(GlobalDecl GD);
449 void mangleSeqID(
unsigned SeqID);
450 void mangleName(GlobalDecl GD);
451 void mangleType(QualType
T);
452 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
453 bool SuppressSubstitution =
false);
454 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
455 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
456 void mangleVendorQualifier(StringRef Name);
457 void mangleVendorType(StringRef Name);
460 bool mangleSubstitution(
const NamedDecl *ND);
461 bool mangleSubstitution(QualType
T);
467 bool mangleStandardSubstitution(
const NamedDecl *ND);
469 void addSubstitution(
const NamedDecl *ND) {
472 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
474 void addSubstitution(QualType
T);
478 void extendSubstitutions(CXXNameMangler*
Other);
480 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
481 bool recursive =
false);
482 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
483 const TemplateArgumentLoc *TemplateArgs,
484 unsigned NumTemplateArgs,
485 unsigned KnownArity = UnknownArity);
487 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
489 void mangleNameWithAbiTags(GlobalDecl GD,
490 ArrayRef<StringRef> AdditionalAbiTags = {});
491 void mangleModuleName(
const NamedDecl *ND);
492 void mangleTemplateName(
const TemplateDecl *TD,
493 ArrayRef<TemplateArgument> Args);
494 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
495 ArrayRef<StringRef> AdditionalAbiTags = {}) {
497 UnknownArity, AdditionalAbiTags);
499 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
500 const DeclContext *DC,
unsigned KnownArity,
501 ArrayRef<StringRef> AdditionalAbiTags);
502 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
503 ArrayRef<StringRef> AdditionalAbiTags = {});
504 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
505 ArrayRef<StringRef> AdditionalAbiTags = {});
506 void mangleSourceName(
const IdentifierInfo *II);
507 void mangleConstructorName(
const CXXConstructorDecl *CCD,
508 ArrayRef<StringRef> AdditionalAbiTags = {});
509 void mangleDestructorName(
const CXXDestructorDecl *CDD,
510 ArrayRef<StringRef> AdditionalAbiTags = {});
511 void mangleRegCallName(
const IdentifierInfo *II);
512 void mangleDeviceStubName(
const IdentifierInfo *II);
513 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
514 void mangleSourceNameWithAbiTags(
const NamedDecl *ND,
515 ArrayRef<StringRef> AdditionalAbiTags = {});
516 void mangleLocalName(GlobalDecl GD,
517 ArrayRef<StringRef> AdditionalAbiTags = {});
518 void mangleBlockForPrefix(
const BlockDecl *
Block);
519 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
520 void mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D);
521 void mangleTemplateParamDecl(
const NamedDecl *Decl);
522 void mangleTemplateParameterList(
const TemplateParameterList *Params);
524 ArrayRef<TemplateArgument> Arguments);
525 void mangleTypeConstraint(
const TypeConstraint *Constraint);
526 void mangleRequiresClause(
const Expr *RequiresClause);
527 void mangleLambda(
const CXXRecordDecl *Lambda);
528 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
529 ArrayRef<StringRef> AdditionalAbiTags = {},
530 bool NoFunction =
false);
531 void mangleNestedName(
const TemplateDecl *TD,
532 ArrayRef<TemplateArgument> Args);
533 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
534 const NamedDecl *PrefixND,
535 ArrayRef<StringRef> AdditionalAbiTags,
536 bool NoFunction =
false);
537 void manglePrefix(NestedNameSpecifier Qualifier);
538 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
539 void manglePrefix(QualType
type);
540 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
542 void DiagnoseUnsupportedPackIndexTemplateName();
543 const NamedDecl *getClosurePrefix(
const Decl *ND);
544 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
545 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
546 StringRef Prefix =
"");
547 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
549 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
555#define ABSTRACT_TYPE(CLASS, PARENT)
556#define NON_CANONICAL_TYPE(CLASS, PARENT)
557#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
558#include "clang/AST/TypeNodes.inc"
560 void mangleType(
const TagType*);
562 static StringRef getCallingConvQualifierName(
CallingConv CC);
565 void mangleSMEAttrs(
unsigned SMEAttrs);
570 void mangleAArch64NeonVectorType(
const VectorType *
T);
572 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
574 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
578 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
579 void mangleFixedPointLiteral();
581 void mangleReflection(
ReflectionKind Kind,
const void *OpaqueOperand);
583 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
584 void mangleMemberExpr(
const Expr *base,
bool isArrow,
588 unsigned NumTemplateArgs,
unsigned knownArity);
589 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
590 void mangleInitListElements(
const InitListExpr *InitList);
593 void mangleReferenceToPack(
const NamedDecl *ND);
594 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
595 bool AsTemplateArg =
false);
599 struct TemplateArgManglingInfo;
602 unsigned NumTemplateArgs);
605 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
608 void mangleTemplateArgExpr(
const Expr *E);
610 bool NeedExactType =
false);
612 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
620 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
622 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
630 getASTContext(), getASTContext().getTranslationUnitDecl(),
631 false, SourceLocation(), SourceLocation(),
632 &getASTContext().Idents.get(
"std"),
655ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
662 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
664 if (ParmVarDecl *ContextParam =
665 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
666 return ContextParam->getDeclContext();
670 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
671 if (ParmVarDecl *ContextParam =
672 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
673 return ContextParam->getDeclContext();
681 if (D == getASTContext().getVaListTagDecl()) {
682 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
683 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
684 return getStdNamespace();
690 return getEffectiveDeclContext(
cast<Decl>(DC));
693 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
695 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
699 if (isLocalContainerContext(ParentDC))
703 return getASTContext().getTranslationUnitDecl();
706 if (
const auto *FD = !getASTContext().getLangOpts().isCompatibleWith(
707 LangOptions::ClangABI::Ver19)
709 : dyn_cast<FunctionDecl>(D)) {
711 return getASTContext().getTranslationUnitDecl();
714 if (FD->isMemberLikeConstrainedFriend() &&
715 !getASTContext().getLangOpts().isCompatibleWith(
716 LangOptions::ClangABI::Ver17))
723bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
726 getEffectiveDeclContext(ND)->isFileContext() &&
733bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
734 const NamedDecl *ND) {
735 if (!NeedsUniqueInternalLinkageNames || !ND)
738 const auto *FD = dyn_cast<FunctionDecl>(ND);
744 if (!FD->getType()->getAs<FunctionProtoType>())
747 if (isInternalLinkageDecl(ND))
753bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
754 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
757 if (FD->hasAttr<OverloadableAttr>())
773 if (FD->isMSVCRTEntryPoint())
787 if (!getASTContext().getLangOpts().
CPlusPlus)
790 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
801 const DeclContext *DC = getEffectiveDeclContext(D);
803 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
805 !VD->getOwningModuleForLinkage())
812void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
813 ArrayRef<StringRef> AdditionalAbiTags) {
814 assert(AbiTags &&
"require AbiTagState");
815 AbiTags->write(Out, ND,
816 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
817 : AdditionalAbiTags);
820void CXXNameMangler::mangleSourceNameWithAbiTags(
821 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
823 writeAbiTags(ND, AdditionalAbiTags);
826void CXXNameMangler::mangle(GlobalDecl GD) {
832 mangleFunctionEncoding(GD);
833 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
836 else if (
const IndirectFieldDecl *IFD =
837 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
838 mangleName(IFD->getAnonField());
840 llvm_unreachable(
"unexpected kind of global decl");
843void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
848 if (!Context.shouldMangleDeclName(FD)) {
853 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
854 if (ReturnTypeAbiTags.empty()) {
863 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
865 FunctionTypeDepth.pop(Saved);
866 mangleFunctionEncodingBareType(FD);
873 SmallString<256> FunctionEncodingBuf;
874 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
875 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
877 FunctionEncodingMangler.disableDerivedAbiTags();
879 FunctionTypeDepthState EncodingSaved =
880 FunctionEncodingMangler.FunctionTypeDepth.push();
881 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
882 FunctionEncodingMangler.FunctionTypeDepth.pop(EncodingSaved);
885 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
886 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
890 const AbiTagList &UsedAbiTags =
891 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
892 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
893 AdditionalAbiTags.erase(
894 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
895 UsedAbiTags.begin(), UsedAbiTags.end(),
896 AdditionalAbiTags.begin()),
897 AdditionalAbiTags.end());
900 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
901 mangleNameWithAbiTags(FD, AdditionalAbiTags);
902 FunctionTypeDepth.pop(Saved);
903 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
907 extendSubstitutions(&FunctionEncodingMangler);
910void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
911 if (FD->
hasAttr<EnableIfAttr>()) {
912 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
913 Out <<
"Ua9enable_ifI";
914 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
917 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
920 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
925 mangleExpression(EIA->getCond());
928 mangleTemplateArgExpr(EIA->getCond());
932 FunctionTypeDepth.pop(Saved);
937 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
938 if (
auto Inherited = CD->getInheritedConstructor())
939 FD = Inherited.getConstructor();
957 bool MangleReturnType =
false;
961 MangleReturnType =
true;
964 FD = PrimaryTemplate->getTemplatedDecl();
967 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
968 MangleReturnType, FD);
972bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
973 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
977 return II && II->
isStr(
"std");
982bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
989static const GlobalDecl
993 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
1002 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1003 TemplateArgs = &Spec->getTemplateArgs();
1004 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1009 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1010 TemplateArgs = &Spec->getTemplateArgs();
1011 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1022void CXXNameMangler::mangleName(GlobalDecl GD) {
1024 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1026 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1027 if (VariableTypeAbiTags.empty()) {
1029 mangleNameWithAbiTags(VD);
1034 llvm::raw_null_ostream NullOutStream;
1035 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1036 VariableNameMangler.disableDerivedAbiTags();
1037 VariableNameMangler.mangleNameWithAbiTags(VD);
1040 const AbiTagList &UsedAbiTags =
1041 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1042 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1043 AdditionalAbiTags.erase(
1044 std::set_difference(VariableTypeAbiTags.begin(),
1045 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1046 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1047 AdditionalAbiTags.end());
1050 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1052 mangleNameWithAbiTags(GD);
1056const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1057 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1059 if (isLocalContainerContext(DC))
1060 return dyn_cast<RecordDecl>(D);
1062 DC = Context.getEffectiveDeclContext(D);
1067void CXXNameMangler::mangleNameWithAbiTags(
1068 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1075 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1077 if (GetLocalClassDecl(ND) &&
1078 (!isLambda(ND) || isCompatibleWith(LangOptions::ClangABI::Ver18) ||
1079 !isCompatibleWith(LangOptions::ClangABI::Ver22))) {
1080 mangleLocalName(GD, AdditionalAbiTags);
1088 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1089 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1093 if (isLocalContainerContext(DC)) {
1094 mangleLocalName(GD, AdditionalAbiTags);
1103 const TemplateArgumentList *TemplateArgs =
nullptr;
1104 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1105 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1110 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1114 mangleNestedName(GD, DC, AdditionalAbiTags);
1117void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1120 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1128void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1130 if (
auto It = ModuleSubstitutions.find(Name);
1131 It != ModuleSubstitutions.end()) {
1133 mangleSeqID(It->second);
1139 auto [Prefix, SubName] = Name.rsplit(
'.');
1140 if (SubName.empty())
1143 mangleModuleNamePrefix(Prefix, IsPartition);
1144 IsPartition =
false;
1150 Out << SubName.size() << SubName;
1151 ModuleSubstitutions.insert({Name, SeqID++});
1154void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1155 ArrayRef<TemplateArgument> Args) {
1156 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1159 mangleUnscopedTemplateName(TD, DC);
1162 mangleNestedName(TD, Args);
1166void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1167 ArrayRef<StringRef> AdditionalAbiTags) {
1172 if (isStdNamespace(DC)) {
1173 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1175 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1180 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1182 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1192 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1195void CXXNameMangler::mangleUnscopedTemplateName(
1196 GlobalDecl GD,
const DeclContext *DC,
1197 ArrayRef<StringRef> AdditionalAbiTags) {
1201 if (mangleSubstitution(ND))
1205 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1206 assert(AdditionalAbiTags.empty() &&
1207 "template template param cannot have abi tags");
1208 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1210 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1216 addSubstitution(ND);
1219void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1233 llvm::APInt valueBits = f.bitcastToAPInt();
1234 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1235 assert(numCharacters != 0);
1238 SmallVector<char, 20> buffer(numCharacters);
1241 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1243 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1246 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1247 hexDigit >>= (digitBitIndex % 64);
1251 static const char charForHex[16] = {
1252 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1253 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1255 buffer[stringIndex] = charForHex[hexDigit];
1258 Out.write(buffer.data(), numCharacters);
1261void CXXNameMangler::mangleFloatLiteral(QualType
T,
const llvm::APFloat &
V) {
1268void CXXNameMangler::mangleFixedPointLiteral() {
1269 DiagnosticsEngine &Diags = Context.getDiags();
1270 Diags.
Report(diag::err_unsupported_itanium_mangling)
1271 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1274void CXXNameMangler::DiagnoseUnsupportedPackIndexTemplateName() {
1275 DiagnosticsEngine &Diags = Context.getDiags();
1276 Diags.
Report(diag::err_unsupported_itanium_mangling)
1277 << UnsupportedItaniumManglingKind::PackIndexTemplateName;
1280void CXXNameMangler::mangleNullPointer(QualType
T) {
1288 const void *OpaqueOperand) {
1324 case ReflectionKind::Null:
1327 case ReflectionKind::Type: {
1328 const auto *TSI =
static_cast<const TypeSourceInfo *
>(OpaqueOperand);
1329 QualType QT = TSI->getType();
1332 if (
const auto *TDT = QT->
getAs<TypedefType>()) {
1334 mangleName(TDT->getDecl()->getCanonicalDecl());
1347void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1348 if (
Value.isSigned() &&
Value.isNegative()) {
1350 Value.abs().print(Out,
false);
1352 Value.print(Out,
false);
1356void CXXNameMangler::mangleNumber(int64_t Number) {
1366void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1374 mangleNumber(NonVirtual);
1380 mangleNumber(NonVirtual);
1386void CXXNameMangler::manglePrefix(QualType
type) {
1387 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1388 if (!mangleSubstitution(QualType(TST, 0))) {
1389 mangleTemplatePrefix(TST->getTemplateName());
1394 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1395 addSubstitution(QualType(TST, 0));
1397 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1399 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1400 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1405 assert(DNT->getQualifier());
1406 manglePrefix(DNT->getQualifier());
1408 mangleSourceName(DNT->getIdentifier());
1411 addSubstitution(QualType(DNT, 0));
1423void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1441 case NestedNameSpecifier::Kind::Null:
1442 llvm_unreachable(
"unexpected null nested name specifier");
1444 case NestedNameSpecifier::Kind::Global:
1454 case NestedNameSpecifier::Kind::MicrosoftSuper:
1455 llvm_unreachable(
"Can't mangle __super specifier");
1457 case NestedNameSpecifier::Kind::Namespace: {
1460 mangleUnresolvedPrefix(Prefix,
1464 mangleSourceNameWithAbiTags(Namespace);
1468 case NestedNameSpecifier::Kind::Type: {
1476 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1477 mangleUnresolvedPrefix(Prefix,
1484 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1499void CXXNameMangler::mangleUnresolvedName(
1500 NestedNameSpecifier Qualifier, DeclarationName name,
1501 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1502 unsigned knownArity) {
1504 mangleUnresolvedPrefix(Qualifier);
1505 switch (
name.getNameKind()) {
1508 mangleSourceName(
name.getAsIdentifierInfo());
1513 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1520 mangleOperatorName(name, knownArity);
1523 llvm_unreachable(
"Can't mangle a constructor name!");
1525 llvm_unreachable(
"Can't mangle a using directive name!");
1527 llvm_unreachable(
"Can't mangle a deduction guide name!");
1531 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1537 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1540void CXXNameMangler::mangleUnqualifiedName(
1541 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1542 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1543 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1550 mangleModuleName(ND);
1554 auto *FD = dyn_cast<FunctionDecl>(ND);
1555 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1557 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1558 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1562 unsigned Arity = KnownArity;
1568 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1575 for (
auto *BD : DD->bindings())
1576 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1578 writeAbiTags(ND, AdditionalAbiTags);
1582 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1585 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1586 llvm::raw_svector_ostream GUIDOS(GUID);
1587 Context.mangleMSGuidDecl(GD, GUIDOS);
1588 Out << GUID.size() << GUID;
1592 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1595 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1596 TPO->getValue(),
true);
1614 if (Context.isInternalLinkageDecl(ND))
1617 bool IsRegCall = FD &&
1621 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1623 bool IsOCLDeviceStub =
1625 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1628 mangleDeviceStubName(II);
1629 else if (IsOCLDeviceStub)
1630 mangleOCLDeviceStubName(II);
1632 mangleRegCallName(II);
1634 mangleSourceName(II);
1636 writeAbiTags(ND, AdditionalAbiTags);
1641 assert(ND &&
"mangling empty name without declaration");
1643 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1646 Out <<
"12_GLOBAL__N_1";
1651 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1653 const auto *RD = VD->getType()->castAsRecordDecl();
1664 assert(RD->isAnonymousStructOrUnion()
1665 &&
"Expected anonymous struct or union!");
1666 const FieldDecl *FD = RD->findFirstNamedDataMember();
1672 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1692 "Typedef should not be in another decl context!");
1693 assert(D->getDeclName().getAsIdentifierInfo() &&
1694 "Typedef was not named!");
1695 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1696 assert(AdditionalAbiTags.empty() &&
1697 "Type cannot have additional abi tags");
1709 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1711 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1717 if (
Record->isLambda() &&
1718 ((DeviceNumber && *DeviceNumber > 0) ||
1719 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1720 assert(AdditionalAbiTags.empty() &&
1721 "Lambda type cannot have additional abi tags");
1728 unsigned UnnamedMangle =
1729 getASTContext().getManglingNumber(TD, Context.isAux());
1731 if (UnnamedMangle > 1)
1732 Out << UnnamedMangle - 2;
1734 writeAbiTags(TD, AdditionalAbiTags);
1740 unsigned AnonStructId =
1742 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1749 Str += llvm::utostr(AnonStructId);
1759 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1770 if (ND && Arity == UnknownArity) {
1774 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1775 if (MD->isImplicitObjectMemberFunction())
1781 mangleOperatorName(Name, Arity);
1782 writeAbiTags(ND, AdditionalAbiTags);
1786 llvm_unreachable(
"Can't mangle a deduction guide name!");
1789 llvm_unreachable(
"Can't mangle a using directive name!");
1793void CXXNameMangler::mangleConstructorName(
1794 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1795 const CXXRecordDecl *InheritedFrom =
nullptr;
1797 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1799 InheritedFrom = Inherited.getConstructor()->
getParent();
1800 InheritedTemplateName =
1801 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1802 InheritedTemplateArgs =
1803 Inherited.getConstructor()->getTemplateSpecializationArgs();
1806 if (CCD == Structor)
1809 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1817 if (InheritedTemplateArgs)
1818 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1820 writeAbiTags(CCD, AdditionalAbiTags);
1823void CXXNameMangler::mangleDestructorName(
1824 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1825 if (CDD == Structor)
1828 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1834 writeAbiTags(CDD, AdditionalAbiTags);
1837void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1841 if (getASTContext().getLangOpts().RegCall4)
1842 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1845 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1849void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1853 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1857void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1861 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1862 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1863 << OCLDeviceStubNamePrefix << II->
getName();
1866void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1873void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1874 ArrayRef<StringRef> AdditionalAbiTags,
1883 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1884 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1887 if (
Method->isExplicitObjectMemberFunction())
1890 mangleQualifiers(MethodQuals);
1891 mangleRefQualifier(
Method->getRefQualifier());
1895 const TemplateArgumentList *TemplateArgs =
nullptr;
1896 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1897 mangleTemplatePrefix(TD, NoFunction);
1900 manglePrefix(DC, NoFunction);
1901 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1906void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1907 ArrayRef<TemplateArgument> Args) {
1912 mangleTemplatePrefix(TD);
1918void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1919 GlobalDecl GD,
const NamedDecl *PrefixND,
1920 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1929 mangleClosurePrefix(PrefixND, NoFunction);
1930 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1941 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1943 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1952void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1953 ArrayRef<StringRef> AdditionalAbiTags) {
1961 const RecordDecl *RD = GetLocalClassDecl(D);
1962 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1967 AbiTagState LocalAbiTags(AbiTags);
1969 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1971 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1972 mangleBlockForPrefix(BD);
1973 }
else if (
const auto *TLSD = dyn_cast<TopLevelStmtDecl>(DC)) {
1974 mangleTopLevelStmtEncoding(TLSD);
1981 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1995 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1997 if (
const ParmVarDecl *Parm
1999 if (
const FunctionDecl *
Func
2004 mangleNumber(
Num - 2);
2013 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
2014 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2015 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
2016 mangleClosurePrefix(PrefixND,
true );
2018 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
2019 assert(AdditionalAbiTags.empty() &&
2020 "Block cannot have additional abi tags");
2021 mangleUnqualifiedBlock(BD);
2024 const NamedDecl *PrefixND = getClosurePrefix(ND);
2025 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
2026 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
2029 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
2030 AdditionalAbiTags,
true);
2032 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2035 if (
const ParmVarDecl *Parm
2036 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
2037 if (
const FunctionDecl *
Func
2042 mangleNumber(
Num - 2);
2047 assert(AdditionalAbiTags.empty() &&
2048 "Block cannot have additional abi tags");
2049 mangleUnqualifiedBlock(BD);
2051 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
2054 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
2056 if (Context.getNextDiscriminator(ND, disc)) {
2060 Out <<
"__" << disc <<
'_';
2065void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
2066 if (GetLocalClassDecl(
Block)) {
2067 mangleLocalName(
Block);
2070 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
2071 if (isLocalContainerContext(DC)) {
2072 mangleLocalName(
Block);
2075 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2076 mangleClosurePrefix(PrefixND);
2079 mangleUnqualifiedBlock(
Block);
2082void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2085 if (Decl *Context =
Block->getBlockManglingContextDecl();
2086 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2088 Context->getDeclContext()->isRecord()) {
2091 mangleSourceNameWithAbiTags(ND);
2097 unsigned Number =
Block->getBlockManglingNumber();
2112void CXXNameMangler::mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D) {
2114 SmallString<16> Name(
"__stmt__");
2116 Out <<
'L' << Name.size() << Name <<
'v';
2126void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2128 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2129 if (Ty->isParameterPack())
2131 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2132 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2135 mangleTypeConstraint(Constraint);
2139 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2140 if (Tn->isExpandedParameterPack()) {
2141 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2143 mangleType(Tn->getExpansionType(I));
2146 QualType
T = Tn->getType();
2147 if (Tn->isParameterPack()) {
2149 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2150 T = PackExpansion->getPattern();
2155 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2156 if (Tt->isExpandedParameterPack()) {
2157 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2159 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2161 if (Tt->isParameterPack())
2163 mangleTemplateParameterList(Tt->getTemplateParameters());
2168void CXXNameMangler::mangleTemplateParameterList(
2169 const TemplateParameterList *Params) {
2171 for (
auto *Param : *Params)
2172 mangleTemplateParamDecl(Param);
2173 mangleRequiresClause(Params->getRequiresClause());
2177void CXXNameMangler::mangleTypeConstraint(
2179 const TemplateDecl *TD =
Concept.getAsTemplateDecl();
2181 DiagnoseUnsupportedPackIndexTemplateName();
2184 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
2186 mangleTemplateName(TD, Arguments);
2188 mangleUnscopedName(TD, DC);
2190 mangleNestedName(TD, DC);
2193void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2194 llvm::SmallVector<TemplateArgument, 8> Args;
2196 for (
const TemplateArgumentLoc &ArgLoc :
2198 Args.push_back(ArgLoc.getArgument());
2203void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2205 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2207 mangleExpression(RequiresClause);
2211void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2215 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2218 if (
const IdentifierInfo *Name =
2220 mangleSourceName(Name);
2221 const TemplateArgumentList *TemplateArgs =
nullptr;
2229 mangleLambdaSig(Lambda);
2244 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2248 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2250 mangleNumber(Number - 2);
2254void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2257 mangleTemplateParamDecl(D);
2261 mangleRequiresClause(TPL->getRequiresClause());
2265 mangleBareFunctionType(Proto,
false,
2269void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2271 case NestedNameSpecifier::Kind::Null:
2272 case NestedNameSpecifier::Kind::Global:
2276 case NestedNameSpecifier::Kind::MicrosoftSuper:
2277 llvm_unreachable(
"Can't mangle __super specifier");
2279 case NestedNameSpecifier::Kind::Namespace:
2280 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2283 case NestedNameSpecifier::Kind::Type:
2284 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2288 llvm_unreachable(
"unexpected nested name specifier");
2291void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2304 if (NoFunction && isLocalContainerContext(DC))
2311 if (mangleSubstitution(ND))
2317 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2318 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2319 mangleTemplatePrefix(TD);
2321 *FD->getTemplateSpecializationArgs());
2323 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2326 addSubstitution(ND);
2331 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2333 addSubstitution(ND);
2338 const TemplateArgumentList *TemplateArgs =
nullptr;
2339 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2340 mangleTemplatePrefix(TD);
2342 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2343 mangleClosurePrefix(PrefixND, NoFunction);
2344 mangleUnqualifiedName(ND,
nullptr);
2346 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2347 manglePrefix(DC, NoFunction);
2348 mangleUnqualifiedName(ND, DC);
2351 addSubstitution(ND);
2358 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2359 return mangleTemplatePrefix(TD);
2361 if (
Template.getAsPackIndexingTemplate()) {
2362 DiagnoseUnsupportedPackIndexTemplateName();
2367 assert(
Dependent &&
"unexpected template name kind");
2371 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2372 if (!Clang11Compat && mangleSubstitution(
Template))
2375 manglePrefix(
Dependent->getQualifier());
2377 if (Clang11Compat && mangleSubstitution(
Template))
2380 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2381 const IdentifierInfo *Id = Name.getIdentifier())
2382 mangleSourceName(Id);
2384 mangleOperatorName(Name.getOperator(), UnknownArity);
2389void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2398 if (mangleSubstitution(ND))
2402 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2403 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2405 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2406 manglePrefix(DC, NoFunction);
2408 mangleUnqualifiedName(GD, DC);
2413 addSubstitution(ND);
2416const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2417 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2420 const NamedDecl *Context =
nullptr;
2421 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2422 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2423 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2426 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2428 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2442void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2445 if (mangleSubstitution(ND))
2448 const TemplateArgumentList *TemplateArgs =
nullptr;
2449 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2450 mangleTemplatePrefix(TD, NoFunction);
2453 const auto *DC = Context.getEffectiveDeclContext(ND);
2454 manglePrefix(DC, NoFunction);
2455 mangleUnqualifiedName(ND, DC);
2460 addSubstitution(ND);
2469 if (mangleSubstitution(TN))
2472 TemplateDecl *TD =
nullptr;
2482 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2483 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2490 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2499 mangleUnresolvedPrefix(
Dependent->getQualifier());
2500 mangleSourceName(II);
2509 SubstTemplateTemplateParmStorage *subst
2520 Out <<
"_SUBSTPACK_";
2525 DiagnoseUnsupportedPackIndexTemplateName();
2529 llvm_unreachable(
"Unexpected DeducedTemplate");
2532 addSubstitution(TN);
2535bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2541 case Type::Adjusted:
2543 case Type::ArrayParameter:
2545 case Type::BlockPointer:
2546 case Type::LValueReference:
2547 case Type::RValueReference:
2548 case Type::MemberPointer:
2549 case Type::ConstantArray:
2550 case Type::IncompleteArray:
2551 case Type::VariableArray:
2552 case Type::DependentSizedArray:
2553 case Type::DependentAddressSpace:
2554 case Type::DependentVector:
2555 case Type::DependentSizedExtVector:
2557 case Type::ExtVector:
2558 case Type::ConstantMatrix:
2559 case Type::DependentSizedMatrix:
2560 case Type::FunctionProto:
2561 case Type::FunctionNoProto:
2563 case Type::Attributed:
2564 case Type::BTFTagAttributed:
2565 case Type::OverflowBehavior:
2566 case Type::HLSLAttributedResource:
2567 case Type::HLSLInlineSpirv:
2569 case Type::DeducedTemplateSpecialization:
2570 case Type::PackExpansion:
2571 case Type::ObjCObject:
2572 case Type::ObjCInterface:
2573 case Type::ObjCObjectPointer:
2574 case Type::ObjCTypeParam:
2577 case Type::MacroQualified:
2579 case Type::DependentBitInt:
2580 case Type::CountAttributed:
2581 case Type::LateParsedAttr:
2582 llvm_unreachable(
"type is illegal as a nested name specifier");
2584 case Type::SubstBuiltinTemplatePack:
2589 Out <<
"_SUBSTBUILTINPACK_";
2591 case Type::SubstTemplateTypeParmPack:
2596 Out <<
"_SUBSTPACK_";
2603 case Type::TypeOfExpr:
2605 case Type::Decltype:
2606 case Type::PackIndexing:
2607 case Type::TemplateTypeParm:
2608 case Type::UnaryTransform:
2621 case Type::SubstTemplateTypeParm: {
2625 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2627 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2628 goto unresolvedType;
2635 case Type::PredefinedSugar:
2639 case Type::UnresolvedUsing:
2640 mangleSourceNameWithAbiTags(
2646 mangleSourceNameWithAbiTags(
2650 case Type::TemplateSpecialization: {
2651 const TemplateSpecializationType *TST =
2661 assert(TD &&
"no template for template specialization type");
2663 goto unresolvedType;
2665 mangleSourceNameWithAbiTags(TD);
2677 llvm_unreachable(
"invalid base for a template specialization type");
2680 SubstTemplateTemplateParmStorage *subst =
2691 Out <<
"_SUBSTPACK_";
2696 DiagnoseUnsupportedPackIndexTemplateName();
2702 mangleSourceNameWithAbiTags(TD);
2712 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2716 case Type::InjectedClassName:
2717 mangleSourceNameWithAbiTags(
2721 case Type::DependentName:
2733void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2743 llvm_unreachable(
"Not an operator name");
2766 case OO_New:
Out <<
"nw";
break;
2768 case OO_Array_New:
Out <<
"na";
break;
2770 case OO_Delete:
Out <<
"dl";
break;
2772 case OO_Array_Delete:
Out <<
"da";
break;
2776 Out << (Arity == 1?
"ps" :
"pl");
break;
2780 Out << (Arity == 1?
"ng" :
"mi");
break;
2784 Out << (Arity == 1?
"ad" :
"an");
break;
2789 Out << (Arity == 1?
"de" :
"ml");
break;
2791 case OO_Tilde:
Out <<
"co";
break;
2793 case OO_Slash:
Out <<
"dv";
break;
2795 case OO_Percent:
Out <<
"rm";
break;
2797 case OO_Pipe:
Out <<
"or";
break;
2799 case OO_Caret:
Out <<
"eo";
break;
2801 case OO_Equal:
Out <<
"aS";
break;
2803 case OO_PlusEqual:
Out <<
"pL";
break;
2805 case OO_MinusEqual:
Out <<
"mI";
break;
2807 case OO_StarEqual:
Out <<
"mL";
break;
2809 case OO_SlashEqual:
Out <<
"dV";
break;
2811 case OO_PercentEqual:
Out <<
"rM";
break;
2813 case OO_AmpEqual:
Out <<
"aN";
break;
2815 case OO_PipeEqual:
Out <<
"oR";
break;
2817 case OO_CaretEqual:
Out <<
"eO";
break;
2819 case OO_LessLess:
Out <<
"ls";
break;
2821 case OO_GreaterGreater:
Out <<
"rs";
break;
2823 case OO_LessLessEqual:
Out <<
"lS";
break;
2825 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2827 case OO_EqualEqual:
Out <<
"eq";
break;
2829 case OO_ExclaimEqual:
Out <<
"ne";
break;
2831 case OO_Less:
Out <<
"lt";
break;
2833 case OO_Greater:
Out <<
"gt";
break;
2835 case OO_LessEqual:
Out <<
"le";
break;
2837 case OO_GreaterEqual:
Out <<
"ge";
break;
2839 case OO_Exclaim:
Out <<
"nt";
break;
2841 case OO_AmpAmp:
Out <<
"aa";
break;
2843 case OO_PipePipe:
Out <<
"oo";
break;
2845 case OO_PlusPlus:
Out <<
"pp";
break;
2847 case OO_MinusMinus:
Out <<
"mm";
break;
2849 case OO_Comma:
Out <<
"cm";
break;
2851 case OO_ArrowStar:
Out <<
"pm";
break;
2853 case OO_Arrow:
Out <<
"pt";
break;
2855 case OO_Call:
Out <<
"cl";
break;
2857 case OO_Subscript:
Out <<
"ix";
break;
2862 case OO_Conditional:
Out <<
"qu";
break;
2865 case OO_Coawait:
Out <<
"aw";
break;
2868 case OO_Spaceship:
Out <<
"ss";
break;
2872 llvm_unreachable(
"Not an overloaded operator");
2876void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2895 SmallString<64> ASString;
2901 if (TargetAS != 0 ||
2903 ASString =
"AS" + llvm::utostr(TargetAS);
2906 default: llvm_unreachable(
"Not a language specific address space");
2910 case LangAS::opencl_global:
2911 ASString =
"CLglobal";
2913 case LangAS::opencl_global_device:
2914 ASString =
"CLdevice";
2916 case LangAS::opencl_global_host:
2917 ASString =
"CLhost";
2919 case LangAS::opencl_local:
2920 ASString =
"CLlocal";
2922 case LangAS::opencl_constant:
2923 ASString =
"CLconstant";
2925 case LangAS::opencl_private:
2926 ASString =
"CLprivate";
2928 case LangAS::opencl_generic:
2929 ASString =
"CLgeneric";
2934 case LangAS::sycl_global:
2935 ASString =
"SYglobal";
2937 case LangAS::sycl_global_device:
2938 ASString =
"SYdevice";
2940 case LangAS::sycl_global_host:
2941 ASString =
"SYhost";
2943 case LangAS::sycl_local:
2944 ASString =
"SYlocal";
2946 case LangAS::sycl_private:
2947 ASString =
"SYprivate";
2949 case LangAS::sycl_generic:
2950 ASString =
"SYgeneric";
2952 case LangAS::sycl_constant:
2953 ASString =
"SYconstant";
2956 case LangAS::cuda_device:
2957 ASString =
"CUdevice";
2959 case LangAS::cuda_constant:
2960 ASString =
"CUconstant";
2962 case LangAS::cuda_shared:
2963 ASString =
"CUshared";
2966 case LangAS::ptr32_sptr:
2967 ASString =
"ptr32_sptr";
2969 case LangAS::ptr32_uptr:
2973 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2974 ASString =
"ptr32_uptr";
2981 if (!ASString.empty())
2982 mangleVendorQualifier(ASString);
2995 mangleVendorQualifier(
"__weak");
2999 mangleVendorQualifier(
"__unaligned");
3003 mangleVendorQualifier(
"__ptrauth");
3013 << unsigned(PtrAuth.isAddressDiscriminated())
3016 << PtrAuth.getExtraDiscriminator()
3031 mangleVendorQualifier(
"__strong");
3035 mangleVendorQualifier(
"__autoreleasing");
3058void CXXNameMangler::mangleVendorQualifier(StringRef name) {
3062void CXXNameMangler::mangleVendorType(StringRef name) {
3069 switch (RefQualifier) {
3083void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
3084 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3109 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3110 if (DeducedTST->getDeducedType().isNull())
3115void CXXNameMangler::mangleType(QualType
T) {
3149 T =
T.getCanonicalType();
3155 if (
const TemplateSpecializationType *TST
3156 = dyn_cast<TemplateSpecializationType>(
T))
3157 if (!TST->isTypeAlias())
3165 =
T.getSingleStepDesugaredType(Context.getASTContext());
3172 auto [ty, quals] =
T.split();
3174 bool isSubstitutable =
3176 if (isSubstitutable && mangleSubstitution(
T))
3183 quals = Qualifiers();
3189 if (quals || ty->isDependentAddressSpaceType()) {
3190 if (
const DependentAddressSpaceType *DAST =
3191 dyn_cast<DependentAddressSpaceType>(ty)) {
3193 mangleQualifiers(Quals, DAST);
3194 mangleType(QualType(Ty, 0));
3196 mangleQualifiers(quals);
3200 mangleType(QualType(ty, 0));
3203 switch (ty->getTypeClass()) {
3204#define ABSTRACT_TYPE(CLASS, PARENT)
3205#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3207 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3209#define TYPE(CLASS, PARENT) \
3211 mangleType(static_cast<const CLASS##Type*>(ty)); \
3213#include "clang/AST/TypeNodes.inc"
3218 if (isSubstitutable)
3222void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3223 bool SuppressSubstitution) {
3224 if (mangleSubstitution(
Record))
3227 if (SuppressSubstitution)
3232void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3276 std::string type_name;
3280 if (NormalizeIntegers &&
T->isInteger()) {
3281 if (
T->isSignedInteger()) {
3282 switch (getASTContext().getTypeSize(
T)) {
3286 if (mangleSubstitution(BuiltinType::SChar))
3289 addSubstitution(BuiltinType::SChar);
3292 if (mangleSubstitution(BuiltinType::Short))
3295 addSubstitution(BuiltinType::Short);
3298 if (mangleSubstitution(BuiltinType::Int))
3301 addSubstitution(BuiltinType::Int);
3304 if (mangleSubstitution(BuiltinType::Long))
3307 addSubstitution(BuiltinType::Long);
3310 if (mangleSubstitution(BuiltinType::Int128))
3313 addSubstitution(BuiltinType::Int128);
3316 llvm_unreachable(
"Unknown integer size for normalization");
3319 switch (getASTContext().getTypeSize(
T)) {
3321 if (mangleSubstitution(BuiltinType::UChar))
3324 addSubstitution(BuiltinType::UChar);
3327 if (mangleSubstitution(BuiltinType::UShort))
3330 addSubstitution(BuiltinType::UShort);
3333 if (mangleSubstitution(BuiltinType::UInt))
3336 addSubstitution(BuiltinType::UInt);
3339 if (mangleSubstitution(BuiltinType::ULong))
3342 addSubstitution(BuiltinType::ULong);
3345 if (mangleSubstitution(BuiltinType::UInt128))
3348 addSubstitution(BuiltinType::UInt128);
3351 llvm_unreachable(
"Unknown integer size for normalization");
3356 switch (
T->getKind()) {
3357 case BuiltinType::Void:
3360 case BuiltinType::Bool:
3363 case BuiltinType::Char_U:
3364 case BuiltinType::Char_S:
3367 case BuiltinType::UChar:
3370 case BuiltinType::UShort:
3373 case BuiltinType::UInt:
3376 case BuiltinType::ULong:
3379 case BuiltinType::ULongLong:
3382 case BuiltinType::UInt128:
3385 case BuiltinType::SChar:
3388 case BuiltinType::WChar_S:
3389 case BuiltinType::WChar_U:
3392 case BuiltinType::Char8:
3395 case BuiltinType::Char16:
3398 case BuiltinType::Char32:
3401 case BuiltinType::Short:
3404 case BuiltinType::Int:
3407 case BuiltinType::Long:
3410 case BuiltinType::LongLong:
3413 case BuiltinType::Int128:
3416 case BuiltinType::Float16:
3419 case BuiltinType::ShortAccum:
3422 case BuiltinType::Accum:
3425 case BuiltinType::LongAccum:
3428 case BuiltinType::UShortAccum:
3431 case BuiltinType::UAccum:
3434 case BuiltinType::ULongAccum:
3437 case BuiltinType::ShortFract:
3440 case BuiltinType::Fract:
3443 case BuiltinType::LongFract:
3446 case BuiltinType::UShortFract:
3449 case BuiltinType::UFract:
3452 case BuiltinType::ULongFract:
3455 case BuiltinType::SatShortAccum:
3458 case BuiltinType::SatAccum:
3461 case BuiltinType::SatLongAccum:
3464 case BuiltinType::SatUShortAccum:
3467 case BuiltinType::SatUAccum:
3470 case BuiltinType::SatULongAccum:
3473 case BuiltinType::SatShortFract:
3476 case BuiltinType::SatFract:
3479 case BuiltinType::SatLongFract:
3482 case BuiltinType::SatUShortFract:
3485 case BuiltinType::SatUFract:
3488 case BuiltinType::SatULongFract:
3491 case BuiltinType::Half:
3494 case BuiltinType::Float:
3497 case BuiltinType::Double:
3500 case BuiltinType::LongDouble: {
3501 const TargetInfo *TI =
3502 getASTContext().getLangOpts().OpenMP &&
3503 getASTContext().getLangOpts().OpenMPIsTargetDevice
3504 ? getASTContext().getAuxTargetInfo()
3505 : &getASTContext().getTargetInfo();
3509 case BuiltinType::Float128: {
3510 const TargetInfo *TI =
3511 getASTContext().getLangOpts().OpenMP &&
3512 getASTContext().getLangOpts().OpenMPIsTargetDevice
3513 ? getASTContext().getAuxTargetInfo()
3514 : &getASTContext().getTargetInfo();
3518 case BuiltinType::BFloat16: {
3519 const TargetInfo *TI =
3520 ((getASTContext().getLangOpts().OpenMP &&
3521 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3522 getASTContext().getLangOpts().SYCLIsDevice)
3523 ? getASTContext().getAuxTargetInfo()
3524 : &getASTContext().getTargetInfo();
3528 case BuiltinType::Ibm128: {
3529 const TargetInfo *TI = &getASTContext().getTargetInfo();
3533 case BuiltinType::MetaInfo:
3537 case BuiltinType::NullPtr:
3541#define BUILTIN_TYPE(Id, SingletonId)
3542#define PLACEHOLDER_TYPE(Id, SingletonId) \
3543 case BuiltinType::Id:
3544#include "clang/AST/BuiltinTypes.def"
3545 case BuiltinType::Dependent:
3547 llvm_unreachable(
"mangling a placeholder type");
3549 case BuiltinType::ObjCId:
3550 Out <<
"11objc_object";
3552 case BuiltinType::ObjCClass:
3553 Out <<
"10objc_class";
3555 case BuiltinType::ObjCSel:
3556 Out <<
"13objc_selector";
3558#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3559 case BuiltinType::Id: \
3560 type_name = "ocl_" #ImgType "_" #Suffix; \
3561 Out << type_name.size() << type_name; \
3563#include "clang/Basic/OpenCLImageTypes.def"
3564 case BuiltinType::OCLSampler:
3565 Out <<
"11ocl_sampler";
3567 case BuiltinType::OCLEvent:
3568 Out <<
"9ocl_event";
3570 case BuiltinType::OCLClkEvent:
3571 Out <<
"12ocl_clkevent";
3573 case BuiltinType::OCLQueue:
3574 Out <<
"9ocl_queue";
3576 case BuiltinType::OCLReserveID:
3577 Out <<
"13ocl_reserveid";
3579#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3580 case BuiltinType::Id: \
3581 type_name = "ocl_" #ExtType; \
3582 Out << type_name.size() << type_name; \
3584#include "clang/Basic/OpenCLExtensionTypes.def"
3588#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3589 case BuiltinType::Id: \
3590 if (T->getKind() == BuiltinType::SveBFloat16 && \
3591 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3593 mangleVendorType("__SVBFloat16_t"); \
3595 type_name = #MangledName; \
3596 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3599#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3600 case BuiltinType::Id: \
3601 type_name = #MangledName; \
3602 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3604#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3605 case BuiltinType::Id: \
3606 type_name = #MangledName; \
3607 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3609#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3610 case BuiltinType::Id: \
3611 type_name = #MangledName; \
3612 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3614#include "clang/Basic/AArch64ACLETypes.def"
3615#define PPC_VECTOR_TYPE(Name, Id, Size) \
3616 case BuiltinType::Id: \
3617 mangleVendorType(#Name); \
3619#include "clang/Basic/PPCTypes.def"
3621#define RVV_TYPE(Name, Id, SingletonId) \
3622 case BuiltinType::Id: \
3623 mangleVendorType(Name); \
3625#include "clang/Basic/RISCVVTypes.def"
3626#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3627 case BuiltinType::Id: \
3628 mangleVendorType(MangledName); \
3630#include "clang/Basic/WebAssemblyReferenceTypes.def"
3631#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3632 case BuiltinType::Id: \
3633 mangleVendorType(Name); \
3635#include "clang/Basic/AMDGPUTypes.def"
3636#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3637 case BuiltinType::Id: \
3638 mangleVendorType(#Name); \
3640#include "clang/Basic/HLSLIntangibleTypes.def"
3641#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
3642 case BuiltinType::Id: \
3643 mangleVendorType(#Name); \
3645#include "clang/Basic/HLSLPackedTypes.def"
3646#define SPIRV_TYPE(Name, Id, SingletonId) \
3647 case BuiltinType::Id: \
3648 mangleVendorType(Name); \
3650#include "clang/Basic/SPIRVTypes.def"
3654StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3673#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3709 return "swiftasynccall";
3711 llvm_unreachable(
"bad calling convention");
3714void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3723 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3724 if (!CCQualifier.empty())
3725 mangleVendorQualifier(CCQualifier);
3758 llvm_unreachable(
"Unrecognised SME attribute");
3773void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3793 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3797CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3804 case ParameterABI::Ordinary:
3808 case ParameterABI::HLSLOut:
3809 case ParameterABI::HLSLInOut:
3814 case ParameterABI::SwiftContext:
3815 case ParameterABI::SwiftAsyncContext:
3816 case ParameterABI::SwiftErrorResult:
3817 case ParameterABI::SwiftIndirectResult:
3823 mangleVendorQualifier(
"ns_consumed");
3826 mangleVendorQualifier(
"noescape");
3832void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3836 Out <<
"11__SME_ATTRSI";
3838 mangleExtFunctionInfo(
T);
3855 mangleType(ExceptTy);
3866 mangleBareFunctionType(
T,
true);
3873 mangleSMEAttrs(SMEAttrs);
3876void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3882 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3884 FunctionTypeDepth.enterFunctionDeclSuffix();
3886 FunctionTypeDepth.leaveFunctionDeclSuffix();
3888 FunctionTypeDepth.pop(saved);
3892void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3893 bool MangleReturnType,
3894 const FunctionDecl *FD) {
3897 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3900 if (MangleReturnType) {
3901 FunctionTypeDepth.enterFunctionDeclSuffix();
3905 mangleVendorQualifier(
"ns_returns_retained");
3910 auto SplitReturnTy = ReturnTy.
split();
3912 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3914 mangleType(ReturnTy);
3916 FunctionTypeDepth.leaveFunctionDeclSuffix();
3924 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3938 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3939 if (Attr->isDynamic())
3940 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3942 Out <<
"U17pass_object_size" << Attr->getType();
3953 FunctionTypeDepth.enterFunctionDeclSuffix();
3957 FunctionTypeDepth.pop(saved);
3962void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3963 mangleName(
T->getDecl());
3968void CXXNameMangler::mangleType(
const EnumType *
T) {
3969 mangleType(
static_cast<const TagType*
>(
T));
3971void CXXNameMangler::mangleType(
const RecordType *
T) {
3972 mangleType(
static_cast<const TagType*
>(
T));
3974void CXXNameMangler::mangleType(
const TagType *
T) {
3975 mangleName(
T->getDecl()->getDefinitionOrSelf());
3981void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3982 Out <<
'A' <<
T->getSize() <<
'_';
3983 mangleType(
T->getElementType());
3985void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3988 if (
T->getSizeExpr())
3989 mangleExpression(
T->getSizeExpr());
3991 mangleType(
T->getElementType());
3993void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3998 if (
T->getSizeExpr())
3999 mangleExpression(
T->getSizeExpr());
4001 mangleType(
T->getElementType());
4003void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
4005 mangleType(
T->getElementType());
4010void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
4012 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
4013 mangleCXXRecordDecl(RD);
4015 mangleType(QualType(
T->getQualifier().getAsType(), 0));
4017 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
4038 mangleType(PointeeType);
4042void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
4043 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
4047void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
4052 Out <<
"_SUBSTPACK_";
4055void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
4060 Out <<
"_SUBSTBUILTINPACK_";
4064void CXXNameMangler::mangleType(
const PointerType *
T) {
4068void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
4074void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
4080void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
4086void CXXNameMangler::mangleType(
const ComplexType *
T) {
4088 mangleType(
T->getElementType());
4094void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
4095 QualType EltType =
T->getElementType();
4096 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4097 const char *EltName =
nullptr;
4098 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4100 case BuiltinType::SChar:
4101 case BuiltinType::UChar:
4102 EltName =
"poly8_t";
4104 case BuiltinType::Short:
4105 case BuiltinType::UShort:
4106 EltName =
"poly16_t";
4108 case BuiltinType::LongLong:
4109 case BuiltinType::ULongLong:
4110 EltName =
"poly64_t";
4112 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
4116 case BuiltinType::SChar: EltName =
"int8_t";
break;
4117 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4118 case BuiltinType::Short: EltName =
"int16_t";
break;
4119 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4120 case BuiltinType::Int: EltName =
"int32_t";
break;
4121 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4122 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4123 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4124 case BuiltinType::Double: EltName =
"float64_t";
break;
4125 case BuiltinType::Float: EltName =
"float32_t";
break;
4126 case BuiltinType::Half: EltName =
"float16_t";
break;
4127 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4128 case BuiltinType::MFloat8:
4129 EltName =
"mfloat8_t";
4132 llvm_unreachable(
"unexpected Neon vector element type");
4135 const char *BaseName =
nullptr;
4136 unsigned BitSize = (
T->getNumElements() *
4137 getASTContext().getTypeSize(EltType));
4139 BaseName =
"__simd64_";
4141 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4142 BaseName =
"__simd128_";
4144 Out << strlen(BaseName) + strlen(EltName);
4145 Out << BaseName << EltName;
4148void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4149 DiagnosticsEngine &Diags = Context.getDiags();
4150 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4151 << UnsupportedItaniumManglingKind::DependentNeonVector;
4156 case BuiltinType::SChar:
4158 case BuiltinType::Short:
4160 case BuiltinType::Int:
4162 case BuiltinType::Long:
4163 case BuiltinType::LongLong:
4165 case BuiltinType::UChar:
4167 case BuiltinType::UShort:
4169 case BuiltinType::UInt:
4171 case BuiltinType::ULong:
4172 case BuiltinType::ULongLong:
4174 case BuiltinType::Half:
4176 case BuiltinType::Float:
4178 case BuiltinType::Double:
4180 case BuiltinType::BFloat16:
4182 case BuiltinType::MFloat8:
4185 llvm_unreachable(
"Unexpected vector element base type");
4192void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4193 QualType EltType =
T->getElementType();
4194 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4196 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4199 assert((BitSize == 64 || BitSize == 128) &&
4200 "Neon vector type not 64 or 128 bits");
4203 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4205 case BuiltinType::UChar:
4208 case BuiltinType::UShort:
4211 case BuiltinType::ULong:
4212 case BuiltinType::ULongLong:
4216 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4222 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4225void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4226 DiagnosticsEngine &Diags = Context.getDiags();
4227 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4228 << UnsupportedItaniumManglingKind::DependentNeonVector;
4255void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4256 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4257 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4258 "expected fixed-length SVE vector!");
4260 QualType EltType =
T->getElementType();
4262 "expected builtin type for fixed-length SVE vector!");
4266 case BuiltinType::SChar:
4269 case BuiltinType::UChar: {
4270 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4276 case BuiltinType::Short:
4279 case BuiltinType::UShort:
4282 case BuiltinType::Int:
4285 case BuiltinType::UInt:
4288 case BuiltinType::Long:
4291 case BuiltinType::ULong:
4294 case BuiltinType::Half:
4297 case BuiltinType::Float:
4300 case BuiltinType::Double:
4303 case BuiltinType::BFloat16:
4307 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4310 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4312 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4315 Out <<
"9__SVE_VLSI";
4316 mangleVendorType(TypeName);
4317 Out <<
"Lj" << VecSizeInBits <<
"EE";
4320void CXXNameMangler::mangleAArch64FixedSveVectorType(
4321 const DependentVectorType *
T) {
4322 DiagnosticsEngine &Diags = Context.getDiags();
4323 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4324 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4327void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4328 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4329 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4330 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4331 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4332 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4333 "expected fixed-length RVV vector!");
4335 QualType EltType =
T->getElementType();
4337 "expected builtin type for fixed-length RVV vector!");
4339 SmallString<20> TypeNameStr;
4340 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4341 TypeNameOS <<
"__rvv_";
4343 case BuiltinType::SChar:
4344 TypeNameOS <<
"int8";
4346 case BuiltinType::UChar:
4347 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4348 TypeNameOS <<
"uint8";
4350 TypeNameOS <<
"bool";
4352 case BuiltinType::Short:
4353 TypeNameOS <<
"int16";
4355 case BuiltinType::UShort:
4356 TypeNameOS <<
"uint16";
4358 case BuiltinType::Int:
4359 TypeNameOS <<
"int32";
4361 case BuiltinType::UInt:
4362 TypeNameOS <<
"uint32";
4364 case BuiltinType::Long:
4365 case BuiltinType::LongLong:
4366 TypeNameOS <<
"int64";
4368 case BuiltinType::ULong:
4369 case BuiltinType::ULongLong:
4370 TypeNameOS <<
"uint64";
4372 case BuiltinType::Float16:
4373 TypeNameOS <<
"float16";
4375 case BuiltinType::Float:
4376 TypeNameOS <<
"float32";
4378 case BuiltinType::Double:
4379 TypeNameOS <<
"float64";
4381 case BuiltinType::BFloat16:
4382 TypeNameOS <<
"bfloat16";
4385 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4388 unsigned VecSizeInBits;
4389 switch (
T->getVectorKind()) {
4390 case VectorKind::RVVFixedLengthMask_1:
4393 case VectorKind::RVVFixedLengthMask_2:
4396 case VectorKind::RVVFixedLengthMask_4:
4400 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4405 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4406 getASTContext().getLangOpts(),
4407 TargetInfo::ArmStreamingKind::NotStreaming);
4408 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4410 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4412 if (VecSizeInBits >= VLen)
4413 TypeNameOS << (VecSizeInBits / VLen);
4415 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4417 TypeNameOS << (VLen / VecSizeInBits);
4421 Out <<
"9__RVV_VLSI";
4422 mangleVendorType(TypeNameStr);
4423 Out <<
"Lj" << VecSizeInBits <<
"EE";
4426void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4427 const DependentVectorType *
T) {
4428 DiagnosticsEngine &Diags = Context.getDiags();
4429 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4430 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4441void CXXNameMangler::mangleType(
const VectorType *
T) {
4442 if ((
T->getVectorKind() == VectorKind::Neon ||
4443 T->getVectorKind() == VectorKind::NeonPoly)) {
4444 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4445 llvm::Triple::ArchType
Arch =
4446 getASTContext().getTargetInfo().getTriple().getArch();
4447 if ((
Arch == llvm::Triple::aarch64 ||
4448 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4449 mangleAArch64NeonVectorType(
T);
4451 mangleNeonVectorType(
T);
4453 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4454 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4455 mangleAArch64FixedSveVectorType(
T);
4457 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4458 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4459 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4460 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4461 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4462 mangleRISCVFixedRVVVectorType(
T);
4465 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4466 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4468 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4471 mangleType(
T->getElementType());
4474void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4475 if ((
T->getVectorKind() == VectorKind::Neon ||
4476 T->getVectorKind() == VectorKind::NeonPoly)) {
4477 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4478 llvm::Triple::ArchType
Arch =
4479 getASTContext().getTargetInfo().getTriple().getArch();
4480 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4482 mangleAArch64NeonVectorType(
T);
4484 mangleNeonVectorType(
T);
4486 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4487 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4488 mangleAArch64FixedSveVectorType(
T);
4490 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4491 mangleRISCVFixedRVVVectorType(
T);
4496 mangleExpression(
T->getSizeExpr());
4498 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4500 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4503 mangleType(
T->getElementType());
4506void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4507 mangleType(
static_cast<const VectorType*
>(
T));
4509void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4511 mangleExpression(
T->getSizeExpr());
4513 mangleType(
T->getElementType());
4516void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4520 mangleVendorType(
"matrix_type");
4523 auto &ASTCtx = getASTContext();
4524 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4525 llvm::APSInt Rows(BitWidth);
4526 Rows =
T->getNumRows();
4527 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4528 llvm::APSInt Columns(BitWidth);
4529 Columns =
T->getNumColumns();
4530 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4531 mangleType(
T->getElementType());
4535void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4538 mangleVendorType(
"matrix_type");
4541 mangleTemplateArgExpr(
T->getRowExpr());
4542 mangleTemplateArgExpr(
T->getColumnExpr());
4543 mangleType(
T->getElementType());
4547void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4549 mangleQualifiers(split.
Quals,
T);
4550 mangleType(QualType(split.
Ty, 0));
4553void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4556 mangleType(
T->getPattern());
4559void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4562 mangleType(
T->getPattern());
4563 mangleExpression(
T->getIndexExpr());
4566void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4567 mangleSourceName(
T->getDecl()->getIdentifier());
4570void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4572 if (
T->isKindOfType())
4573 Out <<
"U8__kindof";
4575 if (!
T->qual_empty()) {
4577 SmallString<64> QualStr;
4578 llvm::raw_svector_ostream QualOS(QualStr);
4579 QualOS <<
"objcproto";
4580 for (
const auto *I :
T->quals()) {
4581 StringRef
name = I->getName();
4584 mangleVendorQualifier(QualStr);
4587 mangleType(
T->getBaseType());
4589 if (
T->isSpecialized()) {
4592 for (
auto typeArg :
T->getTypeArgs())
4593 mangleType(typeArg);
4598void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4599 Out <<
"U13block_pointer";
4603void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4608 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4611void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4612 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4613 mangleTemplateName(TD,
T->template_arguments());
4616 mangleTemplatePrefix(
T->getTemplateName());
4621 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4626void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4637 switch (
T->getKeyword()) {
4638 case ElaboratedTypeKeyword::None:
4639 case ElaboratedTypeKeyword::Typename:
4641 case ElaboratedTypeKeyword::Struct:
4642 case ElaboratedTypeKeyword::Class:
4643 case ElaboratedTypeKeyword::Interface:
4646 case ElaboratedTypeKeyword::Union:
4649 case ElaboratedTypeKeyword::Enum:
4655 manglePrefix(
T->getQualifier());
4656 mangleSourceName(
T->getIdentifier());
4660void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4666void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4672void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4673 Expr *E =
T->getUnderlyingExpr();
4692 mangleExpression(E);
4696void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4700 StringRef BuiltinName;
4701 switch (
T->getUTTKind()) {
4702#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4703 case UnaryTransformType::Enum: \
4704 BuiltinName = "__" #Trait; \
4706#include "clang/Basic/BuiltinTraits.inc"
4708 mangleVendorType(BuiltinName);
4712 mangleType(
T->getBaseType());
4716void CXXNameMangler::mangleType(
const AutoType *
T) {
4717 assert(
T->getDeducedType().isNull() &&
4718 "Deduced AutoType shouldn't be handled here!");
4719 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4720 "shouldn't need to mangle __auto_type!");
4725 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4726 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4727 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4728 T->getTypeConstraintArguments());
4730 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4734void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4735 QualType
Deduced =
T->getDeducedType();
4741 "shouldn't form deduced TST unless we know we have a template");
4745void CXXNameMangler::mangleType(
const AtomicType *
T) {
4749 mangleType(
T->getValueType());
4752void CXXNameMangler::mangleType(
const PipeType *
T) {
4759void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4762 if (
T->isWrapKind()) {
4763 Out <<
"U8ObtWrap_";
4765 Out <<
"U8ObtTrap_";
4767 mangleType(
T->getUnderlyingType());
4770void CXXNameMangler::mangleType(
const BitIntType *
T) {
4774 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4777void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4781 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4782 mangleExpression(
T->getNumBitsExpr());
4786void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4790void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4791 llvm::SmallString<64> Str(
"_Res");
4792 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4794 switch (Attrs.ResourceClass) {
4795 case llvm::dxil::ResourceClass::UAV:
4798 case llvm::dxil::ResourceClass::SRV:
4801 case llvm::dxil::ResourceClass::CBuffer:
4804 case llvm::dxil::ResourceClass::Sampler:
4810 if (Attrs.RawBuffer)
4812 if (Attrs.IsCounter)
4816 if (Attrs.isMultiSampled())
4818 if (
T->hasContainedType())
4820 mangleVendorQualifier(Str);
4822 if (
T->hasContainedType()) {
4823 mangleType(
T->getContainedType());
4825 mangleType(
T->getWrappedType());
4828void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4829 SmallString<20> TypeNameStr;
4830 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4832 TypeNameOS <<
"spirv_type";
4834 TypeNameOS <<
"_" <<
T->getOpcode();
4835 TypeNameOS <<
"_" <<
T->getSize();
4836 TypeNameOS <<
"_" <<
T->getAlignment();
4838 mangleVendorType(TypeNameStr);
4840 for (
auto &Operand :
T->getOperands()) {
4841 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4844 case SpirvOperandKind::ConstantId:
4845 mangleVendorQualifier(
"_Const");
4846 mangleIntegerLiteral(
Operand.getResultType(),
4847 llvm::APSInt(
Operand.getValue()));
4849 case SpirvOperandKind::Literal:
4850 mangleVendorQualifier(
"_Lit");
4851 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4852 llvm::APSInt(
Operand.getValue()));
4854 case SpirvOperandKind::TypeId:
4855 mangleVendorQualifier(
"_Type");
4856 mangleType(
Operand.getResultType());
4859 llvm_unreachable(
"Invalid SpirvOperand kind");
4862 TypeNameOS <<
Operand.getKind();
4866void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4867 const llvm::APSInt &
Value) {
4874 Out << (
Value.getBoolValue() ?
'1' :
'0');
4876 mangleNumber(
Value);
4881void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4883 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4884 if (!RT->getDecl()->isAnonymousStructOrUnion())
4886 const auto *ME = dyn_cast<MemberExpr>(Base);
4889 Base = ME->getBase();
4890 IsArrow = ME->isArrow();
4893 if (
Base->isImplicitCXXThis()) {
4899 Out << (IsArrow ?
"pt" :
"dt");
4900 mangleExpression(Base);
4905void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4906 NestedNameSpecifier Qualifier,
4907 NamedDecl *firstQualifierLookup,
4908 DeclarationName member,
4909 const TemplateArgumentLoc *TemplateArgs,
4910 unsigned NumTemplateArgs,
4915 mangleMemberExprBase(base, isArrow);
4916 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4929 if (callee == fn)
return false;
4933 if (!lookup)
return false;
4950void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4952 Out << CastEncoding;
4957void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4959 InitList = Syntactic;
4960 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4961 mangleExpression(InitList->
getInit(i));
4964void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4965 const concepts::Requirement *Req) {
4966 using concepts::Requirement;
4971 auto HandleSubstitutionFailure =
4972 [&](SourceLocation Loc) {
4973 DiagnosticsEngine &Diags = Context.getDiags();
4974 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4975 << UnsupportedItaniumManglingKind::
4976 RequiresExprWithSubstitutionFailure;
4981 case Requirement::RK_Type: {
4983 if (TR->isSubstitutionFailure())
4984 return HandleSubstitutionFailure(
4985 TR->getSubstitutionDiagnostic()->DiagLoc);
4988 mangleType(TR->getType()->getType());
4992 case Requirement::RK_Simple:
4993 case Requirement::RK_Compound: {
4995 if (ER->isExprSubstitutionFailure())
4996 return HandleSubstitutionFailure(
4997 ER->getExprSubstitutionDiagnostic()->DiagLoc);
5000 mangleExpression(ER->getExpr());
5002 if (ER->hasNoexceptRequirement())
5005 if (!ER->getReturnTypeRequirement().isEmpty()) {
5006 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
5007 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
5008 .getSubstitutionDiagnostic()
5012 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
5017 case Requirement::RK_Nested:
5019 if (NR->hasInvalidConstraint()) {
5022 return HandleSubstitutionFailure(RequiresExprLoc);
5026 mangleExpression(NR->getConstraintExpr());
5031void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
5032 bool AsTemplateArg) {
5066 QualType ImplicitlyConvertedToType;
5070 bool IsPrimaryExpr =
true;
5071 auto NotPrimaryExpr = [&] {
5072 if (AsTemplateArg && IsPrimaryExpr)
5074 IsPrimaryExpr =
false;
5077 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
5091 case Decl::EnumConstant: {
5098 case Decl::NonTypeTemplateParm:
5111 case Expr::NoStmtClass:
5112#define ABSTRACT_STMT(Type)
5113#define EXPR(Type, Base)
5114#define STMT(Type, Base) \
5115 case Expr::Type##Class:
5116#include "clang/AST/StmtNodes.inc"
5121 case Expr::AddrLabelExprClass:
5122 case Expr::DesignatedInitUpdateExprClass:
5123 case Expr::ImplicitValueInitExprClass:
5124 case Expr::ArrayInitLoopExprClass:
5125 case Expr::ArrayInitIndexExprClass:
5126 case Expr::NoInitExprClass:
5127 case Expr::ParenListExprClass:
5128 case Expr::MSPropertyRefExprClass:
5129 case Expr::MSPropertySubscriptExprClass:
5130 case Expr::RecoveryExprClass:
5131 case Expr::ArraySectionExprClass:
5132 case Expr::OMPArrayShapingExprClass:
5133 case Expr::OMPIteratorExprClass:
5134 case Expr::CXXInheritedCtorInitExprClass:
5135 case Expr::CXXParenListInitExprClass:
5136 case Expr::CXXExpansionSelectExprClass:
5137 llvm_unreachable(
"unexpected statement kind");
5139 case Expr::ConstantExprClass:
5143 case Expr::CXXReflectExprClass: {
5150 case Expr::BlockExprClass:
5151 case Expr::ChooseExprClass:
5152 case Expr::CompoundLiteralExprClass:
5153 case Expr::ExtVectorElementExprClass:
5154 case Expr::MatrixElementExprClass:
5155 case Expr::GenericSelectionExprClass:
5156 case Expr::ObjCEncodeExprClass:
5157 case Expr::ObjCIsaExprClass:
5158 case Expr::ObjCIvarRefExprClass:
5159 case Expr::ObjCMessageExprClass:
5160 case Expr::ObjCPropertyRefExprClass:
5161 case Expr::ObjCProtocolExprClass:
5162 case Expr::ObjCSelectorExprClass:
5163 case Expr::ObjCStringLiteralClass:
5164 case Expr::ObjCBoxedExprClass:
5165 case Expr::ObjCArrayLiteralClass:
5166 case Expr::ObjCDictionaryLiteralClass:
5167 case Expr::ObjCSubscriptRefExprClass:
5168 case Expr::ObjCIndirectCopyRestoreExprClass:
5169 case Expr::ObjCAvailabilityCheckExprClass:
5170 case Expr::OffsetOfExprClass:
5171 case Expr::PredefinedExprClass:
5172 case Expr::ShuffleVectorExprClass:
5173 case Expr::ConvertVectorExprClass:
5174 case Expr::StmtExprClass:
5175 case Expr::ArrayTypeTraitExprClass:
5176 case Expr::ExpressionTraitExprClass:
5177 case Expr::VAArgExprClass:
5178 case Expr::CUDAKernelCallExprClass:
5179 case Expr::AsTypeExprClass:
5180 case Expr::PseudoObjectExprClass:
5181 case Expr::AtomicExprClass:
5182 case Expr::SourceLocExprClass:
5183 case Expr::EmbedExprClass:
5184 case Expr::BuiltinBitCastExprClass: {
5188 DiagnosticsEngine &Diags = Context.getDiags();
5196 case Expr::CXXUuidofExprClass: {
5201 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5202 Out <<
"u8__uuidof";
5211 Out <<
"u8__uuidoft";
5215 Out <<
"u8__uuidofz";
5216 mangleExpression(UuidExp);
5223 case Expr::BinaryConditionalOperatorClass: {
5225 DiagnosticsEngine &Diags = Context.getDiags();
5227 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5233 case Expr::OpaqueValueExprClass:
5234 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5236 case Expr::InitListExprClass: {
5244 case Expr::DesignatedInitExprClass: {
5247 for (
const auto &Designator : DIE->designators()) {
5248 if (Designator.isFieldDesignator()) {
5250 mangleSourceName(Designator.getFieldName());
5251 }
else if (Designator.isArrayDesignator()) {
5253 mangleExpression(DIE->getArrayIndex(Designator));
5255 assert(Designator.isArrayRangeDesignator() &&
5256 "unknown designator kind");
5258 mangleExpression(DIE->getArrayRangeStart(Designator));
5259 mangleExpression(DIE->getArrayRangeEnd(Designator));
5262 mangleExpression(DIE->getInit());
5266 case Expr::CXXDefaultArgExprClass:
5270 case Expr::CXXDefaultInitExprClass:
5274 case Expr::CXXStdInitializerListExprClass:
5278 case Expr::SubstNonTypeTemplateParmExprClass: {
5282 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5284 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5285 mangleValueInTemplateArg(SNTTPE->getParameterType(),
5286 CE->getAPValueResult(),
false,
5296 case Expr::UserDefinedLiteralClass:
5299 case Expr::CXXMemberCallExprClass:
5300 case Expr::CallExprClass: {
5322 CallArity = UnknownArity;
5324 mangleExpression(CE->
getCallee(), CallArity);
5326 mangleExpression(Arg);
5331 case Expr::CXXNewExprClass: {
5334 if (
New->isGlobalNew())
Out <<
"gs";
5335 Out << (
New->isArray() ?
"na" :
"nw");
5337 E =
New->placement_arg_end(); I != E; ++I)
5338 mangleExpression(*I);
5340 mangleType(
New->getAllocatedType());
5341 if (
New->hasInitializer()) {
5342 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5346 const Expr *
Init =
New->getInitializer();
5347 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5352 mangleExpression(*I);
5353 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5354 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5355 mangleExpression(PLE->getExpr(i));
5356 }
else if (
New->getInitializationStyle() ==
5357 CXXNewInitializationStyle::Braces &&
5362 mangleExpression(
Init);
5368 case Expr::CXXPseudoDestructorExprClass: {
5371 if (
const Expr *Base = PDE->getBase())
5372 mangleMemberExprBase(Base, PDE->isArrow());
5373 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5374 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5376 mangleUnresolvedPrefix(Qualifier,
5378 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5382 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5385 }
else if (Qualifier) {
5386 mangleUnresolvedPrefix(Qualifier);
5390 QualType DestroyedType = PDE->getDestroyedType();
5391 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5395 case Expr::MemberExprClass: {
5406 case Expr::UnresolvedMemberExprClass: {
5417 case Expr::CXXDependentScopeMemberExprClass: {
5419 const CXXDependentScopeMemberExpr *ME
5430 case Expr::UnresolvedLookupExprClass: {
5439 case Expr::DependentTemplateIdExprClass: {
5442 if (DTI->getTemplateName().getAsPackIndexingTemplate()) {
5443 DiagnoseUnsupportedPackIndexTemplateName();
5446 mangleUnresolvedName(std::nullopt, DTI->getName(),
5447 DTI->template_arguments().data(),
5448 DTI->getNumTemplateArgs(), Arity);
5452 case Expr::CXXUnresolvedConstructExprClass: {
5458 assert(N == 1 &&
"unexpected form for list initialization");
5462 mangleInitListElements(IL);
5469 if (N != 1)
Out <<
'_';
5470 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5471 if (N != 1)
Out <<
'E';
5475 case Expr::CXXConstructExprClass: {
5482 "implicit CXXConstructExpr must have one argument");
5489 mangleExpression(E);
5494 case Expr::CXXTemporaryObjectExprClass: {
5505 if (!List && N != 1)
5507 if (CE->isStdInitListInitialization()) {
5514 mangleInitListElements(ILE);
5517 mangleExpression(E);
5524 case Expr::CXXScalarValueInitExprClass:
5531 case Expr::CXXNoexceptExprClass:
5537 case Expr::UnaryExprOrTypeTraitExprClass: {
5554 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5556 : ImplicitlyConvertedToType;
5558 mangleIntegerLiteral(
T,
V);
5564 auto MangleAlignofSizeofArg = [&] {
5574 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5575 StringRef Name = {}) {
5578 mangleVendorType(Name);
5589 MangleAlignofSizeofArg();
5591 case UETT_PreferredAlignOf:
5595 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5596 MangleExtensionBuiltin(SAE,
"__alignof__");
5602 MangleAlignofSizeofArg();
5606 case UETT_VectorElements:
5607 case UETT_OpenMPRequiredSimdAlign:
5609 case UETT_PtrAuthTypeDiscriminator:
5610 case UETT_DataSizeOf: {
5611 DiagnosticsEngine &Diags = Context.getDiags();
5620 case Expr::TypeTraitExprClass: {
5625 mangleVendorType(Spelling);
5626 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5627 mangleType(TSI->getType());
5633 case Expr::CXXThrowExprClass: {
5647 case Expr::CXXTypeidExprClass: {
5662 case Expr::CXXDeleteExprClass: {
5673 case Expr::UnaryOperatorClass: {
5682 case Expr::ArraySubscriptExprClass: {
5689 mangleExpression(AE->
getLHS());
5690 mangleExpression(AE->
getRHS());
5694 case Expr::MatrixSingleSubscriptExprClass: {
5698 mangleExpression(ME->
getBase());
5703 case Expr::MatrixSubscriptExprClass: {
5707 mangleExpression(ME->
getBase());
5713 case Expr::CompoundAssignOperatorClass:
5714 case Expr::BinaryOperatorClass: {
5722 mangleExpression(BO->
getLHS());
5723 mangleExpression(BO->
getRHS());
5727 case Expr::CXXRewrittenBinaryOperatorClass: {
5730 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5734 mangleExpression(Decomposed.
LHS);
5735 mangleExpression(Decomposed.
RHS);
5739 case Expr::ConditionalOperatorClass: {
5742 mangleOperatorName(OO_Conditional, 3);
5743 mangleExpression(CO->
getCond());
5744 mangleExpression(CO->
getLHS(), Arity);
5745 mangleExpression(CO->
getRHS(), Arity);
5749 case Expr::ImplicitCastExprClass: {
5750 ImplicitlyConvertedToType = E->
getType();
5755 case Expr::ObjCBridgedCastExprClass: {
5761 mangleCastExpression(E,
"cv");
5765 case Expr::CStyleCastExprClass:
5767 mangleCastExpression(E,
"cv");
5770 case Expr::CXXFunctionalCastExprClass: {
5774 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5775 if (CCE->getParenOrBraceRange().isInvalid())
5776 Sub = CCE->getArg(0)->IgnoreImplicit();
5777 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5778 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5779 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5782 mangleInitListElements(IL);
5785 mangleCastExpression(E,
"cv");
5790 case Expr::CXXStaticCastExprClass:
5792 mangleCastExpression(E,
"sc");
5794 case Expr::CXXDynamicCastExprClass:
5796 mangleCastExpression(E,
"dc");
5798 case Expr::CXXReinterpretCastExprClass:
5800 mangleCastExpression(E,
"rc");
5802 case Expr::CXXConstCastExprClass:
5804 mangleCastExpression(E,
"cc");
5806 case Expr::CXXAddrspaceCastExprClass:
5808 mangleCastExpression(E,
"ac");
5811 case Expr::CXXOperatorCallExprClass: {
5820 for (
unsigned i = 0; i != NumArgs; ++i)
5821 mangleExpression(CE->
getArg(i));
5825 case Expr::ParenExprClass:
5829 case Expr::ConceptSpecializationExprClass: {
5831 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5836 mangleTemplateName(CSE->getConceptDecl(), CSE->getTemplateArguments());
5842 mangleUnresolvedName(
5843 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5844 CSE->getConceptNameInfo().getName(),
5845 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5846 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5850 case Expr::RequiresExprClass: {
5856 if (RE->getLParenLoc().isValid()) {
5858 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5859 if (RE->getLocalParameters().empty()) {
5862 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5870 FunctionTypeDepth.enterFunctionDeclSuffix();
5871 for (
const concepts::Requirement *Req : RE->getRequirements())
5872 mangleRequirement(RE->getExprLoc(), Req);
5873 FunctionTypeDepth.pop(saved);
5877 for (
const concepts::Requirement *Req : RE->getRequirements())
5878 mangleRequirement(RE->getExprLoc(), Req);
5884 case Expr::DeclRefExprClass:
5889 case Expr::SubstNonTypeTemplateParmPackExprClass:
5895 Out <<
"_SUBSTPACK_";
5898 case Expr::FunctionParmPackExprClass: {
5902 Out <<
"v110_SUBSTPACK";
5907 case Expr::DependentScopeDeclRefExprClass: {
5916 case Expr::CXXBindTemporaryExprClass:
5920 case Expr::ExprWithCleanupsClass:
5924 case Expr::FloatingLiteralClass: {
5931 case Expr::FixedPointLiteralClass:
5933 mangleFixedPointLiteral();
5936 case Expr::CharacterLiteralClass:
5940 Out << cast<CharacterLiteral>(E)->getValue();
5945 case Expr::ObjCBoolLiteralExprClass:
5948 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5952 case Expr::CXXBoolLiteralExprClass:
5955 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5959 case Expr::IntegerLiteralClass: {
5963 Value.setIsSigned(
true);
5968 case Expr::ImaginaryLiteralClass: {
5975 if (
const FloatingLiteral *Imag =
5976 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5978 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5980 mangleFloat(Imag->getValue());
5985 Value.setIsSigned(
true);
5986 mangleNumber(
Value);
5992 case Expr::StringLiteralClass: {
6002 case Expr::GNUNullExprClass:
6005 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
6008 case Expr::CXXNullPtrLiteralExprClass: {
6014 case Expr::LambdaExprClass: {
6025 case Expr::PackExpansionExprClass:
6031 case Expr::SizeOfPackExprClass: {
6034 if (SPE->isPartiallySubstituted()) {
6036 for (
const auto &A : SPE->getPartialArguments())
6037 mangleTemplateArg(A,
false);
6043 mangleReferenceToPack(SPE->getPack());
6047 case Expr::MaterializeTemporaryExprClass:
6051 case Expr::CXXFoldExprClass: {
6054 if (FE->isLeftFold())
6055 Out << (FE->getInit() ?
"fL" :
"fl");
6057 Out << (FE->getInit() ?
"fR" :
"fr");
6059 if (FE->getOperator() == BO_PtrMemD)
6067 mangleExpression(FE->getLHS());
6069 mangleExpression(FE->getRHS());
6073 case Expr::PackIndexingExprClass: {
6077 mangleReferenceToPack(PE->getPackDecl());
6078 mangleExpression(PE->getIndexExpr());
6082 case Expr::CXXThisExprClass:
6087 case Expr::CoawaitExprClass:
6090 Out <<
"v18co_await";
6094 case Expr::DependentCoawaitExprClass:
6097 Out <<
"v18co_await";
6101 case Expr::CoyieldExprClass:
6104 Out <<
"v18co_yield";
6107 case Expr::SYCLUniqueStableNameExprClass: {
6111 Out <<
"u33__builtin_sycl_unique_stable_name";
6112 mangleType(USN->getTypeSourceInfo()->getType());
6117 case Expr::HLSLOutArgExprClass:
6119 "cannot mangle hlsl temporary value; mangling wrong thing?");
6120 case Expr::OpenACCAsteriskSizeExprClass: {
6122 DiagnosticsEngine &Diags = Context.getDiags();
6123 Diags.
Report(diag::err_unsupported_itanium_mangling)
6124 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
6129 if (AsTemplateArg && !IsPrimaryExpr)
6161void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6166 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6167 nestingDepth == 0) {
6170 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6178 &&
"parameter's type is still an array type?");
6180 if (
const DependentAddressSpaceType *DAST =
6181 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6188 if (parmIndex != 0) {
6189 Out << (parmIndex - 1);
6195 const CXXRecordDecl *InheritedFrom) {
6222 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6225 mangleName(InheritedFrom);
6253 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6257void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6258 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6259 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6260 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6261 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6262 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6263 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6297 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6298 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6299 if (!RD || !RD->isGenericLambda())
6315 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6316 return TTP->hasTypeConstraint();
6333 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6334 return NTTP->getType()->isInstantiationDependentType() ||
6335 NTTP->getType()->getContainedDeducedType();
6342 "A DeducedTemplateName shouldn't escape partial ordering");
6353 auto MangleTemplateParamListToString =
6355 unsigned DepthOffset) {
6356 llvm::raw_svector_ostream Stream(Buffer);
6357 CXXNameMangler(
Mangler.Context, Stream,
6358 WithTemplateDepthOffset{DepthOffset})
6359 .mangleTemplateParameterList(Params);
6362 MangleTemplateParamListToString(ParamTemplateHead,
6363 TTP->getTemplateParameters(), 0);
6367 MangleTemplateParamListToString(ArgTemplateHead,
6369 TTP->getTemplateParameters()->
getDepth());
6370 return ParamTemplateHead != ArgTemplateHead;
6380 return {
true,
nullptr};
6385 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6386 "no parameter for argument");
6407 return {
true,
nullptr};
6422 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6423 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6424 return {NeedExactType,
nullptr};
6436void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6438 unsigned NumTemplateArgs) {
6441 TemplateArgManglingInfo Info(*
this, TN);
6442 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6443 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6445 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6449void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6450 const TemplateArgumentList &AL) {
6453 TemplateArgManglingInfo Info(*
this, TN);
6454 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6455 mangleTemplateArg(Info, i, AL[i]);
6457 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6461void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6462 ArrayRef<TemplateArgument> Args) {
6465 TemplateArgManglingInfo Info(*
this, TN);
6466 for (
unsigned i = 0; i != Args.size(); ++i) {
6467 mangleTemplateArg(Info, i, Args[i]);
6469 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6473void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6474 unsigned Index, TemplateArgument A) {
6475 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6478 if (ArgInfo.TemplateParameterToMangle &&
6479 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6486 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6489 mangleTemplateArg(A, ArgInfo.NeedExactType);
6492void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6502 llvm_unreachable(
"Cannot mangle NULL template argument");
6530 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6531 TPO->getValue(),
true,
6536 ASTContext &Ctx = Context.getASTContext();
6544 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6552 ArrayRef<APValue::LValuePathEntry>(),
6565 true, NeedExactType);
6571 mangleTemplateArg(P, NeedExactType);
6577void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6578 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6579 mangleExpression(E, UnknownArity,
true);
6594 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6595 const ValueDecl *D = DRE->getDecl();
6604 mangleExpression(E);
6617 switch (
V.getKind()) {
6625 assert(RD &&
"unexpected type for record value");
6634 if (!FD->isUnnamedBitField() &&
6644 assert(RD &&
"unexpected type for union value");
6647 if (!FD->isUnnamedBitField())
6657 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6658 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6666 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6673 llvm_unreachable(
"Matrix APValues not yet supported");
6679 return V.getFloat().isPosZero();
6682 return !
V.getFixedPoint().getValue();
6685 return V.getComplexFloatReal().isPosZero() &&
6686 V.getComplexFloatImag().isPosZero();
6689 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6692 return V.isNullPointer();
6695 return !
V.getMemberPointerDecl();
6698 return !
V.getReflectionOpaqueOperand();
6701 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6708 T = AT->getElementType();
6710 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6753 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6754 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6759void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6761 bool NeedExactType) {
6764 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6767 bool IsPrimaryExpr =
true;
6768 auto NotPrimaryExpr = [&] {
6769 if (TopLevel && IsPrimaryExpr)
6771 IsPrimaryExpr =
false;
6775 switch (
V.getKind()) {
6784 llvm_unreachable(
"unexpected value kind in template argument");
6788 assert(RD &&
"unexpected type for record value");
6791 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6794 (Fields.back()->isUnnamedBitField() ||
6796 V.getStructField(Fields.back()->getFieldIndex())))) {
6800 if (Fields.empty()) {
6801 while (!Bases.empty() &&
6803 V.getStructBase(Bases.size() - 1)))
6804 Bases = Bases.drop_back();
6811 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6812 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6813 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6814 if (Fields[I]->isUnnamedBitField())
6816 mangleValueInTemplateArg(Fields[I]->
getType(),
6817 V.getStructField(Fields[I]->getFieldIndex()),
6826 const FieldDecl *FD =
V.getUnionField();
6844 mangleSourceName(II);
6845 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6859 unsigned N =
V.getArraySize();
6861 N =
V.getArrayInitializedElts();
6866 for (
unsigned I = 0; I != N; ++I) {
6867 const APValue &Elem = I <
V.getArrayInitializedElts()
6868 ?
V.getArrayInitializedElt(I)
6869 :
V.getArrayFiller();
6870 mangleValueInTemplateArg(ElemT, Elem,
false);
6877 const VectorType *VT =
T->
castAs<VectorType>();
6882 unsigned N =
V.getVectorLength();
6885 for (
unsigned I = 0; I != N; ++I)
6886 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6892 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6895 mangleIntegerLiteral(
T,
V.getInt());
6899 mangleFloatLiteral(
T,
V.getFloat());
6903 mangleFixedPointLiteral();
6907 const ComplexType *CT =
T->
castAs<ComplexType>();
6911 if (!
V.getComplexFloatReal().isPosZero() ||
6912 !
V.getComplexFloatImag().isPosZero())
6914 if (!
V.getComplexFloatImag().isPosZero())
6921 const ComplexType *CT =
T->
castAs<ComplexType>();
6925 if (
V.getComplexIntReal().getBoolValue() ||
6926 V.getComplexIntImag().getBoolValue())
6928 if (
V.getComplexIntImag().getBoolValue())
6937 "unexpected type for LValue template arg");
6939 if (
V.isNullPointer()) {
6940 mangleNullPointer(
T);
6944 APValue::LValueBase B =
V.getLValueBase();
6948 CharUnits Offset =
V.getLValueOffset();
6966 ASTContext &Ctx = Context.getASTContext();
6969 if (!
V.hasLValuePath()) {
6985 bool IsArrayToPointerDecayMangledAsDecl =
false;
6986 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6988 IsArrayToPointerDecayMangledAsDecl =
6989 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6990 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6994 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6995 !IsArrayToPointerDecayMangledAsDecl) {
7012 if (NeedExactType &&
7014 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7027 QualType TypeSoFar = B.
getType();
7028 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
7032 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
7034 mangleExpression(E);
7035 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
7038 mangleType(QualType(TI.getType(), 0));
7041 llvm_unreachable(
"unexpected lvalue base kind in template argument");
7051 mangleNumber(
V.getLValueOffset().getQuantity());
7058 if (!
V.getLValueOffset().isZero())
7059 mangleNumber(
V.getLValueOffset().getQuantity());
7063 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
7065 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
7067 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
7068 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
7069 TypeSoFar = AT->getElementType();
7071 const Decl *D = E.getAsBaseOrMember().getPointer();
7072 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
7096 mangleReflection(
V.getReflectionOperandKind(),
7097 V.getReflectionOpaqueOperand());
7103 if (!
V.getMemberPointerDecl()) {
7104 mangleNullPointer(
T);
7108 ASTContext &Ctx = Context.getASTContext();
7111 if (!
V.getMemberPointerPath().empty()) {
7114 }
else if (NeedExactType &&
7116 T->
castAs<MemberPointerType>()->getPointeeType(),
7117 V.getMemberPointerDecl()->getType()) &&
7118 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7123 mangle(
V.getMemberPointerDecl());
7125 if (!
V.getMemberPointerPath().empty()) {
7135 if (TopLevel && !IsPrimaryExpr)
7139void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7149 Depth += TemplateDepthOffset;
7151 Out <<
'L' << (Depth - 1) <<
'_';
7157void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7160 }
else if (SeqID == 1) {
7167 MutableArrayRef<char> BufferRef(Buffer);
7168 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7170 for (; SeqID != 0; SeqID /= 36) {
7171 unsigned C = SeqID % 36;
7172 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7175 Out.write(I.base(), I - BufferRef.rbegin());
7180void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7181 bool result = mangleSubstitution(tname);
7182 assert(result &&
"no existing substitution for template name");
7188bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7190 if (mangleStandardSubstitution(ND))
7194 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7204bool CXXNameMangler::mangleSubstitution(QualType
T) {
7207 return mangleSubstitution(RD);
7212 return mangleSubstitution(TypePtr);
7216 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7217 return mangleSubstitution(TD);
7220 return mangleSubstitution(
7224bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7225 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7226 if (I == Substitutions.end())
7229 unsigned SeqID = I->second;
7238bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7247 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7248 if (!SD || !SD->getIdentifier()->isStr(Name))
7251 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7254 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7255 if (TemplateArgs.
size() != 1)
7258 if (TemplateArgs[0].getAsType() != A)
7261 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7270bool CXXNameMangler::isStdCharSpecialization(
7271 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7272 bool HasAllocator) {
7277 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7280 QualType A = TemplateArgs[0].getAsType();
7288 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7292 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7301bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7303 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7311 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7312 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7332 if (
const ClassTemplateSpecializationDecl *SD =
7333 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7334 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7343 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7350 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7357 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7364 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7374void CXXNameMangler::addSubstitution(QualType
T) {
7377 addSubstitution(RD);
7383 addSubstitution(TypePtr);
7387 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7388 return addSubstitution(TD);
7394void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7395 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7396 Substitutions[
Ptr] = SeqID++;
7399void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7400 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7401 if (
Other->SeqID > SeqID) {
7402 Substitutions.swap(
Other->Substitutions);
7403 SeqID =
Other->SeqID;
7407CXXNameMangler::AbiTagList
7408CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7410 if (DisableDerivedAbiTags)
7411 return AbiTagList();
7413 llvm::raw_null_ostream NullOutStream;
7414 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7415 TrackReturnTypeTags.disableDerivedAbiTags();
7417 const FunctionProtoType *Proto =
7419 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7420 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7422 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7423 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7425 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7428CXXNameMangler::AbiTagList
7429CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7431 if (DisableDerivedAbiTags)
7432 return AbiTagList();
7434 llvm::raw_null_ostream NullOutStream;
7435 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7436 TrackVariableType.disableDerivedAbiTags();
7438 TrackVariableType.mangleType(VD->
getType());
7440 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7443bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7444 const VarDecl *VD) {
7445 llvm::raw_null_ostream NullOutStream;
7446 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7447 TrackAbiTags.mangle(VD);
7448 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7453void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7457 "Invalid mangleName() call, argument is not a variable or function!");
7459 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7460 getASTContext().getSourceManager(),
7461 "Mangling declaration");
7463 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7465 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7466 return Mangler.mangle(GlobalDecl(CD,
Type));
7469 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7471 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7472 return Mangler.mangle(GlobalDecl(DD,
Type));
7475 CXXNameMangler Mangler(*
this, Out, D);
7479void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7481 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7485void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7487 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7509 auto &LangOpts = Context.getLangOpts();
7512 Context.baseForVTableAuthentication(ThisRD);
7513 unsigned TypedDiscriminator =
7514 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7516 Mangler.mangleVendorQualifier(
"__vtptrauth");
7517 auto &ManglerStream = Mangler.getStream();
7518 ManglerStream <<
"I";
7519 if (
const auto *ExplicitAuth =
7520 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7521 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7523 if (ExplicitAuth->getAddressDiscrimination() ==
7524 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7525 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7527 ManglerStream <<
"Lb"
7528 << (ExplicitAuth->getAddressDiscrimination() ==
7529 VTablePointerAuthenticationAttr::AddressDiscrimination);
7531 switch (ExplicitAuth->getExtraDiscrimination()) {
7532 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7533 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7534 ManglerStream <<
"Lj" << TypedDiscriminator;
7536 ManglerStream <<
"Lj" << 0;
7539 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7540 ManglerStream <<
"Lj" << TypedDiscriminator;
7542 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7543 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7545 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7546 ManglerStream <<
"Lj" << 0;
7550 ManglerStream <<
"Lj"
7551 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7552 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7553 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7554 ManglerStream <<
"Lj" << TypedDiscriminator;
7556 ManglerStream <<
"Lj" << 0;
7558 ManglerStream <<
"E";
7561void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7562 const ThunkInfo &Thunk,
7563 bool ElideOverrideInfo,
7573 "Use mangleCXXDtor for destructor decls!");
7574 CXXNameMangler Mangler(*
this, Out);
7575 Mangler.getStream() <<
"_ZT";
7577 Mangler.getStream() <<
'c';
7588 Mangler.mangleFunctionEncoding(MD);
7589 if (!ElideOverrideInfo)
7593void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7595 const ThunkInfo &Thunk,
7596 bool ElideOverrideInfo,
7600 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7601 Mangler.getStream() <<
"_ZT";
7603 auto &ThisAdjustment = Thunk.
This;
7605 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7606 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7608 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7609 if (!ElideOverrideInfo)
7614void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7618 CXXNameMangler Mangler(*
this, Out);
7621 Mangler.getStream() <<
"_ZGV";
7622 Mangler.mangleName(D);
7625void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7630 Out <<
"__cxx_global_var_init";
7633void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7636 CXXNameMangler Mangler(*
this, Out);
7637 Mangler.getStream() <<
"__dtor_";
7638 if (shouldMangleDeclName(D))
7641 Mangler.getStream() << D->
getName();
7644void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7648 CXXNameMangler Mangler(*
this, Out);
7649 Mangler.getStream() <<
"__finalize_";
7650 if (shouldMangleDeclName(D))
7653 Mangler.getStream() << D->
getName();
7656void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7657 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7658 CXXNameMangler Mangler(*
this, Out);
7659 Mangler.getStream() <<
"__filt_";
7661 if (shouldMangleDeclName(EnclosingFD))
7662 Mangler.mangle(EnclosingDecl);
7664 Mangler.getStream() << EnclosingFD->getName();
7667void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7668 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7669 CXXNameMangler Mangler(*
this, Out);
7670 Mangler.getStream() <<
"__fin_";
7672 if (shouldMangleDeclName(EnclosingFD))
7673 Mangler.mangle(EnclosingDecl);
7675 Mangler.getStream() << EnclosingFD->getName();
7678void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7681 CXXNameMangler Mangler(*
this, Out);
7682 Mangler.getStream() <<
"_ZTH";
7683 Mangler.mangleName(D);
7687ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7690 CXXNameMangler Mangler(*
this, Out);
7691 Mangler.getStream() <<
"_ZTW";
7692 Mangler.mangleName(D);
7695void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7696 unsigned ManglingNumber,
7700 CXXNameMangler Mangler(*
this, Out);
7701 Mangler.getStream() <<
"_ZGR";
7702 Mangler.mangleName(D);
7703 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7704 Mangler.mangleSeqID(ManglingNumber - 1);
7707void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7710 CXXNameMangler Mangler(*
this, Out);
7711 Mangler.getStream() <<
"_ZTV";
7712 Mangler.mangleCXXRecordDecl(RD);
7715void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7718 CXXNameMangler Mangler(*
this, Out);
7719 Mangler.getStream() <<
"_ZTT";
7720 Mangler.mangleCXXRecordDecl(RD);
7723void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7725 const CXXRecordDecl *
Type,
7728 CXXNameMangler Mangler(*
this, Out);
7729 Mangler.getStream() <<
"_ZTC";
7732 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7733 LangOptions::ClangABI::Ver19);
7734 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7735 Mangler.getStream() << Offset;
7736 Mangler.getStream() <<
'_';
7737 Mangler.mangleCXXRecordDecl(
Type);
7740void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7742 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7743 CXXNameMangler Mangler(*
this, Out);
7744 Mangler.getStream() <<
"_ZTI";
7745 Mangler.mangleType(Ty);
7748void ItaniumMangleContextImpl::mangleCXXRTTIName(
7749 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7751 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7752 Mangler.getStream() <<
"_ZTS";
7753 Mangler.mangleType(Ty);
7756void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7757 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7758 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7761void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7762 llvm_unreachable(
"Can't mangle string literals");
7765void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7767 CXXNameMangler Mangler(*
this, Out);
7768 Mangler.mangleLambdaSig(Lambda);
7771void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7774 CXXNameMangler Mangler(*
this, Out);
7775 Mangler.getStream() <<
"_ZGI";
7779 auto Partition = M->
Name.find(
':');
7780 Mangler.mangleModuleNamePrefix(
7781 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7789 return new ItaniumMangleContextImpl(
7792 return std::nullopt;
7801 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
static bool isUniqueInternalLinkageDecl(GlobalDecl GD, CodeGenModule &CGM)
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,...
ReflectionKind getKind() const
const void * getOpaqueValue() const
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
Test whether the quantity equals zero.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
QualType getElementType() const
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isRequiresExprBody() const
bool isFileContext() const
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
bool isExpansionStmt() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
unsigned getNumTemplateArgs() const
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
TemplateArgumentLoc const * getTemplateArgs() const
IdentifierOrOverloadedOperator getName() const
Represents a vector type where either the type or size is dependent.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
llvm::APSInt getInitVal() const
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APFloat getValue() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
ArrayRef< QualType > exceptions() const
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
CallingConv getCC() const
bool getProducesResult() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC?
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
QualType getReturnType() const
GlobalDecl - represents a global declaration.
CXXCtorType getCtorType() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
CXXDtorType getDtorType() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
const Expr * getSubExpr() const
Describes an C or C++ initializer list.
unsigned getNumInits() const
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
ItaniumMangleContext(ASTContext &C, DiagnosticsEngine &D, bool IsAux=false)
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
UnsignedOrNone(*)(ASTContext &, const NamedDecl *) DiscriminatorOverrideTy
bool isCompatibleWith(ClangABI Version) const
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
std::string Name
The name of this module.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NestedNameSpecifier getQualifier() const
Fetches the nested-name qualifier, if one was given.
decls_iterator decls_begin() const
unsigned getNumDecls() const
Gets the number of declarations in the unresolved set.
TemplateArgumentLoc const * getTemplateArgs() const
unsigned getNumTemplateArgs() const
DeclarationName getName() const
Gets the name looked up.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
unsigned getFunctionScopeDepth() const
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool hasUnaligned() const
bool hasAddressSpace() const
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Encodes a location in the source.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
TemplateName getReplacement() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
virtual const char * getFloat128Mangling() const
Return the mangled code of __float128.
virtual const char * getIbm128Mangling() const
Return the mangled code of __ibm128.
virtual const char * getLongDoubleMangling() const
Return the mangled code of long double.
virtual const char * getBFloat16Mangling() const
Return the mangled code of bfloat.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
std::pair< TemplateName, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template name that this template name refers to, along with the deduced defa...
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ PackIndexingTemplate
A pack-index-template-name.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
unsigned getOrdinal() const
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateName getNamedConcept() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
TypeTrait getTrait() const
Determine which type trait this expression uses.
The base class of the type hierarchy.
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents a GCC generic vector type.
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
@ Number
Just a number, nothing else.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Top level wrappers for InstallAPI frontend operations.
const char * getTraitSpelling(TypeTrait T) LLVM_READONLY
Return the spelling of the trait T. Never null.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte, bool isInstanceMethod, StringRef ClassName, std::optional< StringRef > CategoryName, StringRef MethodName, bool useDirectABI)
Extract mangling function name from MangleContext such that swift can call it to prepare for ObjCDire...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ 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.
bool isTypeAliasAsReflectionName(QualType QT)
[expr.reflect] p5, if a reflect-expression R matches the form ^^reflection-name it is interpreted as ...
@ 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.