35#include "llvm/ADT/StringExtras.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#include "llvm/TargetParser/RISCVTargetParser.h"
42namespace UnsupportedItaniumManglingKind =
43 clang::diag::UnsupportedItaniumManglingKind;
47static bool isLocalContainerContext(
const DeclContext *DC) {
51static const FunctionDecl *getStructor(
const FunctionDecl *fn) {
53 return ftd->getTemplatedDecl();
58static const NamedDecl *getStructor(
const NamedDecl *
decl) {
59 const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(
decl);
60 return (fn ? getStructor(fn) :
decl);
63static bool isLambda(
const NamedDecl *ND) {
64 const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(ND);
71static const unsigned UnknownArity = ~0U;
73class ItaniumMangleContextImpl :
public ItaniumMangleContext {
74 using DiscriminatorKeyTy = std::pair<const DeclContext *, IdentifierInfo *>;
75 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
76 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
77 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
78 NamespaceDecl *StdNamespace =
nullptr;
80 bool NeedsUniqueInternalLinkageNames =
false;
83 explicit ItaniumMangleContextImpl(
84 ASTContext &Context, DiagnosticsEngine &Diags,
85 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 : ItaniumMangleContext(Context, Diags, IsAux),
87 DiscriminatorOverride(DiscriminatorOverride) {}
92 bool shouldMangleCXXName(
const NamedDecl *D)
override;
93 bool shouldMangleStringLiteral(
const StringLiteral *)
override {
98 void needsUniqueInternalLinkageNames()
override {
99 NeedsUniqueInternalLinkageNames =
true;
102 void mangleCXXName(GlobalDecl GD, raw_ostream &)
override;
103 void mangleThunk(
const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
bool,
104 raw_ostream &)
override;
106 const ThunkInfo &Thunk,
bool, raw_ostream &)
override;
107 void mangleReferenceTemporary(
const VarDecl *D,
unsigned ManglingNumber,
108 raw_ostream &)
override;
109 void mangleCXXVTable(
const CXXRecordDecl *RD, raw_ostream &)
override;
110 void mangleCXXVTT(
const CXXRecordDecl *RD, raw_ostream &)
override;
111 void mangleCXXCtorVTable(
const CXXRecordDecl *RD, int64_t Offset,
112 const CXXRecordDecl *
Type, raw_ostream &)
override;
113 void mangleCXXRTTI(QualType T, raw_ostream &)
override;
114 void mangleCXXRTTIName(QualType T, raw_ostream &,
115 bool NormalizeIntegers)
override;
116 void mangleCanonicalTypeName(QualType T, raw_ostream &,
117 bool NormalizeIntegers)
override;
119 void mangleCXXCtorComdat(
const CXXConstructorDecl *D, raw_ostream &)
override;
120 void mangleCXXDtorComdat(
const CXXDestructorDecl *D, raw_ostream &)
override;
121 void mangleStaticGuardVariable(
const VarDecl *D, raw_ostream &)
override;
122 void mangleDynamicInitializer(
const VarDecl *D, raw_ostream &Out)
override;
123 void mangleDynamicAtExitDestructor(
const VarDecl *D,
124 raw_ostream &Out)
override;
125 void mangleDynamicStermFinalizer(
const VarDecl *D, raw_ostream &Out)
override;
126 void mangleSEHFilterExpression(GlobalDecl EnclosingDecl,
127 raw_ostream &Out)
override;
128 void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl,
129 raw_ostream &Out)
override;
130 void mangleItaniumThreadLocalInit(
const VarDecl *D, raw_ostream &)
override;
131 void mangleItaniumThreadLocalWrapper(
const VarDecl *D,
132 raw_ostream &)
override;
134 void mangleStringLiteral(
const StringLiteral *, raw_ostream &)
override;
136 void mangleLambdaSig(
const CXXRecordDecl *Lambda, raw_ostream &)
override;
138 void mangleModuleInitializer(
const Module *
Module, raw_ostream &)
override;
140 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
146 if (
const auto *Tag = dyn_cast<TagDecl>(ND);
147 Tag &&
Tag->getName().empty() && !
Tag->getTypedefNameForAnonDecl())
152 unsigned discriminator = getASTContext().getManglingNumber(ND, isAux());
153 if (discriminator == 1)
155 disc = discriminator - 2;
160 unsigned &discriminator = Uniquifier[ND];
161 if (!discriminator) {
162 const DeclContext *DC = getEffectiveDeclContext(ND);
163 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
165 if (discriminator == 1)
167 disc = discriminator-2;
171 std::string getLambdaString(
const CXXRecordDecl *Lambda)
override {
174 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
175 std::string Name(
"<lambda");
179 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
180 const FunctionDecl *
Func =
184 unsigned DefaultArgNo =
186 Name += llvm::utostr(DefaultArgNo);
190 if (LambdaManglingNumber)
191 LambdaId = LambdaManglingNumber;
193 LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
195 Name += llvm::utostr(LambdaId);
200 DiscriminatorOverrideTy getDiscriminatorOverride()
const override {
201 return DiscriminatorOverride;
204 NamespaceDecl *getStdNamespace();
206 const DeclContext *getEffectiveDeclContext(
const Decl *D);
207 const DeclContext *getEffectiveParentContext(
const DeclContext *DC) {
208 return getEffectiveDeclContext(
cast<Decl>(DC));
211 bool isInternalLinkageDecl(
const NamedDecl *ND);
217class CXXNameMangler {
218 ItaniumMangleContextImpl &Context;
222 bool NormalizeIntegers =
false;
224 bool NullOut =
false;
229 bool DisableDerivedAbiTags =
false;
234 const NamedDecl *Structor;
235 unsigned StructorType = 0;
240 unsigned TemplateDepthOffset = 0;
245 class FunctionTypeDepthState {
247 unsigned InFunctionDeclSuffix : 1;
250 FunctionTypeDepthState() : Depth(0), InFunctionDeclSuffix(0) {}
252 unsigned getNestingDepth(
unsigned ParmDepth)
const {
255 assert(ParmDepth < Depth &&
256 "ParmVarDecl is not visible in current parameter environment");
257 return Depth - ParmDepth - InFunctionDeclSuffix;
260 FunctionTypeDepthState push() {
261 FunctionTypeDepthState Saved = *
this;
263 InFunctionDeclSuffix = 0;
267 void pop(FunctionTypeDepthState Saved) {
268 assert(Depth == Saved.Depth + 1 &&
"unbalanced function type depth pop");
272 void enterFunctionDeclSuffix() { InFunctionDeclSuffix = 1; }
273 void leaveFunctionDeclSuffix() { InFunctionDeclSuffix = 0; }
280 using AbiTagList = SmallVector<StringRef, 4>;
285 class AbiTagState final {
287 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
293 AbiTagState(
const AbiTagState &) =
delete;
294 AbiTagState &operator=(
const AbiTagState &) =
delete;
296 ~AbiTagState() { pop(); }
298 void write(raw_ostream &Out,
const NamedDecl *ND,
299 ArrayRef<StringRef> AdditionalAbiTags) {
303 AdditionalAbiTags.empty() &&
304 "only function and variables need a list of additional abi tags");
305 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
306 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>())
307 llvm::append_range(UsedAbiTags, AbiTag->tags());
314 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
315 llvm::append_range(UsedAbiTags, AbiTag->tags());
316 llvm::append_range(TagList, AbiTag->tags());
319 llvm::append_range(UsedAbiTags, AdditionalAbiTags);
320 llvm::append_range(TagList, AdditionalAbiTags);
323 TagList.erase(llvm::unique(TagList), TagList.end());
325 writeSortedUniqueAbiTags(Out, TagList);
328 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
329 void setUsedAbiTags(
const AbiTagList &AbiTags) {
330 UsedAbiTags = AbiTags;
333 const AbiTagList &getEmittedAbiTags()
const {
334 return EmittedAbiTags;
337 const AbiTagList &getSortedUniqueUsedAbiTags() {
338 llvm::sort(UsedAbiTags);
339 UsedAbiTags.erase(llvm::unique(UsedAbiTags), UsedAbiTags.end());
345 AbiTagList UsedAbiTags;
347 AbiTagList EmittedAbiTags;
349 AbiTagState *&LinkHead;
350 AbiTagState *Parent =
nullptr;
353 assert(LinkHead ==
this &&
354 "abi tag link head must point to us on destruction");
356 Parent->UsedAbiTags.insert(Parent->UsedAbiTags.end(),
357 UsedAbiTags.begin(), UsedAbiTags.end());
358 Parent->EmittedAbiTags.insert(Parent->EmittedAbiTags.end(),
359 EmittedAbiTags.begin(),
360 EmittedAbiTags.end());
365 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
366 for (
const auto &Tag : AbiTags) {
367 EmittedAbiTags.push_back(Tag);
375 AbiTagState *AbiTags =
nullptr;
376 AbiTagState AbiTagsRoot;
378 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
379 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
381 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
383 bool isCompatibleWith(LangOptions::ClangABI Ver) {
384 return Context.getASTContext().
getLangOpts().getClangABICompat() <= Ver;
387 bool isStd(
const NamespaceDecl *NS);
388 bool isStdNamespace(
const DeclContext *DC);
390 const RecordDecl *GetLocalClassDecl(
const Decl *D);
391 bool isSpecializedAs(QualType S, llvm::StringRef Name, QualType A);
392 bool isStdCharSpecialization(
const ClassTemplateSpecializationDecl *SD,
393 llvm::StringRef Name,
bool HasAllocator);
396 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
397 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
398 : Context(
C),
Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
399 AbiTagsRoot(AbiTags) {
404 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
406 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
407 AbiTagsRoot(AbiTags) {}
408 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
410 : Context(
C),
Out(Out_), Structor(getStructor(D)), StructorType(
Type),
411 AbiTagsRoot(AbiTags) {}
413 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
414 bool NormalizeIntegers_)
415 : Context(
C),
Out(Out_), NormalizeIntegers(NormalizeIntegers_),
416 NullOut(
false), Structor(
nullptr), AbiTagsRoot(AbiTags) {}
417 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
418 : Context(Outer.Context),
Out(Out_),
419 NormalizeIntegers(Outer.NormalizeIntegers), Structor(Outer.Structor),
420 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
421 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
422 Substitutions(Outer.Substitutions),
423 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
425 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
426 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
430 struct WithTemplateDepthOffset {
unsigned Offset; };
431 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
432 WithTemplateDepthOffset Offset)
433 : CXXNameMangler(
C,
Out) {
434 TemplateDepthOffset = Offset.Offset;
437 raw_ostream &getStream() {
return Out; }
439 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
440 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
442 void mangle(GlobalDecl GD);
443 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
444 void mangleNumber(
const llvm::APSInt &I);
445 void mangleNumber(int64_t Number);
446 void mangleFloat(
const llvm::APFloat &F);
447 void mangleFunctionEncoding(GlobalDecl GD);
448 void mangleSeqID(
unsigned SeqID);
449 void mangleName(GlobalDecl GD);
450 void mangleType(QualType T);
451 void mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
452 bool SuppressSubstitution =
false);
453 void mangleLambdaSig(
const CXXRecordDecl *Lambda);
454 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
455 void mangleVendorQualifier(StringRef Name);
456 void mangleVendorType(StringRef Name);
459 bool mangleSubstitution(
const NamedDecl *ND);
460 bool mangleSubstitution(QualType T);
466 bool mangleStandardSubstitution(
const NamedDecl *ND);
468 void addSubstitution(
const NamedDecl *ND) {
471 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
473 void addSubstitution(QualType T);
477 void extendSubstitutions(CXXNameMangler*
Other);
479 void mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
480 bool recursive =
false);
481 void mangleUnresolvedName(NestedNameSpecifier Qualifier, DeclarationName name,
482 const TemplateArgumentLoc *TemplateArgs,
483 unsigned NumTemplateArgs,
484 unsigned KnownArity = UnknownArity);
486 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
488 void mangleNameWithAbiTags(GlobalDecl GD,
489 ArrayRef<StringRef> AdditionalAbiTags = {});
490 void mangleModuleName(
const NamedDecl *ND);
491 void mangleTemplateName(
const TemplateDecl *TD,
492 ArrayRef<TemplateArgument> Args);
493 void mangleUnqualifiedName(GlobalDecl GD,
const DeclContext *DC,
494 ArrayRef<StringRef> AdditionalAbiTags = {}) {
496 UnknownArity, AdditionalAbiTags);
498 void mangleUnqualifiedName(GlobalDecl GD, DeclarationName Name,
499 const DeclContext *DC,
unsigned KnownArity,
500 ArrayRef<StringRef> AdditionalAbiTags);
501 void mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
502 ArrayRef<StringRef> AdditionalAbiTags = {});
503 void mangleUnscopedTemplateName(GlobalDecl GD,
const DeclContext *DC,
504 ArrayRef<StringRef> AdditionalAbiTags = {});
505 void mangleSourceName(
const IdentifierInfo *II);
506 void mangleConstructorName(
const CXXConstructorDecl *CCD,
507 ArrayRef<StringRef> AdditionalAbiTags = {});
508 void mangleDestructorName(
const CXXDestructorDecl *CDD,
509 ArrayRef<StringRef> AdditionalAbiTags = {});
510 void mangleRegCallName(
const IdentifierInfo *II);
511 void mangleDeviceStubName(
const IdentifierInfo *II);
512 void mangleOCLDeviceStubName(
const IdentifierInfo *II);
513 void mangleSourceNameWithAbiTags(
const NamedDecl *ND,
514 ArrayRef<StringRef> AdditionalAbiTags = {});
515 void mangleLocalName(GlobalDecl GD,
516 ArrayRef<StringRef> AdditionalAbiTags = {});
517 void mangleBlockForPrefix(
const BlockDecl *
Block);
518 void mangleUnqualifiedBlock(
const BlockDecl *
Block);
519 void mangleTemplateParamDecl(
const NamedDecl *Decl);
520 void mangleTemplateParameterList(
const TemplateParameterList *Params);
521 void mangleTypeConstraint(
const TemplateDecl *
Concept,
522 ArrayRef<TemplateArgument> Arguments);
523 void mangleTypeConstraint(
const TypeConstraint *Constraint);
524 void mangleRequiresClause(
const Expr *RequiresClause);
525 void mangleLambda(
const CXXRecordDecl *Lambda);
526 void mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
527 ArrayRef<StringRef> AdditionalAbiTags = {},
528 bool NoFunction =
false);
529 void mangleNestedName(
const TemplateDecl *TD,
530 ArrayRef<TemplateArgument> Args);
531 void mangleNestedNameWithClosurePrefix(GlobalDecl GD,
532 const NamedDecl *PrefixND,
533 ArrayRef<StringRef> AdditionalAbiTags);
534 void manglePrefix(NestedNameSpecifier Qualifier);
535 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
536 void manglePrefix(QualType
type);
537 void mangleTemplatePrefix(GlobalDecl GD,
bool NoFunction=
false);
539 const NamedDecl *getClosurePrefix(
const Decl *ND);
540 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
541 bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType,
542 StringRef Prefix =
"");
543 void mangleOperatorName(DeclarationName Name,
unsigned Arity);
545 void mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST =
nullptr);
551#define ABSTRACT_TYPE(CLASS, PARENT)
552#define NON_CANONICAL_TYPE(CLASS, PARENT)
553#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
554#include "clang/AST/TypeNodes.inc"
556 void mangleType(
const TagType*);
558 static StringRef getCallingConvQualifierName(
CallingConv CC);
561 void mangleSMEAttrs(
unsigned SMEAttrs);
564 void mangleNeonVectorType(
const VectorType *T);
566 void mangleAArch64NeonVectorType(
const VectorType *T);
568 void mangleAArch64FixedSveVectorType(
const VectorType *T);
570 void mangleRISCVFixedRVVVectorType(
const VectorType *T);
573 void mangleIntegerLiteral(
QualType T,
const llvm::APSInt &
Value);
574 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
575 void mangleFixedPointLiteral();
578 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
579 void mangleMemberExpr(
const Expr *base,
bool isArrow,
583 unsigned NumTemplateArgs,
unsigned knownArity);
584 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
585 void mangleInitListElements(
const InitListExpr *InitList);
588 void mangleReferenceToPack(
const NamedDecl *ND);
589 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
590 bool AsTemplateArg =
false);
594 struct TemplateArgManglingInfo;
597 unsigned NumTemplateArgs);
600 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
603 void mangleTemplateArgExpr(
const Expr *E);
605 bool NeedExactType =
false);
607 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
615 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
617 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
625 getASTContext(), getASTContext().getTranslationUnitDecl(),
626 false, SourceLocation(), SourceLocation(),
627 &getASTContext().Idents.get(
"std"),
650ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
657 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
659 if (ParmVarDecl *ContextParam =
660 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
661 return ContextParam->getDeclContext();
665 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
666 if (ParmVarDecl *ContextParam =
667 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
668 return ContextParam->getDeclContext();
676 if (D == getASTContext().getVaListTagDecl()) {
677 const llvm::Triple &T = getASTContext().getTargetInfo().getTriple();
678 if (T.isARM() || T.isThumb() || T.isAArch64())
679 return getStdNamespace();
685 return getEffectiveDeclContext(
cast<Decl>(DC));
688 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
690 const DeclContext *ParentDC = getEffectiveParentContext(Lambda);
694 if (isLocalContainerContext(ParentDC))
698 return getASTContext().getTranslationUnitDecl();
701 if (
const auto *FD = getASTContext().getLangOpts().getClangABICompat() >
702 LangOptions::ClangABI::Ver19
704 : dyn_cast<FunctionDecl>(D)) {
706 return getASTContext().getTranslationUnitDecl();
709 if (FD->isMemberLikeConstrainedFriend() &&
710 getASTContext().getLangOpts().getClangABICompat() >
711 LangOptions::ClangABI::Ver17)
718bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
721 getEffectiveDeclContext(ND)->isFileContext() &&
728bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
729 const NamedDecl *ND) {
730 if (!NeedsUniqueInternalLinkageNames || !ND)
733 const auto *FD = dyn_cast<FunctionDecl>(ND);
739 if (!FD->getType()->getAs<FunctionProtoType>())
742 if (isInternalLinkageDecl(ND))
748bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
749 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
752 if (FD->hasAttr<OverloadableAttr>())
768 if (FD->isMSVCRTEntryPoint())
782 if (!getASTContext().getLangOpts().
CPlusPlus)
785 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
796 const DeclContext *DC = getEffectiveDeclContext(D);
798 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
800 !VD->getOwningModuleForLinkage())
807void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
808 ArrayRef<StringRef> AdditionalAbiTags) {
809 assert(AbiTags &&
"require AbiTagState");
810 AbiTags->write(Out, ND,
811 DisableDerivedAbiTags ? ArrayRef<StringRef>{}
812 : AdditionalAbiTags);
815void CXXNameMangler::mangleSourceNameWithAbiTags(
816 const NamedDecl *ND, ArrayRef<StringRef> AdditionalAbiTags) {
818 writeAbiTags(ND, AdditionalAbiTags);
821void CXXNameMangler::mangle(GlobalDecl GD) {
827 mangleFunctionEncoding(GD);
828 else if (
isa<VarDecl, FieldDecl, MSGuidDecl, TemplateParamObjectDecl,
831 else if (
const IndirectFieldDecl *IFD =
832 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
833 mangleName(IFD->getAnonField());
835 llvm_unreachable(
"unexpected kind of global decl");
838void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
843 if (!Context.shouldMangleDeclName(FD)) {
848 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
849 if (ReturnTypeAbiTags.empty()) {
858 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
860 FunctionTypeDepth.pop(Saved);
861 mangleFunctionEncodingBareType(FD);
868 SmallString<256> FunctionEncodingBuf;
869 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
870 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
872 FunctionEncodingMangler.disableDerivedAbiTags();
874 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
875 FunctionEncodingMangler.mangleNameWithAbiTags(FD);
876 FunctionTypeDepth.pop(Saved);
879 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
880 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
884 const AbiTagList &UsedAbiTags =
885 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
886 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
887 AdditionalAbiTags.erase(
888 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
889 UsedAbiTags.begin(), UsedAbiTags.end(),
890 AdditionalAbiTags.begin()),
891 AdditionalAbiTags.end());
894 Saved = FunctionTypeDepth.push();
895 mangleNameWithAbiTags(FD, AdditionalAbiTags);
896 FunctionTypeDepth.pop(Saved);
897 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
901 extendSubstitutions(&FunctionEncodingMangler);
904void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
905 if (FD->
hasAttr<EnableIfAttr>()) {
906 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
907 Out <<
"Ua9enable_ifI";
908 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
911 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
914 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
919 mangleExpression(EIA->getCond());
922 mangleTemplateArgExpr(EIA->getCond());
926 FunctionTypeDepth.pop(Saved);
931 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
932 if (
auto Inherited = CD->getInheritedConstructor())
933 FD = Inherited.getConstructor();
951 bool MangleReturnType =
false;
955 MangleReturnType =
true;
958 FD = PrimaryTemplate->getTemplatedDecl();
961 mangleBareFunctionType(FD->
getType()->
castAs<FunctionProtoType>(),
962 MangleReturnType, FD);
966bool CXXNameMangler::isStd(
const NamespaceDecl *NS) {
967 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
971 return II && II->
isStr(
"std");
976bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
983static const GlobalDecl
987 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
996 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
997 TemplateArgs = &Spec->getTemplateArgs();
998 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1003 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
1004 TemplateArgs = &Spec->getTemplateArgs();
1005 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1016void CXXNameMangler::mangleName(GlobalDecl GD) {
1018 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1020 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1021 if (VariableTypeAbiTags.empty()) {
1023 mangleNameWithAbiTags(VD);
1028 llvm::raw_null_ostream NullOutStream;
1029 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1030 VariableNameMangler.disableDerivedAbiTags();
1031 VariableNameMangler.mangleNameWithAbiTags(VD);
1034 const AbiTagList &UsedAbiTags =
1035 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1036 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1037 AdditionalAbiTags.erase(
1038 std::set_difference(VariableTypeAbiTags.begin(),
1039 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1040 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1041 AdditionalAbiTags.end());
1044 mangleNameWithAbiTags(VD, AdditionalAbiTags);
1046 mangleNameWithAbiTags(GD);
1050const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1051 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1053 if (isLocalContainerContext(DC))
1054 return dyn_cast<RecordDecl>(D);
1056 DC = Context.getEffectiveDeclContext(D);
1061void CXXNameMangler::mangleNameWithAbiTags(
1062 GlobalDecl GD, ArrayRef<StringRef> AdditionalAbiTags) {
1069 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1070 bool IsLambda = isLambda(ND);
1072 if (GetLocalClassDecl(ND) &&
1073 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1074 mangleLocalName(GD, AdditionalAbiTags);
1082 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1083 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1087 if (isLocalContainerContext(DC)) {
1088 mangleLocalName(GD, AdditionalAbiTags);
1097 const TemplateArgumentList *TemplateArgs =
nullptr;
1098 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1099 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1104 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1108 mangleNestedName(GD, DC, AdditionalAbiTags);
1111void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1114 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1122void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1124 if (
auto It = ModuleSubstitutions.find(Name);
1125 It != ModuleSubstitutions.end()) {
1127 mangleSeqID(It->second);
1133 auto [Prefix, SubName] = Name.rsplit(
'.');
1134 if (SubName.empty())
1137 mangleModuleNamePrefix(Prefix, IsPartition);
1138 IsPartition =
false;
1144 Out << SubName.size() << SubName;
1145 ModuleSubstitutions.insert({Name, SeqID++});
1148void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1149 ArrayRef<TemplateArgument> Args) {
1150 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1153 mangleUnscopedTemplateName(TD, DC);
1156 mangleNestedName(TD, Args);
1160void CXXNameMangler::mangleUnscopedName(GlobalDecl GD,
const DeclContext *DC,
1161 ArrayRef<StringRef> AdditionalAbiTags) {
1166 if (isStdNamespace(DC)) {
1167 if (getASTContext().getTargetInfo().
getTriple().isOSSolaris()) {
1169 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(ND)) {
1174 if (
const IdentifierInfo *II = RD->getIdentifier()) {
1176 if (llvm::is_contained({
"div_t",
"ldiv_t",
"lconv",
"tm"},
type)) {
1186 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1189void CXXNameMangler::mangleUnscopedTemplateName(
1190 GlobalDecl GD,
const DeclContext *DC,
1191 ArrayRef<StringRef> AdditionalAbiTags) {
1195 if (mangleSubstitution(ND))
1199 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1200 assert(AdditionalAbiTags.empty() &&
1201 "template template param cannot have abi tags");
1202 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1204 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1210 addSubstitution(ND);
1213void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1227 llvm::APInt valueBits = f.bitcastToAPInt();
1228 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1229 assert(numCharacters != 0);
1232 SmallVector<char, 20> buffer(numCharacters);
1235 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1237 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1240 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1241 hexDigit >>= (digitBitIndex % 64);
1245 static const char charForHex[16] = {
1246 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1247 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1249 buffer[stringIndex] = charForHex[hexDigit];
1252 Out.write(buffer.data(), numCharacters);
1255void CXXNameMangler::mangleFloatLiteral(QualType T,
const llvm::APFloat &
V) {
1262void CXXNameMangler::mangleFixedPointLiteral() {
1263 DiagnosticsEngine &Diags = Context.getDiags();
1264 Diags.
Report(diag::err_unsupported_itanium_mangling)
1265 << UnsupportedItaniumManglingKind::FixedPointLiteral;
1268void CXXNameMangler::mangleNullPointer(QualType T) {
1275void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1276 if (
Value.isSigned() &&
Value.isNegative()) {
1278 Value.abs().print(Out,
false);
1280 Value.print(Out,
false);
1284void CXXNameMangler::mangleNumber(int64_t Number) {
1294void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1302 mangleNumber(NonVirtual);
1308 mangleNumber(NonVirtual);
1314void CXXNameMangler::manglePrefix(QualType
type) {
1315 if (
const auto *TST =
type->getAs<TemplateSpecializationType>()) {
1316 if (!mangleSubstitution(QualType(TST, 0))) {
1317 mangleTemplatePrefix(TST->getTemplateName());
1322 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1323 addSubstitution(QualType(TST, 0));
1325 }
else if (
const auto *DNT =
type->getAs<DependentNameType>()) {
1327 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
1328 if (!Clang14Compat && mangleSubstitution(QualType(DNT, 0)))
1333 assert(DNT->getQualifier());
1334 manglePrefix(DNT->getQualifier());
1336 mangleSourceName(DNT->getIdentifier());
1339 addSubstitution(QualType(DNT, 0));
1351void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier Qualifier,
1369 case NestedNameSpecifier::Kind::Null:
1370 llvm_unreachable(
"unexpected null nested name specifier");
1372 case NestedNameSpecifier::Kind::Global:
1382 case NestedNameSpecifier::Kind::MicrosoftSuper:
1383 llvm_unreachable(
"Can't mangle __super specifier");
1385 case NestedNameSpecifier::Kind::Namespace: {
1388 mangleUnresolvedPrefix(Prefix,
1392 mangleSourceNameWithAbiTags(Namespace);
1396 case NestedNameSpecifier::Kind::Type: {
1404 if (NestedNameSpecifier Prefix =
type->getPrefix()) {
1405 mangleUnresolvedPrefix(Prefix,
1412 if (mangleUnresolvedTypeOrSimpleId(QualType(
type, 0), recursive ?
"N" :
""))
1427void CXXNameMangler::mangleUnresolvedName(
1428 NestedNameSpecifier Qualifier, DeclarationName name,
1429 const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs,
1430 unsigned knownArity) {
1432 mangleUnresolvedPrefix(Qualifier);
1433 switch (
name.getNameKind()) {
1436 mangleSourceName(
name.getAsIdentifierInfo());
1441 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1448 mangleOperatorName(name, knownArity);
1451 llvm_unreachable(
"Can't mangle a constructor name!");
1453 llvm_unreachable(
"Can't mangle a using directive name!");
1455 llvm_unreachable(
"Can't mangle a deduction guide name!");
1459 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1465 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1468void CXXNameMangler::mangleUnqualifiedName(
1469 GlobalDecl GD, DeclarationName Name,
const DeclContext *DC,
1470 unsigned KnownArity, ArrayRef<StringRef> AdditionalAbiTags) {
1471 const NamedDecl *ND = cast_or_null<NamedDecl>(GD.
getDecl());
1478 mangleModuleName(ND);
1482 auto *FD = dyn_cast<FunctionDecl>(ND);
1483 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1485 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1486 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1490 unsigned Arity = KnownArity;
1496 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1503 for (
auto *BD : DD->bindings())
1504 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1506 writeAbiTags(ND, AdditionalAbiTags);
1510 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1513 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1514 llvm::raw_svector_ostream GUIDOS(GUID);
1515 Context.mangleMSGuidDecl(GD, GUIDOS);
1516 Out << GUID.size() << GUID;
1520 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1523 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1524 TPO->getValue(),
true);
1542 if (Context.isInternalLinkageDecl(ND))
1545 bool IsRegCall = FD &&
1549 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1551 bool IsOCLDeviceStub =
1553 DeviceKernelAttr::isOpenCLSpelling(FD->
getAttr<DeviceKernelAttr>()) &&
1556 mangleDeviceStubName(II);
1557 else if (IsOCLDeviceStub)
1558 mangleOCLDeviceStubName(II);
1560 mangleRegCallName(II);
1562 mangleSourceName(II);
1564 writeAbiTags(ND, AdditionalAbiTags);
1569 assert(ND &&
"mangling empty name without declaration");
1571 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1574 Out <<
"12_GLOBAL__N_1";
1579 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1581 const auto *RD = VD->getType()->castAsRecordDecl();
1592 assert(RD->isAnonymousStructOrUnion()
1593 &&
"Expected anonymous struct or union!");
1594 const FieldDecl *FD = RD->findFirstNamedDataMember();
1600 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1620 "Typedef should not be in another decl context!");
1621 assert(D->getDeclName().getAsIdentifierInfo() &&
1622 "Typedef was not named!");
1623 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1624 assert(AdditionalAbiTags.empty() &&
1625 "Type cannot have additional abi tags");
1637 if (
const CXXRecordDecl *
Record = dyn_cast<CXXRecordDecl>(TD)) {
1639 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1645 if (
Record->isLambda() &&
1646 ((DeviceNumber && *DeviceNumber > 0) ||
1647 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1648 assert(AdditionalAbiTags.empty() &&
1649 "Lambda type cannot have additional abi tags");
1656 unsigned UnnamedMangle =
1657 getASTContext().getManglingNumber(TD, Context.isAux());
1659 if (UnnamedMangle > 1)
1660 Out << UnnamedMangle - 2;
1662 writeAbiTags(TD, AdditionalAbiTags);
1668 unsigned AnonStructId =
1670 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1677 Str += llvm::utostr(AnonStructId);
1687 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1698 if (ND && Arity == UnknownArity) {
1702 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1703 if (MD->isImplicitObjectMemberFunction())
1709 mangleOperatorName(Name, Arity);
1710 writeAbiTags(ND, AdditionalAbiTags);
1714 llvm_unreachable(
"Can't mangle a deduction guide name!");
1717 llvm_unreachable(
"Can't mangle a using directive name!");
1721void CXXNameMangler::mangleConstructorName(
1722 const CXXConstructorDecl *CCD, ArrayRef<StringRef> AdditionalAbiTags) {
1723 const CXXRecordDecl *InheritedFrom =
nullptr;
1725 const TemplateArgumentList *InheritedTemplateArgs =
nullptr;
1727 InheritedFrom = Inherited.getConstructor()->
getParent();
1728 InheritedTemplateName =
1729 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1730 InheritedTemplateArgs =
1731 Inherited.getConstructor()->getTemplateSpecializationArgs();
1734 if (CCD == Structor)
1737 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1745 if (InheritedTemplateArgs)
1746 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1748 writeAbiTags(CCD, AdditionalAbiTags);
1751void CXXNameMangler::mangleDestructorName(
1752 const CXXDestructorDecl *CDD, ArrayRef<StringRef> AdditionalAbiTags) {
1753 if (CDD == Structor)
1756 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1762 writeAbiTags(CDD, AdditionalAbiTags);
1765void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1769 if (getASTContext().getLangOpts().RegCall4)
1770 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1773 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1777void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1781 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1785void CXXNameMangler::mangleOCLDeviceStubName(
const IdentifierInfo *II) {
1789 StringRef OCLDeviceStubNamePrefix =
"__clang_ocl_kern_imp_";
1790 Out << II->
getLength() + OCLDeviceStubNamePrefix.size()
1791 << OCLDeviceStubNamePrefix << II->
getName();
1794void CXXNameMangler::mangleSourceName(
const IdentifierInfo *II) {
1801void CXXNameMangler::mangleNestedName(GlobalDecl GD,
const DeclContext *DC,
1802 ArrayRef<StringRef> AdditionalAbiTags,
1811 if (
const CXXMethodDecl *
Method = dyn_cast<CXXMethodDecl>(ND)) {
1812 Qualifiers MethodQuals =
Method->getMethodQualifiers();
1815 if (
Method->isExplicitObjectMemberFunction())
1818 mangleQualifiers(MethodQuals);
1819 mangleRefQualifier(
Method->getRefQualifier());
1823 const TemplateArgumentList *TemplateArgs =
nullptr;
1824 if (GlobalDecl TD =
isTemplate(GD, TemplateArgs)) {
1825 mangleTemplatePrefix(TD, NoFunction);
1828 manglePrefix(DC, NoFunction);
1829 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1834void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1835 ArrayRef<TemplateArgument> Args) {
1840 mangleTemplatePrefix(TD);
1846void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1847 GlobalDecl GD,
const NamedDecl *PrefixND,
1848 ArrayRef<StringRef> AdditionalAbiTags) {
1857 mangleClosurePrefix(PrefixND);
1858 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1869 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1871 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1878void CXXNameMangler::mangleLocalName(GlobalDecl GD,
1879 ArrayRef<StringRef> AdditionalAbiTags) {
1887 const RecordDecl *RD = GetLocalClassDecl(D);
1888 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1893 AbiTagState LocalAbiTags(AbiTags);
1895 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
1897 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
1898 mangleBlockForPrefix(BD);
1905 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1919 const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1921 if (
const ParmVarDecl *Parm
1923 if (
const FunctionDecl *
Func
1928 mangleNumber(
Num - 2);
1937 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1938 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1939 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1940 mangleClosurePrefix(PrefixND,
true );
1942 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1943 assert(AdditionalAbiTags.empty() &&
1944 "Block cannot have additional abi tags");
1945 mangleUnqualifiedBlock(BD);
1948 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1949 AdditionalAbiTags,
true );
1951 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1954 if (
const ParmVarDecl *Parm
1955 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1956 if (
const FunctionDecl *
Func
1961 mangleNumber(
Num - 2);
1966 assert(AdditionalAbiTags.empty() &&
1967 "Block cannot have additional abi tags");
1968 mangleUnqualifiedBlock(BD);
1970 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1973 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1975 if (Context.getNextDiscriminator(ND, disc)) {
1979 Out <<
"__" << disc <<
'_';
1984void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1985 if (GetLocalClassDecl(
Block)) {
1986 mangleLocalName(
Block);
1989 const DeclContext *DC = Context.getEffectiveDeclContext(
Block);
1990 if (isLocalContainerContext(DC)) {
1991 mangleLocalName(
Block);
1994 if (
const NamedDecl *PrefixND = getClosurePrefix(
Block))
1995 mangleClosurePrefix(PrefixND);
1998 mangleUnqualifiedBlock(
Block);
2001void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
2004 if (Decl *Context =
Block->getBlockManglingContextDecl();
2005 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2007 Context->getDeclContext()->isRecord()) {
2010 mangleSourceNameWithAbiTags(ND);
2016 unsigned Number =
Block->getBlockManglingNumber();
2038void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *Decl) {
2040 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(Decl)) {
2041 if (Ty->isParameterPack())
2043 const TypeConstraint *Constraint = Ty->getTypeConstraint();
2044 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2047 mangleTypeConstraint(Constraint);
2051 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(Decl)) {
2052 if (Tn->isExpandedParameterPack()) {
2053 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2055 mangleType(Tn->getExpansionType(I));
2058 QualType T = Tn->getType();
2059 if (Tn->isParameterPack()) {
2061 if (
auto *PackExpansion = T->
getAs<PackExpansionType>())
2062 T = PackExpansion->getPattern();
2067 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(Decl)) {
2068 if (Tt->isExpandedParameterPack()) {
2069 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2071 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2073 if (Tt->isParameterPack())
2075 mangleTemplateParameterList(Tt->getTemplateParameters());
2080void CXXNameMangler::mangleTemplateParameterList(
2081 const TemplateParameterList *Params) {
2083 for (
auto *Param : *Params)
2084 mangleTemplateParamDecl(Param);
2085 mangleRequiresClause(Params->getRequiresClause());
2089void CXXNameMangler::mangleTypeConstraint(
2090 const TemplateDecl *
Concept, ArrayRef<TemplateArgument> Arguments) {
2091 const DeclContext *DC = Context.getEffectiveDeclContext(
Concept);
2093 mangleTemplateName(
Concept, Arguments);
2095 mangleUnscopedName(
Concept, DC);
2097 mangleNestedName(
Concept, DC);
2100void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2101 llvm::SmallVector<TemplateArgument, 8> Args;
2103 for (
const TemplateArgumentLoc &ArgLoc :
2105 Args.push_back(ArgLoc.getArgument());
2110void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2112 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2114 mangleExpression(RequiresClause);
2118void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2122 Context && isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2125 if (
const IdentifierInfo *Name =
2127 mangleSourceName(Name);
2128 const TemplateArgumentList *TemplateArgs =
nullptr;
2136 mangleLambdaSig(Lambda);
2151 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2155 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2157 mangleNumber(Number - 2);
2161void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2164 mangleTemplateParamDecl(D);
2168 mangleRequiresClause(TPL->getRequiresClause());
2172 mangleBareFunctionType(Proto,
false,
2176void CXXNameMangler::manglePrefix(NestedNameSpecifier Qualifier) {
2178 case NestedNameSpecifier::Kind::Null:
2179 case NestedNameSpecifier::Kind::Global:
2183 case NestedNameSpecifier::Kind::MicrosoftSuper:
2184 llvm_unreachable(
"Can't mangle __super specifier");
2186 case NestedNameSpecifier::Kind::Namespace:
2187 mangleName(
Qualifier.getAsNamespaceAndPrefix().Namespace->getNamespace());
2190 case NestedNameSpecifier::Kind::Type:
2191 manglePrefix(QualType(
Qualifier.getAsType(), 0));
2195 llvm_unreachable(
"unexpected nested name specifier");
2198void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2211 if (NoFunction && isLocalContainerContext(DC))
2215 if (mangleSubstitution(ND))
2221 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
2222 const TemplateDecl *TD = FD->getPrimaryTemplate()) {
2223 mangleTemplatePrefix(TD);
2225 *FD->getTemplateSpecializationArgs());
2227 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2230 addSubstitution(ND);
2235 manglePrefix(Context.getEffectiveDeclContext(ND), NoFunction);
2237 addSubstitution(ND);
2242 const TemplateArgumentList *TemplateArgs =
nullptr;
2243 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2244 mangleTemplatePrefix(TD);
2246 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2247 mangleClosurePrefix(PrefixND, NoFunction);
2248 mangleUnqualifiedName(ND,
nullptr);
2250 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2251 manglePrefix(DC, NoFunction);
2252 mangleUnqualifiedName(ND, DC);
2255 addSubstitution(ND);
2262 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
2263 return mangleTemplatePrefix(TD);
2266 assert(
Dependent &&
"unexpected template name kind");
2270 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2271 if (!Clang11Compat && mangleSubstitution(
Template))
2274 manglePrefix(
Dependent->getQualifier());
2276 if (Clang11Compat && mangleSubstitution(
Template))
2279 if (IdentifierOrOverloadedOperator Name =
Dependent->getName();
2280 const IdentifierInfo *Id = Name.getIdentifier())
2281 mangleSourceName(Id);
2283 mangleOperatorName(Name.getOperator(), UnknownArity);
2288void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
2297 if (mangleSubstitution(ND))
2301 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2302 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2304 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2305 manglePrefix(DC, NoFunction);
2307 mangleUnqualifiedName(GD, DC);
2312 addSubstitution(ND);
2315const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2316 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2319 const NamedDecl *Context =
nullptr;
2320 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2321 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2322 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
2325 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2327 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2341void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2344 if (mangleSubstitution(ND))
2347 const TemplateArgumentList *TemplateArgs =
nullptr;
2348 if (GlobalDecl TD =
isTemplate(ND, TemplateArgs)) {
2349 mangleTemplatePrefix(TD, NoFunction);
2352 const auto *DC = Context.getEffectiveDeclContext(ND);
2353 manglePrefix(DC, NoFunction);
2354 mangleUnqualifiedName(ND, DC);
2359 addSubstitution(ND);
2368 if (mangleSubstitution(TN))
2371 TemplateDecl *TD =
nullptr;
2381 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2382 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2389 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2398 mangleUnresolvedPrefix(
Dependent->getQualifier());
2399 mangleSourceName(II);
2408 SubstTemplateTemplateParmStorage *subst
2419 Out <<
"_SUBSTPACK_";
2423 llvm_unreachable(
"Unexpected DeducedTemplate");
2426 addSubstitution(TN);
2429bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
2435 case Type::Adjusted:
2437 case Type::ArrayParameter:
2439 case Type::BlockPointer:
2440 case Type::LValueReference:
2441 case Type::RValueReference:
2442 case Type::MemberPointer:
2443 case Type::ConstantArray:
2444 case Type::IncompleteArray:
2445 case Type::VariableArray:
2446 case Type::DependentSizedArray:
2447 case Type::DependentAddressSpace:
2448 case Type::DependentVector:
2449 case Type::DependentSizedExtVector:
2451 case Type::ExtVector:
2452 case Type::ConstantMatrix:
2453 case Type::DependentSizedMatrix:
2454 case Type::FunctionProto:
2455 case Type::FunctionNoProto:
2457 case Type::Attributed:
2458 case Type::BTFTagAttributed:
2459 case Type::OverflowBehavior:
2460 case Type::HLSLAttributedResource:
2461 case Type::HLSLInlineSpirv:
2463 case Type::DeducedTemplateSpecialization:
2464 case Type::PackExpansion:
2465 case Type::ObjCObject:
2466 case Type::ObjCInterface:
2467 case Type::ObjCObjectPointer:
2468 case Type::ObjCTypeParam:
2471 case Type::MacroQualified:
2473 case Type::DependentBitInt:
2474 case Type::CountAttributed:
2475 llvm_unreachable(
"type is illegal as a nested name specifier");
2477 case Type::SubstBuiltinTemplatePack:
2482 Out <<
"_SUBSTBUILTINPACK_";
2484 case Type::SubstTemplateTypeParmPack:
2489 Out <<
"_SUBSTPACK_";
2496 case Type::TypeOfExpr:
2498 case Type::Decltype:
2499 case Type::PackIndexing:
2500 case Type::TemplateTypeParm:
2501 case Type::UnaryTransform:
2514 case Type::SubstTemplateTypeParm: {
2518 if (
auto *TD = dyn_cast<TemplateDecl>(ST->getAssociatedDecl());
2520 return mangleUnresolvedTypeOrSimpleId(ST->getReplacementType(), Prefix);
2521 goto unresolvedType;
2528 case Type::PredefinedSugar:
2532 case Type::UnresolvedUsing:
2533 mangleSourceNameWithAbiTags(
2539 mangleSourceNameWithAbiTags(
2543 case Type::TemplateSpecialization: {
2544 const TemplateSpecializationType *TST =
2554 assert(TD &&
"no template for template specialization type");
2556 goto unresolvedType;
2558 mangleSourceNameWithAbiTags(TD);
2570 llvm_unreachable(
"invalid base for a template specialization type");
2573 SubstTemplateTemplateParmStorage *subst =
2584 Out <<
"_SUBSTPACK_";
2590 mangleSourceNameWithAbiTags(TD);
2600 mangleTemplateArgs(
TemplateName(), TST->template_arguments());
2604 case Type::InjectedClassName:
2605 mangleSourceNameWithAbiTags(
2609 case Type::DependentName:
2621void CXXNameMangler::mangleOperatorName(DeclarationName Name,
unsigned Arity) {
2631 llvm_unreachable(
"Not an operator name");
2654 case OO_New:
Out <<
"nw";
break;
2656 case OO_Array_New:
Out <<
"na";
break;
2658 case OO_Delete:
Out <<
"dl";
break;
2660 case OO_Array_Delete:
Out <<
"da";
break;
2664 Out << (Arity == 1?
"ps" :
"pl");
break;
2668 Out << (Arity == 1?
"ng" :
"mi");
break;
2672 Out << (Arity == 1?
"ad" :
"an");
break;
2677 Out << (Arity == 1?
"de" :
"ml");
break;
2679 case OO_Tilde:
Out <<
"co";
break;
2681 case OO_Slash:
Out <<
"dv";
break;
2683 case OO_Percent:
Out <<
"rm";
break;
2685 case OO_Pipe:
Out <<
"or";
break;
2687 case OO_Caret:
Out <<
"eo";
break;
2689 case OO_Equal:
Out <<
"aS";
break;
2691 case OO_PlusEqual:
Out <<
"pL";
break;
2693 case OO_MinusEqual:
Out <<
"mI";
break;
2695 case OO_StarEqual:
Out <<
"mL";
break;
2697 case OO_SlashEqual:
Out <<
"dV";
break;
2699 case OO_PercentEqual:
Out <<
"rM";
break;
2701 case OO_AmpEqual:
Out <<
"aN";
break;
2703 case OO_PipeEqual:
Out <<
"oR";
break;
2705 case OO_CaretEqual:
Out <<
"eO";
break;
2707 case OO_LessLess:
Out <<
"ls";
break;
2709 case OO_GreaterGreater:
Out <<
"rs";
break;
2711 case OO_LessLessEqual:
Out <<
"lS";
break;
2713 case OO_GreaterGreaterEqual:
Out <<
"rS";
break;
2715 case OO_EqualEqual:
Out <<
"eq";
break;
2717 case OO_ExclaimEqual:
Out <<
"ne";
break;
2719 case OO_Less:
Out <<
"lt";
break;
2721 case OO_Greater:
Out <<
"gt";
break;
2723 case OO_LessEqual:
Out <<
"le";
break;
2725 case OO_GreaterEqual:
Out <<
"ge";
break;
2727 case OO_Exclaim:
Out <<
"nt";
break;
2729 case OO_AmpAmp:
Out <<
"aa";
break;
2731 case OO_PipePipe:
Out <<
"oo";
break;
2733 case OO_PlusPlus:
Out <<
"pp";
break;
2735 case OO_MinusMinus:
Out <<
"mm";
break;
2737 case OO_Comma:
Out <<
"cm";
break;
2739 case OO_ArrowStar:
Out <<
"pm";
break;
2741 case OO_Arrow:
Out <<
"pt";
break;
2743 case OO_Call:
Out <<
"cl";
break;
2745 case OO_Subscript:
Out <<
"ix";
break;
2750 case OO_Conditional:
Out <<
"qu";
break;
2753 case OO_Coawait:
Out <<
"aw";
break;
2756 case OO_Spaceship:
Out <<
"ss";
break;
2760 llvm_unreachable(
"Not an overloaded operator");
2764void CXXNameMangler::mangleQualifiers(Qualifiers Quals,
const DependentAddressSpaceType *DAST) {
2783 SmallString<64> ASString;
2789 if (TargetAS != 0 ||
2791 ASString =
"AS" + llvm::utostr(TargetAS);
2794 default: llvm_unreachable(
"Not a language specific address space");
2798 case LangAS::opencl_global:
2799 ASString =
"CLglobal";
2801 case LangAS::opencl_global_device:
2802 ASString =
"CLdevice";
2804 case LangAS::opencl_global_host:
2805 ASString =
"CLhost";
2807 case LangAS::opencl_local:
2808 ASString =
"CLlocal";
2810 case LangAS::opencl_constant:
2811 ASString =
"CLconstant";
2813 case LangAS::opencl_private:
2814 ASString =
"CLprivate";
2816 case LangAS::opencl_generic:
2817 ASString =
"CLgeneric";
2821 case LangAS::sycl_global:
2822 ASString =
"SYglobal";
2824 case LangAS::sycl_global_device:
2825 ASString =
"SYdevice";
2827 case LangAS::sycl_global_host:
2828 ASString =
"SYhost";
2830 case LangAS::sycl_local:
2831 ASString =
"SYlocal";
2833 case LangAS::sycl_private:
2834 ASString =
"SYprivate";
2837 case LangAS::cuda_device:
2838 ASString =
"CUdevice";
2840 case LangAS::cuda_constant:
2841 ASString =
"CUconstant";
2843 case LangAS::cuda_shared:
2844 ASString =
"CUshared";
2847 case LangAS::ptr32_sptr:
2848 ASString =
"ptr32_sptr";
2850 case LangAS::ptr32_uptr:
2854 if (!getASTContext().getTargetInfo().
getTriple().isOSzOS())
2855 ASString =
"ptr32_uptr";
2862 if (!ASString.empty())
2863 mangleVendorQualifier(ASString);
2876 mangleVendorQualifier(
"__weak");
2880 mangleVendorQualifier(
"__unaligned");
2884 mangleVendorQualifier(
"__ptrauth");
2894 << unsigned(PtrAuth.isAddressDiscriminated())
2897 << PtrAuth.getExtraDiscriminator()
2912 mangleVendorQualifier(
"__strong");
2916 mangleVendorQualifier(
"__autoreleasing");
2939void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2943void CXXNameMangler::mangleVendorType(StringRef name) {
2950 switch (RefQualifier) {
2964void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2965 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2978 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2984 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2990 if (
auto *DeducedTST = Ty->
getAs<DeducedTemplateSpecializationType>())
2991 if (DeducedTST->getDeducedType().isNull())
2996void CXXNameMangler::mangleType(QualType T) {
3036 if (
const TemplateSpecializationType *TST
3037 = dyn_cast<TemplateSpecializationType>(T))
3038 if (!TST->isTypeAlias())
3053 auto [ty, quals] = T.
split();
3055 bool isSubstitutable =
3057 if (isSubstitutable && mangleSubstitution(T))
3064 quals = Qualifiers();
3070 if (quals || ty->isDependentAddressSpaceType()) {
3071 if (
const DependentAddressSpaceType *DAST =
3072 dyn_cast<DependentAddressSpaceType>(ty)) {
3074 mangleQualifiers(Quals, DAST);
3075 mangleType(QualType(Ty, 0));
3077 mangleQualifiers(quals);
3081 mangleType(QualType(ty, 0));
3084 switch (ty->getTypeClass()) {
3085#define ABSTRACT_TYPE(CLASS, PARENT)
3086#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3088 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3090#define TYPE(CLASS, PARENT) \
3092 mangleType(static_cast<const CLASS##Type*>(ty)); \
3094#include "clang/AST/TypeNodes.inc"
3099 if (isSubstitutable)
3103void CXXNameMangler::mangleCXXRecordDecl(
const CXXRecordDecl *
Record,
3104 bool SuppressSubstitution) {
3105 if (mangleSubstitution(
Record))
3108 if (SuppressSubstitution)
3113void CXXNameMangler::mangleType(
const BuiltinType *T) {
3155 std::string type_name;
3159 if (NormalizeIntegers && T->
isInteger()) {
3161 switch (getASTContext().getTypeSize(T)) {
3165 if (mangleSubstitution(BuiltinType::SChar))
3168 addSubstitution(BuiltinType::SChar);
3171 if (mangleSubstitution(BuiltinType::Short))
3174 addSubstitution(BuiltinType::Short);
3177 if (mangleSubstitution(BuiltinType::Int))
3180 addSubstitution(BuiltinType::Int);
3183 if (mangleSubstitution(BuiltinType::Long))
3186 addSubstitution(BuiltinType::Long);
3189 if (mangleSubstitution(BuiltinType::Int128))
3192 addSubstitution(BuiltinType::Int128);
3195 llvm_unreachable(
"Unknown integer size for normalization");
3198 switch (getASTContext().getTypeSize(T)) {
3200 if (mangleSubstitution(BuiltinType::UChar))
3203 addSubstitution(BuiltinType::UChar);
3206 if (mangleSubstitution(BuiltinType::UShort))
3209 addSubstitution(BuiltinType::UShort);
3212 if (mangleSubstitution(BuiltinType::UInt))
3215 addSubstitution(BuiltinType::UInt);
3218 if (mangleSubstitution(BuiltinType::ULong))
3221 addSubstitution(BuiltinType::ULong);
3224 if (mangleSubstitution(BuiltinType::UInt128))
3227 addSubstitution(BuiltinType::UInt128);
3230 llvm_unreachable(
"Unknown integer size for normalization");
3236 case BuiltinType::Void:
3239 case BuiltinType::Bool:
3242 case BuiltinType::Char_U:
3243 case BuiltinType::Char_S:
3246 case BuiltinType::UChar:
3249 case BuiltinType::UShort:
3252 case BuiltinType::UInt:
3255 case BuiltinType::ULong:
3258 case BuiltinType::ULongLong:
3261 case BuiltinType::UInt128:
3264 case BuiltinType::SChar:
3267 case BuiltinType::WChar_S:
3268 case BuiltinType::WChar_U:
3271 case BuiltinType::Char8:
3274 case BuiltinType::Char16:
3277 case BuiltinType::Char32:
3280 case BuiltinType::Short:
3283 case BuiltinType::Int:
3286 case BuiltinType::Long:
3289 case BuiltinType::LongLong:
3292 case BuiltinType::Int128:
3295 case BuiltinType::Float16:
3298 case BuiltinType::ShortAccum:
3301 case BuiltinType::Accum:
3304 case BuiltinType::LongAccum:
3307 case BuiltinType::UShortAccum:
3310 case BuiltinType::UAccum:
3313 case BuiltinType::ULongAccum:
3316 case BuiltinType::ShortFract:
3319 case BuiltinType::Fract:
3322 case BuiltinType::LongFract:
3325 case BuiltinType::UShortFract:
3328 case BuiltinType::UFract:
3331 case BuiltinType::ULongFract:
3334 case BuiltinType::SatShortAccum:
3337 case BuiltinType::SatAccum:
3340 case BuiltinType::SatLongAccum:
3343 case BuiltinType::SatUShortAccum:
3346 case BuiltinType::SatUAccum:
3349 case BuiltinType::SatULongAccum:
3352 case BuiltinType::SatShortFract:
3355 case BuiltinType::SatFract:
3358 case BuiltinType::SatLongFract:
3361 case BuiltinType::SatUShortFract:
3364 case BuiltinType::SatUFract:
3367 case BuiltinType::SatULongFract:
3370 case BuiltinType::Half:
3373 case BuiltinType::Float:
3376 case BuiltinType::Double:
3379 case BuiltinType::LongDouble: {
3380 const TargetInfo *TI =
3381 getASTContext().getLangOpts().OpenMP &&
3382 getASTContext().getLangOpts().OpenMPIsTargetDevice
3383 ? getASTContext().getAuxTargetInfo()
3384 : &getASTContext().getTargetInfo();
3388 case BuiltinType::Float128: {
3389 const TargetInfo *TI =
3390 getASTContext().getLangOpts().OpenMP &&
3391 getASTContext().getLangOpts().OpenMPIsTargetDevice
3392 ? getASTContext().getAuxTargetInfo()
3393 : &getASTContext().getTargetInfo();
3397 case BuiltinType::BFloat16: {
3398 const TargetInfo *TI =
3399 ((getASTContext().getLangOpts().OpenMP &&
3400 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3401 getASTContext().getLangOpts().SYCLIsDevice)
3402 ? getASTContext().getAuxTargetInfo()
3403 : &getASTContext().getTargetInfo();
3407 case BuiltinType::Ibm128: {
3408 const TargetInfo *TI = &getASTContext().getTargetInfo();
3412 case BuiltinType::NullPtr:
3416#define BUILTIN_TYPE(Id, SingletonId)
3417#define PLACEHOLDER_TYPE(Id, SingletonId) \
3418 case BuiltinType::Id:
3419#include "clang/AST/BuiltinTypes.def"
3420 case BuiltinType::Dependent:
3422 llvm_unreachable(
"mangling a placeholder type");
3424 case BuiltinType::ObjCId:
3425 Out <<
"11objc_object";
3427 case BuiltinType::ObjCClass:
3428 Out <<
"10objc_class";
3430 case BuiltinType::ObjCSel:
3431 Out <<
"13objc_selector";
3433#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3434 case BuiltinType::Id: \
3435 type_name = "ocl_" #ImgType "_" #Suffix; \
3436 Out << type_name.size() << type_name; \
3438#include "clang/Basic/OpenCLImageTypes.def"
3439 case BuiltinType::OCLSampler:
3440 Out <<
"11ocl_sampler";
3442 case BuiltinType::OCLEvent:
3443 Out <<
"9ocl_event";
3445 case BuiltinType::OCLClkEvent:
3446 Out <<
"12ocl_clkevent";
3448 case BuiltinType::OCLQueue:
3449 Out <<
"9ocl_queue";
3451 case BuiltinType::OCLReserveID:
3452 Out <<
"13ocl_reserveid";
3454#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3455 case BuiltinType::Id: \
3456 type_name = "ocl_" #ExtType; \
3457 Out << type_name.size() << type_name; \
3459#include "clang/Basic/OpenCLExtensionTypes.def"
3463#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
3464 case BuiltinType::Id: \
3465 if (T->getKind() == BuiltinType::SveBFloat16 && \
3466 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3468 mangleVendorType("__SVBFloat16_t"); \
3470 type_name = #MangledName; \
3471 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3474#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId) \
3475 case BuiltinType::Id: \
3476 type_name = #MangledName; \
3477 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3479#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
3480 case BuiltinType::Id: \
3481 type_name = #MangledName; \
3482 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3484#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
3485 case BuiltinType::Id: \
3486 type_name = #MangledName; \
3487 Out << (type_name == #Name ? "u" : "") << type_name.size() << type_name; \
3489#include "clang/Basic/AArch64ACLETypes.def"
3490#define PPC_VECTOR_TYPE(Name, Id, Size) \
3491 case BuiltinType::Id: \
3492 mangleVendorType(#Name); \
3494#include "clang/Basic/PPCTypes.def"
3496#define RVV_TYPE(Name, Id, SingletonId) \
3497 case BuiltinType::Id: \
3498 mangleVendorType(Name); \
3500#include "clang/Basic/RISCVVTypes.def"
3501#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3502 case BuiltinType::Id: \
3503 mangleVendorType(MangledName); \
3505#include "clang/Basic/WebAssemblyReferenceTypes.def"
3506#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
3507 case BuiltinType::Id: \
3508 mangleVendorType(Name); \
3510#include "clang/Basic/AMDGPUTypes.def"
3511#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3512 case BuiltinType::Id: \
3513 mangleVendorType(#Name); \
3515#include "clang/Basic/HLSLIntangibleTypes.def"
3519StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3539#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
3575 return "swiftasynccall";
3577 llvm_unreachable(
"bad calling convention");
3580void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *T) {
3582 if (T->
getExtInfo() == FunctionType::ExtInfo())
3589 StringRef CCQualifier = getCallingConvQualifierName(T->
getExtInfo().
getCC());
3590 if (!CCQualifier.empty())
3591 mangleVendorQualifier(CCQualifier);
3624 llvm_unreachable(
"Unrecognised SME attribute");
3639void CXXNameMangler::mangleSMEAttrs(
unsigned SMEAttrs) {
3659 Out <<
"Lj" <<
static_cast<unsigned>(Bitmask) <<
"EE";
3663CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
3670 case ParameterABI::Ordinary:
3674 case ParameterABI::HLSLOut:
3675 case ParameterABI::HLSLInOut:
3680 case ParameterABI::SwiftContext:
3681 case ParameterABI::SwiftAsyncContext:
3682 case ParameterABI::SwiftErrorResult:
3683 case ParameterABI::SwiftIndirectResult:
3689 mangleVendorQualifier(
"ns_consumed");
3692 mangleVendorQualifier(
"noescape");
3698void CXXNameMangler::mangleType(
const FunctionProtoType *T) {
3702 Out <<
"11__SME_ATTRSI";
3704 mangleExtFunctionInfo(T);
3721 mangleType(ExceptTy);
3732 mangleBareFunctionType(T,
true);
3739 mangleSMEAttrs(SMEAttrs);
3742void CXXNameMangler::mangleType(
const FunctionNoProtoType *T) {
3748 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3750 FunctionTypeDepth.enterFunctionDeclSuffix();
3752 FunctionTypeDepth.leaveFunctionDeclSuffix();
3754 FunctionTypeDepth.pop(saved);
3758void CXXNameMangler::mangleBareFunctionType(
const FunctionProtoType *Proto,
3759 bool MangleReturnType,
3760 const FunctionDecl *FD) {
3763 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3766 if (MangleReturnType) {
3767 FunctionTypeDepth.enterFunctionDeclSuffix();
3771 mangleVendorQualifier(
"ns_returns_retained");
3776 auto SplitReturnTy = ReturnTy.
split();
3778 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3780 mangleType(ReturnTy);
3782 FunctionTypeDepth.leaveFunctionDeclSuffix();
3790 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3804 assert(Attr->getType() <= 9 && Attr->getType() >= 0);
3805 if (Attr->isDynamic())
3806 Out <<
"U25pass_dynamic_object_size" << Attr->getType();
3808 Out <<
"U17pass_object_size" << Attr->getType();
3819 FunctionTypeDepth.enterFunctionDeclSuffix();
3823 FunctionTypeDepth.pop(saved);
3828void CXXNameMangler::mangleType(
const UnresolvedUsingType *T) {
3834void CXXNameMangler::mangleType(
const EnumType *T) {
3835 mangleType(
static_cast<const TagType*
>(T));
3837void CXXNameMangler::mangleType(
const RecordType *T) {
3838 mangleType(
static_cast<const TagType*
>(T));
3840void CXXNameMangler::mangleType(
const TagType *T) {
3841 mangleName(T->getDecl()->getDefinitionOrSelf());
3847void CXXNameMangler::mangleType(
const ConstantArrayType *T) {
3851void CXXNameMangler::mangleType(
const VariableArrayType *T) {
3859void CXXNameMangler::mangleType(
const DependentSizedArrayType *T) {
3869void CXXNameMangler::mangleType(
const IncompleteArrayType *T) {
3876void CXXNameMangler::mangleType(
const MemberPointerType *T) {
3879 mangleCXXRecordDecl(RD);
3883 if (
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
3904 mangleType(PointeeType);
3908void CXXNameMangler::mangleType(
const TemplateTypeParmType *T) {
3909 mangleTemplateParameter(T->getDepth(), T->getIndex());
3913void CXXNameMangler::mangleType(
const SubstTemplateTypeParmPackType *T) {
3918 Out <<
"_SUBSTPACK_";
3921void CXXNameMangler::mangleType(
const SubstBuiltinTemplatePackType *T) {
3926 Out <<
"_SUBSTBUILTINPACK_";
3930void CXXNameMangler::mangleType(
const PointerType *T) {
3934void CXXNameMangler::mangleType(
const ObjCObjectPointerType *T) {
3940void CXXNameMangler::mangleType(
const LValueReferenceType *T) {
3946void CXXNameMangler::mangleType(
const RValueReferenceType *T) {
3952void CXXNameMangler::mangleType(
const ComplexType *T) {
3960void CXXNameMangler::mangleNeonVectorType(
const VectorType *T) {
3962 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3963 const char *EltName =
nullptr;
3966 case BuiltinType::SChar:
3967 case BuiltinType::UChar:
3968 EltName =
"poly8_t";
3970 case BuiltinType::Short:
3971 case BuiltinType::UShort:
3972 EltName =
"poly16_t";
3974 case BuiltinType::LongLong:
3975 case BuiltinType::ULongLong:
3976 EltName =
"poly64_t";
3978 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3982 case BuiltinType::SChar: EltName =
"int8_t";
break;
3983 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3984 case BuiltinType::Short: EltName =
"int16_t";
break;
3985 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3986 case BuiltinType::Int: EltName =
"int32_t";
break;
3987 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3988 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3989 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3990 case BuiltinType::Double: EltName =
"float64_t";
break;
3991 case BuiltinType::Float: EltName =
"float32_t";
break;
3992 case BuiltinType::Half: EltName =
"float16_t";
break;
3993 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3994 case BuiltinType::MFloat8:
3995 EltName =
"mfloat8_t";
3998 llvm_unreachable(
"unexpected Neon vector element type");
4001 const char *BaseName =
nullptr;
4003 getASTContext().getTypeSize(EltType));
4005 BaseName =
"__simd64_";
4007 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
4008 BaseName =
"__simd128_";
4010 Out << strlen(BaseName) + strlen(EltName);
4011 Out << BaseName << EltName;
4014void CXXNameMangler::mangleNeonVectorType(
const DependentVectorType *T) {
4015 DiagnosticsEngine &Diags = Context.getDiags();
4017 << UnsupportedItaniumManglingKind::DependentNeonVector;
4022 case BuiltinType::SChar:
4024 case BuiltinType::Short:
4026 case BuiltinType::Int:
4028 case BuiltinType::Long:
4029 case BuiltinType::LongLong:
4031 case BuiltinType::UChar:
4033 case BuiltinType::UShort:
4035 case BuiltinType::UInt:
4037 case BuiltinType::ULong:
4038 case BuiltinType::ULongLong:
4040 case BuiltinType::Half:
4042 case BuiltinType::Float:
4044 case BuiltinType::Double:
4046 case BuiltinType::BFloat16:
4048 case BuiltinType::MFloat8:
4051 llvm_unreachable(
"Unexpected vector element base type");
4058void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *T) {
4060 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
4065 assert((BitSize == 64 || BitSize == 128) &&
4066 "Neon vector type not 64 or 128 bits");
4071 case BuiltinType::UChar:
4074 case BuiltinType::UShort:
4077 case BuiltinType::ULong:
4078 case BuiltinType::ULongLong:
4082 llvm_unreachable(
"unexpected Neon polynomial vector element type");
4088 (
"__" + EltName +
"x" + Twine(T->
getNumElements()) +
"_t").str();
4091void CXXNameMangler::mangleAArch64NeonVectorType(
const DependentVectorType *T) {
4092 DiagnosticsEngine &Diags = Context.getDiags();
4094 << UnsupportedItaniumManglingKind::DependentNeonVector;
4121void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *T) {
4122 assert((T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4123 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
4124 "expected fixed-length SVE vector!");
4128 "expected builtin type for fixed-length SVE vector!");
4132 case BuiltinType::SChar:
4135 case BuiltinType::UChar: {
4142 case BuiltinType::Short:
4145 case BuiltinType::UShort:
4148 case BuiltinType::Int:
4151 case BuiltinType::UInt:
4154 case BuiltinType::Long:
4157 case BuiltinType::ULong:
4160 case BuiltinType::Half:
4163 case BuiltinType::Float:
4166 case BuiltinType::Double:
4169 case BuiltinType::BFloat16:
4173 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
4176 unsigned VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4178 if (T->
getVectorKind() == VectorKind::SveFixedLengthPredicate)
4181 Out <<
"9__SVE_VLSI";
4182 mangleVendorType(TypeName);
4183 Out <<
"Lj" << VecSizeInBits <<
"EE";
4186void CXXNameMangler::mangleAArch64FixedSveVectorType(
4187 const DependentVectorType *T) {
4188 DiagnosticsEngine &Diags = Context.getDiags();
4190 << UnsupportedItaniumManglingKind::DependentFixedLengthSVEVector;
4193void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *T) {
4194 assert((T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4199 "expected fixed-length RVV vector!");
4203 "expected builtin type for fixed-length RVV vector!");
4205 SmallString<20> TypeNameStr;
4206 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4207 TypeNameOS <<
"__rvv_";
4209 case BuiltinType::SChar:
4210 TypeNameOS <<
"int8";
4212 case BuiltinType::UChar:
4214 TypeNameOS <<
"uint8";
4216 TypeNameOS <<
"bool";
4218 case BuiltinType::Short:
4219 TypeNameOS <<
"int16";
4221 case BuiltinType::UShort:
4222 TypeNameOS <<
"uint16";
4224 case BuiltinType::Int:
4225 TypeNameOS <<
"int32";
4227 case BuiltinType::UInt:
4228 TypeNameOS <<
"uint32";
4230 case BuiltinType::Long:
4231 case BuiltinType::LongLong:
4232 TypeNameOS <<
"int64";
4234 case BuiltinType::ULong:
4235 case BuiltinType::ULongLong:
4236 TypeNameOS <<
"uint64";
4238 case BuiltinType::Float16:
4239 TypeNameOS <<
"float16";
4241 case BuiltinType::Float:
4242 TypeNameOS <<
"float32";
4244 case BuiltinType::Double:
4245 TypeNameOS <<
"float64";
4247 case BuiltinType::BFloat16:
4248 TypeNameOS <<
"bfloat16";
4251 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4254 unsigned VecSizeInBits;
4256 case VectorKind::RVVFixedLengthMask_1:
4259 case VectorKind::RVVFixedLengthMask_2:
4262 case VectorKind::RVVFixedLengthMask_4:
4266 VecSizeInBits = getASTContext().getTypeInfo(T).Width;
4271 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4272 getASTContext().getLangOpts(),
4273 TargetInfo::ArmStreamingKind::NotStreaming);
4274 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4278 if (VecSizeInBits >= VLen)
4279 TypeNameOS << (VecSizeInBits / VLen);
4281 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4283 TypeNameOS << (VLen / VecSizeInBits);
4287 Out <<
"9__RVV_VLSI";
4288 mangleVendorType(TypeNameStr);
4289 Out <<
"Lj" << VecSizeInBits <<
"EE";
4292void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4293 const DependentVectorType *T) {
4294 DiagnosticsEngine &Diags = Context.getDiags();
4296 << UnsupportedItaniumManglingKind::DependentFixedLengthRVVVectorType;
4307void CXXNameMangler::mangleType(
const VectorType *T) {
4310 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4311 llvm::Triple::ArchType
Arch =
4312 getASTContext().getTargetInfo().getTriple().getArch();
4313 if ((
Arch == llvm::Triple::aarch64 ||
4314 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4315 mangleAArch64NeonVectorType(T);
4317 mangleNeonVectorType(T);
4319 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4320 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4321 mangleAArch64FixedSveVectorType(T);
4323 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData ||
4328 mangleRISCVFixedRVVVectorType(T);
4340void CXXNameMangler::mangleType(
const DependentVectorType *T) {
4343 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4344 llvm::Triple::ArchType
Arch =
4345 getASTContext().getTargetInfo().getTriple().getArch();
4346 if ((
Arch == llvm::Triple::aarch64 ||
Arch == llvm::Triple::aarch64_be) &&
4348 mangleAArch64NeonVectorType(T);
4350 mangleNeonVectorType(T);
4352 }
else if (T->
getVectorKind() == VectorKind::SveFixedLengthData ||
4353 T->
getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4354 mangleAArch64FixedSveVectorType(T);
4356 }
else if (T->
getVectorKind() == VectorKind::RVVFixedLengthData) {
4357 mangleRISCVFixedRVVVectorType(T);
4372void CXXNameMangler::mangleType(
const ExtVectorType *T) {
4373 mangleType(
static_cast<const VectorType*
>(T));
4375void CXXNameMangler::mangleType(
const DependentSizedExtVectorType *T) {
4382void CXXNameMangler::mangleType(
const ConstantMatrixType *T) {
4386 mangleVendorType(
"matrix_type");
4389 auto &ASTCtx = getASTContext();
4390 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4391 llvm::APSInt Rows(BitWidth);
4393 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4394 llvm::APSInt Columns(BitWidth);
4396 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4401void CXXNameMangler::mangleType(
const DependentSizedMatrixType *T) {
4404 mangleVendorType(
"matrix_type");
4413void CXXNameMangler::mangleType(
const DependentAddressSpaceType *T) {
4415 mangleQualifiers(split.
Quals, T);
4416 mangleType(QualType(split.
Ty, 0));
4419void CXXNameMangler::mangleType(
const PackExpansionType *T) {
4422 mangleType(T->getPattern());
4425void CXXNameMangler::mangleType(
const PackIndexingType *T) {
4428 mangleType(T->getPattern());
4429 mangleExpression(T->getIndexExpr());
4432void CXXNameMangler::mangleType(
const ObjCInterfaceType *T) {
4436void CXXNameMangler::mangleType(
const ObjCObjectType *T) {
4438 if (T->isKindOfType())
4439 Out <<
"U8__kindof";
4441 if (!T->qual_empty()) {
4443 SmallString<64> QualStr;
4444 llvm::raw_svector_ostream QualOS(QualStr);
4445 QualOS <<
"objcproto";
4446 for (
const auto *I : T->quals()) {
4447 StringRef
name = I->getName();
4450 mangleVendorQualifier(QualStr);
4453 mangleType(T->getBaseType());
4455 if (T->isSpecialized()) {
4458 for (
auto typeArg : T->getTypeArgs())
4459 mangleType(typeArg);
4464void CXXNameMangler::mangleType(
const BlockPointerType *T) {
4465 Out <<
"U13block_pointer";
4469void CXXNameMangler::mangleType(
const InjectedClassNameType *T) {
4474 T->getDecl()->getCanonicalTemplateSpecializationType(getASTContext()));
4477void CXXNameMangler::mangleType(
const TemplateSpecializationType *T) {
4478 if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) {
4479 mangleTemplateName(TD, T->template_arguments());
4482 mangleTemplatePrefix(T->getTemplateName());
4487 mangleTemplateArgs(T->getTemplateName(), T->template_arguments());
4492void CXXNameMangler::mangleType(
const DependentNameType *T) {
4503 switch (T->getKeyword()) {
4504 case ElaboratedTypeKeyword::None:
4505 case ElaboratedTypeKeyword::Typename:
4507 case ElaboratedTypeKeyword::Struct:
4508 case ElaboratedTypeKeyword::Class:
4509 case ElaboratedTypeKeyword::Interface:
4512 case ElaboratedTypeKeyword::Union:
4515 case ElaboratedTypeKeyword::Enum:
4521 manglePrefix(T->getQualifier());
4522 mangleSourceName(T->getIdentifier());
4526void CXXNameMangler::mangleType(
const TypeOfType *T) {
4532void CXXNameMangler::mangleType(
const TypeOfExprType *T) {
4538void CXXNameMangler::mangleType(
const DecltypeType *T) {
4539 Expr *E = T->getUnderlyingExpr();
4558 mangleExpression(E);
4562void CXXNameMangler::mangleType(
const UnaryTransformType *T) {
4565 if (T->isDependentType()) {
4566 StringRef BuiltinName;
4567 switch (T->getUTTKind()) {
4568#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4569 case UnaryTransformType::Enum: \
4570 BuiltinName = "__" #Trait; \
4572#include "clang/Basic/TransformTypeTraits.def"
4574 mangleVendorType(BuiltinName);
4578 mangleType(T->getBaseType());
4582void CXXNameMangler::mangleType(
const AutoType *T) {
4583 assert(T->getDeducedType().isNull() &&
4584 "Deduced AutoType shouldn't be handled here!");
4585 assert(T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4586 "shouldn't need to mangle __auto_type!");
4591 if (T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4592 Out << (T->isDecltypeAuto() ?
"DK" :
"Dk");
4593 mangleTypeConstraint(T->getTypeConstraintConcept(),
4594 T->getTypeConstraintArguments());
4596 Out << (T->isDecltypeAuto() ?
"Dc" :
"Da");
4600void CXXNameMangler::mangleType(
const DeducedTemplateSpecializationType *T) {
4601 QualType
Deduced = T->getDeducedType();
4607 "shouldn't form deduced TST unless we know we have a template");
4611void CXXNameMangler::mangleType(
const AtomicType *T) {
4618void CXXNameMangler::mangleType(
const PipeType *T) {
4625void CXXNameMangler::mangleType(
const OverflowBehaviorType *T) {
4628 if (T->isWrapKind()) {
4629 Out <<
"U8ObtWrap_";
4631 Out <<
"U8ObtTrap_";
4633 mangleType(T->getUnderlyingType());
4636void CXXNameMangler::mangleType(
const BitIntType *T) {
4643void CXXNameMangler::mangleType(
const DependentBitIntType *T) {
4652void CXXNameMangler::mangleType(
const ArrayParameterType *T) {
4656void CXXNameMangler::mangleType(
const HLSLAttributedResourceType *T) {
4657 llvm::SmallString<64> Str(
"_Res");
4658 const HLSLAttributedResourceType::Attributes &Attrs = T->getAttrs();
4660 switch (Attrs.ResourceClass) {
4661 case llvm::dxil::ResourceClass::UAV:
4664 case llvm::dxil::ResourceClass::SRV:
4667 case llvm::dxil::ResourceClass::CBuffer:
4670 case llvm::dxil::ResourceClass::Sampler:
4676 if (Attrs.RawBuffer)
4678 if (Attrs.IsCounter)
4680 if (T->hasContainedType())
4682 mangleVendorQualifier(Str);
4684 if (T->hasContainedType()) {
4685 mangleType(T->getContainedType());
4687 mangleType(T->getWrappedType());
4690void CXXNameMangler::mangleType(
const HLSLInlineSpirvType *T) {
4691 SmallString<20> TypeNameStr;
4692 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4694 TypeNameOS <<
"spirv_type";
4696 TypeNameOS <<
"_" << T->getOpcode();
4697 TypeNameOS <<
"_" << T->getSize();
4698 TypeNameOS <<
"_" << T->getAlignment();
4700 mangleVendorType(TypeNameStr);
4702 for (
auto &Operand : T->getOperands()) {
4703 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
4706 case SpirvOperandKind::ConstantId:
4707 mangleVendorQualifier(
"_Const");
4708 mangleIntegerLiteral(
Operand.getResultType(),
4709 llvm::APSInt(
Operand.getValue()));
4711 case SpirvOperandKind::Literal:
4712 mangleVendorQualifier(
"_Lit");
4713 mangleIntegerLiteral(Context.getASTContext().
IntTy,
4714 llvm::APSInt(
Operand.getValue()));
4716 case SpirvOperandKind::TypeId:
4717 mangleVendorQualifier(
"_Type");
4718 mangleType(
Operand.getResultType());
4721 llvm_unreachable(
"Invalid SpirvOperand kind");
4724 TypeNameOS <<
Operand.getKind();
4728void CXXNameMangler::mangleIntegerLiteral(QualType T,
4729 const llvm::APSInt &
Value) {
4736 Out << (
Value.getBoolValue() ?
'1' :
'0');
4738 mangleNumber(
Value);
4743void CXXNameMangler::mangleMemberExprBase(
const Expr *Base,
bool IsArrow) {
4745 while (
const auto *RT =
Base->getType()->getAsCanonical<RecordType>()) {
4746 if (!RT->getDecl()->isAnonymousStructOrUnion())
4748 const auto *ME = dyn_cast<MemberExpr>(Base);
4751 Base = ME->getBase();
4752 IsArrow = ME->isArrow();
4755 if (
Base->isImplicitCXXThis()) {
4761 Out << (IsArrow ?
"pt" :
"dt");
4762 mangleExpression(Base);
4767void CXXNameMangler::mangleMemberExpr(
const Expr *base,
bool isArrow,
4768 NestedNameSpecifier Qualifier,
4769 NamedDecl *firstQualifierLookup,
4770 DeclarationName member,
4771 const TemplateArgumentLoc *TemplateArgs,
4772 unsigned NumTemplateArgs,
4777 mangleMemberExprBase(base, isArrow);
4778 mangleUnresolvedName(Qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4791 if (callee == fn)
return false;
4795 if (!lookup)
return false;
4812void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4814 Out << CastEncoding;
4819void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4821 InitList = Syntactic;
4822 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4823 mangleExpression(InitList->
getInit(i));
4826void CXXNameMangler::mangleRequirement(SourceLocation RequiresExprLoc,
4827 const concepts::Requirement *Req) {
4828 using concepts::Requirement;
4833 auto HandleSubstitutionFailure =
4834 [&](SourceLocation Loc) {
4835 DiagnosticsEngine &Diags = Context.getDiags();
4836 Diags.
Report(Loc, diag::err_unsupported_itanium_mangling)
4837 << UnsupportedItaniumManglingKind::
4838 RequiresExprWithSubstitutionFailure;
4843 case Requirement::RK_Type: {
4845 if (TR->isSubstitutionFailure())
4846 return HandleSubstitutionFailure(
4847 TR->getSubstitutionDiagnostic()->DiagLoc);
4850 mangleType(TR->getType()->getType());
4854 case Requirement::RK_Simple:
4855 case Requirement::RK_Compound: {
4857 if (ER->isExprSubstitutionFailure())
4858 return HandleSubstitutionFailure(
4859 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4862 mangleExpression(ER->getExpr());
4864 if (ER->hasNoexceptRequirement())
4867 if (!ER->getReturnTypeRequirement().isEmpty()) {
4868 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4869 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4870 .getSubstitutionDiagnostic()
4874 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4879 case Requirement::RK_Nested:
4881 if (NR->hasInvalidConstraint()) {
4884 return HandleSubstitutionFailure(RequiresExprLoc);
4888 mangleExpression(NR->getConstraintExpr());
4893void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4894 bool AsTemplateArg) {
4927 QualType ImplicitlyConvertedToType;
4931 bool IsPrimaryExpr =
true;
4932 auto NotPrimaryExpr = [&] {
4933 if (AsTemplateArg && IsPrimaryExpr)
4935 IsPrimaryExpr =
false;
4938 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4939 switch (D->getKind()) {
4952 case Decl::EnumConstant: {
4959 case Decl::NonTypeTemplateParm:
4972 case Expr::NoStmtClass:
4973#define ABSTRACT_STMT(Type)
4974#define EXPR(Type, Base)
4975#define STMT(Type, Base) \
4976 case Expr::Type##Class:
4977#include "clang/AST/StmtNodes.inc"
4982 case Expr::AddrLabelExprClass:
4983 case Expr::DesignatedInitUpdateExprClass:
4984 case Expr::ImplicitValueInitExprClass:
4985 case Expr::ArrayInitLoopExprClass:
4986 case Expr::ArrayInitIndexExprClass:
4987 case Expr::NoInitExprClass:
4988 case Expr::ParenListExprClass:
4989 case Expr::MSPropertyRefExprClass:
4990 case Expr::MSPropertySubscriptExprClass:
4991 case Expr::RecoveryExprClass:
4992 case Expr::ArraySectionExprClass:
4993 case Expr::OMPArrayShapingExprClass:
4994 case Expr::OMPIteratorExprClass:
4995 case Expr::CXXInheritedCtorInitExprClass:
4996 case Expr::CXXParenListInitExprClass:
4997 llvm_unreachable(
"unexpected statement kind");
4999 case Expr::ConstantExprClass:
5003 case Expr::CXXReflectExprClass: {
5005 assert(
false &&
"unimplemented");
5010 case Expr::BlockExprClass:
5011 case Expr::ChooseExprClass:
5012 case Expr::CompoundLiteralExprClass:
5013 case Expr::ExtVectorElementExprClass:
5014 case Expr::MatrixElementExprClass:
5015 case Expr::GenericSelectionExprClass:
5016 case Expr::ObjCEncodeExprClass:
5017 case Expr::ObjCIsaExprClass:
5018 case Expr::ObjCIvarRefExprClass:
5019 case Expr::ObjCMessageExprClass:
5020 case Expr::ObjCPropertyRefExprClass:
5021 case Expr::ObjCProtocolExprClass:
5022 case Expr::ObjCSelectorExprClass:
5023 case Expr::ObjCStringLiteralClass:
5024 case Expr::ObjCBoxedExprClass:
5025 case Expr::ObjCArrayLiteralClass:
5026 case Expr::ObjCDictionaryLiteralClass:
5027 case Expr::ObjCSubscriptRefExprClass:
5028 case Expr::ObjCIndirectCopyRestoreExprClass:
5029 case Expr::ObjCAvailabilityCheckExprClass:
5030 case Expr::OffsetOfExprClass:
5031 case Expr::PredefinedExprClass:
5032 case Expr::ShuffleVectorExprClass:
5033 case Expr::ConvertVectorExprClass:
5034 case Expr::StmtExprClass:
5035 case Expr::ArrayTypeTraitExprClass:
5036 case Expr::ExpressionTraitExprClass:
5037 case Expr::VAArgExprClass:
5038 case Expr::CUDAKernelCallExprClass:
5039 case Expr::AsTypeExprClass:
5040 case Expr::PseudoObjectExprClass:
5041 case Expr::AtomicExprClass:
5042 case Expr::SourceLocExprClass:
5043 case Expr::EmbedExprClass:
5044 case Expr::BuiltinBitCastExprClass: {
5048 DiagnosticsEngine &Diags = Context.getDiags();
5056 case Expr::CXXUuidofExprClass: {
5061 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5062 Out <<
"u8__uuidof";
5071 Out <<
"u8__uuidoft";
5075 Out <<
"u8__uuidofz";
5076 mangleExpression(UuidExp);
5083 case Expr::BinaryConditionalOperatorClass: {
5085 DiagnosticsEngine &Diags = Context.getDiags();
5087 << UnsupportedItaniumManglingKind::TernaryWithOmittedMiddleOperand
5093 case Expr::OpaqueValueExprClass:
5094 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
5096 case Expr::InitListExprClass: {
5104 case Expr::DesignatedInitExprClass: {
5107 for (
const auto &Designator : DIE->designators()) {
5108 if (Designator.isFieldDesignator()) {
5110 mangleSourceName(Designator.getFieldName());
5111 }
else if (Designator.isArrayDesignator()) {
5113 mangleExpression(DIE->getArrayIndex(Designator));
5115 assert(Designator.isArrayRangeDesignator() &&
5116 "unknown designator kind");
5118 mangleExpression(DIE->getArrayRangeStart(Designator));
5119 mangleExpression(DIE->getArrayRangeEnd(Designator));
5122 mangleExpression(DIE->getInit());
5126 case Expr::CXXDefaultArgExprClass:
5130 case Expr::CXXDefaultInitExprClass:
5134 case Expr::CXXStdInitializerListExprClass:
5138 case Expr::SubstNonTypeTemplateParmExprClass: {
5142 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
5144 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
5145 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
5146 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
5156 case Expr::UserDefinedLiteralClass:
5159 case Expr::CXXMemberCallExprClass:
5160 case Expr::CallExprClass: {
5182 CallArity = UnknownArity;
5184 mangleExpression(CE->
getCallee(), CallArity);
5186 mangleExpression(Arg);
5191 case Expr::CXXNewExprClass: {
5194 if (
New->isGlobalNew())
Out <<
"gs";
5195 Out << (
New->isArray() ?
"na" :
"nw");
5197 E =
New->placement_arg_end(); I != E; ++I)
5198 mangleExpression(*I);
5200 mangleType(
New->getAllocatedType());
5201 if (
New->hasInitializer()) {
5202 if (
New->getInitializationStyle() == CXXNewInitializationStyle::Braces)
5206 const Expr *
Init =
New->getInitializer();
5207 if (
const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(
Init)) {
5212 mangleExpression(*I);
5213 }
else if (
const ParenListExpr *PLE = dyn_cast<ParenListExpr>(
Init)) {
5214 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
5215 mangleExpression(PLE->getExpr(i));
5216 }
else if (
New->getInitializationStyle() ==
5217 CXXNewInitializationStyle::Braces &&
5222 mangleExpression(
Init);
5228 case Expr::CXXPseudoDestructorExprClass: {
5231 if (
const Expr *Base = PDE->getBase())
5232 mangleMemberExprBase(Base, PDE->isArrow());
5233 NestedNameSpecifier
Qualifier = PDE->getQualifier();
5234 if (TypeSourceInfo *ScopeInfo = PDE->getScopeTypeInfo()) {
5236 mangleUnresolvedPrefix(Qualifier,
5238 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
5242 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
5245 }
else if (Qualifier) {
5246 mangleUnresolvedPrefix(Qualifier);
5250 QualType DestroyedType = PDE->getDestroyedType();
5251 mangleUnresolvedTypeOrSimpleId(DestroyedType);
5255 case Expr::MemberExprClass: {
5266 case Expr::UnresolvedMemberExprClass: {
5277 case Expr::CXXDependentScopeMemberExprClass: {
5279 const CXXDependentScopeMemberExpr *ME
5290 case Expr::UnresolvedLookupExprClass: {
5299 case Expr::CXXUnresolvedConstructExprClass: {
5305 assert(N == 1 &&
"unexpected form for list initialization");
5309 mangleInitListElements(IL);
5316 if (N != 1)
Out <<
'_';
5317 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5318 if (N != 1)
Out <<
'E';
5322 case Expr::CXXConstructExprClass: {
5329 "implicit CXXConstructExpr must have one argument");
5336 mangleExpression(E);
5341 case Expr::CXXTemporaryObjectExprClass: {
5352 if (!List && N != 1)
5354 if (CE->isStdInitListInitialization()) {
5361 mangleInitListElements(ILE);
5364 mangleExpression(E);
5371 case Expr::CXXScalarValueInitExprClass:
5378 case Expr::CXXNoexceptExprClass:
5384 case Expr::UnaryExprOrTypeTraitExprClass: {
5401 QualType T = (ImplicitlyConvertedToType.
isNull() ||
5403 : ImplicitlyConvertedToType;
5405 mangleIntegerLiteral(T,
V);
5411 auto MangleAlignofSizeofArg = [&] {
5421 auto MangleExtensionBuiltin = [&](
const UnaryExprOrTypeTraitExpr *E,
5422 StringRef Name = {}) {
5425 mangleVendorType(Name);
5436 MangleAlignofSizeofArg();
5438 case UETT_PreferredAlignOf:
5442 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5443 MangleExtensionBuiltin(SAE,
"__alignof__");
5449 MangleAlignofSizeofArg();
5453 case UETT_VectorElements:
5454 case UETT_OpenMPRequiredSimdAlign:
5456 case UETT_PtrAuthTypeDiscriminator:
5457 case UETT_DataSizeOf: {
5458 DiagnosticsEngine &Diags = Context.getDiags();
5467 case Expr::TypeTraitExprClass: {
5472 mangleVendorType(Spelling);
5473 for (TypeSourceInfo *TSI : TTE->
getArgs()) {
5474 mangleType(TSI->getType());
5480 case Expr::CXXThrowExprClass: {
5494 case Expr::CXXTypeidExprClass: {
5509 case Expr::CXXDeleteExprClass: {
5520 case Expr::UnaryOperatorClass: {
5529 case Expr::ArraySubscriptExprClass: {
5536 mangleExpression(AE->
getLHS());
5537 mangleExpression(AE->
getRHS());
5541 case Expr::MatrixSingleSubscriptExprClass: {
5545 mangleExpression(ME->
getBase());
5550 case Expr::MatrixSubscriptExprClass: {
5554 mangleExpression(ME->
getBase());
5560 case Expr::CompoundAssignOperatorClass:
5561 case Expr::BinaryOperatorClass: {
5569 mangleExpression(BO->
getLHS());
5570 mangleExpression(BO->
getRHS());
5574 case Expr::CXXRewrittenBinaryOperatorClass: {
5577 CXXRewrittenBinaryOperator::DecomposedForm Decomposed =
5581 mangleExpression(Decomposed.
LHS);
5582 mangleExpression(Decomposed.
RHS);
5586 case Expr::ConditionalOperatorClass: {
5589 mangleOperatorName(OO_Conditional, 3);
5590 mangleExpression(CO->
getCond());
5591 mangleExpression(CO->
getLHS(), Arity);
5592 mangleExpression(CO->
getRHS(), Arity);
5596 case Expr::ImplicitCastExprClass: {
5597 ImplicitlyConvertedToType = E->
getType();
5602 case Expr::ObjCBridgedCastExprClass: {
5608 mangleCastExpression(E,
"cv");
5612 case Expr::CStyleCastExprClass:
5614 mangleCastExpression(E,
"cv");
5617 case Expr::CXXFunctionalCastExprClass: {
5621 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5622 if (CCE->getParenOrBraceRange().isInvalid())
5623 Sub = CCE->getArg(0)->IgnoreImplicit();
5624 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5625 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5626 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5629 mangleInitListElements(IL);
5632 mangleCastExpression(E,
"cv");
5637 case Expr::CXXStaticCastExprClass:
5639 mangleCastExpression(E,
"sc");
5641 case Expr::CXXDynamicCastExprClass:
5643 mangleCastExpression(E,
"dc");
5645 case Expr::CXXReinterpretCastExprClass:
5647 mangleCastExpression(E,
"rc");
5649 case Expr::CXXConstCastExprClass:
5651 mangleCastExpression(E,
"cc");
5653 case Expr::CXXAddrspaceCastExprClass:
5655 mangleCastExpression(E,
"ac");
5658 case Expr::CXXOperatorCallExprClass: {
5667 for (
unsigned i = 0; i != NumArgs; ++i)
5668 mangleExpression(CE->
getArg(i));
5672 case Expr::ParenExprClass:
5676 case Expr::ConceptSpecializationExprClass: {
5678 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5683 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5689 mangleUnresolvedName(
5690 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5691 CSE->getConceptNameInfo().getName(),
5692 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5693 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5697 case Expr::RequiresExprClass: {
5703 if (RE->getLParenLoc().isValid()) {
5705 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5706 if (RE->getLocalParameters().empty()) {
5709 for (ParmVarDecl *Param : RE->getLocalParameters()) {
5717 FunctionTypeDepth.enterFunctionDeclSuffix();
5718 for (
const concepts::Requirement *Req : RE->getRequirements())
5719 mangleRequirement(RE->getExprLoc(), Req);
5720 FunctionTypeDepth.pop(saved);
5724 for (
const concepts::Requirement *Req : RE->getRequirements())
5725 mangleRequirement(RE->getExprLoc(), Req);
5731 case Expr::DeclRefExprClass:
5736 case Expr::SubstNonTypeTemplateParmPackExprClass:
5742 Out <<
"_SUBSTPACK_";
5745 case Expr::FunctionParmPackExprClass: {
5749 Out <<
"v110_SUBSTPACK";
5754 case Expr::DependentScopeDeclRefExprClass: {
5763 case Expr::CXXBindTemporaryExprClass:
5767 case Expr::ExprWithCleanupsClass:
5771 case Expr::FloatingLiteralClass: {
5778 case Expr::FixedPointLiteralClass:
5780 mangleFixedPointLiteral();
5783 case Expr::CharacterLiteralClass:
5787 Out << cast<CharacterLiteral>(E)->getValue();
5792 case Expr::ObjCBoolLiteralExprClass:
5795 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5799 case Expr::CXXBoolLiteralExprClass:
5802 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5806 case Expr::IntegerLiteralClass: {
5810 Value.setIsSigned(
true);
5815 case Expr::ImaginaryLiteralClass: {
5822 if (
const FloatingLiteral *Imag =
5823 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5825 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5827 mangleFloat(Imag->getValue());
5832 Value.setIsSigned(
true);
5833 mangleNumber(
Value);
5839 case Expr::StringLiteralClass: {
5849 case Expr::GNUNullExprClass:
5852 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5855 case Expr::CXXNullPtrLiteralExprClass: {
5861 case Expr::LambdaExprClass: {
5872 case Expr::PackExpansionExprClass:
5878 case Expr::SizeOfPackExprClass: {
5881 if (SPE->isPartiallySubstituted()) {
5883 for (
const auto &A : SPE->getPartialArguments())
5884 mangleTemplateArg(A,
false);
5890 mangleReferenceToPack(SPE->getPack());
5894 case Expr::MaterializeTemporaryExprClass:
5898 case Expr::CXXFoldExprClass: {
5901 if (FE->isLeftFold())
5902 Out << (FE->getInit() ?
"fL" :
"fl");
5904 Out << (FE->getInit() ?
"fR" :
"fr");
5906 if (FE->getOperator() == BO_PtrMemD)
5914 mangleExpression(FE->getLHS());
5916 mangleExpression(FE->getRHS());
5920 case Expr::PackIndexingExprClass: {
5924 mangleReferenceToPack(PE->getPackDecl());
5925 mangleExpression(PE->getIndexExpr());
5929 case Expr::CXXThisExprClass:
5934 case Expr::CoawaitExprClass:
5937 Out <<
"v18co_await";
5941 case Expr::DependentCoawaitExprClass:
5944 Out <<
"v18co_await";
5948 case Expr::CoyieldExprClass:
5951 Out <<
"v18co_yield";
5954 case Expr::SYCLUniqueStableNameExprClass: {
5958 Out <<
"u33__builtin_sycl_unique_stable_name";
5959 mangleType(USN->getTypeSourceInfo()->getType());
5964 case Expr::HLSLOutArgExprClass:
5966 "cannot mangle hlsl temporary value; mangling wrong thing?");
5967 case Expr::OpenACCAsteriskSizeExprClass: {
5969 DiagnosticsEngine &Diags = Context.getDiags();
5970 Diags.
Report(diag::err_unsupported_itanium_mangling)
5971 << UnsupportedItaniumManglingKind::OpenACCAsteriskSizeExpr;
5976 if (AsTemplateArg && !IsPrimaryExpr)
6008void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
6013 if (
unsigned nestingDepth = FunctionTypeDepth.getNestingDepth(parmDepth);
6014 nestingDepth == 0) {
6017 Out <<
"fL" << (nestingDepth - 1) <<
'p';
6025 &&
"parameter's type is still an array type?");
6027 if (
const DependentAddressSpaceType *DAST =
6028 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
6035 if (parmIndex != 0) {
6036 Out << (parmIndex - 1);
6041void CXXNameMangler::mangleCXXCtorType(
CXXCtorType T,
6042 const CXXRecordDecl *InheritedFrom) {
6069 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
6072 mangleName(InheritedFrom);
6075void CXXNameMangler::mangleCXXDtorType(
CXXDtorType T) {
6100 llvm_unreachable(
"Itanium ABI does not use vector deleting dtors");
6104void CXXNameMangler::mangleReferenceToPack(
const NamedDecl *Pack) {
6105 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
6106 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
6107 else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Pack))
6108 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
6109 else if (
const auto *TempTP = dyn_cast<TemplateTemplateParmDecl>(Pack))
6110 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
6144 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
6145 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
6146 if (!RD || !RD->isGenericLambda())
6162 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
6163 return TTP->hasTypeConstraint();
6180 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
6181 return NTTP->getType()->isInstantiationDependentType() ||
6182 NTTP->getType()->getContainedDeducedType();
6189 "A DeducedTemplateName shouldn't escape partial ordering");
6200 auto MangleTemplateParamListToString =
6202 unsigned DepthOffset) {
6203 llvm::raw_svector_ostream Stream(Buffer);
6204 CXXNameMangler(
Mangler.Context, Stream,
6205 WithTemplateDepthOffset{DepthOffset})
6206 .mangleTemplateParameterList(Params);
6209 MangleTemplateParamListToString(ParamTemplateHead,
6210 TTP->getTemplateParameters(), 0);
6214 MangleTemplateParamListToString(ArgTemplateHead,
6216 TTP->getTemplateParameters()->
getDepth());
6217 return ParamTemplateHead != ArgTemplateHead;
6227 return {
true,
nullptr};
6232 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
6233 "no parameter for argument");
6254 return {
true,
nullptr};
6269 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
6270 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
6271 return {NeedExactType,
nullptr};
6283void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6285 unsigned NumTemplateArgs) {
6288 TemplateArgManglingInfo Info(*
this, TN);
6289 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
6290 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
6292 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6296void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6297 const TemplateArgumentList &AL) {
6300 TemplateArgManglingInfo Info(*
this, TN);
6301 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6302 mangleTemplateArg(Info, i, AL[i]);
6304 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6308void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6309 ArrayRef<TemplateArgument> Args) {
6312 TemplateArgManglingInfo Info(*
this, TN);
6313 for (
unsigned i = 0; i != Args.size(); ++i) {
6314 mangleTemplateArg(Info, i, Args[i]);
6316 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6320void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6321 unsigned Index, TemplateArgument A) {
6322 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6325 if (ArgInfo.TemplateParameterToMangle &&
6326 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6333 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6336 mangleTemplateArg(A, ArgInfo.NeedExactType);
6339void CXXNameMangler::mangleTemplateArg(TemplateArgument A,
bool NeedExactType) {
6349 llvm_unreachable(
"Cannot mangle NULL template argument");
6377 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6378 TPO->getValue(),
true,
6383 ASTContext &Ctx = Context.getASTContext();
6391 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6399 ArrayRef<APValue::LValuePathEntry>(),
6412 true, NeedExactType);
6418 mangleTemplateArg(P, NeedExactType);
6424void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6425 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6426 mangleExpression(E, UnknownArity,
true);
6441 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6442 const ValueDecl *D = DRE->getDecl();
6451 mangleExpression(E);
6464 switch (
V.getKind()) {
6472 assert(RD &&
"unexpected type for record value");
6481 if (!FD->isUnnamedBitField() &&
6491 assert(RD &&
"unexpected type for union value");
6494 if (!FD->isUnnamedBitField())
6504 QualType ElemT(T->getArrayElementTypeNoTypeQual(), 0);
6505 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6513 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6520 llvm_unreachable(
"Matrix APValues not yet supported");
6526 return V.getFloat().isPosZero();
6529 return !
V.getFixedPoint().getValue();
6532 return V.getComplexFloatReal().isPosZero() &&
6533 V.getComplexFloatImag().isPosZero();
6536 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6539 return V.isNullPointer();
6542 return !
V.getMemberPointerDecl();
6545 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6552 T = AT->getElementType();
6554 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6597 Diags.
Report(UnionLoc, diag::err_unsupported_itanium_mangling)
6598 << UnsupportedItaniumManglingKind::UnnamedUnionNTTP;
6603void CXXNameMangler::mangleValueInTemplateArg(QualType T,
const APValue &
V,
6605 bool NeedExactType) {
6608 T = getASTContext().getUnqualifiedArrayType(T, Quals);
6611 bool IsPrimaryExpr =
true;
6612 auto NotPrimaryExpr = [&] {
6613 if (TopLevel && IsPrimaryExpr)
6615 IsPrimaryExpr =
false;
6619 switch (
V.getKind()) {
6628 llvm_unreachable(
"unexpected value kind in template argument");
6632 assert(RD &&
"unexpected type for record value");
6635 llvm::SmallVector<const FieldDecl *, 16> Fields(RD->
fields());
6638 (Fields.back()->isUnnamedBitField() ||
6640 V.getStructField(Fields.back()->getFieldIndex())))) {
6644 if (Fields.empty()) {
6645 while (!Bases.empty() &&
6647 V.getStructBase(Bases.size() - 1)))
6648 Bases = Bases.drop_back();
6655 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6656 mangleValueInTemplateArg(Bases[I].
getType(),
V.getStructBase(I),
false);
6657 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6658 if (Fields[I]->isUnnamedBitField())
6660 mangleValueInTemplateArg(Fields[I]->
getType(),
6661 V.getStructField(Fields[I]->getFieldIndex()),
6670 const FieldDecl *FD =
V.getUnionField();
6688 mangleSourceName(II);
6689 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6703 unsigned N =
V.getArraySize();
6705 N =
V.getArrayInitializedElts();
6710 for (
unsigned I = 0; I != N; ++I) {
6711 const APValue &Elem = I <
V.getArrayInitializedElts()
6712 ?
V.getArrayInitializedElt(I)
6713 :
V.getArrayFiller();
6714 mangleValueInTemplateArg(ElemT, Elem,
false);
6721 const VectorType *VT = T->
castAs<VectorType>();
6726 unsigned N =
V.getVectorLength();
6729 for (
unsigned I = 0; I != N; ++I)
6730 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6736 llvm_unreachable(
"Matrix template argument mangling not yet supported");
6739 mangleIntegerLiteral(T,
V.getInt());
6743 mangleFloatLiteral(T,
V.getFloat());
6747 mangleFixedPointLiteral();
6751 const ComplexType *CT = T->
castAs<ComplexType>();
6755 if (!
V.getComplexFloatReal().isPosZero() ||
6756 !
V.getComplexFloatImag().isPosZero())
6758 if (!
V.getComplexFloatImag().isPosZero())
6765 const ComplexType *CT = T->
castAs<ComplexType>();
6769 if (
V.getComplexIntReal().getBoolValue() ||
6770 V.getComplexIntImag().getBoolValue())
6772 if (
V.getComplexIntImag().getBoolValue())
6781 "unexpected type for LValue template arg");
6783 if (
V.isNullPointer()) {
6784 mangleNullPointer(T);
6788 APValue::LValueBase B =
V.getLValueBase();
6792 CharUnits Offset =
V.getLValueOffset();
6810 ASTContext &Ctx = Context.getASTContext();
6813 if (!
V.hasLValuePath()) {
6829 bool IsArrayToPointerDecayMangledAsDecl =
false;
6830 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6831 LangOptions::ClangABI::Ver11) {
6833 IsArrayToPointerDecayMangledAsDecl =
6834 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6835 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6839 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6840 !IsArrayToPointerDecayMangledAsDecl) {
6857 if (NeedExactType &&
6859 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6872 QualType TypeSoFar = B.
getType();
6873 if (
auto *VD = B.
dyn_cast<
const ValueDecl*>()) {
6877 }
else if (
auto *E = B.
dyn_cast<
const Expr*>()) {
6879 mangleExpression(E);
6880 }
else if (
auto TI = B.
dyn_cast<TypeInfoLValue>()) {
6883 mangleType(QualType(TI.getType(), 0));
6886 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6896 mangleNumber(
V.getLValueOffset().getQuantity());
6903 if (!
V.getLValueOffset().isZero())
6904 mangleNumber(
V.getLValueOffset().getQuantity());
6908 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6910 for (APValue::LValuePathEntry E :
V.getLValuePath()) {
6912 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6913 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6914 TypeSoFar = AT->getElementType();
6916 const Decl *D = E.getAsBaseOrMember().getPointer();
6917 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6942 if (!
V.getMemberPointerDecl()) {
6943 mangleNullPointer(T);
6947 ASTContext &Ctx = Context.getASTContext();
6950 if (!
V.getMemberPointerPath().empty()) {
6953 }
else if (NeedExactType &&
6955 T->
castAs<MemberPointerType>()->getPointeeType(),
6956 V.getMemberPointerDecl()->getType()) &&
6957 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6962 mangle(
V.getMemberPointerDecl());
6964 if (!
V.getMemberPointerPath().empty()) {
6974 if (TopLevel && !IsPrimaryExpr)
6978void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6988 Depth += TemplateDepthOffset;
6990 Out <<
'L' << (Depth - 1) <<
'_';
6996void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6999 }
else if (SeqID == 1) {
7006 MutableArrayRef<char> BufferRef(Buffer);
7007 MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
7009 for (; SeqID != 0; SeqID /= 36) {
7010 unsigned C = SeqID % 36;
7011 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
7014 Out.write(I.base(), I - BufferRef.rbegin());
7019void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
7020 bool result = mangleSubstitution(tname);
7021 assert(result &&
"no existing substitution for template name");
7027bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
7029 if (mangleStandardSubstitution(ND))
7033 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
7043bool CXXNameMangler::mangleSubstitution(QualType T) {
7046 return mangleSubstitution(RD);
7051 return mangleSubstitution(TypePtr);
7055 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7056 return mangleSubstitution(TD);
7059 return mangleSubstitution(
7063bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
7064 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
7065 if (I == Substitutions.end())
7068 unsigned SeqID = I->second;
7077bool CXXNameMangler::isSpecializedAs(QualType S, llvm::StringRef Name,
7086 const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
7087 if (!SD || !SD->getIdentifier()->isStr(Name))
7090 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7093 const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
7094 if (TemplateArgs.
size() != 1)
7097 if (TemplateArgs[0].getAsType() != A)
7100 if (SD->getSpecializedTemplate()->getOwningModuleForLinkage())
7109bool CXXNameMangler::isStdCharSpecialization(
7110 const ClassTemplateSpecializationDecl *SD, llvm::StringRef Name,
7111 bool HasAllocator) {
7116 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
7119 QualType A = TemplateArgs[0].getAsType();
7127 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
7131 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
7140bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
7142 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
7150 if (
const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
7151 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
7171 if (
const ClassTemplateSpecializationDecl *SD =
7172 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
7173 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
7182 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
7189 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
7196 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
7203 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
7213void CXXNameMangler::addSubstitution(QualType T) {
7216 addSubstitution(RD);
7222 addSubstitution(TypePtr);
7226 if (TemplateDecl *TD =
Template.getAsTemplateDecl())
7227 return addSubstitution(TD);
7233void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
7234 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
7235 Substitutions[Ptr] = SeqID++;
7238void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
7239 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
7240 if (
Other->SeqID > SeqID) {
7241 Substitutions.swap(
Other->Substitutions);
7242 SeqID =
Other->SeqID;
7246CXXNameMangler::AbiTagList
7247CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
7249 if (DisableDerivedAbiTags)
7250 return AbiTagList();
7252 llvm::raw_null_ostream NullOutStream;
7253 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
7254 TrackReturnTypeTags.disableDerivedAbiTags();
7256 const FunctionProtoType *Proto =
7258 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
7259 TrackReturnTypeTags.FunctionTypeDepth.enterFunctionDeclSuffix();
7261 TrackReturnTypeTags.FunctionTypeDepth.leaveFunctionDeclSuffix();
7262 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
7264 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7267CXXNameMangler::AbiTagList
7268CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
7270 if (DisableDerivedAbiTags)
7271 return AbiTagList();
7273 llvm::raw_null_ostream NullOutStream;
7274 CXXNameMangler TrackVariableType(*
this, NullOutStream);
7275 TrackVariableType.disableDerivedAbiTags();
7277 TrackVariableType.mangleType(VD->
getType());
7279 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
7282bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
7283 const VarDecl *VD) {
7284 llvm::raw_null_ostream NullOutStream;
7285 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
7286 TrackAbiTags.mangle(VD);
7287 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7292void ItaniumMangleContextImpl::mangleCXXName(GlobalDecl GD,
7296 "Invalid mangleName() call, argument is not a variable or function!");
7298 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
7299 getASTContext().getSourceManager(),
7300 "Mangling declaration");
7302 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7304 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7305 return Mangler.mangle(GlobalDecl(CD,
Type));
7308 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7310 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7311 return Mangler.mangle(GlobalDecl(DD,
Type));
7314 CXXNameMangler Mangler(*
this, Out, D);
7318void ItaniumMangleContextImpl::mangleCXXCtorComdat(
const CXXConstructorDecl *D,
7320 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7324void ItaniumMangleContextImpl::mangleCXXDtorComdat(
const CXXDestructorDecl *D,
7326 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7348 auto &LangOpts = Context.getLangOpts();
7351 Context.baseForVTableAuthentication(ThisRD);
7352 unsigned TypedDiscriminator =
7353 Context.getPointerAuthVTablePointerDiscriminator(ThisRD);
7354 Mangler.mangleVendorQualifier(
"__vtptrauth");
7355 auto &ManglerStream = Mangler.getStream();
7356 ManglerStream <<
"I";
7357 if (
const auto *ExplicitAuth =
7358 PtrauthClassRD->
getAttr<VTablePointerAuthenticationAttr>()) {
7359 ManglerStream <<
"Lj" << ExplicitAuth->getKey();
7361 if (ExplicitAuth->getAddressDiscrimination() ==
7362 VTablePointerAuthenticationAttr::DefaultAddressDiscrimination)
7363 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7365 ManglerStream <<
"Lb"
7366 << (ExplicitAuth->getAddressDiscrimination() ==
7367 VTablePointerAuthenticationAttr::AddressDiscrimination);
7369 switch (ExplicitAuth->getExtraDiscrimination()) {
7370 case VTablePointerAuthenticationAttr::DefaultExtraDiscrimination: {
7371 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7372 ManglerStream <<
"Lj" << TypedDiscriminator;
7374 ManglerStream <<
"Lj" << 0;
7377 case VTablePointerAuthenticationAttr::TypeDiscrimination:
7378 ManglerStream <<
"Lj" << TypedDiscriminator;
7380 case VTablePointerAuthenticationAttr::CustomDiscrimination:
7381 ManglerStream <<
"Lj" << ExplicitAuth->getCustomDiscriminationValue();
7383 case VTablePointerAuthenticationAttr::NoExtraDiscrimination:
7384 ManglerStream <<
"Lj" << 0;
7388 ManglerStream <<
"Lj"
7389 << (
unsigned)VTablePointerAuthenticationAttr::DefaultKey;
7390 ManglerStream <<
"Lb" << LangOpts.PointerAuthVTPtrAddressDiscrimination;
7391 if (LangOpts.PointerAuthVTPtrTypeDiscrimination)
7392 ManglerStream <<
"Lj" << TypedDiscriminator;
7394 ManglerStream <<
"Lj" << 0;
7396 ManglerStream <<
"E";
7399void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7400 const ThunkInfo &Thunk,
7401 bool ElideOverrideInfo,
7411 "Use mangleCXXDtor for destructor decls!");
7412 CXXNameMangler Mangler(*
this, Out);
7413 Mangler.getStream() <<
"_ZT";
7415 Mangler.getStream() <<
'c';
7426 Mangler.mangleFunctionEncoding(MD);
7427 if (!ElideOverrideInfo)
7431void ItaniumMangleContextImpl::mangleCXXDtorThunk(
const CXXDestructorDecl *DD,
7433 const ThunkInfo &Thunk,
7434 bool ElideOverrideInfo,
7438 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7439 Mangler.getStream() <<
"_ZT";
7441 auto &ThisAdjustment = Thunk.
This;
7443 Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
7444 ThisAdjustment.Virtual.Itanium.VCallOffsetOffset);
7446 Mangler.mangleFunctionEncoding(GlobalDecl(DD,
Type));
7447 if (!ElideOverrideInfo)
7452void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7456 CXXNameMangler Mangler(*
this, Out);
7459 Mangler.getStream() <<
"_ZGV";
7460 Mangler.mangleName(D);
7463void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7468 Out <<
"__cxx_global_var_init";
7471void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7474 CXXNameMangler Mangler(*
this, Out);
7475 Mangler.getStream() <<
"__dtor_";
7476 if (shouldMangleDeclName(D))
7479 Mangler.getStream() << D->
getName();
7482void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7486 CXXNameMangler Mangler(*
this, Out);
7487 Mangler.getStream() <<
"__finalize_";
7488 if (shouldMangleDeclName(D))
7491 Mangler.getStream() << D->
getName();
7494void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7495 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7496 CXXNameMangler Mangler(*
this, Out);
7497 Mangler.getStream() <<
"__filt_";
7499 if (shouldMangleDeclName(EnclosingFD))
7500 Mangler.mangle(EnclosingDecl);
7502 Mangler.getStream() << EnclosingFD->getName();
7505void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7506 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7507 CXXNameMangler Mangler(*
this, Out);
7508 Mangler.getStream() <<
"__fin_";
7510 if (shouldMangleDeclName(EnclosingFD))
7511 Mangler.mangle(EnclosingDecl);
7513 Mangler.getStream() << EnclosingFD->getName();
7516void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7519 CXXNameMangler Mangler(*
this, Out);
7520 Mangler.getStream() <<
"_ZTH";
7521 Mangler.mangleName(D);
7525ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7528 CXXNameMangler Mangler(*
this, Out);
7529 Mangler.getStream() <<
"_ZTW";
7530 Mangler.mangleName(D);
7533void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7534 unsigned ManglingNumber,
7538 CXXNameMangler Mangler(*
this, Out);
7539 Mangler.getStream() <<
"_ZGR";
7540 Mangler.mangleName(D);
7541 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7542 Mangler.mangleSeqID(ManglingNumber - 1);
7545void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7548 CXXNameMangler Mangler(*
this, Out);
7549 Mangler.getStream() <<
"_ZTV";
7550 Mangler.mangleCXXRecordDecl(RD);
7553void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7556 CXXNameMangler Mangler(*
this, Out);
7557 Mangler.getStream() <<
"_ZTT";
7558 Mangler.mangleCXXRecordDecl(RD);
7561void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7563 const CXXRecordDecl *
Type,
7566 CXXNameMangler Mangler(*
this, Out);
7567 Mangler.getStream() <<
"_ZTC";
7570 bool SuppressSubstitution =
7571 getASTContext().getLangOpts().getClangABICompat() <=
7572 LangOptions::ClangABI::Ver19;
7573 Mangler.mangleCXXRecordDecl(RD, SuppressSubstitution);
7574 Mangler.getStream() << Offset;
7575 Mangler.getStream() <<
'_';
7576 Mangler.mangleCXXRecordDecl(
Type);
7579void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) {
7581 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7582 CXXNameMangler Mangler(*
this, Out);
7583 Mangler.getStream() <<
"_ZTI";
7584 Mangler.mangleType(Ty);
7587void ItaniumMangleContextImpl::mangleCXXRTTIName(
7588 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7590 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7591 Mangler.getStream() <<
"_ZTS";
7592 Mangler.mangleType(Ty);
7595void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7596 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7597 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7600void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7601 llvm_unreachable(
"Can't mangle string literals");
7604void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7606 CXXNameMangler Mangler(*
this, Out);
7607 Mangler.mangleLambdaSig(Lambda);
7610void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7613 CXXNameMangler Mangler(*
this, Out);
7614 Mangler.getStream() <<
"_ZGI";
7618 auto Partition = M->
Name.find(
':');
7619 Mangler.mangleModuleNamePrefix(
7620 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7628 return new ItaniumMangleContextImpl(
7631 return std::nullopt;
7640 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
static bool isUniqueInternalLinkageDecl(GlobalDecl GD, CodeGenModule &CGM)
@ LLVM_MARK_AS_BITMASK_ENUM
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
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.
QualType getElementType() const
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
unsigned getNumBits() const
QualType getPointeeType() const
This class is used for builtin types like 'int'.
bool isSignedInteger() const
Represents a base class of a C++ class.
ConstExprIterator const_arg_iterator
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
bool isGlobalDelete() const
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the member name.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
NamedDecl * getFirstQualifierFoundInScope() const
Retrieve the first part of the nested-name-specifier that was found in the scope of the member access...
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e.
ConstExprIterator const_arg_iterator
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Represents a C++ struct/union/class.
Decl * getLambdaContextDecl() const
Retrieve the declaration that provides additional context for a lambda, when the normal declaration c...
TemplateParameterList * getGenericLambdaTemplateParameterList() const
Retrieve the generic lambda's template parameter list.
base_class_iterator bases_end()
bool isLambda() const
Determine whether this class describes a lambda function object.
unsigned getLambdaManglingNumber() const
If this is the closure type of a lambda expression, retrieve the number to be used for name mangling ...
base_class_iterator bases_begin()
TypeSourceInfo * getLambdaTypeInfo() const
ArrayRef< NamedDecl * > getLambdaExplicitTemplateParameters() const
Retrieve the lambda template parameters that were specified explicitly.
CXXMethodDecl * getLambdaStaticInvoker() const
Retrieve the lambda static invoker, the address of which is returned by the conversion operator,...
const Expr * getSubExpr() const
bool isTypeOperand() const
QualType getTypeOperand(const ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
Expr * getExprOperand() const
bool isListInitialization() const
Determine whether this expression models list-initialization.
Expr * getArg(unsigned I)
unsigned getNumArgs() const
Retrieve the number of arguments.
Expr * getExprOperand() const
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this __uuidof() expression after various required adjustments (removing...
bool isTypeOperand() const
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
QualType getElementType() const
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
llvm::APInt getSize() const
Return the constant array size as an APInt.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isRequiresExprBody() const
bool isFileContext() const
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
Expr * getNumBitsExpr() const
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
unsigned getNumTemplateArgs() const
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
TemplateArgumentLoc const * getTemplateArgs() const
Expr * getSizeExpr() const
Expr * getSizeExpr() const
QualType getElementType() const
Expr * getColumnExpr() const
Expr * getRowExpr() const
IdentifierOrOverloadedOperator getName() const
Represents a vector type where either the type or size is dependent.
Expr * getSizeExpr() const
VectorKind getVectorKind() const
SourceLocation getAttributeLoc() const
QualType getElementType() const
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
llvm::APSInt getInitVal() const
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
llvm::APFloat getValue() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isMemberLikeConstrainedFriend() const
Determine whether a function is a friend function that cannot be redeclared outside of its class,...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ValueDecl * getParameterPack() const
Get the parameter pack which this expression refers to.
Represents a prototype with parameter type info, e.g.
ExtParameterInfo getExtParameterInfo(unsigned I) const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
ArrayRef< QualType > exceptions() const
bool hasInstantiationDependentExceptionSpec() const
Return whether this function has an instantiation-dependent exception spec.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
CallingConv getCC() const
bool getProducesResult() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC?
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
@ SME_AgnosticZAStateMask
static ArmStateValue getArmZT0State(unsigned AttrBits)
static ArmStateValue getArmZAState(unsigned AttrBits)
QualType getReturnType() const
GlobalDecl - represents a global declaration.
CXXCtorType getCtorType() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
CXXDtorType getDtorType() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
const Expr * getSubExpr() const
Describes an C or C++ initializer list.
unsigned getNumInits() const
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
ItaniumMangleContext(ASTContext &C, DiagnosticsEngine &D, bool IsAux=false)
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
UnsignedOrNone(*)(ASTContext &, const NamedDecl *) DiscriminatorOverrideTy
QualType getElementType() const
Returns type of the elements being stored in the matrix.
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
NestedNameSpecifier getQualifier() const
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
std::string Name
The name of this module.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
bool isExternallyVisible() const
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
static NamespaceDecl * Create(ASTContext &C, DeclContext *DC, bool Inline, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const Type * getAsType() const
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
NestedNameSpecifier getQualifier() const
Fetches the nested-name qualifier, if one was given.
decls_iterator decls_begin() const
unsigned getNumDecls() const
Gets the number of declarations in the unresolved set.
TemplateArgumentLoc const * getTemplateArgs() const
unsigned getNumTemplateArgs() const
DeclarationName getName() const
Gets the name looked up.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
Represents a parameter to a function.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
unsigned getFunctionScopeDepth() const
QualType getPointeeType() const
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getCanonicalType() const
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
void * getAsOpaquePtr() const
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool hasUnaligned() const
bool hasAddressSpace() const
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
QualType getPointeeType() const
Encodes a location in the source.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const char * getStmtClassName() const
TemplateName getReplacement() const
TypedefNameDecl * getTypedefNameForAnonDecl() const
virtual const char * getFloat128Mangling() const
Return the mangled code of __float128.
virtual const char * getIbm128Mangling() const
Return the mangled code of __ibm128.
virtual const char * getLongDoubleMangling() const
Return the mangled code of long double.
virtual const char * getBFloat16Mangling() const
Return the mangled code of bfloat.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Location wrapper for a TemplateArgument.
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
bool isDependent() const
Whether this template argument is dependent on a template parameter such that its result can change f...
bool isInstantiationDependent() const
Whether this template argument is dependent on a template parameter.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
std::pair< TemplateName, DefaultArguments > getTemplateDeclAndDefaultArgs() const
Retrieves the underlying template name that this template name refers to, along with the deduced defa...
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
TemplateDecl * getNamedConcept() const
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
TypeTrait getTrait() const
Determine which type trait this expression uses.
The base class of the type hierarchy.
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isVoidPointerType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool isSVESizelessBuiltinType() const
Returns true for SVE scalable vector types.
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const Type * getArrayElementTypeNoTypeQual() const
If this is an array type, return the element type of the array, potentially with type qualifiers miss...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isOpenCLSpecificType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isPointerOrReferenceType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
Expr * getSubExpr() const
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
UnresolvedUsingTypenameDecl * getDecl() const
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Represents a variable template specialization, which refers to a variable template with a given set o...
Expr * getSizeExpr() const
Represents a GCC generic vector type.
unsigned getNumElements() const
VectorKind getVectorKind() const
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
@ 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.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_DefaultClosure
Default closure variant of a ctor.
@ Ctor_CopyingClosure
Copying closure variant of a ctor.
@ Ctor_Complete
Complete object ctor.
@ Ctor_Comdat
The COMDAT used for ctors.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
llvm::StringRef getParameterABISpelling(ParameterABI kind)
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
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
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
@ Template
We are parsing a template declaration.
CXXDtorType
C++ destructor types.
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
@ Type
The name was classified as a type.
@ Concept
The name was classified as a concept name.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ Deduced
The normal deduced case.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Other
Other implicit parameter.
@ EST_Dynamic
throw(T1, T2)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Information about how to mangle a template argument.
bool NeedExactType
Do we need to mangle the template argument with an exactly correct type?
const NamedDecl * TemplateParameterToMangle
If we need to prefix the mangling with a mangling of the template parameter, the corresponding parame...
bool isOverloadable()
Determine whether the resolved template might be overloaded on its template parameter list.
TemplateArgManglingInfo(const CXXNameMangler &Mangler, TemplateName TN)
bool needToMangleTemplateParam(const NamedDecl *Param, const TemplateArgument &Arg)
Determine whether we need to prefix this <template-arg> mangling with a <template-param-decl>.
const NamedDecl * UnresolvedExpandedPack
const CXXNameMangler & Mangler
TemplateDecl * ResolvedTemplate
Info getArgInfo(unsigned ParamIdx, const TemplateArgument &Arg)
Determine information about how this template argument should be mangled.
const Expr * getTrailingRequiresClauseToMangle()
Determine if we should mangle a requires-clause after the template argument list.
bool SeenPackExpansionIntoNonPack
ArrayRef< TemplateArgumentLoc > arguments() const
const Expr * ConstraintExpr
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
The this pointer adjustment as well as an optional return adjustment for a thunk.
ThisAdjustment This
The this pointer adjustment.
ReturnAdjustment Return
The return adjustment.
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.