This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [PATCH, gfortran] Fix initialization of arrays of strings
On Tue, Jul 12, 2005 at 01:13:52AM +0800, Feng Wang wrote:
> --- Steve Kargl <sgk@troutmask.apl.washington.edu>????:
>
>> On Mon, Jul 11, 2005 at 02:40:01PM +0800, Feng Wang wrote:
>>> I think we should fix this in array.c
>>> (resolve_character_array_constructor).
>>> This is earlier than add_init_expr_to_sym. And we should also add
>>> it to the gfc_current_ns->cl_list to void memory leak. The list
>>> will be deallocated with the namespace.
>>>
>>
>> I don't understand what you want to do. I just watched the
>> compiler go through resolve_character_array_constructor
>> and gfc_set_constant_character_len and it appears to do want
>
> Yes, it go through resolve_character_array_constructor.
> 1. I think it is resolve_character_array_constructor that does
> not allocate character length struct compiling this test and
> cause ICE in add_init_expr_to_sym.
module z
integer :: i
character(6) :: a(2) = (/ ('main ' , i = 1, 2) /) ! ICE.
character(6) :: b(2) = (/ 'abcd ' , 'efghij' /) ! Compiles fine.
end module
In the case of b(2), everthing works as expected. That is, memory is
allocated during the resolve_character_array_constructor call. In the
a(2) case we get an ICE because the implied-do-loop is not expanded
in resolve_character_array_constructor, only memory for 1 copy of
'main ' is allocated. The implied-do-loop is expanded in
add_init_expr_to_sym and additional memory is allocated to propagate
a copy of 'main ' to all elements of a(2).
> 2. When invoking gfc_get_charlen, we should add its result to
> gfc_current_ns->cl_list. In the gfc_get_charlen, we get some
> memory. Add it to the list, it will be freed when its namespace
> is deallocated.
This is not important for my patch and this ICE. Shouldn't gfc_get_charlen
add its result to gfc_current_ns->cl_list instead of the calling routine?
--
Steve