This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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-dev] SELECT TYPE execution and allocatable scalar components


On Tue, Sep 22, 2009 at 05:45:02PM +0200, Janus Weil wrote:
> > Salvatore, your new ICE is caused by statements like
> >
> > ALLOCATE(x, SOURCE=y)
> >
> > where x and y are CLASS.
> 
> Ok, here is a patch which fixes it. However, I had to modify some code
> that Steve recently committed as r151023, when he implemented the
> SOURCE argument of ALLOCATE.
> 
> Steve, maybe you can have a look at the patch, to check that I don't
> mess anything up (at least the test cases that came with your patch
> still work).
> 
> In particular I moved the code, which does the initialization via the
> SOURCE argument, from gfc_trans_allocate to resolve_allocate_expr. I
> think that makes sense, since also the 'default initialization' is
> done in resolve_allocate_expr, and one surely does not need to do
> both, right?
> 

Janus, I looked over the patch and believe that the
modification to the code is correct. In fact, it may
fix a bug in my implementation.  The following code
gives

troutmask:sgk[203] ./z
42 23 42 23
1 2 1 2
42 4 42 4
42 23 42 23
42 23 42 23
42 23 42 23

where the last 3 lines are incorrect.  The comments in
the code give the expected values.  I don't have the
fortran-dev branch checked out.  Can you see what the
output is for the code below.

-- 
Steve

program a
 
   implicit none

   type b
     integer :: c = 42  ! default initialization
     integer :: d = 23
   end type b

  type(b), allocatable :: z(:)
  type(b) y

  y = b(1, 2)

  allocate(z(2))
  print '(4(I0,1X))', z(1), z(2)  ! 42 23 42 23
  z = y
  print '(4(I0,1X))', z(1), z(2)  !  1  2  1  2
  z = b(d=4)
  print '(4(I0,1X))', z(1), z(2)  ! 42  4 42  4
  deallocate(z)

  allocate(z(2), source = y)
  print '(4(I0,1X))', z(1), z(2)  !  1  2  1  2
  deallocate(z)

  allocate(z(2), source = b(1,2)) !  1  2  1  2
  print '(4(I0,1X))', z(1), z(2)
  deallocate(z)

  allocate(z(2), source = b(d=4)) ! 42  4 42  4
  print '(4(I0,1X))', z(1), z(2)
  deallocate(z)

end program a


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