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]

[Patch, fortran] PR24789 - ICE when assigning to array of strings


:ADDPATCH fortran:

Just after committing the patch for PR15809 to trunk, I was cleaning up the Bugzilla entries and came across PR24789. It was immediately obvious that I had put the patch in the wrong place! A previous, developmental version of the patch added the size in gfc_conv_variable, where it fixed the above bug as well as PR15809. I forgot to check that the new location did likewise. It is fixed by moving the part of the patch in trans-decl.c a few lines down, so that it picks up all character, pointer arrays and checks that the TYPE_SIZE_UNIT is set.

I will commit this and the testcase to trunk tomorrow morning, under the"blindingly obvious" rule, unless there are any objections.

Bootstrapped and regtested under FC3. It is OK for trunk and I will add a further 24 hours for the composite patch to 4.0 and 4.1.

Paul
2005-12-01  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24789
	* trans-decl.c (gfc_get_symbol_decl):  Move the expression for
	unit size of automatic character length, dummy pointer array
	elements down a few lines from the version that fixed PR15809.

2005-12-01  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24789
	*  gfortran.dg/auto_char_dummy_array_2.f90: New test.


Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c	(revision 107727)
--- gcc/fortran/trans-decl.c	(working copy)
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 847,871 ****
  	      if (TREE_CODE (length) != INTEGER_CST)
  		{
  		  gfc_finish_var_decl (length, sym);
- 
- 		  /* Set the element size of automatic character length
- 		     length, dummy, pointer arrays.  */
- 		  if (sym->attr.pointer && sym->attr.dummy
- 			&& sym->attr.dimension)
- 		    {
- 		      tmp = gfc_build_indirect_ref (sym->backend_decl);
- 		      etype = gfc_get_element_type (TREE_TYPE (tmp));
- 		      if (TYPE_SIZE_UNIT (etype) == NULL_TREE)
- 			{
- 			  tmp = TYPE_SIZE_UNIT (gfc_character1_type_node);
- 			  tmp = fold_convert (TREE_TYPE (tmp), length);
- 			  TYPE_SIZE_UNIT (etype) = tmp;
- 			}
- 		    }
- 
  		  gfc_defer_symbol_init (sym);
  		}
  	    }
  	}
  
        /* Use a copy of the descriptor for dummy arrays.  */
--- 847,870 ----
  	      if (TREE_CODE (length) != INTEGER_CST)
  		{
  		  gfc_finish_var_decl (length, sym);
  		  gfc_defer_symbol_init (sym);
  		}
  	    }
+ 
+ 	  /* Set the element size of automatic and assumed character length
+ 	     length, dummy, pointer arrays.  */
+ 	  if (sym->attr.pointer && sym->attr.dummy
+ 		&& sym->attr.dimension)
+ 	    {
+ 	      tmp = gfc_build_indirect_ref (sym->backend_decl);
+ 	      etype = gfc_get_element_type (TREE_TYPE (tmp));
+ 	      if (TYPE_SIZE_UNIT (etype) == NULL_TREE)
+ 		{
+ 		  tmp = TYPE_SIZE_UNIT (gfc_character1_type_node);
+ 		  tmp = fold_convert (TREE_TYPE (tmp), sym->ts.cl->backend_decl);
+ 		  TYPE_SIZE_UNIT (etype) = tmp;
+ 		}
+ 	    }
  	}
  
        /* Use a copy of the descriptor for dummy arrays.  */


===============auto_char_dummy_array_2.f90======================

! { dg-do compile }
! Test fix for pr24789 - would segfault on the assignment
! because the array descriptor size was not set.
!
! This is the example submitted by Martin Reineke  <martin@mpa-garching.mpg.de>

subroutine foo(vals)
  character(len = *), pointer :: vals(:)
  vals = ''
end subroutine



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