public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array
@ 2014-11-18 16:37 paul.k.romano at gmail dot com
  2014-11-24  7:10 ` [Bug fortran/63938] " Joost.VandeVondele at mat dot ethz.ch
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: paul.k.romano at gmail dot com @ 2014-11-18 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63938
           Summary: OpenMP atomic update does not protect access to
                    automatic array
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: paul.k.romano at gmail dot com

It appears that performing !$omp atomic update on an automatic array does not
protect access to the array. As an example, consider the following program:

program atomic

  integer :: i, x(1)

  x(1) = 0

!$omp parallel do
  do i = 1, 1000
    !$omp atomic
    x(1) = x(1) + 1
  end do
!$omp end parallel do

  print *, x

end program atomic

Compiling and running this program should result in the value 1000. Instead, it
results in an unpredictable value for x, indicating there is a race condition.
If you change x to a scalar or an allocatable array, it works fine and reports
the value 1000. Equivalent code in C does not produce a race condition. The
code gives the correct value when compiled with the Intel fortran compiler.

Information on my build of gcc:
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --disable-multilib
Thread model: posix


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
@ 2014-11-24  7:10 ` Joost.VandeVondele at mat dot ethz.ch
  2014-11-24 10:39 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-11-24  7:10 UTC (permalink / raw)
  To: gcc-bugs

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

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-24
                 CC|                            |Joost.VandeVondele at mat dot ethz
                   |                            |.ch
     Ever confirmed|0                           |1
      Known to fail|                            |4.7.2, 4.8.3, 4.9.2, 5.0

--- Comment #1 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
confirmed to affect all open branches, and at all optimization levels.

It is triggered by the fact that the array index is a constant, i.e.

this fails:

!$omp atomic
 x(1) = x(1) + 1

this works:

!$omp atomic
 x(j) = x(j) + 1


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
  2014-11-24  7:10 ` [Bug fortran/63938] " Joost.VandeVondele at mat dot ethz.ch
@ 2014-11-24 10:39 ` jakub at gcc dot gnu.org
  2014-11-24 10:39 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-24 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.4


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
  2014-11-24  7:10 ` [Bug fortran/63938] " Joost.VandeVondele at mat dot ethz.ch
  2014-11-24 10:39 ` jakub at gcc dot gnu.org
@ 2014-11-24 10:39 ` jakub at gcc dot gnu.org
  2014-11-24 23:09 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-24 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 34088
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34088&action=edit
gcc5-pr63938.patch

Untested fix.


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
                   ` (2 preceding siblings ...)
  2014-11-24 10:39 ` jakub at gcc dot gnu.org
@ 2014-11-24 23:09 ` jakub at gcc dot gnu.org
  2014-11-28 13:37 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-24 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Mon Nov 24 23:08:26 2014
New Revision: 218031

URL: https://gcc.gnu.org/viewcvs?rev=218031&root=gcc&view=rev
Log:
    PR fortran/63938
    * trans-openmp.c (gfc_trans_omp_atomic): Make sure lhsaddr is
    simple enough for goa_lhs_expr_p.

    * libgomp.fortran/pr63938-1.f90: New test.
    * libgomp.fortran/pr63938-2.f90: New test.

Added:
    trunk/libgomp/testsuite/libgomp.fortran/pr63938-1.f90
    trunk/libgomp/testsuite/libgomp.fortran/pr63938-2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-openmp.c
    trunk/libgomp/ChangeLog


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
                   ` (3 preceding siblings ...)
  2014-11-24 23:09 ` jakub at gcc dot gnu.org
@ 2014-11-28 13:37 ` jakub at gcc dot gnu.org
  2014-11-28 17:05 ` jakub at gcc dot gnu.org
  2014-11-28 17:11 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-28 13:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Nov 28 13:36:36 2014
New Revision: 218153

URL: https://gcc.gnu.org/viewcvs?rev=218153&root=gcc&view=rev
Log:
    Backported from mainline
    2014-11-24  Jakub Jelinek  <jakub@redhat.com>

    PR fortran/63938
    * trans-openmp.c (gfc_trans_omp_atomic): Make sure lhsaddr is
    simple enough for goa_lhs_expr_p.

    * libgomp.fortran/pr63938-1.f90: New test.
    * libgomp.fortran/pr63938-2.f90: New test.

Added:
    branches/gcc-4_9-branch/libgomp/testsuite/libgomp.fortran/pr63938-1.f90
    branches/gcc-4_9-branch/libgomp/testsuite/libgomp.fortran/pr63938-2.f90
Modified:
    branches/gcc-4_9-branch/gcc/fortran/ChangeLog
    branches/gcc-4_9-branch/gcc/fortran/trans-openmp.c
    branches/gcc-4_9-branch/libgomp/ChangeLog


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
                   ` (4 preceding siblings ...)
  2014-11-28 13:37 ` jakub at gcc dot gnu.org
@ 2014-11-28 17:05 ` jakub at gcc dot gnu.org
  2014-11-28 17:11 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-28 17:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Nov 28 17:04:51 2014
New Revision: 218167

URL: https://gcc.gnu.org/viewcvs?rev=218167&root=gcc&view=rev
Log:
    Backported from mainline
    2014-11-24  Jakub Jelinek  <jakub@redhat.com>

    PR fortran/63938
    * trans-openmp.c (gfc_trans_omp_atomic): Make sure lhsaddr is
    simple enough for goa_lhs_expr_p.

    * libgomp.fortran/pr63938-1.f90: New test.
    * libgomp.fortran/pr63938-2.f90: New test.

Added:
    branches/gcc-4_8-branch/libgomp/testsuite/libgomp.fortran/pr63938-1.f90
    branches/gcc-4_8-branch/libgomp/testsuite/libgomp.fortran/pr63938-2.f90
Modified:
    branches/gcc-4_8-branch/gcc/fortran/ChangeLog
    branches/gcc-4_8-branch/gcc/fortran/trans-openmp.c
    branches/gcc-4_8-branch/libgomp/ChangeLog


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

* [Bug fortran/63938] OpenMP atomic update does not protect access to automatic array
  2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
                   ` (5 preceding siblings ...)
  2014-11-28 17:05 ` jakub at gcc dot gnu.org
@ 2014-11-28 17:11 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-11-28 17:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.


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

end of thread, other threads:[~2014-11-28 17:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-18 16:37 [Bug fortran/63938] New: OpenMP atomic update does not protect access to automatic array paul.k.romano at gmail dot com
2014-11-24  7:10 ` [Bug fortran/63938] " Joost.VandeVondele at mat dot ethz.ch
2014-11-24 10:39 ` jakub at gcc dot gnu.org
2014-11-24 10:39 ` jakub at gcc dot gnu.org
2014-11-24 23:09 ` jakub at gcc dot gnu.org
2014-11-28 13:37 ` jakub at gcc dot gnu.org
2014-11-28 17:05 ` jakub at gcc dot gnu.org
2014-11-28 17:11 ` jakub 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).