There is some strange behavior with #pragma omp for and volatiles:

=================================
void foo()
{
  volatile int i, j = 1;
#pragma omp for
  for (i = 0; i < j; i += 1)
    ;
}
=================================

bug.cc: In function 'void foo()':
bug.cc:4: internal compiler error: in gimplify_omp_for, at gimplify.c:5880
Please submit a full bug report, [etc.]

A similar code snippet (using ++i instead of i+=1 as incrememt) is accepted:

=================================
void foo()
{
  volatile int i, j = 1;
#pragma omp for
  for (i = 0; i < j; ++i)
    ;
}
=================================

Another slight variation (using i<1 instead of i<j as loop condition)
is rejected:

=================================
void foo()
{
  volatile int i;
#pragma omp for
  for (i = 0; i < 1; ++i)
    ;
}
=================================

bug.cc: In function 'void foo()':
bug.cc:5: error: invalid controlling predicate

The above only holds for the C++ frontend since GCC 4.3.0.
With the C frontend or GCC 4.2.x all three snippets compile fine.


I looked into the specification of OpenMP 3.0 and found nothing forbidding
the use of volatiles as loop counters. On the other hand volatile is IMHO
against the semantics of parallel for where magically changing loop counters
would make no sense. Maybe that's even a defect of the OpenMP specification.


-- 
           Summary: [4.3/4.4 regression] Trouble with volatile and #pragma
                    omp for
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code, rejects-valid, monitored, openmp
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org


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

Reply via email to