https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106490
Bug ID: 106490
Summary: loop counter overflow within omp
Product: gcc
Version: og11 (devel/omp/gcc-11)
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgomp
Assignee: unassigned at gcc dot gnu.org
Reporter: dxin at usc dot edu
CC: jakub at gcc dot gnu.org
Target Milestone: ---
Created attachment 53390
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53390&action=edit
minimum test case
gcc's omp implementation seems to use a signed integer type for the loop
counter. As a result, if the user's code use an unsigned loop variable with a
large loop count, the internal loop counter overflows and the loop body never
run.
This is bug only happens when omp is used, i.e. the test case runs as expected
if the omp pragma is removed.
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
---------------------test case begin------------------------
#include <stdio.h>
#include <limits.h>
#include"omp.h"
//const unsigned int I_LIMIT=(UINT_MAX)>>1;// good, printf runs for a while
const unsigned int I_LIMIT=UINT_MAX;// bad case, crash before any printf
int main()
{
#pragma omp parallel for
for(unsigned int i=0;i<=I_LIMIT;i++){
printf("i=%u,i=%f\n",i,(float)(i));
}
return 0;
}
---------------------test case end------------------------
gcc test_omp_overflow.c -fopenmp
./a.out