36#include "llvm/ADT/StringExtras.h"
37#include "llvm/Support/ErrorHandling.h"
38#include "llvm/Support/raw_ostream.h"
39#include "llvm/TargetParser/RISCVTargetParser.h"
46static bool isLocalContainerContext(
const DeclContext *DC) {
47 return isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC) || isa<BlockDecl>(DC);
52 return ftd->getTemplatedDecl();
59 return (fn ? getStructor(fn) :
decl);
62static bool isLambda(
const NamedDecl *ND) {
70static const unsigned UnknownArity = ~0
U;
73 typedef std::pair<const DeclContext*, IdentifierInfo*> DiscriminatorKeyTy;
74 llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
75 llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
76 const DiscriminatorOverrideTy DiscriminatorOverride =
nullptr;
79 bool NeedsUniqueInternalLinkageNames =
false;
82 explicit ItaniumMangleContextImpl(
84 DiscriminatorOverrideTy DiscriminatorOverride,
bool IsAux =
false)
86 DiscriminatorOverride(DiscriminatorOverride) {}
98 NeedsUniqueInternalLinkageNames =
true;
103 raw_ostream &)
override;
106 raw_ostream &)
override;
108 raw_ostream &)
override;
115 bool NormalizeIntegers)
override;
117 bool NormalizeIntegers)
override;
124 raw_ostream &Out)
override;
127 raw_ostream &Out)
override;
129 raw_ostream &Out)
override;
132 raw_ostream &)
override;
140 bool getNextDiscriminator(
const NamedDecl *ND,
unsigned &disc) {
146 if (
const TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
147 if (Tag->getName().empty() && !Tag->getTypedefNameForAnonDecl())
154 if (discriminator == 1)
156 disc = discriminator - 2;
161 unsigned &discriminator = Uniquifier[ND];
162 if (!discriminator) {
163 const DeclContext *DC = getEffectiveDeclContext(ND);
164 discriminator = ++Discriminator[std::make_pair(DC, ND->
getIdentifier())];
166 if (discriminator == 1)
168 disc = discriminator-2;
175 assert(Lambda->
isLambda() &&
"RD must be a lambda!");
176 std::string Name(
"<lambda");
180 const ParmVarDecl *Parm = dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
185 unsigned DefaultArgNo =
187 Name += llvm::utostr(DefaultArgNo);
191 if (LambdaManglingNumber)
192 LambdaId = LambdaManglingNumber;
196 Name += llvm::utostr(LambdaId);
202 return DiscriminatorOverride;
209 return getEffectiveDeclContext(cast<Decl>(DC));
212 bool isInternalLinkageDecl(
const NamedDecl *ND);
218class CXXNameMangler {
219 ItaniumMangleContextImpl &Context;
223 bool NormalizeIntegers =
false;
225 bool NullOut =
false;
230 bool DisableDerivedAbiTags =
false;
236 unsigned StructorType = 0;
241 unsigned TemplateDepthOffset = 0;
246 class FunctionTypeDepthState {
249 enum { InResultTypeMask = 1 };
252 FunctionTypeDepthState() =
default;
255 unsigned getDepth()
const {
260 bool isInResultType()
const {
261 return Bits & InResultTypeMask;
264 FunctionTypeDepthState push() {
265 FunctionTypeDepthState tmp = *
this;
266 Bits = (Bits & ~InResultTypeMask) + 2;
270 void enterResultType() {
271 Bits |= InResultTypeMask;
274 void leaveResultType() {
275 Bits &= ~InResultTypeMask;
278 void pop(FunctionTypeDepthState saved) {
279 assert(getDepth() == saved.getDepth() + 1);
294 class AbiTagState final {
296 explicit AbiTagState(AbiTagState *&Head) : LinkHead(Head) {
302 AbiTagState(
const AbiTagState &) =
delete;
303 AbiTagState &operator=(
const AbiTagState &) =
delete;
305 ~AbiTagState() { pop(); }
307 void write(raw_ostream &Out,
const NamedDecl *ND,
308 const AbiTagList *AdditionalAbiTags) {
310 if (!isa<FunctionDecl>(ND) && !isa<VarDecl>(ND)) {
312 !AdditionalAbiTags &&
313 "only function and variables need a list of additional abi tags");
314 if (
const auto *NS = dyn_cast<NamespaceDecl>(ND)) {
315 if (
const auto *AbiTag = NS->getAttr<AbiTagAttr>()) {
316 UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
317 AbiTag->tags().end());
325 if (
const auto *AbiTag = ND->
getAttr<AbiTagAttr>()) {
326 UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
327 AbiTag->tags().end());
328 TagList.insert(TagList.end(), AbiTag->tags().begin(),
329 AbiTag->tags().end());
332 if (AdditionalAbiTags) {
333 UsedAbiTags.insert(UsedAbiTags.end(), AdditionalAbiTags->begin(),
334 AdditionalAbiTags->end());
335 TagList.insert(TagList.end(), AdditionalAbiTags->begin(),
336 AdditionalAbiTags->end());
340 TagList.erase(std::unique(TagList.begin(), TagList.end()), TagList.end());
342 writeSortedUniqueAbiTags(Out, TagList);
345 const AbiTagList &getUsedAbiTags()
const {
return UsedAbiTags; }
346 void setUsedAbiTags(
const AbiTagList &AbiTags) {
347 UsedAbiTags = AbiTags;
350 const AbiTagList &getEmittedAbiTags()
const {
351 return EmittedAbiTags;
354 const AbiTagList &getSortedUniqueUsedAbiTags() {
355 llvm::sort(UsedAbiTags);
356 UsedAbiTags.erase(std::unique(UsedAbiTags.begin(), UsedAbiTags.end()),
363 AbiTagList UsedAbiTags;
365 AbiTagList EmittedAbiTags;
367 AbiTagState *&LinkHead;
368 AbiTagState *
Parent =
nullptr;
371 assert(LinkHead ==
this &&
372 "abi tag link head must point to us on destruction");
375 UsedAbiTags.begin(), UsedAbiTags.end());
376 Parent->EmittedAbiTags.insert(
Parent->EmittedAbiTags.end(),
377 EmittedAbiTags.begin(),
378 EmittedAbiTags.end());
383 void writeSortedUniqueAbiTags(raw_ostream &Out,
const AbiTagList &AbiTags) {
384 for (
const auto &Tag : AbiTags) {
385 EmittedAbiTags.push_back(Tag);
393 AbiTagState *AbiTags =
nullptr;
394 AbiTagState AbiTagsRoot;
396 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
397 llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
399 ASTContext &getASTContext()
const {
return Context.getASTContext(); }
402 return Context.getASTContext().
getLangOpts().getClangABICompat() <= Ver;
411 llvm::StringRef Name,
bool HasAllocator);
414 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
415 const NamedDecl *D =
nullptr,
bool NullOut_ =
false)
416 : Context(
C), Out(Out_), NullOut(NullOut_), Structor(getStructor(D)),
417 AbiTagsRoot(AbiTags) {
419 assert(!D || (!isa<CXXDestructorDecl>(D) &&
420 !isa<CXXConstructorDecl>(D)));
422 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
424 : Context(
C), Out(Out_), Structor(getStructor(D)), StructorType(
Type),
425 AbiTagsRoot(AbiTags) {}
426 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
428 : Context(
C), Out(Out_), Structor(getStructor(D)), StructorType(
Type),
429 AbiTagsRoot(AbiTags) {}
431 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out_,
432 bool NormalizeIntegers_)
433 : Context(
C), Out(Out_), NormalizeIntegers(NormalizeIntegers_),
434 NullOut(
false), Structor(nullptr), AbiTagsRoot(AbiTags) {}
435 CXXNameMangler(CXXNameMangler &Outer, raw_ostream &Out_)
436 : Context(Outer.Context), Out(Out_), Structor(Outer.Structor),
437 StructorType(Outer.StructorType), SeqID(Outer.SeqID),
438 FunctionTypeDepth(Outer.FunctionTypeDepth), AbiTagsRoot(AbiTags),
439 Substitutions(Outer.Substitutions),
440 ModuleSubstitutions(Outer.ModuleSubstitutions) {}
442 CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_)
443 : CXXNameMangler(Outer, (raw_ostream &)Out_) {
447 struct WithTemplateDepthOffset {
unsigned Offset; };
448 CXXNameMangler(ItaniumMangleContextImpl &
C, raw_ostream &Out,
449 WithTemplateDepthOffset Offset)
450 : CXXNameMangler(
C, Out) {
451 TemplateDepthOffset = Offset.Offset;
454 raw_ostream &getStream() {
return Out; }
456 void disableDerivedAbiTags() { DisableDerivedAbiTags =
true; }
457 static bool shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
const VarDecl *VD);
460 void mangleCallOffset(int64_t NonVirtual, int64_t
Virtual);
461 void mangleNumber(
const llvm::APSInt &I);
462 void mangleNumber(int64_t Number);
463 void mangleFloat(
const llvm::APFloat &F);
465 void mangleSeqID(
unsigned SeqID);
468 void mangleNameOrStandardSubstitution(
const NamedDecl *ND);
470 void mangleModuleNamePrefix(StringRef Name,
bool IsPartition =
false);
474 bool mangleSubstitution(
const NamedDecl *ND);
482 bool mangleStandardSubstitution(
const NamedDecl *ND);
484 void addSubstitution(
const NamedDecl *ND) {
487 addSubstitution(
reinterpret_cast<uintptr_t>(ND));
492 addSubstitution(
reinterpret_cast<uintptr_t>(NNS));
498 void extendSubstitutions(CXXNameMangler*
Other);
501 bool recursive =
false);
505 unsigned NumTemplateArgs,
506 unsigned KnownArity = UnknownArity);
508 void mangleFunctionEncodingBareType(
const FunctionDecl *FD);
511 const AbiTagList *AdditionalAbiTags);
512 void mangleModuleName(
const NamedDecl *ND);
516 const AbiTagList *AdditionalAbiTags) {
517 mangleUnqualifiedName(GD, cast<NamedDecl>(GD.
getDecl())->getDeclName(), DC,
518 UnknownArity, AdditionalAbiTags);
522 const AbiTagList *AdditionalAbiTags);
524 const AbiTagList *AdditionalAbiTags);
526 const AbiTagList *AdditionalAbiTags);
530 void mangleSourceNameWithAbiTags(
531 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags =
nullptr);
533 const AbiTagList *AdditionalAbiTags);
538 void mangleTypeConstraint(
const ConceptDecl *Concept,
541 void mangleRequiresClause(
const Expr *RequiresClause);
544 const AbiTagList *AdditionalAbiTags,
545 bool NoFunction=
false);
548 void mangleNestedNameWithClosurePrefix(
GlobalDecl GD,
550 const AbiTagList *AdditionalAbiTags);
552 void manglePrefix(
const DeclContext *DC,
bool NoFunction=
false);
554 void mangleTemplatePrefix(
GlobalDecl GD,
bool NoFunction=
false);
557 void mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction =
false);
558 bool mangleUnresolvedTypeOrSimpleId(
QualType DestroyedType,
559 StringRef Prefix =
"");
562 void mangleVendorQualifier(StringRef qualifier);
569#define ABSTRACT_TYPE(CLASS, PARENT)
570#define NON_CANONICAL_TYPE(CLASS, PARENT)
571#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
572#include "clang/AST/TypeNodes.inc"
574 void mangleType(
const TagType*);
576 static StringRef getCallingConvQualifierName(
CallingConv CC);
583 void mangleAArch64NeonVectorType(
const VectorType *
T);
585 void mangleAArch64FixedSveVectorType(
const VectorType *
T);
587 void mangleRISCVFixedRVVVectorType(
const VectorType *
T);
591 void mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V);
592 void mangleFixedPointLiteral();
595 void mangleMemberExprBase(
const Expr *base,
bool isArrow);
596 void mangleMemberExpr(
const Expr *base,
bool isArrow,
601 unsigned NumTemplateArgs,
602 unsigned knownArity);
603 void mangleCastExpression(
const Expr *E, StringRef CastEncoding);
604 void mangleInitListElements(
const InitListExpr *InitList);
607 void mangleExpression(
const Expr *E,
unsigned Arity = UnknownArity,
608 bool AsTemplateArg =
false);
612 struct TemplateArgManglingInfo;
615 unsigned NumTemplateArgs);
618 void mangleTemplateArg(TemplateArgManglingInfo &Info,
unsigned Index,
621 void mangleTemplateArgExpr(
const Expr *E);
623 bool NeedExactType =
false);
625 void mangleTemplateParameter(
unsigned Depth,
unsigned Index);
630 const AbiTagList *AdditionalAbiTags);
633 AbiTagList makeFunctionReturnTypeTags(
const FunctionDecl *FD);
635 AbiTagList makeVariableTypeTags(
const VarDecl *VD);
643 getASTContext(), getASTContext().getTranslationUnitDecl(),
645 &getASTContext().Idents.get(
"std"),
655ItaniumMangleContextImpl::getEffectiveDeclContext(
const Decl *D) {
665 dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
666 return ContextParam->getDeclContext();
670 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
672 dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
673 return ContextParam->getDeclContext();
681 if (D == getASTContext().getVaListTagDecl()) {
682 const llvm::Triple &
T = getASTContext().getTargetInfo().getTriple();
683 if (
T.isARM() ||
T.isThumb() ||
T.isAArch64())
684 return getStdNamespace();
688 if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC) ||
689 isa<OMPDeclareMapperDecl>(DC)) {
690 return getEffectiveDeclContext(cast<Decl>(DC));
693 if (
const auto *VD = dyn_cast<VarDecl>(D))
695 return getASTContext().getTranslationUnitDecl();
697 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
699 return getASTContext().getTranslationUnitDecl();
702 if (FD->isMemberLikeConstrainedFriend() &&
703 getASTContext().getLangOpts().getClangABICompat() >
704 LangOptions::ClangABI::Ver17)
711bool ItaniumMangleContextImpl::isInternalLinkageDecl(
const NamedDecl *ND) {
714 getEffectiveDeclContext(ND)->isFileContext() &&
721bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
723 if (!NeedsUniqueInternalLinkageNames || !ND)
726 const auto *FD = dyn_cast<FunctionDecl>(ND);
735 if (isInternalLinkageDecl(ND))
741bool ItaniumMangleContextImpl::shouldMangleCXXName(
const NamedDecl *D) {
742 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
745 if (FD->hasAttr<OverloadableAttr>())
761 if (FD->isMSVCRTEntryPoint())
775 if (!getASTContext().getLangOpts().
CPlusPlus)
778 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
780 if (isa<DecompositionDecl>(VD))
789 const DeclContext *DC = getEffectiveDeclContext(D);
793 DC = getEffectiveParentContext(DC);
795 !CXXNameMangler::shouldHaveAbiTags(*
this, VD) &&
796 !isa<VarTemplateSpecializationDecl>(VD) &&
797 !VD->getOwningModuleForLinkage())
804void CXXNameMangler::writeAbiTags(
const NamedDecl *ND,
805 const AbiTagList *AdditionalAbiTags) {
806 assert(AbiTags &&
"require AbiTagState");
807 AbiTags->write(Out, ND, DisableDerivedAbiTags ?
nullptr : AdditionalAbiTags);
810void CXXNameMangler::mangleSourceNameWithAbiTags(
811 const NamedDecl *ND,
const AbiTagList *AdditionalAbiTags) {
813 writeAbiTags(ND, AdditionalAbiTags);
821 if (isa<FunctionDecl>(GD.
getDecl()))
822 mangleFunctionEncoding(GD);
827 dyn_cast<IndirectFieldDecl>(GD.
getDecl()))
828 mangleName(IFD->getAnonField());
830 llvm_unreachable(
"unexpected kind of global decl");
833void CXXNameMangler::mangleFunctionEncoding(
GlobalDecl GD) {
838 if (!Context.shouldMangleDeclName(FD)) {
843 AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
844 if (ReturnTypeAbiTags.empty()) {
853 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
855 FunctionTypeDepth.pop(Saved);
856 mangleFunctionEncodingBareType(FD);
864 llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
865 CXXNameMangler FunctionEncodingMangler(*
this, FunctionEncodingStream);
867 FunctionEncodingMangler.disableDerivedAbiTags();
869 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
870 FunctionEncodingMangler.mangleNameWithAbiTags(FD,
nullptr);
871 FunctionTypeDepth.pop(Saved);
874 size_t EncodingPositionStart = FunctionEncodingStream.str().size();
875 FunctionEncodingMangler.mangleFunctionEncodingBareType(FD);
879 const AbiTagList &UsedAbiTags =
880 FunctionEncodingMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
881 AbiTagList AdditionalAbiTags(ReturnTypeAbiTags.size());
882 AdditionalAbiTags.erase(
883 std::set_difference(ReturnTypeAbiTags.begin(), ReturnTypeAbiTags.end(),
884 UsedAbiTags.begin(), UsedAbiTags.end(),
885 AdditionalAbiTags.begin()),
886 AdditionalAbiTags.end());
889 Saved = FunctionTypeDepth.push();
890 mangleNameWithAbiTags(FD, &AdditionalAbiTags);
891 FunctionTypeDepth.pop(Saved);
892 Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
896 extendSubstitutions(&FunctionEncodingMangler);
899void CXXNameMangler::mangleFunctionEncodingBareType(
const FunctionDecl *FD) {
900 if (FD->
hasAttr<EnableIfAttr>()) {
901 FunctionTypeDepthState Saved = FunctionTypeDepth.push();
902 Out <<
"Ua9enable_ifI";
903 for (AttrVec::const_iterator I = FD->
getAttrs().begin(),
906 EnableIfAttr *EIA = dyn_cast<EnableIfAttr>(*I);
909 if (isCompatibleWith(LangOptions::ClangABI::Ver11)) {
914 mangleExpression(EIA->getCond());
917 mangleTemplateArgExpr(EIA->getCond());
921 FunctionTypeDepth.pop(Saved);
926 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD))
927 if (
auto Inherited = CD->getInheritedConstructor())
928 FD = Inherited.getConstructor();
946 bool MangleReturnType =
false;
948 if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
949 isa<CXXConversionDecl>(FD)))
950 MangleReturnType =
true;
953 FD = PrimaryTemplate->getTemplatedDecl();
957 MangleReturnType, FD);
962 if (!Context.getEffectiveParentContext(NS)->isTranslationUnit())
966 return II && II->
isStr(
"std");
971bool CXXNameMangler::isStdNamespace(
const DeclContext *DC) {
975 return isStd(cast<NamespaceDecl>(DC));
982 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
991 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
992 TemplateArgs = &Spec->getTemplateArgs();
993 return GD.
getWithDecl(Spec->getSpecializedTemplate());
998 dyn_cast<VarTemplateSpecializationDecl>(ND)) {
999 TemplateArgs = &Spec->getTemplateArgs();
1000 return GD.
getWithDecl(Spec->getSpecializedTemplate());
1011void CXXNameMangler::mangleName(
GlobalDecl GD) {
1013 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1015 AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD);
1016 if (VariableTypeAbiTags.empty()) {
1018 mangleNameWithAbiTags(VD,
nullptr);
1023 llvm::raw_null_ostream NullOutStream;
1024 CXXNameMangler VariableNameMangler(*
this, NullOutStream);
1025 VariableNameMangler.disableDerivedAbiTags();
1026 VariableNameMangler.mangleNameWithAbiTags(VD,
nullptr);
1029 const AbiTagList &UsedAbiTags =
1030 VariableNameMangler.AbiTagsRoot.getSortedUniqueUsedAbiTags();
1031 AbiTagList AdditionalAbiTags(VariableTypeAbiTags.size());
1032 AdditionalAbiTags.erase(
1033 std::set_difference(VariableTypeAbiTags.begin(),
1034 VariableTypeAbiTags.end(), UsedAbiTags.begin(),
1035 UsedAbiTags.end(), AdditionalAbiTags.begin()),
1036 AdditionalAbiTags.end());
1039 mangleNameWithAbiTags(VD, &AdditionalAbiTags);
1041 mangleNameWithAbiTags(GD,
nullptr);
1045const RecordDecl *CXXNameMangler::GetLocalClassDecl(
const Decl *D) {
1046 const DeclContext *DC = Context.getEffectiveDeclContext(D);
1048 if (isLocalContainerContext(DC))
1049 return dyn_cast<RecordDecl>(D);
1051 DC = Context.getEffectiveDeclContext(D);
1056void CXXNameMangler::mangleNameWithAbiTags(
GlobalDecl GD,
1057 const AbiTagList *AdditionalAbiTags) {
1064 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
1065 bool IsLambda = isLambda(ND);
1071 if (isLocalContainerContext(DC) && ND->
hasLinkage() && !IsLambda)
1073 DC = Context.getEffectiveParentContext(DC);
1074 else if (GetLocalClassDecl(ND) &&
1075 (!IsLambda || isCompatibleWith(LangOptions::ClangABI::Ver18))) {
1076 mangleLocalName(GD, AdditionalAbiTags);
1080 assert(!isa<LinkageSpecDecl>(DC) &&
"context cannot be LinkageSpecDecl");
1084 if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
1085 mangleNestedNameWithClosurePrefix(GD, PrefixND, AdditionalAbiTags);
1089 if (isLocalContainerContext(DC)) {
1090 mangleLocalName(GD, AdditionalAbiTags);
1098 mangleUnscopedTemplateName(TD, DC, AdditionalAbiTags);
1103 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1107 mangleNestedName(GD, DC, AdditionalAbiTags);
1110void CXXNameMangler::mangleModuleName(
const NamedDecl *ND) {
1113 mangleModuleNamePrefix(M->getPrimaryModuleInterfaceName());
1121void CXXNameMangler::mangleModuleNamePrefix(StringRef Name,
bool IsPartition) {
1123 auto It = ModuleSubstitutions.find(Name);
1124 if (It != ModuleSubstitutions.end()) {
1126 mangleSeqID(It->second);
1132 auto Parts = Name.rsplit(
'.');
1133 if (Parts.second.empty())
1134 Parts.second = Parts.first;
1136 mangleModuleNamePrefix(Parts.first, IsPartition);
1137 IsPartition =
false;
1143 Out << Parts.second.size() << Parts.second;
1144 ModuleSubstitutions.insert({Name, SeqID++});
1147void CXXNameMangler::mangleTemplateName(
const TemplateDecl *TD,
1149 const DeclContext *DC = Context.getEffectiveDeclContext(TD);
1152 mangleUnscopedTemplateName(TD, DC,
nullptr);
1155 mangleNestedName(TD, Args);
1160 const AbiTagList *AdditionalAbiTags) {
1164 assert(!isa<LinkageSpecDecl>(DC) &&
"unskipped LinkageSpecDecl");
1165 if (isStdNamespace(DC))
1168 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1171void CXXNameMangler::mangleUnscopedTemplateName(
1176 if (mangleSubstitution(ND))
1180 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
1181 assert(!AdditionalAbiTags &&
1182 "template template param cannot have abi tags");
1183 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
1184 }
else if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND)) {
1185 mangleUnscopedName(GD, DC, AdditionalAbiTags);
1191 addSubstitution(ND);
1194void CXXNameMangler::mangleFloat(
const llvm::APFloat &f) {
1208 llvm::APInt valueBits = f.bitcastToAPInt();
1209 unsigned numCharacters = (valueBits.getBitWidth() + 3) / 4;
1210 assert(numCharacters != 0);
1216 for (
unsigned stringIndex = 0; stringIndex != numCharacters; ++stringIndex) {
1218 unsigned digitBitIndex = 4 * (numCharacters - stringIndex - 1);
1221 uint64_t hexDigit = valueBits.getRawData()[digitBitIndex / 64];
1222 hexDigit >>= (digitBitIndex % 64);
1226 static const char charForHex[16] = {
1227 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
1228 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
1230 buffer[stringIndex] = charForHex[hexDigit];
1233 Out.write(buffer.data(), numCharacters);
1236void CXXNameMangler::mangleFloatLiteral(
QualType T,
const llvm::APFloat &
V) {
1243void CXXNameMangler::mangleFixedPointLiteral() {
1250void CXXNameMangler::mangleNullPointer(
QualType T) {
1257void CXXNameMangler::mangleNumber(
const llvm::APSInt &
Value) {
1258 if (
Value.isSigned() &&
Value.isNegative()) {
1266void CXXNameMangler::mangleNumber(int64_t Number) {
1276void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t
Virtual) {
1284 mangleNumber(NonVirtual);
1290 mangleNumber(NonVirtual);
1298 if (!mangleSubstitution(
QualType(TST, 0))) {
1299 mangleTemplatePrefix(TST->getTemplateName());
1304 mangleTemplateArgs(TST->getTemplateName(), TST->template_arguments());
1307 }
else if (
const auto *DTST =
1309 if (!mangleSubstitution(
QualType(DTST, 0))) {
1310 TemplateName Template = getASTContext().getDependentTemplateName(
1311 DTST->getQualifier(), DTST->getIdentifier());
1312 mangleTemplatePrefix(Template);
1317 mangleTemplateArgs(Template, DTST->template_arguments());
1318 addSubstitution(
QualType(DTST, 0));
1348 switch (qualifier->
getKind()) {
1360 llvm_unreachable(
"Can't mangle __super specifier");
1364 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1372 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1389 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1396 if (mangleUnresolvedTypeOrSimpleId(
QualType(
type, 0), recursive ?
"N" :
""))
1405 mangleUnresolvedPrefix(qualifier->
getPrefix(),
1423void CXXNameMangler::mangleUnresolvedName(
1426 unsigned knownArity) {
1427 if (qualifier) mangleUnresolvedPrefix(qualifier);
1428 switch (
name.getNameKind()) {
1431 mangleSourceName(
name.getAsIdentifierInfo());
1436 mangleUnresolvedTypeOrSimpleId(
name.getCXXNameType());
1443 mangleOperatorName(name, knownArity);
1446 llvm_unreachable(
"Can't mangle a constructor name!");
1448 llvm_unreachable(
"Can't mangle a using directive name!");
1450 llvm_unreachable(
"Can't mangle a deduction guide name!");
1454 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1460 mangleTemplateArgs(
TemplateName(), TemplateArgs, NumTemplateArgs);
1463void CXXNameMangler::mangleUnqualifiedName(
1465 unsigned KnownArity,
const AbiTagList *AdditionalAbiTags) {
1473 mangleModuleName(ND);
1477 auto *FD = dyn_cast<FunctionDecl>(ND);
1478 auto *FTD = dyn_cast<FunctionTemplateDecl>(ND);
1480 (FTD && FTD->getTemplatedDecl()->isMemberLikeConstrainedFriend())) {
1481 if (!isCompatibleWith(LangOptions::ClangABI::Ver17))
1485 unsigned Arity = KnownArity;
1486 switch (Name.getNameKind()) {
1491 if (
auto *DD = dyn_cast<DecompositionDecl>(ND)) {
1498 for (
auto *BD : DD->bindings())
1499 mangleSourceName(BD->getDeclName().getAsIdentifierInfo());
1501 writeAbiTags(ND, AdditionalAbiTags);
1505 if (
auto *GD = dyn_cast<MSGuidDecl>(ND)) {
1508 SmallString<
sizeof(
"_GUID_12345678_1234_1234_1234_1234567890ab")> GUID;
1509 llvm::raw_svector_ostream GUIDOS(GUID);
1510 Context.mangleMSGuidDecl(GD, GUIDOS);
1511 Out << GUID.size() << GUID;
1515 if (
auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
1518 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
1519 TPO->getValue(),
true);
1537 if (Context.isInternalLinkageDecl(ND))
1540 bool IsRegCall = FD &&
1544 FD && FD->
hasAttr<CUDAGlobalAttr>() &&
1547 mangleDeviceStubName(II);
1549 mangleRegCallName(II);
1551 mangleSourceName(II);
1553 writeAbiTags(ND, AdditionalAbiTags);
1558 assert(ND &&
"mangling empty name without declaration");
1560 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
1563 Out <<
"12_GLOBAL__N_1";
1568 if (
const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
1582 &&
"Expected anonymous struct or union!");
1589 assert(FD->
getIdentifier() &&
"Data member name isn't an identifier!");
1602 if (isa<ObjCContainerDecl>(ND))
1606 const TagDecl *TD = cast<TagDecl>(ND);
1609 "Typedef should not be in another decl context!");
1610 assert(D->getDeclName().getAsIdentifierInfo() &&
1611 "Typedef was not named!");
1612 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
1613 assert(!AdditionalAbiTags &&
"Type cannot have additional abi tags");
1616 writeAbiTags(TD,
nullptr);
1626 std::optional<unsigned> DeviceNumber =
1627 Context.getDiscriminatorOverride()(Context.getASTContext(),
Record);
1633 if (
Record->isLambda() &&
1634 ((DeviceNumber && *DeviceNumber > 0) ||
1635 (!DeviceNumber &&
Record->getLambdaManglingNumber() > 0))) {
1636 assert(!AdditionalAbiTags &&
1637 "Lambda type cannot have additional abi tags");
1644 unsigned UnnamedMangle =
1645 getASTContext().getManglingNumber(TD, Context.isAux());
1647 if (UnnamedMangle > 1)
1648 Out << UnnamedMangle - 2;
1650 writeAbiTags(TD, AdditionalAbiTags);
1656 unsigned AnonStructId =
1658 : Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1665 Str += llvm::utostr(AnonStructId);
1675 llvm_unreachable(
"Can't mangle Objective-C selector names here!");
1681 if (
auto Inherited =
1682 cast<CXXConstructorDecl>(ND)->getInheritedConstructor()) {
1683 InheritedFrom = Inherited.getConstructor()->
getParent();
1684 InheritedTemplateName =
1685 TemplateName(Inherited.getConstructor()->getPrimaryTemplate());
1686 InheritedTemplateArgs =
1687 Inherited.getConstructor()->getTemplateSpecializationArgs();
1693 mangleCXXCtorType(
static_cast<CXXCtorType>(StructorType), InheritedFrom);
1701 if (InheritedTemplateArgs)
1702 mangleTemplateArgs(InheritedTemplateName, *InheritedTemplateArgs);
1704 writeAbiTags(ND, AdditionalAbiTags);
1712 mangleCXXDtorType(
static_cast<CXXDtorType>(StructorType));
1718 writeAbiTags(ND, AdditionalAbiTags);
1722 if (ND && Arity == UnknownArity) {
1723 Arity = cast<FunctionDecl>(ND)->getNumParams();
1726 if (
const auto *MD = dyn_cast<CXXMethodDecl>(ND))
1727 if (MD->isImplicitObjectMemberFunction())
1733 mangleOperatorName(Name, Arity);
1734 writeAbiTags(ND, AdditionalAbiTags);
1738 llvm_unreachable(
"Can't mangle a deduction guide name!");
1741 llvm_unreachable(
"Can't mangle a using directive name!");
1745void CXXNameMangler::mangleRegCallName(
const IdentifierInfo *II) {
1749 if (getASTContext().getLangOpts().RegCall4)
1750 Out << II->
getLength() +
sizeof(
"__regcall4__") - 1 <<
"__regcall4__"
1753 Out << II->
getLength() +
sizeof(
"__regcall3__") - 1 <<
"__regcall3__"
1757void CXXNameMangler::mangleDeviceStubName(
const IdentifierInfo *II) {
1761 Out << II->
getLength() +
sizeof(
"__device_stub__") - 1 <<
"__device_stub__"
1772void CXXNameMangler::mangleNestedName(
GlobalDecl GD,
1774 const AbiTagList *AdditionalAbiTags,
1783 if (
const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
1784 Qualifiers MethodQuals = Method->getMethodQualifiers();
1787 if (Method->isExplicitObjectMemberFunction())
1790 mangleQualifiers(MethodQuals);
1791 mangleRefQualifier(Method->getRefQualifier());
1797 mangleTemplatePrefix(TD, NoFunction);
1800 manglePrefix(DC, NoFunction);
1801 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1806void CXXNameMangler::mangleNestedName(
const TemplateDecl *TD,
1812 mangleTemplatePrefix(TD);
1818void CXXNameMangler::mangleNestedNameWithClosurePrefix(
1820 const AbiTagList *AdditionalAbiTags) {
1829 mangleClosurePrefix(PrefixND);
1830 mangleUnqualifiedName(GD,
nullptr, AdditionalAbiTags);
1841 if (
auto *CD = dyn_cast<CXXConstructorDecl>(DC))
1843 else if (
auto *DD = dyn_cast<CXXDestructorDecl>(DC))
1850void CXXNameMangler::mangleLocalName(
GlobalDecl GD,
1851 const AbiTagList *AdditionalAbiTags) {
1858 assert(isa<NamedDecl>(D) || isa<BlockDecl>(D));
1860 const DeclContext *DC = Context.getEffectiveDeclContext(RD ? RD : D);
1865 AbiTagState LocalAbiTags(AbiTags);
1868 mangleObjCMethodName(MD);
1869 else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(DC))
1870 mangleBlockForPrefix(BD);
1876 LocalAbiTags.setUsedAbiTags(LocalAbiTags.getEmittedAbiTags());
1899 mangleNumber(Num - 2);
1908 mangleUnqualifiedName(RD, DC, AdditionalAbiTags);
1909 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1910 if (
const NamedDecl *PrefixND = getClosurePrefix(BD))
1911 mangleClosurePrefix(PrefixND,
true );
1913 manglePrefix(Context.getEffectiveDeclContext(BD),
true );
1914 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1915 mangleUnqualifiedBlock(BD);
1917 const NamedDecl *ND = cast<NamedDecl>(D);
1918 mangleNestedName(GD, Context.getEffectiveDeclContext(ND),
1919 AdditionalAbiTags,
true );
1921 }
else if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
1925 = dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl())) {
1931 mangleNumber(Num - 2);
1936 assert(!AdditionalAbiTags &&
"Block cannot have additional abi tags");
1937 mangleUnqualifiedBlock(BD);
1939 mangleUnqualifiedName(GD, DC, AdditionalAbiTags);
1942 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) {
1944 if (Context.getNextDiscriminator(ND, disc)) {
1948 Out <<
"__" << disc <<
'_';
1953void CXXNameMangler::mangleBlockForPrefix(
const BlockDecl *
Block) {
1954 if (GetLocalClassDecl(
Block)) {
1955 mangleLocalName(
Block,
nullptr);
1959 if (isLocalContainerContext(DC)) {
1960 mangleLocalName(
Block,
nullptr);
1964 mangleClosurePrefix(PrefixND);
1967 mangleUnqualifiedBlock(
Block);
1970void CXXNameMangler::mangleUnqualifiedBlock(
const BlockDecl *
Block) {
1973 if (
Decl *Context =
Block->getBlockManglingContextDecl()) {
1974 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
1975 (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) &&
1976 Context->getDeclContext()->isRecord()) {
1977 const auto *ND = cast<NamedDecl>(Context);
1979 mangleSourceNameWithAbiTags(ND);
1986 unsigned Number =
Block->getBlockManglingNumber();
1990 Number = Context.getBlockId(
Block,
false);
2008void CXXNameMangler::mangleTemplateParamDecl(
const NamedDecl *
Decl) {
2010 if (
auto *Ty = dyn_cast<TemplateTypeParmDecl>(
Decl)) {
2011 if (Ty->isParameterPack())
2014 if (Constraint && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2017 mangleTypeConstraint(Constraint);
2021 }
else if (
auto *Tn = dyn_cast<NonTypeTemplateParmDecl>(
Decl)) {
2022 if (Tn->isExpandedParameterPack()) {
2023 for (
unsigned I = 0, N = Tn->getNumExpansionTypes(); I != N; ++I) {
2025 mangleType(Tn->getExpansionType(I));
2029 if (Tn->isParameterPack()) {
2032 T = PackExpansion->getPattern();
2037 }
else if (
auto *Tt = dyn_cast<TemplateTemplateParmDecl>(
Decl)) {
2038 if (Tt->isExpandedParameterPack()) {
2039 for (
unsigned I = 0, N = Tt->getNumExpansionTemplateParameters(); I != N;
2041 mangleTemplateParameterList(Tt->getExpansionTemplateParameters(I));
2043 if (Tt->isParameterPack())
2045 mangleTemplateParameterList(Tt->getTemplateParameters());
2050void CXXNameMangler::mangleTemplateParameterList(
2053 for (
auto *Param : *Params)
2054 mangleTemplateParamDecl(Param);
2055 mangleRequiresClause(Params->getRequiresClause());
2059void CXXNameMangler::mangleTypeConstraint(
2061 const DeclContext *DC = Context.getEffectiveDeclContext(Concept);
2063 mangleTemplateName(Concept, Arguments);
2065 mangleUnscopedName(Concept, DC,
nullptr);
2067 mangleNestedName(Concept, DC,
nullptr);
2070void CXXNameMangler::mangleTypeConstraint(
const TypeConstraint *Constraint) {
2075 Args.push_back(ArgLoc.getArgument());
2080void CXXNameMangler::mangleRequiresClause(
const Expr *RequiresClause) {
2082 if (RequiresClause && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
2084 mangleExpression(RequiresClause);
2088void CXXNameMangler::mangleLambda(
const CXXRecordDecl *Lambda) {
2092 if (isCompatibleWith(LangOptions::ClangABI::Ver12) &&
2093 (isa<VarDecl>(Context) || isa<FieldDecl>(Context)) &&
2094 !isa<ParmVarDecl>(Context)) {
2097 mangleSourceName(Name);
2107 mangleLambdaSig(Lambda);
2121 std::optional<unsigned> DeviceNumber =
2122 Context.getDiscriminatorOverride()(Context.getASTContext(), Lambda);
2126 assert(Number > 0 &&
"Lambda should be mangled as an unnamed class");
2128 mangleNumber(Number - 2);
2132void CXXNameMangler::mangleLambdaSig(
const CXXRecordDecl *Lambda) {
2135 mangleTemplateParamDecl(D);
2139 mangleRequiresClause(TPL->getRequiresClause());
2143 mangleBareFunctionType(Proto,
false,
2148 switch (qualifier->
getKind()) {
2154 llvm_unreachable(
"Can't mangle __super specifier");
2171 bool Clang14Compat = isCompatibleWith(LangOptions::ClangABI::Ver14);
2172 if (!Clang14Compat && mangleSubstitution(qualifier))
2183 addSubstitution(qualifier);
2187 llvm_unreachable(
"unexpected nested name specifier");
2190void CXXNameMangler::manglePrefix(
const DeclContext *DC,
bool NoFunction) {
2198 assert(!isa<LinkageSpecDecl>(DC) &&
"prefix cannot be LinkageSpecDecl");
2203 if (NoFunction && isLocalContainerContext(DC))
2206 const NamedDecl *ND = cast<NamedDecl>(DC);
2207 if (mangleSubstitution(ND))
2213 mangleTemplatePrefix(TD);
2215 }
else if (
const NamedDecl *PrefixND = getClosurePrefix(ND)) {
2216 mangleClosurePrefix(PrefixND, NoFunction);
2217 mangleUnqualifiedName(ND,
nullptr,
nullptr);
2219 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2220 manglePrefix(DC, NoFunction);
2221 mangleUnqualifiedName(ND, DC,
nullptr);
2224 addSubstitution(ND);
2227void CXXNameMangler::mangleTemplatePrefix(
TemplateName Template) {
2232 return mangleTemplatePrefix(TD);
2235 assert(Dependent &&
"unexpected template name kind");
2239 bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
2240 if (!Clang11Compat && mangleSubstitution(Template))
2244 manglePrefix(Qualifier);
2246 if (Clang11Compat && mangleSubstitution(Template))
2250 mangleSourceName(
Id);
2252 mangleOperatorName(Dependent->getOperator(), UnknownArity);
2254 addSubstitution(Template);
2257void CXXNameMangler::mangleTemplatePrefix(
GlobalDecl GD,
2266 if (mangleSubstitution(ND))
2270 if (
const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) {
2271 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2273 const DeclContext *DC = Context.getEffectiveDeclContext(ND);
2274 manglePrefix(DC, NoFunction);
2275 if (isa<BuiltinTemplateDecl>(ND) || isa<ConceptDecl>(ND))
2276 mangleUnqualifiedName(GD, DC,
nullptr);
2282 addSubstitution(ND);
2285const NamedDecl *CXXNameMangler::getClosurePrefix(
const Decl *ND) {
2286 if (isCompatibleWith(LangOptions::ClangABI::Ver12))
2290 if (
auto *
Block = dyn_cast<BlockDecl>(ND)) {
2291 Context = dyn_cast_or_null<NamedDecl>(
Block->getBlockManglingContextDecl());
2292 }
else if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
2294 Context = dyn_cast_or_null<NamedDecl>(RD->getLambdaContextDecl());
2301 if ((isa<VarDecl>(Context) && cast<VarDecl>(Context)->hasGlobalStorage()) ||
2302 isa<FieldDecl>(Context))
2308void CXXNameMangler::mangleClosurePrefix(
const NamedDecl *ND,
bool NoFunction) {
2311 if (mangleSubstitution(ND))
2316 mangleTemplatePrefix(TD, NoFunction);
2319 const auto *DC = Context.getEffectiveDeclContext(ND);
2320 manglePrefix(DC, NoFunction);
2321 mangleUnqualifiedName(ND, DC,
nullptr);
2326 addSubstitution(ND);
2335 if (mangleSubstitution(TN))
2348 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(TD))
2349 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
2356 llvm_unreachable(
"can't mangle an overloaded template name as a <type>");
2360 assert(Dependent->isIdentifier());
2364 mangleUnresolvedPrefix(Dependent->getQualifier());
2365 mangleSourceName(Dependent->getIdentifier());
2385 Out <<
"_SUBSTPACK_";
2390 addSubstitution(TN);
2393bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(
QualType Ty,
2399 case Type::Adjusted:
2401 case Type::ArrayParameter:
2403 case Type::BlockPointer:
2404 case Type::LValueReference:
2405 case Type::RValueReference:
2406 case Type::MemberPointer:
2407 case Type::ConstantArray:
2408 case Type::IncompleteArray:
2409 case Type::VariableArray:
2410 case Type::DependentSizedArray:
2411 case Type::DependentAddressSpace:
2412 case Type::DependentVector:
2413 case Type::DependentSizedExtVector:
2415 case Type::ExtVector:
2416 case Type::ConstantMatrix:
2417 case Type::DependentSizedMatrix:
2418 case Type::FunctionProto:
2419 case Type::FunctionNoProto:
2421 case Type::Attributed:
2422 case Type::BTFTagAttributed:
2424 case Type::DeducedTemplateSpecialization:
2425 case Type::PackExpansion:
2426 case Type::ObjCObject:
2427 case Type::ObjCInterface:
2428 case Type::ObjCObjectPointer:
2429 case Type::ObjCTypeParam:
2432 case Type::MacroQualified:
2434 case Type::DependentBitInt:
2435 case Type::CountAttributed:
2436 llvm_unreachable(
"type is illegal as a nested name specifier");
2438 case Type::SubstTemplateTypeParmPack:
2443 Out <<
"_SUBSTPACK_";
2450 case Type::TypeOfExpr:
2452 case Type::Decltype:
2453 case Type::PackIndexing:
2454 case Type::TemplateTypeParm:
2455 case Type::UnaryTransform:
2456 case Type::SubstTemplateTypeParm:
2470 mangleSourceNameWithAbiTags(cast<TypedefType>(Ty)->getDecl());
2473 case Type::UnresolvedUsing:
2474 mangleSourceNameWithAbiTags(
2475 cast<UnresolvedUsingType>(Ty)->getDecl());
2480 mangleSourceNameWithAbiTags(cast<TagType>(Ty)->getDecl());
2483 case Type::TemplateSpecialization: {
2485 cast<TemplateSpecializationType>(Ty);
2494 assert(TD &&
"no template for template specialization type");
2495 if (isa<TemplateTemplateParmDecl>(TD))
2496 goto unresolvedType;
2498 mangleSourceNameWithAbiTags(TD);
2505 llvm_unreachable(
"invalid base for a template specialization type");
2519 Out <<
"_SUBSTPACK_";
2524 assert(TD && !isa<TemplateTemplateParmDecl>(TD));
2525 mangleSourceNameWithAbiTags(TD);
2539 case Type::InjectedClassName:
2540 mangleSourceNameWithAbiTags(
2541 cast<InjectedClassNameType>(Ty)->getDecl());
2544 case Type::DependentName:
2545 mangleSourceName(cast<DependentNameType>(Ty)->
getIdentifier());
2548 case Type::DependentTemplateSpecialization: {
2550 cast<DependentTemplateSpecializationType>(Ty);
2551 TemplateName Template = getASTContext().getDependentTemplateName(
2559 return mangleUnresolvedTypeOrSimpleId(cast<UsingType>(Ty)->desugar(),
2561 case Type::Elaborated:
2562 return mangleUnresolvedTypeOrSimpleId(
2563 cast<ElaboratedType>(Ty)->getNamedType(), Prefix);
2569void CXXNameMangler::mangleOperatorName(
DeclarationName Name,
unsigned Arity) {
2570 switch (Name.getNameKind()) {
2579 llvm_unreachable(
"Not an operator name");
2584 mangleType(Name.getCXXNameType());
2589 mangleSourceName(Name.getCXXLiteralIdentifier());
2593 mangleOperatorName(Name.getCXXOverloadedOperator(), Arity);
2602 case OO_New: Out <<
"nw";
break;
2604 case OO_Array_New: Out <<
"na";
break;
2606 case OO_Delete: Out <<
"dl";
break;
2608 case OO_Array_Delete: Out <<
"da";
break;
2612 Out << (Arity == 1?
"ps" :
"pl");
break;
2616 Out << (Arity == 1?
"ng" :
"mi");
break;
2620 Out << (Arity == 1?
"ad" :
"an");
break;
2625 Out << (Arity == 1?
"de" :
"ml");
break;
2627 case OO_Tilde: Out <<
"co";
break;
2629 case OO_Slash: Out <<
"dv";
break;
2631 case OO_Percent: Out <<
"rm";
break;
2633 case OO_Pipe: Out <<
"or";
break;
2635 case OO_Caret: Out <<
"eo";
break;
2637 case OO_Equal: Out <<
"aS";
break;
2639 case OO_PlusEqual: Out <<
"pL";
break;
2641 case OO_MinusEqual: Out <<
"mI";
break;
2643 case OO_StarEqual: Out <<
"mL";
break;
2645 case OO_SlashEqual: Out <<
"dV";
break;
2647 case OO_PercentEqual: Out <<
"rM";
break;
2649 case OO_AmpEqual: Out <<
"aN";
break;
2651 case OO_PipeEqual: Out <<
"oR";
break;
2653 case OO_CaretEqual: Out <<
"eO";
break;
2655 case OO_LessLess: Out <<
"ls";
break;
2657 case OO_GreaterGreater: Out <<
"rs";
break;
2659 case OO_LessLessEqual: Out <<
"lS";
break;
2661 case OO_GreaterGreaterEqual: Out <<
"rS";
break;
2663 case OO_EqualEqual: Out <<
"eq";
break;
2665 case OO_ExclaimEqual: Out <<
"ne";
break;
2667 case OO_Less: Out <<
"lt";
break;
2669 case OO_Greater: Out <<
"gt";
break;
2671 case OO_LessEqual: Out <<
"le";
break;
2673 case OO_GreaterEqual: Out <<
"ge";
break;
2675 case OO_Exclaim: Out <<
"nt";
break;
2677 case OO_AmpAmp: Out <<
"aa";
break;
2679 case OO_PipePipe: Out <<
"oo";
break;
2681 case OO_PlusPlus: Out <<
"pp";
break;
2683 case OO_MinusMinus: Out <<
"mm";
break;
2685 case OO_Comma: Out <<
"cm";
break;
2687 case OO_ArrowStar: Out <<
"pm";
break;
2689 case OO_Arrow: Out <<
"pt";
break;
2691 case OO_Call: Out <<
"cl";
break;
2693 case OO_Subscript: Out <<
"ix";
break;
2698 case OO_Conditional: Out <<
"qu";
break;
2701 case OO_Coawait: Out <<
"aw";
break;
2704 case OO_Spaceship: Out <<
"ss";
break;
2708 llvm_unreachable(
"Not an overloaded operator");
2737 if (TargetAS != 0 ||
2739 ASString =
"AS" + llvm::utostr(TargetAS);
2742 default: llvm_unreachable(
"Not a language specific address space");
2746 case LangAS::opencl_global:
2747 ASString =
"CLglobal";
2749 case LangAS::opencl_global_device:
2750 ASString =
"CLdevice";
2752 case LangAS::opencl_global_host:
2753 ASString =
"CLhost";
2755 case LangAS::opencl_local:
2756 ASString =
"CLlocal";
2758 case LangAS::opencl_constant:
2759 ASString =
"CLconstant";
2761 case LangAS::opencl_private:
2762 ASString =
"CLprivate";
2764 case LangAS::opencl_generic:
2765 ASString =
"CLgeneric";
2769 case LangAS::sycl_global:
2770 ASString =
"SYglobal";
2772 case LangAS::sycl_global_device:
2773 ASString =
"SYdevice";
2775 case LangAS::sycl_global_host:
2776 ASString =
"SYhost";
2778 case LangAS::sycl_local:
2779 ASString =
"SYlocal";
2781 case LangAS::sycl_private:
2782 ASString =
"SYprivate";
2785 case LangAS::cuda_device:
2786 ASString =
"CUdevice";
2788 case LangAS::cuda_constant:
2789 ASString =
"CUconstant";
2791 case LangAS::cuda_shared:
2792 ASString =
"CUshared";
2795 case LangAS::ptr32_sptr:
2796 ASString =
"ptr32_sptr";
2798 case LangAS::ptr32_uptr:
2799 ASString =
"ptr32_uptr";
2806 if (!ASString.empty())
2807 mangleVendorQualifier(ASString);
2820 mangleVendorQualifier(
"__weak");
2824 mangleVendorQualifier(
"__unaligned");
2836 mangleVendorQualifier(
"__strong");
2840 mangleVendorQualifier(
"__autoreleasing");
2863void CXXNameMangler::mangleVendorQualifier(StringRef name) {
2870 switch (RefQualifier) {
2884void CXXNameMangler::mangleObjCMethodName(
const ObjCMethodDecl *MD) {
2885 Context.mangleObjCMethodNameAsSourceName(MD, Out);
2898 Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver17)
2904 if (Ctx.
getLangOpts().getClangABICompat() > LangOptions::ClangABI::Ver6 &&
2911 if (DeducedTST->getDeducedType().isNull())
2916void CXXNameMangler::mangleType(
QualType T) {
2950 T =
T.getCanonicalType();
2957 = dyn_cast<TemplateSpecializationType>(
T))
2966 =
T.getSingleStepDesugaredType(Context.getASTContext());
2975 const Type *ty = split.
Ty;
2977 bool isSubstitutable =
2979 if (isSubstitutable && mangleSubstitution(
T))
2984 if (quals && isa<ArrayType>(
T)) {
2994 dyn_cast<DependentAddressSpaceType>(ty)) {
2996 mangleQualifiers(splitDAST.
Quals, DAST);
2999 mangleQualifiers(quals);
3007#define ABSTRACT_TYPE(CLASS, PARENT)
3008#define NON_CANONICAL_TYPE(CLASS, PARENT) \
3010 llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
3012#define TYPE(CLASS, PARENT) \
3014 mangleType(static_cast<const CLASS##Type*>(ty)); \
3016#include "clang/AST/TypeNodes.inc"
3021 if (isSubstitutable)
3025void CXXNameMangler::mangleNameOrStandardSubstitution(
const NamedDecl *ND) {
3026 if (!mangleStandardSubstitution(ND))
3072 std::string type_name;
3076 if (NormalizeIntegers &&
T->isInteger()) {
3077 if (
T->isSignedInteger()) {
3078 switch (getASTContext().getTypeSize(
T)) {
3082 if (mangleSubstitution(BuiltinType::SChar))
3085 addSubstitution(BuiltinType::SChar);
3088 if (mangleSubstitution(BuiltinType::Short))
3091 addSubstitution(BuiltinType::Short);
3094 if (mangleSubstitution(BuiltinType::Int))
3097 addSubstitution(BuiltinType::Int);
3100 if (mangleSubstitution(BuiltinType::Long))
3103 addSubstitution(BuiltinType::Long);
3106 if (mangleSubstitution(BuiltinType::Int128))
3109 addSubstitution(BuiltinType::Int128);
3112 llvm_unreachable(
"Unknown integer size for normalization");
3115 switch (getASTContext().getTypeSize(
T)) {
3117 if (mangleSubstitution(BuiltinType::UChar))
3120 addSubstitution(BuiltinType::UChar);
3123 if (mangleSubstitution(BuiltinType::UShort))
3126 addSubstitution(BuiltinType::UShort);
3129 if (mangleSubstitution(BuiltinType::UInt))
3132 addSubstitution(BuiltinType::UInt);
3135 if (mangleSubstitution(BuiltinType::ULong))
3138 addSubstitution(BuiltinType::ULong);
3141 if (mangleSubstitution(BuiltinType::UInt128))
3144 addSubstitution(BuiltinType::UInt128);
3147 llvm_unreachable(
"Unknown integer size for normalization");
3152 switch (
T->getKind()) {
3153 case BuiltinType::Void:
3156 case BuiltinType::Bool:
3159 case BuiltinType::Char_U:
3160 case BuiltinType::Char_S:
3163 case BuiltinType::UChar:
3166 case BuiltinType::UShort:
3169 case BuiltinType::UInt:
3172 case BuiltinType::ULong:
3175 case BuiltinType::ULongLong:
3178 case BuiltinType::UInt128:
3181 case BuiltinType::SChar:
3184 case BuiltinType::WChar_S:
3185 case BuiltinType::WChar_U:
3188 case BuiltinType::Char8:
3191 case BuiltinType::Char16:
3194 case BuiltinType::Char32:
3197 case BuiltinType::Short:
3200 case BuiltinType::Int:
3203 case BuiltinType::Long:
3206 case BuiltinType::LongLong:
3209 case BuiltinType::Int128:
3212 case BuiltinType::Float16:
3215 case BuiltinType::ShortAccum:
3218 case BuiltinType::Accum:
3221 case BuiltinType::LongAccum:
3224 case BuiltinType::UShortAccum:
3227 case BuiltinType::UAccum:
3230 case BuiltinType::ULongAccum:
3233 case BuiltinType::ShortFract:
3236 case BuiltinType::Fract:
3239 case BuiltinType::LongFract:
3242 case BuiltinType::UShortFract:
3245 case BuiltinType::UFract:
3248 case BuiltinType::ULongFract:
3251 case BuiltinType::SatShortAccum:
3254 case BuiltinType::SatAccum:
3257 case BuiltinType::SatLongAccum:
3260 case BuiltinType::SatUShortAccum:
3263 case BuiltinType::SatUAccum:
3266 case BuiltinType::SatULongAccum:
3269 case BuiltinType::SatShortFract:
3272 case BuiltinType::SatFract:
3275 case BuiltinType::SatLongFract:
3278 case BuiltinType::SatUShortFract:
3281 case BuiltinType::SatUFract:
3284 case BuiltinType::SatULongFract:
3287 case BuiltinType::Half:
3290 case BuiltinType::Float:
3293 case BuiltinType::Double:
3296 case BuiltinType::LongDouble: {
3298 getASTContext().getLangOpts().OpenMP &&
3299 getASTContext().getLangOpts().OpenMPIsTargetDevice
3300 ? getASTContext().getAuxTargetInfo()
3301 : &getASTContext().getTargetInfo();
3305 case BuiltinType::Float128: {
3307 getASTContext().getLangOpts().OpenMP &&
3308 getASTContext().getLangOpts().OpenMPIsTargetDevice
3309 ? getASTContext().getAuxTargetInfo()
3310 : &getASTContext().getTargetInfo();
3314 case BuiltinType::BFloat16: {
3316 ((getASTContext().getLangOpts().OpenMP &&
3317 getASTContext().getLangOpts().OpenMPIsTargetDevice) ||
3318 getASTContext().getLangOpts().SYCLIsDevice)
3319 ? getASTContext().getAuxTargetInfo()
3320 : &getASTContext().getTargetInfo();
3324 case BuiltinType::Ibm128: {
3325 const TargetInfo *TI = &getASTContext().getTargetInfo();
3329 case BuiltinType::NullPtr:
3333#define BUILTIN_TYPE(Id, SingletonId)
3334#define PLACEHOLDER_TYPE(Id, SingletonId) \
3335 case BuiltinType::Id:
3336#include "clang/AST/BuiltinTypes.def"
3337 case BuiltinType::Dependent:
3339 llvm_unreachable(
"mangling a placeholder type");
3341 case BuiltinType::ObjCId:
3342 Out <<
"11objc_object";
3344 case BuiltinType::ObjCClass:
3345 Out <<
"10objc_class";
3347 case BuiltinType::ObjCSel:
3348 Out <<
"13objc_selector";
3350#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3351 case BuiltinType::Id: \
3352 type_name = "ocl_" #ImgType "_" #Suffix; \
3353 Out << type_name.size() << type_name; \
3355#include "clang/Basic/OpenCLImageTypes.def"
3356 case BuiltinType::OCLSampler:
3357 Out <<
"11ocl_sampler";
3359 case BuiltinType::OCLEvent:
3360 Out <<
"9ocl_event";
3362 case BuiltinType::OCLClkEvent:
3363 Out <<
"12ocl_clkevent";
3365 case BuiltinType::OCLQueue:
3366 Out <<
"9ocl_queue";
3368 case BuiltinType::OCLReserveID:
3369 Out <<
"13ocl_reserveid";
3371#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3372 case BuiltinType::Id: \
3373 type_name = "ocl_" #ExtType; \
3374 Out << type_name.size() << type_name; \
3376#include "clang/Basic/OpenCLExtensionTypes.def"
3380#define SVE_VECTOR_TYPE(InternalName, MangledName, Id, SingletonId, NumEls, \
3381 ElBits, IsSigned, IsFP, IsBF) \
3382 case BuiltinType::Id: \
3383 if (T->getKind() == BuiltinType::SveBFloat16 && \
3384 isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
3386 type_name = "__SVBFloat16_t"; \
3387 Out << "u" << type_name.size() << type_name; \
3389 type_name = MangledName; \
3390 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3394#define SVE_PREDICATE_TYPE(InternalName, MangledName, Id, SingletonId, NumEls) \
3395 case BuiltinType::Id: \
3396 type_name = MangledName; \
3397 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3400#define SVE_OPAQUE_TYPE(InternalName, MangledName, Id, SingletonId) \
3401 case BuiltinType::Id: \
3402 type_name = MangledName; \
3403 Out << (type_name == InternalName ? "u" : "") << type_name.size() \
3406#include "clang/Basic/AArch64SVEACLETypes.def"
3407#define PPC_VECTOR_TYPE(Name, Id, Size) \
3408 case BuiltinType::Id: \
3409 type_name = #Name; \
3410 Out << 'u' << type_name.size() << type_name; \
3412#include "clang/Basic/PPCTypes.def"
3414#define RVV_TYPE(Name, Id, SingletonId) \
3415 case BuiltinType::Id: \
3417 Out << 'u' << type_name.size() << type_name; \
3419#include "clang/Basic/RISCVVTypes.def"
3420#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
3421 case BuiltinType::Id: \
3422 type_name = MangledName; \
3423 Out << 'u' << type_name.size() << type_name; \
3425#include "clang/Basic/WebAssemblyReferenceTypes.def"
3429StringRef CXXNameMangler::getCallingConvQualifierName(
CallingConv CC) {
3472 return "swiftasynccall";
3474 llvm_unreachable(
"bad calling convention");
3477void CXXNameMangler::mangleExtFunctionInfo(
const FunctionType *
T) {
3486 StringRef CCQualifier = getCallingConvQualifierName(
T->
getExtInfo().
getCC());
3487 if (!CCQualifier.empty())
3488 mangleVendorQualifier(CCQualifier);
3502 case ParameterABI::Ordinary:
3506 case ParameterABI::SwiftContext:
3507 case ParameterABI::SwiftAsyncContext:
3508 case ParameterABI::SwiftErrorResult:
3509 case ParameterABI::SwiftIndirectResult:
3515 mangleVendorQualifier(
"ns_consumed");
3518 mangleVendorQualifier(
"noescape");
3525 mangleExtFunctionInfo(
T);
3542 mangleType(ExceptTy);
3553 mangleBareFunctionType(
T,
true);
3567 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3569 FunctionTypeDepth.enterResultType();
3571 FunctionTypeDepth.leaveResultType();
3573 FunctionTypeDepth.pop(saved);
3578 bool MangleReturnType,
3582 FunctionTypeDepthState saved = FunctionTypeDepth.push();
3585 if (MangleReturnType) {
3586 FunctionTypeDepth.enterResultType();
3590 mangleVendorQualifier(
"ns_returns_retained");
3595 auto SplitReturnTy = ReturnTy.
split();
3597 ReturnTy = getASTContext().getQualifiedType(SplitReturnTy);
3599 mangleType(ReturnTy);
3601 FunctionTypeDepth.leaveResultType();
3609 for (
unsigned I = 0, E = Proto->
getNumParams(); I != E; ++I) {
3623 assert(
Attr->getType() <= 9 &&
Attr->getType() >= 0);
3624 if (
Attr->isDynamic())
3625 Out <<
"U25pass_dynamic_object_size" <<
Attr->getType();
3627 Out <<
"U17pass_object_size" <<
Attr->getType();
3638 FunctionTypeDepth.enterResultType();
3642 FunctionTypeDepth.pop(saved);
3648 mangleName(
T->getDecl());
3653void CXXNameMangler::mangleType(
const EnumType *
T) {
3654 mangleType(
static_cast<const TagType*
>(
T));
3656void CXXNameMangler::mangleType(
const RecordType *
T) {
3657 mangleType(
static_cast<const TagType*
>(
T));
3659void CXXNameMangler::mangleType(
const TagType *
T) {
3660 mangleName(
T->getDecl());
3667 Out <<
'A' <<
T->getSize() <<
'_';
3668 mangleType(
T->getElementType());
3673 if (
T->getSizeExpr())
3674 mangleExpression(
T->getSizeExpr());
3676 mangleType(
T->getElementType());
3683 if (
T->getSizeExpr())
3684 mangleExpression(
T->getSizeExpr());
3686 mangleType(
T->getElementType());
3690 mangleType(
T->getElementType());
3720 mangleType(PointeeType);
3725 mangleTemplateParameter(
T->getDepth(),
T->getIndex());
3734 Out <<
"_SUBSTPACK_";
3762 mangleType(
T->getElementType());
3768void CXXNameMangler::mangleNeonVectorType(
const VectorType *
T) {
3770 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3771 const char *EltName =
nullptr;
3772 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3773 switch (cast<BuiltinType>(EltType)->
getKind()) {
3774 case BuiltinType::SChar:
3775 case BuiltinType::UChar:
3776 EltName =
"poly8_t";
3778 case BuiltinType::Short:
3779 case BuiltinType::UShort:
3780 EltName =
"poly16_t";
3782 case BuiltinType::LongLong:
3783 case BuiltinType::ULongLong:
3784 EltName =
"poly64_t";
3786 default: llvm_unreachable(
"unexpected Neon polynomial vector element type");
3789 switch (cast<BuiltinType>(EltType)->
getKind()) {
3790 case BuiltinType::SChar: EltName =
"int8_t";
break;
3791 case BuiltinType::UChar: EltName =
"uint8_t";
break;
3792 case BuiltinType::Short: EltName =
"int16_t";
break;
3793 case BuiltinType::UShort: EltName =
"uint16_t";
break;
3794 case BuiltinType::Int: EltName =
"int32_t";
break;
3795 case BuiltinType::UInt: EltName =
"uint32_t";
break;
3796 case BuiltinType::LongLong: EltName =
"int64_t";
break;
3797 case BuiltinType::ULongLong: EltName =
"uint64_t";
break;
3798 case BuiltinType::Double: EltName =
"float64_t";
break;
3799 case BuiltinType::Float: EltName =
"float32_t";
break;
3800 case BuiltinType::Half: EltName =
"float16_t";
break;
3801 case BuiltinType::BFloat16: EltName =
"bfloat16_t";
break;
3803 llvm_unreachable(
"unexpected Neon vector element type");
3806 const char *BaseName =
nullptr;
3807 unsigned BitSize = (
T->getNumElements() *
3808 getASTContext().getTypeSize(EltType));
3810 BaseName =
"__simd64_";
3812 assert(BitSize == 128 &&
"Neon vector type not 64 or 128 bits");
3813 BaseName =
"__simd128_";
3815 Out << strlen(BaseName) + strlen(EltName);
3816 Out << BaseName << EltName;
3823 "cannot mangle this dependent neon vector type yet");
3824 Diags.
Report(
T->getAttributeLoc(), DiagID);
3829 case BuiltinType::SChar:
3831 case BuiltinType::Short:
3833 case BuiltinType::Int:
3835 case BuiltinType::Long:
3836 case BuiltinType::LongLong:
3838 case BuiltinType::UChar:
3840 case BuiltinType::UShort:
3842 case BuiltinType::UInt:
3844 case BuiltinType::ULong:
3845 case BuiltinType::ULongLong:
3847 case BuiltinType::Half:
3849 case BuiltinType::Float:
3851 case BuiltinType::Double:
3853 case BuiltinType::BFloat16:
3856 llvm_unreachable(
"Unexpected vector element base type");
3863void CXXNameMangler::mangleAArch64NeonVectorType(
const VectorType *
T) {
3865 assert(EltType->
isBuiltinType() &&
"Neon vector element not a BuiltinType");
3867 (
T->getNumElements() * getASTContext().getTypeSize(EltType));
3870 assert((BitSize == 64 || BitSize == 128) &&
3871 "Neon vector type not 64 or 128 bits");
3874 if (
T->getVectorKind() == VectorKind::NeonPoly) {
3875 switch (cast<BuiltinType>(EltType)->
getKind()) {
3876 case BuiltinType::UChar:
3879 case BuiltinType::UShort:
3882 case BuiltinType::ULong:
3883 case BuiltinType::ULongLong:
3887 llvm_unreachable(
"unexpected Neon polynomial vector element type");
3893 (
"__" + EltName +
"x" + Twine(
T->getNumElements()) +
"_t").str();
3900 "cannot mangle this dependent neon vector type yet");
3901 Diags.
Report(
T->getAttributeLoc(), DiagID);
3928void CXXNameMangler::mangleAArch64FixedSveVectorType(
const VectorType *
T) {
3929 assert((
T->getVectorKind() == VectorKind::SveFixedLengthData ||
3930 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) &&
3931 "expected fixed-length SVE vector!");
3935 "expected builtin type for fixed-length SVE vector!");
3938 switch (cast<BuiltinType>(EltType)->
getKind()) {
3939 case BuiltinType::SChar:
3942 case BuiltinType::UChar: {
3943 if (
T->getVectorKind() == VectorKind::SveFixedLengthData)
3949 case BuiltinType::Short:
3952 case BuiltinType::UShort:
3955 case BuiltinType::Int:
3958 case BuiltinType::UInt:
3961 case BuiltinType::Long:
3964 case BuiltinType::ULong:
3967 case BuiltinType::Half:
3970 case BuiltinType::Float:
3973 case BuiltinType::Double:
3976 case BuiltinType::BFloat16:
3980 llvm_unreachable(
"unexpected element type for fixed-length SVE vector!");
3983 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
3985 if (
T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
3989 << VecSizeInBits <<
"EE";
3992void CXXNameMangler::mangleAArch64FixedSveVectorType(
3997 "cannot mangle this dependent fixed-length SVE vector type yet");
3998 Diags.
Report(
T->getAttributeLoc(), DiagID);
4001void CXXNameMangler::mangleRISCVFixedRVVVectorType(
const VectorType *
T) {
4002 assert((
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4003 T->getVectorKind() == VectorKind::RVVFixedLengthMask) &&
4004 "expected fixed-length RVV vector!");
4008 "expected builtin type for fixed-length RVV vector!");
4011 llvm::raw_svector_ostream TypeNameOS(TypeNameStr);
4012 TypeNameOS <<
"__rvv_";
4013 switch (cast<BuiltinType>(EltType)->
getKind()) {
4014 case BuiltinType::SChar:
4015 TypeNameOS <<
"int8";
4017 case BuiltinType::UChar:
4018 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData)
4019 TypeNameOS <<
"uint8";
4021 TypeNameOS <<
"bool";
4023 case BuiltinType::Short:
4024 TypeNameOS <<
"int16";
4026 case BuiltinType::UShort:
4027 TypeNameOS <<
"uint16";
4029 case BuiltinType::Int:
4030 TypeNameOS <<
"int32";
4032 case BuiltinType::UInt:
4033 TypeNameOS <<
"uint32";
4035 case BuiltinType::Long:
4036 TypeNameOS <<
"int64";
4038 case BuiltinType::ULong:
4039 TypeNameOS <<
"uint64";
4041 case BuiltinType::Float16:
4042 TypeNameOS <<
"float16";
4044 case BuiltinType::Float:
4045 TypeNameOS <<
"float32";
4047 case BuiltinType::Double:
4048 TypeNameOS <<
"float64";
4051 llvm_unreachable(
"unexpected element type for fixed-length RVV vector!");
4054 unsigned VecSizeInBits = getASTContext().getTypeInfo(
T).Width;
4057 auto VScale = getASTContext().getTargetInfo().getVScaleRange(
4058 getASTContext().getLangOpts());
4059 unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
4061 if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4063 if (VecSizeInBits >= VLen)
4064 TypeNameOS << (VecSizeInBits / VLen);
4066 TypeNameOS <<
'f' << (VLen / VecSizeInBits);
4068 TypeNameOS << (VLen / VecSizeInBits);
4072 Out <<
"9__RVV_VLSI" <<
'u' << TypeNameStr.size() << TypeNameStr <<
"Lj"
4073 << VecSizeInBits <<
"EE";
4076void CXXNameMangler::mangleRISCVFixedRVVVectorType(
4081 "cannot mangle this dependent fixed-length RVV vector type yet");
4082 Diags.
Report(
T->getAttributeLoc(), DiagID);
4093void CXXNameMangler::mangleType(
const VectorType *
T) {
4094 if ((
T->getVectorKind() == VectorKind::Neon ||
4095 T->getVectorKind() == VectorKind::NeonPoly)) {
4096 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4097 llvm::Triple::ArchType Arch =
4098 getASTContext().getTargetInfo().getTriple().getArch();
4099 if ((Arch == llvm::Triple::aarch64 ||
4100 Arch == llvm::Triple::aarch64_be) && !
Target.isOSDarwin())
4101 mangleAArch64NeonVectorType(
T);
4103 mangleNeonVectorType(
T);
4105 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4106 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4107 mangleAArch64FixedSveVectorType(
T);
4109 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData ||
4110 T->getVectorKind() == VectorKind::RVVFixedLengthMask) {
4111 mangleRISCVFixedRVVVectorType(
T);
4114 Out <<
"Dv" <<
T->getNumElements() <<
'_';
4115 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4117 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4120 mangleType(
T->getElementType());
4124 if ((
T->getVectorKind() == VectorKind::Neon ||
4125 T->getVectorKind() == VectorKind::NeonPoly)) {
4126 llvm::Triple
Target = getASTContext().getTargetInfo().getTriple();
4127 llvm::Triple::ArchType Arch =
4128 getASTContext().getTargetInfo().getTriple().getArch();
4129 if ((Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be) &&
4131 mangleAArch64NeonVectorType(
T);
4133 mangleNeonVectorType(
T);
4135 }
else if (
T->getVectorKind() == VectorKind::SveFixedLengthData ||
4136 T->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
4137 mangleAArch64FixedSveVectorType(
T);
4139 }
else if (
T->getVectorKind() == VectorKind::RVVFixedLengthData) {
4140 mangleRISCVFixedRVVVectorType(
T);
4145 mangleExpression(
T->getSizeExpr());
4147 if (
T->getVectorKind() == VectorKind::AltiVecPixel)
4149 else if (
T->getVectorKind() == VectorKind::AltiVecBool)
4152 mangleType(
T->getElementType());
4160 mangleExpression(
T->getSizeExpr());
4162 mangleType(
T->getElementType());
4169 StringRef VendorQualifier =
"matrix_type";
4170 Out <<
"u" << VendorQualifier.size() << VendorQualifier;
4173 auto &ASTCtx = getASTContext();
4174 unsigned BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
4175 llvm::APSInt Rows(BitWidth);
4176 Rows =
T->getNumRows();
4177 mangleIntegerLiteral(ASTCtx.getSizeType(), Rows);
4178 llvm::APSInt Columns(BitWidth);
4179 Columns =
T->getNumColumns();
4180 mangleIntegerLiteral(ASTCtx.getSizeType(), Columns);
4181 mangleType(
T->getElementType());
4188 StringRef VendorQualifier =
"matrix_type";
4189 Out <<
"u" << VendorQualifier.size() << VendorQualifier;
4192 mangleTemplateArgExpr(
T->getRowExpr());
4193 mangleTemplateArgExpr(
T->getColumnExpr());
4194 mangleType(
T->getElementType());
4200 mangleQualifiers(split.
Quals,
T);
4207 mangleType(
T->getPattern());
4211 if (!
T->hasSelectedType())
4212 mangleType(
T->getPattern());
4214 mangleType(
T->getSelectedType());
4218 mangleSourceName(
T->getDecl()->getIdentifier());
4223 if (
T->isKindOfType())
4224 Out <<
"U8__kindof";
4226 if (!
T->qual_empty()) {
4229 llvm::raw_svector_ostream QualOS(QualStr);
4230 QualOS <<
"objcproto";
4231 for (
const auto *I :
T->quals()) {
4232 StringRef
name = I->getName();
4235 Out <<
'U' << QualStr.size() << QualStr;
4238 mangleType(
T->getBaseType());
4240 if (
T->isSpecialized()) {
4243 for (
auto typeArg :
T->getTypeArgs())
4244 mangleType(typeArg);
4250 Out <<
"U13block_pointer";
4258 mangleType(
T->getInjectedSpecializationType());
4262 if (
TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl()) {
4263 mangleTemplateName(TD,
T->template_arguments());
4268 mangleTemplatePrefix(
T->getTemplateName());
4273 mangleTemplateArgs(
T->getTemplateName(),
T->template_arguments());
4289 switch (
T->getKeyword()) {
4290 case ElaboratedTypeKeyword::None:
4291 case ElaboratedTypeKeyword::Typename:
4293 case ElaboratedTypeKeyword::Struct:
4294 case ElaboratedTypeKeyword::Class:
4295 case ElaboratedTypeKeyword::Interface:
4298 case ElaboratedTypeKeyword::Union:
4301 case ElaboratedTypeKeyword::Enum:
4307 manglePrefix(
T->getQualifier());
4308 mangleSourceName(
T->getIdentifier());
4318 getASTContext().getDependentTemplateName(
T->getQualifier(),
4319 T->getIdentifier());
4320 mangleTemplatePrefix(Prefix);
4325 mangleTemplateArgs(Prefix,
T->template_arguments());
4329void CXXNameMangler::mangleType(
const TypeOfType *
T) {
4342 Expr *E =
T->getUnderlyingExpr();
4352 if (isa<DeclRefExpr>(E) ||
4353 isa<MemberExpr>(E) ||
4354 isa<UnresolvedLookupExpr>(E) ||
4355 isa<DependentScopeDeclRefExpr>(E) ||
4356 isa<CXXDependentScopeMemberExpr>(E) ||
4357 isa<UnresolvedMemberExpr>(E))
4361 mangleExpression(E);
4371 StringRef BuiltinName;
4372 switch (
T->getUTTKind()) {
4373#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
4374 case UnaryTransformType::Enum: \
4375 BuiltinName = "__" #Trait; \
4377#include "clang/Basic/TransformTypeTraits.def"
4379 Out << BuiltinName.size() << BuiltinName;
4383 mangleType(
T->getBaseType());
4387void CXXNameMangler::mangleType(
const AutoType *
T) {
4388 assert(
T->getDeducedType().isNull() &&
4389 "Deduced AutoType shouldn't be handled here!");
4390 assert(
T->getKeyword() != AutoTypeKeyword::GNUAutoType &&
4391 "shouldn't need to mangle __auto_type!");
4396 if (
T->isConstrained() && !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
4397 Out << (
T->isDecltypeAuto() ?
"DK" :
"Dk");
4398 mangleTypeConstraint(
T->getTypeConstraintConcept(),
4399 T->getTypeConstraintArguments());
4401 Out << (
T->isDecltypeAuto() ?
"Dc" :
"Da");
4408 return mangleType(Deduced);
4410 TemplateDecl *TD =
T->getTemplateName().getAsTemplateDecl();
4411 assert(TD &&
"shouldn't form deduced TST unless we know we have a template");
4413 if (mangleSubstitution(TD))
4417 addSubstitution(TD);
4420void CXXNameMangler::mangleType(
const AtomicType *
T) {
4424 mangleType(
T->getValueType());
4427void CXXNameMangler::mangleType(
const PipeType *
T) {
4434void CXXNameMangler::mangleType(
const BitIntType *
T) {
4438 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B") <<
T->getNumBits() <<
"_";
4445 Out <<
"D" << (
T->isUnsigned() ?
"U" :
"B");
4446 mangleExpression(
T->getNumBitsExpr());
4451 mangleType(cast<ConstantArrayType>(
T));
4454void CXXNameMangler::mangleIntegerLiteral(
QualType T,
4455 const llvm::APSInt &
Value) {
4462 Out << (
Value.getBoolValue() ?
'1' :
'0');
4464 mangleNumber(
Value);
4470void CXXNameMangler::mangleMemberExprBase(
const Expr *
Base,
bool IsArrow) {
4473 if (!RT->getDecl()->isAnonymousStructOrUnion())
4475 const auto *ME = dyn_cast<MemberExpr>(
Base);
4478 Base = ME->getBase();
4479 IsArrow = ME->isArrow();
4482 if (
Base->isImplicitCXXThis()) {
4488 Out << (IsArrow ?
"pt" :
"dt");
4489 mangleExpression(
Base);
4494void CXXNameMangler::mangleMemberExpr(
const Expr *base,
4500 unsigned NumTemplateArgs,
4505 mangleMemberExprBase(base, isArrow);
4506 mangleUnresolvedName(qualifier, member, TemplateArgs, NumTemplateArgs, arity);
4519 if (callee == fn)
return false;
4523 if (!lookup)
return false;
4540void CXXNameMangler::mangleCastExpression(
const Expr *E, StringRef CastEncoding) {
4542 Out << CastEncoding;
4547void CXXNameMangler::mangleInitListElements(
const InitListExpr *InitList) {
4549 InitList = Syntactic;
4550 for (
unsigned i = 0, e = InitList->
getNumInits(); i != e; ++i)
4551 mangleExpression(InitList->
getInit(i));
4554void CXXNameMangler::mangleRequirement(
SourceLocation RequiresExprLoc,
4561 auto HandleSubstitutionFailure =
4566 "containing a substitution failure");
4567 Diags.
Report(Loc, DiagID);
4572 case Requirement::RK_Type: {
4573 const auto *TR = cast<concepts::TypeRequirement>(Req);
4574 if (TR->isSubstitutionFailure())
4575 return HandleSubstitutionFailure(
4576 TR->getSubstitutionDiagnostic()->DiagLoc);
4579 mangleType(TR->getType()->getType());
4583 case Requirement::RK_Simple:
4584 case Requirement::RK_Compound: {
4585 const auto *ER = cast<concepts::ExprRequirement>(Req);
4586 if (ER->isExprSubstitutionFailure())
4587 return HandleSubstitutionFailure(
4588 ER->getExprSubstitutionDiagnostic()->DiagLoc);
4591 mangleExpression(ER->getExpr());
4593 if (ER->hasNoexceptRequirement())
4596 if (!ER->getReturnTypeRequirement().isEmpty()) {
4597 if (ER->getReturnTypeRequirement().isSubstitutionFailure())
4598 return HandleSubstitutionFailure(ER->getReturnTypeRequirement()
4599 .getSubstitutionDiagnostic()
4603 mangleTypeConstraint(ER->getReturnTypeRequirement().getTypeConstraint());
4608 case Requirement::RK_Nested:
4609 const auto *NR = cast<concepts::NestedRequirement>(Req);
4610 if (NR->hasInvalidConstraint()) {
4613 return HandleSubstitutionFailure(RequiresExprLoc);
4617 mangleExpression(NR->getConstraintExpr());
4622void CXXNameMangler::mangleExpression(
const Expr *E,
unsigned Arity,
4623 bool AsTemplateArg) {
4652 QualType ImplicitlyConvertedToType;
4656 bool IsPrimaryExpr =
true;
4657 auto NotPrimaryExpr = [&] {
4658 if (AsTemplateArg && IsPrimaryExpr)
4660 IsPrimaryExpr =
false;
4663 auto MangleDeclRefExpr = [&](
const NamedDecl *D) {
4664 switch (D->getKind()) {
4674 mangleFunctionParam(cast<ParmVarDecl>(D));
4677 case Decl::EnumConstant: {
4684 case Decl::NonTypeTemplateParm:
4697 case Expr::NoStmtClass:
4698#define ABSTRACT_STMT(Type)
4699#define EXPR(Type, Base)
4700#define STMT(Type, Base) \
4701 case Expr::Type##Class:
4702#include "clang/AST/StmtNodes.inc"
4707 case Expr::AddrLabelExprClass:
4708 case Expr::DesignatedInitUpdateExprClass:
4709 case Expr::ImplicitValueInitExprClass:
4710 case Expr::ArrayInitLoopExprClass:
4711 case Expr::ArrayInitIndexExprClass:
4712 case Expr::NoInitExprClass:
4713 case Expr::ParenListExprClass:
4714 case Expr::MSPropertyRefExprClass:
4715 case Expr::MSPropertySubscriptExprClass:
4716 case Expr::TypoExprClass:
4717 case Expr::RecoveryExprClass:
4718 case Expr::ArraySectionExprClass:
4719 case Expr::OMPArrayShapingExprClass:
4720 case Expr::OMPIteratorExprClass:
4721 case Expr::CXXInheritedCtorInitExprClass:
4722 case Expr::CXXParenListInitExprClass:
4723 case Expr::PackIndexingExprClass:
4724 llvm_unreachable(
"unexpected statement kind");
4726 case Expr::ConstantExprClass:
4727 E = cast<ConstantExpr>(E)->getSubExpr();
4731 case Expr::BlockExprClass:
4732 case Expr::ChooseExprClass:
4733 case Expr::CompoundLiteralExprClass:
4734 case Expr::ExtVectorElementExprClass:
4735 case Expr::GenericSelectionExprClass:
4736 case Expr::ObjCEncodeExprClass:
4737 case Expr::ObjCIsaExprClass:
4738 case Expr::ObjCIvarRefExprClass:
4739 case Expr::ObjCMessageExprClass:
4740 case Expr::ObjCPropertyRefExprClass:
4741 case Expr::ObjCProtocolExprClass:
4742 case Expr::ObjCSelectorExprClass:
4743 case Expr::ObjCStringLiteralClass:
4744 case Expr::ObjCBoxedExprClass:
4745 case Expr::ObjCArrayLiteralClass:
4746 case Expr::ObjCDictionaryLiteralClass:
4747 case Expr::ObjCSubscriptRefExprClass:
4748 case Expr::ObjCIndirectCopyRestoreExprClass:
4749 case Expr::ObjCAvailabilityCheckExprClass:
4750 case Expr::OffsetOfExprClass:
4751 case Expr::PredefinedExprClass:
4752 case Expr::ShuffleVectorExprClass:
4753 case Expr::ConvertVectorExprClass:
4754 case Expr::StmtExprClass:
4755 case Expr::ArrayTypeTraitExprClass:
4756 case Expr::ExpressionTraitExprClass:
4757 case Expr::VAArgExprClass:
4758 case Expr::CUDAKernelCallExprClass:
4759 case Expr::AsTypeExprClass:
4760 case Expr::PseudoObjectExprClass:
4761 case Expr::AtomicExprClass:
4762 case Expr::SourceLocExprClass:
4763 case Expr::BuiltinBitCastExprClass:
4770 "cannot yet mangle expression type %0");
4778 case Expr::CXXUuidofExprClass: {
4783 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
4784 Out <<
"u8__uuidof";
4793 Out <<
"u8__uuidoft";
4797 Out <<
"u8__uuidofz";
4798 mangleExpression(UuidExp);
4805 case Expr::BinaryConditionalOperatorClass: {
4810 "?: operator with omitted middle operand cannot be mangled");
4817 case Expr::OpaqueValueExprClass:
4818 llvm_unreachable(
"cannot mangle opaque value; mangling wrong thing?");
4820 case Expr::InitListExprClass: {
4823 mangleInitListElements(cast<InitListExpr>(E));
4828 case Expr::DesignatedInitExprClass: {
4830 auto *DIE = cast<DesignatedInitExpr>(E);
4831 for (
const auto &
Designator : DIE->designators()) {
4837 mangleExpression(DIE->getArrayIndex(
Designator));
4840 "unknown designator kind");
4842 mangleExpression(DIE->getArrayRangeStart(
Designator));
4843 mangleExpression(DIE->getArrayRangeEnd(
Designator));
4846 mangleExpression(DIE->getInit());
4850 case Expr::CXXDefaultArgExprClass:
4851 E = cast<CXXDefaultArgExpr>(E)->getExpr();
4854 case Expr::CXXDefaultInitExprClass:
4855 E = cast<CXXDefaultInitExpr>(E)->getExpr();
4858 case Expr::CXXStdInitializerListExprClass:
4859 E = cast<CXXStdInitializerListExpr>(E)->getSubExpr();
4862 case Expr::SubstNonTypeTemplateParmExprClass: {
4865 auto *SNTTPE = cast<SubstNonTypeTemplateParmExpr>(E);
4866 if (
auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
4868 QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
4869 assert(CE->hasAPValueResult() &&
"expected the NTTP to have an APValue");
4870 mangleValueInTemplateArg(ParamType, CE->getAPValueResult(),
false,
4876 E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement();
4880 case Expr::UserDefinedLiteralClass:
4883 case Expr::CXXMemberCallExprClass:
4884 case Expr::CallExprClass: {
4886 const CallExpr *CE = cast<CallExpr>(E);
4905 if (isa<PackExpansionExpr>(Arg))
4906 CallArity = UnknownArity;
4908 mangleExpression(CE->
getCallee(), CallArity);
4910 mangleExpression(Arg);
4915 case Expr::CXXNewExprClass: {
4919 Out << (New->
isArray() ?
"na" :
"nw");
4922 mangleExpression(*I);
4936 mangleExpression(*I);
4938 for (
unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
4939 mangleExpression(PLE->getExpr(i));
4941 CXXNewInitializationStyle::Braces &&
4942 isa<InitListExpr>(
Init)) {
4944 mangleInitListElements(cast<InitListExpr>(
Init));
4946 mangleExpression(
Init);
4952 case Expr::CXXPseudoDestructorExprClass: {
4954 const auto *PDE = cast<CXXPseudoDestructorExpr>(E);
4955 if (
const Expr *
Base = PDE->getBase())
4956 mangleMemberExprBase(
Base, PDE->isArrow());
4960 mangleUnresolvedPrefix(Qualifier,
4962 mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType());
4966 if (!mangleUnresolvedTypeOrSimpleId(ScopeInfo->getType()))
4969 }
else if (Qualifier) {
4970 mangleUnresolvedPrefix(Qualifier);
4974 QualType DestroyedType = PDE->getDestroyedType();
4975 mangleUnresolvedTypeOrSimpleId(DestroyedType);
4979 case Expr::MemberExprClass: {
4990 case Expr::UnresolvedMemberExprClass: {
5001 case Expr::CXXDependentScopeMemberExprClass: {
5004 = cast<CXXDependentScopeMemberExpr>(E);
5014 case Expr::UnresolvedLookupExprClass: {
5023 case Expr::CXXUnresolvedConstructExprClass: {
5029 assert(N == 1 &&
"unexpected form for list initialization");
5030 auto *IL = cast<InitListExpr>(CE->
getArg(0));
5033 mangleInitListElements(IL);
5040 if (N != 1) Out <<
'_';
5041 for (
unsigned I = 0; I != N; ++I) mangleExpression(CE->
getArg(I));
5042 if (N != 1) Out <<
'E';
5046 case Expr::CXXConstructExprClass: {
5048 const auto *CE = cast<CXXConstructExpr>(E);
5053 "implicit CXXConstructExpr must have one argument");
5054 E = cast<CXXConstructExpr>(E)->getArg(0);
5060 mangleExpression(E);
5065 case Expr::CXXTemporaryObjectExprClass: {
5067 const auto *CE = cast<CXXTemporaryObjectExpr>(E);
5076 if (!List && N != 1)
5078 if (CE->isStdInitListInitialization()) {
5084 auto *ILE = cast<InitListExpr>(SILE->getSubExpr()->IgnoreImplicit());
5085 mangleInitListElements(ILE);
5088 mangleExpression(E);
5095 case Expr::CXXScalarValueInitExprClass:
5102 case Expr::CXXNoexceptExprClass:
5105 mangleExpression(cast<CXXNoexceptExpr>(E)->getOperand());
5108 case Expr::UnaryExprOrTypeTraitExprClass: {
5127 : ImplicitlyConvertedToType;
5129 mangleIntegerLiteral(
T,
V);
5135 auto MangleAlignofSizeofArg = [&] {
5148 MangleAlignofSizeofArg();
5150 case UETT_PreferredAlignOf:
5154 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
5155 Out <<
"u11__alignof__";
5166 MangleAlignofSizeofArg();
5168 case UETT_DataSizeOf: {
5172 "cannot yet mangle __datasizeof expression");
5176 case UETT_VecStep: {
5179 "cannot yet mangle vec_step expression");
5183 case UETT_OpenMPRequiredSimdAlign: {
5187 "cannot yet mangle __builtin_omp_required_simd_align expression");
5191 case UETT_VectorElements: {
5195 "cannot yet mangle __builtin_vectorelements expression");
5203 case Expr::TypeTraitExprClass: {
5209 Out << Spelling.size() << Spelling;
5211 mangleType(TSI->getType());
5217 case Expr::CXXThrowExprClass: {
5231 case Expr::CXXTypeidExprClass: {
5246 case Expr::CXXDeleteExprClass: {
5257 case Expr::UnaryOperatorClass: {
5266 case Expr::ArraySubscriptExprClass: {
5273 mangleExpression(AE->
getLHS());
5274 mangleExpression(AE->
getRHS());
5278 case Expr::MatrixSubscriptExprClass: {
5282 mangleExpression(ME->
getBase());
5288 case Expr::CompoundAssignOperatorClass:
5289 case Expr::BinaryOperatorClass: {
5297 mangleExpression(BO->
getLHS());
5298 mangleExpression(BO->
getRHS());
5302 case Expr::CXXRewrittenBinaryOperatorClass: {
5306 cast<CXXRewrittenBinaryOperator>(E)->getDecomposedForm();
5309 mangleExpression(Decomposed.
LHS);
5310 mangleExpression(Decomposed.
RHS);
5314 case Expr::ConditionalOperatorClass: {
5317 mangleOperatorName(OO_Conditional, 3);
5318 mangleExpression(CO->
getCond());
5319 mangleExpression(CO->
getLHS(), Arity);
5320 mangleExpression(CO->
getRHS(), Arity);
5324 case Expr::ImplicitCastExprClass: {
5325 ImplicitlyConvertedToType = E->
getType();
5326 E = cast<ImplicitCastExpr>(E)->getSubExpr();
5330 case Expr::ObjCBridgedCastExprClass: {
5334 StringRef
Kind = cast<ObjCBridgedCastExpr>(E)->getBridgeKindName();
5335 Out <<
"v1U" <<
Kind.size() <<
Kind;
5336 mangleCastExpression(E,
"cv");
5340 case Expr::CStyleCastExprClass:
5342 mangleCastExpression(E,
"cv");
5345 case Expr::CXXFunctionalCastExprClass: {
5347 auto *
Sub = cast<ExplicitCastExpr>(E)->getSubExpr()->IgnoreImplicit();
5349 if (
auto *CCE = dyn_cast<CXXConstructExpr>(Sub))
5350 if (CCE->getParenOrBraceRange().isInvalid())
5351 Sub = CCE->getArg(0)->IgnoreImplicit();
5352 if (
auto *StdInitList = dyn_cast<CXXStdInitializerListExpr>(Sub))
5353 Sub = StdInitList->getSubExpr()->IgnoreImplicit();
5354 if (
auto *IL = dyn_cast<InitListExpr>(Sub)) {
5357 mangleInitListElements(IL);
5360 mangleCastExpression(E,
"cv");
5365 case Expr::CXXStaticCastExprClass:
5367 mangleCastExpression(E,
"sc");
5369 case Expr::CXXDynamicCastExprClass:
5371 mangleCastExpression(E,
"dc");
5373 case Expr::CXXReinterpretCastExprClass:
5375 mangleCastExpression(E,
"rc");
5377 case Expr::CXXConstCastExprClass:
5379 mangleCastExpression(E,
"cc");
5381 case Expr::CXXAddrspaceCastExprClass:
5383 mangleCastExpression(E,
"ac");
5386 case Expr::CXXOperatorCallExprClass: {
5395 for (
unsigned i = 0; i != NumArgs; ++i)
5396 mangleExpression(CE->
getArg(i));
5400 case Expr::ParenExprClass:
5401 E = cast<ParenExpr>(E)->getSubExpr();
5404 case Expr::ConceptSpecializationExprClass: {
5405 auto *CSE = cast<ConceptSpecializationExpr>(E);
5406 if (isCompatibleWith(LangOptions::ClangABI::Ver17)) {
5411 mangleTemplateName(CSE->getNamedConcept(), CSE->getTemplateArguments());
5417 mangleUnresolvedName(
5418 CSE->getNestedNameSpecifierLoc().getNestedNameSpecifier(),
5419 CSE->getConceptNameInfo().getName(),
5420 CSE->getTemplateArgsAsWritten()->getTemplateArgs(),
5421 CSE->getTemplateArgsAsWritten()->getNumTemplateArgs());
5425 case Expr::RequiresExprClass: {
5427 auto *RE = cast<RequiresExpr>(E);
5431 if (RE->getLParenLoc().isValid()) {
5433 FunctionTypeDepthState saved = FunctionTypeDepth.push();
5434 if (RE->getLocalParameters().empty()) {
5437 for (
ParmVarDecl *Param : RE->getLocalParameters()) {
5445 FunctionTypeDepth.enterResultType();
5447 mangleRequirement(RE->getExprLoc(), Req);
5448 FunctionTypeDepth.pop(saved);
5453 mangleRequirement(RE->getExprLoc(), Req);
5459 case Expr::DeclRefExprClass:
5461 MangleDeclRefExpr(cast<DeclRefExpr>(E)->getDecl());
5464 case Expr::SubstNonTypeTemplateParmPackExprClass:
5470 Out <<
"_SUBSTPACK_";
5473 case Expr::FunctionParmPackExprClass: {
5477 Out <<
"v110_SUBSTPACK";
5482 case Expr::DependentScopeDeclRefExprClass: {
5491 case Expr::CXXBindTemporaryExprClass:
5492 E = cast<CXXBindTemporaryExpr>(E)->getSubExpr();
5495 case Expr::ExprWithCleanupsClass:
5496 E = cast<ExprWithCleanups>(E)->getSubExpr();
5499 case Expr::FloatingLiteralClass: {
5506 case Expr::FixedPointLiteralClass:
5508 mangleFixedPointLiteral();
5511 case Expr::CharacterLiteralClass:
5515 Out << cast<CharacterLiteral>(E)->getValue();
5520 case Expr::ObjCBoolLiteralExprClass:
5523 Out << (cast<ObjCBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5527 case Expr::CXXBoolLiteralExprClass:
5530 Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ?
'1' :
'0');
5534 case Expr::IntegerLiteralClass: {
5536 llvm::APSInt
Value(cast<IntegerLiteral>(E)->getValue());
5538 Value.setIsSigned(
true);
5543 case Expr::ImaginaryLiteralClass: {
5551 dyn_cast<FloatingLiteral>(IE->
getSubExpr())) {
5553 mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
5555 mangleFloat(Imag->getValue());
5558 llvm::APSInt
Value(cast<IntegerLiteral>(IE->
getSubExpr())->getValue());
5560 Value.setIsSigned(
true);
5561 mangleNumber(
Value);
5567 case Expr::StringLiteralClass: {
5571 assert(isa<ConstantArrayType>(E->
getType()));
5577 case Expr::GNUNullExprClass:
5580 mangleIntegerLiteral(E->
getType(), llvm::APSInt(32));
5583 case Expr::CXXNullPtrLiteralExprClass: {
5589 case Expr::LambdaExprClass: {
5594 mangleType(Context.getASTContext().
getRecordType(cast<LambdaExpr>(E)->getLambdaClass()));
5599 case Expr::PackExpansionExprClass:
5602 mangleExpression(cast<PackExpansionExpr>(E)->getPattern());
5605 case Expr::SizeOfPackExprClass: {
5607 auto *SPE = cast<SizeOfPackExpr>(E);
5608 if (SPE->isPartiallySubstituted()) {
5610 for (
const auto &A : SPE->getPartialArguments())
5611 mangleTemplateArg(A,
false);
5619 mangleTemplateParameter(TTP->getDepth(), TTP->getIndex());
5621 = dyn_cast<NonTypeTemplateParmDecl>(Pack))
5622 mangleTemplateParameter(NTTP->getDepth(), NTTP->getIndex());
5624 = dyn_cast<TemplateTemplateParmDecl>(Pack))
5625 mangleTemplateParameter(TempTP->getDepth(), TempTP->getIndex());
5627 mangleFunctionParam(cast<ParmVarDecl>(Pack));
5631 case Expr::MaterializeTemporaryExprClass:
5632 E = cast<MaterializeTemporaryExpr>(E)->getSubExpr();
5635 case Expr::CXXFoldExprClass: {
5637 auto *FE = cast<CXXFoldExpr>(E);
5638 if (FE->isLeftFold())
5639 Out << (FE->getInit() ?
"fL" :
"fl");
5641 Out << (FE->getInit() ?
"fR" :
"fr");
5643 if (FE->getOperator() == BO_PtrMemD)
5651 mangleExpression(FE->getLHS());
5653 mangleExpression(FE->getRHS());
5657 case Expr::CXXThisExprClass:
5662 case Expr::CoawaitExprClass:
5665 Out <<
"v18co_await";
5666 mangleExpression(cast<CoawaitExpr>(E)->getOperand());
5669 case Expr::DependentCoawaitExprClass:
5672 Out <<
"v18co_await";
5673 mangleExpression(cast<DependentCoawaitExpr>(E)->getOperand());
5676 case Expr::CoyieldExprClass:
5679 Out <<
"v18co_yield";
5680 mangleExpression(cast<CoawaitExpr>(E)->getOperand());
5682 case Expr::SYCLUniqueStableNameExprClass: {
5683 const auto *USN = cast<SYCLUniqueStableNameExpr>(E);
5686 Out <<
"u33__builtin_sycl_unique_stable_name";
5687 mangleType(USN->getTypeSourceInfo()->getType());
5694 if (AsTemplateArg && !IsPrimaryExpr)
5726void CXXNameMangler::mangleFunctionParam(
const ParmVarDecl *parm) {
5733 assert(parmDepth < FunctionTypeDepth.getDepth());
5734 unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
5735 if (FunctionTypeDepth.isInResultType())
5738 if (nestingDepth == 0) {
5741 Out <<
"fL" << (nestingDepth - 1) <<
'p';
5749 &&
"parameter's type is still an array type?");
5752 dyn_cast<DependentAddressSpaceType>(parm->
getType())) {
5759 if (parmIndex != 0) {
5760 Out << (parmIndex - 1);
5788 llvm_unreachable(
"closure constructors don't exist for the Itanium ABI!");
5791 mangleName(InheritedFrom);
5845 if (
auto *FTD = dyn_cast_or_null<FunctionTemplateDecl>(
ResolvedTemplate)) {
5846 auto *RD = dyn_cast<CXXRecordDecl>(FTD->getDeclContext());
5847 if (!RD || !RD->isGenericLambda())
5863 if (
auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
5864 return TTP->hasTypeConstraint();
5881 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
5882 return NTTP->getType()->isInstantiationDependentType() ||
5883 NTTP->getType()->getContainedDeducedType();
5887 auto *TTP = cast<TemplateTemplateParmDecl>(Param);
5898 auto MangleTemplateParamListToString =
5900 unsigned DepthOffset) {
5901 llvm::raw_svector_ostream Stream(Buffer);
5902 CXXNameMangler(
Mangler.Context, Stream,
5903 WithTemplateDepthOffset{DepthOffset})
5904 .mangleTemplateParameterList(Params);
5907 MangleTemplateParamListToString(ParamTemplateHead,
5908 TTP->getTemplateParameters(), 0);
5912 MangleTemplateParamListToString(ArgTemplateHead,
5914 TTP->getTemplateParameters()->
getDepth());
5915 return ParamTemplateHead != ArgTemplateHead;
5925 return {
true,
nullptr};
5930 assert(ParamIdx < ResolvedTemplate->getTemplateParameters()->size() &&
5931 "no parameter for argument");
5952 return {
true,
nullptr};
5967 auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param);
5968 bool NeedExactType = NTTP && NTTP->getType()->getContainedDeducedType();
5969 return {NeedExactType,
nullptr};
5981void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
5983 unsigned NumTemplateArgs) {
5986 TemplateArgManglingInfo Info(*
this, TN);
5987 for (
unsigned i = 0; i != NumTemplateArgs; ++i) {
5988 mangleTemplateArg(Info, i, TemplateArgs[i].
getArgument());
5990 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
5994void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
5998 TemplateArgManglingInfo Info(*
this, TN);
5999 for (
unsigned i = 0, e = AL.
size(); i != e; ++i) {
6000 mangleTemplateArg(Info, i, AL[i]);
6002 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6006void CXXNameMangler::mangleTemplateArgs(
TemplateName TN,
6010 TemplateArgManglingInfo Info(*
this, TN);
6011 for (
unsigned i = 0; i != Args.size(); ++i) {
6012 mangleTemplateArg(Info, i, Args[i]);
6014 mangleRequiresClause(Info.getTrailingRequiresClauseToMangle());
6018void CXXNameMangler::mangleTemplateArg(TemplateArgManglingInfo &Info,
6020 TemplateArgManglingInfo::Info ArgInfo = Info.getArgInfo(Index, A);
6023 if (ArgInfo.TemplateParameterToMangle &&
6024 !isCompatibleWith(LangOptions::ClangABI::Ver17)) {
6031 mangleTemplateParamDecl(ArgInfo.TemplateParameterToMangle);
6034 mangleTemplateArg(A, ArgInfo.NeedExactType);
6037void CXXNameMangler::mangleTemplateArg(
TemplateArgument A,
bool NeedExactType) {
6047 llvm_unreachable(
"Cannot mangle NULL template argument");
6074 auto *TPO = cast<TemplateParamObjectDecl>(D);
6075 mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
6076 TPO->getValue(),
true,
6089 !isCompatibleWith(LangOptions::ClangABI::Ver11))
6110 true, NeedExactType);
6116 mangleTemplateArg(
P, NeedExactType);
6122void CXXNameMangler::mangleTemplateArgExpr(
const Expr *E) {
6123 if (!isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6124 mangleExpression(E, UnknownArity,
true);
6139 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
6141 if (isa<VarDecl>(D) || isa<FunctionDecl>(D)) {
6149 mangleExpression(E);
6162 switch (
V.getKind()) {
6170 assert(RD &&
"unexpected type for record value");
6179 if (!FD->isUnnamedBitField() &&
6189 assert(RD &&
"unexpected type for union value");
6192 if (!FD->isUnnamedBitField())
6203 for (
unsigned I = 0, N =
V.getArrayInitializedElts(); I != N; ++I)
6211 for (
unsigned I = 0, N =
V.getVectorLength(); I != N; ++I)
6221 return V.getFloat().isPosZero();
6224 return !
V.getFixedPoint().getValue();
6227 return V.getComplexFloatReal().isPosZero() &&
6228 V.getComplexFloatImag().isPosZero();
6231 return !
V.getComplexIntReal() && !
V.getComplexIntImag();
6234 return V.isNullPointer();
6237 return !
V.getMemberPointerDecl();
6240 llvm_unreachable(
"Unhandled APValue::ValueKind enum");
6247 T = AT->getElementType();
6249 dyn_cast<FieldDecl>(E.getAsBaseOrMember().getPointer()))
6253 cast<CXXRecordDecl>(E.getAsBaseOrMember().getPointer()));
6294 Diags.
Report(UnionLoc, DiagID);
6301 bool NeedExactType) {
6304 T = getASTContext().getUnqualifiedArrayType(
T, Quals);
6307 bool IsPrimaryExpr =
true;
6308 auto NotPrimaryExpr = [&] {
6309 if (TopLevel && IsPrimaryExpr)
6311 IsPrimaryExpr =
false;
6315 switch (
V.getKind()) {
6324 llvm_unreachable(
"unexpected value kind in template argument");
6328 assert(RD &&
"unexpected type for record value");
6334 (Fields.back()->isUnnamedBitField() ||
6336 V.getStructField(Fields.back()->getFieldIndex())))) {
6340 if (Fields.empty()) {
6341 while (!Bases.empty() &&
6343 V.getStructBase(Bases.size() - 1)))
6344 Bases = Bases.drop_back();
6351 for (
unsigned I = 0, N = Bases.size(); I != N; ++I)
6352 mangleValueInTemplateArg(Bases[I].getType(),
V.getStructBase(I),
false);
6353 for (
unsigned I = 0, N = Fields.size(); I != N; ++I) {
6354 if (Fields[I]->isUnnamedBitField())
6356 mangleValueInTemplateArg(Fields[I]->getType(),
6357 V.getStructField(Fields[I]->getFieldIndex()),
6384 mangleSourceName(II);
6385 mangleValueInTemplateArg(FD->
getType(),
V.getUnionValue(),
false);
6399 unsigned N =
V.getArraySize();
6401 N =
V.getArrayInitializedElts();
6406 for (
unsigned I = 0; I != N; ++I) {
6407 const APValue &Elem = I <
V.getArrayInitializedElts()
6408 ?
V.getArrayInitializedElt(I)
6409 :
V.getArrayFiller();
6410 mangleValueInTemplateArg(ElemT, Elem,
false);
6422 unsigned N =
V.getVectorLength();
6425 for (
unsigned I = 0; I != N; ++I)
6426 mangleValueInTemplateArg(VT->
getElementType(),
V.getVectorElt(I),
false);
6432 mangleIntegerLiteral(
T,
V.getInt());
6436 mangleFloatLiteral(
T,
V.getFloat());
6440 mangleFixedPointLiteral();
6448 if (!
V.getComplexFloatReal().isPosZero() ||
6449 !
V.getComplexFloatImag().isPosZero())
6451 if (!
V.getComplexFloatImag().isPosZero())
6462 if (
V.getComplexIntReal().getBoolValue() ||
6463 V.getComplexIntImag().getBoolValue())
6465 if (
V.getComplexIntImag().getBoolValue())
6474 "unexpected type for LValue template arg");
6476 if (
V.isNullPointer()) {
6477 mangleNullPointer(
T);
6486 if (Offset.isZero()) {
6498 Out << Offset.getQuantity() <<
'E';
6506 if (!
V.hasLValuePath()) {
6522 bool IsArrayToPointerDecayMangledAsDecl =
false;
6523 if (TopLevel && Ctx.
getLangOpts().getClangABICompat() <=
6524 LangOptions::ClangABI::Ver11) {
6526 IsArrayToPointerDecayMangledAsDecl =
6527 BType->
isArrayType() &&
V.getLValuePath().size() == 1 &&
6528 V.getLValuePath()[0].getAsArrayIndex() == 0 &&
6532 if ((!
V.getLValuePath().empty() ||
V.isLValueOnePastTheEnd()) &&
6533 !IsArrayToPointerDecayMangledAsDecl) {
6550 if (NeedExactType &&
6552 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6572 mangleExpression(E);
6576 mangleType(
QualType(TI.getType(), 0));
6579 llvm_unreachable(
"unexpected lvalue base kind in template argument");
6589 mangleNumber(
V.getLValueOffset().getQuantity());
6596 if (!
V.getLValueOffset().isZero())
6597 mangleNumber(
V.getLValueOffset().getQuantity());
6601 bool OnePastTheEnd =
V.isLValueOnePastTheEnd();
6605 if (
auto *CAT = dyn_cast<ConstantArrayType>(AT))
6606 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
6607 TypeSoFar = AT->getElementType();
6609 const Decl *D = E.getAsBaseOrMember().getPointer();
6610 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
6635 if (!
V.getMemberPointerDecl()) {
6636 mangleNullPointer(
T);
6643 if (!
V.getMemberPointerPath().empty()) {
6646 }
else if (NeedExactType &&
6649 V.getMemberPointerDecl()->getType()) &&
6650 !isCompatibleWith(LangOptions::ClangABI::Ver11)) {
6655 mangle(
V.getMemberPointerDecl());
6657 if (!
V.getMemberPointerPath().empty()) {
6660 if (!Offset.isZero())
6661 mangleNumber(Offset.getQuantity());
6667 if (TopLevel && !IsPrimaryExpr)
6671void CXXNameMangler::mangleTemplateParameter(
unsigned Depth,
unsigned Index) {
6681 Depth += TemplateDepthOffset;
6683 Out <<
'L' << (Depth - 1) <<
'_';
6689void CXXNameMangler::mangleSeqID(
unsigned SeqID) {
6692 }
else if (SeqID == 1) {
6702 for (; SeqID != 0; SeqID /= 36) {
6703 unsigned C = SeqID % 36;
6704 *I++ = (
C < 10 ?
'0' +
C :
'A' +
C - 10);
6707 Out.write(I.base(), I - BufferRef.rbegin());
6712void CXXNameMangler::mangleExistingSubstitution(
TemplateName tname) {
6713 bool result = mangleSubstitution(tname);
6714 assert(result &&
"no existing substitution for template name");
6720bool CXXNameMangler::mangleSubstitution(
const NamedDecl *ND) {
6722 if (mangleStandardSubstitution(ND))
6726 return mangleSubstitution(
reinterpret_cast<uintptr_t>(ND));
6731 "mangleSubstitution(NestedNameSpecifier *) is only used for "
6732 "identifier nested name specifiers.");
6734 return mangleSubstitution(
reinterpret_cast<uintptr_t>(NNS));
6744bool CXXNameMangler::mangleSubstitution(
QualType T) {
6747 return mangleSubstitution(RT->getDecl());
6752 return mangleSubstitution(TypePtr);
6755bool CXXNameMangler::mangleSubstitution(
TemplateName Template) {
6757 return mangleSubstitution(TD);
6760 return mangleSubstitution(
6764bool CXXNameMangler::mangleSubstitution(
uintptr_t Ptr) {
6765 llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
6766 if (I == Substitutions.end())
6769 unsigned SeqID = I->second;
6778bool CXXNameMangler::isSpecializedAs(
QualType S, llvm::StringRef Name,
6788 dyn_cast<ClassTemplateSpecializationDecl>(RT->
getDecl());
6792 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
6796 if (TemplateArgs.
size() != 1)
6799 if (TemplateArgs[0].getAsType() != A)
6811bool CXXNameMangler::isStdCharSpecialization(
6813 bool HasAllocator) {
6818 if (TemplateArgs.
size() != (HasAllocator ? 3 : 2))
6821 QualType A = TemplateArgs[0].getAsType();
6829 if (!isSpecializedAs(TemplateArgs[1].getAsType(),
"char_traits", A))
6833 !isSpecializedAs(TemplateArgs[2].getAsType(),
"allocator", A))
6842bool CXXNameMangler::mangleStandardSubstitution(
const NamedDecl *ND) {
6844 if (
const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
6853 if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
6874 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
6875 if (!isStdNamespace(Context.getEffectiveDeclContext(SD)))
6884 if (isStdCharSpecialization(SD,
"basic_string",
true)) {
6891 if (isStdCharSpecialization(SD,
"basic_istream",
false)) {
6898 if (isStdCharSpecialization(SD,
"basic_ostream",
false)) {
6905 if (isStdCharSpecialization(SD,
"basic_iostream",
false)) {
6915void CXXNameMangler::addSubstitution(
QualType T) {
6918 addSubstitution(RT->
getDecl());
6924 addSubstitution(TypePtr);
6927void CXXNameMangler::addSubstitution(
TemplateName Template) {
6929 return addSubstitution(TD);
6935void CXXNameMangler::addSubstitution(
uintptr_t Ptr) {
6936 assert(!Substitutions.count(Ptr) &&
"Substitution already exists!");
6937 Substitutions[Ptr] = SeqID++;
6940void CXXNameMangler::extendSubstitutions(CXXNameMangler*
Other) {
6941 assert(
Other->SeqID >= SeqID &&
"Must be superset of substitutions!");
6942 if (
Other->SeqID > SeqID) {
6943 Substitutions.swap(
Other->Substitutions);
6944 SeqID =
Other->SeqID;
6949CXXNameMangler::makeFunctionReturnTypeTags(
const FunctionDecl *FD) {
6951 if (DisableDerivedAbiTags)
6952 return AbiTagList();
6954 llvm::raw_null_ostream NullOutStream;
6955 CXXNameMangler TrackReturnTypeTags(*
this, NullOutStream);
6956 TrackReturnTypeTags.disableDerivedAbiTags();
6960 FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
6961 TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
6963 TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
6964 TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
6966 return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
6970CXXNameMangler::makeVariableTypeTags(
const VarDecl *VD) {
6972 if (DisableDerivedAbiTags)
6973 return AbiTagList();
6975 llvm::raw_null_ostream NullOutStream;
6976 CXXNameMangler TrackVariableType(*
this, NullOutStream);
6977 TrackVariableType.disableDerivedAbiTags();
6979 TrackVariableType.mangleType(VD->
getType());
6981 return TrackVariableType.AbiTagsRoot.getSortedUniqueUsedAbiTags();
6984bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &
C,
6986 llvm::raw_null_ostream NullOutStream;
6987 CXXNameMangler TrackAbiTags(
C, NullOutStream,
nullptr,
true);
6988 TrackAbiTags.mangle(VD);
6989 return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
7002void ItaniumMangleContextImpl::mangleCXXName(
GlobalDecl GD,
7005 assert((isa<FunctionDecl, VarDecl, TemplateParamObjectDecl>(D)) &&
7006 "Invalid mangleName() call, argument is not a variable or function!");
7009 getASTContext().getSourceManager(),
7010 "Mangling declaration");
7012 if (
auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
7014 CXXNameMangler Mangler(*
this, Out, CD,
Type);
7018 if (
auto *DD = dyn_cast<CXXDestructorDecl>(D)) {
7020 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7024 CXXNameMangler Mangler(*
this, Out, D);
7030 CXXNameMangler Mangler(*
this, Out, D,
Ctor_Comdat);
7036 CXXNameMangler Mangler(*
this, Out, D,
Dtor_Comdat);
7040void ItaniumMangleContextImpl::mangleThunk(
const CXXMethodDecl *MD,
7050 assert(!isa<CXXDestructorDecl>(MD) &&
7051 "Use mangleCXXDtor for destructor decls!");
7052 CXXNameMangler Mangler(*
this, Out);
7053 Mangler.getStream() <<
"_ZT";
7055 Mangler.getStream() <<
'c';
7066 Mangler.mangleFunctionEncoding(MD);
7069void ItaniumMangleContextImpl::mangleCXXDtorThunk(
7074 CXXNameMangler Mangler(*
this, Out, DD,
Type);
7075 Mangler.getStream() <<
"_ZT";
7085void ItaniumMangleContextImpl::mangleStaticGuardVariable(
const VarDecl *D,
7089 CXXNameMangler Mangler(*
this, Out);
7092 Mangler.getStream() <<
"_ZGV";
7093 Mangler.mangleName(D);
7096void ItaniumMangleContextImpl::mangleDynamicInitializer(
const VarDecl *MD,
7101 Out <<
"__cxx_global_var_init";
7104void ItaniumMangleContextImpl::mangleDynamicAtExitDestructor(
const VarDecl *D,
7107 CXXNameMangler Mangler(*
this, Out);
7108 Mangler.getStream() <<
"__dtor_";
7109 if (shouldMangleDeclName(D))
7112 Mangler.getStream() << D->
getName();
7115void ItaniumMangleContextImpl::mangleDynamicStermFinalizer(
const VarDecl *D,
7119 CXXNameMangler Mangler(*
this, Out);
7120 Mangler.getStream() <<
"__finalize_";
7121 if (shouldMangleDeclName(D))
7124 Mangler.getStream() << D->
getName();
7127void ItaniumMangleContextImpl::mangleSEHFilterExpression(
7128 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7129 CXXNameMangler Mangler(*
this, Out);
7130 Mangler.getStream() <<
"__filt_";
7131 auto *EnclosingFD = cast<FunctionDecl>(EnclosingDecl.
getDecl());
7132 if (shouldMangleDeclName(EnclosingFD))
7133 Mangler.mangle(EnclosingDecl);
7135 Mangler.getStream() << EnclosingFD->getName();
7138void ItaniumMangleContextImpl::mangleSEHFinallyBlock(
7139 GlobalDecl EnclosingDecl, raw_ostream &Out) {
7140 CXXNameMangler Mangler(*
this, Out);
7141 Mangler.getStream() <<
"__fin_";
7142 auto *EnclosingFD = cast<FunctionDecl>(EnclosingDecl.
getDecl());
7143 if (shouldMangleDeclName(EnclosingFD))
7144 Mangler.mangle(EnclosingDecl);
7146 Mangler.getStream() << EnclosingFD->getName();
7149void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(
const VarDecl *D,
7152 CXXNameMangler Mangler(*
this, Out);
7153 Mangler.getStream() <<
"_ZTH";
7154 Mangler.mangleName(D);
7158ItaniumMangleContextImpl::mangleItaniumThreadLocalWrapper(
const VarDecl *D,
7161 CXXNameMangler Mangler(*
this, Out);
7162 Mangler.getStream() <<
"_ZTW";
7163 Mangler.mangleName(D);
7166void ItaniumMangleContextImpl::mangleReferenceTemporary(
const VarDecl *D,
7167 unsigned ManglingNumber,
7171 CXXNameMangler Mangler(*
this, Out);
7172 Mangler.getStream() <<
"_ZGR";
7173 Mangler.mangleName(D);
7174 assert(ManglingNumber > 0 &&
"Reference temporary mangling number is zero!");
7175 Mangler.mangleSeqID(ManglingNumber - 1);
7178void ItaniumMangleContextImpl::mangleCXXVTable(
const CXXRecordDecl *RD,
7181 CXXNameMangler Mangler(*
this, Out);
7182 Mangler.getStream() <<
"_ZTV";
7183 Mangler.mangleNameOrStandardSubstitution(RD);
7186void ItaniumMangleContextImpl::mangleCXXVTT(
const CXXRecordDecl *RD,
7189 CXXNameMangler Mangler(*
this, Out);
7190 Mangler.getStream() <<
"_ZTT";
7191 Mangler.mangleNameOrStandardSubstitution(RD);
7194void ItaniumMangleContextImpl::mangleCXXCtorVTable(
const CXXRecordDecl *RD,
7199 CXXNameMangler Mangler(*
this, Out);
7200 Mangler.getStream() <<
"_ZTC";
7201 Mangler.mangleNameOrStandardSubstitution(RD);
7202 Mangler.getStream() << Offset;
7203 Mangler.getStream() <<
'_';
7204 Mangler.mangleNameOrStandardSubstitution(
Type);
7207void ItaniumMangleContextImpl::mangleCXXRTTI(
QualType Ty, raw_ostream &Out) {
7209 assert(!Ty.
hasQualifiers() &&
"RTTI info cannot have top-level qualifiers");
7210 CXXNameMangler Mangler(*
this, Out);
7211 Mangler.getStream() <<
"_ZTI";
7212 Mangler.mangleType(Ty);
7215void ItaniumMangleContextImpl::mangleCXXRTTIName(
7216 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7218 CXXNameMangler Mangler(*
this, Out, NormalizeIntegers);
7219 Mangler.getStream() <<
"_ZTS";
7220 Mangler.mangleType(Ty);
7223void ItaniumMangleContextImpl::mangleCanonicalTypeName(
7224 QualType Ty, raw_ostream &Out,
bool NormalizeIntegers =
false) {
7225 mangleCXXRTTIName(Ty, Out, NormalizeIntegers);
7228void ItaniumMangleContextImpl::mangleStringLiteral(
const StringLiteral *, raw_ostream &) {
7229 llvm_unreachable(
"Can't mangle string literals");
7232void ItaniumMangleContextImpl::mangleLambdaSig(
const CXXRecordDecl *Lambda,
7234 CXXNameMangler Mangler(*
this, Out);
7235 Mangler.mangleLambdaSig(Lambda);
7238void ItaniumMangleContextImpl::mangleModuleInitializer(
const Module *M,
7241 CXXNameMangler Mangler(*
this, Out);
7242 Mangler.getStream() <<
"_ZGI";
7246 auto Partition = M->
Name.find(
':');
7247 Mangler.mangleModuleNamePrefix(
7248 StringRef(&M->
Name[Partition + 1], M->
Name.size() - Partition - 1),
7256 return new ItaniumMangleContextImpl(
7259 return std::nullopt;
7268 return new ItaniumMangleContextImpl(Context, Diags, DiscriminatorOverride,
Enums/classes describing ABI related information about constructors, destructors and thunks.
Defines the clang::ASTContext interface.
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.
static GlobalDecl getParentOfLocalEntity(const DeclContext *DC)
static StringRef mangleAArch64VectorBase(const BuiltinType *EltType)
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 getIdentifier(const Token &Tok)
Defines the SourceManager interface.
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 ...
unsigned getManglingNumber(const NamedDecl *ND, bool ForAuxTarget=false) const
bool hasSimilarType(QualType T1, QualType T2)
Determine if two types are similar, according to the C++ rules.
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
TemplateName getCanonicalTemplateName(const TemplateName &Name) const
Retrieves the "canonical" template name that refers to a given template.
CharUnits getMemberPointerPathAdjustment(const APValue &MP) const
Find the 'this' offset for the member path in a pointer-to-member APValue.
QualType getRecordType(const RecordDecl *Decl) const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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.
unsigned getTargetAddressSpace(LangAS AS) const
NestedNameSpecifier * getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const
Retrieves the "canonical" nested name specifier for a given nested name specifier.
Represents a constant array type that does not decay to a pointer when used as a function parameter.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
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.
Attr - This represents one attribute.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
A builtin binary operation expression such as "x + y" or "x <= y".
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
A binding in a decomposition declaration.
A fixed int type of a specified bitwidth.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a delete expression for memory deallocation and destructor calls, e.g.
bool isGlobalDelete() const
Represents a C++ member access expression where the actual member referenced could not be resolved be...
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.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
QualType getAllocatedType() const
arg_iterator placement_arg_end()
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
bool hasInitializer() const
Whether this new-expression has any initializer at all.
arg_iterator placement_arg_begin()
Expr * getInitializer()
The initializer of this new-expression.
A call to an overloaded operator written using operator syntax.
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,...
A C++ throw-expression (C++ [except.throw]).
const Expr * getSubExpr() const
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
QualType getTypeOperand(ASTContext &Context) const
Retrieves the type operand of this typeid() expression after various required adjustments (removing r...
bool isTypeOperand() const
Expr * getExprOperand() const
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
bool isListInitialization() const
Determine whether this expression models list-initialization.
Expr * getArg(unsigned I)
unsigned getNumArgs() const
Retrieve the number of arguments.
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
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.
CharUnits - This is an opaque type for sizes expressed in character units.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Declaration of a class template.
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.
Complex values, per C99 6.2.5p11.
QualType getElementType() const
Declaration of a C++20 concept.
ConditionalOperator - The ?: ternary operator.
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Represents the canonical version of C arrays with a specified constant size.
Represents a concrete matrix type with constant number of rows and columns.
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 isFileContext() const
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool isFunctionOrMethod() const
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
bool isParameterPack() const
Whether this declaration is a parameter pack.
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
bool isInAnonymousNamespace() const
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.
@ CXXConversionFunctionName
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Represents the type decltype(expr) (C++11).
Represents a C++17 deduced template specialization type.
Represents an extended address space qualifier where the input address space value is dependent.
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
Represents a qualified type name for which the type name is dependent.
A qualified reference to a name whose declaration cannot yet be resolved.
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
Represents an array type in C++ whose size is a value-dependent expression.
Represents an extended vector type where either the type or size is dependent.
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Represents a dependent template name that cannot be resolved prior to template instantiation.
Represents a template specialization type whose template cannot be resolved, e.g.
const IdentifierInfo * getIdentifier() const
ArrayRef< TemplateArgument > template_arguments() const
NestedNameSpecifier * getQualifier() const
Represents a vector type where either the type or size is dependent.
Designator - A designator in a C99 designated initializer.
bool isArrayDesignator() const
bool isArrayRangeDesignator() const
bool isFieldDesignator() 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.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
An instance of this object exists for each enum constant that is defined.
llvm::APSInt getInitVal() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
ExplicitCastExpr - An explicit cast written in the source code.
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) 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...
ExtVectorType - Extended vector type.
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.
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Represents a reference to a function parameter pack or init-capture pack that has been substituted bu...
VarDecl * 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
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.
Declaration of a template function.
A class which abstracts out some details necessary for making a call.
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? Consumed parameters must have retainable ...
ParameterABI getABI() const
Return the ABI treatment of this parameter.
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
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.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
const Expr * getSubExpr() const
Represents a C array with an unspecified size.
Represents a field injected from an anonymous union/struct into the parent scope.
Describes an C or C++ initializer list.
unsigned getNumInits() const
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
The injected class name of a C++ class template or class template partial specialization.
virtual DiscriminatorOverrideTy getDiscriminatorOverride() const =0
virtual void mangleDynamicStermFinalizer(const VarDecl *D, raw_ostream &)=0
virtual void mangleCXXVTT(const CXXRecordDecl *RD, raw_ostream &)=0
virtual void mangleItaniumThreadLocalInit(const VarDecl *D, raw_ostream &)=0
virtual void mangleCXXCtorComdat(const CXXConstructorDecl *D, raw_ostream &)=0
virtual void mangleLambdaSig(const CXXRecordDecl *Lambda, raw_ostream &)=0
virtual void mangleCXXDtorComdat(const CXXDestructorDecl *D, raw_ostream &)=0
virtual void mangleItaniumThreadLocalWrapper(const VarDecl *D, raw_ostream &)=0
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, const CXXRecordDecl *Type, raw_ostream &)=0
virtual void mangleCXXVTable(const CXXRecordDecl *RD, raw_ostream &)=0
virtual void mangleModuleInitializer(const Module *Module, raw_ostream &)=0
std::optional< unsigned >(*)(ASTContext &, const NamedDecl *) DiscriminatorOverrideTy
An lvalue reference type, per C++11 [dcl.ref].
ClangABI
Clang versions with different platform ABI conformance.
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
virtual std::string getLambdaString(const CXXRecordDecl *Lambda)=0
virtual bool shouldMangleStringLiteral(const StringLiteral *SL)=0
ASTContext & getASTContext() const
uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D)
virtual void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &)=0
virtual bool isUniqueInternalLinkageDecl(const NamedDecl *ND)
virtual void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out)=0
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, const ThisAdjustment &ThisAdjustment, raw_ostream &)=0
virtual void mangleCanonicalTypeName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &)=0
virtual void mangleCXXName(GlobalDecl GD, raw_ostream &)=0
virtual void needsUniqueInternalLinkageNames()
virtual void mangleReferenceTemporary(const VarDecl *D, unsigned ManglingNumber, raw_ostream &)=0
virtual bool shouldMangleCXXName(const NamedDecl *D)=0
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
virtual void mangleDynamicInitializer(const VarDecl *D, raw_ostream &)=0
virtual void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out)=0
virtual void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &)=0
virtual void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk, raw_ostream &)=0
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
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
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
A pointer to member type per C++ 8.3.3 - Pointers to members.
QualType getPointeeType() const
Describes a module or submodule.
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 hasLinkage() const
Determine whether this declaration has linkage.
bool isExternallyVisible() const
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
NamespaceDecl * getOriginalNamespace()
Get the original (first) 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>::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
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.
Interfaces are the core concept in Objective-C for object oriented design.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents a class type in Objective C.
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.
Represents a pack expansion of types.
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
PointerType - C99 6.7.5.1 - Pointer Declarators.
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
void removeObjCLifetime()
bool hasUnaligned() const
bool hasAddressSpace() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
field_range fields() const
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() 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
StringLiteral - This represents a string literal expression, e.g.
A structure for storing the information associated with a substituted template template parameter.
TemplateName getReplacement() const
Represents the result of substituting a set of types for a template type parameter pack.
Represents the declaration of a struct/union/class/enum.
TypedefNameDecl * getTypedefNameForAnonDecl() const
Exposes information about the current target.
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() 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.
void * getAsVoidPointer() const
Retrieve the template name as a void pointer.
@ 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,...
@ 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.
A template parameter object.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Represents a type template specialization; the template must be a class template, a type alias templa...
ArrayRef< TemplateArgument > template_arguments() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
ConceptDecl * getNamedConcept() const
Symbolic representation of typeid(T) for some type T.
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
A container of type source information.
QualType getType() const
Return the type wrapped by this type source info.
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
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.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBooleanType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isDependentAddressSpaceType() const
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 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.
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
Base class for declarations which introduce a typedef-name.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTrait getKind() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
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.
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
DeclarationName getMemberName() const
Retrieve the name of the member that this expression refers to.
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Represents the dependent type named by a dependently-scoped typename using declaration,...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
void print(llvm::raw_ostream &Out) const
Represents a variable declaration or definition.
Represents a variable template specialization, which refers to a variable template with a given set o...
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
QualType getElementType() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool Sub(InterpState &S, CodePtr OpPC)
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.
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 (&&).
LanguageLinkage
Describes the different kinds of language linkage (C++ [dcl.link]) that an entity may have.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
CXXDtorType
C++ destructor types.
@ Dtor_Comdat
The COMDAT used for dtors.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
const char * getTraitSpelling(ExpressionTrait T) LLVM_READONLY
Return the spelling of the type trait TT. Never null.
const FunctionProtoType * T
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.
@ 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
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
const Type * Ty
The locally-unqualified type.
Qualifiers Quals
The local qualifiers.
Iterator for iterating over Stmt * arrays that contain only T *.
A this pointer adjustment.
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::@188 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.
struct clang::ThisAdjustment::VirtualAdjustment::@190 Itanium