Use cl_uint in some SPIR-V tests to avoid UB (#2159)

The following tests under `spirv_new`:
* `op_branch_conditional`
* `op_phi`
* `op_selection_merge`

were using randomly generated `cl_int` values, and storing the
difference between them as a `cl_int`. If one of the generated values is
negative and large enough, while the other is positive and large enough,
the difference then becomes a larger value that cannot be represented
using `cl_int`.

Switch the tests to use `cl_uint` instead, and update the relevant
spvasm{32,64} files to use `OpULessThan` instead of `OpSLessThan`.

Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com>
This commit is contained in:
Ahmed Hesham
2024-11-26 17:29:27 +00:00
committed by GitHub
parent 96e3d7e669
commit 5d85fb3e3b
19 changed files with 84 additions and 82 deletions

View File

@@ -83,27 +83,26 @@ int test_branch_conditional(cl_device_id deviceID,
return 0;
}
#define TEST_BRANCH_CONDITIONAL(name) \
TEST_SPIRV_FUNC(op_##name) \
{ \
const int num = 1 << 10; \
RandomSeed seed(gRandomSeed); \
\
std::vector<cl_int> lhs(num); \
std::vector<cl_int> rhs(num); \
std::vector<cl_int> out(num); \
\
for (int i = 0; i < num; i++) { \
lhs[i] = genrand<cl_int>(seed); \
rhs[i] = genrand<cl_int>(seed); \
out[i] = lhs[i] < rhs[i] ? \
(rhs[i] - lhs[i]) : (lhs[i] - rhs[i]); \
} \
\
return test_branch_conditional(deviceID, context, queue, \
#name, \
lhs, rhs, out); \
} \
#define TEST_BRANCH_CONDITIONAL(name) \
TEST_SPIRV_FUNC(op_##name) \
{ \
const int num = 1 << 10; \
RandomSeed seed(gRandomSeed); \
\
std::vector<cl_uint> lhs(num); \
std::vector<cl_uint> rhs(num); \
std::vector<cl_uint> out(num); \
\
for (int i = 0; i < num; i++) \
{ \
lhs[i] = genrand<cl_uint>(seed); \
rhs[i] = genrand<cl_uint>(seed); \
out[i] = lhs[i] < rhs[i] ? (rhs[i] - lhs[i]) : (lhs[i] - rhs[i]); \
} \
\
return test_branch_conditional(deviceID, context, queue, #name, lhs, \
rhs, out); \
}
TEST_BRANCH_CONDITIONAL(branch_conditional)
TEST_BRANCH_CONDITIONAL(branch_conditional_weighted)