public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement
@ 2015-10-21 20:14 Steve Kargl
  2015-10-21 21:21 ` FX
  2015-10-21 21:21 ` Paul Richard Thomas
  0 siblings, 2 replies; 4+ messages in thread
From: Steve Kargl @ 2015-10-21 20:14 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 438 bytes --]

The attach patch properly sets the length for a zero length string
in a data.  Built and regression tested on x86_64-*-freebsd.  The
testcase is self-explanatory.

OK to commit?


2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* data.c (create_character_initializer): Deal with zero length string.

2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/67939
	* gfortran.dg/pr67939.f90: New test.

-- 
Steve

[-- Attachment #2: pr67939.diff --]
[-- Type: text/x-diff, Size: 2328 bytes --]

Index: gcc/fortran/data.c
===================================================================
--- gcc/fortran/data.c	(revision 229138)
+++ gcc/fortran/data.c	(working copy)
@@ -104,7 +104,7 @@ static gfc_expr *
 create_character_initializer (gfc_expr *init, gfc_typespec *ts,
 			      gfc_ref *ref, gfc_expr *rvalue)
 {
-  int len, start, end;
+  int len, start, end, tlen;
   gfc_char_t *dest;
   bool alloced_init = false;
 	    
@@ -162,12 +162,22 @@ create_character_initializer (gfc_expr *
   else
     len = rvalue->value.character.length;
 
-  if (len > end - start)
+  tlen = end - start;
+  if (len > tlen)
     {
-      gfc_warning_now (0, "Initialization string starting at %L was "
-		       "truncated to fit the variable (%d/%d)",
-		       &rvalue->where, end - start, len);
-      len = end - start;
+      if (tlen < 0)
+	{
+	  gfc_warning_now (0, "Unused initialization string at %L because "
+			   "variable has zero length", &rvalue->where);
+	  len = 0;
+	}
+      else
+	{
+	  gfc_warning_now (0, "Initialization string at %L was truncated to "
+			   "fit the variable (%d/%d)", &rvalue->where,
+			   tlen, len);
+	  len = tlen;
+	}
     }
 
   if (rvalue->ts.type == BT_HOLLERITH)
@@ -181,7 +191,7 @@ create_character_initializer (gfc_expr *
 	    len * sizeof (gfc_char_t));
 
   /* Pad with spaces.  Substrings will already be blanked.  */
-  if (len < end - start && ref == NULL)
+  if (len < tlen && ref == NULL)
     gfc_wide_memset (&dest[start + len], ' ', end - (start + len));
 
   if (rvalue->ts.type == BT_HOLLERITH)
Index: gcc/testsuite/gfortran.dg/pr67939.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr67939.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr67939.f90	(working copy)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+! PR fortran/67939
+! Original code by Gerhard Steinmetz
+! gerhard dot steinmetz dot fortran at t-online dot de
+!
+program p
+   character(100) :: x
+   data x(998:99) /'ab'/   ! { dg-warning "Unused initialization string" }
+   call a
+end
+
+subroutine a
+   character(2) :: x
+   data x(:-1) /'ab'/      ! { dg-warning "Unused initialization string" }
+end subroutine a
+
+subroutine b
+   character(8) :: x
+   data x(3:1) /'abc'/     ! { dg-warning "Unused initialization string" }
+end subroutine b
+

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement
  2015-10-21 20:14 [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement Steve Kargl
@ 2015-10-21 21:21 ` FX
  2015-10-21 21:21 ` Paul Richard Thomas
  1 sibling, 0 replies; 4+ messages in thread
From: FX @ 2015-10-21 21:21 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

> 2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67939
> 	* data.c (create_character_initializer): Deal with zero length string.
> 
> 2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	PR fortran/67939
> 	* gfortran.dg/pr67939.f90: New test.

OK, thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement
  2015-10-21 20:14 [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement Steve Kargl
  2015-10-21 21:21 ` FX
@ 2015-10-21 21:21 ` Paul Richard Thomas
  2015-10-21 21:34   ` Steve Kargl
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Richard Thomas @ 2015-10-21 21:21 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

Hi Steve,

It looks good to me - OK to commit.

Cheers

Paul

PS You, as far as I can tell, are the second most prolific bug fixer
of 2015. The only person that beats you is Mr(or Ms) Unassigned. We
need to sort out who this person is.....

On 21 October 2015 at 22:05, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> The attach patch properly sets the length for a zero length string
> in a data.  Built and regression tested on x86_64-*-freebsd.  The
> testcase is self-explanatory.
>
> OK to commit?
>
>
> 2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/67939
>         * data.c (create_character_initializer): Deal with zero length string.
>
> 2015-10-21  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/67939
>         * gfortran.dg/pr67939.f90: New test.
>
> --
> Steve



-- 
Outside of a dog, a book is a man's best friend. Inside of a dog it's
too dark to read.

Groucho Marx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement
  2015-10-21 21:21 ` Paul Richard Thomas
@ 2015-10-21 21:34   ` Steve Kargl
  0 siblings, 0 replies; 4+ messages in thread
From: Steve Kargl @ 2015-10-21 21:34 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: fortran, gcc-patches

On Wed, Oct 21, 2015 at 11:20:55PM +0200, Paul Richard Thomas wrote:
> 
> It looks good to me - OK to commit.
> 
> Cheers
> 
> Paul
> 
> PS You, as far as I can tell, are the second most prolific bug fixer
> of 2015. The only person that beats you is Mr(or Ms) Unassigned. We
> need to sort out who this person is.....
> 

Well, Gerhard Steinmetz is submitting small self-contained
bugs that appear to be corner cases in the matchers.  Allr
are low hanging fruit.  I leave the hard PR's to people that
know what they are doing. ;-)

-- 
Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-21 21:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21 20:14 [PATCH] PR fortran/67939 -- Fix zero length strings in DATA statement Steve Kargl
2015-10-21 21:21 ` FX
2015-10-21 21:21 ` Paul Richard Thomas
2015-10-21 21:34   ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).