Patchwork [Fortran] PR51448 [4.6/4.7] Fix realloc with RHS conversion function

login
register
mail settings
Submitter Tobias Burnus
Date Dec. 7, 2011, 4:45 p.m.
Message ID <4EDF9840.8020204@net-b.de>
Download mbox | patch
Permalink /patch/129989/
State New
Headers show

Comments

Tobias Burnus - Dec. 7, 2011, 4:45 p.m.
This fixes a -frealloc-lhs regression where the RHS is handled by a 
"conversion function" whose argument has component refs.

Build and regtested on x86-64-linux.
OK for the trunk and 4.7?

Tobias
Mikael Morin - Dec. 7, 2011, 7:45 p.m.
On Wednesday 07 December 2011 17:45:52 Tobias Burnus wrote:
> This fixes a -frealloc-lhs regression where the RHS is handled by a
> "conversion function" whose argument has component refs.
> 
> Build and regtested on x86-64-linux.
> OK for the trunk and 4.7?
> 
> Tobias
OK.

Mikael

Patch

2011-12-07  Tobias Burnus  <burnus@net-b.de>

	PR fortran/51448
	* fortran/trans-array.c (get_std_lbound): Fix handling of
	conversion functions.

2011-12-07  Tobias Burnus  <burnus@net-b.de>

	PR fortran/51448
	* gfortran.dg/realloc_on_assign_8.f90: New.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index ee8f896..2fd5749 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7428,7 +7584,16 @@  get_std_lbound (gfc_expr *expr, tree desc, int dim, bool assumed_size)
 			      gfc_array_index_type, cond,
 			      lbound, gfc_index_one_node);
     }
-  else if (expr->expr_type == EXPR_VARIABLE)
+
+  if (expr->expr_type == EXPR_FUNCTION)
+    {
+      /* A conversion function, so use the argument.  */
+      gcc_assert (expr->value.function.isym
+		  && expr->value.function.isym->conversion);
+      expr = expr->value.function.actual->expr;
+    }
+
+  if (expr->expr_type == EXPR_VARIABLE)
     {
       tmp = TREE_TYPE (expr->symtree->n.sym->backend_decl);
       for (ref = expr->ref; ref; ref = ref->next)
@@ -7441,15 +7606,6 @@  get_std_lbound (gfc_expr *expr, tree desc, int dim, bool assumed_size)
 	}
       return GFC_TYPE_ARRAY_LBOUND(tmp, dim);
     }
-  else if (expr->expr_type == EXPR_FUNCTION)
-    {
-      /* A conversion function, so use the argument.  */
-      expr = expr->value.function.actual->expr;
-      if (expr->expr_type != EXPR_VARIABLE)
-	return gfc_index_one_node;
-      desc = TREE_TYPE (expr->symtree->n.sym->backend_decl);
-      return get_std_lbound (expr, desc, dim, assumed_size);
-    }
 
   return gfc_index_one_node;
 }
--- /dev/null	2011-12-07 07:00:28.727532040 +0100
+++ gcc/gcc/testsuite/gfortran.dg/realloc_on_assign_8.f90	2011-12-07 16:34:46.000000000 +0100
@@ -0,0 +1,17 @@ 
+! { dg-do compile }
+!
+! PR fortran/51448
+!
+! Contribued by Fran├žois Willot
+!
+  PROGRAM MAIN
+  IMPLICIT NONE
+  TYPE mytype
+    REAL b(2)
+  END TYPE mytype
+  TYPE(mytype) a
+  DOUBLE PRECISION, ALLOCATABLE :: x(:)
+  ALLOCATE(x(2))
+  a%b=0.0E0
+  x=a%b
+  END