From: Jakub Jelinek Date: Fri, 28 Nov 2014 17:04:51 +0000 (+0100) Subject: backport: re PR fortran/63938 (OpenMP atomic update does not protect access to automa... X-Git-Tag: releases/gcc-4.8.4~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9543942805fd1a54a9241ce6fdf765523c74d718;p=thirdparty%2Fgcc.git backport: re PR fortran/63938 (OpenMP atomic update does not protect access to automatic array) Backported from mainline 2014-11-24 Jakub Jelinek 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: r218167 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b5dfcf1fa470..2ce28c34c3f3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2014-11-28 Jakub Jelinek + + Backported from mainline + 2014-11-24 Jakub Jelinek + + PR fortran/63938 + * trans-openmp.c (gfc_trans_omp_atomic): Make sure lhsaddr is + simple enough for goa_lhs_expr_p. + 2014-10-10 Jakub Jelinek PR fortran/59488 diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 53a78f08875f..7076e3bef155 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -1227,6 +1227,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_WRITE) diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 8b549f7e41e2..729e54deb8e9 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,6 +1,12 @@ 2014-11-28 Jakub Jelinek Backported from mainline + 2014-11-24 Jakub Jelinek + + PR fortran/63938 + * libgomp.fortran/pr63938-1.f90: New test. + * libgomp.fortran/pr63938-2.f90: New test. + 2014-10-03 Jakub Jelinek PR libgomp/61200 diff --git a/libgomp/testsuite/libgomp.fortran/pr63938-1.f90 b/libgomp/testsuite/libgomp.fortran/pr63938-1.f90 new file mode 100644 index 000000000000..27501b2f8ab0 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr63938-1.f90 @@ -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 index 000000000000..e5f37ba7602a --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr63938-2.f90 @@ -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