diff options
Diffstat (limited to 'clang/lib/AST/MicrosoftMangle.cpp')
-rw-r--r-- | clang/lib/AST/MicrosoftMangle.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 09075e60142a..cdd2c93c4b14 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -35,6 +35,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/xxhash.h" +#include <optional> using namespace clang; @@ -142,8 +143,8 @@ class MicrosoftMangleContextImpl : public MicrosoftMangleContext { llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator; llvm::DenseMap<const NamedDecl *, unsigned> Uniquifier; llvm::DenseMap<const CXXRecordDecl *, unsigned> LambdaIds; - llvm::DenseMap<const NamedDecl *, unsigned> SEHFilterIds; - llvm::DenseMap<const NamedDecl *, unsigned> SEHFinallyIds; + llvm::DenseMap<GlobalDecl, unsigned> SEHFilterIds; + llvm::DenseMap<GlobalDecl, unsigned> SEHFinallyIds; SmallString<16> AnonymousNamespaceHash; public: @@ -201,9 +202,9 @@ public: void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override; void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &Out) override; - void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, + void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out) override; - void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, + void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out) override; void mangleStringLiteral(const StringLiteral *SL, raw_ostream &Out) override; bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { @@ -340,22 +341,22 @@ public: MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_) : Context(C), Out(Out_), Structor(nullptr), StructorType(-1), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, const CXXConstructorDecl *D, CXXCtorType Type) : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_, const CXXDestructorDecl *D, CXXDtorType Type) : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), TemplateArgStringStorage(TemplateArgStringStorageAlloc), - PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) == - 64) {} + PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth( + LangAS::Default) == 64) {} raw_ostream &getStream() const { return Out; } @@ -376,7 +377,7 @@ public: void mangleBits(llvm::APInt Number); void mangleTagTypeKind(TagTypeKind TK); void mangleArtificialTagType(TagTypeKind TK, StringRef UnqualifiedName, - ArrayRef<StringRef> NestedNames = None); + ArrayRef<StringRef> NestedNames = std::nullopt); void mangleAddressSpaceType(QualType T, Qualifiers Quals, SourceRange Range); void mangleType(QualType T, SourceRange Range, QualifierMangleMode QMM = QMM_Mangle); @@ -776,7 +777,7 @@ void MicrosoftCXXNameMangler::mangleVirtualMemPtrThunk( const CXXMethodDecl *MD, const MethodVFTableLocation &ML) { // Get the vftable offset. CharUnits PointerWidth = getASTContext().toCharUnitsFromBits( - getASTContext().getTargetInfo().getPointerWidth(0)); + getASTContext().getTargetInfo().getPointerWidth(LangAS::Default)); uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity(); Out << "?_9"; @@ -838,6 +839,9 @@ void MicrosoftCXXNameMangler::mangleFloat(llvm::APFloat Number) { case APFloat::S_x87DoubleExtended: Out << 'X'; break; case APFloat::S_IEEEquad: Out << 'Y'; break; case APFloat::S_PPCDoubleDouble: Out << 'Z'; break; + case APFloat::S_Float8E5M2: + case APFloat::S_Float8E4M3FN: + llvm_unreachable("Tried to mangle unexpected APFloat semantics"); } mangleBits(Number.bitcastToAPInt()); @@ -1505,7 +1509,7 @@ void MicrosoftCXXNameMangler::mangleIntegerLiteral( void MicrosoftCXXNameMangler::mangleExpression( const Expr *E, const NonTypeTemplateParmDecl *PD) { // See if this is a constant expression. - if (Optional<llvm::APSInt> Value = + if (std::optional<llvm::APSInt> Value = E->getIntegerConstantExpr(Context.getASTContext())) { mangleIntegerLiteral(*Value, PD, E->getType()); return; @@ -2469,6 +2473,10 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, Out << "$halff@"; break; + case BuiltinType::BFloat16: + mangleArtificialTagType(TTK_Struct, "__bf16", {"__clang"}); + break; + #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: #include "clang/Basic/AArch64SVEACLETypes.def" @@ -2501,7 +2509,6 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers, case BuiltinType::SatUShortFract: case BuiltinType::SatUFract: case BuiltinType::SatULongFract: - case BuiltinType::BFloat16: case BuiltinType::Ibm128: case BuiltinType::Float128: { DiagnosticsEngine &Diags = Context.getDiags(); @@ -3070,14 +3077,17 @@ bool MicrosoftCXXNameMangler::isArtificialTagType(QualType T) const { void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals, SourceRange Range) { - const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>(); - assert(ET && "vectors with non-builtin elements are unsupported"); + QualType EltTy = T->getElementType(); + const BuiltinType *ET = EltTy->getAs<BuiltinType>(); + const BitIntType *BitIntTy = EltTy->getAs<BitIntType>(); + assert((ET || BitIntTy) && + "vectors with non-builtin/_BitInt elements are unsupported"); uint64_t Width = getASTContext().getTypeSize(T); // Pattern match exactly the typedefs in our intrinsic headers. Anything that // doesn't match the Intel types uses a custom mangling below. size_t OutSizeBefore = Out.tell(); if (!isa<ExtVectorType>(T)) { - if (getASTContext().getTargetInfo().getTriple().isX86()) { + if (getASTContext().getTargetInfo().getTriple().isX86() && ET) { if (Width == 64 && ET->getKind() == BuiltinType::LongLong) { mangleArtificialTagType(TTK_Union, "__m64"); } else if (Width >= 128) { @@ -3102,7 +3112,8 @@ void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals, MicrosoftCXXNameMangler Extra(Context, Stream); Stream << "?$"; Extra.mangleSourceName("__vector"); - Extra.mangleType(QualType(ET, 0), Range, QMM_Escape); + Extra.mangleType(QualType(ET ? static_cast<const Type *>(ET) : BitIntTy, 0), + Range, QMM_Escape); Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumElements())); mangleArtificialTagType(TTK_Union, TemplateMangling, {"__clang"}); @@ -3720,7 +3731,7 @@ void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator( } void MicrosoftMangleContextImpl::mangleSEHFilterExpression( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { msvc_hashing_ostream MHO(Out); MicrosoftCXXNameMangler Mangler(*this, MHO); // The function body is in the same comdat as the function with the handler, @@ -3732,7 +3743,7 @@ void MicrosoftMangleContextImpl::mangleSEHFilterExpression( } void MicrosoftMangleContextImpl::mangleSEHFinallyBlock( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { msvc_hashing_ostream MHO(Out); MicrosoftCXXNameMangler Mangler(*this, MHO); // The function body is in the same comdat as the function with the handler, |