This very short program produces an ICE with gfortran 11.2.1: module m type :: item real :: x end type type :: container type(item) :: items(3) end type end module program p use m type(item), allocatable :: items(:) type(container) :: c items = [item(3.0), item(4.0), item(5.0)] ! ICE in the line below c = container(items=[(items(i), i = 1, size(items))]) print *, c end program
Confirmed. Potential fix: skip shape check when shape is not available diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 266e41e25b1..451bc97df43 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -1472,6 +1472,8 @@ resolve_structure_cons (gfc_expr *expr, int init) t = false; break; }; + if (cons->expr->shape == NULL) + continue; mpz_set_ui (len, 1); mpz_add (len, len, comp->as->upper[n]->value.integer); mpz_sub (len, len, comp->as->lower[n]->value.integer);
Submitted: https://gcc.gnu.org/pipermail/fortran/2022-February/057577.html
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:bc66b471d16ef2fd8cb66fd1131b41f80ecb9961 commit r12-7351-gbc66b471d16ef2fd8cb66fd1131b41f80ecb9961 Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Feb 21 22:49:05 2022 +0100 Fortran: skip compile-time shape check if constructor shape is not known gcc/fortran/ChangeLog: PR fortran/104619 * resolve.cc (resolve_structure_cons): Skip shape check if shape of constructor cannot be determined at compile time. gcc/testsuite/ChangeLog: PR fortran/104619 * gfortran.dg/derived_constructor_comps_7.f90: New test.
The releases/gcc-11 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:d86949f5f55dbe0eb6f3044366101605882cd58e commit r11-9618-gd86949f5f55dbe0eb6f3044366101605882cd58e Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Feb 21 22:49:05 2022 +0100 Fortran: skip compile-time shape check if constructor shape is not known gcc/fortran/ChangeLog: PR fortran/104619 * resolve.c (resolve_structure_cons): Skip shape check if shape of constructor cannot be determined at compile time. gcc/testsuite/ChangeLog: PR fortran/104619 * gfortran.dg/derived_constructor_comps_7.f90: New test. (cherry picked from commit bc66b471d16ef2fd8cb66fd1131b41f80ecb9961)
The releases/gcc-10 branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>: https://gcc.gnu.org/g:251061b82852bdebc6f13510b415ecb73a2f80ae commit r10-10474-g251061b82852bdebc6f13510b415ecb73a2f80ae Author: Harald Anlauf <anlauf@gmx.de> Date: Mon Feb 21 22:49:05 2022 +0100 Fortran: skip compile-time shape check if constructor shape is not known gcc/fortran/ChangeLog: PR fortran/104619 * resolve.c (resolve_structure_cons): Skip shape check if shape of constructor cannot be determined at compile time. gcc/testsuite/ChangeLog: PR fortran/104619 * gfortran.dg/derived_constructor_comps_7.f90: New test. (cherry picked from commit bc66b471d16ef2fd8cb66fd1131b41f80ecb9961)
Fixed on mainline for gcc-12 and on affected branches. Closing. Thanks for the report!