Bug report

FX fxcoudert@gmail.com
Thu Nov 3 14:46:00 GMT 2011


It's indeed a 4.4 regression (that is still present in 4.7). On this reduced testcase:

>   write(*,*) ff([0,0])
> 
> CONTAINS 
> 
>     ELEMENTAL integer FUNCTION ff(a,b)
>       integer, INTENT(IN) :: a
>       INTEGER, INTENT(IN), OPTIONAL :: b
>       ff = sum(gg([0,0], b))
>     END FUNCTION ff
> 
>     elemental integer FUNCTION gg(a, b)
>       integer, INTENT(IN) :: a
>       INTEGER, INTENT(IN), OPTIONAL :: b
>       gg = 0
>     END FUNCTION gg
> 
> END

The generated code for FF is clearly faulty:

> ff (integer(kind=4) & restrict a, integer(kind=4) * b)
> {
>   integer(kind=4) __result_ff;
> 
>   {
>     integer(kind=4) D.1548;
>     static integer(kind=4) A.1[2] = {0, 0};
>     integer(kind=4) val.0;
> 
>     val.0 = 0;
>     D.1548 = *b;

Here, the pointer to b is unconditionally accessed, while b the pointer can be NULL in case b is not present.

>     {
>       integer(kind=8) S.2;
> 
>       S.2 = 0;
>       while (1)
>         {
>           if (S.2 > 1) goto L.1;
>           {
>             integer(kind=4) D.1550;
> 
>             D.1550 = A.1[S.2];
>             val.0 = gg (&D.1550, &D.1548) + val.0;

And here, it should thus be simply "b" instead of "&D.1548".

>           }
>           S.2 = S.2 + 1;
>         }
>       L.1:;
>     }
>     __result_ff = val.0;
>   }
>   return __result_ff;
> }
> 



More information about the Fortran mailing list