aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-02-21 22:49:05 +0100
committerHarald Anlauf <anlauf@gmx.de>2022-02-22 21:34:58 +0100
commitbc66b471d16ef2fd8cb66fd1131b41f80ecb9961 (patch)
treeeda63dd91babb51df82666b785f93122f103854d /gcc
parent9d1796d82d46dd3086f07953129dc5761feb707b (diff)
downloadgcc-bc66b471d16ef2fd8cb66fd1131b41f80ecb9961.zip
gcc-bc66b471d16ef2fd8cb66fd1131b41f80ecb9961.tar.gz
gcc-bc66b471d16ef2fd8cb66fd1131b41f80ecb9961.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/resolve.cc2
-rw-r--r--gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f9028
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 266e41e..451bc97 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);
diff --git a/gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f90 b/gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f90
new file mode 100644
index 0000000..238ac3d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f90
@@ -0,0 +1,28 @@
+! { dg-do run }
+! PR fortran/104619
+
+module m
+ implicit none
+ type :: item
+ real :: x
+ end type item
+ type :: container
+ type(item) :: items(3)
+ end type container
+end module
+
+program p
+ use m
+ implicit none
+ type(item), allocatable :: items(:)
+ type(container) :: c
+ integer :: i, n
+ items = [item(3.0), item(4.0), item(5.0)]
+ c = container(items=[(items(i), i = 1, size(items))])
+ if (any (c%items% x /= items% x)) stop 1
+ n = size (items)
+ c = container(items=[(items(i), i = 1, n)])
+ if (any (c%items% x /= items% x)) stop 2
+ c = container(items=[(items(i), i = 1, 3)])
+ if (any (c%items% x /= items% x)) stop 3
+end program