[Patch, fortran-dev] SELECT TYPE execution and allocatable scalar components
Janus Weil
janus@gcc.gnu.org
Wed Sep 23 21:12:00 GMT 2009
2009/9/23 Steve Kargl <sgk@troutmask.apl.washington.edu>:
> 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.
Actually I have made some more modifications to the patch already, but
currently it gives the following output for your program
42 23 42 23
1 2 1 2
42 4 42 4
1 2 1 2
1 2 1 2
42 4 42 4
which matches the comments in your code, so I guess it works :)
Thanks for looking at the patch. I guess the bug was that both the
default initializer *and* the SOURCE expression were being used for
initialization, the default initializer coming last, and thereby
effectively determining the value. Right?
Cheers,
Janus
> 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
>
More information about the Fortran
mailing list