Skip to content

[ESIMD][NFC] Added tests for simd class type traits #4146

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 1 commit into from
Jul 23, 2021
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
28 changes: 28 additions & 0 deletions sycl/test/esimd/regression/simd_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s

#include <limits>
#include <sycl/ext/intel/experimental/esimd.hpp>
#include <utility>

// This is a regression test for simd object being non-trivial copy
// constructible. In order to fix it, you need to provide copy constructor for
// SimdWrapper, e.g.:
// SimdWrapper (const SimdWrapper& rhs) : v1(rhs.v1) {}

using namespace sycl::ext::intel::experimental::esimd;

struct SimdWrapper {
union {
// expected-note@+1 {{copy constructor of 'SimdWrapper' is implicitly deleted because variant field '' has a non-trivial copy constructor}}
struct {
simd<int, 4> v1;
};
};
SimdWrapper() {}
};

void encapsulate_simd() SYCL_ESIMD_FUNCTION {
SimdWrapper s1;
// expected-error@+1 {{call to implicitly-deleted copy constructor of 'SimdWrapper'}}
SimdWrapper s2(s1);
}
23 changes: 23 additions & 0 deletions sycl/test/esimd/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ bool test_simd_ctors() SYCL_ESIMD_FUNCTION {
return v0[0] + v1[1] + v2[2] + v3[3] == 1 + 1 + 2 + 6;
}

void test_simd_class_traits() SYCL_ESIMD_FUNCTION {
static_assert(std::is_default_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_trivially_default_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_copy_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(!std::is_trivially_copy_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_move_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(!std::is_trivially_move_constructible<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_copy_assignable<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_trivially_copy_assignable<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_move_assignable<simd<int, 4>>::value,
"type trait mismatch");
static_assert(std::is_trivially_move_assignable<simd<int, 4>>::value,
"type trait mismatch");
}

void test_conversion() SYCL_ESIMD_FUNCTION {
simd<int, 32> v = 3;
simd<float, 32> f = v;
Expand Down