[Patch, Fortran] PR 42647: Missed initialization/dealloc of allocatable scalar DT with allocatable component

Janus Weil janus@gcc.gnu.org
Sun Oct 24 11:29:00 GMT 2010


>> I have not yet had a closer look at the patch, but I think you should also
>> take care of the DEALLOCATE statement. Example:
>>
>> type t
>>  integer, allocatable :: p
>> end type t
>> type(t), allocatable :: a
>>
>> deallocate(a)
>> end
>>
>> (Allocate left away to make dump cleaner.) The DEALLOCATE is translated into
>> the following. You see many accesses to "a.p" which cause a segfault if "a"
>> is not allocated - assume
>>
>>      if (a.p != 0B)
>>        {
>>          __builtin_free ((void *) a.p);
>>        }
>>      a.p = 0B;
>>      if (a == 0B)         {
>>          _gfortran_runtime_error_at
>>        }       else         {
>>          __builtin_free ((void *) a);
>>        }
>>      a = 0B;
>>
>> Hmm, I actually could not make the program crash - even though the dump
>> looks wrong.
>
> Yes, you're right. I need to restructure my patch a bit to make it
> work also for DEALLOCATE.

After two unsuccessful attempts to refactor the patch in different
ways, I simply added a new function
'gfc_deallocate_scalar_with_status' to do the job. The attached
version of the patch fixes all of Tobias' test cases I think, plus it
is free of testsuite regressions.

I guess one should at least remove 'gfc_deallocate_scalar' and instead
use the more general 'gfc_deallocate_scalar_with_status' (I'll do that
soon, followed by another regtest).

In the meantime: Any further comments on this patch?

Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr42647_v5.diff
Type: application/octet-stream
Size: 11845 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20101024/1ef7bdfc/attachment.obj>


More information about the Fortran mailing list