aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2016-04-09 19:09:02 +0000
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2016-04-09 19:09:02 +0000
commita5edb32e6bf15519852b9cc321aa397ed238efef (patch)
tree1ced5448c700f915d81da68df88da1b2b68dd7ff
parentc532c87139a9410212ab0eff59a4980d28646bfa (diff)
downloadgcc-a5edb32e6bf15519852b9cc321aa397ed238efef.zip
gcc-a5edb32e6bf15519852b9cc321aa397ed238efef.tar.gz
gcc-a5edb32e6bf15519852b9cc321aa397ed238efef.tar.bz2
re PR fortran/68566 (ICE on using unusable array in reshape (double free or corruption))
2016-04-09 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/68566 * array.c (match_array_element_spec): Add check for non-integer. * simplify.c (gfc_simplify_reshape): If source shape is NULL return. PR fortran/68566 * gfortran.dg/pr36192.f90: Update test. * gfortran.dg/pr36192_1.f90: Update test. * gfortran.dg/real_dimension_1.f: Update test. * gfortran.dg/parameter_array_init_7.f90: New test. From-SVN: r234864
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/array.c24
-rw-r--r--gcc/fortran/simplify.c3
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gfortran.dg/parameter_array_init_7.f908
-rw-r--r--gcc/testsuite/gfortran.dg/pr36192.f905
-rw-r--r--gcc/testsuite/gfortran.dg/pr36192_1.f904
-rw-r--r--gcc/testsuite/gfortran.dg/real_dimension_1.f8
8 files changed, 50 insertions, 16 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index c300145..961167b 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2016-04-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR fortran/68566
+ * array.c (match_array_element_spec): Add check for non-integer.
+ * simplify.c (gfc_simplify_reshape): If source shape is NULL return.
+
2016-04-06 Patrick Palka <ppalka@gcc.gnu.org>
PR c/70436
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 2fc9dfa..1430e80 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -421,10 +421,15 @@ 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)
- {
- gfc_error ("Expecting a scalar INTEGER expression at %C");
+ 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, found %s",
+ gfc_basic_typename ((*upper)->ts.type));
return AS_UNKNOWN;
}
@@ -448,10 +453,15 @@ 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");
+ gfc_error ("Expecting a scalar INTEGER expression at %C, found %s",
+ gfc_basic_typename ((*upper)->ts.type));
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/ChangeLog b/gcc/testsuite/ChangeLog
index 3d2537b..9784a4b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2016-04-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR fortran/68566
+ * gfortran.dg/pr36192.f90: Update test.
+ * gfortran.dg/pr36192_1.f90: Update test.
+ * gfortran.dg/real_dimension_1.f: Update test.
+ * gfortran.dg/parameter_array_init_7.f90: New test.
+
2016-04-09 John David Anglin <danglin@gcc.gnu.org>
PR testsuite/64039
diff --git a/gcc/testsuite/gfortran.dg/parameter_array_init_7.f90 b/gcc/testsuite/gfortran.dg/parameter_array_init_7.f90
new file mode 100644
index 0000000..890da35
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parameter_array_init_7.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR68566 ICE on using unusable array in reshape
+program p
+ integer, parameter :: n = 2
+ integer, parameter :: a(:) = 0 !{ dg-error "automatic or of deferred shape" }
+ integer, parameter :: b(n, n) = reshape([a, 1+a], [n, n])
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr36192.f90 b/gcc/testsuite/gfortran.dg/pr36192.f90
index df3bfd7..ebf95e3 100644
--- a/gcc/testsuite/gfortran.dg/pr36192.f90
+++ b/gcc/testsuite/gfortran.dg/pr36192.f90
@@ -3,7 +3,6 @@
!
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 "Expecting a scalar INTEGER" }
+ x(1,:) = (/ 1.0, 0.0 /) ! { dg-error "Unclassifiable" }
end program three_body
-! { dg-prune-output "have constant shape" }
diff --git a/gcc/testsuite/gfortran.dg/pr36192_1.f90 b/gcc/testsuite/gfortran.dg/pr36192_1.f90
index 77df317..687a465 100644
--- a/gcc/testsuite/gfortran.dg/pr36192_1.f90
+++ b/gcc/testsuite/gfortran.dg/pr36192_1.f90
@@ -2,11 +2,11 @@
! PR fortran/36192
program three_body
real, parameter :: n = 2, d = 2
- real, dimension(n,d) :: x_hq ! { dg-error "of INTEGER type|of INTEGER type" }
+ real, dimension(n,d) :: x_hq ! { dg-error "Expecting a scalar INTEGER" }
call step(x_hq)
contains
subroutine step(x)
real, dimension(:,:), intent(in) :: x
end subroutine step
end program three_body
-! { dg-prune-output "must have constant shape" }
+! { dg-prune-output "Rank mismatch in argument" }
diff --git a/gcc/testsuite/gfortran.dg/real_dimension_1.f b/gcc/testsuite/gfortran.dg/real_dimension_1.f
index 73e9131..3dd1a5a 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
+! PR 34305 - Test for specifying a real as dimension
program test
- parameter (datasize = 1000)
- dimension idata (datasize) ! { dg-error "must be of INTEGER type|must have constant shape" }
- idata (1) = -1
+ real , parameter :: dsize = 1000
+ dimension idata (dsize) ! { dg-error "scalar INTEGER expression" }
+ idata (1) = -1 ! { dg-error "must have the pointer attribute" }
end