Behavior of ELEMENTAL function with VALUE attribute
FX
fxcoudert@gmail.com
Wed Nov 6 16:04:00 GMT 2013
(As you can guess if you follow my various posts here and on bugzilla, I’ve taken part of the day to try and write a proof-of-concept patch adding support for the IEEE modules in gfortran. This is the latest sticking point.)
Some of the IEEE functions are elemental. I have a working implementation of them, but I thought it would be nicer to have them take arguments by value. However, things are not behaving as I expected them to. Let’s take this code:
> interface
> elemental integer function foo(x)
> integer, value :: x
> end function
> end interface
>
> print *, foo(42)
> print *, foo([0,1])
> end
I declare a nice elemental function FOO, whose argument X is given by value. However, if I scan the generated code for the example above, the first call to FOO is translated as such:
> D.1882 = foo (42);
> _gfortran_transfer_integer_write (&dt_parm.0, &D.1882, 4);
which is as expected, but the array case is translated as this code:
> S.3 = 0;
> while (1)
> {
> if (S.3 > 1) goto L.1;
> {
> integer(kind=4) D.1888;
> integer(kind=4) D.1887;
>
> D.1887 = A.2[S.3];
> D.1888 = foo (&D.1887);
> _gfortran_transfer_integer_write (&dt_parm.1, &D.1888, 4);
> }
> S.3 = S.3 + 1;
> }
> L.1:;
It’s a loop over array elements, but note that foo (&D.1887) is used instead of foo (D.1887), which I would believe to be correct.
Is it, as I think, a bug in gfortran? Or am I missing something deeper about the interaction of ELEMENTAL and VALUE?
Thanks,
FX
More information about the Fortran
mailing list