aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-11-26 21:00:35 +0100
committerHarald Anlauf <anlauf@gmx.de>2021-11-26 21:00:35 +0100
commit4d540c7a4a7fb87b04d06e1ee7f9b004116279a4 (patch)
tree99226378237d96d9f21a76feaa1cf787e53364a6 /gcc/fortran
parentcaa04517e6f78a562f36897a6e7171f0121101b4 (diff)
downloadgcc-4d540c7a4a7fb87b04d06e1ee7f9b004116279a4.zip
gcc-4d540c7a4a7fb87b04d06e1ee7f9b004116279a4.tar.gz
gcc-4d540c7a4a7fb87b04d06e1ee7f9b004116279a4.tar.bz2
Fortran: improve check of arguments to the RESHAPE intrinsic
gcc/fortran/ChangeLog: PR fortran/103411 * check.c (gfc_check_reshape): Improve check of size of source array for the RESHAPE intrinsic against the given shape when pad is not given, and shape is a parameter. Try other simplifications of shape. gcc/testsuite/ChangeLog: PR fortran/103411 * gfortran.dg/pr68153.f90: Adjust test to improved check. * gfortran.dg/reshape_7.f90: Likewise. * gfortran.dg/reshape_9.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/check.c43
1 files changed, 8 insertions, 35 deletions
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 5a5aca1..3e65f3d 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -4699,6 +4699,7 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
mpz_t size;
mpz_t nelems;
int shape_size;
+ bool shape_is_const;
if (!array_check (source, 0))
return false;
@@ -4732,7 +4733,11 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
"than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
return false;
}
- else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
+
+ gfc_simplify_expr (shape, 0);
+ shape_is_const = gfc_is_constant_expr (shape);
+
+ if (shape->expr_type == EXPR_ARRAY && shape_is_const)
{
gfc_expr *e;
int i, extent;
@@ -4748,38 +4753,7 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
gfc_error ("%qs argument of %qs intrinsic at %L has "
"negative element (%d)",
gfc_current_intrinsic_arg[1]->name,
- gfc_current_intrinsic, &e->where, extent);
- return false;
- }
- }
- }
- 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
- && shape->symtree->n.sym->value)
- {
- 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);
+ gfc_current_intrinsic, &shape->where, extent);
return false;
}
}
@@ -4856,8 +4830,7 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
}
}
- if (pad == NULL && shape->expr_type == EXPR_ARRAY
- && gfc_is_constant_expr (shape)
+ if (pad == NULL && shape->expr_type == EXPR_ARRAY && shape_is_const
&& !(source->expr_type == EXPR_VARIABLE && source->symtree->n.sym->as
&& source->symtree->n.sym->as->type == AS_ASSUMED_SIZE))
{