aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-12-07 21:34:31 +0100
committerHarald Anlauf <anlauf@gmx.de>2021-12-07 23:16:18 +0100
commit9eec77c0df9e5c67454a2e8f83246104458ba4f0 (patch)
treefa29641998df52565ca039d0d8afe1c1732587e0 /gcc/fortran
parentcf2cd61dce4f5f0cf9d72328396e7f949db18ddb (diff)
downloadgcc-9eec77c0df9e5c67454a2e8f83246104458ba4f0.zip
gcc-9eec77c0df9e5c67454a2e8f83246104458ba4f0.tar.gz
gcc-9eec77c0df9e5c67454a2e8f83246104458ba4f0.tar.bz2
Fortran: perform array subscript checks only for valid INTEGER bounds
gcc/fortran/ChangeLog: PR fortran/103607 * frontend-passes.c (do_subscript): Ensure that array bounds are of type INTEGER before performing checks on array subscripts. gcc/testsuite/ChangeLog: PR fortran/103607 * gfortran.dg/pr103607.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/frontend-passes.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 4764c83..57b24a1 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -2914,6 +2914,7 @@ do_subscript (gfc_expr **e)
{
if (ar->as->lower[i]
&& ar->as->lower[i]->expr_type == EXPR_CONSTANT
+ && ar->as->lower[i]->ts.type == BT_INTEGER
&& mpz_cmp (val, ar->as->lower[i]->value.integer) < 0)
gfc_warning (warn, "Array reference at %L out of bounds "
"(%ld < %ld) in loop beginning at %L",
@@ -2923,6 +2924,7 @@ do_subscript (gfc_expr **e)
if (ar->as->upper[i]
&& ar->as->upper[i]->expr_type == EXPR_CONSTANT
+ && ar->as->upper[i]->ts.type == BT_INTEGER
&& mpz_cmp (val, ar->as->upper[i]->value.integer) > 0)
gfc_warning (warn, "Array reference at %L out of bounds "
"(%ld > %ld) in loop beginning at %L",
@@ -2938,6 +2940,7 @@ do_subscript (gfc_expr **e)
{
if (ar->as->lower[i]
&& ar->as->lower[i]->expr_type == EXPR_CONSTANT
+ && ar->as->lower[i]->ts.type == BT_INTEGER
&& mpz_cmp (val, ar->as->lower[i]->value.integer) < 0)
gfc_warning (warn, "Array reference at %L out of bounds "
"(%ld < %ld) in loop beginning at %L",
@@ -2947,6 +2950,7 @@ do_subscript (gfc_expr **e)
if (ar->as->upper[i]
&& ar->as->upper[i]->expr_type == EXPR_CONSTANT
+ && ar->as->upper[i]->ts.type == BT_INTEGER
&& mpz_cmp (val, ar->as->upper[i]->value.integer) > 0)
gfc_warning (warn, "Array reference at %L out of bounds "
"(%ld > %ld) in loop beginning at %L",