diff mbox

[Fortran] Fix PR 66041

Message ID 554D348A.2050509@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig May 8, 2015, 10:11 p.m. UTC
Hello world,

this patch fixes the regression in PR 66041, plus one more case
that came up when I looked at this.

OK for trunk?

	Regards, Thomas

2015-05-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/66041
        * frontend-passes.c (scalarized_expr): Clear as->start, as->end
	and as->stride.  Set correct dimension and shape for the
	expression to be passed to lbound.  Free e_in.

2015-05-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

        PR fortran/66041
        * gfortran.dg/inline_matmul_7.f90:  New test.
        * gfortran.dg/inline_matmul_8.f90:  New test.
diff mbox

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 222864)
+++ frontend-passes.c	(Arbeitskopie)
@@ -2611,14 +2611,40 @@  scalarized_expr (gfc_expr *e_in, gfc_expr **index,
 		    {
 		      /* Look at full individual sections, like a(:).  The first index
 			 is the lbound of a full ref.  */
-
+		      int j;
 		      gfc_array_ref *ar;
+		      gfc_expr *lbound_e;
 
-		      ar = gfc_find_array_ref (e_in);
+		      lbound_e = gfc_copy_expr (e_in);
+		      ar = gfc_find_array_ref (lbound_e);
+
 		      ar->type = AR_FULL;
+		      for (j = 0; j < ar->dimen; j++)
+			{
+			  gfc_free_expr (ar->start[j]);
+			  ar->start[j] = NULL;
+			  gfc_free_expr (ar->end[j]);
+			  ar->end[j] = NULL;
+			  gfc_free_expr (ar->stride[j]);
+			  ar->stride[j] = NULL;
+			}
+
+		      /* We have to get rid of the shape, if thre is one.  Do
+			 so by freeing it and calling gfc_resolve to rebuild it,
+			 if necessary.  */
+			 
+		      if (lbound_e->shape)
+			gfc_free_shape (&(lbound_e->shape), lbound_e->rank);
+
+		      lbound_e->rank = ar->dimen;
+			
+		      gfc_resolve_expr (lbound_e);
+		      lbound = get_array_inq_function (GFC_ISYM_LBOUND,
+						       lbound_e, i + 1);
 		    }
-		  lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in,
-						   i_index + 1);
+		  else
+		    lbound = get_array_inq_function (GFC_ISYM_LBOUND, e_in,
+						     i_index + 1);
 		}
 	      
 	      ar->dimen_type[i] = DIMEN_ELEMENT;
@@ -2639,6 +2665,8 @@  scalarized_expr (gfc_expr *e_in, gfc_expr **index,
 	  i_index ++;
 	}
     }
+  gfc_free_expr (e_in);
+
   return e;
 }