Hi Harald, dear all, On 14.10.21 23:27, Harald Anlauf via Fortran wrote:
the attached patch adds a check for the shape of arrays in derived type constructors. This brings it in line with other major brands. ... In developing the patch I encountered a difficulty with testcase dec_structure_6.f90, which uses a DEC extension, namelist "old-style CLIST initializers in STRUCTURE". I could not figure out how to determine the shape of the initializer; it seemed to be always zero. I've added code to accept this, but only under -fdec-structure, and added a TODO in a comment. If somebody reading this could give me a hint to solve end, I would adjust the patch accordingly.
See attached patch – it does initialize the variables similarly to other shapes in that file, except that it has to take the shape from the LHS as seemingly (same testfile) having a 1-dim array can be used to initialize a 2-dim array. You can approve that patch and integrate it then in your own patch :-)
Regtested on x86_64-pc-linux-gnu. OK? Or further comments?
LGTM – with the DECL exception removed from resolve.c. Thanks, Tobias PS: Without the auto-reshape part, a simple 'gfc_array_size (expr, &expr->shape[0]))" would have been sufficient. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index d6a22d13451..86adb81da32 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -892,29 +892,32 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) /* Set up expr as an array constructor. */ if (!scalar) { expr = gfc_get_array_expr (ts->type, ts->kind, &where); 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. */ gcc_assert (gfc_array_size (expr, &cons_size)); cmp = mpz_cmp (cons_size, as_size); if (cmp < 0) gfc_error ("Not enough elements in array initializer at %C"); else if (cmp > 0) gfc_error ("Too many elements in array initializer at %C"); 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. */ else if (!gfc_compare_types (&expr->ts, ts) && !gfc_convert_type (expr, ts, 1)) goto cleanup;