aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/simplify.c
diff options
context:
space:
mode:
authorSteven G. Kargl <kargl@gcc.gnu.org>2019-08-28 20:16:57 +0000
committerSteven G. Kargl <kargl@gcc.gnu.org>2019-08-28 20:16:57 +0000
commit6e12721acde2080202889b3839acca52646b0d28 (patch)
tree24096be9fb03c7794457e06d6309ef46d651d026 /gcc/fortran/simplify.c
parentab0f6d4c5fa6880d5461e2b6bad1879d6a84744f (diff)
downloadgcc-6e12721acde2080202889b3839acca52646b0d28.zip
gcc-6e12721acde2080202889b3839acca52646b0d28.tar.gz
gcc-6e12721acde2080202889b3839acca52646b0d28.tar.bz2
re PR fortran/91565 (ICE in gfc_simplify_reshape, at fortran/simplify.c:6707 etc.)
2019-08-28 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/91565 * simplify.c (gfc_simplify_reshape): Add additional checks of the ORDER dummy argument. 2019-08-28 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/91565 * gfortran.dg/pr91565.f90: New test. From-SVN: r275007
Diffstat (limited to 'gcc/fortran/simplify.c')
-rw-r--r--gcc/fortran/simplify.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 5ab7c81..7fc18d5 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6668,6 +6668,9 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
mpz_init (index);
rank = 0;
+ for (i = 0; i < GFC_MAX_DIMENSIONS; i++)
+ x[i] = 0;
+
for (;;)
{
e = gfc_constructor_lookup_expr (shape_exp->value.constructor, rank);
@@ -6692,8 +6695,28 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
}
else
{
- for (i = 0; i < rank; i++)
- x[i] = 0;
+ mpz_t size;
+ int order_size, shape_size;
+
+ if (order_exp->rank != shape_exp->rank)
+ {
+ gfc_error ("Shapes of ORDER at %L and SHAPE at %L are different",
+ &order_exp->where, &shape_exp->where);
+ return &gfc_bad_expr;
+ }
+
+ gfc_array_size (shape_exp, &size);
+ shape_size = mpz_get_ui (size);
+ mpz_clear (size);
+ gfc_array_size (order_exp, &size);
+ order_size = mpz_get_ui (size);
+ mpz_clear (size);
+ if (order_size != shape_size)
+ {
+ gfc_error ("Sizes of ORDER at %L and SHAPE at %L are different",
+ &order_exp->where, &shape_exp->where);
+ return &gfc_bad_expr;
+ }
for (i = 0; i < rank; i++)
{
@@ -6704,7 +6727,12 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
gcc_assert (order[i] >= 1 && order[i] <= rank);
order[i]--;
- gcc_assert (x[order[i]] == 0);
+ if (x[order[i]] != 0)
+ {
+ gfc_error ("ORDER at %L is not a permutation of the size of "
+ "SHAPE at %L", &order_exp->where, &shape_exp->where);
+ return &gfc_bad_expr;
+ }
x[order[i]] = 1;
}
}