[patch, fortran] Fix PR29458 - spurious warning for implied do-loop counter

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sun Apr 5 13:37:00 GMT 2009


Daniel Franke wrote:
> This code gives a warning about 'i' being used uninitialized:
> 
>   integer :: n, i
>   n = 5
>   n = SUM((/(i,i=1,n)/))
> end
> 
> Attached patch fixes this by shadowing 'i' with a temporary variable. Further, 
> it wraps the implied-do in its own block instead of placing it in the parent 
> block directly. The relevant part now looks like this, 'i' is never touched:
> 
>     {                         
>       shadow_loopvar.4 = 1;
>       D.1515 = n;
>       [...]
>       while (1)
>         {
>           if (shadow_loopvar.4 > D.1515) goto L.1;
>           (*(integer(kind=4)[0] *) atmp.2.data)[offset.3] = shadow_loopvar.4;
>           offset.3 = offset.3 + 1;
>           shadow_loopvar.4 = shadow_loopvar.4 + 1;
>         }
>       L.1:;
>     }

Excuse my ignorance, but what should happen if the user did:
    integer :: n, i
    n = 5
    n = sum((/(i,i=1,n)/))
    print *, i
   end
That should print 5, shouldn't it?

Cheers,
- Tobi

> 2009-04-05  Daniel Franke  <franke.daniel@gmail.com>
> 
> 	PR fortran/29458
> 	* trans-array.c (gfc_trans_array_constructor_value): Shadow implied
> 	do-loop variable to avoid spurious middle-end warnings.
> 
> 2009-04-05  Daniel Franke  <franke.daniel@gmail.com>
> 
> 	PR fortran/29458
> 	* gfortran.dg/implied_do_1.f90: New.



More information about the Fortran mailing list