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)
1775 mangleOperatorName(Name, Arity);
1776 writeAbiTags(ND, AdditionalAbiTags);
1780 llvm_unreachable(
"Can't mangle a deduction guide name!");
1783 llvm_unreachable(
"Can't mangle a using directive name!");
1787void CXXNameMangler::mangleConstructorName(
1788 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1789 const CXXRecordDecl *InheritedFrom =
nullptr;
1791 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1793 InheritedFrom = Inherited.getConstructor()->
getParent();
1794 InheritedTemplateName =
1795 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1796 InheritedTemplateArgs =
1797 Inherited.getConstructor()->getTemplateSpecializationArgs();
1800 if (CCD == Structor)
1803 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1811 if (InheritedTemplateArgs)
1812 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1814 writeAbiTags(CCD, AdditionalAbiTags);
1817void CXXNameMangler::mangleDestructorName(
1818 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1819 if (CDD == Structor)
1822 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1828 writeAbiTags(CDD, AdditionalAbiTags);
1831void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1835 if (getASTContext().getLangOpts().RegCall4)
1836 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1839 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1843void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1847 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1851void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1855 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1856 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1857 << OCLDeviceStubNamePrefix << II->
getName();
1860void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1867void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1868 ArrayRef<StringRef> AdditionalAbiTags,
1877 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1878 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1881 if (
Method->isExplicitObjectMemberFunction())
1884 mangleQualifiers(MethodQuals);
1885 mangleRefQualifier(
Method->getRefQualifier());
1889 const TemplateArgumentList *TemplateArgs =
nullptr;
1890 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1891 mangleTemplatePrefix(TD, NoFunction);
1894 manglePrefix(DC, NoFunction);
1895 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1900void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1901 ArrayRef<TemplateArgument> Args) {
1906 mangleTemplatePrefix(TD);
1912void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1913 GlobalDecl GD,
const NamedDecl *PrefixND,
1914 ArrayRef<StringRef> AdditionalAbiTags,
bool NoFunction) {
1923 mangleClosurePrefix(PrefixND, NoFunction);
1924 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1935 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1937 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1946void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1947 ArrayRef<StringRef> AdditionalAbiTags) {
1955 const RecordDecl *RD = GetLocalClassDecl(D);
1956 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1961 AbiTagState LocalAbiTags(AbiTags);
1963 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1965 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1966 mangleBlockForPrefix(BD);
1967 }
else if (
const auto *TLSD = dyn_cast<TopLevelStmtDecl>(DC)) {
1968 mangleTopLevelStmtEncoding(TLSD);
1975 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1989 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1991 if (
const ParmVarDecl *Parm
1993 if (
const FunctionDecl *
Func
1998 mangleNumber(
Num - 2);
2007 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
2008 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2009 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
2010 mangleClosurePrefix(PrefixND,
true );
2012 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
2013 assert(AdditionalAbiTags.empty() &&
2014 "Block cannot have additional abi tags");
2015 mangleUnqualifiedBlock(BD);
2018 const NamedDecl *PrefixND = getClosurePrefix(ND);
2019 if (PrefixND && !isCompatibleWith(LangOptions::ClangABI::Ver18))
2020 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags,
2023 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
2024 AdditionalAbiTags,
true);
2026 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2029 if (
const ParmVarDecl *Parm
2030 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
2031 if (
const FunctionDecl *
Func
2036 mangleNumber(
Num - 2);
2041 assert(AdditionalAbiTags.empty() &&
2042 "Block cannot have additional abi tags");
2043 mangleUnqualifiedBlock(BD);
2045 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
2048 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
2050 if (Context.getNextDiscriminator(ND, disc)) {
2054 Out <<
"__" << disc <<
'_';
2059void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
2060 if (GetLocalClassDecl(
Block)) {
2061 mangleLocalName(
Block);
2064 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
2065 if (isLocalContainerContext(DC)) {
2066 mangleLocalName(
Block);
2069 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
2070 mangleClosurePrefix(PrefixND);
2073 mangleUnqualifiedBlock(
Block);
2076void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2079 if (Decl *Context =
Block->getBlockManglingContextDecl();
2080 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2082 Context->getDeclContext()->isRecord()) {
2085 mangleSourceNameWithAbiTags(ND);
2091 unsigned Number =
Block->getBlockManglingNumber();
2106void CXXNameMangler::mangleTopLevelStmtEncoding(
const TopLevelStmtDecl *D) {
2108 SmallString<16> Name(
"__stmt__");
2110 Out <<
'L' << Name.size() << Name <<
'v';
2120void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2122 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2123 if (Ty->isParameterPack())
2125 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2126 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2129 mangleTypeConstraint(Constraint);
2133 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2134 if (Tn->isExpandedParameterPack()) {
2135 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2137 mangleType(Tn->getExpansionType(I));
2140 QualType
T = Tn->getType();
2141 if (Tn->isParameterPack()) {
2143 if (
auto *PackExpansion =
T->
getAs<PackExpansionType>())
2144 T = PackExpansion->getPattern();
2149 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2150 if (Tt->isExpandedParameterPack()) {
2151 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2153 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2155 if (Tt->isParameterPack())
2157 mangleTemplateParameterList(Tt->getTemplateParameters());
2162void CXXNameMangler::mangleTemplateParameterList(
2163 const TemplateParameterList *Params) {
2165 for (
auto *Param : *Params)
2166 mangleTemplateParamDecl(Param);
2167 mangleRequiresClause(Params->getRequiresClause());
2171void CXXNameMangler::mangleTypeConstraint(
2173 const TemplateDecl *TD =
Concept.getAsTemplateDecl();
2175 DiagnoseUnsupportedPackIndexTemplateName();
2178 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
2180 mangleTemplateName(TD, Arguments);
2182 mangleUnscopedName(TD, DC);
2184 mangleNestedName(TD, DC);
2187void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2188 llvm::SmallVector<TemplateArgument, 8> Args;
2190 for (
const TemplateArgumentLoc &ArgLoc :
2192 Args.push_back(ArgLoc.getArgument());
2197void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2199 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2201 mangleExpression(RequiresClause);
2205void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2209 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2212 if (
const IdentifierInfo *Name =
2214 mangleSourceName(Name);
2215 const TemplateArgumentList *TemplateArgs =
nullptr;
2223 mangleLambdaSig(Lambda);
2238 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2242 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2244 mangleNumber(Number - 2);
2248void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2251 mangleTemplateParamDecl(D);
2255 mangleRequiresClause(TPL->getRequiresClause());
2259 mangleBareFunctionType(Proto,
false,
2263void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2265 case NestedNameSpecifier::Kind::Null:
2266 case NestedNameSpecifier::Kind::Global:
2270 case NestedNameSpecifier::Kind::MicrosoftSuper:
2271 llvm_unreachable(
"Can't mangle __super specifier");
2273 case NestedNameSpecifier::Kind::Namespace:
2274 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2277 case NestedNameSpecifier::Kind::Type:
2278 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2282 llvm_unreachable(
"unexpected nested name specifier");
2285void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2298 if (NoFunction && isLocalContainerContext(DC))
2305 if (mangleSubstitution(ND))
2311 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2312 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2313 mangleTemplatePrefix(TD);
2315 *FD->getTemplateSpecializationArgs());
2317 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2320 addSubstitution(ND);
2325 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2327 addSubstitution(ND);
2332 const TemplateArgumentList *TemplateArgs =
nullptr;
2333 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2334 mangleTemplatePrefix(TD);
2336 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2337 mangleClosurePrefix(PrefixND, NoFunction);
2338 mangleUnqualifiedName(ND,
nullptr);
2340 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2341 manglePrefix(DC, NoFunction);
2342 mangleUnqualifiedName(ND, DC);
2345 addSubstitution(ND);
2352 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2353 return mangleTemplatePrefix(TD);
2355 if (
Template.getAsPackIndexingTemplate()) {
2356 DiagnoseUnsupportedPackIndexTemplateName();
2361 assert(
Dependent &&
"unexpected template name kind");
2365 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2366 if (!Clang11Compat && mangleSubstitution(
Template))
2369 manglePrefix(
Dependent->getQualifier());
2371 if (Clang11Compat && mangleSubstitution(
Template))
2374 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2375 const IdentifierInfo *Id = Name.getIdentifier())
2376 mangleSourceName(Id);
2378 mangleOperatorName(Name.getOperator(), UnknownArity);
2383void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2392 if (mangleSubstitution(ND))
2396 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2397 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2399 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2400 manglePrefix(DC, NoFunction);
2402 mangleUnqualifiedName(GD, DC);
2407 addSubstitution(ND);
2410const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2411 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2414 const NamedDecl *Context =
nullptr;
2415 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2416 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2417 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2420 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2422 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2436void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2439 if (mangleSubstitution(ND))
2442 const TemplateArgumentList *TemplateArgs =
nullptr;
2443 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2444 mangleTemplatePrefix(TD, NoFunction);
2447 const auto *DC = Context.getEffectiveDeclContext(ND);
2448 manglePrefix(DC, NoFunction);
2449 mangleUnqualifiedName(ND, DC);
2454 addSubstitution(ND);
2463 if (mangleSubstitution(TN))
2466 TemplateDecl *TD =
nullptr;
2476 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2477 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2484 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2493 mangleUnresolvedPrefix(
Dependent->getQualifier());
2494 mangleSourceName(II);
2503 SubstTemplateTemplateParmStorage *subst
2514 Out <<
"_SUBSTPACK_";
2519 DiagnoseUnsupportedPackIndexTemplateName();
2523 llvm_unreachable(
"Unexpected DeducedTemplate");
2526 addSubstitution(TN);
2529bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2535 case Type::Adjusted:
2537 case Type::ArrayParameter:
2539 case Type::BlockPointer:
2540 case Type::LValueReference:
2541 case Type::RValueReference:
2542 case Type::MemberPointer:
2543 case Type::ConstantArray:
2544 case Type::IncompleteArray:
2545 case Type::VariableArray:
2546 case Type::DependentSizedArray:
2547 case Type::DependentAddressSpace:
2548 case Type::DependentVector:
2549 case Type::DependentSizedExtVector:
2551 case Type::ExtVector:
2552 case Type::ConstantMatrix:
2553 case Type::DependentSizedMatrix:
2554 case Type::FunctionProto:
2555 case Type::FunctionNoProto:
2557 case Type::Attributed:
2558 case Type::BTFTagAttributed:
2559 case Type::OverflowBehavior:
2560 case Type::HLSLAttributedResource:
2561 case Type::HLSLInlineSpirv:
2563 case Type::DeducedTemplateSpecialization:
2564 case Type::PackExpansion:
2565 case Type::ObjCObject:
2566 case Type::ObjCInterface:
2567 case Type::ObjCObjectPointer:
2568 case Type::ObjCTypeParam:
2571 case Type::MacroQualified:
2573 case Type::DependentBitInt:
2574 case Type::CountAttributed:
2575 case Type::LateParsedAttr:
2576 llvm_unreachable(
"type is illegal as a nested name specifier");
2578 case Type::SubstBuiltinTemplatePack:
2583 Out <<
"_SUBSTBUILTINPACK_";
2585 case Type::SubstTemplateTypeParmPack:
2590 Out <<
"_SUBSTPACK_";
2597 case Type::TypeOfExpr:
2599 case Type::Decltype:
2600 case Type::PackIndexing:
2601 case Type::TemplateTypeParm:
2602 case Type::UnaryTransform:
2615 case Type::SubstTemplateTypeParm: {
2619 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2621 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2622 goto unresolvedType;
2629 case Type::PredefinedSugar:
2633 case Type::UnresolvedUsing:
2634 mangleSourceNameWithAbiTags(
2640 mangleSourceNameWithAbiTags(
2644 case Type::TemplateSpecialization: {
2645 const TemplateSpecializationType *TST =
2655 assert(TD &&
"no template for template specialization type");
2657 goto unresolvedType;
2659 mangleSourceNameWithAbiTags(TD);
2671 llvm_unreachable(
"invalid base for a template specialization type");
2674 SubstTemplateTemplateParmStorage *subst =
2685 Out <<
"_SUBSTPACK_";
2690 DiagnoseUnsupportedPackIndexTemplateName();
2696 mangleSourceNameWithAbiTags(TD);
2706 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2710 case Type::InjectedClassName:
2711 mangleSourceNameWithAbiTags(
2715 case Type::DependentName:
2727void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2737 llvm_unreachable(
"Not an operator name");
2760 case OO_New:
Out <<
"nw";
break;
2762 case OO_Array_New:
Out <<
"na";
break;
2764 case OO_Delete:
Out <<
"dl";
break;
2766 case OO_Array_Delete:
Out <<
"da";
break;
2770 Out << (Arity == 1?
"ps" :
"pl");
break;
2774 Out << (Arity == 1?
"ng" :
"mi");
break;
2778 Out << (Arity == 1?
"ad" :
"an");
break;
2783 Out << (Arity == 1?
"de" :
"ml");
break;
2785 case OO_Tilde:
Out <<
"co";
break;
2787 case OO_Slash:
Out <<
"dv";
break;
2789 case OO_Percent:
Out <<
"rm";
break;
2791 case OO_Pipe:
Out <<
"or";
break;
2793 case OO_Caret:
Out <<
"eo";
break;
2795 case OO_Equal:
Out <<
"aS";
break;
2797 case OO_PlusEqual:
Out <<
"pL";
break;
2799 case OO_MinusEqual:
Out <<
"mI";
break;
2801 case OO_StarEqual:
Out <<
"mL";
break;
2803 case OO_SlashEqual:
Out <<
"dV";
break;
2805 case OO_PercentEqual:
Out <<
"rM";
break;
2807 case OO_AmpEqual:
Out <<
"aN";
break;
2809 case OO_PipeEqual:
Out <<
"oR";
break;
2811 case OO_CaretEqual:
Out <<
"eO";
break;
2813 case OO_LessLess:
Out <<
"ls";
break;
2815 case OO_GreaterGreater:
Out <<
"rs";
break;
2817 case OO_LessLessEqual:
Out <<
"lS";
break;
2819 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2821 case OO_EqualEqual:
Out <<
"eq";
break;
2823 case OO_ExclaimEqual:
Out <<
"ne";
break;
2825 case OO_Less:
Out <<
"lt";
break;
2827 case OO_Greater:
Out <<
"gt";
break;
2829 case OO_LessEqual:
Out <<
"le";
break;
2831 case OO_GreaterEqual:
Out <<
"ge";
break;
2833 case OO_Exclaim:
Out <<
"nt";
break;
2835 case OO_AmpAmp:
Out <<
"aa";
break;
2837 case OO_PipePipe:
Out <<
"oo";
break;
2839 case OO_PlusPlus:
Out <<
"pp";
break;
2841 case OO_MinusMinus:
Out <<
"mm";
break;
2843 case OO_Comma:
Out <<
"cm";
break;
2845 case OO_ArrowStar:
Out <<
"pm";
break;
2847 case OO_Arrow:
Out <<
"pt";
break;
2849 case OO_Call:
Out <<
"cl";
break;
2851 case OO_Subscript:
Out <<
"ix";
break;
2856 case OO_Conditional:
Out <<
"qu";
break;
2859 case OO_Coawait:
Out <<
"aw";
break;
2862 case OO_Spaceship:
Out <<
"ss";
break;
2866 llvm_unreachable(
"Not an overloaded operator");
2870void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2889 SmallString<64> ASString;
2895 if (TargetAS != 0 ||
2897 ASString =
"AS" + llvm::utostr(TargetAS);
2900 default: llvm_unreachable(
"Not a language specific address space");
2904 case LangAS::opencl_global:
2905 ASString =
"CLglobal";
2907 case LangAS::opencl_global_device:
2908 ASString =
"CLdevice";
2910 case LangAS::opencl_global_host:
2911 ASString =
"CLhost";
2913 case LangAS::opencl_local:
2914 ASString =
"CLlocal";
2916 case LangAS::opencl_constant:
2917 ASString =
"CLconstant";
2919 case LangAS::opencl_private:
2920 ASString =
"CLprivate";
2922 case LangAS::opencl_generic:
2923 ASString =
"CLgeneric";
2928 case LangAS::sycl_global:
2929 ASString =
"SYglobal";
2931 case LangAS::sycl_global_device:
2932 ASString =
"SYdevice";
2934 case LangAS::sycl_global_host:
2935 ASString =
"SYhost";
2937 case LangAS::sycl_local:
2938 ASString =
"SYlocal";
2940 case LangAS::sycl_private:
2941 ASString =
"SYprivate";
2943 case LangAS::sycl_generic:
2944 ASString =
"SYgeneric";
2946 case LangAS::sycl_constant:
2947 ASString =
"SYconstant";
2950 case LangAS::cuda_device:
2951 ASString =
"CUdevice";
2953 case LangAS::cuda_constant:
2954 ASString =
"CUconstant";
2956 case LangAS::cuda_shared:
2957 ASString =
"CUshared";
2960 case LangAS::ptr32_sptr:
2961 ASString =
"ptr32_sptr";
2963 case LangAS::ptr32_uptr:
2967 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2968 ASString =
"ptr32_uptr";
2975 if (!ASString.empty())
2976 mangleVendorQualifier(ASString);
2989 mangleVendorQualifier(
"__weak");
2993 mangleVendorQualifier(
"__unaligned");
2997 mangleVendorQualifier(
"__ptrauth");
3007 << unsigned(PtrAuth.isAddressDiscriminated())
3010 << PtrAuth.getExtraDiscriminator()
3025 mangleVendorQualifier(
"__strong");
3029 mangleVendorQualifier(
"__autoreleasing");
3052void CXXNameMangler::mangleVendorQualifier(StringRef name) {
3056void CXXNameMangler::mangleVendorType(StringRef name) {
3063 switch (RefQualifier) {
3077void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
3078 Context.mangleObjCMethodNameAsSourceName(MD, Out);
3103 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
3104 if (DeducedTST->getDeducedType().isNull())
3109void CXXNameMangler::mangleType(QualType
T) {
3143 T =
T.getCanonicalType();
3149 if (
const TemplateSpecializationType *TST
3150 = dyn_cast<TemplateSpecializationType>(
T))
3151 if (!TST->isTypeAlias())
3159 =
T.getSingleStepDesugaredType(Context.getASTContext());
3166 auto [ty, quals] =
T.split();
3168 bool isSubstitutable =
3170 if (isSubstitutable && mangleSubstitution(
T))
3177 quals = Qualifiers();
3183 if (quals || ty->isDependentAddressSpaceType()) {
3184 if (
const DependentAddressSpaceType *DAST =
3185 dyn_cast<DependentAddressSpaceType>(ty)) {
3187 mangleQualifiers(Quals, DAST);
3188 mangleType(QualType(Ty, 0));
3190 mangleQualifiers(quals);
3194 mangleType(QualType(ty, 0));
3197 switch (ty->getTypeClass()) {
3198#define ABSTRACT_TYPE(CLASS, PARENT)
3199#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3201 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3203#define TYPE(CLASS, PARENT) \
3205 mangleType(static_cast<const CLASS##Type*>(ty)); \
3207#include "clang/AST/TypeNodes.inc"
3212 if (isSubstitutable)
3216void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3217 bool SuppressSubstitution) {
3218 if (mangleSubstitution(
Record))
3221 if (SuppressSubstitution)
3226void CXXNameMangler::mangleType(
const BuiltinType *
T) {
3270 std::string type_name;
3274 if (NormalizeIntegers &&
T->isInteger()) {
3275 if (
T->isSignedInteger()) {
3276 switch (getASTContext().getTypeSize(
T)) {
3280 if (mangleSubstitution(BuiltinType::SChar))
3283 addSubstitution(BuiltinType::SChar);
3286 if (mangleSubstitution(BuiltinType::Short))
3289 addSubstitution(BuiltinType::Short);
3292 if (mangleSubstitution(BuiltinType::Int))
3295 addSubstitution(BuiltinType::Int);
3298 if (mangleSubstitution(BuiltinType::Long))
3301 addSubstitution(BuiltinType::Long);
3304 if (mangleSubstitution(BuiltinType::Int128))
3307 addSubstitution(BuiltinType::Int128);
3310 llvm_unreachable(
"Unknown integer size for normalization");
3313 switch (getASTContext().getTypeSize(
T)) {
3315 if (mangleSubstitution(BuiltinType::UChar))
3318 addSubstitution(BuiltinType::UChar);
3321 if (mangleSubstitution(BuiltinType::UShort))
3324 addSubstitution(BuiltinType::UShort);
3327 if (mangleSubstitution(BuiltinType::UInt))
3330 addSubstitution(BuiltinType::UInt);
3333 if (mangleSubstitution(BuiltinType::ULong))
3336 addSubstitution(BuiltinType::ULong);
3339 if (mangleSubstitution(BuiltinType::UInt128))
3342 addSubstitution(BuiltinType::UInt128);
3345 llvm_unreachable(
"Unknown integer size for normalization");
3350 switch (
T->getKind()) {
3351 case BuiltinType::Void:
3354 case BuiltinType::Bool:
3357 case BuiltinType::Char_U:
3358 case BuiltinType::Char_S:
3361 case BuiltinType::UChar:
3364 case BuiltinType::UShort:
3367 case BuiltinType::UInt:
3370 case BuiltinType::ULong:
3373 case BuiltinType::ULongLong:
3376 case BuiltinType::UInt128:
3379 case BuiltinType::SChar:
3382 case BuiltinType::WChar_S:
3383 case BuiltinType::WChar_U:
3386 case BuiltinType::Char8:
3389 case BuiltinType::Char16:
3392 case BuiltinType::Char32:
3395 case BuiltinType::Short:
3398 case BuiltinType::Int:
3401 case BuiltinType::Long:
3404 case BuiltinType::LongLong:
3407 case BuiltinType::Int128:
3410 case BuiltinType::Float16:
3413 case BuiltinType::ShortAccum:
3416 case BuiltinType::Accum:
3419 case BuiltinType::LongAccum:
3422 case BuiltinType::UShortAccum:
3425 case BuiltinType::UAccum:
3428 case BuiltinType::ULongAccum:
3431 case BuiltinType::ShortFract:
3434 case BuiltinType::Fract:
3437 case BuiltinType::LongFract:
3440 case BuiltinType::UShortFract:
3443 case BuiltinType::UFract:
3446 case BuiltinType::ULongFract:
3449 case BuiltinType::SatShortAccum:
3452 case BuiltinType::SatAccum:
3455 case BuiltinType::SatLongAccum:
3458 case BuiltinType::SatUShortAccum:
3461 case BuiltinType::SatUAccum:
3464 case BuiltinType::SatULongAccum:
3467 case BuiltinType::SatShortFract:
3470 case BuiltinType::SatFract:
3473 case BuiltinType::SatLongFract:
3476 case BuiltinType::SatUShortFract:
3479 case BuiltinType::SatUFract:
3482 case BuiltinType::SatULongFract:
3485 case BuiltinType::Half:
3488 case BuiltinType::Float:
3491 case BuiltinType::Double:
3494 case BuiltinType::LongDouble: {
3495 const TargetInfo *TI =
3496 getASTContext().getLangOpts().OpenMP &&
3497 getASTContext().getLangOpts().OpenMPIsTargetDevice
3498 ? getASTContext().getAuxTargetInfo()
3499 : &getASTContext().getTargetInfo();
3503 case BuiltinType::Float128: {
3504 const TargetInfo *TI =
3505 getASTContext().getLangOpts().OpenMP &&
3506 getASTContext().getLangOpts().OpenMPIsTargetDevice
3507 ? getASTContext().getAuxTargetInfo()
3508 : &getASTContext().getTargetInfo();
3512 case BuiltinType::BFloat16: {
3513 const TargetInfo *TI =
3514 ((getASTContext().getLangOpts().OpenMP &&
3515 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3516 getASTContext().getLangOpts().SYCLIsDevice)
3517 ? getASTContext().getAuxTargetInfo()
3518 : &getASTContext().getTargetInfo();
3522 case BuiltinType::Ibm128: {
3523 const TargetInfo *TI = &getASTContext().getTargetInfo();
3527 case BuiltinType::MetaInfo:
3531 case BuiltinType::NullPtr:
3535#define BUILTIN_TYPE(Id, SingletonId)
3536#define PLACEHOLDER_TYPE(Id, SingletonId) \
3537 case BuiltinType::Id:
3538#include "clang/AST/BuiltinTypes.def"
3539 case BuiltinType::Dependent:
3541 llvm_unreachable(
"mangling a placeholder type");
3543 case BuiltinType::ObjCId:
3544 Out <<
"11objc_object";
3546 case BuiltinType::ObjCClass:
3547 Out <<
"10objc_class";
3549 case BuiltinType::ObjCSel:
3550 Out <<
"13objc_selector";
3552#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3553 case BuiltinType::Id: \
3554 type_name = "ocl_" #ImgType "_" #Suffix; \
3555 Out << type_name.size() << type_name; \
3557#include "clang/Basic/OpenCLImageTypes.def"
3558 case BuiltinType::OCLSampler:
3559 Out <<
"11ocl_sampler";
3561 case BuiltinType::OCLEvent:
3562 Out <<
"9ocl_event";
3564 case BuiltinType::OCLClkEvent:
3565 Out <<
"12ocl_clkevent";
3567 case BuiltinType::OCLQueue:
3568 Out <<
"9ocl_queue";
3570 case BuiltinType::OCLReserveID:
3571 Out <<
"13ocl_reserveid";
3573#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3574 case BuiltinType::Id: \
3575 type_name = "ocl_" #ExtType; \
3576 Out << type_name.size() << type_name; \
3578#include "clang/Basic/OpenCLExtensionTypes.def"
3582#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3583 case BuiltinType::Id: \
3584 if (T->getKind() == BuiltinType::SveBFloat16 && \
3585 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3587 mangleVendorType("__SVBFloat16_t"); \
3589 type_name = #MangledName; \
3590 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3593#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3594 case BuiltinType::Id: \
3595 type_name = #MangledName; \
3596 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3598#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3599 case BuiltinType::Id: \
3600 type_name = #MangledName; \
3601 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3603#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3604 case BuiltinType::Id: \
3605 type_name = #MangledName; \
3606 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3608#include "clang/Basic/AArch64ACLETypes.def"
3609#define PPC_VECTOR_TYPE(Name, Id, Size) \
3610 case BuiltinType::Id: \
3611 mangleVendorType(#Name); \
3613#include "clang/Basic/PPCTypes.def"
3615#define RVV_TYPE(Name, Id, SingletonId) \
3616 case BuiltinType::Id: \
3617 mangleVendorType(Name); \
3619#include "clang/Basic/RISCVVTypes.def"
3620#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3621 case BuiltinType::Id: \
3622 mangleVendorType(MangledName); \
3624#include "clang/Basic/WebAssemblyReferenceTypes.def"
3625#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3626 case BuiltinType::Id: \
3627 mangleVendorType(Name); \
3629#include "clang/Basic/AMDGPUTypes.def"
3630#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3631 case BuiltinType::Id: \
3632 mangleVendorType(#Name); \
3634#include "clang/Basic/HLSLIntangibleTypes.def"
3635#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
3636 case BuiltinType::Id: \
3637 mangleVendorType(#Name); \
3639#include "clang/Basic/HLSLPackedTypes.def"
3640#define SPIRV_TYPE(Name, Id, SingletonId) \
3641 case BuiltinType::Id: \
3642 mangleVendorType(Name); \
3644#include "clang/Basic/SPIRVTypes.def"
3648StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3667#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3703 return "swiftasynccall";
3705 llvm_unreachable(
"bad calling convention");
3708void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3717 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3718 if (!CCQualifier.empty())
3719 mangleVendorQualifier(CCQualifier);
3752 llvm_unreachable(
"Unrecognised SME attribute");
3767void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3787 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3791CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3798 case ParameterABI::Ordinary:
3802 case ParameterABI::HLSLOut:
3803 case ParameterABI::HLSLInOut:
3808 case ParameterABI::SwiftContext:
3809 case ParameterABI::SwiftAsyncContext:
3810 case ParameterABI::SwiftErrorResult:
3811 case ParameterABI::SwiftIndirectResult:
3817 mangleVendorQualifier(
"ns_consumed");
3820 mangleVendorQualifier(
"noescape");
3826void CXXNameMangler::mangleType(
const FunctionProtoType *
T) {
3830 Out <<
"11__SME_ATTRSI";
3832 mangleExtFunctionInfo(
T);
3849 mangleType(ExceptTy);
3860 mangleBareFunctionType(
T,
true);
3867 mangleSMEAttrs(SMEAttrs);
3870void CXXNameMangler::mangleType(
const FunctionNoProtoType *
T) {
3876 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3878 FunctionTypeDepth.enterFunctionDeclSuffix();
3880 FunctionTypeDepth.leaveFunctionDeclSuffix();
3882 FunctionTypeDepth.pop(saved);
3886void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3887 bool MangleReturnType,
3888 const FunctionDecl *FD) {
3891 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3894 if (MangleReturnType) {
3895 FunctionTypeDepth.enterFunctionDeclSuffix();
3899 mangleVendorQualifier(
"ns_returns_retained");
3904 auto SplitReturnTy = ReturnTy.
split();
3906 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3908 mangleType(ReturnTy);
3910 FunctionTypeDepth.leaveFunctionDeclSuffix();
3918 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3932 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3933 if (Attr->isDynamic())
3934 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3936 Out <<
"U17pass_object_size" << Attr->getType();
3947 FunctionTypeDepth.enterFunctionDeclSuffix();
3951 FunctionTypeDepth.pop(saved);
3956void CXXNameMangler::mangleType(
const UnresolvedUsingType *
T) {
3957 mangleName(
T->getDecl());
3962void CXXNameMangler::mangleType(
const EnumType *
T) {
3963 mangleType(
static_cast<const TagType*
>(
T));
3965void CXXNameMangler::mangleType(
const RecordType *
T) {
3966 mangleType(
static_cast<const TagType*
>(
T));
3968void CXXNameMangler::mangleType(
const TagType *
T) {
3969 mangleName(
T->getDecl()->getDefinitionOrSelf());
3975void CXXNameMangler::mangleType(
const ConstantArrayType *
T) {
3976 Out <<
'A' <<
T->getSize() <<
'_';
3977 mangleType(
T->getElementType());
3979void CXXNameMangler::mangleType(
const VariableArrayType *
T) {
3982 if (
T->getSizeExpr())
3983 mangleExpression(
T->getSizeExpr());
3985 mangleType(
T->getElementType());
3987void CXXNameMangler::mangleType(
const DependentSizedArrayType *
T) {
3992 if (
T->getSizeExpr())
3993 mangleExpression(
T->getSizeExpr());
3995 mangleType(
T->getElementType());
3997void CXXNameMangler::mangleType(
const IncompleteArrayType *
T) {
3999 mangleType(
T->getElementType());
4004void CXXNameMangler::mangleType(
const MemberPointerType *
T) {
4006 if (
auto *RD =
T->getMostRecentCXXRecordDecl())
4007 mangleCXXRecordDecl(RD);
4009 mangleType(QualType(
T->getQualifier().getAsType(), 0));
4011 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
4032 mangleType(PointeeType);
4036void CXXNameMangler::mangleType(
const TemplateTypeParmType *
T) {
4037 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
4041void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *
T) {
4046 Out <<
"_SUBSTPACK_";
4049void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *
T) {
4054 Out <<
"_SUBSTBUILTINPACK_";
4058void CXXNameMangler::mangleType(
const PointerType *
T) {
4062void CXXNameMangler::mangleType(
const ObjCObjectPointerType *
T) {
4068void CXXNameMangler::mangleType(
const LValueReferenceType *
T) {
4074void CXXNameMangler::mangleType(
const RValueReferenceType *
T) {
4080void CXXNameMangler::mangleType(
const ComplexType *
T) {
4082 mangleType(
T->getElementType());
4088void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
4089 QualType EltType =
T->getElementType();
4090 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4091 const char *EltName =
nullptr;
4092 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4094 case BuiltinType::SChar:
4095 case BuiltinType::UChar:
4096 EltName =
"poly8_t";
4098 case BuiltinType::Short:
4099 case BuiltinType::UShort:
4100 EltName =
"poly16_t";
4102 case BuiltinType::LongLong:
4103 case BuiltinType::ULongLong:
4104 EltName =
"poly64_t";
4106 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
4110 case BuiltinType::SChar: EltName =
"int8_t";
break;
4111 case BuiltinType::UChar: EltName =
"uint8_t";
break;
4112 case BuiltinType::Short: EltName =
"int16_t";
break;
4113 case BuiltinType::UShort: EltName =
"uint16_t";
break;
4114 case BuiltinType::Int: EltName =
"int32_t";
break;
4115 case BuiltinType::UInt: EltName =
"uint32_t";
break;
4116 case BuiltinType::LongLong: EltName =
"int64_t";
break;
4117 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
4118 case BuiltinType::Double: EltName =
"float64_t";
break;
4119 case BuiltinType::Float: EltName =
"float32_t";
break;
4120 case BuiltinType::Half: EltName =
"float16_t";
break;
4121 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
4122 case BuiltinType::MFloat8:
4123 EltName =
"mfloat8_t";
4126 llvm_unreachable(
"unexpected Neon vector element type");
4129 const char *BaseName =
nullptr;
4130 unsigned BitSize = (
T->getNumElements() *
4131 getASTContext().getTypeSize(EltType));
4133 BaseName =
"__simd64_";
4135 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4136 BaseName =
"__simd128_";
4138 Out << strlen(BaseName) + strlen(EltName);
4139 Out << BaseName << EltName;
4142void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *
T) {
4143 DiagnosticsEngine &Diags = Context.getDiags();
4144 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4145 << UnsupportedItaniumManglingKind::DependentNeonVector;
4150 case BuiltinType::SChar:
4152 case BuiltinType::Short:
4154 case BuiltinType::Int:
4156 case BuiltinType::Long:
4157 case BuiltinType::LongLong:
4159 case BuiltinType::UChar:
4161 case BuiltinType::UShort:
4163 case BuiltinType::UInt:
4165 case BuiltinType::ULong:
4166 case BuiltinType::ULongLong:
4168 case BuiltinType::Half:
4170 case BuiltinType::Float:
4172 case BuiltinType::Double:
4174 case BuiltinType::BFloat16:
4176 case BuiltinType::MFloat8:
4179 llvm_unreachable(
"Unexpected vector element base type");
4186void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
4187 QualType EltType =
T->getElementType();
4188 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4190 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
4193 assert((BitSize == 64 || BitSize == 128) &&
4194 "Neon vector type not 64 or 128 bits");
4197 if (
T->getVectorKind() == VectorKind::NeonPoly) {
4199 case BuiltinType::UChar:
4202 case BuiltinType::UShort:
4205 case BuiltinType::ULong:
4206 case BuiltinType::ULongLong:
4210 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4216 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
4219void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *
T) {
4220 DiagnosticsEngine &Diags = Context.getDiags();
4221 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4222 << UnsupportedItaniumManglingKind::DependentNeonVector;
4249void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
4250 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4251 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4252 "expected fixed-length SVE vector!");
4254 QualType EltType =
T->getElementType();
4256 "expected builtin type for fixed-length SVE vector!");
4260 case BuiltinType::SChar:
4263 case BuiltinType::UChar: {
4264 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
4270 case BuiltinType::Short:
4273 case BuiltinType::UShort:
4276 case BuiltinType::Int:
4279 case BuiltinType::UInt:
4282 case BuiltinType::Long:
4285 case BuiltinType::ULong:
4288 case BuiltinType::Half:
4291 case BuiltinType::Float:
4294 case BuiltinType::Double:
4297 case BuiltinType::BFloat16:
4301 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4304 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4306 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
4309 Out <<
"9__SVE_VLSI";
4310 mangleVendorType(TypeName);
4311 Out <<
"Lj" << VecSizeInBits <<
"EE";
4314void CXXNameMangler::mangleAArch64FixedSveVectorType(
4315 const DependentVectorType *
T) {
4316 DiagnosticsEngine &Diags = Context.getDiags();
4317 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4318 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4321void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4322 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4323 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4324 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4325 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4326 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) &&
4327 "expected fixed-length RVV vector!");
4329 QualType EltType =
T->getElementType();
4331 "expected builtin type for fixed-length RVV vector!");
4333 SmallString<20> TypeNameStr;
4334 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4335 TypeNameOS <<
"__rvv_";
4337 case BuiltinType::SChar:
4338 TypeNameOS <<
"int8";
4340 case BuiltinType::UChar:
4341 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4342 TypeNameOS <<
"uint8";
4344 TypeNameOS <<
"bool";
4346 case BuiltinType::Short:
4347 TypeNameOS <<
"int16";
4349 case BuiltinType::UShort:
4350 TypeNameOS <<
"uint16";
4352 case BuiltinType::Int:
4353 TypeNameOS <<
"int32";
4355 case BuiltinType::UInt:
4356 TypeNameOS <<
"uint32";
4358 case BuiltinType::Long:
4359 case BuiltinType::LongLong:
4360 TypeNameOS <<
"int64";
4362 case BuiltinType::ULong:
4363 case BuiltinType::ULongLong:
4364 TypeNameOS <<
"uint64";
4366 case BuiltinType::Float16:
4367 TypeNameOS <<
"float16";
4369 case BuiltinType::Float:
4370 TypeNameOS <<
"float32";
4372 case BuiltinType::Double:
4373 TypeNameOS <<
"float64";
4375 case BuiltinType::BFloat16:
4376 TypeNameOS <<
"bfloat16";
4379 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4382 unsigned VecSizeInBits;
4383 switch (
T->getVectorKind()) {
4384 case VectorKind::RVVFixedLengthMask_1:
4387 case VectorKind::RVVFixedLengthMask_2:
4390 case VectorKind::RVVFixedLengthMask_4:
4394 VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4399 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4400 getASTContext().getLangOpts(),
4401 TargetInfo::ArmStreamingKind::NotStreaming);
4402 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4404 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4406 if (VecSizeInBits >= VLen)
4407 TypeNameOS << (VecSizeInBits / VLen);
4409 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4411 TypeNameOS << (VLen / VecSizeInBits);
4415 Out <<
"9__RVV_VLSI";
4416 mangleVendorType(TypeNameStr);
4417 Out <<
"Lj" << VecSizeInBits <<
"EE";
4420void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4421 const DependentVectorType *
T) {
4422 DiagnosticsEngine &Diags = Context.getDiags();
4423 Diags.
Report(
T->getAttributeLoc(), diag::err_unsupported_itanium_mangling)
4424 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4435void CXXNameMangler::mangleType(
const VectorType *
T) {
4436 if ((
T->getVectorKind() == VectorKind::Neon ||
4437 T->getVectorKind() == VectorKind::NeonPoly)) {
4438 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4439 llvm::Triple::ArchType
Arch =
4440 getASTContext().getTargetInfo().getTriple().getArch();
4441 if ((
Arch == llvm::Triple::aarch64 ||
4442 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4443 mangleAArch64NeonVectorType(
T);
4445 mangleNeonVectorType(
T);
4447 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4448 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4449 mangleAArch64FixedSveVectorType(
T);
4451 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4452 T->getVectorKind() == VectorKind::RVVFixedLengthMask ||
4453 T->getVectorKind() == VectorKind::RVVFixedLengthMask_1 ||
4454 T->getVectorKind() == VectorKind::RVVFixedLengthMask_2 ||
4455 T->getVectorKind() == VectorKind::RVVFixedLengthMask_4) {
4456 mangleRISCVFixedRVVVectorType(
T);
4459 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4460 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4462 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4465 mangleType(
T->getElementType());
4468void CXXNameMangler::mangleType(
const DependentVectorType *
T) {
4469 if ((
T->getVectorKind() == VectorKind::Neon ||
4470 T->getVectorKind() == VectorKind::NeonPoly)) {
4471 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4472 llvm::Triple::ArchType
Arch =
4473 getASTContext().getTargetInfo().getTriple().getArch();
4474 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4476 mangleAArch64NeonVectorType(
T);
4478 mangleNeonVectorType(
T);
4480 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4481 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4482 mangleAArch64FixedSveVectorType(
T);
4484 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4485 mangleRISCVFixedRVVVectorType(
T);
4490 mangleExpression(
T->getSizeExpr());
4492 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4494 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4497 mangleType(
T->getElementType());
4500void CXXNameMangler::mangleType(
const ExtVectorType *
T) {
4501 mangleType(
static_cast<const VectorType*
>(
T));
4503void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *
T) {
4505 mangleExpression(
T->getSizeExpr());
4507 mangleType(
T->getElementType());
4510void CXXNameMangler::mangleType(
const ConstantMatrixType *
T) {
4514 mangleVendorType(
"matrix_type");
4517 auto &ASTCtx = getASTContext();
4518 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4519 llvm::APSInt Rows(BitWidth);
4520 Rows =
T->getNumRows();
4521 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4522 llvm::APSInt Columns(BitWidth);
4523 Columns =
T->getNumColumns();
4524 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4525 mangleType(
T->getElementType());
4529void CXXNameMangler::mangleType(
const DependentSizedMatrixType *
T) {
4532 mangleVendorType(
"matrix_type");
4535 mangleTemplateArgExpr(
T->getRowExpr());
4536 mangleTemplateArgExpr(
T->getColumnExpr());
4537 mangleType(
T->getElementType());
4541void CXXNameMangler::mangleType(
const DependentAddressSpaceType *
T) {
4543 mangleQualifiers(split.
Quals,
T);
4544 mangleType(QualType(split.
Ty, 0));
4547void CXXNameMangler::mangleType(
const PackExpansionType *
T) {
4550 mangleType(
T->getPattern());
4553void CXXNameMangler::mangleType(
const PackIndexingType *
T) {
4556 mangleType(
T->getPattern());
4557 mangleExpression(
T->getIndexExpr());
4560void CXXNameMangler::mangleType(
const ObjCInterfaceType *
T) {
4561 mangleSourceName(
T->getDecl()->getIdentifier());
4564void CXXNameMangler::mangleType(
const ObjCObjectType *
T) {
4566 if (
T->isKindOfType())
4567 Out <<
"U8__kindof";
4569 if (!
T->qual_empty()) {
4571 SmallString<64> QualStr;
4572 llvm::raw_svector_ostream QualOS(QualStr);
4573 QualOS <<
"objcproto";
4574 for (
const auto *I :
T->quals()) {
4575 StringRef
name = I->getName();
4578 mangleVendorQualifier(QualStr);
4581 mangleType(
T->getBaseType());
4583 if (
T->isSpecialized()) {
4586 for (
auto typeArg :
T->getTypeArgs())
4587 mangleType(typeArg);
4592void CXXNameMangler::mangleType(
const BlockPointerType *
T) {
4593 Out <<
"U13block_pointer";
4597void CXXNameMangler::mangleType(
const InjectedClassNameType *
T) {
4602 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4605void CXXNameMangler::mangleType(
const TemplateSpecializationType *
T) {
4606 if (TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4607 mangleTemplateName(TD,
T->template_arguments());
4610 mangleTemplatePrefix(
T->getTemplateName());
4615 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4620void CXXNameMangler::mangleType(
const DependentNameType *
T) {
4631 switch (
T->getKeyword()) {
4632 case ElaboratedTypeKeyword::None:
4633 case ElaboratedTypeKeyword::Typename:
4635 case ElaboratedTypeKeyword::Struct:
4636 case ElaboratedTypeKeyword::Class:
4637 case ElaboratedTypeKeyword::Interface:
4640 case ElaboratedTypeKeyword::Union:
4643 case ElaboratedTypeKeyword::Enum:
4649 manglePrefix(
T->getQualifier());
4650 mangleSourceName(
T->getIdentifier());
4654void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4660void CXXNameMangler::mangleType(
const TypeOfExprType *
T) {
4666void CXXNameMangler::mangleType(
const DecltypeType *
T) {
4667 Expr *E =
T->getUnderlyingExpr();
4686 mangleExpression(E);
4690void CXXNameMangler::mangleType(
const UnaryTransformType *
T) {
4694 StringRef BuiltinName;
4695 switch (
T->getUTTKind()) {
4696#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4697 case UnaryTransformType::Enum: \
4698 BuiltinName = "__" #Trait; \
4700#include "clang/Basic/BuiltinTraits.inc"
4702 mangleVendorType(BuiltinName);
4706 mangleType(
T->getBaseType());
4710void CXXNameMangler::mangleType(
const AutoType *
T) {
4711 assert(
T->getDeducedType().isNull() &&
4712 "Deduced AutoType shouldn't be handled here!");
4713 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4714 "shouldn't need to mangle __auto_type!");
4719 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4720 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4721 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4722 T->getTypeConstraintArguments());
4724 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4728void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *
T) {
4729 QualType
Deduced =
T->getDeducedType();
4735 "shouldn't form deduced TST unless we know we have a template");
4739void CXXNameMangler::mangleType(
const AtomicType *
T) {
4743 mangleType(
T->getValueType());
4746void CXXNameMangler::mangleType(
const PipeType *
T) {
4753void CXXNameMangler::mangleType(
const OverflowBehaviorType *
T) {
4756 if (
T->isWrapKind()) {
4757 Out <<
"U8ObtWrap_";
4759 Out <<
"U8ObtTrap_";
4761 mangleType(
T->getUnderlyingType());
4764void CXXNameMangler::mangleType(
const BitIntType *
T) {
4768 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4771void CXXNameMangler::mangleType(
const DependentBitIntType *
T) {
4775 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4776 mangleExpression(
T->getNumBitsExpr());
4780void CXXNameMangler::mangleType(
const ArrayParameterType *
T) {
4784void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *
T) {
4785 llvm::SmallString<64> Str(
"_Res");
4786 const HLSLAttributedResourceType::Attributes &Attrs =
T->getAttrs();
4788 switch (Attrs.ResourceClass) {
4789 case llvm::dxil::ResourceClass::UAV:
4792 case llvm::dxil::ResourceClass::SRV:
4795 case llvm::dxil::ResourceClass::CBuffer:
4798 case llvm::dxil::ResourceClass::Sampler:
4804 if (Attrs.RawBuffer)
4806 if (Attrs.IsCounter)
4810 if (Attrs.isMultiSampled())
4812 if (
T->hasContainedType())
4814 mangleVendorQualifier(Str);
4816 if (
T->hasContainedType()) {
4817 mangleType(
T->getContainedType());
4819 mangleType(
T->getWrappedType());
4822void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *
T) {
4823 SmallString<20> TypeNameStr;
4824 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4826 TypeNameOS <<
"spirv_type";
4828 TypeNameOS <<
"_" <<
T->getOpcode();
4829 TypeNameOS <<
"_" <<
T->getSize();
4830 TypeNameOS <<
"_" <<
T->getAlignment();
4832 mangleVendorType(TypeNameStr);
4834 for (
auto &Operand :
T->getOperands()) {
4835 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4838 case SpirvOperandKind::ConstantId:
4839 mangleVendorQualifier(
"_Const");
4840 mangleIntegerLiteral(
Operand.getResultType(),
4841 llvm::APSInt(
Operand.getValue()));
4843 case SpirvOperandKind::Literal:
4844 mangleVendorQualifier(
"_Lit");
4845 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4846 llvm::APSInt(
Operand.getValue()));
4848 case SpirvOperandKind::TypeId:
4849 mangleVendorQualifier(
"_Type");
4850 mangleType(
Operand.getResultType());
4853 llvm_unreachable(
"Invalid SpirvOperand kind");
4856 TypeNameOS <<
Operand.getKind();
4860void CXXNameMangler::mangleIntegerLiteral(QualType
T,
4861 const llvm::APSInt &
Value) {
4868 Out << (
Value.getBoolValue() ?
'1' :
'0');
4870 mangleNumber(
Value);
4875void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4877 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4878 if (!RT->getDecl()->isAnonymousStructOrUnion())
4880 const auto *ME = dyn_cast<MemberExpr>(Base);
4883 Base = ME->getBase();
4884 IsArrow = ME->isArrow();
4887 if (
Base->isImplicitCXXThis()) {
4893 Out << (IsArrow ?
"pt" :
"dt");
4894 mangleExpression(Base);
4899void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4900 NestedNameSpecifier Qualifier,
4901 NamedDecl *firstQualifierLookup,
4902 DeclarationName member,
4903 const TemplateArgumentLoc *TemplateArgs,
4904 unsigned NumTemplateArgs,
4909 mangleMemberExprBase(base, isArrow);
4910 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4923 if (callee == fn)
return false;
4927 if (!lookup)
return false;
4944void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4946 Out << CastEncoding;
4948 if (
const auto *PLIE = dyn_cast<CXXParenListInitExpr>(ECE->
getSubExpr())) {
4949 ArrayRef<Expr *>
Inits = PLIE->getUserSpecifiedInitExprs();
4950 assert(
Inits.size() == 1 &&
"cast must have exactly one operand");
4951 mangleExpression(
Inits.front());
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 auto *PLE = dyn_cast<CXXParenListInitExpr>(
Init)) {
5354 for (
const Expr *Arg : PLE->getUserSpecifiedInitExprs())
5355 mangleExpression(Arg);
5356 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5357 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5358 mangleExpression(PLE->getExpr(i));
5359 }
else if (
New->getInitializationStyle() ==
5360 CXXNewInitializationStyle::Braces &&
5365 mangleExpression(
Init);
5371 case Expr::CXXPseudoDestructorExprClass: {
5374 if (
const Expr *Base = PDE->getBase())
5375 mangleMemberExprBase(Base, PDE->isArrow());
5376 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5377 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5379 mangleUnresolvedPrefix(Qualifier,
5381 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5385 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5388 }
else if (Qualifier) {
5389 mangleUnresolvedPrefix(Qualifier);
5393 QualType DestroyedType = PDE->getDestroyedType();
5394 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5398 case Expr::MemberExprClass: {
5409 case Expr::UnresolvedMemberExprClass: {
5420 case Expr::CXXDependentScopeMemberExprClass: {
5422 const CXXDependentScopeMemberExpr *ME
5433 case Expr::UnresolvedLookupExprClass: {
5442 case Expr::DependentTemplateIdExprClass: {
5445 if (DTI->getTemplateName().getAsPackIndexingTemplate()) {
5446 DiagnoseUnsupportedPackIndexTemplateName();
5449 mangleUnresolvedName(std::nullopt, DTI->getName(),
5450 DTI->template_arguments().data(),
5451 DTI->getNumTemplateArgs(), Arity);
5455 case Expr::CXXUnresolvedConstructExprClass: {
5461 assert(N == 1 &&
"unexpected form for list initialization");
5465 mangleInitListElements(IL);
5472 if (N != 1)
Out <<
'_';
5473 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5474 if (N != 1)
Out <<
'E';
5478 case Expr::CXXConstructExprClass: {
5485 "implicit CXXConstructExpr must have one argument");
5492 mangleExpression(E);
5497 case Expr::CXXTemporaryObjectExprClass: {
5508 if (!List && N != 1)
5510 if (CE->isStdInitListInitialization()) {
5517 mangleInitListElements(ILE);
5520 mangleExpression(E);
5527 case Expr::CXXScalarValueInitExprClass:
5534 case Expr::CXXNoexceptExprClass:
5540 case Expr::UnaryExprOrTypeTraitExprClass: {
5557 QualType
T = (ImplicitlyConvertedToType.
isNull() ||
5559 : ImplicitlyConvertedToType;
5561 mangleIntegerLiteral(
T,
V);
5567 auto MangleAlignofSizeofArg = [&] {
5577 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5578 StringRef Name = {}) {
5581 mangleVendorType(Name);
5592 MangleAlignofSizeofArg();
5594 case UETT_PreferredAlignOf:
5598 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5599 MangleExtensionBuiltin(SAE,
"__alignof__");
5605 MangleAlignofSizeofArg();
5609 case UETT_VectorElements:
5610 case UETT_OpenMPRequiredSimdAlign:
5612 case UETT_PtrAuthTypeDiscriminator:
5613 case UETT_DataSizeOf: {
5614 DiagnosticsEngine &Diags = Context.getDiags();
5623 case Expr::TypeTraitExprClass: {
5628 mangleVendorType(Spelling);
5629 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5630 mangleType(TSI->getType());
5636 case Expr::CXXThrowExprClass: {
5650 case Expr::CXXTypeidExprClass: {
5665 case Expr::CXXDeleteExprClass: {
5676 case Expr::UnaryOperatorClass: {
5685 case Expr::ArraySubscriptExprClass: {
5692 mangleExpression(AE->
getLHS());
5693 mangleExpression(AE->
getRHS());
5697 case Expr::MatrixSingleSubscriptExprClass: {
5701 mangleExpression(ME->
getBase());
5706 case Expr::MatrixSubscriptExprClass: {
5710 mangleExpression(ME->
getBase());
5716 case Expr::CompoundAssignOperatorClass:
5717 case Expr::BinaryOperatorClass: {
5725 mangleExpression(BO->
getLHS());
5726 mangleExpression(BO->
getRHS());
5730 case Expr::CXXRewrittenBinaryOperatorClass: {
5733 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5737 mangleExpression(Decomposed.
LHS);
5738 mangleExpression(Decomposed.
RHS);
5742 case Expr::ConditionalOperatorClass: {
5745 mangleOperatorName(OO_Conditional, 3);
5746 mangleExpression(CO->
getCond());
5747 mangleExpression(CO->
getLHS(), Arity);
5748 mangleExpression(CO->
getRHS(), Arity);
5752 case Expr::ImplicitCastExprClass: {
5753 ImplicitlyConvertedToType = E->
getType();
5758 case Expr::ObjCBridgedCastExprClass: {
5764 mangleCastExpression(E,
"cv");
5768 case Expr::CStyleCastExprClass:
5770 mangleCastExpression(E,
"cv");
5773 case Expr::CXXFunctionalCastExprClass: {
5777 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5778 if (CCE->getParenOrBraceRange().isInvalid())
5779 Sub = CCE->getArg(0)->IgnoreImplicit();
5780 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5781 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5782 if (
auto *PLIE = dyn_cast<CXXParenListInitExpr>(Sub)) {
5783 ArrayRef<Expr *>
Inits = PLIE->getUserSpecifiedInitExprs();
5786 if (
Inits.size() != 1)
5789 mangleExpression(
Init);
5790 if (
Inits.size() != 1)
5792 }
else if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5795 mangleInitListElements(IL);
5798 mangleCastExpression(E,
"cv");
5803 case Expr::CXXStaticCastExprClass:
5805 mangleCastExpression(E,
"sc");
5807 case Expr::CXXDynamicCastExprClass:
5809 mangleCastExpression(E,
"dc");
5811 case Expr::CXXReinterpretCastExprClass:
5813 mangleCastExpression(E,
"rc");
5815 case Expr::CXXConstCastExprClass:
5817 mangleCastExpression(E,
"cc");
5819 case Expr::CXXAddrspaceCastExprClass:
5821 mangleCastExpression(E,
"ac");
5824 case Expr::CXXOperatorCallExprClass: {
5833 for (
unsigned i = 0; i != NumArgs; ++i)
5834 mangleExpression(CE->
getArg(i));
5838 case Expr::ParenExprClass:
5842 case Expr::ConceptSpecializationExprClass: {
5844 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5849 mangleTemplateName(CSE->getConceptDecl(), CSE->getTemplateArguments());
5855 mangleUnresolvedName(
5856 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5857 CSE->getConceptNameInfo().getName(),
5858 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5859 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5863 case Expr::RequiresExprClass: {
5869 if (RE->getLParenLoc().isValid()) {
5871 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5872 if (RE->getLocalParameters().empty()) {
5875 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5883 FunctionTypeDepth.enterFunctionDeclSuffix();
5884 for (
const concepts::Requirement *Req : RE->getRequirements())
5885 mangleRequirement(RE->getExprLoc(), Req);
5886 FunctionTypeDepth.pop(saved);
5890 for (
const concepts::Requirement *Req : RE->getRequirements())
5891 mangleRequirement(RE->getExprLoc(), Req);
5897 case Expr::DeclRefExprClass:
5902 case Expr::SubstNonTypeTemplateParmPackExprClass:
5908 Out <<
"_SUBSTPACK_";
5911 case Expr::FunctionParmPackExprClass: {
5915 Out <<
"v110_SUBSTPACK";
5920 case Expr::DependentScopeDeclRefExprClass: {
5929 case Expr::CXXBindTemporaryExprClass:
5933 case Expr::ExprWithCleanupsClass:
5937 case Expr::FloatingLiteralClass: {
5944 case Expr::FixedPointLiteralClass:
5946 mangleFixedPointLiteral();
5949 case Expr::CharacterLiteralClass:
5953 Out << cast<CharacterLiteral>(E)->getValue();
5958 case Expr::ObjCBoolLiteralExprClass:
5961 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5965 case Expr::CXXBoolLiteralExprClass:
5968 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5972 case Expr::IntegerLiteralClass: {
5976 Value.setIsSigned(
true);
5981 case Expr::ImaginaryLiteralClass: {
5988 if (
const FloatingLiteral *Imag =
5989 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5991 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5993 mangleFloat(Imag->getValue());
5998 Value.setIsSigned(
true);
5999 mangleNumber(
Value);
6005 case Expr::StringLiteralClass: {
6015 case Expr::GNUNullExprClass:
6018 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
6021 case Expr::CXXNullPtrLiteralExprClass: {
6027 case Expr::LambdaExprClass: {
6038 case Expr::PackExpansionExprClass:
6044 case Expr::SizeOfPackExprClass: {
6047 if (SPE->isPartiallySubstituted()) {
6049 for (
const auto &A : SPE->getPartialArguments())
6050 mangleTemplateArg(A,
false);
6056 mangleReferenceToPack(SPE->getPack());
6060 case Expr::MaterializeTemporaryExprClass:
6064 case Expr::CXXFoldExprClass: {
6067 if (FE->isLeftFold())
6068 Out << (FE->getInit() ?
"fL" :
"fl");
6070 Out << (FE->getInit() ?
"fR" :
"fr");
6072 if (FE->getOperator() == BO_PtrMemD)
6080 mangleExpression(FE->getLHS());
6082 mangleExpression(FE->getRHS());
6086 case Expr::PackIndexingExprClass: {
6090 mangleReferenceToPack(PE->getPackDecl());
6091 mangleExpression(PE->getIndexExpr());
6095 case Expr::CXXThisExprClass:
6100 case Expr::CoawaitExprClass:
6103 Out <<
"v18co_await";
6107 case Expr::DependentCoawaitExprClass:
6110 Out <<
"v18co_await";
6114 case Expr::CoyieldExprClass:
6117 Out <<
"v18co_yield";
6120 case Expr::SYCLUniqueStableNameExprClass: {
6124 Out <<
"u33__builtin_sycl_unique_stable_name";
6125 mangleType(USN->getTypeSourceInfo()->getType());
6130 case Expr::HLSLOutArgExprClass:
6132 "cannot mangle hlsl temporary value; mangling wrong thing?");
6133 case Expr::OpenACCAsteriskSizeExprClass: {
6135 DiagnosticsEngine &Diags = Context.getDiags();
6136 Diags.
Report(diag::err_unsupported_itanium_mangling)
6137 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
6142 if (AsTemplateArg && !IsPrimaryExpr)
6174void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6179 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6180 nestingDepth == 0) {
6183 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6191 &&
"parameter's type is still an array type?");
6193 if (
const DependentAddressSpaceType *DAST =
6194 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6201 if (parmIndex != 0) {
6202 Out << (parmIndex - 1);
6208 const CXXRecordDecl *InheritedFrom) {
6235 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6238 mangleName(InheritedFrom);
6266 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6270void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6271 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6272 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6273 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6274 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6275 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6276 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6310 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6311 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6312 if (!RD || !RD->isGenericLambda())
6328 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6329 return TTP->hasTypeConstraint();
6346 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6347 return NTTP->getType()->isInstantiationDependentType() ||
6348 NTTP->getType()->getContainedDeducedType();
6355 "A DeducedTemplateName shouldn't escape partial ordering");
6366 auto MangleTemplateParamListToString =
6368 unsigned DepthOffset) {
6369 llvm::raw_svector_ostream Stream(Buffer);
6370 CXXNameMangler(
Mangler.Context, Stream,
6371 WithTemplateDepthOffset{DepthOffset})
6372 .mangleTemplateParameterList(Params);
6375 MangleTemplateParamListToString(ParamTemplateHead,
6376 TTP->getTemplateParameters(), 0);
6380 MangleTemplateParamListToString(ArgTemplateHead,
6382 TTP->getTemplateParameters()->
getDepth());
6383 return ParamTemplateHead != ArgTemplateHead;
6393 return {
true,
nullptr};
6398 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6399 "no parameter for argument");
6420 return {
true,
nullptr};
6435 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6436 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6437 return {NeedExactType,
nullptr};
6449void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6451 unsigned NumTemplateArgs) {
6454 TemplateArgManglingInfo Info(*
this, TN);
6455 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6456 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6458 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6462void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6463 const TemplateArgumentList &AL) {
6466 TemplateArgManglingInfo Info(*
this, TN);
6467 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6468 mangleTemplateArg(Info, i, AL[i]);
6470 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6474void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6475 ArrayRef<TemplateArgument> Args) {
6478 TemplateArgManglingInfo Info(*
this, TN);
6479 for (
unsigned i = 0; i != Args.size(); ++i) {
6480 mangleTemplateArg(Info, i, Args[i]);
6482 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6486void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6487 unsigned Index, TemplateArgument A) {
6488 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6491 if (ArgInfo.TemplateParameterToMangle &&
6492 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6499 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6502 mangleTemplateArg(A, ArgInfo.NeedExactType);
6505void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6515 llvm_unreachable(
"Cannot mangle NULL template argument");
6543 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6544 TPO->getValue(),
true,
6549 ASTContext &Ctx = Context.getASTContext();
6557 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6565 ArrayRef<APValue::LValuePathEntry>(),
6578 true, NeedExactType);
6584 mangleTemplateArg(P, NeedExactType);
6590void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6591 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6592 mangleExpression(E, UnknownArity,
true);
6607 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6608 const ValueDecl *D = DRE->getDecl();
6617 mangleExpression(E);
6630 switch (
V.getKind()) {
6638 assert(RD &&
"unexpected type for record value");
6647 if (!FD->isUnnamedBitField() &&
6657 assert(RD &&
"unexpected type for union value");
6660 if (!FD->isUnnamedBitField())
6670 QualType ElemT(
T->getArrayElementTypeNoTypeQual(), 0);
6671 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6679 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6686 llvm_unreachable(
"Matrix APValues not yet supported");
6692 return V.getFloat().isPosZero();
6695 return !
V.getFixedPoint().getValue();
6698 return V.getComplexFloatReal().isPosZero() &&
6699 V.getComplexFloatImag().isPosZero();
6702 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6705 return V.isNullPointer();
6708 return !
V.getMemberPointerDecl();
6711 return !
V.getReflectionOpaqueOperand();
6714 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6721 T = AT->getElementType();
6723 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6766 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6767 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6772void CXXNameMangler::mangleValueInTemplateArg(QualType
T,
const APValue &
V,
6774 bool NeedExactType) {
6777 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6780 bool IsPrimaryExpr =
true;
6781 auto NotPrimaryExpr = [&] {
6782 if (TopLevel && IsPrimaryExpr)
6784 IsPrimaryExpr =
false;
6788 switch (
V.getKind()) {
6797 llvm_unreachable(
"unexpected value kind in template argument");
6801 assert(RD &&
"unexpected type for record value");
6804 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6807 (Fields.back()->isUnnamedBitField() ||
6809 V.getStructField(Fields.back()->getFieldIndex())))) {
6813 if (Fields.empty()) {
6814 while (!Bases.empty() &&
6816 V.getStructBase(Bases.size() - 1)))
6817 Bases = Bases.drop_back();
6824 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6825 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6826 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6827 if (Fields[I]->isUnnamedBitField())
6829 mangleValueInTemplateArg(Fields[I]->
getType(),
6830 V.getStructField(Fields[I]->getFieldIndex()),
6839 const FieldDecl *FD =
V.getUnionField();
6857 mangleSourceName(II);
6858 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6872 unsigned N =
V.getArraySize();
6874 N =
V.getArrayInitializedElts();
6879 for (
unsigned I = 0; I != N; ++I) {
6880 const APValue &Elem = I <
V.getArrayInitializedElts()
6881 ?
V.getArrayInitializedElt(I)
6882 :
V.getArrayFiller();
6883 mangleValueInTemplateArg(ElemT, Elem,
false);
6890 const VectorType *VT =
T->
castAs<VectorType>();
6895 unsigned N =
V.getVectorLength();
6898 for (
unsigned I = 0; I != N; ++I)
6899 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6905 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6908 mangleIntegerLiteral(
T,
V.getInt());
6912 mangleFloatLiteral(
T,
V.getFloat());
6916 mangleFixedPointLiteral();
6920 const ComplexType *CT =
T->
castAs<ComplexType>();
6924 if (!
V.getComplexFloatReal().isPosZero() ||
6925 !
V.getComplexFloatImag().isPosZero())
6927 if (!
V.getComplexFloatImag().isPosZero())
6934 const ComplexType *CT =
T->
castAs<ComplexType>();
6938 if (
V.getComplexIntReal().getBoolValue() ||
6939 V.getComplexIntImag().getBoolValue())
6941 if (
V.getComplexIntImag().getBoolValue())
6950 "unexpected type for LValue template arg");
6952 if (
V.isNullPointer()) {
6953 mangleNullPointer(
T);
6957 APValue::LValueBase B =
V.getLValueBase();
6961 CharUnits Offset =
V.getLValueOffset();
6979 ASTContext &Ctx = Context.getASTContext();
6982 if (!
V.hasLValuePath()) {
6998 bool IsArrayToPointerDecayMangledAsDecl =
false;
6999 if (TopLevel && isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7001 IsArrayToPointerDecayMangledAsDecl =
7002 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
7003 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
7007 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
7008 !IsArrayToPointerDecayMangledAsDecl) {
7025 if (NeedExactType &&
7027 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7040 QualType TypeSoFar = B.
getType();
7041 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
7045 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
7047 mangleExpression(E);
7048 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
7051 mangleType(QualType(TI.getType(), 0));
7054 llvm_unreachable(
"unexpected lvalue base kind in template argument");
7064 mangleNumber(
V.getLValueOffset().getQuantity());
7071 if (!
V.getLValueOffset().isZero())
7072 mangleNumber(
V.getLValueOffset().getQuantity());
7076 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
7078 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
7080 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
7081 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
7082 TypeSoFar = AT->getElementType();
7084 const Decl *D = E.getAsBaseOrMember().getPointer();
7085 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
7109 mangleReflection(
V.getReflectionOperandKind(),
7110 V.getReflectionOpaqueOperand());
7116 if (!
V.getMemberPointerDecl()) {
7117 mangleNullPointer(
T);
7121 ASTContext &Ctx = Context.getASTContext();
7124 if (!
V.getMemberPointerPath().empty()) {
7127 }
else if (NeedExactType &&
7129 T->
castAs<MemberPointerType>()->getPointeeType(),
7130 V.getMemberPointerDecl()->getType()) &&
7131 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
7136 mangle(
V.getMemberPointerDecl());
7138 if (!
V.getMemberPointerPath().empty()) {
7148 if (TopLevel && !IsPrimaryExpr)
7152void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
7162 Depth += TemplateDepthOffset;
7164 Out <<
'L' << (Depth - 1) <<
'_';
7170void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
7173 }
else if (SeqID == 1) {
7180 MutableArrayRef<char> BufferRef(Buffer);
7181 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7183 for (; SeqID != 0; SeqID /= 36) {
7184 unsigned C = SeqID % 36;
7185 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7188 Out.write(I.base(), I - BufferRef.rbegin());
7193void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7194 bool result = mangleSubstitution(tname);
7195 assert(result &&
"no existing substitution for template name");
7201bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7203 if (mangleStandardSubstitution(ND))
7207 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7217bool CXXNameMangler::mangleSubstitution(QualType
T) {
7220 return mangleSubstitution(RD);
7225 return mangleSubstitution(TypePtr);
7229 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7230 return mangleSubstitution(TD);
7233 return mangleSubstitution(
7237bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7238 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7239 if (I == Substitutions.end())
7242 unsigned SeqID = I->second;
7251bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7260 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7261 if (!SD || !SD->getIdentifier()->isStr(Name))
7264 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7267 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7268 if (TemplateArgs.
size() != 1)
7271 if (TemplateArgs[0].getAsType() != A)
7274 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7283bool CXXNameMangler::isStdCharSpecialization(
7284 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7285 bool HasAllocator) {
7290 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7293 QualType A = TemplateArgs[0].getAsType();
7301 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7305 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7314bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7316 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7324 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7325 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7345 if (
const ClassTemplateSpecializationDecl *SD =
7346 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7347 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7356 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7363 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7370 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7377 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7387void CXXNameMangler::addSubstitution(QualType
T) {
7390 addSubstitution(RD);
7396 addSubstitution(TypePtr);
7400 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7401 return addSubstitution(TD);
7407void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7408 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7409 Substitutions[
Ptr] = SeqID++;
7412void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7413 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7414 if (
Other->SeqID > SeqID) {
7415 Substitutions.swap(
Other->Substitutions);
7416 SeqID =
Other->SeqID;
7420CXXNameMangler::AbiTagList
7421CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7423 if (DisableDerivedAbiTags)
7424 return AbiTagList();
7426 llvm::raw_null_ostream NullOutStream;
7427 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7428 TrackReturnTypeTags.disableDerivedAbiTags();
7430 const FunctionProtoType *Proto =
7432 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7433 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7435 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7436 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7438 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7441CXXNameMangler::AbiTagList
7442CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7444 if (DisableDerivedAbiTags)
7445 return AbiTagList();
7447 llvm::raw_null_ostream NullOutStream;
7448 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7449 TrackVariableType.disableDerivedAbiTags();
7451 TrackVariableType.mangleType(VD->
getType());
7453 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7456bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7457 const VarDecl *VD) {
7458 llvm::raw_null_ostream NullOutStream;
7459 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7460 TrackAbiTags.mangle(VD);
7461 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7466void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7470 "Invalid mangleName() call, argument is not a variable or function!");
7472 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7473 getASTContext().getSourceManager(),
7474 "Mangling declaration");
7476 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7478 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7479 return Mangler.mangle(GlobalDecl(CD,
Type));
7482 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7484 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7485 return Mangler.mangle(GlobalDecl(DD,
Type));
7488 CXXNameMangler Mangler(*
this, Out, D);
7492void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7494 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7498void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7500 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7522 auto &LangOpts = Context.getLangOpts();
7525 Context.baseForVTableAuthentication(ThisRD);
7526 unsigned TypedDiscriminator =
7527 Context.getPointerAuthVTablePointerDiscriminator(ThisRD,
7529 Mangler.mangleVendorQualifier(
"__vtptrauth");
7530 auto &ManglerStream = Mangler.getStream();
7531 ManglerStream <<
"I";
7532 if (
const auto *ExplicitAuth =
7533 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7534 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7536 if (ExplicitAuth->getAddressDiscrimination() ==
7537 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7538 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7540 ManglerStream <<
"Lb"
7541 << (ExplicitAuth->getAddressDiscrimination() ==
7542 VTablePointerAuthenticationAttr::AddressDiscrimination);
7544 switch (ExplicitAuth->getExtraDiscrimination()) {
7545 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7546 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7547 ManglerStream <<
"Lj" << TypedDiscriminator;
7549 ManglerStream <<
"Lj" << 0;
7552 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7553 ManglerStream <<
"Lj" << TypedDiscriminator;
7555 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7556 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7558 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7559 ManglerStream <<
"Lj" << 0;
7563 ManglerStream <<
"Lj"
7564 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7565 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7566 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7567 ManglerStream <<
"Lj" << TypedDiscriminator;
7569 ManglerStream <<
"Lj" << 0;
7571 ManglerStream <<
"E";
7574void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7575 const ThunkInfo &Thunk,
7576 bool ElideOverrideInfo,
7586 "Use mangleCXXDtor for destructor decls!");
7587 CXXNameMangler Mangler(*
this, Out);
7588 Mangler.getStream() <<
"_ZT";
7590 Mangler.getStream() <<
'c';
7601 Mangler.mangleFunctionEncoding(MD);
7602 if (!ElideOverrideInfo)
7606void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7608 const ThunkInfo &Thunk,
7609 bool ElideOverrideInfo,
7613 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7614 Mangler.getStream() <<
"_ZT";
7616 auto &ThisAdjustment = Thunk.
This;
7618 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7619 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7621 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7622 if (!ElideOverrideInfo)
7627void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7631 CXXNameMangler Mangler(*
this, Out);
7634 Mangler.getStream() <<
"_ZGV";
7635 Mangler.mangleName(D);
7638void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7643 Out <<
"__cxx_global_var_init";
7646void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7649 CXXNameMangler Mangler(*
this, Out);
7650 Mangler.getStream() <<
"__dtor_";
7651 if (shouldMangleDeclName(D))
7654 Mangler.getStream() << D->
getName();
7657void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7661 CXXNameMangler Mangler(*
this, Out);
7662 Mangler.getStream() <<
"__finalize_";
7663 if (shouldMangleDeclName(D))
7666 Mangler.getStream() << D->
getName();
7669void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7670 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7671 CXXNameMangler Mangler(*
this, Out);
7672 Mangler.getStream() <<
"__filt_";
7674 if (shouldMangleDeclName(EnclosingFD))
7675 Mangler.mangle(EnclosingDecl);
7677 Mangler.getStream() << EnclosingFD->getName();
7680void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7681 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7682 CXXNameMangler Mangler(*
this, Out);
7683 Mangler.getStream() <<
"__fin_";
7685 if (shouldMangleDeclName(EnclosingFD))
7686 Mangler.mangle(EnclosingDecl);
7688 Mangler.getStream() << EnclosingFD->getName();
7691void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7694 CXXNameMangler Mangler(*
this, Out);
7695 Mangler.getStream() <<
"_ZTH";
7696 Mangler.mangleName(D);
7700ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7703 CXXNameMangler Mangler(*
this, Out);
7704 Mangler.getStream() <<
"_ZTW";
7705 Mangler.mangleName(D);
7708void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7709 unsigned ManglingNumber,
7713 CXXNameMangler Mangler(*
this, Out);
7714 Mangler.getStream() <<
"_ZGR";
7715 Mangler.mangleName(D);
7716 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7717 Mangler.mangleSeqID(ManglingNumber - 1);
7720void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7723 CXXNameMangler Mangler(*
this, Out);
7724 Mangler.getStream() <<
"_ZTV";
7725 Mangler.mangleCXXRecordDecl(RD);
7728void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7731 CXXNameMangler Mangler(*
this, Out);
7732 Mangler.getStream() <<
"_ZTT";
7733 Mangler.mangleCXXRecordDecl(RD);
7736void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7738 const CXXRecordDecl *
Type,
7741 CXXNameMangler Mangler(*
this, Out);
7742 Mangler.getStream() <<
"_ZTC";
7745 bool SuppressSubstitution = getASTContext().getLangOpts().isCompatibleWith(
7746 LangOptions::ClangABI::Ver19);
7747 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7748 Mangler.getStream() << Offset;
7749 Mangler.getStream() <<
'_';
7750 Mangler.mangleCXXRecordDecl(
Type);
7753void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7755 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7756 CXXNameMangler Mangler(*
this, Out);
7757 Mangler.getStream() <<
"_ZTI";
7758 Mangler.mangleType(Ty);
7761void ItaniumMangleContextImpl::mangleCXXRTTIName(
7762 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7764 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7765 Mangler.getStream() <<
"_ZTS";
7766 Mangler.mangleType(Ty);
7769void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7770 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7771 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7774void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7775 llvm_unreachable(
"Can't mangle string literals");
7778void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7780 CXXNameMangler Mangler(*
this, Out);
7781 Mangler.mangleLambdaSig(Lambda);
7784void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7787 CXXNameMangler Mangler(*
this, Out);
7788 Mangler.getStream() <<
"_ZGI";
7792 auto Partition = M->
Name.find(
':');
7793 Mangler.mangleModuleNamePrefix(
7794 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7802 return new ItaniumMangleContextImpl(
7805 return std::nullopt;
7814 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.