[clang] eb5c211 - [Clang] [Sema] Support matrix types in pseudo-destructor expressions (#117483)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 16 21:49:33 PST 2024
Author: Sirraide
Date: 2024-12-17T06:49:31+01:00
New Revision: eb5c21108fca4c871987faef581158811954c916
URL: https://github.com/llvm/llvm-project/commit/eb5c21108fca4c871987faef581158811954c916
DIFF: https://github.com/llvm/llvm-project/commit/eb5c21108fca4c871987faef581158811954c916.diff
LOG: [Clang] [Sema] Support matrix types in pseudo-destructor expressions (#117483)
We already support vector types, and since matrix element types have to
be scalar types, there should be no problem w/ just enabling this.
This now also allows matrix types to be stored in STL containers.
Added:
clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/matrix-type.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 38aab8c7d32cad..596f3b5142d663 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -419,6 +419,9 @@ Non-comprehensive list of changes in this release
- Clang now rejects ``_BitInt`` matrix element types if the bit width is less than ``CHAR_WIDTH`` or
not a power of two, matching preexisting behaviour for vector types.
+- Matrix types (a Clang extension) can now be used in pseudo-destructor expressions,
+ which allows them to be stored in STL containers.
+
New Compiler Flags
------------------
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index caea13b192ad57..e04ece0bda82eb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8201,7 +8201,7 @@ ExprResult Sema::BuildPseudoDestructorExpr(Expr *Base,
return ExprError();
if (!ObjectType->isDependentType() && !ObjectType->isScalarType() &&
- !ObjectType->isVectorType()) {
+ !ObjectType->isVectorType() && !ObjectType->isMatrixType()) {
if (getLangOpts().MSVCCompat && ObjectType->isVoidType())
Diag(OpLoc, diag::ext_pseudo_dtor_on_void) << Base->getSourceRange();
else {
diff --git a/clang/test/CodeGenCXX/matrix-type.cpp b/clang/test/CodeGenCXX/matrix-type.cpp
index 1a5e5dba2978c8..c3a299e7feee82 100644
--- a/clang/test/CodeGenCXX/matrix-type.cpp
+++ b/clang/test/CodeGenCXX/matrix-type.cpp
@@ -368,3 +368,36 @@ void test_use_matrix_2() {
selector<2> r5 = use_matrix_3(m1);
}
+
+// CHECK-LABEL: define void @_Z22test_pseudo_destructorv()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %a = alloca [25 x double], align 8
+// CHECK-NEXT: %b = alloca [12 x float], align 4
+// CHECK-NEXT: %0 = load <25 x double>, ptr %a, align 8
+// CHECK-NEXT: call void @_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %0)
+// CHECK-NEXT: %1 = load <12 x float>, ptr %b, align 4
+// CHECK-NEXT: call void @_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %1)
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL: define linkonce_odr void @_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %t.addr = alloca [25 x double], align 8
+// CHECK-NEXT: store <25 x double> %t, ptr %t.addr, align 8
+// CHECK-NEXT: ret void
+
+// CHECK-LABEL: define linkonce_odr void @_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %t)
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %t.addr = alloca [12 x float], align 4
+// CHECK-NEXT: store <12 x float> %t, ptr %t.addr, align 4
+// CHECK-NEXT: ret void
+template <typename T>
+void pseudo_destructor(T t) {
+ t.~T();
+}
+
+void test_pseudo_destructor() {
+ dx5x5_t a;
+ fx3x4_t b;
+ pseudo_destructor(a);
+ pseudo_destructor(b);
+}
diff --git a/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
new file mode 100644
index 00000000000000..b5a1b8c8a452a2
--- /dev/null
+++ b/clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -fenable-matrix -verify %s
+// expected-no-diagnostics
+
+template <typename T>
+void f() {
+ T().~T();
+}
+
+template <typename T>
+void f1(T *f) {
+ f->~T();
+ (*f).~T();
+}
+
+using mat4 = float __attribute__((matrix_type(4, 4)));
+using mat4i = int __attribute__((matrix_type(4, 4)));
+
+template <typename T>
+using mat4_t = T __attribute__((matrix_type(4, 4)));
+
+void g() {
+ f<mat4>();
+ f<mat4i>();
+ f<mat4_t<double>>();
+}
+
+void g2(mat4* m1, mat4i* m2, mat4_t<double>* m3) {
+ f1(m1);
+ f1(m2);
+ f1(m3);
+}
More information about the cfe-commits
mailing list