[PATCH, gfortran] Fix initialization of arrays of strings
Steve Kargl
sgk@troutmask.apl.washington.edu
Mon Jul 11 02:05:00 GMT 2005
The following fails with a segmentation faults.
module fmvals
integer :: i
character(6) :: namest(0:50) = (/ ('main ' , i = 0, 50) /)
end module
This may be a PR, but I could find one. If this rings
a bell with anyone, please let me know.
2005-07-10 Steven G. Kargl <kargls@comcast.net>
* decl.c (add_init_expr_to_sym): Fix initialization of an array of strings.
--
Steve
-------------- next part --------------
! { dg-do run }
module fmvals
integer :: i
character(6) :: namest(0:50) = (/ ('main ' , i = 0, 50) /)
end module
program a
use fmvals
if (namest(0) .ne. 'main ') call abort
if (namest(1) .ne. 'main ') call abort
end program a
-------------- next part --------------
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/decl.c,v
retrieving revision 1.37
diff -c -p -r1.37 decl.c
*** decl.c 6 Jul 2005 22:12:12 -0000 1.37
--- decl.c 11 Jul 2005 01:47:52 -0000
*************** add_init_expr_to_sym (const char *name,
*** 756,763 ****
gfc_set_constant_character_len (len, init);
else if (init->expr_type == EXPR_ARRAY)
{
! gfc_free_expr (init->ts.cl->length);
init->ts.cl->length = gfc_copy_expr (sym->ts.cl->length);
for (p = init->value.constructor; p; p = p->next)
gfc_set_constant_character_len (len, p->expr);
}
--- 756,771 ----
gfc_set_constant_character_len (len, init);
else if (init->expr_type == EXPR_ARRAY)
{
! if (init->ts.cl == NULL)
! {
! init->ts.cl = gfc_get_charlen ();
! init->ts.cl->length = gfc_copy_expr (sym->ts.cl->length);
! }
! else if (init->ts.cl->length != NULL)
! gfc_free_expr (init->ts.cl->length);
!
init->ts.cl->length = gfc_copy_expr (sym->ts.cl->length);
+
for (p = init->value.constructor; p; p = p->next)
gfc_set_constant_character_len (len, p->expr);
}
More information about the Gcc-patches
mailing list