From fc478be92f4caf7e437c7ab9a554f71c74377274 Mon Sep 17 00:00:00 2001 From: Wenju He Date: Tue, 12 Nov 2024 14:59:10 +0800 Subject: [PATCH 1/2] [range_api] Fix bitwise shift rhs out-of-range In kernel test_range_kernels, range[2] is 64 and range_two[2] is 128. It is undefined behavior to use either of them as rhs of bitwise shift operator because the rhs is not smaller than the number of bits in range value type. This PR divides rhs by 4 so that it is smaller than 64. --- tests/range/range_api.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/range/range_api.cpp b/tests/range/range_api.cpp index 8f133ddb9..99aeb9426 100644 --- a/tests/range/range_api.cpp +++ b/tests/range/range_api.cpp @@ -50,6 +50,9 @@ void test_range_kernels( const sycl::range range_two_const(range_two); const sycl::range range_const(range); + sycl::range range_quarter(range / 4); + const sycl::range range_quarter_const(range_quarter); + // friend bool operator==(const T& lhs, const T& rhs) INDEX_EQ_KERNEL_TEST(==, range, range_two); @@ -62,8 +65,8 @@ void test_range_kernels( INDEX_KERNEL_TEST(*, range, range_two_const, result); INDEX_KERNEL_TEST(/, range, range_two_const, result); INDEX_KERNEL_TEST(%, range, range_two_const, result); - INDEX_KERNEL_TEST(<<, range, range_two_const, result); - INDEX_KERNEL_TEST(>>, range, range_two_const, result); + INDEX_KERNEL_TEST(<<, range, range_quarter_const, result); + INDEX_KERNEL_TEST(>>, range, range_quarter_const, result); INDEX_KERNEL_TEST(&, range, range_two_const, result); INDEX_KERNEL_TEST(|, range, range_two_const, result); INDEX_KERNEL_TEST(^, range, range_two_const, result); @@ -81,8 +84,8 @@ void test_range_kernels( DUAL_SIZE_INDEX_KERNEL_TEST(*, range, integer, result); DUAL_SIZE_INDEX_KERNEL_TEST(/, range, integer, result); DUAL_SIZE_INDEX_KERNEL_TEST(%, range, integer, result); - DUAL_SIZE_INDEX_KERNEL_TEST(<<, range, integer, result); - DUAL_SIZE_INDEX_KERNEL_TEST(>>, range, integer, result); + DUAL_SIZE_INDEX_KERNEL_TEST(<<, range_quarter, integer, result); + DUAL_SIZE_INDEX_KERNEL_TEST(>>, range_quarter, integer, result); DUAL_SIZE_INDEX_KERNEL_TEST(&, range, integer, result); DUAL_SIZE_INDEX_KERNEL_TEST(|, range, integer, result); DUAL_SIZE_INDEX_KERNEL_TEST(^, range, integer, result); @@ -99,8 +102,8 @@ void test_range_kernels( INDEX_ASSIGNMENT_TESTS(*=, *, range, range_two, result); INDEX_ASSIGNMENT_TESTS(/=, /, range, range_two, result); INDEX_ASSIGNMENT_TESTS(%=, %, range, range_two, result); - INDEX_ASSIGNMENT_TESTS(<<=, <<, range, range_two, result); - INDEX_ASSIGNMENT_TESTS(>>=, >>, range, range_two, result); + INDEX_ASSIGNMENT_TESTS(<<=, <<, range, range_quarter, result); + INDEX_ASSIGNMENT_TESTS(>>=, >>, range, range_quarter, result); INDEX_ASSIGNMENT_TESTS(&=, &, range, range_two, result); INDEX_ASSIGNMENT_TESTS(|=, |, range, range_two, result); INDEX_ASSIGNMENT_TESTS(^=, ^, range, range_two, result); @@ -111,8 +114,8 @@ void test_range_kernels( INDEX_ASSIGNMENT_INTEGER_TESTS(*=, *, range, integer, result); INDEX_ASSIGNMENT_INTEGER_TESTS(/=, /, range, integer, result); INDEX_ASSIGNMENT_INTEGER_TESTS(%=, %, range, integer, result); - INDEX_ASSIGNMENT_INTEGER_TESTS(<<=, <<, range, integer, result); - INDEX_ASSIGNMENT_INTEGER_TESTS(>>=, >>, range, integer, result); + INDEX_ASSIGNMENT_INTEGER_TESTS(<<=, <<, range_quarter, integer, result); + INDEX_ASSIGNMENT_INTEGER_TESTS(>>=, >>, range_quarter, integer, result); INDEX_ASSIGNMENT_INTEGER_TESTS(&=, &, range, integer, result); INDEX_ASSIGNMENT_INTEGER_TESTS(|=, |, range, integer, result); INDEX_ASSIGNMENT_INTEGER_TESTS(^=, ^, range, integer, result); From ae4e294056a8aa0ca568c4387a226c439bd8e6dc Mon Sep 17 00:00:00 2001 From: Wenju He Date: Wed, 13 Nov 2024 13:09:08 +0800 Subject: [PATCH 2/2] add comment in code --- tests/range/range_api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/range/range_api.cpp b/tests/range/range_api.cpp index 99aeb9426..fc1aa019a 100644 --- a/tests/range/range_api.cpp +++ b/tests/range/range_api.cpp @@ -50,6 +50,7 @@ void test_range_kernels( const sycl::range range_two_const(range_two); const sycl::range range_const(range); + // make sure bitwise shift rhs is smaller than number of bits in size_t. sycl::range range_quarter(range / 4); const sycl::range range_quarter_const(range_quarter);