diff options
author | Mikael Morin <mikael@gcc.gnu.org> | 2016-02-05 21:41:15 +0000 |
---|---|---|
committer | Mikael Morin <mikael@gcc.gnu.org> | 2016-02-05 21:41:15 +0000 |
commit | 711d7c231fc6a5a04f65568cf17a47c270527a09 (patch) | |
tree | 6b50b567f3e7b484d1a22fbe37c2dcf74d0ad824 /gcc/fortran/trans-array.c | |
parent | 861c7bcd62bcbbf6e14311e18ba7293cc581e1ff (diff) | |
download | gcc-711d7c231fc6a5a04f65568cf17a47c270527a09.zip gcc-711d7c231fc6a5a04f65568cf17a47c270527a09.tar.gz gcc-711d7c231fc6a5a04f65568cf17a47c270527a09.tar.bz2 |
Fix fortran scalar elemental dependency mishandling
PR fortran/66089
gcc/fortran/
* trans-expr.c (expr_is_variable, gfc_expr_is_variable): Rename
the former to the latter and make it non-static. Update callers.
* gfortran.h (gfc_expr_is_variable): New declaration.
(struct gfc_ss_info): Add field needs_temporary.
* trans-array.c (gfc_scalar_elemental_arg_saved_as_argument):
Tighten the condition on aggregate expressions with a check
that the expression is a variable and doesn't need a temporary.
(gfc_conv_resolve_dependency): Add intermediary reference variable.
Set the needs_temporary field.
gcc/testsuite/
* gfortran.dg/elemental_dependency_6.f90: New.
From-SVN: r233188
Diffstat (limited to 'gcc/fortran/trans-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index eeb688c..2ff2833 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -2464,10 +2464,12 @@ gfc_scalar_elemental_arg_saved_as_reference (gfc_ss_info * ss_info) return true; /* If the expression is a data reference of aggregate type, + and the data reference is not used on the left hand side, avoid a copy by saving a reference to the content. */ - if (ss_info->expr->expr_type == EXPR_VARIABLE + if (!ss_info->data.scalar.needs_temporary && (ss_info->expr->ts.type == BT_DERIVED - || ss_info->expr->ts.type == BT_CLASS)) + || ss_info->expr->ts.type == BT_CLASS) + && gfc_expr_is_variable (ss_info->expr)) return true; /* Otherwise the expression is evaluated to a temporary variable before the @@ -4461,6 +4463,7 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest, gfc_ss *ss; gfc_ref *lref; gfc_ref *rref; + gfc_ss_info *ss_info; gfc_expr *dest_expr; gfc_expr *ss_expr; int nDepend = 0; @@ -4471,15 +4474,16 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest, for (ss = rss; ss != gfc_ss_terminator; ss = ss->next) { - ss_expr = ss->info->expr; + ss_info = ss->info; + ss_expr = ss_info->expr; - if (ss->info->array_outer_dependency) + if (ss_info->array_outer_dependency) { nDepend = 1; break; } - if (ss->info->type != GFC_SS_SECTION) + if (ss_info->type != GFC_SS_SECTION) { if (flag_realloc_lhs && dest_expr != ss_expr @@ -4494,6 +4498,10 @@ gfc_conv_resolve_dependencies (gfc_loopinfo * loop, gfc_ss * dest, nDepend = gfc_check_dependency (dest_expr, ss_expr, false); + if (ss_info->type == GFC_SS_REFERENCE + && gfc_check_dependency (dest_expr, ss_expr, false)) + ss_info->data.scalar.needs_temporary = 1; + continue; } |