[clang] [Clang][MicrosoftMangle] Implement mangling for ConstantMatrixType (PR #134930)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 8 13:53:48 PDT 2025
https://github.com/Losy001 created https://github.com/llvm/llvm-project/pull/134930
This pull request implements mangling for the ConstantMatrixType, allowing matrices to be used on Windows.
Related issues: #53158, #127127
This example code:
```cpp
#include <typeinfo>
#include <stdio.h>
typedef float Matrix4 __attribute__((matrix_type(4, 4)));
int main()
{
printf("%s\n", typeid(Matrix4).name());
}
```
Outputs this:
```
struct __clang::__matrix<float,4,4>
```
Apologies if I did something wrong, this is my first time doing this 😅.
>From 4a3b446a8081636219c704d0a2bbba5af567f5ca Mon Sep 17 00:00:00 2001
From: Losy001 <64610343+Losy001 at users.noreply.github.com>
Date: Tue, 8 Apr 2025 22:41:03 +0200
Subject: [PATCH] Implement mangling for matrix types
---
clang/lib/AST/MicrosoftMangle.cpp | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 4d14614fc1ec7..5ffe8b5d3d3f9 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3526,7 +3526,22 @@ void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T,
void MicrosoftCXXNameMangler::mangleType(const ConstantMatrixType *T,
Qualifiers quals, SourceRange Range) {
- Error(Range.getBegin(), "matrix type") << Range;
+ QualType EltTy = T->getElementType();
+ const BuiltinType *ET = EltTy->getAs<BuiltinType>();
+
+ llvm::SmallString<64> TemplateMangling;
+ llvm::raw_svector_ostream Stream(TemplateMangling);
+ MicrosoftCXXNameMangler Extra(Context, Stream);
+
+ Stream << "?$";
+
+ Extra.mangleSourceName("__matrix");
+ Extra.mangleType(EltTy, Range, QMM_Escape);
+
+ Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumRows()));
+ Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumColumns()));
+
+ mangleArtificialTagType(TagTypeKind::Struct, TemplateMangling, {"__clang"});
}
void MicrosoftCXXNameMangler::mangleType(const DependentSizedMatrixType *T,
More information about the cfe-commits
mailing list