OpenMP_VV
OpenMP_VV copied to clipboard
[5.1][New Test] Add loop iteration count signed/unsigned corner testcase
I did run into this issue recently – and think it could be a useful addition; it just needs to be properly packaged:
- Due to the
int
→unsigned int
integer promotion, thei < 10u
condition evaluates as false and the loop body is not executed. - However, depending how the OpenMP loop iteration count is calculated, it might run 1010 times.
Since OpenMP 5.1, the following wording ensures that the OpenMP count and the C count are the same:
"If var has a signed integer type and the var operand of test-expr after usual arithmetic conversions has an unsigned integer type then the loop iteration count is computed from lb, test-expr and incr using an unsigned integer type corresponding to the type of var." (OpenMP 5.2, 4.4.2 OpenMP Loop-Iteration Spaces and Vectors and, likewise, OpenMP 5.1, 2.11.1 Canonical Loop Nest Form)
int
main ()
{
int error = 0;
#pragma omp for
for (int i = -1000; i < 10u; ++i) {
error = 1;
}
return error;
}