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] PR24311 - MERGE with character arguments causingICE in IO statements.


:ADDPATCH fortran:

This problem was caused by a patch to trans-io.c(gfc_trans_transfer), which changed from transferring arrays element by element to passing the array descriptor to the library. This failed because gfc_conv_expr_descriptor was unable to handle the unusual(unique?) phenomenon of a character array that has no charlen in the typespec. This has been fixed by the direct method of writing a charlen in iresolve.c(gfc_resolve_merge). This seems like the right place to do this, on the grounds that, no matter what, the output from MERGE will be correctly loaded with a character length.

Bubblestrapped and regtested on FC3/i686. OK for mainline and 4.0?

Paul T
2005-10-11  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24311
	* iresolve.c (gfc_resolve_merge): Deal with the first two
	arguments of merge being character constants by transferring
	the character length to the output typespec.

2005-10-11  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/24311
	gfortran.dg/merge_char_2.f90: New test.


Index: gcc/gcc/fortran/iresolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/iresolve.c,v
retrieving revision 1.41
diff -c -p -r1.41 iresolve.c
*** gcc/gcc/fortran/iresolve.c	3 Oct 2005 07:22:18 -0000	1.41
--- gcc/gcc/fortran/iresolve.c	11 Oct 2005 22:46:10 -0000
*************** gfc_resolve_merge (gfc_expr * f, gfc_exp
*** 979,984 ****
--- 979,997 ----
  		   gfc_expr * fsource ATTRIBUTE_UNUSED,
  		   gfc_expr * mask ATTRIBUTE_UNUSED)
  {
+   /* Merge is unusual in that tsource can be a character constant, whose typespec
+      is transferred to that of the output array.  This will not have had a charlen
+      created, so it is done here to prevent the middle-end being hit by an
+      apparently incomplete character array(PR24311).  */
+   if (tsource->expr_type == EXPR_CONSTANT
+ 	&& tsource->ts.type == BT_CHARACTER
+ 	&& tsource->ts.cl == NULL)
+     {
+       tsource->ts.cl = gfc_get_charlen ();
+       tsource->ts.cl->next = gfc_current_ns->cl_list;
+       gfc_current_ns->cl_list = tsource->ts.cl;
+       tsource->ts.cl->length = gfc_int_expr (tsource->value.character.length);
+     }
    f->ts = tsource->ts;
    f->value.function.name =
      gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),

------------------merge_char_2.f90------------------------

! { dg-do run }
! { dg-options "-O0" }
! This tests the patch for PR24311 in which the PRINT statement would
! ICE on trying to print a MERGE statement with character constants
! for the first two arguments.
!
! Contributed by Paul Thomas <pault@gcc.gnu.org>
!
  integer, dimension(6) :: i = (/1,0,0,1,1,0/)
  print '(6a1)', Merge ("a", "b", i  == 1) ! { dg-output "abbaab" }
  end



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