This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Sun, Apr 05, 2009 at 03:16:58PM +0200, 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:;
>     }

What happens if someone used shadow_loopvar as a variable
in their code?  Do we need to use _shadow_loopvar (note 
the leading underscore)?

> 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.

Can you change the testcase to 

! { dg-do "run" }
! PR fortran/29458 - spurious warning for implied do-loop counter
  
  integer :: n, i
  n = 5
  i = 10
  n = SUM((/(2*i,i=1,n,2)/))
  if (i /= 10) call abort
end

This will test that future code changes doesn't break the
preservation of the value of i.

The code looks ok to me.  Please commit to trunk.

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]