Skip to content

Commit

Permalink
Merge pull request #856 from AlexeySachkov/private/asachkov/fix-Wc++1…
Browse files Browse the repository at this point in the history
…1-narrowing

Fix `-Wc++11-narrowing` warnings
  • Loading branch information
bader authored Jan 19, 2024
2 parents 436fe73 + e4e58e7 commit 1e7e820
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 120 deletions.
12 changes: 6 additions & 6 deletions tests/buffer/buffer_deduction_guides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class check_buffer_deduction {
void operator()(const std::string& type) {
// create container
// using this API because of no_cnstr and no_def_cnstr types
std::array<T, size> arr = {user_def_types::get_init_value_helper<T>(0),
user_def_types::get_init_value_helper<T>(0),
user_def_types::get_init_value_helper<T>(0)};
std::array<T, size> arr = {user_def_types::get_init_value<T>(0),
user_def_types::get_init_value<T>(0),
user_def_types::get_init_value<T>(0)};
type_name = type;

test_inputiterator(arr);
Expand Down Expand Up @@ -123,9 +123,9 @@ class check_buffer_deduction {
const int arr_size = r.size();

std::unique_ptr<T[]> data(
new T[size]{user_def_types::get_init_value_helper<T>(0),
user_def_types::get_init_value_helper<T>(0),
user_def_types::get_init_value_helper<T>(0)});
new T[size]{user_def_types::get_init_value<T>(0),
user_def_types::get_init_value<T>(0),
user_def_types::get_init_value<T>(0)});

INFO("buffer_ctors_deduction::test_type() " + type_name);
// buffer with no alloccator and no property list
Expand Down
39 changes: 30 additions & 9 deletions tests/common/type_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,50 @@ struct arrow_operator_overloaded {
}
};

// Helper structure to extract element type of vec/marray
// Fallback for scalars, which returns unmodified T
template <typename T>
struct vec_marray_element_type {
using type = T;
};

// vec and marray specializations
template <typename T, int N>
struct vec_marray_element_type<sycl::vec<T, N>> {
using type = T;
};

#ifndef SYCL_CTS_COMPILING_WITH_HIPSYCL
template <typename T, int N>
struct vec_marray_element_type<sycl::marray<T, N>> {
using type = T;
};
#endif

// Returns instance of type T
template <typename T>
inline constexpr auto get_init_value_helper(int x) {
return x;
inline constexpr auto get_init_value(int x) {
// Explicit cast is required to silence a warning about narrowing conversion
// in case when T is smaller than int.
return T{static_cast<typename vec_marray_element_type<T>::type>(x)};
}

// Returns instance of type bool
// Special case for bool
template <>
inline constexpr auto get_init_value_helper<bool>(int x) {
return (x % 2 != 0);
inline constexpr auto get_init_value<bool>(int x) {
return x % 2 != 0;
}

// Returns instance of user defined struct with no constructor
// Specializations for user-defined types
template <>
inline constexpr auto get_init_value_helper<no_cnstr>(int x) {
inline constexpr auto get_init_value<no_cnstr>(int x) {
no_cnstr instance{};
instance = x;
return instance;
}

// Returns instance of user defined struct default constructor
template <>
inline constexpr auto get_init_value_helper<def_cnstr>(int x) {
inline constexpr auto get_init_value<def_cnstr>(int x) {
def_cnstr instance;
instance = x;
return instance;
Expand Down
16 changes: 6 additions & 10 deletions tests/multi_ptr/multi_ptr_access_members.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ struct test_result {
int value_to_init = 49;
// Variables that will be used to check that access members returns correct
// value
T dereference_ret_value =
user_def_types::get_init_value_helper<T>(value_to_init);
T dereference_op_ret_value =
user_def_types::get_init_value_helper<T>(value_to_init);
T get_member_ret_value =
user_def_types::get_init_value_helper<T>(value_to_init);
T get_raw_member_ret_value =
user_def_types::get_init_value_helper<T>(value_to_init);
T dereference_ret_value = user_def_types::get_init_value<T>(value_to_init);
T dereference_op_ret_value = user_def_types::get_init_value<T>(value_to_init);
T get_member_ret_value = user_def_types::get_init_value<T>(value_to_init);
T get_raw_member_ret_value = user_def_types::get_init_value<T>(value_to_init);
};

} // namespace detail
Expand Down Expand Up @@ -92,7 +88,7 @@ class run_access_members_tests {
const std::string &is_decorated_name) {
auto queue = once_per_unit::get_queue();
constexpr int val_to_init = 42;
T value = user_def_types::get_init_value_helper<T>(val_to_init);
T value = user_def_types::get_init_value<T>(val_to_init);

// Variable that contains all variables that will be used to verify test
// result
Expand Down Expand Up @@ -170,7 +166,7 @@ class run_access_members_tests {
}
});
}
T expected_value = user_def_types::get_init_value_helper<T>(val_to_init);
T expected_value = user_def_types::get_init_value<T>(val_to_init);
// Dereference and multi_ptr::operator->() available only when:
// !std::is_void<sycl::multi_ptr::value_type>::value
if constexpr (!std::is_void_v<typename multi_ptr_t::value_type>) {
Expand Down
3 changes: 1 addition & 2 deletions tests/multi_ptr/multi_ptr_accessor_constructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ void run_tests(sycl_cts::util::logger& log, const std::string& type_name) {
bool same_value = false;

// default value
T init_value =
user_def_types::get_init_value_helper<std::remove_const_t<T>>(10);
T init_value = user_def_types::get_init_value<std::remove_const_t<T>>(10);

auto queue = once_per_unit::get_queue();

Expand Down
4 changes: 2 additions & 2 deletions tests/multi_ptr/multi_ptr_common_assignment_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class run_common_assign_tests {
const std::string &address_space_name,
const std::string &is_decorated_name) {
auto queue = once_per_unit::get_queue();
T value = user_def_types::get_init_value_helper<T>(expected_val);
T value = user_def_types::get_init_value<T>(expected_val);
sycl::range r(1);
std::array<bool, 3> res;
res.fill(false);
Expand Down Expand Up @@ -96,7 +96,7 @@ class run_common_assign_tests {
check(const_mptr_in, mptr_in, ref, res_acc);
} else {
T private_val =
user_def_types::get_init_value_helper<T>(expected_val);
user_def_types::get_init_value<T>(expected_val);

multi_ptr_t mptr_in =
sycl::address_space_cast<space, decorated, T>(
Expand Down
2 changes: 1 addition & 1 deletion tests/multi_ptr/multi_ptr_common_constructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void run_tests(sycl_cts::util::logger &log, const std::string &type_name) {
// Arrays for result values
bool same_type[types_size]{};
bool same_value[values_size]{};
T ref_value{user_def_types::get_init_value_helper<T>(0)};
T ref_value{user_def_types::get_init_value<T>(0)};
auto queue = once_per_unit::get_queue();

using GlobalAccType = sycl::accessor<T, 1, sycl::access_mode::read_write>;
Expand Down
4 changes: 2 additions & 2 deletions tests/multi_ptr/multi_ptr_comparison_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class run_multi_ptr_comparison_op_test {

using multi_ptr_t = sycl::multi_ptr<T, space, decorated>;

const T m_small_value = user_def_types::get_init_value_helper<T>(1);
const T m_great_value = user_def_types::get_init_value_helper<T>(2);
const T m_small_value = user_def_types::get_init_value<T>(1);
const T m_great_value = user_def_types::get_init_value<T>(2);
// Use an array to be sure that we have two elements that has consecutive
// memory addresses
const T m_values_arr[2] = {m_small_value, m_great_value};
Expand Down
6 changes: 3 additions & 3 deletions tests/multi_ptr/multi_ptr_convert_assignment_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class run_convert_assignment_operators_tests {
const std::string &src_is_decorated_name,
const std::string &dst_is_decorated_name) {
auto queue = once_per_unit::get_queue();
T value = user_def_types::get_init_value_helper<T>(expected_val);
T value = user_def_types::get_init_value<T>(expected_val);
auto r = sycl::range(1);
SECTION(
sycl_cts::section_name(
Expand Down Expand Up @@ -113,7 +113,7 @@ class run_convert_assignment_operators_tests {
res_acc[0] = *(mptr_out.get_raw()) == ref;
} else {
T private_val =
user_def_types::get_init_value_helper<T>(expected_val);
user_def_types::get_init_value<T>(expected_val);

const src_multi_ptr_t mptr_in(
sycl::address_space_cast<
Expand Down Expand Up @@ -184,7 +184,7 @@ class run_convert_assignment_operators_tests {
res_acc[0] = *(mptr_out.get_raw()) == ref;
} else {
T private_val =
user_def_types::get_init_value_helper<T>(expected_val);
user_def_types::get_init_value<T>(expected_val);

const src_multi_ptr_t mptr_in(
sycl::address_space_cast<
Expand Down
2 changes: 1 addition & 1 deletion tests/multi_ptr/multi_ptr_deduction_guides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class check_multi_ptr_deduction {
accessor<T, dims, Mode, target::device>,
local_accessor<T, dims>>;
bool res = false;
T data{user_def_types::get_init_value_helper<T>(0)};
T data{user_def_types::get_init_value<T>(0)};
auto r = sycl_cts::util::get_cts_object::range<dims>::get(1, 1, 1);
{
sycl::buffer<bool, 1> buf_res(&res, {1});
Expand Down
4 changes: 2 additions & 2 deletions tests/multi_ptr/multi_ptr_explicit_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class run_explicit_convert_tests {
template <typename T1>
void run_test(sycl::queue &queue, sycl::range<1> &r) {
bool res = false;
T value = user_def_types::get_init_value_helper<T>(expected_val);
T value = user_def_types::get_init_value<T>(expected_val);
{
sycl::buffer<bool> res_buf(&res, sycl::range<1>(1));
sycl::buffer<T> val_buffer(&value, sycl::range<1>(1));
Expand Down Expand Up @@ -103,7 +103,7 @@ class run_explicit_convert_tests {
res_acc[0] = (*(mptr_out.get()) == ref);
} else {
T private_val =
user_def_types::get_init_value_helper<T>(expected_val);
user_def_types::get_init_value<T>(expected_val);

input_multi_ptr_t<T> mptr_in = sycl::address_space_cast<
sycl::access::address_space::generic_space, decorated, T>(
Expand Down
6 changes: 3 additions & 3 deletions tests/multi_ptr/multi_ptr_implicit_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class run_implicit_convert_tests {
template <typename src_multi_ptr_t, typename dest_multi_ptr_t>
void preform_implicit_conversion_test() {
auto queue = once_per_unit::get_queue();
T value = user_def_types::get_init_value_helper<T>(expected_val);
T value = user_def_types::get_init_value<T>(expected_val);
bool res = false;

constexpr sycl::access::decorated src_multi_ptr_decorated =
Expand Down Expand Up @@ -127,8 +127,8 @@ class run_implicit_convert_tests {
// for cases, when dest_multi_ptr_t equals to multi_ptr<void>
const T value_dest = *(reinterpret_cast<const T *>(mptr_dest.get()));

res_acc[0] = (value_dest ==
user_def_types::get_init_value_helper<T>(expected_val));
res_acc[0] =
(value_dest == user_def_types::get_init_value<T>(expected_val));
};

using kname =
Expand Down
2 changes: 1 addition & 1 deletion tests/multi_ptr/multi_ptr_prefetch_member.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class run_prefetch_test {
"Data type shouldn't be is same to void type");

auto queue = once_per_unit::get_queue();
T value = user_def_types::get_init_value_helper<T>(expected_val);
T value = user_def_types::get_init_value<T>(expected_val);
SECTION(sycl_cts::section_name("Check multi_ptr::prefetch()")
.with("T", type_name)
.with("address_space", "access::address_space::global_space")
Expand Down
4 changes: 2 additions & 2 deletions tests/spec_constants/spec_constants_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ constexpr int default_val = 20;

template <typename T, int case_num>
constexpr sycl::specialization_id<T> spec_const(
user_def_types::get_init_value_helper<T>(default_val));
user_def_types::get_init_value<T>(default_val));

template <typename T>
void fill_init_values(T &result, int val) {
result = user_def_types::get_init_value_helper<T>(val);
result = user_def_types::get_init_value<T>(val);
}

template <typename T, int numElements>
Expand Down
4 changes: 2 additions & 2 deletions tests/spec_constants/spec_constants_defined_various_ways.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void perform_test(util::logger &log, const std::string &type_name,
}
}
sycl::range<1> range(1);
T result { user_def_types::get_init_value_helper<T>(0) };
T ref { user_def_types::get_init_value_helper<T>(0) };
T result{user_def_types::get_init_value<T>(0)};
T ref{user_def_types::get_init_value<T>(0)};
{
fill_init_values(ref, case_num);
sycl::buffer<T, 1> result_buffer(&result, range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,48 @@ static std::string get_hint(sc_vw_id test_id) {
// Defined in a non-global named namespace
template <typename T, int case_num>
constexpr sycl::specialization_id<T> sc_nonglob(
user_def_types::get_init_value_helper<T>(case_num));
user_def_types::get_init_value<T>(case_num));

// A static member variable of a struct in a non-global namespace
struct struct_nonglob {
constexpr struct_nonglob() {}
template <typename T, int case_num>
static constexpr sycl::specialization_id<T> sc{
user_def_types::get_init_value_helper<T>(case_num)};
user_def_types::get_init_value<T>(case_num)};
};
} // namespace spec_const_help

namespace {
// Defined in an unnamed namespace
template <typename T, int case_num>
constexpr sycl::specialization_id<T> sc_unnamed(
user_def_types::get_init_value_helper<T>(case_num));
user_def_types::get_init_value<T>(case_num));

// A static member variable of a struct in an unnamed namespace
struct struct_unnamed {
constexpr struct_unnamed() {}
template <typename T, int case_num>
static constexpr sycl::specialization_id<T> sc{
user_def_types::get_init_value_helper<T>(case_num)};
user_def_types::get_init_value<T>(case_num)};
};
} // unnamed namespace

// Defined in the global namespace as inline constexpr
template <typename T, int case_num>
inline constexpr sycl::specialization_id<T> sc_glob_inl(
user_def_types::get_init_value_helper<T>(case_num));
user_def_types::get_init_value<T>(case_num));

// Defined in the global namespace as static constexpr
template <typename T, int case_num>
static constexpr sycl::specialization_id<T> sc_glob_static(
user_def_types::get_init_value_helper<T>(case_num));
user_def_types::get_init_value<T>(case_num));

// A static member variable of a struct in the global namespace
struct struct_glob {
constexpr struct_glob() {}
template <typename T, int case_num>
static constexpr sycl::specialization_id<T> sc{
user_def_types::get_init_value_helper<T>(case_num)};
user_def_types::get_init_value<T>(case_num)};
};

// A static member variable declared inline constexpr of a struct in the global
Expand All @@ -106,7 +106,7 @@ struct struct_glob_inl {
constexpr struct_glob_inl() {}
template <typename T, int case_num>
static inline constexpr sycl::specialization_id<T> sc{
user_def_types::get_init_value_helper<T>(case_num)};
user_def_types::get_init_value<T>(case_num)};
};

// A static member variable of a templated struct in the global namespace
Expand All @@ -115,7 +115,7 @@ struct struct_glob_tmpl {
constexpr struct_glob_tmpl() {}
template <int case_num>
static constexpr sycl::specialization_id<T> sc{
user_def_types::get_init_value_helper<T>(case_num)};
user_def_types::get_init_value<T>(case_num)};
};

#endif // __SYCLCTS_TESTS_SPEC_CONST_DEFINED_VARIOUS_WAYS_HELPER_H
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class check_spec_constant_exception_throw_for_type {
// kernel_bundle
{
bool exception_was_thrown = false;
T res{user_def_types::get_init_value_helper<T>(0)};
T res{user_def_types::get_init_value<T>(0)};
const int case_num = 1;
auto queue = sycl_cts::util::get_cts_object::queue();

Expand Down Expand Up @@ -85,7 +85,7 @@ class check_spec_constant_exception_throw_for_type {
// kernel_bundle
{
bool exception_was_thrown = false;
T sc_val{user_def_types::get_init_value_helper<T>(0)};
T sc_val{user_def_types::get_init_value<T>(0)};
const int case_num = 2;
auto queue = sycl_cts::util::get_cts_object::queue();

Expand Down
Loading

0 comments on commit 1e7e820

Please sign in to comment.