public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9618] Fortran: skip compile-time shape check if constructor shape is not known
@ 2022-02-23 18:51 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-02-23 18:51 UTC (permalink / raw)
To: gcc-cvs
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)
Diff:
---
gcc/fortran/resolve.c | 2 ++
.../gfortran.dg/derived_constructor_comps_7.f90 | 28 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index b2304f3af71..4edc0b680e5 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -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 00000000000..238ac3d9f26
--- /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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-23 18:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 18:51 [gcc r11-9618] Fortran: skip compile-time shape check if constructor shape is not known Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).