https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105345
Bug ID: 105345 Summary: [OpenMP] Wrong iteration loop count when mixing signed and unsigned Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: openmp, wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: frederik at gcc dot gnu.org, jakub at gcc dot gnu.org Target Milestone: --- The following program has a loop count of 0 without OpenMP (-fno-openmp) but is executed 1010 times with -fopenmp in GCC. The problem is that the following is not honored: "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) (Likewise: OpenMP 5.1, 2.11.1 Canonical Loop Nest Form) The wording seems to be new since OpenMP 5.1 - and to ensure that the OpenMP and C loop counts are the same: int main () { #pragma omp for for (int i = -1000; i < 10u; ++i) { __builtin_printf("%d\n", i); __builtin_abort (); } }