Skip to content

[Clang] [Sema] Support matrix types in pseudo-destructor expressions #117483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ Non-comprehensive list of changes in this release
- ``__builtin_reduce_and`` function can now be used in constant expressions.
- ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be used in constant expressions.

- 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
------------------

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8189,7 +8189,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 {
Expand Down
33 changes: 33 additions & 0 deletions clang/test/CodeGenCXX/matrix-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 31 additions & 0 deletions clang/test/SemaCXX/matrix-types-pseudo-destructor.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a constexpr test to ensure that this noop works fine in a constant expression too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it turns out we currently don’t support matrix types in constant expressions, so, er, I’ll open a separate issue about that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
Loading