From 57e596204fceef2e9196c76f0cb102e4fd66646d Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sat, 7 Nov 2015 20:18:17 +0000 Subject: [PATCH] re PR fortran/68153 (ICE for intrinsic reshape with negative dim in effective shape) 2015-11-07 Steven G. Kargl PR fortran/68153 * check.c (gfc_check_reshape): Improve check for valid SHAPE argument. 2015-11-07 Steven G. Kargl PR fortran/68153 * gfortran.dg/pr68153.f90: New test. From-SVN: r229939 --- gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/check.c | 30 +++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr68153.f90 | 9 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr68153.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 15583d9848b..fc3afba3aaf 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2015-11-07 Steven G. Kargl + + PR fortran/68153 + * check.c (gfc_check_reshape): Improve check for valid SHAPE argument. + 2015-11-07 Steven G. Kargl PR fortran/68151 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 6548a017f44..86dae5b000c 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -3711,6 +3711,36 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape, } } } + else if (shape->expr_type == EXPR_VARIABLE && shape->ref + && shape->ref->u.ar.type == AR_FULL && shape->ref->u.ar.dimen == 1 + && shape->ref->u.ar.as + && shape->ref->u.ar.as->lower[0]->expr_type == EXPR_CONSTANT + && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER + && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT + && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER + && shape->symtree->n.sym->attr.flavor == FL_PARAMETER) + { + int i, extent; + gfc_expr *e, *v; + + v = shape->symtree->n.sym->value; + + for (i = 0; i < shape_size; i++) + { + e = gfc_constructor_lookup_expr (v->value.constructor, i); + if (e == NULL) + break; + + gfc_extract_int (e, &extent); + + if (extent < 0) + { + gfc_error ("Element %d of actual argument of RESHAPE at %L " + "cannot be negative", i + 1, &shape->where); + return false; + } + } + } if (pad != NULL) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9df4b08166..65e940b1b7e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-07 Steven G. Kargl + + PR fortran/68153 + * gfortran.dg/pr68153.f90: New test. + 2015-11-07 Steven G. Kargl PR fortran/68151 diff --git a/gcc/testsuite/gfortran.dg/pr68153.f90 b/gcc/testsuite/gfortran.dg/pr68153.f90 new file mode 100644 index 00000000000..1a360f80cd6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr68153.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/68153 +! Original code contribute by Gerhard Steinmetz +! +! +program foo + integer, parameter :: a(2) = [2, -2] + integer, parameter :: b(2,2) = reshape([1, 2, 3, 4], a) ! { dg-error "cannot be negative" } +end program foo -- 2.30.2