re PR fortran/49792 (OpenMP workshare: Wrong result with array assignment)

PR fortran/49792
	* trans-expr.c (gfc_trans_assignment_1): Set OMPWS_SCALARIZER_WS
	bit in ompws_flags only if loop.temp_ss is NULL, and clear it if
	lhs needs reallocation.
	* trans-openmp.c (gfc_trans_omp_workshare): Don't return early if
	code is NULL, emit a barrier if workshare emitted no code at all
	and NOWAIT clause isn't present.

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

From-SVN: r177898
This commit is contained in:
Jakub Jelinek 2011-08-19 15:25:22 +02:00 committed by Jakub Jelinek
parent df698a8707
commit c26dffff5c
6 changed files with 64 additions and 7 deletions

View File

@ -1,3 +1,13 @@
2011-08-19 Jakub Jelinek <jakub@redhat.com>
PR fortran/49792
* trans-expr.c (gfc_trans_assignment_1): Set OMPWS_SCALARIZER_WS
bit in ompws_flags only if loop.temp_ss is NULL, and clear it if
lhs needs reallocation.
* trans-openmp.c (gfc_trans_omp_workshare): Don't return early if
code is NULL, emit a barrier if workshare emitted no code at all
and NOWAIT clause isn't present.
2011-08-19 Mikael Morin <mikael.morin@sfr.fr>
PR fortran/50071

View File

@ -6137,10 +6137,6 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
rss = NULL;
if (lss != gfc_ss_terminator)
{
/* Allow the scalarizer to workshare array assignments. */
if (ompws_flags & OMPWS_WORKSHARE_FLAG)
ompws_flags |= OMPWS_SCALARIZER_WS;
/* The assignment needs scalarization. */
lss_section = lss;
@ -6196,6 +6192,10 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
gfc_mark_ss_chain_used (loop.temp_ss, 3);
}
/* Allow the scalarizer to workshare array assignments. */
if ((ompws_flags & OMPWS_WORKSHARE_FLAG) && loop.temp_ss == NULL)
ompws_flags |= OMPWS_SCALARIZER_WS;
/* Start the scalarized loop body. */
gfc_start_scalarized_body (&loop, &body);
}
@ -6304,6 +6304,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
&& !gfc_expr_attr (expr1).codimension
&& !gfc_is_coindexed (expr1))
{
ompws_flags &= ~OMPWS_SCALARIZER_WS;
tmp = gfc_alloc_allocatable_for_assignment (&loop, expr1, expr2);
if (tmp != NULL_TREE)
gfc_add_expr_to_block (&loop.code[expr1->rank - 1], tmp);

View File

@ -1764,9 +1764,6 @@ gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
pushlevel (0);
if (!code)
return build_empty_stmt (input_location);
gfc_start_block (&block);
pblock = &block;
@ -1903,6 +1900,9 @@ gfc_trans_omp_workshare (gfc_code *code, gfc_omp_clauses *clauses)
else
poplevel (0, 0, 0);
if (IS_EMPTY_STMT (stmt) && !clauses->nowait)
stmt = gfc_trans_omp_barrier ();
ompws_flags = 0;
return stmt;
}

View File

@ -1,3 +1,9 @@
2011-08-19 Jakub Jelinek <jakub@redhat.com>
PR fortran/49792
* testsuite/libgomp.fortran/pr49792-1.f90: New test.
* testsuite/libgomp.fortran/pr49792-2.f90: New test.
2011-08-08 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* config/posix95/lock.c, posix95/omp-lock.h: Remove.

View File

@ -0,0 +1,18 @@
! PR fortran/49792
! { dg-do run }
subroutine reverse(n, a)
integer :: n
real(kind=8) :: a(n)
!$omp parallel workshare
a(:) = a(n:1:-1)
!$omp end parallel workshare
end subroutine reverse
program pr49792
real(kind=8) :: a(16) = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
real(kind=8) :: b(16)
b(:) = a(16:1:-1)
call reverse (16,a)
if (any (a.ne.b)) call abort
end program pr49792

View File

@ -0,0 +1,22 @@
! PR fortran/49792
! { dg-do run }
! { dg-options "-std=f2003 -fall-intrinsics" }
subroutine reverse(n, a)
integer :: n
real(kind=8) :: a(n)
!$omp parallel workshare
a(:) = a(n:1:-1)
!$omp end parallel workshare
end subroutine reverse
program pr49792
integer :: b(16)
integer, allocatable :: a(:)
b = 1
!$omp parallel workshare
a = b
!$omp end parallel workshare
if (size(a).ne.size(b)) call abort()
if (any (a.ne.b)) call abort()
end program pr49792