From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] PR fortran/104619 - [10/11/12 Regression] ICE on list comprehension with default derived type constructor
Date: Mon, 21 Feb 2022 22:55:51 +0100 [thread overview]
Message-ID: <trinity-09b868ea-e496-4eaf-9306-adf4a8a68278-1645480551337@3c-app-gmx-bs09> (raw)
[-- Attachment #1: Type: text/plain, Size: 361 bytes --]
Dear Fortranners,
a recently introduced shape validation for an array constructor
against the declared shape of a DT component failed to punt if
the shape of the constructor cannot be determined at compile time.
Suggested solution: skip the shape check in those cases.
Regtested on x86_64-pc-linux-gnu. OK for mainline / affected branches?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-skip-compile-time-shape-check-if-constructor.patch --]
[-- Type: text/x-patch, Size: 2270 bytes --]
From 356d1ab6ddb58559d3641f169f44fd24f7cb00d1 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 21 Feb 2022 22:49:05 +0100
Subject: [PATCH] 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.
---
gcc/fortran/resolve.cc | 2 ++
.../derived_constructor_comps_7.f90 | 28 +++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f90
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);
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
--
2.34.1
next reply other threads:[~2022-02-21 21:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 21:55 Harald Anlauf [this message]
2022-02-22 19:08 ` Thomas Koenig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-09b868ea-e496-4eaf-9306-adf4a8a68278-1645480551337@3c-app-gmx-bs09 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).