re PR fortran/42162 (OpenMP: ICE: tree check in omp_add_variable, at gimplify.c:5282)

PR fortran/42162
	* trans-openmp.c (gfc_trans_omp_do): When dovar isn't a VAR_DECL,
	don't use simple loop and handle clauses properly.

	* testsuite/libgomp.fortran/pr42162.f90: New test.

From-SVN: r154654
This commit is contained in:
Jakub Jelinek 2009-11-25 21:28:56 +01:00 committed by Jakub Jelinek
parent fc07d9e3cb
commit 281e33e1bb
4 changed files with 81 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2009-11-25 Jakub Jelinek <jakub@redhat.com>
PR fortran/42162
* trans-openmp.c (gfc_trans_omp_do): When dovar isn't a VAR_DECL,
don't use simple loop and handle clauses properly.
2009-11-24 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/42008

View File

@ -1160,6 +1160,7 @@ gfc_trans_omp_do (gfc_code *code, stmtblock_t *pblock,
{
int simple = 0;
int dovar_found = 0;
tree dovar_decl;
if (clauses)
{
@ -1200,12 +1201,19 @@ gfc_trans_omp_do (gfc_code *code, stmtblock_t *pblock,
gfc_conv_expr_val (&se, code->ext.iterator->step);
gfc_add_block_to_block (pblock, &se.pre);
step = gfc_evaluate_now (se.expr, pblock);
dovar_decl = dovar;
/* Special case simple loops. */
if (integer_onep (step))
simple = 1;
else if (tree_int_cst_equal (step, integer_minus_one_node))
simple = -1;
if (TREE_CODE (dovar) == VAR_DECL)
{
if (integer_onep (step))
simple = 1;
else if (tree_int_cst_equal (step, integer_minus_one_node))
simple = -1;
}
else
dovar_decl
= gfc_trans_omp_variable (code->ext.iterator->var->symtree->n.sym);
/* Loop body. */
if (simple)
@ -1249,7 +1257,7 @@ gfc_trans_omp_do (gfc_code *code, stmtblock_t *pblock,
if (!dovar_found)
{
tmp = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE);
OMP_CLAUSE_DECL (tmp) = dovar;
OMP_CLAUSE_DECL (tmp) = dovar_decl;
omp_clauses = gfc_trans_add_clause (tmp, omp_clauses);
}
else if (dovar_found == 2)
@ -1269,7 +1277,7 @@ gfc_trans_omp_do (gfc_code *code, stmtblock_t *pblock,
tmp = fold_build2 (MODIFY_EXPR, type, dovar, tmp);
for (c = omp_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
&& OMP_CLAUSE_DECL (c) == dovar)
&& OMP_CLAUSE_DECL (c) == dovar_decl)
{
OMP_CLAUSE_LASTPRIVATE_STMT (c) = tmp;
break;
@ -1279,11 +1287,11 @@ gfc_trans_omp_do (gfc_code *code, stmtblock_t *pblock,
{
for (c = par_clauses; c ; c = OMP_CLAUSE_CHAIN (c))
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
&& OMP_CLAUSE_DECL (c) == dovar)
&& OMP_CLAUSE_DECL (c) == dovar_decl)
{
tree l = build_omp_clause (input_location,
OMP_CLAUSE_LASTPRIVATE);
OMP_CLAUSE_DECL (l) = dovar;
OMP_CLAUSE_DECL (l) = dovar_decl;
OMP_CLAUSE_CHAIN (l) = omp_clauses;
OMP_CLAUSE_LASTPRIVATE_STMT (l) = tmp;
omp_clauses = l;

View File

@ -1,7 +1,12 @@
2009-11-25 Jakub Jelinek <jakub@redhat.com>
PR fortran/42162
* testsuite/libgomp.fortran/pr42162.f90: New test.
2009-11-13 Jakub Jelinek <jakub@redhat.com>
PR middle-end/42029
* libgomp.c/pr42029.c: New test.
* testsuite/libgomp.c/pr42029.c: New test.
2009-10-26 Jakub Jelinek <jakub@redhat.com>

View File

@ -0,0 +1,53 @@
! PR fortran/42162
! { dg-do run }
subroutine sub1(k, a)
implicit none
integer :: k, a(3)
!$omp do
do k=1,3
a(k) = a(k) + 1
enddo
!$omp end do
end subroutine sub1
subroutine sub2(k, a)
implicit none
integer :: k, a(3)
!$omp do private (k)
do k=1,3
a(k) = a(k) + 1
enddo
!$omp end do
end subroutine sub2
subroutine sub3(k, a)
implicit none
integer :: k, a(3)
!$omp do lastprivate (k)
do k=1,3
a(k) = a(k) + 1
enddo
!$omp end do
end subroutine sub3
program pr42162
implicit none
integer :: k, a(3), b(3), c(3)
a = 1
b = 2
c = 3
k = 3
!$omp parallel num_threads(3)
call sub1 (k, a)
!$omp end parallel
k = 4
!$omp parallel num_threads(3)
call sub2 (k, b)
!$omp end parallel
k = 10
!$omp parallel num_threads(3)
call sub3 (k, c)
!$omp end parallel
if (k.ne.4.or.any(a.ne.2).or.any(b.ne.3).or.any(c.ne.4)) call abort
end