From patchwork Tue Nov 30 17:03:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix gfortran.dg/realloc_on_assign_2.f03 (was: Re: [Patch, fortran] PR35810 - [TR 15581 / F2003] Automatic reallocation on assignment to allocatable variables) Date: Tue, 30 Nov 2010 07:03:55 -0000 From: Tobias Burnus X-Patchwork-Id: 73634 Message-Id: <4CF52E7B.3010204@net-b.de> To: Paul Richard Thomas Cc: gcc patches , fortran@gcc.gnu.org On 11/30/2010 05:47 PM, Paul Richard Thomas wrote: >> And as "xwrkt =invima (...)" only sets one element, all other elements are >> undefined according to the Fortran standard. But, using SUM, one accesses >> all elements. > Absolutely right - that's the point, isn't it? > Thus, your patch is correct. Committed as Rev. 167305. And to answer my question: For the function result an new array temporary will be malloced - hence the wrong results. Thus, there is an abort with MALLOC_PERTURB_ and thus valgrind shows uninitialized variables. Tobias Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 167304) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-11-30 Tobias Burnus + + * gfortran.dg/realloc_on_assign_2.f03 (invima): Assign + a value to all array elements. + 2010-11-30 Richard Guenther PR tree-optimization/46722 Index: gcc/testsuite/gfortran.dg/realloc_on_assign_2.f03 =================================================================== --- gcc/testsuite/gfortran.dg/realloc_on_assign_2.f03 (revision 167304) +++ gcc/testsuite/gfortran.dg/realloc_on_assign_2.f03 (working copy) @@ -114,6 +114,7 @@ real, dimension (1:m,1:m) :: invima real, dimension (1:m,1:m), intent (in) :: a integer, intent (in) :: j, k + invima = 0.0 invima (j, j) = 1.0 / (1.0 - a (j, j)) end function invima subroutine test6