http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61050

            Bug ID: 61050
           Summary: OpenMP: wrong behavior of 'omp for' on corner cases
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guido at vanguardiasur dot com.ar

Created attachment 32728
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32728&action=edit
example input

Note: by infinite loop, we mean something of the form 'for (i=0; i>=0; i++)',
not considering overflow.

#pragma omp for changes the behavior of empty/infinite loops. Some empty loops
are entered once per thread, and some infinite loops are either not entered at
all or entered once. An example is attached and more are found in [1].

In the attached example, this loop:

    char i;
    #pragma omp for
    for (i=100; i<90; i--)
        printf("Hello %i %i\n", i, omp_get_thread_num());

is entered exactly once, with i = 100, when it should never be entered. There
are no parallel directives.

We believe this is caused by a miscalculation of the number of iterations, or a
wrong empty loop check (or both).
The calculated number of iterations (extracted from the assembly) for the
previous example is 12, when it should probably be zero. Also, some loops give
a negative loop count but are still entered (once).

This happens on gcc 4.9.0, 4.8.2 and some older versions too. We've reproduced
it easily. We checked the OpenMP specification and it does not mention an
exception in these cases. Also note, this behavior does not seem to occur in
fortran.

gcc -v -save-temps output at http://sprunge.us/TfaC.

[1]
    http://sprunge.us/TbWj
    http://sprunge.us/NCeA
    http://sprunge.us/PAZD
    http://sprunge.us/faTD
    http://sprunge.us/CIMN

Reply via email to