diff mbox series

[fortran] Fix PR 88871

Message ID 61631d6c-bf99-b4c9-227d-45a254a2d007@netcologne.de
State New
Headers show
Series [fortran] Fix PR 88871 | expand

Commit Message

Thomas Koenig Jan. 17, 2019, 6:30 a.m. UTC
Hello world,

the attached patch fixes PR 88871, a regression introduced by
my recent patch for removing unnecessary substrings.

Regression-tested; this now also works with valgrind on Linux,
where the failure did not show up otherwise.

No test case because, well - it did show up on a few systems, so we will
notice if it regresses. OK for trunk?

Regards

	Thomas

2019-01-17  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/88871
	* resolve.c (resolve_ref):  Fix logic for removal of
	reference.

Comments

Thomas Koenig Jan. 18, 2019, 5:09 p.m. UTC | #1
Am 17.01.19 um 07:30 schrieb Thomas Koenig:
> 
> No test case because, well - it did show up on a few systems, so we will
> notice if it regresses. OK for trunk?

Both Dominique and Jürgen confirmed that it fixes the PR.

I will commit this tomorrow unless there are any objections - I'd
like to get this out of the way.

Regards

	Thomas
Jakub Jelinek Jan. 18, 2019, 9:50 p.m. UTC | #2
Hi!

On Thu, Jan 17, 2019 at 07:30:34AM +0100, Thomas Koenig wrote:
> 2019-01-17  Thomas Koenig  <tkoenig@gcc.gnu.org>
> 
> 	PR fortran/88871
> 	* resolve.c (resolve_ref):  Fix logic for removal of
> 	reference.

Just a few ChangeLog formatting nits of what I've seen recently from
multiple people, there should be exactly one space after ):, not two,
and there should be no space between ) and :, or, if there is just
filename, between filename and :, so
	* filename.whatever : New test.
is not correct and it should be
	* filename.whatever: New test.
Similarly:
	* filename.whatever : External declarations for foo and blah.
etc. should be
	* filename.whatever (foo, blah): Declare.
or similar.

Thanks.

	Jakub
diff mbox series

Patch

Index: resolve.c
===================================================================
--- resolve.c	(Revision 267953)
+++ resolve.c	(Arbeitskopie)
@@ -5046,6 +5046,7 @@  resolve_ref (gfc_expr *expr)
   int current_part_dimension, n_components, seen_part_dimension;
   gfc_ref *ref, **prev;
   bool equal_length;
+  bool breakout;
 
   for (ref = expr->ref; ref; ref = ref->next)
     if (ref->type == REF_ARRAY && ref->u.ar.as == NULL)
@@ -5054,12 +5055,12 @@  resolve_ref (gfc_expr *expr)
 	break;
       }
 
-  
-  for (ref = expr->ref, prev = &expr->ref; ref; prev = &ref->next, ref = ref->next)
-    switch (ref->type)
+  breakout = false;
+  for (prev = &expr->ref; !breakout && *prev != NULL; prev = &(*prev)->next)
+    switch ((*prev)->type)
       {
       case REF_ARRAY:
-	if (!resolve_array_ref (&ref->u.ar))
+	if (!resolve_array_ref (&(*prev)->u.ar))
 	  return false;
 	break;
 
@@ -5069,17 +5070,20 @@  resolve_ref (gfc_expr *expr)
 
       case REF_SUBSTRING:
 	equal_length = false;
-	if (!resolve_substring (ref, &equal_length))
+	if (!resolve_substring (*prev, &equal_length))
 	  return false;
 
 	if (expr->expr_type != EXPR_SUBSTRING && equal_length)
 	  {
 	    /* Remove the reference and move the charlen, if any.  */
+	    ref = *prev;
 	    *prev = ref->next;
 	    ref->next = NULL;
 	    expr->ts.u.cl = ref->u.ss.length;
 	    ref->u.ss.length = NULL;
 	    gfc_free_ref_list (ref);
+	    if (*prev == NULL)
+	      breakout = true;
 	  }
 	break;
       }