Patchwork Fix gfortran.dg/realloc_on_assign_2.f03 (was: Re: [Patch, fortran] PR35810 - [TR 15581 / F2003] Automatic reallocation on assignment to allocatable variables)

login
register
mail settings
Submitter Tobias Burnus
Date Nov. 30, 2010, 5:03 p.m.
Message ID <4CF52E7B.3010204@net-b.de>
Download mbox | patch
Permalink /patch/73634/
State New
Headers show

Comments

Tobias Burnus - Nov. 30, 2010, 5:03 p.m.
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
Paul Richard Thomas - Nov. 30, 2010, 9:23 p.m.
Tobias,

Thanks for the patch... and indeed for analysing the problem.

Cheers

Paul

On Tue, Nov 30, 2010 at 6:03 PM, Tobias Burnus <burnus@net-b.de> wrote:
> 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
>

Patch

Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 167304)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@ 
+2010-11-30  Tobias Burnus  <burnus@net-b.de>
+
+	* gfortran.dg/realloc_on_assign_2.f03 (invima): Assign
+	a value to all array elements.
+
 2010-11-30  Richard Guenther  <rguenther@suse.de>
 
 	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