[clang] cf6ca98 - [Clang] Add and use mangleVendorType helper. NFC. (#108970)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 30 10:03:39 PDT 2024
Author: Jay Foad
Date: 2024-10-30T17:03:35Z
New Revision: cf6ca98481a90728f1d3adc748aa0f271afc59aa
URL: https://github.com/llvm/llvm-project/commit/cf6ca98481a90728f1d3adc748aa0f271afc59aa
DIFF: https://github.com/llvm/llvm-project/commit/cf6ca98481a90728f1d3adc748aa0f271afc59aa.diff
LOG: [Clang] Add and use mangleVendorType helper. NFC. (#108970)
Added:
Modified:
clang/lib/AST/ItaniumMangle.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b3e46508cf596d..14bc260d0245fb 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -468,6 +468,7 @@ class CXXNameMangler {
void mangleLambdaSig(const CXXRecordDecl *Lambda);
void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false);
void mangleVendorQualifier(StringRef Name);
+ void mangleVendorType(StringRef Name);
private:
@@ -2891,6 +2892,10 @@ void CXXNameMangler::mangleVendorQualifier(StringRef name) {
Out << 'U' << name.size() << name;
}
+void CXXNameMangler::mangleVendorType(StringRef name) {
+ Out << 'u' << name.size() << name;
+}
+
void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) {
// <ref-qualifier> ::= R # lvalue reference
// ::= O # rvalue-reference
@@ -3413,8 +3418,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
if (T->getKind() == BuiltinType::SveBFloat16 && \
isCompatibleWith(LangOptions::ClangABI::Ver17)) { \
/* Prior to Clang 18.0 we used this incorrect mangled name */ \
- type_name = "__SVBFloat16_t"; \
- Out << "u" << type_name.size() << type_name; \
+ mangleVendorType("__SVBFloat16_t"); \
} else { \
type_name = MangledName; \
Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
@@ -3436,35 +3440,30 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
Out << (type_name == Name ? "u" : "") << type_name.size() << type_name; \
break;
#include "clang/Basic/AArch64SVEACLETypes.def"
-#define PPC_VECTOR_TYPE(Name, Id, Size) \
- case BuiltinType::Id: \
- type_name = #Name; \
- Out << 'u' << type_name.size() << type_name; \
+#define PPC_VECTOR_TYPE(Name, Id, Size) \
+ case BuiltinType::Id: \
+ mangleVendorType(#Name); \
break;
#include "clang/Basic/PPCTypes.def"
// TODO: Check the mangling scheme for RISC-V V.
#define RVV_TYPE(Name, Id, SingletonId) \
case BuiltinType::Id: \
- type_name = Name; \
- Out << 'u' << type_name.size() << type_name; \
+ mangleVendorType(Name); \
break;
#include "clang/Basic/RISCVVTypes.def"
#define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS) \
case BuiltinType::Id: \
- type_name = MangledName; \
- Out << 'u' << type_name.size() << type_name; \
+ mangleVendorType(MangledName); \
break;
#include "clang/Basic/WebAssemblyReferenceTypes.def"
#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
case BuiltinType::Id: \
- type_name = Name; \
- Out << 'u' << type_name.size() << type_name; \
+ mangleVendorType(Name); \
break;
#include "clang/Basic/AMDGPUTypes.def"
#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
case BuiltinType::Id: \
- type_name = #Name; \
- Out << 'u' << type_name.size() << type_name; \
+ mangleVendorType(#Name); \
break;
#include "clang/Basic/HLSLIntangibleTypes.def"
}
@@ -4035,8 +4034,9 @@ void CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
if (T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
VecSizeInBits *= 8;
- Out << "9__SVE_VLSI" << 'u' << TypeName.size() << TypeName << "Lj"
- << VecSizeInBits << "EE";
+ Out << "9__SVE_VLSI";
+ mangleVendorType(TypeName);
+ Out << "Lj" << VecSizeInBits << "EE";
}
void CXXNameMangler::mangleAArch64FixedSveVectorType(
@@ -4136,8 +4136,9 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const VectorType *T) {
}
TypeNameOS << "_t";
- Out << "9__RVV_VLSI" << 'u' << TypeNameStr.size() << TypeNameStr << "Lj"
- << VecSizeInBits << "EE";
+ Out << "9__RVV_VLSI";
+ mangleVendorType(TypeNameStr);
+ Out << "Lj" << VecSizeInBits << "EE";
}
void CXXNameMangler::mangleRISCVFixedRVVVectorType(
@@ -4236,8 +4237,7 @@ void CXXNameMangler::mangleType(const ConstantMatrixType *T) {
// Mangle matrix types as a vendor extended type:
// u<Len>matrix_typeI<Rows><Columns><element type>E
- StringRef VendorQualifier = "matrix_type";
- Out << "u" << VendorQualifier.size() << VendorQualifier;
+ mangleVendorType("matrix_type");
Out << "I";
auto &ASTCtx = getASTContext();
@@ -4255,8 +4255,7 @@ void CXXNameMangler::mangleType(const ConstantMatrixType *T) {
void CXXNameMangler::mangleType(const DependentSizedMatrixType *T) {
// Mangle matrix types as a vendor extended type:
// u<Len>matrix_typeI<row expr><column expr><element type>E
- StringRef VendorQualifier = "matrix_type";
- Out << "u" << VendorQualifier.size() << VendorQualifier;
+ mangleVendorType("matrix_type");
Out << "I";
mangleTemplateArgExpr(T->getRowExpr());
@@ -4302,7 +4301,7 @@ void CXXNameMangler::mangleType(const ObjCObjectType *T) {
StringRef name = I->getName();
QualOS << name.size() << name;
}
- Out << 'U' << QualStr.size() << QualStr;
+ mangleVendorQualifier(QualStr);
}
mangleType(T->getBaseType());
@@ -4436,8 +4435,6 @@ void CXXNameMangler::mangleType(const UnaryTransformType *T) {
// If this is dependent, we need to record that. If not, we simply
// mangle it as the underlying type since they are equivalent.
if (T->isDependentType()) {
- Out << "u";
-
StringRef BuiltinName;
switch (T->getUTTKind()) {
#define TRANSFORM_TYPE_TRAIT_DEF(Enum, Trait) \
@@ -4446,7 +4443,7 @@ void CXXNameMangler::mangleType(const UnaryTransformType *T) {
break;
#include "clang/Basic/TransformTypeTraits.def"
}
- Out << BuiltinName.size() << BuiltinName;
+ mangleVendorType(BuiltinName);
}
Out << "I";
@@ -5311,9 +5308,8 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
// <expression> ::= u <source-name> <template-arg>* E # vendor extension
const TypeTraitExpr *TTE = cast<TypeTraitExpr>(E);
NotPrimaryExpr();
- Out << 'u';
llvm::StringRef Spelling = getTraitSpelling(TTE->getTrait());
- Out << Spelling.size() << Spelling;
+ mangleVendorType(Spelling);
for (TypeSourceInfo *TSI : TTE->getArgs()) {
mangleType(TSI->getType());
}
More information about the cfe-commits
mailing list