[Patch, fortran] PR59026 - ELEMENTAL procedure with VALUE arguments emits wrong code
Paul Richard Thomas
paul.richard.thomas@gmail.com
Sat Feb 8 17:48:00 GMT 2014
Dear All,
This is another corner of a corner case that is not a regression but
fixes a wrong-code-on-valid.
At present, an actual argument of an elemental procedure with the
VALUE attribute is not passed by value. The fix is obvious.
Bootstraps and regtests on FC17/x86_64 - OK for trunk, 4.8 and 4.7?
Cheers
Paul
2014-02-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59026
* trans-expr.c (gfc_conv_procedure_call): Pass the value of the
actual argument to a formal argument with the value attribute
in an elemental procedure.
2014-02-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/59026
* gfortran.dg/elemental_by_value_1.f90 : New test
-------------- next part --------------
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c (revision 205031)
--- gcc/fortran/trans-expr.c (working copy)
*************** gfc_conv_procedure_call (gfc_se * se, gf
*** 4050,4056 ****
--- 4050,4060 ----
gfc_init_se (&parmse, se);
parm_kind = ELEMENTAL;
+ if (fsym && fsym->attr.value)
+ gfc_conv_expr (&parmse, e);
+ else
gfc_conv_expr_reference (&parmse, e);
+
if (e->ts.type == BT_CHARACTER && !e->rank
&& e->expr_type == EXPR_FUNCTION)
parmse.expr = build_fold_indirect_ref_loc (input_location,
Index: gcc/testsuite/gfortran.dg/elemental_by_value_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/elemental_by_value_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/elemental_by_value_1.f90 (working copy)
***************
*** 0 ****
--- 1,22 ----
+ ! { dg-do run }
+ !
+ ! PR fortran/59026
+ !
+ ! Contributed by F-X Coudert <fxcoudert@gcc.gnu.org>
+ !
+ ! Failed to dereference the argument in scalarized loop.
+ !
+ elemental integer function foo(x)
+ integer, value :: x
+ foo = x + 1
+ end function
+
+ interface
+ elemental integer function foo(x)
+ integer, value :: x
+ end function
+ end interface
+
+ if (foo(42) .ne. 43) call abort
+ if (any (foo([0,1]) .ne. [1,2])) call abort
+ end
More information about the Gcc-patches
mailing list