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] PR 42647: Missed initialization/dealloc of allocatable scalar DT with allocatable component


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.

Attachment: pr42647_v6.diff
Description: Binary data

Attachment: allocatable_scalar_10.f90
Description: Binary data


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