Behavior of ELEMENTAL function with VALUE attribute

Paul Richard Thomas paul.richard.thomas@gmail.com
Wed Nov 6 20:50:00 GMT 2013


Dear All,

The patch below fixes the problem for:
elemental integer function foo(x)
  integer, value :: x
  foo = x
end function


   interface
     elemental integer function foo(x)
       integer, value :: x
     end function
   end interface

   print *, foo(42)
   print *, foo([0,1])
 end

patch:
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c    (revision 204357)
--- gcc/fortran/trans-expr.c    (working copy)
*************** gfc_conv_procedure_call (gfc_se * se, gf
*** 4047,4053 ****
--- 4047,4057 ----
        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,

I haven't checked if it causes regressions or if it is consistent with
other actual args.

Cheers

Paul

On 6 November 2013 21:08, N.M. Maclaren <nmm1@cam.ac.uk> wrote:
> On Nov 6 2013, FX wrote:
>
>>> I think it is a bug.
>>>
>>> VALUE appears in very few places in Sec. 12 of F2008.  None of
>>> those occurence suggest that your code is broken.
>>
>>
>> Thanks. The Intel compiler accepts it, so with three of us in agreement, I
>> filed it as PR 59026 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59026).
>
>
> Ah!  I misread what was going on earlier, so I take back what I said,
> and agree that is a bug.  I thought that you were objecting to the
> redundant copy (which may be unfortunate, but is not a bug).  Not
> accepting that code definitely is one.
>
> My general points about the potential for VALUE to affect the actual
> representation remain, of course, but that's secondary to this simple
> code-generation error.
>
>
> Regards,
> Nick Maclaren.
>
>
>



-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy



More information about the Fortran mailing list