diff mbox

[fortran] Fix PR 34145, single char detection

Message ID 1283679909.1254.8.camel@linux-fd1f.site
State New
Headers show

Commit Message

Thomas Koenig Sept. 5, 2010, 9:45 a.m. UTC
Hello world,

the attached patch fixes PR 34145, where we failed to detect that a
string was in fact a single character.

Regression-tested.

OK for trunk?

	Thomas

2010-09-05  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/34145
	* trans-expr.c (gfc_conv_substring):  If start and end
	of the string reference are equal, set the length to one.

2010-09-05  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/34145
	* char_length_17.f90:  New test.

Comments

Thomas Koenig Sept. 6, 2010, 7:04 p.m. UTC | #1
Am Sonntag, den 05.09.2010, 11:45 +0200 schrieb Thomas Koenig:
> Hello world,
> 
> the attached patch fixes PR 34145, where we failed to detect that a
> string was in fact a single character.


ping**0.25?

	Thomas
Mikael Morin Sept. 6, 2010, 7:32 p.m. UTC | #2
Le 06.09.2010 21:04, Thomas Koenig a écrit :
>
> Am Sonntag, den 05.09.2010, 11:45 +0200 schrieb Thomas Koenig:
>> Hello world,
>>
>> the attached patch fixes PR 34145, where we failed to detect that a
>> string was in fact a single character.
>
>
> ping**0.25?
>
> 	Thomas
>
>
I OKed it already, but it seems that I forgot to CC the mailing lists.
OK again.

Mikael.
Thomas Koenig Sept. 6, 2010, 7:48 p.m. UTC | #3
Hello Mikael,
> Le 06.09.2010 21:04, Thomas Koenig a écrit :
> >
> > Am Sonntag, den 05.09.2010, 11:45 +0200 schrieb Thomas Koenig:
> >> Hello world,
> >>
> >> the attached patch fixes PR 34145, where we failed to detect that a
> >> string was in fact a single character.
> >
> >
> > ping**0.25?
> >
> > 	Thomas
> >
> >
> I OKed it already, but it seems that I forgot to CC the mailing lists.
> OK again.

Sende          fortran/ChangeLog
Sende          fortran/trans-expr.c
Sende          testsuite/ChangeLog
Hinzufügen     testsuite/gfortran.dg/char_length_17.f90
Übertrage Daten ....
Revision 163932 übertragen.

Thanks a lot! It seems I missed your original OK in my inbox.

I'm looking at your transpose patch right now, which survived the
testing I gave it so far.

	Thomas
diff mbox

Patch

Index: trans-expr.c
===================================================================
--- trans-expr.c	(Revision 163868)
+++ trans-expr.c	(Arbeitskopie)
@@ -463,12 +463,20 @@  gfc_conv_substring (gfc_se * se, gfc_ref * ref, in
       gfc_free (msg);
     }
 
-  tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node,
-			 end.expr, start.expr);
-  tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node,
-			 build_int_cst (gfc_charlen_type_node, 1), tmp);
-  tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node, tmp,
-			 build_int_cst (gfc_charlen_type_node, 0));
+  /* If the start and end expressions are equal, the length is one.  */
+  if (ref->u.ss.end
+      && gfc_dep_compare_expr (ref->u.ss.start, ref->u.ss.end) == 0)
+    tmp = build_int_cst (gfc_charlen_type_node, 1);
+  else
+    {
+      tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node,
+			     end.expr, start.expr);
+      tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node,
+			     build_int_cst (gfc_charlen_type_node, 1), tmp);
+      tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node,
+			     tmp, build_int_cst (gfc_charlen_type_node, 0));
+    }
+
   se->string_length = tmp;
 }