public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: "José Rui Faustino de Sousa" <jrfsousa@gmail.com>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [Patch, fortran V3] PR fortran/100683 - Array initialization refuses valid
Date: Thu, 17 Jun 2021 19:34:09 +0000	[thread overview]
Message-ID: <aa24b662-f174-b520-8b54-e5d26e7bd218@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

Hi all!

Update to a proposed patch to:

PR100683 - Array initialization refuses valid

due to more errors being found...

Patch tested only on x86_64-pc-linux-gnu.

Add call to simplify expression before parsing *and* check 
*appropriately* if the expression is still an array after simplification.

Add two more situations (already present in the original PR) to 
pr87993.f90 to catch the kind of error I was making.

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/pr87993.f90: increased test coverage.
     * gfortran.dg/PR100683.f90: New test.

[-- Attachment #2: PR100683.patch --]
[-- Type: text/x-patch, Size: 2157 bytes --]

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 45c3ad3..01a2977 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -7137,7 +7137,12 @@ gfc_resolve_expr (gfc_expr *e)
       /* Also try to expand a constructor.  */
       if (t)
 	{
+	  t = gfc_simplify_expr (e, 1);
+	  if (!t)
+	    break;
 	  gfc_expression_rank (e);
+	  if (e->expr_type != EXPR_ARRAY)
+	    break;
 	  if (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
+
diff --git a/gcc/testsuite/gfortran.dg/pr87993.f90 b/gcc/testsuite/gfortran.dg/pr87993.f90
index 96d353d..abc6d0d 100644
--- a/gcc/testsuite/gfortran.dg/pr87993.f90
+++ b/gcc/testsuite/gfortran.dg/pr87993.f90
@@ -2,7 +2,15 @@
 ! Code contributed by Gerhard Steinmetz <gscfq at t-online dot de>
 program p
    integer, parameter :: a(2) = 1
-   integer, parameter :: b = a%kind
+   character, parameter :: b(2) = "X"
+   integer, parameter :: i = a%kind
+   integer, parameter :: j = a(2)%kind
+   integer, parameter :: k = b%kind
+   integer, parameter :: l = b(2)%kind
    if (any(a /= 1)) stop 1
-   if (b /= kind(a)) stop 2
+   if (any(b /= "X")) stop 2
+   if (i /= kind(a)) stop 3
+   if (j /= kind(a)) stop 4
+   if (k /= kind(b)) stop 5
+   if (l /= kind(b)) stop 6
 end

             reply	other threads:[~2021-06-17 19:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17 19:34 José Rui Faustino de Sousa [this message]
2021-06-21 12:37 ` Tobias Burnus
2021-06-21 15:21   ` José Rui Faustino de Sousa
2021-06-21 18:27     ` Paul Richard Thomas
2021-10-22  7:42     ` José's pending bind(C) patches / status (was: Re: [Patch, fortran V3] PR fortran/100683 - Array initialization refuses valid) Tobias Burnus
2021-10-22  8:19       ` Paul Richard Thomas
2021-10-22 13:06       ` Tobias Burnus
2021-10-22 20:29         ` Harald Anlauf
2021-10-22 20:36         ` Harald Anlauf
2021-10-22 20:44         ` Harald Anlauf
  -- strict thread matches above, loose matches on Subject: below --
2021-06-03 15:04 [Patch, fortran] PR fortran/100120/100816/100818/100819/100821 problems raised by aggregate data types dhumieres.dominique
2021-06-04 15:24 ` Paul Richard Thomas
2021-06-05 12:40   ` dhumieres.dominique
2021-06-06 17:58     ` Re:[Patch, fortran] PR fortran/93308/93963/94327/94331/97046 problems raised by descriptor handling dhumieres.dominique
2021-06-19 10:57       ` [Patch, fortran v2] " dhumieres.dominique
2021-06-19 11:00         ` [Patch, fortran V3] PR fortran/100683 - Array initialization refuses valid dhumieres.dominique

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=aa24b662-f174-b520-8b54-e5d26e7bd218@gmail.com \
    --to=jrfsousa@gmail.com \
    --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).