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

Janus Weil janus@gcc.gnu.org
Mon Oct 25 15:22:00 GMT 2010


2010/10/23 Janus Weil <janus@gcc.gnu.org>:
>>> 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).

The attached version of the patch does this and is regression-free. Ok
for trunk?

Cheers,
Janus


2010-10-25  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42647
	* trans.h (gfc_deallocate_scalar_with_status): New prototype.
	* trans.c (gfc_deallocate_scalar_with_status): New function for
	deallocation of allocatable scalars.
	* trans-decl.c (gfc_trans_deferred_vars): Call it here ...
	* trans-array.c (structure_alloc_comps): ... and here.

2010-10-25  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42647
	* gfortran.dg/allocatable_scalar_9.f90: Extended.
	* gfortran.dg/allocatable_scalar_10.f90: New.
	* gfortran.dg/class_19.f03: Extended.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr42647_v6.diff
Type: application/octet-stream
Size: 10638 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20101025/75950850/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: allocatable_scalar_10.f90
Type: application/octet-stream
Size: 298 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20101025/75950850/attachment-0001.obj>


More information about the Gcc-patches mailing list