aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/decl.c
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-10-15 21:23:17 +0200
committerHarald Anlauf <anlauf@gmx.de>2021-10-15 21:23:17 +0200
commit1e819bd95ebeefc1dc469daa1855ce005cb77822 (patch)
treee92e1e5ba1f1abf39844b4c0e87c50145c49f75e /gcc/fortran/decl.c
parent4aef14b09557ce072f1269bd8a05fa2b1df0eda2 (diff)
downloadgcc-1e819bd95ebeefc1dc469daa1855ce005cb77822.zip
gcc-1e819bd95ebeefc1dc469daa1855ce005cb77822.tar.gz
gcc-1e819bd95ebeefc1dc469daa1855ce005cb77822.tar.bz2
Fortran: validate shape of arrays in constructors against declarations
gcc/fortran/ChangeLog: PR fortran/102685 * decl.c (match_clist_expr): Set rank/shape of clist initializer to match LHS. * resolve.c (resolve_structure_cons): In a structure constructor, compare shapes of array components against declared shape. gcc/testsuite/ChangeLog: PR fortran/102685 * gfortran.dg/derived_constructor_char_1.f90: Fix invalid code. * gfortran.dg/pr70931.f90: Likewise. * gfortran.dg/transfer_simplify_2.f90: Likewise. * gfortran.dg/pr102685.f90: New test. Co-authored-by: Tobias Burnus <tobias@codesourcery.com>
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r--gcc/fortran/decl.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index d6a22d1..86adb81 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -896,9 +896,6 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as)
expr->ts = *ts;
expr->value.constructor = array_head;
- expr->rank = as->rank;
- expr->shape = gfc_get_shape (expr->rank);
-
/* Validate sizes. We built expr ourselves, so cons_size will be
constant (we fail above for non-constant expressions).
We still need to verify that the sizes match. */
@@ -911,6 +908,12 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as)
mpz_clear (cons_size);
if (cmp)
goto cleanup;
+
+ /* Set the rank/shape to match the LHS as auto-reshape is implied. */
+ expr->rank = as->rank;
+ expr->shape = gfc_get_shape (as->rank);
+ for (int i = 0; i < as->rank; ++i)
+ spec_dimen_size (as, i, &expr->shape[i]);
}
/* Make sure scalar types match. */