aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2023-01-23 21:19:03 +0100
committerHarald Anlauf <anlauf@gmx.de>2023-02-05 19:52:10 +0100
commitd4bb7751af090736fb4a3bd7278d7094f35e02e4 (patch)
tree9e60a6666d181f94b6b05cb755409d7d8da30546 /gcc/fortran
parentc67d76171e87d3ce364400684a654712047058b1 (diff)
downloadgcc-d4bb7751af090736fb4a3bd7278d7094f35e02e4.zip
gcc-d4bb7751af090736fb4a3bd7278d7094f35e02e4.tar.gz
gcc-d4bb7751af090736fb4a3bd7278d7094f35e02e4.tar.bz2
Fortran: avoid ICE on invalid array subscript triplets [PR108501]
gcc/fortran/ChangeLog: PR fortran/108501 * interface.c (get_expr_storage_size): Check array subscript triplets that we actually have integer values before trying to extract with mpz_get_si. gcc/testsuite/ChangeLog: PR fortran/108501 * gfortran.dg/pr108501.f90: New test. (cherry picked from commit 771d793df1622a476e1cf8d05f0a6aee350fa56b)
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/interface.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 3fff18b..bf4cdfe 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -2862,7 +2862,8 @@ get_expr_storage_size (gfc_expr *e)
if (ref->u.ar.stride[i])
{
- if (ref->u.ar.stride[i]->expr_type == EXPR_CONSTANT)
+ if (ref->u.ar.stride[i]->expr_type == EXPR_CONSTANT
+ && ref->u.ar.stride[i]->ts.type == BT_INTEGER)
stride = mpz_get_si (ref->u.ar.stride[i]->value.integer);
else
return 0;
@@ -2870,26 +2871,30 @@ get_expr_storage_size (gfc_expr *e)
if (ref->u.ar.start[i])
{
- if (ref->u.ar.start[i]->expr_type == EXPR_CONSTANT)
+ if (ref->u.ar.start[i]->expr_type == EXPR_CONSTANT
+ && ref->u.ar.start[i]->ts.type == BT_INTEGER)
start = mpz_get_si (ref->u.ar.start[i]->value.integer);
else
return 0;
}
else if (ref->u.ar.as->lower[i]
- && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT)
+ && ref->u.ar.as->lower[i]->expr_type == EXPR_CONSTANT
+ && ref->u.ar.as->lower[i]->ts.type == BT_INTEGER)
start = mpz_get_si (ref->u.ar.as->lower[i]->value.integer);
else
return 0;
if (ref->u.ar.end[i])
{
- if (ref->u.ar.end[i]->expr_type == EXPR_CONSTANT)
+ if (ref->u.ar.end[i]->expr_type == EXPR_CONSTANT
+ && ref->u.ar.end[i]->ts.type == BT_INTEGER)
end = mpz_get_si (ref->u.ar.end[i]->value.integer);
else
return 0;
}
else if (ref->u.ar.as->upper[i]
- && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT)
+ && ref->u.ar.as->upper[i]->expr_type == EXPR_CONSTANT
+ && ref->u.ar.as->upper[i]->ts.type == BT_INTEGER)
end = mpz_get_si (ref->u.ar.as->upper[i]->value.integer);
else
return 0;
@@ -2930,7 +2935,9 @@ get_expr_storage_size (gfc_expr *e)
|| ref->u.ar.as->upper[i] == NULL
|| ref->u.ar.as->lower[i] == NULL
|| ref->u.ar.as->upper[i]->expr_type != EXPR_CONSTANT
- || ref->u.ar.as->lower[i]->expr_type != EXPR_CONSTANT)
+ || ref->u.ar.as->lower[i]->expr_type != EXPR_CONSTANT
+ || ref->u.ar.as->upper[i]->ts.type != BT_INTEGER
+ || ref->u.ar.as->lower[i]->ts.type != BT_INTEGER)
return 0;
elements
@@ -2952,7 +2959,9 @@ get_expr_storage_size (gfc_expr *e)
{
if (!as->upper[i] || !as->lower[i]
|| as->upper[i]->expr_type != EXPR_CONSTANT
- || as->lower[i]->expr_type != EXPR_CONSTANT)
+ || as->lower[i]->expr_type != EXPR_CONSTANT
+ || as->upper[i]->ts.type != BT_INTEGER
+ || as->lower[i]->ts.type != BT_INTEGER)
return 0;
elements = elements