|
| 1 | +// RUN: %clangxx -fsycl -fpreview-breaking-changes -fsyntax-only %s -Xclang -verify |
| 2 | +// REQUIRES: preview-breaking-changes-supported |
| 3 | + |
| 4 | +#include <sycl/sycl.hpp> |
| 5 | + |
| 6 | +using namespace sycl; |
| 7 | +using namespace sycl::detail; |
| 8 | + |
| 9 | +namespace builtin_same_shape_v_tests { |
| 10 | +using swizzle1 = decltype(std::declval<vec<float, 2>>().swizzle<0>()); |
| 11 | +using swizzle2 = decltype(std::declval<vec<float, 2>>().swizzle<0, 0>()); |
| 12 | +using swizzle3 = decltype(std::declval<vec<float, 2>>().swizzle<0, 0, 1>()); |
| 13 | + |
| 14 | +static_assert(builtin_same_shape_v<float>); |
| 15 | +static_assert(builtin_same_shape_v<int, float>); |
| 16 | +static_assert(builtin_same_shape_v<marray<int, 2>>); |
| 17 | +static_assert(builtin_same_shape_v<marray<int, 2>, marray<float, 2>>); |
| 18 | +static_assert(builtin_same_shape_v<vec<int, 2>>); |
| 19 | +static_assert(builtin_same_shape_v<vec<int, 2>, vec<float, 2>>); |
| 20 | +static_assert(builtin_same_shape_v<vec<int, 2>, swizzle2>); |
| 21 | + |
| 22 | +static_assert(!builtin_same_shape_v<float, marray<float, 1>>); |
| 23 | +static_assert(!builtin_same_shape_v<float, vec<float, 1>>); |
| 24 | +static_assert(!builtin_same_shape_v<marray<float, 1>, vec<float, 1>>); |
| 25 | +static_assert(!builtin_same_shape_v<float, swizzle1>); |
| 26 | +static_assert(!builtin_same_shape_v<marray<float, 1>, swizzle1>); |
| 27 | +static_assert(!builtin_same_shape_v<swizzle2, swizzle1>); |
| 28 | +} // namespace builtin_same_shape_v_tests |
| 29 | + |
| 30 | +namespace builtin_marray_impl_tests { |
| 31 | +// Integer functions/relational bitselect only accept fixed-width integer |
| 32 | +// element types for vector/swizzle elements. Make sure that our marray->vec |
| 33 | +// delegator can handle that. |
| 34 | + |
| 35 | +auto foo(char x) { return x; } |
| 36 | +auto foo(signed char x) { return x; } |
| 37 | +auto foo(unsigned char x) { return x; } |
| 38 | +auto foo(vec<int8_t, 2> x) { return x; } |
| 39 | +auto foo(vec<uint8_t, 2> x) { return x; } |
| 40 | + |
| 41 | +auto test() { |
| 42 | + marray<char, 2> x; |
| 43 | + marray<signed char, 2> y; |
| 44 | + marray<unsigned char, 2> z; |
| 45 | + auto TestOne = [](auto x) { |
| 46 | + std::ignore = builtin_marray_impl([](auto x) { return foo(x); }, x); |
| 47 | + }; |
| 48 | + TestOne(x); |
| 49 | + TestOne(y); |
| 50 | + TestOne(z); |
| 51 | +} |
| 52 | +} // namespace builtin_marray_impl_tests |
| 53 | + |
| 54 | +namespace builtin_enable_integer_tests { |
| 55 | +using swizzle1 = decltype(std::declval<vec<int8_t, 2>>().swizzle<0>()); |
| 56 | +using swizzle2 = decltype(std::declval<vec<int8_t, 2>>().swizzle<0, 0>()); |
| 57 | +template <typename... Ts> void ignore() {} |
| 58 | + |
| 59 | +void test() { |
| 60 | + // clang-format off |
| 61 | + ignore<builtin_enable_integer_t<char>, |
| 62 | + builtin_enable_integer_t<signed char>, |
| 63 | + builtin_enable_integer_t<unsigned char>>(); |
| 64 | + // clang-format on |
| 65 | + |
| 66 | + ignore<builtin_enable_integer_t<vec<int8_t, 2>>, |
| 67 | + builtin_enable_integer_t<vec<uint8_t, 2>>>(); |
| 68 | + |
| 69 | + ignore<builtin_enable_integer_t<char, char>>(); |
| 70 | + ignore<builtin_enable_integer_t<vec<int8_t, 2>, vec<int8_t, 2>>>(); |
| 71 | + ignore<builtin_enable_integer_t<vec<int8_t, 2>, swizzle2>>(); |
| 72 | + ignore<builtin_enable_integer_t<swizzle2, swizzle2>>(); |
| 73 | + |
| 74 | + { |
| 75 | + // Only one of char/signed char maps onto int8_t. The other type isn't a |
| 76 | + // valid vector element type for integer builtins. |
| 77 | + |
| 78 | + static_assert(std::is_signed_v<char>); |
| 79 | + |
| 80 | + // clang-format off |
| 81 | + // expected-error-re@*:* {{no type named 'type' in 'sycl::detail::builtin_enable<sycl::detail::default_ret_type, sycl::detail::integer_elem_type, sycl::detail::any_shape, sycl::detail::same_elem_type, sycl::vec<{{.*}}, 2>>'}} |
| 82 | + // expected-note@+1 {{in instantiation of template type alias 'builtin_enable_integer_t' requested here}} |
| 83 | + ignore<builtin_enable_integer_t<vec<signed char, 2>>, builtin_enable_integer_t<vec<char, 2>>>(); |
| 84 | + // clang-format on |
| 85 | + } |
| 86 | + |
| 87 | + // expected-error@*:* {{no type named 'type' in 'sycl::detail::builtin_enable<sycl::detail::default_ret_type, sycl::detail::integer_elem_type, sycl::detail::any_shape, sycl::detail::same_elem_type, char, signed char>'}} |
| 88 | + // expected-note@+1 {{in instantiation of template type alias 'builtin_enable_integer_t' requested here}} |
| 89 | + ignore<builtin_enable_integer_t<char, signed char>>(); |
| 90 | +} |
| 91 | +} // namespace builtin_enable_integer_tests |
| 92 | + |
| 93 | +namespace builtin_enable_bitselect_tests { |
| 94 | +// Essentially the same as builtin_enable_integer_t + FP types support. |
| 95 | +using swizzle1 = decltype(std::declval<vec<int8_t, 2>>().swizzle<0>()); |
| 96 | +using swizzle2 = decltype(std::declval<vec<int8_t, 2>>().swizzle<0, 0>()); |
| 97 | +template <typename... Ts> void ignore() {} |
| 98 | + |
| 99 | +void test() { |
| 100 | + // clang-format off |
| 101 | + ignore<builtin_enable_bitselect_t<char>, |
| 102 | + builtin_enable_bitselect_t<signed char>, |
| 103 | + builtin_enable_bitselect_t<unsigned char>, |
| 104 | + builtin_enable_bitselect_t<float>>(); |
| 105 | + // clang-format on |
| 106 | + |
| 107 | + ignore<builtin_enable_bitselect_t<vec<int8_t, 2>>, |
| 108 | + builtin_enable_bitselect_t<vec<uint8_t, 2>>, |
| 109 | + builtin_enable_bitselect_t<vec<float, 2>>>(); |
| 110 | + |
| 111 | + ignore<builtin_enable_bitselect_t<char, char>>(); |
| 112 | + ignore<builtin_enable_bitselect_t<vec<int8_t, 2>, vec<int8_t, 2>>>(); |
| 113 | + ignore<builtin_enable_bitselect_t<vec<int8_t, 2>, swizzle2>>(); |
| 114 | + ignore<builtin_enable_bitselect_t<swizzle2, swizzle2>>(); |
| 115 | + |
| 116 | + { |
| 117 | + // Only one of char/signed char maps onto int8_t. The other type isn't a |
| 118 | + // valid vector element type for integer builtins. |
| 119 | + |
| 120 | + static_assert(std::is_signed_v<char>); |
| 121 | + |
| 122 | + // clang-format off |
| 123 | + // expected-error-re@*:* {{no type named 'type' in 'sycl::detail::builtin_enable<sycl::detail::default_ret_type, sycl::detail::bitselect_elem_type, sycl::detail::any_shape, sycl::detail::same_elem_type, sycl::vec<{{.*}}, 2>>'}} |
| 124 | + // expected-note@+1 {{in instantiation of template type alias 'builtin_enable_bitselect_t' requested here}} |
| 125 | + ignore<builtin_enable_bitselect_t<vec<signed char, 2>>, builtin_enable_bitselect_t<vec<char, 2>>>(); |
| 126 | + // clang-format on |
| 127 | + } |
| 128 | + |
| 129 | + // expected-error@*:* {{no type named 'type' in 'sycl::detail::builtin_enable<sycl::detail::default_ret_type, sycl::detail::bitselect_elem_type, sycl::detail::any_shape, sycl::detail::same_elem_type, char, signed char>'}} |
| 130 | + // expected-note@+1 {{in instantiation of template type alias 'builtin_enable_bitselect_t' requested here}} |
| 131 | + ignore<builtin_enable_bitselect_t<char, signed char>>(); |
| 132 | +} |
| 133 | +} // namespace builtin_enable_bitselect_tests |
0 commit comments