aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/decl.c
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-09-13 19:28:10 +0200
committerHarald Anlauf <anlauf@gmx.de>2021-09-13 19:28:10 +0200
commit104c05c5284b7822d770ee51a7d91946c7e56d50 (patch)
treee060f101cdc32bf5e520de8e5275db9d4236b74c /gcc/fortran/decl.c
parent8d93ba93d3b13ac3d3c34404cad87732c809605b (diff)
downloadgcc-104c05c5284b7822d770ee51a7d91946c7e56d50.zip
gcc-104c05c5284b7822d770ee51a7d91946c7e56d50.tar.gz
gcc-104c05c5284b7822d770ee51a7d91946c7e56d50.tar.bz2
Fortran - ensure simplification of bounds of array-valued named constants
gcc/fortran/ChangeLog: PR fortran/82314 * decl.c (add_init_expr_to_sym): For proper initialization of array-valued named constants the array bounds need to be simplified before adding the initializer. gcc/testsuite/ChangeLog: PR fortran/82314 * gfortran.dg/pr82314.f90: New test.
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r--gcc/fortran/decl.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 2e49a67..f2e8896 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2169,6 +2169,24 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
sym->as->type = AS_EXPLICIT;
}
+ /* Ensure that explicit bounds are simplified. */
+ if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
+ && sym->as->type == AS_EXPLICIT)
+ {
+ for (int dim = 0; dim < sym->as->rank; ++dim)
+ {
+ gfc_expr *e;
+
+ e = sym->as->lower[dim];
+ if (e->expr_type != EXPR_CONSTANT)
+ gfc_reduce_init_expr (e);
+
+ e = sym->as->upper[dim];
+ if (e->expr_type != EXPR_CONSTANT)
+ gfc_reduce_init_expr (e);
+ }
+ }
+
/* Need to check if the expression we initialized this
to was one of the iso_c_binding named constants. If so,
and we're a parameter (constant), let it be iso_c.