Bug 43532

Summary: Segfault using shape intrinsic function with deferred-shape array
Product: gcc Reporter: PierreC <pchwood>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, tkoenig
Priority: P3 Keywords: wrong-code
Version: 4.4.1   
Target Milestone: ---   
Host: x86_64 Target:
Build: Known to work:
Known to fail: 4.1.2, 4.2.1, 4.3.4, 4.4.4, 4.5.0 Last reconfirmed: 2010-03-27 17:59:38
Bug Depends on:    
Bug Blocks: 32834    

Description PierreC 2010-03-26 11:22:49 UTC
Reported and confirmed in the fortran mailing list.
test case, trimmed down by Janus:

   implicit none

   type myobj
      real :: myarray(10)
   end type myobj

   real        :: array(10)
   type(myobj) :: obj

   call myfunc(obj,array)

contains

   subroutine myfunc(this, array)
      type(myobj) :: this
      real        :: array(:)
      write (*,*) 'shape bound', shape(this%myarray)
      write (*,*) 'shape input', shape(array)
      write (*,*) shape(array) /= shape(this%myarray) ! SEGFAULT
   end subroutine myfunc

end
Comment 1 Paul Thomas 2010-03-27 17:59:38 UTC
With the function calls interchanged, the problem goes away. ie. with:

write (*,*) shape(this%myarray) /= shape(array) ! SEGFAULT

I can't see from the code yet why this is happening but can confirm the bug.

Paul
Comment 2 Tobias Burnus 2010-03-28 21:19:03 UTC
Valgrind shows:

==4509== Conditional jump or move depends on uninitialised value(s)
==4509==    at 0x4EB51A3: _gfortran_shape_4 (shape_i4.c:47)
==4509==    by 0x40091E: myfunc.1553 (hjfdf.f90:19)
==4509==    by 0x400A87: MAIN__ (hjfdf.f90:10)
==4509==    by 0x400AC2: main (hjfdf.f90:10)
==4509== 
==4509== Use of uninitialised value of size 8
==4509==    at 0x4EB51E2: _gfortran_shape_4 (shape_i4.c:53)
==4509==    by 0x40091E: myfunc.1553 (hjfdf.f90:19)
==4509==    by 0x400A87: MAIN__ (hjfdf.f90:10)
==4509==    by 0x400AC2: main (hjfdf.f90:10)
==4509== 
==4509== Invalid write of size 4
==4509==    at 0x4EB51E2: _gfortran_shape_4 (shape_i4.c:53)
==4509==    by 0x40091E: myfunc.1553 (hjfdf.f90:19)
==4509==    by 0x400A87: MAIN__ (hjfdf.f90:10)
==4509==    by 0x400AC2: main (hjfdf.f90:10)
==4509==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
Comment 3 Thomas Koenig 2010-10-23 10:05:48 UTC
This went away, probably with the commit for PR 46007.

Closing.