re PR fortran/63938 (OpenMP atomic update does not protect access to automatic array)
authorJakub Jelinek <jakub@redhat.com>
Mon, 24 Nov 2014 23:08:26 +0000 (00:08 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 24 Nov 2014 23:08:26 +0000 (00:08 +0100)
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.

From-SVN: r218031

gcc/fortran/ChangeLog
gcc/fortran/trans-openmp.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.fortran/pr63938-1.f90 [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/pr63938-2.f90 [new file with mode: 0644]

index e797d44c8b70717438b4b116841e4e67f01fff83..9dcacbd0d6eb96e2e5e8bfebba288dd98ea284e3 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2014-11-24  Tobias Burnus  <burnus@net-b.de>
 
        * error.c (gfc_fatal_error_1): Remove.
index 038c3e9a6e4095faba6da93874f6a39fd11dffc7..d7660d772ae90ce6c7d03f0eee7d64a062936ea8 100644 (file)
@@ -2683,6 +2683,18 @@ gfc_trans_omp_atomic (gfc_code *code)
     }
 
   lhsaddr = save_expr (lhsaddr);
+  if (TREE_CODE (lhsaddr) != SAVE_EXPR
+      && (TREE_CODE (lhsaddr) != ADDR_EXPR
+         || TREE_CODE (TREE_OPERAND (lhsaddr, 0)) != VAR_DECL))
+    {
+      /* Make sure LHS is simple enough so that goa_lhs_expr_p can recognize
+        it even after unsharing function body.  */
+      tree var = create_tmp_var_raw (TREE_TYPE (lhsaddr), NULL);
+      DECL_CONTEXT (var) = current_function_decl;
+      lhsaddr = build4 (TARGET_EXPR, TREE_TYPE (lhsaddr), var, lhsaddr,
+                       NULL_TREE, NULL_TREE);
+    }
+
   rhs = gfc_evaluate_now (rse.expr, &block);
 
   if (((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_MASK)
index 08425e98ee29397fa735a3c4fa2071ae3ff12c51..097b36f3ad259f5ce43e4bc13eb568bd33c735dc 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/63938
+       * libgomp.fortran/pr63938-1.f90: New test.
+       * libgomp.fortran/pr63938-2.f90: New test.
+
 2014-11-21  Steve Ellcey  <sellcey@imgtec.com>
 
        * config/linux/mips/futex.h (SYS_futex): Define if not already done.
diff --git a/libgomp/testsuite/libgomp.fortran/pr63938-1.f90 b/libgomp/testsuite/libgomp.fortran/pr63938-1.f90
new file mode 100644 (file)
index 0000000..27501b2
--- /dev/null
@@ -0,0 +1,14 @@
+! PR fortran/63938
+! { dg-do run }
+
+program pr63938_1
+  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
+  if (x(1) .ne. 1000) call abort
+end program pr63938_1
diff --git a/libgomp/testsuite/libgomp.fortran/pr63938-2.f90 b/libgomp/testsuite/libgomp.fortran/pr63938-2.f90
new file mode 100644 (file)
index 0000000..e5f37ba
--- /dev/null
@@ -0,0 +1,18 @@
+! PR fortran/63938
+! { dg-do run }
+
+program pr63938_2
+  type t
+    integer :: x
+  end type
+  integer :: i
+  type(t) :: x
+  x%x = 0
+!$omp parallel do
+  do i = 1, 1000
+    !$omp atomic
+    x%x = x%x + 1
+  end do
+!$omp end parallel do
+  if (x%x .ne. 1000) call abort
+end program pr63938_2