[clang] [Clang] Add and use mangleVendorType helper. NFC. (PR #108970)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 17 05:39:10 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/108970.diff
1 Files Affected:
- (modified) clang/lib/AST/ItaniumMangle.cpp (+24-28)
``````````diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6e1da0c3192da..ef8e91b7cbdf9f 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:
@@ -2871,6 +2872,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
@@ -3389,8 +3394,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; \
@@ -3407,35 +3411,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) \
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"
}
@@ -4006,8 +4005,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(
@@ -4107,8 +4107,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(
@@ -4207,8 +4208,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();
@@ -4226,8 +4226,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());
@@ -4273,7 +4272,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());
@@ -4407,8 +4406,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) \
@@ -4417,7 +4414,7 @@ void CXXNameMangler::mangleType(const UnaryTransformType *T) {
break;
#include "clang/Basic/TransformTypeTraits.def"
}
- Out << BuiltinName.size() << BuiltinName;
+ mangleVendorType(BuiltinName);
}
Out << "I";
@@ -5250,9 +5247,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());
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/108970
More information about the cfe-commits
mailing list