diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-10-14 20:19:50 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-10-14 20:19:50 +0200 |
commit | b47490c572c5938f887b54240af6096a7c90f640 (patch) | |
tree | 9db7531d1ff5a78e155f275f63fc8ea78ac9f104 /gcc | |
parent | 1b115daf62d94337b3d0b2962b0bbbf005a450e0 (diff) | |
download | gcc-b47490c572c5938f887b54240af6096a7c90f640.zip gcc-b47490c572c5938f887b54240af6096a7c90f640.tar.gz gcc-b47490c572c5938f887b54240af6096a7c90f640.tar.bz2 |
Fortran: generate error message for negative elements in SHAPE array
gcc/fortran/ChangeLog:
PR fortran/102717
* simplify.c (gfc_simplify_reshape): Replace assert by error
message for negative elements in SHAPE array.
gcc/testsuite/ChangeLog:
PR fortran/102717
* gfortran.dg/reshape_shape_2.f90: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/simplify.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/reshape_shape_2.f90 | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index f40e493..d675f2c 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6840,7 +6840,13 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, gfc_extract_int (e, &shape[rank]); gcc_assert (rank >= 0 && rank < GFC_MAX_DIMENSIONS); - gcc_assert (shape[rank] >= 0); + if (shape[rank] < 0) + { + gfc_error ("The SHAPE array for the RESHAPE intrinsic at %L has a " + "negative value %d for dimension %d", + &shape_exp->where, shape[rank], rank+1); + return &gfc_bad_expr; + } rank++; } diff --git a/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 new file mode 100644 index 0000000..8f17576 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/102717 + +program p + integer, parameter :: a(1) = 2 + integer, parameter :: b(2) = reshape([3,4], -[a]) ! { dg-error "negative" } +end |