diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0b38750b0ded..2ca0e2431221 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2009-11-25 Jakub Jelinek + + 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 PR fortran/42008 diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 4d461cfa488b..7343d1ad0da9 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -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; diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index e36c7e2ca7f7..070d82f2ac80 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,7 +1,12 @@ +2009-11-25 Jakub Jelinek + + PR fortran/42162 + * testsuite/libgomp.fortran/pr42162.f90: New test. + 2009-11-13 Jakub Jelinek PR middle-end/42029 - * libgomp.c/pr42029.c: New test. + * testsuite/libgomp.c/pr42029.c: New test. 2009-10-26 Jakub Jelinek diff --git a/libgomp/testsuite/libgomp.fortran/pr42162.f90 b/libgomp/testsuite/libgomp.fortran/pr42162.f90 new file mode 100644 index 000000000000..dbcc3b71d9b4 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/pr42162.f90 @@ -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