[fortran] Fix PR 81116, missing dependency handling for allocatable character

Message ID b7e86dec-608b-7d41-65cb-a495337bd5f7@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig Aug. 7, 2017, 7:59 p.m.
Hello world,

the attached patch fixes the PR by adding a dependency check
for the case of concatenation operators.

Regression-tested.  OK for trunk?

Regards

	Thomas

2017-08-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/81116
         * frontend-passes.c (realloc_string_callback): If expression is
	a concatenation, also check for dependency.
         (constant_string_length): Check for presence of symtree.

2017-08-07  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/81116
         * gfortran.dg/realloc_on_assignment_29.f90:  New test.

Comments

Thomas Koenig Aug. 13, 2017, 5:35 p.m. | #1
> the attached patch fixes the PR by adding a dependency check
> for the case of concatenation operators.
> 
> Regression-tested.  OK for trunk?

Ping?

Regards

	Thomas
Jerry DeLisle Aug. 16, 2017, 12:58 a.m. | #2
On 08/13/2017 10:35 AM, Thomas Koenig wrote:
> 
>> the attached patch fixes the PR by adding a dependency check
>> for the case of concatenation operators.
>>
>> Regression-tested.  OK for trunk?
> 
> Ping?
> 
> Regards
> 
>      Thomas

OK,

Thanks for patch.

Jerry

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 250720)
+++ frontend-passes.c	(Arbeitskopie)
@@ -238,21 +238,25 @@  realloc_string_callback (gfc_code **c, int *walk_s
     return 0;
 
   expr2 = gfc_discard_nops (co->expr2);
-  if (expr2->expr_type != EXPR_VARIABLE)
-    return 0;
 
-  found_substr = false;
-  for (ref = expr2->ref; ref; ref = ref->next)
+  if (expr2->expr_type == EXPR_VARIABLE)
     {
-      if (ref->type == REF_SUBSTRING)
+      found_substr = false;
+      for (ref = expr2->ref; ref; ref = ref->next)
 	{
-	  found_substr = true;
-	  break;
+	  if (ref->type == REF_SUBSTRING)
+	    {
+	      found_substr = true;
+	      break;
+	    }
 	}
+      if (!found_substr)
+	return 0;
     }
-  if (!found_substr)
+  else if (expr2->expr_type != EXPR_OP
+	   || expr2->value.op.op != INTRINSIC_CONCAT)
     return 0;
-
+  
   if (!gfc_check_dependency (expr1, expr2, true))
     return 0;
 
@@ -625,7 +629,8 @@  constant_string_length (gfc_expr *e)
 
   /* Return length of char symbol, if constant.  */
 
-  if (e->symtree->n.sym->ts.u.cl && e->symtree->n.sym->ts.u.cl->length
+  if (e->symtree && e->symtree->n.sym->ts.u.cl
+      && e->symtree->n.sym->ts.u.cl->length
       && e->symtree->n.sym->ts.u.cl->length->expr_type == EXPR_CONSTANT)
     return gfc_copy_expr (e->symtree->n.sym->ts.u.cl->length);