Skip to content

Commit c10875c

Browse files
[ESIMD][NFC] Added tests for simd class type traits (#4146)
1 parent 4614ee4 commit c10875c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s
2+
3+
#include <limits>
4+
#include <sycl/ext/intel/experimental/esimd.hpp>
5+
#include <utility>
6+
7+
// This is a regression test for simd object being non-trivial copy
8+
// constructible. In order to fix it, you need to provide copy constructor for
9+
// SimdWrapper, e.g.:
10+
// SimdWrapper (const SimdWrapper& rhs) : v1(rhs.v1) {}
11+
12+
using namespace sycl::ext::intel::experimental::esimd;
13+
14+
struct SimdWrapper {
15+
union {
16+
// expected-note@+1 {{copy constructor of 'SimdWrapper' is implicitly deleted because variant field '' has a non-trivial copy constructor}}
17+
struct {
18+
simd<int, 4> v1;
19+
};
20+
};
21+
SimdWrapper() {}
22+
};
23+
24+
void encapsulate_simd() SYCL_ESIMD_FUNCTION {
25+
SimdWrapper s1;
26+
// expected-error@+1 {{call to implicitly-deleted copy constructor of 'SimdWrapper'}}
27+
SimdWrapper s2(s1);
28+
}

sycl/test/esimd/simd.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ bool test_simd_ctors() SYCL_ESIMD_FUNCTION {
1515
return v0[0] + v1[1] + v2[2] + v3[3] == 1 + 1 + 2 + 6;
1616
}
1717

18+
void test_simd_class_traits() SYCL_ESIMD_FUNCTION {
19+
static_assert(std::is_default_constructible<simd<int, 4>>::value,
20+
"type trait mismatch");
21+
static_assert(std::is_trivially_default_constructible<simd<int, 4>>::value,
22+
"type trait mismatch");
23+
static_assert(std::is_copy_constructible<simd<int, 4>>::value,
24+
"type trait mismatch");
25+
static_assert(!std::is_trivially_copy_constructible<simd<int, 4>>::value,
26+
"type trait mismatch");
27+
static_assert(std::is_move_constructible<simd<int, 4>>::value,
28+
"type trait mismatch");
29+
static_assert(!std::is_trivially_move_constructible<simd<int, 4>>::value,
30+
"type trait mismatch");
31+
static_assert(std::is_copy_assignable<simd<int, 4>>::value,
32+
"type trait mismatch");
33+
static_assert(std::is_trivially_copy_assignable<simd<int, 4>>::value,
34+
"type trait mismatch");
35+
static_assert(std::is_move_assignable<simd<int, 4>>::value,
36+
"type trait mismatch");
37+
static_assert(std::is_trivially_move_assignable<simd<int, 4>>::value,
38+
"type trait mismatch");
39+
}
40+
1841
void test_conversion() SYCL_ESIMD_FUNCTION {
1942
simd<int, 32> v = 3;
2043
simd<float, 32> f = v;

0 commit comments

Comments
 (0)