mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
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:
@@ -88,13 +88,13 @@ TEST_SPIRV_FUNC(op_phi_2_blocks)
|
||||
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);
|
||||
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_int>(seed);
|
||||
rhs[i] = genrand<cl_int>(seed);
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -106,15 +106,15 @@ TEST_SPIRV_FUNC(op_phi_3_blocks)
|
||||
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);
|
||||
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_int>(seed);
|
||||
rhs[i] = genrand<cl_int>(seed);
|
||||
lhs[i] = genrand<cl_uint>(seed);
|
||||
rhs[i] = genrand<cl_uint>(seed);
|
||||
if (lhs[i] < rhs[i]) {
|
||||
out[i] = lhs[i] < 0 ? -lhs[i] : lhs[i];
|
||||
out[i] = lhs[i] < 65535 ? -lhs[i] : lhs[i];
|
||||
} else {
|
||||
out[i] = lhs[i] - rhs[i];
|
||||
}
|
||||
@@ -128,17 +128,17 @@ TEST_SPIRV_FUNC(op_phi_4_blocks)
|
||||
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);
|
||||
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_int>(seed);
|
||||
rhs[i] = genrand<cl_int>(seed);
|
||||
lhs[i] = genrand<cl_uint>(seed);
|
||||
rhs[i] = genrand<cl_uint>(seed);
|
||||
if (lhs[i] < rhs[i]) {
|
||||
out[i] = lhs[i] < 0 ? -lhs[i] : lhs[i];
|
||||
out[i] = lhs[i] < 65535 ? -lhs[i] : lhs[i];
|
||||
} else {
|
||||
out[i] = rhs[i] < 0 ? -rhs[i] : rhs[i];
|
||||
out[i] = rhs[i] < 65535 ? -rhs[i] : rhs[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user