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, gfortran] Fix initialization of arrays of strings


Committed to mainline and 4.0.2. A new patch is attached. Approved by Steve
Kargl off the list.

Steve, I changed the patch mailed to you a little.

--- Steve Kargl <sgk@troutmask.apl.washington.edu>写道:

> On Tue, Jul 12, 2005 at 08:32:48AM +0800, Feng Wang wrote:
> > 
> > All the 'main  ' memory is allocated during gfc_set_constant_character_len
> > call. I mean that resolve_character_array_constructor does not call
> > gfc_get_charlen to set ts.cl if the constractor's expr is not of
> EXPR_CONSTANT
> > (a(2)). This cause an ICE when invoking gfc_free_expr (init->ts.cl->length)
> in
> > add_init_expr_to_sym. The memory I said is the memory of (gfc_charlen).
> > 
> 
> Is the attached patch acceptable to you?
> 


Best Regards,
Feng Wang

--
Creative Compiler Research Group,
National University of Defense Technology, China.


	

	
		
___________________________________________________________ 
雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱
http://cn.mail.yahoo.com/?id=77071
Index: testsuite/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ChangeLog,v
retrieving revision 1.5765
diff -c -3 -p -r1.5765 ChangeLog
*** testsuite/ChangeLog	13 Jul 2005 19:25:53 -0000	1.5765
--- testsuite/ChangeLog	14 Jul 2005 01:21:42 -0000
***************
*** 1,3 ****
--- 1,7 ----
+ 2005-07-14  Steven G. Kargl  <kargls@comcast.net>
+ 
+ 	* gfortran.dg/char_array_constructor.f90: New test.
+ 
  2005-07-13  Paul Thomas  <pault@gcc.gnu.org>
  
  	* gfortran.dg/past_eor.f90: New.
Index: testsuite/gfortran.dg/char_array_constructor.f90
===================================================================
RCS file: testsuite/gfortran.dg/char_array_constructor.f90
diff -N testsuite/gfortran.dg/char_array_constructor.f90
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gfortran.dg/char_array_constructor.f90	14 Jul 2005 01:21:42 -0000
***************
*** 0 ****
--- 1,15 ----
+ ! { dg-do run }
+ module z
+    integer :: i
+    character(6) :: a(2) = (/ ('main  ' , i = 1, 2) /)
+    character(6) :: b(2) = (/ 'abcd  ' , 'efghij' /)
+ end module
+ 
+ program y
+   use z
+   if (a(1) /= 'main  ') call abort
+   if (a(2) /= 'main  ') call abort
+   if (b(1) /= 'abcd  ') call abort
+   if (b(2) /= 'efghij') call abort
+ end program y
+ 
Index: fortran/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/ChangeLog,v
retrieving revision 1.493
diff -c -3 -p -r1.493 ChangeLog
*** fortran/ChangeLog	13 Jul 2005 13:33:31 -0000	1.493
--- fortran/ChangeLog	14 Jul 2005 01:21:53 -0000
***************
*** 1,3 ****
--- 1,9 ----
+ 2005-07-14  Feng Wang  <fengwang@nudt.edu.cn>
+ 	Steven G. Kargl  <kargls@comcast.net>
+ 
+ 	* array.c (resolve_character_array_constructor): Allocate gfc_charlen
+ 	for the array and attach to namespace list for automatic deallocation.
+ 
  2005-07-13  Andreas Schwab  <schwab@suse.de>
  
  	* Make-lang.in (fortran/dependency.o): Depend on
Index: fortran/array.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/array.c,v
retrieving revision 1.17
diff -c -3 -p -r1.17 array.c
*** fortran/array.c	25 Jun 2005 00:40:33 -0000	1.17
--- fortran/array.c	14 Jul 2005 01:21:55 -0000
*************** resolve_character_array_constructor (gfc
*** 1529,1535 ****
  
    max_length = -1;
  
!   if (expr->ts.cl == NULL || expr->ts.cl->length == NULL)
      {
        /* Find the maximum length of the elements. Do nothing for variable array
  	 constructor.  */
--- 1529,1542 ----
  
    max_length = -1;
  
!   if (expr->ts.cl == NULL)
!     {
!       expr->ts.cl = gfc_get_charlen ();
!       expr->ts.cl->next = gfc_current_ns->cl_list;
!       gfc_current_ns->cl_list = expr->ts.cl;
!     }
! 
!   if (expr->ts.cl->length == NULL)
      {
        /* Find the maximum length of the elements. Do nothing for variable array
  	 constructor.  */
*************** resolve_character_array_constructor (gfc
*** 1542,1549 ****
        if (max_length != -1)
  	{
  	  /* Update the character length of the array constructor.  */
- 	  if (expr->ts.cl == NULL)
- 	    expr->ts.cl = gfc_get_charlen ();
  	  expr->ts.cl->length = gfc_int_expr (max_length);
  	  /* Update the element constructors.  */
  	  for (p = expr->value.constructor; p; p = p->next)
--- 1549,1554 ----

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