https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128134
Bug ID: 128134
Summary: wrong code with #pragma omp tile over an int loop that
ends near INT_MAX
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
int main(void)
{
int n = 0;
#pragma omp tile sizes(4)
for (int i = __INT_MAX__ - 7; i < __INT_MAX__; i++)
if (i < __INT_MAX__ - 7)
__builtin_abort();
else
n++;
if (n != 7)
__builtin_abort();
}
godbolt: https://godbolt.org/z/zsq5EGeTf
The loop runs for i = 2147483640 .. 2147483646, and tiling must not change
that, so the program should exit normally, as it does without -fopenmp. With
-fopenmp (or -fopenmp-simd) at -O0 the tiled loop runs i = 2147483640 ..
2147483643, skips 2147483644 .. 2147483646, continues with i = -2147483648 and
aborts; -O1 stops with SIGILL, and -O2, -O3 and -Os do not terminate. With -O0
-fopenmp -fsanitize=undefined, UBSan reports "signed integer overflow:
2147483644 + 4 cannot be represented in type 'int'" at the pragma line.