public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/106490] New: loop counter overflow within omp
@ 2022-07-31  8:12 dxin at usc dot edu
  2022-08-01  9:20 ` [Bug middle-end/106490] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: dxin at usc dot edu @ 2022-07-31  8:12 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug middle-end/106490] loop counter overflow within omp
  2022-07-31  8:12 [Bug libgomp/106490] New: loop counter overflow within omp dxin at usc dot edu
@ 2022-08-01  9:20 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-01  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libgomp                     |middle-end
           Keywords|                            |openmp
            Version|og11 (devel/omp/gcc-11)     |12.1.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Does the OMP standard allow never ending loops?  I think OMP computes the
number of iterations but that doesn't fit an uint here.  Using UINT_MAX-1 as
upper bound works as expected.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-01  9:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-31  8:12 [Bug libgomp/106490] New: loop counter overflow within omp dxin at usc dot edu
2022-08-01  9:20 ` [Bug middle-end/106490] " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).