Skip to content

Commit eb5c211

Browse files
authored
[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.
1 parent e2cabd7 commit eb5c211

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ Non-comprehensive list of changes in this release
419419
- Clang now rejects ``_BitInt`` matrix element types if the bit width is less than ``CHAR_WIDTH`` or
420420
not a power of two, matching preexisting behaviour for vector types.
421421

422+
- Matrix types (a Clang extension) can now be used in pseudo-destructor expressions,
423+
which allows them to be stored in STL containers.
424+
422425
New Compiler Flags
423426
------------------
424427

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8201,7 +8201,7 @@ ExprResult Sema::BuildPseudoDestructorExpr(Expr *Base,
82018201
return ExprError();
82028202

82038203
if (!ObjectType->isDependentType() && !ObjectType->isScalarType() &&
8204-
!ObjectType->isVectorType()) {
8204+
!ObjectType->isVectorType() && !ObjectType->isMatrixType()) {
82058205
if (getLangOpts().MSVCCompat && ObjectType->isVoidType())
82068206
Diag(OpLoc, diag::ext_pseudo_dtor_on_void) << Base->getSourceRange();
82078207
else {

clang/test/CodeGenCXX/matrix-type.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,36 @@ void test_use_matrix_2() {
368368

369369
selector<2> r5 = use_matrix_3(m1);
370370
}
371+
372+
// CHECK-LABEL: define void @_Z22test_pseudo_destructorv()
373+
// CHECK-NEXT: entry:
374+
// CHECK-NEXT: %a = alloca [25 x double], align 8
375+
// CHECK-NEXT: %b = alloca [12 x float], align 4
376+
// CHECK-NEXT: %0 = load <25 x double>, ptr %a, align 8
377+
// CHECK-NEXT: call void @_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %0)
378+
// CHECK-NEXT: %1 = load <12 x float>, ptr %b, align 4
379+
// CHECK-NEXT: call void @_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %1)
380+
// CHECK-NEXT: ret void
381+
382+
// CHECK-LABEL: define linkonce_odr void @_Z17pseudo_destructorIu11matrix_typeILm5ELm5EdEEvT_(<25 x double> %t)
383+
// CHECK-NEXT: entry:
384+
// CHECK-NEXT: %t.addr = alloca [25 x double], align 8
385+
// CHECK-NEXT: store <25 x double> %t, ptr %t.addr, align 8
386+
// CHECK-NEXT: ret void
387+
388+
// CHECK-LABEL: define linkonce_odr void @_Z17pseudo_destructorIu11matrix_typeILm3ELm4EfEEvT_(<12 x float> %t)
389+
// CHECK-NEXT: entry:
390+
// CHECK-NEXT: %t.addr = alloca [12 x float], align 4
391+
// CHECK-NEXT: store <12 x float> %t, ptr %t.addr, align 4
392+
// CHECK-NEXT: ret void
393+
template <typename T>
394+
void pseudo_destructor(T t) {
395+
t.~T();
396+
}
397+
398+
void test_pseudo_destructor() {
399+
dx5x5_t a;
400+
fx3x4_t b;
401+
pseudo_destructor(a);
402+
pseudo_destructor(b);
403+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clang_cc1 -fsyntax-only -fenable-matrix -verify %s
2+
// expected-no-diagnostics
3+
4+
template <typename T>
5+
void f() {
6+
T().~T();
7+
}
8+
9+
template <typename T>
10+
void f1(T *f) {
11+
f->~T();
12+
(*f).~T();
13+
}
14+
15+
using mat4 = float __attribute__((matrix_type(4, 4)));
16+
using mat4i = int __attribute__((matrix_type(4, 4)));
17+
18+
template <typename T>
19+
using mat4_t = T __attribute__((matrix_type(4, 4)));
20+
21+
void g() {
22+
f<mat4>();
23+
f<mat4i>();
24+
f<mat4_t<double>>();
25+
}
26+
27+
void g2(mat4* m1, mat4i* m2, mat4_t<double>* m3) {
28+
f1(m1);
29+
f1(m2);
30+
f1(m3);
31+
}

0 commit comments

Comments
 (0)