This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR68566 ICE on using unusable array in reshape


This problem is when array indexes are given that have non-integer expressions
or otherwise bad arrays, not just related to reshape.

There are several test cases presented in the PR.  Most of these are fixed by
adding a check for any non-integer in match_array_element_spec.  The patch-let
in gfc_simplify_reshape avoids passing a NULL shape further into simplification.

I will add an additional test case for the original posted problem in the PR.
Two existing tests get exercised, changing the error message.  Finding the
problems earlier in the matchers I think is the right way to go. I am curious if
the old checks ever get triggered (I will look into that a little later.

Regression tested on x86-64-linux.  OK for trunk?


2016-04-02  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/68566
	* array.c (match_array_element_spec): Add check for non-integer dimension given.
	* simplify.c (gfc_simplify_reshape): If source shape is NULL return.
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 2fc9dfa..57bdf7e 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -421,8 +421,12 @@ match_array_element_spec (gfc_array_spec *as)
   if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
     return AS_UNKNOWN;
 
-  if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN
-      && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0)
+  if (((*upper)->expr_type == EXPR_CONSTANT
+	&& (*upper)->ts.type != BT_INTEGER) ||
+      ((*upper)->expr_type == EXPR_FUNCTION
+	&& (*upper)->ts.type == BT_UNKNOWN
+	&& (*upper)->symtree
+	&& strcmp ((*upper)->symtree->name, "null") == 0))
     {
       gfc_error ("Expecting a scalar INTEGER expression at %C");
       return AS_UNKNOWN;
@@ -448,8 +452,12 @@ match_array_element_spec (gfc_array_spec *as)
   if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
     return AS_UNKNOWN;
 
-  if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN
-      && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0)
+  if (((*upper)->expr_type == EXPR_CONSTANT
+	&& (*upper)->ts.type != BT_INTEGER) ||
+      ((*upper)->expr_type == EXPR_FUNCTION
+	&& (*upper)->ts.type == BT_UNKNOWN
+	&& (*upper)->symtree
+	&& strcmp ((*upper)->symtree->name, "null") == 0))
     {
       gfc_error ("Expecting a scalar INTEGER expression at %C");
       return AS_UNKNOWN;
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 12a8f32..a631010 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -5163,6 +5163,9 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
       || !is_constant_array_expr (order_exp))
     return NULL;
 
+  if (source->shape == NULL)
+    return NULL;
+
   /* Proceed with simplification, unpacking the array.  */
 
   mpz_init (index);
diff --git a/gcc/testsuite/gfortran.dg/pr36192.f90 b/gcc/testsuite/gfortran.dg/pr36192.f90
index df3bfd7..d8b48f2 100644
--- a/gcc/testsuite/gfortran.dg/pr36192.f90
+++ b/gcc/testsuite/gfortran.dg/pr36192.f90
@@ -3,7 +3,7 @@
 !
 program three_body
   real, parameter :: n = 2, d = 2
-  real, dimension(n,d) :: x      ! { dg-error "of INTEGER type|of INTEGER type" }
-  x(1,:) = (/ 1.0, 0.0 /)
+  real, dimension(n,d) :: x      ! { dg-error "scalar INTEGER expression" }
+  x(1,:) = (/ 1.0, 0.0 /)        ! { dg-error "Unclassifiable statement" }
 end program three_body
-! { dg-prune-output "have constant shape" }
+
diff --git a/gcc/testsuite/gfortran.dg/real_dimension_1.f b/gcc/testsuite/gfortran.dg/real_dimension_1.f
index 73e9131..5fd200a 100644
--- a/gcc/testsuite/gfortran.dg/real_dimension_1.f
+++ b/gcc/testsuite/gfortran.dg/real_dimension_1.f
@@ -1,7 +1,7 @@
 ! { dg-do compile }
 ! PR 34305 - make sure there's an error message for specifying a
       program test
-      parameter (datasize = 1000) 
-      dimension idata (datasize)  ! { dg-error "must be of INTEGER type|must have constant shape" }
-      idata (1) = -1
+      parameter (datasize = 1000) ! Note that datasize is defualt type real
+      dimension idata (datasize)  ! { dg-error "Expecting a scalar INTEGER expression" }
       end
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]