https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128308

            Bug ID: 128308
           Summary: wrong code with -fopenmp: schedule(static, chunk) with
                    a chunk above INT_MAX on an int loop crashes
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: openmp, 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

#include <stdio.h>

int a[8];

int main(void)
{
#pragma omp parallel for num_threads(1) schedule(static, 0xffffffffL)
  for (int i = 0; i < 8; ++i)
    a[i] = 1;
  int sum = 0;
  for (int i = 0; i < 8; ++i)
    sum += a[i];
  printf("%d\n", sum);
  return 0;
}

godbolt: https://godbolt.org/z/rxPsWfGsj

The chunk size 0xffffffff is positive and larger than the 8 iterations, so the
loop runs as one chunk and the program must print 8, as it does without
-fopenmp. With -fopenmp at -O0, -O1, -O2, -O3 and -Os it crashes with SIGSEGV;
with a long iterator (for (long i = 0; i < 8; ++i)) it prints 8.

Reply via email to