Dear All,
This is something of a corner case, where gfc_conv_expr comes back
with a SAVE_EXPR, in the case of complex, scalar, coarray lvalues. The
first field of the SAVE_EXPR is a perfectly viable expression to
assign to, so I have taken that. If anybody out there has a better
solution, please speak up! The testcase is good, anyway....
Discussed on https://groups.google.com/forum/#!topic/opencoarrays/Cl2iK3OfUTs
Bootstrapped and regtested on FC21/x86_64 - OK for trunk?
Paul
2015-09-08 Paul Thomas <[email protected]>
PR fortran/66681
* trans-expr.c (gfc_trans_assignment_1): If the lvalue is a
complex type and a save_expr, take the field to be assigned to.
2015-09-08 Paul Thomas <[email protected]>
PR fortran/66681
* gfortran.dg/coarray_40.f90: New test.
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c (revision 227511)
--- gcc/fortran/trans-expr.c (working copy)
*************** gfc_trans_assignment_1 (gfc_expr * expr1
*** 9269,9274 ****
--- 9269,9281 ----
gfc_add_block_to_block (&loop.post, &rse.post);
}
+ /* Complex scalar coarrays sometimes produce a SAVE_EXPR on type conversion.
+ Take the expression to assign to. */
+ if (TREE_CODE (lse.expr) == SAVE_EXPR
+ && TREE_CODE (TREE_TYPE (lse.expr)) == COMPLEX_TYPE
+ && expr1->symtree->n.sym->attr.codimension)
+ lse.expr = TREE_OPERAND (lse.expr, 0);
+
tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts,
expr_is_variable (expr2) || scalar_to_array
|| expr2->expr_type == EXPR_ARRAY,
Index: gcc/testsuite/gfortran.dg/coarray_40.f90
===================================================================
*** gcc/testsuite/gfortran.dg/coarray_40.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/coarray_40.f90 (working copy)
***************
*** 0 ****
--- 1,11 ----
+ ! { dg-do compile }
+ ! { dg-options "-fcoarray=single -fdump-tree-original" }
+ ! Test the fix for PR66681.
+ !
+ ! Contributed by Damian Rouson <[email protected]>
+ !
+ complex a[*]
+ a = this_image ()
+ print *,this_image (),a
+ end
+ ! { dg-final { scan-tree-dump-times "SAVE_EXPR" 0 "original" } }