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


>> 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

Attachment: pr42647_v5.diff
Description: Binary data


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