* [Patch, fortran V2] PR fortran/100683 - Array initialization refuses valid
@ 2021-06-14 16:12 José Rui Faustino de Sousa
0 siblings, 0 replies; only message in thread
From: José Rui Faustino de Sousa @ 2021-06-14 16:12 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 578 bytes --]
Hi all!
Update to a proposed patch to:
PR100683 - Array initialization refuses valid
due to errors found by Dominique d'Humieres.
Patch tested only on x86_64-pc-linux-gnu.
Add call to simplify expression before parsing *and* check if the
expression is still an array after simplification.
Thank you very much.
Best regards,
José Rui
Fortran: Fix bogus error
gcc/fortran/ChangeLog:
PR fortran/100683
* resolve.c (gfc_resolve_expr): Add call to gfc_simplify_expr.
gcc/testsuite/ChangeLog:
PR fortran/100683
* gfortran.dg/PR100683.f90: New test.
[-- Attachment #2: PR100683.patch --]
[-- Type: text/x-patch, Size: 1406 bytes --]
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a37ad66..a9518e7 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -7138,8 +7138,10 @@ gfc_resolve_expr (gfc_expr *e)
/* Also try to expand a constructor. */
if (t)
{
+ gfc_simplify_expr(e, 1);
gfc_expression_rank (e);
- if (gfc_is_constant_expr (e) || gfc_is_expandable_expr (e))
+ if (e->expr_type == EXPR_ARRAY
+ && (gfc_is_constant_expr (e) || gfc_is_expandable_expr (e)))
gfc_expand_constructor (e, false);
}
diff --git a/gcc/testsuite/gfortran.dg/PR100683.f90 b/gcc/testsuite/gfortran.dg/PR100683.f90
new file mode 100644
index 0000000..6929bb5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR100683.f90
@@ -0,0 +1,36 @@
+! { dg-do run }
+!
+! Test the fix for PR100683
+!
+
+program main_p
+
+ implicit none
+
+ integer :: i
+ integer, parameter :: n = 11
+ integer, parameter :: u(*) = [(i, i=1,n)]
+
+ type :: foo_t
+ integer :: i
+ end type foo_t
+
+ type, extends(foo_t) :: bar_t
+ integer :: a(n)
+ end type bar_t
+
+ type(bar_t), parameter :: a(*) = [(bar_t(i, u), i=1,n)]
+ type(bar_t) :: b(n) = [(bar_t(i, u), i=1,n)]
+
+ if(any(a(:)%i/=u)) stop 1
+ do i = 1, n
+ if(any(a(i)%a/=u)) stop 2
+ end do
+ if(any(b(:)%i/=u)) stop 3
+ do i = 1, n
+ if(any(b(i)%a/=u)) stop 4
+ end do
+ stop
+
+end program main_p
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-14 16:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 16:12 [Patch, fortran V2] PR fortran/100683 - Array initialization refuses valid José Rui Faustino de Sousa
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).